local-operator-ui 0.42.4 → 0.42.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/out/main/index.js +4 -0
  2. package/out/renderer/assets/{agent-details-page-BWSojjKJ.js → agent-details-page-sxSaHR4K.js} +1 -1
  3. package/out/renderer/assets/{agent-hub-page-aubDNr6m.js → agent-hub-page-2B3Cz0L7.js} +1 -1
  4. package/out/renderer/assets/{agents-page-DeOCoJow.js → agents-page-SWONT2Y-.js} +3 -3
  5. package/out/renderer/assets/{browser-page-DUwB_Shx.js → browser-page-CEC2xvua.js} +1 -1
  6. package/out/renderer/assets/{browser-webauthn-prompt-D90b-ibP.js → browser-webauthn-prompt-DGYOEUVY.js} +1 -1
  7. package/out/renderer/assets/{index-wz2cjW5P.js → index-CRQJfecC.js} +184 -184
  8. package/out/renderer/assets/{legacy-agents-page-zQ2FJ-pr.js → legacy-agents-page-WYJ6UHsm.js} +1 -1
  9. package/out/renderer/assets/{library-page-CB9dDvmn.js → library-page-DQ0q6JRi.js} +3 -3
  10. package/out/renderer/assets/{mesh-page-SxvMrMpp.js → mesh-page-DO-LVvVi.js} +1 -1
  11. package/out/renderer/assets/{org-access-DVt3GFMX.js → org-access-C90qeM0I.js} +1 -1
  12. package/out/renderer/assets/{projects-page-ACh1mgoo.js → projects-page-BQAyETlA.js} +1 -1
  13. package/out/renderer/assets/{publication-validation-D2z_zWQT.js → publication-validation-RgDLfmCM.js} +1 -1
  14. package/out/renderer/assets/{radient-auth-buttons-Di1zLV23.js → radient-auth-buttons-BmW-BaEj.js} +1 -1
  15. package/out/renderer/assets/{schedules-page-BA4nO5Tw.js → schedules-page-xJSXx04Y.js} +1 -1
  16. package/out/renderer/assets/{settings-page-D5KhLQHE.js → settings-page-CqTYuMWP.js} +1 -1
  17. package/out/renderer/assets/{smartart-58otsUWh.js → smartart-BGclmjFB.js} +1 -1
  18. package/out/renderer/assets/{team-bridge-page-CJdJd9cs.js → team-bridge-page-DrXABFbC.js} +1 -1
  19. package/out/renderer/assets/{use-download-agent-mutation-BAzM19BL.js → use-download-agent-mutation-n0p2QCHH.js} +1 -1
  20. package/out/renderer/index.html +1 -1
  21. package/package.json +1 -1
package/out/main/index.js CHANGED
@@ -76186,6 +76186,10 @@ async function initializeBrowserHost(options, bindings) {
76186
76186
  addressOverlay?.dismissForTab(tabId, "page_focus");
76187
76187
  });
76188
76188
  contents.on("blur", () => host.setPageFocused(tabId, false));
76189
+ contents.on("before-mouse-event", (_event, mouse) => {
76190
+ if (mouse.type === "mouseDown")
76191
+ addressOverlay?.dismissForTab(tabId, "page_pointer");
76192
+ });
76189
76193
  contents.on(
76190
76194
  "did-start-navigation",
76191
76195
  (_event, _url, isInPlace, isMainFrame) => {
@@ -1,4 +1,4 @@
1
- import{r as E,j as e,c as J}from"./index-DhltrflG.js";import{i as ge,a as fe}from"./publication-validation-D2z_zWQT.js";import{h as oe,u as U,A as le,B as je,f as be}from"./path-utils-BkJr3--b.js";import{ap as C,aq as B,T as $,ar as O,as as ce,at as pe,au as ee,S as ye,av as we,aw as ve}from"./conversation-input-sync-BXv32NfB.js";import{c as Ne,u as Ce,L as Ae,T as te,B as l,S as K,h as de,i as L,j as I,k as v,X as ke,l as N,A as se,m as ae,n as ne}from"./error-boundary-CqZRoe9S.js";import{f as De,h as Se,u as Te,i as _e,a as Ee,b as Fe,c as ze,O as Pe,A as qe,d as ie}from"./use-download-agent-mutation-BAzM19BL.js";import{t as a}from"./messages-Cq_3N7VC.js";import{e as re}from"./en-US-CHJkXXr4.js";import{m as Me,o as Le,p as Ie,q as Ke,S as Ue,s as Be,t as Oe,v as Qe,x as Re,A as He,y as We,z as Ye}from"./index-wz2cjW5P.js";import{H as $e}from"./heart-B3mi-jou.js";import"./book-open-CPvwVqAp.js";import"./console-mirror-BiiClM8r.js";/**
1
+ import{r as E,j as e,c as J}from"./index-DhltrflG.js";import{i as ge,a as fe}from"./publication-validation-RgDLfmCM.js";import{h as oe,u as U,A as le,B as je,f as be}from"./path-utils-BkJr3--b.js";import{ap as C,aq as B,T as $,ar as O,as as ce,at as pe,au as ee,S as ye,av as we,aw as ve}from"./conversation-input-sync-BXv32NfB.js";import{c as Ne,u as Ce,L as Ae,T as te,B as l,S as K,h as de,i as L,j as I,k as v,X as ke,l as N,A as se,m as ae,n as ne}from"./error-boundary-CqZRoe9S.js";import{f as De,h as Se,u as Te,i as _e,a as Ee,b as Fe,c as ze,O as Pe,A as qe,d as ie}from"./use-download-agent-mutation-n0p2QCHH.js";import{t as a}from"./messages-Cq_3N7VC.js";import{e as re}from"./en-US-CHJkXXr4.js";import{m as Me,o as Le,p as Ie,q as Ke,S as Ue,s as Be,t as Oe,v as Qe,x as Re,A as He,y as We,z as Ye}from"./index-CRQJfecC.js";import{H as $e}from"./heart-B3mi-jou.js";import"./book-open-CPvwVqAp.js";import"./console-mirror-BiiClM8r.js";/**
2
2
  * @license lucide-react v0.507.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{r,j as e,c as U}from"./index-DhltrflG.js";import{A as zs,D as yt,h as ce,u as ie,a as Ce,c as re,r as es,d as fe,a1 as ps,f as ss,$ as vt,L as Nt}from"./path-utils-BkJr3--b.js";import{P as wt}from"./page-header-B3bOo0UX.js";import{c as St,l as le,B as P,k as C,u as ke,y as _t,I as Ie,T as Ms,D as qe,a as Ue,b as He,d as Be,e as Ke,f as Qe,A as be,m as pe,n as ge,Y as Pt,Z as Tt,_ as Ct,a3 as It,F as gs,G as fs,H as ks,J as js,K as ys}from"./error-boundary-CqZRoe9S.js";import{ap as ts,at as vs,bk as Rt,bl as Ds,a4 as G,aq as je,bc as qs,bm as At,ar as Lt,bn as Ot,P as Us,ax as Hs,bo as Se,bp as Et,bq as Ft}from"./conversation-input-sync-BXv32NfB.js";import{t as l}from"./messages-Cq_3N7VC.js";import{a as $t,p as Bs,P as Ks,u as zt}from"./publication-validation-D2z_zWQT.js";import{h as ae,O as Mt,A as Dt,d as qt,a as Ut,b as Ht,c as Bt,e as Qs,C as Kt,f as Qt,n as Vt,u as Wt,i as Yt}from"./use-download-agent-mutation-BAzM19BL.js";import{H as Gt}from"./heart-B3mi-jou.js";import{z as Jt,bH as Xt,aO as Zt,bI as Vs,bJ as Ws,bK as Ys,bL as ea,bM as sa,aK as as,bN as Ge,aD as ta,aB as Gs,bO as aa,az as ia,u as na,h as la,c as Ns,aI as ra,d as ca,H as oa,bP as da,x as ua,bQ as ma}from"./index-wz2cjW5P.js";import{n as ha,i as xa,H as ba,p as ws,a as pa,o as Js,u as ga}from"./org-access-DVt3GFMX.js";import{R as Xs}from"./radient-auth-buttons-Di1zLV23.js";import{f as fa}from"./format-esAOn2VS.js";import{o as ka,a as Ve}from"./org-surface-gate-tHnRzD9A.js";import{B as ja}from"./building-2-CTbbzJRN.js";import"./en-US-CHJkXXr4.js";import"./book-open-CPvwVqAp.js";import"./console-mirror-BiiClM8r.js";/**
1
+ import{r,j as e,c as U}from"./index-DhltrflG.js";import{A as zs,D as yt,h as ce,u as ie,a as Ce,c as re,r as es,d as fe,a1 as ps,f as ss,$ as vt,L as Nt}from"./path-utils-BkJr3--b.js";import{P as wt}from"./page-header-B3bOo0UX.js";import{c as St,l as le,B as P,k as C,u as ke,y as _t,I as Ie,T as Ms,D as qe,a as Ue,b as He,d as Be,e as Ke,f as Qe,A as be,m as pe,n as ge,Y as Pt,Z as Tt,_ as Ct,a3 as It,F as gs,G as fs,H as ks,J as js,K as ys}from"./error-boundary-CqZRoe9S.js";import{ap as ts,at as vs,bk as Rt,bl as Ds,a4 as G,aq as je,bc as qs,bm as At,ar as Lt,bn as Ot,P as Us,ax as Hs,bo as Se,bp as Et,bq as Ft}from"./conversation-input-sync-BXv32NfB.js";import{t as l}from"./messages-Cq_3N7VC.js";import{a as $t,p as Bs,P as Ks,u as zt}from"./publication-validation-RgDLfmCM.js";import{h as ae,O as Mt,A as Dt,d as qt,a as Ut,b as Ht,c as Bt,e as Qs,C as Kt,f as Qt,n as Vt,u as Wt,i as Yt}from"./use-download-agent-mutation-n0p2QCHH.js";import{H as Gt}from"./heart-B3mi-jou.js";import{z as Jt,bH as Xt,aO as Zt,bI as Vs,bJ as Ws,bK as Ys,bL as ea,bM as sa,aK as as,bN as Ge,aD as ta,aB as Gs,bO as aa,az as ia,u as na,h as la,c as Ns,aI as ra,d as ca,H as oa,bP as da,x as ua,bQ as ma}from"./index-CRQJfecC.js";import{n as ha,i as xa,H as ba,p as ws,a as pa,o as Js,u as ga}from"./org-access-C90qeM0I.js";import{R as Xs}from"./radient-auth-buttons-BmW-BaEj.js";import{f as fa}from"./format-esAOn2VS.js";import{o as ka,a as Ve}from"./org-surface-gate-tHnRzD9A.js";import{B as ja}from"./building-2-CTbbzJRN.js";import"./en-US-CHJkXXr4.js";import"./book-open-CPvwVqAp.js";import"./console-mirror-BiiClM8r.js";/**
2
2
  * @license lucide-react v0.507.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,7 +1,7 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./legacy-agents-page-zQ2FJ-pr.js","./index-DhltrflG.js","./index-UXcKfWo6.css","./page-header-B3bOo0UX.js","./error-boundary-CqZRoe9S.js","./messages-Cq_3N7VC.js","./index-wz2cjW5P.js","./path-utils-BkJr3--b.js","./conversation-input-sync-BXv32NfB.js","./conversation-input-sync-CAX4_ErH.css","./console-mirror-BiiClM8r.js","./console-mirror-DOrYoP_4.css","./index-DHKnfVbX.css","./notebook-pen-FphG2dMG.js","./org-access-DVt3GFMX.js","./org-surface-gate-tHnRzD9A.js","./radient-auth-buttons-Di1zLV23.js","./publication-validation-D2z_zWQT.js"])))=>i.map(i=>d[i]);
2
- import{aZ as xs,ag as bs,a_ as Ie,a$ as Pt,b0 as it,b1 as js,b2 as gt,ar as ke,a7 as vs,a8 as ys,a9 as ks,aa as Ns,aA as ws,ax as rt,T as Me,ap as Bt,b3 as Ut,a4 as _s,b4 as Ss,aq as Cs,b5 as Es,b6 as qt,b7 as Is,b8 as As,b9 as pt,ba as Rs,bb as Ts,bc as Ds,bd as $s}from"./conversation-input-sync-BXv32NfB.js";import{r as i,j as e,c as K}from"./index-DhltrflG.js";import{ax as Ls,ay as Os,az as zt,x as Ht,aA as Fs,aB as lt,aC as Ms,aD as et,aE as tt,aF as Ps,aG as Bs,aH as xt,aI as Kt,aJ as Us,aK as qs,aL as Wt,aM as zs,aN as Hs,y as Ks,aO as Vt,A as Ws}from"./index-wz2cjW5P.js";import{y as Pe,q as ot,a as ze,c as ee,h as Gt,Y as Vs,Z as Gs,u as ct,_ as Js,d as X,g as Ke,D as Be,A as dt,$ as Ys,B as Qs}from"./path-utils-BkJr3--b.js";import{c as Zs,B as E,x as Xs,y as en,k as ve,z as oe,A as ce,m as de,n as me,I as Ne,F as $e,G as Le,H as Oe,J as Fe,K as xe,M as He,N as Ue,q as tn,r as sn,s as nn,w as an,T as st,u as Te,D as Jt,a as Yt,b as Qt,d as Zt,e as Xt,C as rn,f as es,O as ln,P as We,Q as Ve,R as be,U as ue,V as Ge,W as le,Y as on,Z as cn,_ as bt}from"./error-boundary-CqZRoe9S.js";import{t as r,a as dn}from"./messages-Cq_3N7VC.js";import{u as ts,n as Je,H as un,p as mn,a as hn}from"./org-access-DVt3GFMX.js";import"./console-mirror-BiiClM8r.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./legacy-agents-page-WYJ6UHsm.js","./index-DhltrflG.js","./index-UXcKfWo6.css","./page-header-B3bOo0UX.js","./error-boundary-CqZRoe9S.js","./messages-Cq_3N7VC.js","./index-CRQJfecC.js","./path-utils-BkJr3--b.js","./conversation-input-sync-BXv32NfB.js","./conversation-input-sync-CAX4_ErH.css","./console-mirror-BiiClM8r.js","./console-mirror-DOrYoP_4.css","./index-DHKnfVbX.css","./notebook-pen-FphG2dMG.js","./org-access-C90qeM0I.js","./org-surface-gate-tHnRzD9A.js","./radient-auth-buttons-BmW-BaEj.js","./publication-validation-RgDLfmCM.js"])))=>i.map(i=>d[i]);
2
+ import{aZ as xs,ag as bs,a_ as Ie,a$ as Pt,b0 as it,b1 as js,b2 as gt,ar as ke,a7 as vs,a8 as ys,a9 as ks,aa as Ns,aA as ws,ax as rt,T as Me,ap as Bt,b3 as Ut,a4 as _s,b4 as Ss,aq as Cs,b5 as Es,b6 as qt,b7 as Is,b8 as As,b9 as pt,ba as Rs,bb as Ts,bc as Ds,bd as $s}from"./conversation-input-sync-BXv32NfB.js";import{r as i,j as e,c as K}from"./index-DhltrflG.js";import{ax as Ls,ay as Os,az as zt,x as Ht,aA as Fs,aB as lt,aC as Ms,aD as et,aE as tt,aF as Ps,aG as Bs,aH as xt,aI as Kt,aJ as Us,aK as qs,aL as Wt,aM as zs,aN as Hs,y as Ks,aO as Vt,A as Ws}from"./index-CRQJfecC.js";import{y as Pe,q as ot,a as ze,c as ee,h as Gt,Y as Vs,Z as Gs,u as ct,_ as Js,d as X,g as Ke,D as Be,A as dt,$ as Ys,B as Qs}from"./path-utils-BkJr3--b.js";import{c as Zs,B as E,x as Xs,y as en,k as ve,z as oe,A as ce,m as de,n as me,I as Ne,F as $e,G as Le,H as Oe,J as Fe,K as xe,M as He,N as Ue,q as tn,r as sn,s as nn,w as an,T as st,u as Te,D as Jt,a as Yt,b as Qt,d as Zt,e as Xt,C as rn,f as es,O as ln,P as We,Q as Ve,R as be,U as ue,V as Ge,W as le,Y as on,Z as cn,_ as bt}from"./error-boundary-CqZRoe9S.js";import{t as r,a as dn}from"./messages-Cq_3N7VC.js";import{u as ts,n as Je,H as un,p as mn,a as hn}from"./org-access-C90qeM0I.js";import"./console-mirror-BiiClM8r.js";/**
3
3
  * @license lucide-react v0.507.0 - ISC
4
4
  *
5
5
  * This source code is licensed under the ISC license.
6
6
  * See the LICENSE file in the root directory of this source tree.
7
- */const fn=[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]],gn=Zs("log-in",fn),pn=[],Ee="config-composer-note",jt="Configure agents by conversation",xn=["A reviewer that only reads code","Add the coder twice to release-crew","A team called shipping with a manager and two coders"],bn={idle:"bg-ink-dim",running:"bg-accent",stopping:"bg-warning",done:"bg-success",stopped:"bg-ink-muted",error:"bg-danger"};function jn({status:t,pulse:s}){return e.jsx("span",{"aria-hidden":"true",className:K("size-2 shrink-0 rounded-full",bn[t]??"bg-ink-dim",s&&"animate-pulse")})}function vn({run:t}){return t.activity.length===0?e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing to show yet — the run has not called a tool."}):e.jsx("ul",{className:"space-y-1",children:t.activity.map((s,n)=>e.jsxs("li",{className:"flex items-baseline gap-2 text-body-sm",children:[e.jsx("span",{className:"text-ink-dim tabular-nums",children:new Date(s.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),e.jsx("span",{className:"text-ink",children:s.verb})]},`${s.ts}:${s.verb}:${n}`))})}const vt="-mr-2",yn="max-h-[clamp(3.5rem,10vh,5.5rem)]";function kn(){const t=i.useRef(null),[s,n]=i.useState(!1);return i.useEffect(()=>{const a=t.current;if(!a)return;const l=()=>n(a.scrollHeight>a.clientHeight+1);l();const u=new ResizeObserver(l);return u.observe(a),()=>u.disconnect()}),{ref:t,overflowing:s}}function Nn({children:t}){const{ref:s,overflowing:n}=kn();return e.jsx("div",{ref:s,tabIndex:n?0:void 0,role:n?"region":void 0,"aria-label":n?"Run details":void 0,"data-lo-region-cue":n?"":void 0,className:K("mb-2 overflow-y-auto empty:hidden",yn),children:t})}const wn="mb-1 flex min-h-7 items-center gap-3",yt=t=>t===1?"1 definition":`${t} definitions`;function _n({run:t,about:s,blockedReason:n,hasDraft:a,onClearAbout:l,onDismiss:u}){const[g,h]=i.useState(!1),v=i.useRef(null),p=t.status==="running"||t.status==="stopping",d=t.enabled&&t.status!=="idle",m=!!n&&a&&!d,S=!!n&&a&&d&&!p;i.useEffect(()=>{if(!p)return;const j=k=>{k.key!=="Escape"||k.defaultPrevented||document.querySelector('[role="alertdialog"], [role="dialog"]')||v.current?.focus()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[p]);const x=t.status==="running"?t.step??"Working on your request":t.status==="stopping"?"Stopping":t.status==="done"?t.results.length>0?"Finished":"Finished without changing anything":t.status==="stopped"?"Stopped":t.status==="error"?t.canRetry?"Stopped with an error":"Finished with an error":"";return e.jsxs("div",{className:Ie,"data-testid":d?"config-run-strip":void 0,children:[e.jsxs("div",{className:wn,children:[d?e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx(jn,{status:t.status,pulse:p}),e.jsxs("span",{"aria-live":"polite",className:"min-w-0 truncate text-body-sm text-ink",children:[x,t.status==="done"&&t.touched.length>0?e.jsx("span",{className:"sr-only",children:`. Configured ${yt(t.touched.length)}`}):null]}),(p||t.status==="stopped"||t.status==="done")&&t.elapsed!=="0s"?e.jsx("span",{className:"shrink-0 text-meta text-ink-muted tabular-nums",children:t.elapsed}):null,t.touched.length>0?e.jsxs("span",{"aria-hidden":t.status==="done"?!0:void 0,className:"shrink-0 text-meta text-ink-muted",children:[e.jsx("span",{className:"sr-only",children:"Configured "}),yt(t.touched.length)]}):null]}):null,t.enabled&&!S?e.jsxs(e.Fragment,{children:[m?null:e.jsx("span",{id:n?void 0:Ee,"data-testid":n?void 0:"config-composer-note",className:d?"sr-only":"min-w-0 flex-1 truncate text-meta text-ink-dim",children:"Runs in the background. This does not appear in your conversation."}),n?e.jsx("span",{id:Ee,"data-testid":"config-composer-note",className:m?"min-w-0 flex-1 truncate text-meta text-ink-dim":"sr-only",children:n}):null]}):e.jsx("span",{className:"flex-1","aria-hidden":"true"}),e.jsxs("div",{className:"ms-auto flex shrink-0 items-center gap-1",children:[s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"data-testid":"config-composer-about",title:`About ${s.kind} ${s.name}`,className:"max-w-56 truncate text-meta text-ink-muted",children:["About ",s.kind," ",s.name]}),e.jsx(E,{variant:"ghost",size:"sm",className:d?void 0:vt,onClick:l,children:"Clear"})]}):null,d&&t.activity.length>0?e.jsxs(E,{variant:"ghost",size:"sm","aria-expanded":g,onClick:()=>h(j=>!j),children:[g?e.jsx(Xs,{className:"size-3.5"}):e.jsx(en,{className:"size-3.5 rtl:-scale-x-100"}),"Watch"]}):null,d?p?e.jsxs(E,{ref:v,variant:"secondary",size:"sm",disabled:t.status==="stopping",onClick:()=>void t.stop(),children:[e.jsx(js,{className:"size-3.5"}),t.status==="stopping"?"Stopping…":"Stop"]}):e.jsx(E,{variant:"ghost",size:"sm",className:vt,onClick:u,children:"Dismiss"}):null]})]}),t.enabled?null:e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-dim",children:t.disabledReason}),S?e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-muted",children:n}):null,d?e.jsxs(Nn,{children:[t.attached?e.jsx("p",{className:"mt-1 text-meta text-ink-muted",children:"Another configuration run was already going, so this page attached to it. Your request was not sent — it is still in the box."}):null,t.stopError?e.jsxs("div",{className:"mt-2 border-danger-border border-t pt-2","data-testid":"config-stop-refused",children:[e.jsx("p",{className:"text-body-sm text-danger",children:"The stop did not take — the run is still going."}),e.jsx("p",{className:"mt-0.5 text-meta text-ink-muted",children:t.stopError})]}):null,g?e.jsx("div",{className:"mt-2 border-hairline border-t pt-2",children:e.jsx(vn,{run:t})}):null,t.status==="stopped"?e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink",children:t.results.length>0?"Stopped. Changes it had already made were kept.":"Stopped. Nothing had been changed yet."}),t.results.length>0?e.jsx("ul",{className:"space-y-0.5",children:t.results.map(j=>e.jsxs("li",{className:"text-ink-muted",children:[j.created?"Created ":"Changed ",e.jsx("span",{className:"text-ink",children:j.target.name})]},`${j.target.kind}:${j.target.name}`))}):null]}):null,t.status==="done"?e.jsx(Sn,{run:t}):null,t.status==="error"&&t.error?e.jsx("div",{className:"mt-2 border-danger-border border-t pt-2",children:e.jsx("p",{className:"text-body-sm text-danger",children:t.error})}):null]}):null,d&&t.status==="error"&&t.error?e.jsxs("div",{className:"mb-2.5 flex items-center gap-2",children:[t.canRetry?e.jsx(E,{variant:"secondary",size:"sm","data-testid":"config-retry",disabled:t.starting,onClick:()=>void t.retry(),children:t.starting?"Sending…":"Retry"}):null,e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing else was changed by this run."})]}):null]})}function Sn({run:t}){return t.results.length===0?e.jsxs("div",{className:"mt-2 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink-muted",children:"The run answered without changing any agent or team."}),t.answer?e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-ink",children:t.answer}):null,t.topic?e.jsxs("p",{className:"mt-1 text-meta text-ink-muted",children:["You asked: ",t.topic]}):null]}):e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2",children:[e.jsx("ul",{className:"space-y-1 text-body-sm",children:t.results.map(s=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-ink",children:[s.created?"Created ":"Updated ",s.target.name]}),e.jsxs("span",{className:"text-ink-muted",children:[" (",s.target.kind,")"]}),s.changes.length>0?e.jsxs("span",{className:"text-ink-muted",children:[": ",s.changes.map(n=>n.label).join(", ")]}):s.created?null:e.jsx("span",{className:"text-ink-muted",children:": its settings changed. The list does not show instructions, so open it to see what was written."})]},`${s.target.kind}:${s.target.name}`))}),t.answer?e.jsx("p",{className:"whitespace-pre-wrap text-body-sm text-ink-muted",children:t.answer}):null]})}const we="agents-config",Cn=t=>`Change the ${t.kind} ${t.name}: `;function Ye(t,s,n){t.setAbout(s);const a=Pe.getState();a.getCurrentInput(we)||a.setComposerText(we,n)}function En(t){const s=Pe.getState();s.getCurrentInput(we).trim()===Cn(t).trim()&&s.setComposerText(we,"")}function ss({run:t,hero:s=!1,blockedReason:n,about:a,onClearAbout:l}){const u=i.useRef(null),g=xs(),h=ot(A=>A.cwd),v=ze(),p=t.frontend===null&&t.status==="idle"&&h.length>0&&ee(v.data,"draft_preview"),d=Gt({...Vs({cwd:h,model:null},ee(v.data,"draft_fast")),enabled:p}),m=we,S=A=>Pe.getState().setCurrentInput(m,A),x=t.status==="running"||t.status==="stopping",j=!t.enabled||!!n,k=Pe(A=>(A.inputByConversation[we]?.currentInput??"").trim().length>0),T=n||(x?"Working on your request…":t.enabled?void 0:jt),y=a?`Change ${a.name}…`:t.enabled?s?"Describe what you want…":"Ask for a change, or describe something new…":jt,N=a?`${a.kind}:${a.name}`:null;i.useEffect(()=>{N&&u.current?.focusInput()},[N]);const _=()=>{t.dismiss(),u.current?.focusInput()},$=()=>{l(),u.current?.focusInput()};return e.jsxs("div",{"data-testid":"config-composer",children:[e.jsx("div",{className:"sr-only",id:"config-composer-label",children:"Ask for an agent or team change"}),e.jsx(bs,{ref:u,conversationId:m,messages:pn,isLoading:!1,transcriptless:!0,placeholderOverride:y,sessionStatus:t.frontend?{frontend:t.frontend,costChannels:ee(v.data,"cost_channels")}:d.data?{frontend:d.data.snapshot,draft:!0,costChannels:ee(v.data,"cost_channels")}:void 0,recordingProbe:g,hostNotice:{id:Ee,blocksInput:!t.enabled||!!n||x,placeholder:T,statedByNode:k,node:e.jsx(_n,{run:t,about:a,blockedReason:n,hasDraft:k,onClearAbout:$,onDismiss:_})},onSendMessage:(A,f)=>t.start(A,a,f)}),s&&t.enabled?e.jsx("div",{className:K(it,Pt),children:e.jsx("div",{className:K(Ie,"mt-2 flex flex-col items-start gap-0.5",!a&&!x?"":"invisible"),children:xn.map(A=>e.jsx(E,{variant:"ghost",size:"sm",className:"-ml-2 h-auto max-w-full justify-start whitespace-normal break-words px-2 py-1 text-start text-body-sm text-ink-muted hover:bg-elevated hover:text-ink disabled:text-ink-disabled disabled:hover:bg-transparent",disabled:j,onClick:()=>{S(A),u.current?.focusInput()},children:A},A))})}):null]})}const kt=(t,s)=>t.kind===s.kind&&t.name===s.name;function In(t){return`${t.kind}:${t.name}`}const J=Gs(t=>({sessionId:null,status:"idle",topic:"",images:[],files:[],about:null,error:null,stopError:null,unsent:!1,startedAt:null,settledAt:null,touched:[],results:[],answer:"",marks:[],before:null,setAbout:s=>t({about:s}),adopt:(s,n,a,l=[],u=[])=>t({sessionId:s,status:"running",topic:n,images:l,files:u,error:null,stopError:null,startedAt:Date.now(),settledAt:null,touched:[],results:[],answer:"",before:a,unsent:!1}),noteTouched:s=>t(n=>n.touched.some(a=>kt(a,s))?n:{touched:[...n.touched,s]}),stopping:()=>t(s=>s.status==="running"?{status:"stopping",stopError:null}:s),stopFailed:s=>t({status:"running",stopError:s}),settle:(s,n,a)=>t(()=>({status:n,settledAt:Date.now(),results:s,answer:a,marks:s.map(l=>({...l.target,created:l.created})),sessionId:null,images:[],files:[],stopError:null,before:null,unsent:!1})),fail:s=>t({status:"error",error:s,unsent:!1,stopError:null}),failUnsent:s=>t({status:"error",error:s,unsent:!0,stopError:null}),dismiss:()=>t({status:"idle",sessionId:null,error:null,stopError:null,unsent:!1,topic:"",images:[],files:[],touched:[],results:[],answer:"",marks:[],startedAt:null,settledAt:null,before:null}),clearMark:s=>t(n=>({marks:n.marks.filter(a=>!kt(a,s))}))})),An=/Value error,\s*([\s\S]*?)\s*\[type=/,Rn=/^\d+ validation errors? for \S+[\s\S]*?\n\s*/i,Tn=/\s*\[type=[^\]]*\][\s\S]*$/m,Dn=/\s*For further information visit \S+/g,$n=/'([^']+)' already exists/,Ln=/cannot contain spaces or path separators/i,On=/effort tier '([^']+)' is unavailable/i,Fn=/team name must be/i,Mn=/manager '([^']+)'/i,Pn=/(?:member|role) '([^']+)' (?:is not|does not)/i,Bn=/depth|cycle|circular/i,Un=/instructions/i,qn=/description/i;function zn(t){const s=t.match(An);return s?.[1]?s[1].trim():t.replace(Rn,"").replace(Tn,"").replace(Dn,"").trim()}function Ae(t){const s=zn(t),n=s.match($n);if(n)return{message:r("ui.agents.refusals.name_taken",{name:n[1]}),field:"name"};if(Ln.test(s))return{message:r("ui.agents.refusals.name_grammar"),field:"name"};const a=s.match(On);if(a)return{message:r("ui.agents.refusals.effort_unavailable",{tier:a[1]}),field:"effort"};if(s.match(Fn))return{message:r("ui.agents.refusals.team_name_bound"),field:"name"};const u=s.match(Mn);if(u)return{message:r("ui.agents.refusals.missing_manager",{name:u[1]}),field:"manager"};const g=s.match(Pn);return g?{message:r("ui.agents.refusals.missing_member",{name:g[1]}),field:"members"}:Bn.test(s)?{message:r("ui.agents.refusals.team_nesting"),field:"members"}:Un.test(s)?{message:s,field:"instructions"}:qn.test(s)?{message:s,field:"description"}:{message:s,field:null}}function Hn(t,s){const n=new Set(s),a=`${t}-copy`;if(!n.has(a))return a;for(let l=2;l<100;l+=1){const u=`${a}-${l}`;if(!n.has(u))return u}return a}function De(t){return t.action_class==="proactive"?"proactive":"reactive"}const ns={get proactive(){return r("ui.agents.refusals.class.label.proactive")}},Kn={get proactive(){return r("ui.agents.refusals.class.meaning.proactive")},get reactive(){return r("ui.agents.refusals.class.meaning.reactive")}},Wn={get proactive(){return r("ui.agents.refusals.class.effect.proactive")},get reactive(){return r("ui.agents.refusals.class.effect.reactive")}};let as=r("ui.agents.refusals.class.install_disclosure");dn(()=>{as=r("ui.agents.refusals.class.install_disclosure")});function Vn(t,s){const n=[];return t.source==="builtin"&&n.push({op:"profiles.install",name:t.name}),n.push({op:"profiles.update",name:t.name,fields:{action_class:s}}),n}async function Gn(t,s,n,a=()=>crypto.randomUUID()){if(De(t)===s)return null;let l=null;const u=Vn(t,s);for(let g=0;g<u.length;g+=1){const h=u[g];try{l=await n(h,a())}catch(v){throw new is(v,u.slice(0,g))}}return l}class is extends Error{completed;constructor(s,n){super(s instanceof Error?s.message:String(s)),this.name="ClassSwitchError",this.completed=n}}function Jn(t,s){const n=t instanceof Error&&t.message?t.message:r("ui.agents.refusals.class.error.no_reason"),a=Ae(n).message;return s.some(l=>l.op==="profiles.install")?r("ui.agents.refusals.class.error.install_landed",{reason:a}):a}const Yn=new Set(["agent","team"]);function Qn(t){const s=typeof t.args?.op=="string"?t.args.op:null,n=typeof t.args?.name=="string"?t.args.name:null,a=t.toolName==="team"?"team":"agent",l=n?{kind:a,name:n}:null,u=t.phase==="done"&&!t.isError&&!t.notRunReason&&!t.neverSent,g=h=>({writes:h&&u});switch(s){case"create":return{verb:n?`Creating ${a} ${n}`:`Creating a ${a}`,target:l,...g(!0)};case"update":return{verb:n?`Updating ${a} ${n}`:`Updating a ${a}`,target:l,...g(!0)};case"install":return{verb:n?`Installing ${n}`:"Installing an agent",target:l,...g(!0)};case"list":case"search":case"show":return{verb:n?`Reading ${n}`:`Reading ${a}s`,target:l,...g(!1)};default:return{verb:t.phase==="running"?`Working on ${a}s`:`Checked ${a}s`,target:l,...g(!0)}}}const Zn={description:"description",kind:"kind",tools:"tools",effort:"effort tier",delegate:"delegation",action_class:"class",manager:"manager",members:"members",instructions:"instructions"};function Xn(t){return{description:t.description??"",kind:t.kind,tools:t.tools&&t.tools.length>0?[...t.tools].sort().join(","):"*",effort:t.effort??"inherit",delegate:String(!!t.delegate),action_class:De(t)}}function ea(t){return{description:t.description??"",manager:t.manager??"",members:(t.members??[]).map(s=>`${s.kind}:${s.role}x${s.count}`).sort().join(",")}}function Nt(t,s){return{agents:Object.fromEntries((t??[]).map(n=>[n.name,Xn(n)])),teams:Object.fromEntries((s??[]).map(n=>[n.name,ea(n)]))}}function ta(t,s){if(t===s)return"tools";const n=h=>h==="*"?null:new Set(h.split(",")),a=n(t),l=n(s);if(l===null)return"tools widened to every tool";if(a===null)return"tools narrowed to a list";const u=[...l].filter(h=>!a.has(h)),g=[...a].filter(h=>!l.has(h));return u.length&&!g.length?u.length===1?`tool added: ${u[0]}`:`${u.length} tools added`:g.length&&!u.length?g.length===1?`tool removed: ${g[0]}`:`${g.length} tools removed`:"tools changed"}function sa(t,s,n){if(t==="tools")return ta(s,n);if(t==="delegate")return n==="true"?"delegation turned on":"delegation turned off";if(t==="action_class")return n==="proactive"?"class changed to proactive":"class changed to reactive — proactive messaging stopped";if(t==="members"){const a=l=>l?l.split(",").length:0;return`members changed (${a(s)} to ${a(n)})`}return`${Zn[t]??t} changed`}function na(t,s,n){const a=[],l=new Set;for(const u of n){const g=`${u.kind}:${u.name}`;if(l.has(g))continue;l.add(g);const h=t[u.kind==="agent"?"agents":"teams"][u.name],v=s[u.kind==="agent"?"agents":"teams"][u.name];if(!v)continue;if(!h){a.push({target:u,created:!0,changes:[]});continue}const p=[];for(const d of Object.keys(v))v[d]!==h[d]&&p.push({label:sa(d,h[d],v[d]),before:h[d],after:v[d]});a.push({target:u,created:!1,changes:p})}for(const[u,g]of[["agent",s.agents],["team",s.teams]])for(const h of Object.keys(g))l.has(`${u}:${h}`)||(u==="agent"?t.agents[h]:t.teams[h])||a.push({target:{kind:u,name:h},created:!0,changes:[]});return a}function aa(t){return ee(t,"agents_config")&&ee(t,"session_interrupt")&&ee(t,"profile_catalogue")&&ee(t,"team_catalogue")}function ia(t){if(!(t instanceof Be)||t.status!==409)return null;const n=t.detail?.session_id;return typeof n=="string"&&n.length>0?n:null}function ra(t,s){const[n,a]=i.useState(()=>Date.now());return i.useEffect(()=>{if(!t||!s)return;const l=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(l)},[t,s]),t?Math.max(0,n-t):0}function la(t){const s=Math.floor(t/1e3);return s<60?`${s}s`:`${Math.floor(s/60)}m ${String(s%60).padStart(2,"0")}s`}function wt(t){for(let s=(t?.length??0)-1;s>=0;s-=1){const n=t?.[s];if(n?.kind==="assistant"&&n.text?.trim())return n.text.trim()}return""}function oa(t){const n=t?.payload?.frontend;if(!n||typeof n!="object")return null;const a=n.streaming;if(typeof a=="boolean")return a;const l=n.snapshot?.streaming;return typeof l=="boolean"?l:null}function ca(){const t=ze(),s=aa(t.data),n=ct(),a=J(),[l,u]=i.useState(!1),[g,h]=i.useState(!1),v=i.useRef(!1),p=a.status==="running"||a.status==="stopping",d=Js(a.sessionId??void 0,!!a.sessionId),m=i.useMemo(()=>wt(d.transcript?.records),[d.transcript?.records]);Ls(a.sessionId??void 0,d.subscriptionId);const S=d.transcript?.records,x=i.useRef(S);i.useEffect(()=>{x.current=S},[S]);const j=i.useMemo(()=>(d.transcript?.records??[]).filter(C=>C.kind==="tool"&&Yn.has(C.toolName)).map(C=>({...Qn({toolName:C.toolName,args:C.args??null,phase:C.phase,ts:C.ts,isError:C.isError,notRunReason:C.notRunReason,neverSent:C.neverSent}),ts:C.ts})),[d.transcript]);i.useEffect(()=>{if(p)for(const o of j)o.target&&o.writes&&a.noteTouched(o.target)},[j,p,a]);const k=p&&j.length>0?j[j.length-1].verb:null,T=la(ra(a.startedAt,p)),y=i.useCallback(async(o,C="")=>{if(v.current)return;v.current=!0;const R=a.before;let w=[];try{const[B,P]=await Promise.all([X({op:"profiles.list"}),X({op:"teams.list"})]);R&&(w=na(R,Nt(B.profiles,P.teams),a.touched))}catch{J.getState().fail("The run finished, but the agents and teams lists could not be read to describe what changed."),gt(n);return}if(gt(n),J.getState().settle(w,o,C),o==="done"&&w.length>0){const B=w.filter(P=>P.created).length;ke(B>0?`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} changed.`:`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} updated.`)}},[n,a.before,a.touched]);i.useEffect(()=>{if(p){if(d.failure){J.getState().fail(d.failure.statement);return}v.current||d.frontend&&(d.frontend.streaming||d.turnsCompleted!==0&&y(a.status==="stopping"?"stopped":"done",m))}},[p,m,d.failure,d.frontend,d.turnsCompleted,a.status,y]),i.useEffect(()=>{const o=a.sessionId;if(!p||!o)return;let C=!1;const R=async()=>{if(!(C||v.current))try{const P=await X({op:"sessions.get",sessionId:o});if(C||v.current||oa(P)!==!1)return;const z=wt(x.current);if(!z)return;y(J.getState().status==="stopping"?"stopped":"done",z)}catch{}},w=setTimeout(()=>void R(),400),B=setInterval(()=>void R(),4e3);return()=>{C=!0,clearTimeout(w),clearInterval(B)}},[p,a.sessionId,y]);const N=async(o,C,R=[])=>{if(l||!o.trim()&&R.length===0)return!1;u(!0),h(!1),v.current=!1;const w=Nt(n.getQueryData(["desktop","profiles"]),n.getQueryData(["desktop","teams"])),B=C?`About the ${C.kind} “${C.name}”: ${o.trim()}`:o.trim(),{images:P,files:z,failures:te,overflow:ne,fileOverflow:Z}=await vs(R,B),M=ys(te);if(M)return J.getState().fail(M),!1;const q=ks(ne);if(q)return J.getState().fail(q),!1;const se=Ns(Z);if(se)return J.getState().fail(se),!1;try{let W;try{W=(await X({op:"sessions.create",requestId:crypto.randomUUID(),purpose:"agents-config"})).session_id}catch(Y){const H=ia(Y);if(H)return h(!0),a.adopt(H,o.trim(),w,P,z),!1;throw Y}return a.adopt(W,B,w,P,z),await _(W,B,P,z),!0}catch(W){const Y=J.getState().sessionId;return J.getState().failUnsent(Ke(W,Y?"The run was set up, but your request could not be sent. It is still in the box — send it again when the backend is reachable.":"The configuration run could not be started. Your request is still here.")),!1}finally{u(!1)}},_=async(o,C,R=[],w=[])=>{await X({op:"sessions.message",sessionId:o,requestId:crypto.randomUUID(),text:C,...R.length>0?{images:R}:{},...w.length>0?{files:w}:{}})},$=async()=>{const o=J.getState();if(!(l||!o.unsent||!o.sessionId||!o.topic&&o.images.length===0)){u(!0);try{await _(o.sessionId,o.topic,o.images,o.files),a.adopt(o.sessionId,o.topic,o.before),v.current=!1}catch(C){J.getState().failUnsent(Ke(C,"The request could not be sent. It is still in the box."))}finally{u(!1)}}},A=async()=>{const o=J.getState().sessionId;if(o){a.stopping();try{await Os(o,crypto.randomUUID())}catch(C){J.getState().stopFailed(Ke(C,"The run did not acknowledge the request."))}}},f=s?null:t.isLoading?"Connecting to the backend…":t.error?"The backend could not be reached, so the composer is unavailable for now.":"Ask for a change needs a newer backend. Update Local Operator to configure agents by conversation.";return{enabled:s,disabledReason:f,status:a.status,sessionId:a.sessionId,frontend:d.frontend,topic:a.topic,error:a.error,stopError:a.stopError,about:a.about,setAbout:a.setAbout,touched:a.touched,results:a.results,answer:a.answer,step:k,elapsed:T,activity:j,start:N,stop:A,retry:$,canRetry:a.unsent&&!!a.sessionId,dismiss:a.dismiss,starting:l,attached:g}}function da(t){return JSON.stringify(t.agent_id?["agent","id",t.agent_id]:["agent","source",t.source,t.name])}function ua(t){return JSON.stringify(t.id?["team","id",t.id]:["team","local",t.name])}function U({title:t,description:s,actions:n,children:a,className:l}){return e.jsxs("section",{className:K("space-y-2",l),children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:[e.jsx("h3",{className:"text-heading",children:t}),n]}),s?e.jsx("p",{className:"text-meta text-ink-muted",children:s}):null,a]})}const ut="min-h-6",rs="h-[calc(var(--text-title)*var(--text-title--line-height))]";function ye({text:t,empty:s="Nothing here yet.",mono:n=!1}){const[a,l]=i.useState(!1),[u,g]=i.useState(!1),h=i.useRef(null);return i.useEffect(()=>{if(a)return;const v=h.current;if(!v)return;const p=()=>g(!!t&&v.scrollHeight>v.clientHeight+1);p();const d=new ResizeObserver(p);return d.observe(v),()=>d.disconnect()},[t,a]),t.trim()?e.jsxs("div",{children:[e.jsx("div",{ref:h,className:K("whitespace-pre-wrap text-body text-ink",!a&&"line-clamp-10",n&&"font-mono text-meta"),children:t}),u?e.jsx(E,{variant:"link",size:"sm",className:K("mt-px -mb-[3px]",ut),"aria-expanded":a,onClick:()=>l(v=>!v),children:a?"Show less":"Show all"}):null]}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:s})}function ma({source:t,appearance:s="chip"}){const n=ls(t);return s==="text"?e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:n}):e.jsx(oe,{variant:"neutral",children:n})}function ls(t){return t==="builtin"?"Built-in":t==="installed"?"Installed":"Custom"}let mt=!1,os=null;function _t(t,s){mt=t,os=t?s??null:null}function cs(t,s){i.useEffect(()=>{if(!s)return;const n=a=>{a.key!=="Escape"||a.defaultPrevented||mt||(a.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[s,t])}function ht({dirty:t,pending:s,onSave:n,onCancel:a,saveLabel:l="Save changes",pendingLabel:u="Saving…",dirtyHint:g,submit:h,confirming:v,onConfirmingChange:p}){const[d,m]=i.useState(!1),S=i.useRef(null),x=i.useRef(null),j=v!==void 0,k=j?v:d,T=i.useRef(!1);i.useEffect(()=>{k?x.current?.focus():T.current&&document.activeElement===document.body&&S.current?.focus(),T.current=k},[k]);const y=i.useRef(null);i.useEffect(()=>{const _=y.current,$=_?.closest("[data-agents-pane]");if(!_||!$)return;const A=()=>$.style.setProperty("--lo-pane-footer-h",`${_.getBoundingClientRect().height}px`);A();const f=new ResizeObserver(A);return f.observe(_),()=>{f.disconnect(),$.style.removeProperty("--lo-pane-footer-h")}},[]);const N=_=>{j||m(_),p?.(_)};return i.useEffect(()=>{t||(j||m(!1),p?.(!1))},[t,j,p]),e.jsxs("div",{ref:y,"data-testid":"edit-footer","data-lo-pane-footer":!0,className:"sticky bottom-0 z-10 flex flex-wrap items-center gap-2 border-hairline border-t bg-canvas py-3",children:[e.jsx(E,{ref:S,type:h?"submit":void 0,variant:"primary",onClick:h?void 0:n,disabled:s,children:s?u:l}),k?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:g??"Discard your unsaved changes?"}),e.jsx(E,{variant:"danger",onClick:a,children:"Discard changes"}),e.jsx(E,{ref:x,variant:"ghost",onClick:()=>{N(!1),S.current?.focus()},children:"Keep editing"})]}):e.jsx(E,{variant:"ghost",onClick:()=>{mt&&os?.(),t?N(!0):a()},disabled:s,children:"Cancel"}),t&&!k?e.jsx("span",{className:"ms-auto text-meta text-ink-dim",children:"Unsaved changes"}):null]})}let nt=!1;function ds(){nt=!0}function us(){const t=nt;return nt=!1,t}function ha({rows:t=6}){return e.jsx("div",{className:"space-y-1","aria-hidden":"true",children:fa.slice(0,t).map(s=>e.jsx(ve,{className:"h-12 w-full"},s))})}const fa=["a","b","c","d","e","f","g","h"];function St(){return e.jsxs("div",{className:"space-y-8","aria-hidden":"true",children:[e.jsx(ve,{className:"h-7 w-64"}),e.jsx(ve,{className:"h-5 w-40"}),e.jsx(ve,{className:"h-28 w-full"}),e.jsx(ve,{className:"h-24 w-full"})]})}function Ct({title:t,what:s,meaning:n,onRetry:a,retrying:l=!1}){return e.jsxs("div",{role:"alert",className:"max-w-xl space-y-2",children:[e.jsx("h2",{className:"text-heading",children:t}),e.jsx("p",{className:"text-body-sm text-ink",children:s}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:n}),e.jsx(E,{variant:"secondary",onClick:a,disabled:l,children:l?"Retrying…":"Retry"})]})}function he({label:t,htmlFor:s,error:n}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("label",{htmlFor:s,className:"text-body-sm text-ink-muted",children:t}),n?e.jsx("span",{className:"text-meta text-danger",role:"alert",children:n}):null]})}const ga=/^[A-Za-z0-9_.:-]{1,128}$/;function pe(t){return{description:t.description??"",instructions:t.instructions??"",tools:t.tools&&t.tools.length>0?[...t.tools]:null,effort:t.effort??"inherit",delegate:t.delegate??!1}}function pa(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.instructions!==t.instructions&&(n.instructions=s.instructions),JSON.stringify(s.tools)!==JSON.stringify(t.tools)&&(n.tools=s.tools??[]),s.effort!==t.effort&&(n.effort=s.effort),s.delegate!==t.delegate&&(n.delegate=s.delegate),n}function xa({profile:t}){const s=[ls(t.source),De(t)==="proactive"?ns.proactive:null,t.delegate?"Delegates":null,t.kind==="specialist"?"Specialist":null].filter(Boolean);return e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("p",{className:"text-body-sm text-ink-muted",children:s.join(" · ")}),t.divergent_fields?.length?e.jsx(oe,{variant:"warning",children:"Modified"}):null]})}const ba=5e3;let Qe=null;function ja({profile:t,displayedName:s,notice:n,onNotice:a,onChanged:l}){const u=De(t),[g,h]=i.useState(null),[v,p]=i.useState(!1),d=i.useRef(null),m=i.useId();i.useEffect(()=>{g!==null&&u===g&&h(null)},[u,g]),i.useEffect(()=>{const j=Qe;!j||j.name!==t.name||(Qe=null,!(Date.now()-j.at>ba)&&d.current?.focus())},[t.name]);const S=g??u,x=async j=>{if(!(v||j===S)){Qe={name:t.name,at:Date.now()},a(null),h(j),p(!0);try{await Gn(t,j,(k,T)=>k.op==="profiles.install"?X({op:"profiles.install",name:k.name,requestId:T}):X({op:"profiles.update",name:k.name,requestId:T,fields:k.fields??{}})),l(t.name),ke(j==="proactive"?`${s} is now proactive — it may message you on its own.`:`${s} is now reactive — proactive messaging stopped.`)}catch(k){h(null);const T=k instanceof is?k.completed:[],y=Jn(k,T);a(y),Me(y),l(t.name)}finally{p(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex items-center gap-2 text-body-sm",children:[e.jsx(He,{ref:d,checked:S==="proactive","aria-disabled":v,"aria-labelledby":m,"data-testid":"agent-class-switch",className:"after:absolute after:inset-0 after:content-['']",onCheckedChange:j=>void x(j?"proactive":"reactive")}),e.jsx("span",{id:m,className:"text-ink",children:"Can message me on its own"}),e.jsx("span",{"aria-live":"polite",className:"text-ink-muted",children:v?"Switching…":S==="proactive"?"On":"Off"})]}),e.jsx("p",{className:"text-body-sm text-ink",children:Kn[S]}),e.jsx("p",{className:"text-meta text-ink-muted",children:Wn[S]}),t.source==="builtin"?e.jsx("p",{className:"text-meta text-ink-muted",children:as}):null,n?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-class-error",children:[e.jsx(de,{children:"The switch did not go through"}),e.jsx(me,{children:n})]}):null]})}function ms({tools:t,onChange:s,error:n}){const[a,l]=i.useState(""),[u,g]=i.useState(null),h=i.useId(),v=()=>{const p=a.trim();if(p){if(!ga.test(p)){g("Tool names are letters, digits, dot, underscore, dash or colon.");return}if(t?.includes(p)){g("That tool is already listed.");return}g(null),l(""),s([...t??[],p])}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:t===null,onCheckedChange:p=>s(p?null:[]),"aria-label":"Give this agent every tool"}),e.jsx("span",{children:"All tools"})]}),t===null?e.jsx("p",{className:"text-meta text-ink-muted",children:"This agent may use whatever the session offers."}):e.jsxs(e.Fragment,{children:[t.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.map(p=>e.jsx("li",{children:e.jsxs(oe,{variant:"outline",children:[p,e.jsx(E,{variant:"ghost",size:"sm","aria-label":`Remove ${p}`,onClick:()=>s(t.filter(d=>d!==p)),className:"ms-1 h-4 px-1",children:"×"})]})},p))}):e.jsx("p",{className:"text-meta text-ink-muted",children:"No tools yet. Add one below, or turn on All tools."}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(he,{label:"Add a tool",htmlFor:h,error:u??n}),e.jsx(Ne,{id:h,value:a,inputSize:"md",placeholder:"Tool name","aria-invalid":!!(u??n),onChange:p=>{l(p.target.value),g(null)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),v())}})]}),e.jsx(E,{variant:"secondary",onClick:v,disabled:!a.trim(),children:"Add"})]})]})]})}function va({profile:t,displayedName:s,classNotice:n,onClassNotice:a,teams:l,effortTiers:u,askEnabled:g,onSaved:h,onDuplicate:v,onOpenTeam:p,onAskAgent:d,onDirtyChange:m,belowHeader:S}){const[x,j]=i.useState(!1),[k,T]=i.useState(()=>pe(t)),[y,N]=i.useState(()=>pe(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),[z,te]=i.useState(!1),ne=i.useRef(null),Z=i.useRef(t.definition_revision),M=dt(),q=JSON.stringify(y)!==JSON.stringify(k);i.useEffect(()=>(m?.(x&&q),()=>m?.(!1)),[m,x,q]),i.useEffect(()=>{us()&&requestAnimationFrame(()=>ne.current?.focus())},[]),i.useEffect(()=>{if(x&&q)return;const I=pe(t);T(I),N(I)},[t,x,q]),i.useEffect(()=>{if(!x){P(!1);return}const I=pe(t);P(q&&JSON.stringify(I)!==JSON.stringify(k))},[t,x,q,k]);const se=()=>{j(!1),f(null),C(null),w(!1),te(!1);const I=pe(t);T(I),N(I),Z.current=t.definition_revision};cs(()=>{if(z){te(!1);return}q?te(!0):se()},x);const Y=async I=>{if(I?.preventDefault(),_)return;const F=pa(k,y);if(Object.keys(F).length===0){se();return}if(typeof F.instructions=="string"&&!F.instructions.trim()){f("Give the agent instructions."),C("instructions");return}$(!0),f(null),C(null);try{const V=await X({op:"profiles.update",name:t.name,requestId:crypto.randomUUID(),fields:F,expectedDefinitionRevision:Z.current});j(!1),w(!1);const G=pe(V);T(G),N(G),Z.current=V.definition_revision,h(V.name),ke(`Saved ${V.name}.`),requestAnimationFrame(()=>ne.current?.focus())}catch(V){const G=Ae(V instanceof Error?V.message:"The agent could not be saved.");f(G.message),C(G.field);const ae=V?.status;if(V?.code==="local-concurrent-edit"){P(!0),$(!1);return}const re=typeof ae=="number"&&ae!==408&&ae>=400&&ae<500;w(!re),re||Me("The save could not be confirmed. Check whether it was applied before retrying.")}finally{$(!1)}},H=async()=>{if(!_){$(!0),f(null);try{const I=await X({op:"profiles.install",name:t.name,requestId:crypto.randomUUID()}),F=pe(I);T(F),N(F),h(I.name),ke(`Installed ${I.name}. It can be edited now.`),requestAnimationFrame(()=>ne.current?.focus())}catch(I){const F=Ae(I instanceof Error?I.message:"The agent could not be installed.");f(F.message),Me(F.message)}finally{$(!1)}}},Q=(l??[]).filter(I=>I.manager===t.name||(I.members??[]).some(F=>F.role===t.name)),fe=t.source==="builtin";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:ne,tabIndex:-1,title:s,className:"truncate text-title focus:outline-none",children:s}),e.jsx(xa,{profile:t})]}),x?null:e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"agent",name:t.name}),M("/chat")},children:"New chat"}),fe?e.jsxs(E,{variant:"secondary",onClick:H,disabled:_,children:[e.jsx(gn,{className:"size-4"}),_?"Installing…":"Install to edit"]}):e.jsx(E,{variant:"secondary",onClick:()=>{j(!0),f(null),C(null),Z.current=t.definition_revision},children:"Edit"}),g?e.jsx(E,{variant:"ghost",onClick:()=>d(`Change the agent ${t.name}: `),children:"Ask for a change"}):null,e.jsxs(tn,{children:[e.jsx(sn,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon","aria-label":"More actions",className:"-mr-2",children:e.jsx(ws,{"aria-hidden":"true"})})}),e.jsx(nn,{align:"end",children:e.jsx(an,{onSelect:()=>v(t),children:"Duplicate as new agent"})})]})]})]}),fe?e.jsxs(ce,{variant:"info",children:[e.jsx(de,{children:"Built-in agent"}),e.jsx(me,{children:"This one ships with the app and cannot be edited in place. Install it to get an editable copy, or duplicate it as a new agent."})]}):null,B?e.jsxs(ce,{variant:"warning","data-testid":"agent-conflict",children:[e.jsx(de,{children:"This changed while you were editing"}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:"Something else — a configuration run, or another window — wrote to this agent after you opened it. Your edits are kept; saving writes only the fields you changed."}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:se,children:"Reload the saved version"})]})]}):null,R?e.jsxs(ce,{variant:"danger","data-testid":"agent-unconfirmed",children:[e.jsx(de,{children:"The last save was not confirmed"}),e.jsx(me,{children:"The backend did not answer, so the write may or may not have landed. Check the agent below, then edit again."})]}):null,A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),S,e.jsx("form",{noValidate:!0,onSubmit:I=>{I.preventDefault(),Y(I)},className:"space-y-8",children:x?e.jsxs(e.Fragment,{children:[e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:y.description,error:o==="description"?A:null,onChange:I=>N(F=>({...F,description:I}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:y.instructions,rows:12,required:!0,error:o==="instructions"?A:null,onChange:I=>N(F=>({...F,instructions:I}))}),e.jsx(U,{title:"Tools",children:e.jsx(ms,{tools:y.tools,error:o==="tools"?A:null,onChange:I=>N(F=>({...F,tools:I}))})}),e.jsx(U,{title:"Delegation and effort",description:"Whether this agent may hand work to subagents, and which effort tier it runs at.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:y.delegate,onCheckedChange:I=>N(F=>({...F,delegate:I})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-effort",error:o==="effort"?A:null}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,placeholder:"Choose an effort tier",busyLabel:"Loading effort tiers",options:["inherit",...u].map(I=>({id:I,name:I,description:I==="inherit"?"Use the session's own effort":void 0})),selected:{id:y.effort,name:y.effort},onSelect:I=>N(F=>({...F,effort:I.id})),helperText:"Tiers come from the backend's subagent model settings."})]})]})}),e.jsx(ht,{submit:!0,confirming:z,onConfirmingChange:te,dirty:q,pending:_,onSave:()=>void Y(),onCancel:se,saveLabel:"Save changes",dirtyHint:"Discard your unsaved changes to this agent?"})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"When to use it",children:e.jsx(ye,{text:t.description||"",empty:"No description yet — add one so a model knows when to pick this agent."})}),e.jsx(U,{title:"Instructions",children:e.jsx(ye,{text:t.instructions??t.packaged_instructions??"",empty:"No instructions yet."})}),e.jsx(U,{title:"Tools",children:t.tools&&t.tools.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.tools.map(I=>e.jsx("li",{children:e.jsx(oe,{variant:"outline",children:I})},I))}):e.jsx(oe,{variant:"neutral",children:"All tools"})}),e.jsxs(U,{title:"Delegation and effort",children:[e.jsx("p",{className:"text-body-sm text-ink",children:t.delegate?"May hand work to subagents.":"Does its own work; it does not delegate."}),e.jsxs("p",{className:"text-body-sm text-ink-muted",children:["Effort tier: ",t.effort??"inherit"]}),t.effort&&Q.length?e.jsx("p",{className:"text-body-sm text-ink-muted",children:r("ui.agents.models.pin_reach",{count:Q.length,teams:Q.map(I=>I.name).join(", ")})}):null]}),e.jsx(U,{title:"Messaging",description:"Reactive agents only reply. Proactive agents may also message you first.",children:e.jsx(ja,{profile:t,displayedName:s,notice:n,onNotice:a,onChanged:h})}),e.jsx(U,{title:"Used by",description:"Teams that name this agent as a manager or a member.",children:Q.length>0?e.jsx("ul",{className:"flex flex-wrap gap-x-3 gap-y-1",children:Q.map(I=>e.jsx("li",{children:e.jsx(E,{variant:"link",className:K("-my-0.5",ut),onClick:()=>p(I.name),children:I.name})},I.id))}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:"No team uses it yet."})}),e.jsxs(U,{title:"Where it came from",description:t.source==="builtin"?"Shipped with the app.":t.source==="installed"?"Installed from a packaged starter.":"Created on this machine.",children:[e.jsxs("dl",{className:"space-y-1 text-body-sm",children:[t.seed_origin?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Source"}),e.jsx("dd",{className:"text-ink",children:t.seed_origin})]}):null,t.divergent_fields?.length?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Changed from the packaged copy"}),e.jsx("dd",{className:"text-ink",children:t.divergent_fields.join(", ")})]}):null]}),t.packaged_instructions&&t.divergent_fields?.length?e.jsx(rt,{summary:"Compare with the packaged instructions",className:"mt-2",children:e.jsx(ye,{text:t.packaged_instructions,mono:!0})}):null]})]})})]})}function qe({title:t,description:s,label:n,value:a,onChange:l,rows:u,required:g,error:h,fieldRef:v}){const p=i.useId();return e.jsxs(U,{title:t,description:s,children:[e.jsx(he,{label:n,htmlFor:p,error:h}),u?e.jsx(st,{id:p,ref:v,value:a,rows:u,required:g,"aria-invalid":!!h,className:K("min-h-0"),onChange:d=>l(d.target.value)}):e.jsx(Ne,{id:p,value:a,"aria-invalid":!!h,onChange:d=>l(d.target.value)})]})}function ya({initial:t,takenNames:s,effortTiers:n,onDirtyChange:a,onSaved:l,onCancel:u}){const[g,h]=i.useState(()=>t?Hn(t.name,s):""),[v,p]=i.useState(t?.kind??"role"),[d,m]=i.useState(()=>t?{...pe(t),description:t.description??""}:{description:"",instructions:"",tools:null,effort:"inherit",delegate:!1}),[S,x]=i.useState(!1),[j,k]=i.useState(null),[T,y]=i.useState(null),N=i.useRef(null),_=i.useRef(null);i.useEffect(()=>(a?.(!!(g.trim()||d.instructions.trim())),()=>a?.(!1)),[a,g,d.instructions]),i.useEffect(()=>{N.current?.focus(),N.current?.select()},[]);const $=async f=>{if(f?.preventDefault(),!S){if(!g.trim()){k("Give the agent a name."),y("name"),N.current?.focus();return}if(/[\\/\s]/.test(g.trim())){k("Names cannot contain spaces or slashes."),y("name"),N.current?.focus();return}if(s.includes(g.trim())){k(`An agent called “${g.trim()}” already exists. Choose another name, or open the existing one to change it.`),y("name"),N.current?.focus();return}if(!d.instructions.trim()){k("Give the agent instructions."),y("instructions"),_.current?.focus();return}x(!0),k(null),y(null);try{const o=await X({op:"profiles.create",requestId:crypto.randomUUID(),name:g.trim(),fields:{kind:v,description:d.description,instructions:d.instructions,tools:d.tools??[],effort:d.effort,delegate:d.delegate}});ke(`Created ${o.name}.`),ds(),l(o.name)}catch(o){const C=Ae(o instanceof Error?o.message:"The agent could not be created.");k(C.message),y(C.field)}finally{x(!1)}}},A=t?"Duplicate as a new agent":"New agent";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("h2",{className:"text-title",children:A}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:t?`A copy of ${t.name}. It is a separate agent: changing it does not change the original.`:"Reusable instructions shared by agent commands, subagents and teams. Chats stay separate."})]}),j&&!T?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-create-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:j})]}):null,e.jsxs("form",{noValidate:!0,onSubmit:f=>{f.preventDefault(),$(f)},className:"space-y-8",children:[e.jsx(U,{title:"Name and role",children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Name",htmlFor:"agent-create-name",error:T==="name"?j:null}),e.jsx(Ne,{id:"agent-create-name",ref:N,value:g,required:!0,"aria-invalid":T==="name",onChange:f=>h(f.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"How it works with others",htmlFor:"agent-create-kind"}),e.jsxs($e,{value:v,onValueChange:f=>p(f),children:[e.jsx(Le,{id:"agent-create-kind",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"role",children:"You can chat with it directly"}),e.jsx(xe,{value:"specialist",children:"Other agents can call on it"})]})]})]})]})}),e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:d.description,error:T==="description"?j:null,onChange:f=>m(o=>({...o,description:f}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:d.instructions,rows:12,required:!0,fieldRef:_,error:T==="instructions"?j:null,onChange:f=>m(o=>({...o,instructions:f}))}),e.jsx(U,{title:"Delegation and effort",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:d.delegate,onCheckedChange:f=>m(o=>({...o,delegate:f})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-create-effort"}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,busyLabel:"Loading effort tiers",placeholder:"Choose an effort tier",options:["inherit",...n].map(f=>({id:f,name:f,description:f==="inherit"?"Use the session's own effort":"A tier configured in Settings"})),selected:{id:d.effort,name:d.effort},onSelect:f=>m(o=>({...o,effort:f.id}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:"Tools"}),e.jsx(ms,{tools:d.tools,error:T==="tools"?j:null,onChange:f=>m(o=>({...o,tools:f}))})]})]})}),e.jsx(ht,{submit:!0,dirty:!!(g.trim()||d.instructions),pending:S,saveLabel:t?"Create the copy":"Create agent",pendingLabel:"Creating…",dirtyHint:"Discard this new agent?",onSave:()=>void $(),onCancel:u})]})]})}function hs(t,s,n=Date.now()){const a=Date.parse(t.expires_at);return t.local_fingerprint.length>0&&t.proposal_fingerprint.length>0&&t.link_id===s.link_id&&(t.direction==="push"||t.remote_fingerprint.length>0)&&t.proposal.kind===s.kind&&t.hub_source===s.hub_source&&t.visibility===s.visibility&&t.tenant_id===s.tenant_id&&t.expected_policy_revision===s.policy.revision&&t.expected_remote_revision===s.remote_revision&&Number.isFinite(a)&&a>n}function Et(t,s,n=Date.now()){return t.can_confirm&&t.preview_receipt.length>0&&hs(t,s,n)}const Ze=t=>Number.isFinite(Date.parse(t))?Ss(new Date(t)):r("ui.hub.status.unknown"),ka=t=>[t.pull.state,t.push.state].some(s=>["checking","merging","applying","pushing"].includes(s));function Na({link:t}){Te();const s=Ps(t.link_id),n=lt(t),a=Bs(t),[l,u]=i.useState(null),[g,h]=i.useState(null),[v,p]=i.useState(null),[d,m]=i.useState(!1),[S,x]=i.useState(!1),j=i.useRef(null),k=i.useId(),T=s.isPending||ka(t),y=!xt(t.baseline_state),N=l??g;i.useEffect(()=>{N&&!hs(N,t)&&(u(null),h(null),x(!0))},[t,N]),i.useEffect(()=>{if(!N)return;const f=Date.parse(N.expires_at)-Date.now(),o=setTimeout(()=>{u(null),h(null),x(!0)},Math.max(0,Math.min(f,2147483647)));return()=>clearTimeout(o)},[N]);const _=f=>{T||(f.action==="preview"&&x(!1),s.mutate(f,{onSuccess:o=>{if(f.action==="preview")u(o.preview?.direction==="push"?o.preview:null);else if(f.action==="apply"&&f.preview){const C=o.preview?.direction==="pull"?o.preview:null;h(C),p(JSON.stringify(o.reports,null,2)),m(C?.choices.acknowledge_unknown_baseline??!1)}else u(null),h(null)},onError:o=>{o instanceof Be&&["publication-preview-changed","application-preview-changed","remote-revision-changed"].includes(o.code??"")&&(u(null),h(null),x(!0))}}))},$=()=>{s.isPending||(u(null),h(null))},A=f=>r(f==="pull"?"ui.hub.links.direction_pull":"ui.hub.links.direction_push");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-4 py-4","data-hub-link":t.link_id,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"break-words text-heading text-ink",children:n}),e.jsx("p",{className:"break-words text-meta text-ink-muted",children:t.name}),e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.links.source_address",{address:t.hub_source})})]}),e.jsx(Kt,{link:t}),e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:["pull","push"].map(f=>{const o=t[f];return e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1","data-hub-direction":f,children:[e.jsx("h4",{className:"text-body-sm text-ink",children:A(f)}),e.jsx("p",{className:K("text-body-sm",o.state==="failed"?"text-danger":o.state==="available"?"text-accent":"text-ink-muted"),children:Us(o)}),o.error_class&&e.jsx("p",{className:"text-meta text-warning",children:et(o.error_class)}),o.last_checked_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.last_checked",{time:Ze(o.last_checked_at)})}),o.last_success_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.last_success",{time:Ze(o.last_success_at)})}),o.next_retry_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.next_retry",{time:Ze(o.next_retry_at)})}),o.model_used&&e.jsx("p",{className:"break-words text-meta text-ink-muted",children:r("ui.hub.links.actual_model",{model:o.model_used})}),o.operation_id&&e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.status.receipt",{operation:o.operation_id})}),a[f].retryable&&(f==="pull"||t.policy.auto_push)&&e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"retry",linkId:t.link_id,direction:f}),children:r("ui.hub.links.retry")})]},f)})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"check",linkId:t.link_id}),children:r("ui.hub.subscriptions.check")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0}),children:r("ui.hub.links.preview_pull")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite||!t.remote_revision||!xt(t.baseline_state)||t.visibility==="org"&&!t.tenant_name,onClick:()=>_({action:"preview",linkId:t.link_id}),children:r("ui.hub.subscriptions.preview_publish")})]}),S&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.preview_changed")}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(s.variables?.action==="preview"||s.variables?.action==="confirm"?"push":"pull"),item:t.name,source:n})}),s.data?.reports.filter(f=>f.link_id===t.link_id).map((f,o)=>e.jsx("output",{className:"text-meta text-ink-muted",children:r("ui.hub.links.action_result",{direction:A(f.direction),item:t.name,source:n,outcome:f.outcome})},`${f.operation_id??f.direction}-${o}`)),e.jsx(Jt,{open:l!==null||g!==null,onOpenChange:f=>{f||$()},children:e.jsxs(Yt,{className:"max-w-3xl",closeDisabled:s.isPending,onOpenAutoFocus:f=>{f.preventDefault(),j.current?.focus()},onEscapeKeyDown:f=>{s.isPending&&f.preventDefault()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:l?r("ui.hub.links.preview_payload",{source:n}):r("ui.hub.links.preview_pull")}),e.jsx(Xt,{children:l||!y?r("ui.hub.subscriptions.enable_safety"):r("ui.hub.links.unknown_baseline")})]}),e.jsx("pre",{className:"max-h-[50vh] overflow-auto whitespace-pre-wrap break-words rounded-md bg-sunken p-3 text-mono-sm text-ink",children:JSON.stringify(N?.proposal,null,2)}),N?.warnings.length?e.jsxs("div",{children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.preview_warnings")}),N.warnings.map((f,o)=>e.jsx("p",{className:"break-words text-body-sm text-warning",children:f},`${o}-${f}`))]}):null,N?.reason&&e.jsx("p",{className:"text-body-sm text-warning",children:et(N.reason)}),g&&v&&e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words bg-sunken p-3 text-mono-sm text-ink",children:v}),g&&y&&e.jsxs("label",{htmlFor:k,className:"flex items-start gap-2 text-body-sm text-ink",children:[e.jsx(rn,{id:k,checked:d,onCheckedChange:f=>m(f===!0)}),r("ui.hub.links.acknowledge_baseline")]}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(l?"push":"pull"),item:t.name,source:n})}),e.jsxs(es,{children:[e.jsx(E,{ref:j,variant:"outline",disabled:s.isPending,onClick:$,children:r("ui.hub.subscriptions.cancel")}),l?e.jsx(E,{disabled:s.isPending||!s.canWrite||!Et(l,t),onClick:()=>_({action:"confirm",linkId:t.link_id,previewReceipt:l.preview_receipt}),children:r("ui.hub.links.confirm_publish")}):e.jsxs(e.Fragment,{children:[["local","remote"].map(f=>e.jsx(E,{variant:"outline",disabled:s.isPending||!s.canWrite||y&&!d,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0,prefer:f,acknowledgeUnknownBaseline:y&&d}),children:r(f==="local"?"ui.hub.links.prefer_local":"ui.hub.links.prefer_remote")},f)),e.jsx(E,{disabled:s.isPending||!s.canWrite||!g||!Et(g,t)||g.choices.acknowledge_unknown_baseline!==d||g.choices.replace!==null||g.choices.confirm_replace,onClick:()=>{g&&_({action:"apply",linkId:t.link_id,previewReceipt:g.preview_receipt,confirmApply:!0,prefer:g.choices.prefer??void 0,acknowledgeUnknownBaseline:g.choices.acknowledge_unknown_baseline})},children:r("ui.hub.subscriptions.pull")})]})]})]})})]})}function wa({row:t,source:s,organizations:n,isAuthenticated:a,onSignIn:l,initialOpen:u,onResolved:g}){Te();const[h,v]=i.useState(u??!1),[p,d]=i.useState(""),m=Ms(g),S=i.useRef(null),x=i.useRef(null),j=i.useRef(!1);i.useEffect(()=>{h?S.current?.focus():j.current&&(j.current=!1,x.current?.focus())},[h]);const k=p!=="public"&&p!=="",T=k?n.find(_=>_.tenant_id===p):null,N=p!==""&&(!k||!!T)&&(k||p==="public");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-3","data-hub-source-unresolved":t.local_id,children:[e.jsx(ce,{variant:"warning",className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[m.upgradeMessage&&e.jsx("output",{className:"block text-meta text-warning","data-hub-core-upgrade":!0,children:m.upgradeMessage}),e.jsx(de,{"data-hub-unresolved-label":!0,children:r("ui.hub.links.source_not_confirmed")}),e.jsx("h3",{className:"break-words text-body-sm font-medium text-ink",children:t.name}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_what",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_why",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_next")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.source_address",{address:s})}),e.jsx("p",{className:"break-all text-mono-sm text-ink-muted",children:r("ui.hub.links.hub_id",{address:t.hub_id})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_irreversible")}),h?null:e.jsx(E,{ref:x,variant:"primary",size:"sm",className:"self-start",onClick:()=>v(!0),children:r("ui.hub.links.resolve_action")})]})}),h?e.jsxs("div",{ref:S,tabIndex:-1,className:"flex flex-col gap-2 outline-none",children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.resolve_title")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_description",{item:t.name})}),a?e.jsxs("label",{className:"text-body-sm text-ink",children:[r("ui.hub.links.scope_label"),e.jsxs("select",{className:"mt-1 w-full rounded-md border border-control bg-surface px-2 py-1 text-body-sm text-ink",value:p,disabled:m.isPending,onChange:_=>d(_.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("ui.hub.links.scope_placeholder")}),e.jsx("option",{value:"public",children:r("ui.hub.links.scope_public")}),n.map(_=>e.jsx("option",{value:_.tenant_id,children:r("ui.hub.links.scope_private",{organization:_.tenant_name})},_.tenant_id))]})]}):e.jsx(E,{variant:"outline",onClick:l,children:r("ui.hub.links.sign_in_to_publish")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",disabled:m.isPending,onClick:()=>{j.current=!0,v(!1)},children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:m.isPending||!m.canWrite||!N,onClick:()=>m.mutate({kind:t.kind,localId:t.local_id,name:t.name,hubSource:s,visibility:k?"org":"public",tenantId:k?T?.tenant_id??null:null}),children:m.isPending?r("ui.hub.links.resolve_action_confirming"):m.isSuccess?r("ui.hub.links.resolve_action_done"):r("ui.hub.links.resolve_action_confirm")})]}),!N&&!m.isPending&&a?e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.scope_required")}):null,m.error?e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:m.error instanceof tt?m.error.message:m.error instanceof Be&&m.error.code==="origin-conflict"?r("ui.hub.links.resolve_conflict"):m.error instanceof Be&&m.error.code?et(m.error.code):r("ui.hub.links.resolve_failed_generic")}):null]}):null]})}function _a({enabled:t,kind:s,name:n,localId:a}){Te();const l=zt(t),{isAuthenticated:u}=Bt(),g=dt(),[h]=Ut(),v=h.get("resolve"),p=v!==null,{memberships:d}=Ht({enabled:t&&u}),m=ts(d).map(w=>({tenant_id:w.tenant_id,tenant_name:w.tenant_name})),S=_s.radientBaseUrl;if(!t)return null;const x=s&&n?Fs(l.data,s,a,n):l.data?.links.filter(w=>!s||w.kind===s)??[],j=(l.data?.unresolved??[]).filter(w=>(!s||w.kind===s)&&(!n||(a?w.local_id===a:w.name===n))),k=w=>r(w?"ui.hub.subscriptions.configured_on":"ui.hub.subscriptions.configured_off"),T=w=>{const B=x[0]?w(x[0]):!1;return x.every(P=>w(P)===B)},y=w=>T(w)?k(w(x[0])):r("ui.hub.links.mixed"),N=(()=>{if(x.length===0)return"";const w=x[0],B=x.length>1?` · ${r("ui.hub.links.sources_count",{count:x.length})}`:"";return`${lt(w)}${B} · ${r("ui.hub.subscriptions.subscribe")} ${y(P=>P.policy.subscribe)} · ${r("ui.hub.subscriptions.auto_push")} ${y(P=>P.policy.auto_push)}`})(),_=x.some(w=>[w.pull.state,w.push.state].some(B=>B==="available"||B==="failed")),$=i.useRef(null),[A,f]=i.useState(!1);i.useEffect(()=>{!A||x.length===0||($.current?.querySelector("button[aria-expanded]")?.focus(),f(!1))},[A,x]);const[o,C]=i.useState(_),R=i.useRef(_);return i.useEffect(()=>{_&&!R.current&&C(!0),R.current=_},[_]),l.isLoading?null:l.error&&!l.data?e.jsxs("div",{className:"flex flex-col items-start gap-2",children:[e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.load_failed")}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>void l.refetch(),children:r("ui.hub.links.retry")})]}):x.length===0&&j.length===0?null:e.jsxs("div",{ref:$,className:"flex min-w-0 flex-col gap-3","data-hub-links-panel":!0,children:[j.map(w=>e.jsx(wa,{row:w,source:S,organizations:m,isAuthenticated:u,onSignIn:()=>g("/settings"),initialOpen:p,onResolved:()=>f(!0)},`${w.kind}:${w.local_id}:${v}`)),x.length>0?e.jsxs(rt,{open:o,onOpenChange:C,summary:`${r("ui.hub.links.title")} · ${N}`,className:"min-w-0",children:[e.jsx("div",{className:"divide-y divide-hairline",children:x.map(w=>e.jsx(Na,{link:w},w.link_id))}),l.error&&l.data&&e.jsx("p",{role:"alert",className:"text-meta text-warning",children:r("ui.hub.links.load_failed")})]}):null]})}const Sa=["lo","med","hi"],Ca=["auto","none","minimal","low","medium","high","xhigh","max"],Re="inherit";function It(t){return t??Re}function Ea(t){return t===Re?null:t}function Ia(t){return t===Re?null:t}function Aa(t,s){return{...t,...s.tier===void 0?{}:{tier:Ea(s.tier)},...s.effort===void 0?{}:{effort:Ia(s.effort)}}}function at(t){const{tier:s,effort:n,key:a,...l}=t;return JSON.stringify({...l,...s?{tier:s}:{},...n?{effort:n}:{}})}function Ra(t,s){const n=`${s.kind}\0${s.role.toLocaleLowerCase()}`;return(t?.members??[]).find(a=>`${a.kind}\0${a.role.toLocaleLowerCase()}`===n)??null}const Ta={team:"ui.agents.models.source.team",row:"ui.agents.models.source.row",none:"ui.agents.models.source.none"},Da={team:"ui.agents.models.source.team",tier:"ui.agents.models.source.tier",model_default:"ui.agents.models.source.model_default"},fs=t=>Ta[t],$a=t=>Da[t];function La(t){return t.isSuccess?"available":t.isError&&Oa(t.error)?"unavailable":"absent"}function Oa(t){return Ys(t)!=="outdated"}function Fa({team:t}){Te();const s=i.useId(),n=ze(),{isAuthenticated:a}=Bt(),l=ee(n.data,"hub_links"),[u,g]=i.useState(!1),[h,v]=i.useState(null),[p,d]=i.useState(Je),m=i.useRef(null),S=i.useRef(null),x=zt(l),j=Ht({enabled:u&&a&&ee(n.data,"radient_org")}),k=ts(j.memberships),T=h?k.find(R=>R.tenant_id===h):null,y=h?T?.tenant_name?r("ui.hub.links.source_private",{organization:T.tenant_name}):r("ui.hub.links.source_unavailable"):r("ui.hub.links.source_public"),N=(x.data?.links??[]).filter(R=>R.kind==="team"&&R.local_id===t.id),_=N.find(R=>R.visibility===(h?"org":"public")&&R.tenant_id===h),$=N.find(R=>R.link_id!==_?.link_id),A=x.data?.unresolved.some(R=>R.kind==="team"&&R.local_id===t.id),f=ct(),o=Cs({mutationFn:async()=>{if(!a||_||!l||!x.isSuccess||$||A||h&&!T)throw new Error("hub-team-destination-not-ready");const R=JSON.stringify({id:t.id,target:h,policy:_?null:p}),w=m.current?.tuple===R?m.current:{tuple:R,id:crypto.randomUUID()};return m.current=w,X({op:"team.publish",teamId:t.id,requestId:w.id,...h?{visibility:"org",tenantId:h}:{},..._?{}:p})},onSuccess:()=>{f.invalidateQueries({queryKey:qs})}});if(!l||!u&&(N.length>0||A))return null;const C=!a||!x.isSuccess||!!_||!!$||!!A||!!h&&!T;return e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"outline",disabled:!a||!x.isSuccess,onClick:()=>{g(!0),v(null),d(Je()),m.current=null,o.reset()},children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Jt,{open:u,onOpenChange:R=>{o.isPending||g(R)},children:e.jsxs(Yt,{onOpenAutoFocus:R=>{R.preventDefault(),S.current?.focus()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Xt,{children:r("ui.hub.skills.initial_policy_description")})]}),e.jsx("label",{htmlFor:`${s}-target`,className:"text-body-sm text-ink",children:y}),e.jsxs("select",{id:`${s}-target`,disabled:o.isPending||o.isSuccess,value:h??"",className:"rounded-md border border-control bg-surface px-3 py-2 text-body-sm text-ink",onChange:R=>{v(R.target.value||null),d(Je()),m.current=null},children:[e.jsx("option",{value:"",children:r("ui.hub.links.source_public")}),k.map(R=>e.jsx("option",{value:R.tenant_id,children:R.tenant_name},R.tenant_id))]}),$?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.subscriptions.source_separation",{currentSource:lt($),newSource:y})}):A?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.links.source_unavailable")}):_?e.jsx(Kt,{link:_}):e.jsx(un,{value:p,onChange:d,source:y,item:t.name,visibility:h?"org":"public",organization:T?.tenant_name??null,destinationKey:`${t.id}:${h??"public"}`,canEnableAutoPush:!1,disabled:C||o.isPending||o.isSuccess}),x.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.load_failed")}),o.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.action_failed",{direction:r("ui.hub.links.direction_push"),item:t.name,source:y})}),o.isSuccess&&e.jsx("output",{className:"text-body-sm text-ink",children:mn(o.data)?r("ui.hub.links.published",{item:t.name,source:y}):r("ui.hub.skills.policy_pending")}),e.jsxs(es,{children:[e.jsx(E,{ref:S,variant:"outline",disabled:o.isPending,onClick:()=>g(!1),children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:C||o.isPending||o.isSuccess,onClick:()=>o.mutate(),children:r("ui.hub.links.confirm_publish")})]})]})})]})}function Ce(t){return{description:t?.description??"",manager:t?.manager??"manager",members:(t?.members??[]).map(s=>({...s,count:ft(s),key:crypto.randomUUID()})),instructions:t?.instructions??"",project:t?.project??""}}function Ma(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.manager!==t.manager&&(n.manager=s.manager),JSON.stringify(s.members.map(at))!==JSON.stringify(t.members.map(at))&&(n.members=s.members.map(({key:a,...l})=>l)),s.instructions!==t.instructions&&(n.instructions=s.instructions),s.project!==t.project&&(n.project=s.project),n}function At(t,s,n){return(t.kind==="agent"?(s??[]).map(l=>l.name):(n??[]).map(l=>l.name)).includes(t.role)}function Pa(t){return(t??[]).reduce((s,n)=>s+ft(n),0)}function ft(t){return t.count||1}function gs(t){const s=Pa(t);return s===1?"1 member":`${s} members`}function Rt(t){const s=t.tier.value?r("ui.agents.models.reading.tier_layer",{tier:t.tier.value,source:r(fs(t.tier.source))}):null;return t.model.value?{value:t.model.value,layer:s}:t.available?{value:r("ui.agents.models.reading.session_model"),layer:s}:{value:r("ui.agents.models.reading.not_resolved"),layer:s}}function Tt(t){const{requested:s,value:n,source:a}=t.effort,l=r($a(a));return s==="auto"?{value:r("ui.agents.models.reading.effort_auto"),layer:r("ui.agents.models.source.model_default")}:n&&s&&n!==s?{value:r("ui.agents.models.reading.effort_clamped",{requested:s,value:n}),layer:l}:n?{value:n,layer:l}:{value:r("ui.agents.models.reading.effort_default"),layer:a==="model_default"?null:l}}function Ba(t){return t.tier.value?r(fs(t.tier.source)):null}function Dt(t,s,n){return t.layer?r(n,{value:t.value,layer:t.layer}):r(s,{value:t.value})}function $t(t){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",title:t.value,children:t.value}),t.layer?e.jsx("span",{className:"block truncate text-meta text-ink-dim",title:t.layer,children:t.layer}):null]})}function Lt(t){return JSON.stringify({...t,members:t.members.map(at)})}function Ot(){return e.jsxs("colgroup",{children:[e.jsx("col",{}),e.jsx("col",{className:"w-24"}),e.jsx("col",{className:"w-16"})]})}function Ft({team:t,agents:s,teams:n,askEnabled:a,onSaved:l,onCancelCreate:u,onOpenAgent:g,onAskAgent:h,onDirtyChange:v,belowHeader:p}){const d=!t,[m,S]=i.useState(d),[x,j]=i.useState(t?.name??""),[k,T]=i.useState(()=>Ce(t)),[y,N]=i.useState(()=>Ce(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),z=i.useRef(t?.definition_revision),te=i.useRef(null),ne=i.useRef(null),Z=i.useRef(null),M=i.useRef(null),q=i.useRef(!1);i.useEffect(()=>{us()&&requestAnimationFrame(()=>te.current?.focus())},[]);const se=dt();Te();const W=ct(),Y=t?.name??n?.[0]?.name??null,H=Es(Y,!!Y),Q=La(H),fe=Q==="available",I=H.data&&H.data.team===t?.name?H.data:null,F=d?!!(x.trim()||y.description||y.members.length):Lt(y)!==Lt(k);i.useEffect(()=>(v?.((d||m)&&F),()=>v?.(!1)),[v,d,m,F]),i.useEffect(()=>{if(m&&F)return;const b=Ce(t);T(b),N(b)},[t,m,F]),i.useEffect(()=>{if(!q.current)return;q.current=!1;const b=M.current;typeof b?.scrollIntoView=="function"&&b.scrollIntoView({block:"nearest"})});const V=()=>{if(d){u?.();return}S(!1),f(null),C(null),w(!1),z.current=t?.definition_revision;const b=Ce(t);T(b),N(b)};cs(()=>{if(R){w(!1);return}F?w(!0):V()},m);const ae=async b=>{if(b?.preventDefault(),!_){if(d&&!x.trim()){f("Give the team a name."),C("name"),Z.current?.focus();return}if(d&&/[\\/\s]/.test(x.trim())){f("Names cannot contain spaces or slashes."),C("name"),Z.current?.focus();return}if(d&&(n??[]).some(c=>c.name===x.trim())){f(`A team called “${x.trim()}” already exists. Open it to change it, or choose another name.`),C("name"),Z.current?.focus();return}if(d&&!y.instructions.trim()){f("Give the team instructions."),C("instructions"),ne.current?.focus();return}$(!0),f(null),C(null);try{const c=t?await X({op:"teams.update",name:t.name,requestId:crypto.randomUUID(),fields:Ma(k,y),expectedDefinitionRevision:z.current}):await X({op:"teams.create",requestId:crypto.randomUUID(),fields:{name:x,description:y.description,manager:y.manager,members:y.members.map(({key:L,...O})=>O),instructions:y.instructions,project:y.project}}),D=Ce(c);T(D),N(D),P(!1),z.current=c.definition_revision,S(!1),l(c.name),H.refetch(),W.invalidateQueries({queryKey:["desktop","team"]}),ke(`${d?"Created":"Saved"} ${c.name}.`),d&&ds(),requestAnimationFrame(()=>te.current?.focus())}catch(c){if(c?.code==="local-concurrent-edit"){P(!0),f(null),C(null);return}const L=Ae(c instanceof Error?c.message:"The team could not be saved.");f(L.message),C(L.field),Me(L.message)}finally{$(!1)}}},ie=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?{...L,...c}:L)})),re=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?Aa(L,c):L)})),_e=y.members.length?y.members:t?.members,ge=t?qt(t):"New team",Se=y.members.some(b=>b.kind==="team");return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:te,tabIndex:-1,title:ge,className:"truncate text-title focus:outline-none",children:ge}),t?e.jsxs("p",{className:"text-body-sm text-ink-muted",children:[gs(_e),Se?" · Includes a team":""]}):null]}),t&&!m?e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs,a&&"-mr-3"),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"team",name:t.name}),se("/chat")},children:"New team chat"}),e.jsx(Fa,{team:t}),e.jsx(E,{variant:"secondary",onClick:()=>{z.current=t.definition_revision,S(!0)},children:"Edit"}),a?e.jsx(E,{variant:"ghost",onClick:()=>h(`Change the team ${t.name}: `),children:"Ask for a change"}):null]}):null]}),A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"team-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),p,m&&B?e.jsxs(ce,{variant:"warning","data-testid":"team-conflict",children:[e.jsx(de,{children:r("ui.hub.conflict.title")}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:r("ui.hub.conflict.body")}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:V,children:r("ui.hub.conflict.reload")})]})]}):null,e.jsx("form",{noValidate:!0,onSubmit:b=>{b.preventDefault(),ae(b)},className:"space-y-8",children:d||m?e.jsxs(e.Fragment,{children:[d?e.jsxs(U,{title:"Name",description:"How you and your chats will refer to this team.",children:[e.jsx(he,{label:"Team name",htmlFor:"team-name",error:o==="name"?A:null}),e.jsx(Ne,{ref:Z,id:"team-name","data-testid":"team-name-input",value:x,required:!0,maxLength:64,autoFocus:!0,"aria-invalid":o==="name",onChange:b=>j(b.target.value)})]}):null,e.jsx(U,{title:"Manager",description:"The agent that leads the chat and decides who works on what.",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{label:"Manager agent",htmlFor:"team-manager",error:o==="manager"?A:null}),e.jsx(Ue,{ariaLabel:"Manager agent",showLabel:!1,placeholder:"Choose a manager",busyLabel:"Loading agents",options:je(s,n),selected:je(s,n).find(b=>b.id===y.manager)??null,onSelect:b=>N(c=>({...c,manager:b.id})),onCustomSubmit:b=>N(c=>({...c,manager:b})),listNotice:"Agents and teams on this machine"}),je(s,n).some(b=>b.id===y.manager)?null:e.jsxs(oe,{variant:"warning","data-testid":"team-manager-missing",children:["Not found: ",y.manager]})]})}),e.jsxs(U,{title:"Members",description:"Who the manager can delegate to, how many of each, and the model each runs on.",children:[e.jsx("p",{"data-testid":"team-override-scope",className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),d&&!Y?e.jsx("p",{"data-testid":"team-override-no-probe",className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.no_probe_hint")}):null,Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null,e.jsxs("div",{className:"space-y-4",children:[y.members.map((b,c)=>{const D=!At(b,s,n),L=Ra(I??void 0,b);return e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_8rem_auto_auto] items-center gap-x-2 gap-y-1",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(Ue,{ariaLabel:`Member ${c+1}`,showLabel:!1,placeholder:"Choose an agent or team",busyLabel:"Loading agents",options:[...je(s,n).filter(O=>b.kind==="team"?O.group==="Teams":O.group==="Agents")],selected:je(s,n).find(O=>O.id===b.role)??null,onSelect:O=>ie(c,{role:O.id,kind:O.group==="Teams"?"team":"agent"}),onCustomSubmit:O=>ie(c,{role:O})})}),e.jsxs($e,{value:b.kind,onValueChange:O=>ie(c,{kind:O}),children:[e.jsx(Le,{"aria-label":`Member ${c+1} kind`,className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"agent",children:"Agent"}),e.jsx(xe,{value:"team",children:"Team"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One fewer ${b.role}`,disabled:b.count<=1,onClick:()=>ie(c,{count:b.count-1}),children:e.jsx(ln,{"aria-hidden":"true"})}),e.jsx("span",{className:"min-w-6 text-center text-body-sm tabular-nums","aria-label":`${b.count} of ${b.role}`,children:b.count}),e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One more ${b.role}`,disabled:b.count>=16,onClick:()=>ie(c,{count:b.count+1}),children:e.jsx(Wt,{"aria-hidden":"true"})})]}),e.jsx(E,{variant:"ghost",onClick:()=>N(O=>({...O,members:O.members.filter((Ga,ps)=>ps!==c)})),children:"Remove"}),D?e.jsxs(oe,{variant:"warning",className:"col-span-full w-fit",children:["Not found: ",b.role]}):null,fe?e.jsxs("div",{className:"col-span-full grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] items-end gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.tier_field")}),e.jsxs($e,{value:It(b.tier),onValueChange:O=>re(c,{tier:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.tier_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_tier")}),Sa.map(O=>e.jsx(xe,{value:O,children:O},O))]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.effort_field")}),e.jsxs($e,{value:It(b.effort),onValueChange:O=>re(c,{effort:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.effort_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_effort")}),Ca.map(O=>e.jsx(xe,{value:O,children:O==="auto"?r("ui.agents.models.override.auto"):O},O))]})]})]})]}):null,L?e.jsxs("div",{className:"col-span-full flex flex-wrap items-baseline gap-x-3 gap-y-1 text-meta",children:[e.jsx("span",{className:"text-ink-dim",children:r("ui.agents.models.reading.saved_label")}),e.jsx("span",{className:"text-ink-muted",children:Dt({value:Rt(L).value,layer:Ba(L)},"ui.agents.models.reading.model_cell","ui.agents.models.reading.model_cell_layer")}),e.jsx("span",{className:"text-ink-muted",children:Dt(Tt(L),"ui.agents.models.reading.effort_cell","ui.agents.models.reading.effort_cell_layer")})]}):null,L&&!L.available?e.jsxs("div",{className:"col-span-full",children:[e.jsx("p",{"data-testid":"team-member-unavailable",className:"text-meta text-danger",children:r("ui.agents.models.reading.unavailable_editor",{member:L.role||`Member ${c+1}`,reason:L.reason})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]}):null]},b.key)}),e.jsx(E,{ref:M,variant:"secondary",onClick:()=>{q.current=!0,N(b=>({...b,members:[...b.members,{role:"",count:1,kind:"agent",key:crypto.randomUUID()}]}))},children:"Add member"})]})]}),e.jsxs(U,{title:"Description",children:[e.jsx(he,{label:"What this team is for",htmlFor:"team-description",error:o==="description"?A:null}),e.jsx(Ne,{id:"team-description",value:y.description,onChange:b=>N(c=>({...c,description:b.target.value}))})]}),e.jsxs(U,{title:"Collaboration instructions",children:[o==="instructions"?e.jsx("p",{className:"text-meta text-danger",role:"alert","data-testid":"team-instructions-error",children:A}):null,e.jsx(st,{ref:ne,"aria-label":"Collaboration instructions","aria-invalid":o==="instructions",className:"min-h-36",maxLength:8e3,value:y.instructions,onChange:b=>N(c=>({...c,instructions:b.target.value}))})]}),e.jsx(U,{title:"Project brief",children:e.jsx(st,{"aria-label":"Project brief",className:"min-h-36",maxLength:8e3,value:y.project,onChange:b=>N(c=>({...c,project:b.target.value}))})}),e.jsx(ht,{submit:!0,confirming:R,onConfirmingChange:w,dirty:F,pending:_,saveLabel:d?"Create team":"Save changes",pendingLabel:d?"Creating…":"Saving…",dirtyHint:"Discard this team?",onSave:()=>void ae(),onCancel:V})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Manager",children:e.jsxs(We,{className:"table-fixed","aria-label":"Manager: the agent that leads the chat",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:e.jsxs(be,{className:"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(E,{variant:"link",className:K("-my-0.5 min-w-0 justify-start truncate",ut),onClick:()=>g(y.manager),children:y.manager}),je(s,n).some(b=>b.id===y.manager)?null:e.jsx(oe,{variant:"warning","data-testid":"team-manager-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:"Agent"}),e.jsx(le,{})]})})]})}),e.jsxs(U,{title:"Members",children:[e.jsxs(We,{className:"table-fixed","aria-label":"Members",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:(t?.members??[]).map(b=>e.jsxs(be,{className:"last:border-0",children:[e.jsx(le,{className:"px-0 py-2 text-ink",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate",children:b.role}),At(b,s,n)?null:e.jsx(oe,{variant:"warning","data-testid":"team-member-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:b.kind==="team"?"Team":"Agent"}),e.jsx(le,{className:"px-0 py-2 text-right text-ink-muted tabular-nums",children:`×${ft(b)}`})]},`${b.kind}:${b.role}`))})]}),Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null]}),fe&&I?.members.length?e.jsxs(U,{title:r("ui.agents.models.reading.title"),description:r("ui.agents.models.reading.description"),children:[e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),H.isFetching?e.jsx("p",{"data-testid":"team-effective-refreshing",className:"text-meta text-ink-dim",children:r("ui.agents.models.reading.refreshing")}):null,e.jsxs(We,{className:K("table-fixed",H.isFetching&&"opacity-60"),"aria-label":r("ui.agents.models.reading.title"),children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-24"}),e.jsx("col",{}),e.jsx("col",{className:"w-32"})]}),e.jsx(Ve,{children:e.jsxs(be,{children:[e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.member_col")}),e.jsx(ue,{className:"px-2",children:r("ui.agents.models.reading.model_col")}),e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.effort_col")})]})}),e.jsx(Ge,{children:I.members.map(b=>e.jsxs(i.Fragment,{children:[e.jsxs(be,{className:b.available?"last:border-0":"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsx("span",{className:"block truncate text-body-sm text-ink",title:b.role,children:b.role})}),e.jsx(le,{className:"px-2 py-2",children:$t(Rt(b))}),e.jsx(le,{className:"px-0 py-2",children:$t(Tt(b))})]}),b.available?null:e.jsx(be,{className:"last:border-0",children:e.jsxs(le,{colSpan:3,className:"px-0 pb-2",children:[e.jsx("span",{"data-testid":"team-effective-unavailable",className:"block text-meta text-danger",children:r("ui.agents.models.reading.unavailable",{member:b.role,reason:b.reason})}),e.jsx("span",{className:"block text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]})})]},`${b.kind}:${b.role}`))})]})]}):null,e.jsx(U,{title:"What it is for",children:e.jsx(ye,{text:t?.description??"",empty:"No description yet."})}),t?.instructions?e.jsx(U,{title:"Collaboration instructions",children:e.jsx(ye,{text:t.instructions})}):null,t?.project?e.jsx(rt,{summary:"Project brief",children:e.jsx(ye,{text:t.project})}):null]})})]})}function je(t,s){return[...(t??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Agents"})),...(s??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Teams"}))]}const Ua=i.lazy(()=>$s(()=>import("./legacy-agents-page-zQ2FJ-pr.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]),import.meta.url).then(t=>({default:t.LegacyAgentsPage}))),Mt=/^subagents\.models\.([^.]+)$/,qa=["lo","med","hi"],Xe={all:"All",custom:"Custom",installed:"Installed",builtin:"Built-in"};function za(t){return!t||t.getAttribute("role")!=="tab"||t.getAttribute("aria-selected")==="true"?t:t.closest('[role="tablist"]')?.querySelector('[role="tab"][aria-selected="true"]')??null}function ni(){const{agentId:t}=Qs(),[s,n]=Ut(),a=s.get("kind")==="team"||s.get("create")==="team",l=s.has("create"),u=s.get("name"),g=s.get("duplicate"),h=ze(),v=ee(h.data,a?"team_catalogue":"profile_catalogue"),p=Is(v),d=As(v),m=v&&!!u&&!l,S=pt(a?null:u,m),x=Rs(a?u:null,m),j=pt(a?null:g,!!g),[k,T]=i.useState(""),[y,N]=i.useState("all"),[_,$]=i.useState(null),[A,f]=i.useState(null),o=ca(),C=J(c=>c.marks),R=J(c=>c.clearMark),w=Gt({queryKey:["desktop","settings","effort-tiers"],enabled:v,queryFn:()=>X({op:"settings.list"}),staleTime:6e4}),B=i.useMemo(()=>(w.data?.settings??[]).filter(c=>{const D=c.key.match(Mt)?.[1];return!D||!qa.includes(D)?!1:typeof c.value=="string"&&c.value.trim().length>0}).map(c=>c.key.match(Mt)?.[1]).filter(c=>!!c),[w.data]),P=zs(),z=i.useCallback(c=>Hs(c,P),[P]),te=i.useMemo(()=>Wa(p.data,k,y,z),[p.data,k,y,z]),ne=i.useMemo(()=>Va(d.data,k),[d.data,k]),Z=a?ne:te,M=u??null,[q,se]=i.useState(null);q!==null&&q.name!==M&&se(null);const W=i.useCallback(c=>{const D=new URLSearchParams;(c.kind??(a?"team":"agent"))==="team"&&D.set("kind","team"),c.name&&D.set("name",c.name),c.create!==null&&c.create!==void 0&&D.set("create",c.create),c.duplicate&&D.set("duplicate",c.duplicate),$(null),n(D)},[a,n]),Y=`${a?"team":"agent"}:${l??""}:${M??""}`,H=i.useCallback(c=>f(c?Y:null),[Y]),Q=A!==null&&A===Y,fe=(c,D,L)=>e.jsxs(e.Fragment,{children:[e.jsx(_a,{kind:c,name:D,localId:L,enabled:ee(h.data,"hub_links")}),e.jsx(hn,{kind:c,name:D,enabled:ee(h.data,"hub_updates")&&!ee(h.data,"hub_links")})]}),I=i.useRef(null),F=i.useRef(null),V=i.useRef(null),G=i.useCallback(c=>{if(Q){const D=F.current,L=document.activeElement;I.current=D?.isConnected&&D.closest("form")?D:L instanceof HTMLElement?L:null,$(c);return}W(c)},[Q,W]),ae=i.useCallback(()=>{$(null);const c=I.current;requestAnimationFrame(()=>{const D=za(c);D?.isConnected&&D.focus()})},[]),ie=_!==null;i.useEffect(()=>{if(!ie)return;_t(!0,()=>$(null)),V.current?.focus();const c=requestAnimationFrame(()=>{const L=V.current?.closest('[role="alertdialog"]');L&&!L.contains(document.activeElement)&&V.current?.focus()}),D=L=>{L.key!=="Escape"||L.defaultPrevented||(L.preventDefault(),ae())};return window.addEventListener("keydown",D),()=>{cancelAnimationFrame(c),window.removeEventListener("keydown",D),_t(!1)}},[ie,ae]),i.useEffect(()=>{const c=D=>{D.key!=="Escape"||D.defaultPrevented||window.matchMedia("(max-width: 999px)").matches&&(!M&&!l||Q||ie||(D.preventDefault(),G({name:null})))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[G,M,l,Q,ie]),i.useEffect(()=>{const D=J.getState().about;if(!D)return;const L=a?"team":"agent";M&&D.kind===L&&D.name===M||(o.setAbout(null),En(D))},[M,a,o]),i.useEffect(()=>{M&&R({kind:a?"team":"agent",name:M})},[M,a,R]);const re=()=>{p.refetch(),d.refetch(),M&&(a?x.refetch():S.refetch())};if(t)return e.jsx(i.Suspense,{fallback:e.jsx("p",{className:"p-6 text-body",children:"Loading saved agent…"}),children:e.jsx(Ua,{})});const _e=a?x.error:S.error,ge=a?d.error:p.error,Se=v&&!ge&&!l&&!M,b=a?x.isLoading:S.isLoading;return e.jsxs("div",{"data-glass-region":"canvas","data-glass-split":"",className:"panel-flush flex min-h-0 flex-1 bg-canvas text-ink",children:[e.jsxs("aside",{"data-open":M?"true":void 0,"data-glass-region":"page-sidebar",className:"panel-top-pad flex w-72 shrink-0 flex-col gap-3 bg-surface px-4 pb-4 max-[999px]:data-[open=true]:hidden",children:[e.jsx("h1",{className:"pt-4 text-heading",children:"Agents and teams"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(on,{value:a?"team":"agent",onValueChange:c=>G({kind:c,name:null}),children:e.jsxs(cn,{"aria-label":"Browse definitions by type",className:"w-full",children:[e.jsxs(bt,{value:"agent",className:"flex-1","data-testid":"agents-tab",children:[e.jsx(Ks,{className:"size-3.5"}),"Agents",p.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:p.data.length}):null]}),e.jsxs(bt,{value:"team",className:"flex-1","data-testid":"teams-tab",children:[e.jsx(Ts,{className:"size-3.5"}),"Teams",d.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:d.data.length}):null]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ds,{"aria-hidden":"true",className:"pointer-events-none absolute top-2 start-2 size-4 text-ink-dim"}),e.jsx(Ne,{className:"ps-8",type:"search","aria-label":"Search agents and teams",placeholder:a?"Search teams":"Search agents",value:k,onChange:c=>T(c.target.value)})]}),!a&&p.data?e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Show definitions owned by"}),e.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Object.keys(Xe).map(c=>e.jsx(E,{variant:"ghost",size:"sm","aria-pressed":y===c,onClick:()=>N(c),className:K("flex-1",y===c&&Vt),children:Xe[c]},c))})]}):null]}),e.jsx("div",{"data-lo-pane-edge-cues":!0,className:"min-h-0 flex-1 overflow-y-auto",children:ge?null:!p.data&&!d.data?e.jsx(ha,{}):Z.length===0?e.jsx("p",{className:"px-1 py-2 text-body-sm text-ink-muted",children:k?`Nothing matches “${k}”.`:a?"No teams yet. Ask for one below, or add one by hand.":y==="all"?"No agents yet. Ask for one below, or add one by hand.":`No ${Xe[y].toLowerCase()} agents.`}):e.jsx(Ka,{rows:Z,name:l?null:M,teamMode:a,printName:z,marked:new Map(C.map(c=>[In(c),c.created])),onOpen:c=>G({name:c})})}),e.jsxs(E,{variant:"ghost",className:"w-full justify-start",disabled:!v,onClick:()=>G({create:a?"team":"agent"}),children:[e.jsx(Wt,{className:"size-4"}),a?"Add team manually":"Add agent manually"]})]}),e.jsxs("main",{"data-glass-region":"canvas-content",className:"panel-top-pad flex min-w-0 flex-1 flex-col",children:[M||l?e.jsx("div",{className:"flex shrink-0 items-center border-hairline border-b px-4 py-2 min-[1000px]:hidden",children:e.jsxs(E,{variant:"ghost",size:"sm",onClick:()=>G({name:null}),children:[e.jsx(Ws,{className:"size-4"}),"Back to the list"]})}):null,e.jsx("div",{"data-agents-pane":!0,onFocus:c=>{c.target instanceof HTMLElement&&(F.current=c.target)},"data-lo-pane-edge-cues":!0,className:K("min-h-0 flex-1 overflow-auto",Se?void 0:"px-4 pt-6 [scroll-padding-bottom:calc(var(--lo-pane-footer-h)+var(--lo-pane-footer-cue-h)+4px)] [scrollbar-gutter:stable_both-edges]"),children:Se?e.jsx(Ha,{teamMode:a,run:o,onAddManually:()=>G({create:a?"team":"agent"})}):e.jsx("div",{className:it,children:e.jsx("div",{className:Ie,children:v?ge?e.jsx(Ct,{title:a?"Teams could not be read":"Agents could not be read",what:ge instanceof Error?ge.message:"The request did not complete.",meaning:"Nothing is lost. This is a read that failed — the backend answered an error, which is different from the backend being out of date.",onRetry:re,retrying:p.isFetching||d.isFetching}):M&&b?e.jsx(St,{}):M&&_e?e.jsx(Ct,{title:a?`“${M}” could not be read`:`“${M}” could not be read`,what:_e instanceof Error?_e.message:"The request did not complete.",meaning:"The definition may have been removed, or the backend refused the read.",onRetry:()=>{S.refetch(),x.refetch()},retrying:S.isFetching||x.isFetching}):l&&a?e.jsx(Ft,{agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancelCreate:()=>W({name:null}),onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:u??""},c)}},"team:create"):l&&g&&j.isLoading?e.jsx(St,{}):l?e.jsx(ya,{initial:j.data??null,takenNames:(p.data??[]).map(c=>c.name),effortTiers:B,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancel:()=>W({name:null})},"agent:create"):a&&x.data?e.jsx(Ft,{team:x.data,agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("team",x.data.name,x.data.id),onSaved:c=>{re(),W({name:c})},onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:x.data?.name??""},c)}},ua(x.data)):!a&&S.data?e.jsx(va,{profile:S.data,displayedName:z(S.data.name),classNotice:q?.name===S.data.name?q.copy:null,onClassNotice:c=>se(c?{name:S.data.name,copy:c}:null),teams:d.data,effortTiers:B,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("agent",S.data.name,S.data.agent_id??void 0),onSaved:c=>{re(),W({name:c})},onDuplicate:c=>G({create:"agent",duplicate:c.name}),onOpenTeam:c=>G({kind:"team",name:c}),onAskAgent:c=>{Ye(o,{kind:"agent",name:S.data?.name??""},c)}},da(S.data)):M?e.jsx(ve,{className:"h-6 w-40"}):null:e.jsxs(ce,{variant:h.isLoading?"neutral":"warning",className:"max-w-xl",children:[e.jsx(de,{children:h.isLoading?"Connecting to the backend":h.error?"The backend could not be reached":"Reusable agents need a newer backend"}),e.jsx(me,{children:h.isLoading?"Loading what this backend can do…":h.error?h.error.message:"Update the backend to manage reusable agents and teams. Saved chats are unchanged."})]})})})}),_?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-hairline border-t bg-surface px-4 py-3",role:"alertdialog","aria-label":"Discard your unsaved changes?",children:[e.jsx("span",{className:"text-body-sm text-ink",children:a?"Discard your unsaved changes to this team?":"Discard your unsaved changes to this agent?"}),e.jsx(E,{variant:"danger",onClick:()=>{f(null),W(_)},children:"Discard changes"}),e.jsx(E,{ref:V,variant:"ghost",onClick:ae,children:"Keep editing"})]}):null,Se?null:e.jsx("div",{className:"shrink-0 bg-canvas",children:e.jsx(ss,{run:o,about:o.about,onClearAbout:()=>o.setAbout(null),blockedReason:Q?"Finish or cancel your edit first.":null})})]})]})}function Ha({teamMode:t,run:s,onAddManually:n}){const a=K(it,Pt);return e.jsxs("div",{className:"flex min-h-full flex-col justify-center space-y-4 pb-12",children:[e.jsx("div",{className:a,children:e.jsxs("div",{className:K(Ie,"space-y-2"),children:[e.jsx("h2",{className:"text-title",children:t?"Ask for a team":"Ask for an agent"}),e.jsx("p",{className:"text-body text-ink-muted",children:t?"A team has one agent that leads the chat and members it can hand work to. Describe what you want and a configuration run sets it up.":"An agent is a reusable set of instructions you can start a chat with, or let other agents call on. Describe what you want and a configuration run sets it up."})]})}),e.jsx(ss,{run:s,hero:!0,about:s.about,onClearAbout:()=>s.setAbout(null)}),e.jsx("div",{className:a,children:e.jsx("div",{className:Ie,children:e.jsx(E,{variant:"ghost",className:"-ml-3",onClick:n,children:t?"Or add a team by hand":"Or add an agent by hand"})})})]})}function Ka({rows:t,name:s,teamMode:n,marked:a,printName:l,onOpen:u}){const g=i.useRef(new Map),[h,v]=i.useState(s),p=m=>"members"in m?qt(m):l(m.name),d=(m,S)=>{const x=t.findIndex(k=>k.name===m);if(x<0)return;const j=t[Math.min(t.length-1,Math.max(0,x+S))];j&&(v(j.name),g.current.get(j.name)?.focus())};return e.jsx("ul",{"aria-label":n?"Teams":"Agents",className:"space-y-0.5",children:t.map(m=>{const S="source"in m,x=a.get(`${n?"team":"agent"}:${m.name}`);return e.jsx("li",{children:e.jsxs("button",{ref:j=>{j?g.current.set(m.name,j):g.current.delete(m.name)},type:"button","aria-current":m.name===s?"true":void 0,tabIndex:m.name===(h??t[0]?.name)?0:-1,"data-testid":`roster-row-${m.name}`,title:m.description?`${p(m)} - ${m.description}`:p(m),className:K("flex min-h-12 w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-start hover:bg-row-hover",m.name===s&&Vt),onFocus:()=>v(m.name),onClick:()=>u(m.name),onKeyDown:j=>{j.key==="ArrowDown"?(j.preventDefault(),d(m.name,1)):j.key==="ArrowUp"?(j.preventDefault(),d(m.name,-1)):j.key==="Home"?(j.preventDefault(),d(m.name,-t.length)):j.key==="End"&&(j.preventDefault(),d(m.name,t.length))},children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-body-sm text-ink",children:p(m)}),x!==void 0?e.jsx(oe,{variant:"attention","data-testid":"roster-row-updated",children:x?"New":"Updated"}):null,e.jsx("span",{className:"ms-auto shrink-0 text-meta text-ink-dim tabular-nums",children:"members"in m?gs(m.members):e.jsx(ma,{source:m.source,appearance:"text"})})]}),e.jsxs("span",{className:"flex min-h-lh w-full items-baseline text-meta text-ink-muted",children:[S&&De(m)==="proactive"?e.jsxs("span",{className:"me-1 shrink-0","data-testid":"roster-row-proactive",children:[e.jsx("span",{className:"text-ink",children:ns.proactive}),e.jsx("span",{className:"text-ink-dim",children:" ·"})]}):null,m.description?e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.description}):e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink-dim",children:"No description"})]})]})},m.name)})})}function Wa(t,s,n,a){const l=s.trim().toLowerCase();return(t??[]).filter(u=>n==="builtin"&&u.source!=="builtin"||n==="installed"&&u.source!=="installed"||n==="custom"&&u.source!=="custom"?!1:l?a(u.name).toLowerCase().includes(l)||u.name.toLowerCase().includes(l)||(u.description??"").toLowerCase().includes(l):!0)}function Va(t,s){const n=s.trim().toLowerCase();return(t??[]).filter(a=>!n||a.name.toLowerCase().includes(n)||(a.label??"").toLowerCase().includes(n)||(a.description??"").toLowerCase().includes(n))}export{ni as AgentsPage};
7
+ */const fn=[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]],gn=Zs("log-in",fn),pn=[],Ee="config-composer-note",jt="Configure agents by conversation",xn=["A reviewer that only reads code","Add the coder twice to release-crew","A team called shipping with a manager and two coders"],bn={idle:"bg-ink-dim",running:"bg-accent",stopping:"bg-warning",done:"bg-success",stopped:"bg-ink-muted",error:"bg-danger"};function jn({status:t,pulse:s}){return e.jsx("span",{"aria-hidden":"true",className:K("size-2 shrink-0 rounded-full",bn[t]??"bg-ink-dim",s&&"animate-pulse")})}function vn({run:t}){return t.activity.length===0?e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing to show yet — the run has not called a tool."}):e.jsx("ul",{className:"space-y-1",children:t.activity.map((s,n)=>e.jsxs("li",{className:"flex items-baseline gap-2 text-body-sm",children:[e.jsx("span",{className:"text-ink-dim tabular-nums",children:new Date(s.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),e.jsx("span",{className:"text-ink",children:s.verb})]},`${s.ts}:${s.verb}:${n}`))})}const vt="-mr-2",yn="max-h-[clamp(3.5rem,10vh,5.5rem)]";function kn(){const t=i.useRef(null),[s,n]=i.useState(!1);return i.useEffect(()=>{const a=t.current;if(!a)return;const l=()=>n(a.scrollHeight>a.clientHeight+1);l();const u=new ResizeObserver(l);return u.observe(a),()=>u.disconnect()}),{ref:t,overflowing:s}}function Nn({children:t}){const{ref:s,overflowing:n}=kn();return e.jsx("div",{ref:s,tabIndex:n?0:void 0,role:n?"region":void 0,"aria-label":n?"Run details":void 0,"data-lo-region-cue":n?"":void 0,className:K("mb-2 overflow-y-auto empty:hidden",yn),children:t})}const wn="mb-1 flex min-h-7 items-center gap-3",yt=t=>t===1?"1 definition":`${t} definitions`;function _n({run:t,about:s,blockedReason:n,hasDraft:a,onClearAbout:l,onDismiss:u}){const[g,h]=i.useState(!1),v=i.useRef(null),p=t.status==="running"||t.status==="stopping",d=t.enabled&&t.status!=="idle",m=!!n&&a&&!d,S=!!n&&a&&d&&!p;i.useEffect(()=>{if(!p)return;const j=k=>{k.key!=="Escape"||k.defaultPrevented||document.querySelector('[role="alertdialog"], [role="dialog"]')||v.current?.focus()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[p]);const x=t.status==="running"?t.step??"Working on your request":t.status==="stopping"?"Stopping":t.status==="done"?t.results.length>0?"Finished":"Finished without changing anything":t.status==="stopped"?"Stopped":t.status==="error"?t.canRetry?"Stopped with an error":"Finished with an error":"";return e.jsxs("div",{className:Ie,"data-testid":d?"config-run-strip":void 0,children:[e.jsxs("div",{className:wn,children:[d?e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx(jn,{status:t.status,pulse:p}),e.jsxs("span",{"aria-live":"polite",className:"min-w-0 truncate text-body-sm text-ink",children:[x,t.status==="done"&&t.touched.length>0?e.jsx("span",{className:"sr-only",children:`. Configured ${yt(t.touched.length)}`}):null]}),(p||t.status==="stopped"||t.status==="done")&&t.elapsed!=="0s"?e.jsx("span",{className:"shrink-0 text-meta text-ink-muted tabular-nums",children:t.elapsed}):null,t.touched.length>0?e.jsxs("span",{"aria-hidden":t.status==="done"?!0:void 0,className:"shrink-0 text-meta text-ink-muted",children:[e.jsx("span",{className:"sr-only",children:"Configured "}),yt(t.touched.length)]}):null]}):null,t.enabled&&!S?e.jsxs(e.Fragment,{children:[m?null:e.jsx("span",{id:n?void 0:Ee,"data-testid":n?void 0:"config-composer-note",className:d?"sr-only":"min-w-0 flex-1 truncate text-meta text-ink-dim",children:"Runs in the background. This does not appear in your conversation."}),n?e.jsx("span",{id:Ee,"data-testid":"config-composer-note",className:m?"min-w-0 flex-1 truncate text-meta text-ink-dim":"sr-only",children:n}):null]}):e.jsx("span",{className:"flex-1","aria-hidden":"true"}),e.jsxs("div",{className:"ms-auto flex shrink-0 items-center gap-1",children:[s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"data-testid":"config-composer-about",title:`About ${s.kind} ${s.name}`,className:"max-w-56 truncate text-meta text-ink-muted",children:["About ",s.kind," ",s.name]}),e.jsx(E,{variant:"ghost",size:"sm",className:d?void 0:vt,onClick:l,children:"Clear"})]}):null,d&&t.activity.length>0?e.jsxs(E,{variant:"ghost",size:"sm","aria-expanded":g,onClick:()=>h(j=>!j),children:[g?e.jsx(Xs,{className:"size-3.5"}):e.jsx(en,{className:"size-3.5 rtl:-scale-x-100"}),"Watch"]}):null,d?p?e.jsxs(E,{ref:v,variant:"secondary",size:"sm",disabled:t.status==="stopping",onClick:()=>void t.stop(),children:[e.jsx(js,{className:"size-3.5"}),t.status==="stopping"?"Stopping…":"Stop"]}):e.jsx(E,{variant:"ghost",size:"sm",className:vt,onClick:u,children:"Dismiss"}):null]})]}),t.enabled?null:e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-dim",children:t.disabledReason}),S?e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-muted",children:n}):null,d?e.jsxs(Nn,{children:[t.attached?e.jsx("p",{className:"mt-1 text-meta text-ink-muted",children:"Another configuration run was already going, so this page attached to it. Your request was not sent — it is still in the box."}):null,t.stopError?e.jsxs("div",{className:"mt-2 border-danger-border border-t pt-2","data-testid":"config-stop-refused",children:[e.jsx("p",{className:"text-body-sm text-danger",children:"The stop did not take — the run is still going."}),e.jsx("p",{className:"mt-0.5 text-meta text-ink-muted",children:t.stopError})]}):null,g?e.jsx("div",{className:"mt-2 border-hairline border-t pt-2",children:e.jsx(vn,{run:t})}):null,t.status==="stopped"?e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink",children:t.results.length>0?"Stopped. Changes it had already made were kept.":"Stopped. Nothing had been changed yet."}),t.results.length>0?e.jsx("ul",{className:"space-y-0.5",children:t.results.map(j=>e.jsxs("li",{className:"text-ink-muted",children:[j.created?"Created ":"Changed ",e.jsx("span",{className:"text-ink",children:j.target.name})]},`${j.target.kind}:${j.target.name}`))}):null]}):null,t.status==="done"?e.jsx(Sn,{run:t}):null,t.status==="error"&&t.error?e.jsx("div",{className:"mt-2 border-danger-border border-t pt-2",children:e.jsx("p",{className:"text-body-sm text-danger",children:t.error})}):null]}):null,d&&t.status==="error"&&t.error?e.jsxs("div",{className:"mb-2.5 flex items-center gap-2",children:[t.canRetry?e.jsx(E,{variant:"secondary",size:"sm","data-testid":"config-retry",disabled:t.starting,onClick:()=>void t.retry(),children:t.starting?"Sending…":"Retry"}):null,e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing else was changed by this run."})]}):null]})}function Sn({run:t}){return t.results.length===0?e.jsxs("div",{className:"mt-2 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink-muted",children:"The run answered without changing any agent or team."}),t.answer?e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-ink",children:t.answer}):null,t.topic?e.jsxs("p",{className:"mt-1 text-meta text-ink-muted",children:["You asked: ",t.topic]}):null]}):e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2",children:[e.jsx("ul",{className:"space-y-1 text-body-sm",children:t.results.map(s=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-ink",children:[s.created?"Created ":"Updated ",s.target.name]}),e.jsxs("span",{className:"text-ink-muted",children:[" (",s.target.kind,")"]}),s.changes.length>0?e.jsxs("span",{className:"text-ink-muted",children:[": ",s.changes.map(n=>n.label).join(", ")]}):s.created?null:e.jsx("span",{className:"text-ink-muted",children:": its settings changed. The list does not show instructions, so open it to see what was written."})]},`${s.target.kind}:${s.target.name}`))}),t.answer?e.jsx("p",{className:"whitespace-pre-wrap text-body-sm text-ink-muted",children:t.answer}):null]})}const we="agents-config",Cn=t=>`Change the ${t.kind} ${t.name}: `;function Ye(t,s,n){t.setAbout(s);const a=Pe.getState();a.getCurrentInput(we)||a.setComposerText(we,n)}function En(t){const s=Pe.getState();s.getCurrentInput(we).trim()===Cn(t).trim()&&s.setComposerText(we,"")}function ss({run:t,hero:s=!1,blockedReason:n,about:a,onClearAbout:l}){const u=i.useRef(null),g=xs(),h=ot(A=>A.cwd),v=ze(),p=t.frontend===null&&t.status==="idle"&&h.length>0&&ee(v.data,"draft_preview"),d=Gt({...Vs({cwd:h,model:null},ee(v.data,"draft_fast")),enabled:p}),m=we,S=A=>Pe.getState().setCurrentInput(m,A),x=t.status==="running"||t.status==="stopping",j=!t.enabled||!!n,k=Pe(A=>(A.inputByConversation[we]?.currentInput??"").trim().length>0),T=n||(x?"Working on your request…":t.enabled?void 0:jt),y=a?`Change ${a.name}…`:t.enabled?s?"Describe what you want…":"Ask for a change, or describe something new…":jt,N=a?`${a.kind}:${a.name}`:null;i.useEffect(()=>{N&&u.current?.focusInput()},[N]);const _=()=>{t.dismiss(),u.current?.focusInput()},$=()=>{l(),u.current?.focusInput()};return e.jsxs("div",{"data-testid":"config-composer",children:[e.jsx("div",{className:"sr-only",id:"config-composer-label",children:"Ask for an agent or team change"}),e.jsx(bs,{ref:u,conversationId:m,messages:pn,isLoading:!1,transcriptless:!0,placeholderOverride:y,sessionStatus:t.frontend?{frontend:t.frontend,costChannels:ee(v.data,"cost_channels")}:d.data?{frontend:d.data.snapshot,draft:!0,costChannels:ee(v.data,"cost_channels")}:void 0,recordingProbe:g,hostNotice:{id:Ee,blocksInput:!t.enabled||!!n||x,placeholder:T,statedByNode:k,node:e.jsx(_n,{run:t,about:a,blockedReason:n,hasDraft:k,onClearAbout:$,onDismiss:_})},onSendMessage:(A,f)=>t.start(A,a,f)}),s&&t.enabled?e.jsx("div",{className:K(it,Pt),children:e.jsx("div",{className:K(Ie,"mt-2 flex flex-col items-start gap-0.5",!a&&!x?"":"invisible"),children:xn.map(A=>e.jsx(E,{variant:"ghost",size:"sm",className:"-ml-2 h-auto max-w-full justify-start whitespace-normal break-words px-2 py-1 text-start text-body-sm text-ink-muted hover:bg-elevated hover:text-ink disabled:text-ink-disabled disabled:hover:bg-transparent",disabled:j,onClick:()=>{S(A),u.current?.focusInput()},children:A},A))})}):null]})}const kt=(t,s)=>t.kind===s.kind&&t.name===s.name;function In(t){return`${t.kind}:${t.name}`}const J=Gs(t=>({sessionId:null,status:"idle",topic:"",images:[],files:[],about:null,error:null,stopError:null,unsent:!1,startedAt:null,settledAt:null,touched:[],results:[],answer:"",marks:[],before:null,setAbout:s=>t({about:s}),adopt:(s,n,a,l=[],u=[])=>t({sessionId:s,status:"running",topic:n,images:l,files:u,error:null,stopError:null,startedAt:Date.now(),settledAt:null,touched:[],results:[],answer:"",before:a,unsent:!1}),noteTouched:s=>t(n=>n.touched.some(a=>kt(a,s))?n:{touched:[...n.touched,s]}),stopping:()=>t(s=>s.status==="running"?{status:"stopping",stopError:null}:s),stopFailed:s=>t({status:"running",stopError:s}),settle:(s,n,a)=>t(()=>({status:n,settledAt:Date.now(),results:s,answer:a,marks:s.map(l=>({...l.target,created:l.created})),sessionId:null,images:[],files:[],stopError:null,before:null,unsent:!1})),fail:s=>t({status:"error",error:s,unsent:!1,stopError:null}),failUnsent:s=>t({status:"error",error:s,unsent:!0,stopError:null}),dismiss:()=>t({status:"idle",sessionId:null,error:null,stopError:null,unsent:!1,topic:"",images:[],files:[],touched:[],results:[],answer:"",marks:[],startedAt:null,settledAt:null,before:null}),clearMark:s=>t(n=>({marks:n.marks.filter(a=>!kt(a,s))}))})),An=/Value error,\s*([\s\S]*?)\s*\[type=/,Rn=/^\d+ validation errors? for \S+[\s\S]*?\n\s*/i,Tn=/\s*\[type=[^\]]*\][\s\S]*$/m,Dn=/\s*For further information visit \S+/g,$n=/'([^']+)' already exists/,Ln=/cannot contain spaces or path separators/i,On=/effort tier '([^']+)' is unavailable/i,Fn=/team name must be/i,Mn=/manager '([^']+)'/i,Pn=/(?:member|role) '([^']+)' (?:is not|does not)/i,Bn=/depth|cycle|circular/i,Un=/instructions/i,qn=/description/i;function zn(t){const s=t.match(An);return s?.[1]?s[1].trim():t.replace(Rn,"").replace(Tn,"").replace(Dn,"").trim()}function Ae(t){const s=zn(t),n=s.match($n);if(n)return{message:r("ui.agents.refusals.name_taken",{name:n[1]}),field:"name"};if(Ln.test(s))return{message:r("ui.agents.refusals.name_grammar"),field:"name"};const a=s.match(On);if(a)return{message:r("ui.agents.refusals.effort_unavailable",{tier:a[1]}),field:"effort"};if(s.match(Fn))return{message:r("ui.agents.refusals.team_name_bound"),field:"name"};const u=s.match(Mn);if(u)return{message:r("ui.agents.refusals.missing_manager",{name:u[1]}),field:"manager"};const g=s.match(Pn);return g?{message:r("ui.agents.refusals.missing_member",{name:g[1]}),field:"members"}:Bn.test(s)?{message:r("ui.agents.refusals.team_nesting"),field:"members"}:Un.test(s)?{message:s,field:"instructions"}:qn.test(s)?{message:s,field:"description"}:{message:s,field:null}}function Hn(t,s){const n=new Set(s),a=`${t}-copy`;if(!n.has(a))return a;for(let l=2;l<100;l+=1){const u=`${a}-${l}`;if(!n.has(u))return u}return a}function De(t){return t.action_class==="proactive"?"proactive":"reactive"}const ns={get proactive(){return r("ui.agents.refusals.class.label.proactive")}},Kn={get proactive(){return r("ui.agents.refusals.class.meaning.proactive")},get reactive(){return r("ui.agents.refusals.class.meaning.reactive")}},Wn={get proactive(){return r("ui.agents.refusals.class.effect.proactive")},get reactive(){return r("ui.agents.refusals.class.effect.reactive")}};let as=r("ui.agents.refusals.class.install_disclosure");dn(()=>{as=r("ui.agents.refusals.class.install_disclosure")});function Vn(t,s){const n=[];return t.source==="builtin"&&n.push({op:"profiles.install",name:t.name}),n.push({op:"profiles.update",name:t.name,fields:{action_class:s}}),n}async function Gn(t,s,n,a=()=>crypto.randomUUID()){if(De(t)===s)return null;let l=null;const u=Vn(t,s);for(let g=0;g<u.length;g+=1){const h=u[g];try{l=await n(h,a())}catch(v){throw new is(v,u.slice(0,g))}}return l}class is extends Error{completed;constructor(s,n){super(s instanceof Error?s.message:String(s)),this.name="ClassSwitchError",this.completed=n}}function Jn(t,s){const n=t instanceof Error&&t.message?t.message:r("ui.agents.refusals.class.error.no_reason"),a=Ae(n).message;return s.some(l=>l.op==="profiles.install")?r("ui.agents.refusals.class.error.install_landed",{reason:a}):a}const Yn=new Set(["agent","team"]);function Qn(t){const s=typeof t.args?.op=="string"?t.args.op:null,n=typeof t.args?.name=="string"?t.args.name:null,a=t.toolName==="team"?"team":"agent",l=n?{kind:a,name:n}:null,u=t.phase==="done"&&!t.isError&&!t.notRunReason&&!t.neverSent,g=h=>({writes:h&&u});switch(s){case"create":return{verb:n?`Creating ${a} ${n}`:`Creating a ${a}`,target:l,...g(!0)};case"update":return{verb:n?`Updating ${a} ${n}`:`Updating a ${a}`,target:l,...g(!0)};case"install":return{verb:n?`Installing ${n}`:"Installing an agent",target:l,...g(!0)};case"list":case"search":case"show":return{verb:n?`Reading ${n}`:`Reading ${a}s`,target:l,...g(!1)};default:return{verb:t.phase==="running"?`Working on ${a}s`:`Checked ${a}s`,target:l,...g(!0)}}}const Zn={description:"description",kind:"kind",tools:"tools",effort:"effort tier",delegate:"delegation",action_class:"class",manager:"manager",members:"members",instructions:"instructions"};function Xn(t){return{description:t.description??"",kind:t.kind,tools:t.tools&&t.tools.length>0?[...t.tools].sort().join(","):"*",effort:t.effort??"inherit",delegate:String(!!t.delegate),action_class:De(t)}}function ea(t){return{description:t.description??"",manager:t.manager??"",members:(t.members??[]).map(s=>`${s.kind}:${s.role}x${s.count}`).sort().join(",")}}function Nt(t,s){return{agents:Object.fromEntries((t??[]).map(n=>[n.name,Xn(n)])),teams:Object.fromEntries((s??[]).map(n=>[n.name,ea(n)]))}}function ta(t,s){if(t===s)return"tools";const n=h=>h==="*"?null:new Set(h.split(",")),a=n(t),l=n(s);if(l===null)return"tools widened to every tool";if(a===null)return"tools narrowed to a list";const u=[...l].filter(h=>!a.has(h)),g=[...a].filter(h=>!l.has(h));return u.length&&!g.length?u.length===1?`tool added: ${u[0]}`:`${u.length} tools added`:g.length&&!u.length?g.length===1?`tool removed: ${g[0]}`:`${g.length} tools removed`:"tools changed"}function sa(t,s,n){if(t==="tools")return ta(s,n);if(t==="delegate")return n==="true"?"delegation turned on":"delegation turned off";if(t==="action_class")return n==="proactive"?"class changed to proactive":"class changed to reactive — proactive messaging stopped";if(t==="members"){const a=l=>l?l.split(",").length:0;return`members changed (${a(s)} to ${a(n)})`}return`${Zn[t]??t} changed`}function na(t,s,n){const a=[],l=new Set;for(const u of n){const g=`${u.kind}:${u.name}`;if(l.has(g))continue;l.add(g);const h=t[u.kind==="agent"?"agents":"teams"][u.name],v=s[u.kind==="agent"?"agents":"teams"][u.name];if(!v)continue;if(!h){a.push({target:u,created:!0,changes:[]});continue}const p=[];for(const d of Object.keys(v))v[d]!==h[d]&&p.push({label:sa(d,h[d],v[d]),before:h[d],after:v[d]});a.push({target:u,created:!1,changes:p})}for(const[u,g]of[["agent",s.agents],["team",s.teams]])for(const h of Object.keys(g))l.has(`${u}:${h}`)||(u==="agent"?t.agents[h]:t.teams[h])||a.push({target:{kind:u,name:h},created:!0,changes:[]});return a}function aa(t){return ee(t,"agents_config")&&ee(t,"session_interrupt")&&ee(t,"profile_catalogue")&&ee(t,"team_catalogue")}function ia(t){if(!(t instanceof Be)||t.status!==409)return null;const n=t.detail?.session_id;return typeof n=="string"&&n.length>0?n:null}function ra(t,s){const[n,a]=i.useState(()=>Date.now());return i.useEffect(()=>{if(!t||!s)return;const l=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(l)},[t,s]),t?Math.max(0,n-t):0}function la(t){const s=Math.floor(t/1e3);return s<60?`${s}s`:`${Math.floor(s/60)}m ${String(s%60).padStart(2,"0")}s`}function wt(t){for(let s=(t?.length??0)-1;s>=0;s-=1){const n=t?.[s];if(n?.kind==="assistant"&&n.text?.trim())return n.text.trim()}return""}function oa(t){const n=t?.payload?.frontend;if(!n||typeof n!="object")return null;const a=n.streaming;if(typeof a=="boolean")return a;const l=n.snapshot?.streaming;return typeof l=="boolean"?l:null}function ca(){const t=ze(),s=aa(t.data),n=ct(),a=J(),[l,u]=i.useState(!1),[g,h]=i.useState(!1),v=i.useRef(!1),p=a.status==="running"||a.status==="stopping",d=Js(a.sessionId??void 0,!!a.sessionId),m=i.useMemo(()=>wt(d.transcript?.records),[d.transcript?.records]);Ls(a.sessionId??void 0,d.subscriptionId);const S=d.transcript?.records,x=i.useRef(S);i.useEffect(()=>{x.current=S},[S]);const j=i.useMemo(()=>(d.transcript?.records??[]).filter(C=>C.kind==="tool"&&Yn.has(C.toolName)).map(C=>({...Qn({toolName:C.toolName,args:C.args??null,phase:C.phase,ts:C.ts,isError:C.isError,notRunReason:C.notRunReason,neverSent:C.neverSent}),ts:C.ts})),[d.transcript]);i.useEffect(()=>{if(p)for(const o of j)o.target&&o.writes&&a.noteTouched(o.target)},[j,p,a]);const k=p&&j.length>0?j[j.length-1].verb:null,T=la(ra(a.startedAt,p)),y=i.useCallback(async(o,C="")=>{if(v.current)return;v.current=!0;const R=a.before;let w=[];try{const[B,P]=await Promise.all([X({op:"profiles.list"}),X({op:"teams.list"})]);R&&(w=na(R,Nt(B.profiles,P.teams),a.touched))}catch{J.getState().fail("The run finished, but the agents and teams lists could not be read to describe what changed."),gt(n);return}if(gt(n),J.getState().settle(w,o,C),o==="done"&&w.length>0){const B=w.filter(P=>P.created).length;ke(B>0?`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} changed.`:`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} updated.`)}},[n,a.before,a.touched]);i.useEffect(()=>{if(p){if(d.failure){J.getState().fail(d.failure.statement);return}v.current||d.frontend&&(d.frontend.streaming||d.turnsCompleted!==0&&y(a.status==="stopping"?"stopped":"done",m))}},[p,m,d.failure,d.frontend,d.turnsCompleted,a.status,y]),i.useEffect(()=>{const o=a.sessionId;if(!p||!o)return;let C=!1;const R=async()=>{if(!(C||v.current))try{const P=await X({op:"sessions.get",sessionId:o});if(C||v.current||oa(P)!==!1)return;const z=wt(x.current);if(!z)return;y(J.getState().status==="stopping"?"stopped":"done",z)}catch{}},w=setTimeout(()=>void R(),400),B=setInterval(()=>void R(),4e3);return()=>{C=!0,clearTimeout(w),clearInterval(B)}},[p,a.sessionId,y]);const N=async(o,C,R=[])=>{if(l||!o.trim()&&R.length===0)return!1;u(!0),h(!1),v.current=!1;const w=Nt(n.getQueryData(["desktop","profiles"]),n.getQueryData(["desktop","teams"])),B=C?`About the ${C.kind} “${C.name}”: ${o.trim()}`:o.trim(),{images:P,files:z,failures:te,overflow:ne,fileOverflow:Z}=await vs(R,B),M=ys(te);if(M)return J.getState().fail(M),!1;const q=ks(ne);if(q)return J.getState().fail(q),!1;const se=Ns(Z);if(se)return J.getState().fail(se),!1;try{let W;try{W=(await X({op:"sessions.create",requestId:crypto.randomUUID(),purpose:"agents-config"})).session_id}catch(Y){const H=ia(Y);if(H)return h(!0),a.adopt(H,o.trim(),w,P,z),!1;throw Y}return a.adopt(W,B,w,P,z),await _(W,B,P,z),!0}catch(W){const Y=J.getState().sessionId;return J.getState().failUnsent(Ke(W,Y?"The run was set up, but your request could not be sent. It is still in the box — send it again when the backend is reachable.":"The configuration run could not be started. Your request is still here.")),!1}finally{u(!1)}},_=async(o,C,R=[],w=[])=>{await X({op:"sessions.message",sessionId:o,requestId:crypto.randomUUID(),text:C,...R.length>0?{images:R}:{},...w.length>0?{files:w}:{}})},$=async()=>{const o=J.getState();if(!(l||!o.unsent||!o.sessionId||!o.topic&&o.images.length===0)){u(!0);try{await _(o.sessionId,o.topic,o.images,o.files),a.adopt(o.sessionId,o.topic,o.before),v.current=!1}catch(C){J.getState().failUnsent(Ke(C,"The request could not be sent. It is still in the box."))}finally{u(!1)}}},A=async()=>{const o=J.getState().sessionId;if(o){a.stopping();try{await Os(o,crypto.randomUUID())}catch(C){J.getState().stopFailed(Ke(C,"The run did not acknowledge the request."))}}},f=s?null:t.isLoading?"Connecting to the backend…":t.error?"The backend could not be reached, so the composer is unavailable for now.":"Ask for a change needs a newer backend. Update Local Operator to configure agents by conversation.";return{enabled:s,disabledReason:f,status:a.status,sessionId:a.sessionId,frontend:d.frontend,topic:a.topic,error:a.error,stopError:a.stopError,about:a.about,setAbout:a.setAbout,touched:a.touched,results:a.results,answer:a.answer,step:k,elapsed:T,activity:j,start:N,stop:A,retry:$,canRetry:a.unsent&&!!a.sessionId,dismiss:a.dismiss,starting:l,attached:g}}function da(t){return JSON.stringify(t.agent_id?["agent","id",t.agent_id]:["agent","source",t.source,t.name])}function ua(t){return JSON.stringify(t.id?["team","id",t.id]:["team","local",t.name])}function U({title:t,description:s,actions:n,children:a,className:l}){return e.jsxs("section",{className:K("space-y-2",l),children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:[e.jsx("h3",{className:"text-heading",children:t}),n]}),s?e.jsx("p",{className:"text-meta text-ink-muted",children:s}):null,a]})}const ut="min-h-6",rs="h-[calc(var(--text-title)*var(--text-title--line-height))]";function ye({text:t,empty:s="Nothing here yet.",mono:n=!1}){const[a,l]=i.useState(!1),[u,g]=i.useState(!1),h=i.useRef(null);return i.useEffect(()=>{if(a)return;const v=h.current;if(!v)return;const p=()=>g(!!t&&v.scrollHeight>v.clientHeight+1);p();const d=new ResizeObserver(p);return d.observe(v),()=>d.disconnect()},[t,a]),t.trim()?e.jsxs("div",{children:[e.jsx("div",{ref:h,className:K("whitespace-pre-wrap text-body text-ink",!a&&"line-clamp-10",n&&"font-mono text-meta"),children:t}),u?e.jsx(E,{variant:"link",size:"sm",className:K("mt-px -mb-[3px]",ut),"aria-expanded":a,onClick:()=>l(v=>!v),children:a?"Show less":"Show all"}):null]}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:s})}function ma({source:t,appearance:s="chip"}){const n=ls(t);return s==="text"?e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:n}):e.jsx(oe,{variant:"neutral",children:n})}function ls(t){return t==="builtin"?"Built-in":t==="installed"?"Installed":"Custom"}let mt=!1,os=null;function _t(t,s){mt=t,os=t?s??null:null}function cs(t,s){i.useEffect(()=>{if(!s)return;const n=a=>{a.key!=="Escape"||a.defaultPrevented||mt||(a.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[s,t])}function ht({dirty:t,pending:s,onSave:n,onCancel:a,saveLabel:l="Save changes",pendingLabel:u="Saving…",dirtyHint:g,submit:h,confirming:v,onConfirmingChange:p}){const[d,m]=i.useState(!1),S=i.useRef(null),x=i.useRef(null),j=v!==void 0,k=j?v:d,T=i.useRef(!1);i.useEffect(()=>{k?x.current?.focus():T.current&&document.activeElement===document.body&&S.current?.focus(),T.current=k},[k]);const y=i.useRef(null);i.useEffect(()=>{const _=y.current,$=_?.closest("[data-agents-pane]");if(!_||!$)return;const A=()=>$.style.setProperty("--lo-pane-footer-h",`${_.getBoundingClientRect().height}px`);A();const f=new ResizeObserver(A);return f.observe(_),()=>{f.disconnect(),$.style.removeProperty("--lo-pane-footer-h")}},[]);const N=_=>{j||m(_),p?.(_)};return i.useEffect(()=>{t||(j||m(!1),p?.(!1))},[t,j,p]),e.jsxs("div",{ref:y,"data-testid":"edit-footer","data-lo-pane-footer":!0,className:"sticky bottom-0 z-10 flex flex-wrap items-center gap-2 border-hairline border-t bg-canvas py-3",children:[e.jsx(E,{ref:S,type:h?"submit":void 0,variant:"primary",onClick:h?void 0:n,disabled:s,children:s?u:l}),k?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:g??"Discard your unsaved changes?"}),e.jsx(E,{variant:"danger",onClick:a,children:"Discard changes"}),e.jsx(E,{ref:x,variant:"ghost",onClick:()=>{N(!1),S.current?.focus()},children:"Keep editing"})]}):e.jsx(E,{variant:"ghost",onClick:()=>{mt&&os?.(),t?N(!0):a()},disabled:s,children:"Cancel"}),t&&!k?e.jsx("span",{className:"ms-auto text-meta text-ink-dim",children:"Unsaved changes"}):null]})}let nt=!1;function ds(){nt=!0}function us(){const t=nt;return nt=!1,t}function ha({rows:t=6}){return e.jsx("div",{className:"space-y-1","aria-hidden":"true",children:fa.slice(0,t).map(s=>e.jsx(ve,{className:"h-12 w-full"},s))})}const fa=["a","b","c","d","e","f","g","h"];function St(){return e.jsxs("div",{className:"space-y-8","aria-hidden":"true",children:[e.jsx(ve,{className:"h-7 w-64"}),e.jsx(ve,{className:"h-5 w-40"}),e.jsx(ve,{className:"h-28 w-full"}),e.jsx(ve,{className:"h-24 w-full"})]})}function Ct({title:t,what:s,meaning:n,onRetry:a,retrying:l=!1}){return e.jsxs("div",{role:"alert",className:"max-w-xl space-y-2",children:[e.jsx("h2",{className:"text-heading",children:t}),e.jsx("p",{className:"text-body-sm text-ink",children:s}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:n}),e.jsx(E,{variant:"secondary",onClick:a,disabled:l,children:l?"Retrying…":"Retry"})]})}function he({label:t,htmlFor:s,error:n}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("label",{htmlFor:s,className:"text-body-sm text-ink-muted",children:t}),n?e.jsx("span",{className:"text-meta text-danger",role:"alert",children:n}):null]})}const ga=/^[A-Za-z0-9_.:-]{1,128}$/;function pe(t){return{description:t.description??"",instructions:t.instructions??"",tools:t.tools&&t.tools.length>0?[...t.tools]:null,effort:t.effort??"inherit",delegate:t.delegate??!1}}function pa(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.instructions!==t.instructions&&(n.instructions=s.instructions),JSON.stringify(s.tools)!==JSON.stringify(t.tools)&&(n.tools=s.tools??[]),s.effort!==t.effort&&(n.effort=s.effort),s.delegate!==t.delegate&&(n.delegate=s.delegate),n}function xa({profile:t}){const s=[ls(t.source),De(t)==="proactive"?ns.proactive:null,t.delegate?"Delegates":null,t.kind==="specialist"?"Specialist":null].filter(Boolean);return e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("p",{className:"text-body-sm text-ink-muted",children:s.join(" · ")}),t.divergent_fields?.length?e.jsx(oe,{variant:"warning",children:"Modified"}):null]})}const ba=5e3;let Qe=null;function ja({profile:t,displayedName:s,notice:n,onNotice:a,onChanged:l}){const u=De(t),[g,h]=i.useState(null),[v,p]=i.useState(!1),d=i.useRef(null),m=i.useId();i.useEffect(()=>{g!==null&&u===g&&h(null)},[u,g]),i.useEffect(()=>{const j=Qe;!j||j.name!==t.name||(Qe=null,!(Date.now()-j.at>ba)&&d.current?.focus())},[t.name]);const S=g??u,x=async j=>{if(!(v||j===S)){Qe={name:t.name,at:Date.now()},a(null),h(j),p(!0);try{await Gn(t,j,(k,T)=>k.op==="profiles.install"?X({op:"profiles.install",name:k.name,requestId:T}):X({op:"profiles.update",name:k.name,requestId:T,fields:k.fields??{}})),l(t.name),ke(j==="proactive"?`${s} is now proactive — it may message you on its own.`:`${s} is now reactive — proactive messaging stopped.`)}catch(k){h(null);const T=k instanceof is?k.completed:[],y=Jn(k,T);a(y),Me(y),l(t.name)}finally{p(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex items-center gap-2 text-body-sm",children:[e.jsx(He,{ref:d,checked:S==="proactive","aria-disabled":v,"aria-labelledby":m,"data-testid":"agent-class-switch",className:"after:absolute after:inset-0 after:content-['']",onCheckedChange:j=>void x(j?"proactive":"reactive")}),e.jsx("span",{id:m,className:"text-ink",children:"Can message me on its own"}),e.jsx("span",{"aria-live":"polite",className:"text-ink-muted",children:v?"Switching…":S==="proactive"?"On":"Off"})]}),e.jsx("p",{className:"text-body-sm text-ink",children:Kn[S]}),e.jsx("p",{className:"text-meta text-ink-muted",children:Wn[S]}),t.source==="builtin"?e.jsx("p",{className:"text-meta text-ink-muted",children:as}):null,n?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-class-error",children:[e.jsx(de,{children:"The switch did not go through"}),e.jsx(me,{children:n})]}):null]})}function ms({tools:t,onChange:s,error:n}){const[a,l]=i.useState(""),[u,g]=i.useState(null),h=i.useId(),v=()=>{const p=a.trim();if(p){if(!ga.test(p)){g("Tool names are letters, digits, dot, underscore, dash or colon.");return}if(t?.includes(p)){g("That tool is already listed.");return}g(null),l(""),s([...t??[],p])}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:t===null,onCheckedChange:p=>s(p?null:[]),"aria-label":"Give this agent every tool"}),e.jsx("span",{children:"All tools"})]}),t===null?e.jsx("p",{className:"text-meta text-ink-muted",children:"This agent may use whatever the session offers."}):e.jsxs(e.Fragment,{children:[t.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.map(p=>e.jsx("li",{children:e.jsxs(oe,{variant:"outline",children:[p,e.jsx(E,{variant:"ghost",size:"sm","aria-label":`Remove ${p}`,onClick:()=>s(t.filter(d=>d!==p)),className:"ms-1 h-4 px-1",children:"×"})]})},p))}):e.jsx("p",{className:"text-meta text-ink-muted",children:"No tools yet. Add one below, or turn on All tools."}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(he,{label:"Add a tool",htmlFor:h,error:u??n}),e.jsx(Ne,{id:h,value:a,inputSize:"md",placeholder:"Tool name","aria-invalid":!!(u??n),onChange:p=>{l(p.target.value),g(null)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),v())}})]}),e.jsx(E,{variant:"secondary",onClick:v,disabled:!a.trim(),children:"Add"})]})]})]})}function va({profile:t,displayedName:s,classNotice:n,onClassNotice:a,teams:l,effortTiers:u,askEnabled:g,onSaved:h,onDuplicate:v,onOpenTeam:p,onAskAgent:d,onDirtyChange:m,belowHeader:S}){const[x,j]=i.useState(!1),[k,T]=i.useState(()=>pe(t)),[y,N]=i.useState(()=>pe(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),[z,te]=i.useState(!1),ne=i.useRef(null),Z=i.useRef(t.definition_revision),M=dt(),q=JSON.stringify(y)!==JSON.stringify(k);i.useEffect(()=>(m?.(x&&q),()=>m?.(!1)),[m,x,q]),i.useEffect(()=>{us()&&requestAnimationFrame(()=>ne.current?.focus())},[]),i.useEffect(()=>{if(x&&q)return;const I=pe(t);T(I),N(I)},[t,x,q]),i.useEffect(()=>{if(!x){P(!1);return}const I=pe(t);P(q&&JSON.stringify(I)!==JSON.stringify(k))},[t,x,q,k]);const se=()=>{j(!1),f(null),C(null),w(!1),te(!1);const I=pe(t);T(I),N(I),Z.current=t.definition_revision};cs(()=>{if(z){te(!1);return}q?te(!0):se()},x);const Y=async I=>{if(I?.preventDefault(),_)return;const F=pa(k,y);if(Object.keys(F).length===0){se();return}if(typeof F.instructions=="string"&&!F.instructions.trim()){f("Give the agent instructions."),C("instructions");return}$(!0),f(null),C(null);try{const V=await X({op:"profiles.update",name:t.name,requestId:crypto.randomUUID(),fields:F,expectedDefinitionRevision:Z.current});j(!1),w(!1);const G=pe(V);T(G),N(G),Z.current=V.definition_revision,h(V.name),ke(`Saved ${V.name}.`),requestAnimationFrame(()=>ne.current?.focus())}catch(V){const G=Ae(V instanceof Error?V.message:"The agent could not be saved.");f(G.message),C(G.field);const ae=V?.status;if(V?.code==="local-concurrent-edit"){P(!0),$(!1);return}const re=typeof ae=="number"&&ae!==408&&ae>=400&&ae<500;w(!re),re||Me("The save could not be confirmed. Check whether it was applied before retrying.")}finally{$(!1)}},H=async()=>{if(!_){$(!0),f(null);try{const I=await X({op:"profiles.install",name:t.name,requestId:crypto.randomUUID()}),F=pe(I);T(F),N(F),h(I.name),ke(`Installed ${I.name}. It can be edited now.`),requestAnimationFrame(()=>ne.current?.focus())}catch(I){const F=Ae(I instanceof Error?I.message:"The agent could not be installed.");f(F.message),Me(F.message)}finally{$(!1)}}},Q=(l??[]).filter(I=>I.manager===t.name||(I.members??[]).some(F=>F.role===t.name)),fe=t.source==="builtin";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:ne,tabIndex:-1,title:s,className:"truncate text-title focus:outline-none",children:s}),e.jsx(xa,{profile:t})]}),x?null:e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"agent",name:t.name}),M("/chat")},children:"New chat"}),fe?e.jsxs(E,{variant:"secondary",onClick:H,disabled:_,children:[e.jsx(gn,{className:"size-4"}),_?"Installing…":"Install to edit"]}):e.jsx(E,{variant:"secondary",onClick:()=>{j(!0),f(null),C(null),Z.current=t.definition_revision},children:"Edit"}),g?e.jsx(E,{variant:"ghost",onClick:()=>d(`Change the agent ${t.name}: `),children:"Ask for a change"}):null,e.jsxs(tn,{children:[e.jsx(sn,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon","aria-label":"More actions",className:"-mr-2",children:e.jsx(ws,{"aria-hidden":"true"})})}),e.jsx(nn,{align:"end",children:e.jsx(an,{onSelect:()=>v(t),children:"Duplicate as new agent"})})]})]})]}),fe?e.jsxs(ce,{variant:"info",children:[e.jsx(de,{children:"Built-in agent"}),e.jsx(me,{children:"This one ships with the app and cannot be edited in place. Install it to get an editable copy, or duplicate it as a new agent."})]}):null,B?e.jsxs(ce,{variant:"warning","data-testid":"agent-conflict",children:[e.jsx(de,{children:"This changed while you were editing"}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:"Something else — a configuration run, or another window — wrote to this agent after you opened it. Your edits are kept; saving writes only the fields you changed."}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:se,children:"Reload the saved version"})]})]}):null,R?e.jsxs(ce,{variant:"danger","data-testid":"agent-unconfirmed",children:[e.jsx(de,{children:"The last save was not confirmed"}),e.jsx(me,{children:"The backend did not answer, so the write may or may not have landed. Check the agent below, then edit again."})]}):null,A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),S,e.jsx("form",{noValidate:!0,onSubmit:I=>{I.preventDefault(),Y(I)},className:"space-y-8",children:x?e.jsxs(e.Fragment,{children:[e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:y.description,error:o==="description"?A:null,onChange:I=>N(F=>({...F,description:I}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:y.instructions,rows:12,required:!0,error:o==="instructions"?A:null,onChange:I=>N(F=>({...F,instructions:I}))}),e.jsx(U,{title:"Tools",children:e.jsx(ms,{tools:y.tools,error:o==="tools"?A:null,onChange:I=>N(F=>({...F,tools:I}))})}),e.jsx(U,{title:"Delegation and effort",description:"Whether this agent may hand work to subagents, and which effort tier it runs at.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:y.delegate,onCheckedChange:I=>N(F=>({...F,delegate:I})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-effort",error:o==="effort"?A:null}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,placeholder:"Choose an effort tier",busyLabel:"Loading effort tiers",options:["inherit",...u].map(I=>({id:I,name:I,description:I==="inherit"?"Use the session's own effort":void 0})),selected:{id:y.effort,name:y.effort},onSelect:I=>N(F=>({...F,effort:I.id})),helperText:"Tiers come from the backend's subagent model settings."})]})]})}),e.jsx(ht,{submit:!0,confirming:z,onConfirmingChange:te,dirty:q,pending:_,onSave:()=>void Y(),onCancel:se,saveLabel:"Save changes",dirtyHint:"Discard your unsaved changes to this agent?"})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"When to use it",children:e.jsx(ye,{text:t.description||"",empty:"No description yet — add one so a model knows when to pick this agent."})}),e.jsx(U,{title:"Instructions",children:e.jsx(ye,{text:t.instructions??t.packaged_instructions??"",empty:"No instructions yet."})}),e.jsx(U,{title:"Tools",children:t.tools&&t.tools.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.tools.map(I=>e.jsx("li",{children:e.jsx(oe,{variant:"outline",children:I})},I))}):e.jsx(oe,{variant:"neutral",children:"All tools"})}),e.jsxs(U,{title:"Delegation and effort",children:[e.jsx("p",{className:"text-body-sm text-ink",children:t.delegate?"May hand work to subagents.":"Does its own work; it does not delegate."}),e.jsxs("p",{className:"text-body-sm text-ink-muted",children:["Effort tier: ",t.effort??"inherit"]}),t.effort&&Q.length?e.jsx("p",{className:"text-body-sm text-ink-muted",children:r("ui.agents.models.pin_reach",{count:Q.length,teams:Q.map(I=>I.name).join(", ")})}):null]}),e.jsx(U,{title:"Messaging",description:"Reactive agents only reply. Proactive agents may also message you first.",children:e.jsx(ja,{profile:t,displayedName:s,notice:n,onNotice:a,onChanged:h})}),e.jsx(U,{title:"Used by",description:"Teams that name this agent as a manager or a member.",children:Q.length>0?e.jsx("ul",{className:"flex flex-wrap gap-x-3 gap-y-1",children:Q.map(I=>e.jsx("li",{children:e.jsx(E,{variant:"link",className:K("-my-0.5",ut),onClick:()=>p(I.name),children:I.name})},I.id))}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:"No team uses it yet."})}),e.jsxs(U,{title:"Where it came from",description:t.source==="builtin"?"Shipped with the app.":t.source==="installed"?"Installed from a packaged starter.":"Created on this machine.",children:[e.jsxs("dl",{className:"space-y-1 text-body-sm",children:[t.seed_origin?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Source"}),e.jsx("dd",{className:"text-ink",children:t.seed_origin})]}):null,t.divergent_fields?.length?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Changed from the packaged copy"}),e.jsx("dd",{className:"text-ink",children:t.divergent_fields.join(", ")})]}):null]}),t.packaged_instructions&&t.divergent_fields?.length?e.jsx(rt,{summary:"Compare with the packaged instructions",className:"mt-2",children:e.jsx(ye,{text:t.packaged_instructions,mono:!0})}):null]})]})})]})}function qe({title:t,description:s,label:n,value:a,onChange:l,rows:u,required:g,error:h,fieldRef:v}){const p=i.useId();return e.jsxs(U,{title:t,description:s,children:[e.jsx(he,{label:n,htmlFor:p,error:h}),u?e.jsx(st,{id:p,ref:v,value:a,rows:u,required:g,"aria-invalid":!!h,className:K("min-h-0"),onChange:d=>l(d.target.value)}):e.jsx(Ne,{id:p,value:a,"aria-invalid":!!h,onChange:d=>l(d.target.value)})]})}function ya({initial:t,takenNames:s,effortTiers:n,onDirtyChange:a,onSaved:l,onCancel:u}){const[g,h]=i.useState(()=>t?Hn(t.name,s):""),[v,p]=i.useState(t?.kind??"role"),[d,m]=i.useState(()=>t?{...pe(t),description:t.description??""}:{description:"",instructions:"",tools:null,effort:"inherit",delegate:!1}),[S,x]=i.useState(!1),[j,k]=i.useState(null),[T,y]=i.useState(null),N=i.useRef(null),_=i.useRef(null);i.useEffect(()=>(a?.(!!(g.trim()||d.instructions.trim())),()=>a?.(!1)),[a,g,d.instructions]),i.useEffect(()=>{N.current?.focus(),N.current?.select()},[]);const $=async f=>{if(f?.preventDefault(),!S){if(!g.trim()){k("Give the agent a name."),y("name"),N.current?.focus();return}if(/[\\/\s]/.test(g.trim())){k("Names cannot contain spaces or slashes."),y("name"),N.current?.focus();return}if(s.includes(g.trim())){k(`An agent called “${g.trim()}” already exists. Choose another name, or open the existing one to change it.`),y("name"),N.current?.focus();return}if(!d.instructions.trim()){k("Give the agent instructions."),y("instructions"),_.current?.focus();return}x(!0),k(null),y(null);try{const o=await X({op:"profiles.create",requestId:crypto.randomUUID(),name:g.trim(),fields:{kind:v,description:d.description,instructions:d.instructions,tools:d.tools??[],effort:d.effort,delegate:d.delegate}});ke(`Created ${o.name}.`),ds(),l(o.name)}catch(o){const C=Ae(o instanceof Error?o.message:"The agent could not be created.");k(C.message),y(C.field)}finally{x(!1)}}},A=t?"Duplicate as a new agent":"New agent";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("h2",{className:"text-title",children:A}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:t?`A copy of ${t.name}. It is a separate agent: changing it does not change the original.`:"Reusable instructions shared by agent commands, subagents and teams. Chats stay separate."})]}),j&&!T?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-create-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:j})]}):null,e.jsxs("form",{noValidate:!0,onSubmit:f=>{f.preventDefault(),$(f)},className:"space-y-8",children:[e.jsx(U,{title:"Name and role",children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Name",htmlFor:"agent-create-name",error:T==="name"?j:null}),e.jsx(Ne,{id:"agent-create-name",ref:N,value:g,required:!0,"aria-invalid":T==="name",onChange:f=>h(f.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"How it works with others",htmlFor:"agent-create-kind"}),e.jsxs($e,{value:v,onValueChange:f=>p(f),children:[e.jsx(Le,{id:"agent-create-kind",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"role",children:"You can chat with it directly"}),e.jsx(xe,{value:"specialist",children:"Other agents can call on it"})]})]})]})]})}),e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:d.description,error:T==="description"?j:null,onChange:f=>m(o=>({...o,description:f}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:d.instructions,rows:12,required:!0,fieldRef:_,error:T==="instructions"?j:null,onChange:f=>m(o=>({...o,instructions:f}))}),e.jsx(U,{title:"Delegation and effort",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:d.delegate,onCheckedChange:f=>m(o=>({...o,delegate:f})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-create-effort"}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,busyLabel:"Loading effort tiers",placeholder:"Choose an effort tier",options:["inherit",...n].map(f=>({id:f,name:f,description:f==="inherit"?"Use the session's own effort":"A tier configured in Settings"})),selected:{id:d.effort,name:d.effort},onSelect:f=>m(o=>({...o,effort:f.id}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:"Tools"}),e.jsx(ms,{tools:d.tools,error:T==="tools"?j:null,onChange:f=>m(o=>({...o,tools:f}))})]})]})}),e.jsx(ht,{submit:!0,dirty:!!(g.trim()||d.instructions),pending:S,saveLabel:t?"Create the copy":"Create agent",pendingLabel:"Creating…",dirtyHint:"Discard this new agent?",onSave:()=>void $(),onCancel:u})]})]})}function hs(t,s,n=Date.now()){const a=Date.parse(t.expires_at);return t.local_fingerprint.length>0&&t.proposal_fingerprint.length>0&&t.link_id===s.link_id&&(t.direction==="push"||t.remote_fingerprint.length>0)&&t.proposal.kind===s.kind&&t.hub_source===s.hub_source&&t.visibility===s.visibility&&t.tenant_id===s.tenant_id&&t.expected_policy_revision===s.policy.revision&&t.expected_remote_revision===s.remote_revision&&Number.isFinite(a)&&a>n}function Et(t,s,n=Date.now()){return t.can_confirm&&t.preview_receipt.length>0&&hs(t,s,n)}const Ze=t=>Number.isFinite(Date.parse(t))?Ss(new Date(t)):r("ui.hub.status.unknown"),ka=t=>[t.pull.state,t.push.state].some(s=>["checking","merging","applying","pushing"].includes(s));function Na({link:t}){Te();const s=Ps(t.link_id),n=lt(t),a=Bs(t),[l,u]=i.useState(null),[g,h]=i.useState(null),[v,p]=i.useState(null),[d,m]=i.useState(!1),[S,x]=i.useState(!1),j=i.useRef(null),k=i.useId(),T=s.isPending||ka(t),y=!xt(t.baseline_state),N=l??g;i.useEffect(()=>{N&&!hs(N,t)&&(u(null),h(null),x(!0))},[t,N]),i.useEffect(()=>{if(!N)return;const f=Date.parse(N.expires_at)-Date.now(),o=setTimeout(()=>{u(null),h(null),x(!0)},Math.max(0,Math.min(f,2147483647)));return()=>clearTimeout(o)},[N]);const _=f=>{T||(f.action==="preview"&&x(!1),s.mutate(f,{onSuccess:o=>{if(f.action==="preview")u(o.preview?.direction==="push"?o.preview:null);else if(f.action==="apply"&&f.preview){const C=o.preview?.direction==="pull"?o.preview:null;h(C),p(JSON.stringify(o.reports,null,2)),m(C?.choices.acknowledge_unknown_baseline??!1)}else u(null),h(null)},onError:o=>{o instanceof Be&&["publication-preview-changed","application-preview-changed","remote-revision-changed"].includes(o.code??"")&&(u(null),h(null),x(!0))}}))},$=()=>{s.isPending||(u(null),h(null))},A=f=>r(f==="pull"?"ui.hub.links.direction_pull":"ui.hub.links.direction_push");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-4 py-4","data-hub-link":t.link_id,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"break-words text-heading text-ink",children:n}),e.jsx("p",{className:"break-words text-meta text-ink-muted",children:t.name}),e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.links.source_address",{address:t.hub_source})})]}),e.jsx(Kt,{link:t}),e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:["pull","push"].map(f=>{const o=t[f];return e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1","data-hub-direction":f,children:[e.jsx("h4",{className:"text-body-sm text-ink",children:A(f)}),e.jsx("p",{className:K("text-body-sm",o.state==="failed"?"text-danger":o.state==="available"?"text-accent":"text-ink-muted"),children:Us(o)}),o.error_class&&e.jsx("p",{className:"text-meta text-warning",children:et(o.error_class)}),o.last_checked_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.last_checked",{time:Ze(o.last_checked_at)})}),o.last_success_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.last_success",{time:Ze(o.last_success_at)})}),o.next_retry_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.next_retry",{time:Ze(o.next_retry_at)})}),o.model_used&&e.jsx("p",{className:"break-words text-meta text-ink-muted",children:r("ui.hub.links.actual_model",{model:o.model_used})}),o.operation_id&&e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.status.receipt",{operation:o.operation_id})}),a[f].retryable&&(f==="pull"||t.policy.auto_push)&&e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"retry",linkId:t.link_id,direction:f}),children:r("ui.hub.links.retry")})]},f)})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"check",linkId:t.link_id}),children:r("ui.hub.subscriptions.check")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0}),children:r("ui.hub.links.preview_pull")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite||!t.remote_revision||!xt(t.baseline_state)||t.visibility==="org"&&!t.tenant_name,onClick:()=>_({action:"preview",linkId:t.link_id}),children:r("ui.hub.subscriptions.preview_publish")})]}),S&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.preview_changed")}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(s.variables?.action==="preview"||s.variables?.action==="confirm"?"push":"pull"),item:t.name,source:n})}),s.data?.reports.filter(f=>f.link_id===t.link_id).map((f,o)=>e.jsx("output",{className:"text-meta text-ink-muted",children:r("ui.hub.links.action_result",{direction:A(f.direction),item:t.name,source:n,outcome:f.outcome})},`${f.operation_id??f.direction}-${o}`)),e.jsx(Jt,{open:l!==null||g!==null,onOpenChange:f=>{f||$()},children:e.jsxs(Yt,{className:"max-w-3xl",closeDisabled:s.isPending,onOpenAutoFocus:f=>{f.preventDefault(),j.current?.focus()},onEscapeKeyDown:f=>{s.isPending&&f.preventDefault()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:l?r("ui.hub.links.preview_payload",{source:n}):r("ui.hub.links.preview_pull")}),e.jsx(Xt,{children:l||!y?r("ui.hub.subscriptions.enable_safety"):r("ui.hub.links.unknown_baseline")})]}),e.jsx("pre",{className:"max-h-[50vh] overflow-auto whitespace-pre-wrap break-words rounded-md bg-sunken p-3 text-mono-sm text-ink",children:JSON.stringify(N?.proposal,null,2)}),N?.warnings.length?e.jsxs("div",{children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.preview_warnings")}),N.warnings.map((f,o)=>e.jsx("p",{className:"break-words text-body-sm text-warning",children:f},`${o}-${f}`))]}):null,N?.reason&&e.jsx("p",{className:"text-body-sm text-warning",children:et(N.reason)}),g&&v&&e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words bg-sunken p-3 text-mono-sm text-ink",children:v}),g&&y&&e.jsxs("label",{htmlFor:k,className:"flex items-start gap-2 text-body-sm text-ink",children:[e.jsx(rn,{id:k,checked:d,onCheckedChange:f=>m(f===!0)}),r("ui.hub.links.acknowledge_baseline")]}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(l?"push":"pull"),item:t.name,source:n})}),e.jsxs(es,{children:[e.jsx(E,{ref:j,variant:"outline",disabled:s.isPending,onClick:$,children:r("ui.hub.subscriptions.cancel")}),l?e.jsx(E,{disabled:s.isPending||!s.canWrite||!Et(l,t),onClick:()=>_({action:"confirm",linkId:t.link_id,previewReceipt:l.preview_receipt}),children:r("ui.hub.links.confirm_publish")}):e.jsxs(e.Fragment,{children:[["local","remote"].map(f=>e.jsx(E,{variant:"outline",disabled:s.isPending||!s.canWrite||y&&!d,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0,prefer:f,acknowledgeUnknownBaseline:y&&d}),children:r(f==="local"?"ui.hub.links.prefer_local":"ui.hub.links.prefer_remote")},f)),e.jsx(E,{disabled:s.isPending||!s.canWrite||!g||!Et(g,t)||g.choices.acknowledge_unknown_baseline!==d||g.choices.replace!==null||g.choices.confirm_replace,onClick:()=>{g&&_({action:"apply",linkId:t.link_id,previewReceipt:g.preview_receipt,confirmApply:!0,prefer:g.choices.prefer??void 0,acknowledgeUnknownBaseline:g.choices.acknowledge_unknown_baseline})},children:r("ui.hub.subscriptions.pull")})]})]})]})})]})}function wa({row:t,source:s,organizations:n,isAuthenticated:a,onSignIn:l,initialOpen:u,onResolved:g}){Te();const[h,v]=i.useState(u??!1),[p,d]=i.useState(""),m=Ms(g),S=i.useRef(null),x=i.useRef(null),j=i.useRef(!1);i.useEffect(()=>{h?S.current?.focus():j.current&&(j.current=!1,x.current?.focus())},[h]);const k=p!=="public"&&p!=="",T=k?n.find(_=>_.tenant_id===p):null,N=p!==""&&(!k||!!T)&&(k||p==="public");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-3","data-hub-source-unresolved":t.local_id,children:[e.jsx(ce,{variant:"warning",className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[m.upgradeMessage&&e.jsx("output",{className:"block text-meta text-warning","data-hub-core-upgrade":!0,children:m.upgradeMessage}),e.jsx(de,{"data-hub-unresolved-label":!0,children:r("ui.hub.links.source_not_confirmed")}),e.jsx("h3",{className:"break-words text-body-sm font-medium text-ink",children:t.name}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_what",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_why",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_next")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.source_address",{address:s})}),e.jsx("p",{className:"break-all text-mono-sm text-ink-muted",children:r("ui.hub.links.hub_id",{address:t.hub_id})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_irreversible")}),h?null:e.jsx(E,{ref:x,variant:"primary",size:"sm",className:"self-start",onClick:()=>v(!0),children:r("ui.hub.links.resolve_action")})]})}),h?e.jsxs("div",{ref:S,tabIndex:-1,className:"flex flex-col gap-2 outline-none",children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.resolve_title")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_description",{item:t.name})}),a?e.jsxs("label",{className:"text-body-sm text-ink",children:[r("ui.hub.links.scope_label"),e.jsxs("select",{className:"mt-1 w-full rounded-md border border-control bg-surface px-2 py-1 text-body-sm text-ink",value:p,disabled:m.isPending,onChange:_=>d(_.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("ui.hub.links.scope_placeholder")}),e.jsx("option",{value:"public",children:r("ui.hub.links.scope_public")}),n.map(_=>e.jsx("option",{value:_.tenant_id,children:r("ui.hub.links.scope_private",{organization:_.tenant_name})},_.tenant_id))]})]}):e.jsx(E,{variant:"outline",onClick:l,children:r("ui.hub.links.sign_in_to_publish")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",disabled:m.isPending,onClick:()=>{j.current=!0,v(!1)},children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:m.isPending||!m.canWrite||!N,onClick:()=>m.mutate({kind:t.kind,localId:t.local_id,name:t.name,hubSource:s,visibility:k?"org":"public",tenantId:k?T?.tenant_id??null:null}),children:m.isPending?r("ui.hub.links.resolve_action_confirming"):m.isSuccess?r("ui.hub.links.resolve_action_done"):r("ui.hub.links.resolve_action_confirm")})]}),!N&&!m.isPending&&a?e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.scope_required")}):null,m.error?e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:m.error instanceof tt?m.error.message:m.error instanceof Be&&m.error.code==="origin-conflict"?r("ui.hub.links.resolve_conflict"):m.error instanceof Be&&m.error.code?et(m.error.code):r("ui.hub.links.resolve_failed_generic")}):null]}):null]})}function _a({enabled:t,kind:s,name:n,localId:a}){Te();const l=zt(t),{isAuthenticated:u}=Bt(),g=dt(),[h]=Ut(),v=h.get("resolve"),p=v!==null,{memberships:d}=Ht({enabled:t&&u}),m=ts(d).map(w=>({tenant_id:w.tenant_id,tenant_name:w.tenant_name})),S=_s.radientBaseUrl;if(!t)return null;const x=s&&n?Fs(l.data,s,a,n):l.data?.links.filter(w=>!s||w.kind===s)??[],j=(l.data?.unresolved??[]).filter(w=>(!s||w.kind===s)&&(!n||(a?w.local_id===a:w.name===n))),k=w=>r(w?"ui.hub.subscriptions.configured_on":"ui.hub.subscriptions.configured_off"),T=w=>{const B=x[0]?w(x[0]):!1;return x.every(P=>w(P)===B)},y=w=>T(w)?k(w(x[0])):r("ui.hub.links.mixed"),N=(()=>{if(x.length===0)return"";const w=x[0],B=x.length>1?` · ${r("ui.hub.links.sources_count",{count:x.length})}`:"";return`${lt(w)}${B} · ${r("ui.hub.subscriptions.subscribe")} ${y(P=>P.policy.subscribe)} · ${r("ui.hub.subscriptions.auto_push")} ${y(P=>P.policy.auto_push)}`})(),_=x.some(w=>[w.pull.state,w.push.state].some(B=>B==="available"||B==="failed")),$=i.useRef(null),[A,f]=i.useState(!1);i.useEffect(()=>{!A||x.length===0||($.current?.querySelector("button[aria-expanded]")?.focus(),f(!1))},[A,x]);const[o,C]=i.useState(_),R=i.useRef(_);return i.useEffect(()=>{_&&!R.current&&C(!0),R.current=_},[_]),l.isLoading?null:l.error&&!l.data?e.jsxs("div",{className:"flex flex-col items-start gap-2",children:[e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.load_failed")}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>void l.refetch(),children:r("ui.hub.links.retry")})]}):x.length===0&&j.length===0?null:e.jsxs("div",{ref:$,className:"flex min-w-0 flex-col gap-3","data-hub-links-panel":!0,children:[j.map(w=>e.jsx(wa,{row:w,source:S,organizations:m,isAuthenticated:u,onSignIn:()=>g("/settings"),initialOpen:p,onResolved:()=>f(!0)},`${w.kind}:${w.local_id}:${v}`)),x.length>0?e.jsxs(rt,{open:o,onOpenChange:C,summary:`${r("ui.hub.links.title")} · ${N}`,className:"min-w-0",children:[e.jsx("div",{className:"divide-y divide-hairline",children:x.map(w=>e.jsx(Na,{link:w},w.link_id))}),l.error&&l.data&&e.jsx("p",{role:"alert",className:"text-meta text-warning",children:r("ui.hub.links.load_failed")})]}):null]})}const Sa=["lo","med","hi"],Ca=["auto","none","minimal","low","medium","high","xhigh","max"],Re="inherit";function It(t){return t??Re}function Ea(t){return t===Re?null:t}function Ia(t){return t===Re?null:t}function Aa(t,s){return{...t,...s.tier===void 0?{}:{tier:Ea(s.tier)},...s.effort===void 0?{}:{effort:Ia(s.effort)}}}function at(t){const{tier:s,effort:n,key:a,...l}=t;return JSON.stringify({...l,...s?{tier:s}:{},...n?{effort:n}:{}})}function Ra(t,s){const n=`${s.kind}\0${s.role.toLocaleLowerCase()}`;return(t?.members??[]).find(a=>`${a.kind}\0${a.role.toLocaleLowerCase()}`===n)??null}const Ta={team:"ui.agents.models.source.team",row:"ui.agents.models.source.row",none:"ui.agents.models.source.none"},Da={team:"ui.agents.models.source.team",tier:"ui.agents.models.source.tier",model_default:"ui.agents.models.source.model_default"},fs=t=>Ta[t],$a=t=>Da[t];function La(t){return t.isSuccess?"available":t.isError&&Oa(t.error)?"unavailable":"absent"}function Oa(t){return Ys(t)!=="outdated"}function Fa({team:t}){Te();const s=i.useId(),n=ze(),{isAuthenticated:a}=Bt(),l=ee(n.data,"hub_links"),[u,g]=i.useState(!1),[h,v]=i.useState(null),[p,d]=i.useState(Je),m=i.useRef(null),S=i.useRef(null),x=zt(l),j=Ht({enabled:u&&a&&ee(n.data,"radient_org")}),k=ts(j.memberships),T=h?k.find(R=>R.tenant_id===h):null,y=h?T?.tenant_name?r("ui.hub.links.source_private",{organization:T.tenant_name}):r("ui.hub.links.source_unavailable"):r("ui.hub.links.source_public"),N=(x.data?.links??[]).filter(R=>R.kind==="team"&&R.local_id===t.id),_=N.find(R=>R.visibility===(h?"org":"public")&&R.tenant_id===h),$=N.find(R=>R.link_id!==_?.link_id),A=x.data?.unresolved.some(R=>R.kind==="team"&&R.local_id===t.id),f=ct(),o=Cs({mutationFn:async()=>{if(!a||_||!l||!x.isSuccess||$||A||h&&!T)throw new Error("hub-team-destination-not-ready");const R=JSON.stringify({id:t.id,target:h,policy:_?null:p}),w=m.current?.tuple===R?m.current:{tuple:R,id:crypto.randomUUID()};return m.current=w,X({op:"team.publish",teamId:t.id,requestId:w.id,...h?{visibility:"org",tenantId:h}:{},..._?{}:p})},onSuccess:()=>{f.invalidateQueries({queryKey:qs})}});if(!l||!u&&(N.length>0||A))return null;const C=!a||!x.isSuccess||!!_||!!$||!!A||!!h&&!T;return e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"outline",disabled:!a||!x.isSuccess,onClick:()=>{g(!0),v(null),d(Je()),m.current=null,o.reset()},children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Jt,{open:u,onOpenChange:R=>{o.isPending||g(R)},children:e.jsxs(Yt,{onOpenAutoFocus:R=>{R.preventDefault(),S.current?.focus()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Xt,{children:r("ui.hub.skills.initial_policy_description")})]}),e.jsx("label",{htmlFor:`${s}-target`,className:"text-body-sm text-ink",children:y}),e.jsxs("select",{id:`${s}-target`,disabled:o.isPending||o.isSuccess,value:h??"",className:"rounded-md border border-control bg-surface px-3 py-2 text-body-sm text-ink",onChange:R=>{v(R.target.value||null),d(Je()),m.current=null},children:[e.jsx("option",{value:"",children:r("ui.hub.links.source_public")}),k.map(R=>e.jsx("option",{value:R.tenant_id,children:R.tenant_name},R.tenant_id))]}),$?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.subscriptions.source_separation",{currentSource:lt($),newSource:y})}):A?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.links.source_unavailable")}):_?e.jsx(Kt,{link:_}):e.jsx(un,{value:p,onChange:d,source:y,item:t.name,visibility:h?"org":"public",organization:T?.tenant_name??null,destinationKey:`${t.id}:${h??"public"}`,canEnableAutoPush:!1,disabled:C||o.isPending||o.isSuccess}),x.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.load_failed")}),o.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.action_failed",{direction:r("ui.hub.links.direction_push"),item:t.name,source:y})}),o.isSuccess&&e.jsx("output",{className:"text-body-sm text-ink",children:mn(o.data)?r("ui.hub.links.published",{item:t.name,source:y}):r("ui.hub.skills.policy_pending")}),e.jsxs(es,{children:[e.jsx(E,{ref:S,variant:"outline",disabled:o.isPending,onClick:()=>g(!1),children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:C||o.isPending||o.isSuccess,onClick:()=>o.mutate(),children:r("ui.hub.links.confirm_publish")})]})]})})]})}function Ce(t){return{description:t?.description??"",manager:t?.manager??"manager",members:(t?.members??[]).map(s=>({...s,count:ft(s),key:crypto.randomUUID()})),instructions:t?.instructions??"",project:t?.project??""}}function Ma(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.manager!==t.manager&&(n.manager=s.manager),JSON.stringify(s.members.map(at))!==JSON.stringify(t.members.map(at))&&(n.members=s.members.map(({key:a,...l})=>l)),s.instructions!==t.instructions&&(n.instructions=s.instructions),s.project!==t.project&&(n.project=s.project),n}function At(t,s,n){return(t.kind==="agent"?(s??[]).map(l=>l.name):(n??[]).map(l=>l.name)).includes(t.role)}function Pa(t){return(t??[]).reduce((s,n)=>s+ft(n),0)}function ft(t){return t.count||1}function gs(t){const s=Pa(t);return s===1?"1 member":`${s} members`}function Rt(t){const s=t.tier.value?r("ui.agents.models.reading.tier_layer",{tier:t.tier.value,source:r(fs(t.tier.source))}):null;return t.model.value?{value:t.model.value,layer:s}:t.available?{value:r("ui.agents.models.reading.session_model"),layer:s}:{value:r("ui.agents.models.reading.not_resolved"),layer:s}}function Tt(t){const{requested:s,value:n,source:a}=t.effort,l=r($a(a));return s==="auto"?{value:r("ui.agents.models.reading.effort_auto"),layer:r("ui.agents.models.source.model_default")}:n&&s&&n!==s?{value:r("ui.agents.models.reading.effort_clamped",{requested:s,value:n}),layer:l}:n?{value:n,layer:l}:{value:r("ui.agents.models.reading.effort_default"),layer:a==="model_default"?null:l}}function Ba(t){return t.tier.value?r(fs(t.tier.source)):null}function Dt(t,s,n){return t.layer?r(n,{value:t.value,layer:t.layer}):r(s,{value:t.value})}function $t(t){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",title:t.value,children:t.value}),t.layer?e.jsx("span",{className:"block truncate text-meta text-ink-dim",title:t.layer,children:t.layer}):null]})}function Lt(t){return JSON.stringify({...t,members:t.members.map(at)})}function Ot(){return e.jsxs("colgroup",{children:[e.jsx("col",{}),e.jsx("col",{className:"w-24"}),e.jsx("col",{className:"w-16"})]})}function Ft({team:t,agents:s,teams:n,askEnabled:a,onSaved:l,onCancelCreate:u,onOpenAgent:g,onAskAgent:h,onDirtyChange:v,belowHeader:p}){const d=!t,[m,S]=i.useState(d),[x,j]=i.useState(t?.name??""),[k,T]=i.useState(()=>Ce(t)),[y,N]=i.useState(()=>Ce(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),z=i.useRef(t?.definition_revision),te=i.useRef(null),ne=i.useRef(null),Z=i.useRef(null),M=i.useRef(null),q=i.useRef(!1);i.useEffect(()=>{us()&&requestAnimationFrame(()=>te.current?.focus())},[]);const se=dt();Te();const W=ct(),Y=t?.name??n?.[0]?.name??null,H=Es(Y,!!Y),Q=La(H),fe=Q==="available",I=H.data&&H.data.team===t?.name?H.data:null,F=d?!!(x.trim()||y.description||y.members.length):Lt(y)!==Lt(k);i.useEffect(()=>(v?.((d||m)&&F),()=>v?.(!1)),[v,d,m,F]),i.useEffect(()=>{if(m&&F)return;const b=Ce(t);T(b),N(b)},[t,m,F]),i.useEffect(()=>{if(!q.current)return;q.current=!1;const b=M.current;typeof b?.scrollIntoView=="function"&&b.scrollIntoView({block:"nearest"})});const V=()=>{if(d){u?.();return}S(!1),f(null),C(null),w(!1),z.current=t?.definition_revision;const b=Ce(t);T(b),N(b)};cs(()=>{if(R){w(!1);return}F?w(!0):V()},m);const ae=async b=>{if(b?.preventDefault(),!_){if(d&&!x.trim()){f("Give the team a name."),C("name"),Z.current?.focus();return}if(d&&/[\\/\s]/.test(x.trim())){f("Names cannot contain spaces or slashes."),C("name"),Z.current?.focus();return}if(d&&(n??[]).some(c=>c.name===x.trim())){f(`A team called “${x.trim()}” already exists. Open it to change it, or choose another name.`),C("name"),Z.current?.focus();return}if(d&&!y.instructions.trim()){f("Give the team instructions."),C("instructions"),ne.current?.focus();return}$(!0),f(null),C(null);try{const c=t?await X({op:"teams.update",name:t.name,requestId:crypto.randomUUID(),fields:Ma(k,y),expectedDefinitionRevision:z.current}):await X({op:"teams.create",requestId:crypto.randomUUID(),fields:{name:x,description:y.description,manager:y.manager,members:y.members.map(({key:L,...O})=>O),instructions:y.instructions,project:y.project}}),D=Ce(c);T(D),N(D),P(!1),z.current=c.definition_revision,S(!1),l(c.name),H.refetch(),W.invalidateQueries({queryKey:["desktop","team"]}),ke(`${d?"Created":"Saved"} ${c.name}.`),d&&ds(),requestAnimationFrame(()=>te.current?.focus())}catch(c){if(c?.code==="local-concurrent-edit"){P(!0),f(null),C(null);return}const L=Ae(c instanceof Error?c.message:"The team could not be saved.");f(L.message),C(L.field),Me(L.message)}finally{$(!1)}}},ie=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?{...L,...c}:L)})),re=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?Aa(L,c):L)})),_e=y.members.length?y.members:t?.members,ge=t?qt(t):"New team",Se=y.members.some(b=>b.kind==="team");return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:te,tabIndex:-1,title:ge,className:"truncate text-title focus:outline-none",children:ge}),t?e.jsxs("p",{className:"text-body-sm text-ink-muted",children:[gs(_e),Se?" · Includes a team":""]}):null]}),t&&!m?e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs,a&&"-mr-3"),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"team",name:t.name}),se("/chat")},children:"New team chat"}),e.jsx(Fa,{team:t}),e.jsx(E,{variant:"secondary",onClick:()=>{z.current=t.definition_revision,S(!0)},children:"Edit"}),a?e.jsx(E,{variant:"ghost",onClick:()=>h(`Change the team ${t.name}: `),children:"Ask for a change"}):null]}):null]}),A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"team-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),p,m&&B?e.jsxs(ce,{variant:"warning","data-testid":"team-conflict",children:[e.jsx(de,{children:r("ui.hub.conflict.title")}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:r("ui.hub.conflict.body")}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:V,children:r("ui.hub.conflict.reload")})]})]}):null,e.jsx("form",{noValidate:!0,onSubmit:b=>{b.preventDefault(),ae(b)},className:"space-y-8",children:d||m?e.jsxs(e.Fragment,{children:[d?e.jsxs(U,{title:"Name",description:"How you and your chats will refer to this team.",children:[e.jsx(he,{label:"Team name",htmlFor:"team-name",error:o==="name"?A:null}),e.jsx(Ne,{ref:Z,id:"team-name","data-testid":"team-name-input",value:x,required:!0,maxLength:64,autoFocus:!0,"aria-invalid":o==="name",onChange:b=>j(b.target.value)})]}):null,e.jsx(U,{title:"Manager",description:"The agent that leads the chat and decides who works on what.",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{label:"Manager agent",htmlFor:"team-manager",error:o==="manager"?A:null}),e.jsx(Ue,{ariaLabel:"Manager agent",showLabel:!1,placeholder:"Choose a manager",busyLabel:"Loading agents",options:je(s,n),selected:je(s,n).find(b=>b.id===y.manager)??null,onSelect:b=>N(c=>({...c,manager:b.id})),onCustomSubmit:b=>N(c=>({...c,manager:b})),listNotice:"Agents and teams on this machine"}),je(s,n).some(b=>b.id===y.manager)?null:e.jsxs(oe,{variant:"warning","data-testid":"team-manager-missing",children:["Not found: ",y.manager]})]})}),e.jsxs(U,{title:"Members",description:"Who the manager can delegate to, how many of each, and the model each runs on.",children:[e.jsx("p",{"data-testid":"team-override-scope",className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),d&&!Y?e.jsx("p",{"data-testid":"team-override-no-probe",className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.no_probe_hint")}):null,Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null,e.jsxs("div",{className:"space-y-4",children:[y.members.map((b,c)=>{const D=!At(b,s,n),L=Ra(I??void 0,b);return e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_8rem_auto_auto] items-center gap-x-2 gap-y-1",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(Ue,{ariaLabel:`Member ${c+1}`,showLabel:!1,placeholder:"Choose an agent or team",busyLabel:"Loading agents",options:[...je(s,n).filter(O=>b.kind==="team"?O.group==="Teams":O.group==="Agents")],selected:je(s,n).find(O=>O.id===b.role)??null,onSelect:O=>ie(c,{role:O.id,kind:O.group==="Teams"?"team":"agent"}),onCustomSubmit:O=>ie(c,{role:O})})}),e.jsxs($e,{value:b.kind,onValueChange:O=>ie(c,{kind:O}),children:[e.jsx(Le,{"aria-label":`Member ${c+1} kind`,className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"agent",children:"Agent"}),e.jsx(xe,{value:"team",children:"Team"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One fewer ${b.role}`,disabled:b.count<=1,onClick:()=>ie(c,{count:b.count-1}),children:e.jsx(ln,{"aria-hidden":"true"})}),e.jsx("span",{className:"min-w-6 text-center text-body-sm tabular-nums","aria-label":`${b.count} of ${b.role}`,children:b.count}),e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One more ${b.role}`,disabled:b.count>=16,onClick:()=>ie(c,{count:b.count+1}),children:e.jsx(Wt,{"aria-hidden":"true"})})]}),e.jsx(E,{variant:"ghost",onClick:()=>N(O=>({...O,members:O.members.filter((Ga,ps)=>ps!==c)})),children:"Remove"}),D?e.jsxs(oe,{variant:"warning",className:"col-span-full w-fit",children:["Not found: ",b.role]}):null,fe?e.jsxs("div",{className:"col-span-full grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] items-end gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.tier_field")}),e.jsxs($e,{value:It(b.tier),onValueChange:O=>re(c,{tier:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.tier_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_tier")}),Sa.map(O=>e.jsx(xe,{value:O,children:O},O))]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.effort_field")}),e.jsxs($e,{value:It(b.effort),onValueChange:O=>re(c,{effort:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.effort_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_effort")}),Ca.map(O=>e.jsx(xe,{value:O,children:O==="auto"?r("ui.agents.models.override.auto"):O},O))]})]})]})]}):null,L?e.jsxs("div",{className:"col-span-full flex flex-wrap items-baseline gap-x-3 gap-y-1 text-meta",children:[e.jsx("span",{className:"text-ink-dim",children:r("ui.agents.models.reading.saved_label")}),e.jsx("span",{className:"text-ink-muted",children:Dt({value:Rt(L).value,layer:Ba(L)},"ui.agents.models.reading.model_cell","ui.agents.models.reading.model_cell_layer")}),e.jsx("span",{className:"text-ink-muted",children:Dt(Tt(L),"ui.agents.models.reading.effort_cell","ui.agents.models.reading.effort_cell_layer")})]}):null,L&&!L.available?e.jsxs("div",{className:"col-span-full",children:[e.jsx("p",{"data-testid":"team-member-unavailable",className:"text-meta text-danger",children:r("ui.agents.models.reading.unavailable_editor",{member:L.role||`Member ${c+1}`,reason:L.reason})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]}):null]},b.key)}),e.jsx(E,{ref:M,variant:"secondary",onClick:()=>{q.current=!0,N(b=>({...b,members:[...b.members,{role:"",count:1,kind:"agent",key:crypto.randomUUID()}]}))},children:"Add member"})]})]}),e.jsxs(U,{title:"Description",children:[e.jsx(he,{label:"What this team is for",htmlFor:"team-description",error:o==="description"?A:null}),e.jsx(Ne,{id:"team-description",value:y.description,onChange:b=>N(c=>({...c,description:b.target.value}))})]}),e.jsxs(U,{title:"Collaboration instructions",children:[o==="instructions"?e.jsx("p",{className:"text-meta text-danger",role:"alert","data-testid":"team-instructions-error",children:A}):null,e.jsx(st,{ref:ne,"aria-label":"Collaboration instructions","aria-invalid":o==="instructions",className:"min-h-36",maxLength:8e3,value:y.instructions,onChange:b=>N(c=>({...c,instructions:b.target.value}))})]}),e.jsx(U,{title:"Project brief",children:e.jsx(st,{"aria-label":"Project brief",className:"min-h-36",maxLength:8e3,value:y.project,onChange:b=>N(c=>({...c,project:b.target.value}))})}),e.jsx(ht,{submit:!0,confirming:R,onConfirmingChange:w,dirty:F,pending:_,saveLabel:d?"Create team":"Save changes",pendingLabel:d?"Creating…":"Saving…",dirtyHint:"Discard this team?",onSave:()=>void ae(),onCancel:V})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Manager",children:e.jsxs(We,{className:"table-fixed","aria-label":"Manager: the agent that leads the chat",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:e.jsxs(be,{className:"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(E,{variant:"link",className:K("-my-0.5 min-w-0 justify-start truncate",ut),onClick:()=>g(y.manager),children:y.manager}),je(s,n).some(b=>b.id===y.manager)?null:e.jsx(oe,{variant:"warning","data-testid":"team-manager-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:"Agent"}),e.jsx(le,{})]})})]})}),e.jsxs(U,{title:"Members",children:[e.jsxs(We,{className:"table-fixed","aria-label":"Members",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:(t?.members??[]).map(b=>e.jsxs(be,{className:"last:border-0",children:[e.jsx(le,{className:"px-0 py-2 text-ink",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate",children:b.role}),At(b,s,n)?null:e.jsx(oe,{variant:"warning","data-testid":"team-member-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:b.kind==="team"?"Team":"Agent"}),e.jsx(le,{className:"px-0 py-2 text-right text-ink-muted tabular-nums",children:`×${ft(b)}`})]},`${b.kind}:${b.role}`))})]}),Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null]}),fe&&I?.members.length?e.jsxs(U,{title:r("ui.agents.models.reading.title"),description:r("ui.agents.models.reading.description"),children:[e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),H.isFetching?e.jsx("p",{"data-testid":"team-effective-refreshing",className:"text-meta text-ink-dim",children:r("ui.agents.models.reading.refreshing")}):null,e.jsxs(We,{className:K("table-fixed",H.isFetching&&"opacity-60"),"aria-label":r("ui.agents.models.reading.title"),children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-24"}),e.jsx("col",{}),e.jsx("col",{className:"w-32"})]}),e.jsx(Ve,{children:e.jsxs(be,{children:[e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.member_col")}),e.jsx(ue,{className:"px-2",children:r("ui.agents.models.reading.model_col")}),e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.effort_col")})]})}),e.jsx(Ge,{children:I.members.map(b=>e.jsxs(i.Fragment,{children:[e.jsxs(be,{className:b.available?"last:border-0":"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsx("span",{className:"block truncate text-body-sm text-ink",title:b.role,children:b.role})}),e.jsx(le,{className:"px-2 py-2",children:$t(Rt(b))}),e.jsx(le,{className:"px-0 py-2",children:$t(Tt(b))})]}),b.available?null:e.jsx(be,{className:"last:border-0",children:e.jsxs(le,{colSpan:3,className:"px-0 pb-2",children:[e.jsx("span",{"data-testid":"team-effective-unavailable",className:"block text-meta text-danger",children:r("ui.agents.models.reading.unavailable",{member:b.role,reason:b.reason})}),e.jsx("span",{className:"block text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]})})]},`${b.kind}:${b.role}`))})]})]}):null,e.jsx(U,{title:"What it is for",children:e.jsx(ye,{text:t?.description??"",empty:"No description yet."})}),t?.instructions?e.jsx(U,{title:"Collaboration instructions",children:e.jsx(ye,{text:t.instructions})}):null,t?.project?e.jsx(rt,{summary:"Project brief",children:e.jsx(ye,{text:t.project})}):null]})})]})}function je(t,s){return[...(t??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Agents"})),...(s??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Teams"}))]}const Ua=i.lazy(()=>$s(()=>import("./legacy-agents-page-WYJ6UHsm.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]),import.meta.url).then(t=>({default:t.LegacyAgentsPage}))),Mt=/^subagents\.models\.([^.]+)$/,qa=["lo","med","hi"],Xe={all:"All",custom:"Custom",installed:"Installed",builtin:"Built-in"};function za(t){return!t||t.getAttribute("role")!=="tab"||t.getAttribute("aria-selected")==="true"?t:t.closest('[role="tablist"]')?.querySelector('[role="tab"][aria-selected="true"]')??null}function ni(){const{agentId:t}=Qs(),[s,n]=Ut(),a=s.get("kind")==="team"||s.get("create")==="team",l=s.has("create"),u=s.get("name"),g=s.get("duplicate"),h=ze(),v=ee(h.data,a?"team_catalogue":"profile_catalogue"),p=Is(v),d=As(v),m=v&&!!u&&!l,S=pt(a?null:u,m),x=Rs(a?u:null,m),j=pt(a?null:g,!!g),[k,T]=i.useState(""),[y,N]=i.useState("all"),[_,$]=i.useState(null),[A,f]=i.useState(null),o=ca(),C=J(c=>c.marks),R=J(c=>c.clearMark),w=Gt({queryKey:["desktop","settings","effort-tiers"],enabled:v,queryFn:()=>X({op:"settings.list"}),staleTime:6e4}),B=i.useMemo(()=>(w.data?.settings??[]).filter(c=>{const D=c.key.match(Mt)?.[1];return!D||!qa.includes(D)?!1:typeof c.value=="string"&&c.value.trim().length>0}).map(c=>c.key.match(Mt)?.[1]).filter(c=>!!c),[w.data]),P=zs(),z=i.useCallback(c=>Hs(c,P),[P]),te=i.useMemo(()=>Wa(p.data,k,y,z),[p.data,k,y,z]),ne=i.useMemo(()=>Va(d.data,k),[d.data,k]),Z=a?ne:te,M=u??null,[q,se]=i.useState(null);q!==null&&q.name!==M&&se(null);const W=i.useCallback(c=>{const D=new URLSearchParams;(c.kind??(a?"team":"agent"))==="team"&&D.set("kind","team"),c.name&&D.set("name",c.name),c.create!==null&&c.create!==void 0&&D.set("create",c.create),c.duplicate&&D.set("duplicate",c.duplicate),$(null),n(D)},[a,n]),Y=`${a?"team":"agent"}:${l??""}:${M??""}`,H=i.useCallback(c=>f(c?Y:null),[Y]),Q=A!==null&&A===Y,fe=(c,D,L)=>e.jsxs(e.Fragment,{children:[e.jsx(_a,{kind:c,name:D,localId:L,enabled:ee(h.data,"hub_links")}),e.jsx(hn,{kind:c,name:D,enabled:ee(h.data,"hub_updates")&&!ee(h.data,"hub_links")})]}),I=i.useRef(null),F=i.useRef(null),V=i.useRef(null),G=i.useCallback(c=>{if(Q){const D=F.current,L=document.activeElement;I.current=D?.isConnected&&D.closest("form")?D:L instanceof HTMLElement?L:null,$(c);return}W(c)},[Q,W]),ae=i.useCallback(()=>{$(null);const c=I.current;requestAnimationFrame(()=>{const D=za(c);D?.isConnected&&D.focus()})},[]),ie=_!==null;i.useEffect(()=>{if(!ie)return;_t(!0,()=>$(null)),V.current?.focus();const c=requestAnimationFrame(()=>{const L=V.current?.closest('[role="alertdialog"]');L&&!L.contains(document.activeElement)&&V.current?.focus()}),D=L=>{L.key!=="Escape"||L.defaultPrevented||(L.preventDefault(),ae())};return window.addEventListener("keydown",D),()=>{cancelAnimationFrame(c),window.removeEventListener("keydown",D),_t(!1)}},[ie,ae]),i.useEffect(()=>{const c=D=>{D.key!=="Escape"||D.defaultPrevented||window.matchMedia("(max-width: 999px)").matches&&(!M&&!l||Q||ie||(D.preventDefault(),G({name:null})))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[G,M,l,Q,ie]),i.useEffect(()=>{const D=J.getState().about;if(!D)return;const L=a?"team":"agent";M&&D.kind===L&&D.name===M||(o.setAbout(null),En(D))},[M,a,o]),i.useEffect(()=>{M&&R({kind:a?"team":"agent",name:M})},[M,a,R]);const re=()=>{p.refetch(),d.refetch(),M&&(a?x.refetch():S.refetch())};if(t)return e.jsx(i.Suspense,{fallback:e.jsx("p",{className:"p-6 text-body",children:"Loading saved agent…"}),children:e.jsx(Ua,{})});const _e=a?x.error:S.error,ge=a?d.error:p.error,Se=v&&!ge&&!l&&!M,b=a?x.isLoading:S.isLoading;return e.jsxs("div",{"data-glass-region":"canvas","data-glass-split":"",className:"panel-flush flex min-h-0 flex-1 bg-canvas text-ink",children:[e.jsxs("aside",{"data-open":M?"true":void 0,"data-glass-region":"page-sidebar",className:"panel-top-pad flex w-72 shrink-0 flex-col gap-3 bg-surface px-4 pb-4 max-[999px]:data-[open=true]:hidden",children:[e.jsx("h1",{className:"pt-4 text-heading",children:"Agents and teams"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(on,{value:a?"team":"agent",onValueChange:c=>G({kind:c,name:null}),children:e.jsxs(cn,{"aria-label":"Browse definitions by type",className:"w-full",children:[e.jsxs(bt,{value:"agent",className:"flex-1","data-testid":"agents-tab",children:[e.jsx(Ks,{className:"size-3.5"}),"Agents",p.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:p.data.length}):null]}),e.jsxs(bt,{value:"team",className:"flex-1","data-testid":"teams-tab",children:[e.jsx(Ts,{className:"size-3.5"}),"Teams",d.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:d.data.length}):null]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ds,{"aria-hidden":"true",className:"pointer-events-none absolute top-2 start-2 size-4 text-ink-dim"}),e.jsx(Ne,{className:"ps-8",type:"search","aria-label":"Search agents and teams",placeholder:a?"Search teams":"Search agents",value:k,onChange:c=>T(c.target.value)})]}),!a&&p.data?e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Show definitions owned by"}),e.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Object.keys(Xe).map(c=>e.jsx(E,{variant:"ghost",size:"sm","aria-pressed":y===c,onClick:()=>N(c),className:K("flex-1",y===c&&Vt),children:Xe[c]},c))})]}):null]}),e.jsx("div",{"data-lo-pane-edge-cues":!0,className:"min-h-0 flex-1 overflow-y-auto",children:ge?null:!p.data&&!d.data?e.jsx(ha,{}):Z.length===0?e.jsx("p",{className:"px-1 py-2 text-body-sm text-ink-muted",children:k?`Nothing matches “${k}”.`:a?"No teams yet. Ask for one below, or add one by hand.":y==="all"?"No agents yet. Ask for one below, or add one by hand.":`No ${Xe[y].toLowerCase()} agents.`}):e.jsx(Ka,{rows:Z,name:l?null:M,teamMode:a,printName:z,marked:new Map(C.map(c=>[In(c),c.created])),onOpen:c=>G({name:c})})}),e.jsxs(E,{variant:"ghost",className:"w-full justify-start",disabled:!v,onClick:()=>G({create:a?"team":"agent"}),children:[e.jsx(Wt,{className:"size-4"}),a?"Add team manually":"Add agent manually"]})]}),e.jsxs("main",{"data-glass-region":"canvas-content",className:"panel-top-pad flex min-w-0 flex-1 flex-col",children:[M||l?e.jsx("div",{className:"flex shrink-0 items-center border-hairline border-b px-4 py-2 min-[1000px]:hidden",children:e.jsxs(E,{variant:"ghost",size:"sm",onClick:()=>G({name:null}),children:[e.jsx(Ws,{className:"size-4"}),"Back to the list"]})}):null,e.jsx("div",{"data-agents-pane":!0,onFocus:c=>{c.target instanceof HTMLElement&&(F.current=c.target)},"data-lo-pane-edge-cues":!0,className:K("min-h-0 flex-1 overflow-auto",Se?void 0:"px-4 pt-6 [scroll-padding-bottom:calc(var(--lo-pane-footer-h)+var(--lo-pane-footer-cue-h)+4px)] [scrollbar-gutter:stable_both-edges]"),children:Se?e.jsx(Ha,{teamMode:a,run:o,onAddManually:()=>G({create:a?"team":"agent"})}):e.jsx("div",{className:it,children:e.jsx("div",{className:Ie,children:v?ge?e.jsx(Ct,{title:a?"Teams could not be read":"Agents could not be read",what:ge instanceof Error?ge.message:"The request did not complete.",meaning:"Nothing is lost. This is a read that failed — the backend answered an error, which is different from the backend being out of date.",onRetry:re,retrying:p.isFetching||d.isFetching}):M&&b?e.jsx(St,{}):M&&_e?e.jsx(Ct,{title:a?`“${M}” could not be read`:`“${M}” could not be read`,what:_e instanceof Error?_e.message:"The request did not complete.",meaning:"The definition may have been removed, or the backend refused the read.",onRetry:()=>{S.refetch(),x.refetch()},retrying:S.isFetching||x.isFetching}):l&&a?e.jsx(Ft,{agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancelCreate:()=>W({name:null}),onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:u??""},c)}},"team:create"):l&&g&&j.isLoading?e.jsx(St,{}):l?e.jsx(ya,{initial:j.data??null,takenNames:(p.data??[]).map(c=>c.name),effortTiers:B,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancel:()=>W({name:null})},"agent:create"):a&&x.data?e.jsx(Ft,{team:x.data,agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("team",x.data.name,x.data.id),onSaved:c=>{re(),W({name:c})},onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:x.data?.name??""},c)}},ua(x.data)):!a&&S.data?e.jsx(va,{profile:S.data,displayedName:z(S.data.name),classNotice:q?.name===S.data.name?q.copy:null,onClassNotice:c=>se(c?{name:S.data.name,copy:c}:null),teams:d.data,effortTiers:B,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("agent",S.data.name,S.data.agent_id??void 0),onSaved:c=>{re(),W({name:c})},onDuplicate:c=>G({create:"agent",duplicate:c.name}),onOpenTeam:c=>G({kind:"team",name:c}),onAskAgent:c=>{Ye(o,{kind:"agent",name:S.data?.name??""},c)}},da(S.data)):M?e.jsx(ve,{className:"h-6 w-40"}):null:e.jsxs(ce,{variant:h.isLoading?"neutral":"warning",className:"max-w-xl",children:[e.jsx(de,{children:h.isLoading?"Connecting to the backend":h.error?"The backend could not be reached":"Reusable agents need a newer backend"}),e.jsx(me,{children:h.isLoading?"Loading what this backend can do…":h.error?h.error.message:"Update the backend to manage reusable agents and teams. Saved chats are unchanged."})]})})})}),_?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-hairline border-t bg-surface px-4 py-3",role:"alertdialog","aria-label":"Discard your unsaved changes?",children:[e.jsx("span",{className:"text-body-sm text-ink",children:a?"Discard your unsaved changes to this team?":"Discard your unsaved changes to this agent?"}),e.jsx(E,{variant:"danger",onClick:()=>{f(null),W(_)},children:"Discard changes"}),e.jsx(E,{ref:V,variant:"ghost",onClick:ae,children:"Keep editing"})]}):null,Se?null:e.jsx("div",{className:"shrink-0 bg-canvas",children:e.jsx(ss,{run:o,about:o.about,onClearAbout:()=>o.setAbout(null),blockedReason:Q?"Finish or cancel your edit first.":null})})]})]})}function Ha({teamMode:t,run:s,onAddManually:n}){const a=K(it,Pt);return e.jsxs("div",{className:"flex min-h-full flex-col justify-center space-y-4 pb-12",children:[e.jsx("div",{className:a,children:e.jsxs("div",{className:K(Ie,"space-y-2"),children:[e.jsx("h2",{className:"text-title",children:t?"Ask for a team":"Ask for an agent"}),e.jsx("p",{className:"text-body text-ink-muted",children:t?"A team has one agent that leads the chat and members it can hand work to. Describe what you want and a configuration run sets it up.":"An agent is a reusable set of instructions you can start a chat with, or let other agents call on. Describe what you want and a configuration run sets it up."})]})}),e.jsx(ss,{run:s,hero:!0,about:s.about,onClearAbout:()=>s.setAbout(null)}),e.jsx("div",{className:a,children:e.jsx("div",{className:Ie,children:e.jsx(E,{variant:"ghost",className:"-ml-3",onClick:n,children:t?"Or add a team by hand":"Or add an agent by hand"})})})]})}function Ka({rows:t,name:s,teamMode:n,marked:a,printName:l,onOpen:u}){const g=i.useRef(new Map),[h,v]=i.useState(s),p=m=>"members"in m?qt(m):l(m.name),d=(m,S)=>{const x=t.findIndex(k=>k.name===m);if(x<0)return;const j=t[Math.min(t.length-1,Math.max(0,x+S))];j&&(v(j.name),g.current.get(j.name)?.focus())};return e.jsx("ul",{"aria-label":n?"Teams":"Agents",className:"space-y-0.5",children:t.map(m=>{const S="source"in m,x=a.get(`${n?"team":"agent"}:${m.name}`);return e.jsx("li",{children:e.jsxs("button",{ref:j=>{j?g.current.set(m.name,j):g.current.delete(m.name)},type:"button","aria-current":m.name===s?"true":void 0,tabIndex:m.name===(h??t[0]?.name)?0:-1,"data-testid":`roster-row-${m.name}`,title:m.description?`${p(m)} - ${m.description}`:p(m),className:K("flex min-h-12 w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-start hover:bg-row-hover",m.name===s&&Vt),onFocus:()=>v(m.name),onClick:()=>u(m.name),onKeyDown:j=>{j.key==="ArrowDown"?(j.preventDefault(),d(m.name,1)):j.key==="ArrowUp"?(j.preventDefault(),d(m.name,-1)):j.key==="Home"?(j.preventDefault(),d(m.name,-t.length)):j.key==="End"&&(j.preventDefault(),d(m.name,t.length))},children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-body-sm text-ink",children:p(m)}),x!==void 0?e.jsx(oe,{variant:"attention","data-testid":"roster-row-updated",children:x?"New":"Updated"}):null,e.jsx("span",{className:"ms-auto shrink-0 text-meta text-ink-dim tabular-nums",children:"members"in m?gs(m.members):e.jsx(ma,{source:m.source,appearance:"text"})})]}),e.jsxs("span",{className:"flex min-h-lh w-full items-baseline text-meta text-ink-muted",children:[S&&De(m)==="proactive"?e.jsxs("span",{className:"me-1 shrink-0","data-testid":"roster-row-proactive",children:[e.jsx("span",{className:"text-ink",children:ns.proactive}),e.jsx("span",{className:"text-ink-dim",children:" ·"})]}):null,m.description?e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.description}):e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink-dim",children:"No description"})]})]})},m.name)})})}function Wa(t,s,n,a){const l=s.trim().toLowerCase();return(t??[]).filter(u=>n==="builtin"&&u.source!=="builtin"||n==="installed"&&u.source!=="installed"||n==="custom"&&u.source!=="custom"?!1:l?a(u.name).toLowerCase().includes(l)||u.name.toLowerCase().includes(l)||(u.description??"").toLowerCase().includes(l):!0)}function Va(t,s){const n=s.trim().toLowerCase();return(t??[]).filter(a=>!n||a.name.toLowerCase().includes(n)||(a.label??"").toLowerCase().includes(n)||(a.description??"").toLowerCase().includes(n))}export{ni as AgentsPage};