@xopcai/xopc 0.0.411 → 0.0.412

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 (94) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-sGJnq-SA.js → agent-avatar-dicebear-BrGZdh5N.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-BI7OTo-T.js → agent-defaults-settings-panel-BjZpom5V.js} +1 -1
  5. package/dist/gateway/static/root/assets/{agents-RIXL0p7_.js → agents-s3ws5Qi-.js} +3 -3
  6. package/dist/gateway/static/root/assets/{app-management-settings-panel-BGzhSS6H.js → app-management-settings-panel-C6DHuX0L.js} +1 -1
  7. package/dist/gateway/static/root/assets/{appearance-settings-DtEZq4b2.js → appearance-settings-DYGY92Yr.js} +1 -1
  8. package/dist/gateway/static/root/assets/{apps-page-DZqBof2D.js → apps-page-PpT_YMmD.js} +1 -1
  9. package/dist/gateway/static/root/assets/{archive-plugin-CGdU_E5B.js → archive-plugin-DAmsio91.js} +1 -1
  10. package/dist/gateway/static/root/assets/{automations-page-BAPZY56r.js → automations-page-BVutrwON.js} +1 -1
  11. package/dist/gateway/static/root/assets/{automations-workspace-CI-yQnSj.js → automations-workspace-G6-9IYbR.js} +1 -1
  12. package/dist/gateway/static/root/assets/{binary-plugins-B0ispXo2.js → binary-plugins-41QCRAxz.js} +1 -1
  13. package/dist/gateway/static/root/assets/{block-editor-B9Ci-prO.js → block-editor-BQ8AA-Ot.js} +1 -1
  14. package/dist/gateway/static/root/assets/{browser-automations-page-Xzdif447.js → browser-automations-page-o3jNFlCb.js} +1 -1
  15. package/dist/gateway/static/root/assets/{browser-settings-page-Bhu-83eC.js → browser-settings-page-G0dVwiX4.js} +1 -1
  16. package/dist/gateway/static/root/assets/{capabilities-page-BIc0Zlsw.js → capabilities-page-BZQanmZY.js} +2 -2
  17. package/dist/gateway/static/root/assets/{capabilities-settings-panel-CQEfpLdj.js → capabilities-settings-panel-D-YadSx_.js} +1 -1
  18. package/dist/gateway/static/root/assets/{capability-header-actions-Cic05oWh.js → capability-header-actions-CDgI-YZF.js} +1 -1
  19. package/dist/gateway/static/root/assets/{channels-DQbEoo_o.js → channels-3WX3f0bR.js} +1 -1
  20. package/dist/gateway/static/root/assets/{chat-terminal-dock-Bm-IGeDe.js → chat-terminal-dock-CUkCx_9x.js} +1 -1
  21. package/dist/gateway/static/root/assets/{computer-settings-page-C9xMfwXK.js → computer-settings-page-CuZrL9gL.js} +1 -1
  22. package/dist/gateway/static/root/assets/{connector-service-page-DcdASUU9.js → connector-service-page-49mgdRET.js} +1 -1
  23. package/dist/gateway/static/root/assets/{connectors-page-eh-xpMPK.js → connectors-page-Bjj2wAeG.js} +1 -1
  24. package/dist/gateway/static/root/assets/{date-picker-gVLWu9R0.js → date-picker-BpBjADAk.js} +1 -1
  25. package/dist/gateway/static/root/assets/{dependency-picker-C0LARyok.js → dependency-picker-R8kdHLr3.js} +1 -1
  26. package/dist/gateway/static/root/assets/{desktop-pet-v_le3sCs.js → desktop-pet-BpiosRqb.js} +1 -1
  27. package/dist/gateway/static/root/assets/{desktop-pet-settings-B_-j-D4W.js → desktop-pet-settings-9h6evrKB.js} +1 -1
  28. package/dist/gateway/static/root/assets/{device-pairing-wizard-CxG_FcQ6.js → device-pairing-wizard-CZ5lwiLE.js} +1 -1
  29. package/dist/gateway/static/root/assets/{directory-picker-path-field-CBefVUPR.js → directory-picker-path-field-DwXqp_iu.js} +1 -1
  30. package/dist/gateway/static/root/assets/{extension-debug-page-CTe7Molh.js → extension-debug-page-Bj93A2Gn.js} +1 -1
  31. package/dist/gateway/static/root/assets/{extension-page-C0-oP7S_.js → extension-page-Bri62YsN.js} +1 -1
  32. package/dist/gateway/static/root/assets/{extension-settings-page-DYJmgMUg.js → extension-settings-page-BSo6vRhS.js} +1 -1
  33. package/dist/gateway/static/root/assets/{gateway-settings-C13P4lQd.js → gateway-settings-DgEwWJwz.js} +1 -1
  34. package/dist/gateway/static/root/assets/{highlight-code-CslBKXdS.js → highlight-code-CSFBakwF.js} +1 -1
  35. package/dist/gateway/static/root/assets/{highlighted-body-KQOG7T2V-CN5PNRN3.js → highlighted-body-KQOG7T2V-Ci1QpkBn.js} +1 -1
  36. package/dist/gateway/static/root/assets/{home-page-B_XrkGmA.js → home-page-BKj-aPsL.js} +2 -2
  37. package/dist/gateway/static/root/assets/{image-generation-api-DRLXG9Ws.js → image-generation-api-N5MYXlxr.js} +1 -1
  38. package/dist/gateway/static/root/assets/{imports-page--cuF5vwU.js → imports-page-YfaRnpk1.js} +1 -1
  39. package/dist/gateway/static/root/assets/{index-6YjAt50A.js → index-CiDVRMmX.js} +9 -9
  40. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-5g2PxgBs.js → keyboard-shortcuts-settings-BTQcPOix.js} +1 -1
  41. package/dist/gateway/static/root/assets/{local-app-workbench-page-B6U1HQpp.js → local-app-workbench-page-kCZ_fbSZ.js} +1 -1
  42. package/dist/gateway/static/root/assets/{local-apps-page-BChE6nUD.js → local-apps-page-BjzaB1ls.js} +1 -1
  43. package/dist/gateway/static/root/assets/{logs-page-B9mq03SK.js → logs-page-5Jt3uqYt.js} +1 -1
  44. package/dist/gateway/static/root/assets/{management-settings-2W_qJsha.js → management-settings-DOQMLPrI.js} +1 -1
  45. package/dist/gateway/static/root/assets/{media-plugins-BmLuWkkZ.js → media-plugins-8mlDAjD6.js} +1 -1
  46. package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-B4nztFE4.js +1 -0
  47. package/dist/gateway/static/root/assets/{note-detail-panel-C4gZsNBL.js → note-detail-panel-1wsKlkk3.js} +3 -3
  48. package/dist/gateway/static/root/assets/note-image-lightbox-B82cToeV.js +1 -0
  49. package/dist/gateway/static/root/assets/{notes-page-Chdwrjni.js → notes-page-DKREWOku.js} +1 -1
  50. package/dist/gateway/static/root/assets/{page-context-capture-button-B7rDRlS7.js → page-context-capture-button-oSJIFF3E.js} +1 -1
  51. package/dist/gateway/static/root/assets/{personal-page-mQl9BftY.js → personal-page-CoqQTkkS.js} +1 -1
  52. package/dist/gateway/static/root/assets/{plugin-details-dialog-FvwSxZPB.js → plugin-details-dialog-CdOJ3Tir.js} +1 -1
  53. package/dist/gateway/static/root/assets/{preview-open-alternatives-Z4NM7_Dn.js → preview-open-alternatives-n6Shdp3u.js} +1 -1
  54. package/dist/gateway/static/root/assets/{product-open-page-C5TcIaJj.js → product-open-page-BPF5rRTI.js} +1 -1
  55. package/dist/gateway/static/root/assets/{product-preview-content-5xID6jIj.js → product-preview-content-BOsGPNbw.js} +1 -1
  56. package/dist/gateway/static/root/assets/{project-detail-page-CGOyx7zX.js → project-detail-page-ZADyvA7-.js} +1 -1
  57. package/dist/gateway/static/root/assets/{projects-page-Dd11tbRX.js → projects-page-BkRe6Z8S.js} +1 -1
  58. package/dist/gateway/static/root/assets/{remote-access-hub-Bintk9nL.js → remote-access-hub-CCGf5kF4.js} +1 -1
  59. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-CbmiiLsq.js → runtime-tools-settings-panel-BxaxVlwM.js} +1 -1
  60. package/dist/gateway/static/root/assets/{schema-form-DtPkiYwm.js → schema-form-cXD1BC02.js} +1 -1
  61. package/dist/gateway/static/root/assets/{sessions-page-BBlEP7y3.js → sessions-page-B81rRu2-.js} +1 -1
  62. package/dist/gateway/static/root/assets/settings-advanced-gate-DLHGV-I-.js +1 -0
  63. package/dist/gateway/static/root/assets/{settings-form-section-DD3iD5t5.js → settings-form-section-BXeszXR7.js} +1 -1
  64. package/dist/gateway/static/root/assets/{settings-page-iLY3LRDq.js → settings-page-CNmh4YmR.js} +1 -1
  65. package/dist/gateway/static/root/assets/{setup-status-panel-v4P0IAkG.js → setup-status-panel-gEqkJWyw.js} +1 -1
  66. package/dist/gateway/static/root/assets/{share-preview-page-B8h9lqDL.js → share-preview-page-CS9cOCgX.js} +1 -1
  67. package/dist/gateway/static/root/assets/{shares-settings-DMzej6z2.js → shares-settings-D9Ul96XW.js} +1 -1
  68. package/dist/gateway/static/root/assets/{skill-api-C9RsrvOp.js → skill-api-B5lDCuOH.js} +1 -1
  69. package/dist/gateway/static/root/assets/{skill-reload-api-B20x7EE9.js → skill-reload-api-NLAaNaDn.js} +1 -1
  70. package/dist/gateway/static/root/assets/{skills-page-C_ulsnv7.js → skills-page-dWeFt-6J.js} +1 -1
  71. package/dist/gateway/static/root/assets/{system-settings-panel-PTRGMKkq.js → system-settings-panel-DdDsFdCh.js} +1 -1
  72. package/dist/gateway/static/root/assets/{task-detail-page-DEPwo4vf.js → task-detail-page-DO3FM--W.js} +1 -1
  73. package/dist/gateway/static/root/assets/{task-result-evidence-DjNWPpn_.js → task-result-evidence-HJO1BlJm.js} +1 -1
  74. package/dist/gateway/static/root/assets/{tracing-settings-page-CVJt7IXC.js → tracing-settings-page-Dm3yToJ1.js} +1 -1
  75. package/dist/gateway/static/root/assets/{tunnel-api-C6XfsSWy.js → tunnel-api-DXU94F2Y.js} +1 -1
  76. package/dist/gateway/static/root/assets/{usage-page-DgqLD8Y5.js → usage-page-DJJhACRJ.js} +1 -1
  77. package/dist/gateway/static/root/assets/{use-autosave-DO-Twmbm.js → use-autosave-B1z_TIBu.js} +1 -1
  78. package/dist/gateway/static/root/assets/{user-model-page-BwK37aob.js → user-model-page-DnZ4qFaO.js} +1 -1
  79. package/dist/gateway/static/root/assets/{voice-api-key-field-MGe3HkS_.js → voice-api-key-field-HOLjEhh3.js} +1 -1
  80. package/dist/gateway/static/root/assets/{work-discovery-overlay-DptHqYh5.js → work-discovery-overlay-C9RklDaR.js} +1 -1
  81. package/dist/gateway/static/root/assets/{xopc-cloud-account-card-Y_UIryBH.js → xopc-cloud-account-card-CWwGTBib.js} +1 -1
  82. package/dist/gateway/static/root/index.html +1 -1
  83. package/dist/package.js +1 -1
  84. package/dist/src/agent-catalog/repository.js +4 -0
  85. package/dist/src/cli/utils/init-workspace-core.js +5 -3
  86. package/dist/src/config/config-file.d.ts +6 -0
  87. package/dist/src/config/config-file.js +35 -0
  88. package/dist/src/config/loader.js +5 -4
  89. package/dist/src/gateway/service.js +4 -4
  90. package/dist/src/home-intelligence/host.js +2 -2
  91. package/package.json +5 -5
  92. package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-61Il2HQR.js +0 -1
  93. package/dist/gateway/static/root/assets/note-image-lightbox-XqJIaaRV.js +0 -1
  94. package/dist/gateway/static/root/assets/settings-advanced-gate-BCQUth4g.js +0 -1
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{m as i,u as a}from"./chunk-KS7C4IRE-BvcCCgTW.js";import{n as o,r as s,t as c}from"./popover-select-DGKUpVsz.js";import{t as l}from"./circle-check-C23XjkUj.js";import{t as u}from"./external-link-DjqjBmc3.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./messages-DMXSIJUO.js";import{t as p}from"./cn-0WouolD0.js";import{i as m,l as h,n as g,o as _}from"./locale-store-DAgpZxAS.js";import{n as v}from"./copy-to-clipboard-HOJ79TWv.js";import{i as y}from"./vendor-swr-BIWyz7Rc.js";import{t as b}from"./button-aIC072nz.js";import{t as x}from"./skeleton-BI5TyibZ.js";import{n as S,r as C}from"./gateway-config-swr-BVqYVaGy.js";import{n as w}from"./electron-env-Dit0bHgy.js";import{$o as T,Al as E,Ao as D,B as O,Bc as k,Bn as A,Cs as j,Dd as M,E as N,El as P,Es as F,F as I,Fc as L,G as R,H as z,Hl as B,Hn as V,Ic as ee,Jo as H,K as U,Kc as te,Lc as ne,M as re,Md as W,N as ie,Os as ae,Pc as oe,Pd as se,Pl as G,Pu as ce,Qo as K,R as le,Rc as ue,Sd as q,Ss as de,T as J,Ts as fe,U as Y,Un as pe,V as X,Va as me,Vl as he,Vn as ge,W as _e,Xo as ve,Yo as ye,Za as Z,Zo as be,_i as xe,_o as Se,_s as Ce,as as we,bs as Te,ca as Ee,cd as De,cs as Oe,ds as ke,es as Ae,fd as je,gi as Me,gs as Ne,hi as Pe,jd as Fe,ld as Ie,ll as Le,ls as Re,mi as ze,ms as Be,ns as Ve,os as He,ps as Ue,qc as We,rl as Ge,ro as Ke,rs as qe,sd as Je,sl as Ye,ss as Xe,ts as Ze,tu as Qe,us as $e,vs as et,wl as tt,ws as nt,xd as rt,xs as it,yi as at,ys as ot,zc as st}from"./index-6YjAt50A.js";import{n as ct,t as lt}from"./capability-header-actions-Cic05oWh.js";import{t as ut}from"./connector-service-page-DcdASUU9.js";import{t as dt}from"./number-input-DDeqHK-G.js";var Q=e(t(),1),ft=n(),$=r();function pt(e){let t=(0,ft.c)(57),{connector:n,installed:r,onInstall:i,onOpenDetails:a,t:o}=e,s,c,u,d,f,m;if(t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a||t[4]!==o){let e=n.capabilities.filter(mt),h=e.slice(0,2),g=Math.max(0,e.length-h.length),_=o.connect,v;t[11]!==n||t[12]!==o?(v=Y(n,o),t[11]=n,t[12]=o,t[13]=v):v=t[13];let y=v,x=n.verificationLevel===`verified`?o.connectorVerified:n.verificationLevel===`beta`?o.connectorBeta:n.verificationLevel===`experimental`?o.connectorExperimental:null,S;t[14]!==_||t[15]!==n||t[16]!==i?(S=e=>(0,$.jsxs)(b,{type:`button`,variant:`secondary`,className:p(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:()=>i(n),children:[(0,$.jsx)(Qe,{className:`size-4`}),_]}),t[14]=_,t[15]=n,t[16]=i,t[17]=S):S=t[17],s=S,m=`group flex min-h-[8.75rem] flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,c=`flex min-w-0 flex-1 flex-col`;let C;t[18]===n?C=t[19]:(C=(0,$.jsx)(X,{connector:n}),t[18]=n,t[19]=C);let w;t[20]!==n||t[21]!==a?(w=a?(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-sm font-semibold text-fg hover:underline`,onClick:()=>a(n),children:n.displayName}):(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[20]=n,t[21]=a,t[22]=w):w=t[22];let T;t[23]===x?T=t[24]:(T=x?(0,$.jsx)(`span`,{className:`mt-1 inline-flex rounded-full border border-edge px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:x}):null,t[23]=x,t[24]=T);let E;t[25]!==T||t[26]!==w?(E=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[w,T]}),t[25]=T,t[26]=w,t[27]=E):E=t[27];let D;t[28]!==E||t[29]!==C?(D=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[C,E]}),t[28]=E,t[29]=C,t[30]=D):D=t[30];let O;t[31]!==r||t[32]!==s?(O=r?null:(0,$.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 sm:flex`,children:s()}),t[31]=r,t[32]=s,t[33]=O):O=t[33];let k;t[34]!==r||t[35]!==o.connectedBadge?(k=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(l,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[34]=r,t[35]=o.connectedBadge,t[36]=k):k=t[36];let A;t[37]!==O||t[38]!==k?(A=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[O,k]}),t[37]=O,t[38]=k,t[39]=A):A=t[39],t[40]!==D||t[41]!==A?(u=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[D,A]}),t[40]=D,t[41]=A,t[42]=u):u=t[42],t[43]===y?d=t[44]:(d=(0,$.jsx)(`p`,{className:`mt-3 line-clamp-2 text-sm leading-6 text-fg-muted`,title:y,children:y}),t[43]=y,t[44]=d),f=h.length>0?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[h.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:o.connectorCapabilityLabels[e]??e},e)),g>0?(0,$.jsxs)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,g]}):null]}):null,t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=u,t[8]=d,t[9]=f,t[10]=m}else s=t[5],c=t[6],u=t[7],d=t[8],f=t[9],m=t[10];let h;t[45]!==c||t[46]!==u||t[47]!==d||t[48]!==f?(h=(0,$.jsxs)(`div`,{className:c,children:[u,d,f]}),t[45]=c,t[46]=u,t[47]=d,t[48]=f,t[49]=h):h=t[49];let g;t[50]!==r||t[51]!==s?(g=r?null:(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 border-t border-edge pt-3 sm:hidden`,children:s(`w-full`)}),t[50]=r,t[51]=s,t[52]=g):g=t[52];let _;return t[53]!==m||t[54]!==h||t[55]!==g?(_=(0,$.jsxs)(`div`,{className:m,children:[h,g]}),t[53]=m,t[54]=h,t[55]=g,t[56]=_):_=t[56],_}function mt(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}var ht=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function gt(e,t){return t.some(t=>t.connectorId===e.id)}var _t=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`;function vt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:p(`size-10 shrink-0 rounded-xl`,_t)}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full min-h-[9.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:p(`h-4 min-w-0 flex-1`,_t)}),(0,$.jsx)(`div`,{className:p(`h-8 w-[4.5rem] shrink-0 rounded-lg`,_t)})]}),(0,$.jsx)(`div`,{className:p(`h-3 w-full`,_t)}),(0,$.jsx)(`div`,{className:p(`h-3 w-[88%]`,_t)})]})]})}),e[1]=n):n=e[1],n}function yt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(x,{className:`size-9 shrink-0 rounded-lg`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4`,"aria-hidden":!0,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,$.jsx)(x,{className:`h-4 w-28 max-w-full`}),(0,$.jsx)(x,{className:`h-3 w-20 max-w-full`})]})]}),(0,$.jsx)(x,{className:`mt-2 h-3 w-48 max-w-full`}),(0,$.jsx)(x,{className:`ml-auto mt-auto h-3 w-16`})]}),e[1]=n):n=e[1],n}var bt=[`understand`,`act`,`reach`];function xt(e){if(e.benefits?.length)return[...new Set(e.benefits)];let t=new Set(e.capabilities),n=[e.id,e.displayName,...e.tags??[]].join(` `).toLowerCase(),r=[];return(t.has(`context`)||t.has(`memory_source`)||t.has(`resources`)||e.category===`docs`||e.category===`data`||/notion|drive|document|confluence|airtable|database|knowledge|wiki/.test(n))&&r.push(`understand`),t.has(`tools`)&&r.push(`act`),(t.has(`channel`)||/slack|telegram|discord|teams|mail|message|wechat|weixin/.test(n))&&r.push(`reach`),r.length?[...new Set(r)]:[`act`]}function St(e){return xt(e)[0]??`act`}function Ct(e,t){let n=t?St(t):`act`,r=e.connectionStatus===`connected`||e.status===`connected`||e.usage.lastHealthStatus===`ok`,i=e.status===`not_configured`||e.status===`failed`||e.status===`degraded`||e.status===`unauthorized`||e.connectionStatus===`unauthorized`||e.connectionStatus===`error`,a=n===`understand`?e.usage.lastResourceCount:n===`act`?e.usage.lastToolCount:void 0;return{benefit:n,state:r?`ready`:i?`needs_setup`:`checking`,availableCount:a}}function wt(e,t){return t.connectorCapabilityLabels[e]??e}function Tt(e,t){if(e.runtime.type===`mcp`)return _e(t.connectorRuntimeMcp,{serverId:e.runtime.serverId});let n=e.runtime.type===`composio`?e.runtime.toolkit:e.runtime.type===`cli`?e.runtime.adapterId:e.runtime.sourceKind;return _e(t.connectorRuntimeGeneric,{runtime:e.runtime.type,id:n??e.runtime.type})}function Et(e,t){return e.auth.mode===`cli`?t.connectorAuthCli:e.auth.mode===`oauth`?t.connectorAuthOAuth:e.auth.mode===`apiKey`?t.connectorAuthApiKey:t.connectorAuthNone}function Dt(e){let t=(0,ft.c)(133),{connector:n,installed:r,onClose:i,onInstall:a,t:o}=e,s;t[0]!==n||t[1]!==o?(s=Y(n,o),t[0]=n,t[1]=o,t[2]=s):s=t[2];let c=s,u,d,f,m,h,g,_,v,y,x,S,C,w,T,E,D;if(t[3]!==n||t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==o){let e=xt(n),a;t[24]!==n.setup.config||t[25]!==n.setup.secrets?(a=[...(n.setup.secrets??[]).filter(At),...(n.setup.config??[]).filter(kt)],t[24]=n.setup.config,t[25]=n.setup.secrets,t[26]=a):a=t[26];let s=a,b=n.capabilities.filter(Ot);f=oe,_=!0,t[27]===i?v=t[28]:(v=e=>{e||i()},t[27]=i,t[28]=v),d=st,t[29]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(ue,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),t[29]=g):g=t[29],u=ee,t[30]===Symbol.for(`react.memo_cache_sentinel`)?(m=p(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,42rem)] w-[min(100%-2rem,min(92vw,44rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),t[30]=m):m=t[30];let O;t[31]===n?O=t[32]:(O=(0,$.jsx)(X,{connector:n,size:`lg`}),t[31]=n,t[32]=O);let A;t[33]===n.displayName?A=t[34]:(A=(0,$.jsx)(k,{className:`text-base font-semibold text-fg`,children:n.displayName}),t[33]=n.displayName,t[34]=A);let j;t[35]!==r||t[36]!==o.connectedBadge?(j=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(l,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[35]=r,t[36]=o.connectedBadge,t[37]=j):j=t[37];let M;t[38]!==A||t[39]!==j?(M=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[A,j]}),t[38]=A,t[39]=j,t[40]=M):M=t[40];let N;t[41]===c?N=t[42]:(N=(0,$.jsx)(ne,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:c}),t[41]=c,t[42]=N);let F;t[43]!==M||t[44]!==N?(F=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[M,N]}),t[43]=M,t[44]=N,t[45]=F):F=t[45];let I;t[46]!==O||t[47]!==F?(I=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[O,F]}),t[46]=O,t[47]=F,t[48]=I):I=t[48];let R;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(R=p(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,ae.focusRingPanel),t[49]=R):R=t[49];let z;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(te,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[50]=z):z=t[50];let B;t[51]===o.modalClose?B=t[52]:(B=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:R,"aria-label":o.modalClose,children:z})}),t[51]=o.modalClose,t[52]=B),t[53]!==I||t[54]!==B?(h=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-5 py-5 sm:px-6`,children:[I,B]}),t[53]=I,t[54]=B,t[55]=h):h=t[55],T=`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-5 sm:px-6`,E=e.length?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:o.connectorWhyConnect}),(0,$.jsx)(`div`,{className:`mt-3 divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorBenefitHeadings[e]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:o.connectorBenefitHints[e]})]},e))})]}):null;let V;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(ce,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),t[56]=V):V=t[56];let H;t[57]===o.detailPermissions?H=t[58]:(H=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.detailPermissions}),t[57]=o.detailPermissions,t[58]=H);let U;t[59]!==n||t[60]!==o?(U=Et(n,o),t[59]=n,t[60]=o,t[61]=U):U=t[61];let re;t[62]===U?re=t[63]:(re=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:U}),t[62]=U,t[63]=re);let W;t[64]!==H||t[65]!==re?(W=(0,$.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-edge-subtle px-4 py-3`,children:[V,(0,$.jsxs)(`div`,{children:[H,re]})]}),t[64]=H,t[65]=re,t[66]=W):W=t[66];let ie;t[67]===o.connectorSetupTitle?ie=t[68]:(ie=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorSetupTitle}),t[67]=o.connectorSetupTitle,t[68]=ie);let se;t[69]!==s.length||t[70]!==o.connectorRequiredInputsCount||t[71]!==o.connectorSetupNone?(se=s.length?_e(o.connectorRequiredInputsCount,{count:String(s.length)}):o.connectorSetupNone,t[69]=s.length,t[70]=o.connectorRequiredInputsCount,t[71]=o.connectorSetupNone,t[72]=se):se=t[72];let G;t[73]===se?G=t[74]:(G=(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:se}),t[73]=se,t[74]=G);let K;t[75]!==ie||t[76]!==G?(K=(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[ie,G]}),t[75]=ie,t[76]=G,t[77]=K):K=t[77],t[78]!==W||t[79]!==K?(D=(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[W,K]}),t[78]=W,t[79]=K,t[80]=D):D=t[80],C=`rounded-xl border border-edge bg-surface-base`,t[81]===o.connectorTechnicalDetails?w=t[82]:(w=(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:o.connectorTechnicalDetails}),t[81]=o.connectorTechnicalDetails,t[82]=w),y=`space-y-5 border-t border-edge-subtle px-4 py-4`;let le;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),t[83]=le):le=t[83];let q;t[84]===o.connectorRuntimeTitle?q=t[85]:(q=(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[le,o.connectorRuntimeTitle]}),t[84]=o.connectorRuntimeTitle,t[85]=q);let de;t[86]!==n||t[87]!==o?(de=Tt(n,o),t[86]=n,t[87]=o,t[88]=de):de=t[88];let J;t[89]===de?J=t[90]:(J=(0,$.jsx)(`p`,{className:`mt-1 break-words text-xs text-fg-subtle`,children:de}),t[89]=de,t[90]=J),t[91]!==q||t[92]!==J?(x=(0,$.jsxs)(`div`,{children:[q,J]}),t[91]=q,t[92]=J,t[93]=x):x=t[93],S=b.length?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:b.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-panel px-2 py-1 text-xs text-fg-muted`,children:wt(e,o)},e))}):null,t[3]=n,t[4]=c,t[5]=r,t[6]=i,t[7]=o,t[8]=u,t[9]=d,t[10]=f,t[11]=m,t[12]=h,t[13]=g,t[14]=_,t[15]=v,t[16]=y,t[17]=x,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else u=t[8],d=t[9],f=t[10],m=t[11],h=t[12],g=t[13],_=t[14],v=t[15],y=t[16],x=t[17],S=t[18],C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];let O;t[94]!==y||t[95]!==x||t[96]!==S?(O=(0,$.jsxs)(`div`,{className:y,children:[x,S]}),t[94]=y,t[95]=x,t[96]=S,t[97]=O):O=t[97];let A;t[98]!==O||t[99]!==C||t[100]!==w?(A=(0,$.jsxs)(`details`,{className:C,children:[w,O]}),t[98]=O,t[99]=C,t[100]=w,t[101]=A):A=t[101];let j;t[102]!==A||t[103]!==T||t[104]!==E||t[105]!==D?(j=(0,$.jsxs)(`div`,{className:T,children:[E,D,A]}),t[102]=A,t[103]=T,t[104]=E,t[105]=D,t[106]=j):j=t[106];let M;t[107]===o.modalClose?M=t[108]:(M=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(b,{variant:`secondary`,children:o.modalClose})}),t[107]=o.modalClose,t[108]=M);let N;t[109]!==n||t[110]!==r||t[111]!==i||t[112]!==a||t[113]!==o.connect?(N=r?null:(0,$.jsxs)(b,{variant:`primary`,onClick:()=>{a(n),i()},children:[(0,$.jsx)(Qe,{className:`size-4`}),o.connect]}),t[109]=n,t[110]=r,t[111]=i,t[112]=a,t[113]=o.connect,t[114]=N):N=t[114];let F;t[115]!==M||t[116]!==N?(F=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-5 py-4 sm:px-6`,children:[M,N]}),t[115]=M,t[116]=N,t[117]=F):F=t[117];let I;t[118]!==u||t[119]!==m||t[120]!==h||t[121]!==j||t[122]!==F?(I=(0,$.jsxs)(u,{className:m,children:[h,j,F]}),t[118]=u,t[119]=m,t[120]=h,t[121]=j,t[122]=F,t[123]=I):I=t[123];let R;t[124]!==d||t[125]!==g||t[126]!==I?(R=(0,$.jsxs)(d,{children:[g,I]}),t[124]=d,t[125]=g,t[126]=I,t[127]=R):R=t[127];let z;return t[128]!==f||t[129]!==_||t[130]!==v||t[131]!==R?(z=(0,$.jsx)(f,{open:_,onOpenChange:v,children:R}),t[128]=f,t[129]=_,t[130]=v,t[131]=R,t[132]=z):z=t[132],z}function Ot(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}function kt(e){return e.required}function At(e){return e.required}var jt=(0,Q.memo)(function(e){let t=(0,ft.c)(45),{onRefresh:n,refreshing:r,refreshLabel:i,onBrowseCatalog:a,onAddCustomServer:o,addLabel:s,browseLabel:c,customLabel:l,serviceLabel:u,moreActionsLabel:f}=e,[m,h]=(0,Q.useState)(!1),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=p(`touch-target flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-fg outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[highlighted]:bg-surface-hover`,ae.transition),t[0]=g):g=t[0];let _=g,v;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(he,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[1]=v):v=t[1];let y;t[2]===s?y=t[3]:(y=(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:s}),t[2]=s,t[3]=y);let x;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(se,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[4]=x):x=t[4];let S;t[5]!==s||t[6]!==y?(S=(0,$.jsx)(at,{asChild:!0,children:(0,$.jsxs)(b,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":s,children:[v,y,x]})}),t[5]=s,t[6]=y,t[7]=S):S=t[7];let C;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Le,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[8]=C):C=t[8];let w;t[9]!==c||t[10]!==a?(w=(0,$.jsxs)(Pe,{className:_,onSelect:a,children:[C,c]}),t[9]=c,t[10]=a,t[11]=w):w=t[11];let T;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(We,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[12]=T):T=t[12];let E;t[13]!==l||t[14]!==o?(E=(0,$.jsxs)(Pe,{className:_,onSelect:o,children:[T,l]}),t[13]=l,t[14]=o,t[15]=E):E=t[15];let D;t[16]!==w||t[17]!==E?(D=(0,$.jsx)(Me,{children:(0,$.jsxs)(ze,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[w,E]})}),t[16]=w,t[17]=E,t[18]=D):D=t[18];let O;t[19]!==D||t[20]!==S?(O=(0,$.jsxs)(xe,{children:[S,D]}),t[19]=D,t[20]=S,t[21]=O):O=t[21];let k;t[22]===m?k=t[23]:(k=(0,$.jsx)(ut,{open:m,onOpenChange:h,hideTrigger:!0}),t[22]=m,t[23]=k);let A;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(Ie,{className:`size-4`,"aria-hidden":!0}),t[24]=A):A=t[24];let j;t[25]===f?j=t[26]:(j=(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`size-9 shrink-0 p-0`,"aria-label":f,title:f,children:A})}),t[25]=f,t[26]=j);let M;t[27]!==n||t[28]!==i||t[29]!==r?(M=n?(0,$.jsxs)(Pe,{className:_,disabled:r,onSelect:n,children:[r?(0,$.jsx)(d,{className:`size-4 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),i]}):null,t[27]=n,t[28]=i,t[29]=r,t[30]=M):M=t[30];let N,P;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>h(!0),P=(0,$.jsx)(tt,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[31]=N,t[32]=P):(N=t[31],P=t[32]);let F;t[33]===u?F=t[34]:(F=(0,$.jsxs)(Pe,{className:_,onSelect:N,children:[P,u]}),t[33]=u,t[34]=F);let I;t[35]!==M||t[36]!==F?(I=(0,$.jsx)(Me,{children:(0,$.jsxs)(ze,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[M,F]})}),t[35]=M,t[36]=F,t[37]=I):I=t[37];let L;t[38]!==j||t[39]!==I?(L=(0,$.jsxs)(xe,{children:[j,I]}),t[38]=j,t[39]=I,t[40]=L):L=t[40];let R;return t[41]!==O||t[42]!==k||t[43]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[O,k,L]}),t[41]=O,t[42]=k,t[43]=L,t[44]=R):R=t[44],R});function Mt(e=``,t=``){return{clientKey:crypto.randomUUID(),key:e,value:t}}var Nt=/^([^:=]+)[:=](.*)$/;function Pt(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return It(e)}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=Nt.exec(t);r&&n.push(Mt(r[1].trim(),r[2].trim()))}return n.length>0?n:null}function Ft(e){let t=Object.create(null);for(let n of e){let e=n.key.trim();e&&(t[e]=n.reference??n.value)}return Object.keys(t).length>0?t:void 0}function It(e){if(!e||typeof e!=`object`)return[Mt()];let t=Object.entries(e).map(([e,t])=>typeof t==`object`&&t&&!Array.isArray(t)?{...Mt(e),reference:t}:Mt(e,t==null?``:String(t)));return t.length>0?t:[Mt()]}function Lt(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.xopcConnector;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&t.managed===!0)}function Rt(e){let t=e.trim();if(!t)return;if(t.startsWith(`[`)){let e=JSON.parse(t);if(!Array.isArray(e)||e.some(e=>typeof e!=`string`))throw Error(`Command arguments must be a JSON array of strings.`);return e}let n=[],r=``,i=``,a=!1;for(let e=0;e<t.length;e++){let o=t[e];o===`\\`&&t[e+1]&&i!==`'`&&/[\s"'\\]/.test(t[e+1])?(r+=t[++e],a=!0):i?o===i?i=``:r+=o:o===`"`||o===`'`?(i=o,a=!0):/\s/.test(o)?a&&=(n.push(r),r=``,!1):(r+=o,a=!0)}if(i)throw Error(`Command arguments contain an unclosed quote.`);return a&&n.push(r),n}function zt(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Bt(e){let t={...e.extra,exposure:e.exposure};if(e.displayName?.trim()?t.displayName=e.displayName.trim():delete t.displayName,delete t.command,delete t.args,delete t.env,delete t.cwd,delete t.url,delete t.headers,delete t.type,e.transport===`stdio`){t.type=`stdio`,t.command=e.command.trim();let n=Rt(e.argsText);if(n&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envEntries){let n=new Set;for(let t of e.envEntries)if(!(!t.key.trim()&&!t.value&&!t.reference)){if(!t.key.trim()||n.has(t.key.trim()))throw Error(`Environment variable names must be non-empty and unique.`);n.add(t.key.trim())}let r=Ft(e.envEntries);r&&(t.env=r)}else e.envJson.trim()&&(t.env=zt(e.envJson));delete t.oauth,delete t.auth}else{t.type=`http`,t.url=e.url.trim();let n=Ft(e.headers);n&&(t.headers=n);let r={...t.oauth??{}};e.oauthClientId.trim()?r.clientId=e.oauthClientId.trim():delete r.clientId,Object.keys(r).length?t.oauth=r:delete t.oauth}return e.timeout===void 0?delete t.timeout:t.timeout=e.timeout,t}function Vt(e,t){let n=t.oauth;return{clientKey:e,id:e,displayName:typeof t.displayName==`string`?t.displayName:``,transport:typeof t.url==`string`?`streamable-http`:`stdio`,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?JSON.stringify(t.args):``,envJson:t.env?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:``,url:typeof t.url==`string`?t.url:``,headers:It(t.headers),oauthClientId:typeof n?.clientId==`string`?n.clientId:``,timeout:typeof t.timeout==`number`?t.timeout:void 0,exposure:t.exposure??`codemode`,extra:t}}function Ht(e,t){let n=`mcp`;try{n=e.transport===`streamable-http`?new URL(e.url).hostname:e.command.split(/[\\/]/).pop()||n}catch{}let r=n.replace(/[^a-zA-Z0-9_-]+/g,`_`).replace(/^_+|_+$/g,``)||`mcp`,i=new Set([...t].map(e=>e.replace(/-/g,`_`))),a=r;for(let e=2;i.has(a.replace(/-/g,`_`));e++)a=`${r}_${e}`;return a}function Ut(e){let t=e.trim(),n=new URL(/^[a-z][a-z\d+.-]*:/i.test(t)&&!/^[^/]+:\d+(?:[/?#]|$)/.test(t)?t:`${/^(localhost|127\.0\.0\.1)(:|\/|$)/i.test(t)?`http`:`https`}://${t}`);if(![`http:`,`https:`].includes(n.protocol)||n.username||n.password)throw Error(`Use an HTTP or HTTPS MCP address without embedded credentials.`);return n.href}function Wt(e){let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Expected a JSON object.`);let n=t.mcpServers??t.mcp?.servers??t.servers;if(n!==void 0&&(!n||typeof n!=`object`||Array.isArray(n)))throw Error(`Expected a server configuration object.`);let r=n?Object.entries(n):[[``,t]];if(!r.length)throw Error(`No MCP servers found.`);return r.map(([e,t])=>{if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid MCP server configuration.`);let n=t;if(typeof n.url!=`string`&&typeof n.command!=`string`)throw Error(`The configuration needs an MCP URL or command.`);if(n.args!==void 0&&(!Array.isArray(n.args)||n.args.some(e=>typeof e!=`string`)))throw Error(`Command arguments must be strings.`);let r=Vt(e,n);return r.clientKey=crypto.randomUUID(),r.url&&=Ut(r.url),r})}function Gt(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`streamable-http`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[],oauthClientId:``,timeout:void 0,exposure:`codemode`,extra:{}}}function Kt(e){let t=e?.mcp?.servers??{};return{servers:Object.entries(t).filter(([,e])=>!Lt(e)).map(([e,t])=>Vt(e,t)).sort((e,t)=>e.id.localeCompare(t.id))}}function qt(e){return Bt(e)}async function Jt(e,t){return(await _(m(`/api/mcp/servers/${encodeURIComponent(e)}/tools`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload.tools}async function Yt(e,t,n,r){return(await _(m(`/api/mcp/drafts`),{method:`POST`,signal:r,body:JSON.stringify({serverId:e.id,sourceServerId:t,expectedServer:n,server:Bt(e)})})).payload}async function Xt(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/probe`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload}async function Zt(e){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}`),{method:`DELETE`})}async function Qt(e,t=!1){let n=await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/commit`),{method:`POST`,body:JSON.stringify({enable:t})});return S(),n.payload}async function $t(e){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`POST`})).payload}async function en(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{signal:t})).payload}async function tn(e){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`DELETE`})}async function nn(e,t){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth/redirect`),{method:`POST`,body:JSON.stringify({url:t})})}async function rn(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/tools`),{signal:t})).payload.tools}async function an(e){let t=await _(m(`/api/mcp/servers`),{signal:e});return Object.fromEntries(t.payload.servers.filter(e=>e.lastCheck&&Number.isFinite(Date.parse(e.lastCheck.checkedAt))).map(e=>[e.id,e.lastCheck]))}async function on(e){let t=await _(m(`/api/mcp/servers/${encodeURIComponent(e.id)}`),{method:`DELETE`,body:JSON.stringify({expectedServer:e.extra})});return S(),t.payload}function sn(e){let t=(0,ft.c)(111),{serverId:n,displayName:r,returnFocusTo:i,draftId:a,t:o,onClose:s,onConfigure:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],t[0]=l):l=t[0];let[u,d]=(0,Q.useState)(l),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(0),x=(0,Q.useRef)(!1),S;t[1]!==a||t[2]!==n||t[3]!==o.setupAccessDenied||t[4]!==o.setupConflict||t[5]!==o.setupGatewayUnauthorized||t[6]!==o.setupRateLimited||t[7]!==o.toolsLoadFailed?(S=()=>{let e=new AbortController,t=!0;return p(!0),h(``),d([]),(a?rn(a,e.signal):Jt(n,e.signal)).then(e=>{t&&d(e)}).catch(e=>{let n=e?.status;t&&h(n===401?o.setupGatewayUnauthorized:n===403?o.setupAccessDenied:n===429?o.setupRateLimited:n===404||n===409?o.setupConflict:o.toolsLoadFailed)}).finally(()=>{t&&p(!1)}),()=>{t=!1,e.abort()}},t[1]=a,t[2]=n,t[3]=o.setupAccessDenied,t[4]=o.setupConflict,t[5]=o.setupGatewayUnauthorized,t[6]=o.setupRateLimited,t[7]=o.toolsLoadFailed,t[8]=S):S=t[8];let C;t[9]!==a||t[10]!==v||t[11]!==n||t[12]!==o?(C=[n,a,v,o],t[9]=a,t[10]=v,t[11]=n,t[12]=o,t[13]=C):C=t[13],(0,Q.useEffect)(S,C);let w,T,E,D,O,A,j,M,N,P,F,I,R;if(t[14]!==r||t[15]!==m||t[16]!==f||t[17]!==s||t[18]!==c||t[19]!==g||t[20]!==i||t[21]!==n||t[22]!==o.exposureLabels||t[23]!==o.setupConfigure||t[24]!==o.toolDetails||t[25]!==o.toolsClearSearch||t[26]!==o.toolsDialogSearchEmpty||t[27]!==o.toolsDialogSearchPlaceholder||t[28]!==o.toolsDialogSubtitle||t[29]!==o.toolsDialogTitle||t[30]!==o.toolsEmpty||t[31]!==o.toolsLoading||t[32]!==o.toolsRetryHint||t[33]!==o.toolsSearchSummary||t[34]!==o.toolsTitle||t[35]!==u){let e=g.trim().toLowerCase(),a;if(t[49]!==n){let e;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(e=/-/g,t[51]=e):e=t[51],a=n.replace(e,`_`),t[49]=n,t[50]=a}else a=t[50];let l=`mcp__${a}__`,d=u.filter(t=>`${t.name} ${t.description}`.toLowerCase().includes(e));E=oe,A=!0,t[52]===s?j=t[53]:(j=e=>{e||s()},t[52]=s,t[53]=j),T=st,t[54]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(ue,{className:`fixed inset-0 z-[60] bg-scrim`}),t[54]=O):O=t[54],w=ee,t[55]===i?I=t[56]:(I=e=>{(x.current||i)&&e.preventDefault(),!x.current&&i?.isConnected&&i.focus()},t[55]=i,t[56]=I),R=`fixed left-1/2 top-1/2 z-[60] flex h-[min(42rem,calc(100dvh-2rem))] w-[min(48rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`;let p;t[57]===o.toolsDialogTitle?p=t[58]:(p=(0,$.jsx)(k,{className:`font-semibold`,children:o.toolsDialogTitle}),t[57]=o.toolsDialogTitle,t[58]=p);let h;t[59]!==r||t[60]!==m||t[61]!==f||t[62]!==n||t[63]!==o.toolsDialogSubtitle||t[64]!==u.length?(h=f||m?r||n:o.toolsDialogSubtitle.replace(`{{serverId}}`,r||n).replace(`{{count}}`,String(u.length)),t[59]=r,t[60]=m,t[61]=f,t[62]=n,t[63]=o.toolsDialogSubtitle,t[64]=u.length,t[65]=h):h=t[65];let v;t[66]===h?v=t[67]:(v=(0,$.jsx)(ne,{className:`mt-1 break-words text-sm text-fg-muted`,children:h}),t[66]=h,t[67]=v);let y;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>_(e.target.value),t[68]=y):y=t[68];let S;t[69]!==g||t[70]!==o.toolsDialogSearchPlaceholder?(S=(0,$.jsx)(`input`,{className:`mt-4 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,value:g,onChange:y,placeholder:o.toolsDialogSearchPlaceholder,"aria-label":o.toolsDialogSearchPlaceholder}),t[69]=g,t[70]=o.toolsDialogSearchPlaceholder,t[71]=S):S=t[71];let C=e&&!f&&!m?(0,$.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-fg-muted`,children:o.toolsSearchSummary.replace(`{{visible}}`,String(d.length)).replace(`{{count}}`,String(u.length))}):null;t[72]!==p||t[73]!==v||t[74]!==S||t[75]!==C?(D=(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-edge p-5`,children:[p,v,S,C]}),t[72]=p,t[73]=v,t[74]=S,t[75]=C,t[76]=D):D=t[76],M=`min-h-0 flex-1 overflow-y-auto p-5`,N=f,t[77]!==o.toolsTitle||t[78]!==u.length?(P=o.toolsTitle.replace(`{{count}}`,String(u.length)),t[77]=o.toolsTitle,t[78]=u.length,t[79]=P):P=t[79],F=f?(0,$.jsx)(`div`,{role:`status`,"aria-label":o.toolsLoading,className:`space-y-3`,children:[0,1,2].map(ln)}):m?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm text-danger`,children:m}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:o.toolsRetryHint}),c?(0,$.jsx)(b,{variant:`secondary`,onClick:()=>{x.current=!0,c()},children:o.setupConfigure}):null]}):d.length?(0,$.jsx)(`div`,{className:`space-y-3`,children:d.map(e=>(0,$.jsxs)(`article`,{className:`rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`h3`,{className:`break-all font-mono text-sm font-semibold text-fg`,children:e.name.startsWith(l)?e.name.slice(l.length):e.name}),e.exposure&&Object.hasOwn(o.exposureLabels,e.exposure)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o.exposureLabels[e.exposure]}):null,e.description?(0,$.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap break-words text-sm text-fg-muted`,children:e.description}):null,(0,$.jsxs)(`details`,{className:`mt-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:o.toolDetails}),(0,$.jsx)(`p`,{className:`mt-2 break-all font-mono text-xs text-fg-muted`,children:e.name}),(0,$.jsx)(`pre`,{className:`mt-2 overflow-x-auto rounded-md bg-surface-panel p-3 text-xs text-fg`,children:JSON.stringify(e.inputSchema,null,2)})]})]},e.name))}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.length?o.toolsDialogSearchEmpty:o.toolsEmpty}),e?(0,$.jsx)(b,{variant:`secondary`,onClick:()=>_(``),children:o.toolsClearSearch}):null]}),t[14]=r,t[15]=m,t[16]=f,t[17]=s,t[18]=c,t[19]=g,t[20]=i,t[21]=n,t[22]=o.exposureLabels,t[23]=o.setupConfigure,t[24]=o.toolDetails,t[25]=o.toolsClearSearch,t[26]=o.toolsDialogSearchEmpty,t[27]=o.toolsDialogSearchPlaceholder,t[28]=o.toolsDialogSubtitle,t[29]=o.toolsDialogTitle,t[30]=o.toolsEmpty,t[31]=o.toolsLoading,t[32]=o.toolsRetryHint,t[33]=o.toolsSearchSummary,t[34]=o.toolsTitle,t[35]=u,t[36]=w,t[37]=T,t[38]=E,t[39]=D,t[40]=O,t[41]=A,t[42]=j,t[43]=M,t[44]=N,t[45]=P,t[46]=F,t[47]=I,t[48]=R}else w=t[36],T=t[37],E=t[38],D=t[39],O=t[40],A=t[41],j=t[42],M=t[43],N=t[44],P=t[45],F=t[46],I=t[47],R=t[48];let z;t[80]!==M||t[81]!==N||t[82]!==P||t[83]!==F?(z=(0,$.jsx)(`div`,{className:M,"aria-busy":N,"aria-label":P,children:F}),t[80]=M,t[81]=N,t[82]=P,t[83]=F,t[84]=z):z=t[84];let B;t[85]===Symbol.for(`react.memo_cache_sentinel`)?(B=()=>y(cn),t[85]=B):B=t[85];let V;t[86]!==f||t[87]!==o.refreshTools?(V=(0,$.jsx)(b,{variant:`secondary`,disabled:f,onClick:B,children:o.refreshTools}),t[86]=f,t[87]=o.refreshTools,t[88]=V):V=t[88];let H;t[89]!==s||t[90]!==o.toolsDialogClose?(H=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(b,{onClick:s,children:o.toolsDialogClose})}),t[89]=s,t[90]=o.toolsDialogClose,t[91]=H):H=t[91];let U;t[92]!==V||t[93]!==H?(U=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge p-4`,children:[V,H]}),t[92]=V,t[93]=H,t[94]=U):U=t[94];let te;t[95]!==w||t[96]!==D||t[97]!==z||t[98]!==U||t[99]!==I||t[100]!==R?(te=(0,$.jsxs)(w,{onCloseAutoFocus:I,className:R,children:[D,z,U]}),t[95]=w,t[96]=D,t[97]=z,t[98]=U,t[99]=I,t[100]=R,t[101]=te):te=t[101];let re;t[102]!==T||t[103]!==O||t[104]!==te?(re=(0,$.jsxs)(T,{children:[O,te]}),t[102]=T,t[103]=O,t[104]=te,t[105]=re):re=t[105];let W;return t[106]!==E||t[107]!==A||t[108]!==j||t[109]!==re?(W=(0,$.jsx)(E,{open:A,onOpenChange:j,children:re}),t[106]=E,t[107]=A,t[108]=j,t[109]=re,t[110]=W):W=t[110],W}function cn(e){return e+1}function ln(e){return(0,$.jsx)(x,{className:`h-24 w-full`},e)}function un(e){if(e.transport===`stdio`)return e.command.trim();try{let t=new URL(e.url);return`${t.protocol}//${t.host}${t.pathname}`}catch{return e.url.trim().split(/[?#]/,1)[0].replace(/\/\/[^/]*@/,`//`)}}function dn({row:e,lastCheck:t,t:n,cs:r,onEdit:i,onRemove:a}){let o=g(e=>e.language),[s,c]=(0,Q.useState)(!1),u=(0,Q.useRef)(null),[d,f]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),_=e.displayName||e.id,v=un(e),y=e.extra.enabled===!1,x=y?M:t?l:rt,S=e.transport===`stdio`?Ye:P,C=y?n.setupDisabled:t?r.customCheckSucceeded:r.customUnchecked,w=t?new Intl.DateTimeFormat(o,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.checkedAt)):null;return(0,$.jsxs)(`li`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`div`,{title:n.transportLabels[e.transport],className:`flex size-9 shrink-0 items-center justify-center rounded-xl border border-edge-subtle bg-surface-inset text-fg-muted`,children:(0,$.jsx)(S,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,$.jsx)(`h3`,{className:`min-w-0 max-w-full text-sm font-semibold text-fg`,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,title:_,className:`block max-w-full truncate rounded text-left hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:_})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px]`,children:[(0,$.jsxs)(`span`,{title:w?r.customLastChecked.replace(`{{time}}`,w):void 0,"aria-label":w?`${C} · ${r.customLastChecked.replace(`{{time}}`,w)}`:C,className:p(`inline-flex shrink-0 items-center gap-1`,!y&&t?`text-emerald-700 dark:text-emerald-300`:`text-fg-muted`),children:[(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),C]}),t?(0,$.jsx)(`span`,{className:`text-fg-muted`,children:r.customToolCount.replace(`{{count}}`,String(t.toolCount))}):null]})]})})]}),(0,$.jsx)(`p`,{title:v,className:`mt-2 truncate font-mono text-xs leading-5 text-fg-muted`,children:v})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[11px] text-fg-subtle`,children:n.transportLabels[e.transport]}),(0,$.jsx)(b,{variant:`ghost`,className:`h-8 px-2 py-1 text-xs`,onClick:i,children:n.setupConfigure}),(0,$.jsx)(b,{ref:u,variant:`secondary`,className:`h-8 px-2 py-1 text-xs shadow-none sm:shadow-none`,disabled:y,onClick:()=>c(!0),children:n.viewTools}),(0,$.jsxs)(xe,{children:[(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(b,{variant:`ghost`,className:`size-8 p-0`,"aria-label":r.customManage.replace(`{{name}}`,_),title:r.customManage.replace(`{{name}}`,_),children:(0,$.jsx)(Ie,{className:`size-4`,"aria-hidden":!0})})}),(0,$.jsx)(Me,{children:(0,$.jsx)(ze,{align:`end`,sideOffset:6,className:`z-50 min-w-36 rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover`,children:(0,$.jsxs)(Pe,{onSelect:()=>f(!0),className:`flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-danger outline-none data-[highlighted]:bg-surface-hover`,children:[(0,$.jsx)(Ge,{className:`size-4`,"aria-hidden":!0}),n.removeServer]})})})]})]}),m?(0,$.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-danger`,children:m}):null,s?(0,$.jsx)(sn,{serverId:e.id,displayName:e.displayName,returnFocusTo:u.current,t:n,onClose:()=>c(!1),onConfigure:()=>{c(!1),i()}}):null,(0,$.jsx)(Ee,{open:d,title:r.removeConfirmTitle.replace(`{{name}}`,_),description:r.removeConfirmDescription,confirmLabel:n.removeServer,cancelLabel:r.modalCancel,destructive:!0,onCancel:()=>f(!1),onConfirm:()=>{f(!1),h(``),a().catch(()=>h(n.setupRemoveFailed))}})]})}function fn(e){let t=(0,ft.c)(30),{servers:n,lastChecks:r,t:i,cs:a,onAdd:o,onEdit:s,onRemove:c}=e,l;t[0]===a.customIntegrationsTitle?l=t[1]:(l=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:a.customIntegrationsTitle}),t[0]=a.customIntegrationsTitle,t[1]=l);let u;t[2]===n.length?u=t[3]:(u=(0,$.jsx)(`span`,{className:`rounded-md bg-surface-inset px-1.5 py-0.5 text-xs tabular-nums text-fg-muted`,children:n.length}),t[2]=n.length,t[3]=u);let d;t[4]!==l||t[5]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l,u]}),t[4]=l,t[5]=u,t[6]=d):d=t[6];let f;t[7]===a.customIntegrationsHint?f=t[8]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.customIntegrationsHint}),t[7]=a.customIntegrationsHint,t[8]=f);let p;t[9]!==d||t[10]!==f?(p=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[d,f]}),t[9]=d,t[10]=f,t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(he,{className:`size-3.5`,"aria-hidden":!0}),t[12]=m):m=t[12];let h;t[13]!==a.customAdd||t[14]!==o?(h=(0,$.jsxs)(b,{variant:`secondary`,className:`shrink-0 text-xs shadow-none sm:shadow-none`,onClick:o,children:[m,a.customAdd]}),t[13]=a.customAdd,t[14]=o,t[15]=h):h=t[15];let g;t[16]!==p||t[17]!==h?(g=(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[p,h]}),t[16]=p,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==a||t[20]!==r||t[21]!==s||t[22]!==c||t[23]!==n||t[24]!==i?(_=n.length?(0,$.jsx)(`ul`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,$.jsx)(dn,{row:e,lastCheck:r[e.id],t:i,cs:a,onEdit:()=>s(e),onRemove:()=>c(e)},e.clientKey))}):(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-edge px-5 py-8 text-center text-sm text-fg-muted`,children:a.customEmpty}),t[19]=a,t[20]=r,t[21]=s,t[22]=c,t[23]=n,t[24]=i,t[25]=_):_=t[25];let v;return t[26]!==a.customIntegrationsTitle||t[27]!==g||t[28]!==_?(v=(0,$.jsxs)(`section`,{"aria-label":a.customIntegrationsTitle,children:[g,_]}),t[26]=a.customIntegrationsTitle,t[27]=g,t[28]=_,t[29]=v):v=t[29],v}function pn(e){return e.format===`agent-plugin`&&!!e.pluginId&&(!!e.setup?.authorizations?.length||e.authorizationStatus===`required`||!!e.components?.mcp.some(e=>e.type!==`stdio`))}function mn(e){let t=(0,ft.c)(54),{extension:n,language:r,onOpen:i}=e,a;t[0]===r?a=t[1]:(a=r.startsWith(`zh`),t[0]=r,t[1]=a);let o=a,s;t[2]===o?s=t[3]:(s=(e,t)=>o?e:t,t[2]=o,t[3]=s);let c=s,u=n.installationState===`preparing`,d=n.activationEligible===!1,f=n.authorizationStatus===`required`,m;t[4]!==d||t[5]!==n.readiness||t[6]!==f||t[7]!==u||t[8]!==c?(m=u?c(`准备未完成`,`Setup incomplete`):d?c(`已停用`,`Disabled`):f?c(`需要授权`,`Authorization required`):n.readiness===`blocked`||n.readiness===`degraded`?c(`需要处理`,`Needs attention`):c(`已连接`,`Connected`),t[4]=d,t[5]=n.readiness,t[6]=f,t[7]=u,t[8]=c,t[9]=m):m=t[9];let h=m,g;t[10]!==d||t[11]!==f||t[12]!==u||t[13]!==c?(g=u?c(`继续安装`,`Continue setup`):!d&&f?c(`去授权`,`Connect account`):c(`查看详情`,`View details`),t[10]=d,t[11]=f,t[12]=u,t[13]=c,t[14]=g):g=t[14];let _=g,v;t[15]===n.setup?.authorizations?v=t[16]:(v=n.setup?.authorizations??[],t[15]=n.setup?.authorizations,t[16]=v);let y=v,b=y.length===1?y[0].title:n.name,x=u||!d&&(f||n.readiness===`blocked`||n.readiness===`degraded`),S=u?rt:d?M:x?Fe:l,C=x&&`border-amber-500/25`,w;t[17]===C?w=t[18]:(w=p(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left transition-colors hover:bg-surface-hover/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,C),t[17]=C,t[18]=w);let T=n.branding?.iconUrl,E;t[19]===T?E=t[20]:(E=(0,$.jsx)(I,{iconUrl:T,fallback:B,className:`size-9`}),t[19]=T,t[20]=E);let D;t[21]===b?D=t[22]:(D=(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-fg`,title:b,children:b}),t[21]=b,t[22]=D);let O=x?`text-amber-700 dark:text-amber-300`:d?`text-fg-muted`:`text-emerald-700 dark:text-emerald-300`,k;t[23]===O?k=t[24]:(k=p(`mt-1 inline-flex items-center gap-1 text-[11px]`,O),t[23]=O,t[24]=k);let A;t[25]===S?A=t[26]:(A=(0,$.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),t[25]=S,t[26]=A);let j;t[27]!==h||t[28]!==k||t[29]!==A?(j=(0,$.jsxs)(`span`,{className:k,children:[A,h]}),t[27]=h,t[28]=k,t[29]=A,t[30]=j):j=t[30];let N;t[31]!==D||t[32]!==j?(N=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[D,j]}),t[31]=D,t[32]=j,t[33]=N):N=t[33];let P;t[34]!==N||t[35]!==E?(P=(0,$.jsxs)(`span`,{className:`flex w-full min-w-0 items-start gap-3`,children:[E,N]}),t[34]=N,t[35]=E,t[36]=P):P=t[36];let F=n.name,L;t[37]===c?L=t[38]:(L=c(`由插件提供`,`Provided by plugin`),t[37]=c,t[38]=L);let R;t[39]!==n.name||t[40]!==L?(R=(0,$.jsxs)(`span`,{className:`mt-2 block w-full truncate text-xs leading-5 text-fg-muted`,title:F,children:[L,` · `,n.name]}),t[39]=n.name,t[40]=L,t[41]=R):R=t[41];let z=x?`text-accent-fg`:`text-fg-muted`,V;t[42]===z?V=t[43]:(V=p(`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs`,z),t[42]=z,t[43]=V);let ee;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(W,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[44]=ee):ee=t[44];let H;t[45]!==_||t[46]!==V?(H=(0,$.jsxs)(`span`,{className:V,children:[_,ee]}),t[45]=_,t[46]=V,t[47]=H):H=t[47];let U;return t[48]!==i||t[49]!==P||t[50]!==R||t[51]!==H||t[52]!==w?(U=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:w,children:[P,R,H]}),t[48]=i,t[49]=P,t[50]=R,t[51]=H,t[52]=w,t[53]=U):U=t[53],U}function hn(e){let t=e.connectedAt?Date.parse(e.connectedAt):0;return Number.isFinite(t)?t:0}function gn(e,t){return e.status===`active`&&t.status!==`active`?-1:e.status!==`active`&&t.status===`active`?1:e.isCurrentAuthorization===t.isCurrentAuthorization?hn(t)-hn(e):e.isCurrentAuthorization?-1:1}function _n(e){let t=new Map;for(let n of e){let e=n.accountId??n.identityKey??`authorization:${n.id}`;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>{let n=[...t].sort(gn);return{key:e,primary:n[0],authorizations:n}}).sort((e,t)=>gn(e.primary,t.primary))}var vn=p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D);function yn(e){return e.materialized.type===`composio`?e.materialized.toolkit:null}function bn(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function xn(e,t,n){return e.status===`connected`?_e(n.composioHealthConnected,{count:String(t)}):e.status===`reauthorization_required`?n.composioHealthReconnect:e.status===`disconnected`?n.composioHealthDisconnected:e.errorCode===`missing_credential`?n.composioHealthMissingCredential:e.errorCode===`unauthorized`?n.composioHealthUnauthorized:e.errorCode===`forbidden`?n.composioHealthForbidden:e.errorCode===`network`?n.composioHealthNetwork:e.errorCode===`timeout`?n.composioHealthTimeout:n.composioHealthDegraded}function Sn(e,t){return e===`active`?t.composioConnectionHealthy:e===`pending`?t.composioConnectionPending:e===`expired`?t.composioConnectionExpired:e===`failed`?t.composioConnectionFailed:e===`revoked`||e===`disabled`?t.composioConnectionRevoked:t.composioConnectionUnknown}function Cn(e,t,n){return e.status===`paused`?t?.scanEnabled===!1?n.connectorLearningPausedByPolicy:n.connectorLearningPausedByFailure:e.status===`queued`?n.connectorLearningQueued:e.status===`running`?n.connectorLearningRunning:e.status===`completed`?n.connectorLearningCompleted:n.connectorLearningFailed}function wn({instance:e,t,onChanged:n}){let r=yn(e),i=g(e=>e.language)===`zh`,[a,c]=(0,Q.useState)([]),[u,f]=(0,Q.useState)([]),[m,h]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),[y,S]=(0,Q.useState)([]),[C,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)([]),[A,M]=(0,Q.useState)({}),[N,P]=(0,Q.useState)(`read`),[I,L]=(0,Q.useState)(!1),[R,B]=(0,Q.useState)(null),[V,ee]=(0,Q.useState)(!1),[U,te]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(null),[W,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(!1),[se,K]=(0,Q.useState)(!1),le=(0,Q.useRef)(0),ue=(0,Q.useRef)(0),q=(0,Q.useMemo)(()=>_n(a),[a]),J=(0,Q.useCallback)(e=>new Promise((t,n)=>{let r=window.setTimeout(()=>n(Error(i?`连接服务响应超时,请重试。`:`The connection service timed out. Please retry.`)),15e3);e.then(t,n).finally(()=>window.clearTimeout(r))}),[i]),Y=(0,Q.useCallback)(async()=>{if(!r||e.materialized.type!==`composio`||e.materialized.role===`credential`)return;L(!0),B(null);let t=++le.current;try{let e=(await Promise.allSettled([J(Xe()).then(e=>{t===le.current&&(c(e.filter(e=>e.toolkit.toLowerCase()===r.toLowerCase())),ie(!0))}),J(qe(r)).then(e=>{t===le.current&&P(e)}),J(Ve(r)).then(e=>{t===le.current&&(v(e.policy),S(e.agents))})])).find(e=>e.status===`rejected`);t===le.current&&e?.status===`rejected`&&B(String(e.reason instanceof Error?e.reason.message:e.reason))}finally{t===le.current&&L(!1)}},[e.materialized,r,J]);(0,Q.useEffect)(()=>(Y(),()=>{le.current++}),[Y]);let pe=(0,Q.useCallback)(async()=>{if(!r)return;let e=++ue.current;K(!0),ee(!1);let t=t=>n=>{e===ue.current&&t(n)},n=await Promise.allSettled([J(Oe(r)).then(t(f)),J(Re(20)).then(t(e=>h(e.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===r.toLowerCase())))),J(we(r)).then(t(D)),J(Ze(r)).then(t(T))]);e===ue.current&&(ee(n.some(e=>e.status===`rejected`)),K(!1))},[r,J]);(0,Q.useEffect)(()=>(ae&&pe(),()=>{ue.current++}),[ae,pe]),(0,Q.useEffect)(()=>{let e=!1,t=_n(a).map(e=>e.primary).filter(e=>e.supportsLearning&&e.accountId);if(t.length)return J($e()).then(t=>{e||k(t)}).catch(()=>{}),Promise.allSettled(t.map(async e=>[e.accountId,await J(He(e.accountId))])).then(t=>{e||M(Object.fromEntries(t.flatMap(e=>e.status===`fulfilled`?[e.value]:[])))}),()=>{e=!0}},[a,J]);let X=(0,Q.useCallback)(async i=>{if(!r)return;let a=w()?null:window.open(`about:blank`,`_blank`);a&&(a.opener=null),L(!0),B(null);try{if(!w()&&!a)throw Error(`Allow popups to open the authorization page.`);let t=await et(e.connectorId,i);if(!t.authorizationUrl)throw Error(`The authorization provider did not return an authorization URL.`);if(w()){let e=await window.electronAPI?.shell?.openExternalUrl(t.authorizationUrl);if(!e?.ok)throw Error(e?.error??`Could not open the system browser.`)}else a.location.href=t.authorizationUrl;let o=await F(r,t.connectionId,12e4,t.attemptId);if(i&&o.accountId!==i)throw Error(`A different account was authorized. The original account and its task bindings were not changed.`);await Promise.all([n?.(),Y()])}catch(e){B(z(e,t))}finally{a?.close(),L(!1)}},[e.connectorId,Y,n,t,r]),me=(0,Q.useCallback)(async t=>{L(!0),B(null);try{await nt(e.instanceId,{config:{...e.config??{},authConfigId:t||void 0}}),await Promise.all([n?.(),Y()])}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[e.config,e.instanceId,Y,n]),he=async e=>{let t=w()?null:window.open(`about:blank`,`_blank`);t&&(t.opener=null),B(null);try{let n=await Ae(e.id);if(n.authorizationUrl)if(w())await window.electronAPI?.shell?.openExternalUrl(n.authorizationUrl);else if(t)t.location.href=n.authorizationUrl;else throw Error(`Allow popups to reopen authorization.`);else t?.close(),await Y()}catch(e){t?.close(),B(e instanceof Error?e.message:String(e))}},ge=(0,Q.useCallback)(async e=>{if(r){P(e),B(null);try{await Ne(r,e)}catch(e){B(e instanceof Error?e.message:String(e)),await Y()}}},[Y,r]),ve=(0,Q.useCallback)(async e=>{if(r){B(null);try{v(await j(r,e))}catch(e){B(e instanceof Error?e.message:String(e))}}},[r]),ye=(0,Q.useCallback)(e=>{if(!_)return;let t=_.allowedAgentIds.includes(e);t&&_.allowedAgentIds.length===1||ve({allowedAgentIds:t?_.allowedAgentIds.filter(t=>t!==e):[..._.allowedAgentIds,e]})},[ve,_]),Z=(0,Q.useCallback)(async e=>{L(!0),B(null);try{await e(),await Y()}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[Y]);if(!r)return null;if(e.materialized.type===`composio`&&e.materialized.role===`credential`)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioApiKeyStored});let be=q.filter(e=>e.primary.status===`active`).length,xe=be>0?t.composioAddAccount:t.composioConnectAccount,Se=W&&be>0,Te=E?.requiresCustomAuthConfig===!0,De=E?.authConfigs.filter(e=>e.status===`ENABLED`&&e.isEnabledForToolRouter)??[];return(0,$.jsxs)(`div`,{className:`space-y-5`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`span`,{className:p(`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium`,Se?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`),children:[Se?(0,$.jsx)(l,{className:`size-3.5`}):(0,$.jsx)(Fe,{className:`size-3.5`}),Se?t.connectionReady:W||R?t.connectionNeedsSetup:t.connectionChecking]}),W&&(0,$.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:_e(t.composioAccountCount,{count:String(q.length)})})]}),(0,$.jsxs)(b,{variant:`primary`,className:`shrink-0`,disabled:I,onClick:()=>void X(),children:[I?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(ce,{className:`size-4`}),xe]})]}),R?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center justify-between gap-2 rounded-xl border border-danger/20 bg-danger/5 px-3 py-2 text-sm text-danger`,children:[(0,$.jsx)(`p`,{children:R}),(0,$.jsx)(b,{variant:`secondary`,disabled:I,onClick:()=>void Y(),children:t.composioRetry})]}):null,C&&!Se?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-amber-500/25 bg-amber-500/5 p-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:xn(C,be,t)}),C.recovery===`none`?null:(0,$.jsx)(b,{variant:`secondary`,disabled:I,onClick:()=>void(C.recovery===`retry`?Y():X()),children:C.recovery===`retry`?t.composioRetry:t.composioReconnectAccount})]}):null,Te&&De.length===0?(0,$.jsx)(`p`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/5 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:t.composioAuthConfigEmpty}):null,_?(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-start`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAccessTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:N===`read`?t.composioAccessReadHint:N===`admin`?t.composioAccessAdminHint:t.composioAccessWriteHint})]}),(0,$.jsxs)(o,{value:N,onChange:e=>void ge(e.currentTarget.value),children:[(0,$.jsx)(s,{value:`read`,children:t.composioAccessReadOnly}),(0,$.jsx)(s,{value:`write`,children:t.composioAccessReadWrite}),N===`admin`?(0,$.jsx)(s,{value:`admin`,children:t.composioAccessAdminCurrent}):null]})]}),(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm text-fg-muted`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioConfirmationPolicy}),(0,$.jsxs)(o,{value:_.confirmationPolicy,onChange:e=>void ve({confirmationPolicy:e.currentTarget.value}),children:[(0,$.jsx)(s,{value:`writes`,children:t.composioConfirmWrites}),(0,$.jsx)(s,{value:`always`,children:t.composioConfirmAlways}),_.confirmationPolicy===`never`?(0,$.jsx)(s,{value:`never`,children:t.composioConfirmNever}):null]})]}),(0,$.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAllowedAgents}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.allowedAgentIds.length?t.composioAllowedAgentsSelected:t.composioAllowedAgentsAll}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-2.5 py-1 text-xs transition-colors`,_.allowedAgentIds.length===0?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>void ve({allowedAgentIds:[]}),children:t.composioAllowedAgentsAllOption}),y.map(e=>(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-2.5 py-1 text-xs transition-colors`,_.allowedAgentIds.includes(e.id)?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>ye(e.id),children:e.name},e.id))]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-2 border-t border-edge-subtle p-4 text-xs text-fg-muted`,children:[(0,$.jsx)(`legend`,{children:i?`可用账号范围`:`Available accounts`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:_.selectedAccountIds===null,disabled:I,onChange:e=>void ve({selectedAccountIds:e.currentTarget.checked?null:[]})}),i?`所有账号(包括以后新增)`:`All accounts, including new ones`]}),_.selectedAccountIds!==null&&q.map(({primary:e})=>e.accountId&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:_.selectedAccountIds.includes(e.accountId),onChange:t=>void ve({selectedAccountIds:t.currentTarget.checked?[..._.selectedAccountIds,e.accountId]:_.selectedAccountIds.filter(t=>t!==e.accountId)})}),e.alias??e.accountEmail??e.accountId]},e.accountId)),_.selectedAccountIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择账号,Agent 无法使用此应用。`:`No accounts selected. Agents cannot use this app.`})]})]})]}):null,(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.composioConnectedAccounts}),W&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_e(t.composioAccountCount,{count:String(q.length)})})]}),(0,$.jsxs)(b,{variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:I,onClick:()=>void Y(),children:[(0,$.jsx)(G,{className:p(`size-3.5`,I&&`animate-spin`)}),t.refresh]})]}),q.length?(0,$.jsx)(`div`,{className:`divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:q.map(e=>{let r=e.primary,a=O.find(e=>r.accountId?e.accountId===r.accountId:e.connectionId===r.id),c=r.accountId?A[r.accountId]:void 0;return(0,$.jsxs)(`article`,{className:`px-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start justify-between gap-3 sm:flex-row`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,$.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:r.alias??r.workspace??r.accountEmail??r.username??t.composioUnnamedAuthorization})}),(0,$.jsx)(`p`,{className:`mt-1 break-all text-xs text-fg-muted`,children:r.accountEmail??r.username??r.workspace??r.accountId}),r.backendLabel&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:r.backendLabel}),(0,$.jsx)(`p`,{className:p(`mt-1 text-xs`,r.status===`active`?`text-emerald-700 dark:text-emerald-300`:`text-amber-700 dark:text-amber-300`),children:r.accountEnabled===!1?i?`已暂停`:`Paused`:Sn(r.status,t)}),a?(0,$.jsx)(`p`,{className:p(`mt-1 text-xs`,a.status===`failed`?`text-red-600`:`text-fg-subtle`),children:_e(t.connectorLearningStatus,{status:Cn(a,c,t),count:String(a.candidatesCreated)})}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[r.status===`pending`&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,onClick:()=>void he(r),children:i?`继续授权`:`Continue authorization`}),r.accountId&&(0,$.jsx)(b,{variant:`ghost`,className:`h-8 px-2.5 text-xs text-danger`,disabled:I,onClick:()=>re(r.accountId),children:i?`断开`:`Disconnect`}),r.accountId&&r.status!==`active`&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:I,onClick:()=>void X(r.accountId),children:t.composioReconnectAccount}),r.accountId&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:I,onClick:()=>void Z(()=>it(r.accountId,{enabled:r.accountEnabled===!1})),children:r.accountEnabled===!1?i?`启用`:`Enable`:i?`暂停`:`Pause`}),r.supportsLearning&&r.status===`active`&&r.accountEnabled!==!1?(0,$.jsxs)(b,{variant:`secondary`,className:`h-8 shrink-0 px-2.5 text-xs`,disabled:I,onClick:()=>void Z(async()=>{if(!r.accountId)throw Error(`Connector account is unavailable.`);await Ce(r.accountId),await n?.()}),children:[(0,$.jsx)(G,{className:`size-3.5`}),t.composioSyncNow]}):null]})]}),(0,$.jsxs)(`details`,{className:`mt-3 text-xs text-fg-muted`,children:[(0,$.jsx)(`summary`,{className:`w-fit cursor-pointer font-medium hover:text-fg`,children:t.composioAccountSettings}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-4 rounded-lg bg-surface-panel p-3`,children:[r.accountId&&(0,$.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,$.jsx)(`legend`,{className:`mb-2 font-medium`,children:t.composioAllowedAgents}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:r.allowedAgentIds==null,onChange:e=>void Z(()=>it(r.accountId,{allowedAgentIds:e.currentTarget.checked?null:[]}))}),t.composioAllowedAgentsAllOption]}),r.allowedAgentIds!=null&&y.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:r.allowedAgentIds.includes(e.id),onChange:t=>{let n=t.currentTarget.checked;Z(()=>it(r.accountId,{allowedAgentIds:n?[...r.allowedAgentIds,e.id]:r.allowedAgentIds.filter(t=>t!==e.id)}))}}),e.name]},e.id)),r.allowedAgentIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择 Agent:任何 Agent 都不能使用此账号。`:`No agents selected: this account is unavailable to all agents.`})]}),r.supportsLearning&&c?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:c.scanEnabled,disabled:I,onChange:e=>void Z(()=>fe(r.accountId,{scanEnabled:e.currentTarget.checked}))}),t.connectorScheduledScan]}),c.scanEnabled?(0,$.jsxs)(`label`,{className:`sm:col-span-2`,children:[t.connectorScanInterval,(0,$.jsxs)(o,{className:`mt-1`,value:String(c.intervalMinutes??30),disabled:I,onChange:e=>void Z(()=>fe(r.accountId,{intervalMinutes:Number(e.currentTarget.value)})),children:[(0,$.jsxs)(s,{value:`5`,children:[`5 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`15`,children:[`15 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`30`,children:[`30 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`60`,children:[`60 `,t.connectorMinutes]})]})]}):null]}):null,(0,$.jsxs)(`label`,{className:`block`,children:[t.composioAccountAlias,(0,$.jsx)(`input`,{className:p(vn,`mt-1 h-8 py-1 text-xs`),defaultValue:r.alias??``,onBlur:e=>{e.currentTarget.value!==(r.alias??``)&&Z(()=>de(r.id,{alias:e.currentTarget.value}))}})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.authorizations.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 break-all font-mono text-fg-subtle`,children:[t.composioAuthorizationId,`: `,e.providerConnectionId]}),(0,$.jsx)(b,{variant:`ghost`,className:`size-7 shrink-0 p-0 text-danger`,title:t.composioRevoke,disabled:I,onClick:()=>te(e.id),children:(0,$.jsx)(Ge,{className:`size-3.5`})})]},e.id))}),(0,$.jsx)(`div`,{className:`flex justify-end gap-1`,children:(0,$.jsx)(b,{variant:`ghost`,className:`size-8 p-0`,title:t.refresh,disabled:I,onClick:()=>void Z(()=>ke(r.id)),children:(0,$.jsx)(G,{className:`size-4`})})})]})]})]},e.key)})}):I&&!W?(0,$.jsxs)(`div`,{"aria-busy":`true`,"aria-label":t.connectionChecking,className:`space-y-3`,children:[(0,$.jsx)(x,{className:`h-16 w-full`}),(0,$.jsx)(x,{className:`h-16 w-full`})]}):W?(0,$.jsx)(`div`,{className:`rounded-xl border border-dashed border-edge px-4 py-8 text-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioConnectionsEmpty})}):null]}),(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-base`,onToggle:e=>oe(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`space-y-5 border-t border-edge-subtle px-4 py-4`,children:[se?(0,$.jsx)(x,{"aria-label":t.connectionChecking,className:`h-16 w-full`}):null,V?(0,$.jsxs)(`p`,{className:`rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,children:[t.composioDiagnosticsUnavailable,(0,$.jsx)(b,{variant:`ghost`,disabled:se,onClick:()=>void pe(),children:t.composioRetry})]}):null,E?.mode===`byok`?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAuthConfigTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:Te?t.composioAuthConfigRequiredHint:t.composioAuthConfigOptionalHint})]}),(0,$.jsx)(`a`,{className:`text-xs font-medium text-accent-fg hover:underline`,href:`https://app.composio.dev`,target:`_blank`,rel:`noreferrer`,children:t.composioAuthConfigManage})]}),(0,$.jsxs)(o,{className:`mt-3`,value:typeof e.config?.authConfigId==`string`?e.config.authConfigId:``,disabled:I,onChange:e=>void me(e.currentTarget.value),children:[Te?null:(0,$.jsx)(s,{value:``,children:t.composioAuthConfigManaged}),Te&&typeof e.config?.authConfigId!=`string`?(0,$.jsx)(s,{value:``,disabled:!0,children:t.composioAuthConfigSelect}):null,De.map(e=>(0,$.jsxs)(s,{value:e.id,children:[e.name,` · `,e.authScheme??`OAuth`]},e.id))]})]}):null,(0,$.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),(0,$.jsx)(`div`,{className:`space-y-2`,children:u.length?u.slice(0,8).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:[bn(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),(0,$.jsx)(`div`,{className:`space-y-2`,children:m.length?m.slice(0,5).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})})]})]})]})]}),(0,$.jsx)(Ee,{open:ne!==null,title:i?`断开账号`:`Disconnect account`,description:i?`停止此账号的工具使用和学习,并撤销其全部授权。已保存的数据不会删除。`:`Stop tool access and learning for this account and revoke all its authorizations. Saved data will not be deleted.`,confirmLabel:i?`断开`:`Disconnect`,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=ne;re(null),e&&Z(()=>H(e))},onCancel:()=>re(null)}),(0,$.jsx)(Ee,{open:U!==null,title:t.composioRevoke,description:t.composioRevokeConfirm,confirmLabel:t.composioRevoke,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=U;te(null),e&&Z(()=>Be(e))},onCancel:()=>te(null)})]})}var Tn=p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D);function En(e,t){let n={};for(let r of e?.setup.config??[]){let e=t.config?.[r.key]??r.defaultValue??``;n[r.key]=typeof e==`string`?e:JSON.stringify(e,null,2)}return n}function Dn(e,t){let n=t.trim();return e===`json`?n?JSON.parse(n):void 0:e===`number`?n?Number(n):void 0:e===`boolean`?n===`true`:n||void 0}function On({instance:e,definition:t,onClose:n,onChanged:r,t:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(()=>En(t,e)),[y,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),D=t?.setup.config??[],O=(e.materialized.type===`mcp`||e.materialized.type===`memorySource`)&&D.length>0&&(t?.setup.secrets??[]).length===0,A=e.materialized.type===`mcp`,j=e.materialized.type===`composio`,M=e.materialized.type===`memorySource`,N=t?Y(t,i):null,P=(0,Q.useCallback)(async()=>{C(!0),x(null);try{let t=await Te(e.instanceId);T(t),t.ok||x(t.error??t.action??i.healthStatusLabels[t.status]),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{C(!1)}},[e.instanceId,r,i.healthStatusLabels]),F=(0,Q.useCallback)(async()=>{o(!0),x(null);try{await Ue(e.instanceId),await r(),n()}catch(e){x(e instanceof Error?e.message:String(e)),o(!1)}},[e.instanceId,r,n]),I=(0,Q.useCallback)(async()=>{if(!(!t||!O)){u(!0),x(null);try{let n={};for(let e of t.setup.config??[]){let t=Dn(e.type,_[e.key]??``);t!==void 0&&(n[e.key]=t)}await nt(e.instanceId,{config:n}),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[_,t,e.instanceId,r,O]),R=(0,Q.useCallback)(async()=>{m(!0),g(null),x(null);try{g((await ot(e.connectorId)).recordIds.length),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{m(!1)}},[e.connectorId,r]);return(0,$.jsxs)(oe,{open:!0,onOpenChange:e=>{e||n()},children:[(0,$.jsxs)(st,{children:[(0,$.jsx)(ue,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(ee,{className:p(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,j?`h-[min(100dvh-2rem,36rem)] w-[min(100%-2rem,40rem)]`:`h-[min(100dvh-2rem,44rem)] w-[min(100%-2rem,min(92vw,54rem))]`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(X,{connector:t,size:`lg`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(k,{className:`text-base font-semibold text-fg`,children:e.displayName}),(0,$.jsx)(ne,{className:`mt-1 text-sm text-fg-muted`,children:N??(e.materialized.type===`mcp`?_e(i.mcpServerRuntime,{serverId:e.materialized.serverId}):_e(i.runtimeLabel,{runtime:e.materialized.type}))})]})]}),(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:p(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,ae.focusRingPanel),"aria-label":i.modalClose,children:[(0,$.jsx)(te,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`sr-only`,children:i.modalClose})]})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:[y?(0,$.jsx)(`p`,{className:`mb-4 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:y}):null,A?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-fg-muted`,role:`status`,children:w?.ok?_e(i.toolsAvailable,{count:String(w.toolCount)}):w?i.healthStatusLabels[w.status]:e.usage.lastHealthStatus?i.healthStatusLabels[e.usage.lastHealthStatus]:i.healthNotTested}),(0,$.jsxs)(b,{variant:`secondary`,"aria-busy":S,disabled:S||!e.enabled,onClick:()=>void P(),children:[S?(0,$.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4`,"aria-hidden":!0}),i.test]})]}),O?D.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key)):null]}):null,j?(0,$.jsx)(wn,{instance:e,t:i,onChanged:r}):null,M?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-edge bg-surface-base p-4 text-sm`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:i.connectedSourceSync}),N?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:N}):null,h===null?null:(0,$.jsx)(`p`,{className:`mt-1 text-xs text-emerald-600`,children:_e(i.connectedSourceSynced,{count:String(h)})})]}),(0,$.jsxs)(b,{disabled:f,onClick:()=>void R(),children:[f?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(je,{className:`size-4`}),i.composioSyncNow]})]}),O?(0,$.jsx)(`div`,{className:`grid gap-3 rounded-xl border border-edge bg-surface-base p-4`,children:D.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key))}):null]}):null,!A&&!j&&!M?(0,$.jsx)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:(0,$.jsx)(`p`,{children:i.connectorPolicyHint})}):null,(0,$.jsxs)(`details`,{className:`mt-5 rounded-xl border border-edge`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-danger`,children:i.dangerZone}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 border-t border-danger/15 px-4 py-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-fg-muted`,children:i.removeConnectorHint}),(0,$.jsxs)(b,{variant:`secondary`,className:`shrink-0 border-danger/30 text-danger hover:bg-danger/10`,disabled:a,onClick:()=>c(!0),children:[a?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(Ge,{className:`size-4`}),i.remove]})]})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,$.jsx)(b,{variant:`secondary`,onClick:n,children:i.modalClose}),(A||M)&&O?(0,$.jsxs)(b,{variant:`primary`,disabled:l,onClick:()=>void I(),children:[l?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(E,{className:`size-4`}),i.modalSave]}):null]})]})]}),(0,$.jsx)(Ee,{open:s,title:_e(i.removeConfirmTitle,{name:e.displayName}),description:i.removeConfirmDescription,confirmLabel:i.removeConfirmAction,cancelLabel:i.modalCancel,destructive:!0,onConfirm:()=>{c(!1),F()},onCancel:()=>{a||c(!1)}})]})}function kn(e){let t=(0,ft.c)(2),n;return t[0]===e?n=t[1]:(n=e.instance.materialized.type===`cli`&&e.definition?(0,$.jsx)(R,{definition:e.definition,instance:e.instance,onClose:e.onClose,onChanged:e.onChanged}):(0,$.jsx)(On,{...e}),t[0]=e,t[1]=n),n}function An(e){let t=(0,ft.c)(59),{instance:n,definition:r,highlighted:i,onOpenDetails:a,t:o}=e,s=i===void 0?!1:i,c;t[0]!==r||t[1]!==n?(c=Ct(n,r),t[0]=r,t[1]=n,t[2]=c):c=t[2];let u=c.state,d;t[3]!==r||t[4]!==o?(d=r?Y(r,o):null,t[3]=r,t[4]=o,t[5]=d):d=t[5];let f=d,m,h,g,_,v,y,b,x,S;if(t[6]!==u||t[7]!==r||t[8]!==s||t[9]!==n||t[10]!==a||t[11]!==o.connectionChecking||t[12]!==o.connectionNeedsSetup||t[13]!==o.connectionReady){m=u===`ready`?{label:o.connectionReady,Icon:l,className:`text-emerald-700 dark:text-emerald-300`}:u===`needs_setup`?{label:o.connectionNeedsSetup,Icon:Fe,className:`text-amber-700 dark:text-amber-300`}:{label:o.connectionChecking,Icon:rt,className:`text-fg-muted`},S=`button`;let e=u===`needs_setup`&&`border-amber-500/25`,i=s&&`bg-accent-soft`;t[23]!==e||t[24]!==i?(h=p(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left hover:bg-surface-hover/45`,ae.transition,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,e,i),t[23]=e,t[24]=i,t[25]=h):h=t[25],t[26]!==n||t[27]!==a?(g=()=>a(n),t[26]=n,t[27]=a,t[28]=g):g=t[28],b=`flex w-full min-w-0 items-start gap-3`,t[29]===r?x=t[30]:(x=(0,$.jsx)(X,{connector:r,size:`sm`}),t[29]=r,t[30]=x),v=`min-w-0 flex-1`,t[31]===n.displayName?y=t[32]:(y=(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,title:n.displayName,children:n.displayName}),t[31]=n.displayName,t[32]=y),_=p(`mt-1 inline-flex items-center gap-1 text-[11px]`,m.className),t[6]=u,t[7]=r,t[8]=s,t[9]=n,t[10]=a,t[11]=o.connectionChecking,t[12]=o.connectionNeedsSetup,t[13]=o.connectionReady,t[14]=m,t[15]=h,t[16]=g,t[17]=_,t[18]=v,t[19]=y,t[20]=b,t[21]=x,t[22]=S}else m=t[14],h=t[15],g=t[16],_=t[17],v=t[18],y=t[19],b=t[20],x=t[21],S=t[22];let C;t[33]===m.Icon?C=t[34]:(C=(0,$.jsx)(m.Icon,{className:`size-3.5`,"aria-hidden":!0}),t[33]=m.Icon,t[34]=C);let w;t[35]!==m.label||t[36]!==C||t[37]!==_?(w=(0,$.jsxs)(`span`,{className:_,children:[C,m.label]}),t[35]=m.label,t[36]=C,t[37]=_,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==v||t[41]!==y?(T=(0,$.jsxs)(`div`,{className:v,children:[y,w]}),t[39]=w,t[40]=v,t[41]=y,t[42]=T):T=t[42];let E;t[43]!==T||t[44]!==b||t[45]!==x?(E=(0,$.jsxs)(`div`,{className:b,children:[x,T]}),t[43]=T,t[44]=b,t[45]=x,t[46]=E):E=t[46];let D;t[47]===f?D=t[48]:(D=f?(0,$.jsx)(`p`,{className:`mt-2 w-full line-clamp-2 text-xs leading-5 text-fg-muted`,title:f,children:f}):null,t[47]=f,t[48]=D);let O;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(W,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[49]=O):O=t[49];let k;t[50]===o.installedDetails?k=t[51]:(k=(0,$.jsxs)(`span`,{className:`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs text-fg-muted`,children:[o.installedDetails,O]}),t[50]=o.installedDetails,t[51]=k);let A;return t[52]!==h||t[53]!==g||t[54]!==E||t[55]!==D||t[56]!==k||t[57]!==S?(A=(0,$.jsxs)(`button`,{type:S,className:h,onClick:g,children:[E,D,k]}),t[52]=h,t[53]=g,t[54]=E,t[55]=D,t[56]=k,t[57]=S,t[58]=A):A=t[58],A}function jn(e,t){return Gt()}function Mn(e){let t=e.headers.filter(e=>e.key.trim()),n=t.find(e=>e.key.toLowerCase()===`authorization`&&!e.reference&&/^Bearer\s/i.test(e.value)),r=e.extra.auth||t.some(e=>e.reference)||e.extra.oauth&&t.some(e=>e.key.toLowerCase()===`authorization`)?`existing`:e.extra.oauth?`oauth`:n?`bearer`:t.length?`headers`:`auto`;return{mode:r,token:n?.value.replace(/^Bearer\s+/i,``)??``,apiKey:``,headerName:``,customHeaders:t.length?t:[Mt()],additionalHeaders:r===`bearer`?t.filter(e=>e!==n):r===`oauth`?t:[]}}function Nn(e,t){if(e.transport===`stdio`||t.mode===`existing`)return{...e,extra:{...e.extra}};let n={...e.extra};delete n.auth,t.mode!==`oauth`&&delete n.oauth;let r=t.mode===`headers`?t.customHeaders:t.additionalHeaders;if(t.mode===`bearer`){let e=t.token.trim().replace(/^Bearer\s+/i,``);r=[...r,Mt(`Authorization`,`Bearer ${e}`)]}return t.mode===`apiKey`&&(r=[...r,Mt(t.headerName.trim(),t.apiKey.trim())]),{...e,extra:n,headers:r,oauthClientId:t.mode===`oauth`?e.oauthClientId:``}}function Pn(e){let t=new Set;return e.findIndex(e=>{let n=e.key.trim();if(!n&&!e.value&&!e.reference)return!1;if(!/^[!#$%&'*+.^_`|~\da-z-]+$/i.test(n)||/[\r\n]/.test(e.value))return!0;let r=n.toLowerCase();return t.has(r)?!0:(t.add(r),!1)})}function Fn(){return p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D)}function In({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,pasteFailedTitle:o,dismissLabel:s,keyPlaceholder:c,valuePlaceholder:l,headers:u,onChange:d,referenceLabel:f=`Existing credential reference`,showValueLabel:m=`Show value`,hideValueLabel:h=`Hide value`,allowPaste:g=!0}){let[_,y]=(0,Q.useState)(new Set),[x,S]=(0,Q.useState)(!1),C=(e,t)=>{d(u.map((n,r)=>r===e?{...n,...t}:n))},w=()=>{d([...u,Mt()])},T=e=>{let t=u.filter((t,n)=>n!==e);d(t.length>0?t:[Mt()])},E=async()=>{try{let e=await v();if(!e){S(!0);return}let t=Pt(e);if(!t?.length){S(!0);return}d(t)}catch{S(!0)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,$.jsx)(`span`,{children:e}),t?(0,$.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),g?(0,$.jsxs)(b,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void E(),children:[(0,$.jsx)(q,{className:`size-3.5`,"aria-hidden":!0}),i]}):null]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map((e,t)=>(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto_auto]`,children:[(0,$.jsx)(`input`,{className:p(Fn(),`col-span-3 min-w-0 font-mono text-xs sm:col-span-1`),"aria-label":`${c} ${t+1}`,value:e.key,placeholder:c,onChange:e=>C(t,{key:e.target.value})}),(0,$.jsx)(`input`,{className:p(Fn(),`min-w-0 font-mono text-xs`),type:_.has(e.clientKey)?`text`:`password`,autoComplete:`off`,"aria-label":`${l} ${t+1}`,readOnly:!!e.reference,value:e.reference?f:e.value,placeholder:e.reference?f:l,onChange:e=>C(t,{value:e.target.value})}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,className:`size-10 shrink-0 px-0`,disabled:!!e.reference,"aria-label":_.has(e.clientKey)?h:m,onClick:()=>y(t=>{let n=new Set(t);return n.has(e.clientKey)?n.delete(e.clientKey):n.add(e.clientKey),n}),children:_.has(e.clientKey)?(0,$.jsx)(De,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(Je,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:u.length<=1&&!e.key&&!e.value,onClick:()=>T(t),"aria-label":r,children:(0,$.jsx)(Ge,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})}),e.reference?(0,$.jsx)(`p`,{className:`col-span-3 break-words text-xs text-fg-muted sm:col-span-4`,children:f}):null]},e.clientKey))}),(0,$.jsx)(Ee,{open:x,title:o,description:a,confirmLabel:s,onConfirm:()=>S(!1),onCancel:()=>S(!1)}),(0,$.jsxs)(`button`,{type:`button`,className:p(`self-start text-sm text-accent hover:underline`,ae.press),onClick:w,children:[`+ `,n]})]})}var Ln=p(`w-full min-w-0 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,D);function Rn(e){let t=(0,ft.c)(20),{value:n,onChange:r,label:i,t:a,required:o}=e,s=o===void 0?!1:o,[c,l]=(0,Q.useState)(!1),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=p(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=c?`text`:`password`,f;t[1]===r?f=t[2]:(f=e=>r(e.target.value),t[1]=r,t[2]=f);let m;t[3]!==s||t[4]!==d||t[5]!==f||t[6]!==n?(m=(0,$.jsx)(`input`,{className:u,type:d,value:n,required:s,autoComplete:`off`,onChange:f}),t[3]=s,t[4]=d,t[5]=f,t[6]=n,t[7]=m):m=t[7];let h;t[8]!==i||t[9]!==m?(h=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i,m]}),t[8]=i,t[9]=m,t[10]=h):h=t[10];let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>l(zn),t[11]=g):g=t[11];let _;t[12]===c?_=t[13]:(_=c?(0,$.jsx)(De,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),t[12]=c,t[13]=_);let v=c?a.setupHideValue:a.setupShowValue,y;t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(b,{type:`button`,variant:`ghost`,className:`gap-1.5 text-xs`,onClick:g,children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16];let x;return t[17]!==y||t[18]!==h?(x=(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[h,y]}),t[17]=y,t[18]=h,t[19]=x):x=t[19],x}function zn(e){return!e}function Bn(e){let t=(0,ft.c)(17),{headers:n,onChange:r,t:i,additional:a,environment:o}=e,s=a===void 0?!1:a,c=o===void 0?!1:o,l=c?i.envLabel:s?i.setupAdditionalHeaders:i.headersLabel,u=c?i.setupAddEnv:i.addHeader,d=c?i.setupRemoveEnv:i.removeHeader,f=c?i.setupEnvName:i.headerKeyPlaceholder,p=c?i.setupEnvValue:i.headerValuePlaceholder,m=!c,h;return t[0]!==n||t[1]!==r||t[2]!==i.optionalSuffix||t[3]!==i.pasteHeaders||t[4]!==i.pasteHeadersDismiss||t[5]!==i.pasteHeadersFailed||t[6]!==i.pasteHeadersFailedTitle||t[7]!==i.setupHideValue||t[8]!==i.setupReference||t[9]!==i.setupShowValue||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==f||t[14]!==p||t[15]!==m?(h=(0,$.jsx)(In,{label:l,optionalLabel:i.optionalSuffix,addLabel:u,removeHeaderAria:d,pasteLabel:i.pasteHeaders,pasteFailed:i.pasteHeadersFailed,pasteFailedTitle:i.pasteHeadersFailedTitle,dismissLabel:i.pasteHeadersDismiss,keyPlaceholder:f,valuePlaceholder:p,headers:n,onChange:r,referenceLabel:i.setupReference,showValueLabel:i.setupShowValue,hideValueLabel:i.setupHideValue,allowPaste:m}),t[0]=n,t[1]=r,t[2]=i.optionalSuffix,t[3]=i.pasteHeaders,t[4]=i.pasteHeadersDismiss,t[5]=i.pasteHeadersFailed,t[6]=i.pasteHeadersFailedTitle,t[7]=i.setupHideValue,t[8]=i.setupReference,t[9]=i.setupShowValue,t[10]=l,t[11]=u,t[12]=d,t[13]=f,t[14]=p,t[15]=m,t[16]=h):h=t[16],h}function Vn(e){let t=(0,ft.c)(52),{draft:n,onChange:r,t:i,allowExisting:a}=e,c=i.setupAuthLabel,l=i.setupAuthLabel,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=p(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=n.mode,f;t[1]===r?f=t[2]:(f=e=>r({mode:e.target.value}),t[1]=r,t[2]=f);let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=[`auto`,`oauth`,`bearer`,`apiKey`,`headers`,`none`],t[3]=m):m=t[3];let h;t[4]===i.setupAuthModes?h=t[5]:(h=m.map(e=>(0,$.jsx)(s,{value:e,children:i.setupAuthModes[e]},e)),t[4]=i.setupAuthModes,t[5]=h);let g;t[6]!==a||t[7]!==n.mode||t[8]!==i.setupAuthModes?(g=a||n.mode===`existing`?(0,$.jsx)(s,{value:`existing`,children:i.setupAuthModes.existing}):null,t[6]=a,t[7]=n.mode,t[8]=i.setupAuthModes,t[9]=g):g=t[9];let _;t[10]!==n.mode||t[11]!==i.setupAuthLabel||t[12]!==f||t[13]!==h||t[14]!==g?(_=(0,$.jsxs)(o,{"aria-label":l,className:u,value:d,onChange:f,children:[h,g]}),t[10]=n.mode,t[11]=i.setupAuthLabel,t[12]=f,t[13]=h,t[14]=g,t[15]=_):_=t[15];let v;t[16]!==i.setupAuthLabel||t[17]!==_?(v=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[c,_]}),t[16]=i.setupAuthLabel,t[17]=_,t[18]=v):v=t[18];let y;t[19]!==n.mode||t[20]!==i.setupAuthAutoHint?(y=n.mode===`auto`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthAutoHint}):null,t[19]=n.mode,t[20]=i.setupAuthAutoHint,t[21]=y):y=t[21];let b;t[22]!==n.mode||t[23]!==i.setupAuthOAuthHint?(b=n.mode===`oauth`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthOAuthHint}):null,t[22]=n.mode,t[23]=i.setupAuthOAuthHint,t[24]=b):b=t[24];let x;t[25]!==n.mode||t[26]!==i.setupExistingHint?(x=n.mode===`existing`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupExistingHint}):null,t[25]=n.mode,t[26]=i.setupExistingHint,t[27]=x):x=t[27];let S;t[28]!==n.mode||t[29]!==n.token||t[30]!==r||t[31]!==i?(S=n.mode===`bearer`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Rn,{value:n.token,onChange:e=>r({token:e}),label:i.setupTokenLabel,t:i,required:!0}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupTokenHint})]}):null,t[28]=n.mode,t[29]=n.token,t[30]=r,t[31]=i,t[32]=S):S=t[32];let C;t[33]!==n.apiKey||t[34]!==n.headerName||t[35]!==n.mode||t[36]!==r||t[37]!==i?(C=n.mode===`apiKey`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i.setupApiKeyHeader,(0,$.jsx)(`input`,{className:p(Ln,`mt-1.5`),placeholder:`x-api-key`,value:n.headerName,required:!0,onChange:e=>r({headerName:e.target.value})})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupApiKeyHint}),(0,$.jsx)(Rn,{value:n.apiKey,onChange:e=>r({apiKey:e}),label:`API Key`,t:i,required:!0})]}):null,t[33]=n.apiKey,t[34]=n.headerName,t[35]=n.mode,t[36]=r,t[37]=i,t[38]=C):C=t[38];let w;t[39]!==n.customHeaders||t[40]!==n.mode||t[41]!==r||t[42]!==i?(w=n.mode===`headers`?(0,$.jsx)(Bn,{headers:n.customHeaders,onChange:e=>r({customHeaders:e}),t:i}):null,t[39]=n.customHeaders,t[40]=n.mode,t[41]=r,t[42]=i,t[43]=w):w=t[43];let T;return t[44]!==v||t[45]!==y||t[46]!==b||t[47]!==x||t[48]!==S||t[49]!==C||t[50]!==w?(T=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[v,y,b,x,S,C,w]}),t[44]=v,t[45]=y,t[46]=b,t[47]=x,t[48]=S,t[49]=C,t[50]=w,t[51]=T):T=t[51],T}function Hn(e){let t=(0,ft.c)(8),{label:n,children:r,hint:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{children:n}),t[0]=n,t[1]=a);let o;t[2]===i?o=t[3]:(o=i?(0,$.jsx)(`span`,{className:`block text-xs font-normal text-fg-muted`,children:i}):null,t[2]=i,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-fg`,children:[a,r,o]}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Un({row:e,t,onUpdate:n}){let[r,i]=(0,Q.useState)(()=>It(e.envJson?JSON.parse(e.envJson):void 0)),[a,o]=(0,Q.useState)(!1),s=[];try{s=Rt(e.argsText)??[]}catch{}let c=e=>n({argsText:JSON.stringify(e)});return(0,$.jsxs)(`div`,{"data-field":`commandOptions`,className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.argsLabel}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,onClick:()=>o(e=>!e),children:a?t.setupArgsRows:t.setupArgsPaste})]}),a?(0,$.jsx)(Hn,{label:t.setupArgsPaste,hint:t.argsHint,children:(0,$.jsx)(`input`,{className:Ln,value:e.argsText,onChange:e=>n({argsText:e.target.value})})}):s.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`input`,{className:Ln,"aria-label":`${t.argsLabel} ${n+1}`,value:e,onChange:e=>c(s.map((t,r)=>r===n?e.target.value:t))}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,"aria-label":t.setupRemoveArg,onClick:()=>c(s.filter((e,t)=>t!==n)),children:(0,$.jsx)(Ge,{className:`size-4`,"aria-hidden":!0})})]},n)),a?null:(0,$.jsxs)(b,{type:`button`,variant:`ghost`,onClick:()=>c([...s,``]),children:[(0,$.jsx)(he,{className:`size-4`,"aria-hidden":!0}),t.setupAddArg]})]}),(0,$.jsx)(Bn,{environment:!0,headers:r,t,onChange:e=>{i(e),n({envEntries:e,envJson:JSON.stringify(Ft(e)??{})})}})]})}function Wn(e){let t=(0,ft.c)(15),{row:n,t:r,onUpdate:i,variant:a,showOAuth:c,idReadOnly:l}=e,u=a===void 0?`all`:a,d=c===void 0?!1:c,f=l===void 0?!1:l,p=u!==`advanced`,m=u!==`basic`,h;t[0]!==p||t[1]!==i||t[2]!==n||t[3]!==r?(h=p?(0,$.jsxs)($.Fragment,{children:[n.transport===`stdio`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:`${r.commandLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`command`,className:Ln,value:n.command,required:!0,onChange:e=>i({command:e.target.value})})}),(0,$.jsx)(Un,{row:n,t:r,onUpdate:i})]}):(0,$.jsx)(Hn,{label:`${r.urlLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`url`,className:Ln,value:n.url,placeholder:`https://example.com/mcp`,required:!0,onChange:e=>i({url:e.target.value})})}),(0,$.jsx)(Hn,{label:r.setupNameLabel,hint:r.setupNameHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.displayName??``,placeholder:r.setupNamePlaceholder,onChange:e=>i({displayName:e.target.value})})})]}):null,t[0]=p,t[1]=i,t[2]=n,t[3]=r,t[4]=h):h=t[4];let g;t[5]!==m||t[6]!==f||t[7]!==i||t[8]!==n||t[9]!==d||t[10]!==r?(g=m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:r.serverIdLabel,hint:r.setupIdHint,children:(0,$.jsx)(`input`,{className:Ln,readOnly:f,value:n.id,onChange:e=>i({id:e.target.value}),placeholder:r.serverIdPlaceholder})}),n.transport===`stdio`?(0,$.jsx)(Hn,{label:r.cwdLabel,children:(0,$.jsx)(`input`,{className:Ln,value:n.cwd,onChange:e=>i({cwd:e.target.value})})}):null,n.transport!==`stdio`&&d?(0,$.jsx)(Hn,{label:r.oauthClientIdLabel,hint:r.oauthClientIdHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.oauthClientId,onChange:e=>i({oauthClientId:e.target.value})})}):null,(0,$.jsx)(Hn,{label:r.exposureLabel,hint:r.setupExposureHint,children:(0,$.jsx)(o,{"aria-label":r.exposureLabel,className:Ln,value:n.exposure,onChange:e=>i({exposure:e.target.value}),children:[`codemode`,`deferred`,`direct`,`hidden`].map(e=>(0,$.jsx)(s,{value:e,children:r.exposureLabels[e]},e))})}),(0,$.jsx)(Hn,{label:r.requestTimeoutLabel,children:(0,$.jsx)(dt,{allowEmpty:!0,type:`number`,min:1,className:Ln,value:n.timeout??``,placeholder:r.setupDefaultTimeout,onChange:e=>i({timeout:e.target.value?Number(e.target.value):void 0})})})]}):null,t[5]=m,t[6]=f,t[7]=i,t[8]=n,t[9]=d,t[10]=r,t[11]=g):g=t[11];let _;return t[12]!==h||t[13]!==g?(_=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[h,g]}),t[12]=h,t[13]=g,t[14]=_):_=t[14],_}function Gn(e,t){let n=e;if(n?.status===429)return t.setupRateLimited;if(n?.status===401)return t.setupGatewayUnauthorized;if(n?.status===404||n?.status===409)return t.setupConflict;if(n?.status&&n.status>=500)return t.setupGatewayCheckFailed;let r={command_missing:t.setupCommandMissing,connection_refused:t.setupConnectionRefused,host_not_found:t.setupHostNotFound,timeout:t.setupTimedOut,access_denied:t.setupAccessDenied,network:t.setupServiceNetworkFailed,tls:t.setupTlsFailed,invalid_response:t.setupInvalidResponse,not_found:t.setupEndpointNotFound,rate_limited:t.setupServiceRateLimited,configuration:t.setupInvalidConfig};if(n?.errorCode&&Object.hasOwn(r,n.errorCode))return r[n.errorCode];let i=e instanceof Error?e.message:typeof e==`string`?e:n?.error??``;return/ENOENT|command not found|executable.{0,30}not found/i.test(i)?t.setupCommandMissing:/ECONNREFUSED|connection refused/i.test(i)?t.setupConnectionRefused:/ENOTFOUND|EAI_AGAIN|could not resolve/i.test(i)?t.setupHostNotFound:/timeout|timed out/i.test(i)?t.setupTimedOut:/fetch failed|failed to fetch|network error|NetworkError/i.test(i)?n?.error===void 0?t.setupGatewayNetworkFailed:t.setupServiceNetworkFailed:/\b(?:401|403)\b|unauthorized|forbidden|permission denied/i.test(i)?t.setupAccessDenied:t.setupCheckFailed}function Kn(e,t){return JSON.stringify({id:e.id,config:qt(Nn(e,t))})}function qn(e,t){try{return Kn(e,t)}catch{return JSON.stringify({row:e,auth:t})}}function Jn(e){let{t,cs:n}=e,r=(0,Q.useId)(),[i,a]=(0,Q.useState)(e.initialRow),[c,f]=(0,Q.useState)(()=>Mn(e.initialRow)),[m,h]=(0,Q.useState)(`idle`),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(),[C,w]=(0,Q.useState)(),[T,E]=(0,Q.useState)(),[D,O]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(``),[P,F]=(0,Q.useState)(``),[I,L]=(0,Q.useState)([]),[R,z]=(0,Q.useState)(`0`),[B,V]=(0,Q.useState)(0),[H,U]=(0,Q.useState)(``),[re,W]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(!1),se=e.mode===`edit`,[G,ce]=(0,Q.useState)(``),K=(0,Q.useRef)(void 0),[le]=(0,Q.useState)(()=>qn(e.initialRow,Mn(e.initialRow))),q=(0,Q.useRef)(e.mode===`edit`?e.initialRow.id:``),de=(0,Q.useRef)(void 0),J=(0,Q.useRef)(void 0),fe=(0,Q.useRef)(void 0),Y=(0,Q.useRef)(null),pe=(0,Q.useRef)(``),X=(0,Q.useRef)(!0),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)(e.onSaved);ye.current=e.onSaved;let Z=T?.state===`starting`||T?.state===`authorizing`,be=m!==`idle`||Z,xe=le!==qn(i,c),Se=i.extra.enabled===!1,Ce=!v&&(xe||!!M.trim());(0,Q.useEffect)(()=>(X.current=!0,()=>{X.current=!1,de.current?.abort(),Y.current?.close(),K.current&&Zt(K.current).catch(()=>{})}),[]),(0,Q.useEffect)(()=>{if(!Ce)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ce]),(0,Q.useEffect)(()=>{if(!x)return;let e=_e.current?.querySelector(`[data-field="${x.field}"]`),t=e?.closest(`details`);t&&(t.open=!0);let n=e?.querySelector(`input,button,textarea`)??e;return n?.setAttribute(`aria-invalid`,`true`),n?.setAttribute(`aria-describedby`,r),x.focus!==!1&&(n??ve.current)?.focus(),()=>{n?.removeAttribute(`aria-invalid`),n?.removeAttribute(`aria-describedby`)}},[x,r]),(0,Q.useEffect)(()=>{if(!T||!Z)return;let e=new AbortController;J.current=e;let n;async function r(){try{let n=await en(K.current,e.signal);if(e.signal.aborted||(E(n),n.authorizationUrl&&pe.current!==n.authorizationUrl&&(pe.current=n.authorizationUrl,window.electronAPI?.shell?.openExternalUrl?!(await window.electronAPI.shell.openExternalUrl(n.authorizationUrl)).ok&&!e.signal.aborted&&_(t.oauthOpenFailed):Y.current&&!Y.current.closed&&Y.current.location.replace(n.authorizationUrl)),e.signal.aborted))return;if(n.state===`connected`){fe.current=void 0,Y.current?.close(),w({state:`connected`,toolCount:n.toolCount}),_(``);return}if(n.state===`error`||n.state===`cancelled`){fe.current=void 0,Y.current?.close(),_(n.state===`cancelled`?t.setupCancelled:t.setupAuthFailed),/client.{0,20}(id|registration)|register|registration/i.test(n.error??``)&&O(!0);return}}catch{if(e.signal.aborted)return;we(),Y.current?.close(),_(t.setupAuthFailed);return}n=setTimeout(()=>void r(),1200)}return r(),()=>{e.abort(),clearTimeout(n)}},[T?.id,Z,t.oauthOpenFailed,t.setupCancelled,t.setupAuthFailed]);function we(){de.current?.abort(),J.current?.abort(),K.current&&Zt(K.current).catch(()=>{}),K.current=void 0,ce(``),W(!1),w(void 0),E(void 0),_(``),S(void 0)}function Te(e){a(t=>({...t,...e})),we()}function De(e){f(t=>({...t,...e})),we()}function Oe(){m===`saving`||Z||(m===`checking`&&(we(),h(`idle`)),Ce?ae(!0):e.onClose())}function ke(){try{L(Wt(M)),z(`0`),F(``)}catch{F(t.setupImportError),L([])}}function Ae(){let t=I[Number(R)];if(!t)return;let n={...t,id:q.current||t.id,clientKey:e.initialRow.clientKey,extra:{...t.extra,...q.current?{enabled:i.extra.enabled}:{}}};a(n),f(Mn(n)),we(),V(e=>e+1),j(!1),N(``),L([])}function je(e){function n(e,t){return S({field:e,message:t}),!1}if(e.transport===`streamable-http`){try{e.url=Ut(e.url)}catch{return n(`url`,t.setupAddressInvalid)}if(c.mode===`bearer`&&!c.token.trim().replace(/^Bearer\s*/i,``)||c.mode===`apiKey`&&(!c.apiKey.trim()||!c.headerName.trim()))return n(`auth`,t.setupCredentialRequired);if(Pn(e.headers)>=0)return n(`auth`,t.setupHeaderInvalid);if(c.mode===`oauth`&&e.headers.some(e=>e.key.trim().toLowerCase()===`authorization`))return n(`auth`,t.setupOAuthHeaderConflict);if(c.mode===`headers`&&!e.headers.some(e=>e.key.trim()&&(e.value.trim()||e.reference)))return n(`auth`,t.setupCredentialRequired)}else if(!e.command.trim())return n(`command`,t.setupCommandRequired);if(e.timeout!==void 0&&(!Number.isFinite(e.timeout)||e.timeout<=0))return n(`advanced`,t.setupInvalidConfig);try{qt(e)}catch(r){return n(e.transport===`stdio`?`commandOptions`:`advanced`,r instanceof Error&&r.message.startsWith(`Environment`)?t.setupEnvInvalid:t.setupInvalidConfig)}return!0}async function Me(){_(``),h(`checking`),pe.current=``,window.electronAPI?.shell?.openExternalUrl||(Y.current=window.open(`about:blank`,`_blank`),Y.current&&(Y.current.opener=null));try{let e=await $t(K.current);if(!X.current){Y.current?.close(),K.current&&Zt(K.current).catch(()=>{});return}fe.current=e.id,E(e)}catch{Y.current?.close(),X.current&&_(t.setupAuthFailed)}finally{X.current&&h(`idle`)}}async function Ne(){let r=Nn(i,c);if(!je(r))return;let o=e.existingCustomServers.filter(t=>t.clientKey!==e.initialRow.clientKey&&t.id!==q.current),s=new Set([...e.managedServerIds,...o.map(e=>e.id)]);if(r.id=q.current||r.id.trim()||Ht(r,s),!/^[a-zA-Z0-9_-]+$/.test(r.id)||[...s].some(e=>e.replace(/-/g,`_`)===r.id.replace(/-/g,`_`))){S({field:`advanced`,message:n.duplicateServerId});return}we(),h(`checking`);let l=new AbortController;de.current=l;try{let n=await Yt(r,q.current||void 0,e.initialRow.extra,l.signal);if(!X.current||l.signal.aborted){Zt(n.id).catch(()=>{});return}K.current=n.id,a(r),ce(qn(r,c));let i=await Xt(n.id,l.signal);if(!X.current||l.signal.aborted)return;w(i),i.state===`error`&&_(Gn(i,t))}catch(e){X.current&&!l.signal.aborted&&_(e.status===409?t.setupConflict:Gn(e,t))}finally{X.current&&de.current===l&&h(`idle`)}}async function Pe(n=!1){if(!(!K.current||C?.state!==`connected`||G!==qn(i,c))){h(`saving`),_(``);try{let t=await Qt(K.current,n);K.current=void 0,await ye.current().catch(()=>{}),t?.reloadRequired?y(!0):e.onClose()}catch(e){let n=e.status;n===404||n===409?(we(),_(t.setupConflict)):_(t.setupSaveFailed)}finally{X.current&&h(`idle`)}}}async function Fe(){J.current?.abort();let e=K.current;fe.current=void 0,E(void 0),Y.current?.close(),_(t.setupCancelled),h(`checking`);try{e&&await tn(e)}catch{X.current&&(we(),_(t.setupCancelled))}finally{X.current&&h(`idle`)}}async function Ie(){T?.authorizationUrl&&(window.electronAPI?.shell?.openExternalUrl?(await window.electronAPI.shell.openExternalUrl(T.authorizationUrl)).ok||_(t.oauthOpenFailed):window.open(T.authorizationUrl,`_blank`,`noopener,noreferrer`))}async function Le(){if(T)try{await nn(K.current,H),U(``),_(``)}catch{_(t.setupRedirectInvalid)}}let Re=!!K.current&&G===qn(i,c)&&(c.mode===`oauth`||c.mode===`auto`&&C?.state===`oauth_required`)&&C?.state!==`connected`,ze=/^(?:https?:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?=[:/]|$)/i.test(i.url.trim()),Be=I[Number(R)];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(oe,{open:e.open,onOpenChange:e=>{e||Oe()},children:(0,$.jsxs)(st,{children:[(0,$.jsx)(ue,{className:`fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(ee,{ref:he,tabIndex:-1,className:`fixed left-1/2 top-1/2 z-[60] flex h-[min(44rem,calc(100dvh-2rem))] w-[min(42rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`,onOpenAutoFocus:e=>{e.preventDefault(),he.current?.focus()},children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge p-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(k,{className:`font-semibold`,children:e.mode===`edit`?t.setupEditTitle:t.setupTitle}),(0,$.jsx)(ne,{className:`mt-1 text-sm text-fg-muted`,children:t.setupHint})]}),(0,$.jsx)(`button`,{type:`button`,disabled:m===`saving`||Z,onClick:Oe,className:`rounded-lg p-2 text-fg-muted hover:bg-surface-hover disabled:opacity-50`,"aria-label":n.modalClose,children:(0,$.jsx)(te,{className:`size-5`,"aria-hidden":!0})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-5`,children:[A?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(b,{variant:`ghost`,onClick:()=>j(!1),children:t.setupImportBack}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportEmpty}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[t.setupImport,(0,$.jsx)(`textarea`,{className:p(Ln,`mt-1.5 min-h-40 font-mono text-xs`),value:M,placeholder:`{"mcpServers": {"docs": {"url": "https://example.com/mcp"}}}`,onChange:e=>{N(e.target.value),L([]),F(``)}})]}),(0,$.jsx)(b,{variant:`secondary`,disabled:!M.trim(),onClick:ke,children:t.setupImportPreview}),P?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:P}):null,Be?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportScope}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium`,children:[t.setupImportChoose,(0,$.jsx)(o,{"aria-label":t.setupImportChoose,className:p(Ln,`mt-1.5`),value:R,onChange:e=>z(e.target.value),children:I.map((e,t)=>(0,$.jsx)(s,{value:String(t),children:e.displayName||e.id||un(e)},t))})]}),(0,$.jsxs)(`p`,{className:`break-all text-sm text-fg-muted`,children:[Be.transport===`stdio`?t.setupUseCommand:t.setupUseUrl,` · `,un(Be)]})]}):null]}):(0,$.jsxs)(`form`,{ref:_e,noValidate:!0,onBlurCapture:e=>{if(e.target instanceof HTMLInputElement&&e.target.dataset.field===`url`&&i.url.trim())try{Ut(i.url)}catch{S({field:`url`,message:t.setupAddressInvalid,focus:!1})}},onSubmit:e=>{e.preventDefault(),Ne()},children:[(0,$.jsxs)(`fieldset`,{disabled:be||v,className:`min-w-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(me,{className:`flex gap-1`,role:`group`,"aria-label":t.transportLabel,children:[`streamable-http`,`stdio`].map(e=>(0,$.jsx)(b,{type:`button`,variant:i.transport===e?`secondary`:`ghost`,"aria-pressed":i.transport===e,onClick:()=>Te({transport:e}),children:e===`stdio`?t.setupUseCommand:t.setupUseUrl},e))}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,onClick:()=>j(!0),children:t.setupImport})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(Wn,{row:i,t,variant:`basic`,onUpdate:Te},`${i.transport}-${B}`)}),i.transport===`streamable-http`?(0,$.jsx)(`div`,{"data-field":`auth`,children:(0,$.jsx)(Vn,{allowExisting:!!i.extra.auth||i.headers.some(e=>!!e.reference),draft:c,onChange:De,t})}):null,x?(0,$.jsx)(`p`,{id:r,ref:ve,tabIndex:-1,role:`alert`,className:`text-sm text-danger`,children:x.message}):null,(0,$.jsxs)(`details`,{"data-field":`advanced`,className:`rounded-lg border border-edge p-3`,open:D,onToggle:e=>O(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg-muted`,children:t.setupAdvanced}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[(0,$.jsx)(Wn,{row:i,t,variant:`advanced`,idReadOnly:se,showOAuth:c.mode===`oauth`,onUpdate:Te}),i.transport===`streamable-http`&&c.mode!==`headers`&&c.mode!==`existing`?(0,$.jsx)(Bn,{additional:!0,headers:c.additionalHeaders,onChange:e=>De({additionalHeaders:e}),t}):null]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:i.transport===`stdio`?t.setupCommandHostHint:ze?t.setupLocalhostHint:t.setupGatewayHint}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.setupTestNotice})]}),(0,$.jsx)(`button`,{type:`submit`,hidden:!0})]}),v?(0,$.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-fg`,children:t.setupReloadRequired}):null,!A&&!v?(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,"aria-live":`polite`,children:[m===`idle`?null:(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(d,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),m===`saving`?t.setupSaving:t.setupChecking]}),m===`idle`&&se&&!xe&&!C&&!g&&!Z?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:Se?t.setupDisabled:e.lastCheck?t.setupLastCheck.replace(`{{count}}`,String(e.lastCheck.toolCount)):t.setupSavedUnchecked}):null,C?.state===`connected`?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-success`,children:[(0,$.jsx)(l,{className:`size-4 shrink-0`,"aria-hidden":!0}),C.toolCount?t.setupConnected.replace(`{{count}}`,String(C.toolCount)):t.setupZeroTools]}),(0,$.jsx)(b,{ref:ge,variant:`secondary`,onClick:()=>W(!0),children:t.viewTools})]}):null,C?.state===`token_required`?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:t.setupNeedsAuth}):null,C?.state===`oauth_required`&&!Z?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupOAuthRequired}):null,Z?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(d,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),t.setupAuthorizing]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[T?.authorizationUrl?(0,$.jsxs)(b,{variant:`secondary`,onClick:()=>void Ie(),children:[(0,$.jsx)(u,{className:`size-4`,"aria-hidden":!0}),t.oauthOpenAuthorization]}):null,(0,$.jsx)(b,{variant:`ghost`,onClick:()=>void Fe(),children:t.setupCancelAuth})]}),T?.acceptsRedirect?(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:t.setupRemoteFallback}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.setupRedirectHint}),(0,$.jsxs)(`label`,{className:`mt-2 block text-sm`,children:[t.setupRedirectLabel,(0,$.jsx)(`input`,{className:Ln,value:H,onChange:e=>U(e.target.value)})]}),(0,$.jsx)(b,{className:`mt-2`,disabled:!H.trim(),onClick:()=>void Le(),children:t.setupContinue})]}):null]}):null,g?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-1 text-sm`,children:[(0,$.jsx)(`p`,{className:`text-danger`,children:g}),g!==t.setupSaveFailed&&m!==`saving`?(0,$.jsx)(`p`,{className:`text-fg-muted`,children:t.setupTestFailure}):null]}):null]}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge p-4`,children:[(0,$.jsx)(b,{variant:`secondary`,disabled:m===`saving`||Z,onClick:Oe,children:se||v?t.setupClose:n.modalCancel}),v?null:A?(0,$.jsx)(b,{variant:`primary`,disabled:!Be,onClick:Ae,children:t.setupImportApply}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(b,{variant:C?.state===`connected`?`secondary`:`primary`,disabled:be,onClick:()=>Re?void Me():void Ne(),children:Re?t.setupSignIn:t.setupTestConnection}),C?.state===`connected`&&G===qn(i,c)?(0,$.jsxs)($.Fragment,{children:[Se?(0,$.jsx)(b,{variant:`secondary`,disabled:be,onClick:()=>void Pe(!0),children:t.setupEnableSave}):null,(0,$.jsx)(b,{variant:`primary`,disabled:be,"aria-busy":be,onClick:()=>void Pe(),children:se?t.setupSaveOnly:t.setupAddConnection})]}):null]})]})]})]})}),(0,$.jsx)(Ee,{open:ie,title:t.setupUnsavedTitle,description:t.setupUnsavedHint,confirmLabel:t.setupDiscard,cancelLabel:t.setupKeepEditing,onCancel:()=>ae(!1),onConfirm:e.onClose,overlayClassName:`z-[70]`,contentClassName:`z-[70]`}),re?(0,$.jsx)(sn,{draftId:K.current,serverId:i.id,displayName:i.displayName,returnFocusTo:ge.current,t,onClose:()=>W(!1)}):null]})}var Yn=`recommended`,Xn=`builtin`,Zn=`composio`,Qn=`xopc-store`;function $n(e,t=`en`){return e==="default"&&t.startsWith(`zh`)?Yn:Xn}function er(e,t){let n=e.connectorManifest;if(!n||typeof n!=`object`||Array.isArray(n))return null;let r=n;if(r.contractVersion!==1||r.id!==e.name)return null;let i=r.runtime,a=r.auth;if(!i||typeof i!=`object`||Array.isArray(i)||!a||typeof a!=`object`||Array.isArray(a))return null;let o=i,s=a;if(o.type!==`mcp`||typeof o.serverId!=`string`)return null;let c=[`code`,`docs`,`browser`,`data`,`automation`,`custom`].includes(String(r.category??``))?r.category:`custom`,l=s.mode===`oauth`?{mode:`oauth`,...typeof s.clientId==`string`?{clientId:s.clientId}:{}}:s.mode===`apiKey`?{mode:`apiKey`}:{mode:`none`},u=e.localizations?.[t===`zh`?`zh-CN`:`en`];return{id:e.name,version:e.latestVersion??`store`,displayName:u?.displayName??(typeof r.displayName==`string`?r.displayName:e.name),description:u?.description??(typeof r.description==`string`?r.description:e.description),category:c,kind:`mcp`,source:`store`,...e.branding?.iconUrl?{branding:{logoUrl:e.branding.iconUrl,source:`registry`}}:{},capabilities:Array.isArray(r.capabilities)?r.capabilities.filter(e=>typeof e==`string`):[],tags:Array.isArray(r.tags)?r.tags.filter(e=>typeof e==`string`):[`store`],auth:l,setup:r.setup&&typeof r.setup==`object`&&!Array.isArray(r.setup)?r.setup:{},runtime:{type:`mcp`,serverId:o.serverId}}}function tr(e){return ie(e.map(e=>({connector:e,service:{id:e.id,source:e.source===`builtin`?`builtin-connector`:e.source===`store`?`store-connector`:`registry-connector`}})),`en`).map(e=>e.connector)}function nr(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/user-model`}function rr({embedded:e=!1,onHeaderActionChange:t}){let n=Z().filter(pn),r=g(e=>e.language),o=f(r),s=o.connectorsSettings,l=o.mcpSettings,u=h(e=>e.conversationId),m=!!u,_=a(),[v,x]=i(),S=v.get(`understanding`)===`1`,w=nr(v.get(`returnTo`)),E=!!v.get(`returnTo`)&&!S,D=v.get(`tab`),[k,j]=(0,Q.useState)(!S&&D===`connected`?`connected`:`discover`),{data:M}=y(m&&k===`discover`&&!S?[`service-recommendations`,r]:null,()=>N(r),{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>new Set(M?.items.filter(e=>e.service?.source===`store-plugin`).map(e=>re(e.id))??[]),[M]),F=(0,Q.useRef)(!1),[I,L]=(0,Q.useState)({catalog:[],registryCatalog:[],instances:[],loading:!0,error:null}),[R,z]=(0,Q.useState)(!1),[B,ee]=(0,Q.useState)(!1),[H,te]=(0,Q.useState)(1),[ne,W]=(0,Q.useState)(void 0),[ie,ae]=(0,Q.useState)(``),[oe,se]=(0,Q.useState)(S||E?v.get(`connector`)??``:``),[G,ce]=(0,Q.useState)($n(S?`understanding`:`default`,r)),[ue,q]=(0,Q.useState)(`name`),[de,fe]=(0,Q.useState)(S?`understand`:`all`),[Y,X]=(0,Q.useState)(null),[he,_e]=(0,Q.useState)(null),[xe,Ce]=(0,Q.useState)(null),[we,Te]=(0,Q.useState)(null),[Ee,De]=(0,Q.useState)(null),[Oe,ke]=(0,Q.useState)(null),{data:Ae,mutate:je}=C(m),Me=Ae?.payload?.config,Ne=(0,Q.useMemo)(()=>Me===void 0?null:Kt(Me),[Me]),Pe=Ne?.servers??[],Fe=I.instances.length+Pe.length+n.length,[Ie,Le]=(0,Q.useState)({});(0,Q.useEffect)(()=>{if(Le({}),!m||!Me)return;let e=new AbortController;return an(e.signal).then(t=>{e.signal.aborted||Le(t)}).catch(()=>{}),()=>e.abort()},[m,Me]);let Re=(0,Q.useCallback)(async()=>{if(!u){L({catalog:[],registryCatalog:[],instances:[],loading:!1,error:null});return}L(e=>({...e,loading:!0,error:null}));try{let[e,t]=await Promise.all([ve(),be()]);L(n=>({catalog:e,registryCatalog:n.registryCatalog,instances:t,loading:!1,error:null}))}catch(e){L({catalog:[],registryCatalog:[],instances:[],loading:!1,error:e instanceof Error?e.message:String(e)})}},[u]);(0,Q.useEffect)(()=>{Re()},[Re]),(0,Q.useEffect)(()=>{F.current||I.loading||m&&!Ne||(j(S?`discover`:Fe>0?`connected`:`discover`),F.current=!0)},[m,Fe,Ne,S,I.loading]),(0,Q.useEffect)(()=>{ce(e=>e===`builtin`||e===`recommended`?$n(S?`understanding`:`default`,r):e)},[r,S]);let ze=(0,Q.useCallback)(e=>{F.current=!0,j(e)},[]),Be=(0,Q.useMemo)(()=>[{id:Zn,displayName:s.composioSourceName},{id:Qn,displayName:s.storeSourceName}],[s.composioSourceName,s.storeSourceName]),Ve=(0,Q.useCallback)(async e=>{if(!m||G===`builtin`||G===`recommended`){L(e=>({...e,registryCatalog:[]})),te(1),W(void 0);return}let t=oe.trim(),n=Math.max(e?.page??1,1),i=e?.append??!1,a=G===`all`?Be:Be.filter(e=>e.id===G);if(a.length!==0){z(!0),i?L(e=>({...e,error:null})):(te(1),W(void 0),L(e=>({...e,registryCatalog:[],error:null})));try{let e=await Promise.all(a.map(async e=>{if(e.id===`composio`){let e=await ye({q:t||void 0,page:n,pageSize:24,verification:`experimental`});return{connectors:e.connectors,totalPages:e.meta.totalPages}}let i=await K({q:t||void 0,page:n,pageSize:24,sort:ue===`source`?`newest`:`downloads`});return{connectors:i.items.flatMap(e=>{let t=er(e,r);return t?[t]:[]}),totalPages:i.meta.totalPages}})),o=tr(e.flatMap(e=>e.connectors)),s=Math.max(1,...e.map(e=>e.totalPages??1));te(n),W(s),L(e=>({...e,registryCatalog:i?tr([...e.registryCatalog,...o]):o}))}catch(e){L(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{z(!1)}}},[ue,oe,G,m,Be,r]);(0,Q.useEffect)(()=>{if(k!==`discover`||I.loading)return;if(G===`builtin`||G===`recommended`){L(e=>({...e,registryCatalog:[]})),te(1),W(void 0);return}let e=window.setTimeout(()=>{Ve()},oe.trim()?350:0);return()=>window.clearTimeout(e)},[oe,G,Ve,I.loading,k]);let He=(0,Q.useMemo)(()=>new Set(I.instances.map(e=>e.connectorId)),[I.instances]),Ue=(0,Q.useMemo)(()=>new Map([...I.catalog,...I.registryCatalog].map(e=>[e.id,e])),[I.catalog,I.registryCatalog]);(0,Q.useEffect)(()=>{if(I.loading)return;let e=v.get(`connector`),t=v.get(`instance`);if(!e&&!t)return;let n=I.instances.find(n=>t?n.instanceId===t:n.connectorId===e);if(n)F.current=!0,ae(``),Ce(n.instanceId),Te(n),j(`connected`);else if(e){let t=Ue.get(e);if(!t)return;F.current=!0,ce($n(S?`understanding`:`default`,r)),se(``),_e(t),j(`discover`)}let i=new URLSearchParams(v);i.delete(`connector`),i.delete(`instance`),i.set(`tab`,n?`connected`:`discover`),x(i,{replace:!0})},[Ue,S,r,v,x,I.instances,I.loading]);let We=(0,Q.useCallback)(async e=>{ee(!0),L(e=>({...e,error:null}));try{let t=await T(e);X(U(t.definition,{packageName:t.packageName,version:t.version,reviewHash:t.reviewHash,permissions:t.permissions}))}catch(e){L(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{ee(!1)}},[]);(0,Q.useEffect)(()=>{let e=v.get(`storeConnector`);if(!m||!e)return;let t=new URLSearchParams(v);t.delete(`storeConnector`),x(t,{replace:!0}),We(e)},[m,v,x,We]);let Ge=(0,Q.useMemo)(()=>new Set(I.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[I.instances]),qe=(0,Q.useCallback)(async e=>{let t=await on(e);await je(),await Re(),t.reloadRequired&&L(e=>({...e,error:l.setupReloadRequired}))},[Re,je,l.setupReloadRequired]),Je=(0,Q.useCallback)(()=>{ke({mode:`add`,row:jn(Pe,Ge)})},[Pe,Ge]),Ye=Ke(e=>e.setPageHeader),Xe=Ke(e=>e.clearPageHeader),Ze=(0,Q.useMemo)(()=>({searchLabel:k===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder,search:(0,$.jsx)(ct,{value:k===`connected`?ie:oe,onChange:k===`connected`?ae:se,placeholder:k===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder}),secondary:(0,$.jsx)(jt,{onRefresh:k===`connected`&&m?Re:void 0,refreshing:I.loading,refreshLabel:s.refreshConnections,onBrowseCatalog:()=>ze(`discover`),onAddCustomServer:Je,addLabel:s.addConnection,browseLabel:s.addFromCatalog,customLabel:s.addCustomServerAdvanced,serviceLabel:r.startsWith(`zh`)?`应用连接服务`:`Connection service`,moreActionsLabel:o.capabilitiesHub.moreActions})}),[ie,s,oe,m,r,Re,o.capabilitiesHub.moreActions,Je,ze,I.loading,k]);(0,Q.useLayoutEffect)(()=>e?(t?.(Ze),()=>t?.(null)):(Ye({startExtra:null,main:(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:s.title})}),end:(0,$.jsx)(lt,{contribution:Ze})}),()=>Xe()),[Xe,s.title,e,Ze,t,Ye]);let Qe=(0,Q.useMemo)(()=>I.instances.map(e=>({instance:e,value:Ct(e,Ue.get(e.connectorId))})),[Ue,I.instances]),$e=(0,Q.useMemo)(()=>new Map(Qe.map(({instance:e,value:t})=>[e.instanceId,t])),[Qe]),et=(0,Q.useMemo)(()=>I.instances.filter(e=>V(e,ie)).sort((e,t)=>{let n={needs_setup:0,checking:1,ready:2},r=$e.get(e.instanceId)?.state??`checking`,i=$e.get(t.instanceId)?.state??`checking`;return n[r]-n[i]||e.displayName.localeCompare(t.displayName)}),[ie,$e,I.instances]),tt=(0,Q.useMemo)(()=>et.filter(e=>$e.get(e.instanceId)?.state===`needs_setup`),[$e,et]),nt=(0,Q.useMemo)(()=>et.filter(e=>$e.get(e.instanceId)?.state!==`needs_setup`),[$e,et]),rt=(0,Q.useMemo)(()=>Pe.filter(e=>A(e,ie)),[ie,Pe]),it=(0,Q.useMemo)(()=>{let e=ie.trim().toLowerCase();return n.filter(t=>[t.name,t.description,...(t.setup?.authorizations??[]).map(e=>e.title),...(t.components?.mcp??[]).map(e=>e.name)].filter(Boolean).join(` `).toLowerCase().includes(e))},[ie,n]),at=et.length+rt.length+it.length,ot=(0,Q.useMemo)(()=>I.catalog.filter(e=>e.source===`builtin`&&e.integrationStrategy?.preferred!==!1&&pe(e)),[I.catalog]),st=(0,Q.useMemo)(()=>G===`recommended`?[]:G===`builtin`?ot:G===`all`?tr([...ot,...I.registryCatalog]):I.registryCatalog,[ot,G,I.registryCatalog]),ut=(0,Q.useMemo)(()=>{let e=S?st.filter(e=>e.understanding?.mode===`activity`):tr(st).filter(e=>!P.has(re(e.id)));return ge(de===`all`?e:e.filter(e=>xt(e).includes(de)),oe,ue)},[ue,oe,st,S,de,P]),dt=(0,Q.useMemo)(()=>bt.filter(e=>st.some(t=>xt(t).includes(e))),[st]);(0,Q.useEffect)(()=>{de!==`all`&&!dt.includes(de)&&fe(`all`)},[dt,de]);let ft=k===`discover`&&G!==`builtin`&&!!(ne&&H<ne),mt=(0,Q.useMemo)(()=>I.instances.find(e=>e.instanceId===xe)??we,[xe,we,I.instances]),_t=(0,Q.useMemo)(()=>[{value:Yn,label:r===`zh`?`推荐服务`:`Recommended services`},{value:`all`,label:s.discoverSourceAll},{value:Xn,label:s.discoverSourceBuiltin},...Be.map(e=>({value:e.id,label:e.displayName}))],[s.discoverSourceAll,s.discoverSourceBuiltin,Be,r]),St=[{id:`connected`,label:s.tabConnected,count:Fe},{id:`discover`,label:s.tabDiscover}];return(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,$.jsxs)(`div`,{className:p(`mx-auto flex w-full max-w-7xl flex-col gap-6 px-4 sm:px-6 lg:px-8`,e?`pb-7 pt-3 lg:pb-9 lg:pt-4`:`py-7 lg:py-9`),children:[m?null:(0,$.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:s.tokenHint}),S?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.understandingSetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.understandingSetupHint})]}),(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`shrink-0`,onClick:()=>_(w),children:s.understandingSetupDone})]}):null,E?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.recoverySetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.recoverySetupHint})]}),(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`min-h-11 shrink-0`,onClick:()=>_(w),children:s.recoverySetupDone})]}):null,(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(`div`,{className:`border-b border-edge-subtle pb-3 dark:border-edge-subtle`,children:(0,$.jsx)(Se,{items:St,activeTab:k,onChange:ze,ariaLabel:s.navAria,tabIdPrefix:`connectors-tab`,panelIdPrefix:`connectors-panel`,className:`flex-wrap`})}),I.error?(0,$.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:I.error}):null,k===`connected`&&m?(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:I.loading?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.slice(0,3).map(e=>(0,$.jsx)(yt,{},e))}):Fe===0?(0,$.jsxs)(`div`,{className:`py-14 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.connectionsEmpty}),(0,$.jsx)(b,{type:`button`,variant:`primary`,className:`mt-4`,onClick:()=>ze(`discover`),children:s.addFromCatalog})]}):at===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.connectionsSearchEmpty}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[tt.length?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:s.needsAttentionTitle}),(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-amber-700 dark:text-amber-300`,children:tt.length})]}),(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:tt.map(e=>(0,$.jsx)(An,{instance:e,definition:Ue.get(e.connectorId),highlighted:e.instanceId===Ee,onOpenDetails:e=>{De(null),Ce(e.instanceId),Te(e)},t:s},e.instanceId))})]}):null,nt.length||it.length?(0,$.jsx)(`section`,{children:(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[nt.map(e=>(0,$.jsx)(An,{instance:e,definition:Ue.get(e.connectorId),highlighted:e.instanceId===Ee,onOpenDetails:e=>{De(null),Ce(e.instanceId),Te(e)},t:s},e.instanceId)),it.map(e=>(0,$.jsx)(mn,{extension:e,language:r,onOpen:()=>_(le(e.pluginId,`connections`,e.authorizationStatus===`required`))},e.id))]})}):null,rt.length||!ie.trim()?(0,$.jsx)(fn,{servers:rt,lastChecks:Ie,t:l,cs:s,onAdd:Je,onEdit:e=>ke({mode:`edit`,row:structuredClone(e)}),onRemove:qe}):null]})}):null,k===`discover`&&m?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[S?null:(0,$.jsx)(me,{className:`flex min-w-0 flex-1 basis-80 flex-wrap gap-2`,role:`group`,"aria-label":s.taskFilterAria,indicatorClassName:`rounded-lg bg-surface-active`,children:[`all`,...dt].map(e=>(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,de===e?`border-accent/40 bg-accent-soft text-accent-fg`:`border-edge bg-surface-panel text-fg-muted hover:bg-surface-hover hover:text-fg`),"aria-pressed":de===e,onClick:()=>fe(e),children:e===`all`?s.taskAll:s.connectorBenefitHeadings[e]},e))}),(0,$.jsxs)(`div`,{className:p(`ml-auto grid w-full gap-2 sm:flex sm:w-auto sm:justify-end`,S?`grid-cols-1`:`grid-cols-2`),children:[S?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(c,{value:G,options:_t,placeholder:s.discoverSourceAll,allowEmpty:!1,ariaLabel:s.registrySourceAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:ce})}),G===`recommended`?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(c,{value:ue,options:[{value:`name`,label:s.sortName},{value:`source`,label:s.sortSource}],placeholder:s.sortName,allowEmpty:!1,ariaLabel:s.sortAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:e=>q(e)})})]})]}),G===`recommended`?(0,$.jsx)(J,{layout:`cards`,initialCount:6,query:oe,onChanged:async()=>{await Re(),await je()}}):(I.loading||R)&&ut.length===0?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.map(e=>(0,$.jsx)(vt,{},e))}):ut.length===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.discoverEmpty}):(0,$.jsxs)(`div`,{className:`relative`,children:[R?(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[1] flex justify-center bg-surface-panel/40 pt-[min(28vh,7.5rem)] backdrop-blur-[1px] motion-reduce:backdrop-blur-none dark:bg-surface-base/35`,"aria-busy":`true`,"aria-label":s.loading,children:(0,$.jsx)(d,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:ut.map(e=>(0,$.jsx)(pt,{connector:e,installed:He.has(e.id)||gt(e,I.instances),onInstall:e=>{if(e.source===`store`){We(e.id);return}X(U(e))},onOpenDetails:e.source===`store`?void 0:_e,t:s},e.id))}),ft?(0,$.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,$.jsxs)(b,{type:`button`,variant:`secondary`,disabled:R||B,onClick:()=>void Ve({page:H+1,append:!0}),children:[R?(0,$.jsx)(d,{className:`size-4 animate-spin`}):null,s.loadMore]})}):null]})]}):null]}),Y?(0,$.jsx)(O,{draft:Y,onChange:X,onClose:()=>X(null),t:s,onInstalled:async e=>{await Re(),await je(),De(e.instanceId),ze(`connected`)}}):null,he?(0,$.jsx)(Dt,{connector:he,installed:He.has(he.id)||gt(he,I.instances),onClose:()=>_e(null),onInstall:e=>X(U(e)),t:s}):null,mt?(0,$.jsx)(kn,{instance:mt,definition:Ue.get(mt.connectorId),onClose:()=>{Ce(null),Te(null)},onChanged:Re,t:s,mcp:l}):null,Oe?(0,$.jsx)(Jn,{open:!0,mode:Oe.mode,initialRow:Oe.row,lastCheck:Oe.mode===`edit`?Ie[Oe.row.id]:void 0,existingCustomServers:Pe,config:Me,managedServerIds:Ge,t:l,cs:s,onClose:()=>ke(null),onSaved:async()=>{await je(),await Re(),ze(`connected`)}},`${Oe.mode}-${Oe.row.clientKey}`):null]})})}export{rr as ConnectorsPage};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{m as i,u as a}from"./chunk-KS7C4IRE-BvcCCgTW.js";import{n as o,r as s,t as c}from"./popover-select-DGKUpVsz.js";import{t as l}from"./circle-check-C23XjkUj.js";import{t as u}from"./external-link-DjqjBmc3.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./messages-DMXSIJUO.js";import{t as p}from"./cn-0WouolD0.js";import{i as m,l as h,n as g,o as _}from"./locale-store-DAgpZxAS.js";import{n as v}from"./copy-to-clipboard-HOJ79TWv.js";import{i as y}from"./vendor-swr-BIWyz7Rc.js";import{t as b}from"./button-aIC072nz.js";import{t as x}from"./skeleton-BI5TyibZ.js";import{n as S,r as C}from"./gateway-config-swr-BVqYVaGy.js";import{n as w}from"./electron-env-Dit0bHgy.js";import{$o as T,Al as E,Ao as D,B as O,Bc as k,Bn as A,Cs as j,Dd as M,E as N,El as P,Es as F,F as I,Fc as L,G as R,H as z,Hl as B,Hn as V,Ic as ee,Jo as H,K as U,Kc as te,Lc as ne,M as re,Md as W,N as ie,Os as ae,Pc as oe,Pd as se,Pl as G,Pu as ce,Qo as K,R as le,Rc as ue,Sd as q,Ss as de,T as J,Ts as fe,U as Y,Un as pe,V as X,Va as me,Vl as he,Vn as ge,W as _e,Xo as ve,Yo as ye,Za as Z,Zo as be,_i as xe,_o as Se,_s as Ce,as as we,bs as Te,ca as Ee,cd as De,cs as Oe,ds as ke,es as Ae,fd as je,gi as Me,gs as Ne,hi as Pe,jd as Fe,ld as Ie,ll as Le,ls as Re,mi as ze,ms as Be,ns as Ve,os as He,ps as Ue,qc as We,rl as Ge,ro as Ke,rs as qe,sd as Je,sl as Ye,ss as Xe,ts as Ze,tu as Qe,us as $e,vs as et,wl as tt,ws as nt,xd as rt,xs as it,yi as at,ys as ot,zc as st}from"./index-CiDVRMmX.js";import{n as ct,t as lt}from"./capability-header-actions-CDgI-YZF.js";import{t as ut}from"./connector-service-page-49mgdRET.js";import{t as dt}from"./number-input-DDeqHK-G.js";var Q=e(t(),1),ft=n(),$=r();function pt(e){let t=(0,ft.c)(57),{connector:n,installed:r,onInstall:i,onOpenDetails:a,t:o}=e,s,c,u,d,f,m;if(t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a||t[4]!==o){let e=n.capabilities.filter(mt),h=e.slice(0,2),g=Math.max(0,e.length-h.length),_=o.connect,v;t[11]!==n||t[12]!==o?(v=Y(n,o),t[11]=n,t[12]=o,t[13]=v):v=t[13];let y=v,x=n.verificationLevel===`verified`?o.connectorVerified:n.verificationLevel===`beta`?o.connectorBeta:n.verificationLevel===`experimental`?o.connectorExperimental:null,S;t[14]!==_||t[15]!==n||t[16]!==i?(S=e=>(0,$.jsxs)(b,{type:`button`,variant:`secondary`,className:p(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:()=>i(n),children:[(0,$.jsx)(Qe,{className:`size-4`}),_]}),t[14]=_,t[15]=n,t[16]=i,t[17]=S):S=t[17],s=S,m=`group flex min-h-[8.75rem] flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,c=`flex min-w-0 flex-1 flex-col`;let C;t[18]===n?C=t[19]:(C=(0,$.jsx)(X,{connector:n}),t[18]=n,t[19]=C);let w;t[20]!==n||t[21]!==a?(w=a?(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-sm font-semibold text-fg hover:underline`,onClick:()=>a(n),children:n.displayName}):(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[20]=n,t[21]=a,t[22]=w):w=t[22];let T;t[23]===x?T=t[24]:(T=x?(0,$.jsx)(`span`,{className:`mt-1 inline-flex rounded-full border border-edge px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:x}):null,t[23]=x,t[24]=T);let E;t[25]!==T||t[26]!==w?(E=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[w,T]}),t[25]=T,t[26]=w,t[27]=E):E=t[27];let D;t[28]!==E||t[29]!==C?(D=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[C,E]}),t[28]=E,t[29]=C,t[30]=D):D=t[30];let O;t[31]!==r||t[32]!==s?(O=r?null:(0,$.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 sm:flex`,children:s()}),t[31]=r,t[32]=s,t[33]=O):O=t[33];let k;t[34]!==r||t[35]!==o.connectedBadge?(k=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(l,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[34]=r,t[35]=o.connectedBadge,t[36]=k):k=t[36];let A;t[37]!==O||t[38]!==k?(A=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[O,k]}),t[37]=O,t[38]=k,t[39]=A):A=t[39],t[40]!==D||t[41]!==A?(u=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[D,A]}),t[40]=D,t[41]=A,t[42]=u):u=t[42],t[43]===y?d=t[44]:(d=(0,$.jsx)(`p`,{className:`mt-3 line-clamp-2 text-sm leading-6 text-fg-muted`,title:y,children:y}),t[43]=y,t[44]=d),f=h.length>0?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[h.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:o.connectorCapabilityLabels[e]??e},e)),g>0?(0,$.jsxs)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,g]}):null]}):null,t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=u,t[8]=d,t[9]=f,t[10]=m}else s=t[5],c=t[6],u=t[7],d=t[8],f=t[9],m=t[10];let h;t[45]!==c||t[46]!==u||t[47]!==d||t[48]!==f?(h=(0,$.jsxs)(`div`,{className:c,children:[u,d,f]}),t[45]=c,t[46]=u,t[47]=d,t[48]=f,t[49]=h):h=t[49];let g;t[50]!==r||t[51]!==s?(g=r?null:(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 border-t border-edge pt-3 sm:hidden`,children:s(`w-full`)}),t[50]=r,t[51]=s,t[52]=g):g=t[52];let _;return t[53]!==m||t[54]!==h||t[55]!==g?(_=(0,$.jsxs)(`div`,{className:m,children:[h,g]}),t[53]=m,t[54]=h,t[55]=g,t[56]=_):_=t[56],_}function mt(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}var ht=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function gt(e,t){return t.some(t=>t.connectorId===e.id)}var _t=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`;function vt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:p(`size-10 shrink-0 rounded-xl`,_t)}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full min-h-[9.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:p(`h-4 min-w-0 flex-1`,_t)}),(0,$.jsx)(`div`,{className:p(`h-8 w-[4.5rem] shrink-0 rounded-lg`,_t)})]}),(0,$.jsx)(`div`,{className:p(`h-3 w-full`,_t)}),(0,$.jsx)(`div`,{className:p(`h-3 w-[88%]`,_t)})]})]})}),e[1]=n):n=e[1],n}function yt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(x,{className:`size-9 shrink-0 rounded-lg`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4`,"aria-hidden":!0,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,$.jsx)(x,{className:`h-4 w-28 max-w-full`}),(0,$.jsx)(x,{className:`h-3 w-20 max-w-full`})]})]}),(0,$.jsx)(x,{className:`mt-2 h-3 w-48 max-w-full`}),(0,$.jsx)(x,{className:`ml-auto mt-auto h-3 w-16`})]}),e[1]=n):n=e[1],n}var bt=[`understand`,`act`,`reach`];function xt(e){if(e.benefits?.length)return[...new Set(e.benefits)];let t=new Set(e.capabilities),n=[e.id,e.displayName,...e.tags??[]].join(` `).toLowerCase(),r=[];return(t.has(`context`)||t.has(`memory_source`)||t.has(`resources`)||e.category===`docs`||e.category===`data`||/notion|drive|document|confluence|airtable|database|knowledge|wiki/.test(n))&&r.push(`understand`),t.has(`tools`)&&r.push(`act`),(t.has(`channel`)||/slack|telegram|discord|teams|mail|message|wechat|weixin/.test(n))&&r.push(`reach`),r.length?[...new Set(r)]:[`act`]}function St(e){return xt(e)[0]??`act`}function Ct(e,t){let n=t?St(t):`act`,r=e.connectionStatus===`connected`||e.status===`connected`||e.usage.lastHealthStatus===`ok`,i=e.status===`not_configured`||e.status===`failed`||e.status===`degraded`||e.status===`unauthorized`||e.connectionStatus===`unauthorized`||e.connectionStatus===`error`,a=n===`understand`?e.usage.lastResourceCount:n===`act`?e.usage.lastToolCount:void 0;return{benefit:n,state:r?`ready`:i?`needs_setup`:`checking`,availableCount:a}}function wt(e,t){return t.connectorCapabilityLabels[e]??e}function Tt(e,t){if(e.runtime.type===`mcp`)return _e(t.connectorRuntimeMcp,{serverId:e.runtime.serverId});let n=e.runtime.type===`composio`?e.runtime.toolkit:e.runtime.type===`cli`?e.runtime.adapterId:e.runtime.sourceKind;return _e(t.connectorRuntimeGeneric,{runtime:e.runtime.type,id:n??e.runtime.type})}function Et(e,t){return e.auth.mode===`cli`?t.connectorAuthCli:e.auth.mode===`oauth`?t.connectorAuthOAuth:e.auth.mode===`apiKey`?t.connectorAuthApiKey:t.connectorAuthNone}function Dt(e){let t=(0,ft.c)(133),{connector:n,installed:r,onClose:i,onInstall:a,t:o}=e,s;t[0]!==n||t[1]!==o?(s=Y(n,o),t[0]=n,t[1]=o,t[2]=s):s=t[2];let c=s,u,d,f,m,h,g,_,v,y,x,S,C,w,T,E,D;if(t[3]!==n||t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==o){let e=xt(n),a;t[24]!==n.setup.config||t[25]!==n.setup.secrets?(a=[...(n.setup.secrets??[]).filter(At),...(n.setup.config??[]).filter(kt)],t[24]=n.setup.config,t[25]=n.setup.secrets,t[26]=a):a=t[26];let s=a,b=n.capabilities.filter(Ot);f=oe,_=!0,t[27]===i?v=t[28]:(v=e=>{e||i()},t[27]=i,t[28]=v),d=st,t[29]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(ue,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),t[29]=g):g=t[29],u=ee,t[30]===Symbol.for(`react.memo_cache_sentinel`)?(m=p(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,42rem)] w-[min(100%-2rem,min(92vw,44rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),t[30]=m):m=t[30];let O;t[31]===n?O=t[32]:(O=(0,$.jsx)(X,{connector:n,size:`lg`}),t[31]=n,t[32]=O);let A;t[33]===n.displayName?A=t[34]:(A=(0,$.jsx)(k,{className:`text-base font-semibold text-fg`,children:n.displayName}),t[33]=n.displayName,t[34]=A);let j;t[35]!==r||t[36]!==o.connectedBadge?(j=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(l,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[35]=r,t[36]=o.connectedBadge,t[37]=j):j=t[37];let M;t[38]!==A||t[39]!==j?(M=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[A,j]}),t[38]=A,t[39]=j,t[40]=M):M=t[40];let N;t[41]===c?N=t[42]:(N=(0,$.jsx)(ne,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:c}),t[41]=c,t[42]=N);let F;t[43]!==M||t[44]!==N?(F=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[M,N]}),t[43]=M,t[44]=N,t[45]=F):F=t[45];let I;t[46]!==O||t[47]!==F?(I=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[O,F]}),t[46]=O,t[47]=F,t[48]=I):I=t[48];let R;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(R=p(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,ae.focusRingPanel),t[49]=R):R=t[49];let z;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(te,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[50]=z):z=t[50];let B;t[51]===o.modalClose?B=t[52]:(B=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:R,"aria-label":o.modalClose,children:z})}),t[51]=o.modalClose,t[52]=B),t[53]!==I||t[54]!==B?(h=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-5 py-5 sm:px-6`,children:[I,B]}),t[53]=I,t[54]=B,t[55]=h):h=t[55],T=`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-5 sm:px-6`,E=e.length?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:o.connectorWhyConnect}),(0,$.jsx)(`div`,{className:`mt-3 divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorBenefitHeadings[e]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:o.connectorBenefitHints[e]})]},e))})]}):null;let V;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(ce,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),t[56]=V):V=t[56];let H;t[57]===o.detailPermissions?H=t[58]:(H=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.detailPermissions}),t[57]=o.detailPermissions,t[58]=H);let U;t[59]!==n||t[60]!==o?(U=Et(n,o),t[59]=n,t[60]=o,t[61]=U):U=t[61];let re;t[62]===U?re=t[63]:(re=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:U}),t[62]=U,t[63]=re);let W;t[64]!==H||t[65]!==re?(W=(0,$.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-edge-subtle px-4 py-3`,children:[V,(0,$.jsxs)(`div`,{children:[H,re]})]}),t[64]=H,t[65]=re,t[66]=W):W=t[66];let ie;t[67]===o.connectorSetupTitle?ie=t[68]:(ie=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorSetupTitle}),t[67]=o.connectorSetupTitle,t[68]=ie);let se;t[69]!==s.length||t[70]!==o.connectorRequiredInputsCount||t[71]!==o.connectorSetupNone?(se=s.length?_e(o.connectorRequiredInputsCount,{count:String(s.length)}):o.connectorSetupNone,t[69]=s.length,t[70]=o.connectorRequiredInputsCount,t[71]=o.connectorSetupNone,t[72]=se):se=t[72];let G;t[73]===se?G=t[74]:(G=(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:se}),t[73]=se,t[74]=G);let K;t[75]!==ie||t[76]!==G?(K=(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[ie,G]}),t[75]=ie,t[76]=G,t[77]=K):K=t[77],t[78]!==W||t[79]!==K?(D=(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[W,K]}),t[78]=W,t[79]=K,t[80]=D):D=t[80],C=`rounded-xl border border-edge bg-surface-base`,t[81]===o.connectorTechnicalDetails?w=t[82]:(w=(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:o.connectorTechnicalDetails}),t[81]=o.connectorTechnicalDetails,t[82]=w),y=`space-y-5 border-t border-edge-subtle px-4 py-4`;let le;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(le=(0,$.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),t[83]=le):le=t[83];let q;t[84]===o.connectorRuntimeTitle?q=t[85]:(q=(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[le,o.connectorRuntimeTitle]}),t[84]=o.connectorRuntimeTitle,t[85]=q);let de;t[86]!==n||t[87]!==o?(de=Tt(n,o),t[86]=n,t[87]=o,t[88]=de):de=t[88];let J;t[89]===de?J=t[90]:(J=(0,$.jsx)(`p`,{className:`mt-1 break-words text-xs text-fg-subtle`,children:de}),t[89]=de,t[90]=J),t[91]!==q||t[92]!==J?(x=(0,$.jsxs)(`div`,{children:[q,J]}),t[91]=q,t[92]=J,t[93]=x):x=t[93],S=b.length?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:b.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-panel px-2 py-1 text-xs text-fg-muted`,children:wt(e,o)},e))}):null,t[3]=n,t[4]=c,t[5]=r,t[6]=i,t[7]=o,t[8]=u,t[9]=d,t[10]=f,t[11]=m,t[12]=h,t[13]=g,t[14]=_,t[15]=v,t[16]=y,t[17]=x,t[18]=S,t[19]=C,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else u=t[8],d=t[9],f=t[10],m=t[11],h=t[12],g=t[13],_=t[14],v=t[15],y=t[16],x=t[17],S=t[18],C=t[19],w=t[20],T=t[21],E=t[22],D=t[23];let O;t[94]!==y||t[95]!==x||t[96]!==S?(O=(0,$.jsxs)(`div`,{className:y,children:[x,S]}),t[94]=y,t[95]=x,t[96]=S,t[97]=O):O=t[97];let A;t[98]!==O||t[99]!==C||t[100]!==w?(A=(0,$.jsxs)(`details`,{className:C,children:[w,O]}),t[98]=O,t[99]=C,t[100]=w,t[101]=A):A=t[101];let j;t[102]!==A||t[103]!==T||t[104]!==E||t[105]!==D?(j=(0,$.jsxs)(`div`,{className:T,children:[E,D,A]}),t[102]=A,t[103]=T,t[104]=E,t[105]=D,t[106]=j):j=t[106];let M;t[107]===o.modalClose?M=t[108]:(M=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(b,{variant:`secondary`,children:o.modalClose})}),t[107]=o.modalClose,t[108]=M);let N;t[109]!==n||t[110]!==r||t[111]!==i||t[112]!==a||t[113]!==o.connect?(N=r?null:(0,$.jsxs)(b,{variant:`primary`,onClick:()=>{a(n),i()},children:[(0,$.jsx)(Qe,{className:`size-4`}),o.connect]}),t[109]=n,t[110]=r,t[111]=i,t[112]=a,t[113]=o.connect,t[114]=N):N=t[114];let F;t[115]!==M||t[116]!==N?(F=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-5 py-4 sm:px-6`,children:[M,N]}),t[115]=M,t[116]=N,t[117]=F):F=t[117];let I;t[118]!==u||t[119]!==m||t[120]!==h||t[121]!==j||t[122]!==F?(I=(0,$.jsxs)(u,{className:m,children:[h,j,F]}),t[118]=u,t[119]=m,t[120]=h,t[121]=j,t[122]=F,t[123]=I):I=t[123];let R;t[124]!==d||t[125]!==g||t[126]!==I?(R=(0,$.jsxs)(d,{children:[g,I]}),t[124]=d,t[125]=g,t[126]=I,t[127]=R):R=t[127];let z;return t[128]!==f||t[129]!==_||t[130]!==v||t[131]!==R?(z=(0,$.jsx)(f,{open:_,onOpenChange:v,children:R}),t[128]=f,t[129]=_,t[130]=v,t[131]=R,t[132]=z):z=t[132],z}function Ot(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}function kt(e){return e.required}function At(e){return e.required}var jt=(0,Q.memo)(function(e){let t=(0,ft.c)(45),{onRefresh:n,refreshing:r,refreshLabel:i,onBrowseCatalog:a,onAddCustomServer:o,addLabel:s,browseLabel:c,customLabel:l,serviceLabel:u,moreActionsLabel:f}=e,[m,h]=(0,Q.useState)(!1),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=p(`touch-target flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-fg outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[highlighted]:bg-surface-hover`,ae.transition),t[0]=g):g=t[0];let _=g,v;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(he,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[1]=v):v=t[1];let y;t[2]===s?y=t[3]:(y=(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:s}),t[2]=s,t[3]=y);let x;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(se,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[4]=x):x=t[4];let S;t[5]!==s||t[6]!==y?(S=(0,$.jsx)(at,{asChild:!0,children:(0,$.jsxs)(b,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":s,children:[v,y,x]})}),t[5]=s,t[6]=y,t[7]=S):S=t[7];let C;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,$.jsx)(Le,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[8]=C):C=t[8];let w;t[9]!==c||t[10]!==a?(w=(0,$.jsxs)(Pe,{className:_,onSelect:a,children:[C,c]}),t[9]=c,t[10]=a,t[11]=w):w=t[11];let T;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(We,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[12]=T):T=t[12];let E;t[13]!==l||t[14]!==o?(E=(0,$.jsxs)(Pe,{className:_,onSelect:o,children:[T,l]}),t[13]=l,t[14]=o,t[15]=E):E=t[15];let D;t[16]!==w||t[17]!==E?(D=(0,$.jsx)(Me,{children:(0,$.jsxs)(ze,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[w,E]})}),t[16]=w,t[17]=E,t[18]=D):D=t[18];let O;t[19]!==D||t[20]!==S?(O=(0,$.jsxs)(xe,{children:[S,D]}),t[19]=D,t[20]=S,t[21]=O):O=t[21];let k;t[22]===m?k=t[23]:(k=(0,$.jsx)(ut,{open:m,onOpenChange:h,hideTrigger:!0}),t[22]=m,t[23]=k);let A;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(Ie,{className:`size-4`,"aria-hidden":!0}),t[24]=A):A=t[24];let j;t[25]===f?j=t[26]:(j=(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`size-9 shrink-0 p-0`,"aria-label":f,title:f,children:A})}),t[25]=f,t[26]=j);let M;t[27]!==n||t[28]!==i||t[29]!==r?(M=n?(0,$.jsxs)(Pe,{className:_,disabled:r,onSelect:n,children:[r?(0,$.jsx)(d,{className:`size-4 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),i]}):null,t[27]=n,t[28]=i,t[29]=r,t[30]=M):M=t[30];let N,P;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(N=()=>h(!0),P=(0,$.jsx)(tt,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[31]=N,t[32]=P):(N=t[31],P=t[32]);let F;t[33]===u?F=t[34]:(F=(0,$.jsxs)(Pe,{className:_,onSelect:N,children:[P,u]}),t[33]=u,t[34]=F);let I;t[35]!==M||t[36]!==F?(I=(0,$.jsx)(Me,{children:(0,$.jsxs)(ze,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[M,F]})}),t[35]=M,t[36]=F,t[37]=I):I=t[37];let L;t[38]!==j||t[39]!==I?(L=(0,$.jsxs)(xe,{children:[j,I]}),t[38]=j,t[39]=I,t[40]=L):L=t[40];let R;return t[41]!==O||t[42]!==k||t[43]!==L?(R=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[O,k,L]}),t[41]=O,t[42]=k,t[43]=L,t[44]=R):R=t[44],R});function Mt(e=``,t=``){return{clientKey:crypto.randomUUID(),key:e,value:t}}var Nt=/^([^:=]+)[:=](.*)$/;function Pt(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return It(e)}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=Nt.exec(t);r&&n.push(Mt(r[1].trim(),r[2].trim()))}return n.length>0?n:null}function Ft(e){let t=Object.create(null);for(let n of e){let e=n.key.trim();e&&(t[e]=n.reference??n.value)}return Object.keys(t).length>0?t:void 0}function It(e){if(!e||typeof e!=`object`)return[Mt()];let t=Object.entries(e).map(([e,t])=>typeof t==`object`&&t&&!Array.isArray(t)?{...Mt(e),reference:t}:Mt(e,t==null?``:String(t)));return t.length>0?t:[Mt()]}function Lt(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.xopcConnector;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&t.managed===!0)}function Rt(e){let t=e.trim();if(!t)return;if(t.startsWith(`[`)){let e=JSON.parse(t);if(!Array.isArray(e)||e.some(e=>typeof e!=`string`))throw Error(`Command arguments must be a JSON array of strings.`);return e}let n=[],r=``,i=``,a=!1;for(let e=0;e<t.length;e++){let o=t[e];o===`\\`&&t[e+1]&&i!==`'`&&/[\s"'\\]/.test(t[e+1])?(r+=t[++e],a=!0):i?o===i?i=``:r+=o:o===`"`||o===`'`?(i=o,a=!0):/\s/.test(o)?a&&=(n.push(r),r=``,!1):(r+=o,a=!0)}if(i)throw Error(`Command arguments contain an unclosed quote.`);return a&&n.push(r),n}function zt(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Bt(e){let t={...e.extra,exposure:e.exposure};if(e.displayName?.trim()?t.displayName=e.displayName.trim():delete t.displayName,delete t.command,delete t.args,delete t.env,delete t.cwd,delete t.url,delete t.headers,delete t.type,e.transport===`stdio`){t.type=`stdio`,t.command=e.command.trim();let n=Rt(e.argsText);if(n&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envEntries){let n=new Set;for(let t of e.envEntries)if(!(!t.key.trim()&&!t.value&&!t.reference)){if(!t.key.trim()||n.has(t.key.trim()))throw Error(`Environment variable names must be non-empty and unique.`);n.add(t.key.trim())}let r=Ft(e.envEntries);r&&(t.env=r)}else e.envJson.trim()&&(t.env=zt(e.envJson));delete t.oauth,delete t.auth}else{t.type=`http`,t.url=e.url.trim();let n=Ft(e.headers);n&&(t.headers=n);let r={...t.oauth??{}};e.oauthClientId.trim()?r.clientId=e.oauthClientId.trim():delete r.clientId,Object.keys(r).length?t.oauth=r:delete t.oauth}return e.timeout===void 0?delete t.timeout:t.timeout=e.timeout,t}function Vt(e,t){let n=t.oauth;return{clientKey:e,id:e,displayName:typeof t.displayName==`string`?t.displayName:``,transport:typeof t.url==`string`?`streamable-http`:`stdio`,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?JSON.stringify(t.args):``,envJson:t.env?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:``,url:typeof t.url==`string`?t.url:``,headers:It(t.headers),oauthClientId:typeof n?.clientId==`string`?n.clientId:``,timeout:typeof t.timeout==`number`?t.timeout:void 0,exposure:t.exposure??`codemode`,extra:t}}function Ht(e,t){let n=`mcp`;try{n=e.transport===`streamable-http`?new URL(e.url).hostname:e.command.split(/[\\/]/).pop()||n}catch{}let r=n.replace(/[^a-zA-Z0-9_-]+/g,`_`).replace(/^_+|_+$/g,``)||`mcp`,i=new Set([...t].map(e=>e.replace(/-/g,`_`))),a=r;for(let e=2;i.has(a.replace(/-/g,`_`));e++)a=`${r}_${e}`;return a}function Ut(e){let t=e.trim(),n=new URL(/^[a-z][a-z\d+.-]*:/i.test(t)&&!/^[^/]+:\d+(?:[/?#]|$)/.test(t)?t:`${/^(localhost|127\.0\.0\.1)(:|\/|$)/i.test(t)?`http`:`https`}://${t}`);if(![`http:`,`https:`].includes(n.protocol)||n.username||n.password)throw Error(`Use an HTTP or HTTPS MCP address without embedded credentials.`);return n.href}function Wt(e){let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Expected a JSON object.`);let n=t.mcpServers??t.mcp?.servers??t.servers;if(n!==void 0&&(!n||typeof n!=`object`||Array.isArray(n)))throw Error(`Expected a server configuration object.`);let r=n?Object.entries(n):[[``,t]];if(!r.length)throw Error(`No MCP servers found.`);return r.map(([e,t])=>{if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid MCP server configuration.`);let n=t;if(typeof n.url!=`string`&&typeof n.command!=`string`)throw Error(`The configuration needs an MCP URL or command.`);if(n.args!==void 0&&(!Array.isArray(n.args)||n.args.some(e=>typeof e!=`string`)))throw Error(`Command arguments must be strings.`);let r=Vt(e,n);return r.clientKey=crypto.randomUUID(),r.url&&=Ut(r.url),r})}function Gt(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`streamable-http`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[],oauthClientId:``,timeout:void 0,exposure:`codemode`,extra:{}}}function Kt(e){let t=e?.mcp?.servers??{};return{servers:Object.entries(t).filter(([,e])=>!Lt(e)).map(([e,t])=>Vt(e,t)).sort((e,t)=>e.id.localeCompare(t.id))}}function qt(e){return Bt(e)}async function Jt(e,t){return(await _(m(`/api/mcp/servers/${encodeURIComponent(e)}/tools`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload.tools}async function Yt(e,t,n,r){return(await _(m(`/api/mcp/drafts`),{method:`POST`,signal:r,body:JSON.stringify({serverId:e.id,sourceServerId:t,expectedServer:n,server:Bt(e)})})).payload}async function Xt(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/probe`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload}async function Zt(e){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}`),{method:`DELETE`})}async function Qt(e,t=!1){let n=await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/commit`),{method:`POST`,body:JSON.stringify({enable:t})});return S(),n.payload}async function $t(e){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`POST`})).payload}async function en(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{signal:t})).payload}async function tn(e){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`DELETE`})}async function nn(e,t){await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/auth/redirect`),{method:`POST`,body:JSON.stringify({url:t})})}async function rn(e,t){return(await _(m(`/api/mcp/drafts/${encodeURIComponent(e)}/tools`),{signal:t})).payload.tools}async function an(e){let t=await _(m(`/api/mcp/servers`),{signal:e});return Object.fromEntries(t.payload.servers.filter(e=>e.lastCheck&&Number.isFinite(Date.parse(e.lastCheck.checkedAt))).map(e=>[e.id,e.lastCheck]))}async function on(e){let t=await _(m(`/api/mcp/servers/${encodeURIComponent(e.id)}`),{method:`DELETE`,body:JSON.stringify({expectedServer:e.extra})});return S(),t.payload}function sn(e){let t=(0,ft.c)(111),{serverId:n,displayName:r,returnFocusTo:i,draftId:a,t:o,onClose:s,onConfigure:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],t[0]=l):l=t[0];let[u,d]=(0,Q.useState)(l),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(0),x=(0,Q.useRef)(!1),S;t[1]!==a||t[2]!==n||t[3]!==o.setupAccessDenied||t[4]!==o.setupConflict||t[5]!==o.setupGatewayUnauthorized||t[6]!==o.setupRateLimited||t[7]!==o.toolsLoadFailed?(S=()=>{let e=new AbortController,t=!0;return p(!0),h(``),d([]),(a?rn(a,e.signal):Jt(n,e.signal)).then(e=>{t&&d(e)}).catch(e=>{let n=e?.status;t&&h(n===401?o.setupGatewayUnauthorized:n===403?o.setupAccessDenied:n===429?o.setupRateLimited:n===404||n===409?o.setupConflict:o.toolsLoadFailed)}).finally(()=>{t&&p(!1)}),()=>{t=!1,e.abort()}},t[1]=a,t[2]=n,t[3]=o.setupAccessDenied,t[4]=o.setupConflict,t[5]=o.setupGatewayUnauthorized,t[6]=o.setupRateLimited,t[7]=o.toolsLoadFailed,t[8]=S):S=t[8];let C;t[9]!==a||t[10]!==v||t[11]!==n||t[12]!==o?(C=[n,a,v,o],t[9]=a,t[10]=v,t[11]=n,t[12]=o,t[13]=C):C=t[13],(0,Q.useEffect)(S,C);let w,T,E,D,O,A,j,M,N,P,F,I,R;if(t[14]!==r||t[15]!==m||t[16]!==f||t[17]!==s||t[18]!==c||t[19]!==g||t[20]!==i||t[21]!==n||t[22]!==o.exposureLabels||t[23]!==o.setupConfigure||t[24]!==o.toolDetails||t[25]!==o.toolsClearSearch||t[26]!==o.toolsDialogSearchEmpty||t[27]!==o.toolsDialogSearchPlaceholder||t[28]!==o.toolsDialogSubtitle||t[29]!==o.toolsDialogTitle||t[30]!==o.toolsEmpty||t[31]!==o.toolsLoading||t[32]!==o.toolsRetryHint||t[33]!==o.toolsSearchSummary||t[34]!==o.toolsTitle||t[35]!==u){let e=g.trim().toLowerCase(),a;if(t[49]!==n){let e;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(e=/-/g,t[51]=e):e=t[51],a=n.replace(e,`_`),t[49]=n,t[50]=a}else a=t[50];let l=`mcp__${a}__`,d=u.filter(t=>`${t.name} ${t.description}`.toLowerCase().includes(e));E=oe,A=!0,t[52]===s?j=t[53]:(j=e=>{e||s()},t[52]=s,t[53]=j),T=st,t[54]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(ue,{className:`fixed inset-0 z-[60] bg-scrim`}),t[54]=O):O=t[54],w=ee,t[55]===i?I=t[56]:(I=e=>{(x.current||i)&&e.preventDefault(),!x.current&&i?.isConnected&&i.focus()},t[55]=i,t[56]=I),R=`fixed left-1/2 top-1/2 z-[60] flex h-[min(42rem,calc(100dvh-2rem))] w-[min(48rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`;let p;t[57]===o.toolsDialogTitle?p=t[58]:(p=(0,$.jsx)(k,{className:`font-semibold`,children:o.toolsDialogTitle}),t[57]=o.toolsDialogTitle,t[58]=p);let h;t[59]!==r||t[60]!==m||t[61]!==f||t[62]!==n||t[63]!==o.toolsDialogSubtitle||t[64]!==u.length?(h=f||m?r||n:o.toolsDialogSubtitle.replace(`{{serverId}}`,r||n).replace(`{{count}}`,String(u.length)),t[59]=r,t[60]=m,t[61]=f,t[62]=n,t[63]=o.toolsDialogSubtitle,t[64]=u.length,t[65]=h):h=t[65];let v;t[66]===h?v=t[67]:(v=(0,$.jsx)(ne,{className:`mt-1 break-words text-sm text-fg-muted`,children:h}),t[66]=h,t[67]=v);let y;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>_(e.target.value),t[68]=y):y=t[68];let S;t[69]!==g||t[70]!==o.toolsDialogSearchPlaceholder?(S=(0,$.jsx)(`input`,{className:`mt-4 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,value:g,onChange:y,placeholder:o.toolsDialogSearchPlaceholder,"aria-label":o.toolsDialogSearchPlaceholder}),t[69]=g,t[70]=o.toolsDialogSearchPlaceholder,t[71]=S):S=t[71];let C=e&&!f&&!m?(0,$.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-fg-muted`,children:o.toolsSearchSummary.replace(`{{visible}}`,String(d.length)).replace(`{{count}}`,String(u.length))}):null;t[72]!==p||t[73]!==v||t[74]!==S||t[75]!==C?(D=(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-edge p-5`,children:[p,v,S,C]}),t[72]=p,t[73]=v,t[74]=S,t[75]=C,t[76]=D):D=t[76],M=`min-h-0 flex-1 overflow-y-auto p-5`,N=f,t[77]!==o.toolsTitle||t[78]!==u.length?(P=o.toolsTitle.replace(`{{count}}`,String(u.length)),t[77]=o.toolsTitle,t[78]=u.length,t[79]=P):P=t[79],F=f?(0,$.jsx)(`div`,{role:`status`,"aria-label":o.toolsLoading,className:`space-y-3`,children:[0,1,2].map(ln)}):m?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm text-danger`,children:m}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:o.toolsRetryHint}),c?(0,$.jsx)(b,{variant:`secondary`,onClick:()=>{x.current=!0,c()},children:o.setupConfigure}):null]}):d.length?(0,$.jsx)(`div`,{className:`space-y-3`,children:d.map(e=>(0,$.jsxs)(`article`,{className:`rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`h3`,{className:`break-all font-mono text-sm font-semibold text-fg`,children:e.name.startsWith(l)?e.name.slice(l.length):e.name}),e.exposure&&Object.hasOwn(o.exposureLabels,e.exposure)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o.exposureLabels[e.exposure]}):null,e.description?(0,$.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap break-words text-sm text-fg-muted`,children:e.description}):null,(0,$.jsxs)(`details`,{className:`mt-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:o.toolDetails}),(0,$.jsx)(`p`,{className:`mt-2 break-all font-mono text-xs text-fg-muted`,children:e.name}),(0,$.jsx)(`pre`,{className:`mt-2 overflow-x-auto rounded-md bg-surface-panel p-3 text-xs text-fg`,children:JSON.stringify(e.inputSchema,null,2)})]})]},e.name))}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.length?o.toolsDialogSearchEmpty:o.toolsEmpty}),e?(0,$.jsx)(b,{variant:`secondary`,onClick:()=>_(``),children:o.toolsClearSearch}):null]}),t[14]=r,t[15]=m,t[16]=f,t[17]=s,t[18]=c,t[19]=g,t[20]=i,t[21]=n,t[22]=o.exposureLabels,t[23]=o.setupConfigure,t[24]=o.toolDetails,t[25]=o.toolsClearSearch,t[26]=o.toolsDialogSearchEmpty,t[27]=o.toolsDialogSearchPlaceholder,t[28]=o.toolsDialogSubtitle,t[29]=o.toolsDialogTitle,t[30]=o.toolsEmpty,t[31]=o.toolsLoading,t[32]=o.toolsRetryHint,t[33]=o.toolsSearchSummary,t[34]=o.toolsTitle,t[35]=u,t[36]=w,t[37]=T,t[38]=E,t[39]=D,t[40]=O,t[41]=A,t[42]=j,t[43]=M,t[44]=N,t[45]=P,t[46]=F,t[47]=I,t[48]=R}else w=t[36],T=t[37],E=t[38],D=t[39],O=t[40],A=t[41],j=t[42],M=t[43],N=t[44],P=t[45],F=t[46],I=t[47],R=t[48];let z;t[80]!==M||t[81]!==N||t[82]!==P||t[83]!==F?(z=(0,$.jsx)(`div`,{className:M,"aria-busy":N,"aria-label":P,children:F}),t[80]=M,t[81]=N,t[82]=P,t[83]=F,t[84]=z):z=t[84];let B;t[85]===Symbol.for(`react.memo_cache_sentinel`)?(B=()=>y(cn),t[85]=B):B=t[85];let V;t[86]!==f||t[87]!==o.refreshTools?(V=(0,$.jsx)(b,{variant:`secondary`,disabled:f,onClick:B,children:o.refreshTools}),t[86]=f,t[87]=o.refreshTools,t[88]=V):V=t[88];let H;t[89]!==s||t[90]!==o.toolsDialogClose?(H=(0,$.jsx)(L,{asChild:!0,children:(0,$.jsx)(b,{onClick:s,children:o.toolsDialogClose})}),t[89]=s,t[90]=o.toolsDialogClose,t[91]=H):H=t[91];let U;t[92]!==V||t[93]!==H?(U=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge p-4`,children:[V,H]}),t[92]=V,t[93]=H,t[94]=U):U=t[94];let te;t[95]!==w||t[96]!==D||t[97]!==z||t[98]!==U||t[99]!==I||t[100]!==R?(te=(0,$.jsxs)(w,{onCloseAutoFocus:I,className:R,children:[D,z,U]}),t[95]=w,t[96]=D,t[97]=z,t[98]=U,t[99]=I,t[100]=R,t[101]=te):te=t[101];let re;t[102]!==T||t[103]!==O||t[104]!==te?(re=(0,$.jsxs)(T,{children:[O,te]}),t[102]=T,t[103]=O,t[104]=te,t[105]=re):re=t[105];let W;return t[106]!==E||t[107]!==A||t[108]!==j||t[109]!==re?(W=(0,$.jsx)(E,{open:A,onOpenChange:j,children:re}),t[106]=E,t[107]=A,t[108]=j,t[109]=re,t[110]=W):W=t[110],W}function cn(e){return e+1}function ln(e){return(0,$.jsx)(x,{className:`h-24 w-full`},e)}function un(e){if(e.transport===`stdio`)return e.command.trim();try{let t=new URL(e.url);return`${t.protocol}//${t.host}${t.pathname}`}catch{return e.url.trim().split(/[?#]/,1)[0].replace(/\/\/[^/]*@/,`//`)}}function dn({row:e,lastCheck:t,t:n,cs:r,onEdit:i,onRemove:a}){let o=g(e=>e.language),[s,c]=(0,Q.useState)(!1),u=(0,Q.useRef)(null),[d,f]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),_=e.displayName||e.id,v=un(e),y=e.extra.enabled===!1,x=y?M:t?l:rt,S=e.transport===`stdio`?Ye:P,C=y?n.setupDisabled:t?r.customCheckSucceeded:r.customUnchecked,w=t?new Intl.DateTimeFormat(o,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.checkedAt)):null;return(0,$.jsxs)(`li`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`div`,{title:n.transportLabels[e.transport],className:`flex size-9 shrink-0 items-center justify-center rounded-xl border border-edge-subtle bg-surface-inset text-fg-muted`,children:(0,$.jsx)(S,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,$.jsx)(`h3`,{className:`min-w-0 max-w-full text-sm font-semibold text-fg`,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,title:_,className:`block max-w-full truncate rounded text-left hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:_})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px]`,children:[(0,$.jsxs)(`span`,{title:w?r.customLastChecked.replace(`{{time}}`,w):void 0,"aria-label":w?`${C} · ${r.customLastChecked.replace(`{{time}}`,w)}`:C,className:p(`inline-flex shrink-0 items-center gap-1`,!y&&t?`text-emerald-700 dark:text-emerald-300`:`text-fg-muted`),children:[(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),C]}),t?(0,$.jsx)(`span`,{className:`text-fg-muted`,children:r.customToolCount.replace(`{{count}}`,String(t.toolCount))}):null]})]})})]}),(0,$.jsx)(`p`,{title:v,className:`mt-2 truncate font-mono text-xs leading-5 text-fg-muted`,children:v})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[11px] text-fg-subtle`,children:n.transportLabels[e.transport]}),(0,$.jsx)(b,{variant:`ghost`,className:`h-8 px-2 py-1 text-xs`,onClick:i,children:n.setupConfigure}),(0,$.jsx)(b,{ref:u,variant:`secondary`,className:`h-8 px-2 py-1 text-xs shadow-none sm:shadow-none`,disabled:y,onClick:()=>c(!0),children:n.viewTools}),(0,$.jsxs)(xe,{children:[(0,$.jsx)(at,{asChild:!0,children:(0,$.jsx)(b,{variant:`ghost`,className:`size-8 p-0`,"aria-label":r.customManage.replace(`{{name}}`,_),title:r.customManage.replace(`{{name}}`,_),children:(0,$.jsx)(Ie,{className:`size-4`,"aria-hidden":!0})})}),(0,$.jsx)(Me,{children:(0,$.jsx)(ze,{align:`end`,sideOffset:6,className:`z-50 min-w-36 rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover`,children:(0,$.jsxs)(Pe,{onSelect:()=>f(!0),className:`flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-danger outline-none data-[highlighted]:bg-surface-hover`,children:[(0,$.jsx)(Ge,{className:`size-4`,"aria-hidden":!0}),n.removeServer]})})})]})]}),m?(0,$.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-danger`,children:m}):null,s?(0,$.jsx)(sn,{serverId:e.id,displayName:e.displayName,returnFocusTo:u.current,t:n,onClose:()=>c(!1),onConfigure:()=>{c(!1),i()}}):null,(0,$.jsx)(Ee,{open:d,title:r.removeConfirmTitle.replace(`{{name}}`,_),description:r.removeConfirmDescription,confirmLabel:n.removeServer,cancelLabel:r.modalCancel,destructive:!0,onCancel:()=>f(!1),onConfirm:()=>{f(!1),h(``),a().catch(()=>h(n.setupRemoveFailed))}})]})}function fn(e){let t=(0,ft.c)(30),{servers:n,lastChecks:r,t:i,cs:a,onAdd:o,onEdit:s,onRemove:c}=e,l;t[0]===a.customIntegrationsTitle?l=t[1]:(l=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:a.customIntegrationsTitle}),t[0]=a.customIntegrationsTitle,t[1]=l);let u;t[2]===n.length?u=t[3]:(u=(0,$.jsx)(`span`,{className:`rounded-md bg-surface-inset px-1.5 py-0.5 text-xs tabular-nums text-fg-muted`,children:n.length}),t[2]=n.length,t[3]=u);let d;t[4]!==l||t[5]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l,u]}),t[4]=l,t[5]=u,t[6]=d):d=t[6];let f;t[7]===a.customIntegrationsHint?f=t[8]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.customIntegrationsHint}),t[7]=a.customIntegrationsHint,t[8]=f);let p;t[9]!==d||t[10]!==f?(p=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[d,f]}),t[9]=d,t[10]=f,t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(he,{className:`size-3.5`,"aria-hidden":!0}),t[12]=m):m=t[12];let h;t[13]!==a.customAdd||t[14]!==o?(h=(0,$.jsxs)(b,{variant:`secondary`,className:`shrink-0 text-xs shadow-none sm:shadow-none`,onClick:o,children:[m,a.customAdd]}),t[13]=a.customAdd,t[14]=o,t[15]=h):h=t[15];let g;t[16]!==p||t[17]!==h?(g=(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[p,h]}),t[16]=p,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==a||t[20]!==r||t[21]!==s||t[22]!==c||t[23]!==n||t[24]!==i?(_=n.length?(0,$.jsx)(`ul`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,$.jsx)(dn,{row:e,lastCheck:r[e.id],t:i,cs:a,onEdit:()=>s(e),onRemove:()=>c(e)},e.clientKey))}):(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-edge px-5 py-8 text-center text-sm text-fg-muted`,children:a.customEmpty}),t[19]=a,t[20]=r,t[21]=s,t[22]=c,t[23]=n,t[24]=i,t[25]=_):_=t[25];let v;return t[26]!==a.customIntegrationsTitle||t[27]!==g||t[28]!==_?(v=(0,$.jsxs)(`section`,{"aria-label":a.customIntegrationsTitle,children:[g,_]}),t[26]=a.customIntegrationsTitle,t[27]=g,t[28]=_,t[29]=v):v=t[29],v}function pn(e){return e.format===`agent-plugin`&&!!e.pluginId&&(!!e.setup?.authorizations?.length||e.authorizationStatus===`required`||!!e.components?.mcp.some(e=>e.type!==`stdio`))}function mn(e){let t=(0,ft.c)(54),{extension:n,language:r,onOpen:i}=e,a;t[0]===r?a=t[1]:(a=r.startsWith(`zh`),t[0]=r,t[1]=a);let o=a,s;t[2]===o?s=t[3]:(s=(e,t)=>o?e:t,t[2]=o,t[3]=s);let c=s,u=n.installationState===`preparing`,d=n.activationEligible===!1,f=n.authorizationStatus===`required`,m;t[4]!==d||t[5]!==n.readiness||t[6]!==f||t[7]!==u||t[8]!==c?(m=u?c(`准备未完成`,`Setup incomplete`):d?c(`已停用`,`Disabled`):f?c(`需要授权`,`Authorization required`):n.readiness===`blocked`||n.readiness===`degraded`?c(`需要处理`,`Needs attention`):c(`已连接`,`Connected`),t[4]=d,t[5]=n.readiness,t[6]=f,t[7]=u,t[8]=c,t[9]=m):m=t[9];let h=m,g;t[10]!==d||t[11]!==f||t[12]!==u||t[13]!==c?(g=u?c(`继续安装`,`Continue setup`):!d&&f?c(`去授权`,`Connect account`):c(`查看详情`,`View details`),t[10]=d,t[11]=f,t[12]=u,t[13]=c,t[14]=g):g=t[14];let _=g,v;t[15]===n.setup?.authorizations?v=t[16]:(v=n.setup?.authorizations??[],t[15]=n.setup?.authorizations,t[16]=v);let y=v,b=y.length===1?y[0].title:n.name,x=u||!d&&(f||n.readiness===`blocked`||n.readiness===`degraded`),S=u?rt:d?M:x?Fe:l,C=x&&`border-amber-500/25`,w;t[17]===C?w=t[18]:(w=p(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left transition-colors hover:bg-surface-hover/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,C),t[17]=C,t[18]=w);let T=n.branding?.iconUrl,E;t[19]===T?E=t[20]:(E=(0,$.jsx)(I,{iconUrl:T,fallback:B,className:`size-9`}),t[19]=T,t[20]=E);let D;t[21]===b?D=t[22]:(D=(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-fg`,title:b,children:b}),t[21]=b,t[22]=D);let O=x?`text-amber-700 dark:text-amber-300`:d?`text-fg-muted`:`text-emerald-700 dark:text-emerald-300`,k;t[23]===O?k=t[24]:(k=p(`mt-1 inline-flex items-center gap-1 text-[11px]`,O),t[23]=O,t[24]=k);let A;t[25]===S?A=t[26]:(A=(0,$.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),t[25]=S,t[26]=A);let j;t[27]!==h||t[28]!==k||t[29]!==A?(j=(0,$.jsxs)(`span`,{className:k,children:[A,h]}),t[27]=h,t[28]=k,t[29]=A,t[30]=j):j=t[30];let N;t[31]!==D||t[32]!==j?(N=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[D,j]}),t[31]=D,t[32]=j,t[33]=N):N=t[33];let P;t[34]!==N||t[35]!==E?(P=(0,$.jsxs)(`span`,{className:`flex w-full min-w-0 items-start gap-3`,children:[E,N]}),t[34]=N,t[35]=E,t[36]=P):P=t[36];let F=n.name,L;t[37]===c?L=t[38]:(L=c(`由插件提供`,`Provided by plugin`),t[37]=c,t[38]=L);let R;t[39]!==n.name||t[40]!==L?(R=(0,$.jsxs)(`span`,{className:`mt-2 block w-full truncate text-xs leading-5 text-fg-muted`,title:F,children:[L,` · `,n.name]}),t[39]=n.name,t[40]=L,t[41]=R):R=t[41];let z=x?`text-accent-fg`:`text-fg-muted`,V;t[42]===z?V=t[43]:(V=p(`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs`,z),t[42]=z,t[43]=V);let ee;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,$.jsx)(W,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[44]=ee):ee=t[44];let H;t[45]!==_||t[46]!==V?(H=(0,$.jsxs)(`span`,{className:V,children:[_,ee]}),t[45]=_,t[46]=V,t[47]=H):H=t[47];let U;return t[48]!==i||t[49]!==P||t[50]!==R||t[51]!==H||t[52]!==w?(U=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:w,children:[P,R,H]}),t[48]=i,t[49]=P,t[50]=R,t[51]=H,t[52]=w,t[53]=U):U=t[53],U}function hn(e){let t=e.connectedAt?Date.parse(e.connectedAt):0;return Number.isFinite(t)?t:0}function gn(e,t){return e.status===`active`&&t.status!==`active`?-1:e.status!==`active`&&t.status===`active`?1:e.isCurrentAuthorization===t.isCurrentAuthorization?hn(t)-hn(e):e.isCurrentAuthorization?-1:1}function _n(e){let t=new Map;for(let n of e){let e=n.accountId??n.identityKey??`authorization:${n.id}`;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>{let n=[...t].sort(gn);return{key:e,primary:n[0],authorizations:n}}).sort((e,t)=>gn(e.primary,t.primary))}var vn=p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D);function yn(e){return e.materialized.type===`composio`?e.materialized.toolkit:null}function bn(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function xn(e,t,n){return e.status===`connected`?_e(n.composioHealthConnected,{count:String(t)}):e.status===`reauthorization_required`?n.composioHealthReconnect:e.status===`disconnected`?n.composioHealthDisconnected:e.errorCode===`missing_credential`?n.composioHealthMissingCredential:e.errorCode===`unauthorized`?n.composioHealthUnauthorized:e.errorCode===`forbidden`?n.composioHealthForbidden:e.errorCode===`network`?n.composioHealthNetwork:e.errorCode===`timeout`?n.composioHealthTimeout:n.composioHealthDegraded}function Sn(e,t){return e===`active`?t.composioConnectionHealthy:e===`pending`?t.composioConnectionPending:e===`expired`?t.composioConnectionExpired:e===`failed`?t.composioConnectionFailed:e===`revoked`||e===`disabled`?t.composioConnectionRevoked:t.composioConnectionUnknown}function Cn(e,t,n){return e.status===`paused`?t?.scanEnabled===!1?n.connectorLearningPausedByPolicy:n.connectorLearningPausedByFailure:e.status===`queued`?n.connectorLearningQueued:e.status===`running`?n.connectorLearningRunning:e.status===`completed`?n.connectorLearningCompleted:n.connectorLearningFailed}function wn({instance:e,t,onChanged:n}){let r=yn(e),i=g(e=>e.language)===`zh`,[a,c]=(0,Q.useState)([]),[u,f]=(0,Q.useState)([]),[m,h]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),[y,S]=(0,Q.useState)([]),[C,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)([]),[A,M]=(0,Q.useState)({}),[N,P]=(0,Q.useState)(`read`),[I,L]=(0,Q.useState)(!1),[R,B]=(0,Q.useState)(null),[V,ee]=(0,Q.useState)(!1),[U,te]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(null),[W,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(!1),[se,K]=(0,Q.useState)(!1),le=(0,Q.useRef)(0),ue=(0,Q.useRef)(0),q=(0,Q.useMemo)(()=>_n(a),[a]),J=(0,Q.useCallback)(e=>new Promise((t,n)=>{let r=window.setTimeout(()=>n(Error(i?`连接服务响应超时,请重试。`:`The connection service timed out. Please retry.`)),15e3);e.then(t,n).finally(()=>window.clearTimeout(r))}),[i]),Y=(0,Q.useCallback)(async()=>{if(!r||e.materialized.type!==`composio`||e.materialized.role===`credential`)return;L(!0),B(null);let t=++le.current;try{let e=(await Promise.allSettled([J(Xe()).then(e=>{t===le.current&&(c(e.filter(e=>e.toolkit.toLowerCase()===r.toLowerCase())),ie(!0))}),J(qe(r)).then(e=>{t===le.current&&P(e)}),J(Ve(r)).then(e=>{t===le.current&&(v(e.policy),S(e.agents))})])).find(e=>e.status===`rejected`);t===le.current&&e?.status===`rejected`&&B(String(e.reason instanceof Error?e.reason.message:e.reason))}finally{t===le.current&&L(!1)}},[e.materialized,r,J]);(0,Q.useEffect)(()=>(Y(),()=>{le.current++}),[Y]);let pe=(0,Q.useCallback)(async()=>{if(!r)return;let e=++ue.current;K(!0),ee(!1);let t=t=>n=>{e===ue.current&&t(n)},n=await Promise.allSettled([J(Oe(r)).then(t(f)),J(Re(20)).then(t(e=>h(e.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===r.toLowerCase())))),J(we(r)).then(t(D)),J(Ze(r)).then(t(T))]);e===ue.current&&(ee(n.some(e=>e.status===`rejected`)),K(!1))},[r,J]);(0,Q.useEffect)(()=>(ae&&pe(),()=>{ue.current++}),[ae,pe]),(0,Q.useEffect)(()=>{let e=!1,t=_n(a).map(e=>e.primary).filter(e=>e.supportsLearning&&e.accountId);if(t.length)return J($e()).then(t=>{e||k(t)}).catch(()=>{}),Promise.allSettled(t.map(async e=>[e.accountId,await J(He(e.accountId))])).then(t=>{e||M(Object.fromEntries(t.flatMap(e=>e.status===`fulfilled`?[e.value]:[])))}),()=>{e=!0}},[a,J]);let X=(0,Q.useCallback)(async i=>{if(!r)return;let a=w()?null:window.open(`about:blank`,`_blank`);a&&(a.opener=null),L(!0),B(null);try{if(!w()&&!a)throw Error(`Allow popups to open the authorization page.`);let t=await et(e.connectorId,i);if(!t.authorizationUrl)throw Error(`The authorization provider did not return an authorization URL.`);if(w()){let e=await window.electronAPI?.shell?.openExternalUrl(t.authorizationUrl);if(!e?.ok)throw Error(e?.error??`Could not open the system browser.`)}else a.location.href=t.authorizationUrl;let o=await F(r,t.connectionId,12e4,t.attemptId);if(i&&o.accountId!==i)throw Error(`A different account was authorized. The original account and its task bindings were not changed.`);await Promise.all([n?.(),Y()])}catch(e){B(z(e,t))}finally{a?.close(),L(!1)}},[e.connectorId,Y,n,t,r]),me=(0,Q.useCallback)(async t=>{L(!0),B(null);try{await nt(e.instanceId,{config:{...e.config??{},authConfigId:t||void 0}}),await Promise.all([n?.(),Y()])}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[e.config,e.instanceId,Y,n]),he=async e=>{let t=w()?null:window.open(`about:blank`,`_blank`);t&&(t.opener=null),B(null);try{let n=await Ae(e.id);if(n.authorizationUrl)if(w())await window.electronAPI?.shell?.openExternalUrl(n.authorizationUrl);else if(t)t.location.href=n.authorizationUrl;else throw Error(`Allow popups to reopen authorization.`);else t?.close(),await Y()}catch(e){t?.close(),B(e instanceof Error?e.message:String(e))}},ge=(0,Q.useCallback)(async e=>{if(r){P(e),B(null);try{await Ne(r,e)}catch(e){B(e instanceof Error?e.message:String(e)),await Y()}}},[Y,r]),ve=(0,Q.useCallback)(async e=>{if(r){B(null);try{v(await j(r,e))}catch(e){B(e instanceof Error?e.message:String(e))}}},[r]),ye=(0,Q.useCallback)(e=>{if(!_)return;let t=_.allowedAgentIds.includes(e);t&&_.allowedAgentIds.length===1||ve({allowedAgentIds:t?_.allowedAgentIds.filter(t=>t!==e):[..._.allowedAgentIds,e]})},[ve,_]),Z=(0,Q.useCallback)(async e=>{L(!0),B(null);try{await e(),await Y()}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[Y]);if(!r)return null;if(e.materialized.type===`composio`&&e.materialized.role===`credential`)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioApiKeyStored});let be=q.filter(e=>e.primary.status===`active`).length,xe=be>0?t.composioAddAccount:t.composioConnectAccount,Se=W&&be>0,Te=E?.requiresCustomAuthConfig===!0,De=E?.authConfigs.filter(e=>e.status===`ENABLED`&&e.isEnabledForToolRouter)??[];return(0,$.jsxs)(`div`,{className:`space-y-5`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`span`,{className:p(`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium`,Se?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`),children:[Se?(0,$.jsx)(l,{className:`size-3.5`}):(0,$.jsx)(Fe,{className:`size-3.5`}),Se?t.connectionReady:W||R?t.connectionNeedsSetup:t.connectionChecking]}),W&&(0,$.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:_e(t.composioAccountCount,{count:String(q.length)})})]}),(0,$.jsxs)(b,{variant:`primary`,className:`shrink-0`,disabled:I,onClick:()=>void X(),children:[I?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(ce,{className:`size-4`}),xe]})]}),R?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center justify-between gap-2 rounded-xl border border-danger/20 bg-danger/5 px-3 py-2 text-sm text-danger`,children:[(0,$.jsx)(`p`,{children:R}),(0,$.jsx)(b,{variant:`secondary`,disabled:I,onClick:()=>void Y(),children:t.composioRetry})]}):null,C&&!Se?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-amber-500/25 bg-amber-500/5 p-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:xn(C,be,t)}),C.recovery===`none`?null:(0,$.jsx)(b,{variant:`secondary`,disabled:I,onClick:()=>void(C.recovery===`retry`?Y():X()),children:C.recovery===`retry`?t.composioRetry:t.composioReconnectAccount})]}):null,Te&&De.length===0?(0,$.jsx)(`p`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/5 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:t.composioAuthConfigEmpty}):null,_?(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-start`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAccessTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:N===`read`?t.composioAccessReadHint:N===`admin`?t.composioAccessAdminHint:t.composioAccessWriteHint})]}),(0,$.jsxs)(o,{value:N,onChange:e=>void ge(e.currentTarget.value),children:[(0,$.jsx)(s,{value:`read`,children:t.composioAccessReadOnly}),(0,$.jsx)(s,{value:`write`,children:t.composioAccessReadWrite}),N===`admin`?(0,$.jsx)(s,{value:`admin`,children:t.composioAccessAdminCurrent}):null]})]}),(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm text-fg-muted`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioConfirmationPolicy}),(0,$.jsxs)(o,{value:_.confirmationPolicy,onChange:e=>void ve({confirmationPolicy:e.currentTarget.value}),children:[(0,$.jsx)(s,{value:`writes`,children:t.composioConfirmWrites}),(0,$.jsx)(s,{value:`always`,children:t.composioConfirmAlways}),_.confirmationPolicy===`never`?(0,$.jsx)(s,{value:`never`,children:t.composioConfirmNever}):null]})]}),(0,$.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAllowedAgents}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.allowedAgentIds.length?t.composioAllowedAgentsSelected:t.composioAllowedAgentsAll}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-2.5 py-1 text-xs transition-colors`,_.allowedAgentIds.length===0?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>void ve({allowedAgentIds:[]}),children:t.composioAllowedAgentsAllOption}),y.map(e=>(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-2.5 py-1 text-xs transition-colors`,_.allowedAgentIds.includes(e.id)?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>ye(e.id),children:e.name},e.id))]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-2 border-t border-edge-subtle p-4 text-xs text-fg-muted`,children:[(0,$.jsx)(`legend`,{children:i?`可用账号范围`:`Available accounts`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:_.selectedAccountIds===null,disabled:I,onChange:e=>void ve({selectedAccountIds:e.currentTarget.checked?null:[]})}),i?`所有账号(包括以后新增)`:`All accounts, including new ones`]}),_.selectedAccountIds!==null&&q.map(({primary:e})=>e.accountId&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:_.selectedAccountIds.includes(e.accountId),onChange:t=>void ve({selectedAccountIds:t.currentTarget.checked?[..._.selectedAccountIds,e.accountId]:_.selectedAccountIds.filter(t=>t!==e.accountId)})}),e.alias??e.accountEmail??e.accountId]},e.accountId)),_.selectedAccountIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择账号,Agent 无法使用此应用。`:`No accounts selected. Agents cannot use this app.`})]})]})]}):null,(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.composioConnectedAccounts}),W&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_e(t.composioAccountCount,{count:String(q.length)})})]}),(0,$.jsxs)(b,{variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:I,onClick:()=>void Y(),children:[(0,$.jsx)(G,{className:p(`size-3.5`,I&&`animate-spin`)}),t.refresh]})]}),q.length?(0,$.jsx)(`div`,{className:`divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:q.map(e=>{let r=e.primary,a=O.find(e=>r.accountId?e.accountId===r.accountId:e.connectionId===r.id),c=r.accountId?A[r.accountId]:void 0;return(0,$.jsxs)(`article`,{className:`px-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start justify-between gap-3 sm:flex-row`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,$.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:r.alias??r.workspace??r.accountEmail??r.username??t.composioUnnamedAuthorization})}),(0,$.jsx)(`p`,{className:`mt-1 break-all text-xs text-fg-muted`,children:r.accountEmail??r.username??r.workspace??r.accountId}),r.backendLabel&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:r.backendLabel}),(0,$.jsx)(`p`,{className:p(`mt-1 text-xs`,r.status===`active`?`text-emerald-700 dark:text-emerald-300`:`text-amber-700 dark:text-amber-300`),children:r.accountEnabled===!1?i?`已暂停`:`Paused`:Sn(r.status,t)}),a?(0,$.jsx)(`p`,{className:p(`mt-1 text-xs`,a.status===`failed`?`text-red-600`:`text-fg-subtle`),children:_e(t.connectorLearningStatus,{status:Cn(a,c,t),count:String(a.candidatesCreated)})}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[r.status===`pending`&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,onClick:()=>void he(r),children:i?`继续授权`:`Continue authorization`}),r.accountId&&(0,$.jsx)(b,{variant:`ghost`,className:`h-8 px-2.5 text-xs text-danger`,disabled:I,onClick:()=>re(r.accountId),children:i?`断开`:`Disconnect`}),r.accountId&&r.status!==`active`&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:I,onClick:()=>void X(r.accountId),children:t.composioReconnectAccount}),r.accountId&&(0,$.jsx)(b,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:I,onClick:()=>void Z(()=>it(r.accountId,{enabled:r.accountEnabled===!1})),children:r.accountEnabled===!1?i?`启用`:`Enable`:i?`暂停`:`Pause`}),r.supportsLearning&&r.status===`active`&&r.accountEnabled!==!1?(0,$.jsxs)(b,{variant:`secondary`,className:`h-8 shrink-0 px-2.5 text-xs`,disabled:I,onClick:()=>void Z(async()=>{if(!r.accountId)throw Error(`Connector account is unavailable.`);await Ce(r.accountId),await n?.()}),children:[(0,$.jsx)(G,{className:`size-3.5`}),t.composioSyncNow]}):null]})]}),(0,$.jsxs)(`details`,{className:`mt-3 text-xs text-fg-muted`,children:[(0,$.jsx)(`summary`,{className:`w-fit cursor-pointer font-medium hover:text-fg`,children:t.composioAccountSettings}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-4 rounded-lg bg-surface-panel p-3`,children:[r.accountId&&(0,$.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,$.jsx)(`legend`,{className:`mb-2 font-medium`,children:t.composioAllowedAgents}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:r.allowedAgentIds==null,onChange:e=>void Z(()=>it(r.accountId,{allowedAgentIds:e.currentTarget.checked?null:[]}))}),t.composioAllowedAgentsAllOption]}),r.allowedAgentIds!=null&&y.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:I,checked:r.allowedAgentIds.includes(e.id),onChange:t=>{let n=t.currentTarget.checked;Z(()=>it(r.accountId,{allowedAgentIds:n?[...r.allowedAgentIds,e.id]:r.allowedAgentIds.filter(t=>t!==e.id)}))}}),e.name]},e.id)),r.allowedAgentIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择 Agent:任何 Agent 都不能使用此账号。`:`No agents selected: this account is unavailable to all agents.`})]}),r.supportsLearning&&c?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:c.scanEnabled,disabled:I,onChange:e=>void Z(()=>fe(r.accountId,{scanEnabled:e.currentTarget.checked}))}),t.connectorScheduledScan]}),c.scanEnabled?(0,$.jsxs)(`label`,{className:`sm:col-span-2`,children:[t.connectorScanInterval,(0,$.jsxs)(o,{className:`mt-1`,value:String(c.intervalMinutes??30),disabled:I,onChange:e=>void Z(()=>fe(r.accountId,{intervalMinutes:Number(e.currentTarget.value)})),children:[(0,$.jsxs)(s,{value:`5`,children:[`5 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`15`,children:[`15 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`30`,children:[`30 `,t.connectorMinutes]}),(0,$.jsxs)(s,{value:`60`,children:[`60 `,t.connectorMinutes]})]})]}):null]}):null,(0,$.jsxs)(`label`,{className:`block`,children:[t.composioAccountAlias,(0,$.jsx)(`input`,{className:p(vn,`mt-1 h-8 py-1 text-xs`),defaultValue:r.alias??``,onBlur:e=>{e.currentTarget.value!==(r.alias??``)&&Z(()=>de(r.id,{alias:e.currentTarget.value}))}})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.authorizations.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 break-all font-mono text-fg-subtle`,children:[t.composioAuthorizationId,`: `,e.providerConnectionId]}),(0,$.jsx)(b,{variant:`ghost`,className:`size-7 shrink-0 p-0 text-danger`,title:t.composioRevoke,disabled:I,onClick:()=>te(e.id),children:(0,$.jsx)(Ge,{className:`size-3.5`})})]},e.id))}),(0,$.jsx)(`div`,{className:`flex justify-end gap-1`,children:(0,$.jsx)(b,{variant:`ghost`,className:`size-8 p-0`,title:t.refresh,disabled:I,onClick:()=>void Z(()=>ke(r.id)),children:(0,$.jsx)(G,{className:`size-4`})})})]})]})]},e.key)})}):I&&!W?(0,$.jsxs)(`div`,{"aria-busy":`true`,"aria-label":t.connectionChecking,className:`space-y-3`,children:[(0,$.jsx)(x,{className:`h-16 w-full`}),(0,$.jsx)(x,{className:`h-16 w-full`})]}):W?(0,$.jsx)(`div`,{className:`rounded-xl border border-dashed border-edge px-4 py-8 text-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioConnectionsEmpty})}):null]}),(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-base`,onToggle:e=>oe(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`space-y-5 border-t border-edge-subtle px-4 py-4`,children:[se?(0,$.jsx)(x,{"aria-label":t.connectionChecking,className:`h-16 w-full`}):null,V?(0,$.jsxs)(`p`,{className:`rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,children:[t.composioDiagnosticsUnavailable,(0,$.jsx)(b,{variant:`ghost`,disabled:se,onClick:()=>void pe(),children:t.composioRetry})]}):null,E?.mode===`byok`?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAuthConfigTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:Te?t.composioAuthConfigRequiredHint:t.composioAuthConfigOptionalHint})]}),(0,$.jsx)(`a`,{className:`text-xs font-medium text-accent-fg hover:underline`,href:`https://app.composio.dev`,target:`_blank`,rel:`noreferrer`,children:t.composioAuthConfigManage})]}),(0,$.jsxs)(o,{className:`mt-3`,value:typeof e.config?.authConfigId==`string`?e.config.authConfigId:``,disabled:I,onChange:e=>void me(e.currentTarget.value),children:[Te?null:(0,$.jsx)(s,{value:``,children:t.composioAuthConfigManaged}),Te&&typeof e.config?.authConfigId!=`string`?(0,$.jsx)(s,{value:``,disabled:!0,children:t.composioAuthConfigSelect}):null,De.map(e=>(0,$.jsxs)(s,{value:e.id,children:[e.name,` · `,e.authScheme??`OAuth`]},e.id))]})]}):null,(0,$.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),(0,$.jsx)(`div`,{className:`space-y-2`,children:u.length?u.slice(0,8).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:[bn(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),(0,$.jsx)(`div`,{className:`space-y-2`,children:m.length?m.slice(0,5).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})})]})]})]})]}),(0,$.jsx)(Ee,{open:ne!==null,title:i?`断开账号`:`Disconnect account`,description:i?`停止此账号的工具使用和学习,并撤销其全部授权。已保存的数据不会删除。`:`Stop tool access and learning for this account and revoke all its authorizations. Saved data will not be deleted.`,confirmLabel:i?`断开`:`Disconnect`,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=ne;re(null),e&&Z(()=>H(e))},onCancel:()=>re(null)}),(0,$.jsx)(Ee,{open:U!==null,title:t.composioRevoke,description:t.composioRevokeConfirm,confirmLabel:t.composioRevoke,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=U;te(null),e&&Z(()=>Be(e))},onCancel:()=>te(null)})]})}var Tn=p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D);function En(e,t){let n={};for(let r of e?.setup.config??[]){let e=t.config?.[r.key]??r.defaultValue??``;n[r.key]=typeof e==`string`?e:JSON.stringify(e,null,2)}return n}function Dn(e,t){let n=t.trim();return e===`json`?n?JSON.parse(n):void 0:e===`number`?n?Number(n):void 0:e===`boolean`?n===`true`:n||void 0}function On({instance:e,definition:t,onClose:n,onChanged:r,t:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(()=>En(t,e)),[y,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),D=t?.setup.config??[],O=(e.materialized.type===`mcp`||e.materialized.type===`memorySource`)&&D.length>0&&(t?.setup.secrets??[]).length===0,A=e.materialized.type===`mcp`,j=e.materialized.type===`composio`,M=e.materialized.type===`memorySource`,N=t?Y(t,i):null,P=(0,Q.useCallback)(async()=>{C(!0),x(null);try{let t=await Te(e.instanceId);T(t),t.ok||x(t.error??t.action??i.healthStatusLabels[t.status]),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{C(!1)}},[e.instanceId,r,i.healthStatusLabels]),F=(0,Q.useCallback)(async()=>{o(!0),x(null);try{await Ue(e.instanceId),await r(),n()}catch(e){x(e instanceof Error?e.message:String(e)),o(!1)}},[e.instanceId,r,n]),I=(0,Q.useCallback)(async()=>{if(!(!t||!O)){u(!0),x(null);try{let n={};for(let e of t.setup.config??[]){let t=Dn(e.type,_[e.key]??``);t!==void 0&&(n[e.key]=t)}await nt(e.instanceId,{config:n}),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[_,t,e.instanceId,r,O]),R=(0,Q.useCallback)(async()=>{m(!0),g(null),x(null);try{g((await ot(e.connectorId)).recordIds.length),await r()}catch(e){x(e instanceof Error?e.message:String(e))}finally{m(!1)}},[e.connectorId,r]);return(0,$.jsxs)(oe,{open:!0,onOpenChange:e=>{e||n()},children:[(0,$.jsxs)(st,{children:[(0,$.jsx)(ue,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(ee,{className:p(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,j?`h-[min(100dvh-2rem,36rem)] w-[min(100%-2rem,40rem)]`:`h-[min(100dvh-2rem,44rem)] w-[min(100%-2rem,min(92vw,54rem))]`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(X,{connector:t,size:`lg`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(k,{className:`text-base font-semibold text-fg`,children:e.displayName}),(0,$.jsx)(ne,{className:`mt-1 text-sm text-fg-muted`,children:N??(e.materialized.type===`mcp`?_e(i.mcpServerRuntime,{serverId:e.materialized.serverId}):_e(i.runtimeLabel,{runtime:e.materialized.type}))})]})]}),(0,$.jsx)(L,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:p(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,ae.focusRingPanel),"aria-label":i.modalClose,children:[(0,$.jsx)(te,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`sr-only`,children:i.modalClose})]})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:[y?(0,$.jsx)(`p`,{className:`mb-4 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:y}):null,A?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-fg-muted`,role:`status`,children:w?.ok?_e(i.toolsAvailable,{count:String(w.toolCount)}):w?i.healthStatusLabels[w.status]:e.usage.lastHealthStatus?i.healthStatusLabels[e.usage.lastHealthStatus]:i.healthNotTested}),(0,$.jsxs)(b,{variant:`secondary`,"aria-busy":S,disabled:S||!e.enabled,onClick:()=>void P(),children:[S?(0,$.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4`,"aria-hidden":!0}),i.test]})]}),O?D.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key)):null]}):null,j?(0,$.jsx)(wn,{instance:e,t:i,onChanged:r}):null,M?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-edge bg-surface-base p-4 text-sm`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:i.connectedSourceSync}),N?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:N}):null,h===null?null:(0,$.jsx)(`p`,{className:`mt-1 text-xs text-emerald-600`,children:_e(i.connectedSourceSynced,{count:String(h)})})]}),(0,$.jsxs)(b,{disabled:f,onClick:()=>void R(),children:[f?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(je,{className:`size-4`}),i.composioSyncNow]})]}),O?(0,$.jsx)(`div`,{className:`grid gap-3 rounded-xl border border-edge bg-surface-base p-4`,children:D.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key))}):null]}):null,!A&&!j&&!M?(0,$.jsx)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:(0,$.jsx)(`p`,{children:i.connectorPolicyHint})}):null,(0,$.jsxs)(`details`,{className:`mt-5 rounded-xl border border-edge`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-danger`,children:i.dangerZone}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 border-t border-danger/15 px-4 py-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-fg-muted`,children:i.removeConnectorHint}),(0,$.jsxs)(b,{variant:`secondary`,className:`shrink-0 border-danger/30 text-danger hover:bg-danger/10`,disabled:a,onClick:()=>c(!0),children:[a?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(Ge,{className:`size-4`}),i.remove]})]})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,$.jsx)(b,{variant:`secondary`,onClick:n,children:i.modalClose}),(A||M)&&O?(0,$.jsxs)(b,{variant:`primary`,disabled:l,onClick:()=>void I(),children:[l?(0,$.jsx)(d,{className:`size-4 animate-spin`}):(0,$.jsx)(E,{className:`size-4`}),i.modalSave]}):null]})]})]}),(0,$.jsx)(Ee,{open:s,title:_e(i.removeConfirmTitle,{name:e.displayName}),description:i.removeConfirmDescription,confirmLabel:i.removeConfirmAction,cancelLabel:i.modalCancel,destructive:!0,onConfirm:()=>{c(!1),F()},onCancel:()=>{a||c(!1)}})]})}function kn(e){let t=(0,ft.c)(2),n;return t[0]===e?n=t[1]:(n=e.instance.materialized.type===`cli`&&e.definition?(0,$.jsx)(R,{definition:e.definition,instance:e.instance,onClose:e.onClose,onChanged:e.onChanged}):(0,$.jsx)(On,{...e}),t[0]=e,t[1]=n),n}function An(e){let t=(0,ft.c)(59),{instance:n,definition:r,highlighted:i,onOpenDetails:a,t:o}=e,s=i===void 0?!1:i,c;t[0]!==r||t[1]!==n?(c=Ct(n,r),t[0]=r,t[1]=n,t[2]=c):c=t[2];let u=c.state,d;t[3]!==r||t[4]!==o?(d=r?Y(r,o):null,t[3]=r,t[4]=o,t[5]=d):d=t[5];let f=d,m,h,g,_,v,y,b,x,S;if(t[6]!==u||t[7]!==r||t[8]!==s||t[9]!==n||t[10]!==a||t[11]!==o.connectionChecking||t[12]!==o.connectionNeedsSetup||t[13]!==o.connectionReady){m=u===`ready`?{label:o.connectionReady,Icon:l,className:`text-emerald-700 dark:text-emerald-300`}:u===`needs_setup`?{label:o.connectionNeedsSetup,Icon:Fe,className:`text-amber-700 dark:text-amber-300`}:{label:o.connectionChecking,Icon:rt,className:`text-fg-muted`},S=`button`;let e=u===`needs_setup`&&`border-amber-500/25`,i=s&&`bg-accent-soft`;t[23]!==e||t[24]!==i?(h=p(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left hover:bg-surface-hover/45`,ae.transition,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,e,i),t[23]=e,t[24]=i,t[25]=h):h=t[25],t[26]!==n||t[27]!==a?(g=()=>a(n),t[26]=n,t[27]=a,t[28]=g):g=t[28],b=`flex w-full min-w-0 items-start gap-3`,t[29]===r?x=t[30]:(x=(0,$.jsx)(X,{connector:r,size:`sm`}),t[29]=r,t[30]=x),v=`min-w-0 flex-1`,t[31]===n.displayName?y=t[32]:(y=(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,title:n.displayName,children:n.displayName}),t[31]=n.displayName,t[32]=y),_=p(`mt-1 inline-flex items-center gap-1 text-[11px]`,m.className),t[6]=u,t[7]=r,t[8]=s,t[9]=n,t[10]=a,t[11]=o.connectionChecking,t[12]=o.connectionNeedsSetup,t[13]=o.connectionReady,t[14]=m,t[15]=h,t[16]=g,t[17]=_,t[18]=v,t[19]=y,t[20]=b,t[21]=x,t[22]=S}else m=t[14],h=t[15],g=t[16],_=t[17],v=t[18],y=t[19],b=t[20],x=t[21],S=t[22];let C;t[33]===m.Icon?C=t[34]:(C=(0,$.jsx)(m.Icon,{className:`size-3.5`,"aria-hidden":!0}),t[33]=m.Icon,t[34]=C);let w;t[35]!==m.label||t[36]!==C||t[37]!==_?(w=(0,$.jsxs)(`span`,{className:_,children:[C,m.label]}),t[35]=m.label,t[36]=C,t[37]=_,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==v||t[41]!==y?(T=(0,$.jsxs)(`div`,{className:v,children:[y,w]}),t[39]=w,t[40]=v,t[41]=y,t[42]=T):T=t[42];let E;t[43]!==T||t[44]!==b||t[45]!==x?(E=(0,$.jsxs)(`div`,{className:b,children:[x,T]}),t[43]=T,t[44]=b,t[45]=x,t[46]=E):E=t[46];let D;t[47]===f?D=t[48]:(D=f?(0,$.jsx)(`p`,{className:`mt-2 w-full line-clamp-2 text-xs leading-5 text-fg-muted`,title:f,children:f}):null,t[47]=f,t[48]=D);let O;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(W,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[49]=O):O=t[49];let k;t[50]===o.installedDetails?k=t[51]:(k=(0,$.jsxs)(`span`,{className:`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs text-fg-muted`,children:[o.installedDetails,O]}),t[50]=o.installedDetails,t[51]=k);let A;return t[52]!==h||t[53]!==g||t[54]!==E||t[55]!==D||t[56]!==k||t[57]!==S?(A=(0,$.jsxs)(`button`,{type:S,className:h,onClick:g,children:[E,D,k]}),t[52]=h,t[53]=g,t[54]=E,t[55]=D,t[56]=k,t[57]=S,t[58]=A):A=t[58],A}function jn(e,t){return Gt()}function Mn(e){let t=e.headers.filter(e=>e.key.trim()),n=t.find(e=>e.key.toLowerCase()===`authorization`&&!e.reference&&/^Bearer\s/i.test(e.value)),r=e.extra.auth||t.some(e=>e.reference)||e.extra.oauth&&t.some(e=>e.key.toLowerCase()===`authorization`)?`existing`:e.extra.oauth?`oauth`:n?`bearer`:t.length?`headers`:`auto`;return{mode:r,token:n?.value.replace(/^Bearer\s+/i,``)??``,apiKey:``,headerName:``,customHeaders:t.length?t:[Mt()],additionalHeaders:r===`bearer`?t.filter(e=>e!==n):r===`oauth`?t:[]}}function Nn(e,t){if(e.transport===`stdio`||t.mode===`existing`)return{...e,extra:{...e.extra}};let n={...e.extra};delete n.auth,t.mode!==`oauth`&&delete n.oauth;let r=t.mode===`headers`?t.customHeaders:t.additionalHeaders;if(t.mode===`bearer`){let e=t.token.trim().replace(/^Bearer\s+/i,``);r=[...r,Mt(`Authorization`,`Bearer ${e}`)]}return t.mode===`apiKey`&&(r=[...r,Mt(t.headerName.trim(),t.apiKey.trim())]),{...e,extra:n,headers:r,oauthClientId:t.mode===`oauth`?e.oauthClientId:``}}function Pn(e){let t=new Set;return e.findIndex(e=>{let n=e.key.trim();if(!n&&!e.value&&!e.reference)return!1;if(!/^[!#$%&'*+.^_`|~\da-z-]+$/i.test(n)||/[\r\n]/.test(e.value))return!0;let r=n.toLowerCase();return t.has(r)?!0:(t.add(r),!1)})}function Fn(){return p(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,D)}function In({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,pasteFailedTitle:o,dismissLabel:s,keyPlaceholder:c,valuePlaceholder:l,headers:u,onChange:d,referenceLabel:f=`Existing credential reference`,showValueLabel:m=`Show value`,hideValueLabel:h=`Hide value`,allowPaste:g=!0}){let[_,y]=(0,Q.useState)(new Set),[x,S]=(0,Q.useState)(!1),C=(e,t)=>{d(u.map((n,r)=>r===e?{...n,...t}:n))},w=()=>{d([...u,Mt()])},T=e=>{let t=u.filter((t,n)=>n!==e);d(t.length>0?t:[Mt()])},E=async()=>{try{let e=await v();if(!e){S(!0);return}let t=Pt(e);if(!t?.length){S(!0);return}d(t)}catch{S(!0)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,$.jsx)(`span`,{children:e}),t?(0,$.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),g?(0,$.jsxs)(b,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void E(),children:[(0,$.jsx)(q,{className:`size-3.5`,"aria-hidden":!0}),i]}):null]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map((e,t)=>(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto_auto]`,children:[(0,$.jsx)(`input`,{className:p(Fn(),`col-span-3 min-w-0 font-mono text-xs sm:col-span-1`),"aria-label":`${c} ${t+1}`,value:e.key,placeholder:c,onChange:e=>C(t,{key:e.target.value})}),(0,$.jsx)(`input`,{className:p(Fn(),`min-w-0 font-mono text-xs`),type:_.has(e.clientKey)?`text`:`password`,autoComplete:`off`,"aria-label":`${l} ${t+1}`,readOnly:!!e.reference,value:e.reference?f:e.value,placeholder:e.reference?f:l,onChange:e=>C(t,{value:e.target.value})}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,className:`size-10 shrink-0 px-0`,disabled:!!e.reference,"aria-label":_.has(e.clientKey)?h:m,onClick:()=>y(t=>{let n=new Set(t);return n.has(e.clientKey)?n.delete(e.clientKey):n.add(e.clientKey),n}),children:_.has(e.clientKey)?(0,$.jsx)(De,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(Je,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:u.length<=1&&!e.key&&!e.value,onClick:()=>T(t),"aria-label":r,children:(0,$.jsx)(Ge,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})}),e.reference?(0,$.jsx)(`p`,{className:`col-span-3 break-words text-xs text-fg-muted sm:col-span-4`,children:f}):null]},e.clientKey))}),(0,$.jsx)(Ee,{open:x,title:o,description:a,confirmLabel:s,onConfirm:()=>S(!1),onCancel:()=>S(!1)}),(0,$.jsxs)(`button`,{type:`button`,className:p(`self-start text-sm text-accent hover:underline`,ae.press),onClick:w,children:[`+ `,n]})]})}var Ln=p(`w-full min-w-0 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,D);function Rn(e){let t=(0,ft.c)(20),{value:n,onChange:r,label:i,t:a,required:o}=e,s=o===void 0?!1:o,[c,l]=(0,Q.useState)(!1),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=p(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=c?`text`:`password`,f;t[1]===r?f=t[2]:(f=e=>r(e.target.value),t[1]=r,t[2]=f);let m;t[3]!==s||t[4]!==d||t[5]!==f||t[6]!==n?(m=(0,$.jsx)(`input`,{className:u,type:d,value:n,required:s,autoComplete:`off`,onChange:f}),t[3]=s,t[4]=d,t[5]=f,t[6]=n,t[7]=m):m=t[7];let h;t[8]!==i||t[9]!==m?(h=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i,m]}),t[8]=i,t[9]=m,t[10]=h):h=t[10];let g;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>l(zn),t[11]=g):g=t[11];let _;t[12]===c?_=t[13]:(_=c?(0,$.jsx)(De,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),t[12]=c,t[13]=_);let v=c?a.setupHideValue:a.setupShowValue,y;t[14]!==_||t[15]!==v?(y=(0,$.jsxs)(b,{type:`button`,variant:`ghost`,className:`gap-1.5 text-xs`,onClick:g,children:[_,v]}),t[14]=_,t[15]=v,t[16]=y):y=t[16];let x;return t[17]!==y||t[18]!==h?(x=(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[h,y]}),t[17]=y,t[18]=h,t[19]=x):x=t[19],x}function zn(e){return!e}function Bn(e){let t=(0,ft.c)(17),{headers:n,onChange:r,t:i,additional:a,environment:o}=e,s=a===void 0?!1:a,c=o===void 0?!1:o,l=c?i.envLabel:s?i.setupAdditionalHeaders:i.headersLabel,u=c?i.setupAddEnv:i.addHeader,d=c?i.setupRemoveEnv:i.removeHeader,f=c?i.setupEnvName:i.headerKeyPlaceholder,p=c?i.setupEnvValue:i.headerValuePlaceholder,m=!c,h;return t[0]!==n||t[1]!==r||t[2]!==i.optionalSuffix||t[3]!==i.pasteHeaders||t[4]!==i.pasteHeadersDismiss||t[5]!==i.pasteHeadersFailed||t[6]!==i.pasteHeadersFailedTitle||t[7]!==i.setupHideValue||t[8]!==i.setupReference||t[9]!==i.setupShowValue||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==f||t[14]!==p||t[15]!==m?(h=(0,$.jsx)(In,{label:l,optionalLabel:i.optionalSuffix,addLabel:u,removeHeaderAria:d,pasteLabel:i.pasteHeaders,pasteFailed:i.pasteHeadersFailed,pasteFailedTitle:i.pasteHeadersFailedTitle,dismissLabel:i.pasteHeadersDismiss,keyPlaceholder:f,valuePlaceholder:p,headers:n,onChange:r,referenceLabel:i.setupReference,showValueLabel:i.setupShowValue,hideValueLabel:i.setupHideValue,allowPaste:m}),t[0]=n,t[1]=r,t[2]=i.optionalSuffix,t[3]=i.pasteHeaders,t[4]=i.pasteHeadersDismiss,t[5]=i.pasteHeadersFailed,t[6]=i.pasteHeadersFailedTitle,t[7]=i.setupHideValue,t[8]=i.setupReference,t[9]=i.setupShowValue,t[10]=l,t[11]=u,t[12]=d,t[13]=f,t[14]=p,t[15]=m,t[16]=h):h=t[16],h}function Vn(e){let t=(0,ft.c)(52),{draft:n,onChange:r,t:i,allowExisting:a}=e,c=i.setupAuthLabel,l=i.setupAuthLabel,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=p(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=n.mode,f;t[1]===r?f=t[2]:(f=e=>r({mode:e.target.value}),t[1]=r,t[2]=f);let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=[`auto`,`oauth`,`bearer`,`apiKey`,`headers`,`none`],t[3]=m):m=t[3];let h;t[4]===i.setupAuthModes?h=t[5]:(h=m.map(e=>(0,$.jsx)(s,{value:e,children:i.setupAuthModes[e]},e)),t[4]=i.setupAuthModes,t[5]=h);let g;t[6]!==a||t[7]!==n.mode||t[8]!==i.setupAuthModes?(g=a||n.mode===`existing`?(0,$.jsx)(s,{value:`existing`,children:i.setupAuthModes.existing}):null,t[6]=a,t[7]=n.mode,t[8]=i.setupAuthModes,t[9]=g):g=t[9];let _;t[10]!==n.mode||t[11]!==i.setupAuthLabel||t[12]!==f||t[13]!==h||t[14]!==g?(_=(0,$.jsxs)(o,{"aria-label":l,className:u,value:d,onChange:f,children:[h,g]}),t[10]=n.mode,t[11]=i.setupAuthLabel,t[12]=f,t[13]=h,t[14]=g,t[15]=_):_=t[15];let v;t[16]!==i.setupAuthLabel||t[17]!==_?(v=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[c,_]}),t[16]=i.setupAuthLabel,t[17]=_,t[18]=v):v=t[18];let y;t[19]!==n.mode||t[20]!==i.setupAuthAutoHint?(y=n.mode===`auto`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthAutoHint}):null,t[19]=n.mode,t[20]=i.setupAuthAutoHint,t[21]=y):y=t[21];let b;t[22]!==n.mode||t[23]!==i.setupAuthOAuthHint?(b=n.mode===`oauth`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthOAuthHint}):null,t[22]=n.mode,t[23]=i.setupAuthOAuthHint,t[24]=b):b=t[24];let x;t[25]!==n.mode||t[26]!==i.setupExistingHint?(x=n.mode===`existing`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupExistingHint}):null,t[25]=n.mode,t[26]=i.setupExistingHint,t[27]=x):x=t[27];let S;t[28]!==n.mode||t[29]!==n.token||t[30]!==r||t[31]!==i?(S=n.mode===`bearer`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Rn,{value:n.token,onChange:e=>r({token:e}),label:i.setupTokenLabel,t:i,required:!0}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupTokenHint})]}):null,t[28]=n.mode,t[29]=n.token,t[30]=r,t[31]=i,t[32]=S):S=t[32];let C;t[33]!==n.apiKey||t[34]!==n.headerName||t[35]!==n.mode||t[36]!==r||t[37]!==i?(C=n.mode===`apiKey`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i.setupApiKeyHeader,(0,$.jsx)(`input`,{className:p(Ln,`mt-1.5`),placeholder:`x-api-key`,value:n.headerName,required:!0,onChange:e=>r({headerName:e.target.value})})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupApiKeyHint}),(0,$.jsx)(Rn,{value:n.apiKey,onChange:e=>r({apiKey:e}),label:`API Key`,t:i,required:!0})]}):null,t[33]=n.apiKey,t[34]=n.headerName,t[35]=n.mode,t[36]=r,t[37]=i,t[38]=C):C=t[38];let w;t[39]!==n.customHeaders||t[40]!==n.mode||t[41]!==r||t[42]!==i?(w=n.mode===`headers`?(0,$.jsx)(Bn,{headers:n.customHeaders,onChange:e=>r({customHeaders:e}),t:i}):null,t[39]=n.customHeaders,t[40]=n.mode,t[41]=r,t[42]=i,t[43]=w):w=t[43];let T;return t[44]!==v||t[45]!==y||t[46]!==b||t[47]!==x||t[48]!==S||t[49]!==C||t[50]!==w?(T=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[v,y,b,x,S,C,w]}),t[44]=v,t[45]=y,t[46]=b,t[47]=x,t[48]=S,t[49]=C,t[50]=w,t[51]=T):T=t[51],T}function Hn(e){let t=(0,ft.c)(8),{label:n,children:r,hint:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{children:n}),t[0]=n,t[1]=a);let o;t[2]===i?o=t[3]:(o=i?(0,$.jsx)(`span`,{className:`block text-xs font-normal text-fg-muted`,children:i}):null,t[2]=i,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-fg`,children:[a,r,o]}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Un({row:e,t,onUpdate:n}){let[r,i]=(0,Q.useState)(()=>It(e.envJson?JSON.parse(e.envJson):void 0)),[a,o]=(0,Q.useState)(!1),s=[];try{s=Rt(e.argsText)??[]}catch{}let c=e=>n({argsText:JSON.stringify(e)});return(0,$.jsxs)(`div`,{"data-field":`commandOptions`,className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.argsLabel}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,onClick:()=>o(e=>!e),children:a?t.setupArgsRows:t.setupArgsPaste})]}),a?(0,$.jsx)(Hn,{label:t.setupArgsPaste,hint:t.argsHint,children:(0,$.jsx)(`input`,{className:Ln,value:e.argsText,onChange:e=>n({argsText:e.target.value})})}):s.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`input`,{className:Ln,"aria-label":`${t.argsLabel} ${n+1}`,value:e,onChange:e=>c(s.map((t,r)=>r===n?e.target.value:t))}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,"aria-label":t.setupRemoveArg,onClick:()=>c(s.filter((e,t)=>t!==n)),children:(0,$.jsx)(Ge,{className:`size-4`,"aria-hidden":!0})})]},n)),a?null:(0,$.jsxs)(b,{type:`button`,variant:`ghost`,onClick:()=>c([...s,``]),children:[(0,$.jsx)(he,{className:`size-4`,"aria-hidden":!0}),t.setupAddArg]})]}),(0,$.jsx)(Bn,{environment:!0,headers:r,t,onChange:e=>{i(e),n({envEntries:e,envJson:JSON.stringify(Ft(e)??{})})}})]})}function Wn(e){let t=(0,ft.c)(15),{row:n,t:r,onUpdate:i,variant:a,showOAuth:c,idReadOnly:l}=e,u=a===void 0?`all`:a,d=c===void 0?!1:c,f=l===void 0?!1:l,p=u!==`advanced`,m=u!==`basic`,h;t[0]!==p||t[1]!==i||t[2]!==n||t[3]!==r?(h=p?(0,$.jsxs)($.Fragment,{children:[n.transport===`stdio`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:`${r.commandLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`command`,className:Ln,value:n.command,required:!0,onChange:e=>i({command:e.target.value})})}),(0,$.jsx)(Un,{row:n,t:r,onUpdate:i})]}):(0,$.jsx)(Hn,{label:`${r.urlLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`url`,className:Ln,value:n.url,placeholder:`https://example.com/mcp`,required:!0,onChange:e=>i({url:e.target.value})})}),(0,$.jsx)(Hn,{label:r.setupNameLabel,hint:r.setupNameHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.displayName??``,placeholder:r.setupNamePlaceholder,onChange:e=>i({displayName:e.target.value})})})]}):null,t[0]=p,t[1]=i,t[2]=n,t[3]=r,t[4]=h):h=t[4];let g;t[5]!==m||t[6]!==f||t[7]!==i||t[8]!==n||t[9]!==d||t[10]!==r?(g=m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:r.serverIdLabel,hint:r.setupIdHint,children:(0,$.jsx)(`input`,{className:Ln,readOnly:f,value:n.id,onChange:e=>i({id:e.target.value}),placeholder:r.serverIdPlaceholder})}),n.transport===`stdio`?(0,$.jsx)(Hn,{label:r.cwdLabel,children:(0,$.jsx)(`input`,{className:Ln,value:n.cwd,onChange:e=>i({cwd:e.target.value})})}):null,n.transport!==`stdio`&&d?(0,$.jsx)(Hn,{label:r.oauthClientIdLabel,hint:r.oauthClientIdHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.oauthClientId,onChange:e=>i({oauthClientId:e.target.value})})}):null,(0,$.jsx)(Hn,{label:r.exposureLabel,hint:r.setupExposureHint,children:(0,$.jsx)(o,{"aria-label":r.exposureLabel,className:Ln,value:n.exposure,onChange:e=>i({exposure:e.target.value}),children:[`codemode`,`deferred`,`direct`,`hidden`].map(e=>(0,$.jsx)(s,{value:e,children:r.exposureLabels[e]},e))})}),(0,$.jsx)(Hn,{label:r.requestTimeoutLabel,children:(0,$.jsx)(dt,{allowEmpty:!0,type:`number`,min:1,className:Ln,value:n.timeout??``,placeholder:r.setupDefaultTimeout,onChange:e=>i({timeout:e.target.value?Number(e.target.value):void 0})})})]}):null,t[5]=m,t[6]=f,t[7]=i,t[8]=n,t[9]=d,t[10]=r,t[11]=g):g=t[11];let _;return t[12]!==h||t[13]!==g?(_=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[h,g]}),t[12]=h,t[13]=g,t[14]=_):_=t[14],_}function Gn(e,t){let n=e;if(n?.status===429)return t.setupRateLimited;if(n?.status===401)return t.setupGatewayUnauthorized;if(n?.status===404||n?.status===409)return t.setupConflict;if(n?.status&&n.status>=500)return t.setupGatewayCheckFailed;let r={command_missing:t.setupCommandMissing,connection_refused:t.setupConnectionRefused,host_not_found:t.setupHostNotFound,timeout:t.setupTimedOut,access_denied:t.setupAccessDenied,network:t.setupServiceNetworkFailed,tls:t.setupTlsFailed,invalid_response:t.setupInvalidResponse,not_found:t.setupEndpointNotFound,rate_limited:t.setupServiceRateLimited,configuration:t.setupInvalidConfig};if(n?.errorCode&&Object.hasOwn(r,n.errorCode))return r[n.errorCode];let i=e instanceof Error?e.message:typeof e==`string`?e:n?.error??``;return/ENOENT|command not found|executable.{0,30}not found/i.test(i)?t.setupCommandMissing:/ECONNREFUSED|connection refused/i.test(i)?t.setupConnectionRefused:/ENOTFOUND|EAI_AGAIN|could not resolve/i.test(i)?t.setupHostNotFound:/timeout|timed out/i.test(i)?t.setupTimedOut:/fetch failed|failed to fetch|network error|NetworkError/i.test(i)?n?.error===void 0?t.setupGatewayNetworkFailed:t.setupServiceNetworkFailed:/\b(?:401|403)\b|unauthorized|forbidden|permission denied/i.test(i)?t.setupAccessDenied:t.setupCheckFailed}function Kn(e,t){return JSON.stringify({id:e.id,config:qt(Nn(e,t))})}function qn(e,t){try{return Kn(e,t)}catch{return JSON.stringify({row:e,auth:t})}}function Jn(e){let{t,cs:n}=e,r=(0,Q.useId)(),[i,a]=(0,Q.useState)(e.initialRow),[c,f]=(0,Q.useState)(()=>Mn(e.initialRow)),[m,h]=(0,Q.useState)(`idle`),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(),[C,w]=(0,Q.useState)(),[T,E]=(0,Q.useState)(),[D,O]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,N]=(0,Q.useState)(``),[P,F]=(0,Q.useState)(``),[I,L]=(0,Q.useState)([]),[R,z]=(0,Q.useState)(`0`),[B,V]=(0,Q.useState)(0),[H,U]=(0,Q.useState)(``),[re,W]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(!1),se=e.mode===`edit`,[G,ce]=(0,Q.useState)(``),K=(0,Q.useRef)(void 0),[le]=(0,Q.useState)(()=>qn(e.initialRow,Mn(e.initialRow))),q=(0,Q.useRef)(e.mode===`edit`?e.initialRow.id:``),de=(0,Q.useRef)(void 0),J=(0,Q.useRef)(void 0),fe=(0,Q.useRef)(void 0),Y=(0,Q.useRef)(null),pe=(0,Q.useRef)(``),X=(0,Q.useRef)(!0),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(null),ye=(0,Q.useRef)(e.onSaved);ye.current=e.onSaved;let Z=T?.state===`starting`||T?.state===`authorizing`,be=m!==`idle`||Z,xe=le!==qn(i,c),Se=i.extra.enabled===!1,Ce=!v&&(xe||!!M.trim());(0,Q.useEffect)(()=>(X.current=!0,()=>{X.current=!1,de.current?.abort(),Y.current?.close(),K.current&&Zt(K.current).catch(()=>{})}),[]),(0,Q.useEffect)(()=>{if(!Ce)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ce]),(0,Q.useEffect)(()=>{if(!x)return;let e=_e.current?.querySelector(`[data-field="${x.field}"]`),t=e?.closest(`details`);t&&(t.open=!0);let n=e?.querySelector(`input,button,textarea`)??e;return n?.setAttribute(`aria-invalid`,`true`),n?.setAttribute(`aria-describedby`,r),x.focus!==!1&&(n??ve.current)?.focus(),()=>{n?.removeAttribute(`aria-invalid`),n?.removeAttribute(`aria-describedby`)}},[x,r]),(0,Q.useEffect)(()=>{if(!T||!Z)return;let e=new AbortController;J.current=e;let n;async function r(){try{let n=await en(K.current,e.signal);if(e.signal.aborted||(E(n),n.authorizationUrl&&pe.current!==n.authorizationUrl&&(pe.current=n.authorizationUrl,window.electronAPI?.shell?.openExternalUrl?!(await window.electronAPI.shell.openExternalUrl(n.authorizationUrl)).ok&&!e.signal.aborted&&_(t.oauthOpenFailed):Y.current&&!Y.current.closed&&Y.current.location.replace(n.authorizationUrl)),e.signal.aborted))return;if(n.state===`connected`){fe.current=void 0,Y.current?.close(),w({state:`connected`,toolCount:n.toolCount}),_(``);return}if(n.state===`error`||n.state===`cancelled`){fe.current=void 0,Y.current?.close(),_(n.state===`cancelled`?t.setupCancelled:t.setupAuthFailed),/client.{0,20}(id|registration)|register|registration/i.test(n.error??``)&&O(!0);return}}catch{if(e.signal.aborted)return;we(),Y.current?.close(),_(t.setupAuthFailed);return}n=setTimeout(()=>void r(),1200)}return r(),()=>{e.abort(),clearTimeout(n)}},[T?.id,Z,t.oauthOpenFailed,t.setupCancelled,t.setupAuthFailed]);function we(){de.current?.abort(),J.current?.abort(),K.current&&Zt(K.current).catch(()=>{}),K.current=void 0,ce(``),W(!1),w(void 0),E(void 0),_(``),S(void 0)}function Te(e){a(t=>({...t,...e})),we()}function De(e){f(t=>({...t,...e})),we()}function Oe(){m===`saving`||Z||(m===`checking`&&(we(),h(`idle`)),Ce?ae(!0):e.onClose())}function ke(){try{L(Wt(M)),z(`0`),F(``)}catch{F(t.setupImportError),L([])}}function Ae(){let t=I[Number(R)];if(!t)return;let n={...t,id:q.current||t.id,clientKey:e.initialRow.clientKey,extra:{...t.extra,...q.current?{enabled:i.extra.enabled}:{}}};a(n),f(Mn(n)),we(),V(e=>e+1),j(!1),N(``),L([])}function je(e){function n(e,t){return S({field:e,message:t}),!1}if(e.transport===`streamable-http`){try{e.url=Ut(e.url)}catch{return n(`url`,t.setupAddressInvalid)}if(c.mode===`bearer`&&!c.token.trim().replace(/^Bearer\s*/i,``)||c.mode===`apiKey`&&(!c.apiKey.trim()||!c.headerName.trim()))return n(`auth`,t.setupCredentialRequired);if(Pn(e.headers)>=0)return n(`auth`,t.setupHeaderInvalid);if(c.mode===`oauth`&&e.headers.some(e=>e.key.trim().toLowerCase()===`authorization`))return n(`auth`,t.setupOAuthHeaderConflict);if(c.mode===`headers`&&!e.headers.some(e=>e.key.trim()&&(e.value.trim()||e.reference)))return n(`auth`,t.setupCredentialRequired)}else if(!e.command.trim())return n(`command`,t.setupCommandRequired);if(e.timeout!==void 0&&(!Number.isFinite(e.timeout)||e.timeout<=0))return n(`advanced`,t.setupInvalidConfig);try{qt(e)}catch(r){return n(e.transport===`stdio`?`commandOptions`:`advanced`,r instanceof Error&&r.message.startsWith(`Environment`)?t.setupEnvInvalid:t.setupInvalidConfig)}return!0}async function Me(){_(``),h(`checking`),pe.current=``,window.electronAPI?.shell?.openExternalUrl||(Y.current=window.open(`about:blank`,`_blank`),Y.current&&(Y.current.opener=null));try{let e=await $t(K.current);if(!X.current){Y.current?.close(),K.current&&Zt(K.current).catch(()=>{});return}fe.current=e.id,E(e)}catch{Y.current?.close(),X.current&&_(t.setupAuthFailed)}finally{X.current&&h(`idle`)}}async function Ne(){let r=Nn(i,c);if(!je(r))return;let o=e.existingCustomServers.filter(t=>t.clientKey!==e.initialRow.clientKey&&t.id!==q.current),s=new Set([...e.managedServerIds,...o.map(e=>e.id)]);if(r.id=q.current||r.id.trim()||Ht(r,s),!/^[a-zA-Z0-9_-]+$/.test(r.id)||[...s].some(e=>e.replace(/-/g,`_`)===r.id.replace(/-/g,`_`))){S({field:`advanced`,message:n.duplicateServerId});return}we(),h(`checking`);let l=new AbortController;de.current=l;try{let n=await Yt(r,q.current||void 0,e.initialRow.extra,l.signal);if(!X.current||l.signal.aborted){Zt(n.id).catch(()=>{});return}K.current=n.id,a(r),ce(qn(r,c));let i=await Xt(n.id,l.signal);if(!X.current||l.signal.aborted)return;w(i),i.state===`error`&&_(Gn(i,t))}catch(e){X.current&&!l.signal.aborted&&_(e.status===409?t.setupConflict:Gn(e,t))}finally{X.current&&de.current===l&&h(`idle`)}}async function Pe(n=!1){if(!(!K.current||C?.state!==`connected`||G!==qn(i,c))){h(`saving`),_(``);try{let t=await Qt(K.current,n);K.current=void 0,await ye.current().catch(()=>{}),t?.reloadRequired?y(!0):e.onClose()}catch(e){let n=e.status;n===404||n===409?(we(),_(t.setupConflict)):_(t.setupSaveFailed)}finally{X.current&&h(`idle`)}}}async function Fe(){J.current?.abort();let e=K.current;fe.current=void 0,E(void 0),Y.current?.close(),_(t.setupCancelled),h(`checking`);try{e&&await tn(e)}catch{X.current&&(we(),_(t.setupCancelled))}finally{X.current&&h(`idle`)}}async function Ie(){T?.authorizationUrl&&(window.electronAPI?.shell?.openExternalUrl?(await window.electronAPI.shell.openExternalUrl(T.authorizationUrl)).ok||_(t.oauthOpenFailed):window.open(T.authorizationUrl,`_blank`,`noopener,noreferrer`))}async function Le(){if(T)try{await nn(K.current,H),U(``),_(``)}catch{_(t.setupRedirectInvalid)}}let Re=!!K.current&&G===qn(i,c)&&(c.mode===`oauth`||c.mode===`auto`&&C?.state===`oauth_required`)&&C?.state!==`connected`,ze=/^(?:https?:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?=[:/]|$)/i.test(i.url.trim()),Be=I[Number(R)];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(oe,{open:e.open,onOpenChange:e=>{e||Oe()},children:(0,$.jsxs)(st,{children:[(0,$.jsx)(ue,{className:`fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(ee,{ref:he,tabIndex:-1,className:`fixed left-1/2 top-1/2 z-[60] flex h-[min(44rem,calc(100dvh-2rem))] w-[min(42rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`,onOpenAutoFocus:e=>{e.preventDefault(),he.current?.focus()},children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge p-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(k,{className:`font-semibold`,children:e.mode===`edit`?t.setupEditTitle:t.setupTitle}),(0,$.jsx)(ne,{className:`mt-1 text-sm text-fg-muted`,children:t.setupHint})]}),(0,$.jsx)(`button`,{type:`button`,disabled:m===`saving`||Z,onClick:Oe,className:`rounded-lg p-2 text-fg-muted hover:bg-surface-hover disabled:opacity-50`,"aria-label":n.modalClose,children:(0,$.jsx)(te,{className:`size-5`,"aria-hidden":!0})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-5`,children:[A?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(b,{variant:`ghost`,onClick:()=>j(!1),children:t.setupImportBack}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportEmpty}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[t.setupImport,(0,$.jsx)(`textarea`,{className:p(Ln,`mt-1.5 min-h-40 font-mono text-xs`),value:M,placeholder:`{"mcpServers": {"docs": {"url": "https://example.com/mcp"}}}`,onChange:e=>{N(e.target.value),L([]),F(``)}})]}),(0,$.jsx)(b,{variant:`secondary`,disabled:!M.trim(),onClick:ke,children:t.setupImportPreview}),P?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:P}):null,Be?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportScope}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium`,children:[t.setupImportChoose,(0,$.jsx)(o,{"aria-label":t.setupImportChoose,className:p(Ln,`mt-1.5`),value:R,onChange:e=>z(e.target.value),children:I.map((e,t)=>(0,$.jsx)(s,{value:String(t),children:e.displayName||e.id||un(e)},t))})]}),(0,$.jsxs)(`p`,{className:`break-all text-sm text-fg-muted`,children:[Be.transport===`stdio`?t.setupUseCommand:t.setupUseUrl,` · `,un(Be)]})]}):null]}):(0,$.jsxs)(`form`,{ref:_e,noValidate:!0,onBlurCapture:e=>{if(e.target instanceof HTMLInputElement&&e.target.dataset.field===`url`&&i.url.trim())try{Ut(i.url)}catch{S({field:`url`,message:t.setupAddressInvalid,focus:!1})}},onSubmit:e=>{e.preventDefault(),Ne()},children:[(0,$.jsxs)(`fieldset`,{disabled:be||v,className:`min-w-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(me,{className:`flex gap-1`,role:`group`,"aria-label":t.transportLabel,children:[`streamable-http`,`stdio`].map(e=>(0,$.jsx)(b,{type:`button`,variant:i.transport===e?`secondary`:`ghost`,"aria-pressed":i.transport===e,onClick:()=>Te({transport:e}),children:e===`stdio`?t.setupUseCommand:t.setupUseUrl},e))}),(0,$.jsx)(b,{type:`button`,variant:`ghost`,onClick:()=>j(!0),children:t.setupImport})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(Wn,{row:i,t,variant:`basic`,onUpdate:Te},`${i.transport}-${B}`)}),i.transport===`streamable-http`?(0,$.jsx)(`div`,{"data-field":`auth`,children:(0,$.jsx)(Vn,{allowExisting:!!i.extra.auth||i.headers.some(e=>!!e.reference),draft:c,onChange:De,t})}):null,x?(0,$.jsx)(`p`,{id:r,ref:ve,tabIndex:-1,role:`alert`,className:`text-sm text-danger`,children:x.message}):null,(0,$.jsxs)(`details`,{"data-field":`advanced`,className:`rounded-lg border border-edge p-3`,open:D,onToggle:e=>O(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg-muted`,children:t.setupAdvanced}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[(0,$.jsx)(Wn,{row:i,t,variant:`advanced`,idReadOnly:se,showOAuth:c.mode===`oauth`,onUpdate:Te}),i.transport===`streamable-http`&&c.mode!==`headers`&&c.mode!==`existing`?(0,$.jsx)(Bn,{additional:!0,headers:c.additionalHeaders,onChange:e=>De({additionalHeaders:e}),t}):null]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:i.transport===`stdio`?t.setupCommandHostHint:ze?t.setupLocalhostHint:t.setupGatewayHint}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.setupTestNotice})]}),(0,$.jsx)(`button`,{type:`submit`,hidden:!0})]}),v?(0,$.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-fg`,children:t.setupReloadRequired}):null,!A&&!v?(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,"aria-live":`polite`,children:[m===`idle`?null:(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(d,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),m===`saving`?t.setupSaving:t.setupChecking]}),m===`idle`&&se&&!xe&&!C&&!g&&!Z?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:Se?t.setupDisabled:e.lastCheck?t.setupLastCheck.replace(`{{count}}`,String(e.lastCheck.toolCount)):t.setupSavedUnchecked}):null,C?.state===`connected`?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-success`,children:[(0,$.jsx)(l,{className:`size-4 shrink-0`,"aria-hidden":!0}),C.toolCount?t.setupConnected.replace(`{{count}}`,String(C.toolCount)):t.setupZeroTools]}),(0,$.jsx)(b,{ref:ge,variant:`secondary`,onClick:()=>W(!0),children:t.viewTools})]}):null,C?.state===`token_required`?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:t.setupNeedsAuth}):null,C?.state===`oauth_required`&&!Z?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupOAuthRequired}):null,Z?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(d,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),t.setupAuthorizing]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[T?.authorizationUrl?(0,$.jsxs)(b,{variant:`secondary`,onClick:()=>void Ie(),children:[(0,$.jsx)(u,{className:`size-4`,"aria-hidden":!0}),t.oauthOpenAuthorization]}):null,(0,$.jsx)(b,{variant:`ghost`,onClick:()=>void Fe(),children:t.setupCancelAuth})]}),T?.acceptsRedirect?(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:t.setupRemoteFallback}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.setupRedirectHint}),(0,$.jsxs)(`label`,{className:`mt-2 block text-sm`,children:[t.setupRedirectLabel,(0,$.jsx)(`input`,{className:Ln,value:H,onChange:e=>U(e.target.value)})]}),(0,$.jsx)(b,{className:`mt-2`,disabled:!H.trim(),onClick:()=>void Le(),children:t.setupContinue})]}):null]}):null,g?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-1 text-sm`,children:[(0,$.jsx)(`p`,{className:`text-danger`,children:g}),g!==t.setupSaveFailed&&m!==`saving`?(0,$.jsx)(`p`,{className:`text-fg-muted`,children:t.setupTestFailure}):null]}):null]}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge p-4`,children:[(0,$.jsx)(b,{variant:`secondary`,disabled:m===`saving`||Z,onClick:Oe,children:se||v?t.setupClose:n.modalCancel}),v?null:A?(0,$.jsx)(b,{variant:`primary`,disabled:!Be,onClick:Ae,children:t.setupImportApply}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(b,{variant:C?.state===`connected`?`secondary`:`primary`,disabled:be,onClick:()=>Re?void Me():void Ne(),children:Re?t.setupSignIn:t.setupTestConnection}),C?.state===`connected`&&G===qn(i,c)?(0,$.jsxs)($.Fragment,{children:[Se?(0,$.jsx)(b,{variant:`secondary`,disabled:be,onClick:()=>void Pe(!0),children:t.setupEnableSave}):null,(0,$.jsx)(b,{variant:`primary`,disabled:be,"aria-busy":be,onClick:()=>void Pe(),children:se?t.setupSaveOnly:t.setupAddConnection})]}):null]})]})]})]})}),(0,$.jsx)(Ee,{open:ie,title:t.setupUnsavedTitle,description:t.setupUnsavedHint,confirmLabel:t.setupDiscard,cancelLabel:t.setupKeepEditing,onCancel:()=>ae(!1),onConfirm:e.onClose,overlayClassName:`z-[70]`,contentClassName:`z-[70]`}),re?(0,$.jsx)(sn,{draftId:K.current,serverId:i.id,displayName:i.displayName,returnFocusTo:ge.current,t,onClose:()=>W(!1)}):null]})}var Yn=`recommended`,Xn=`builtin`,Zn=`composio`,Qn=`xopc-store`;function $n(e,t=`en`){return e==="default"&&t.startsWith(`zh`)?Yn:Xn}function er(e,t){let n=e.connectorManifest;if(!n||typeof n!=`object`||Array.isArray(n))return null;let r=n;if(r.contractVersion!==1||r.id!==e.name)return null;let i=r.runtime,a=r.auth;if(!i||typeof i!=`object`||Array.isArray(i)||!a||typeof a!=`object`||Array.isArray(a))return null;let o=i,s=a;if(o.type!==`mcp`||typeof o.serverId!=`string`)return null;let c=[`code`,`docs`,`browser`,`data`,`automation`,`custom`].includes(String(r.category??``))?r.category:`custom`,l=s.mode===`oauth`?{mode:`oauth`,...typeof s.clientId==`string`?{clientId:s.clientId}:{}}:s.mode===`apiKey`?{mode:`apiKey`}:{mode:`none`},u=e.localizations?.[t===`zh`?`zh-CN`:`en`];return{id:e.name,version:e.latestVersion??`store`,displayName:u?.displayName??(typeof r.displayName==`string`?r.displayName:e.name),description:u?.description??(typeof r.description==`string`?r.description:e.description),category:c,kind:`mcp`,source:`store`,...e.branding?.iconUrl?{branding:{logoUrl:e.branding.iconUrl,source:`registry`}}:{},capabilities:Array.isArray(r.capabilities)?r.capabilities.filter(e=>typeof e==`string`):[],tags:Array.isArray(r.tags)?r.tags.filter(e=>typeof e==`string`):[`store`],auth:l,setup:r.setup&&typeof r.setup==`object`&&!Array.isArray(r.setup)?r.setup:{},runtime:{type:`mcp`,serverId:o.serverId}}}function tr(e){return ie(e.map(e=>({connector:e,service:{id:e.id,source:e.source===`builtin`?`builtin-connector`:e.source===`store`?`store-connector`:`registry-connector`}})),`en`).map(e=>e.connector)}function nr(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/user-model`}function rr({embedded:e=!1,onHeaderActionChange:t}){let n=Z().filter(pn),r=g(e=>e.language),o=f(r),s=o.connectorsSettings,l=o.mcpSettings,u=h(e=>e.conversationId),m=!!u,_=a(),[v,x]=i(),S=v.get(`understanding`)===`1`,w=nr(v.get(`returnTo`)),E=!!v.get(`returnTo`)&&!S,D=v.get(`tab`),[k,j]=(0,Q.useState)(!S&&D===`connected`?`connected`:`discover`),{data:M}=y(m&&k===`discover`&&!S?[`service-recommendations`,r]:null,()=>N(r),{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>new Set(M?.items.filter(e=>e.service?.source===`store-plugin`).map(e=>re(e.id))??[]),[M]),F=(0,Q.useRef)(!1),[I,L]=(0,Q.useState)({catalog:[],registryCatalog:[],instances:[],loading:!0,error:null}),[R,z]=(0,Q.useState)(!1),[B,ee]=(0,Q.useState)(!1),[H,te]=(0,Q.useState)(1),[ne,W]=(0,Q.useState)(void 0),[ie,ae]=(0,Q.useState)(``),[oe,se]=(0,Q.useState)(S||E?v.get(`connector`)??``:``),[G,ce]=(0,Q.useState)($n(S?`understanding`:`default`,r)),[ue,q]=(0,Q.useState)(`name`),[de,fe]=(0,Q.useState)(S?`understand`:`all`),[Y,X]=(0,Q.useState)(null),[he,_e]=(0,Q.useState)(null),[xe,Ce]=(0,Q.useState)(null),[we,Te]=(0,Q.useState)(null),[Ee,De]=(0,Q.useState)(null),[Oe,ke]=(0,Q.useState)(null),{data:Ae,mutate:je}=C(m),Me=Ae?.payload?.config,Ne=(0,Q.useMemo)(()=>Me===void 0?null:Kt(Me),[Me]),Pe=Ne?.servers??[],Fe=I.instances.length+Pe.length+n.length,[Ie,Le]=(0,Q.useState)({});(0,Q.useEffect)(()=>{if(Le({}),!m||!Me)return;let e=new AbortController;return an(e.signal).then(t=>{e.signal.aborted||Le(t)}).catch(()=>{}),()=>e.abort()},[m,Me]);let Re=(0,Q.useCallback)(async()=>{if(!u){L({catalog:[],registryCatalog:[],instances:[],loading:!1,error:null});return}L(e=>({...e,loading:!0,error:null}));try{let[e,t]=await Promise.all([ve(),be()]);L(n=>({catalog:e,registryCatalog:n.registryCatalog,instances:t,loading:!1,error:null}))}catch(e){L({catalog:[],registryCatalog:[],instances:[],loading:!1,error:e instanceof Error?e.message:String(e)})}},[u]);(0,Q.useEffect)(()=>{Re()},[Re]),(0,Q.useEffect)(()=>{F.current||I.loading||m&&!Ne||(j(S?`discover`:Fe>0?`connected`:`discover`),F.current=!0)},[m,Fe,Ne,S,I.loading]),(0,Q.useEffect)(()=>{ce(e=>e===`builtin`||e===`recommended`?$n(S?`understanding`:`default`,r):e)},[r,S]);let ze=(0,Q.useCallback)(e=>{F.current=!0,j(e)},[]),Be=(0,Q.useMemo)(()=>[{id:Zn,displayName:s.composioSourceName},{id:Qn,displayName:s.storeSourceName}],[s.composioSourceName,s.storeSourceName]),Ve=(0,Q.useCallback)(async e=>{if(!m||G===`builtin`||G===`recommended`){L(e=>({...e,registryCatalog:[]})),te(1),W(void 0);return}let t=oe.trim(),n=Math.max(e?.page??1,1),i=e?.append??!1,a=G===`all`?Be:Be.filter(e=>e.id===G);if(a.length!==0){z(!0),i?L(e=>({...e,error:null})):(te(1),W(void 0),L(e=>({...e,registryCatalog:[],error:null})));try{let e=await Promise.all(a.map(async e=>{if(e.id===`composio`){let e=await ye({q:t||void 0,page:n,pageSize:24,verification:`experimental`});return{connectors:e.connectors,totalPages:e.meta.totalPages}}let i=await K({q:t||void 0,page:n,pageSize:24,sort:ue===`source`?`newest`:`downloads`});return{connectors:i.items.flatMap(e=>{let t=er(e,r);return t?[t]:[]}),totalPages:i.meta.totalPages}})),o=tr(e.flatMap(e=>e.connectors)),s=Math.max(1,...e.map(e=>e.totalPages??1));te(n),W(s),L(e=>({...e,registryCatalog:i?tr([...e.registryCatalog,...o]):o}))}catch(e){L(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{z(!1)}}},[ue,oe,G,m,Be,r]);(0,Q.useEffect)(()=>{if(k!==`discover`||I.loading)return;if(G===`builtin`||G===`recommended`){L(e=>({...e,registryCatalog:[]})),te(1),W(void 0);return}let e=window.setTimeout(()=>{Ve()},oe.trim()?350:0);return()=>window.clearTimeout(e)},[oe,G,Ve,I.loading,k]);let He=(0,Q.useMemo)(()=>new Set(I.instances.map(e=>e.connectorId)),[I.instances]),Ue=(0,Q.useMemo)(()=>new Map([...I.catalog,...I.registryCatalog].map(e=>[e.id,e])),[I.catalog,I.registryCatalog]);(0,Q.useEffect)(()=>{if(I.loading)return;let e=v.get(`connector`),t=v.get(`instance`);if(!e&&!t)return;let n=I.instances.find(n=>t?n.instanceId===t:n.connectorId===e);if(n)F.current=!0,ae(``),Ce(n.instanceId),Te(n),j(`connected`);else if(e){let t=Ue.get(e);if(!t)return;F.current=!0,ce($n(S?`understanding`:`default`,r)),se(``),_e(t),j(`discover`)}let i=new URLSearchParams(v);i.delete(`connector`),i.delete(`instance`),i.set(`tab`,n?`connected`:`discover`),x(i,{replace:!0})},[Ue,S,r,v,x,I.instances,I.loading]);let We=(0,Q.useCallback)(async e=>{ee(!0),L(e=>({...e,error:null}));try{let t=await T(e);X(U(t.definition,{packageName:t.packageName,version:t.version,reviewHash:t.reviewHash,permissions:t.permissions}))}catch(e){L(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{ee(!1)}},[]);(0,Q.useEffect)(()=>{let e=v.get(`storeConnector`);if(!m||!e)return;let t=new URLSearchParams(v);t.delete(`storeConnector`),x(t,{replace:!0}),We(e)},[m,v,x,We]);let Ge=(0,Q.useMemo)(()=>new Set(I.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[I.instances]),qe=(0,Q.useCallback)(async e=>{let t=await on(e);await je(),await Re(),t.reloadRequired&&L(e=>({...e,error:l.setupReloadRequired}))},[Re,je,l.setupReloadRequired]),Je=(0,Q.useCallback)(()=>{ke({mode:`add`,row:jn(Pe,Ge)})},[Pe,Ge]),Ye=Ke(e=>e.setPageHeader),Xe=Ke(e=>e.clearPageHeader),Ze=(0,Q.useMemo)(()=>({searchLabel:k===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder,search:(0,$.jsx)(ct,{value:k===`connected`?ie:oe,onChange:k===`connected`?ae:se,placeholder:k===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder}),secondary:(0,$.jsx)(jt,{onRefresh:k===`connected`&&m?Re:void 0,refreshing:I.loading,refreshLabel:s.refreshConnections,onBrowseCatalog:()=>ze(`discover`),onAddCustomServer:Je,addLabel:s.addConnection,browseLabel:s.addFromCatalog,customLabel:s.addCustomServerAdvanced,serviceLabel:r.startsWith(`zh`)?`应用连接服务`:`Connection service`,moreActionsLabel:o.capabilitiesHub.moreActions})}),[ie,s,oe,m,r,Re,o.capabilitiesHub.moreActions,Je,ze,I.loading,k]);(0,Q.useLayoutEffect)(()=>e?(t?.(Ze),()=>t?.(null)):(Ye({startExtra:null,main:(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:s.title})}),end:(0,$.jsx)(lt,{contribution:Ze})}),()=>Xe()),[Xe,s.title,e,Ze,t,Ye]);let Qe=(0,Q.useMemo)(()=>I.instances.map(e=>({instance:e,value:Ct(e,Ue.get(e.connectorId))})),[Ue,I.instances]),$e=(0,Q.useMemo)(()=>new Map(Qe.map(({instance:e,value:t})=>[e.instanceId,t])),[Qe]),et=(0,Q.useMemo)(()=>I.instances.filter(e=>V(e,ie)).sort((e,t)=>{let n={needs_setup:0,checking:1,ready:2},r=$e.get(e.instanceId)?.state??`checking`,i=$e.get(t.instanceId)?.state??`checking`;return n[r]-n[i]||e.displayName.localeCompare(t.displayName)}),[ie,$e,I.instances]),tt=(0,Q.useMemo)(()=>et.filter(e=>$e.get(e.instanceId)?.state===`needs_setup`),[$e,et]),nt=(0,Q.useMemo)(()=>et.filter(e=>$e.get(e.instanceId)?.state!==`needs_setup`),[$e,et]),rt=(0,Q.useMemo)(()=>Pe.filter(e=>A(e,ie)),[ie,Pe]),it=(0,Q.useMemo)(()=>{let e=ie.trim().toLowerCase();return n.filter(t=>[t.name,t.description,...(t.setup?.authorizations??[]).map(e=>e.title),...(t.components?.mcp??[]).map(e=>e.name)].filter(Boolean).join(` `).toLowerCase().includes(e))},[ie,n]),at=et.length+rt.length+it.length,ot=(0,Q.useMemo)(()=>I.catalog.filter(e=>e.source===`builtin`&&e.integrationStrategy?.preferred!==!1&&pe(e)),[I.catalog]),st=(0,Q.useMemo)(()=>G===`recommended`?[]:G===`builtin`?ot:G===`all`?tr([...ot,...I.registryCatalog]):I.registryCatalog,[ot,G,I.registryCatalog]),ut=(0,Q.useMemo)(()=>{let e=S?st.filter(e=>e.understanding?.mode===`activity`):tr(st).filter(e=>!P.has(re(e.id)));return ge(de===`all`?e:e.filter(e=>xt(e).includes(de)),oe,ue)},[ue,oe,st,S,de,P]),dt=(0,Q.useMemo)(()=>bt.filter(e=>st.some(t=>xt(t).includes(e))),[st]);(0,Q.useEffect)(()=>{de!==`all`&&!dt.includes(de)&&fe(`all`)},[dt,de]);let ft=k===`discover`&&G!==`builtin`&&!!(ne&&H<ne),mt=(0,Q.useMemo)(()=>I.instances.find(e=>e.instanceId===xe)??we,[xe,we,I.instances]),_t=(0,Q.useMemo)(()=>[{value:Yn,label:r===`zh`?`推荐服务`:`Recommended services`},{value:`all`,label:s.discoverSourceAll},{value:Xn,label:s.discoverSourceBuiltin},...Be.map(e=>({value:e.id,label:e.displayName}))],[s.discoverSourceAll,s.discoverSourceBuiltin,Be,r]),St=[{id:`connected`,label:s.tabConnected,count:Fe},{id:`discover`,label:s.tabDiscover}];return(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,$.jsxs)(`div`,{className:p(`mx-auto flex w-full max-w-7xl flex-col gap-6 px-4 sm:px-6 lg:px-8`,e?`pb-7 pt-3 lg:pb-9 lg:pt-4`:`py-7 lg:py-9`),children:[m?null:(0,$.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:s.tokenHint}),S?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.understandingSetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.understandingSetupHint})]}),(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`shrink-0`,onClick:()=>_(w),children:s.understandingSetupDone})]}):null,E?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.recoverySetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.recoverySetupHint})]}),(0,$.jsx)(b,{type:`button`,variant:`secondary`,className:`min-h-11 shrink-0`,onClick:()=>_(w),children:s.recoverySetupDone})]}):null,(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(`div`,{className:`border-b border-edge-subtle pb-3 dark:border-edge-subtle`,children:(0,$.jsx)(Se,{items:St,activeTab:k,onChange:ze,ariaLabel:s.navAria,tabIdPrefix:`connectors-tab`,panelIdPrefix:`connectors-panel`,className:`flex-wrap`})}),I.error?(0,$.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:I.error}):null,k===`connected`&&m?(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:I.loading?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.slice(0,3).map(e=>(0,$.jsx)(yt,{},e))}):Fe===0?(0,$.jsxs)(`div`,{className:`py-14 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.connectionsEmpty}),(0,$.jsx)(b,{type:`button`,variant:`primary`,className:`mt-4`,onClick:()=>ze(`discover`),children:s.addFromCatalog})]}):at===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.connectionsSearchEmpty}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[tt.length?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:s.needsAttentionTitle}),(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-amber-700 dark:text-amber-300`,children:tt.length})]}),(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:tt.map(e=>(0,$.jsx)(An,{instance:e,definition:Ue.get(e.connectorId),highlighted:e.instanceId===Ee,onOpenDetails:e=>{De(null),Ce(e.instanceId),Te(e)},t:s},e.instanceId))})]}):null,nt.length||it.length?(0,$.jsx)(`section`,{children:(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[nt.map(e=>(0,$.jsx)(An,{instance:e,definition:Ue.get(e.connectorId),highlighted:e.instanceId===Ee,onOpenDetails:e=>{De(null),Ce(e.instanceId),Te(e)},t:s},e.instanceId)),it.map(e=>(0,$.jsx)(mn,{extension:e,language:r,onOpen:()=>_(le(e.pluginId,`connections`,e.authorizationStatus===`required`))},e.id))]})}):null,rt.length||!ie.trim()?(0,$.jsx)(fn,{servers:rt,lastChecks:Ie,t:l,cs:s,onAdd:Je,onEdit:e=>ke({mode:`edit`,row:structuredClone(e)}),onRemove:qe}):null]})}):null,k===`discover`&&m?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[S?null:(0,$.jsx)(me,{className:`flex min-w-0 flex-1 basis-80 flex-wrap gap-2`,role:`group`,"aria-label":s.taskFilterAria,indicatorClassName:`rounded-lg bg-surface-active`,children:[`all`,...dt].map(e=>(0,$.jsx)(`button`,{type:`button`,className:p(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,de===e?`border-accent/40 bg-accent-soft text-accent-fg`:`border-edge bg-surface-panel text-fg-muted hover:bg-surface-hover hover:text-fg`),"aria-pressed":de===e,onClick:()=>fe(e),children:e===`all`?s.taskAll:s.connectorBenefitHeadings[e]},e))}),(0,$.jsxs)(`div`,{className:p(`ml-auto grid w-full gap-2 sm:flex sm:w-auto sm:justify-end`,S?`grid-cols-1`:`grid-cols-2`),children:[S?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(c,{value:G,options:_t,placeholder:s.discoverSourceAll,allowEmpty:!1,ariaLabel:s.registrySourceAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:ce})}),G===`recommended`?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(c,{value:ue,options:[{value:`name`,label:s.sortName},{value:`source`,label:s.sortSource}],placeholder:s.sortName,allowEmpty:!1,ariaLabel:s.sortAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:e=>q(e)})})]})]}),G===`recommended`?(0,$.jsx)(J,{layout:`cards`,initialCount:6,query:oe,onChanged:async()=>{await Re(),await je()}}):(I.loading||R)&&ut.length===0?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.map(e=>(0,$.jsx)(vt,{},e))}):ut.length===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.discoverEmpty}):(0,$.jsxs)(`div`,{className:`relative`,children:[R?(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[1] flex justify-center bg-surface-panel/40 pt-[min(28vh,7.5rem)] backdrop-blur-[1px] motion-reduce:backdrop-blur-none dark:bg-surface-base/35`,"aria-busy":`true`,"aria-label":s.loading,children:(0,$.jsx)(d,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:ut.map(e=>(0,$.jsx)(pt,{connector:e,installed:He.has(e.id)||gt(e,I.instances),onInstall:e=>{if(e.source===`store`){We(e.id);return}X(U(e))},onOpenDetails:e.source===`store`?void 0:_e,t:s},e.id))}),ft?(0,$.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,$.jsxs)(b,{type:`button`,variant:`secondary`,disabled:R||B,onClick:()=>void Ve({page:H+1,append:!0}),children:[R?(0,$.jsx)(d,{className:`size-4 animate-spin`}):null,s.loadMore]})}):null]})]}):null]}),Y?(0,$.jsx)(O,{draft:Y,onChange:X,onClose:()=>X(null),t:s,onInstalled:async e=>{await Re(),await je(),De(e.instanceId),ze(`connected`)}}):null,he?(0,$.jsx)(Dt,{connector:he,installed:He.has(he.id)||gt(he,I.instances),onClose:()=>_e(null),onInstall:e=>X(U(e)),t:s}):null,mt?(0,$.jsx)(kn,{instance:mt,definition:Ue.get(mt.connectorId),onClose:()=>{Ce(null),Te(null)},onChanged:Re,t:s,mcp:l}):null,Oe?(0,$.jsx)(Jn,{open:!0,mode:Oe.mode,initialRow:Oe.row,lastCheck:Oe.mode===`edit`?Ie[Oe.row.id]:void 0,existingCustomServers:Pe,config:Me,managedServerIds:Ge,t:l,cs:s,onClose:()=>ke(null),onSaved:async()=>{await je(),await Re(),ze(`connected`)}},`${Oe.mode}-${Oe.row.clientKey}`):null]})})}export{rr as ConnectorsPage};