local-operator-ui 0.44.0 → 0.44.2

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 (112) hide show
  1. package/out/main/index.js +32506 -27973
  2. package/out/preload/index.js +84 -6
  3. package/out/renderer/assets/{_basePickBy-D3VtwrNY.js → _basePickBy-LPJBKSk3.js} +1 -1
  4. package/out/renderer/assets/{_baseUniq-D5X85E0S.js → _baseUniq-D8M8HOYM.js} +1 -1
  5. package/out/renderer/assets/agent-details-page-CZuUDIS7.js +6 -0
  6. package/out/renderer/assets/agent-hub-page-B2h53zmZ.js +6 -0
  7. package/out/renderer/assets/agents-page-DxPAtB0k.js +7 -0
  8. package/out/renderer/assets/{approvalsOverlay-BUwR8zXi.js → approvalsOverlay-BjR3EVfg.js} +1 -1
  9. package/out/renderer/assets/{arc-C5lHNCVd.js → arc-Blq81BHO.js} +1 -1
  10. package/out/renderer/assets/{architectureDiagram-IEHRJDOE-DMuNgh30.js → architectureDiagram-IEHRJDOE-BKX_zyB3.js} +1 -1
  11. package/out/renderer/assets/{blockDiagram-JOT3LUYC-DBulh7Ye.js → blockDiagram-JOT3LUYC-DesagpJf.js} +1 -1
  12. package/out/renderer/assets/{book-open-YbPNmvto.js → book-open-BGI5fs27.js} +1 -1
  13. package/out/renderer/assets/browser-page-C156D5SG.js +1 -0
  14. package/out/renderer/assets/{browser-webauthn-prompt-YVU9CDM6.js → browser-webauthn-prompt-dv7y6_dA.js} +1 -1
  15. package/out/renderer/assets/{building-2-Dk-t19G0.js → building-2-D2OTMmkt.js} +1 -1
  16. package/out/renderer/assets/{c4Diagram-VJAJSXHY-L3-9aXQh.js → c4Diagram-VJAJSXHY-CWsH54Hv.js} +1 -1
  17. package/out/renderer/assets/channel-DEPypRI4.js +1 -0
  18. package/out/renderer/assets/{chunk-4BMEZGHF-CgXFdlYf.js → chunk-4BMEZGHF-B0-zmu4b.js} +1 -1
  19. package/out/renderer/assets/{chunk-A2AXSNBT-DT1C_gy2.js → chunk-A2AXSNBT-RQCYYGRS.js} +1 -1
  20. package/out/renderer/assets/{chunk-AEK57VVT-YwH-fCeY.js → chunk-AEK57VVT-DwkZ07Wr.js} +1 -1
  21. package/out/renderer/assets/{chunk-D6G4REZN-CPspVwrW.js → chunk-D6G4REZN-BWg_1fD9.js} +1 -1
  22. package/out/renderer/assets/{chunk-RZ5BOZE2-BEbcJaEy.js → chunk-RZ5BOZE2-3EjCkn2h.js} +1 -1
  23. package/out/renderer/assets/{chunk-XZIHB7SX-BZPybVmi.js → chunk-XZIHB7SX-DoadzlFd.js} +1 -1
  24. package/out/renderer/assets/classDiagram-GIVACNV2-D64NGwBp.js +1 -0
  25. package/out/renderer/assets/classDiagram-v2-COTLJTTW-D64NGwBp.js +1 -0
  26. package/out/renderer/assets/clone-BrsLxtaK.js +1 -0
  27. package/out/renderer/assets/{console-mirror-BiNs1Fcs.js → console-mirror-Cx1_mcwT.js} +10 -10
  28. package/out/renderer/assets/{consoleCapture-C6-j0c5S.js → consoleCapture-CBiwH6qH.js} +1 -1
  29. package/out/renderer/assets/{conversation-input-sync-BNDyyAZz.js → conversation-input-sync-6W6mDd5c.js} +225 -225
  30. package/out/renderer/assets/{dagre-OKDRZEBW-WqN1d2Ic.js → dagre-OKDRZEBW-CkNv39Aw.js} +1 -1
  31. package/out/renderer/assets/{diagram-SSKATNLV-DYfmB1X1.js → diagram-SSKATNLV-DKGhEDc0.js} +1 -1
  32. package/out/renderer/assets/{diagram-VNBRO52H-Bfu4SDNY.js → diagram-VNBRO52H-2dRMMinF.js} +1 -1
  33. package/out/renderer/assets/{en-US-CHJkXXr4.js → en-US-CW_dDnkH.js} +1 -1
  34. package/out/renderer/assets/{erDiagram-Q7BY3M3F-IWOis8-U.js → erDiagram-Q7BY3M3F-BaZqUE9f.js} +1 -1
  35. package/out/renderer/assets/{error-boundary-Bq37z0Vv.js → error-boundary-BhcUnSSp.js} +2 -2
  36. package/out/renderer/assets/{flowDiagram-4HSFHLVR-DG_QDSF3.js → flowDiagram-4HSFHLVR-DO71jsf7.js} +1 -1
  37. package/out/renderer/assets/{ganttDiagram-APWFNJXF-BN03PoHm.js → ganttDiagram-APWFNJXF-aaChmBo1.js} +1 -1
  38. package/out/renderer/assets/{gitGraphDiagram-7IBYFJ6S-Bif0BK48.js → gitGraphDiagram-7IBYFJ6S-DH2o95aG.js} +1 -1
  39. package/out/renderer/assets/{graph-C-tc8AsB.js → graph-BzuMIyA9.js} +1 -1
  40. package/out/renderer/assets/{hash-C3PLrCW5.js → hash-Bof-oLZ7.js} +1 -1
  41. package/out/renderer/assets/{heart-DDY0lTmm.js → heart-Bd5kZnjR.js} +1 -1
  42. package/out/renderer/assets/{index-IM2mLpeL.js → index-B0Ue5RBi.js} +1 -1
  43. package/out/renderer/assets/index-BABrnwf5.css +1 -0
  44. package/out/renderer/assets/{index-C1xioNnx.js → index-Bf_5C9hH.js} +198 -198
  45. package/out/renderer/assets/{index-B4nU7SY-.js → index-CNnTZGuV.js} +1 -1
  46. package/out/renderer/assets/{index-OcjLnSVT.js → index-CxK1ypFa.js} +1 -1
  47. package/out/renderer/assets/infoDiagram-PH2N3AL5-DZJ-3Hbl.js +2 -0
  48. package/out/renderer/assets/{installer-DVWaW2Cw.js → installer-BTKc-9AM.js} +1 -1
  49. package/out/renderer/assets/{journeyDiagram-U35MCT3I-_OmkcLjc.js → journeyDiagram-U35MCT3I-B1iYgquG.js} +1 -1
  50. package/out/renderer/assets/{kanban-definition-NDS4AKOZ-DUSiV5yR.js → kanban-definition-NDS4AKOZ-D6b_9SBk.js} +1 -1
  51. package/out/renderer/assets/{layout-BwlaoNdS.js → layout-BYe1V9vC.js} +1 -1
  52. package/out/renderer/assets/legacy-agents-page-B4QsRAZI.js +33 -0
  53. package/out/renderer/assets/{library-page-ckanGPFY.js → library-page-VgK0BSR2.js} +3 -3
  54. package/out/renderer/assets/{mermaid.core-CrjcyFIw.js → mermaid.core-CENNKUw2.js} +5 -5
  55. package/out/renderer/assets/mesh-page-CEgyAVW-.js +1 -0
  56. package/out/renderer/assets/{messages-Bsgf6o-p.js → messages-Bst4VOU3.js} +10 -10
  57. package/out/renderer/assets/{mindmap-definition-ALO5MXBD-B-X_MKbg.js → mindmap-definition-ALO5MXBD-DPYnshtf.js} +1 -1
  58. package/out/renderer/assets/{mini-_lgzfzw2.js → mini-DjdzboAc.js} +1 -1
  59. package/out/renderer/assets/{notebook-pen-BYY7185A.js → notebook-pen-CZVJiq5R.js} +1 -1
  60. package/out/renderer/assets/org-access-DZc8cPye.js +1 -0
  61. package/out/renderer/assets/org-surface-gate-Bj7rZIwL.js +1 -0
  62. package/out/renderer/assets/{page-header-CSOT2M6K.js → page-header-Dtg6CqtK.js} +1 -1
  63. package/out/renderer/assets/parseISO-CxPiCKvF.js +1 -0
  64. package/out/renderer/assets/path-utils-CzhWDDSj.js +58 -0
  65. package/out/renderer/assets/{pieDiagram-IB7DONF6-KbwgG4tn.js → pieDiagram-IB7DONF6-1_U-X3IZ.js} +1 -1
  66. package/out/renderer/assets/{projects-page-CVNMOB_d.js → projects-page-Bw-AAZ11.js} +6 -6
  67. package/out/renderer/assets/publication-validation-Iutn5hzY.js +1 -0
  68. package/out/renderer/assets/{quadrantDiagram-7GDLP6J5-Bjz4TG3c.js → quadrantDiagram-7GDLP6J5-kbwdrehe.js} +1 -1
  69. package/out/renderer/assets/{radar-MK3ICKWK-BKRNfIwb.js → radar-MK3ICKWK-DpsIZo-R.js} +1 -1
  70. package/out/renderer/assets/{radient-auth-buttons-OK28kSbr.js → radient-auth-buttons-C1Juzc0D.js} +1 -1
  71. package/out/renderer/assets/{requirementDiagram-KVF5MWMF-D4k7IA0L.js → requirementDiagram-KVF5MWMF-qtUg8gWV.js} +1 -1
  72. package/out/renderer/assets/{sankeyDiagram-QLVOVGJD-Dd96CGIr.js → sankeyDiagram-QLVOVGJD-B6i8Lf5L.js} +1 -1
  73. package/out/renderer/assets/{schedules-page-Bf3w5M5d.js → schedules-page-DjiYevaS.js} +2 -2
  74. package/out/renderer/assets/{sequenceDiagram-X6HHIX6F-dLuGQfA8.js → sequenceDiagram-X6HHIX6F-B3NVLrcT.js} +1 -1
  75. package/out/renderer/assets/settings-page-BUpTYpEG.js +287 -0
  76. package/out/renderer/assets/{smartart-BKb_WKE6.js → smartart-BTOCcWLh.js} +1 -1
  77. package/out/renderer/assets/{stateDiagram-DGXRK772-xdA_EMO3.js → stateDiagram-DGXRK772-nACatGwh.js} +1 -1
  78. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-LbiD2EL_.js +1 -0
  79. package/out/renderer/assets/team-bridge-page-BW45aiP2.js +21 -0
  80. package/out/renderer/assets/{timeline-definition-BDJGKUSR-DJcCw_S5.js → timeline-definition-BDJGKUSR-BXO43hMG.js} +1 -1
  81. package/out/renderer/assets/use-default-on-banner-DjHLTfeK.js +1 -0
  82. package/out/renderer/assets/use-download-agent-mutation-D6QgUMMQ.js +56 -0
  83. package/out/renderer/assets/{use-session-snapshot-1Qr287OF.js → use-session-snapshot-CI2ND9fV.js} +1 -1
  84. package/out/renderer/assets/{xychartDiagram-VJFVF3MP-AN9BWRc1.js → xychartDiagram-VJFVF3MP-CA90n1Qk.js} +1 -1
  85. package/out/renderer/browser-approvals-overlay.html +2 -2
  86. package/out/renderer/console-capture.html +6 -6
  87. package/out/renderer/index.html +8 -8
  88. package/out/renderer/installer.html +5 -5
  89. package/out/renderer/mini.html +8 -8
  90. package/package.json +2 -2
  91. package/out/renderer/assets/agent-details-page-DuT7ksQQ.js +0 -6
  92. package/out/renderer/assets/agent-hub-page-Ql4T_UHE.js +0 -6
  93. package/out/renderer/assets/agents-page-b9zRicwX.js +0 -7
  94. package/out/renderer/assets/browser-page-B3tf6s7R.js +0 -1
  95. package/out/renderer/assets/channel-DL0ftT8O.js +0 -1
  96. package/out/renderer/assets/classDiagram-GIVACNV2-jy6TeuKv.js +0 -1
  97. package/out/renderer/assets/classDiagram-v2-COTLJTTW-jy6TeuKv.js +0 -1
  98. package/out/renderer/assets/clone-CxDM6XKV.js +0 -1
  99. package/out/renderer/assets/format-esAOn2VS.js +0 -1
  100. package/out/renderer/assets/index-CJBIsxq7.css +0 -1
  101. package/out/renderer/assets/infoDiagram-PH2N3AL5-BSH7k17A.js +0 -2
  102. package/out/renderer/assets/legacy-agents-page-oa1T18xF.js +0 -33
  103. package/out/renderer/assets/mesh-page-DUvJxJjk.js +0 -1
  104. package/out/renderer/assets/org-access-M6CGnpV0.js +0 -1
  105. package/out/renderer/assets/org-surface-gate-BwyP7jwt.js +0 -1
  106. package/out/renderer/assets/parseISO-BHJWTxrA.js +0 -1
  107. package/out/renderer/assets/path-utils-Dy8qomEz.js +0 -58
  108. package/out/renderer/assets/publication-validation-DaTmgJDa.js +0 -1
  109. package/out/renderer/assets/settings-page-CfM3A9yR.js +0 -287
  110. package/out/renderer/assets/stateDiagram-v2-YXO3MK2T-eb84WKtw.js +0 -1
  111. package/out/renderer/assets/team-bridge-page-Bq0clyqS.js +0 -21
  112. package/out/renderer/assets/use-download-agent-mutation-BsUnGrAQ.js +0 -56
@@ -1,6 +0,0 @@
1
- import{r,j as e,c as U}from"./index-B4nU7SY-.js";import{A as zs,D as yt,h as ce,u as ie,a as Ce,c as re,r as es,d as fe,a3 as ps,f as ss,a2 as vt,O as Nt}from"./path-utils-Dy8qomEz.js";import{P as wt}from"./page-header-CSOT2M6K.js";import{c as St,l as le,B as P,k as C,u as ke,y as _t,I as Ie,T as Ms,D as qe,a as Ue,b as He,d as Be,e as Ke,f as Qe,A as be,m as pe,n as ge,Y as Pt,Z as Tt,_ as Ct,$ as It,F as gs,G as fs,H as ks,J as js,K as ys}from"./error-boundary-Bq37z0Vv.js";import{ap as ts,at as vs,be as Rt,bf as Ds,a4 as G,aq as je,bc as qs,bg as At,ar as Ot,bh as Et,P as Us,ax as Hs,bi as Se,bj as Lt,bk as Ft}from"./conversation-input-sync-BNDyyAZz.js";import{t as l}from"./messages-Bsgf6o-p.js";import{a as $t,p as Bs,P as Ks,u as zt}from"./publication-validation-DaTmgJDa.js";import{h as ae,O as Mt,A as Dt,d as qt,a as Ut,b as Ht,c as Bt,e as Qs,C as Kt,f as Qt,n as Vt,u as Wt,i as Yt}from"./use-download-agent-mutation-BsUnGrAQ.js";import{H as Gt}from"./heart-DDY0lTmm.js";import{z as Jt,aP as Xt,aO as Zt,aQ as Vs,aR as Ws,aS as Ys,aT as ea,aU as sa,aK as as,aV as Ge,aD as ta,aB as Gs,aW as aa,az as ia,u as na,h as la,c as Ns,aI as ra,d as ca,H as oa,aX as da,x as ua,aY as ma}from"./index-C1xioNnx.js";import{n as ha,i as xa,H as ba,p as ws,a as pa,o as Js,u as ga}from"./org-access-M6CGnpV0.js";import{R as Xs}from"./radient-auth-buttons-OK28kSbr.js";import{f as fa}from"./format-esAOn2VS.js";import{o as ka,a as Ve}from"./org-surface-gate-BwyP7jwt.js";import{B as ja}from"./building-2-Dk-t19G0.js";import"./en-US-CHJkXXr4.js";import"./book-open-YbPNmvto.js";import"./console-mirror-BiNs1Fcs.js";/**
2
- * @license lucide-react v0.507.0 - ISC
3
- *
4
- * This source code is licensed under the ISC license.
5
- * See the LICENSE file in the root directory of this source tree.
6
- */const ya=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M17 12h.01",key:"1m0b6t"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M7 12h.01",key:"eqddd0"}]],va=St("circle-ellipsis",ya),Na=({agent:s,isLiked:t,isFavourited:a,onLikeToggle:i,onFavouriteToggle:n,onDownload:u,isLikeActionLoading:m=!1,isFavouriteActionLoading:E=!1,isDownloading:p=!1,actionError:v=null,onRetryAction:L,showActions:_=!0,viewerStateKnown:b=!0,orgName:h=null})=>{const O=zs(),{isAuthenticated:f}=ts(),w=s.description??"",[I,F]=r.useState(!1),T=r.useRef(null),g=r.useCallback(A=>{if(T.current?.disconnect(),T.current=null,!A)return;const z=()=>F(A.scrollHeight-A.clientHeight>1);z();const H=new ResizeObserver(z);H.observe(A),T.current=H},[]),R=f?b?t?"Unlike agent":"Like agent":"Your likes could not be read, so this is not shown as unliked.":"Log in to Radient to like agents",k=f?b?a?"Unfavourite agent":"Favourite agent":"Your favourites could not be read, so this is not shown as unfavourited.":"Log in to Radient to favourite agents",j=b?t?"Unlike agent":"Like agent":"Like state unavailable",y=b?a?"Unfavourite agent":"Favourite agent":"Favourite state unavailable",o=s.visibility==="org",x=ae(s.name);return e.jsxs("div",{"data-glass-block":"",className:"flex h-full flex-col overflow-hidden rounded-md bg-surface transition-colors duration-fast ease-out-quart hover:bg-elevated",children:[e.jsxs("button",{type:"button",onClick:()=>O(`/agent-hub/${s.id}`),className:"flex min-h-0 flex-1 cursor-pointer flex-col gap-2 p-4 text-left","aria-label":`View details for ${x}`,children:[e.jsx("h3",{className:"truncate font-medium text-heading text-ink",children:x}),o&&e.jsx(Mt,{orgName:h}),e.jsx(le,{content:I?w:"",children:e.jsx("span",{ref:g,className:"line-clamp-3 min-h-0 text-body-sm text-ink-muted",children:w})}),e.jsxs("div",{className:"mt-auto flex flex-col gap-2 pt-2",children:[e.jsx(Dt,{tags:s.tags,categories:s.categories}),e.jsxs("p",{className:"truncate text-ink-dim text-meta",children:[s.account_metadata?.name??"Unknown author",e.jsx("span",{"aria-hidden":"true",className:"mx-1.5",children:"·"}),"updated ",qt(new Date(s.updated_at))," ago"]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 border-t border-hairline px-3 py-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-0.5","data-viewer-state":o?"org":f?b?"known":"unknown":"signed-out",children:[!o&&e.jsxs(e.Fragment,{children:[e.jsx(le,{content:R,children:e.jsx("span",{children:e.jsxs(P,{variant:"ghost",size:"sm",onClick:f&&b?()=>i(s.id):void 0,disabled:m||!f||!b,"aria-label":j,className:U(t&&"text-danger"),children:[e.jsx(Gt,{fill:t?"currentColor":"none","data-testid":"agent-like-heart"}),e.jsx("span",{"data-testid":"agent-like-count",className:"inline-flex h-4 min-w-4 items-center font-mono text-mono-sm text-ink-muted",children:s.like_count??0})]})})}),e.jsx(le,{content:k,children:e.jsx("span",{children:e.jsxs(P,{variant:"ghost",size:"sm",onClick:f?()=>n(s.id):void 0,disabled:E||!f||!b,"aria-label":y,className:U(a&&"text-warning"),children:[e.jsx(Jt,{fill:a?"currentColor":"none","data-testid":"agent-favourite-star"}),e.jsx("span",{"data-testid":"agent-favourite-count",className:"inline-flex h-4 min-w-4 items-center font-mono text-mono-sm text-ink-muted",children:s.favourite_count??0})]})})})]}),e.jsx(le,{content:"Downloads",children:e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 pr-1 text-ink-dim",children:[e.jsx(vs,{"aria-hidden":"true",className:"size-3.5"}),e.jsx("span",{className:"inline-flex h-4 min-w-6 items-center font-mono text-mono-sm",children:p?e.jsx(C,{className:"h-3 w-6"}):(s.download_count??0).toLocaleString()})]})})]}),_&&u&&e.jsx("div",{className:"ml-auto flex shrink-0 items-center",children:e.jsxs(P,{variant:"secondary",size:"sm",onClick:()=>u(s),disabled:p,"aria-label":`Download ${x}`,"data-tour-tag":"agent-hub-download-button",children:[e.jsx(vs,{"data-testid":"agent-download"}),"Get"]})})]}),v&&e.jsxs("output",{"data-testid":"agent-card-error",className:"flex flex-wrap items-center gap-x-2 gap-y-1 border-t border-hairline px-3 py-2 text-body-sm text-danger",children:[e.jsx("span",{className:"min-w-0 flex-1",children:v}),L&&e.jsx(P,{variant:"ghost",size:"sm",onClick:L,children:"Try again"})]})]})},wa=({agent:s,status:t,viewerStateKnown:a=!0,orgName:i=null})=>{const{isAuthenticated:n}=ts(),[u,m]=r.useState(null),E=t?.liked??!1,p=t?.favourited??!1,v=Ut(),L=Ht(),_=Bt(),b=()=>{!n||v.isPending||(m(null),v.mutate({agentId:s.id,isCurrentlyLiked:E},{onError:()=>m("like")}))},h=()=>{!n||L.isPending||(m(null),L.mutate({agentId:s.id,isCurrentlyFavourited:p},{onError:()=>m("favourite")}))},O=()=>{_.isPending||(m(null),_.mutate({agentId:s.id,agentName:s.name},{onError:()=>m("download")}))},f=u?u==="like"?{action:"like",error:v.error,retry:b}:u==="favourite"?{action:"favourite",error:L.error,retry:h}:{action:"download",error:_.error,retry:O}:null;return e.jsx(Na,{agent:s,isLiked:n&&E,isFavourited:n&&p,onLikeToggle:b,onFavouriteToggle:h,onDownload:O,isLikeActionLoading:v.isPending,isFavouriteActionLoading:L.isPending,isDownloading:_.isPending,viewerStateKnown:a,orgName:i,actionError:f?$t(f.action,f.error,ae(s.name)):null,onRetryAction:f?.retry})},Ss=({selected:s,onClick:t,children:a,...i})=>e.jsx("button",{type:"button",onClick:t,"aria-pressed":s,className:U("flex w-full cursor-pointer items-center gap-2.5 rounded-sm px-3 py-1.5 text-left","text-body-sm transition-colors duration-fast ease-out-quart",s?Zt:"text-ink hover:bg-row-hover"),...i,children:a}),_s=Object.keys(Kt),Sa=s=>[...s].sort((t,a)=>{const i=_s.indexOf(t),n=_s.indexOf(a);return i!==-1&&n!==-1?i-n:i!==-1?-1:n!==-1?1:t.localeCompare(a)}),_a=({selectedCategory:s,onSelectCategory:t,categories:a})=>{ke();const i=Sa(s&&!a.includes(s)?[...a,s]:a);return e.jsxs("div",{className:"flex h-full flex-col overflow-y-auto",children:[e.jsx("h2",{className:"mb-2 px-3 font-medium text-ink-dim text-meta",children:l("ui.hub.taxonomy.heading")}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsxs(Ss,{selected:s===null,onClick:()=>t(null),"data-testid":"category-all",children:[e.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:e.jsx(Xt,{size:16,"aria-hidden":"true"})}),l("ui.hub.taxonomy.all")]}),i.map(n=>{const u=Qs(n),m=n==="other"?e.jsx(va,{size:16}):u.icon;return e.jsxs(Ss,{selected:s===n,onClick:()=>t(n),"data-testid":`category-${n}`,children:[e.jsx("span",{className:"flex size-4 shrink-0 items-center justify-center",children:m}),u.label]},n)})]})]})},is=({page:s,count:t,onChange:a,ariaLabel:i="Agent pages"})=>{const n=r.useRef(null),u=r.useRef(null),m=r.useRef(null);return r.useEffect(()=>{const E=m.current;m.current=null,E==="previous"&&n.current?.focus(),E==="next"&&u.current?.focus()},[s]),t<=1?null:e.jsxs("nav",{"aria-label":i,className:"mt-6 flex min-h-13 items-center justify-between gap-3 border-t border-hairline","data-testid":"agent-hub-pager",children:[e.jsxs("span",{className:"select-none text-meta text-ink-dim",children:["Page ",s," of ",t]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(P,{variant:"secondary",size:"sm",ref:n,onClick:()=>{s-1<=1&&(m.current="next"),a(s-1)},disabled:s<=1,"aria-label":"Previous page",children:[e.jsx(Rt,{"aria-hidden":"true"}),"Previous"]}),e.jsxs(P,{variant:"secondary",size:"sm",ref:u,onClick:()=>{s+1>=t&&(m.current="previous"),a(s+1)},disabled:s>=t,"aria-label":"Next page",children:["Next",e.jsx(_t,{"aria-hidden":"true"})]})]})]})},Pa=/alias/i;function Ps(s){return s instanceof yt?s.code==="alias-occupied"?!0:s.code==="origin-conflict"&&Pa.test(s.message):!1}const Ta=/\/+$/;function ns(s){const t=s.replace(Ta,"");try{const{pathname:a}=new URL(t);return a===""||a==="/"?`${t}/v1`:t}catch{return`${t}/v1`}}const Ts=s=>s?.skills===1&&s.revision_cas===1;function Ca(s,t=1,a=20){const i=new URL(Vs(s,"skills"));return i.searchParams.set("page",String(t)),i.searchParams.set("per_page",String(a)),Ws(i.toString())}function Ia(s,t){return Ws(Vs(s,"skills",t))}function Ra(s){return Ds({operation:"org_skills.list",tenantId:s})}function Aa(s,t){return Ds({operation:"org_skill.get",tenantId:s,skillId:t})}const ls=12,_e={all:["public-teams"],list:(s,t)=>[..._e.all,"list",{page:s,perPage:t}],detail:s=>[..._e.all,"detail",s]},Re=(s,t)=>t instanceof Ys?t.status===null?!1:t.status>=500&&s<1:s<1,Zs=({page:s=1,perPage:t=ls,enabled:a=!0}={})=>{const i=ce({queryKey:_e.list(s,t),queryFn:()=>ea(G.radientBaseUrl,s,t),select:n=>n.result,enabled:a,retry:Re,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,placeholderData:n=>n});return{...i,teams:i.data?.records??[],isRefreshing:i.isFetching&&i.data!==void 0,pagination:i.data?{page:i.data.page,perPage:i.data.per_page,totalPages:i.data.total_pages,totalRecords:i.data.total_records}:void 0}},Oa=({teamId:s,enabled:t=!0})=>{const a=ce({queryKey:_e.detail(s??""),queryFn:()=>sa(G.radientBaseUrl,s),select:i=>i.result,enabled:t&&!!s,retry:Re,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,retryOnMount:!1});return{...a,team:a.data}};function oe(s){if(s.getQueryState(ps.capabilities)?.status!=="success"||!re(s.getQueryData(ps.capabilities),"hub_skills"))throw new Error("This backend does not support the complete Hub Skills adapter.")}function et(s,t,a){const i=ie(),n=Ce();return ce({queryKey:["hub-skills",G.radientBaseUrl,s.visibility,s.tenantId,t],enabled:a&&!n.isError&&re(n.data,"hub_skills"),queryFn:async()=>{if(oe(i),s.visibility==="org"){const m=(await Ra(s.tenantId)).result;return{rows:m.skills,pages:1,total:m.skills.length,contract:m.sync_contract}}const u=(await Ca(G.radientBaseUrl,t,20)).result;return{rows:u.records,pages:u.total_pages,total:u.total_records,contract:u.sync_contract}},staleTime:3e4,retry:s.visibility==="org"?es:Re,retryOnMount:!1,refetchOnWindowFocus:!1})}function Ea(s,t,a){const i=ie(),n=Ce();return ce({queryKey:["hub-skill",G.radientBaseUrl,s.visibility,s.tenantId,t],enabled:a&&t!==null&&!n.isError&&re(n.data,"hub_skills"),queryFn:async()=>(oe(i),(s.visibility==="org"?await Aa(s.tenantId,t):await Ia(G.radientBaseUrl,t)).result),staleTime:3e4,retry:s.visibility==="org"?es:Re,retryOnMount:!1})}function rs(s,t){s.setQueryData(as,t.links)}function cs(s){s.invalidateQueries({queryKey:as}),s.invalidateQueries({queryKey:["desktop","skills"]})}function La(){const s=ie();return je({mutationFn:t=>(oe(s),fe({op:"hub.skillPull",requestId:t.requestId,hubId:t.remoteId,hubSource:ns(G.radientBaseUrl),visibility:t.scope.visibility,tenantId:t.scope.tenantId,localAlias:t.alias,subscribe:t.subscribe,autoPush:t.autoPush,confirmPublicEgress:t.consent})),onSuccess:t=>{rs(s,t)},onSettled:()=>{cs(s)}})}function Fa(){const s=ie();return je({mutationFn:t=>(oe(s),fe({op:"hub.skillSubscribe",requestId:t.requestId,hubId:t.remoteId,hubSource:ns(G.radientBaseUrl),visibility:t.scope.visibility,tenantId:t.scope.tenantId,localAlias:t.alias})),onSuccess:t=>{rs(s,t)},onSettled:()=>{cs(s)}})}function $a(){const s=ie();return je({mutationFn:t=>(oe(s),fe({op:"hub.skillUnpull",requestId:t.requestId,linkId:t.linkId})),onSuccess:t=>{rs(s,t)},onSettled:()=>{cs(s)}})}function za(){const s=ie();return je({mutationFn:t=>(oe(s),fe({op:"hub.skillPublish",requestId:t.requestId,...t.draft,dryRun:t.previewReceipt===void 0,...t.previewReceipt?{previewReceipt:t.previewReceipt,confirmPublish:!0}:{}})),onSuccess:t=>{t.local_link_receipt?.state==="complete"&&(s.invalidateQueries({queryKey:as}),s.invalidateQueries({queryKey:["desktop","skills"]}),s.invalidateQueries({queryKey:["hub-skills"]}))}})}const Ma=/\/+$/;function Cs(s){return s.replace(Ma,"")}function Da(s,t){return t.visibility==="public"?s.visibility==="public"&&!s.tenant_id:s.visibility==="org"&&s.tenant_id===t.tenantId}function Je(s){const t=s.id??s.hub_id??"",a=s.tenantId??s.tenant_id??"";return`${t}\0${s.visibility}\0${a}`}function qa(s,t){const a=Cs(t),i=new Map;for(const n of s??[])n.kind==="skill"&&Cs(n.hub_source)===a&&i.set(Je({hub_id:n.hub_id,visibility:n.visibility,tenantId:n.tenant_id}),n);return i}function Is(s,t,a=!0){if(!a)return{kind:"unknown"};if(!s)return{kind:"not-present"};const i=Ge(s);return i==="present"&&(s.pull.state==="available"||t?.state==="available"&&!t.error_class)?{kind:"update",link:s,automatic:t?.auto_will_apply===!0||s.auto_will_apply}:i==="absent"?s.policy.subscribe?{kind:"subscribed",link:s}:{kind:"detached",link:s}:s.policy.subscribe?{kind:"pulled",link:s}:{kind:"manual",link:s}}function Ua(s){return s?"policy":"create"}function Ha(s){return JSON.stringify({op:"pull",selected:s.selected,scope:s.scope,localAlias:s.localAlias,subscribe:s.subscribe,autoPush:s.autoPush,consent:s.consent})}function Ba({scope:s,source:t,verifiedCas:a,enabled:i=!0,heading:n=!0}){ke();const u=r.useId(),[m,E]=r.useState(""),[p,v]=r.useState(""),[L,_]=r.useState(ha),[b,h]=r.useState(null),[O,f]=r.useState(!1),w=za(),I=r.useRef(null),F=ce({queryKey:["desktop","skills","hub-publication"],queryFn:()=>fe({op:"skills.list"}),staleTime:3e4,retry:!1}),T=`${s.visibility}:${s.tenantId??""}`,g=r.useRef(T);r.useEffect(()=>{g.current!==T&&(g.current=T,_(y=>({...y,autoPush:!1,confirmPublicEgress:!1})),h(null),f(!0))},[T]);const R={sourceSkill:m,localAlias:p,visibility:s.visibility,tenantId:s.tenantId,...L},k=b?xa(b,R):!1;r.useEffect(()=>{if(!b)return;const y=setTimeout(()=>{h(null),f(!0)},Math.max(0,Math.min(Date.parse(b.expires_at)-Date.now(),2147483647)));return()=>clearTimeout(y)},[b]);const j=y=>{if(!i||w.isPending||!m||!p||y&&!k)return;const o=JSON.stringify({draft:R,receipt:y?b?.preview_receipt:null}),x=I.current&&I.current.tuple===o&&(y||w.error)?I.current:{tuple:o,id:crypto.randomUUID()};I.current=x,y||(h(null),f(!1)),w.mutate({requestId:x.id,draft:R,...y&&b?{previewReceipt:b.preview_receipt}:{}},{onSuccess:A=>{A.preview?(h(A.preview),f(!1)):ws(A)&&h(null)}})};return e.jsxs("section",{className:"flex min-w-0 flex-col gap-4","data-hub-skill-publication":!0,children:[n&&e.jsx("h3",{className:"text-heading text-ink",children:l("ui.hub.skills.publish_title")}),e.jsx("label",{htmlFor:`${u}-source`,className:"text-body-sm text-ink",children:l("ui.hub.skills.select_authored")}),e.jsxs("select",{id:`${u}-source`,"data-testid":"hub-skill-publish-source",value:m,disabled:w.isPending||!i,className:"rounded-md border border-control bg-surface px-3 py-2 text-body-sm text-ink",onChange:y=>{E(y.target.value),v(y.target.value),h(null),_(o=>({...o,autoPush:!1,confirmPublicEgress:!1}))},children:[e.jsx("option",{value:"",children:l("ui.hub.skills.select_authored")}),F.data?.data.skills.map(y=>e.jsx("option",{value:y.name,children:y.name},y.name))]}),e.jsx("label",{htmlFor:`${u}-alias`,className:"text-body-sm text-ink",children:l("ui.hub.subscriptions.alias")}),e.jsx(Ie,{id:`${u}-alias`,"data-testid":"hub-skill-publish-alias",value:p,disabled:w.isPending||!i,onChange:y=>{v(y.target.value),_(o=>({...o,autoPush:!1,confirmPublicEgress:!1}))}}),e.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.text_limits")}),e.jsx(ba,{value:L,onChange:_,source:t,item:m||p,visibility:s.visibility,organization:s.organization,destinationKey:`${T}:${m}`,canEnableAutoPush:a,disabled:w.isPending||!i}),F.isLoading&&e.jsx("output",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.loading")}),F.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:l("ui.hub.status.other_error")}),w.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:l("ui.hub.links.action_failed",{direction:l("ui.hub.links.direction_push"),item:m||p,source:t})}),(O||b&&!k&&b.can_confirm)&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:l("ui.hub.links.preview_changed")}),b&&b.visibility===s.visibility&&b.tenant_id===s.tenantId&&e.jsxs("div",{className:"flex min-w-0 flex-col gap-3",children:[e.jsx("h4",{className:"text-body-sm text-ink",children:l("ui.hub.links.preview_payload",{source:t})}),e.jsx(Ms,{readOnly:!0,rows:12,"aria-label":l("ui.hub.links.preview_payload",{source:t}),value:JSON.stringify(b.proposal.fields,null,2),className:"max-h-96 bg-sunken text-mono-sm"}),b.warnings.map((y,o)=>e.jsx("p",{className:"break-words text-body-sm text-warning",children:y},`${o}-${y}`)),b.reason&&e.jsx("p",{className:"text-body-sm text-warning",children:ta(b.reason)})]}),w.data?.publication===null&&w.data.local_link_receipt?.state==="pending-reconciliation"&&e.jsx("output",{className:"text-body-sm text-warning","data-testid":"hub-skill-pending-reconcile",children:l("ui.hub.links.publication_pending")}),w.data?.publication&&e.jsx("output",{className:"text-body-sm text-ink","data-testid":"hub-skill-published",children:ws(w.data)?l("ui.hub.links.published",{item:w.data.link?.name??p,source:w.data.link?Gs(w.data.link):t}):l("ui.hub.skills.policy_pending")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{variant:"outline","data-testid":"hub-skill-publish-preview",disabled:!i||w.isPending||!m||!p,onClick:()=>j(!1),children:l("ui.hub.subscriptions.preview_publish")}),e.jsx(P,{"data-testid":"hub-skill-publish-confirm",disabled:!i||w.isPending||!k,onClick:()=>j(!0),children:l("ui.hub.links.confirm_publish")})]})]})}const Ka={available:"text-accent",applied:"text-success",failed:"text-danger",review:"text-warning",updating:"text-ink-muted"},Qa={available:"ui.hub.skills.update_available",applied:"ui.hub.skills.update_applied",failed:"ui.hub.skills.update_failed",review:"ui.hub.links.mark_review",updating:"ui.hub.links.mark_busy"},Va={"not-present":"ui.hub.skills.not_downloaded",subscribed:"ui.hub.skills.subscribed_absent",pulled:"ui.hub.skills.pulled",manual:"ui.hub.skills.manual",detached:"ui.hub.skills.detached"};function Rs(s,t,a){const i=t?ca(t):null;return i&&(s.kind==="update"||a&&(t?.state==="applied"||t?.state==="failed"||t?.error_class))?i:s.kind==="update"?{kind:"available",auto:s.automatic}:null}function As(s,t){return s.kind==="unknown"?t:s.kind!=="update"?l(Va[s.kind]):l(s.link.policy.subscribe?"ui.hub.skills.pulled":"ui.hub.skills.manual")}function Os({mark:s}){return ke(),s?e.jsxs("span",{"data-hub-mark-state":s.kind,className:U("flex shrink-0 items-center gap-1 text-meta",Ka[s.kind]),children:[e.jsx(oa,{mark:s}),e.jsx("span",{children:l(Qa[s.kind])})]}):null}function Es(s,t){const a=s.publisher?.trim();return a?l("ui.hub.skills.published_by",{publisher:a}):s.visibility==="org"?t??l("ui.hub.links.source_unavailable"):l("ui.hub.skills.public_hub")}function Wa({scope:s,signedIn:t,accessible:a=!0}){ke();const i=r.useId(),[n,u]=r.useState(1),[m,E]=r.useState(""),[p,v]=r.useState(null),[L,_]=r.useState(!1),[b,h]=r.useState("unsubscribe"),[O,f]=r.useState(!1),w=r.useRef(null),I=s.visibility==="public"?l("ui.hub.links.source_public"):s.organization?l("ui.hub.links.source_private",{organization:s.organization}):l("ui.hub.links.source_unavailable"),F=Ce(),T=a&&re(F.data,"hub_updates"),g=et(s,n,a&&(s.visibility==="public"||t)),R=Ts(g.data?.contract),k=Ea(s,p,R&&a),j=La(),y=Fa(),o=$a(),x=aa(),A=ia(a&&re(F.data,"hub_links")),z=na(T),H=r.useMemo(()=>qa(A.data?.links,ns(G.radientBaseUrl)),[A.data]),M=r.useMemo(()=>la(z.data),[z.data]),q=j.data?.link?.link_id,N=!A.isLoading&&!A.error,D=A.error?l("ui.hub.skills.inventory_unknown"):l("ui.hub.links.loading"),se=k.data?.visibility===s.visibility&&(s.visibility==="public"?!k.data.tenant_id:k.data.tenant_id===s.tenantId),te=a&&!k.error&&!g.error&&se&&Ts(k.data?.sync_contract)&&!!k.data?.revision,de=(g.data?.rows??[]).filter(d=>Da(d,s)),ye=de.filter(d=>`${d.name} ${d.description}`.toLocaleLowerCase().includes(m.toLocaleLowerCase())),Q=de.find(d=>d.id===p),S=Q?H.get(Je({id:Q.id,visibility:Q.visibility,tenantId:Q.tenant_id??null})):void 0,ve=S?M.get(Ns("skill",S.name)):void 0,ue=Is(S,ve,N),ee=S?Ge(S)==="present":!1,Ae=d=>{const $=H.get(Je({id:d.id,visibility:d.visibility,tenantId:d.tenant_id??null})),X=$?M.get(Ns("skill",$.name)):void 0;return{link:$,update:X,state:Is($,X,N)}},me=d=>(w.current?.tuple!==d&&(w.current={tuple:d,id:crypto.randomUUID()}),w.current.id),ne=d=>{if(!p||!te||!t)return;const $=d?.name??Q?.name??"";if(!$)return;const X=d?d.policy.subscribe:!1,xe=d?.policy.auto_push??!1,Ne=!1;j.mutate({requestId:me(Ha({selected:p,scope:s,localAlias:$,subscribe:X,autoPush:xe,consent:Ne})),remoteId:p,scope:s,alias:$,subscribe:X,autoPush:xe,consent:Ne})},Oe=()=>{if(!p||!te||!t)return;if(Ua(S)==="policy"&&S){if(S.policy.subscribe||x.isPending)return;h("subscribe"),x.mutate({link:S,patch:{subscribe:!0}});return}const d=Q?.name??"";d&&y.mutate({requestId:me(JSON.stringify({op:"subscribe",selected:p,scope:s,localAlias:d})),remoteId:p,scope:s,alias:d})},Ee=()=>{S&&o.mutate({requestId:me(JSON.stringify({op:"unpull",link:S.link_id})),linkId:S.link_id},{onSuccess:()=>{j.reset(),y.reset()}})},V=()=>{!S||S.policy.subscribe===!1||x.isPending||!x.canWrite||(h("unsubscribe"),x.mutate({link:S,patch:{subscribe:!1}}))},J=t&&R&&a&&!g.error,he=g.data?.total??de.length,B=g.error?null:g.isLoading?l("ui.hub.skills.loading"):s.organization?l("ui.hub.skills.count_shared",{count:he,organization:s.organization}):l("ui.hub.skills.count",{count:he});return e.jsxs("section",{className:"flex min-w-0 flex-col gap-4","data-hub-skills-library":!0,children:[s.visibility==="org"&&!t?e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:l("ui.hub.status.no_credential")}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:U("flex min-w-56 max-w-md flex-1 items-center rounded-sm border border-control bg-surface","transition-colors duration-fast ease-out-quart","has-[:focus-visible]:outline-solid has-[:focus-visible]:outline-2","has-[:focus-visible]:outline-accent has-[:focus-visible]:outline-offset-2"),children:[e.jsx(qs,{"aria-hidden":"true",className:"ml-2 shrink-0 text-ink-dim"}),e.jsx(Ie,{id:`${i}-search`,type:"search","data-testid":"hub-skill-search",value:m,placeholder:l("ui.hub.skills.search"),"aria-label":l("ui.hub.skills.search"),onChange:d=>E(d.target.value),className:"h-8 min-w-0 flex-1 border-0 bg-transparent outline-none"})]}),J&&e.jsx(P,{variant:"secondary","data-testid":"hub-skill-publish-open",onClick:()=>f(!0),children:l("ui.hub.skills.publish_title")})]}),B!==null&&e.jsx("p",{"aria-live":"polite",className:"text-meta text-ink-dim","data-testid":"hub-skill-status",children:s.organization||g.isLoading?e.jsx("span",{"data-testid":"hub-skill-source",children:B}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:B})," · ",e.jsx("span",{"data-testid":"hub-skill-source",children:l("ui.hub.skills.public_hub")})]})}),g.error&&e.jsxs("div",{role:"alert",className:"flex flex-col items-start gap-2 text-body-sm text-warning",children:[e.jsx("p",{children:l("ui.hub.skills.catalogue_failed",{source:I})}),e.jsx(P,{variant:"outline",className:"self-start",disabled:g.isFetching,onClick:()=>void g.refetch(),children:l("ui.hub.links.retry")})]}),g.isSuccess&&!R&&e.jsx("p",{className:"text-body-sm text-warning",children:l("ui.hub.skills.unavailable")}),R&&e.jsxs(e.Fragment,{children:[ye.length===0&&e.jsx("p",{className:"text-body-sm text-ink-muted",children:l(m?"ui.hub.skills.search_empty":"ui.hub.skills.remote_empty")}),e.jsx("ul",{className:"grid list-none grid-cols-[repeat(auto-fill,minmax(17.5rem,1fr))] gap-6 p-0",children:ye.map(d=>{const $=Ae(d),X=Rs($.state,$.update,$.link?Ge($.link)==="present":!1);return e.jsx("li",{className:"min-w-0",children:e.jsxs("button",{type:"button","aria-haspopup":"dialog","aria-expanded":p===d.id,"aria-label":l("ui.hub.skills.open_detail",{item:d.name}),"data-testid":"hub-skill-open","data-skill-id":d.id,"data-skill-state":$.state.kind,onClick:()=>{v(d.id),j.reset(),y.reset(),o.reset(),x.reset()},className:U("flex h-full w-full flex-col overflow-hidden rounded-md bg-surface text-left","transition-colors duration-fast ease-out-quart hover:bg-elevated","focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-1"),children:[e.jsxs("span",{className:"flex min-h-0 flex-1 flex-col gap-2 p-4",children:[e.jsx("span",{className:"truncate font-medium text-heading text-ink",children:d.name}),d.description?e.jsx("span",{className:"line-clamp-3 text-body-sm text-ink-muted",children:d.description}):null,e.jsx("span",{className:"mt-auto truncate text-ink-dim text-meta",children:Es(d,s.organization)})]}),e.jsxs("span",{className:"flex items-center justify-between gap-2 border-t border-hairline px-4 py-2 text-meta",children:[e.jsx("span",{className:"truncate text-ink-muted",children:As($.state,D)}),e.jsx(Os,{mark:X})]})]})},d.id)})}),e.jsx(is,{page:n,count:g.data?.pages??1,onChange:u,ariaLabel:l("ui.hub.skills.title")})]})]}),!a&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:l("ui.hub.status.access_lost")}),e.jsx(qe,{open:!!p&&R,onOpenChange:d=>{d||v(null)},children:e.jsxs(Ue,{"data-hub-skill-detail":"",className:"max-h-[85vh] overflow-y-auto sm:max-w-2xl",children:[e.jsxs(He,{children:[e.jsx(Be,{"data-testid":"hub-skill-detail-name",children:k.data?.name??Q?.name??l("ui.hub.skills.title")}),e.jsx(Ke,{children:k.data&&se?Es(k.data,s.organization):I})]}),k.isLoading&&e.jsx("output",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.loading")}),k.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:l("ui.hub.status.other_error")}),k.data&&se&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("p",{className:"text-body-sm text-ink-muted",children:[As(ue,D),e.jsx("span",{"aria-hidden":"true",className:"mx-1.5",children:"·"}),l("ui.hub.skills.revision",{revision:String(k.data.content_revision)})]}),e.jsx(Os,{mark:Rs(ue,ve,ee)})]}),e.jsx("p",{"data-testid":"hub-skill-description",className:"max-w-3xl select-text whitespace-pre-wrap break-words text-body-sm text-ink-muted",children:k.data.description}),S&&ee&&S.local_path&&e.jsx("p",{"data-testid":"hub-skill-local-path",className:"break-words font-mono text-meta text-ink-dim",children:l("ui.hub.skills.local_path",{path:`⁨${S.local_path}⁩`})}),e.jsx("h4",{className:"text-body-sm text-ink",children:l("ui.hub.skills.files")}),e.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.file_count",{count:k.data.files.length})}),k.data.files.map(d=>e.jsxs("details",{className:"min-w-0",children:[e.jsx("summary",{className:"break-words text-mono-sm text-ink",children:d.path}),e.jsx(Ms,{readOnly:!0,rows:12,"aria-label":d.path,value:d.content,className:"max-h-96 bg-sunken text-mono-sm"})]},d.path)),S&&e.jsxs("div",{className:"flex flex-col gap-2 border-t border-hairline pt-3",children:[e.jsx(ra,{link:S}),S.policy.subscribe&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(P,{variant:"outline",size:"sm","data-testid":"hub-skill-unsubscribe",disabled:x.isPending||!x.canWrite,onClick:V,children:l("ui.hub.skills.unsubscribe")}),e.jsx("span",{className:"text-meta text-ink-muted",children:l("ui.hub.skills.unsubscribe_help")})]}),x.error&&e.jsx("p",{role:"alert",className:"text-meta text-danger",children:l("ui.hub.subscriptions.save_failed",{setting:b==="subscribe"?l("ui.hub.subscriptions.subscribe"):l("ui.hub.skills.unsubscribe"),source:I})})]}),S&&ee&&e.jsx(pa,{kind:"skill",name:S.name,enabled:T}),j.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger","data-testid":"hub-skill-pull-failed",children:l(Ps(j.error)?"ui.hub.skills.local_exists":"ui.hub.skills.pull_failed")}),j.data&&!j.data.reports?.some(d=>d.applied||d.outcome==="unchanged")&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger","data-testid":"hub-skill-pull-failed",children:l("ui.hub.skills.pull_failed")}),j.data?.link&&j.data.reports?.some(d=>d.link_id===q&&d.direction==="pull"&&d.applied)&&e.jsx("output",{"data-testid":"hub-skill-installed",className:"text-body-sm text-ink",children:l("ui.hub.skills.installed_alias",{item:j.data.link.name,source:Gs(j.data.link)})}),o.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger","data-testid":"hub-skill-unpull-failed",children:l("ui.hub.skills.unpull_failed")}),y.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger","data-testid":"hub-skill-subscribe-failed",children:l(Ps(y.error)?"ui.hub.skills.local_exists":"ui.hub.skills.subscribe_failed")}),!t&&e.jsx("p",{className:"text-meta text-ink-muted",children:l("ui.hub.status.no_credential")}),(!S||!ee)&&e.jsxs(Qe,{className:"flex-row flex-wrap justify-start gap-2",children:[e.jsx(P,{"data-testid":"hub-skill-download",disabled:!t||!te||j.isPending||!N,"aria-label":l("ui.hub.skills.pull_title",{item:k.data.name,source:I}),onClick:()=>ne(S),children:l("ui.hub.skills.download")}),!S?.policy.subscribe&&e.jsx(P,{variant:"outline","data-testid":"hub-skill-subscribe",disabled:!t||!te||!N||y.isPending||x.isPending||(S?!x.canWrite:!1),onClick:Oe,children:l("ui.hub.subscriptions.subscribe")})]}),S&&ee&&e.jsx(Qe,{className:"flex-row flex-wrap justify-start gap-2",children:e.jsx(P,{variant:"outline","data-testid":"hub-skill-unpull",disabled:o.isPending,onClick:()=>{o.reset(),_(!0)},children:l("ui.hub.skills.unpull")})}),(!S||!ee)&&e.jsx("p",{className:"text-meta text-ink-muted",children:S?.policy.subscribe?l("ui.hub.skills.download_help"):l("ui.hub.skills.subscribe_help")})]})]})}),e.jsx(qe,{open:L,onOpenChange:d=>{d||_(!1)},children:e.jsxs(Ue,{className:"sm:max-w-md",children:[e.jsxs(He,{children:[e.jsx(Be,{children:l("ui.hub.skills.unpull_title",{item:k.data?.name??S?.name??""})}),e.jsx(Ke,{children:l("ui.hub.skills.unpull_body")})]}),e.jsxs(Qe,{children:[e.jsx(P,{variant:"outline",onClick:()=>_(!1),children:l("ui.hub.subscriptions.cancel")}),e.jsx(P,{"data-testid":"hub-skill-unpull-confirm",disabled:o.isPending,onClick:()=>{Ee(),_(!1)},children:l("ui.hub.skills.unpull")})]})]})}),e.jsx(qe,{open:O,onOpenChange:f,children:e.jsxs(Ue,{className:"max-h-[85vh] overflow-y-auto sm:max-w-2xl",children:[e.jsxs(He,{children:[e.jsx(Be,{children:l("ui.hub.skills.publish_title")}),e.jsx(Ke,{children:I})]}),e.jsx(Ba,{scope:s,source:I,verifiedCas:R&&a&&t,enabled:R&&a&&t,heading:!1})]})})]})}const st={all:["org-teams"],list:s=>[...st.all,"list",s]},tt=({tenantId:s,enabled:t=!0})=>{const a=ce({queryKey:st.list(s??""),queryFn:async()=>(await da(s)).result??{teams:[]},enabled:t&&!!s,staleTime:3e5,gcTime:6e5,refetchOnWindowFocus:!1,retryOnMount:!1,retry:es});return{...a,teams:a.data?.teams??[]}},Ya=(s,t)=>{const a=s?.name?.trim()||t?.trim()||"Team",i=s?.renamed_from?.trim()||null;return s?.invalid_name===!0&&i?{level:"warning",message:`Pulled "${a}". The published name "${i}" is not usable locally, so the team was stored as "${a}".`}:i?{level:"success",message:`Pulled "${a}" (you already have a team called "${i}").`}:{level:"success",message:`Pulled team "${a}".`}},at=()=>{const s=ie();return je({mutationFn:async({teamId:t,tenantId:a})=>{if(!G.baseUrl)throw new Error("Local Operator API URL is not configured.");return Et.pullOrgTeamFromRadient(G.baseUrl,t,a)},onSuccess:(t,a)=>{const i=Ya(t.result,a.name);i.level==="warning"?At(i.message):Ot(i.message),s.invalidateQueries({queryKey:["desktop","teams"]})},onError:t=>{console.error("Pulling an organization team failed:",t)}})},Ga=/^v/i,it=s=>s.members.reduce((t,a)=>t+a.count,0),Ja=s=>s.count>1?`${s.role} ×${s.count}`:s.role,Xe=s=>s.members.map(Ja).join(", "),nt=s=>{const t=(s.version??"").trim().replace(Ga,"").trim();return t===""?null:t},lt=s=>{const t=s.account_metadata?.name?.trim();return t||null},Xa=s=>{const t=(s.description??"").trim();return t===""?null:t},Ze=240,Za=Ze/2,ei=(s,t)=>{if(t||s.length<=Ze)return s;const a=s.slice(0,Ze),i=a.lastIndexOf(" ");return`${(i>=Za?a.slice(0,i):a).trimEnd()}…`},Pe=s=>fa(s,"d MMM yyyy"),Te=s=>{if(!s)return null;const t=new Date(s);return Number.isNaN(t.getTime())?null:t},Ls=(s,t,a)=>{const i=a-t.getTime();let n;return i<0?n=Pe(t):i<6e4?n="just now":n=`${Qt(t,new Date(a))} ago`,{label:s,when:n,iso:t.toISOString(),exact:Pe(t)}},si=(s,t=Date.now())=>{const a=Te(s.updated_at);if(a)return Ls("updated",a,t);const i=Te(s.created_date);return i?Ls("created",i,t):null},ti=s=>{const t=Te(s.created_date),a=Te(s.updated_at);return{created:t?Pe(t):null,updated:a?Pe(a):null}},ai=s=>s==="role"?"Role":s==="specialist"?"Specialist":s,ii=["refresh-hub","retry","sign-in"],ni=({tenantId:s,orgName:t})=>{const{teams:a,isLoading:i,isFetching:n,isError:u,error:m,refetch:E}=tt({tenantId:s}),p=Js(m),v=at(),[L,_]=r.useState(null),[b,h]=r.useState(null),O=r.useRef(new Map),f=r.useRef(null);r.useEffect(()=>{v.isPending||f.current===null||(O.current.get(f.current)?.focus(),f.current=null)},[v.isPending]);const[w,I]=r.useState(!1),[F,T]=r.useState(()=>new Set),g=(o,x)=>T(A=>{const z=new Set(A);return x?z.add(o):z.delete(o),z}),R=(o,x)=>{o.key!=="Escape"||!F.has(x)||(o.target instanceof Element?o.target:null)?.closest('[data-testid="org-team-pull-error"]')||(g(x,!1),o.currentTarget.querySelector("button[aria-expanded]")?.focus(),o.preventDefault())},k=r.useMemo(()=>{if(!Us(v.error))return null;const o=a.find(x=>x.id===L);return Bs({code:v.error.code,message:v.error.message,details:v.error.details},{name:o?.name??"this team",hubAgentId:null,surface:"pull"})},[v.error,L,a]),j=(o,x)=>{switch(o){case"refresh-hub":E();break;case"retry":y(x);break;case"sign-in":I(!0);break}},y=o=>{v.isPending||(f.current=o.id,_(null),h(o.id),v.mutate({teamId:o.id,tenantId:s,name:o.name},{onSettled:()=>h(null),onError:()=>_(o.id)}))};return e.jsxs("section",{className:"mb-6 max-w-4xl rounded-md bg-surface","aria-label":`Teams shared with ${t??"this organization"}`,"data-testid":"org-teams",children:[i&&e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col divide-y divide-hairline","data-testid":"org-teams-loading",children:[e.jsx(We,{}),e.jsx(We,{}),e.jsx(We,{})]}),!i&&u&&e.jsxs(be,{variant:p?"warning":"danger",className:"m-4 w-auto","data-testid":"org-teams-error",children:[e.jsx(pe,{children:p==="plan"?"That organization needs an active Team plan":p==="no_access"?"You do not have access to that organization":"Teams could not be loaded"}),e.jsx(ge,{children:p==="plan"?`Reading an organization's teams is part of the Team plan. An owner of ${t??"this organization"} can activate it in the Radient console, and then its teams will be listed here.`:p==="no_access"?`You are not a member of ${t??"that organization"}, so its teams are not listed here. An owner can invite you again.`:ss("The teams shared with this organization could not be read.",m)}),p!=="no_access"&&e.jsx("div",{className:"mt-2",children:e.jsx(P,{variant:"primary",size:"sm",onClick:()=>void E(),disabled:n,"aria-busy":n,children:n?"Trying…":"Try again"})})]}),!i&&!u&&a.length===0&&e.jsx("p",{className:"p-4 text-body-sm text-ink-muted","data-testid":"org-teams-empty",children:`Teams shared into ${t??"this organization"} appear here for its members.`}),!i&&!u&&a.length>0&&e.jsx("ul",{className:"flex flex-col divide-y divide-hairline",children:a.map(o=>e.jsxs("li",{className:U(rt,"transition-colors duration-fast ease-out-quart hover:bg-elevated first:rounded-t-md last:rounded-b-md"),onKeyDown:x=>R(x,o.id),children:[e.jsx(Hs,{className:"min-w-0",open:F.has(o.id),onOpenChange:x=>g(o.id,x),summaryAlign:"firstLine",triggerClassName:"min-w-0",chevronClassName:"text-ink-dim mt-1",rowClassName:"py-0",summary:e.jsx(ci,{team:o,expanded:F.has(o.id)}),trailing:e.jsx("div",{className:"-mt-1 ml-3 shrink-0 self-start",children:e.jsx(P,{ref:x=>{x?O.current.set(o.id,x):O.current.delete(o.id)},variant:"secondary",size:"sm",onClick:()=>y(o),disabled:v.isPending,"aria-label":`Pull team ${ae(o.name)}`,children:b===o.id?"Pulling…":"Pull"})}),children:e.jsx(oi,{team:o})}),L===o.id&&e.jsxs("div",{className:"mt-1 flex flex-col items-start gap-1 pl-5","data-testid":"org-team-pull-error",children:[e.jsx("output",{className:"text-meta text-danger",children:k?.body??v.error?.message??`"${ae(o.name)}" could not be pulled.`}),k?.actions.filter(x=>ii.includes(x)).map(x=>e.jsx(P,{variant:"primary",size:"sm",onClick:()=>j(x,o),children:Ks[x]},x)),w&&e.jsx("div",{className:"mt-1","data-testid":"org-team-pull-reauth",children:e.jsx(Xs,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:()=>{I(!1),_(null),E()}})})]})]},o.id))})]})},rt="px-4 py-3",ct=()=>e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"mx-1.5",children:"·"}),e.jsx("span",{className:"sr-only",children:", "})]}),li=({team:s})=>{const t=s.manager?.trim(),a=it(s);return e.jsxs("span",{className:"block truncate text-meta",children:[t?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink-dim",children:"Manager:"})," ",e.jsx("span",{className:"text-ink-muted",children:t})]}):null,t?e.jsx(ct,{}):null,s.members.length===0?e.jsx("span",{className:"text-ink-dim",children:"No members"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-ink-dim",children:[a," ",a===1?"member":"members",":"]})," ",e.jsx("span",{className:"text-ink-muted",children:Xe(s)})]})]})},ri=({team:s})=>{const t=s.project?.trim(),a=lt(s),i=si(s),n=[];return t&&n.push({key:"project",node:t}),a&&n.push({key:"author",node:a}),i&&n.push({key:"recency",node:e.jsxs(e.Fragment,{children:[i.label," ",e.jsx(le,{content:i.exact,children:e.jsx("time",{dateTime:i.iso,children:i.when})})]})}),n.length===0?null:e.jsx("span",{className:"block truncate text-ink-dim text-meta",children:n.map((u,m)=>e.jsxs("span",{children:[m>0?e.jsx(ct,{}):null,u.node]},u.key))})},ci=({team:s,expanded:t})=>{const a=Xa(s),i=nt(s);return e.jsxs("span",{className:"flex min-w-0 flex-col",children:[e.jsxs("span",{className:"flex min-w-0 items-baseline",children:[e.jsx("span",{className:"truncate font-medium text-body text-ink",children:ae(s.name)}),i?e.jsxs("span",{className:"ml-2 shrink-0 text-ink-dim text-meta",children:["v",i]}):null]}),a?e.jsxs(e.Fragment,{children:[e.jsx("span",{...Se,"aria-hidden":"true",className:U("mt-1 select-text break-words text-body-sm text-ink-muted",t?"line-clamp-[12] whitespace-pre-line":"line-clamp-2"),children:a}),e.jsx("span",{className:"sr-only",children:ei(a,t)})]}):e.jsx("span",{className:"mt-1 text-body-sm text-ink-dim",children:"No description"}),e.jsxs("span",{className:"mt-1 flex min-w-0 flex-col",children:[e.jsx(li,{team:s}),e.jsx(ri,{team:s})]})]})},oi=({team:s})=>{const t=s.manager?.trim(),a=ti(s),i=[a.created?`Created ${a.created}`:null,a.updated?`Updated ${a.updated}`:null].filter(u=>u!==null),n=!!t||s.members.length>0;return e.jsxs("div",{className:"mt-1 flex flex-col gap-2",children:[n||i.length===0?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-ink-dim text-meta",children:"Members"}),e.jsxs("ul",{className:"flex flex-col gap-0.5",children:[t?e.jsxs("li",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:t}),e.jsx("span",{className:"text-ink-dim text-meta",children:"Manager"})]}):null,s.members.map(u=>e.jsxs("li",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:u.role}),e.jsx("span",{className:"text-ink-dim text-meta",children:ai(u.kind)}),u.count>1?e.jsxs("span",{className:"text-ink-dim text-meta tabular-nums",children:["×",u.count]}):null]},`${u.kind}:${u.role}`)),n?null:e.jsx("li",{className:"text-ink-dim text-meta",children:"No members"})]})]}):null,i.length>0?e.jsx("p",{className:"text-ink-dim text-meta",children:i.join(" · ")}):null]})},We=()=>e.jsxs("div",{className:U(rt,"pl-9"),"data-testid":"org-team-skeleton-row",children:[e.jsx("div",{className:"flex h-[1lh] items-center text-body",children:e.jsx(C,{className:"h-4.5 w-40"})}),e.jsxs("div",{className:"mt-1 flex h-[2lh] flex-col justify-evenly text-body-sm",children:[e.jsx(C,{className:"h-3.5 w-full"}),e.jsx(C,{className:"h-3.5 w-2/3"})]}),e.jsx("div",{className:"mt-1 flex h-[1lh] items-center text-meta",children:e.jsx(C,{className:"h-3 w-64"})}),e.jsx("div",{className:"flex h-[1lh] items-center text-meta",children:e.jsx(C,{className:"h-3 w-48"})})]}),ot=(s,t)=>t instanceof Ys?t.message:ss(s,t),di=["refresh-hub","retry","sign-in"],ui=({signedIn:s,onOpenSettings:t})=>{const[a,i]=r.useState(1),[n,u]=r.useState(""),{teams:m,isLoading:E,isFetching:p,isError:v,error:L,refetch:_,pagination:b}=Zs({page:a,perPage:ls}),h=at(),[O,f]=r.useState(null),[w,I]=r.useState(null),F=r.useRef(new Map),T=r.useRef(null);r.useEffect(()=>{h.isPending||T.current===null||(F.current.get(T.current)?.focus(),T.current=null)},[h.isPending]);const g=Vt(n.trim()),R=r.useMemo(()=>g?m.filter(N=>ae(N.name).toLowerCase().includes(g)||(N.description??"").toLowerCase().includes(g)):m,[m,g]),k=N=>{h.isPending||(f(null),I(N.id),T.current=N.id,h.mutate({teamId:N.id,name:N.name},{onSettled:()=>I(null),onError:()=>f(N.id)}))},j=r.useMemo(()=>{if(!Us(h.error))return null;const N=m.find(D=>D.id===O);return Bs({code:h.error.code,message:h.error.message,details:h.error.details},{name:N?.name??"this team",hubAgentId:null,surface:"pull"})},[h.error,O,m]),y=j?.body??(vt(h.error)==="unauthorized"?"The team could not be pulled: this machine has no Radient sign-in for the hub. Sign in on the settings page, then pull again.":"The team could not be pulled."),[o,x]=r.useState(!1),A=(N,D)=>{switch(N){case"refresh-hub":_();break;case"retry":k(D);break;case"sign-in":x(!0);break}},z=E&&m.length===0,H=b?.totalRecords??m.length,M=r.useRef(null),q=N=>{const D=n!=="";u(N),D&&N===""&&M.current?.focus()};return e.jsxs("section",{"aria-label":"Public teams",className:"flex flex-col","data-testid":"agent-hub-public-teams",children:[e.jsx("h2",{className:"sr-only",children:"Public teams"}),e.jsx("p",{className:"mb-3 max-w-3xl text-body-sm text-ink-muted",children:"Public teams are published to the hub by anyone and can be read here without signing in. Pulling one copies it into this machine's local team registry."}),s?null:e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2","data-testid":"agent-hub-public-teams-signed-out",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:"Sign in to Radient to pull a team into this machine."}),e.jsx(P,{variant:"secondary",size:"sm",onClick:t,children:"Open settings to sign in"})]}),e.jsx("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:e.jsxs("div",{className:U("flex min-w-56 max-w-md flex-1 items-center rounded-sm border border-control bg-surface","transition-colors duration-fast ease-out-quart","has-[:focus-visible]:outline-solid has-[:focus-visible]:outline-2","has-[:focus-visible]:outline-accent has-[:focus-visible]:outline-offset-2"),children:[e.jsx(qs,{"aria-hidden":"true",className:"ml-2 shrink-0 text-ink-dim"}),e.jsx(Ie,{ref:M,type:"search",value:n,onChange:N=>q(N.target.value),placeholder:"Search teams","aria-label":"Search teams",className:"h-8 min-w-0 flex-1 border-0 bg-transparent outline-none","data-testid":"agent-hub-public-teams-search"})]})}),z&&e.jsxs("div",{"aria-hidden":"true",className:"flex max-w-4xl flex-col gap-3","data-testid":"agent-hub-public-teams-loading",children:[e.jsx(Ye,{}),e.jsx(Ye,{}),e.jsx(Ye,{})]}),!z&&v&&e.jsxs(be,{variant:"danger",className:"w-auto max-w-2xl","data-testid":"agent-hub-public-teams-error",children:[e.jsx(pe,{children:"Public teams could not be loaded"}),e.jsx(ge,{children:ot("The public team catalogue could not be read.",L)}),e.jsx("div",{className:"mt-2",children:e.jsx(P,{variant:"primary",size:"sm",onClick:()=>void _(),disabled:p,"aria-busy":p,children:p?"Trying…":"Try again"})})]}),!z&&!v&&m.length===0&&e.jsx("p",{className:"max-w-2xl text-body-sm text-ink-muted","data-testid":"agent-hub-public-teams-empty",children:"No teams have been published to the public hub yet."}),!z&&!v&&m.length>0&&e.jsxs(e.Fragment,{children:[!g||R.length>0?e.jsxs("p",{className:"mb-3 text-meta text-ink-dim","data-testid":"agent-hub-public-teams-status",children:[g?`${R.length} of ${m.length} teams on this page match "${n.trim()}"`:`${H} ${H===1?"team":"teams"} in the public hub`,g?e.jsxs("span",{className:"text-ink-dim",children:[" ","· search covers the teams loaded here"]}):null]}):null,R.length===0?e.jsx("p",{className:"max-w-2xl text-body-sm text-ink-muted","data-testid":"agent-hub-public-teams-search-miss",children:`No team on this page matches "${n.trim()}".`}):e.jsx("ul",{className:"flex max-w-4xl flex-col gap-3",children:R.map(N=>e.jsx(mi,{team:N,pulling:w===N.id,pullPending:h.isPending,onPull:k,pullButtonRef:D=>{D?F.current.set(N.id,D):F.current.delete(N.id)},failed:O===N.id,failureBody:y,treatment:j,onTreatmentAction:A,reauthenticating:o,onReauthenticated:()=>{x(!1),f(null),_()}},N.id))}),!g&&b&&b.totalPages>1&&e.jsx(is,{count:b.totalPages,page:b.page,onChange:N=>{i(N),M.current?.scrollIntoView({block:"nearest"})}})]})]})},mi=({team:s,pulling:t,pullPending:a,onPull:i,failed:n,failureBody:u,treatment:m,onTreatmentAction:E,reauthenticating:p,onReauthenticated:v,pullButtonRef:L})=>{const[_,b]=r.useState(!1),h=Oa({teamId:_?s.id:void 0}),O=ae(s.name),f=nt(s),w=lt(s),I=s.manager?.trim(),F=it(s),T=(s.description??"").trim();return e.jsxs("li",{className:"rounded-md bg-surface p-4","data-testid":"agent-hub-public-team","data-team-name":s.name,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline",children:[e.jsx("h3",{className:"truncate font-medium text-heading text-ink",children:O}),f?e.jsxs("span",{className:"ml-2 shrink-0 text-ink-dim text-meta",children:["v",f]}):null]}),T?e.jsx("p",{...Se,className:"mt-1 line-clamp-3 max-w-3xl select-text text-body-sm text-ink-muted",children:T}):e.jsx("p",{className:"mt-1 text-body-sm text-ink-dim",children:"No description"}),e.jsxs("p",{className:"mt-2 flex flex-wrap items-baseline gap-x-2 text-meta",children:[I?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-ink-dim",children:"Manager:"}),e.jsx("span",{className:"text-ink-muted",children:I})]}):null,s.members.length===0?e.jsx("span",{className:"text-ink-dim",children:"No members"}):e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-ink-dim",children:[F," ",F===1?"member":"members",":"]}),e.jsx(le,{content:Xe(s),children:e.jsx("span",{className:"truncate text-ink-muted",children:Xe(s)})})]})]}),w?e.jsxs("p",{className:"mt-1 text-ink-dim text-meta",children:["Published by ",e.jsx("span",{className:"text-ink-muted",children:w})]}):null]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-2",children:[e.jsx(P,{ref:L,variant:"secondary",size:"sm",onClick:()=>i(s),disabled:a,"aria-label":`Pull team ${O}`,children:t?"Pulling…":"Pull"}),n&&e.jsxs("div",{className:"flex max-w-56 flex-col items-end gap-1","data-testid":"agent-hub-public-team-pull-error",children:[e.jsx("output",{className:"text-right text-meta text-danger",children:u}),m?.actions.filter(g=>di.includes(g)).map(g=>e.jsx(P,{variant:"primary",size:"sm",onClick:()=>E(g,s),children:Ks[g]},g)),p&&e.jsx("div",{"data-testid":"agent-hub-public-team-pull-reauth",children:e.jsx(Xs,{titleText:"Sign in again",descriptionText:"",onSignInSuccess:v})})]})]})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Hs,{summary:"Brief",open:_,onOpenChange:b,className:"w-full",triggerClassName:"w-full",triggerLabel:`View the brief for ${O}`,chevronClassName:"text-ink-dim",children:e.jsx(hi,{detail:h})})})]})},hi=({detail:s})=>{if(s.isLoading)return e.jsxs("div",{className:"flex flex-col gap-1","data-testid":"agent-hub-public-team-brief-loading",children:[e.jsx(C,{className:"h-[1lh] w-2/3"}),e.jsx(C,{className:"h-[2lh] w-full"})]});if(s.isError)return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("output",{className:"text-meta text-danger",children:ot("This team's brief could not be read.",s.error)}),e.jsx(P,{variant:"primary",size:"sm",onClick:()=>void s.refetch(),disabled:s.isFetching,"aria-busy":s.isFetching,children:s.isFetching?"Trying…":"Try again"})]});const t=s.team;if(!t)return null;const a=(t.instructions??"").trim(),i=(t.project??"").trim();return e.jsxs("div",{className:"flex max-w-3xl flex-col gap-3 text-body-sm","data-testid":"agent-hub-public-team-brief",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-ink-dim text-meta",children:"Collaboration brief"}),a?e.jsx("p",{...Se,className:"whitespace-pre-line select-text text-ink-muted",children:a}):e.jsx("p",{className:"text-ink-dim",children:"This team has no collaboration brief."})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-ink-dim text-meta",children:"Project brief"}),i?e.jsx("p",{...Se,className:"whitespace-pre-line select-text text-ink-muted",children:i}):e.jsx("p",{className:"text-ink-dim",children:"This team has no project brief."})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("p",{className:"text-ink-dim text-meta",children:"Roster"}),e.jsxs("ul",{className:"flex flex-col gap-0.5",children:[t.manager?.trim()?e.jsxs("li",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:t.manager.trim()}),e.jsx("span",{className:"text-ink-dim text-meta",children:"Manager"})]}):null,t.members.length===0?e.jsx("li",{className:"text-ink-dim",children:"No members"}):t.members.map(n=>e.jsxs("li",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:n.count>1?`${n.role} ×${n.count}`:n.role}),e.jsx("span",{className:"text-ink-dim text-meta",children:n.kind})]},`${n.kind}:${n.role}`))]})]})]})},Ye=()=>e.jsxs("div",{className:"rounded-md bg-surface p-4",children:[e.jsx(C,{className:"h-[1lh] w-1/3"}),e.jsx(C,{className:"mt-1 flex h-[3lh] w-full"}),e.jsx(C,{className:"mt-2 h-[1lh] w-2/3"})]}),xi=(s,t)=>{const[a,i]=r.useState(s);return r.useEffect(()=>{const n=setTimeout(()=>i(s),t);return()=>clearTimeout(n)},[s,t]),a},we=[{value:"download_count:desc",label:"Most downloaded",sort:"download_count",order:"desc"},{value:"like_count:desc",label:"Most liked",sort:"like_count",order:"desc"},{value:"favourite_count:desc",label:"Most favourited",sort:"favourite_count",order:"desc"},{value:"created_at:desc",label:"Newest",sort:"created_at",order:"desc"},{value:"updated_at:desc",label:"Recently updated",sort:"updated_at",order:"desc"},{value:"name:asc",label:"Name (A to Z)",sort:"name",order:"asc"}],bi=[{value:"name",label:"Name"},{value:"description",label:"Description"}],pi=300,K="public",Fs={agents:"agent-hub-view-agents",teams:"agent-hub-view-teams",skills:"agent-hub-view-skills"},$s="agent-hub-view-panel",gi=()=>e.jsxs("div",{className:"flex h-full flex-col overflow-hidden rounded-md bg-surface",children:[e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-2 p-4",children:[e.jsx(C,{className:"h-5.5 w-2/3"}),e.jsx(C,{className:"h-3.5 w-full"}),e.jsx(C,{className:"h-3.5 w-full"}),e.jsx(C,{className:"h-3.5 w-1/2"}),e.jsxs("div",{className:"mt-auto flex flex-col gap-2 pt-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(C,{className:"h-5.5 w-24"}),e.jsx(C,{className:"h-5.5 w-20"})]}),e.jsx("div",{className:"flex items-center gap-1.5",children:e.jsx(C,{className:"h-5.5 w-24"})})]}),e.jsx(C,{className:"h-4.5 w-32"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 border-t border-hairline px-3 py-2",children:[e.jsx(C,{className:"size-4"}),e.jsx(C,{className:"h-4 w-6"}),e.jsx(C,{className:"size-4"}),e.jsx(C,{className:"h-4 w-6"}),e.jsx(C,{className:"ml-auto h-7 w-16"})]})]}),Fi=()=>{const s=zs(),{isAuthenticated:t}=ts(),[a,i]=r.useState(1),[n]=r.useState(12),[u,m]=r.useState(null),[E,p]=r.useState(""),[v,L]=r.useState("name"),[_,b]=r.useState(we[0].value),[h,O]=r.useState(K),[f,w]=r.useState("agents");ke();const[I,F]=r.useState([]),T=xi(E,pi),g=we.find(c=>c.value===_)??we[0],R=Ce(),k=!R.isError&&re(R.data,"hub_skills"),j=f==="skills"&&!k?"agents":f;r.useEffect(()=>{f==="skills"&&!k&&w("agents")},[f,k]);const y=Lt(),o=Nt(R.data,"radient_org"),x=t?ka(o,y??null):null,{memberships:A}=ua({enabled:Ve(o)}),z=r.useMemo(()=>ga(A),[A]),H=h===K||z.some(c=>c.tenant_id===h);r.useEffect(()=>{!H&&j!=="skills"&&O(K)},[H,j]);const M=h===K?null:z.find(c=>c.tenant_id===h)??null,q=M?.tenant_id,N=M?.tenant_name||null,D=u!==null||T!=="",se=tt({tenantId:q}),te=Zs({page:1,perPage:ls,enabled:h===K}),de=q&&se.isSuccess?se.teams.length:null,ye=te.isSuccess?te.pagination?.totalRecords??null:null,Q=D?null:h===K?ye:de,S=h===K?{visibility:"public",tenantId:null}:{visibility:"org",tenantId:h},ve=H&&(h===K||Ve(o)),ue=et(S,1,k&&ve&&(h===K||t)),ee=ue.isSuccess?ue.data.total:null,Ae=M?.role==="owner"||M?.role==="admin",me=r.useMemo(()=>new Map(A.map(c=>[c.tenant_id,c.tenant_name])),[A]),{data:ne,agents:Oe,isLoading:Ee,isFetching:V,error:J,refetch:he,pagination:B}=zt({page:a,perPage:n,categories:u?[u]:void 0,name:v==="name"&&T||void 0,description:v==="description"&&T||void 0,sort:g.sort,order:g.order,tenantId:q}),d=M?Js(J):null,$=Oe??[],X=V&&ne!==void 0,{statuses:xe,isKnown:Ne,isError:dt,isFetching:Le,refetch:ut}=Wt({agentIds:q?[]:$.map(c=>c.id)}),Fe=r.useRef(null),$e=r.useRef(null),[os,mt]=r.useState(0);r.useEffect(()=>{os!==0&&(Fe.current??$e.current)?.focus()},[os]);const ds=r.useRef(null),ze=r.useRef(!1),Me=r.useMemo(()=>[...new Set((ne?.records??[]).flatMap(c=>c.categories??[]))],[ne]);r.useEffect(()=>{F(c=>Me.every(Y=>c.includes(Y))?c:[...new Set([...c,...Me])])},[Me]);const ht=()=>{m(null),p(""),i(1),mt(c=>c+1)},W=(Ee||V)&&ne===void 0,us=!W&&!D&&(J!==null||$.length===0);r.useEffect(()=>{!ze.current||W||(ze.current=!1,J?ds.current?.focus():(Fe.current??$e.current)?.focus())},[W,J]);const ms=r.useRef(null),xt=c=>{i(c),ms.current?.scrollIntoView({block:"nearest"})},bt=c=>{m(c),i(1)},pt=c=>{p(c),i(1)},gt=c=>{O(c),i(1)},hs=r.useRef(new Map),ft=c=>{L(c),i(1)},kt=B&&!D?B.totalRecords:null,De=q?`shared with ${N??"this organization"}`:"in the public hub",xs=(c,Y)=>`${c} ${Y}${c===1?"":"s"} ${De}`;let Z;return j==="skills"?Z=" ":j==="teams"?q?se.isLoading?Z="Loading teams…":Q!==null?Z=xs(Q,"team"):Z=`Teams ${De}`:Z=" ":W?Z="Loading agents…":B?Z=xs(B.totalRecords,"agent"):Z=`Agents ${De}`,e.jsxs("div",{className:"flex h-full flex-col gap-8 p-6",children:[e.jsx(wt,{title:"Agent Hub",subtitle:"Discover and download agents, teams and skills on Radient",icon:ma}),e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-4",children:[x&&e.jsxs(be,{variant:"warning",className:"max-w-2xl","data-testid":"agent-hub-org-unavailable",children:[e.jsx(pe,{children:"Organizations are unavailable"}),e.jsx(ge,{children:x})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2","data-testid":"agent-hub-browse-bar",children:[e.jsx(Pt,{value:j,onValueChange:c=>w(c),children:e.jsx(Tt,{"aria-label":"Browse the hub by type",children:["agents","teams",...k?["skills"]:[]].map(c=>{const Y=c==="agents"?kt:c==="teams"?Q:ee;return e.jsxs(Ct,{value:c,id:Fs[c],"aria-controls":j===c?$s:void 0,"data-testid":`agent-hub-view-${c}`,children:[c==="agents"?"Agents":c==="teams"?"Teams":l("ui.hub.skills.title"),Y!==null&&e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:Y})]},c)})})}),z.length>0&&e.jsxs("div",{className:"ml-auto flex min-w-0 items-center gap-2",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","data-testid":"agent-hub-scope",children:[e.jsx("legend",{className:"sr-only",children:"Show the hub of"}),e.jsx("div",{className:"flex flex-wrap gap-0.5 rounded-md bg-sunken p-0.5",children:[{value:K,label:"Public hub",Icon:Ft},...z.map(c=>({value:c.tenant_id,label:c.tenant_name||"Organization",Icon:ja}))].map(({value:c,label:Y,Icon:jt})=>e.jsxs(P,{ref:bs=>{bs?hs.current.set(c,bs):hs.current.delete(c)},variant:"ghost",size:"sm","aria-pressed":h===c,onClick:()=>gt(c),title:Y,"data-testid":`agent-hub-scope-${c===K?"public":`org-${c}`}`,className:U("max-w-48",h===c&&"bg-surface text-ink hover:bg-surface"),children:[e.jsx(jt,{"aria-hidden":"true"}),e.jsx("span",{className:"truncate",children:Y})]},c))})]})]})]}),e.jsx(It,{id:$s,labelledBy:Fs[j],children:e.jsxs("div",{className:"flex min-h-0 flex-1 flex-row overflow-hidden",children:[j==="agents"&&e.jsx(e.Fragment,{children:e.jsx("div",{className:"mr-6 hidden w-60 shrink-0 rounded-md bg-surface p-2 md:block","data-glass-region":"panel","data-tour-tag":"agent-hub-sidebar-container",children:!us&&e.jsx(_a,{selectedCategory:u,onSelectCategory:bt,categories:I})})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col overflow-y-auto",children:[j==="agents"&&!us&&e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:U("flex min-w-56 flex-1 items-center rounded-sm border border-control bg-surface","transition-colors duration-fast ease-out-quart","has-[:focus-visible]:outline-solid has-[:focus-visible]:outline-2","has-[:focus-visible]:outline-accent has-[:focus-visible]:outline-offset-2"),children:[e.jsx(Ie,{ref:Fe,type:"search",value:E,onChange:c=>pt(c.target.value),placeholder:"Search agents","aria-label":"Search agents",className:"h-8 min-w-0 flex-1 border-0 bg-transparent outline-none","data-testid":"agent-hub-search"}),e.jsxs(gs,{value:v,onValueChange:ft,children:[e.jsx(fs,{className:"w-auto shrink-0 border-y-0 border-l border-hairline border-r-0 bg-transparent pl-2 outline-none","aria-label":"Search in","data-testid":"agent-hub-search-scope",children:e.jsx(ks,{})}),e.jsx(js,{children:bi.map(c=>e.jsx(ys,{value:c.value,children:c.label},c.value))})]})]}),e.jsxs(gs,{value:_,onValueChange:b,children:[e.jsx(fs,{className:"w-48","aria-label":"Sort agents","data-testid":"agent-hub-sort",children:e.jsx(ks,{})}),e.jsx(js,{children:we.map(c=>e.jsx(ys,{value:c.value,children:c.label},c.value))})]})]}),e.jsxs("p",{ref:ms,"aria-live":"polite",className:"mb-3 text-meta text-ink-dim","data-testid":"agent-hub-status",children:[Z,j==="agents"&&X?e.jsxs(e.Fragment,{children:[" ",e.jsx("span",{"data-testid":"agent-hub-updating",children:"Updating…"})]}):null]}),j==="agents"&&e.jsxs(e.Fragment,{children:[t&&dt&&e.jsxs("output",{className:"mb-3 flex flex-wrap items-center gap-2 text-meta text-warning","data-testid":"agent-hub-status-unknown",children:[e.jsx("span",{children:"Your likes and favourites could not be read, so no card shows a viewer state."}),e.jsx(P,{variant:"ghost",size:"sm",onClick:()=>void ut(),disabled:Le,"aria-busy":Le,children:Le?"Trying…":"Try again"})]}),W&&e.jsx("div",{"data-testid":"agent-hub-loading",className:"grid grid-cols-[repeat(auto-fill,minmax(17.5rem,1fr))] gap-6",children:Array.from({length:6},(c,Y)=>e.jsx(gi,{},Y))}),W&&B===void 0&&e.jsx("div",{"aria-hidden":"true",className:"mt-6 flex min-h-13 items-center justify-center","data-testid":"agent-hub-pager-placeholder",children:e.jsx(C,{className:"h-4 w-24"})}),e.jsx("output",{"aria-live":"polite","data-testid":"agent-hub-outage",className:U(!W&&J&&!d?"block":"sr-only"),children:!W&&J&&!d&&e.jsxs(be,{variant:"danger",className:"max-w-2xl","aria-busy":V,"data-testid":"agent-hub-error",children:[e.jsx(pe,{children:t?"The hub could not be loaded":"Sign in to use the hub"}),e.jsx(ge,{children:t?ss("The agent list could not be loaded.",J):"You are not signed in to Radient, so the hub has no credential to read the agent list with. Sign in on the settings page, then try again."}),e.jsx("div",{className:"mt-2",children:e.jsx(P,{ref:ds,variant:"outline",size:"sm",onClick:()=>{ze.current=!0,he()},disabled:V,"aria-busy":V,children:V?"Trying…":"Try again"})})]})}),!W&&d&&M&&e.jsxs(be,{variant:"warning",className:"max-w-2xl","data-testid":"agent-hub-org-no-access",children:[e.jsx(pe,{children:d==="plan"?"That organization needs an active Team plan":"You do not have access to that organization"}),e.jsx(ge,{children:d==="plan"?`Sharing agents inside an organization is part of the Team plan. An owner of ${M.tenant_name||"this organization"} can activate it in the Radient console, and then its agents will be listed here.`:`You are not a member of ${M.tenant_name||"that organization"}, so its agents are not listed here. An owner can invite you again.`}),d==="plan"&&e.jsx("div",{className:"mt-2",children:e.jsx(P,{variant:"primary",size:"sm",onClick:()=>void he(),disabled:V,"aria-busy":V,children:V?"Trying…":"Try again"})})]}),!W&&!J&&e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(17.5rem,1fr))] gap-6","aria-busy":X,children:$.length===0?e.jsxs("div",{"data-testid":"agent-hub-empty",className:U("col-span-full w-full flex flex-col items-center gap-2 rounded-md bg-surface px-6 py-10 text-center",!q&&"max-w-2xl justify-self-center"),children:[e.jsx("p",{className:"text-heading text-ink",children:q?"This organization has no shared agents yet.":u?`No agents in ${Qs(u).label}.`:D?"No agents match that search.":"The hub is empty."}),e.jsx("p",{className:"max-w-md text-body-sm text-ink-muted",children:q?`Agents published into ${M?.tenant_name||"this organization"} appear here for its members.`:u?"Nothing in this category yet. Clear the filter to see the whole hub.":D?"No agent's name or description carries that. Clear it to see the whole hub.":"Nobody has published an agent yet. Yours could be the first."}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center justify-center gap-2",children:D?e.jsx(P,{variant:"secondary",onClick:ht,children:u?"Clear filter":"Clear search"}):q&&!Ae?null:e.jsx(P,{ref:$e,variant:"secondary",onClick:()=>s("/agents"),children:"Publish an agent"})})]}):$.map(c=>e.jsx(wa,{agent:c,status:t?xe[c.id]:void 0,viewerStateKnown:t&&Yt(Ne,xe,c.id),orgName:c.visibility==="org"?me.get(c.tenant_id)??null:null},c.id))}),!W&&B&&B.totalPages>1&&e.jsx(is,{count:B.totalPages,page:B.page,onChange:xt})]}),j==="skills"&&(k?e.jsx(Wa,{scope:h===K?{visibility:"public",tenantId:null,organization:null}:{visibility:"org",tenantId:h,organization:N},signedIn:t,accessible:H&&(h===K||Ve(o))},`skills:${h}`):e.jsx("p",{className:"text-body-sm text-warning",children:l("ui.hub.skills.unavailable")})),j==="teams"&&(M?e.jsx(ni,{tenantId:M.tenant_id,orgName:N}):e.jsx(ui,{signedIn:t,onOpenSettings:()=>s("/settings")}))]})]})})]})]})};export{Fi as AgentHubPage};
@@ -1,7 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./legacy-agents-page-oa1T18xF.js","./index-B4nU7SY-.js","./messages-Bsgf6o-p.js","./index-CJBIsxq7.css","./page-header-CSOT2M6K.js","./error-boundary-Bq37z0Vv.js","./index-C1xioNnx.js","./path-utils-Dy8qomEz.js","./conversation-input-sync-BNDyyAZz.js","./conversation-input-sync-CAX4_ErH.css","./console-mirror-BiNs1Fcs.js","./console-mirror-DOrYoP_4.css","./index-DHKnfVbX.css","./notebook-pen-BYY7185A.js","./org-access-M6CGnpV0.js","./org-surface-gate-BwyP7jwt.js","./radient-auth-buttons-OK28kSbr.js","./publication-validation-DaTmgJDa.js"])))=>i.map(i=>d[i]);
2
- import{aZ as xs,ag as bs,a_ as Ie,a$ as Pt,b0 as it,b1 as js,b2 as gt,ar as ke,a7 as vs,a8 as ys,a9 as ks,aa as Ns,aA as ws,ax as rt,T as Me,ap as Bt,b3 as Ut,a4 as _s,b4 as Ss,aq as Cs,b5 as Es,b6 as qt,b7 as Is,b8 as As,b9 as pt,ba as Rs,bb as Ts,bc as Ds,bd as $s}from"./conversation-input-sync-BNDyyAZz.js";import{r as i,j as e,c as K}from"./index-B4nU7SY-.js";import{ax as Ls,ay as Os,az as zt,x as Ht,aA as Fs,aB as lt,aC as Ms,aD as et,aE as tt,aF as Ps,aG as Bs,aH as xt,aI as Kt,aJ as Us,aK as qs,aL as Wt,aM as zs,aN as Hs,y as Ks,aO as Vt,A as Ws}from"./index-C1xioNnx.js";import{y as Pe,q as ot,a as ze,c as ee,h as Gt,$ as Vs,a0 as Gs,u as ct,a1 as Js,d as X,g as Ke,D as Be,A as dt,a2 as Ys,B as Qs}from"./path-utils-Dy8qomEz.js";import{c as Zs,B as E,x as Xs,y as en,k as ve,z as oe,A as ce,m as de,n as me,I as Ne,F as $e,G as Le,H as Oe,J as Fe,K as xe,M as He,N as Ue,q as tn,r as sn,s as nn,w as an,T as st,u as Te,D as Jt,a as Yt,b as Qt,d as Zt,e as Xt,C as rn,f as es,O as ln,P as We,Q as Ve,R as be,U as ue,V as Ge,W as le,Y as on,Z as cn,_ as bt}from"./error-boundary-Bq37z0Vv.js";import{t as r,a as dn}from"./messages-Bsgf6o-p.js";import{u as ts,n as Je,H as un,p as mn,a as hn}from"./org-access-M6CGnpV0.js";import"./console-mirror-BiNs1Fcs.js";/**
3
- * @license lucide-react v0.507.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */const fn=[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]],gn=Zs("log-in",fn),pn=[],Ee="config-composer-note",jt="Configure agents by conversation",xn=["A reviewer that only reads code","Add the coder twice to release-crew","A team called shipping with a manager and two coders"],bn={idle:"bg-ink-dim",running:"bg-accent",stopping:"bg-warning",done:"bg-success",stopped:"bg-ink-muted",error:"bg-danger"};function jn({status:t,pulse:s}){return e.jsx("span",{"aria-hidden":"true",className:K("size-2 shrink-0 rounded-full",bn[t]??"bg-ink-dim",s&&"animate-pulse")})}function vn({run:t}){return t.activity.length===0?e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing to show yet — the run has not called a tool."}):e.jsx("ul",{className:"space-y-1",children:t.activity.map((s,n)=>e.jsxs("li",{className:"flex items-baseline gap-2 text-body-sm",children:[e.jsx("span",{className:"text-ink-dim tabular-nums",children:new Date(s.ts).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}),e.jsx("span",{className:"text-ink",children:s.verb})]},`${s.ts}:${s.verb}:${n}`))})}const vt="-mr-2",yn="max-h-[clamp(3.5rem,10vh,5.5rem)]";function kn(){const t=i.useRef(null),[s,n]=i.useState(!1);return i.useEffect(()=>{const a=t.current;if(!a)return;const l=()=>n(a.scrollHeight>a.clientHeight+1);l();const u=new ResizeObserver(l);return u.observe(a),()=>u.disconnect()}),{ref:t,overflowing:s}}function Nn({children:t}){const{ref:s,overflowing:n}=kn();return e.jsx("div",{ref:s,tabIndex:n?0:void 0,role:n?"region":void 0,"aria-label":n?"Run details":void 0,"data-lo-region-cue":n?"":void 0,className:K("mb-2 overflow-y-auto empty:hidden",yn),children:t})}const wn="mb-1 flex min-h-7 items-center gap-3",yt=t=>t===1?"1 definition":`${t} definitions`;function _n({run:t,about:s,blockedReason:n,hasDraft:a,onClearAbout:l,onDismiss:u}){const[g,h]=i.useState(!1),v=i.useRef(null),p=t.status==="running"||t.status==="stopping",d=t.enabled&&t.status!=="idle",m=!!n&&a&&!d,S=!!n&&a&&d&&!p;i.useEffect(()=>{if(!p)return;const j=k=>{k.key!=="Escape"||k.defaultPrevented||document.querySelector('[role="alertdialog"], [role="dialog"]')||v.current?.focus()};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[p]);const x=t.status==="running"?t.step??"Working on your request":t.status==="stopping"?"Stopping":t.status==="done"?t.results.length>0?"Finished":"Finished without changing anything":t.status==="stopped"?"Stopped":t.status==="error"?t.canRetry?"Stopped with an error":"Finished with an error":"";return e.jsxs("div",{className:Ie,"data-testid":d?"config-run-strip":void 0,children:[e.jsxs("div",{className:wn,children:[d?e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[e.jsx(jn,{status:t.status,pulse:p}),e.jsxs("span",{"aria-live":"polite",className:"min-w-0 truncate text-body-sm text-ink",children:[x,t.status==="done"&&t.touched.length>0?e.jsx("span",{className:"sr-only",children:`. Configured ${yt(t.touched.length)}`}):null]}),(p||t.status==="stopped"||t.status==="done")&&t.elapsed!=="0s"?e.jsx("span",{className:"shrink-0 text-meta text-ink-muted tabular-nums",children:t.elapsed}):null,t.touched.length>0?e.jsxs("span",{"aria-hidden":t.status==="done"?!0:void 0,className:"shrink-0 text-meta text-ink-muted",children:[e.jsx("span",{className:"sr-only",children:"Configured "}),yt(t.touched.length)]}):null]}):null,t.enabled&&!S?e.jsxs(e.Fragment,{children:[m?null:e.jsx("span",{id:n?void 0:Ee,"data-testid":n?void 0:"config-composer-note",className:d?"sr-only":"min-w-0 flex-1 truncate text-meta text-ink-dim",children:"Runs in the background. This does not appear in your conversation."}),n?e.jsx("span",{id:Ee,"data-testid":"config-composer-note",className:m?"min-w-0 flex-1 truncate text-meta text-ink-dim":"sr-only",children:n}):null]}):e.jsx("span",{className:"flex-1","aria-hidden":"true"}),e.jsxs("div",{className:"ms-auto flex shrink-0 items-center gap-1",children:[s?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"data-testid":"config-composer-about",title:`About ${s.kind} ${s.name}`,className:"max-w-56 truncate text-meta text-ink-muted",children:["About ",s.kind," ",s.name]}),e.jsx(E,{variant:"ghost",size:"sm",className:d?void 0:vt,onClick:l,children:"Clear"})]}):null,d&&t.activity.length>0?e.jsxs(E,{variant:"ghost",size:"sm","aria-expanded":g,onClick:()=>h(j=>!j),children:[g?e.jsx(Xs,{className:"size-3.5"}):e.jsx(en,{className:"size-3.5 rtl:-scale-x-100"}),"Watch"]}):null,d?p?e.jsxs(E,{ref:v,variant:"secondary",size:"sm",disabled:t.status==="stopping",onClick:()=>void t.stop(),children:[e.jsx(js,{className:"size-3.5"}),t.status==="stopping"?"Stopping…":"Stop"]}):e.jsx(E,{variant:"ghost",size:"sm",className:vt,onClick:u,children:"Dismiss"}):null]})]}),t.enabled?null:e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-dim",children:t.disabledReason}),S?e.jsx("p",{id:Ee,"data-testid":"config-composer-note",className:"mb-2 text-meta text-ink-muted",children:n}):null,d?e.jsxs(Nn,{children:[t.attached?e.jsx("p",{className:"mt-1 text-meta text-ink-muted",children:"Another configuration run was already going, so this page attached to it. Your request was not sent — it is still in the box."}):null,t.stopError?e.jsxs("div",{className:"mt-2 border-danger-border border-t pt-2","data-testid":"config-stop-refused",children:[e.jsx("p",{className:"text-body-sm text-danger",children:"The stop did not take — the run is still going."}),e.jsx("p",{className:"mt-0.5 text-meta text-ink-muted",children:t.stopError})]}):null,g?e.jsx("div",{className:"mt-2 border-hairline border-t pt-2",children:e.jsx(vn,{run:t})}):null,t.status==="stopped"?e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink",children:t.results.length>0?"Stopped. Changes it had already made were kept.":"Stopped. Nothing had been changed yet."}),t.results.length>0?e.jsx("ul",{className:"space-y-0.5",children:t.results.map(j=>e.jsxs("li",{className:"text-ink-muted",children:[j.created?"Created ":"Changed ",e.jsx("span",{className:"text-ink",children:j.target.name})]},`${j.target.kind}:${j.target.name}`))}):null]}):null,t.status==="done"?e.jsx(Sn,{run:t}):null,t.status==="error"&&t.error?e.jsx("div",{className:"mt-2 border-danger-border border-t pt-2",children:e.jsx("p",{className:"text-body-sm text-danger",children:t.error})}):null]}):null,d&&t.status==="error"&&t.error?e.jsxs("div",{className:"mb-2.5 flex items-center gap-2",children:[t.canRetry?e.jsx(E,{variant:"secondary",size:"sm","data-testid":"config-retry",disabled:t.starting,onClick:()=>void t.retry(),children:t.starting?"Sending…":"Retry"}):null,e.jsx("p",{className:"text-meta text-ink-muted",children:"Nothing else was changed by this run."})]}):null]})}function Sn({run:t}){return t.results.length===0?e.jsxs("div",{className:"mt-2 border-hairline border-t pt-2 text-body-sm",children:[e.jsx("p",{className:"text-ink-muted",children:"The run answered without changing any agent or team."}),t.answer?e.jsx("p",{className:"mt-1 whitespace-pre-wrap text-ink",children:t.answer}):null,t.topic?e.jsxs("p",{className:"mt-1 text-meta text-ink-muted",children:["You asked: ",t.topic]}):null]}):e.jsxs("div",{className:"mt-2 space-y-1 border-hairline border-t pt-2",children:[e.jsx("ul",{className:"space-y-1 text-body-sm",children:t.results.map(s=>e.jsxs("li",{children:[e.jsxs("span",{className:"text-ink",children:[s.created?"Created ":"Updated ",s.target.name]}),e.jsxs("span",{className:"text-ink-muted",children:[" (",s.target.kind,")"]}),s.changes.length>0?e.jsxs("span",{className:"text-ink-muted",children:[": ",s.changes.map(n=>n.label).join(", ")]}):s.created?null:e.jsx("span",{className:"text-ink-muted",children:": its settings changed. The list does not show instructions, so open it to see what was written."})]},`${s.target.kind}:${s.target.name}`))}),t.answer?e.jsx("p",{className:"whitespace-pre-wrap text-body-sm text-ink-muted",children:t.answer}):null]})}const we="agents-config",Cn=t=>`Change the ${t.kind} ${t.name}: `;function Ye(t,s,n){t.setAbout(s);const a=Pe.getState();a.getCurrentInput(we)||a.setComposerText(we,n)}function En(t){const s=Pe.getState();s.getCurrentInput(we).trim()===Cn(t).trim()&&s.setComposerText(we,"")}function ss({run:t,hero:s=!1,blockedReason:n,about:a,onClearAbout:l}){const u=i.useRef(null),g=xs(),h=ot(A=>A.cwd),v=ze(),p=t.frontend===null&&t.status==="idle"&&h.length>0&&ee(v.data,"draft_preview"),d=Gt({...Vs({cwd:h,model:null},ee(v.data,"draft_fast")),enabled:p}),m=we,S=A=>Pe.getState().setCurrentInput(m,A),x=t.status==="running"||t.status==="stopping",j=!t.enabled||!!n,k=Pe(A=>(A.inputByConversation[we]?.currentInput??"").trim().length>0),T=n||(x?"Working on your request…":t.enabled?void 0:jt),y=a?`Change ${a.name}…`:t.enabled?s?"Describe what you want…":"Ask for a change, or describe something new…":jt,N=a?`${a.kind}:${a.name}`:null;i.useEffect(()=>{N&&u.current?.focusInput()},[N]);const _=()=>{t.dismiss(),u.current?.focusInput()},$=()=>{l(),u.current?.focusInput()};return e.jsxs("div",{"data-testid":"config-composer",children:[e.jsx("div",{className:"sr-only",id:"config-composer-label",children:"Ask for an agent or team change"}),e.jsx(bs,{ref:u,conversationId:m,messages:pn,isLoading:!1,transcriptless:!0,placeholderOverride:y,sessionStatus:t.frontend?{frontend:t.frontend,costChannels:ee(v.data,"cost_channels")}:d.data?{frontend:d.data.snapshot,draft:!0,costChannels:ee(v.data,"cost_channels")}:void 0,recordingProbe:g,hostNotice:{id:Ee,blocksInput:!t.enabled||!!n||x,placeholder:T,statedByNode:k,node:e.jsx(_n,{run:t,about:a,blockedReason:n,hasDraft:k,onClearAbout:$,onDismiss:_})},onSendMessage:(A,f)=>t.start(A,a,f)}),s&&t.enabled?e.jsx("div",{className:K(it,Pt),children:e.jsx("div",{className:K(Ie,"mt-2 flex flex-col items-start gap-0.5",!a&&!x?"":"invisible"),children:xn.map(A=>e.jsx(E,{variant:"ghost",size:"sm",className:"-ml-2 h-auto max-w-full justify-start whitespace-normal break-words px-2 py-1 text-start text-body-sm text-ink-muted hover:bg-elevated hover:text-ink disabled:text-ink-disabled disabled:hover:bg-transparent",disabled:j,onClick:()=>{S(A),u.current?.focusInput()},children:A},A))})}):null]})}const kt=(t,s)=>t.kind===s.kind&&t.name===s.name;function In(t){return`${t.kind}:${t.name}`}const J=Gs(t=>({sessionId:null,status:"idle",topic:"",images:[],files:[],about:null,error:null,stopError:null,unsent:!1,startedAt:null,settledAt:null,touched:[],results:[],answer:"",marks:[],before:null,setAbout:s=>t({about:s}),adopt:(s,n,a,l=[],u=[])=>t({sessionId:s,status:"running",topic:n,images:l,files:u,error:null,stopError:null,startedAt:Date.now(),settledAt:null,touched:[],results:[],answer:"",before:a,unsent:!1}),noteTouched:s=>t(n=>n.touched.some(a=>kt(a,s))?n:{touched:[...n.touched,s]}),stopping:()=>t(s=>s.status==="running"?{status:"stopping",stopError:null}:s),stopFailed:s=>t({status:"running",stopError:s}),settle:(s,n,a)=>t(()=>({status:n,settledAt:Date.now(),results:s,answer:a,marks:s.map(l=>({...l.target,created:l.created})),sessionId:null,images:[],files:[],stopError:null,before:null,unsent:!1})),fail:s=>t({status:"error",error:s,unsent:!1,stopError:null}),failUnsent:s=>t({status:"error",error:s,unsent:!0,stopError:null}),dismiss:()=>t({status:"idle",sessionId:null,error:null,stopError:null,unsent:!1,topic:"",images:[],files:[],touched:[],results:[],answer:"",marks:[],startedAt:null,settledAt:null,before:null}),clearMark:s=>t(n=>({marks:n.marks.filter(a=>!kt(a,s))}))})),An=/Value error,\s*([\s\S]*?)\s*\[type=/,Rn=/^\d+ validation errors? for \S+[\s\S]*?\n\s*/i,Tn=/\s*\[type=[^\]]*\][\s\S]*$/m,Dn=/\s*For further information visit \S+/g,$n=/'([^']+)' already exists/,Ln=/cannot contain spaces or path separators/i,On=/effort tier '([^']+)' is unavailable/i,Fn=/team name must be/i,Mn=/manager '([^']+)'/i,Pn=/(?:member|role) '([^']+)' (?:is not|does not)/i,Bn=/depth|cycle|circular/i,Un=/instructions/i,qn=/description/i;function zn(t){const s=t.match(An);return s?.[1]?s[1].trim():t.replace(Rn,"").replace(Tn,"").replace(Dn,"").trim()}function Ae(t){const s=zn(t),n=s.match($n);if(n)return{message:r("ui.agents.refusals.name_taken",{name:n[1]}),field:"name"};if(Ln.test(s))return{message:r("ui.agents.refusals.name_grammar"),field:"name"};const a=s.match(On);if(a)return{message:r("ui.agents.refusals.effort_unavailable",{tier:a[1]}),field:"effort"};if(s.match(Fn))return{message:r("ui.agents.refusals.team_name_bound"),field:"name"};const u=s.match(Mn);if(u)return{message:r("ui.agents.refusals.missing_manager",{name:u[1]}),field:"manager"};const g=s.match(Pn);return g?{message:r("ui.agents.refusals.missing_member",{name:g[1]}),field:"members"}:Bn.test(s)?{message:r("ui.agents.refusals.team_nesting"),field:"members"}:Un.test(s)?{message:s,field:"instructions"}:qn.test(s)?{message:s,field:"description"}:{message:s,field:null}}function Hn(t,s){const n=new Set(s),a=`${t}-copy`;if(!n.has(a))return a;for(let l=2;l<100;l+=1){const u=`${a}-${l}`;if(!n.has(u))return u}return a}function De(t){return t.action_class==="proactive"?"proactive":"reactive"}const ns={get proactive(){return r("ui.agents.refusals.class.label.proactive")}},Kn={get proactive(){return r("ui.agents.refusals.class.meaning.proactive")},get reactive(){return r("ui.agents.refusals.class.meaning.reactive")}},Wn={get proactive(){return r("ui.agents.refusals.class.effect.proactive")},get reactive(){return r("ui.agents.refusals.class.effect.reactive")}};let as=r("ui.agents.refusals.class.install_disclosure");dn(()=>{as=r("ui.agents.refusals.class.install_disclosure")});function Vn(t,s){const n=[];return t.source==="builtin"&&n.push({op:"profiles.install",name:t.name}),n.push({op:"profiles.update",name:t.name,fields:{action_class:s}}),n}async function Gn(t,s,n,a=()=>crypto.randomUUID()){if(De(t)===s)return null;let l=null;const u=Vn(t,s);for(let g=0;g<u.length;g+=1){const h=u[g];try{l=await n(h,a())}catch(v){throw new is(v,u.slice(0,g))}}return l}class is extends Error{completed;constructor(s,n){super(s instanceof Error?s.message:String(s)),this.name="ClassSwitchError",this.completed=n}}function Jn(t,s){const n=t instanceof Error&&t.message?t.message:r("ui.agents.refusals.class.error.no_reason"),a=Ae(n).message;return s.some(l=>l.op==="profiles.install")?r("ui.agents.refusals.class.error.install_landed",{reason:a}):a}const Yn=new Set(["agent","team"]);function Qn(t){const s=typeof t.args?.op=="string"?t.args.op:null,n=typeof t.args?.name=="string"?t.args.name:null,a=t.toolName==="team"?"team":"agent",l=n?{kind:a,name:n}:null,u=t.phase==="done"&&!t.isError&&!t.notRunReason&&!t.neverSent,g=h=>({writes:h&&u});switch(s){case"create":return{verb:n?`Creating ${a} ${n}`:`Creating a ${a}`,target:l,...g(!0)};case"update":return{verb:n?`Updating ${a} ${n}`:`Updating a ${a}`,target:l,...g(!0)};case"install":return{verb:n?`Installing ${n}`:"Installing an agent",target:l,...g(!0)};case"list":case"search":case"show":return{verb:n?`Reading ${n}`:`Reading ${a}s`,target:l,...g(!1)};default:return{verb:t.phase==="running"?`Working on ${a}s`:`Checked ${a}s`,target:l,...g(!0)}}}const Zn={description:"description",kind:"kind",tools:"tools",effort:"effort tier",delegate:"delegation",action_class:"class",manager:"manager",members:"members",instructions:"instructions"};function Xn(t){return{description:t.description??"",kind:t.kind,tools:t.tools&&t.tools.length>0?[...t.tools].sort().join(","):"*",effort:t.effort??"inherit",delegate:String(!!t.delegate),action_class:De(t)}}function ea(t){return{description:t.description??"",manager:t.manager??"",members:(t.members??[]).map(s=>`${s.kind}:${s.role}x${s.count}`).sort().join(",")}}function Nt(t,s){return{agents:Object.fromEntries((t??[]).map(n=>[n.name,Xn(n)])),teams:Object.fromEntries((s??[]).map(n=>[n.name,ea(n)]))}}function ta(t,s){if(t===s)return"tools";const n=h=>h==="*"?null:new Set(h.split(",")),a=n(t),l=n(s);if(l===null)return"tools widened to every tool";if(a===null)return"tools narrowed to a list";const u=[...l].filter(h=>!a.has(h)),g=[...a].filter(h=>!l.has(h));return u.length&&!g.length?u.length===1?`tool added: ${u[0]}`:`${u.length} tools added`:g.length&&!u.length?g.length===1?`tool removed: ${g[0]}`:`${g.length} tools removed`:"tools changed"}function sa(t,s,n){if(t==="tools")return ta(s,n);if(t==="delegate")return n==="true"?"delegation turned on":"delegation turned off";if(t==="action_class")return n==="proactive"?"class changed to proactive":"class changed to reactive — proactive messaging stopped";if(t==="members"){const a=l=>l?l.split(",").length:0;return`members changed (${a(s)} to ${a(n)})`}return`${Zn[t]??t} changed`}function na(t,s,n){const a=[],l=new Set;for(const u of n){const g=`${u.kind}:${u.name}`;if(l.has(g))continue;l.add(g);const h=t[u.kind==="agent"?"agents":"teams"][u.name],v=s[u.kind==="agent"?"agents":"teams"][u.name];if(!v)continue;if(!h){a.push({target:u,created:!0,changes:[]});continue}const p=[];for(const d of Object.keys(v))v[d]!==h[d]&&p.push({label:sa(d,h[d],v[d]),before:h[d],after:v[d]});a.push({target:u,created:!1,changes:p})}for(const[u,g]of[["agent",s.agents],["team",s.teams]])for(const h of Object.keys(g))l.has(`${u}:${h}`)||(u==="agent"?t.agents[h]:t.teams[h])||a.push({target:{kind:u,name:h},created:!0,changes:[]});return a}function aa(t){return ee(t,"agents_config")&&ee(t,"session_interrupt")&&ee(t,"profile_catalogue")&&ee(t,"team_catalogue")}function ia(t){if(!(t instanceof Be)||t.status!==409)return null;const n=t.detail?.session_id;return typeof n=="string"&&n.length>0?n:null}function ra(t,s){const[n,a]=i.useState(()=>Date.now());return i.useEffect(()=>{if(!t||!s)return;const l=setInterval(()=>a(Date.now()),1e3);return()=>clearInterval(l)},[t,s]),t?Math.max(0,n-t):0}function la(t){const s=Math.floor(t/1e3);return s<60?`${s}s`:`${Math.floor(s/60)}m ${String(s%60).padStart(2,"0")}s`}function wt(t){for(let s=(t?.length??0)-1;s>=0;s-=1){const n=t?.[s];if(n?.kind==="assistant"&&n.text?.trim())return n.text.trim()}return""}function oa(t){const n=t?.payload?.frontend;if(!n||typeof n!="object")return null;const a=n.streaming;if(typeof a=="boolean")return a;const l=n.snapshot?.streaming;return typeof l=="boolean"?l:null}function ca(){const t=ze(),s=aa(t.data),n=ct(),a=J(),[l,u]=i.useState(!1),[g,h]=i.useState(!1),v=i.useRef(!1),p=a.status==="running"||a.status==="stopping",d=Js(a.sessionId??void 0,!!a.sessionId),m=i.useMemo(()=>wt(d.transcript?.records),[d.transcript?.records]);Ls(a.sessionId??void 0,d.subscriptionId);const S=d.transcript?.records,x=i.useRef(S);i.useEffect(()=>{x.current=S},[S]);const j=i.useMemo(()=>(d.transcript?.records??[]).filter(C=>C.kind==="tool"&&Yn.has(C.toolName)).map(C=>({...Qn({toolName:C.toolName,args:C.args??null,phase:C.phase,ts:C.ts,isError:C.isError,notRunReason:C.notRunReason,neverSent:C.neverSent}),ts:C.ts})),[d.transcript]);i.useEffect(()=>{if(p)for(const o of j)o.target&&o.writes&&a.noteTouched(o.target)},[j,p,a]);const k=p&&j.length>0?j[j.length-1].verb:null,T=la(ra(a.startedAt,p)),y=i.useCallback(async(o,C="")=>{if(v.current)return;v.current=!0;const R=a.before;let w=[];try{const[B,P]=await Promise.all([X({op:"profiles.list"}),X({op:"teams.list"})]);R&&(w=na(R,Nt(B.profiles,P.teams),a.touched))}catch{J.getState().fail("The run finished, but the agents and teams lists could not be read to describe what changed."),gt(n);return}if(gt(n),J.getState().settle(w,o,C),o==="done"&&w.length>0){const B=w.filter(P=>P.created).length;ke(B>0?`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} changed.`:`Configuration run finished: ${w.length} definition${w.length===1?"":"s"} updated.`)}},[n,a.before,a.touched]);i.useEffect(()=>{if(p){if(d.failure){J.getState().fail(d.failure.statement);return}v.current||d.frontend&&(d.frontend.streaming||d.turnsCompleted!==0&&y(a.status==="stopping"?"stopped":"done",m))}},[p,m,d.failure,d.frontend,d.turnsCompleted,a.status,y]),i.useEffect(()=>{const o=a.sessionId;if(!p||!o)return;let C=!1;const R=async()=>{if(!(C||v.current))try{const P=await X({op:"sessions.get",sessionId:o});if(C||v.current||oa(P)!==!1)return;const z=wt(x.current);if(!z)return;y(J.getState().status==="stopping"?"stopped":"done",z)}catch{}},w=setTimeout(()=>void R(),400),B=setInterval(()=>void R(),4e3);return()=>{C=!0,clearTimeout(w),clearInterval(B)}},[p,a.sessionId,y]);const N=async(o,C,R=[])=>{if(l||!o.trim()&&R.length===0)return!1;u(!0),h(!1),v.current=!1;const w=Nt(n.getQueryData(["desktop","profiles"]),n.getQueryData(["desktop","teams"])),B=C?`About the ${C.kind} “${C.name}”: ${o.trim()}`:o.trim(),{images:P,files:z,failures:te,overflow:ne,fileOverflow:Z}=await vs(R,B),M=ys(te);if(M)return J.getState().fail(M),!1;const q=ks(ne);if(q)return J.getState().fail(q),!1;const se=Ns(Z);if(se)return J.getState().fail(se),!1;try{let W;try{W=(await X({op:"sessions.create",requestId:crypto.randomUUID(),purpose:"agents-config"})).session_id}catch(Y){const H=ia(Y);if(H)return h(!0),a.adopt(H,o.trim(),w,P,z),!1;throw Y}return a.adopt(W,B,w,P,z),await _(W,B,P,z),!0}catch(W){const Y=J.getState().sessionId;return J.getState().failUnsent(Ke(W,Y?"The run was set up, but your request could not be sent. It is still in the box — send it again when the backend is reachable.":"The configuration run could not be started. Your request is still here.")),!1}finally{u(!1)}},_=async(o,C,R=[],w=[])=>{await X({op:"sessions.message",sessionId:o,requestId:crypto.randomUUID(),text:C,...R.length>0?{images:R}:{},...w.length>0?{files:w}:{}})},$=async()=>{const o=J.getState();if(!(l||!o.unsent||!o.sessionId||!o.topic&&o.images.length===0)){u(!0);try{await _(o.sessionId,o.topic,o.images,o.files),a.adopt(o.sessionId,o.topic,o.before),v.current=!1}catch(C){J.getState().failUnsent(Ke(C,"The request could not be sent. It is still in the box."))}finally{u(!1)}}},A=async()=>{const o=J.getState().sessionId;if(o){a.stopping();try{await Os(o,crypto.randomUUID())}catch(C){J.getState().stopFailed(Ke(C,"The run did not acknowledge the request."))}}},f=s?null:t.isLoading?"Connecting to the backend…":t.error?"The backend could not be reached, so the composer is unavailable for now.":"Ask for a change needs a newer backend. Update Local Operator to configure agents by conversation.";return{enabled:s,disabledReason:f,status:a.status,sessionId:a.sessionId,frontend:d.frontend,topic:a.topic,error:a.error,stopError:a.stopError,about:a.about,setAbout:a.setAbout,touched:a.touched,results:a.results,answer:a.answer,step:k,elapsed:T,activity:j,start:N,stop:A,retry:$,canRetry:a.unsent&&!!a.sessionId,dismiss:a.dismiss,starting:l,attached:g}}function da(t){return JSON.stringify(t.agent_id?["agent","id",t.agent_id]:["agent","source",t.source,t.name])}function ua(t){return JSON.stringify(t.id?["team","id",t.id]:["team","local",t.name])}function U({title:t,description:s,actions:n,children:a,className:l}){return e.jsxs("section",{className:K("space-y-2",l),children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1",children:[e.jsx("h3",{className:"text-heading",children:t}),n]}),s?e.jsx("p",{className:"text-meta text-ink-muted",children:s}):null,a]})}const ut="min-h-6",rs="h-[calc(var(--text-title)*var(--text-title--line-height))]";function ye({text:t,empty:s="Nothing here yet.",mono:n=!1}){const[a,l]=i.useState(!1),[u,g]=i.useState(!1),h=i.useRef(null);return i.useEffect(()=>{if(a)return;const v=h.current;if(!v)return;const p=()=>g(!!t&&v.scrollHeight>v.clientHeight+1);p();const d=new ResizeObserver(p);return d.observe(v),()=>d.disconnect()},[t,a]),t.trim()?e.jsxs("div",{children:[e.jsx("div",{ref:h,className:K("whitespace-pre-wrap text-body text-ink",!a&&"line-clamp-10",n&&"font-mono text-meta"),children:t}),u?e.jsx(E,{variant:"link",size:"sm",className:K("mt-px -mb-[3px]",ut),"aria-expanded":a,onClick:()=>l(v=>!v),children:a?"Show less":"Show all"}):null]}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:s})}function ma({source:t,appearance:s="chip"}){const n=ls(t);return s==="text"?e.jsx("span",{className:"shrink-0 text-meta text-ink-dim",children:n}):e.jsx(oe,{variant:"neutral",children:n})}function ls(t){return t==="builtin"?"Built-in":t==="installed"?"Installed":"Custom"}let mt=!1,os=null;function _t(t,s){mt=t,os=t?s??null:null}function cs(t,s){i.useEffect(()=>{if(!s)return;const n=a=>{a.key!=="Escape"||a.defaultPrevented||mt||(a.preventDefault(),t())};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[s,t])}function ht({dirty:t,pending:s,onSave:n,onCancel:a,saveLabel:l="Save changes",pendingLabel:u="Saving…",dirtyHint:g,submit:h,confirming:v,onConfirmingChange:p}){const[d,m]=i.useState(!1),S=i.useRef(null),x=i.useRef(null),j=v!==void 0,k=j?v:d,T=i.useRef(!1);i.useEffect(()=>{k?x.current?.focus():T.current&&document.activeElement===document.body&&S.current?.focus(),T.current=k},[k]);const y=i.useRef(null);i.useEffect(()=>{const _=y.current,$=_?.closest("[data-agents-pane]");if(!_||!$)return;const A=()=>$.style.setProperty("--lo-pane-footer-h",`${_.getBoundingClientRect().height}px`);A();const f=new ResizeObserver(A);return f.observe(_),()=>{f.disconnect(),$.style.removeProperty("--lo-pane-footer-h")}},[]);const N=_=>{j||m(_),p?.(_)};return i.useEffect(()=>{t||(j||m(!1),p?.(!1))},[t,j,p]),e.jsxs("div",{ref:y,"data-testid":"edit-footer","data-lo-pane-footer":!0,className:"sticky bottom-0 z-10 flex flex-wrap items-center gap-2 border-hairline border-t bg-canvas py-3",children:[e.jsx(E,{ref:S,type:h?"submit":void 0,variant:"primary",onClick:h?void 0:n,disabled:s,children:s?u:l}),k?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:g??"Discard your unsaved changes?"}),e.jsx(E,{variant:"danger",onClick:a,children:"Discard changes"}),e.jsx(E,{ref:x,variant:"ghost",onClick:()=>{N(!1),S.current?.focus()},children:"Keep editing"})]}):e.jsx(E,{variant:"ghost",onClick:()=>{mt&&os?.(),t?N(!0):a()},disabled:s,children:"Cancel"}),t&&!k?e.jsx("span",{className:"ms-auto text-meta text-ink-dim",children:"Unsaved changes"}):null]})}let nt=!1;function ds(){nt=!0}function us(){const t=nt;return nt=!1,t}function ha({rows:t=6}){return e.jsx("div",{className:"space-y-1","aria-hidden":"true",children:fa.slice(0,t).map(s=>e.jsx(ve,{className:"h-12 w-full"},s))})}const fa=["a","b","c","d","e","f","g","h"];function St(){return e.jsxs("div",{className:"space-y-8","aria-hidden":"true",children:[e.jsx(ve,{className:"h-7 w-64"}),e.jsx(ve,{className:"h-5 w-40"}),e.jsx(ve,{className:"h-28 w-full"}),e.jsx(ve,{className:"h-24 w-full"})]})}function Ct({title:t,what:s,meaning:n,onRetry:a,retrying:l=!1}){return e.jsxs("div",{role:"alert",className:"max-w-xl space-y-2",children:[e.jsx("h2",{className:"text-heading",children:t}),e.jsx("p",{className:"text-body-sm text-ink",children:s}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:n}),e.jsx(E,{variant:"secondary",onClick:a,disabled:l,children:l?"Retrying…":"Retry"})]})}function he({label:t,htmlFor:s,error:n}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("label",{htmlFor:s,className:"text-body-sm text-ink-muted",children:t}),n?e.jsx("span",{className:"text-meta text-danger",role:"alert",children:n}):null]})}const ga=/^[A-Za-z0-9_.:-]{1,128}$/;function pe(t){return{description:t.description??"",instructions:t.instructions??"",tools:t.tools&&t.tools.length>0?[...t.tools]:null,effort:t.effort??"inherit",delegate:t.delegate??!1}}function pa(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.instructions!==t.instructions&&(n.instructions=s.instructions),JSON.stringify(s.tools)!==JSON.stringify(t.tools)&&(n.tools=s.tools??[]),s.effort!==t.effort&&(n.effort=s.effort),s.delegate!==t.delegate&&(n.delegate=s.delegate),n}function xa({profile:t}){const s=[ls(t.source),De(t)==="proactive"?ns.proactive:null,t.delegate?"Delegates":null,t.kind==="specialist"?"Specialist":null].filter(Boolean);return e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[e.jsx("p",{className:"text-body-sm text-ink-muted",children:s.join(" · ")}),t.divergent_fields?.length?e.jsx(oe,{variant:"warning",children:"Modified"}):null]})}const ba=5e3;let Qe=null;function ja({profile:t,displayedName:s,notice:n,onNotice:a,onChanged:l}){const u=De(t),[g,h]=i.useState(null),[v,p]=i.useState(!1),d=i.useRef(null),m=i.useId();i.useEffect(()=>{g!==null&&u===g&&h(null)},[u,g]),i.useEffect(()=>{const j=Qe;!j||j.name!==t.name||(Qe=null,!(Date.now()-j.at>ba)&&d.current?.focus())},[t.name]);const S=g??u,x=async j=>{if(!(v||j===S)){Qe={name:t.name,at:Date.now()},a(null),h(j),p(!0);try{await Gn(t,j,(k,T)=>k.op==="profiles.install"?X({op:"profiles.install",name:k.name,requestId:T}):X({op:"profiles.update",name:k.name,requestId:T,fields:k.fields??{}})),l(t.name),ke(j==="proactive"?`${s} is now proactive — it may message you on its own.`:`${s} is now reactive — proactive messaging stopped.`)}catch(k){h(null);const T=k instanceof is?k.completed:[],y=Jn(k,T);a(y),Me(y),l(t.name)}finally{p(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative flex items-center gap-2 text-body-sm",children:[e.jsx(He,{ref:d,checked:S==="proactive","aria-disabled":v,"aria-labelledby":m,"data-testid":"agent-class-switch",className:"after:absolute after:inset-0 after:content-['']",onCheckedChange:j=>void x(j?"proactive":"reactive")}),e.jsx("span",{id:m,className:"text-ink",children:"Can message me on its own"}),e.jsx("span",{"aria-live":"polite",className:"text-ink-muted",children:v?"Switching…":S==="proactive"?"On":"Off"})]}),e.jsx("p",{className:"text-body-sm text-ink",children:Kn[S]}),e.jsx("p",{className:"text-meta text-ink-muted",children:Wn[S]}),t.source==="builtin"?e.jsx("p",{className:"text-meta text-ink-muted",children:as}):null,n?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-class-error",children:[e.jsx(de,{children:"The switch did not go through"}),e.jsx(me,{children:n})]}):null]})}function ms({tools:t,onChange:s,error:n}){const[a,l]=i.useState(""),[u,g]=i.useState(null),h=i.useId(),v=()=>{const p=a.trim();if(p){if(!ga.test(p)){g("Tool names are letters, digits, dot, underscore, dash or colon.");return}if(t?.includes(p)){g("That tool is already listed.");return}g(null),l(""),s([...t??[],p])}};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:t===null,onCheckedChange:p=>s(p?null:[]),"aria-label":"Give this agent every tool"}),e.jsx("span",{children:"All tools"})]}),t===null?e.jsx("p",{className:"text-meta text-ink-muted",children:"This agent may use whatever the session offers."}):e.jsxs(e.Fragment,{children:[t.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.map(p=>e.jsx("li",{children:e.jsxs(oe,{variant:"outline",children:[p,e.jsx(E,{variant:"ghost",size:"sm","aria-label":`Remove ${p}`,onClick:()=>s(t.filter(d=>d!==p)),className:"ms-1 h-4 px-1",children:"×"})]})},p))}):e.jsx("p",{className:"text-meta text-ink-muted",children:"No tools yet. Add one below, or turn on All tools."}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx(he,{label:"Add a tool",htmlFor:h,error:u??n}),e.jsx(Ne,{id:h,value:a,inputSize:"md",placeholder:"Tool name","aria-invalid":!!(u??n),onChange:p=>{l(p.target.value),g(null)},onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),v())}})]}),e.jsx(E,{variant:"secondary",onClick:v,disabled:!a.trim(),children:"Add"})]})]})]})}function va({profile:t,displayedName:s,classNotice:n,onClassNotice:a,teams:l,effortTiers:u,askEnabled:g,onSaved:h,onDuplicate:v,onOpenTeam:p,onAskAgent:d,onDirtyChange:m,belowHeader:S}){const[x,j]=i.useState(!1),[k,T]=i.useState(()=>pe(t)),[y,N]=i.useState(()=>pe(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),[z,te]=i.useState(!1),ne=i.useRef(null),Z=i.useRef(t.definition_revision),M=dt(),q=JSON.stringify(y)!==JSON.stringify(k);i.useEffect(()=>(m?.(x&&q),()=>m?.(!1)),[m,x,q]),i.useEffect(()=>{us()&&requestAnimationFrame(()=>ne.current?.focus())},[]),i.useEffect(()=>{if(x&&q)return;const I=pe(t);T(I),N(I)},[t,x,q]),i.useEffect(()=>{if(!x){P(!1);return}const I=pe(t);P(q&&JSON.stringify(I)!==JSON.stringify(k))},[t,x,q,k]);const se=()=>{j(!1),f(null),C(null),w(!1),te(!1);const I=pe(t);T(I),N(I),Z.current=t.definition_revision};cs(()=>{if(z){te(!1);return}q?te(!0):se()},x);const Y=async I=>{if(I?.preventDefault(),_)return;const F=pa(k,y);if(Object.keys(F).length===0){se();return}if(typeof F.instructions=="string"&&!F.instructions.trim()){f("Give the agent instructions."),C("instructions");return}$(!0),f(null),C(null);try{const V=await X({op:"profiles.update",name:t.name,requestId:crypto.randomUUID(),fields:F,expectedDefinitionRevision:Z.current});j(!1),w(!1);const G=pe(V);T(G),N(G),Z.current=V.definition_revision,h(V.name),ke(`Saved ${V.name}.`),requestAnimationFrame(()=>ne.current?.focus())}catch(V){const G=Ae(V instanceof Error?V.message:"The agent could not be saved.");f(G.message),C(G.field);const ae=V?.status;if(V?.code==="local-concurrent-edit"){P(!0),$(!1);return}const re=typeof ae=="number"&&ae!==408&&ae>=400&&ae<500;w(!re),re||Me("The save could not be confirmed. Check whether it was applied before retrying.")}finally{$(!1)}},H=async()=>{if(!_){$(!0),f(null);try{const I=await X({op:"profiles.install",name:t.name,requestId:crypto.randomUUID()}),F=pe(I);T(F),N(F),h(I.name),ke(`Installed ${I.name}. It can be edited now.`),requestAnimationFrame(()=>ne.current?.focus())}catch(I){const F=Ae(I instanceof Error?I.message:"The agent could not be installed.");f(F.message),Me(F.message)}finally{$(!1)}}},Q=(l??[]).filter(I=>I.manager===t.name||(I.members??[]).some(F=>F.role===t.name)),fe=t.source==="builtin";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:ne,tabIndex:-1,title:s,className:"truncate text-title focus:outline-none",children:s}),e.jsx(xa,{profile:t})]}),x?null:e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"agent",name:t.name}),M("/chat")},children:"New chat"}),fe?e.jsxs(E,{variant:"secondary",onClick:H,disabled:_,children:[e.jsx(gn,{className:"size-4"}),_?"Installing…":"Install to edit"]}):e.jsx(E,{variant:"secondary",onClick:()=>{j(!0),f(null),C(null),Z.current=t.definition_revision},children:"Edit"}),g?e.jsx(E,{variant:"ghost",onClick:()=>d(`Change the agent ${t.name}: `),children:"Ask for a change"}):null,e.jsxs(tn,{children:[e.jsx(sn,{asChild:!0,children:e.jsx(E,{variant:"ghost",size:"icon","aria-label":"More actions",className:"-mr-2",children:e.jsx(ws,{"aria-hidden":"true"})})}),e.jsx(nn,{align:"end",children:e.jsx(an,{onSelect:()=>v(t),children:"Duplicate as new agent"})})]})]})]}),fe?e.jsxs(ce,{variant:"info",children:[e.jsx(de,{children:"Built-in agent"}),e.jsx(me,{children:"This one ships with the app and cannot be edited in place. Install it to get an editable copy, or duplicate it as a new agent."})]}):null,B?e.jsxs(ce,{variant:"warning","data-testid":"agent-conflict",children:[e.jsx(de,{children:"This changed while you were editing"}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:"Something else — a configuration run, or another window — wrote to this agent after you opened it. Your edits are kept; saving writes only the fields you changed."}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:se,children:"Reload the saved version"})]})]}):null,R?e.jsxs(ce,{variant:"danger","data-testid":"agent-unconfirmed",children:[e.jsx(de,{children:"The last save was not confirmed"}),e.jsx(me,{children:"The backend did not answer, so the write may or may not have landed. Check the agent below, then edit again."})]}):null,A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),S,e.jsx("form",{noValidate:!0,onSubmit:I=>{I.preventDefault(),Y(I)},className:"space-y-8",children:x?e.jsxs(e.Fragment,{children:[e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:y.description,error:o==="description"?A:null,onChange:I=>N(F=>({...F,description:I}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:y.instructions,rows:12,required:!0,error:o==="instructions"?A:null,onChange:I=>N(F=>({...F,instructions:I}))}),e.jsx(U,{title:"Tools",children:e.jsx(ms,{tools:y.tools,error:o==="tools"?A:null,onChange:I=>N(F=>({...F,tools:I}))})}),e.jsx(U,{title:"Delegation and effort",description:"Whether this agent may hand work to subagents, and which effort tier it runs at.",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:y.delegate,onCheckedChange:I=>N(F=>({...F,delegate:I})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-effort",error:o==="effort"?A:null}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,placeholder:"Choose an effort tier",busyLabel:"Loading effort tiers",options:["inherit",...u].map(I=>({id:I,name:I,description:I==="inherit"?"Use the session's own effort":void 0})),selected:{id:y.effort,name:y.effort},onSelect:I=>N(F=>({...F,effort:I.id})),helperText:"Tiers come from the backend's subagent model settings."})]})]})}),e.jsx(ht,{submit:!0,confirming:z,onConfirmingChange:te,dirty:q,pending:_,onSave:()=>void Y(),onCancel:se,saveLabel:"Save changes",dirtyHint:"Discard your unsaved changes to this agent?"})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"When to use it",children:e.jsx(ye,{text:t.description||"",empty:"No description yet — add one so a model knows when to pick this agent."})}),e.jsx(U,{title:"Instructions",children:e.jsx(ye,{text:t.instructions??t.packaged_instructions??"",empty:"No instructions yet."})}),e.jsx(U,{title:"Tools",children:t.tools&&t.tools.length>0?e.jsx("ul",{className:"flex flex-wrap gap-1.5",children:t.tools.map(I=>e.jsx("li",{children:e.jsx(oe,{variant:"outline",children:I})},I))}):e.jsx(oe,{variant:"neutral",children:"All tools"})}),e.jsxs(U,{title:"Delegation and effort",children:[e.jsx("p",{className:"text-body-sm text-ink",children:t.delegate?"May hand work to subagents.":"Does its own work; it does not delegate."}),e.jsxs("p",{className:"text-body-sm text-ink-muted",children:["Effort tier: ",t.effort??"inherit"]}),t.effort&&Q.length?e.jsx("p",{className:"text-body-sm text-ink-muted",children:r("ui.agents.models.pin_reach",{count:Q.length,teams:Q.map(I=>I.name).join(", ")})}):null]}),e.jsx(U,{title:"Messaging",description:"Reactive agents only reply. Proactive agents may also message you first.",children:e.jsx(ja,{profile:t,displayedName:s,notice:n,onNotice:a,onChanged:h})}),e.jsx(U,{title:"Used by",description:"Teams that name this agent as a manager or a member.",children:Q.length>0?e.jsx("ul",{className:"flex flex-wrap gap-x-3 gap-y-1",children:Q.map(I=>e.jsx("li",{children:e.jsx(E,{variant:"link",className:K("-my-0.5",ut),onClick:()=>p(I.name),children:I.name})},I.id))}):e.jsx("p",{className:"text-body-sm text-ink-muted",children:"No team uses it yet."})}),e.jsxs(U,{title:"Where it came from",description:t.source==="builtin"?"Shipped with the app.":t.source==="installed"?"Installed from a packaged starter.":"Created on this machine.",children:[e.jsxs("dl",{className:"space-y-1 text-body-sm",children:[t.seed_origin?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Source"}),e.jsx("dd",{className:"text-ink",children:t.seed_origin})]}):null,t.divergent_fields?.length?e.jsxs("div",{className:"flex gap-2",children:[e.jsx("dt",{className:"text-ink-muted",children:"Changed from the packaged copy"}),e.jsx("dd",{className:"text-ink",children:t.divergent_fields.join(", ")})]}):null]}),t.packaged_instructions&&t.divergent_fields?.length?e.jsx(rt,{summary:"Compare with the packaged instructions",className:"mt-2",children:e.jsx(ye,{text:t.packaged_instructions,mono:!0})}):null]})]})})]})}function qe({title:t,description:s,label:n,value:a,onChange:l,rows:u,required:g,error:h,fieldRef:v}){const p=i.useId();return e.jsxs(U,{title:t,description:s,children:[e.jsx(he,{label:n,htmlFor:p,error:h}),u?e.jsx(st,{id:p,ref:v,value:a,rows:u,required:g,"aria-invalid":!!h,className:K("min-h-0"),onChange:d=>l(d.target.value)}):e.jsx(Ne,{id:p,value:a,"aria-invalid":!!h,onChange:d=>l(d.target.value)})]})}function ya({initial:t,takenNames:s,effortTiers:n,onDirtyChange:a,onSaved:l,onCancel:u}){const[g,h]=i.useState(()=>t?Hn(t.name,s):""),[v,p]=i.useState(t?.kind??"role"),[d,m]=i.useState(()=>t?{...pe(t),description:t.description??""}:{description:"",instructions:"",tools:null,effort:"inherit",delegate:!1}),[S,x]=i.useState(!1),[j,k]=i.useState(null),[T,y]=i.useState(null),N=i.useRef(null),_=i.useRef(null);i.useEffect(()=>(a?.(!!(g.trim()||d.instructions.trim())),()=>a?.(!1)),[a,g,d.instructions]),i.useEffect(()=>{N.current?.focus(),N.current?.select()},[]);const $=async f=>{if(f?.preventDefault(),!S){if(!g.trim()){k("Give the agent a name."),y("name"),N.current?.focus();return}if(/[\\/\s]/.test(g.trim())){k("Names cannot contain spaces or slashes."),y("name"),N.current?.focus();return}if(s.includes(g.trim())){k(`An agent called “${g.trim()}” already exists. Choose another name, or open the existing one to change it.`),y("name"),N.current?.focus();return}if(!d.instructions.trim()){k("Give the agent instructions."),y("instructions"),_.current?.focus();return}x(!0),k(null),y(null);try{const o=await X({op:"profiles.create",requestId:crypto.randomUUID(),name:g.trim(),fields:{kind:v,description:d.description,instructions:d.instructions,tools:d.tools??[],effort:d.effort,delegate:d.delegate}});ke(`Created ${o.name}.`),ds(),l(o.name)}catch(o){const C=Ae(o instanceof Error?o.message:"The agent could not be created.");k(C.message),y(C.field)}finally{x(!1)}}},A=t?"Duplicate as a new agent":"New agent";return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-2",children:[e.jsx("h2",{className:"text-title",children:A}),e.jsx("p",{className:"text-body-sm text-ink-muted",children:t?`A copy of ${t.name}. It is a separate agent: changing it does not change the original.`:"Reusable instructions shared by agent commands, subagents and teams. Chats stay separate."})]}),j&&!T?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"agent-create-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:j})]}):null,e.jsxs("form",{noValidate:!0,onSubmit:f=>{f.preventDefault(),$(f)},className:"space-y-8",children:[e.jsx(U,{title:"Name and role",children:e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Name",htmlFor:"agent-create-name",error:T==="name"?j:null}),e.jsx(Ne,{id:"agent-create-name",ref:N,value:g,required:!0,"aria-invalid":T==="name",onChange:f=>h(f.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"How it works with others",htmlFor:"agent-create-kind"}),e.jsxs($e,{value:v,onValueChange:f=>p(f),children:[e.jsx(Le,{id:"agent-create-kind",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"role",children:"You can chat with it directly"}),e.jsx(xe,{value:"specialist",children:"Other agents can call on it"})]})]})]})]})}),e.jsx(qe,{title:"When to use it",description:"One sentence the model reads to decide when this agent is the right one.",label:"When to use this agent",value:d.description,error:T==="description"?j:null,onChange:f=>m(o=>({...o,description:f}))}),e.jsx(qe,{title:"Instructions",description:"What the agent is told to do. This is the agent's whole behaviour.",label:"Instructions",value:d.instructions,rows:12,required:!0,fieldRef:_,error:T==="instructions"?j:null,onChange:f=>m(o=>({...o,instructions:f}))}),e.jsx(U,{title:"Delegation and effort",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-body-sm",children:[e.jsx(He,{checked:d.delegate,onCheckedChange:f=>m(o=>({...o,delegate:f})),"aria-label":"May delegate to subagents"}),e.jsx("span",{children:"May delegate to subagents"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(he,{label:"Effort tier",htmlFor:"agent-create-effort"}),e.jsx(Ue,{ariaLabel:"Effort tier",showLabel:!1,busyLabel:"Loading effort tiers",placeholder:"Choose an effort tier",options:["inherit",...n].map(f=>({id:f,name:f,description:f==="inherit"?"Use the session's own effort":"A tier configured in Settings"})),selected:{id:d.effort,name:d.effort},onSelect:f=>m(o=>({...o,effort:f.id}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("span",{className:"text-body-sm text-ink-muted",children:"Tools"}),e.jsx(ms,{tools:d.tools,error:T==="tools"?j:null,onChange:f=>m(o=>({...o,tools:f}))})]})]})}),e.jsx(ht,{submit:!0,dirty:!!(g.trim()||d.instructions),pending:S,saveLabel:t?"Create the copy":"Create agent",pendingLabel:"Creating…",dirtyHint:"Discard this new agent?",onSave:()=>void $(),onCancel:u})]})]})}function hs(t,s,n=Date.now()){const a=Date.parse(t.expires_at);return t.local_fingerprint.length>0&&t.proposal_fingerprint.length>0&&t.link_id===s.link_id&&(t.direction==="push"||t.remote_fingerprint.length>0)&&t.proposal.kind===s.kind&&t.hub_source===s.hub_source&&t.visibility===s.visibility&&t.tenant_id===s.tenant_id&&t.expected_policy_revision===s.policy.revision&&t.expected_remote_revision===s.remote_revision&&Number.isFinite(a)&&a>n}function Et(t,s,n=Date.now()){return t.can_confirm&&t.preview_receipt.length>0&&hs(t,s,n)}const Ze=t=>Number.isFinite(Date.parse(t))?Ss(new Date(t)):r("ui.hub.status.unknown"),ka=t=>[t.pull.state,t.push.state].some(s=>["checking","merging","applying","pushing"].includes(s));function Na({link:t}){Te();const s=Ps(t.link_id),n=lt(t),a=Bs(t),[l,u]=i.useState(null),[g,h]=i.useState(null),[v,p]=i.useState(null),[d,m]=i.useState(!1),[S,x]=i.useState(!1),j=i.useRef(null),k=i.useId(),T=s.isPending||ka(t),y=!xt(t.baseline_state),N=l??g;i.useEffect(()=>{N&&!hs(N,t)&&(u(null),h(null),x(!0))},[t,N]),i.useEffect(()=>{if(!N)return;const f=Date.parse(N.expires_at)-Date.now(),o=setTimeout(()=>{u(null),h(null),x(!0)},Math.max(0,Math.min(f,2147483647)));return()=>clearTimeout(o)},[N]);const _=f=>{T||(f.action==="preview"&&x(!1),s.mutate(f,{onSuccess:o=>{if(f.action==="preview")u(o.preview?.direction==="push"?o.preview:null);else if(f.action==="apply"&&f.preview){const C=o.preview?.direction==="pull"?o.preview:null;h(C),p(JSON.stringify(o.reports,null,2)),m(C?.choices.acknowledge_unknown_baseline??!1)}else u(null),h(null)},onError:o=>{o instanceof Be&&["publication-preview-changed","application-preview-changed","remote-revision-changed"].includes(o.code??"")&&(u(null),h(null),x(!0))}}))},$=()=>{s.isPending||(u(null),h(null))},A=f=>r(f==="pull"?"ui.hub.links.direction_pull":"ui.hub.links.direction_push");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-4 py-4","data-hub-link":t.link_id,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"break-words text-heading text-ink",children:n}),e.jsx("p",{className:"break-words text-meta text-ink-muted",children:t.name}),e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.links.source_address",{address:t.hub_source})})]}),e.jsx(Kt,{link:t}),e.jsx("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:["pull","push"].map(f=>{const o=t[f];return e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1","data-hub-direction":f,children:[e.jsx("h4",{className:"text-body-sm text-ink",children:A(f)}),e.jsx("p",{className:K("text-body-sm",o.state==="failed"?"text-danger":o.state==="available"?"text-accent":"text-ink-muted"),children:Us(o)}),o.error_class&&e.jsx("p",{className:"text-meta text-warning",children:et(o.error_class)}),o.last_checked_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.last_checked",{time:Ze(o.last_checked_at)})}),o.last_success_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.last_success",{time:Ze(o.last_success_at)})}),o.next_retry_at&&e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.status.next_retry",{time:Ze(o.next_retry_at)})}),o.model_used&&e.jsx("p",{className:"break-words text-meta text-ink-muted",children:r("ui.hub.links.actual_model",{model:o.model_used})}),o.operation_id&&e.jsx("p",{className:"break-all text-meta text-ink-dim",children:r("ui.hub.status.receipt",{operation:o.operation_id})}),a[f].retryable&&(f==="pull"||t.policy.auto_push)&&e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"retry",linkId:t.link_id,direction:f}),children:r("ui.hub.links.retry")})]},f)})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"check",linkId:t.link_id}),children:r("ui.hub.subscriptions.check")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0}),children:r("ui.hub.links.preview_pull")}),e.jsx(E,{variant:"outline",size:"sm",disabled:T||!s.canWrite||!t.remote_revision||!xt(t.baseline_state)||t.visibility==="org"&&!t.tenant_name,onClick:()=>_({action:"preview",linkId:t.link_id}),children:r("ui.hub.subscriptions.preview_publish")})]}),S&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.preview_changed")}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(s.variables?.action==="preview"||s.variables?.action==="confirm"?"push":"pull"),item:t.name,source:n})}),s.data?.reports.filter(f=>f.link_id===t.link_id).map((f,o)=>e.jsx("output",{className:"text-meta text-ink-muted",children:r("ui.hub.links.action_result",{direction:A(f.direction),item:t.name,source:n,outcome:f.outcome})},`${f.operation_id??f.direction}-${o}`)),e.jsx(Jt,{open:l!==null||g!==null,onOpenChange:f=>{f||$()},children:e.jsxs(Yt,{className:"max-w-3xl",closeDisabled:s.isPending,onOpenAutoFocus:f=>{f.preventDefault(),j.current?.focus()},onEscapeKeyDown:f=>{s.isPending&&f.preventDefault()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:l?r("ui.hub.links.preview_payload",{source:n}):r("ui.hub.links.preview_pull")}),e.jsx(Xt,{children:l||!y?r("ui.hub.subscriptions.enable_safety"):r("ui.hub.links.unknown_baseline")})]}),e.jsx("pre",{className:"max-h-[50vh] overflow-auto whitespace-pre-wrap break-words rounded-md bg-sunken p-3 text-mono-sm text-ink",children:JSON.stringify(N?.proposal,null,2)}),N?.warnings.length?e.jsxs("div",{children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.preview_warnings")}),N.warnings.map((f,o)=>e.jsx("p",{className:"break-words text-body-sm text-warning",children:f},`${o}-${f}`))]}):null,N?.reason&&e.jsx("p",{className:"text-body-sm text-warning",children:et(N.reason)}),g&&v&&e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap break-words bg-sunken p-3 text-mono-sm text-ink",children:v}),g&&y&&e.jsxs("label",{htmlFor:k,className:"flex items-start gap-2 text-body-sm text-ink",children:[e.jsx(rn,{id:k,checked:d,onCheckedChange:f=>m(f===!0)}),r("ui.hub.links.acknowledge_baseline")]}),s.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:s.error instanceof tt?s.error.message:r("ui.hub.links.action_failed",{direction:A(l?"push":"pull"),item:t.name,source:n})}),e.jsxs(es,{children:[e.jsx(E,{ref:j,variant:"outline",disabled:s.isPending,onClick:$,children:r("ui.hub.subscriptions.cancel")}),l?e.jsx(E,{disabled:s.isPending||!s.canWrite||!Et(l,t),onClick:()=>_({action:"confirm",linkId:t.link_id,previewReceipt:l.preview_receipt}),children:r("ui.hub.links.confirm_publish")}):e.jsxs(e.Fragment,{children:[["local","remote"].map(f=>e.jsx(E,{variant:"outline",disabled:s.isPending||!s.canWrite||y&&!d,onClick:()=>_({action:"apply",linkId:t.link_id,preview:!0,prefer:f,acknowledgeUnknownBaseline:y&&d}),children:r(f==="local"?"ui.hub.links.prefer_local":"ui.hub.links.prefer_remote")},f)),e.jsx(E,{disabled:s.isPending||!s.canWrite||!g||!Et(g,t)||g.choices.acknowledge_unknown_baseline!==d||g.choices.replace!==null||g.choices.confirm_replace,onClick:()=>{g&&_({action:"apply",linkId:t.link_id,previewReceipt:g.preview_receipt,confirmApply:!0,prefer:g.choices.prefer??void 0,acknowledgeUnknownBaseline:g.choices.acknowledge_unknown_baseline})},children:r("ui.hub.subscriptions.pull")})]})]})]})})]})}function wa({row:t,source:s,organizations:n,isAuthenticated:a,onSignIn:l,initialOpen:u,onResolved:g}){Te();const[h,v]=i.useState(u??!1),[p,d]=i.useState(""),m=Ms(g),S=i.useRef(null),x=i.useRef(null),j=i.useRef(!1);i.useEffect(()=>{h?S.current?.focus():j.current&&(j.current=!1,x.current?.focus())},[h]);const k=p!=="public"&&p!=="",T=k?n.find(_=>_.tenant_id===p):null,N=p!==""&&(!k||!!T)&&(k||p==="public");return e.jsxs("section",{className:"flex min-w-0 flex-col gap-3","data-hub-source-unresolved":t.local_id,children:[e.jsx(ce,{variant:"warning",className:"p-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[m.upgradeMessage&&e.jsx("output",{className:"block text-meta text-warning","data-hub-core-upgrade":!0,children:m.upgradeMessage}),e.jsx(de,{"data-hub-unresolved-label":!0,children:r("ui.hub.links.source_not_confirmed")}),e.jsx("h3",{className:"break-words text-body-sm font-medium text-ink",children:t.name}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_what",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_why",{item:t.name})}),e.jsx("p",{className:"text-body-sm text-ink",children:r("ui.hub.links.unresolved_next")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.source_address",{address:s})}),e.jsx("p",{className:"break-all text-mono-sm text-ink-muted",children:r("ui.hub.links.hub_id",{address:t.hub_id})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_irreversible")}),h?null:e.jsx(E,{ref:x,variant:"primary",size:"sm",className:"self-start",onClick:()=>v(!0),children:r("ui.hub.links.resolve_action")})]})}),h?e.jsxs("div",{ref:S,tabIndex:-1,className:"flex flex-col gap-2 outline-none",children:[e.jsx("h4",{className:"text-body-sm text-ink",children:r("ui.hub.links.resolve_title")}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.resolve_description",{item:t.name})}),a?e.jsxs("label",{className:"text-body-sm text-ink",children:[r("ui.hub.links.scope_label"),e.jsxs("select",{className:"mt-1 w-full rounded-md border border-control bg-surface px-2 py-1 text-body-sm text-ink",value:p,disabled:m.isPending,onChange:_=>d(_.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:r("ui.hub.links.scope_placeholder")}),e.jsx("option",{value:"public",children:r("ui.hub.links.scope_public")}),n.map(_=>e.jsx("option",{value:_.tenant_id,children:r("ui.hub.links.scope_private",{organization:_.tenant_name})},_.tenant_id))]})]}):e.jsx(E,{variant:"outline",onClick:l,children:r("ui.hub.links.sign_in_to_publish")}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(E,{variant:"outline",disabled:m.isPending,onClick:()=>{j.current=!0,v(!1)},children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:m.isPending||!m.canWrite||!N,onClick:()=>m.mutate({kind:t.kind,localId:t.local_id,name:t.name,hubSource:s,visibility:k?"org":"public",tenantId:k?T?.tenant_id??null:null}),children:m.isPending?r("ui.hub.links.resolve_action_confirming"):m.isSuccess?r("ui.hub.links.resolve_action_done"):r("ui.hub.links.resolve_action_confirm")})]}),!N&&!m.isPending&&a?e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.hub.links.scope_required")}):null,m.error?e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:m.error instanceof tt?m.error.message:m.error instanceof Be&&m.error.code==="origin-conflict"?r("ui.hub.links.resolve_conflict"):m.error instanceof Be&&m.error.code?et(m.error.code):r("ui.hub.links.resolve_failed_generic")}):null]}):null]})}function _a({enabled:t,kind:s,name:n,localId:a}){Te();const l=zt(t),{isAuthenticated:u}=Bt(),g=dt(),[h]=Ut(),v=h.get("resolve"),p=v!==null,{memberships:d}=Ht({enabled:t&&u}),m=ts(d).map(w=>({tenant_id:w.tenant_id,tenant_name:w.tenant_name})),S=_s.radientBaseUrl;if(!t)return null;const x=s&&n?Fs(l.data,s,a,n):l.data?.links.filter(w=>!s||w.kind===s)??[],j=(l.data?.unresolved??[]).filter(w=>(!s||w.kind===s)&&(!n||(a?w.local_id===a:w.name===n))),k=w=>r(w?"ui.hub.subscriptions.configured_on":"ui.hub.subscriptions.configured_off"),T=w=>{const B=x[0]?w(x[0]):!1;return x.every(P=>w(P)===B)},y=w=>T(w)?k(w(x[0])):r("ui.hub.links.mixed"),N=(()=>{if(x.length===0)return"";const w=x[0],B=x.length>1?` · ${r("ui.hub.links.sources_count",{count:x.length})}`:"";return`${lt(w)}${B} · ${r("ui.hub.subscriptions.subscribe")} ${y(P=>P.policy.subscribe)} · ${r("ui.hub.subscriptions.auto_push")} ${y(P=>P.policy.auto_push)}`})(),_=x.some(w=>[w.pull.state,w.push.state].some(B=>B==="available"||B==="failed")),$=i.useRef(null),[A,f]=i.useState(!1);i.useEffect(()=>{!A||x.length===0||($.current?.querySelector("button[aria-expanded]")?.focus(),f(!1))},[A,x]);const[o,C]=i.useState(_),R=i.useRef(_);return i.useEffect(()=>{_&&!R.current&&C(!0),R.current=_},[_]),l.isLoading?null:l.error&&!l.data?e.jsxs("div",{className:"flex flex-col items-start gap-2",children:[e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.load_failed")}),e.jsx(E,{variant:"outline",size:"sm",onClick:()=>void l.refetch(),children:r("ui.hub.links.retry")})]}):x.length===0&&j.length===0?null:e.jsxs("div",{ref:$,className:"flex min-w-0 flex-col gap-3","data-hub-links-panel":!0,children:[j.map(w=>e.jsx(wa,{row:w,source:S,organizations:m,isAuthenticated:u,onSignIn:()=>g("/settings"),initialOpen:p,onResolved:()=>f(!0)},`${w.kind}:${w.local_id}:${v}`)),x.length>0?e.jsxs(rt,{open:o,onOpenChange:C,summary:`${r("ui.hub.links.title")} · ${N}`,className:"min-w-0",children:[e.jsx("div",{className:"divide-y divide-hairline",children:x.map(w=>e.jsx(Na,{link:w},w.link_id))}),l.error&&l.data&&e.jsx("p",{role:"alert",className:"text-meta text-warning",children:r("ui.hub.links.load_failed")})]}):null]})}const Sa=["lo","med","hi"],Ca=["auto","none","minimal","low","medium","high","xhigh","max"],Re="inherit";function It(t){return t??Re}function Ea(t){return t===Re?null:t}function Ia(t){return t===Re?null:t}function Aa(t,s){return{...t,...s.tier===void 0?{}:{tier:Ea(s.tier)},...s.effort===void 0?{}:{effort:Ia(s.effort)}}}function at(t){const{tier:s,effort:n,key:a,...l}=t;return JSON.stringify({...l,...s?{tier:s}:{},...n?{effort:n}:{}})}function Ra(t,s){const n=`${s.kind}\0${s.role.toLocaleLowerCase()}`;return(t?.members??[]).find(a=>`${a.kind}\0${a.role.toLocaleLowerCase()}`===n)??null}const Ta={team:"ui.agents.models.source.team",row:"ui.agents.models.source.row",none:"ui.agents.models.source.none"},Da={team:"ui.agents.models.source.team",tier:"ui.agents.models.source.tier",model_default:"ui.agents.models.source.model_default"},fs=t=>Ta[t],$a=t=>Da[t];function La(t){return t.isSuccess?"available":t.isError&&Oa(t.error)?"unavailable":"absent"}function Oa(t){return Ys(t)!=="outdated"}function Fa({team:t}){Te();const s=i.useId(),n=ze(),{isAuthenticated:a}=Bt(),l=ee(n.data,"hub_links"),[u,g]=i.useState(!1),[h,v]=i.useState(null),[p,d]=i.useState(Je),m=i.useRef(null),S=i.useRef(null),x=zt(l),j=Ht({enabled:u&&a&&ee(n.data,"radient_org")}),k=ts(j.memberships),T=h?k.find(R=>R.tenant_id===h):null,y=h?T?.tenant_name?r("ui.hub.links.source_private",{organization:T.tenant_name}):r("ui.hub.links.source_unavailable"):r("ui.hub.links.source_public"),N=(x.data?.links??[]).filter(R=>R.kind==="team"&&R.local_id===t.id),_=N.find(R=>R.visibility===(h?"org":"public")&&R.tenant_id===h),$=N.find(R=>R.link_id!==_?.link_id),A=x.data?.unresolved.some(R=>R.kind==="team"&&R.local_id===t.id),f=ct(),o=Cs({mutationFn:async()=>{if(!a||_||!l||!x.isSuccess||$||A||h&&!T)throw new Error("hub-team-destination-not-ready");const R=JSON.stringify({id:t.id,target:h,policy:_?null:p}),w=m.current?.tuple===R?m.current:{tuple:R,id:crypto.randomUUID()};return m.current=w,X({op:"team.publish",teamId:t.id,requestId:w.id,...h?{visibility:"org",tenantId:h}:{},..._?{}:p})},onSuccess:()=>{f.invalidateQueries({queryKey:qs})}});if(!l||!u&&(N.length>0||A))return null;const C=!a||!x.isSuccess||!!_||!!$||!!A||!!h&&!T;return e.jsxs(e.Fragment,{children:[e.jsx(E,{variant:"outline",disabled:!a||!x.isSuccess,onClick:()=>{g(!0),v(null),d(Je()),m.current=null,o.reset()},children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Jt,{open:u,onOpenChange:R=>{o.isPending||g(R)},children:e.jsxs(Yt,{onOpenAutoFocus:R=>{R.preventDefault(),S.current?.focus()},children:[e.jsxs(Qt,{children:[e.jsx(Zt,{children:r("ui.hub.subscriptions.preview_publish")}),e.jsx(Xt,{children:r("ui.hub.skills.initial_policy_description")})]}),e.jsx("label",{htmlFor:`${s}-target`,className:"text-body-sm text-ink",children:y}),e.jsxs("select",{id:`${s}-target`,disabled:o.isPending||o.isSuccess,value:h??"",className:"rounded-md border border-control bg-surface px-3 py-2 text-body-sm text-ink",onChange:R=>{v(R.target.value||null),d(Je()),m.current=null},children:[e.jsx("option",{value:"",children:r("ui.hub.links.source_public")}),k.map(R=>e.jsx("option",{value:R.tenant_id,children:R.tenant_name},R.tenant_id))]}),$?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.subscriptions.source_separation",{currentSource:lt($),newSource:y})}):A?e.jsx("p",{className:"text-body-sm text-warning",children:r("ui.hub.links.source_unavailable")}):_?e.jsx(Kt,{link:_}):e.jsx(un,{value:p,onChange:d,source:y,item:t.name,visibility:h?"org":"public",organization:T?.tenant_name??null,destinationKey:`${t.id}:${h??"public"}`,canEnableAutoPush:!1,disabled:C||o.isPending||o.isSuccess}),x.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-warning",children:r("ui.hub.links.load_failed")}),o.error&&e.jsx("p",{role:"alert",className:"text-body-sm text-danger",children:r("ui.hub.links.action_failed",{direction:r("ui.hub.links.direction_push"),item:t.name,source:y})}),o.isSuccess&&e.jsx("output",{className:"text-body-sm text-ink",children:mn(o.data)?r("ui.hub.links.published",{item:t.name,source:y}):r("ui.hub.skills.policy_pending")}),e.jsxs(es,{children:[e.jsx(E,{ref:S,variant:"outline",disabled:o.isPending,onClick:()=>g(!1),children:r("ui.hub.subscriptions.cancel")}),e.jsx(E,{disabled:C||o.isPending||o.isSuccess,onClick:()=>o.mutate(),children:r("ui.hub.links.confirm_publish")})]})]})})]})}function Ce(t){return{description:t?.description??"",manager:t?.manager??"manager",members:(t?.members??[]).map(s=>({...s,count:ft(s),key:crypto.randomUUID()})),instructions:t?.instructions??"",project:t?.project??""}}function Ma(t,s){const n={};return s.description!==t.description&&(n.description=s.description),s.manager!==t.manager&&(n.manager=s.manager),JSON.stringify(s.members.map(at))!==JSON.stringify(t.members.map(at))&&(n.members=s.members.map(({key:a,...l})=>l)),s.instructions!==t.instructions&&(n.instructions=s.instructions),s.project!==t.project&&(n.project=s.project),n}function At(t,s,n){return(t.kind==="agent"?(s??[]).map(l=>l.name):(n??[]).map(l=>l.name)).includes(t.role)}function Pa(t){return(t??[]).reduce((s,n)=>s+ft(n),0)}function ft(t){return t.count||1}function gs(t){const s=Pa(t);return s===1?"1 member":`${s} members`}function Rt(t){const s=t.tier.value?r("ui.agents.models.reading.tier_layer",{tier:t.tier.value,source:r(fs(t.tier.source))}):null;return t.model.value?{value:t.model.value,layer:s}:t.available?{value:r("ui.agents.models.reading.session_model"),layer:s}:{value:r("ui.agents.models.reading.not_resolved"),layer:s}}function Tt(t){const{requested:s,value:n,source:a}=t.effort,l=r($a(a));return s==="auto"?{value:r("ui.agents.models.reading.effort_auto"),layer:r("ui.agents.models.source.model_default")}:n&&s&&n!==s?{value:r("ui.agents.models.reading.effort_clamped",{requested:s,value:n}),layer:l}:n?{value:n,layer:l}:{value:r("ui.agents.models.reading.effort_default"),layer:a==="model_default"?null:l}}function Ba(t){return t.tier.value?r(fs(t.tier.source)):null}function Dt(t,s,n){return t.layer?r(n,{value:t.value,layer:t.layer}):r(s,{value:t.value})}function $t(t){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"block truncate text-body-sm text-ink",title:t.value,children:t.value}),t.layer?e.jsx("span",{className:"block truncate text-meta text-ink-dim",title:t.layer,children:t.layer}):null]})}function Lt(t){return JSON.stringify({...t,members:t.members.map(at)})}function Ot(){return e.jsxs("colgroup",{children:[e.jsx("col",{}),e.jsx("col",{className:"w-24"}),e.jsx("col",{className:"w-16"})]})}function Ft({team:t,agents:s,teams:n,askEnabled:a,onSaved:l,onCancelCreate:u,onOpenAgent:g,onAskAgent:h,onDirtyChange:v,belowHeader:p}){const d=!t,[m,S]=i.useState(d),[x,j]=i.useState(t?.name??""),[k,T]=i.useState(()=>Ce(t)),[y,N]=i.useState(()=>Ce(t)),[_,$]=i.useState(!1),[A,f]=i.useState(null),[o,C]=i.useState(null),[R,w]=i.useState(!1),[B,P]=i.useState(!1),z=i.useRef(t?.definition_revision),te=i.useRef(null),ne=i.useRef(null),Z=i.useRef(null),M=i.useRef(null),q=i.useRef(!1);i.useEffect(()=>{us()&&requestAnimationFrame(()=>te.current?.focus())},[]);const se=dt();Te();const W=ct(),Y=t?.name??n?.[0]?.name??null,H=Es(Y,!!Y),Q=La(H),fe=Q==="available",I=H.data&&H.data.team===t?.name?H.data:null,F=d?!!(x.trim()||y.description||y.members.length):Lt(y)!==Lt(k);i.useEffect(()=>(v?.((d||m)&&F),()=>v?.(!1)),[v,d,m,F]),i.useEffect(()=>{if(m&&F)return;const b=Ce(t);T(b),N(b)},[t,m,F]),i.useEffect(()=>{if(!q.current)return;q.current=!1;const b=M.current;typeof b?.scrollIntoView=="function"&&b.scrollIntoView({block:"nearest"})});const V=()=>{if(d){u?.();return}S(!1),f(null),C(null),w(!1),z.current=t?.definition_revision;const b=Ce(t);T(b),N(b)};cs(()=>{if(R){w(!1);return}F?w(!0):V()},m);const ae=async b=>{if(b?.preventDefault(),!_){if(d&&!x.trim()){f("Give the team a name."),C("name"),Z.current?.focus();return}if(d&&/[\\/\s]/.test(x.trim())){f("Names cannot contain spaces or slashes."),C("name"),Z.current?.focus();return}if(d&&(n??[]).some(c=>c.name===x.trim())){f(`A team called “${x.trim()}” already exists. Open it to change it, or choose another name.`),C("name"),Z.current?.focus();return}if(d&&!y.instructions.trim()){f("Give the team instructions."),C("instructions"),ne.current?.focus();return}$(!0),f(null),C(null);try{const c=t?await X({op:"teams.update",name:t.name,requestId:crypto.randomUUID(),fields:Ma(k,y),expectedDefinitionRevision:z.current}):await X({op:"teams.create",requestId:crypto.randomUUID(),fields:{name:x,description:y.description,manager:y.manager,members:y.members.map(({key:L,...O})=>O),instructions:y.instructions,project:y.project}}),D=Ce(c);T(D),N(D),P(!1),z.current=c.definition_revision,S(!1),l(c.name),H.refetch(),W.invalidateQueries({queryKey:["desktop","team"]}),ke(`${d?"Created":"Saved"} ${c.name}.`),d&&ds(),requestAnimationFrame(()=>te.current?.focus())}catch(c){if(c?.code==="local-concurrent-edit"){P(!0),f(null),C(null);return}const L=Ae(c instanceof Error?c.message:"The team could not be saved.");f(L.message),C(L.field),Me(L.message)}finally{$(!1)}}},ie=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?{...L,...c}:L)})),re=(b,c)=>N(D=>({...D,members:D.members.map((L,O)=>O===b?Aa(L,c):L)})),_e=y.members.length?y.members:t?.members,ge=t?qt(t):"New team",Se=y.members.some(b=>b.kind==="team");return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("header",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-3",children:[e.jsxs("div",{className:"min-w-0 flex-[1_1_16rem] space-y-1",children:[e.jsx("h2",{ref:te,tabIndex:-1,title:ge,className:"truncate text-title focus:outline-none",children:ge}),t?e.jsxs("p",{className:"text-body-sm text-ink-muted",children:[gs(_e),Se?" · Includes a team":""]}):null]}),t&&!m?e.jsxs("div",{className:K("flex shrink-0 items-center gap-2",rs,a&&"-mr-3"),children:[e.jsx(E,{variant:"primary",onClick:()=>{ot.getState().stageDraft({kind:"team",name:t.name}),se("/chat")},children:"New team chat"}),e.jsx(Fa,{team:t}),e.jsx(E,{variant:"secondary",onClick:()=>{z.current=t.definition_revision,S(!0)},children:"Edit"}),a?e.jsx(E,{variant:"ghost",onClick:()=>h(`Change the team ${t.name}: `),children:"Ask for a change"}):null]}):null]}),A&&!o?e.jsxs(ce,{variant:"danger",role:"alert","data-testid":"team-save-error",children:[e.jsx(de,{children:"That did not save"}),e.jsx(me,{children:A})]}):null]}),p,m&&B?e.jsxs(ce,{variant:"warning","data-testid":"team-conflict",children:[e.jsx(de,{children:r("ui.hub.conflict.title")}),e.jsxs(me,{children:[e.jsx("span",{className:"block",children:r("ui.hub.conflict.body")}),e.jsx(E,{variant:"secondary",size:"sm",className:"mt-2",onClick:V,children:r("ui.hub.conflict.reload")})]})]}):null,e.jsx("form",{noValidate:!0,onSubmit:b=>{b.preventDefault(),ae(b)},className:"space-y-8",children:d||m?e.jsxs(e.Fragment,{children:[d?e.jsxs(U,{title:"Name",description:"How you and your chats will refer to this team.",children:[e.jsx(he,{label:"Team name",htmlFor:"team-name",error:o==="name"?A:null}),e.jsx(Ne,{ref:Z,id:"team-name","data-testid":"team-name-input",value:x,required:!0,maxLength:64,autoFocus:!0,"aria-invalid":o==="name",onChange:b=>j(b.target.value)})]}):null,e.jsx(U,{title:"Manager",description:"The agent that leads the chat and decides who works on what.",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{label:"Manager agent",htmlFor:"team-manager",error:o==="manager"?A:null}),e.jsx(Ue,{ariaLabel:"Manager agent",showLabel:!1,placeholder:"Choose a manager",busyLabel:"Loading agents",options:je(s,n),selected:je(s,n).find(b=>b.id===y.manager)??null,onSelect:b=>N(c=>({...c,manager:b.id})),onCustomSubmit:b=>N(c=>({...c,manager:b})),listNotice:"Agents and teams on this machine"}),je(s,n).some(b=>b.id===y.manager)?null:e.jsxs(oe,{variant:"warning","data-testid":"team-manager-missing",children:["Not found: ",y.manager]})]})}),e.jsxs(U,{title:"Members",description:"Who the manager can delegate to, how many of each, and the model each runs on.",children:[e.jsx("p",{"data-testid":"team-override-scope",className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),d&&!Y?e.jsx("p",{"data-testid":"team-override-no-probe",className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.no_probe_hint")}):null,Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null,e.jsxs("div",{className:"space-y-4",children:[y.members.map((b,c)=>{const D=!At(b,s,n),L=Ra(I??void 0,b);return e.jsxs("div",{className:"grid grid-cols-[minmax(0,1fr)_8rem_auto_auto] items-center gap-x-2 gap-y-1",children:[e.jsx("div",{className:"min-w-0",children:e.jsx(Ue,{ariaLabel:`Member ${c+1}`,showLabel:!1,placeholder:"Choose an agent or team",busyLabel:"Loading agents",options:[...je(s,n).filter(O=>b.kind==="team"?O.group==="Teams":O.group==="Agents")],selected:je(s,n).find(O=>O.id===b.role)??null,onSelect:O=>ie(c,{role:O.id,kind:O.group==="Teams"?"team":"agent"}),onCustomSubmit:O=>ie(c,{role:O})})}),e.jsxs($e,{value:b.kind,onValueChange:O=>ie(c,{kind:O}),children:[e.jsx(Le,{"aria-label":`Member ${c+1} kind`,className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:"agent",children:"Agent"}),e.jsx(xe,{value:"team",children:"Team"})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One fewer ${b.role}`,disabled:b.count<=1,onClick:()=>ie(c,{count:b.count-1}),children:e.jsx(ln,{"aria-hidden":"true"})}),e.jsx("span",{className:"min-w-6 text-center text-body-sm tabular-nums","aria-label":`${b.count} of ${b.role}`,children:b.count}),e.jsx(E,{variant:"secondary",size:"icon-sm","aria-label":`One more ${b.role}`,disabled:b.count>=16,onClick:()=>ie(c,{count:b.count+1}),children:e.jsx(Wt,{"aria-hidden":"true"})})]}),e.jsx(E,{variant:"ghost",onClick:()=>N(O=>({...O,members:O.members.filter((Ga,ps)=>ps!==c)})),children:"Remove"}),D?e.jsxs(oe,{variant:"warning",className:"col-span-full w-fit",children:["Not found: ",b.role]}):null,fe?e.jsxs("div",{className:"col-span-full grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)] items-end gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.tier_field")}),e.jsxs($e,{value:It(b.tier),onValueChange:O=>re(c,{tier:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.tier_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_tier")}),Sa.map(O=>e.jsx(xe,{value:O,children:O},O))]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-1",children:[e.jsx("span",{className:"text-meta text-ink-dim",children:r("ui.agents.models.override.effort_field")}),e.jsxs($e,{value:It(b.effort),onValueChange:O=>re(c,{effort:O}),children:[e.jsx(Le,{"aria-label":r("ui.agents.models.override.effort_label",{member:b.role||`Member ${c+1}`}),className:"w-full",children:e.jsx(Oe,{})}),e.jsxs(Fe,{children:[e.jsx(xe,{value:Re,children:r("ui.agents.models.override.inherit_effort")}),Ca.map(O=>e.jsx(xe,{value:O,children:O==="auto"?r("ui.agents.models.override.auto"):O},O))]})]})]})]}):null,L?e.jsxs("div",{className:"col-span-full flex flex-wrap items-baseline gap-x-3 gap-y-1 text-meta",children:[e.jsx("span",{className:"text-ink-dim",children:r("ui.agents.models.reading.saved_label")}),e.jsx("span",{className:"text-ink-muted",children:Dt({value:Rt(L).value,layer:Ba(L)},"ui.agents.models.reading.model_cell","ui.agents.models.reading.model_cell_layer")}),e.jsx("span",{className:"text-ink-muted",children:Dt(Tt(L),"ui.agents.models.reading.effort_cell","ui.agents.models.reading.effort_cell_layer")})]}):null,L&&!L.available?e.jsxs("div",{className:"col-span-full",children:[e.jsx("p",{"data-testid":"team-member-unavailable",className:"text-meta text-danger",children:r("ui.agents.models.reading.unavailable_editor",{member:L.role||`Member ${c+1}`,reason:L.reason})}),e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]}):null]},b.key)}),e.jsx(E,{ref:M,variant:"secondary",onClick:()=>{q.current=!0,N(b=>({...b,members:[...b.members,{role:"",count:1,kind:"agent",key:crypto.randomUUID()}]}))},children:"Add member"})]})]}),e.jsxs(U,{title:"Description",children:[e.jsx(he,{label:"What this team is for",htmlFor:"team-description",error:o==="description"?A:null}),e.jsx(Ne,{id:"team-description",value:y.description,onChange:b=>N(c=>({...c,description:b.target.value}))})]}),e.jsxs(U,{title:"Collaboration instructions",children:[o==="instructions"?e.jsx("p",{className:"text-meta text-danger",role:"alert","data-testid":"team-instructions-error",children:A}):null,e.jsx(st,{ref:ne,"aria-label":"Collaboration instructions","aria-invalid":o==="instructions",className:"min-h-36",maxLength:8e3,value:y.instructions,onChange:b=>N(c=>({...c,instructions:b.target.value}))})]}),e.jsx(U,{title:"Project brief",children:e.jsx(st,{"aria-label":"Project brief",className:"min-h-36",maxLength:8e3,value:y.project,onChange:b=>N(c=>({...c,project:b.target.value}))})}),e.jsx(ht,{submit:!0,confirming:R,onConfirmingChange:w,dirty:F,pending:_,saveLabel:d?"Create team":"Save changes",pendingLabel:d?"Creating…":"Saving…",dirtyHint:"Discard this team?",onSave:()=>void ae(),onCancel:V})]}):e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Manager",children:e.jsxs(We,{className:"table-fixed","aria-label":"Manager: the agent that leads the chat",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:e.jsxs(be,{className:"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(E,{variant:"link",className:K("-my-0.5 min-w-0 justify-start truncate",ut),onClick:()=>g(y.manager),children:y.manager}),je(s,n).some(b=>b.id===y.manager)?null:e.jsx(oe,{variant:"warning","data-testid":"team-manager-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:"Agent"}),e.jsx(le,{})]})})]})}),e.jsxs(U,{title:"Members",children:[e.jsxs(We,{className:"table-fixed","aria-label":"Members",children:[e.jsx(Ot,{}),e.jsx(Ve,{className:"sr-only",children:e.jsxs(be,{children:[e.jsx(ue,{children:"Member"}),e.jsx(ue,{children:"Type"}),e.jsx(ue,{children:"Count"})]})}),e.jsx(Ge,{children:(t?.members??[]).map(b=>e.jsxs(be,{className:"last:border-0",children:[e.jsx(le,{className:"px-0 py-2 text-ink",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate",children:b.role}),At(b,s,n)?null:e.jsx(oe,{variant:"warning","data-testid":"team-member-missing",children:"Not found"})]})}),e.jsx(le,{className:"px-2 py-2 text-ink-dim text-meta",children:b.kind==="team"?"Team":"Agent"}),e.jsx(le,{className:"px-0 py-2 text-right text-ink-muted tabular-nums",children:`×${ft(b)}`})]},`${b.kind}:${b.role}`))})]}),Q==="unavailable"?e.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[e.jsx("p",{className:"text-meta text-danger",children:r("ui.agents.models.reading.read_failed")}),e.jsx(E,{variant:"ghost",size:"sm",onClick:()=>void H.refetch(),children:r("ui.agents.models.reading.try_again")})]}):null]}),fe&&I?.members.length?e.jsxs(U,{title:r("ui.agents.models.reading.title"),description:r("ui.agents.models.reading.description"),children:[e.jsx("p",{className:"text-meta text-ink-muted",children:r("ui.agents.models.override.scope_hint")}),H.isFetching?e.jsx("p",{"data-testid":"team-effective-refreshing",className:"text-meta text-ink-dim",children:r("ui.agents.models.reading.refreshing")}):null,e.jsxs(We,{className:K("table-fixed",H.isFetching&&"opacity-60"),"aria-label":r("ui.agents.models.reading.title"),children:[e.jsxs("colgroup",{children:[e.jsx("col",{className:"w-24"}),e.jsx("col",{}),e.jsx("col",{className:"w-32"})]}),e.jsx(Ve,{children:e.jsxs(be,{children:[e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.member_col")}),e.jsx(ue,{className:"px-2",children:r("ui.agents.models.reading.model_col")}),e.jsx(ue,{className:"px-0",children:r("ui.agents.models.reading.effort_col")})]})}),e.jsx(Ge,{children:I.members.map(b=>e.jsxs(i.Fragment,{children:[e.jsxs(be,{className:b.available?"last:border-0":"border-0",children:[e.jsx(le,{className:"px-0 py-2",children:e.jsx("span",{className:"block truncate text-body-sm text-ink",title:b.role,children:b.role})}),e.jsx(le,{className:"px-2 py-2",children:$t(Rt(b))}),e.jsx(le,{className:"px-0 py-2",children:$t(Tt(b))})]}),b.available?null:e.jsx(be,{className:"last:border-0",children:e.jsxs(le,{colSpan:3,className:"px-0 pb-2",children:[e.jsx("span",{"data-testid":"team-effective-unavailable",className:"block text-meta text-danger",children:r("ui.agents.models.reading.unavailable",{member:b.role,reason:b.reason})}),e.jsx("span",{className:"block text-meta text-ink-muted",children:r("ui.agents.models.reading.unavailable_hint")})]})})]},`${b.kind}:${b.role}`))})]})]}):null,e.jsx(U,{title:"What it is for",children:e.jsx(ye,{text:t?.description??"",empty:"No description yet."})}),t?.instructions?e.jsx(U,{title:"Collaboration instructions",children:e.jsx(ye,{text:t.instructions})}):null,t?.project?e.jsx(rt,{summary:"Project brief",children:e.jsx(ye,{text:t.project})}):null]})})]})}function je(t,s){return[...(t??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Agents"})),...(s??[]).map(n=>({id:n.name,name:n.name,description:n.description,group:"Teams"}))]}const Ua=i.lazy(()=>$s(()=>import("./legacy-agents-page-oa1T18xF.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17]),import.meta.url).then(t=>({default:t.LegacyAgentsPage}))),Mt=/^subagents\.models\.([^.]+)$/,qa=["lo","med","hi"],Xe={all:"All",custom:"Custom",installed:"Installed",builtin:"Built-in"};function za(t){return!t||t.getAttribute("role")!=="tab"||t.getAttribute("aria-selected")==="true"?t:t.closest('[role="tablist"]')?.querySelector('[role="tab"][aria-selected="true"]')??null}function ni(){const{agentId:t}=Qs(),[s,n]=Ut(),a=s.get("kind")==="team"||s.get("create")==="team",l=s.has("create"),u=s.get("name"),g=s.get("duplicate"),h=ze(),v=ee(h.data,a?"team_catalogue":"profile_catalogue"),p=Is(v),d=As(v),m=v&&!!u&&!l,S=pt(a?null:u,m),x=Rs(a?u:null,m),j=pt(a?null:g,!!g),[k,T]=i.useState(""),[y,N]=i.useState("all"),[_,$]=i.useState(null),[A,f]=i.useState(null),o=ca(),C=J(c=>c.marks),R=J(c=>c.clearMark),w=Gt({queryKey:["desktop","settings","effort-tiers"],enabled:v,queryFn:()=>X({op:"settings.list"}),staleTime:6e4}),B=i.useMemo(()=>(w.data?.settings??[]).filter(c=>{const D=c.key.match(Mt)?.[1];return!D||!qa.includes(D)?!1:typeof c.value=="string"&&c.value.trim().length>0}).map(c=>c.key.match(Mt)?.[1]).filter(c=>!!c),[w.data]),P=zs(),z=i.useCallback(c=>Hs(c,P),[P]),te=i.useMemo(()=>Wa(p.data,k,y,z),[p.data,k,y,z]),ne=i.useMemo(()=>Va(d.data,k),[d.data,k]),Z=a?ne:te,M=u??null,[q,se]=i.useState(null);q!==null&&q.name!==M&&se(null);const W=i.useCallback(c=>{const D=new URLSearchParams;(c.kind??(a?"team":"agent"))==="team"&&D.set("kind","team"),c.name&&D.set("name",c.name),c.create!==null&&c.create!==void 0&&D.set("create",c.create),c.duplicate&&D.set("duplicate",c.duplicate),$(null),n(D)},[a,n]),Y=`${a?"team":"agent"}:${l??""}:${M??""}`,H=i.useCallback(c=>f(c?Y:null),[Y]),Q=A!==null&&A===Y,fe=(c,D,L)=>e.jsxs(e.Fragment,{children:[e.jsx(_a,{kind:c,name:D,localId:L,enabled:ee(h.data,"hub_links")}),e.jsx(hn,{kind:c,name:D,enabled:ee(h.data,"hub_updates")&&!ee(h.data,"hub_links")})]}),I=i.useRef(null),F=i.useRef(null),V=i.useRef(null),G=i.useCallback(c=>{if(Q){const D=F.current,L=document.activeElement;I.current=D?.isConnected&&D.closest("form")?D:L instanceof HTMLElement?L:null,$(c);return}W(c)},[Q,W]),ae=i.useCallback(()=>{$(null);const c=I.current;requestAnimationFrame(()=>{const D=za(c);D?.isConnected&&D.focus()})},[]),ie=_!==null;i.useEffect(()=>{if(!ie)return;_t(!0,()=>$(null)),V.current?.focus();const c=requestAnimationFrame(()=>{const L=V.current?.closest('[role="alertdialog"]');L&&!L.contains(document.activeElement)&&V.current?.focus()}),D=L=>{L.key!=="Escape"||L.defaultPrevented||(L.preventDefault(),ae())};return window.addEventListener("keydown",D),()=>{cancelAnimationFrame(c),window.removeEventListener("keydown",D),_t(!1)}},[ie,ae]),i.useEffect(()=>{const c=D=>{D.key!=="Escape"||D.defaultPrevented||window.matchMedia("(max-width: 999px)").matches&&(!M&&!l||Q||ie||(D.preventDefault(),G({name:null})))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[G,M,l,Q,ie]),i.useEffect(()=>{const D=J.getState().about;if(!D)return;const L=a?"team":"agent";M&&D.kind===L&&D.name===M||(o.setAbout(null),En(D))},[M,a,o]),i.useEffect(()=>{M&&R({kind:a?"team":"agent",name:M})},[M,a,R]);const re=()=>{p.refetch(),d.refetch(),M&&(a?x.refetch():S.refetch())};if(t)return e.jsx(i.Suspense,{fallback:e.jsx("p",{className:"p-6 text-body",children:"Loading saved agent…"}),children:e.jsx(Ua,{})});const _e=a?x.error:S.error,ge=a?d.error:p.error,Se=v&&!ge&&!l&&!M,b=a?x.isLoading:S.isLoading;return e.jsxs("div",{"data-glass-region":"canvas","data-glass-split":"",className:"panel-flush flex min-h-0 flex-1 bg-canvas text-ink",children:[e.jsxs("aside",{"data-open":M?"true":void 0,"data-glass-region":"page-sidebar",className:"panel-top-pad flex w-72 shrink-0 flex-col gap-3 bg-surface px-4 pb-4 max-[999px]:data-[open=true]:hidden",children:[e.jsx("h1",{className:"pt-4 text-heading",children:"Agents and teams"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(on,{value:a?"team":"agent",onValueChange:c=>G({kind:c,name:null}),children:e.jsxs(cn,{"aria-label":"Browse definitions by type",className:"w-full",children:[e.jsxs(bt,{value:"agent",className:"flex-1","data-testid":"agents-tab",children:[e.jsx(Ks,{className:"size-3.5"}),"Agents",p.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:p.data.length}):null]}),e.jsxs(bt,{value:"team",className:"flex-1","data-testid":"teams-tab",children:[e.jsx(Ts,{className:"size-3.5"}),"Teams",d.data?e.jsx("span",{className:"min-w-[2ch] font-normal text-ink-dim tabular-nums",children:d.data.length}):null]})]})}),e.jsxs("div",{className:"relative",children:[e.jsx(Ds,{"aria-hidden":"true",className:"pointer-events-none absolute top-2 start-2 size-4 text-ink-dim"}),e.jsx(Ne,{className:"ps-8",type:"search","aria-label":"Search agents and teams",placeholder:a?"Search teams":"Search agents",value:k,onChange:c=>T(c.target.value)})]}),!a&&p.data?e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:"Show definitions owned by"}),e.jsx("div",{"data-glass-well":"",className:"flex gap-0.5 rounded-md bg-sunken p-0.5",children:Object.keys(Xe).map(c=>e.jsx(E,{variant:"ghost",size:"sm","aria-pressed":y===c,onClick:()=>N(c),className:K("flex-1",y===c&&Vt),children:Xe[c]},c))})]}):null]}),e.jsx("div",{"data-lo-pane-edge-cues":!0,className:"min-h-0 flex-1 overflow-y-auto",children:ge?null:!p.data&&!d.data?e.jsx(ha,{}):Z.length===0?e.jsx("p",{className:"px-1 py-2 text-body-sm text-ink-muted",children:k?`Nothing matches “${k}”.`:a?"No teams yet. Ask for one below, or add one by hand.":y==="all"?"No agents yet. Ask for one below, or add one by hand.":`No ${Xe[y].toLowerCase()} agents.`}):e.jsx(Ka,{rows:Z,name:l?null:M,teamMode:a,printName:z,marked:new Map(C.map(c=>[In(c),c.created])),onOpen:c=>G({name:c})})}),e.jsxs(E,{variant:"ghost",className:"w-full justify-start",disabled:!v,onClick:()=>G({create:a?"team":"agent"}),children:[e.jsx(Wt,{className:"size-4"}),a?"Add team manually":"Add agent manually"]})]}),e.jsxs("main",{"data-glass-region":"canvas-content",className:"panel-top-pad flex min-w-0 flex-1 flex-col",children:[M||l?e.jsx("div",{className:"flex shrink-0 items-center border-hairline border-b px-4 py-2 min-[1000px]:hidden",children:e.jsxs(E,{variant:"ghost",size:"sm",onClick:()=>G({name:null}),children:[e.jsx(Ws,{className:"size-4"}),"Back to the list"]})}):null,e.jsx("div",{"data-agents-pane":!0,onFocus:c=>{c.target instanceof HTMLElement&&(F.current=c.target)},"data-lo-pane-edge-cues":!0,className:K("min-h-0 flex-1 overflow-auto",Se?void 0:"px-4 pt-6 [scroll-padding-bottom:calc(var(--lo-pane-footer-h)+var(--lo-pane-footer-cue-h)+4px)] [scrollbar-gutter:stable_both-edges]"),children:Se?e.jsx(Ha,{teamMode:a,run:o,onAddManually:()=>G({create:a?"team":"agent"})}):e.jsx("div",{className:it,children:e.jsx("div",{className:Ie,children:v?ge?e.jsx(Ct,{title:a?"Teams could not be read":"Agents could not be read",what:ge instanceof Error?ge.message:"The request did not complete.",meaning:"Nothing is lost. This is a read that failed — the backend answered an error, which is different from the backend being out of date.",onRetry:re,retrying:p.isFetching||d.isFetching}):M&&b?e.jsx(St,{}):M&&_e?e.jsx(Ct,{title:a?`“${M}” could not be read`:`“${M}” could not be read`,what:_e instanceof Error?_e.message:"The request did not complete.",meaning:"The definition may have been removed, or the backend refused the read.",onRetry:()=>{S.refetch(),x.refetch()},retrying:S.isFetching||x.isFetching}):l&&a?e.jsx(Ft,{agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancelCreate:()=>W({name:null}),onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:u??""},c)}},"team:create"):l&&g&&j.isLoading?e.jsx(St,{}):l?e.jsx(ya,{initial:j.data??null,takenNames:(p.data??[]).map(c=>c.name),effortTiers:B,onDirtyChange:H,onSaved:c=>{re(),W({name:c})},onCancel:()=>W({name:null})},"agent:create"):a&&x.data?e.jsx(Ft,{team:x.data,agents:p.data,teams:d.data,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("team",x.data.name,x.data.id),onSaved:c=>{re(),W({name:c})},onOpenAgent:c=>G({kind:"agent",name:c}),onAskAgent:c=>{Ye(o,{kind:"team",name:x.data?.name??""},c)}},ua(x.data)):!a&&S.data?e.jsx(va,{profile:S.data,displayedName:z(S.data.name),classNotice:q?.name===S.data.name?q.copy:null,onClassNotice:c=>se(c?{name:S.data.name,copy:c}:null),teams:d.data,effortTiers:B,askEnabled:o.enabled,onDirtyChange:H,belowHeader:fe("agent",S.data.name,S.data.agent_id??void 0),onSaved:c=>{re(),W({name:c})},onDuplicate:c=>G({create:"agent",duplicate:c.name}),onOpenTeam:c=>G({kind:"team",name:c}),onAskAgent:c=>{Ye(o,{kind:"agent",name:S.data?.name??""},c)}},da(S.data)):M?e.jsx(ve,{className:"h-6 w-40"}):null:e.jsxs(ce,{variant:h.isLoading?"neutral":"warning",className:"max-w-xl",children:[e.jsx(de,{children:h.isLoading?"Connecting to the backend":h.error?"The backend could not be reached":"Reusable agents need a newer backend"}),e.jsx(me,{children:h.isLoading?"Loading what this backend can do…":h.error?h.error.message:"Update the backend to manage reusable agents and teams. Saved chats are unchanged."})]})})})}),_?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-hairline border-t bg-surface px-4 py-3",role:"alertdialog","aria-label":"Discard your unsaved changes?",children:[e.jsx("span",{className:"text-body-sm text-ink",children:a?"Discard your unsaved changes to this team?":"Discard your unsaved changes to this agent?"}),e.jsx(E,{variant:"danger",onClick:()=>{f(null),W(_)},children:"Discard changes"}),e.jsx(E,{ref:V,variant:"ghost",onClick:ae,children:"Keep editing"})]}):null,Se?null:e.jsx("div",{className:"shrink-0 bg-canvas",children:e.jsx(ss,{run:o,about:o.about,onClearAbout:()=>o.setAbout(null),blockedReason:Q?"Finish or cancel your edit first.":null})})]})]})}function Ha({teamMode:t,run:s,onAddManually:n}){const a=K(it,Pt);return e.jsxs("div",{className:"flex min-h-full flex-col justify-center space-y-4 pb-12",children:[e.jsx("div",{className:a,children:e.jsxs("div",{className:K(Ie,"space-y-2"),children:[e.jsx("h2",{className:"text-title",children:t?"Ask for a team":"Ask for an agent"}),e.jsx("p",{className:"text-body text-ink-muted",children:t?"A team has one agent that leads the chat and members it can hand work to. Describe what you want and a configuration run sets it up.":"An agent is a reusable set of instructions you can start a chat with, or let other agents call on. Describe what you want and a configuration run sets it up."})]})}),e.jsx(ss,{run:s,hero:!0,about:s.about,onClearAbout:()=>s.setAbout(null)}),e.jsx("div",{className:a,children:e.jsx("div",{className:Ie,children:e.jsx(E,{variant:"ghost",className:"-ml-3",onClick:n,children:t?"Or add a team by hand":"Or add an agent by hand"})})})]})}function Ka({rows:t,name:s,teamMode:n,marked:a,printName:l,onOpen:u}){const g=i.useRef(new Map),[h,v]=i.useState(s),p=m=>"members"in m?qt(m):l(m.name),d=(m,S)=>{const x=t.findIndex(k=>k.name===m);if(x<0)return;const j=t[Math.min(t.length-1,Math.max(0,x+S))];j&&(v(j.name),g.current.get(j.name)?.focus())};return e.jsx("ul",{"aria-label":n?"Teams":"Agents",className:"space-y-0.5",children:t.map(m=>{const S="source"in m,x=a.get(`${n?"team":"agent"}:${m.name}`);return e.jsx("li",{children:e.jsxs("button",{ref:j=>{j?g.current.set(m.name,j):g.current.delete(m.name)},type:"button","aria-current":m.name===s?"true":void 0,tabIndex:m.name===(h??t[0]?.name)?0:-1,"data-testid":`roster-row-${m.name}`,title:m.description?`${p(m)} - ${m.description}`:p(m),className:K("flex min-h-12 w-full flex-col items-start gap-0.5 rounded-md px-2 py-1.5 text-start hover:bg-row-hover",m.name===s&&Vt),onFocus:()=>v(m.name),onClick:()=>u(m.name),onKeyDown:j=>{j.key==="ArrowDown"?(j.preventDefault(),d(m.name,1)):j.key==="ArrowUp"?(j.preventDefault(),d(m.name,-1)):j.key==="Home"?(j.preventDefault(),d(m.name,-t.length)):j.key==="End"&&(j.preventDefault(),d(m.name,t.length))},children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-body-sm text-ink",children:p(m)}),x!==void 0?e.jsx(oe,{variant:"attention","data-testid":"roster-row-updated",children:x?"New":"Updated"}):null,e.jsx("span",{className:"ms-auto shrink-0 text-meta text-ink-dim tabular-nums",children:"members"in m?gs(m.members):e.jsx(ma,{source:m.source,appearance:"text"})})]}),e.jsxs("span",{className:"flex min-h-lh w-full items-baseline text-meta text-ink-muted",children:[S&&De(m)==="proactive"?e.jsxs("span",{className:"me-1 shrink-0","data-testid":"roster-row-proactive",children:[e.jsx("span",{className:"text-ink",children:ns.proactive}),e.jsx("span",{className:"text-ink-dim",children:" ·"})]}):null,m.description?e.jsx("span",{className:"min-w-0 flex-1 truncate",children:m.description}):e.jsx("span",{className:"min-w-0 flex-1 truncate text-ink-dim",children:"No description"})]})]})},m.name)})})}function Wa(t,s,n,a){const l=s.trim().toLowerCase();return(t??[]).filter(u=>n==="builtin"&&u.source!=="builtin"||n==="installed"&&u.source!=="installed"||n==="custom"&&u.source!=="custom"?!1:l?a(u.name).toLowerCase().includes(l)||u.name.toLowerCase().includes(l)||(u.description??"").toLowerCase().includes(l):!0)}function Va(t,s){const n=s.trim().toLowerCase();return(t??[]).filter(a=>!n||a.name.toLowerCase().includes(n)||(a.label??"").toLowerCase().includes(n)||(a.description??"").toLowerCase().includes(n))}export{ni as AgentsPage};
@@ -1 +0,0 @@
1
- import{j as r}from"./index-B4nU7SY-.js";import{B as o}from"./index-C1xioNnx.js";import"./messages-Bsgf6o-p.js";import"./error-boundary-Bq37z0Vv.js";import"./path-utils-Dy8qomEz.js";import"./conversation-input-sync-BNDyyAZz.js";import"./console-mirror-BiNs1Fcs.js";const u=()=>r.jsx(o,{tabScope:"all",requestScope:"all",hostSessionId:null,isRoutePage:!0,surfaceTag:"browser-route",dockSurfaceTag:"browser-approvals-dock"});export{u as BrowserPage};
@@ -1 +0,0 @@
1
- import{U as a,C as n}from"./mermaid.core-CrjcyFIw.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-A2AXSNBT-DT1C_gy2.js";import{_ as i}from"./mermaid.core-CrjcyFIw.js";import"./chunk-RZ5BOZE2-BEbcJaEy.js";import"./conversation-input-sync-BNDyyAZz.js";import"./index-B4nU7SY-.js";import"./messages-Bsgf6o-p.js";import"./path-utils-Dy8qomEz.js";import"./error-boundary-Bq37z0Vv.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-A2AXSNBT-DT1C_gy2.js";import{_ as i}from"./mermaid.core-CrjcyFIw.js";import"./chunk-RZ5BOZE2-BEbcJaEy.js";import"./conversation-input-sync-BNDyyAZz.js";import"./index-B4nU7SY-.js";import"./messages-Bsgf6o-p.js";import"./path-utils-Dy8qomEz.js";import"./error-boundary-Bq37z0Vv.js";var f={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{f as diagram};
@@ -1 +0,0 @@
1
- import{b as r}from"./_baseUniq-D5X85E0S.js";var e=4;function a(o){return r(o,e)}export{a as c};
@@ -1 +0,0 @@
1
- import{g as b,t as d,c as w,n as N,b as Y,d as F,f as S,e as H}from"./en-US-CHJkXXr4.js";function y(n,t){const e=b(),r=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??e.weekStartsOn??e.locale?.options?.weekStartsOn??0,a=d(n,t?.in),s=a.getDay(),i=(s<r?7:0)+s-r;return a.setDate(a.getDate()-i),a.setHours(0,0,0,0),a}function O(n,t){return y(n,{...t,weekStartsOn:1})}function W(n,t){const e=d(n,t?.in),r=e.getFullYear(),a=w(e,0);a.setFullYear(r+1,0,4),a.setHours(0,0,0,0);const s=O(a),i=w(e,0);i.setFullYear(r,0,4),i.setHours(0,0,0,0);const f=O(i);return e.getTime()>=s.getTime()?r+1:e.getTime()>=f.getTime()?r:r-1}function D(n,t){const e=d(n,t?.in);return e.setHours(0,0,0,0),e}function v(n,t,e){const[r,a]=N(e?.in,n,t),s=D(r),i=D(a),f=+s-Y(s),h=+i-Y(i);return Math.round((f-h)/F)}function C(n,t){const e=W(n,t),r=w(n,0);return r.setFullYear(e,0,4),r.setHours(0,0,0,0),O(r)}function G(n){return n instanceof Date||typeof n=="object"&&Object.prototype.toString.call(n)==="[object Date]"}function Q(n){return!(!G(n)&&typeof n!="number"||isNaN(+d(n)))}function _(n,t){const e=d(n,t?.in);return e.setFullYear(e.getFullYear(),0,1),e.setHours(0,0,0,0),e}function B(n,t){const e=d(n,t?.in);return v(e,_(e))+1}function X(n,t){const e=d(n,t?.in),r=+O(e)-+C(e);return Math.round(r/S)+1}function E(n,t){const e=d(n,t?.in),r=e.getFullYear(),a=b(),s=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,i=w(t?.in||n,0);i.setFullYear(r+1,0,s),i.setHours(0,0,0,0);const f=y(i,t),h=w(t?.in||n,0);h.setFullYear(r,0,s),h.setHours(0,0,0,0);const x=y(h,t);return+e>=+f?r+1:+e>=+x?r:r-1}function L(n,t){const e=b(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??e.firstWeekContainsDate??e.locale?.options?.firstWeekContainsDate??1,a=E(n,t),s=w(t?.in||n,0);return s.setFullYear(a,0,r),s.setHours(0,0,0,0),y(s,t)}function I(n,t){const e=d(n,t?.in),r=+y(e,t)-+L(e,t);return Math.round(r/S)+1}function o(n,t){const e=n<0?"-":"",r=Math.abs(n).toString().padStart(t,"0");return e+r}const m={y(n,t){const e=n.getFullYear(),r=e>0?e:1-e;return o(t==="yy"?r%100:r,t.length)},M(n,t){const e=n.getMonth();return t==="M"?String(e+1):o(e+1,2)},d(n,t){return o(n.getDate(),t.length)},a(n,t){const e=n.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return e.toUpperCase();case"aaa":return e;case"aaaaa":return e[0];case"aaaa":default:return e==="am"?"a.m.":"p.m."}},h(n,t){return o(n.getHours()%12||12,t.length)},H(n,t){return o(n.getHours(),t.length)},m(n,t){return o(n.getMinutes(),t.length)},s(n,t){return o(n.getSeconds(),t.length)},S(n,t){const e=t.length,r=n.getMilliseconds(),a=Math.trunc(r*Math.pow(10,e-3));return o(a,t.length)}},g={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},M={G:function(n,t,e){const r=n.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return e.era(r,{width:"abbreviated"});case"GGGGG":return e.era(r,{width:"narrow"});case"GGGG":default:return e.era(r,{width:"wide"})}},y:function(n,t,e){if(t==="yo"){const r=n.getFullYear(),a=r>0?r:1-r;return e.ordinalNumber(a,{unit:"year"})}return m.y(n,t)},Y:function(n,t,e,r){const a=E(n,r),s=a>0?a:1-a;if(t==="YY"){const i=s%100;return o(i,2)}return t==="Yo"?e.ordinalNumber(s,{unit:"year"}):o(s,t.length)},R:function(n,t){const e=W(n);return o(e,t.length)},u:function(n,t){const e=n.getFullYear();return o(e,t.length)},Q:function(n,t,e){const r=Math.ceil((n.getMonth()+1)/3);switch(t){case"Q":return String(r);case"QQ":return o(r,2);case"Qo":return e.ordinalNumber(r,{unit:"quarter"});case"QQQ":return e.quarter(r,{width:"abbreviated",context:"formatting"});case"QQQQQ":return e.quarter(r,{width:"narrow",context:"formatting"});case"QQQQ":default:return e.quarter(r,{width:"wide",context:"formatting"})}},q:function(n,t,e){const r=Math.ceil((n.getMonth()+1)/3);switch(t){case"q":return String(r);case"qq":return o(r,2);case"qo":return e.ordinalNumber(r,{unit:"quarter"});case"qqq":return e.quarter(r,{width:"abbreviated",context:"standalone"});case"qqqqq":return e.quarter(r,{width:"narrow",context:"standalone"});case"qqqq":default:return e.quarter(r,{width:"wide",context:"standalone"})}},M:function(n,t,e){const r=n.getMonth();switch(t){case"M":case"MM":return m.M(n,t);case"Mo":return e.ordinalNumber(r+1,{unit:"month"});case"MMM":return e.month(r,{width:"abbreviated",context:"formatting"});case"MMMMM":return e.month(r,{width:"narrow",context:"formatting"});case"MMMM":default:return e.month(r,{width:"wide",context:"formatting"})}},L:function(n,t,e){const r=n.getMonth();switch(t){case"L":return String(r+1);case"LL":return o(r+1,2);case"Lo":return e.ordinalNumber(r+1,{unit:"month"});case"LLL":return e.month(r,{width:"abbreviated",context:"standalone"});case"LLLLL":return e.month(r,{width:"narrow",context:"standalone"});case"LLLL":default:return e.month(r,{width:"wide",context:"standalone"})}},w:function(n,t,e,r){const a=I(n,r);return t==="wo"?e.ordinalNumber(a,{unit:"week"}):o(a,t.length)},I:function(n,t,e){const r=X(n);return t==="Io"?e.ordinalNumber(r,{unit:"week"}):o(r,t.length)},d:function(n,t,e){return t==="do"?e.ordinalNumber(n.getDate(),{unit:"date"}):m.d(n,t)},D:function(n,t,e){const r=B(n);return t==="Do"?e.ordinalNumber(r,{unit:"dayOfYear"}):o(r,t.length)},E:function(n,t,e){const r=n.getDay();switch(t){case"E":case"EE":case"EEE":return e.day(r,{width:"abbreviated",context:"formatting"});case"EEEEE":return e.day(r,{width:"narrow",context:"formatting"});case"EEEEEE":return e.day(r,{width:"short",context:"formatting"});case"EEEE":default:return e.day(r,{width:"wide",context:"formatting"})}},e:function(n,t,e,r){const a=n.getDay(),s=(a-r.weekStartsOn+8)%7||7;switch(t){case"e":return String(s);case"ee":return o(s,2);case"eo":return e.ordinalNumber(s,{unit:"day"});case"eee":return e.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return e.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return e.day(a,{width:"short",context:"formatting"});case"eeee":default:return e.day(a,{width:"wide",context:"formatting"})}},c:function(n,t,e,r){const a=n.getDay(),s=(a-r.weekStartsOn+8)%7||7;switch(t){case"c":return String(s);case"cc":return o(s,t.length);case"co":return e.ordinalNumber(s,{unit:"day"});case"ccc":return e.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return e.day(a,{width:"narrow",context:"standalone"});case"cccccc":return e.day(a,{width:"short",context:"standalone"});case"cccc":default:return e.day(a,{width:"wide",context:"standalone"})}},i:function(n,t,e){const r=n.getDay(),a=r===0?7:r;switch(t){case"i":return String(a);case"ii":return o(a,t.length);case"io":return e.ordinalNumber(a,{unit:"day"});case"iii":return e.day(r,{width:"abbreviated",context:"formatting"});case"iiiii":return e.day(r,{width:"narrow",context:"formatting"});case"iiiiii":return e.day(r,{width:"short",context:"formatting"});case"iiii":default:return e.day(r,{width:"wide",context:"formatting"})}},a:function(n,t,e){const a=n.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return e.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"aaa":return e.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return e.dayPeriod(a,{width:"narrow",context:"formatting"});case"aaaa":default:return e.dayPeriod(a,{width:"wide",context:"formatting"})}},b:function(n,t,e){const r=n.getHours();let a;switch(r===12?a=g.noon:r===0?a=g.midnight:a=r/12>=1?"pm":"am",t){case"b":case"bb":return e.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"bbb":return e.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return e.dayPeriod(a,{width:"narrow",context:"formatting"});case"bbbb":default:return e.dayPeriod(a,{width:"wide",context:"formatting"})}},B:function(n,t,e){const r=n.getHours();let a;switch(r>=17?a=g.evening:r>=12?a=g.afternoon:r>=4?a=g.morning:a=g.night,t){case"B":case"BB":case"BBB":return e.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"BBBBB":return e.dayPeriod(a,{width:"narrow",context:"formatting"});case"BBBB":default:return e.dayPeriod(a,{width:"wide",context:"formatting"})}},h:function(n,t,e){if(t==="ho"){let r=n.getHours()%12;return r===0&&(r=12),e.ordinalNumber(r,{unit:"hour"})}return m.h(n,t)},H:function(n,t,e){return t==="Ho"?e.ordinalNumber(n.getHours(),{unit:"hour"}):m.H(n,t)},K:function(n,t,e){const r=n.getHours()%12;return t==="Ko"?e.ordinalNumber(r,{unit:"hour"}):o(r,t.length)},k:function(n,t,e){let r=n.getHours();return r===0&&(r=24),t==="ko"?e.ordinalNumber(r,{unit:"hour"}):o(r,t.length)},m:function(n,t,e){return t==="mo"?e.ordinalNumber(n.getMinutes(),{unit:"minute"}):m.m(n,t)},s:function(n,t,e){return t==="so"?e.ordinalNumber(n.getSeconds(),{unit:"second"}):m.s(n,t)},S:function(n,t){return m.S(n,t)},X:function(n,t,e){const r=n.getTimezoneOffset();if(r===0)return"Z";switch(t){case"X":return P(r);case"XXXX":case"XX":return l(r);case"XXXXX":case"XXX":default:return l(r,":")}},x:function(n,t,e){const r=n.getTimezoneOffset();switch(t){case"x":return P(r);case"xxxx":case"xx":return l(r);case"xxxxx":case"xxx":default:return l(r,":")}},O:function(n,t,e){const r=n.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+p(r,":");case"OOOO":default:return"GMT"+l(r,":")}},z:function(n,t,e){const r=n.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+p(r,":");case"zzzz":default:return"GMT"+l(r,":")}},t:function(n,t,e){const r=Math.trunc(+n/1e3);return o(r,t.length)},T:function(n,t,e){return o(+n,t.length)}};function p(n,t=""){const e=n>0?"-":"+",r=Math.abs(n),a=Math.trunc(r/60),s=r%60;return s===0?e+String(a):e+String(a)+t+o(s,2)}function P(n,t){return n%60===0?(n>0?"-":"+")+o(Math.abs(n)/60,2):l(n,t)}function l(n,t=""){const e=n>0?"-":"+",r=Math.abs(n),a=o(Math.trunc(r/60),2),s=o(r%60,2);return e+a+t+s}const T=(n,t)=>{switch(n){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});case"PPPP":default:return t.date({width:"full"})}},q=(n,t)=>{switch(n){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});case"pppp":default:return t.time({width:"full"})}},R=(n,t)=>{const e=n.match(/(P+)(p+)?/)||[],r=e[1],a=e[2];if(!a)return T(n,t);let s;switch(r){case"P":s=t.dateTime({width:"short"});break;case"PP":s=t.dateTime({width:"medium"});break;case"PPP":s=t.dateTime({width:"long"});break;case"PPPP":default:s=t.dateTime({width:"full"});break}return s.replace("{{date}}",T(r,t)).replace("{{time}}",q(a,t))},$={p:q,P:R},j=/^D+$/,V=/^Y+$/,A=["D","DD","YY","YYYY"];function J(n){return j.test(n)}function K(n){return V.test(n)}function U(n,t,e){const r=Z(n,t,e);if(console.warn(r),A.includes(n))throw new RangeError(r)}function Z(n,t,e){const r=n[0]==="Y"?"years":"days of the month";return`Use \`${n.toLowerCase()}\` instead of \`${n}\` (in \`${t}\`) for formatting ${r} to the input \`${e}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const z=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,tt=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,et=/^'([^]*?)'?$/,nt=/''/g,rt=/[a-zA-Z]/;function ot(n,t,e){const r=b(),a=e?.locale??r.locale??H,s=e?.firstWeekContainsDate??e?.locale?.options?.firstWeekContainsDate??r.firstWeekContainsDate??r.locale?.options?.firstWeekContainsDate??1,i=e?.weekStartsOn??e?.locale?.options?.weekStartsOn??r.weekStartsOn??r.locale?.options?.weekStartsOn??0,f=d(n,e?.in);if(!Q(f))throw new RangeError("Invalid time value");let h=t.match(tt).map(u=>{const c=u[0];if(c==="p"||c==="P"){const k=$[c];return k(u,a.formatLong)}return u}).join("").match(z).map(u=>{if(u==="''")return{isToken:!1,value:"'"};const c=u[0];if(c==="'")return{isToken:!1,value:at(u)};if(M[c])return{isToken:!0,value:u};if(c.match(rt))throw new RangeError("Format string contains an unescaped latin alphabet character `"+c+"`");return{isToken:!1,value:u}});a.localize.preprocessor&&(h=a.localize.preprocessor(f,h));const x={firstWeekContainsDate:s,weekStartsOn:i,locale:a};return h.map(u=>{if(!u.isToken)return u.value;const c=u.value;(!e?.useAdditionalWeekYearTokens&&K(c)||!e?.useAdditionalDayOfYearTokens&&J(c))&&U(c,t,String(n));const k=M[c[0]];return k(f,c,a.localize,x)}).join("")}function at(n){const t=n.match(et);return t?t[1].replace(nt,"'"):n}export{o as a,y as b,O as c,I as d,X as e,ot as f,E as g,K as h,Q as i,J as j,_ as k,$ as l,D as s,U as w};