local-operator-ui 0.31.34 → 0.32.1

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 (83) hide show
  1. package/out/main/index.js +23 -0
  2. package/out/renderer/assets/{_basePickBy-BGuZGQlL.js → _basePickBy-DN1soX-A.js} +1 -1
  3. package/out/renderer/assets/{_baseUniq-avrxGYhI.js → _baseUniq-RMmELqQ5.js} +1 -1
  4. package/out/renderer/assets/{agent-details-page-CSjm9_q7.js → agent-details-page-COT3PIN2.js} +1 -1
  5. package/out/renderer/assets/{agent-hub-page-BXiVDudt.js → agent-hub-page-C-es-mk1.js} +1 -1
  6. package/out/renderer/assets/{agents-page-CDuIQEse.js → agents-page-o7n6ecG3.js} +3 -3
  7. package/out/renderer/assets/{arc-CQRcxcOn.js → arc-DS8xQWUs.js} +1 -1
  8. package/out/renderer/assets/{architectureDiagram-IEHRJDOE-CkwuxGbl.js → architectureDiagram-IEHRJDOE-B7sJdcPR.js} +1 -1
  9. package/out/renderer/assets/{blockDiagram-JOT3LUYC-DErhLlTs.js → blockDiagram-JOT3LUYC-CEZT1uDD.js} +1 -1
  10. package/out/renderer/assets/{book-open-CueO0nwZ.js → book-open-BAj696yM.js} +1 -1
  11. package/out/renderer/assets/browser-page-D4sBd0oc.js +1 -0
  12. package/out/renderer/assets/{browser-webauthn-prompt-D5Ca5EtW.js → browser-webauthn-prompt-BCo8np7p.js} +1 -1
  13. package/out/renderer/assets/{c4Diagram-VJAJSXHY-Bvg0BHpF.js → c4Diagram-VJAJSXHY-DBVjyCLA.js} +1 -1
  14. package/out/renderer/assets/channel-C3VXp7A-.js +1 -0
  15. package/out/renderer/assets/{chunk-4BMEZGHF-EIhFYl3X.js → chunk-4BMEZGHF-BxNCkNoW.js} +1 -1
  16. package/out/renderer/assets/{chunk-A2AXSNBT-xwy-uUTS.js → chunk-A2AXSNBT-Lfamso1B.js} +1 -1
  17. package/out/renderer/assets/{chunk-AEK57VVT-Br1voKIL.js → chunk-AEK57VVT-DWGVRKaK.js} +1 -1
  18. package/out/renderer/assets/{chunk-D6G4REZN-C4Dh_tJf.js → chunk-D6G4REZN-Cd-lqD91.js} +1 -1
  19. package/out/renderer/assets/{chunk-RZ5BOZE2-bSGVs_Tb.js → chunk-RZ5BOZE2-DgyoVs1v.js} +1 -1
  20. package/out/renderer/assets/{chunk-XZIHB7SX-CN1-qcAy.js → chunk-XZIHB7SX-BFhFEYpa.js} +1 -1
  21. package/out/renderer/assets/classDiagram-GIVACNV2-CvXgJ-UO.js +1 -0
  22. package/out/renderer/assets/classDiagram-v2-COTLJTTW-CvXgJ-UO.js +1 -0
  23. package/out/renderer/assets/clone-CvVESMNe.js +1 -0
  24. package/out/renderer/assets/{console-mirror-D3uHRfYy.js → console-mirror-CwJYzF72.js} +1 -1
  25. package/out/renderer/assets/{consoleCapture-DwjQLM40.js → consoleCapture-C9Olow9O.js} +1 -1
  26. package/out/renderer/assets/{conversation-input-sync-QxTZG_kn.js → conversation-input-sync-OV-zVDW5.js} +245 -245
  27. package/out/renderer/assets/{dagre-OKDRZEBW-BY039iHz.js → dagre-OKDRZEBW-BOxi2j1A.js} +1 -1
  28. package/out/renderer/assets/{diagram-SSKATNLV-bB3dlGcF.js → diagram-SSKATNLV-B8l7c4p0.js} +1 -1
  29. package/out/renderer/assets/{diagram-VNBRO52H-Cyhtu1_5.js → diagram-VNBRO52H-NKSUB35T.js} +1 -1
  30. package/out/renderer/assets/{erDiagram-Q7BY3M3F-CNtBW35e.js → erDiagram-Q7BY3M3F-a6r09WA_.js} +1 -1
  31. package/out/renderer/assets/{error-boundary-BCN3_4Dn.js → error-boundary-CSpbAh09.js} +2 -2
  32. package/out/renderer/assets/{flowDiagram-4HSFHLVR-DpPSE1IC.js → flowDiagram-4HSFHLVR-BFiGMf_k.js} +1 -1
  33. package/out/renderer/assets/{ganttDiagram-APWFNJXF-xMxTMO4B.js → ganttDiagram-APWFNJXF-CYB2B_gT.js} +1 -1
  34. package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-B7-mMQYk.js → gitGraphDiagram-7IBYFJ6S-DbM7Polm.js} +1 -1
  35. package/out/renderer/assets/{graph-By5Jgx_F.js → graph-rfU03juW.js} +1 -1
  36. package/out/renderer/assets/index-BiiXZuiA.css +1 -0
  37. package/out/renderer/assets/{index-CL3E7OEw.js → index-C6Rz44O3.js} +158 -158
  38. package/out/renderer/assets/{index-DE0OwCyE.js → index-Csj4v8y7.js} +1 -1
  39. package/out/renderer/assets/{index-jwwX9AyN.js → index-UUV473dx.js} +1 -1
  40. package/out/renderer/assets/{infoDiagram-PH2N3AL5-DX8aEhB8.js → infoDiagram-PH2N3AL5-ClJ7U04k.js} +1 -1
  41. package/out/renderer/assets/{installer-DovMkJto.js → installer-CuFSLnbh.js} +1 -1
  42. package/out/renderer/assets/{journeyDiagram-U35MCT3I-CH_A0wDP.js → journeyDiagram-U35MCT3I-BtpUbwn1.js} +1 -1
  43. package/out/renderer/assets/{kanban-definition-NDS4AKOZ-DtwsMDtl.js → kanban-definition-NDS4AKOZ-C6fCkxuY.js} +1 -1
  44. package/out/renderer/assets/{layout-HO9_Xm1P.js → layout-R6hKYsWC.js} +1 -1
  45. package/out/renderer/assets/{legacy-agents-page-D6fK_4tD.js → legacy-agents-page-ObLsHUbL.js} +1 -1
  46. package/out/renderer/assets/{mermaid.core-w9t0zfcx.js → mermaid.core-B4zmbJ1v.js} +5 -5
  47. package/out/renderer/assets/{mesh-page-D4paHK3u.js → mesh-page-W2mFLFyL.js} +1 -1
  48. package/out/renderer/assets/{mindmap-definition-ALO5MXBD-B76wJgpo.js → mindmap-definition-ALO5MXBD-B14Q-tDI.js} +1 -1
  49. package/out/renderer/assets/{mini-BUYwiX1L.js → mini-DmjYYgQ7.js} +1 -1
  50. package/out/renderer/assets/{org-surface-gate-CoX7en0B.js → org-surface-gate-Bl-JDkP1.js} +1 -1
  51. package/out/renderer/assets/{page-header-ouA0fPx9.js → page-header-CtaLB27K.js} +1 -1
  52. package/out/renderer/assets/{pieDiagram-IB7DONF6-DBCDwb5q.js → pieDiagram-IB7DONF6-C4F14e7c.js} +1 -1
  53. package/out/renderer/assets/{projects-page-agDoCBOh.js → projects-page-IWQ_wrd0.js} +1 -1
  54. package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-OWbzuMt_.js → quadrantDiagram-7GDLP6J5-Do8zaQAE.js} +1 -1
  55. package/out/renderer/assets/{radar-MK3ICKWK-CRLok0av.js → radar-MK3ICKWK-CksLvXCz.js} +1 -1
  56. package/out/renderer/assets/{radient-auth-buttons-BuYF7pw2.js → radient-auth-buttons-UbGqgyO-.js} +1 -1
  57. package/out/renderer/assets/{requirementDiagram-KVF5MWMF-Ct-Jg5Jo.js → requirementDiagram-KVF5MWMF-hacvWToD.js} +1 -1
  58. package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-BJ0V1pBE.js → sankeyDiagram-QLVOVGJD-BZUs-8o3.js} +1 -1
  59. package/out/renderer/assets/{schedules-page-BjwANHEZ.js → schedules-page-BCltJWXt.js} +1 -1
  60. package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-CqLGptQb.js → sequenceDiagram-X6HHIX6F-2Y2WNAUb.js} +1 -1
  61. package/out/renderer/assets/settings-page-WTysblMK.js +292 -0
  62. package/out/renderer/assets/{settings-section-8d2ITQC3.js → settings-section-4FpgfOx3.js} +1 -1
  63. package/out/renderer/assets/{stateDiagram-DGXRK772-B-WRbN_h.js → stateDiagram-DGXRK772-BMTZfz59.js} +1 -1
  64. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-yS7nmQDd.js +1 -0
  65. package/out/renderer/assets/{timeline-definition-BDJGKUSR-Cdvoj120.js → timeline-definition-BDJGKUSR-DwYOqPRG.js} +1 -1
  66. package/out/renderer/assets/{ui-preferences-store-ClQPCzID.js → ui-preferences-store-C8Rl4euY.js} +1 -1
  67. package/out/renderer/assets/{use-download-agent-mutation-BEa3kVfY.js → use-download-agent-mutation-BeXUxQ99.js} +1 -1
  68. package/out/renderer/assets/{use-memberships-query-TpnxzBRP.js → use-memberships-query-BCYb4zy-.js} +1 -1
  69. package/out/renderer/assets/{xychartDiagram-VJFVF3MP-c6md61_B.js → xychartDiagram-VJFVF3MP-BgB8Xy4z.js} +1 -1
  70. package/out/renderer/console-capture.html +5 -5
  71. package/out/renderer/index.html +7 -7
  72. package/out/renderer/installer.html +4 -4
  73. package/out/renderer/mini.html +6 -6
  74. package/package.json +2 -2
  75. package/out/renderer/assets/browser-page-BH9k2DzV.js +0 -1
  76. package/out/renderer/assets/channel-238GQ5wt.js +0 -1
  77. package/out/renderer/assets/classDiagram-GIVACNV2-BFR--RB2.js +0 -1
  78. package/out/renderer/assets/classDiagram-v2-COTLJTTW-BFR--RB2.js +0 -1
  79. package/out/renderer/assets/clone-DJut1uh5.js +0 -1
  80. package/out/renderer/assets/index-B4ItTI5Q.css +0 -1
  81. package/out/renderer/assets/settings-page-NSosCB_S.js +0 -292
  82. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-CzCtqiki.js +0 -1
  83. /package/out/renderer/assets/{index-DvjcW_EJ.js → index-D3AKz4S0.js} +0 -0
package/out/main/index.js CHANGED
@@ -1662,6 +1662,20 @@ const desktopRequestUnion = zod.z.discriminatedUnion("op", [
1662
1662
  base: chains.optional()
1663
1663
  }).strict(),
1664
1664
  zod.z.object({ op: zod.z.literal("settings.reset"), key: settingKey }).strict(),
1665
+ /*
1666
+ * THE VOICING SURFACE's read (`features.tts`), and the twin of the STT
1667
+ * cascade report: every rung in order with its availability and the reason a
1668
+ * reader would be shown, plus the surface's own `servable` bit. It is a GET
1669
+ * with no parameters - the daemon resolves the cascade against THIS
1670
+ * machine's stored credentials - so a client cannot scope it to anything and
1671
+ * has nothing to send.
1672
+ *
1673
+ * Gated on its own capability key rather than on `settings`: the two are
1674
+ * different contracts on different release trains (a backend can serve the
1675
+ * registry and predate voicing), and a surface that fired this read at such a
1676
+ * backend would render a 404 as a failure of the user's own account.
1677
+ */
1678
+ zod.z.object({ op: zod.z.literal("tts.paths") }).strict(),
1665
1679
  zod.z.object({ op: zod.z.literal("config.get") }).strict(),
1666
1680
  zod.z.object({ op: zod.z.literal("config.update"), value: configUpdate }).strict(),
1667
1681
  zod.z.object({ op: zod.z.literal("instructions.get") }).strict(),
@@ -3240,6 +3254,15 @@ function desktopEndpoint(request) {
3240
3254
  };
3241
3255
  case "settings.reset":
3242
3256
  return { path: `/v1/settings/${request.key}/reset`, method: "POST" };
3257
+ /*
3258
+ * The synthesis availability report. A plain GET with no query at all: the
3259
+ * resolver reads this machine's credential store, so there is no parameter a
3260
+ * caller could scope it by - and it is deliberately NOT cached by this
3261
+ * layer (the daemon withdrew the TTL: availability is a statement about a
3262
+ * credential the user may have just removed).
3263
+ */
3264
+ case "tts.paths":
3265
+ return { path: "/v1/tts/paths", method: "GET" };
3243
3266
  case "config.get":
3244
3267
  return { path: "/v1/config", method: "GET" };
3245
3268
  case "config.update":
@@ -1 +1 @@
1
- import{e as o,c as b,g as v,k as O,h as P,j as p,l as w,m as A,n as x,t as c,o as N}from"./_baseUniq-avrxGYhI.js";import{as as g,aa as y,at as E,au as F,av as M,aw as I,ax as _,ay as $,az as B,aA as T}from"./mermaid.core-w9t0zfcx.js";var S=/\s/;function z(n){for(var r=n.length;r--&&S.test(n.charAt(r)););return r}var G=/^\s+/;function H(n){return n&&n.slice(0,z(n)+1).replace(G,"")}var m=NaN,L=/^[-+]0x[0-9a-f]+$/i,R=/^0b[01]+$/i,q=/^0o[0-7]+$/i,C=parseInt;function K(n){if(typeof n=="number")return n;if(o(n))return m;if(g(n)){var r=typeof n.valueOf=="function"?n.valueOf():n;n=g(r)?r+"":r}if(typeof n!="string")return n===0?n:+n;n=H(n);var t=R.test(n);return t||q.test(n)?C(n.slice(2),t?2:8):L.test(n)?m:+n}var W=1/0,X=17976931348623157e292;function Y(n){if(!n)return n===0?n:0;if(n=K(n),n===W||n===-1/0){var r=n<0?-1:1;return r*X}return n===n?n:0}function D(n){var r=Y(n),t=r%1;return r===r?t?r-t:r:0}function fn(n){var r=n==null?0:n.length;return r?b(n):[]}var l=Object.prototype,J=l.hasOwnProperty,dn=y(function(n,r){n=Object(n);var t=-1,e=r.length,a=e>2?r[2]:void 0;for(a&&E(r[0],r[1],a)&&(e=1);++t<e;)for(var f=r[t],i=F(f),s=-1,d=i.length;++s<d;){var u=i[s],h=n[u];(h===void 0||M(h,l[u])&&!J.call(n,u))&&(n[u]=f[u])}return n});function un(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}function Q(n){return function(r,t,e){var a=Object(r);if(!I(r)){var f=v(t);r=O(r),t=function(s){return f(a[s],s,a)}}var i=n(r,t,e);return i>-1?a[f?r[i]:i]:void 0}}var U=Math.max;function Z(n,r,t){var e=n==null?0:n.length;if(!e)return-1;var a=t==null?0:D(t);return a<0&&(a=U(e+a,0)),P(n,v(r),a)}var hn=Q(Z);function V(n,r){var t=-1,e=I(n)?Array(n.length):[];return p(n,function(a,f,i){e[++t]=r(a,f,i)}),e}function gn(n,r){var t=_(n)?w:V;return t(n,v(r))}var j=Object.prototype,k=j.hasOwnProperty;function nn(n,r){return n!=null&&k.call(n,r)}function vn(n,r){return n!=null&&A(n,r,nn)}function rn(n,r){return n<r}function tn(n,r,t){for(var e=-1,a=n.length;++e<a;){var f=n[e],i=r(f);if(i!=null&&(s===void 0?i===i&&!o(i):t(i,s)))var s=i,d=f}return d}function mn(n){return n&&n.length?tn(n,$,rn):void 0}function an(n,r,t,e){if(!g(n))return n;r=x(r,n);for(var a=-1,f=r.length,i=f-1,s=n;s!=null&&++a<f;){var d=c(r[a]),u=t;if(d==="__proto__"||d==="constructor"||d==="prototype")return n;if(a!=i){var h=s[d];u=void 0,u===void 0&&(u=g(h)?h:B(r[a+1])?[]:{})}T(s,d,u),s=s[d]}return n}function on(n,r,t){for(var e=-1,a=r.length,f={};++e<a;){var i=r[e],s=N(n,i);t(s,i)&&an(f,x(i,n),s)}return f}export{rn as a,tn as b,V as c,on as d,mn as e,fn as f,hn as g,vn as h,dn as i,D as j,un as l,gn as m,Y as t};
1
+ import{e as o,c as b,g as v,k as O,h as P,j as p,l as w,m as A,n as x,t as c,o as N}from"./_baseUniq-RMmELqQ5.js";import{as as g,aa as y,at as E,au as F,av as M,aw as I,ax as _,ay as $,az as B,aA as T}from"./mermaid.core-B4zmbJ1v.js";var S=/\s/;function z(n){for(var r=n.length;r--&&S.test(n.charAt(r)););return r}var G=/^\s+/;function H(n){return n&&n.slice(0,z(n)+1).replace(G,"")}var m=NaN,L=/^[-+]0x[0-9a-f]+$/i,R=/^0b[01]+$/i,q=/^0o[0-7]+$/i,C=parseInt;function K(n){if(typeof n=="number")return n;if(o(n))return m;if(g(n)){var r=typeof n.valueOf=="function"?n.valueOf():n;n=g(r)?r+"":r}if(typeof n!="string")return n===0?n:+n;n=H(n);var t=R.test(n);return t||q.test(n)?C(n.slice(2),t?2:8):L.test(n)?m:+n}var W=1/0,X=17976931348623157e292;function Y(n){if(!n)return n===0?n:0;if(n=K(n),n===W||n===-1/0){var r=n<0?-1:1;return r*X}return n===n?n:0}function D(n){var r=Y(n),t=r%1;return r===r?t?r-t:r:0}function fn(n){var r=n==null?0:n.length;return r?b(n):[]}var l=Object.prototype,J=l.hasOwnProperty,dn=y(function(n,r){n=Object(n);var t=-1,e=r.length,a=e>2?r[2]:void 0;for(a&&E(r[0],r[1],a)&&(e=1);++t<e;)for(var f=r[t],i=F(f),s=-1,d=i.length;++s<d;){var u=i[s],h=n[u];(h===void 0||M(h,l[u])&&!J.call(n,u))&&(n[u]=f[u])}return n});function un(n){var r=n==null?0:n.length;return r?n[r-1]:void 0}function Q(n){return function(r,t,e){var a=Object(r);if(!I(r)){var f=v(t);r=O(r),t=function(s){return f(a[s],s,a)}}var i=n(r,t,e);return i>-1?a[f?r[i]:i]:void 0}}var U=Math.max;function Z(n,r,t){var e=n==null?0:n.length;if(!e)return-1;var a=t==null?0:D(t);return a<0&&(a=U(e+a,0)),P(n,v(r),a)}var hn=Q(Z);function V(n,r){var t=-1,e=I(n)?Array(n.length):[];return p(n,function(a,f,i){e[++t]=r(a,f,i)}),e}function gn(n,r){var t=_(n)?w:V;return t(n,v(r))}var j=Object.prototype,k=j.hasOwnProperty;function nn(n,r){return n!=null&&k.call(n,r)}function vn(n,r){return n!=null&&A(n,r,nn)}function rn(n,r){return n<r}function tn(n,r,t){for(var e=-1,a=n.length;++e<a;){var f=n[e],i=r(f);if(i!=null&&(s===void 0?i===i&&!o(i):t(i,s)))var s=i,d=f}return d}function mn(n){return n&&n.length?tn(n,$,rn):void 0}function an(n,r,t,e){if(!g(n))return n;r=x(r,n);for(var a=-1,f=r.length,i=f-1,s=n;s!=null&&++a<f;){var d=c(r[a]),u=t;if(d==="__proto__"||d==="constructor"||d==="prototype")return n;if(a!=i){var h=s[d];u=void 0,u===void 0&&(u=g(h)?h:B(r[a+1])?[]:{})}T(s,d,u),s=s[d]}return n}function on(n,r,t){for(var e=-1,a=r.length,f={};++e<a;){var i=r[e],s=N(n,i);t(s,i)&&an(f,x(i,n),s)}return f}export{rn as a,tn as b,V as c,on as d,mn as e,fn as f,hn as g,vn as h,dn as i,D as j,un as l,gn as m,Y as t};
@@ -1 +1 @@
1
- import{aH as S,aI as Rn,ax as T,aJ as w,aK as xn,aL as Mn,aw as sn,aM as mn,aN as un,aO as x,au as U,aP as Cn,aQ as on,aR as Fn,aS as E,aF as gn,aT as R,as as ln,aU as Dn,aV as D,aW as Gn,aX as Un,aY as _,aA as Nn,aZ as Bn,av as Kn,a_ as X,a$ as Hn,b0 as jn,az as Yn,ay as cn,aD as Zn,b1 as m}from"./mermaid.core-w9t0zfcx.js";var qn="[object Symbol]";function N(n){return typeof n=="symbol"||S(n)&&Rn(n)==qn}function dn(n,r){for(var e=-1,t=n==null?0:n.length,a=Array(t);++e<t;)a[e]=r(n[e],e,n);return a}var J=w?w.prototype:void 0,Q=J?J.toString:void 0;function pn(n){if(typeof n=="string")return n;if(T(n))return dn(n,pn)+"";if(N(n))return Q?Q.call(n):"";var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}function Xn(){}function An(n,r){for(var e=-1,t=n==null?0:n.length;++e<t&&r(n[e],e,n)!==!1;);return n}function Jn(n,r,e,t){for(var a=n.length,i=e+-1;++i<a;)if(r(n[i],i,n))return i;return-1}function Qn(n){return n!==n}function Wn(n,r,e){for(var t=e-1,a=n.length;++t<a;)if(n[t]===r)return t;return-1}function zn(n,r,e){return r===r?Wn(n,r,e):Jn(n,Qn,e)}function Vn(n,r){var e=n==null?0:n.length;return!!e&&zn(n,r,0)>-1}function $(n){return sn(n)?xn(n):Mn(n)}var kn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,nr=/^\w*$/;function B(n,r){if(T(n))return!1;var e=typeof n;return e=="number"||e=="symbol"||e=="boolean"||n==null||N(n)?!0:nr.test(n)||!kn.test(n)||r!=null&&n in Object(r)}var rr=500;function er(n){var r=mn(n,function(t){return e.size===rr&&e.clear(),t}),e=r.cache;return r}var tr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ir=/\\(\\)?/g,ar=er(function(n){var r=[];return n.charCodeAt(0)===46&&r.push(""),n.replace(tr,function(e,t,a,i){r.push(a?i.replace(ir,"$1"):t||e)}),r});function fr(n){return n==null?"":pn(n)}function yn(n,r){return T(n)?n:B(n,r)?[n]:ar(fr(n))}function M(n){if(typeof n=="string"||N(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}function bn(n,r){r=yn(r,n);for(var e=0,t=r.length;n!=null&&e<t;)n=n[M(r[e++])];return e&&e==t?n:void 0}function sr(n,r,e){var t=n==null?void 0:bn(n,r);return t===void 0?e:t}function K(n,r){for(var e=-1,t=r.length,a=n.length;++e<t;)n[a+e]=r[e];return n}var W=w?w.isConcatSpreadable:void 0;function ur(n){return T(n)||un(n)||!!(W&&n&&n[W])}function Ot(n,r,e,t,a){var i=-1,f=n.length;for(e||(e=ur),a||(a=[]);++i<f;){var s=n[i];e(s)?K(a,s):t||(a[a.length]=s)}return a}function or(n,r,e,t){var a=-1,i=n==null?0:n.length;for(t&&i&&(e=n[++a]);++a<i;)e=r(e,n[a],a,n);return e}function gr(n,r){return n&&x(r,$(r),n)}function lr(n,r){return n&&x(r,U(r),n)}function Tn(n,r){for(var e=-1,t=n==null?0:n.length,a=0,i=[];++e<t;){var f=n[e];r(f,e,n)&&(i[a++]=f)}return i}function hn(){return[]}var cr=Object.prototype,dr=cr.propertyIsEnumerable,z=Object.getOwnPropertySymbols,H=z?function(n){return n==null?[]:(n=Object(n),Tn(z(n),function(r){return dr.call(n,r)}))}:hn;function pr(n,r){return x(n,H(n),r)}var Ar=Object.getOwnPropertySymbols,wn=Ar?function(n){for(var r=[];n;)K(r,H(n)),n=Cn(n);return r}:hn;function yr(n,r){return x(n,wn(n),r)}function On(n,r,e){var t=r(n);return T(n)?t:K(t,e(n))}function G(n){return On(n,$,H)}function br(n){return On(n,U,wn)}var Tr=Object.prototype,hr=Tr.hasOwnProperty;function wr(n){var r=n.length,e=new n.constructor(r);return r&&typeof n[0]=="string"&&hr.call(n,"index")&&(e.index=n.index,e.input=n.input),e}function Or(n,r){var e=r?on(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.byteLength)}var $r=/\w*$/;function _r(n){var r=new n.constructor(n.source,$r.exec(n));return r.lastIndex=n.lastIndex,r}var V=w?w.prototype:void 0,k=V?V.valueOf:void 0;function Sr(n){return k?Object(k.call(n)):{}}var Er="[object Boolean]",Ir="[object Date]",Pr="[object Map]",vr="[object Number]",Lr="[object RegExp]",Rr="[object Set]",xr="[object String]",Mr="[object Symbol]",mr="[object ArrayBuffer]",Cr="[object DataView]",Fr="[object Float32Array]",Dr="[object Float64Array]",Gr="[object Int8Array]",Ur="[object Int16Array]",Nr="[object Int32Array]",Br="[object Uint8Array]",Kr="[object Uint8ClampedArray]",Hr="[object Uint16Array]",jr="[object Uint32Array]";function Yr(n,r,e){var t=n.constructor;switch(r){case mr:return on(n);case Er:case Ir:return new t(+n);case Cr:return Or(n,e);case Fr:case Dr:case Gr:case Ur:case Nr:case Br:case Kr:case Hr:case jr:return Fn(n,e);case Pr:return new t;case vr:case xr:return new t(n);case Lr:return _r(n);case Rr:return new t;case Mr:return Sr(n)}}var Zr="[object Map]";function qr(n){return S(n)&&E(n)==Zr}var nn=R&&R.isMap,Xr=nn?gn(nn):qr,Jr="[object Set]";function Qr(n){return S(n)&&E(n)==Jr}var rn=R&&R.isSet,Wr=rn?gn(rn):Qr,zr=1,Vr=2,kr=4,$n="[object Arguments]",ne="[object Array]",re="[object Boolean]",ee="[object Date]",te="[object Error]",_n="[object Function]",ie="[object GeneratorFunction]",ae="[object Map]",fe="[object Number]",Sn="[object Object]",se="[object RegExp]",ue="[object Set]",oe="[object String]",ge="[object Symbol]",le="[object WeakMap]",ce="[object ArrayBuffer]",de="[object DataView]",pe="[object Float32Array]",Ae="[object Float64Array]",ye="[object Int8Array]",be="[object Int16Array]",Te="[object Int32Array]",he="[object Uint8Array]",we="[object Uint8ClampedArray]",Oe="[object Uint16Array]",$e="[object Uint32Array]",g={};g[$n]=g[ne]=g[ce]=g[de]=g[re]=g[ee]=g[pe]=g[Ae]=g[ye]=g[be]=g[Te]=g[ae]=g[fe]=g[Sn]=g[se]=g[ue]=g[oe]=g[ge]=g[he]=g[we]=g[Oe]=g[$e]=!0;g[te]=g[_n]=g[le]=!1;function C(n,r,e,t,a,i){var f,s=r&zr,u=r&Vr,d=r&kr;if(f!==void 0)return f;if(!ln(n))return n;var l=T(n);if(l){if(f=wr(n),!s)return Dn(n,f)}else{var o=E(n),c=o==_n||o==ie;if(D(n))return Gn(n,s);if(o==Sn||o==$n||c&&!a){if(f=u||c?{}:Un(n),!s)return u?yr(n,lr(f,n)):pr(n,gr(f,n))}else{if(!g[o])return a?n:{};f=Yr(n,o,s)}}i||(i=new _);var h=i.get(n);if(h)return h;i.set(n,f),Wr(n)?n.forEach(function(p){f.add(C(p,r,e,p,n,i))}):Xr(n)&&n.forEach(function(p,A){f.set(A,C(p,r,e,A,n,i))});var y=d?u?br:G:u?U:$,b=l?void 0:y(n);return An(b||n,function(p,A){b&&(A=p,p=n[A]),Nn(f,A,C(p,r,e,A,n,i))}),f}var _e="__lodash_hash_undefined__";function Se(n){return this.__data__.set(n,_e),this}function Ee(n){return this.__data__.has(n)}function I(n){var r=-1,e=n==null?0:n.length;for(this.__data__=new Bn;++r<e;)this.add(n[r])}I.prototype.add=I.prototype.push=Se;I.prototype.has=Ee;function Ie(n,r){for(var e=-1,t=n==null?0:n.length;++e<t;)if(r(n[e],e,n))return!0;return!1}function En(n,r){return n.has(r)}var Pe=1,ve=2;function In(n,r,e,t,a,i){var f=e&Pe,s=n.length,u=r.length;if(s!=u&&!(f&&u>s))return!1;var d=i.get(n),l=i.get(r);if(d&&l)return d==r&&l==n;var o=-1,c=!0,h=e&ve?new I:void 0;for(i.set(n,r),i.set(r,n);++o<s;){var y=n[o],b=r[o];if(t)var p=f?t(b,y,o,r,n,i):t(y,b,o,n,r,i);if(p!==void 0){if(p)continue;c=!1;break}if(h){if(!Ie(r,function(A,O){if(!En(h,O)&&(y===A||a(y,A,e,t,i)))return h.push(O)})){c=!1;break}}else if(!(y===b||a(y,b,e,t,i))){c=!1;break}}return i.delete(n),i.delete(r),c}function Le(n){var r=-1,e=Array(n.size);return n.forEach(function(t,a){e[++r]=[a,t]}),e}function j(n){var r=-1,e=Array(n.size);return n.forEach(function(t){e[++r]=t}),e}var Re=1,xe=2,Me="[object Boolean]",me="[object Date]",Ce="[object Error]",Fe="[object Map]",De="[object Number]",Ge="[object RegExp]",Ue="[object Set]",Ne="[object String]",Be="[object Symbol]",Ke="[object ArrayBuffer]",He="[object DataView]",en=w?w.prototype:void 0,F=en?en.valueOf:void 0;function je(n,r,e,t,a,i,f){switch(e){case He:if(n.byteLength!=r.byteLength||n.byteOffset!=r.byteOffset)return!1;n=n.buffer,r=r.buffer;case Ke:return!(n.byteLength!=r.byteLength||!i(new X(n),new X(r)));case Me:case me:case De:return Kn(+n,+r);case Ce:return n.name==r.name&&n.message==r.message;case Ge:case Ne:return n==r+"";case Fe:var s=Le;case Ue:var u=t&Re;if(s||(s=j),n.size!=r.size&&!u)return!1;var d=f.get(n);if(d)return d==r;t|=xe,f.set(n,r);var l=In(s(n),s(r),t,a,i,f);return f.delete(n),l;case Be:if(F)return F.call(n)==F.call(r)}return!1}var Ye=1,Ze=Object.prototype,qe=Ze.hasOwnProperty;function Xe(n,r,e,t,a,i){var f=e&Ye,s=G(n),u=s.length,d=G(r),l=d.length;if(u!=l&&!f)return!1;for(var o=u;o--;){var c=s[o];if(!(f?c in r:qe.call(r,c)))return!1}var h=i.get(n),y=i.get(r);if(h&&y)return h==r&&y==n;var b=!0;i.set(n,r),i.set(r,n);for(var p=f;++o<u;){c=s[o];var A=n[c],O=r[c];if(t)var q=f?t(O,A,c,r,n,i):t(A,O,c,n,r,i);if(!(q===void 0?A===O||a(A,O,e,t,i):q)){b=!1;break}p||(p=c=="constructor")}if(b&&!p){var P=n.constructor,v=r.constructor;P!=v&&"constructor"in n&&"constructor"in r&&!(typeof P=="function"&&P instanceof P&&typeof v=="function"&&v instanceof v)&&(b=!1)}return i.delete(n),i.delete(r),b}var Je=1,tn="[object Arguments]",an="[object Array]",L="[object Object]",Qe=Object.prototype,fn=Qe.hasOwnProperty;function We(n,r,e,t,a,i){var f=T(n),s=T(r),u=f?an:E(n),d=s?an:E(r);u=u==tn?L:u,d=d==tn?L:d;var l=u==L,o=d==L,c=u==d;if(c&&D(n)){if(!D(r))return!1;f=!0,l=!1}if(c&&!l)return i||(i=new _),f||Hn(n)?In(n,r,e,t,a,i):je(n,r,u,e,t,a,i);if(!(e&Je)){var h=l&&fn.call(n,"__wrapped__"),y=o&&fn.call(r,"__wrapped__");if(h||y){var b=h?n.value():n,p=y?r.value():r;return i||(i=new _),a(b,p,e,t,i)}}return c?(i||(i=new _),Xe(n,r,e,t,a,i)):!1}function Y(n,r,e,t,a){return n===r?!0:n==null||r==null||!S(n)&&!S(r)?n!==n&&r!==r:We(n,r,e,t,Y,a)}var ze=1,Ve=2;function ke(n,r,e,t){var a=e.length,i=a;if(n==null)return!i;for(n=Object(n);a--;){var f=e[a];if(f[2]?f[1]!==n[f[0]]:!(f[0]in n))return!1}for(;++a<i;){f=e[a];var s=f[0],u=n[s],d=f[1];if(f[2]){if(u===void 0&&!(s in n))return!1}else{var l=new _,o;if(!(o===void 0?Y(d,u,ze|Ve,t,l):o))return!1}}return!0}function Pn(n){return n===n&&!ln(n)}function nt(n){for(var r=$(n),e=r.length;e--;){var t=r[e],a=n[t];r[e]=[t,a,Pn(a)]}return r}function vn(n,r){return function(e){return e==null?!1:e[n]===r&&(r!==void 0||n in Object(e))}}function rt(n){var r=nt(n);return r.length==1&&r[0][2]?vn(r[0][0],r[0][1]):function(e){return e===n||ke(e,n,r)}}function et(n,r){return n!=null&&r in Object(n)}function tt(n,r,e){r=yn(r,n);for(var t=-1,a=r.length,i=!1;++t<a;){var f=M(r[t]);if(!(i=n!=null&&e(n,f)))break;n=n[f]}return i||++t!=a?i:(a=n==null?0:n.length,!!a&&jn(a)&&Yn(f,a)&&(T(n)||un(n)))}function it(n,r){return n!=null&&tt(n,r,et)}var at=1,ft=2;function st(n,r){return B(n)&&Pn(r)?vn(M(n),r):function(e){var t=sr(e,n);return t===void 0&&t===r?it(e,n):Y(r,t,at|ft)}}function ut(n){return function(r){return r?.[n]}}function ot(n){return function(r){return bn(r,n)}}function gt(n){return B(n)?ut(M(n)):ot(n)}function Ln(n){return typeof n=="function"?n:n==null?cn:typeof n=="object"?T(n)?st(n[0],n[1]):rt(n):gt(n)}function lt(n,r){return n&&Zn(n,r,$)}function ct(n,r){return function(e,t){if(e==null)return e;if(!sn(e))return n(e,t);for(var a=e.length,i=-1,f=Object(e);++i<a&&t(f[i],i,f)!==!1;);return e}}var Z=ct(lt);function dt(n){return typeof n=="function"?n:cn}function $t(n,r){var e=T(n)?An:Z;return e(n,dt(r))}function pt(n,r){var e=[];return Z(n,function(t,a,i){r(t,a,i)&&e.push(t)}),e}function _t(n,r){var e=T(n)?Tn:pt;return e(n,Ln(r))}function At(n,r){return dn(r,function(e){return n[e]})}function St(n){return n==null?[]:At(n,$(n))}function Et(n){return n===void 0}function yt(n,r,e,t,a){return a(n,function(i,f,s){e=t?(t=!1,i):r(e,i,f,s)}),e}function It(n,r,e){var t=T(n)?or:yt,a=arguments.length<3;return t(n,Ln(r),e,a,Z)}var bt=1/0,Tt=m&&1/j(new m([,-0]))[1]==bt?function(n){return new m(n)}:Xn,ht=200;function Pt(n,r,e){var t=-1,a=Vn,i=n.length,f=!0,s=[],u=s;if(i>=ht){var d=r?null:Tt(n);if(d)return j(d);f=!1,a=En,u=new I}else u=r?[]:s;n:for(;++t<i;){var l=n[t],o=r?r(l):l;if(l=l!==0?l:0,f&&o===o){for(var c=u.length;c--;)if(u[c]===o)continue n;r&&u.push(o),s.push(l)}else a(u,o,e)||(u!==s&&u.push(o),s.push(l))}return s}export{Tn as A,pt as B,Ie as C,Xn as D,I as S,Pt as a,C as b,Ot as c,$t as d,N as e,_t as f,Ln as g,Jn as h,Et as i,Z as j,$ as k,dn as l,tt as m,yn as n,bn as o,dt as p,lt as q,It as r,it as s,M as t,fr as u,St as v,Vn as w,En as x,zn as y,br as z};
1
+ import{aH as S,aI as Rn,ax as T,aJ as w,aK as xn,aL as Mn,aw as sn,aM as mn,aN as un,aO as x,au as U,aP as Cn,aQ as on,aR as Fn,aS as E,aF as gn,aT as R,as as ln,aU as Dn,aV as D,aW as Gn,aX as Un,aY as _,aA as Nn,aZ as Bn,av as Kn,a_ as X,a$ as Hn,b0 as jn,az as Yn,ay as cn,aD as Zn,b1 as m}from"./mermaid.core-B4zmbJ1v.js";var qn="[object Symbol]";function N(n){return typeof n=="symbol"||S(n)&&Rn(n)==qn}function dn(n,r){for(var e=-1,t=n==null?0:n.length,a=Array(t);++e<t;)a[e]=r(n[e],e,n);return a}var J=w?w.prototype:void 0,Q=J?J.toString:void 0;function pn(n){if(typeof n=="string")return n;if(T(n))return dn(n,pn)+"";if(N(n))return Q?Q.call(n):"";var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}function Xn(){}function An(n,r){for(var e=-1,t=n==null?0:n.length;++e<t&&r(n[e],e,n)!==!1;);return n}function Jn(n,r,e,t){for(var a=n.length,i=e+-1;++i<a;)if(r(n[i],i,n))return i;return-1}function Qn(n){return n!==n}function Wn(n,r,e){for(var t=e-1,a=n.length;++t<a;)if(n[t]===r)return t;return-1}function zn(n,r,e){return r===r?Wn(n,r,e):Jn(n,Qn,e)}function Vn(n,r){var e=n==null?0:n.length;return!!e&&zn(n,r,0)>-1}function $(n){return sn(n)?xn(n):Mn(n)}var kn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,nr=/^\w*$/;function B(n,r){if(T(n))return!1;var e=typeof n;return e=="number"||e=="symbol"||e=="boolean"||n==null||N(n)?!0:nr.test(n)||!kn.test(n)||r!=null&&n in Object(r)}var rr=500;function er(n){var r=mn(n,function(t){return e.size===rr&&e.clear(),t}),e=r.cache;return r}var tr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ir=/\\(\\)?/g,ar=er(function(n){var r=[];return n.charCodeAt(0)===46&&r.push(""),n.replace(tr,function(e,t,a,i){r.push(a?i.replace(ir,"$1"):t||e)}),r});function fr(n){return n==null?"":pn(n)}function yn(n,r){return T(n)?n:B(n,r)?[n]:ar(fr(n))}function M(n){if(typeof n=="string"||N(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}function bn(n,r){r=yn(r,n);for(var e=0,t=r.length;n!=null&&e<t;)n=n[M(r[e++])];return e&&e==t?n:void 0}function sr(n,r,e){var t=n==null?void 0:bn(n,r);return t===void 0?e:t}function K(n,r){for(var e=-1,t=r.length,a=n.length;++e<t;)n[a+e]=r[e];return n}var W=w?w.isConcatSpreadable:void 0;function ur(n){return T(n)||un(n)||!!(W&&n&&n[W])}function Ot(n,r,e,t,a){var i=-1,f=n.length;for(e||(e=ur),a||(a=[]);++i<f;){var s=n[i];e(s)?K(a,s):t||(a[a.length]=s)}return a}function or(n,r,e,t){var a=-1,i=n==null?0:n.length;for(t&&i&&(e=n[++a]);++a<i;)e=r(e,n[a],a,n);return e}function gr(n,r){return n&&x(r,$(r),n)}function lr(n,r){return n&&x(r,U(r),n)}function Tn(n,r){for(var e=-1,t=n==null?0:n.length,a=0,i=[];++e<t;){var f=n[e];r(f,e,n)&&(i[a++]=f)}return i}function hn(){return[]}var cr=Object.prototype,dr=cr.propertyIsEnumerable,z=Object.getOwnPropertySymbols,H=z?function(n){return n==null?[]:(n=Object(n),Tn(z(n),function(r){return dr.call(n,r)}))}:hn;function pr(n,r){return x(n,H(n),r)}var Ar=Object.getOwnPropertySymbols,wn=Ar?function(n){for(var r=[];n;)K(r,H(n)),n=Cn(n);return r}:hn;function yr(n,r){return x(n,wn(n),r)}function On(n,r,e){var t=r(n);return T(n)?t:K(t,e(n))}function G(n){return On(n,$,H)}function br(n){return On(n,U,wn)}var Tr=Object.prototype,hr=Tr.hasOwnProperty;function wr(n){var r=n.length,e=new n.constructor(r);return r&&typeof n[0]=="string"&&hr.call(n,"index")&&(e.index=n.index,e.input=n.input),e}function Or(n,r){var e=r?on(n.buffer):n.buffer;return new n.constructor(e,n.byteOffset,n.byteLength)}var $r=/\w*$/;function _r(n){var r=new n.constructor(n.source,$r.exec(n));return r.lastIndex=n.lastIndex,r}var V=w?w.prototype:void 0,k=V?V.valueOf:void 0;function Sr(n){return k?Object(k.call(n)):{}}var Er="[object Boolean]",Ir="[object Date]",Pr="[object Map]",vr="[object Number]",Lr="[object RegExp]",Rr="[object Set]",xr="[object String]",Mr="[object Symbol]",mr="[object ArrayBuffer]",Cr="[object DataView]",Fr="[object Float32Array]",Dr="[object Float64Array]",Gr="[object Int8Array]",Ur="[object Int16Array]",Nr="[object Int32Array]",Br="[object Uint8Array]",Kr="[object Uint8ClampedArray]",Hr="[object Uint16Array]",jr="[object Uint32Array]";function Yr(n,r,e){var t=n.constructor;switch(r){case mr:return on(n);case Er:case Ir:return new t(+n);case Cr:return Or(n,e);case Fr:case Dr:case Gr:case Ur:case Nr:case Br:case Kr:case Hr:case jr:return Fn(n,e);case Pr:return new t;case vr:case xr:return new t(n);case Lr:return _r(n);case Rr:return new t;case Mr:return Sr(n)}}var Zr="[object Map]";function qr(n){return S(n)&&E(n)==Zr}var nn=R&&R.isMap,Xr=nn?gn(nn):qr,Jr="[object Set]";function Qr(n){return S(n)&&E(n)==Jr}var rn=R&&R.isSet,Wr=rn?gn(rn):Qr,zr=1,Vr=2,kr=4,$n="[object Arguments]",ne="[object Array]",re="[object Boolean]",ee="[object Date]",te="[object Error]",_n="[object Function]",ie="[object GeneratorFunction]",ae="[object Map]",fe="[object Number]",Sn="[object Object]",se="[object RegExp]",ue="[object Set]",oe="[object String]",ge="[object Symbol]",le="[object WeakMap]",ce="[object ArrayBuffer]",de="[object DataView]",pe="[object Float32Array]",Ae="[object Float64Array]",ye="[object Int8Array]",be="[object Int16Array]",Te="[object Int32Array]",he="[object Uint8Array]",we="[object Uint8ClampedArray]",Oe="[object Uint16Array]",$e="[object Uint32Array]",g={};g[$n]=g[ne]=g[ce]=g[de]=g[re]=g[ee]=g[pe]=g[Ae]=g[ye]=g[be]=g[Te]=g[ae]=g[fe]=g[Sn]=g[se]=g[ue]=g[oe]=g[ge]=g[he]=g[we]=g[Oe]=g[$e]=!0;g[te]=g[_n]=g[le]=!1;function C(n,r,e,t,a,i){var f,s=r&zr,u=r&Vr,d=r&kr;if(f!==void 0)return f;if(!ln(n))return n;var l=T(n);if(l){if(f=wr(n),!s)return Dn(n,f)}else{var o=E(n),c=o==_n||o==ie;if(D(n))return Gn(n,s);if(o==Sn||o==$n||c&&!a){if(f=u||c?{}:Un(n),!s)return u?yr(n,lr(f,n)):pr(n,gr(f,n))}else{if(!g[o])return a?n:{};f=Yr(n,o,s)}}i||(i=new _);var h=i.get(n);if(h)return h;i.set(n,f),Wr(n)?n.forEach(function(p){f.add(C(p,r,e,p,n,i))}):Xr(n)&&n.forEach(function(p,A){f.set(A,C(p,r,e,A,n,i))});var y=d?u?br:G:u?U:$,b=l?void 0:y(n);return An(b||n,function(p,A){b&&(A=p,p=n[A]),Nn(f,A,C(p,r,e,A,n,i))}),f}var _e="__lodash_hash_undefined__";function Se(n){return this.__data__.set(n,_e),this}function Ee(n){return this.__data__.has(n)}function I(n){var r=-1,e=n==null?0:n.length;for(this.__data__=new Bn;++r<e;)this.add(n[r])}I.prototype.add=I.prototype.push=Se;I.prototype.has=Ee;function Ie(n,r){for(var e=-1,t=n==null?0:n.length;++e<t;)if(r(n[e],e,n))return!0;return!1}function En(n,r){return n.has(r)}var Pe=1,ve=2;function In(n,r,e,t,a,i){var f=e&Pe,s=n.length,u=r.length;if(s!=u&&!(f&&u>s))return!1;var d=i.get(n),l=i.get(r);if(d&&l)return d==r&&l==n;var o=-1,c=!0,h=e&ve?new I:void 0;for(i.set(n,r),i.set(r,n);++o<s;){var y=n[o],b=r[o];if(t)var p=f?t(b,y,o,r,n,i):t(y,b,o,n,r,i);if(p!==void 0){if(p)continue;c=!1;break}if(h){if(!Ie(r,function(A,O){if(!En(h,O)&&(y===A||a(y,A,e,t,i)))return h.push(O)})){c=!1;break}}else if(!(y===b||a(y,b,e,t,i))){c=!1;break}}return i.delete(n),i.delete(r),c}function Le(n){var r=-1,e=Array(n.size);return n.forEach(function(t,a){e[++r]=[a,t]}),e}function j(n){var r=-1,e=Array(n.size);return n.forEach(function(t){e[++r]=t}),e}var Re=1,xe=2,Me="[object Boolean]",me="[object Date]",Ce="[object Error]",Fe="[object Map]",De="[object Number]",Ge="[object RegExp]",Ue="[object Set]",Ne="[object String]",Be="[object Symbol]",Ke="[object ArrayBuffer]",He="[object DataView]",en=w?w.prototype:void 0,F=en?en.valueOf:void 0;function je(n,r,e,t,a,i,f){switch(e){case He:if(n.byteLength!=r.byteLength||n.byteOffset!=r.byteOffset)return!1;n=n.buffer,r=r.buffer;case Ke:return!(n.byteLength!=r.byteLength||!i(new X(n),new X(r)));case Me:case me:case De:return Kn(+n,+r);case Ce:return n.name==r.name&&n.message==r.message;case Ge:case Ne:return n==r+"";case Fe:var s=Le;case Ue:var u=t&Re;if(s||(s=j),n.size!=r.size&&!u)return!1;var d=f.get(n);if(d)return d==r;t|=xe,f.set(n,r);var l=In(s(n),s(r),t,a,i,f);return f.delete(n),l;case Be:if(F)return F.call(n)==F.call(r)}return!1}var Ye=1,Ze=Object.prototype,qe=Ze.hasOwnProperty;function Xe(n,r,e,t,a,i){var f=e&Ye,s=G(n),u=s.length,d=G(r),l=d.length;if(u!=l&&!f)return!1;for(var o=u;o--;){var c=s[o];if(!(f?c in r:qe.call(r,c)))return!1}var h=i.get(n),y=i.get(r);if(h&&y)return h==r&&y==n;var b=!0;i.set(n,r),i.set(r,n);for(var p=f;++o<u;){c=s[o];var A=n[c],O=r[c];if(t)var q=f?t(O,A,c,r,n,i):t(A,O,c,n,r,i);if(!(q===void 0?A===O||a(A,O,e,t,i):q)){b=!1;break}p||(p=c=="constructor")}if(b&&!p){var P=n.constructor,v=r.constructor;P!=v&&"constructor"in n&&"constructor"in r&&!(typeof P=="function"&&P instanceof P&&typeof v=="function"&&v instanceof v)&&(b=!1)}return i.delete(n),i.delete(r),b}var Je=1,tn="[object Arguments]",an="[object Array]",L="[object Object]",Qe=Object.prototype,fn=Qe.hasOwnProperty;function We(n,r,e,t,a,i){var f=T(n),s=T(r),u=f?an:E(n),d=s?an:E(r);u=u==tn?L:u,d=d==tn?L:d;var l=u==L,o=d==L,c=u==d;if(c&&D(n)){if(!D(r))return!1;f=!0,l=!1}if(c&&!l)return i||(i=new _),f||Hn(n)?In(n,r,e,t,a,i):je(n,r,u,e,t,a,i);if(!(e&Je)){var h=l&&fn.call(n,"__wrapped__"),y=o&&fn.call(r,"__wrapped__");if(h||y){var b=h?n.value():n,p=y?r.value():r;return i||(i=new _),a(b,p,e,t,i)}}return c?(i||(i=new _),Xe(n,r,e,t,a,i)):!1}function Y(n,r,e,t,a){return n===r?!0:n==null||r==null||!S(n)&&!S(r)?n!==n&&r!==r:We(n,r,e,t,Y,a)}var ze=1,Ve=2;function ke(n,r,e,t){var a=e.length,i=a;if(n==null)return!i;for(n=Object(n);a--;){var f=e[a];if(f[2]?f[1]!==n[f[0]]:!(f[0]in n))return!1}for(;++a<i;){f=e[a];var s=f[0],u=n[s],d=f[1];if(f[2]){if(u===void 0&&!(s in n))return!1}else{var l=new _,o;if(!(o===void 0?Y(d,u,ze|Ve,t,l):o))return!1}}return!0}function Pn(n){return n===n&&!ln(n)}function nt(n){for(var r=$(n),e=r.length;e--;){var t=r[e],a=n[t];r[e]=[t,a,Pn(a)]}return r}function vn(n,r){return function(e){return e==null?!1:e[n]===r&&(r!==void 0||n in Object(e))}}function rt(n){var r=nt(n);return r.length==1&&r[0][2]?vn(r[0][0],r[0][1]):function(e){return e===n||ke(e,n,r)}}function et(n,r){return n!=null&&r in Object(n)}function tt(n,r,e){r=yn(r,n);for(var t=-1,a=r.length,i=!1;++t<a;){var f=M(r[t]);if(!(i=n!=null&&e(n,f)))break;n=n[f]}return i||++t!=a?i:(a=n==null?0:n.length,!!a&&jn(a)&&Yn(f,a)&&(T(n)||un(n)))}function it(n,r){return n!=null&&tt(n,r,et)}var at=1,ft=2;function st(n,r){return B(n)&&Pn(r)?vn(M(n),r):function(e){var t=sr(e,n);return t===void 0&&t===r?it(e,n):Y(r,t,at|ft)}}function ut(n){return function(r){return r?.[n]}}function ot(n){return function(r){return bn(r,n)}}function gt(n){return B(n)?ut(M(n)):ot(n)}function Ln(n){return typeof n=="function"?n:n==null?cn:typeof n=="object"?T(n)?st(n[0],n[1]):rt(n):gt(n)}function lt(n,r){return n&&Zn(n,r,$)}function ct(n,r){return function(e,t){if(e==null)return e;if(!sn(e))return n(e,t);for(var a=e.length,i=-1,f=Object(e);++i<a&&t(f[i],i,f)!==!1;);return e}}var Z=ct(lt);function dt(n){return typeof n=="function"?n:cn}function $t(n,r){var e=T(n)?An:Z;return e(n,dt(r))}function pt(n,r){var e=[];return Z(n,function(t,a,i){r(t,a,i)&&e.push(t)}),e}function _t(n,r){var e=T(n)?Tn:pt;return e(n,Ln(r))}function At(n,r){return dn(r,function(e){return n[e]})}function St(n){return n==null?[]:At(n,$(n))}function Et(n){return n===void 0}function yt(n,r,e,t,a){return a(n,function(i,f,s){e=t?(t=!1,i):r(e,i,f,s)}),e}function It(n,r,e){var t=T(n)?or:yt,a=arguments.length<3;return t(n,Ln(r),e,a,Z)}var bt=1/0,Tt=m&&1/j(new m([,-0]))[1]==bt?function(n){return new m(n)}:Xn,ht=200;function Pt(n,r,e){var t=-1,a=Vn,i=n.length,f=!0,s=[],u=s;if(i>=ht){var d=r?null:Tt(n);if(d)return j(d);f=!1,a=En,u=new I}else u=r?[]:s;n:for(;++t<i;){var l=n[t],o=r?r(l):l;if(l=l!==0?l:0,f&&o===o){for(var c=u.length;c--;)if(u[c]===o)continue n;r&&u.push(o),s.push(l)}else a(u,o,e)||(u!==s&&u.push(o),s.push(l))}return s}export{Tn as A,pt as B,Ie as C,Xn as D,I as S,Pt as a,C as b,Ot as c,$t as d,N as e,_t as f,Ln as g,Jn as h,Et as i,Z as j,$ as k,dn as l,tt as m,yn as n,bn as o,dt as p,lt as q,It as r,it as s,M as t,fr as u,St as v,Vn as w,En as x,zn as y,br as z};
@@ -1,4 +1,4 @@
1
- import{r as E,j as e,c as Z}from"./index-DvjcW_EJ.js";import{l as ue,c as he,u as xe,d as ge,g as je,i as fe,a as pe,b as ye,e as ve}from"./use-memberships-query-TpnxzBRP.js";import{aG as ne,u as I,aM as b,aN as K,ax as Y,aO as O,aP as ie,aQ as re,aR as we,ay as be,aS as Ce,aT as J,aw as Ne,aU as Ae,aV as ke}from"./conversation-input-sync-QxTZG_kn.js";import{c as Se,L as De,T as ee,B as l,S as z,a as oe,b as M,d as L,e as v,X as Te,f as w,A as te,g as se,h as ae}from"./error-boundary-BCN3_4Dn.js";import{f as W,u as Ee,i as Fe,a as _e,b as Pe,c as qe,O as Me,H as Le,A as ze}from"./use-download-agent-mutation-BEa3kVfY.js";import{S as Ie,a as Ke,A as Oe,b as Qe,c as Ue}from"./index-CL3E7OEw.js";import"./ui-preferences-store-ClQPCzID.js";import"./en-US-BcB1DWxG.js";import"./book-open-CueO0nwZ.js";import"./console-mirror-D3uHRfYy.js";/**
1
+ import{r as E,j as e,c as Z}from"./index-D3AKz4S0.js";import{l as ue,c as he,u as xe,d as ge,g as je,i as fe,a as pe,b as ye,e as ve}from"./use-memberships-query-BCYb4zy-.js";import{aG as ne,u as I,aM as b,aN as K,ax as Y,aO as O,aP as ie,aQ as re,aR as we,ay as be,aS as Ce,aT as J,aw as Ne,aU as Ae,aV as ke}from"./conversation-input-sync-OV-zVDW5.js";import{c as Se,L as De,T as ee,B as l,S as z,a as oe,b as M,d as L,e as v,X as Te,f as w,A as te,g as se,h as ae}from"./error-boundary-CSpbAh09.js";import{f as W,u as Ee,i as Fe,a as _e,b as Pe,c as qe,O as Me,H as Le,A as ze}from"./use-download-agent-mutation-BeXUxQ99.js";import{S as Ie,a as Ke,A as Oe,b as Qe,c as Ue}from"./index-C6Rz44O3.js";import"./ui-preferences-store-C8Rl4euY.js";import"./en-US-BcB1DWxG.js";import"./book-open-BAj696yM.js";import"./console-mirror-CwJYzF72.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 C}from"./index-DvjcW_EJ.js";import{aQ as De,aM as xe,aS as Re,aG as ms,aH as hs,u as xs,aN as gs,be as fs,aO as ps,a8 as _e,bf as bs,az as js,ay as Be,b3 as vs,bg as Ns,a as ys,bh as ws,aZ as ks,bi as Ts}from"./conversation-input-sync-QxTZG_kn.js";import{P as Cs}from"./page-header-ouA0fPx9.js";import{c as Ue,f as Q,B as f,e as x,r as Ss,A as J,g as ee,h as se,z as Rs,F as _s,G as As,H as Ps,I as Os,s as Ae,t as Pe,u as Oe,v as Ee,w as ze}from"./error-boundary-BCN3_4Dn.js";import{e as Es,f as zs,p as Is,P as Ms,b as Fs,h as Ls}from"./use-memberships-query-TpnxzBRP.js";import{O as $s,A as Ds,f as Bs,H as Us,a as Vs,b as Hs,c as qs,d as Ve,C as Ys,e as Qs,u as Ws,i as Gs}from"./use-download-agent-mutation-BEa3kVfY.js";import{c as Zs,at as Xs,as as Ks,au as Js,av as et}from"./index-CL3E7OEw.js";import{R as st}from"./radient-auth-buttons-BuYF7pw2.js";import{o as He,u as tt,a as at,b as nt}from"./org-surface-gate-CoX7en0B.js";import{f as it}from"./format-CZUObkkr.js";import"./ui-preferences-store-ClQPCzID.js";import"./en-US-BcB1DWxG.js";import"./book-open-CueO0nwZ.js";import"./console-mirror-D3uHRfYy.js";/**
1
+ import{r,j as e,c as C}from"./index-D3AKz4S0.js";import{aQ as De,aM as xe,aS as Re,aG as ms,aH as hs,u as xs,aN as gs,be as fs,aO as ps,a8 as _e,bf as bs,az as js,ay as Be,b3 as vs,bg as Ns,a as ys,bh as ws,aZ as ks,bi as Ts}from"./conversation-input-sync-OV-zVDW5.js";import{P as Cs}from"./page-header-CtaLB27K.js";import{c as Ue,f as Q,B as f,e as x,r as Ss,A as J,g as ee,h as se,z as Rs,F as _s,G as As,H as Ps,I as Os,s as Ae,t as Pe,u as Oe,v as Ee,w as ze}from"./error-boundary-CSpbAh09.js";import{e as Es,f as zs,p as Is,P as Ms,b as Fs,h as Ls}from"./use-memberships-query-BCYb4zy-.js";import{O as $s,A as Ds,f as Bs,H as Us,a as Vs,b as Hs,c as qs,d as Ve,C as Ys,e as Qs,u as Ws,i as Gs}from"./use-download-agent-mutation-BeXUxQ99.js";import{c as Zs,at as Xs,as as Ks,au as Js,av as et}from"./index-C6Rz44O3.js";import{R as st}from"./radient-auth-buttons-UbGqgyO-.js";import{o as He,u as tt,a as at,b as nt}from"./org-surface-gate-Bl-JDkP1.js";import{f as it}from"./format-CZUObkkr.js";import"./ui-preferences-store-C8Rl4euY.js";import"./en-US-BcB1DWxG.js";import"./book-open-BAj696yM.js";import"./console-mirror-CwJYzF72.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-D6fK_4tD.js","./index-DvjcW_EJ.js","./index-B4ItTI5Q.css","./conversation-input-sync-QxTZG_kn.js","./ui-preferences-store-ClQPCzID.js","./error-boundary-BCN3_4Dn.js","./conversation-input-sync-CIGg7Rga.css","./page-header-ouA0fPx9.js","./index-CL3E7OEw.js","./console-mirror-D3uHRfYy.js","./console-mirror-DOrYoP_4.css","./index-DHKnfVbX.css","./settings-section-8d2ITQC3.js","./use-memberships-query-TpnxzBRP.js","./org-surface-gate-CoX7en0B.js","./radient-auth-buttons-BuYF7pw2.js"])))=>i.map(i=>d[i]);
2
- import{ao as _e,a$ as yt,as as vt,b0 as kt,a as et,u as wt,b1 as Nt,X as V,b2 as Pe,aO as me,d as ce,aA as Te,ab as St,ac as Ct,ae as Et,S as It,aQ as tt,ah as st,b3 as nt,ax as ke,b4 as at,b5 as At,aR as Tt,b6 as Rt,b7 as $t,b8 as Dt,b9 as Be,ba as Lt,aG as Ft,bb as _t,bc as Ot,bd as Mt}from"./conversation-input-sync-QxTZG_kn.js";import{r as o,j as e,c as Z}from"./index-DvjcW_EJ.js";import{ag as Ut,ah as Pt,ai as Bt,aj as qt,ak as zt,al as Wt,am as Ht,an as Kt,ao as Gt,ap as it,aq as Vt,ar as Jt,b as Yt,as as rt,A as Qt}from"./index-CL3E7OEw.js";import{c as Xt,j as O,B as N,q as Zt,r as es,e as de,A as se,g as ne,h as ae,I as he,s as ot,t as lt,u as ct,v as dt,w as we,x as Ee,y as Ne,T as Le,M as ts,z as ss,F as ns,G as qe}from"./error-boundary-BCN3_4Dn.js";import{C as as,c as is}from"./ui-preferences-store-ClQPCzID.js";import"./console-mirror-D3uHRfYy.js";/**
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./legacy-agents-page-ObLsHUbL.js","./index-D3AKz4S0.js","./index-BiiXZuiA.css","./conversation-input-sync-OV-zVDW5.js","./ui-preferences-store-C8Rl4euY.js","./error-boundary-CSpbAh09.js","./conversation-input-sync-CIGg7Rga.css","./page-header-CtaLB27K.js","./index-C6Rz44O3.js","./console-mirror-CwJYzF72.js","./console-mirror-DOrYoP_4.css","./index-DHKnfVbX.css","./settings-section-4FpgfOx3.js","./use-memberships-query-BCYb4zy-.js","./org-surface-gate-Bl-JDkP1.js","./radient-auth-buttons-UbGqgyO-.js"])))=>i.map(i=>d[i]);
2
+ import{ao as _e,a$ as yt,as as vt,b0 as kt,a as et,u as wt,b1 as Nt,X as V,b2 as Pe,aO as me,d as ce,aA as Te,ab as St,ac as Ct,ae as Et,S as It,aQ as tt,ah as st,b3 as nt,ax as ke,b4 as at,b5 as At,aR as Tt,b6 as Rt,b7 as $t,b8 as Dt,b9 as Be,ba as Lt,aG as Ft,bb as _t,bc as Ot,bd as Mt}from"./conversation-input-sync-OV-zVDW5.js";import{r as o,j as e,c as Z}from"./index-D3AKz4S0.js";import{ag as Ut,ah as Pt,ai as Bt,aj as qt,ak as zt,al as Wt,am as Ht,an as Kt,ao as Gt,ap as it,aq as Vt,ar as Jt,b as Yt,as as rt,A as Qt}from"./index-C6Rz44O3.js";import{c as Xt,j as O,B as N,q as Zt,r as es,e as de,A as se,g as ne,h as ae,I as he,s as ot,t as lt,u as ct,v as dt,w as we,x as Ee,y as Ne,T as Le,M as ts,z as ss,F as ns,G as qe}from"./error-boundary-CSpbAh09.js";import{C as as,c as is}from"./ui-preferences-store-C8Rl4euY.js";import"./console-mirror-CwJYzF72.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 rs=[["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"}]],os=Xt("log-in",rs),ls=[],ze="config-composer-note",We="Configure agents by conversation",cs=["A reviewer that only reads code","Add the coder twice to release-crew","A team called shipping with a manager and two coders"],ds={idle:"bg-ink-dim",running:"bg-accent",stopping:"bg-warning",done:"bg-success",stopped:"bg-ink-muted",error:"bg-danger"};function us({status:t,pulse:s}){return e.jsx("span",{"aria-hidden":"true",className:Z("size-2 shrink-0 rounded-full",ds[t]??"bg-ink-dim",s&&"animate-pulse")})}function ms({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:"max-h-48 space-y-1 overflow-y-auto",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}`))})}function He({run:t,onDismiss:s}){const[n,a]=o.useState(!1),i=o.useRef(null),l=t.status==="running"||t.status==="stopping";o.useEffect(()=>{if(!l)return;const h=g=>{g.key!=="Escape"||g.defaultPrevented||document.querySelector('[role="alertdialog"], [role="dialog"]')||i.current?.focus()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[l]);const u=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:"border-hairline border-b pb-2","data-testid":"config-run-strip",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx(us,{status:t.status,pulse:l}),e.jsx("span",{"aria-live":"polite",className:"text-body-sm text-ink",children:u}),(l||t.status==="stopped"||t.status==="done")&&t.elapsed!=="0s"?e.jsx("span",{className:"text-meta text-ink-muted tabular-nums",children:t.elapsed}):null,t.touched.length>0?e.jsx(O,{variant:"neutral",children:t.touched.length===1?"1 definition":`${t.touched.length} definitions`}):null,e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[t.activity.length>0?e.jsxs(N,{variant:"ghost",size:"sm","aria-expanded":n,onClick:()=>a(h=>!h),children:[n?e.jsx(Zt,{className:"size-3.5"}):e.jsx(es,{className:"size-3.5"}),"Watch"]}):null,l?e.jsxs(N,{ref:i,variant:"secondary",size:"sm",disabled:t.status==="stopping",onClick:()=>void t.stop(),children:[e.jsx(kt,{className:"size-3.5"}),t.status==="stopping"?"Stopping…":"Stop"]}):e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>s?s():t.dismiss(),children:"Dismiss"})]})]}),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,n?e.jsx("div",{className:"mt-2 border-hairline border-t pt-2",children:e.jsx(ms,{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(h=>e.jsxs("li",{className:"text-ink-muted",children:[h.created?"Created ":"Changed ",e.jsx("span",{className:"text-ink",children:h.target.name})]},`${h.target.kind}:${h.target.name}`))}):null]}):null,t.status==="done"?e.jsx(hs,{run:t}):null,t.status==="error"&&t.error?e.jsxs("div",{className:"mt-2 border-danger-border border-t pt-2",children:[e.jsx("p",{className:"text-body-sm text-danger",children:t.error}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[t.canRetry?e.jsx(N,{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 hs({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 je="agents-config",fs=t=>`Change the ${t.kind} ${t.name}: `;function Re(t,s,n){t.setAbout(s);const a=_e.getState();a.getCurrentInput(je)||a.setComposerText(je,n)}function gs(t){const s=_e.getState();s.getCurrentInput(je).trim()===fs(t).trim()&&s.setComposerText(je,"")}function ut({run:t,hero:s=!1,blockedReason:n,about:a,onClearAbout:i,onStripHeightChange:l}){const u=o.useRef(null),h=o.useRef(null),g=yt(),c=je,r=T=>_e.getState().setCurrentInput(c,T),y=o.useCallback(T=>{if(h.current?.disconnect(),h.current=null,!l)return;if(!T){l(0);return}const $=()=>l(T.getBoundingClientRect().height);if($(),typeof ResizeObserver>"u")return;const D=new ResizeObserver($);D.observe(T),h.current=D},[l]),v=t.status==="running"||t.status==="stopping",j=!t.enabled||!!n,b=n||(v?"Working on your request…":t.enabled?void 0:We),C=a?`Change ${a.name}…`:t.enabled?"Describe what you want…":We,p=a?`${a.kind}:${a.name}`:null;o.useEffect(()=>{p&&u.current?.focusInput()},[p]);const k=()=>{t.dismiss(),u.current?.focusInput()},R=()=>{i(),u.current?.focusInput()};return e.jsxs("div",{className:Z("relative rounded-md border border-hairline bg-surface p-3",s&&"shadow-none"),"data-testid":"config-composer",children:[e.jsx("div",{className:"sr-only",id:"config-composer-label",children:"Ask for an agent or team change"}),t.enabled&&t.status!=="idle"?s?e.jsx(He,{run:t,onDismiss:k}):e.jsx("div",{ref:y,className:"absolute inset-x-0 bottom-full rounded-t-md border-hairline border bg-canvas p-3",children:e.jsx(He,{run:t,onDismiss:k})}):null,a?e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsxs(O,{variant:"accent","data-testid":"config-composer-about",children:["About ",a.kind," ",a.name]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:R,children:"Clear"})]}):null,e.jsx(vt,{ref:u,conversationId:c,messages:ls,isLoading:!1,transcriptless:!0,placeholderOverride:C,sessionStatus:t.frontend?{frontend:t.frontend}:void 0,recordingProbe:g,hostNotice:{id:ze,blocksInput:!t.enabled||!!n||v,placeholder:b,node:e.jsx("p",{id:ze,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-muted",children:t.enabled?"Runs in the background. This does not appear in your conversation.":t.disabledReason})},onSendMessage:(T,$)=>t.start(T,a,$)}),t.enabled?e.jsx("div",{className:Z("mt-2 flex flex-wrap gap-1.5",as,t.enabled&&!a&&!v?"":"invisible"),children:cs.map(T=>e.jsx(N,{variant:"outline",size:"sm",disabled:j,onClick:()=>{r(T),u.current?.focusInput()},children:T},T))}):null]})}const Ke=(t,s)=>t.kind===s.kind&&t.name===s.name;function ps(t){return`${t.kind}:${t.name}`}const z=is(t=>({sessionId:null,status:"idle",topic:"",images:[],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,i=[])=>t({sessionId:s,status:"running",topic:n,images:i,error:null,stopError:null,startedAt:Date.now(),settledAt:null,touched:[],results:[],answer:"",before:a,unsent:!1}),noteTouched:s=>t(n=>n.touched.some(a=>Ke(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(i=>({...i.target,created:i.created})),sessionId:null,images:[],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:[],touched:[],results:[],answer:"",marks:[],startedAt:null,settledAt:null,before:null}),clearMark:s=>t(n=>({marks:n.marks.filter(a=>!Ke(a,s))}))})),xs=/Value error,\s*([\s\S]*?)\s*\[type=/,bs=/^\d+ validation errors? for \S+[\s\S]*?\n\s*/i,js=/\s*\[type=[^\]]*\][\s\S]*$/m,ys=/\s*For further information visit \S+/g,vs=/'([^']+)' already exists/,ks=/cannot contain spaces or path separators/i,ws=/effort tier '([^']+)' is unavailable/i,Ns=/team name must be/i,Ss=/manager '([^']+)'/i,Cs=/(?:member|role) '([^']+)' (?:is not|does not)/i,Es=/depth|cycle|circular/i,Is=/instructions/i,As=/description/i;function Ts(t){const s=t.match(xs);return s?.[1]?s[1].trim():t.replace(bs,"").replace(js,"").replace(ys,"").trim()}function ye(t){const s=Ts(t),n=s.match(vs);if(n)return{message:`An agent called “${n[1]}” already exists. Choose another name, or open the existing one to change it.`,field:"name"};if(ks.test(s))return{message:"Names cannot contain spaces or slashes.",field:"name"};const a=s.match(ws);if(a)return{message:`“${a[1]}” is not a configured effort tier. Use inherit, or add the tier in Settings.`,field:"effort"};if(s.match(Ns))return{message:"A team name is 1-64 characters.",field:"name"};const l=s.match(Ss);if(l)return{message:`“${l[1]}” is not an agent or a team on this machine.`,field:"manager"};const u=s.match(Cs);return u?{message:`“${u[1]}” is not an agent or a team on this machine.`,field:"members"}:Es.test(s)?{message:"That team would nest too deeply, or would contain itself. Check its members.",field:"members"}:Is.test(s)?{message:s,field:"instructions"}:As.test(s)?{message:s,field:"description"}:{message:s,field:null}}function Rs(t,s){const n=new Set(s),a=`${t}-copy`;if(!n.has(a))return a;for(let i=2;i<100;i+=1){const l=`${a}-${i}`;if(!n.has(l))return l}return a}function Ie(t){return t.action_class==="proactive"?"proactive":"reactive"}const $s={proactive:"Proactive"},Ds={proactive:"It may message you on its own: after sending you something it waits a few minutes for a reply, nudges again with growing gaps for a fixed number of tries, then waits for you — and it may also wake on its own schedule.",reactive:"It replies when you write to it. It does not nudge you, and it does not wake on its own schedule."},Ls={proactive:"Turning this off stops the nudging and the scheduled wakes. It still replies when you write to it.",reactive:"Turning this on lets it write first: it will wait a few minutes for your reply, nudge you again up to a fixed number of tries, and it may wake on its own schedule. It still replies when you write to it."},Fs="This one ships with the app and has no copy of its own yet, so switching installs it first — the same agent and the same instructions, now editable — and then sets its class.";function _s(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 Os(t,s,n,a=()=>crypto.randomUUID()){if(Ie(t)===s)return null;let i=null;const l=_s(t,s);for(let u=0;u<l.length;u+=1){const h=l[u];try{i=await n(h,a())}catch(g){throw new mt(g,l.slice(0,u))}}return i}class mt extends Error{completed;constructor(s,n){super(s instanceof Error?s.message:String(s)),this.name="ClassSwitchError",this.completed=n}}function Ms(t,s){const n=t instanceof Error&&t.message?t.message:"The backend sent no reason for it. Try the switch again.",a=ye(n).message;return s.some(i=>i.op==="profiles.install")?`${a} The install did land, so the agent is editable now.`:a}const Us=new Set(["agent","team"]);function Ps(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",i=n?{kind:a,name:n}:null,l=t.phase==="done"&&!t.isError&&!t.notRunReason&&!t.neverSent,u=h=>({writes:h&&l});switch(s){case"create":return{verb:n?`Creating ${a} ${n}`:`Creating a ${a}`,target:i,...u(!0)};case"update":return{verb:n?`Updating ${a} ${n}`:`Updating a ${a}`,target:i,...u(!0)};case"install":return{verb:n?`Installing ${n}`:"Installing an agent",target:i,...u(!0)};case"list":case"search":case"show":return{verb:n?`Reading ${n}`:`Reading ${a}s`,target:i,...u(!1)};default:return{verb:t.phase==="running"?`Working on ${a}s`:`Checked ${a}s`,target:i,...u(!0)}}}const Bs={description:"description",kind:"kind",tools:"tools",effort:"effort tier",delegate:"delegation",action_class:"class",manager:"manager",members:"members",instructions:"instructions"};function qs(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:Ie(t)}}function zs(t){return{description:t.description??"",manager:t.manager??"",members:(t.members??[]).map(s=>`${s.kind}:${s.role}x${s.count}`).sort().join(",")}}function Ge(t,s){return{agents:Object.fromEntries((t??[]).map(n=>[n.name,qs(n)])),teams:Object.fromEntries((s??[]).map(n=>[n.name,zs(n)]))}}function Ws(t,s){if(t===s)return"tools";const n=h=>h==="*"?null:new Set(h.split(",")),a=n(t),i=n(s);if(i===null)return"tools widened to every tool";if(a===null)return"tools narrowed to a list";const l=[...i].filter(h=>!a.has(h)),u=[...a].filter(h=>!i.has(h));return l.length&&!u.length?l.length===1?`tool added: ${l[0]}`:`${l.length} tools added`:u.length&&!l.length?u.length===1?`tool removed: ${u[0]}`:`${u.length} tools removed`:"tools changed"}function Hs(t,s,n){if(t==="tools")return Ws(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=i=>i?i.split(",").length:0;return`members changed (${a(s)} to ${a(n)})`}return`${Bs[t]??t} changed`}function Ks(t,s,n){const a=[],i=new Set;for(const l of n){const u=`${l.kind}:${l.name}`;if(i.has(u))continue;i.add(u);const h=t[l.kind==="agent"?"agents":"teams"][l.name],g=s[l.kind==="agent"?"agents":"teams"][l.name];if(!g)continue;if(!h){a.push({target:l,created:!0,changes:[]});continue}const c=[];for(const r of Object.keys(g))g[r]!==h[r]&&c.push({label:Hs(r,h[r],g[r]),before:h[r],after:g[r]});a.push({target:l,created:!1,changes:c})}for(const[l,u]of[["agent",s.agents],["team",s.teams]])for(const h of Object.keys(u))i.has(`${l}:${h}`)||(l==="agent"?t.agents[h]:t.teams[h])||a.push({target:{kind:l,name:h},created:!0,changes:[]});return a}function Gs(t){return ce(t,"agents_config")&&ce(t,"session_interrupt")&&ce(t,"profile_catalogue")&&ce(t,"team_catalogue")}function Vs(t){if(!(t instanceof It)||t.status!==409)return null;const n=t.detail?.session_id;return typeof n=="string"&&n.length>0?n:null}function Js(t,s){const[n,a]=o.useState(()=>Date.now());return o.useEffect(()=>{if(!t||!s)return;const i=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(i)},[t,s]),t?Math.max(0,n-t):0}function Ys(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 Ve(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 Qs(t){const n=t?.payload?.frontend;if(!n||typeof n!="object")return null;const a=n.streaming;if(typeof a=="boolean")return a;const i=n.snapshot?.streaming;return typeof i=="boolean"?i:null}function Xs(){const t=et(),s=Gs(t.data),n=wt(),a=z(),[i,l]=o.useState(!1),[u,h]=o.useState(!1),g=o.useRef(!1),c=a.status==="running"||a.status==="stopping",r=Nt(a.sessionId??void 0,!!a.sessionId),y=o.useMemo(()=>Ve(r.transcript?.records),[r.transcript?.records]);Ut(a.sessionId??void 0,r.subscriptionId);const v=r.transcript?.records,j=o.useRef(v);o.useEffect(()=>{j.current=v},[v]);const b=o.useMemo(()=>(r.transcript?.records??[]).filter(E=>E.kind==="tool"&&Us.has(E.toolName)).map(E=>({...Ps({toolName:E.toolName,args:E.args??null,phase:E.phase,ts:E.ts,isError:E.isError,notRunReason:E.notRunReason,neverSent:E.neverSent}),ts:E.ts})),[r.transcript]);o.useEffect(()=>{if(c)for(const x of b)x.target&&x.writes&&a.noteTouched(x.target)},[b,c,a]);const C=c&&b.length>0?b[b.length-1].verb:null,p=Ys(Js(a.startedAt,c)),k=o.useCallback(async(x,E="")=>{if(g.current)return;g.current=!0;const L=a.before;let I=[];try{const[U,_]=await Promise.all([V({op:"profiles.list"}),V({op:"teams.list"})]);L&&(I=Ks(L,Ge(U.profiles,_.teams),a.touched))}catch{z.getState().fail("The run finished, but the agents and teams lists could not be read to describe what changed."),Pe(n);return}if(Pe(n),z.getState().settle(I,x,E),x==="done"&&I.length>0){const U=I.filter(_=>_.created).length;me(U>0?`Configuration run finished: ${I.length} definition${I.length===1?"":"s"} changed.`:`Configuration run finished: ${I.length} definition${I.length===1?"":"s"} updated.`)}},[n,a.before,a.touched]);o.useEffect(()=>{if(c){if(r.failure){z.getState().fail(r.failure.statement);return}g.current||r.frontend&&(r.frontend.streaming||r.turnsCompleted!==0&&k(a.status==="stopping"?"stopped":"done",y))}},[c,y,r.failure,r.frontend,r.turnsCompleted,a.status,k]),o.useEffect(()=>{const x=a.sessionId;if(!c||!x)return;let E=!1;const L=async()=>{if(!(E||g.current))try{const _=await V({op:"sessions.get",sessionId:x});if(E||g.current||Qs(_)!==!1)return;const H=Ve(j.current);if(!H)return;k(z.getState().status==="stopping"?"stopped":"done",H)}catch{}},I=setTimeout(()=>void L(),400),U=setInterval(()=>void L(),4e3);return()=>{E=!0,clearTimeout(I),clearInterval(U)}},[c,a.sessionId,k]);const R=async(x,E,L=[])=>{if(i||!x.trim()&&L.length===0)return!1;l(!0),h(!1),g.current=!1;const I=Ge(n.getQueryData(["desktop","profiles"]),n.getQueryData(["desktop","teams"])),U=E?`About the ${E.kind} “${E.name}”: ${x.trim()}`:x.trim(),{images:_,unreadable:H,overflow:q}=await St(L,U),X=Ct(H);if(X)return z.getState().fail(X),!1;const P=Et(q);if(P)return z.getState().fail(P),!1;try{let W;try{W=(await V({op:"sessions.create",requestId:crypto.randomUUID(),purpose:"agents-config"})).session_id}catch(K){const J=Vs(K);if(J)return h(!0),a.adopt(J,x.trim(),I,_),!1;throw K}return a.adopt(W,U,I,_),await T(W,U,_),!0}catch(W){const K=z.getState().sessionId;return z.getState().failUnsent(Te(W,K?"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{l(!1)}},T=async(x,E,L=[])=>{await V({op:"sessions.message",sessionId:x,requestId:crypto.randomUUID(),text:E,...L.length>0?{images:L}:{}})},$=async()=>{const x=z.getState();if(!(i||!x.unsent||!x.sessionId||!x.topic&&x.images.length===0)){l(!0);try{await T(x.sessionId,x.topic,x.images),a.adopt(x.sessionId,x.topic,x.before),g.current=!1}catch(E){z.getState().failUnsent(Te(E,"The request could not be sent. It is still in the box."))}finally{l(!1)}}},D=async()=>{const x=z.getState().sessionId;if(x){a.stopping();try{await Pt(x,crypto.randomUUID())}catch(E){z.getState().stopFailed(Te(E,"The run did not acknowledge the request."))}}},w=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:w,status:a.status,sessionId:a.sessionId,frontend:r.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:C,elapsed:p,activity:b,start:R,stop:D,retry:$,canRetry:a.unsent&&!!a.sessionId,dismiss:a.dismiss,starting:i,attached:u}}function F({title:t,description:s,actions:n,children:a,className:i}){return e.jsxs("section",{className:Z("space-y-2 border-hairline border-t pt-4 first:border-t-0 first:pt-0",i),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]})}function ue({text:t,empty:s="Nothing here yet.",mono:n=!1}){const[a,i]=o.useState(!1),[l,u]=o.useState(!1),h=o.useRef(null);return o.useEffect(()=>{if(a)return;const g=h.current;g&&u(!!t&&g.scrollHeight>g.clientHeight+1)},[t,a]),t.trim()?e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{ref:h,tabIndex:0,"aria-label":"The full text",className:Z("whitespace-pre-wrap rounded-sm border border-hairline bg-surface px-3 py-2 text-body-sm text-ink",!a&&"max-h-64 overflow-y-auto",n&&"font-mono text-meta"),children:t}),l?e.jsx(N,{variant:"link",size:"sm",onClick:()=>i(g=>!g),children:a?"Show less":"Show all"}):null]}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:s})}function ht({source:t,appearance:s="chip"}){const n=t==="builtin"?"Built-in":t==="installed"?"Installed":"Custom";return s==="text"?e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:n}):e.jsx(O,{variant:"neutral",children:n})}function ft(t,s){o.useEffect(()=>{if(!s)return;const n=a=>{a.key!=="Escape"||a.defaultPrevented||(a.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[s,t])}function Oe({dirty:t,pending:s,onSave:n,onCancel:a,saveLabel:i="Save changes",pendingLabel:l="Saving…",dirtyHint:u,submit:h,confirming:g,onConfirmingChange:c}){const[r,y]=o.useState(!1),v=o.useRef(null),j=o.useRef(null),b=g!==void 0,C=b?g:r;o.useEffect(()=>{C&&j.current?.focus()},[C]);const p=k=>{b||y(k),c?.(k)};return o.useEffect(()=>{t||(b||y(!1),c?.(!1))},[t,b,c]),e.jsxs("div",{"data-testid":"edit-footer",className:"sticky bottom-0 z-10 -mx-6 mt-6 flex flex-wrap items-center gap-2 border-hairline border-t bg-canvas px-6 py-3",children:[e.jsx(N,{ref:v,type:h?"submit":void 0,variant:"primary",onClick:h?void 0:n,disabled:s,children:s?l:i}),C?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:u??"Discard your unsaved changes?"}),e.jsx(N,{variant:"danger",onClick:a,children:"Discard changes"}),e.jsx(N,{ref:j,variant:"ghost",onClick:()=>{p(!1),v.current?.focus()},children:"Keep editing"})]}):e.jsx(N,{variant:"ghost",onClick:()=>t?p(!0):a(),disabled:s,children:"Cancel"}),t&&!C?e.jsx("span",{className:"text-meta text-ink-muted",children:"Unsaved changes"}):null]})}let Fe=!1;function gt(){Fe=!0}function pt(){const t=Fe;return Fe=!1,t}function Zs({rows:t=6}){return e.jsx("div",{className:"space-y-1","aria-hidden":"true",children:en.slice(0,t).map(s=>e.jsx(de,{className:"h-11 w-full"},s))})}const en=["a","b","c","d","e","f","g","h"];function Je(){return e.jsxs("div",{className:"max-w-3xl space-y-6","aria-hidden":"true",children:[e.jsx(de,{className:"h-7 w-64"}),e.jsx(de,{className:"h-5 w-40"}),e.jsx(de,{className:"h-28 w-full"}),e.jsx(de,{className:"h-24 w-full"})]})}function Ye({title:t,what:s,meaning:n,onRetry:a,retrying:i=!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(N,{variant:"secondary",onClick:a,disabled:i,children:i?"Retrying…":"Retry"})]})}function ee({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 tn=/^[A-Za-z0-9_.:-]{1,128}$/;function te(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 sn(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 nn({profile:t}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(ht,{source:t.source}),t.divergent_fields?.length?e.jsx(O,{variant:"warning",children:"Modified"}):null,t.kind==="specialist"?e.jsx(O,{variant:"neutral",children:"Specialist"}):null,t.delegate?e.jsx(O,{variant:"neutral",children:"Delegates"}):null,t.tools&&t.tools.length>0?e.jsx(O,{variant:"neutral",children:t.tools.length===1?"1 tool":`${t.tools.length} tools`}):null]})}const an=5e3;let $e=null;function rn({profile:t,displayedName:s,notice:n,onNotice:a,onChanged:i}){const l=Ie(t),[u,h]=o.useState(null),[g,c]=o.useState(!1),r=o.useRef(null),y=o.useId();o.useEffect(()=>{u!==null&&l===u&&h(null)},[l,u]),o.useEffect(()=>{const b=$e;!b||b.name!==t.name||($e=null,!(Date.now()-b.at>an)&&r.current?.focus())},[t.name]);const v=u??l,j=async b=>{if(!(g||b===v)){$e={name:t.name,at:Date.now()},a(null),h(b),c(!0);try{await Os(t,b,(C,p)=>C.op==="profiles.install"?V({op:"profiles.install",name:C.name,requestId:p}):V({op:"profiles.update",name:C.name,requestId:p,fields:C.fields??{}})),i(t.name),me(b==="proactive"?`${s} is now proactive — it may message you on its own.`:`${s} is now reactive — proactive messaging stopped.`)}catch(C){h(null);const p=C instanceof mt?C.completed:[],k=Ms(C,p);a(k),ke(k),i(t.name)}finally{c(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex items-center gap-2 text-body-sm",children:[e.jsx(Ee,{ref:r,checked:v==="proactive","aria-disabled":g,"aria-labelledby":y,"data-testid":"agent-class-switch",className:"after:absolute after:inset-0 after:content-['']",onCheckedChange:b=>void j(b?"proactive":"reactive")}),e.jsx("span",{id:y,className:"text-ink",children:"Can message me on its own"}),e.jsx("span",{"aria-live":"polite",className:"text-ink-muted",children:g?"Switching…":v==="proactive"?"On":"Off"})]}),e.jsx("p",{className:"text-body-sm text-ink",children:Ds[v]}),e.jsx("p",{className:"text-meta text-ink-muted",children:Ls[v]}),t.source==="builtin"?e.jsx("p",{className:"text-meta text-ink-muted",children:Fs}):null,n?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-class-error",children:[e.jsx(ne,{children:"The switch did not go through"}),e.jsx(ae,{children:n})]}):null]})}function xt({tools:t,onChange:s,error:n}){const[a,i]=o.useState(""),[l,u]=o.useState(null),h=o.useId(),g=()=>{const c=a.trim();if(c){if(!tn.test(c)){u("Tool names are letters, digits, dot, underscore, dash or colon.");return}if(t?.includes(c)){u("That tool is already listed.");return}u(null),i(""),s([...t??[],c])}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(Ee,{checked:t===null,onCheckedChange:c=>s(c?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(c=>e.jsx("li",{children:e.jsxs(O,{variant:"outline",children:[c,e.jsx(N,{variant:"ghost",size:"sm","aria-label":`Remove ${c}`,onClick:()=>s(t.filter(r=>r!==c)),className:"ml-1 h-4 px-1",children:"×"})]})},c))}):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(ee,{label:"Add a tool",htmlFor:h,error:l??n}),e.jsx(he,{id:h,value:a,inputSize:"md",placeholder:"Tool name","aria-invalid":!!(l??n),onChange:c=>{i(c.target.value),u(null)},onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),g())}})]}),e.jsx(N,{variant:"secondary",onClick:g,disabled:!a.trim(),children:"Add"})]})]})]})}function on({profile:t,displayedName:s,classNotice:n,onClassNotice:a,teams:i,effortTiers:l,askEnabled:u,onSaved:h,onDuplicate:g,onOpenTeam:c,onAskAgent:r,onDirtyChange:y}){const[v,j]=o.useState(!1),[b,C]=o.useState(()=>te(t)),[p,k]=o.useState(()=>te(t)),[R,T]=o.useState(!1),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(!1),[I,U]=o.useState(!1),[_,H]=o.useState(!1),q=o.useRef(null),X=tt(),P=JSON.stringify(p)!==JSON.stringify(b);o.useEffect(()=>(y?.(v&&P),()=>y?.(!1)),[y,v,P]),o.useEffect(()=>{pt()&&requestAnimationFrame(()=>q.current?.focus())},[]),o.useEffect(()=>{if(v&&P)return;const f=te(t);C(f),k(f)},[t,v,P]),o.useEffect(()=>{if(!v){U(!1);return}const f=te(t);U(P&&JSON.stringify(f)!==JSON.stringify(b))},[t,v,P,b]);const W=()=>{j(!1),D(null),x(null),L(!1),H(!1);const f=te(t);C(f),k(f)};ft(()=>{if(_){H(!1);return}P?H(!0):W()},v);const J=async f=>{if(f?.preventDefault(),R)return;const A=sn(b,p);if(Object.keys(A).length===0){W();return}if(typeof A.instructions=="string"&&!A.instructions.trim()){D("Give the agent instructions."),x("instructions");return}T(!0),D(null),x(null);try{const G=await V({op:"profiles.update",name:t.name,requestId:crypto.randomUUID(),fields:A});j(!1),L(!1);const Y=te(G);C(Y),k(Y),h(G.name),me(`Saved ${G.name}.`),requestAnimationFrame(()=>q.current?.focus())}catch(G){const Y=ye(G instanceof Error?G.message:"The agent could not be saved.");D(Y.message),x(Y.field);const re=G?.status,fe=typeof re=="number"&&re!==408&&re>=400&&re<500;L(!fe),fe||ke("The save could not be confirmed. Check whether it was applied before retrying.")}finally{T(!1)}},d=async()=>{if(!R){T(!0),D(null);try{const f=await V({op:"profiles.install",name:t.name,requestId:crypto.randomUUID()}),A=te(f);C(A),k(A),h(f.name),me(`Installed ${f.name}. It can be edited now.`),requestAnimationFrame(()=>q.current?.focus())}catch(f){const A=ye(f instanceof Error?f.message:"The agent could not be installed.");D(A.message),ke(A.message)}finally{T(!1)}}},S=(i??[]).filter(f=>f.manager===t.name||(f.members??[]).some(A=>A.role===t.name)),B=t.source==="builtin";return e.jsxs("div",{className:"max-w-3xl space-y-6",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 space-y-2",children:[e.jsx("h2",{ref:q,tabIndex:-1,className:"text-title focus:outline-none",children:s}),e.jsx(nn,{profile:t})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"primary",onClick:()=>{st.getState().stageDraft({kind:"agent",name:t.name}),X("/chat")},children:"New chat"}),B?e.jsxs(N,{variant:"secondary",onClick:d,disabled:R,children:[e.jsx(os,{className:"size-4"}),R?"Installing…":"Install to edit"]}):e.jsx(N,{variant:"secondary",onClick:()=>{j(!0),D(null),x(null)},children:"Edit"}),e.jsx(N,{variant:"ghost",onClick:()=>g(t),children:"Duplicate as new agent"}),u?e.jsx(N,{variant:"ghost",onClick:()=>r(`Change the agent ${t.name}: `),children:"Ask for a change"}):null]})]}),B?e.jsxs(se,{variant:"info",children:[e.jsx(ne,{children:"Built-in agent"}),e.jsx(ae,{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,I?e.jsxs(se,{variant:"warning","data-testid":"agent-conflict",children:[e.jsx(ne,{children:"This changed while you were editing"}),e.jsxs(ae,{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(N,{variant:"secondary",size:"sm",className:"mt-2",onClick:W,children:"Reload the saved version"})]})]}):null,E?e.jsxs(se,{variant:"danger","data-testid":"agent-unconfirmed",children:[e.jsx(ne,{children:"The last save was not confirmed"}),e.jsx(ae,{children:"The backend did not answer, so the write may or may not have landed. Check the agent below, then edit again."})]}):null,$&&!w?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-save-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:$})]}):null]}),e.jsx("form",{noValidate:!0,onSubmit:f=>{f.preventDefault(),J(f)},className:"space-y-6",children:v?e.jsxs(e.Fragment,{children:[e.jsx(Se,{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:p.description,error:w==="description"?$:null,onChange:f=>k(A=>({...A,description:f}))}),e.jsx(Se,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:p.instructions,rows:12,required:!0,error:w==="instructions"?$:null,onChange:f=>k(A=>({...A,instructions:f}))}),e.jsx(F,{title:"Tools",children:e.jsx(xt,{tools:p.tools,error:w==="tools"?$:null,onChange:f=>k(A=>({...A,tools:f}))})}),e.jsx(F,{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(Ee,{checked:p.delegate,onCheckedChange:f=>k(A=>({...A,delegate:f})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"max-w-sm space-y-1",children:[e.jsx(ee,{label:"Effort tier",htmlFor:"agent-effort",error:w==="effort"?$:null}),e.jsx(Ne,{ariaLabel:"Effort tier",showLabel:!1,placeholder:"Choose an effort tier",busyLabel:"Loading effort tiers",options:["inherit",...l].map(f=>({id:f,name:f,description:f==="inherit"?"Use the session's own effort":void 0})),selected:{id:p.effort,name:p.effort},onSelect:f=>k(A=>({...A,effort:f.id})),helperText:"Tiers come from the backend's subagent model settings."})]})]})}),e.jsx(Oe,{submit:!0,confirming:_,onConfirmingChange:H,dirty:P,pending:R,onSave:()=>void J(),onCancel:W,saveLabel:"Save changes",dirtyHint:"Discard your unsaved changes to this agent?"})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"When to use it",children:e.jsx(ue,{text:t.description||"",empty:"No description yet — add one so a model knows when to pick this agent."})}),e.jsx(F,{title:"Instructions",children:e.jsx(ue,{text:t.instructions??t.packaged_instructions??"",empty:"No instructions yet."})}),e.jsx(F,{title:"Tools",children:t.tools&&t.tools.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.tools.map(f=>e.jsx("li",{children:e.jsx(O,{variant:"outline",children:f})},f))}):e.jsx(O,{variant:"neutral",children:"All tools"})}),e.jsxs(F,{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"]})]}),e.jsx(F,{title:"Messaging",description:"Reactive agents only reply. Proactive agents may also message you first.",children:e.jsx(rn,{profile:t,displayedName:s,notice:n,onNotice:a,onChanged:h})}),e.jsx(F,{title:"Used by",description:"Teams that name this agent as a manager or a member.",children:S.length>0?e.jsx("ul",{className:"flex flex-wrap gap-x-3 gap-y-1",children:S.map(f=>e.jsx("li",{children:e.jsx(N,{variant:"link",onClick:()=>c(f.name),children:f.name})},f.id))}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:"No team uses it yet."})}),e.jsxs(F,{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(nt,{summary:"Compare with the packaged instructions",className:"mt-2",children:e.jsx(ue,{text:t.packaged_instructions,mono:!0})}):null]})]})})]})}function Se({title:t,description:s,label:n,value:a,onChange:i,rows:l,required:u,error:h,fieldRef:g}){const c=o.useId();return e.jsxs(F,{title:t,description:s,children:[e.jsx(ee,{label:n,htmlFor:c,error:h}),l?e.jsx(Le,{id:c,ref:g,value:a,rows:l,required:u,"aria-invalid":!!h,className:Z("min-h-0"),onChange:r=>i(r.target.value)}):e.jsx(he,{id:c,value:a,"aria-invalid":!!h,onChange:r=>i(r.target.value)})]})}function ln({initial:t,takenNames:s,effortTiers:n,onDirtyChange:a,onSaved:i,onCancel:l}){const[u,h]=o.useState(()=>t?Rs(t.name,s):""),[g,c]=o.useState(t?.kind??"role"),[r,y]=o.useState(()=>t?{...te(t),description:t.description??""}:{description:"",instructions:"",tools:null,effort:"inherit",delegate:!1}),[v,j]=o.useState(!1),[b,C]=o.useState(null),[p,k]=o.useState(null),R=o.useRef(null),T=o.useRef(null);o.useEffect(()=>(a?.(!!(u.trim()||r.instructions.trim())),()=>a?.(!1)),[a,u,r.instructions]),o.useEffect(()=>{R.current?.focus(),R.current?.select()},[]);const $=async w=>{if(w?.preventDefault(),!v){if(!u.trim()){C("Give the agent a name."),k("name"),R.current?.focus();return}if(/[\\/\s]/.test(u.trim())){C("Names cannot contain spaces or slashes."),k("name"),R.current?.focus();return}if(s.includes(u.trim())){C(`An agent called “${u.trim()}” already exists. Choose another name, or open the existing one to change it.`),k("name"),R.current?.focus();return}if(!r.instructions.trim()){C("Give the agent instructions."),k("instructions"),T.current?.focus();return}j(!0),C(null),k(null);try{const x=await V({op:"profiles.create",requestId:crypto.randomUUID(),name:u.trim(),fields:{kind:g,description:r.description,instructions:r.instructions,tools:r.tools??[],effort:r.effort,delegate:r.delegate}});me(`Created ${x.name}.`),gt(),i(x.name)}catch(x){const E=ye(x instanceof Error?x.message:"The agent could not be created.");C(E.message),k(E.field)}finally{j(!1)}}},D=t?"Duplicate as a new agent":"New agent";return e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("h2",{className:"text-title",children:D}),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."})]}),b&&!p?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-create-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:b})]}):null,e.jsxs("form",{noValidate:!0,onSubmit:w=>{w.preventDefault(),$(w)},className:"space-y-6",children:[e.jsx(F,{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(ee,{label:"Name",htmlFor:"agent-create-name",error:p==="name"?b:null}),e.jsx(he,{id:"agent-create-name",ref:R,value:u,required:!0,"aria-invalid":p==="name",onChange:w=>h(w.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ee,{label:"How it works with others",htmlFor:"agent-create-kind"}),e.jsxs(ot,{value:g,onValueChange:w=>c(w),children:[e.jsx(lt,{id:"agent-create-kind",children:e.jsx(ct,{})}),e.jsxs(dt,{children:[e.jsx(we,{value:"role",children:"You can chat with it directly"}),e.jsx(we,{value:"specialist",children:"Other agents can call on it"})]})]})]})]})}),e.jsx(Se,{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:r.description,error:p==="description"?b:null,onChange:w=>y(x=>({...x,description:w}))}),e.jsx(Se,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:r.instructions,rows:12,required:!0,fieldRef:T,error:p==="instructions"?b:null,onChange:w=>y(x=>({...x,instructions:w}))}),e.jsx(F,{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(Ee,{checked:r.delegate,onCheckedChange:w=>y(x=>({...x,delegate:w})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"max-w-sm space-y-1",children:[e.jsx(ee,{label:"Effort tier",htmlFor:"agent-create-effort"}),e.jsx(Ne,{ariaLabel:"Effort tier",showLabel:!1,busyLabel:"Loading effort tiers",placeholder:"Choose an effort tier",options:["inherit",...n].map(w=>({id:w,name:w,description:w==="inherit"?"Use the session's own effort":"A tier configured in Settings"})),selected:{id:r.effort,name:r.effort},onSelect:w=>y(x=>({...x,effort:w.id}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:"Tools"}),e.jsx(xt,{tools:r.tools,error:p==="tools"?b:null,onChange:w=>y(x=>({...x,tools:w}))})]})]})}),e.jsx(Oe,{submit:!0,dirty:!!(u.trim()||r.instructions),pending:v,saveLabel:t?"Create the copy":"Create agent",pendingLabel:"Creating…",dirtyHint:"Discard this new agent?",onSave:()=>void $(),onCancel:l})]})]})}const Ce=t=>t==null?"":typeof t=="string"?t:JSON.stringify(t,null,2),cn={available:"border-hairline",updating:"border-hairline",applied:"border-hairline",review:"border-warning-border",failed:"border-danger-border"};function dn(t){const s=[];for(const n of t??[])for(const a of n.fields??[])for(const i of a.regions??[])(i.provenance==="unresolved"||Ce(i.local)!==Ce(i.remote))&&s.push({field:a.field,region:i});return s}function un({regions:t}){return t.length?e.jsx("ul",{className:"space-y-3","data-testid":"hub-update-preview",children:t.map(({field:s,region:n},a)=>e.jsxs("li",{className:"space-y-1 text-meta",children:[e.jsx("p",{className:"font-medium text-ink",children:n.heading||n.name||s}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-ink-muted",children:"Yours"}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:Ce(n.local)||"(nothing)"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-ink-muted",children:"The hub's"}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:Ce(n.remote)||"(nothing)"})]})]})]},`${s}:${n.id??a}`))}):e.jsx("p",{className:"text-meta text-ink-muted",children:"No differences to show: the hub's version matches yours."})}function mn({kind:t,name:s,enabled:n}){const a=Bt(n),i=qt(),[l,u]=o.useState(null),h=Wt(t,s),g=zt(a.data).get(h),c=Ht(g),r=i.notes[h],y=i.pending.has(h);if(!g||!c)return r?e.jsx("section",{"data-testid":"hub-update-panel","aria-label":"Hub update",className:"mb-6 max-w-3xl rounded-md border border-hairline p-3 text-body-sm",children:e.jsx("p",{role:r.tone==="error"?"alert":"status",className:r.tone==="error"?"text-danger":"text-ink",children:r.message})}):null;const v=c.kind==="review",j=g.classification==="baseline-unknown",b=p=>({prefer:p,acknowledgeUnknownBaseline:j}),C=async()=>{const p=await i.applyItem(t,s,{...b(),dryRun:!0});u(p??[])};return e.jsxs("section",{"data-testid":"hub-update-panel","aria-label":"Hub update",className:Z("mb-6 max-w-3xl space-y-2 rounded-md border p-3 text-body-sm",cn[c.kind]),children:[e.jsxs("p",{className:"flex items-start gap-2 text-ink",children:[e.jsx(Kt,{mark:c,className:"mt-0.5"}),e.jsx("span",{className:Z(c.kind==="failed"&&"text-danger"),children:Gt(g,c)})]}),v&&j&&e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing records what you changed on this device. Either choice adds the hub's additions and deletes nothing of yours; where the two versions differ, your choice decides which wording stays."}),v&&!j&&e.jsx("p",{className:"text-meta text-ink-muted",children:"Where the two versions differ, your choice decides which wording stays. Everything else is merged, and your current version is saved as a backup first."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[c.kind==="available"&&e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s),children:y?"Updating…":"Update from the hub"}),c.kind==="failed"&&c.retryable&&e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void i.retryItem(t,s),children:y?"Retrying…":"Retry"}),v&&e.jsxs(e.Fragment,{children:[e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void C(),children:y&&!l?"Loading…":"Preview the differences"}),e.jsx(N,{size:"sm",variant:"ghost","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s,b("local")),children:"Keep mine where they differ"}),e.jsx(N,{size:"sm",variant:"ghost","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s,b("remote")),children:"Use the hub's where they differ"})]})]}),l&&v&&e.jsx(un,{regions:dn(l)}),r&&e.jsx("p",{role:r.tone==="error"?"alert":"status",className:r.tone==="error"?"text-meta text-danger":"text-meta text-ink-muted",children:r.message})]})}function be(t){return{description:t?.description??"",manager:t?.manager??"manager",members:(t?.members??[]).map(s=>({...s,key:crypto.randomUUID()})),instructions:t?.instructions??"",project:t?.project??""}}function hn(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(({key:a,...i})=>i))!==JSON.stringify(t.members.map(({key:a,...i})=>i))&&(n.members=s.members.map(({key:a,...i})=>i)),s.instructions!==t.instructions&&(n.instructions=s.instructions),s.project!==t.project&&(n.project=s.project),n}function Qe(t,s,n){return(t.kind==="agent"?(s??[]).map(i=>i.name):(n??[]).map(i=>i.name)).includes(t.role)}function Xe({team:t,agents:s,teams:n,askEnabled:a,onSaved:i,onCancelCreate:l,onOpenAgent:u,onAskAgent:h,onDirtyChange:g}){const c=!t,[r,y]=o.useState(c),[v,j]=o.useState(t?.name??""),[b,C]=o.useState(()=>be(t)),[p,k]=o.useState(()=>be(t)),[R,T]=o.useState(!1),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(!1),I=o.useRef(null),U=o.useRef(null),_=o.useRef(null);o.useEffect(()=>{pt()&&requestAnimationFrame(()=>I.current?.focus())},[]);const H=tt(),q=c?!!(v.trim()||p.description||p.members.length):JSON.stringify(p)!==JSON.stringify(b);o.useEffect(()=>(g?.((c||r)&&q),()=>g?.(!1)),[g,c,r,q]),o.useEffect(()=>{if(r&&q)return;const d=be(t);C(d),k(d)},[t,r,q]);const X=()=>{if(c){l?.();return}y(!1),D(null),x(null),L(!1);const d=be(t);C(d),k(d)};ft(()=>{if(E){L(!1);return}q?L(!0):X()},r);const W=async d=>{if(d?.preventDefault(),!R){if(c&&!v.trim()){D("Give the team a name."),x("name"),_.current?.focus();return}if(c&&/[\\/\s]/.test(v.trim())){D("Names cannot contain spaces or slashes."),x("name"),_.current?.focus();return}if(c&&(n??[]).some(S=>S.name===v.trim())){D(`A team called “${v.trim()}” already exists. Open it to change it, or choose another name.`),x("name"),_.current?.focus();return}if(c&&!p.instructions.trim()){D("Give the team instructions."),x("instructions"),U.current?.focus();return}T(!0),D(null),x(null);try{const S=t?await V({op:"teams.update",name:t.name,requestId:crypto.randomUUID(),fields:hn(b,p)}):await V({op:"teams.create",requestId:crypto.randomUUID(),fields:{name:v,description:p.description,manager:p.manager,members:p.members.map(({key:f,...A})=>A),instructions:p.instructions,project:p.project}}),B=be(S);C(B),k(B),y(!1),i(S.name),me(`${c?"Created":"Saved"} ${S.name}.`),c&&gt(),requestAnimationFrame(()=>I.current?.focus())}catch(S){const B=ye(S instanceof Error?S.message:"The team could not be saved.");D(B.message),x(B.field),ke(B.message)}finally{T(!1)}}},K=(d,S)=>k(B=>({...B,members:B.members.map((f,A)=>A===d?{...f,...S}:f)})),J=(p.members.length?p.members:t?.members??[]).reduce((d,S)=>d+(S.count||1),0);return e.jsxs("div",{className:"max-w-3xl space-y-6",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 space-y-2",children:[e.jsx("h2",{ref:I,tabIndex:-1,className:"text-title focus:outline-none",children:t?at(t):"New team"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(O,{variant:"neutral",children:J===1?"1 agent":`${J} agents`}),p.members.some(d=>d.kind==="team")?e.jsx(O,{variant:"neutral",children:"Includes a team"}):null]})]}),t?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"primary",onClick:()=>{st.getState().stageDraft({kind:"team",name:t.name}),H("/chat")},children:"New team chat"}),r?null:e.jsx(N,{variant:"secondary",onClick:()=>y(!0),children:"Edit"}),a?e.jsx(N,{variant:"ghost",onClick:()=>h(`Change the team ${t.name}: `),children:"Ask for a change"}):null]}):null]}),$&&!w?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"team-save-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:$})]}):null]}),e.jsx("form",{noValidate:!0,onSubmit:d=>{d.preventDefault(),W(d)},className:"space-y-6",children:c||r?e.jsxs(e.Fragment,{children:[c?e.jsxs(F,{title:"Name",description:"How you and your chats will refer to this team.",children:[e.jsx(ee,{label:"Team name",htmlFor:"team-name",error:w==="name"?$:null}),e.jsx(he,{ref:_,id:"team-name","data-testid":"team-name-input",value:v,required:!0,maxLength:64,autoFocus:!0,"aria-invalid":w==="name",onChange:d=>j(d.target.value)})]}):null,e.jsx(F,{title:"Manager",description:"The agent that leads the chat and decides who works on what.",children:e.jsxs("div",{className:"max-w-md space-y-2",children:[e.jsx(ee,{label:"Manager agent",htmlFor:"team-manager",error:w==="manager"?$:null}),e.jsx(Ne,{ariaLabel:"Manager agent",showLabel:!1,placeholder:"Choose a manager",busyLabel:"Loading agents",options:le(s,n),selected:le(s,n).find(d=>d.id===p.manager)??null,onSelect:d=>k(S=>({...S,manager:d.id})),onCustomSubmit:d=>k(S=>({...S,manager:d})),listNotice:"Agents and teams on this machine"}),le(s,n).some(d=>d.id===p.manager)?null:e.jsxs(O,{variant:"warning","data-testid":"team-manager-missing",children:["Not found: ",p.manager]})]})}),e.jsx(F,{title:"Members",description:"Who the manager can delegate to, and how many of each.",children:e.jsxs("div",{className:"space-y-2",children:[p.members.map((d,S)=>{const B=!Qe(d,s,n);return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"w-56",children:e.jsx(Ne,{ariaLabel:`Member ${S+1}`,showLabel:!1,placeholder:"Choose an agent or team",busyLabel:"Loading agents",options:[...le(s,n).filter(f=>d.kind==="team"?f.group==="Teams":f.group==="Agents")],selected:le(s,n).find(f=>f.id===d.role)??null,onSelect:f=>K(S,{role:f.id,kind:f.group==="Teams"?"team":"agent"}),onCustomSubmit:f=>K(S,{role:f})})}),e.jsxs(ot,{value:d.kind,onValueChange:f=>K(S,{kind:f}),children:[e.jsx(lt,{"aria-label":`Member ${S+1} kind`,className:"w-32",children:e.jsx(ct,{})}),e.jsxs(dt,{children:[e.jsx(we,{value:"agent",children:"Agent"}),e.jsx(we,{value:"team",children:"Team"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(N,{variant:"secondary",size:"icon-sm","aria-label":`One fewer ${d.role}`,disabled:d.count<=1,onClick:()=>K(S,{count:d.count-1}),children:e.jsx(ts,{"aria-hidden":"true"})}),e.jsx("span",{className:"min-w-6 text-center text-body-sm tabular-nums","aria-label":`${d.count} of ${d.role}`,children:d.count}),e.jsx(N,{variant:"secondary",size:"icon-sm","aria-label":`One more ${d.role}`,disabled:d.count>=16,onClick:()=>K(S,{count:d.count+1}),children:e.jsx(it,{"aria-hidden":"true"})})]}),e.jsx(N,{variant:"ghost",onClick:()=>k(f=>({...f,members:f.members.filter((A,G)=>G!==S)})),children:"Remove"}),B?e.jsxs(O,{variant:"warning",children:["Not found: ",d.role]}):null]},d.key)}),e.jsx(N,{variant:"secondary",onClick:()=>k(d=>({...d,members:[...d.members,{role:"",count:1,kind:"agent",key:crypto.randomUUID()}]})),children:"Add member"})]})}),e.jsxs(F,{title:"Description",children:[e.jsx(ee,{label:"What this team is for",htmlFor:"team-description",error:w==="description"?$:null}),e.jsx(he,{id:"team-description",value:p.description,onChange:d=>k(S=>({...S,description:d.target.value}))})]}),e.jsxs(F,{title:"Collaboration instructions",children:[w==="instructions"?e.jsx("p",{className:"text-meta text-danger",role:"alert","data-testid":"team-instructions-error",children:$}):null,e.jsx(Le,{ref:U,"aria-label":"Collaboration instructions","aria-invalid":w==="instructions",className:"min-h-36",maxLength:8e3,value:p.instructions,onChange:d=>k(S=>({...S,instructions:d.target.value}))})]}),e.jsx(F,{title:"Project brief",children:e.jsx(Le,{"aria-label":"Project brief",className:"min-h-36",maxLength:8e3,value:p.project,onChange:d=>k(S=>({...S,project:d.target.value}))})}),e.jsx(Oe,{submit:!0,confirming:E,onConfirmingChange:L,dirty:q,pending:R,saveLabel:c?"Create team":"Save changes",pendingLabel:c?"Creating…":"Saving…",dirtyHint:"Discard this team?",onSave:()=>void W(),onCancel:X})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"Manager",description:"The agent that leads the chat.",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"link",onClick:()=>u(p.manager),children:p.manager}),le(s,n).some(d=>d.id===p.manager)?null:e.jsx(O,{variant:"warning","data-testid":"team-manager-missing",children:"Not found"})]})}),e.jsx(F,{title:"Members",children:e.jsx("ul",{className:"space-y-1",children:(t?.members??[]).map(d=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-body-sm",children:[e.jsx("span",{className:"text-ink",children:d.role}),e.jsx(O,{variant:"neutral",children:d.kind==="team"?"Team":"Agent"}),e.jsx("span",{className:"text-ink-muted",children:d.count===1?"×1":`×${d.count}`}),Qe(d,s,n)?null:e.jsx(O,{variant:"warning","data-testid":"team-member-missing",children:"Not found"})]},`${d.kind}:${d.role}`))})}),e.jsx(F,{title:"What it is for",children:e.jsx(ue,{text:t?.description??"",empty:"No description yet."})}),t?.instructions?e.jsx(F,{title:"Collaboration instructions",children:e.jsx(ue,{text:t.instructions})}):null,t?.project?e.jsx(nt,{summary:"Project brief",children:e.jsx(ue,{text:t.project})}):null]})})]})}function le(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 fn=o.lazy(()=>Mt(()=>import("./legacy-agents-page-D6fK_4tD.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]),import.meta.url).then(t=>({default:t.LegacyAgentsPage}))),Ze=/^subagents\.models\.([^.]+)$/,gn=["lo","med","hi"],De={all:"All",custom:"Custom",installed:"Installed",builtin:"Built-in"},ve=t=>{const s=JSON.stringify(t)??"";let n=5381;for(let a=0;a<s.length;a+=1)n=(n*33^s.charCodeAt(a))>>>0;return`${s.length}.${n.toString(36)}`};function Cn(){const t=At("surface"),{agentId:s}=Tt(),[n,a]=Rt(),i=n.get("kind")==="team"||n.get("create")==="team",l=n.has("create"),u=n.get("name"),h=n.get("duplicate"),g=et(),c=ce(g.data,i?"team_catalogue":"profile_catalogue"),r=$t(c),y=Dt(c),v=c&&!!u&&!l,j=Be(i?null:u,v),b=Lt(i?u:null,v),C=Be(i?null:h,!!h),[p,k]=o.useState(""),[R,T]=o.useState("all"),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(0),I=Xs(),U=z(m=>m.marks),_=z(m=>m.clearMark),H=Ft({queryKey:["desktop","settings","effort-tiers"],enabled:c,queryFn:()=>V({op:"settings.list"}),staleTime:6e4}),q=o.useMemo(()=>(H.data?.settings??[]).filter(m=>{const M=m.key.match(Ze)?.[1];return!M||!gn.includes(M)?!1:typeof m.value=="string"&&m.value.trim().length>0}).map(m=>m.key.match(Ze)?.[1]).filter(m=>!!m),[H.data]),X=Vt(),P=o.useCallback(m=>Jt(m,X),[X]),W=o.useMemo(()=>bn(r.data,p,R,P),[r.data,p,R,P]),K=o.useMemo(()=>jn(y.data,p),[y.data,p]),J=i?K:W,d=u??null,[S,B]=o.useState(null);S!==null&&S.name!==d&&B(null);const f=o.useCallback(m=>{const M=new URLSearchParams;(m.kind??(i?"team":"agent"))==="team"&&M.set("kind","team"),m.name&&M.set("name",m.name),m.create!==null&&m.create!==void 0&&M.set("create",m.create),m.duplicate&&M.set("duplicate",m.duplicate),D(null),a(M)},[i,a]),A=`${i?"team":"agent"}:${l??""}:${d??""}`,G=o.useCallback(m=>x(m?A:null),[A]),Y=w!==null&&w===A,[re,fe]=o.useState(!1),ge=`${i?"team":"agent"}:${d??""}`,ie=i?b.data?ve(b.data):null:j.data?ve(j.data):null,oe=o.useRef({identity:ge,content:ie});o.useEffect(()=>{if(oe.current.identity!==ge){oe.current={identity:ge,content:ie},fe(!1);return}if(ie===null||oe.current.content===null){oe.current={identity:ge,content:ie};return}oe.current.content!==ie&&(oe.current.content=ie,Y&&fe(!0))},[ge,ie,Y]);const Me=(m,M)=>e.jsxs(e.Fragment,{children:[e.jsx(mn,{kind:m,name:M,enabled:ce(g.data,"hub_updates")}),re&&e.jsx("output",{className:"mb-6 block max-w-3xl rounded-md border border-warning-border px-3 py-2 text-meta text-ink-muted",children:"The hub updated this definition while you were editing, and the form below now shows the merged version. Edits you had not saved were replaced."})]}),Q=o.useCallback(m=>{if(Y){D(m);return}f(m)},[Y,f]);o.useEffect(()=>{const m=M=>{M.key!=="Escape"||M.defaultPrevented||window.matchMedia("(max-width: 999px)").matches&&(!d&&!l||(M.preventDefault(),Q({name:null})))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Q,d,l]),o.useEffect(()=>{const M=z.getState().about;if(!M)return;const Ue=i?"team":"agent";d&&M.kind===Ue&&M.name===d||(I.setAbout(null),gs(M))},[d,i,I]),o.useEffect(()=>{d&&_({kind:i?"team":"agent",name:d})},[d,i,_]);const pe=()=>{r.refetch(),y.refetch(),j.refetch(),b.refetch()};if(s)return e.jsx(o.Suspense,{fallback:e.jsx("p",{className:"p-6 text-body",children:"Loading saved agent…"}),children:e.jsx(fn,{})});const Ae=i?b.error:j.error,xe=i?y.error:r.error,bt=c&&!xe&&!l&&!d,jt=i?b.isLoading:j.isLoading;return e.jsxs("div",{className:"flex h-full min-h-0 bg-canvas text-ink",children:[e.jsxs("aside",{ref:t,"data-open":d?"true":void 0,className:"flex w-72 shrink-0 flex-col gap-3 bg-surface p-4 max-[999px]:data-[open=true]:hidden",children:[e.jsx("h1",{className:"text-heading",children:"Agents and teams"}),e.jsx(ss,{value:i?"team":"agent",onValueChange:m=>Q({kind:m,name:null}),children:e.jsxs(ns,{"aria-label":"Browse definitions by type",className:"w-full",children:[e.jsxs(qe,{value:"agent",className:"flex-1","data-testid":"agents-tab",children:[e.jsx(Yt,{className:"size-3.5"}),"Agents",r.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:r.data.length}):null]}),e.jsxs(qe,{value:"team",className:"flex-1","data-testid":"teams-tab",children:[e.jsx(_t,{className:"size-3.5"}),"Teams",y.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:y.data.length}):null]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ot,{"aria-hidden":"true",className:"pointer-events-none absolute top-2 left-2 size-4 text-ink-dim"}),e.jsx(he,{className:"pl-8",type:"search","aria-label":"Search agents and teams",placeholder:i?"Search teams":"Search agents",value:p,onChange:m=>k(m.target.value)})]}),!i&&r.data?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{"aria-hidden":"true",className:"text-meta text-ink-muted",children:"Showing"}),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",{className:"flex flex-wrap gap-0.5 rounded-md bg-sunken p-0.5",children:Object.keys(De).map(m=>e.jsx(N,{variant:"ghost",size:"sm","aria-pressed":R===m,onClick:()=>T(m),className:Z(R===m&&rt),children:De[m]},m))})]})]}):null,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:xe?null:!r.data&&!y.data?e.jsx(Zs,{}):J.length===0?e.jsx("p",{className:"px-1 py-2 text-body-sm text-ink-muted",children:p?`Nothing matches “${p}”.`:i?"No teams yet. Ask for one below, or add one by hand.":R==="all"?"No agents yet. Ask for one below, or add one by hand.":`No ${De[R].toLowerCase()} agents.`}):e.jsx(xn,{rows:J,name:l?null:d,teamMode:i,printName:P,marked:new Map(U.map(m=>[ps(m),m.created])),onOpen:m=>Q({name:m})})}),e.jsxs(N,{variant:"secondary",disabled:!c,onClick:()=>Q({create:i?"team":"agent"}),children:[e.jsx(it,{className:"size-4"}),i?"Add team manually":"Add agent manually"]})]}),e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col",children:[d||l?e.jsx("div",{className:"flex shrink-0 items-center border-hairline border-b px-4 py-2 min-[1000px]:hidden",children:e.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>Q({name:null}),children:[e.jsx(Qt,{className:"size-4"}),"Back to the list"]})}):null,e.jsx("div",{"data-agents-pane":!0,className:"min-h-0 flex-1 overflow-auto p-6 pb-0",style:E>0?{paddingBottom:E+16}:void 0,children:c?xe?e.jsx(Ye,{title:i?"Teams could not be read":"Agents could not be read",what:xe instanceof Error?xe.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:pe,retrying:r.isFetching||y.isFetching}):d&&jt?e.jsx(Je,{}):d&&Ae?e.jsx(Ye,{title:i?`“${d}” could not be read`:`“${d}” could not be read`,what:Ae instanceof Error?Ae.message:"The request did not complete.",meaning:"The definition may have been removed, or the backend refused the read.",onRetry:()=>{j.refetch(),b.refetch()},retrying:j.isFetching||b.isFetching}):l&&i?e.jsx(Xe,{agents:r.data,teams:y.data,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onCancelCreate:()=>f({name:null}),onOpenAgent:m=>Q({kind:"agent",name:m}),onAskAgent:m=>{Re(I,{kind:"team",name:u??""},m)}},"team:create"):l&&h&&C.isLoading?e.jsx(Je,{}):l?e.jsx(ln,{initial:C.data??null,takenNames:(r.data??[]).map(m=>m.name),effortTiers:q,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onCancel:()=>f({name:null})},"agent:create"):i&&b.data?e.jsxs(e.Fragment,{children:[Me("team",b.data.name),e.jsx(Xe,{team:b.data,agents:r.data,teams:y.data,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onOpenAgent:m=>Q({kind:"agent",name:m}),onAskAgent:m=>{Re(I,{kind:"team",name:b.data?.name??""},m)}},`team:${b.data.name}:${ve(b.data)}`)]}):!i&&j.data?e.jsxs(e.Fragment,{children:[Me("agent",j.data.name),e.jsx(on,{profile:j.data,displayedName:P(j.data.name),classNotice:S?.name===j.data.name?S.copy:null,onClassNotice:m=>B(m?{name:j.data.name,copy:m}:null),teams:y.data,effortTiers:q,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onDuplicate:m=>Q({create:"agent",duplicate:m.name}),onOpenTeam:m=>Q({kind:"team",name:m}),onAskAgent:m=>{Re(I,{kind:"agent",name:j.data?.name??""},m)}},`agent:${j.data.name}:${j.data.source}:${ve(j.data)}`)]}):d?e.jsx(de,{className:"h-6 w-40"}):e.jsx(pn,{teamMode:i,run:I,onAddManually:()=>Q({create:i?"team":"agent"})}):e.jsxs(se,{variant:g.isLoading?"neutral":"warning",className:"max-w-xl",children:[e.jsx(ne,{children:g.isLoading?"Connecting to the backend":g.error?"The backend could not be reached":"Reusable agents need a newer backend"}),e.jsx(ae,{children:g.isLoading?"Loading what this backend can do…":g.error?g.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:i?"Discard your unsaved changes to this team?":"Discard your unsaved changes to this agent?"}),e.jsx(N,{variant:"danger",onClick:()=>{x(null),f($)},children:"Discard changes"}),e.jsx(N,{variant:"ghost",onClick:()=>D(null),children:"Keep editing"})]}):null,bt?null:e.jsx("div",{className:"shrink-0 border-hairline border-t bg-canvas p-4",children:e.jsx(ut,{run:I,about:I.about,onClearAbout:()=>I.setAbout(null),onStripHeightChange:L,blockedReason:Y?"Finish or cancel your edit first.":null})})]})]})}function pn({teamMode:t,run:s,onAddManually:n}){return e.jsxs("div",{className:"max-w-xl space-y-4",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(ut,{run:s,hero:!0,about:s.about,onClearAbout:()=>s.setAbout(null)}),e.jsx(N,{variant:"ghost",onClick:n,children:t?"Or add a team by hand":"Or add an agent by hand"})]})}function xn({rows:t,name:s,teamMode:n,marked:a,printName:i,onOpen:l}){const u=o.useRef(new Map),[h,g]=o.useState(s),c=(r,y)=>{const v=t.findIndex(b=>b.name===r);if(v<0)return;const j=t[Math.min(t.length-1,Math.max(0,v+y))];j&&(g(j.name),u.current.get(j.name)?.focus())};return e.jsx("ul",{"aria-label":n?"Teams":"Agents",className:"space-y-1",children:t.map(r=>{const y="source"in r,v=a.get(`${n?"team":"agent"}:${r.name}`);return e.jsx("li",{children:e.jsxs("button",{ref:j=>{j?u.current.set(r.name,j):u.current.delete(r.name)},type:"button","aria-current":r.name===s?"true":void 0,tabIndex:r.name===(h??t[0]?.name)?0:-1,"data-testid":`roster-row-${r.name}`,className:Z("flex min-h-11 w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left hover:bg-row-hover",r.name===s&&rt),onFocus:()=>g(r.name),onClick:()=>l(r.name),onKeyDown:j=>{j.key==="ArrowDown"?(j.preventDefault(),c(r.name,1)):j.key==="ArrowUp"?(j.preventDefault(),c(r.name,-1)):j.key==="Home"?(j.preventDefault(),c(r.name,-t.length)):j.key==="End"&&(j.preventDefault(),c(r.name,t.length))},children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx("span",{className:"truncate text-body-sm text-ink",children:"members"in r?at(r):i(r.name)}),y?e.jsx(ht,{source:r.source,appearance:"text"}):null,v!==void 0?e.jsx(O,{variant:"attention","data-testid":"roster-row-updated",children:v?"New":"Updated"}):null]}),e.jsxs("span",{className:"flex w-full flex-wrap items-center gap-1.5",children:["members"in r?e.jsx(O,{variant:"neutral",children:r.members.length===1?"1 member":`${r.members.length} members`}):null,y&&Ie(r)==="proactive"?e.jsx(O,{variant:"neutral","data-testid":"roster-row-proactive",children:$s.proactive}):null,r.description?e.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:r.description}):null]})]})},r.name)})})}function bn(t,s,n,a){const i=s.trim().toLowerCase();return(t??[]).filter(l=>n==="builtin"&&l.source!=="builtin"||n==="installed"&&l.source!=="installed"||n==="custom"&&l.source!=="custom"?!1:i?a(l.name).toLowerCase().includes(i)||l.name.toLowerCase().includes(i)||(l.description??"").toLowerCase().includes(i):!0)}function jn(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{Cn as AgentsPage};
7
+ */const rs=[["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"}]],os=Xt("log-in",rs),ls=[],ze="config-composer-note",We="Configure agents by conversation",cs=["A reviewer that only reads code","Add the coder twice to release-crew","A team called shipping with a manager and two coders"],ds={idle:"bg-ink-dim",running:"bg-accent",stopping:"bg-warning",done:"bg-success",stopped:"bg-ink-muted",error:"bg-danger"};function us({status:t,pulse:s}){return e.jsx("span",{"aria-hidden":"true",className:Z("size-2 shrink-0 rounded-full",ds[t]??"bg-ink-dim",s&&"animate-pulse")})}function ms({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:"max-h-48 space-y-1 overflow-y-auto",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}`))})}function He({run:t,onDismiss:s}){const[n,a]=o.useState(!1),i=o.useRef(null),l=t.status==="running"||t.status==="stopping";o.useEffect(()=>{if(!l)return;const h=g=>{g.key!=="Escape"||g.defaultPrevented||document.querySelector('[role="alertdialog"], [role="dialog"]')||i.current?.focus()};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[l]);const u=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:"border-hairline border-b pb-2","data-testid":"config-run-strip",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[e.jsx(us,{status:t.status,pulse:l}),e.jsx("span",{"aria-live":"polite",className:"text-body-sm text-ink",children:u}),(l||t.status==="stopped"||t.status==="done")&&t.elapsed!=="0s"?e.jsx("span",{className:"text-meta text-ink-muted tabular-nums",children:t.elapsed}):null,t.touched.length>0?e.jsx(O,{variant:"neutral",children:t.touched.length===1?"1 definition":`${t.touched.length} definitions`}):null,e.jsxs("div",{className:"ml-auto flex items-center gap-1",children:[t.activity.length>0?e.jsxs(N,{variant:"ghost",size:"sm","aria-expanded":n,onClick:()=>a(h=>!h),children:[n?e.jsx(Zt,{className:"size-3.5"}):e.jsx(es,{className:"size-3.5"}),"Watch"]}):null,l?e.jsxs(N,{ref:i,variant:"secondary",size:"sm",disabled:t.status==="stopping",onClick:()=>void t.stop(),children:[e.jsx(kt,{className:"size-3.5"}),t.status==="stopping"?"Stopping…":"Stop"]}):e.jsx(N,{variant:"ghost",size:"sm",onClick:()=>s?s():t.dismiss(),children:"Dismiss"})]})]}),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,n?e.jsx("div",{className:"mt-2 border-hairline border-t pt-2",children:e.jsx(ms,{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(h=>e.jsxs("li",{className:"text-ink-muted",children:[h.created?"Created ":"Changed ",e.jsx("span",{className:"text-ink",children:h.target.name})]},`${h.target.kind}:${h.target.name}`))}):null]}):null,t.status==="done"?e.jsx(hs,{run:t}):null,t.status==="error"&&t.error?e.jsxs("div",{className:"mt-2 border-danger-border border-t pt-2",children:[e.jsx("p",{className:"text-body-sm text-danger",children:t.error}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[t.canRetry?e.jsx(N,{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 hs({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 je="agents-config",fs=t=>`Change the ${t.kind} ${t.name}: `;function Re(t,s,n){t.setAbout(s);const a=_e.getState();a.getCurrentInput(je)||a.setComposerText(je,n)}function gs(t){const s=_e.getState();s.getCurrentInput(je).trim()===fs(t).trim()&&s.setComposerText(je,"")}function ut({run:t,hero:s=!1,blockedReason:n,about:a,onClearAbout:i,onStripHeightChange:l}){const u=o.useRef(null),h=o.useRef(null),g=yt(),c=je,r=T=>_e.getState().setCurrentInput(c,T),y=o.useCallback(T=>{if(h.current?.disconnect(),h.current=null,!l)return;if(!T){l(0);return}const $=()=>l(T.getBoundingClientRect().height);if($(),typeof ResizeObserver>"u")return;const D=new ResizeObserver($);D.observe(T),h.current=D},[l]),v=t.status==="running"||t.status==="stopping",j=!t.enabled||!!n,b=n||(v?"Working on your request…":t.enabled?void 0:We),C=a?`Change ${a.name}…`:t.enabled?"Describe what you want…":We,p=a?`${a.kind}:${a.name}`:null;o.useEffect(()=>{p&&u.current?.focusInput()},[p]);const k=()=>{t.dismiss(),u.current?.focusInput()},R=()=>{i(),u.current?.focusInput()};return e.jsxs("div",{className:Z("relative rounded-md border border-hairline bg-surface p-3",s&&"shadow-none"),"data-testid":"config-composer",children:[e.jsx("div",{className:"sr-only",id:"config-composer-label",children:"Ask for an agent or team change"}),t.enabled&&t.status!=="idle"?s?e.jsx(He,{run:t,onDismiss:k}):e.jsx("div",{ref:y,className:"absolute inset-x-0 bottom-full rounded-t-md border-hairline border bg-canvas p-3",children:e.jsx(He,{run:t,onDismiss:k})}):null,a?e.jsxs("div",{className:"mb-2 flex items-center gap-2",children:[e.jsxs(O,{variant:"accent","data-testid":"config-composer-about",children:["About ",a.kind," ",a.name]}),e.jsx(N,{variant:"ghost",size:"sm",onClick:R,children:"Clear"})]}):null,e.jsx(vt,{ref:u,conversationId:c,messages:ls,isLoading:!1,transcriptless:!0,placeholderOverride:C,sessionStatus:t.frontend?{frontend:t.frontend}:void 0,recordingProbe:g,hostNotice:{id:ze,blocksInput:!t.enabled||!!n||v,placeholder:b,node:e.jsx("p",{id:ze,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-muted",children:t.enabled?"Runs in the background. This does not appear in your conversation.":t.disabledReason})},onSendMessage:(T,$)=>t.start(T,a,$)}),t.enabled?e.jsx("div",{className:Z("mt-2 flex flex-wrap gap-1.5",as,t.enabled&&!a&&!v?"":"invisible"),children:cs.map(T=>e.jsx(N,{variant:"outline",size:"sm",disabled:j,onClick:()=>{r(T),u.current?.focusInput()},children:T},T))}):null]})}const Ke=(t,s)=>t.kind===s.kind&&t.name===s.name;function ps(t){return`${t.kind}:${t.name}`}const z=is(t=>({sessionId:null,status:"idle",topic:"",images:[],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,i=[])=>t({sessionId:s,status:"running",topic:n,images:i,error:null,stopError:null,startedAt:Date.now(),settledAt:null,touched:[],results:[],answer:"",before:a,unsent:!1}),noteTouched:s=>t(n=>n.touched.some(a=>Ke(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(i=>({...i.target,created:i.created})),sessionId:null,images:[],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:[],touched:[],results:[],answer:"",marks:[],startedAt:null,settledAt:null,before:null}),clearMark:s=>t(n=>({marks:n.marks.filter(a=>!Ke(a,s))}))})),xs=/Value error,\s*([\s\S]*?)\s*\[type=/,bs=/^\d+ validation errors? for \S+[\s\S]*?\n\s*/i,js=/\s*\[type=[^\]]*\][\s\S]*$/m,ys=/\s*For further information visit \S+/g,vs=/'([^']+)' already exists/,ks=/cannot contain spaces or path separators/i,ws=/effort tier '([^']+)' is unavailable/i,Ns=/team name must be/i,Ss=/manager '([^']+)'/i,Cs=/(?:member|role) '([^']+)' (?:is not|does not)/i,Es=/depth|cycle|circular/i,Is=/instructions/i,As=/description/i;function Ts(t){const s=t.match(xs);return s?.[1]?s[1].trim():t.replace(bs,"").replace(js,"").replace(ys,"").trim()}function ye(t){const s=Ts(t),n=s.match(vs);if(n)return{message:`An agent called “${n[1]}” already exists. Choose another name, or open the existing one to change it.`,field:"name"};if(ks.test(s))return{message:"Names cannot contain spaces or slashes.",field:"name"};const a=s.match(ws);if(a)return{message:`“${a[1]}” is not a configured effort tier. Use inherit, or add the tier in Settings.`,field:"effort"};if(s.match(Ns))return{message:"A team name is 1-64 characters.",field:"name"};const l=s.match(Ss);if(l)return{message:`“${l[1]}” is not an agent or a team on this machine.`,field:"manager"};const u=s.match(Cs);return u?{message:`“${u[1]}” is not an agent or a team on this machine.`,field:"members"}:Es.test(s)?{message:"That team would nest too deeply, or would contain itself. Check its members.",field:"members"}:Is.test(s)?{message:s,field:"instructions"}:As.test(s)?{message:s,field:"description"}:{message:s,field:null}}function Rs(t,s){const n=new Set(s),a=`${t}-copy`;if(!n.has(a))return a;for(let i=2;i<100;i+=1){const l=`${a}-${i}`;if(!n.has(l))return l}return a}function Ie(t){return t.action_class==="proactive"?"proactive":"reactive"}const $s={proactive:"Proactive"},Ds={proactive:"It may message you on its own: after sending you something it waits a few minutes for a reply, nudges again with growing gaps for a fixed number of tries, then waits for you — and it may also wake on its own schedule.",reactive:"It replies when you write to it. It does not nudge you, and it does not wake on its own schedule."},Ls={proactive:"Turning this off stops the nudging and the scheduled wakes. It still replies when you write to it.",reactive:"Turning this on lets it write first: it will wait a few minutes for your reply, nudge you again up to a fixed number of tries, and it may wake on its own schedule. It still replies when you write to it."},Fs="This one ships with the app and has no copy of its own yet, so switching installs it first — the same agent and the same instructions, now editable — and then sets its class.";function _s(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 Os(t,s,n,a=()=>crypto.randomUUID()){if(Ie(t)===s)return null;let i=null;const l=_s(t,s);for(let u=0;u<l.length;u+=1){const h=l[u];try{i=await n(h,a())}catch(g){throw new mt(g,l.slice(0,u))}}return i}class mt extends Error{completed;constructor(s,n){super(s instanceof Error?s.message:String(s)),this.name="ClassSwitchError",this.completed=n}}function Ms(t,s){const n=t instanceof Error&&t.message?t.message:"The backend sent no reason for it. Try the switch again.",a=ye(n).message;return s.some(i=>i.op==="profiles.install")?`${a} The install did land, so the agent is editable now.`:a}const Us=new Set(["agent","team"]);function Ps(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",i=n?{kind:a,name:n}:null,l=t.phase==="done"&&!t.isError&&!t.notRunReason&&!t.neverSent,u=h=>({writes:h&&l});switch(s){case"create":return{verb:n?`Creating ${a} ${n}`:`Creating a ${a}`,target:i,...u(!0)};case"update":return{verb:n?`Updating ${a} ${n}`:`Updating a ${a}`,target:i,...u(!0)};case"install":return{verb:n?`Installing ${n}`:"Installing an agent",target:i,...u(!0)};case"list":case"search":case"show":return{verb:n?`Reading ${n}`:`Reading ${a}s`,target:i,...u(!1)};default:return{verb:t.phase==="running"?`Working on ${a}s`:`Checked ${a}s`,target:i,...u(!0)}}}const Bs={description:"description",kind:"kind",tools:"tools",effort:"effort tier",delegate:"delegation",action_class:"class",manager:"manager",members:"members",instructions:"instructions"};function qs(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:Ie(t)}}function zs(t){return{description:t.description??"",manager:t.manager??"",members:(t.members??[]).map(s=>`${s.kind}:${s.role}x${s.count}`).sort().join(",")}}function Ge(t,s){return{agents:Object.fromEntries((t??[]).map(n=>[n.name,qs(n)])),teams:Object.fromEntries((s??[]).map(n=>[n.name,zs(n)]))}}function Ws(t,s){if(t===s)return"tools";const n=h=>h==="*"?null:new Set(h.split(",")),a=n(t),i=n(s);if(i===null)return"tools widened to every tool";if(a===null)return"tools narrowed to a list";const l=[...i].filter(h=>!a.has(h)),u=[...a].filter(h=>!i.has(h));return l.length&&!u.length?l.length===1?`tool added: ${l[0]}`:`${l.length} tools added`:u.length&&!l.length?u.length===1?`tool removed: ${u[0]}`:`${u.length} tools removed`:"tools changed"}function Hs(t,s,n){if(t==="tools")return Ws(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=i=>i?i.split(",").length:0;return`members changed (${a(s)} to ${a(n)})`}return`${Bs[t]??t} changed`}function Ks(t,s,n){const a=[],i=new Set;for(const l of n){const u=`${l.kind}:${l.name}`;if(i.has(u))continue;i.add(u);const h=t[l.kind==="agent"?"agents":"teams"][l.name],g=s[l.kind==="agent"?"agents":"teams"][l.name];if(!g)continue;if(!h){a.push({target:l,created:!0,changes:[]});continue}const c=[];for(const r of Object.keys(g))g[r]!==h[r]&&c.push({label:Hs(r,h[r],g[r]),before:h[r],after:g[r]});a.push({target:l,created:!1,changes:c})}for(const[l,u]of[["agent",s.agents],["team",s.teams]])for(const h of Object.keys(u))i.has(`${l}:${h}`)||(l==="agent"?t.agents[h]:t.teams[h])||a.push({target:{kind:l,name:h},created:!0,changes:[]});return a}function Gs(t){return ce(t,"agents_config")&&ce(t,"session_interrupt")&&ce(t,"profile_catalogue")&&ce(t,"team_catalogue")}function Vs(t){if(!(t instanceof It)||t.status!==409)return null;const n=t.detail?.session_id;return typeof n=="string"&&n.length>0?n:null}function Js(t,s){const[n,a]=o.useState(()=>Date.now());return o.useEffect(()=>{if(!t||!s)return;const i=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(i)},[t,s]),t?Math.max(0,n-t):0}function Ys(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 Ve(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 Qs(t){const n=t?.payload?.frontend;if(!n||typeof n!="object")return null;const a=n.streaming;if(typeof a=="boolean")return a;const i=n.snapshot?.streaming;return typeof i=="boolean"?i:null}function Xs(){const t=et(),s=Gs(t.data),n=wt(),a=z(),[i,l]=o.useState(!1),[u,h]=o.useState(!1),g=o.useRef(!1),c=a.status==="running"||a.status==="stopping",r=Nt(a.sessionId??void 0,!!a.sessionId),y=o.useMemo(()=>Ve(r.transcript?.records),[r.transcript?.records]);Ut(a.sessionId??void 0,r.subscriptionId);const v=r.transcript?.records,j=o.useRef(v);o.useEffect(()=>{j.current=v},[v]);const b=o.useMemo(()=>(r.transcript?.records??[]).filter(E=>E.kind==="tool"&&Us.has(E.toolName)).map(E=>({...Ps({toolName:E.toolName,args:E.args??null,phase:E.phase,ts:E.ts,isError:E.isError,notRunReason:E.notRunReason,neverSent:E.neverSent}),ts:E.ts})),[r.transcript]);o.useEffect(()=>{if(c)for(const x of b)x.target&&x.writes&&a.noteTouched(x.target)},[b,c,a]);const C=c&&b.length>0?b[b.length-1].verb:null,p=Ys(Js(a.startedAt,c)),k=o.useCallback(async(x,E="")=>{if(g.current)return;g.current=!0;const L=a.before;let I=[];try{const[U,_]=await Promise.all([V({op:"profiles.list"}),V({op:"teams.list"})]);L&&(I=Ks(L,Ge(U.profiles,_.teams),a.touched))}catch{z.getState().fail("The run finished, but the agents and teams lists could not be read to describe what changed."),Pe(n);return}if(Pe(n),z.getState().settle(I,x,E),x==="done"&&I.length>0){const U=I.filter(_=>_.created).length;me(U>0?`Configuration run finished: ${I.length} definition${I.length===1?"":"s"} changed.`:`Configuration run finished: ${I.length} definition${I.length===1?"":"s"} updated.`)}},[n,a.before,a.touched]);o.useEffect(()=>{if(c){if(r.failure){z.getState().fail(r.failure.statement);return}g.current||r.frontend&&(r.frontend.streaming||r.turnsCompleted!==0&&k(a.status==="stopping"?"stopped":"done",y))}},[c,y,r.failure,r.frontend,r.turnsCompleted,a.status,k]),o.useEffect(()=>{const x=a.sessionId;if(!c||!x)return;let E=!1;const L=async()=>{if(!(E||g.current))try{const _=await V({op:"sessions.get",sessionId:x});if(E||g.current||Qs(_)!==!1)return;const H=Ve(j.current);if(!H)return;k(z.getState().status==="stopping"?"stopped":"done",H)}catch{}},I=setTimeout(()=>void L(),400),U=setInterval(()=>void L(),4e3);return()=>{E=!0,clearTimeout(I),clearInterval(U)}},[c,a.sessionId,k]);const R=async(x,E,L=[])=>{if(i||!x.trim()&&L.length===0)return!1;l(!0),h(!1),g.current=!1;const I=Ge(n.getQueryData(["desktop","profiles"]),n.getQueryData(["desktop","teams"])),U=E?`About the ${E.kind} “${E.name}”: ${x.trim()}`:x.trim(),{images:_,unreadable:H,overflow:q}=await St(L,U),X=Ct(H);if(X)return z.getState().fail(X),!1;const P=Et(q);if(P)return z.getState().fail(P),!1;try{let W;try{W=(await V({op:"sessions.create",requestId:crypto.randomUUID(),purpose:"agents-config"})).session_id}catch(K){const J=Vs(K);if(J)return h(!0),a.adopt(J,x.trim(),I,_),!1;throw K}return a.adopt(W,U,I,_),await T(W,U,_),!0}catch(W){const K=z.getState().sessionId;return z.getState().failUnsent(Te(W,K?"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{l(!1)}},T=async(x,E,L=[])=>{await V({op:"sessions.message",sessionId:x,requestId:crypto.randomUUID(),text:E,...L.length>0?{images:L}:{}})},$=async()=>{const x=z.getState();if(!(i||!x.unsent||!x.sessionId||!x.topic&&x.images.length===0)){l(!0);try{await T(x.sessionId,x.topic,x.images),a.adopt(x.sessionId,x.topic,x.before),g.current=!1}catch(E){z.getState().failUnsent(Te(E,"The request could not be sent. It is still in the box."))}finally{l(!1)}}},D=async()=>{const x=z.getState().sessionId;if(x){a.stopping();try{await Pt(x,crypto.randomUUID())}catch(E){z.getState().stopFailed(Te(E,"The run did not acknowledge the request."))}}},w=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:w,status:a.status,sessionId:a.sessionId,frontend:r.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:C,elapsed:p,activity:b,start:R,stop:D,retry:$,canRetry:a.unsent&&!!a.sessionId,dismiss:a.dismiss,starting:i,attached:u}}function F({title:t,description:s,actions:n,children:a,className:i}){return e.jsxs("section",{className:Z("space-y-2 border-hairline border-t pt-4 first:border-t-0 first:pt-0",i),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]})}function ue({text:t,empty:s="Nothing here yet.",mono:n=!1}){const[a,i]=o.useState(!1),[l,u]=o.useState(!1),h=o.useRef(null);return o.useEffect(()=>{if(a)return;const g=h.current;g&&u(!!t&&g.scrollHeight>g.clientHeight+1)},[t,a]),t.trim()?e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{ref:h,tabIndex:0,"aria-label":"The full text",className:Z("whitespace-pre-wrap rounded-sm border border-hairline bg-surface px-3 py-2 text-body-sm text-ink",!a&&"max-h-64 overflow-y-auto",n&&"font-mono text-meta"),children:t}),l?e.jsx(N,{variant:"link",size:"sm",onClick:()=>i(g=>!g),children:a?"Show less":"Show all"}):null]}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:s})}function ht({source:t,appearance:s="chip"}){const n=t==="builtin"?"Built-in":t==="installed"?"Installed":"Custom";return s==="text"?e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:n}):e.jsx(O,{variant:"neutral",children:n})}function ft(t,s){o.useEffect(()=>{if(!s)return;const n=a=>{a.key!=="Escape"||a.defaultPrevented||(a.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[s,t])}function Oe({dirty:t,pending:s,onSave:n,onCancel:a,saveLabel:i="Save changes",pendingLabel:l="Saving…",dirtyHint:u,submit:h,confirming:g,onConfirmingChange:c}){const[r,y]=o.useState(!1),v=o.useRef(null),j=o.useRef(null),b=g!==void 0,C=b?g:r;o.useEffect(()=>{C&&j.current?.focus()},[C]);const p=k=>{b||y(k),c?.(k)};return o.useEffect(()=>{t||(b||y(!1),c?.(!1))},[t,b,c]),e.jsxs("div",{"data-testid":"edit-footer",className:"sticky bottom-0 z-10 -mx-6 mt-6 flex flex-wrap items-center gap-2 border-hairline border-t bg-canvas px-6 py-3",children:[e.jsx(N,{ref:v,type:h?"submit":void 0,variant:"primary",onClick:h?void 0:n,disabled:s,children:s?l:i}),C?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:u??"Discard your unsaved changes?"}),e.jsx(N,{variant:"danger",onClick:a,children:"Discard changes"}),e.jsx(N,{ref:j,variant:"ghost",onClick:()=>{p(!1),v.current?.focus()},children:"Keep editing"})]}):e.jsx(N,{variant:"ghost",onClick:()=>t?p(!0):a(),disabled:s,children:"Cancel"}),t&&!C?e.jsx("span",{className:"text-meta text-ink-muted",children:"Unsaved changes"}):null]})}let Fe=!1;function gt(){Fe=!0}function pt(){const t=Fe;return Fe=!1,t}function Zs({rows:t=6}){return e.jsx("div",{className:"space-y-1","aria-hidden":"true",children:en.slice(0,t).map(s=>e.jsx(de,{className:"h-11 w-full"},s))})}const en=["a","b","c","d","e","f","g","h"];function Je(){return e.jsxs("div",{className:"max-w-3xl space-y-6","aria-hidden":"true",children:[e.jsx(de,{className:"h-7 w-64"}),e.jsx(de,{className:"h-5 w-40"}),e.jsx(de,{className:"h-28 w-full"}),e.jsx(de,{className:"h-24 w-full"})]})}function Ye({title:t,what:s,meaning:n,onRetry:a,retrying:i=!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(N,{variant:"secondary",onClick:a,disabled:i,children:i?"Retrying…":"Retry"})]})}function ee({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 tn=/^[A-Za-z0-9_.:-]{1,128}$/;function te(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 sn(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 nn({profile:t}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(ht,{source:t.source}),t.divergent_fields?.length?e.jsx(O,{variant:"warning",children:"Modified"}):null,t.kind==="specialist"?e.jsx(O,{variant:"neutral",children:"Specialist"}):null,t.delegate?e.jsx(O,{variant:"neutral",children:"Delegates"}):null,t.tools&&t.tools.length>0?e.jsx(O,{variant:"neutral",children:t.tools.length===1?"1 tool":`${t.tools.length} tools`}):null]})}const an=5e3;let $e=null;function rn({profile:t,displayedName:s,notice:n,onNotice:a,onChanged:i}){const l=Ie(t),[u,h]=o.useState(null),[g,c]=o.useState(!1),r=o.useRef(null),y=o.useId();o.useEffect(()=>{u!==null&&l===u&&h(null)},[l,u]),o.useEffect(()=>{const b=$e;!b||b.name!==t.name||($e=null,!(Date.now()-b.at>an)&&r.current?.focus())},[t.name]);const v=u??l,j=async b=>{if(!(g||b===v)){$e={name:t.name,at:Date.now()},a(null),h(b),c(!0);try{await Os(t,b,(C,p)=>C.op==="profiles.install"?V({op:"profiles.install",name:C.name,requestId:p}):V({op:"profiles.update",name:C.name,requestId:p,fields:C.fields??{}})),i(t.name),me(b==="proactive"?`${s} is now proactive — it may message you on its own.`:`${s} is now reactive — proactive messaging stopped.`)}catch(C){h(null);const p=C instanceof mt?C.completed:[],k=Ms(C,p);a(k),ke(k),i(t.name)}finally{c(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex items-center gap-2 text-body-sm",children:[e.jsx(Ee,{ref:r,checked:v==="proactive","aria-disabled":g,"aria-labelledby":y,"data-testid":"agent-class-switch",className:"after:absolute after:inset-0 after:content-['']",onCheckedChange:b=>void j(b?"proactive":"reactive")}),e.jsx("span",{id:y,className:"text-ink",children:"Can message me on its own"}),e.jsx("span",{"aria-live":"polite",className:"text-ink-muted",children:g?"Switching…":v==="proactive"?"On":"Off"})]}),e.jsx("p",{className:"text-body-sm text-ink",children:Ds[v]}),e.jsx("p",{className:"text-meta text-ink-muted",children:Ls[v]}),t.source==="builtin"?e.jsx("p",{className:"text-meta text-ink-muted",children:Fs}):null,n?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-class-error",children:[e.jsx(ne,{children:"The switch did not go through"}),e.jsx(ae,{children:n})]}):null]})}function xt({tools:t,onChange:s,error:n}){const[a,i]=o.useState(""),[l,u]=o.useState(null),h=o.useId(),g=()=>{const c=a.trim();if(c){if(!tn.test(c)){u("Tool names are letters, digits, dot, underscore, dash or colon.");return}if(t?.includes(c)){u("That tool is already listed.");return}u(null),i(""),s([...t??[],c])}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(Ee,{checked:t===null,onCheckedChange:c=>s(c?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(c=>e.jsx("li",{children:e.jsxs(O,{variant:"outline",children:[c,e.jsx(N,{variant:"ghost",size:"sm","aria-label":`Remove ${c}`,onClick:()=>s(t.filter(r=>r!==c)),className:"ml-1 h-4 px-1",children:"×"})]})},c))}):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(ee,{label:"Add a tool",htmlFor:h,error:l??n}),e.jsx(he,{id:h,value:a,inputSize:"md",placeholder:"Tool name","aria-invalid":!!(l??n),onChange:c=>{i(c.target.value),u(null)},onKeyDown:c=>{c.key==="Enter"&&(c.preventDefault(),g())}})]}),e.jsx(N,{variant:"secondary",onClick:g,disabled:!a.trim(),children:"Add"})]})]})]})}function on({profile:t,displayedName:s,classNotice:n,onClassNotice:a,teams:i,effortTiers:l,askEnabled:u,onSaved:h,onDuplicate:g,onOpenTeam:c,onAskAgent:r,onDirtyChange:y}){const[v,j]=o.useState(!1),[b,C]=o.useState(()=>te(t)),[p,k]=o.useState(()=>te(t)),[R,T]=o.useState(!1),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(!1),[I,U]=o.useState(!1),[_,H]=o.useState(!1),q=o.useRef(null),X=tt(),P=JSON.stringify(p)!==JSON.stringify(b);o.useEffect(()=>(y?.(v&&P),()=>y?.(!1)),[y,v,P]),o.useEffect(()=>{pt()&&requestAnimationFrame(()=>q.current?.focus())},[]),o.useEffect(()=>{if(v&&P)return;const f=te(t);C(f),k(f)},[t,v,P]),o.useEffect(()=>{if(!v){U(!1);return}const f=te(t);U(P&&JSON.stringify(f)!==JSON.stringify(b))},[t,v,P,b]);const W=()=>{j(!1),D(null),x(null),L(!1),H(!1);const f=te(t);C(f),k(f)};ft(()=>{if(_){H(!1);return}P?H(!0):W()},v);const J=async f=>{if(f?.preventDefault(),R)return;const A=sn(b,p);if(Object.keys(A).length===0){W();return}if(typeof A.instructions=="string"&&!A.instructions.trim()){D("Give the agent instructions."),x("instructions");return}T(!0),D(null),x(null);try{const G=await V({op:"profiles.update",name:t.name,requestId:crypto.randomUUID(),fields:A});j(!1),L(!1);const Y=te(G);C(Y),k(Y),h(G.name),me(`Saved ${G.name}.`),requestAnimationFrame(()=>q.current?.focus())}catch(G){const Y=ye(G instanceof Error?G.message:"The agent could not be saved.");D(Y.message),x(Y.field);const re=G?.status,fe=typeof re=="number"&&re!==408&&re>=400&&re<500;L(!fe),fe||ke("The save could not be confirmed. Check whether it was applied before retrying.")}finally{T(!1)}},d=async()=>{if(!R){T(!0),D(null);try{const f=await V({op:"profiles.install",name:t.name,requestId:crypto.randomUUID()}),A=te(f);C(A),k(A),h(f.name),me(`Installed ${f.name}. It can be edited now.`),requestAnimationFrame(()=>q.current?.focus())}catch(f){const A=ye(f instanceof Error?f.message:"The agent could not be installed.");D(A.message),ke(A.message)}finally{T(!1)}}},S=(i??[]).filter(f=>f.manager===t.name||(f.members??[]).some(A=>A.role===t.name)),B=t.source==="builtin";return e.jsxs("div",{className:"max-w-3xl space-y-6",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 space-y-2",children:[e.jsx("h2",{ref:q,tabIndex:-1,className:"text-title focus:outline-none",children:s}),e.jsx(nn,{profile:t})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"primary",onClick:()=>{st.getState().stageDraft({kind:"agent",name:t.name}),X("/chat")},children:"New chat"}),B?e.jsxs(N,{variant:"secondary",onClick:d,disabled:R,children:[e.jsx(os,{className:"size-4"}),R?"Installing…":"Install to edit"]}):e.jsx(N,{variant:"secondary",onClick:()=>{j(!0),D(null),x(null)},children:"Edit"}),e.jsx(N,{variant:"ghost",onClick:()=>g(t),children:"Duplicate as new agent"}),u?e.jsx(N,{variant:"ghost",onClick:()=>r(`Change the agent ${t.name}: `),children:"Ask for a change"}):null]})]}),B?e.jsxs(se,{variant:"info",children:[e.jsx(ne,{children:"Built-in agent"}),e.jsx(ae,{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,I?e.jsxs(se,{variant:"warning","data-testid":"agent-conflict",children:[e.jsx(ne,{children:"This changed while you were editing"}),e.jsxs(ae,{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(N,{variant:"secondary",size:"sm",className:"mt-2",onClick:W,children:"Reload the saved version"})]})]}):null,E?e.jsxs(se,{variant:"danger","data-testid":"agent-unconfirmed",children:[e.jsx(ne,{children:"The last save was not confirmed"}),e.jsx(ae,{children:"The backend did not answer, so the write may or may not have landed. Check the agent below, then edit again."})]}):null,$&&!w?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-save-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:$})]}):null]}),e.jsx("form",{noValidate:!0,onSubmit:f=>{f.preventDefault(),J(f)},className:"space-y-6",children:v?e.jsxs(e.Fragment,{children:[e.jsx(Se,{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:p.description,error:w==="description"?$:null,onChange:f=>k(A=>({...A,description:f}))}),e.jsx(Se,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:p.instructions,rows:12,required:!0,error:w==="instructions"?$:null,onChange:f=>k(A=>({...A,instructions:f}))}),e.jsx(F,{title:"Tools",children:e.jsx(xt,{tools:p.tools,error:w==="tools"?$:null,onChange:f=>k(A=>({...A,tools:f}))})}),e.jsx(F,{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(Ee,{checked:p.delegate,onCheckedChange:f=>k(A=>({...A,delegate:f})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"max-w-sm space-y-1",children:[e.jsx(ee,{label:"Effort tier",htmlFor:"agent-effort",error:w==="effort"?$:null}),e.jsx(Ne,{ariaLabel:"Effort tier",showLabel:!1,placeholder:"Choose an effort tier",busyLabel:"Loading effort tiers",options:["inherit",...l].map(f=>({id:f,name:f,description:f==="inherit"?"Use the session's own effort":void 0})),selected:{id:p.effort,name:p.effort},onSelect:f=>k(A=>({...A,effort:f.id})),helperText:"Tiers come from the backend's subagent model settings."})]})]})}),e.jsx(Oe,{submit:!0,confirming:_,onConfirmingChange:H,dirty:P,pending:R,onSave:()=>void J(),onCancel:W,saveLabel:"Save changes",dirtyHint:"Discard your unsaved changes to this agent?"})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"When to use it",children:e.jsx(ue,{text:t.description||"",empty:"No description yet — add one so a model knows when to pick this agent."})}),e.jsx(F,{title:"Instructions",children:e.jsx(ue,{text:t.instructions??t.packaged_instructions??"",empty:"No instructions yet."})}),e.jsx(F,{title:"Tools",children:t.tools&&t.tools.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.tools.map(f=>e.jsx("li",{children:e.jsx(O,{variant:"outline",children:f})},f))}):e.jsx(O,{variant:"neutral",children:"All tools"})}),e.jsxs(F,{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"]})]}),e.jsx(F,{title:"Messaging",description:"Reactive agents only reply. Proactive agents may also message you first.",children:e.jsx(rn,{profile:t,displayedName:s,notice:n,onNotice:a,onChanged:h})}),e.jsx(F,{title:"Used by",description:"Teams that name this agent as a manager or a member.",children:S.length>0?e.jsx("ul",{className:"flex flex-wrap gap-x-3 gap-y-1",children:S.map(f=>e.jsx("li",{children:e.jsx(N,{variant:"link",onClick:()=>c(f.name),children:f.name})},f.id))}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:"No team uses it yet."})}),e.jsxs(F,{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(nt,{summary:"Compare with the packaged instructions",className:"mt-2",children:e.jsx(ue,{text:t.packaged_instructions,mono:!0})}):null]})]})})]})}function Se({title:t,description:s,label:n,value:a,onChange:i,rows:l,required:u,error:h,fieldRef:g}){const c=o.useId();return e.jsxs(F,{title:t,description:s,children:[e.jsx(ee,{label:n,htmlFor:c,error:h}),l?e.jsx(Le,{id:c,ref:g,value:a,rows:l,required:u,"aria-invalid":!!h,className:Z("min-h-0"),onChange:r=>i(r.target.value)}):e.jsx(he,{id:c,value:a,"aria-invalid":!!h,onChange:r=>i(r.target.value)})]})}function ln({initial:t,takenNames:s,effortTiers:n,onDirtyChange:a,onSaved:i,onCancel:l}){const[u,h]=o.useState(()=>t?Rs(t.name,s):""),[g,c]=o.useState(t?.kind??"role"),[r,y]=o.useState(()=>t?{...te(t),description:t.description??""}:{description:"",instructions:"",tools:null,effort:"inherit",delegate:!1}),[v,j]=o.useState(!1),[b,C]=o.useState(null),[p,k]=o.useState(null),R=o.useRef(null),T=o.useRef(null);o.useEffect(()=>(a?.(!!(u.trim()||r.instructions.trim())),()=>a?.(!1)),[a,u,r.instructions]),o.useEffect(()=>{R.current?.focus(),R.current?.select()},[]);const $=async w=>{if(w?.preventDefault(),!v){if(!u.trim()){C("Give the agent a name."),k("name"),R.current?.focus();return}if(/[\\/\s]/.test(u.trim())){C("Names cannot contain spaces or slashes."),k("name"),R.current?.focus();return}if(s.includes(u.trim())){C(`An agent called “${u.trim()}” already exists. Choose another name, or open the existing one to change it.`),k("name"),R.current?.focus();return}if(!r.instructions.trim()){C("Give the agent instructions."),k("instructions"),T.current?.focus();return}j(!0),C(null),k(null);try{const x=await V({op:"profiles.create",requestId:crypto.randomUUID(),name:u.trim(),fields:{kind:g,description:r.description,instructions:r.instructions,tools:r.tools??[],effort:r.effort,delegate:r.delegate}});me(`Created ${x.name}.`),gt(),i(x.name)}catch(x){const E=ye(x instanceof Error?x.message:"The agent could not be created.");C(E.message),k(E.field)}finally{j(!1)}}},D=t?"Duplicate as a new agent":"New agent";return e.jsxs("div",{className:"max-w-3xl space-y-6",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("h2",{className:"text-title",children:D}),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."})]}),b&&!p?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"agent-create-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:b})]}):null,e.jsxs("form",{noValidate:!0,onSubmit:w=>{w.preventDefault(),$(w)},className:"space-y-6",children:[e.jsx(F,{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(ee,{label:"Name",htmlFor:"agent-create-name",error:p==="name"?b:null}),e.jsx(he,{id:"agent-create-name",ref:R,value:u,required:!0,"aria-invalid":p==="name",onChange:w=>h(w.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ee,{label:"How it works with others",htmlFor:"agent-create-kind"}),e.jsxs(ot,{value:g,onValueChange:w=>c(w),children:[e.jsx(lt,{id:"agent-create-kind",children:e.jsx(ct,{})}),e.jsxs(dt,{children:[e.jsx(we,{value:"role",children:"You can chat with it directly"}),e.jsx(we,{value:"specialist",children:"Other agents can call on it"})]})]})]})]})}),e.jsx(Se,{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:r.description,error:p==="description"?b:null,onChange:w=>y(x=>({...x,description:w}))}),e.jsx(Se,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:r.instructions,rows:12,required:!0,fieldRef:T,error:p==="instructions"?b:null,onChange:w=>y(x=>({...x,instructions:w}))}),e.jsx(F,{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(Ee,{checked:r.delegate,onCheckedChange:w=>y(x=>({...x,delegate:w})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"max-w-sm space-y-1",children:[e.jsx(ee,{label:"Effort tier",htmlFor:"agent-create-effort"}),e.jsx(Ne,{ariaLabel:"Effort tier",showLabel:!1,busyLabel:"Loading effort tiers",placeholder:"Choose an effort tier",options:["inherit",...n].map(w=>({id:w,name:w,description:w==="inherit"?"Use the session's own effort":"A tier configured in Settings"})),selected:{id:r.effort,name:r.effort},onSelect:w=>y(x=>({...x,effort:w.id}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:"Tools"}),e.jsx(xt,{tools:r.tools,error:p==="tools"?b:null,onChange:w=>y(x=>({...x,tools:w}))})]})]})}),e.jsx(Oe,{submit:!0,dirty:!!(u.trim()||r.instructions),pending:v,saveLabel:t?"Create the copy":"Create agent",pendingLabel:"Creating…",dirtyHint:"Discard this new agent?",onSave:()=>void $(),onCancel:l})]})]})}const Ce=t=>t==null?"":typeof t=="string"?t:JSON.stringify(t,null,2),cn={available:"border-hairline",updating:"border-hairline",applied:"border-hairline",review:"border-warning-border",failed:"border-danger-border"};function dn(t){const s=[];for(const n of t??[])for(const a of n.fields??[])for(const i of a.regions??[])(i.provenance==="unresolved"||Ce(i.local)!==Ce(i.remote))&&s.push({field:a.field,region:i});return s}function un({regions:t}){return t.length?e.jsx("ul",{className:"space-y-3","data-testid":"hub-update-preview",children:t.map(({field:s,region:n},a)=>e.jsxs("li",{className:"space-y-1 text-meta",children:[e.jsx("p",{className:"font-medium text-ink",children:n.heading||n.name||s}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-ink-muted",children:"Yours"}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:Ce(n.local)||"(nothing)"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-ink-muted",children:"The hub's"}),e.jsx("pre",{className:"max-h-40 overflow-auto whitespace-pre-wrap rounded-sm border border-hairline p-2 text-ink",children:Ce(n.remote)||"(nothing)"})]})]})]},`${s}:${n.id??a}`))}):e.jsx("p",{className:"text-meta text-ink-muted",children:"No differences to show: the hub's version matches yours."})}function mn({kind:t,name:s,enabled:n}){const a=Bt(n),i=qt(),[l,u]=o.useState(null),h=Wt(t,s),g=zt(a.data).get(h),c=Ht(g),r=i.notes[h],y=i.pending.has(h);if(!g||!c)return r?e.jsx("section",{"data-testid":"hub-update-panel","aria-label":"Hub update",className:"mb-6 max-w-3xl rounded-md border border-hairline p-3 text-body-sm",children:e.jsx("p",{role:r.tone==="error"?"alert":"status",className:r.tone==="error"?"text-danger":"text-ink",children:r.message})}):null;const v=c.kind==="review",j=g.classification==="baseline-unknown",b=p=>({prefer:p,acknowledgeUnknownBaseline:j}),C=async()=>{const p=await i.applyItem(t,s,{...b(),dryRun:!0});u(p??[])};return e.jsxs("section",{"data-testid":"hub-update-panel","aria-label":"Hub update",className:Z("mb-6 max-w-3xl space-y-2 rounded-md border p-3 text-body-sm",cn[c.kind]),children:[e.jsxs("p",{className:"flex items-start gap-2 text-ink",children:[e.jsx(Kt,{mark:c,className:"mt-0.5"}),e.jsx("span",{className:Z(c.kind==="failed"&&"text-danger"),children:Gt(g,c)})]}),v&&j&&e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing records what you changed on this device. Either choice adds the hub's additions and deletes nothing of yours; where the two versions differ, your choice decides which wording stays."}),v&&!j&&e.jsx("p",{className:"text-meta text-ink-muted",children:"Where the two versions differ, your choice decides which wording stays. Everything else is merged, and your current version is saved as a backup first."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[c.kind==="available"&&e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s),children:y?"Updating…":"Update from the hub"}),c.kind==="failed"&&c.retryable&&e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void i.retryItem(t,s),children:y?"Retrying…":"Retry"}),v&&e.jsxs(e.Fragment,{children:[e.jsx(N,{size:"sm",variant:"outline","aria-disabled":y||void 0,onClick:()=>!y&&void C(),children:y&&!l?"Loading…":"Preview the differences"}),e.jsx(N,{size:"sm",variant:"ghost","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s,b("local")),children:"Keep mine where they differ"}),e.jsx(N,{size:"sm",variant:"ghost","aria-disabled":y||void 0,onClick:()=>!y&&void i.applyItem(t,s,b("remote")),children:"Use the hub's where they differ"})]})]}),l&&v&&e.jsx(un,{regions:dn(l)}),r&&e.jsx("p",{role:r.tone==="error"?"alert":"status",className:r.tone==="error"?"text-meta text-danger":"text-meta text-ink-muted",children:r.message})]})}function be(t){return{description:t?.description??"",manager:t?.manager??"manager",members:(t?.members??[]).map(s=>({...s,key:crypto.randomUUID()})),instructions:t?.instructions??"",project:t?.project??""}}function hn(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(({key:a,...i})=>i))!==JSON.stringify(t.members.map(({key:a,...i})=>i))&&(n.members=s.members.map(({key:a,...i})=>i)),s.instructions!==t.instructions&&(n.instructions=s.instructions),s.project!==t.project&&(n.project=s.project),n}function Qe(t,s,n){return(t.kind==="agent"?(s??[]).map(i=>i.name):(n??[]).map(i=>i.name)).includes(t.role)}function Xe({team:t,agents:s,teams:n,askEnabled:a,onSaved:i,onCancelCreate:l,onOpenAgent:u,onAskAgent:h,onDirtyChange:g}){const c=!t,[r,y]=o.useState(c),[v,j]=o.useState(t?.name??""),[b,C]=o.useState(()=>be(t)),[p,k]=o.useState(()=>be(t)),[R,T]=o.useState(!1),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(!1),I=o.useRef(null),U=o.useRef(null),_=o.useRef(null);o.useEffect(()=>{pt()&&requestAnimationFrame(()=>I.current?.focus())},[]);const H=tt(),q=c?!!(v.trim()||p.description||p.members.length):JSON.stringify(p)!==JSON.stringify(b);o.useEffect(()=>(g?.((c||r)&&q),()=>g?.(!1)),[g,c,r,q]),o.useEffect(()=>{if(r&&q)return;const d=be(t);C(d),k(d)},[t,r,q]);const X=()=>{if(c){l?.();return}y(!1),D(null),x(null),L(!1);const d=be(t);C(d),k(d)};ft(()=>{if(E){L(!1);return}q?L(!0):X()},r);const W=async d=>{if(d?.preventDefault(),!R){if(c&&!v.trim()){D("Give the team a name."),x("name"),_.current?.focus();return}if(c&&/[\\/\s]/.test(v.trim())){D("Names cannot contain spaces or slashes."),x("name"),_.current?.focus();return}if(c&&(n??[]).some(S=>S.name===v.trim())){D(`A team called “${v.trim()}” already exists. Open it to change it, or choose another name.`),x("name"),_.current?.focus();return}if(c&&!p.instructions.trim()){D("Give the team instructions."),x("instructions"),U.current?.focus();return}T(!0),D(null),x(null);try{const S=t?await V({op:"teams.update",name:t.name,requestId:crypto.randomUUID(),fields:hn(b,p)}):await V({op:"teams.create",requestId:crypto.randomUUID(),fields:{name:v,description:p.description,manager:p.manager,members:p.members.map(({key:f,...A})=>A),instructions:p.instructions,project:p.project}}),B=be(S);C(B),k(B),y(!1),i(S.name),me(`${c?"Created":"Saved"} ${S.name}.`),c&&gt(),requestAnimationFrame(()=>I.current?.focus())}catch(S){const B=ye(S instanceof Error?S.message:"The team could not be saved.");D(B.message),x(B.field),ke(B.message)}finally{T(!1)}}},K=(d,S)=>k(B=>({...B,members:B.members.map((f,A)=>A===d?{...f,...S}:f)})),J=(p.members.length?p.members:t?.members??[]).reduce((d,S)=>d+(S.count||1),0);return e.jsxs("div",{className:"max-w-3xl space-y-6",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 space-y-2",children:[e.jsx("h2",{ref:I,tabIndex:-1,className:"text-title focus:outline-none",children:t?at(t):"New team"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(O,{variant:"neutral",children:J===1?"1 agent":`${J} agents`}),p.members.some(d=>d.kind==="team")?e.jsx(O,{variant:"neutral",children:"Includes a team"}):null]})]}),t?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"primary",onClick:()=>{st.getState().stageDraft({kind:"team",name:t.name}),H("/chat")},children:"New team chat"}),r?null:e.jsx(N,{variant:"secondary",onClick:()=>y(!0),children:"Edit"}),a?e.jsx(N,{variant:"ghost",onClick:()=>h(`Change the team ${t.name}: `),children:"Ask for a change"}):null]}):null]}),$&&!w?e.jsxs(se,{variant:"danger",role:"alert","data-testid":"team-save-error",children:[e.jsx(ne,{children:"That did not save"}),e.jsx(ae,{children:$})]}):null]}),e.jsx("form",{noValidate:!0,onSubmit:d=>{d.preventDefault(),W(d)},className:"space-y-6",children:c||r?e.jsxs(e.Fragment,{children:[c?e.jsxs(F,{title:"Name",description:"How you and your chats will refer to this team.",children:[e.jsx(ee,{label:"Team name",htmlFor:"team-name",error:w==="name"?$:null}),e.jsx(he,{ref:_,id:"team-name","data-testid":"team-name-input",value:v,required:!0,maxLength:64,autoFocus:!0,"aria-invalid":w==="name",onChange:d=>j(d.target.value)})]}):null,e.jsx(F,{title:"Manager",description:"The agent that leads the chat and decides who works on what.",children:e.jsxs("div",{className:"max-w-md space-y-2",children:[e.jsx(ee,{label:"Manager agent",htmlFor:"team-manager",error:w==="manager"?$:null}),e.jsx(Ne,{ariaLabel:"Manager agent",showLabel:!1,placeholder:"Choose a manager",busyLabel:"Loading agents",options:le(s,n),selected:le(s,n).find(d=>d.id===p.manager)??null,onSelect:d=>k(S=>({...S,manager:d.id})),onCustomSubmit:d=>k(S=>({...S,manager:d})),listNotice:"Agents and teams on this machine"}),le(s,n).some(d=>d.id===p.manager)?null:e.jsxs(O,{variant:"warning","data-testid":"team-manager-missing",children:["Not found: ",p.manager]})]})}),e.jsx(F,{title:"Members",description:"Who the manager can delegate to, and how many of each.",children:e.jsxs("div",{className:"space-y-2",children:[p.members.map((d,S)=>{const B=!Qe(d,s,n);return e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"w-56",children:e.jsx(Ne,{ariaLabel:`Member ${S+1}`,showLabel:!1,placeholder:"Choose an agent or team",busyLabel:"Loading agents",options:[...le(s,n).filter(f=>d.kind==="team"?f.group==="Teams":f.group==="Agents")],selected:le(s,n).find(f=>f.id===d.role)??null,onSelect:f=>K(S,{role:f.id,kind:f.group==="Teams"?"team":"agent"}),onCustomSubmit:f=>K(S,{role:f})})}),e.jsxs(ot,{value:d.kind,onValueChange:f=>K(S,{kind:f}),children:[e.jsx(lt,{"aria-label":`Member ${S+1} kind`,className:"w-32",children:e.jsx(ct,{})}),e.jsxs(dt,{children:[e.jsx(we,{value:"agent",children:"Agent"}),e.jsx(we,{value:"team",children:"Team"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(N,{variant:"secondary",size:"icon-sm","aria-label":`One fewer ${d.role}`,disabled:d.count<=1,onClick:()=>K(S,{count:d.count-1}),children:e.jsx(ts,{"aria-hidden":"true"})}),e.jsx("span",{className:"min-w-6 text-center text-body-sm tabular-nums","aria-label":`${d.count} of ${d.role}`,children:d.count}),e.jsx(N,{variant:"secondary",size:"icon-sm","aria-label":`One more ${d.role}`,disabled:d.count>=16,onClick:()=>K(S,{count:d.count+1}),children:e.jsx(it,{"aria-hidden":"true"})})]}),e.jsx(N,{variant:"ghost",onClick:()=>k(f=>({...f,members:f.members.filter((A,G)=>G!==S)})),children:"Remove"}),B?e.jsxs(O,{variant:"warning",children:["Not found: ",d.role]}):null]},d.key)}),e.jsx(N,{variant:"secondary",onClick:()=>k(d=>({...d,members:[...d.members,{role:"",count:1,kind:"agent",key:crypto.randomUUID()}]})),children:"Add member"})]})}),e.jsxs(F,{title:"Description",children:[e.jsx(ee,{label:"What this team is for",htmlFor:"team-description",error:w==="description"?$:null}),e.jsx(he,{id:"team-description",value:p.description,onChange:d=>k(S=>({...S,description:d.target.value}))})]}),e.jsxs(F,{title:"Collaboration instructions",children:[w==="instructions"?e.jsx("p",{className:"text-meta text-danger",role:"alert","data-testid":"team-instructions-error",children:$}):null,e.jsx(Le,{ref:U,"aria-label":"Collaboration instructions","aria-invalid":w==="instructions",className:"min-h-36",maxLength:8e3,value:p.instructions,onChange:d=>k(S=>({...S,instructions:d.target.value}))})]}),e.jsx(F,{title:"Project brief",children:e.jsx(Le,{"aria-label":"Project brief",className:"min-h-36",maxLength:8e3,value:p.project,onChange:d=>k(S=>({...S,project:d.target.value}))})}),e.jsx(Oe,{submit:!0,confirming:E,onConfirmingChange:L,dirty:q,pending:R,saveLabel:c?"Create team":"Save changes",pendingLabel:c?"Creating…":"Saving…",dirtyHint:"Discard this team?",onSave:()=>void W(),onCancel:X})]}):e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"Manager",description:"The agent that leads the chat.",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(N,{variant:"link",onClick:()=>u(p.manager),children:p.manager}),le(s,n).some(d=>d.id===p.manager)?null:e.jsx(O,{variant:"warning","data-testid":"team-manager-missing",children:"Not found"})]})}),e.jsx(F,{title:"Members",children:e.jsx("ul",{className:"space-y-1",children:(t?.members??[]).map(d=>e.jsxs("li",{className:"flex flex-wrap items-center gap-2 text-body-sm",children:[e.jsx("span",{className:"text-ink",children:d.role}),e.jsx(O,{variant:"neutral",children:d.kind==="team"?"Team":"Agent"}),e.jsx("span",{className:"text-ink-muted",children:d.count===1?"×1":`×${d.count}`}),Qe(d,s,n)?null:e.jsx(O,{variant:"warning","data-testid":"team-member-missing",children:"Not found"})]},`${d.kind}:${d.role}`))})}),e.jsx(F,{title:"What it is for",children:e.jsx(ue,{text:t?.description??"",empty:"No description yet."})}),t?.instructions?e.jsx(F,{title:"Collaboration instructions",children:e.jsx(ue,{text:t.instructions})}):null,t?.project?e.jsx(nt,{summary:"Project brief",children:e.jsx(ue,{text:t.project})}):null]})})]})}function le(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 fn=o.lazy(()=>Mt(()=>import("./legacy-agents-page-ObLsHUbL.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]),import.meta.url).then(t=>({default:t.LegacyAgentsPage}))),Ze=/^subagents\.models\.([^.]+)$/,gn=["lo","med","hi"],De={all:"All",custom:"Custom",installed:"Installed",builtin:"Built-in"},ve=t=>{const s=JSON.stringify(t)??"";let n=5381;for(let a=0;a<s.length;a+=1)n=(n*33^s.charCodeAt(a))>>>0;return`${s.length}.${n.toString(36)}`};function Cn(){const t=At("surface"),{agentId:s}=Tt(),[n,a]=Rt(),i=n.get("kind")==="team"||n.get("create")==="team",l=n.has("create"),u=n.get("name"),h=n.get("duplicate"),g=et(),c=ce(g.data,i?"team_catalogue":"profile_catalogue"),r=$t(c),y=Dt(c),v=c&&!!u&&!l,j=Be(i?null:u,v),b=Lt(i?u:null,v),C=Be(i?null:h,!!h),[p,k]=o.useState(""),[R,T]=o.useState("all"),[$,D]=o.useState(null),[w,x]=o.useState(null),[E,L]=o.useState(0),I=Xs(),U=z(m=>m.marks),_=z(m=>m.clearMark),H=Ft({queryKey:["desktop","settings","effort-tiers"],enabled:c,queryFn:()=>V({op:"settings.list"}),staleTime:6e4}),q=o.useMemo(()=>(H.data?.settings??[]).filter(m=>{const M=m.key.match(Ze)?.[1];return!M||!gn.includes(M)?!1:typeof m.value=="string"&&m.value.trim().length>0}).map(m=>m.key.match(Ze)?.[1]).filter(m=>!!m),[H.data]),X=Vt(),P=o.useCallback(m=>Jt(m,X),[X]),W=o.useMemo(()=>bn(r.data,p,R,P),[r.data,p,R,P]),K=o.useMemo(()=>jn(y.data,p),[y.data,p]),J=i?K:W,d=u??null,[S,B]=o.useState(null);S!==null&&S.name!==d&&B(null);const f=o.useCallback(m=>{const M=new URLSearchParams;(m.kind??(i?"team":"agent"))==="team"&&M.set("kind","team"),m.name&&M.set("name",m.name),m.create!==null&&m.create!==void 0&&M.set("create",m.create),m.duplicate&&M.set("duplicate",m.duplicate),D(null),a(M)},[i,a]),A=`${i?"team":"agent"}:${l??""}:${d??""}`,G=o.useCallback(m=>x(m?A:null),[A]),Y=w!==null&&w===A,[re,fe]=o.useState(!1),ge=`${i?"team":"agent"}:${d??""}`,ie=i?b.data?ve(b.data):null:j.data?ve(j.data):null,oe=o.useRef({identity:ge,content:ie});o.useEffect(()=>{if(oe.current.identity!==ge){oe.current={identity:ge,content:ie},fe(!1);return}if(ie===null||oe.current.content===null){oe.current={identity:ge,content:ie};return}oe.current.content!==ie&&(oe.current.content=ie,Y&&fe(!0))},[ge,ie,Y]);const Me=(m,M)=>e.jsxs(e.Fragment,{children:[e.jsx(mn,{kind:m,name:M,enabled:ce(g.data,"hub_updates")}),re&&e.jsx("output",{className:"mb-6 block max-w-3xl rounded-md border border-warning-border px-3 py-2 text-meta text-ink-muted",children:"The hub updated this definition while you were editing, and the form below now shows the merged version. Edits you had not saved were replaced."})]}),Q=o.useCallback(m=>{if(Y){D(m);return}f(m)},[Y,f]);o.useEffect(()=>{const m=M=>{M.key!=="Escape"||M.defaultPrevented||window.matchMedia("(max-width: 999px)").matches&&(!d&&!l||(M.preventDefault(),Q({name:null})))};return window.addEventListener("keydown",m),()=>window.removeEventListener("keydown",m)},[Q,d,l]),o.useEffect(()=>{const M=z.getState().about;if(!M)return;const Ue=i?"team":"agent";d&&M.kind===Ue&&M.name===d||(I.setAbout(null),gs(M))},[d,i,I]),o.useEffect(()=>{d&&_({kind:i?"team":"agent",name:d})},[d,i,_]);const pe=()=>{r.refetch(),y.refetch(),j.refetch(),b.refetch()};if(s)return e.jsx(o.Suspense,{fallback:e.jsx("p",{className:"p-6 text-body",children:"Loading saved agent…"}),children:e.jsx(fn,{})});const Ae=i?b.error:j.error,xe=i?y.error:r.error,bt=c&&!xe&&!l&&!d,jt=i?b.isLoading:j.isLoading;return e.jsxs("div",{className:"flex h-full min-h-0 bg-canvas text-ink",children:[e.jsxs("aside",{ref:t,"data-open":d?"true":void 0,className:"flex w-72 shrink-0 flex-col gap-3 bg-surface p-4 max-[999px]:data-[open=true]:hidden",children:[e.jsx("h1",{className:"text-heading",children:"Agents and teams"}),e.jsx(ss,{value:i?"team":"agent",onValueChange:m=>Q({kind:m,name:null}),children:e.jsxs(ns,{"aria-label":"Browse definitions by type",className:"w-full",children:[e.jsxs(qe,{value:"agent",className:"flex-1","data-testid":"agents-tab",children:[e.jsx(Yt,{className:"size-3.5"}),"Agents",r.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:r.data.length}):null]}),e.jsxs(qe,{value:"team",className:"flex-1","data-testid":"teams-tab",children:[e.jsx(_t,{className:"size-3.5"}),"Teams",y.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:y.data.length}):null]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ot,{"aria-hidden":"true",className:"pointer-events-none absolute top-2 left-2 size-4 text-ink-dim"}),e.jsx(he,{className:"pl-8",type:"search","aria-label":"Search agents and teams",placeholder:i?"Search teams":"Search agents",value:p,onChange:m=>k(m.target.value)})]}),!i&&r.data?e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("span",{"aria-hidden":"true",className:"text-meta text-ink-muted",children:"Showing"}),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",{className:"flex flex-wrap gap-0.5 rounded-md bg-sunken p-0.5",children:Object.keys(De).map(m=>e.jsx(N,{variant:"ghost",size:"sm","aria-pressed":R===m,onClick:()=>T(m),className:Z(R===m&&rt),children:De[m]},m))})]})]}):null,e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:xe?null:!r.data&&!y.data?e.jsx(Zs,{}):J.length===0?e.jsx("p",{className:"px-1 py-2 text-body-sm text-ink-muted",children:p?`Nothing matches “${p}”.`:i?"No teams yet. Ask for one below, or add one by hand.":R==="all"?"No agents yet. Ask for one below, or add one by hand.":`No ${De[R].toLowerCase()} agents.`}):e.jsx(xn,{rows:J,name:l?null:d,teamMode:i,printName:P,marked:new Map(U.map(m=>[ps(m),m.created])),onOpen:m=>Q({name:m})})}),e.jsxs(N,{variant:"secondary",disabled:!c,onClick:()=>Q({create:i?"team":"agent"}),children:[e.jsx(it,{className:"size-4"}),i?"Add team manually":"Add agent manually"]})]}),e.jsxs("main",{className:"flex min-w-0 flex-1 flex-col",children:[d||l?e.jsx("div",{className:"flex shrink-0 items-center border-hairline border-b px-4 py-2 min-[1000px]:hidden",children:e.jsxs(N,{variant:"ghost",size:"sm",onClick:()=>Q({name:null}),children:[e.jsx(Qt,{className:"size-4"}),"Back to the list"]})}):null,e.jsx("div",{"data-agents-pane":!0,className:"min-h-0 flex-1 overflow-auto p-6 pb-0",style:E>0?{paddingBottom:E+16}:void 0,children:c?xe?e.jsx(Ye,{title:i?"Teams could not be read":"Agents could not be read",what:xe instanceof Error?xe.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:pe,retrying:r.isFetching||y.isFetching}):d&&jt?e.jsx(Je,{}):d&&Ae?e.jsx(Ye,{title:i?`“${d}” could not be read`:`“${d}” could not be read`,what:Ae instanceof Error?Ae.message:"The request did not complete.",meaning:"The definition may have been removed, or the backend refused the read.",onRetry:()=>{j.refetch(),b.refetch()},retrying:j.isFetching||b.isFetching}):l&&i?e.jsx(Xe,{agents:r.data,teams:y.data,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onCancelCreate:()=>f({name:null}),onOpenAgent:m=>Q({kind:"agent",name:m}),onAskAgent:m=>{Re(I,{kind:"team",name:u??""},m)}},"team:create"):l&&h&&C.isLoading?e.jsx(Je,{}):l?e.jsx(ln,{initial:C.data??null,takenNames:(r.data??[]).map(m=>m.name),effortTiers:q,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onCancel:()=>f({name:null})},"agent:create"):i&&b.data?e.jsxs(e.Fragment,{children:[Me("team",b.data.name),e.jsx(Xe,{team:b.data,agents:r.data,teams:y.data,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onOpenAgent:m=>Q({kind:"agent",name:m}),onAskAgent:m=>{Re(I,{kind:"team",name:b.data?.name??""},m)}},`team:${b.data.name}:${ve(b.data)}`)]}):!i&&j.data?e.jsxs(e.Fragment,{children:[Me("agent",j.data.name),e.jsx(on,{profile:j.data,displayedName:P(j.data.name),classNotice:S?.name===j.data.name?S.copy:null,onClassNotice:m=>B(m?{name:j.data.name,copy:m}:null),teams:y.data,effortTiers:q,askEnabled:I.enabled,onDirtyChange:G,onSaved:m=>{pe(),f({name:m})},onDuplicate:m=>Q({create:"agent",duplicate:m.name}),onOpenTeam:m=>Q({kind:"team",name:m}),onAskAgent:m=>{Re(I,{kind:"agent",name:j.data?.name??""},m)}},`agent:${j.data.name}:${j.data.source}:${ve(j.data)}`)]}):d?e.jsx(de,{className:"h-6 w-40"}):e.jsx(pn,{teamMode:i,run:I,onAddManually:()=>Q({create:i?"team":"agent"})}):e.jsxs(se,{variant:g.isLoading?"neutral":"warning",className:"max-w-xl",children:[e.jsx(ne,{children:g.isLoading?"Connecting to the backend":g.error?"The backend could not be reached":"Reusable agents need a newer backend"}),e.jsx(ae,{children:g.isLoading?"Loading what this backend can do…":g.error?g.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:i?"Discard your unsaved changes to this team?":"Discard your unsaved changes to this agent?"}),e.jsx(N,{variant:"danger",onClick:()=>{x(null),f($)},children:"Discard changes"}),e.jsx(N,{variant:"ghost",onClick:()=>D(null),children:"Keep editing"})]}):null,bt?null:e.jsx("div",{className:"shrink-0 border-hairline border-t bg-canvas p-4",children:e.jsx(ut,{run:I,about:I.about,onClearAbout:()=>I.setAbout(null),onStripHeightChange:L,blockedReason:Y?"Finish or cancel your edit first.":null})})]})]})}function pn({teamMode:t,run:s,onAddManually:n}){return e.jsxs("div",{className:"max-w-xl space-y-4",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(ut,{run:s,hero:!0,about:s.about,onClearAbout:()=>s.setAbout(null)}),e.jsx(N,{variant:"ghost",onClick:n,children:t?"Or add a team by hand":"Or add an agent by hand"})]})}function xn({rows:t,name:s,teamMode:n,marked:a,printName:i,onOpen:l}){const u=o.useRef(new Map),[h,g]=o.useState(s),c=(r,y)=>{const v=t.findIndex(b=>b.name===r);if(v<0)return;const j=t[Math.min(t.length-1,Math.max(0,v+y))];j&&(g(j.name),u.current.get(j.name)?.focus())};return e.jsx("ul",{"aria-label":n?"Teams":"Agents",className:"space-y-1",children:t.map(r=>{const y="source"in r,v=a.get(`${n?"team":"agent"}:${r.name}`);return e.jsx("li",{children:e.jsxs("button",{ref:j=>{j?u.current.set(r.name,j):u.current.delete(r.name)},type:"button","aria-current":r.name===s?"true":void 0,tabIndex:r.name===(h??t[0]?.name)?0:-1,"data-testid":`roster-row-${r.name}`,className:Z("flex min-h-11 w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-left hover:bg-row-hover",r.name===s&&rt),onFocus:()=>g(r.name),onClick:()=>l(r.name),onKeyDown:j=>{j.key==="ArrowDown"?(j.preventDefault(),c(r.name,1)):j.key==="ArrowUp"?(j.preventDefault(),c(r.name,-1)):j.key==="Home"?(j.preventDefault(),c(r.name,-t.length)):j.key==="End"&&(j.preventDefault(),c(r.name,t.length))},children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx("span",{className:"truncate text-body-sm text-ink",children:"members"in r?at(r):i(r.name)}),y?e.jsx(ht,{source:r.source,appearance:"text"}):null,v!==void 0?e.jsx(O,{variant:"attention","data-testid":"roster-row-updated",children:v?"New":"Updated"}):null]}),e.jsxs("span",{className:"flex w-full flex-wrap items-center gap-1.5",children:["members"in r?e.jsx(O,{variant:"neutral",children:r.members.length===1?"1 member":`${r.members.length} members`}):null,y&&Ie(r)==="proactive"?e.jsx(O,{variant:"neutral","data-testid":"roster-row-proactive",children:$s.proactive}):null,r.description?e.jsx("span",{className:"min-w-0 flex-1 truncate text-meta text-ink-muted",children:r.description}):null]})]})},r.name)})})}function bn(t,s,n,a){const i=s.trim().toLowerCase();return(t??[]).filter(l=>n==="builtin"&&l.source!=="builtin"||n==="installed"&&l.source!=="installed"||n==="custom"&&l.source!=="custom"?!1:i?a(l.name).toLowerCase().includes(i)||l.name.toLowerCase().includes(i)||(l.description??"").toLowerCase().includes(i):!0)}function jn(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{Cn as AgentsPage};
@@ -1 +1 @@
1
- import{w as ln,p as un,c as G,s as j,e as z,h as an,f as g,t as tn,g as K,m as _,i as rn,j as o,k as sn,l as on,n as fn}from"./conversation-input-sync-QxTZG_kn.js";function cn(l){return l.innerRadius}function gn(l){return l.outerRadius}function yn(l){return l.startAngle}function mn(l){return l.endAngle}function pn(l){return l&&l.padAngle}function dn(l,h,E,q,v,A,B,u){var I=E-l,i=q-h,n=B-v,m=u-A,a=m*I-n*i;if(!(a*a<g))return a=(n*(h-A)-m*(l-v))/a,[l+a*I,h+a*i]}function V(l,h,E,q,v,A,B){var u=l-E,I=h-q,i=(B?A:-A)/K(u*u+I*I),n=i*I,m=-i*u,a=l+n,s=h+m,f=E+n,c=q+m,C=(a+f)/2,t=(s+c)/2,p=f-a,y=c-s,R=p*p+y*y,T=v-A,P=a*c-f*s,O=(y<0?-1:1)*K(on(0,T*T*R-P*P)),S=(P*y-p*O)/R,k=(-P*p-y*O)/R,w=(P*y+p*O)/R,d=(-P*p+y*O)/R,x=S-C,e=k-t,r=w-C,F=d-t;return x*x+e*e>r*r+F*F&&(S=w,k=d),{cx:S,cy:k,x01:-n,y01:-m,x11:S*(v/T-1),y11:k*(v/T-1)}}function hn(){var l=cn,h=gn,E=z(0),q=null,v=yn,A=mn,B=pn,u=null,I=ln(i);function i(){var n,m,a=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=A.apply(this,arguments)-an,C=rn(c-f),t=c>f;if(u||(u=n=I()),s<a&&(m=s,s=a,a=m),!(s>g))u.moveTo(0,0);else if(C>tn-g)u.moveTo(s*G(f),s*j(f)),u.arc(0,0,s,f,c,!t),a>g&&(u.moveTo(a*G(c),a*j(c)),u.arc(0,0,a,c,f,t));else{var p=f,y=c,R=f,T=c,P=C,O=C,S=B.apply(this,arguments)/2,k=S>g&&(q?+q.apply(this,arguments):K(a*a+s*s)),w=_(rn(s-a)/2,+E.apply(this,arguments)),d=w,x=w,e,r;if(k>g){var F=sn(k/a*j(S)),L=sn(k/s*j(S));(P-=F*2)>g?(F*=t?1:-1,R+=F,T-=F):(P=0,R=T=(f+c)/2),(O-=L*2)>g?(L*=t?1:-1,p+=L,y-=L):(O=0,p=y=(f+c)/2)}var H=s*G(p),J=s*j(p),M=a*G(T),N=a*j(T);if(w>g){var Q=s*G(y),U=s*j(y),W=a*G(R),X=a*j(R),D;if(C<un)if(D=dn(H,J,W,X,Q,U,M,N)){var Y=H-D[0],Z=J-D[1],$=Q-D[0],b=U-D[1],nn=1/j(fn((Y*$+Z*b)/(K(Y*Y+Z*Z)*K($*$+b*b)))/2),en=K(D[0]*D[0]+D[1]*D[1]);d=_(w,(a-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else d=x=0}O>g?x>g?(e=V(W,X,H,J,s,x,t),r=V(Q,U,M,N,s,x,t),u.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),u.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(u.moveTo(H,J),u.arc(0,0,s,p,y,!t)):u.moveTo(H,J),!(a>g)||!(P>g)?u.lineTo(M,N):d>g?(e=V(M,N,Q,U,a,-d,t),r=V(H,J,W,X,a,-d,t),u.lineTo(e.cx+e.x01,e.cy+e.y01),d<w?u.arc(e.cx,e.cy,d,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,d,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,a,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),u.arc(r.cx,r.cy,d,o(r.y11,r.x11),o(r.y01,r.x01),!t))):u.arc(0,0,a,T,R,t)}if(u.closePath(),n)return u=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,m=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-un/2;return[G(m)*n,j(m)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:z(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:z(+n),i):h},i.cornerRadius=function(n){return arguments.length?(E=typeof n=="function"?n:z(+n),i):E},i.padRadius=function(n){return arguments.length?(q=n==null?null:typeof n=="function"?n:z(+n),i):q},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:z(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:z(+n),i):A},i.padAngle=function(n){return arguments.length?(B=typeof n=="function"?n:z(+n),i):B},i.context=function(n){return arguments.length?(u=n??null,i):u},i}export{hn as d};
1
+ import{w as ln,p as un,c as G,s as j,e as z,h as an,f as g,t as tn,g as K,m as _,i as rn,j as o,k as sn,l as on,n as fn}from"./conversation-input-sync-OV-zVDW5.js";function cn(l){return l.innerRadius}function gn(l){return l.outerRadius}function yn(l){return l.startAngle}function mn(l){return l.endAngle}function pn(l){return l&&l.padAngle}function dn(l,h,E,q,v,A,B,u){var I=E-l,i=q-h,n=B-v,m=u-A,a=m*I-n*i;if(!(a*a<g))return a=(n*(h-A)-m*(l-v))/a,[l+a*I,h+a*i]}function V(l,h,E,q,v,A,B){var u=l-E,I=h-q,i=(B?A:-A)/K(u*u+I*I),n=i*I,m=-i*u,a=l+n,s=h+m,f=E+n,c=q+m,C=(a+f)/2,t=(s+c)/2,p=f-a,y=c-s,R=p*p+y*y,T=v-A,P=a*c-f*s,O=(y<0?-1:1)*K(on(0,T*T*R-P*P)),S=(P*y-p*O)/R,k=(-P*p-y*O)/R,w=(P*y+p*O)/R,d=(-P*p+y*O)/R,x=S-C,e=k-t,r=w-C,F=d-t;return x*x+e*e>r*r+F*F&&(S=w,k=d),{cx:S,cy:k,x01:-n,y01:-m,x11:S*(v/T-1),y11:k*(v/T-1)}}function hn(){var l=cn,h=gn,E=z(0),q=null,v=yn,A=mn,B=pn,u=null,I=ln(i);function i(){var n,m,a=+l.apply(this,arguments),s=+h.apply(this,arguments),f=v.apply(this,arguments)-an,c=A.apply(this,arguments)-an,C=rn(c-f),t=c>f;if(u||(u=n=I()),s<a&&(m=s,s=a,a=m),!(s>g))u.moveTo(0,0);else if(C>tn-g)u.moveTo(s*G(f),s*j(f)),u.arc(0,0,s,f,c,!t),a>g&&(u.moveTo(a*G(c),a*j(c)),u.arc(0,0,a,c,f,t));else{var p=f,y=c,R=f,T=c,P=C,O=C,S=B.apply(this,arguments)/2,k=S>g&&(q?+q.apply(this,arguments):K(a*a+s*s)),w=_(rn(s-a)/2,+E.apply(this,arguments)),d=w,x=w,e,r;if(k>g){var F=sn(k/a*j(S)),L=sn(k/s*j(S));(P-=F*2)>g?(F*=t?1:-1,R+=F,T-=F):(P=0,R=T=(f+c)/2),(O-=L*2)>g?(L*=t?1:-1,p+=L,y-=L):(O=0,p=y=(f+c)/2)}var H=s*G(p),J=s*j(p),M=a*G(T),N=a*j(T);if(w>g){var Q=s*G(y),U=s*j(y),W=a*G(R),X=a*j(R),D;if(C<un)if(D=dn(H,J,W,X,Q,U,M,N)){var Y=H-D[0],Z=J-D[1],$=Q-D[0],b=U-D[1],nn=1/j(fn((Y*$+Z*b)/(K(Y*Y+Z*Z)*K($*$+b*b)))/2),en=K(D[0]*D[0]+D[1]*D[1]);d=_(w,(a-en)/(nn-1)),x=_(w,(s-en)/(nn+1))}else d=x=0}O>g?x>g?(e=V(W,X,H,J,s,x,t),r=V(Q,U,M,N,s,x,t),u.moveTo(e.cx+e.x01,e.cy+e.y01),x<w?u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,x,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,s,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),!t),u.arc(r.cx,r.cy,x,o(r.y11,r.x11),o(r.y01,r.x01),!t))):(u.moveTo(H,J),u.arc(0,0,s,p,y,!t)):u.moveTo(H,J),!(a>g)||!(P>g)?u.lineTo(M,N):d>g?(e=V(M,N,Q,U,a,-d,t),r=V(H,J,W,X,a,-d,t),u.lineTo(e.cx+e.x01,e.cy+e.y01),d<w?u.arc(e.cx,e.cy,d,o(e.y01,e.x01),o(r.y01,r.x01),!t):(u.arc(e.cx,e.cy,d,o(e.y01,e.x01),o(e.y11,e.x11),!t),u.arc(0,0,a,o(e.cy+e.y11,e.cx+e.x11),o(r.cy+r.y11,r.cx+r.x11),t),u.arc(r.cx,r.cy,d,o(r.y11,r.x11),o(r.y01,r.x01),!t))):u.arc(0,0,a,T,R,t)}if(u.closePath(),n)return u=null,n+""||null}return i.centroid=function(){var n=(+l.apply(this,arguments)+ +h.apply(this,arguments))/2,m=(+v.apply(this,arguments)+ +A.apply(this,arguments))/2-un/2;return[G(m)*n,j(m)*n]},i.innerRadius=function(n){return arguments.length?(l=typeof n=="function"?n:z(+n),i):l},i.outerRadius=function(n){return arguments.length?(h=typeof n=="function"?n:z(+n),i):h},i.cornerRadius=function(n){return arguments.length?(E=typeof n=="function"?n:z(+n),i):E},i.padRadius=function(n){return arguments.length?(q=n==null?null:typeof n=="function"?n:z(+n),i):q},i.startAngle=function(n){return arguments.length?(v=typeof n=="function"?n:z(+n),i):v},i.endAngle=function(n){return arguments.length?(A=typeof n=="function"?n:z(+n),i):A},i.padAngle=function(n){return arguments.length?(B=typeof n=="function"?n:z(+n),i):B},i.context=function(n){return arguments.length?(u=n??null,i):u},i}export{hn as d};