@xopcai/xopc 0.0.221 → 0.0.222

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 (135) 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-B8SBTGg3.js → agent-avatar-dicebear-DsR_2U9-.js} +1 -1
  4. package/dist/gateway/static/root/assets/agents-DijFbC4G.js +68 -0
  5. package/dist/gateway/static/root/assets/{app-management-settings-panel-BtmPXaqu.js → app-management-settings-panel-BCzVX09V.js} +1 -1
  6. package/dist/gateway/static/root/assets/{appearance-settings-t7HoJyNN.js → appearance-settings-DgSpwqQI.js} +1 -1
  7. package/dist/gateway/static/root/assets/{apps-page-DJ_Dsb1j.js → apps-page-BFAmf9hq.js} +1 -1
  8. package/dist/gateway/static/root/assets/{attachment-load-CsLXzas8.js → attachment-load-BQHcAR6J.js} +1 -1
  9. package/dist/gateway/static/root/assets/{automations-page-D-zgoAKz.js → automations-page-CswK3HFb.js} +1 -1
  10. package/dist/gateway/static/root/assets/automations-workspace-B8us5JBf.js +6 -0
  11. package/dist/gateway/static/root/assets/{binary-plugins-B-MjP_22.js → binary-plugins-BlpyTJ1b.js} +1 -1
  12. package/dist/gateway/static/root/assets/{block-editor-i4CfDqLG.js → block-editor-C3mwGsms.js} +4 -4
  13. package/dist/gateway/static/root/assets/browser-settings-page-BeBd17-3.js +8 -0
  14. package/dist/gateway/static/root/assets/{browser-workflows-page-EEFHUm1i.js → browser-workflows-page-CZNOOQY4.js} +2 -2
  15. package/dist/gateway/static/root/assets/capabilities-settings-panel-Bv0z3KRq.js +7 -0
  16. package/dist/gateway/static/root/assets/capability-presets-settings-panel-BczD-pWE.js +3 -0
  17. package/dist/gateway/static/root/assets/{channels-settings-Je-9a5ZC.js → channels-settings-2KQYq6xl.js} +1 -1
  18. package/dist/gateway/static/root/assets/{chat-terminal-dock-DT-OFl4r.js → chat-terminal-dock-2fpzufzt.js} +1 -1
  19. package/dist/gateway/static/root/assets/connectors-page-PB1boaNy.js +2 -0
  20. package/dist/gateway/static/root/assets/{cron-expression-MZ_AJqrm.js → cron-expression-VePLfPUR.js} +1 -1
  21. package/dist/gateway/static/root/assets/{date-picker-Bv9hZLuD.js → date-picker-CJegmPTJ.js} +1 -1
  22. package/dist/gateway/static/root/assets/{dependency-picker-D-6oO_Vk.js → dependency-picker-B2o9unBk.js} +1 -1
  23. package/dist/gateway/static/root/assets/{desktop-pet-CiI5caKj.js → desktop-pet-BH4Np-ay.js} +1 -1
  24. package/dist/gateway/static/root/assets/{desktop-pet-settings-DhkSOy4K.js → desktop-pet-settings-Duu3ctxD.js} +1 -1
  25. package/dist/gateway/static/root/assets/{directory-picker-path-field-C4s4Pz8I.js → directory-picker-path-field-BBCUZOg2.js} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-debug-page-DE7J1-6W.js → extension-debug-page-DS_o3F97.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-page-DSnACD7E.js → extension-page-BTLBZdCq.js} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-settings-page-Dk7k2Pok.js → extension-settings-page-KTGrYbgk.js} +1 -1
  29. package/dist/gateway/static/root/assets/{gateway-config-api-IOA1OlHx.js → gateway-config-api-D3YJVfzY.js} +1 -1
  30. package/dist/gateway/static/root/assets/{gateway-settings-FX7QsgSQ.js → gateway-settings-B8--s3yC.js} +1 -1
  31. package/dist/gateway/static/root/assets/heartbeat-settings-5YQ5BUwp.js +1 -0
  32. package/dist/gateway/static/root/assets/home-page-DfIVWJl3.js +1 -0
  33. package/dist/gateway/static/root/assets/{index-Dcj5KJRg.css → index-BXGC3VFm.css} +1 -1
  34. package/dist/gateway/static/root/assets/{index-EvA8c7fo.js → index-jqDCfet4.js} +47 -47
  35. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BjYiM4xq.js → keyboard-shortcuts-settings-D-Ib-suu.js} +1 -1
  36. package/dist/gateway/static/root/assets/local-app-workbench-page-CAb0odzu.js +2 -0
  37. package/dist/gateway/static/root/assets/{local-apps-page-7DHvwSgA.js → local-apps-page-Bsy1lvAc.js} +1 -1
  38. package/dist/gateway/static/root/assets/logs-page-CFxKbDZl.js +2 -0
  39. package/dist/gateway/static/root/assets/{management-settings-BSxppo9Z.js → management-settings-D-akydG4.js} +1 -1
  40. package/dist/gateway/static/root/assets/{markdown-split-D4oDjZtl.js → markdown-split-DHH4Cu2i.js} +1 -1
  41. package/dist/gateway/static/root/assets/{media-plugins-BPNTGROA.js → media-plugins-BwHtUXkj.js} +1 -1
  42. package/dist/gateway/static/root/assets/{notes-page-DU5tKPTq.js → notes-page-BxM1p6hz.js} +1 -1
  43. package/dist/gateway/static/root/assets/notes-workbench-BGjEC89c.js +4 -0
  44. package/dist/gateway/static/root/assets/{product-open-page-CPoQvD6P.js → product-open-page-DrfWH1ir.js} +1 -1
  45. package/dist/gateway/static/root/assets/project-detail-page-Dj9kEQwg.js +1 -0
  46. package/dist/gateway/static/root/assets/{projects-page-CitO1LMc.js → projects-page-CBRy5Ezz.js} +1 -1
  47. package/dist/gateway/static/root/assets/remote-access-hub-DSwz9RBh.js +1 -0
  48. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-xqnWcvIv.js → runtime-tools-settings-panel-DF7syQRd.js} +1 -1
  49. package/dist/gateway/static/root/assets/{schema-form-CuIDPYu6.js → schema-form-BQ_qRIsM.js} +1 -1
  50. package/dist/gateway/static/root/assets/sessions-page-WtattyVX.js +1 -0
  51. package/dist/gateway/static/root/assets/settings-advanced-gate-CNAz_q1F.js +1 -0
  52. package/dist/gateway/static/root/assets/{settings-form-section-DkAv9ncE.js → settings-form-section-BBHGOQHU.js} +1 -1
  53. package/dist/gateway/static/root/assets/{settings-loading-skeleton-BJUQiEKb.js → settings-loading-skeleton-CiwjP2-b.js} +1 -1
  54. package/dist/gateway/static/root/assets/{settings-page-KHRbLwmw.js → settings-page-Rl9waapk.js} +1 -1
  55. package/dist/gateway/static/root/assets/setup-status-panel-CNo4Ajhn.js +1 -0
  56. package/dist/gateway/static/root/assets/{share-preview-page-WCVtJ3sX.js → share-preview-page-B7PI3yZ6.js} +1 -1
  57. package/dist/gateway/static/root/assets/shares-settings-DpOH0zWB.js +1 -0
  58. package/dist/gateway/static/root/assets/{skill-reload-api-C_4cG30x.js → skill-reload-api-BOf4xCat.js} +1 -1
  59. package/dist/gateway/static/root/assets/{skills-page-CKhR9J81.js → skills-page-YbtR_zEU.js} +1 -1
  60. package/dist/gateway/static/root/assets/{skills-page.utils-AYX-e5sD.js → skills-page.utils-DTmx2Zza.js} +1 -1
  61. package/dist/gateway/static/root/assets/{system-settings-panel-IIF-K9ML.js → system-settings-panel-BZDJcKdS.js} +1 -1
  62. package/dist/gateway/static/root/assets/task-detail-page-DrMX5Yhj.js +1 -0
  63. package/dist/gateway/static/root/assets/{use-autosave-DcktF1j1.js → use-autosave-Be9aR9qA.js} +1 -1
  64. package/dist/gateway/static/root/assets/user-context-page-ewIK2ddC.js +1 -0
  65. package/dist/gateway/static/root/assets/{voice-api-key-field-BMkNTHHE.js → voice-api-key-field-IMc3Ua6C.js} +1 -1
  66. package/dist/gateway/static/root/assets/{work-discovery-overlay-DVoiXekA.js → work-discovery-overlay-TC-xQenr.js} +1 -1
  67. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-Cw4LQjuM.js → workflow-run-setup-panel-B2auxcRv.js} +2 -2
  68. package/dist/gateway/static/root/assets/workflows-page-Bdn82kFQ.js +5 -0
  69. package/dist/gateway/static/root/index.html +2 -2
  70. package/dist/package.js +1 -1
  71. package/dist/src/agent/agent-manager.js +4 -4
  72. package/dist/src/agent/embedded/model-runtime.js +1 -1
  73. package/dist/src/agent/embedded/run-for-session.js +1 -1
  74. package/dist/src/agent/image/tool-model-config.js +1 -1
  75. package/dist/src/agent/ipc/inbox.js +1 -1
  76. package/dist/src/agent/memory/create-memory-manager.js +1 -1
  77. package/dist/src/agent/service.js +2 -2
  78. package/dist/src/agent/session/session-inspector.js +1 -1
  79. package/dist/src/agent/skills/hub-lock.js +1 -1
  80. package/dist/src/agent/tasks/task-judge-service.js +3 -3
  81. package/dist/src/agent-runtime/index.js +1 -1
  82. package/dist/src/agent-runtime/runtime-profile.js +1 -1
  83. package/dist/src/ai-assist/text-assist.js +1 -1
  84. package/dist/src/auth/credentials.js +2 -2
  85. package/dist/src/auth/profiles/store.js +1 -1
  86. package/dist/src/auth/sync-provider-auth.js +2 -2
  87. package/dist/src/browser/providers/browser-ext-install.js +1 -1
  88. package/dist/src/channels/attachments/voice-stt-webchat.js +20 -3
  89. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  90. package/dist/src/cli/commands/models.js +1 -1
  91. package/dist/src/config/agent-profile.js +1 -1
  92. package/dist/src/config/index.js +4 -4
  93. package/dist/src/config/loader.js +1 -1
  94. package/dist/src/config/models-json.js +1 -1
  95. package/dist/src/connectors/learning-coordinator.js +3 -19
  96. package/dist/src/extensions/lockfile.js +1 -1
  97. package/dist/src/gateway/agents-admin.js +2 -2
  98. package/dist/src/gateway/file-path-classifier.js +1 -1
  99. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  100. package/dist/src/gateway/hono/routes/models.js +1 -1
  101. package/dist/src/gateway/hono/routes/voice.js +8 -1
  102. package/dist/src/gateway/hono/routes/workflows.js +2 -2
  103. package/dist/src/gateway/service/config-coordinator.js +1 -1
  104. package/dist/src/gateway/service.js +9 -9
  105. package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
  106. package/dist/src/providers/index.js +2 -2
  107. package/dist/src/providers/model-registry.js +1 -1
  108. package/dist/src/providers/register-runtime-providers.js +1 -1
  109. package/dist/src/tui/tui-startup-resources.js +1 -1
  110. package/dist/src/tui/tui.js +1 -1
  111. package/dist/src/voice/audio/normalize.d.ts +7 -0
  112. package/dist/src/voice/audio/normalize.js +30 -4
  113. package/dist/src/voice/local/runtime-worker.js +26 -6
  114. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  115. package/package.json +7 -13
  116. package/dist/gateway/static/root/assets/agents-Brs2-m6t.js +0 -68
  117. package/dist/gateway/static/root/assets/automations-workspace-DehLRXfd.js +0 -6
  118. package/dist/gateway/static/root/assets/browser-settings-page-C3QIO4Ti.js +0 -8
  119. package/dist/gateway/static/root/assets/capabilities-settings-panel-BHhUp7FW.js +0 -7
  120. package/dist/gateway/static/root/assets/capability-presets-settings-panel-DoClNVLz.js +0 -3
  121. package/dist/gateway/static/root/assets/connectors-page-D8z9Trw4.js +0 -2
  122. package/dist/gateway/static/root/assets/heartbeat-settings-D5CGVyci.js +0 -1
  123. package/dist/gateway/static/root/assets/home-page-DzfZFZx5.js +0 -1
  124. package/dist/gateway/static/root/assets/local-app-workbench-page-hPyTaVYU.js +0 -2
  125. package/dist/gateway/static/root/assets/logs-page-DW0xMKWP.js +0 -2
  126. package/dist/gateway/static/root/assets/notes-workbench-D669d98r.js +0 -4
  127. package/dist/gateway/static/root/assets/project-detail-page-CpsQ9PTA.js +0 -1
  128. package/dist/gateway/static/root/assets/remote-access-hub-C9-bL4V6.js +0 -1
  129. package/dist/gateway/static/root/assets/sessions-page-CPSARi4y.js +0 -1
  130. package/dist/gateway/static/root/assets/settings-advanced-gate-BxT80Fmr.js +0 -1
  131. package/dist/gateway/static/root/assets/setup-status-panel-C8jd20Db.js +0 -1
  132. package/dist/gateway/static/root/assets/shares-settings-DrQ_cOXh.js +0 -1
  133. package/dist/gateway/static/root/assets/task-detail-page-CYjsecEr.js +0 -1
  134. package/dist/gateway/static/root/assets/user-context-page-Cy1D2hkt.js +0 -1
  135. package/dist/gateway/static/root/assets/workflows-page-DKKH1_Yt.js +0 -5
@@ -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{d as i,l as a}from"./chunk-KS7C4IRE-BaASWQor.js";import{i as o,t as s}from"./popover-select-BzdnTy3h.js";import{t as c}from"./circle-check-C23XjkUj.js";import{t as l}from"./external-link-DjqjBmc3.js";import{t as u}from"./loader-circle-CifKLtgG.js";import{t as d}from"./x-B_N4OPjy.js";import{t as f}from"./cn-JdwAhgNB.js";import{t as p}from"./button-CSEbl4zT.js";import{t as m}from"./interaction-BmQogeqz.js";import{t as h}from"./messages-kx5W39dO.js";import{l as g,n as _,o as v,r as y,s as b}from"./locale-store-iKjqemWG.js";import{i as x,o as S}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as C,i as w,n as T,o as E,r as D,s as O,t as k}from"./dist-BPoKqzeH.js";import{i as A}from"./vendor-swr-BIWyz7Rc.js";import{Dr as j,El as M,Er as N,Hs as P,Ja as F,Ks as I,Ni as L,Rs as R,Tr as z,Xa as B,Ya as V,hs as ee,ma as te,or as ne,uo as re,ws as ie}from"./index-EvA8c7fo.js";import{n as ae,r as oe}from"./settings-page-layout-BRQNel6r.js";import{n as se}from"./settings-loading-skeleton-BJUQiEKb.js";import{t as ce}from"./schema-form-CuIDPYu6.js";import{t as le}from"./browser-BLJWD7WI.js";import{n as ue,t as de}from"./channels-status-swr-ByRbxC6z.js";var H=e(t(),1),U=n();function fe(e){let t=e.actions??{};for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n?.result===`qr`)return[e,n]}let n=Object.entries(t).find(([,e])=>e.result===`qr`);if(n)return n;let r=e.ui?.card?.primaryAction;if(r&&t[r])return[r,t[r]];for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n)return[e,n]}return Object.entries(t).find(([,e])=>e.result===`form`)??null}var pe=e(le(),1),W=r();async function me(e){let t=await v(y(`/api/channels/${encodeURIComponent(e.channelId)}/actions/${encodeURIComponent(e.actionId)}?locale=${encodeURIComponent(e.locale)}`),{method:`POST`,body:JSON.stringify({...e.accountId?{accountId:e.accountId}:{},...e.input===void 0?{}:{input:e.input}})}),n=await t.json().catch(()=>({}));if(!t.ok||n.ok===!1)throw Error(n.error?.message??t.statusText);return n.payload??{type:`ok`}}function G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function J(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function he({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,H.useMemo)(()=>fe(e),[e]),o=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[s,d]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{d({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let m=(0,H.useCallback)(async(n,i)=>{d(e=>({...e,busy:!0,error:null}));try{let a=await me({channelId:e.id,actionId:n,locale:t,input:i});d(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){d(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=q(s.payload,e.id);if(!t){d(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return d(e=>e.generatedQr?{...e,generatedQr:null}:e),pe.toDataURL(t,{width:220,margin:1}).then(e=>{n||d(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,s.payload]),(0,H.useEffect)(()=>{let n=s.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||me({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(d(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||d(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,s.poll]);let h=a?.[1].label??(e.configured?n.reconnect:n.connect),g=e.actions?.[`doctor.run`]?.label??n.diagnose,_=K(s.payload),v=q(s.payload,e.id),y=v?s.generatedQr:J(s.payload),b=a?.[1].result===`qr`&&(s.busy||s.payload?.type===`qr`||s.payload?.type===`poll`),x=s.payload?.type===`form`?s.payload:null,S=s.payload?.type===`diagnostics`?s.payload.checks:null;return(0,W.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:f(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,W.jsxs)(p,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void m(a[0]),children:[s.busy?(0,W.jsx)(u,{className:`size-4 animate-spin`}):(0,W.jsx)(I,{className:`size-4`}),h]}):null,e.actions?.[`doctor.run`]?(0,W.jsxs)(p,{type:`button`,variant:`secondary`,disabled:s.busy,onClick:()=>void m(`doctor.run`),children:[(0,W.jsx)(ie,{className:`size-4`}),g]}):null]})]}),_?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:_}):null,s.error?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:s.error}):null,b?(0,W.jsxs)(`div`,{className:f(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base p-3 shadow-surface`,i?`mt-1 flex-col text-center sm:h-64 sm:flex-row sm:text-left`:`mt-4 flex-col sm:h-64 sm:flex-row`),children:[(0,W.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:y?(0,W.jsx)(`img`,{src:y,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,W.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,W.jsx)(V,{className:`size-48 rounded-md`})})}),(0,W.jsxs)(`div`,{className:f(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[y?(0,W.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,W.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,W.jsx)(V,{className:`h-4 w-48 max-w-full`}),(0,W.jsx)(V,{className:`h-4 w-36 max-w-full`})]}),v?(0,W.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:v,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,W.jsx)(l,{className:`size-3.5`})]}):null]})]}):null,s.payload?.type===`poll`&&s.payload.phase===`done`?(0,W.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg bg-surface-base px-3 py-2 text-sm shadow-surface`,children:[(0,W.jsx)(c,{className:s.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,W.jsx)(`span`,{className:s.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:s.payload.message??(s.payload.ok?n.complete:n.failed)})]}):null,x?(0,W.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,W.jsx)(ce,{schema:x.schema,values:s.formDraft,onChange:e=>d(t=>({...t,formDraft:e})),disabled:s.busy,labels:o}),(0,W.jsx)(p,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void m(x.submitAction,s.formDraft),children:n.saveSetup})]}):null,S?(0,W.jsx)(`div`,{className:`mt-4 space-y-2`,children:S.map((e,t)=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e.status??`unknown`})]}),e.message?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ge=40;function Y(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function _e(e,t){return e.find(e=>e.id===Y(t))?.agentId?.trim().toLowerCase()??``}function ve(e,t,n){let r=Y(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:ge,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function ye(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function be(e,t,n){let r=ye(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function xe(e,t=!1){return e===`drawer`?f(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,x):f(`fixed left-1/2 top-1/2 flex h-[min(calc(100dvh-2rem),52rem)] w-[min(calc(100%-2rem),32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,t&&`h-[min(calc(100dvh-2rem),48rem)] w-[min(calc(100%-2rem),36rem)]`,x,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Se(e){let t=(0,U.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:h,footer:g,wide:_,headerExtra:v}=e,y=_===void 0?!1:_,b=n===`drawer`,[x,A]=(0,H.useState)(null),j;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,W.jsx)(C,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,S)}),t[0]=j):j=t[0];let M;t[1]!==n||t[2]!==y?(M=xe(n,y),t[1]=n,t[2]=y,t[3]=M):M=t[3];let N;t[4]===c?N=t[5]:(N=c?(0,W.jsx)(O,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=N);let P;t[6]===l?P=t[7]:(P=l?(0,W.jsx)(w,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=P);let F;t[8]!==u||t[9]!==s||t[10]!==v||t[11]!==b||t[12]!==a?(F=b?(0,W.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,W.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,W.jsx)(T,{asChild:!0,children:(0,W.jsx)(p,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,W.jsx)(d,{className:`size-5`,strokeWidth:1.75})})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(T,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:f(m,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,W.jsx)(d,{className:`size-4`})})}),v]}),t[8]=u,t[9]=s,t[10]=v,t[11]=b,t[12]=a,t[13]=F):F=t[13];let I=b?`p-4`:`p-6`,L;t[14]===I?L=t[15]:(L=f(`min-h-0 flex-1 overflow-y-auto`,I),t[14]=I,t[15]=L);let R;t[16]!==h||t[17]!==L?(R=(0,W.jsx)(`div`,{className:L,children:h}),t[16]=h,t[17]=L,t[18]=R):R=t[18];let z;t[19]!==g||t[20]!==x||t[21]!==N||t[22]!==P||t[23]!==F||t[24]!==R?(z=(0,W.jsxs)(o,{layer:`modal`,portalContainer:x,children:[N,P,F,R,g]}),t[19]=g,t[20]=x,t[21]=N,t[22]=P,t[23]=F,t[24]=R,t[25]=z):z=t[25];let B;t[26]!==z||t[27]!==M?(B=(0,W.jsxs)(E,{children:[j,(0,W.jsx)(D,{ref:A,className:M,onOpenAutoFocus:Ce,children:z})]}),t[26]=z,t[27]=M,t[28]=B):B=t[28];let V;return t[29]!==i||t[30]!==r||t[31]!==B?(V=(0,W.jsx)(k,{open:r,onOpenChange:i,children:B}),t[29]=i,t[30]=r,t[31]=B,t[32]=V):V=t[32],V}function Ce(e){return e.preventDefault()}var we=(0,H.memo)(function(e){let t=(0,U.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,W.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,t[0]=n.saved,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==n.refresh||t[4]!==a||t[5]!==r?(s=(0,W.jsx)(te,{className:`size-9 shrink-0 p-0`,loading:r,label:n.refresh,onClick:a}),t[3]=n.refresh,t[4]=a,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==o||t[8]!==s?(c=(0,W.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-end gap-2`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c});function Te(e){let t=(0,U.c)(24),{ch:n,dirty:r,saving:i,onCancel:a,onDiscard:o,onSave:s,showCancel:c}=e,l=c===void 0?!0:c,u;t[0]!==n.unsavedHint||t[1]!==r?(u=r?(0,W.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,t[0]=n.unsavedHint,t[1]=r,t[2]=u):u=t[2];let d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,W.jsx)(p,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,m;t[7]!==n.discard||t[8]!==o||t[9]!==f?(m=(0,W.jsx)(p,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=m):m=t[10];let h=!r||i,g;t[11]===s?g=t[12]:(g=()=>void s(),t[11]=s,t[12]=g);let _=i?n.saving:n.save,v;t[13]!==h||t[14]!==g||t[15]!==_?(v=(0,W.jsx)(p,{type:`button`,variant:`primary`,disabled:h,onClick:g,children:_}),t[13]=h,t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==d||t[18]!==m||t[19]!==v?(y=(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,m,v]}),t[17]=d,t[18]=m,t[19]=v,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==u?(b=(0,W.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,y]}),t[21]=y,t[22]=u,t[23]=b):b=t[23],b}function Ee(e){return y(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function De(e){return(await b(Ee(e))).payload?.channels??[]}function Oe(e,t){let n=(0,U.c)(14),r;n[0]!==e||n[1]!==t?(r=e?Ee(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>De(t),n[3]=t,n[4]=i);let a;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(a={revalidateOnFocus:!1},n[5]=a):a=n[5];let{data:o,error:s,isLoading:c,isValidating:l,mutate:u}=A(r,i,a),d;n[6]===o?d=n[7]:(d=o??[],n[6]=o,n[7]=d);let f;return n[8]!==s||n[9]!==c||n[10]!==l||n[11]!==u||n[12]!==d?(f={entries:d,isLoading:c,isValidating:l,error:s,mutate:u},n[8]=s,n[9]=c,n[10]=l,n[11]=u,n[12]=d,n[13]=f):f=n[13],f}var ke=`channels-status`;function Ae(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function je(e){let t=t=>e(t.detail);return window.addEventListener(ke,t),()=>window.removeEventListener(ke,t)}function Me(e,t){let n=(0,U.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return je(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Ne(e){return e?y(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Pe(e){return(await b(y(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Fe=[`enabled`];async function Ie(){let e=await b(y(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Le(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Re(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function ze(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Be(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Ve(e){return e===`running`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:e===`stopped`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`checking`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:e===`disabled`?`bg-surface-hover text-fg-muted`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`}function He(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Fe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Fe.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ue(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Ue(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Ue(r[n]),properties:{}}),e===t.length-1){o[n]=Ue(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Ue(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Q(e,t,n){return t==null||t===``?null:e.toLowerCase().includes(`dmpolicy`)&&typeof t==`string`?`${n.dmPolicy}: ${n.policy.dm[t]??t}`:(e.toLowerCase().includes(`stream`)||e.toLowerCase().includes(`streaming`))&&typeof t==`string`?`${n.cardStream}: ${n.policy.stream[t]??t}`:typeof t==`boolean`?t?n.enabledLabel:n.disabledLabel:String(t)}function Xe(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(et(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Q(e,Je(t,e),n);i&&r.push(i)}let a=Ye(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Ze(e,t){let n=X(e),r=fe(e);return n.state===`needs_setup`?r?.[1].label??t.completeSetup:!n.enabled&&n.ready?t.enableChannel:n.state===`error`?t.diagnose:n.ready?t.manageChannel:r?.[1].label??t.startConfiguration}function Qe(e,t){let n=fe(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function $e(e,t){let n=e.capabilities??{},r=[];return n.login===!0&&r.push(t.cardCapabilityLogin),n.pairing===!0&&r.push(t.cardCapabilityPairing),n.multiAccount===!0&&r.push(t.cardCapabilityMultiAccount),n.streaming===!0&&r.push(t.cardCapabilityStreaming),n.media===!0&&r.push(t.cardCapabilityMedia),n.doctor===!0&&r.push(t.cardCapabilityDoctor),r.slice(0,3)}function et(e,t){return e.code===`telegram.missing_credential`?t.setupIssueTelegramMissingCredential:e.code===`weixin.missing_account`?t.setupIssueWeixinMissingAccount:e.code===`feishu.missing_credentials`?t.setupIssueFeishuMissingCredentials:e.code===`config.missing_required`&&e.fieldPath?t.setupIssueMissingRequired.replace(`{{field}}`,e.fieldPath):e.message}function tt({entry:e}){let t=g(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(y(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Le(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,W.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,W.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,W.jsx)(B,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,U.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,o;t[0]===i?o=t[1]:(o=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=o);let s=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,c=r&&`cursor-not-allowed opacity-60`,l;t[2]!==s||t[3]!==c?(l=f(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,s,c),t[2]=s,t[3]=c,t[4]=l):l=t[4];let u=n?`translate-x-5`:`translate-x-0.5`,d;t[5]===u?d=t[6]:(d=f(`size-5 rounded-full bg-white shadow-surface transition-transform`,u),t[5]=u,t[6]=d);let p;t[7]===d?p=t[8]:(p=(0,W.jsx)(`span`,{className:d}),t[7]=d,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==o||t[13]!==l||t[14]!==p?(m=(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:o,className:l,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=o,t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,U.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:s,onOpen:c,onToggle:l,onRestart:d}=e,m;t[0]===n?m=t[1]:(m=X(n),t[0]=n,t[1]=m);let h=m,g,_,v,y,b,x,S;if(t[2]!==a||t[3]!==s||t[4]!==r||t[5]!==n||t[6]!==c||t[7]!==d||t[8]!==l||t[9]!==i||t[10]!==h.enabled||t[11]!==h.ready){let e=Xe(n,r,s),o=$e(n,s);g=!h.enabled&&h.ready?l:i===`stopped`?d:c,x=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let u;t[19]===n?u=t[20]:(u=(0,W.jsx)(tt,{entry:n}),t[19]=n,t[20]=u);let p;t[21]===n.label?p=t[22]:(p=(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=p);let m;t[23]===i?m=t[24]:(m=f(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Ve(i)),t[23]=i,t[24]=m);let C;t[25]!==s||t[26]!==i?(C=ze(i,s),t[25]=s,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==m||t[29]!==C?(w=(0,W.jsx)(`span`,{className:m,children:C}),t[28]=m,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==p?(T=(0,W.jsxs)(`div`,{className:`min-w-0`,children:[p,w]}),t[31]=w,t[32]=p,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==u?(E=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[u,T]}),t[34]=T,t[35]=u,t[36]=E):E=t[36];let D=h.enabled,O;t[37]!==s.toggleChannel||t[38]!==n.label?(O=s.toggleChannel.replace(`{{channel}}`,n.label),t[37]=s.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==l||t[42]!==h.enabled||t[43]!==O?(k=(0,W.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:l}),t[40]=a,t[41]=l,t[42]=h.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(S=(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=S):S=t[47],_=`button`,v=c,y=`mt-5 min-h-[6.25rem] text-left`,b=h.ready?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,W.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:s.cardSetupTitle}),(0,W.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,s)}),o.length>0?(0,W.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:o.map(it)}):null]}),t[2]=a,t[3]=s,t[4]=r,t[5]=n,t[6]=c,t[7]=d,t[8]=l,t[9]=i,t[10]=h.enabled,t[11]=h.ready,t[12]=g,t[13]=_,t[14]=v,t[15]=y,t[16]=b,t[17]=x,t[18]=S}else g=t[12],_=t[13],v=t[14],y=t[15],b=t[16],x=t[17],S=t[18];let C;t[48]!==_||t[49]!==v||t[50]!==y||t[51]!==b?(C=(0,W.jsx)(`button`,{type:_,onClick:v,className:y,children:b}),t[48]=_,t[49]=v,t[50]=y,t[51]=b,t[52]=C):C=t[52];let w=a||o,T;t[53]!==a||t[54]!==o?(T=a||o?(0,W.jsx)(u,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=o,t[55]=T):T=t[55];let E;t[56]!==s||t[57]!==n||t[58]!==o||t[59]!==i?(E=o?s.restartingChannel:i===`stopped`?s.restartChannel:Ze(n,s),t[56]=s,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==g||t[62]!==T||t[63]!==E||t[64]!==w?(D=(0,W.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,W.jsxs)(p,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:g,disabled:w,children:[T,E]})}),t[61]=g,t[62]=T,t[63]=E,t[64]=w,t[65]=D):D=t[65];let O;return t[66]!==D||t[67]!==x||t[68]!==S||t[69]!==C?(O=(0,W.jsxs)(`article`,{className:x,children:[S,C,D]}),t[66]=D,t[67]=x,t[68]=S,t[69]=C,t[70]=O):O=t[70],O}function it(e){return(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function $(e){return(0,W.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,U.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:o,ch:s,onRestart:l,onCheck:d,onManageConnection:m}=e,h=n===`running`?c:n===`stopped`||n===`needs_setup`?M:u,g=n===`running`&&`text-emerald-600 dark:text-emerald-400`,_=n===`stopped`&&`text-red-600 dark:text-red-400`,v=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,y=n===`disabled`&&`text-fg-muted`,b=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,x;t[0]!==g||t[1]!==_||t[2]!==v||t[3]!==y||t[4]!==b?(x=f(`mt-0.5 size-5 shrink-0`,g,_,v,y,b),t[0]=g,t[1]=_,t[2]=v,t[3]=y,t[4]=b,t[5]=x):x=t[5];let S;t[6]!==h||t[7]!==x?(S=(0,W.jsx)(h,{className:x}),t[6]=h,t[7]=x,t[8]=S):S=t[8];let C;t[9]===s.connectionStatus?C=t[10]:(C=(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:s.connectionStatus}),t[9]=s.connectionStatus,t[10]=C);let w;t[11]!==s||t[12]!==n?(w=Be(n,s),t[11]=s,t[12]=n,t[13]=w):w=t[13];let T;t[14]===w?T=t[15]:(T=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[14]=w,t[15]=T);let E;t[16]!==T||t[17]!==C?(E=(0,W.jsxs)(`div`,{children:[C,T]}),t[16]=T,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==S?(D=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[S,E]}),t[19]=E,t[20]=S,t[21]=D):D=t[21];let O=i||r,k;t[22]===i?k=t[23]:(k=i?(0,W.jsx)(u,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=k);let A=i?s.checkingConnection:s.checkConnection,j;t[24]!==d||t[25]!==O||t[26]!==k||t[27]!==A?(j=(0,W.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:O,onClick:d,children:[k,A]}),t[24]=d,t[25]=O,t[26]=k,t[27]=A,t[28]=j):j=t[28];let N;t[29]!==s.restartChannel||t[30]!==s.restartingChannel||t[31]!==i||t[32]!==l||t[33]!==r||t[34]!==n?(N=n===`stopped`?(0,W.jsxs)(p,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:l,children:[r?(0,W.jsx)(u,{className:`size-4 animate-spin`}):(0,W.jsx)(P,{className:`size-4`}),r?s.restartingChannel:s.restartChannel]}):null,t[29]=s.restartChannel,t[30]=s.restartingChannel,t[31]=i,t[32]=l,t[33]=r,t[34]=n,t[35]=N):N=t[35];let F;t[36]!==o||t[37]!==s.connectionOptions||t[38]!==s.hideConnectionOptions||t[39]!==i||t[40]!==m||t[41]!==r||t[42]!==a?(F=o?(0,W.jsx)(p,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:m,children:a?s.hideConnectionOptions:s.connectionOptions}):null,t[36]=o,t[37]=s.connectionOptions,t[38]=s.hideConnectionOptions,t[39]=i,t[40]=m,t[41]=r,t[42]=a,t[43]=F):F=t[43];let I;t[44]!==j||t[45]!==N||t[46]!==F?(I=(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[j,N,F]}),t[44]=j,t[45]=N,t[46]=F,t[47]=I):I=t[47];let L;return t[48]!==D||t[49]!==I?(L=(0,W.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[D,I]})}),t[48]=D,t[49]=I,t[50]=L):L=t[50],L}function ot(e){let t=(0,U.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,W.jsx)(ee,{className:`mt-0.5 size-4 shrink-0`}),t[11]=u):u=t[11],o=`min-w-0`,t[12]===r.setupReadinessTitle?s=t[13]:(s=(0,W.jsx)(`h3`,{className:`text-sm font-semibold`,children:r.setupReadinessTitle}),t[12]=r.setupReadinessTitle,t[13]=s);let p=e.enabled?r.setupReadinessEnabledBody:r.setupReadinessDisabledBody;t[14]===p?c=t[15]:(c=(0,W.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-amber-900 dark:text-amber-200`,children:p}),t[14]=p,t[15]=c),i=`mt-2 list-disc space-y-1 pl-5 text-sm text-amber-900 dark:text-amber-200`;let m;t[16]===r?m=t[17]:(m=e=>(0,W.jsx)(`li`,{children:et(e,r)},`${e.code}:${e.fieldPath??``}`),t[16]=r,t[17]=m),a=e.issues.map(m)}t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;t[18]!==i||t[19]!==a?(p=(0,W.jsx)(`ul`,{className:i,children:a}),t[18]=i,t[19]=a,t[20]=p):p=t[20];let m;t[21]!==p||t[22]!==o||t[23]!==s||t[24]!==c?(m=(0,W.jsxs)(`div`,{className:o,children:[s,c,p]}),t[21]=p,t[22]=o,t[23]=s,t[24]=c,t[25]=m):m=t[25];let h;t[26]!==m||t[27]!==l||t[28]!==u?(h=(0,W.jsxs)(`div`,{className:l,children:[u,m]}),t[26]=m,t[27]=l,t[28]=u,t[29]=h):h=t[29];let g;return t[30]!==h||t[31]!==d?(g=(0,W.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function st(){let e=_(e=>e.language),t=h(e),n=g(e=>!!e.token),r=a(),{channelId:o}=i(),c=j(o),u=Oe(n,e),d=u.entries,{data:p,mutate:m,isValidating:b}=A(n?de():null,ue,{revalidateOnFocus:!0}),{data:x,mutate:S}=A(n?`channels-config-map`:null,Ie,{revalidateOnFocus:!1}),C=x?.channels??{},w=x?.bindings??[],{data:T}=A(n?`channel-routing-agents`:null,F,{revalidateOnFocus:!1}),E=re(e=>e.setPageHeader),D=re(e=>e.clearPageHeader),O=(0,H.useMemo)(()=>d.find(e=>e.id===c),[c,d]),k=O?Re(O):null,{data:M,mutate:P}=A(n&&k?Ne(k):null,()=>Pe(k)),[I,B]=(0,H.useState)(null),[V,ee]=(0,H.useState)(!1),[te,ie]=(0,H.useState)(null),[le,U]=(0,H.useState)(null),[pe,me]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[q,J]=(0,H.useState)(null),ge=I??M??{},Y=t.channelsSettings,ye=(0,H.useMemo)(()=>O?.configSchema??{type:`object`,properties:{}},[O?.configSchema]),xe=(0,H.useMemo)(()=>Ke(ye,Fe),[ye]),Ce=(0,H.useMemo)(()=>He(O),[O]),Ee=(0,H.useMemo)(()=>We(xe,Ce),[Ce,xe]),De=(0,H.useMemo)(()=>Ke(xe,Ce),[Ce,xe]),ke=(0,H.useMemo)(()=>qe(Ee),[Ee]),je=O?q??_e(w,O.id):``,Le=(0,H.useMemo)(()=>(T?.items??[]).map(e=>{let n=ne(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[T?.items,t.agentsSettings]),Be=T?.items.find(e=>e.id===T.defaultId),Z=Be?ne(Be,t.agentsSettings):T?.defaultId??``,Ue=(0,H.useMemo)(()=>({defaultBooleanLabel:Y.schemaBooleanDefault,unsupportedArrayType:Y.schemaUnsupportedArrayType,arrayAddPlaceholder:Y.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>Y.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[Y]),Ge=(0,H.useMemo)(()=>new Map((p??[]).map(e=>[e.name,e])),[p]),Je=p!==void 0,Ye=(0,H.useCallback)(e=>be(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([u.mutate(),m()])},[u,m]);Me((0,H.useCallback)(e=>{let t=Ae(e);t&&m(t,!1)},[m]),n);let Xe=(0,H.useMemo)(()=>n?(0,W.jsx)(we,{ch:Y,refreshing:u.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[u.isValidating,Y,n,b,Q]);(0,H.useLayoutEffect)(()=>(E({startExtra:null,main:(0,W.jsx)(`div`,{className:`min-w-0`,children:(0,W.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>D()),[D,Xe,t.settingsSections.channels,E]);let Ze=(0,H.useCallback)(e=>{r(N(e)),B(null),J(null),K(null)},[r]),Qe=(0,H.useCallback)(()=>{r(z),B(null),J(null),K(null)},[r]),$e=(0,H.useCallback)(async e=>{U(e.id),K(null);try{let t=await v(y(`/api/channels/${encodeURIComponent(e.id)}/restart`),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}await Q()}catch(e){K(e instanceof Error?e.message:String(e))}finally{U(null)}},[Q]);(0,H.useEffect)(()=>{J(null),me(!1)},[O?.id]);let et=(0,H.useCallback)(async()=>{if(!O||!I&&q===null)return!1;let e=Re(O);ee(!0),K(null);try{let t=await v(y(`/api/config`),{method:`PATCH`,body:JSON.stringify({...I?{channels:{[e]:I}}:{},...q===null?{}:{bindings:ve(w,O.id,q)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return I&&await P(I,!1),await S(),await u.mutate(),B(null),J(null),!0}catch(e){return K(e instanceof Error?e.message:String(e)),!1}finally{ee(!1)}},[O,q,w,u,I,S,P]),it=(0,H.useCallback)(async e=>{let t=X(e),n=Re(e),r=O?.id===e.id?I:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ie(e.id),K(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await v(y(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[n]:i}})});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??a.statusText)}await u.mutate(),await S(),await m(),O?.id===e.id&&(await P(),B(null))}catch(e){K(e instanceof Error?e.message:String(e))}finally{ie(null)}},[O?.id,u,I,S,P,m,Ze]),$=O?.ui?.modal,st=$?.placement!==`replace-config`,ct=O?Ye(O):`checking`,lt=O?!X(O).ready||pe:!1;return n?(0,W.jsxs)(oe,{gap:`gap-4`,children:[u.isLoading?(0,W.jsx)(se,{sections:2}):u.error?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(u.error)}):(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:d.map(e=>(0,W.jsx)(rt,{entry:e,config:C[Re(e)]?.config,runtime:Ye(e),busy:te===e.id,restarting:le===e.id,ch:Y,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),G?(0,W.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:G}):null,(0,W.jsx)(Se,{presentation:`modal`,open:!!O,onOpenChange:e=>{e||Qe()},closeAriaLabel:Y.close,srTitle:O?.label??Y.selectChannel,srDescription:O?.description,wide:!0,footer:O?(0,W.jsx)(Te,{ch:Y,dirty:!!I||q!==null,saving:V,onCancel:Qe,onDiscard:()=>{B(null),J(null)},onSave:et}):null,children:O?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,W.jsx)(tt,{entry:O}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:O.label}),(0,W.jsx)(`span`,{className:f(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Ve(ct)),children:ze(ct,Y)})]}),(0,W.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-fg-muted`,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:!X(O).ready&&fe(O)?.[1].result===`qr`?Y.scanLoginHint.replace(`{{channel}}`,O.label):O.description}),O.docsPath?(0,W.jsxs)(`a`,{href:O.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[Y.docs,(0,W.jsx)(l,{className:`size-3.5`})]}):null]})]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,W.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:X(O).enabled?Y.enabledLabel:Y.disabledLabel}),(0,W.jsx)(nt,{checked:X(O).enabled,disabled:te===O.id,label:Y.toggleChannel.replace(`{{channel}}`,O.label),onToggle:()=>void it(O)})]})]})}),(0,W.jsx)(at,{runtime:ct,restarting:le===O.id,checking:b,showConnectionOptions:pe,canManageConnection:X(O).ready&&$?.placement!==`replace-config`,ch:Y,onRestart:()=>void $e(O),onCheck:()=>void Q(),onManageConnection:()=>me(e=>!e)}),(0,W.jsx)(ot,{entry:O,ch:Y}),lt&&$?.placement!==`replace-config`?(0,W.jsx)(he,{entry:O,locale:e,messages:Y,compact:!0,onChanged:async()=>{await P(),await Q(),await S()}},O.id):null,$?.entrypoint&&$.placement===`before-config`?(0,W.jsx)(L,{extensionId:O.extensionId,extensionName:O.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:O.id,entry:O,config:ge}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,W.jsx)(L,{extensionId:O.extensionId,extensionName:O.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:O.id,entry:O,config:ge}}):null,st&&ke?(0,W.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.basicConfiguration}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.basicConfigurationHint})]}),(0,W.jsx)(ce,{schema:Ee,values:ge,onChange:e=>B(e),disabled:V,labels:Ue})]}):null,(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(R,{className:`size-4 text-fg-muted`}),Y.messageHandling]}),(0,W.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,W.jsxs)(`div`,{className:`mb-3`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.agentRouting}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.messageHandlingHint})]}),(0,W.jsx)(s,{value:je,options:Le,placeholder:Y.agentRoutingSelect,emptyLabel:Y.agentRoutingDefault.replace(`{{agent}}`,Z||Y.agentRoutingSelect),ariaLabel:Y.agentRouting,disabled:V||!T,onChange:e=>J(e)})]})]}),st&&qe(De)?(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(R,{className:`size-4 text-fg-muted`}),Y.advancedConfiguration]}),(0,W.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,W.jsx)(ce,{schema:De,values:ge,onChange:e=>B(e),disabled:V,labels:Ue})})]}):null,G?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:G}):null]}):null})]}):(0,W.jsxs)(oe,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,W.jsx)(ae,{title:t.settingsSections.channels}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:Y.tokenRequired})]})}export{st as ChannelsSettingsPanel};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a}from"./chunk-KS7C4IRE-BaASWQor.js";import{i as o,t as s}from"./popover-select-BzdnTy3h.js";import{t as c}from"./circle-check-C23XjkUj.js";import{t as l}from"./external-link-DjqjBmc3.js";import{t as u}from"./loader-circle-CifKLtgG.js";import{t as d}from"./x-B_N4OPjy.js";import{t as f}from"./cn-JdwAhgNB.js";import{t as p}from"./button-CSEbl4zT.js";import{t as m}from"./interaction-BmQogeqz.js";import{t as h}from"./messages-kx5W39dO.js";import{l as g,n as _,o as v,r as y,s as b}from"./locale-store-iKjqemWG.js";import{i as x,o as S}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as C,i as w,n as T,o as E,r as D,s as O,t as k}from"./dist-BPoKqzeH.js";import{i as A}from"./vendor-swr-BIWyz7Rc.js";import{Dl as j,Dr as M,Er as N,Ja as P,Ni as F,Tr as I,Ts as L,Us as R,Xa as z,Ya as B,gs as V,ma as ee,or as te,qs as ne,uo as re,zs as ie}from"./index-jqDCfet4.js";import{n as ae,r as oe}from"./settings-page-layout-BRQNel6r.js";import{n as se}from"./settings-loading-skeleton-CiwjP2-b.js";import{t as ce}from"./schema-form-BQ_qRIsM.js";import{t as le}from"./browser-BLJWD7WI.js";import{n as ue,t as de}from"./channels-status-swr-ByRbxC6z.js";var H=e(t(),1),U=n();function fe(e){let t=e.actions??{};for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n?.result===`qr`)return[e,n]}let n=Object.entries(t).find(([,e])=>e.result===`qr`);if(n)return n;let r=e.ui?.card?.primaryAction;if(r&&t[r])return[r,t[r]];for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n)return[e,n]}return Object.entries(t).find(([,e])=>e.result===`form`)??null}var pe=e(le(),1),W=r();async function me(e){let t=await v(y(`/api/channels/${encodeURIComponent(e.channelId)}/actions/${encodeURIComponent(e.actionId)}?locale=${encodeURIComponent(e.locale)}`),{method:`POST`,body:JSON.stringify({...e.accountId?{accountId:e.accountId}:{},...e.input===void 0?{}:{input:e.input}})}),n=await t.json().catch(()=>({}));if(!t.ok||n.ok===!1)throw Error(n.error?.message??t.statusText);return n.payload??{type:`ok`}}function G(e){return e?.type===`poll`&&e.phase===`done`}function K(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function q(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function J(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function he({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,H.useMemo)(()=>fe(e),[e]),o=(0,H.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[s,d]=(0,H.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,H.useEffect)(()=>{d({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let m=(0,H.useCallback)(async(n,i)=>{d(e=>({...e,busy:!0,error:null}));try{let a=await me({channelId:e.id,actionId:n,locale:t,input:i});d(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){d(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,H.useEffect)(()=>{let t=q(s.payload,e.id);if(!t){d(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return d(e=>e.generatedQr?{...e,generatedQr:null}:e),pe.toDataURL(t,{width:220,margin:1}).then(e=>{n||d(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,s.payload]),(0,H.useEffect)(()=>{let n=s.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||me({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(d(t=>({...t,payload:e,poll:G(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),G(e)&&window.clearInterval(a))}).catch(e=>{i||d(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,s.poll]);let h=a?.[1].label??(e.configured?n.reconnect:n.connect),g=e.actions?.[`doctor.run`]?.label??n.diagnose,_=K(s.payload),v=q(s.payload,e.id),y=v?s.generatedQr:J(s.payload),b=a?.[1].result===`qr`&&(s.busy||s.payload?.type===`qr`||s.payload?.type===`poll`),x=s.payload?.type===`form`?s.payload:null,S=s.payload?.type===`diagnostics`?s.payload.checks:null;return(0,W.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:f(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,W.jsxs)(p,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void m(a[0]),children:[s.busy?(0,W.jsx)(u,{className:`size-4 animate-spin`}):(0,W.jsx)(ne,{className:`size-4`}),h]}):null,e.actions?.[`doctor.run`]?(0,W.jsxs)(p,{type:`button`,variant:`secondary`,disabled:s.busy,onClick:()=>void m(`doctor.run`),children:[(0,W.jsx)(L,{className:`size-4`}),g]}):null]})]}),_?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:_}):null,s.error?(0,W.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:s.error}):null,b?(0,W.jsxs)(`div`,{className:f(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base p-3 shadow-surface`,i?`mt-1 flex-col text-center sm:h-64 sm:flex-row sm:text-left`:`mt-4 flex-col sm:h-64 sm:flex-row`),children:[(0,W.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:y?(0,W.jsx)(`img`,{src:y,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,W.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,W.jsx)(B,{className:`size-48 rounded-md`})})}),(0,W.jsxs)(`div`,{className:f(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[y?(0,W.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,W.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,W.jsx)(B,{className:`h-4 w-48 max-w-full`}),(0,W.jsx)(B,{className:`h-4 w-36 max-w-full`})]}),v?(0,W.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:v,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,W.jsx)(l,{className:`size-3.5`})]}):null]})]}):null,s.payload?.type===`poll`&&s.payload.phase===`done`?(0,W.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg bg-surface-base px-3 py-2 text-sm shadow-surface`,children:[(0,W.jsx)(c,{className:s.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,W.jsx)(`span`,{className:s.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:s.payload.message??(s.payload.ok?n.complete:n.failed)})]}):null,x?(0,W.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,W.jsx)(ce,{schema:x.schema,values:s.formDraft,onChange:e=>d(t=>({...t,formDraft:e})),disabled:s.busy,labels:o}),(0,W.jsx)(p,{type:`button`,variant:`primary`,disabled:s.busy,onClick:()=>void m(x.submitAction,s.formDraft),children:n.saveSetup})]}):null,S?(0,W.jsx)(`div`,{className:`mt-4 space-y-2`,children:S.map((e,t)=>(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e.status??`unknown`})]}),e.message?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ge=40;function Y(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function _e(e,t){return e.find(e=>e.id===Y(t))?.agentId?.trim().toLowerCase()??``}function ve(e,t,n){let r=Y(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:ge,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function ye(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function be(e,t,n){let r=ye(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function xe(e,t=!1){return e===`drawer`?f(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,x):f(`fixed left-1/2 top-1/2 flex h-[min(calc(100dvh-2rem),52rem)] w-[min(calc(100%-2rem),32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,t&&`h-[min(calc(100dvh-2rem),48rem)] w-[min(calc(100%-2rem),36rem)]`,x,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Se(e){let t=(0,U.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:h,footer:g,wide:_,headerExtra:v}=e,y=_===void 0?!1:_,b=n===`drawer`,[x,A]=(0,H.useState)(null),j;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,W.jsx)(C,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,S)}),t[0]=j):j=t[0];let M;t[1]!==n||t[2]!==y?(M=xe(n,y),t[1]=n,t[2]=y,t[3]=M):M=t[3];let N;t[4]===c?N=t[5]:(N=c?(0,W.jsx)(O,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=N);let P;t[6]===l?P=t[7]:(P=l?(0,W.jsx)(w,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=P);let F;t[8]!==u||t[9]!==s||t[10]!==v||t[11]!==b||t[12]!==a?(F=b?(0,W.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,W.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,s?(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,W.jsx)(T,{asChild:!0,children:(0,W.jsx)(p,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,W.jsx)(d,{className:`size-5`,strokeWidth:1.75})})})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(T,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:f(m,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,W.jsx)(d,{className:`size-4`})})}),v]}),t[8]=u,t[9]=s,t[10]=v,t[11]=b,t[12]=a,t[13]=F):F=t[13];let I=b?`p-4`:`p-6`,L;t[14]===I?L=t[15]:(L=f(`min-h-0 flex-1 overflow-y-auto`,I),t[14]=I,t[15]=L);let R;t[16]!==h||t[17]!==L?(R=(0,W.jsx)(`div`,{className:L,children:h}),t[16]=h,t[17]=L,t[18]=R):R=t[18];let z;t[19]!==g||t[20]!==x||t[21]!==N||t[22]!==P||t[23]!==F||t[24]!==R?(z=(0,W.jsxs)(o,{layer:`modal`,portalContainer:x,children:[N,P,F,R,g]}),t[19]=g,t[20]=x,t[21]=N,t[22]=P,t[23]=F,t[24]=R,t[25]=z):z=t[25];let B;t[26]!==z||t[27]!==M?(B=(0,W.jsxs)(E,{children:[j,(0,W.jsx)(D,{ref:A,className:M,onOpenAutoFocus:Ce,children:z})]}),t[26]=z,t[27]=M,t[28]=B):B=t[28];let V;return t[29]!==i||t[30]!==r||t[31]!==B?(V=(0,W.jsx)(k,{open:r,onOpenChange:i,children:B}),t[29]=i,t[30]=r,t[31]=B,t[32]=V):V=t[32],V}function Ce(e){return e.preventDefault()}var we=(0,H.memo)(function(e){let t=(0,U.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,W.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,t[0]=n.saved,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==n.refresh||t[4]!==a||t[5]!==r?(s=(0,W.jsx)(ee,{className:`size-9 shrink-0 p-0`,loading:r,label:n.refresh,onClick:a}),t[3]=n.refresh,t[4]=a,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==o||t[8]!==s?(c=(0,W.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-end gap-2`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c});function Te(e){let t=(0,U.c)(24),{ch:n,dirty:r,saving:i,onCancel:a,onDiscard:o,onSave:s,showCancel:c}=e,l=c===void 0?!0:c,u;t[0]!==n.unsavedHint||t[1]!==r?(u=r?(0,W.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,t[0]=n.unsavedHint,t[1]=r,t[2]=u):u=t[2];let d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,W.jsx)(p,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,m;t[7]!==n.discard||t[8]!==o||t[9]!==f?(m=(0,W.jsx)(p,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=m):m=t[10];let h=!r||i,g;t[11]===s?g=t[12]:(g=()=>void s(),t[11]=s,t[12]=g);let _=i?n.saving:n.save,v;t[13]!==h||t[14]!==g||t[15]!==_?(v=(0,W.jsx)(p,{type:`button`,variant:`primary`,disabled:h,onClick:g,children:_}),t[13]=h,t[14]=g,t[15]=_,t[16]=v):v=t[16];let y;t[17]!==d||t[18]!==m||t[19]!==v?(y=(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,m,v]}),t[17]=d,t[18]=m,t[19]=v,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==u?(b=(0,W.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,y]}),t[21]=y,t[22]=u,t[23]=b):b=t[23],b}function Ee(e){return y(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function De(e){return(await b(Ee(e))).payload?.channels??[]}function Oe(e,t){let n=(0,U.c)(14),r;n[0]!==e||n[1]!==t?(r=e?Ee(t):null,n[0]=e,n[1]=t,n[2]=r):r=n[2];let i;n[3]===t?i=n[4]:(i=()=>De(t),n[3]=t,n[4]=i);let a;n[5]===Symbol.for(`react.memo_cache_sentinel`)?(a={revalidateOnFocus:!1},n[5]=a):a=n[5];let{data:o,error:s,isLoading:c,isValidating:l,mutate:u}=A(r,i,a),d;n[6]===o?d=n[7]:(d=o??[],n[6]=o,n[7]=d);let f;return n[8]!==s||n[9]!==c||n[10]!==l||n[11]!==u||n[12]!==d?(f={entries:d,isLoading:c,isValidating:l,error:s,mutate:u},n[8]=s,n[9]=c,n[10]=l,n[11]=u,n[12]=d,n[13]=f):f=n[13],f}var ke=`channels-status`;function Ae(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function je(e){let t=t=>e(t.detail);return window.addEventListener(ke,t),()=>window.removeEventListener(ke,t)}function Me(e,t){let n=(0,U.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return je(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,H.useEffect)(i,a)}function Ne(e){return e?y(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Pe(e){return(await b(y(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Fe=[`enabled`];async function Ie(){let e=await b(y(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Le(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Re(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function X(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function ze(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function Be(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Ve(e){return e===`running`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:e===`stopped`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`checking`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:e===`disabled`?`bg-surface-hover text-fg-muted`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`}function He(e){if(!e)return[];let t=e.uiHints??{},n=Z(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=X(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!Z(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Fe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Fe.includes(e))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ue(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function We(e,t){let n={...Ue(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!Z(r)||!Z(r[n]))break;let o=Z(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Ue(r[n]),properties:{}}),e===t.length-1){o[n]=Ue(r[n]);break}i=r[n],a=o[n]}}return n}function Ge(e){let t=e.properties;if(!Z(t))return!1;for(let[e,n]of Object.entries(t))Z(n)&&n.type===`object`&&Ge(n)&&delete t[e];return Object.keys(t).length===0}function Ke(e,t){let n=Ue(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!Z(i))break;if(e===t.length-1){delete i[n];break}if(!Z(i[n]))break;r=i[n]}}return Ge(n),n}function qe(e){return e.type===`object`&&Z(e.properties)&&Object.keys(e.properties).length>0}function Je(e,t){let n=e;for(let e of t.split(`.`)){if(!Z(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return Z(t)?Object.values(t).filter(e=>Z(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Q(e,t,n){return t==null||t===``?null:e.toLowerCase().includes(`dmpolicy`)&&typeof t==`string`?`${n.dmPolicy}: ${n.policy.dm[t]??t}`:(e.toLowerCase().includes(`stream`)||e.toLowerCase().includes(`streaming`))&&typeof t==`string`?`${n.cardStream}: ${n.policy.stream[t]??t}`:typeof t==`boolean`?t?n.enabledLabel:n.disabledLabel:String(t)}function Xe(e,t,n){let r=[],i=X(e);if(i.issues.length>0&&r.push(et(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Q(e,Je(t,e),n);i&&r.push(i)}let a=Ye(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Ze(e,t){let n=X(e),r=fe(e);return n.state===`needs_setup`?r?.[1].label??t.completeSetup:!n.enabled&&n.ready?t.enableChannel:n.state===`error`?t.diagnose:n.ready?t.manageChannel:r?.[1].label??t.startConfiguration}function Qe(e,t){let n=fe(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function $e(e,t){let n=e.capabilities??{},r=[];return n.login===!0&&r.push(t.cardCapabilityLogin),n.pairing===!0&&r.push(t.cardCapabilityPairing),n.multiAccount===!0&&r.push(t.cardCapabilityMultiAccount),n.streaming===!0&&r.push(t.cardCapabilityStreaming),n.media===!0&&r.push(t.cardCapabilityMedia),n.doctor===!0&&r.push(t.cardCapabilityDoctor),r.slice(0,3)}function et(e,t){return e.code===`telegram.missing_credential`?t.setupIssueTelegramMissingCredential:e.code===`weixin.missing_account`?t.setupIssueWeixinMissingAccount:e.code===`feishu.missing_credentials`?t.setupIssueFeishuMissingCredentials:e.code===`config.missing_required`&&e.fieldPath?t.setupIssueMissingRequired.replace(`{{field}}`,e.fieldPath):e.message}function tt({entry:e}){let t=g(e=>e.token),[n,r]=(0,H.useState)(!1),i=(0,H.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(y(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Le(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,W.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,W.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,W.jsx)(z,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,U.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,o;t[0]===i?o=t[1]:(o=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=o);let s=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,c=r&&`cursor-not-allowed opacity-60`,l;t[2]!==s||t[3]!==c?(l=f(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,s,c),t[2]=s,t[3]=c,t[4]=l):l=t[4];let u=n?`translate-x-5`:`translate-x-0.5`,d;t[5]===u?d=t[6]:(d=f(`size-5 rounded-full bg-white shadow-surface transition-transform`,u),t[5]=u,t[6]=d);let p;t[7]===d?p=t[8]:(p=(0,W.jsx)(`span`,{className:d}),t[7]=d,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==o||t[13]!==l||t[14]!==p?(m=(0,W.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:o,className:l,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=o,t[13]=l,t[14]=p,t[15]=m):m=t[15],m}function rt(e){let t=(0,U.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:s,onOpen:c,onToggle:l,onRestart:d}=e,m;t[0]===n?m=t[1]:(m=X(n),t[0]=n,t[1]=m);let h=m,g,_,v,y,b,x,S;if(t[2]!==a||t[3]!==s||t[4]!==r||t[5]!==n||t[6]!==c||t[7]!==d||t[8]!==l||t[9]!==i||t[10]!==h.enabled||t[11]!==h.ready){let e=Xe(n,r,s),o=$e(n,s);g=!h.enabled&&h.ready?l:i===`stopped`?d:c,x=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let u;t[19]===n?u=t[20]:(u=(0,W.jsx)(tt,{entry:n}),t[19]=n,t[20]=u);let p;t[21]===n.label?p=t[22]:(p=(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=p);let m;t[23]===i?m=t[24]:(m=f(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Ve(i)),t[23]=i,t[24]=m);let C;t[25]!==s||t[26]!==i?(C=ze(i,s),t[25]=s,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==m||t[29]!==C?(w=(0,W.jsx)(`span`,{className:m,children:C}),t[28]=m,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==p?(T=(0,W.jsxs)(`div`,{className:`min-w-0`,children:[p,w]}),t[31]=w,t[32]=p,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==u?(E=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[u,T]}),t[34]=T,t[35]=u,t[36]=E):E=t[36];let D=h.enabled,O;t[37]!==s.toggleChannel||t[38]!==n.label?(O=s.toggleChannel.replace(`{{channel}}`,n.label),t[37]=s.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==l||t[42]!==h.enabled||t[43]!==O?(k=(0,W.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:l}),t[40]=a,t[41]=l,t[42]=h.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(S=(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=S):S=t[47],_=`button`,v=c,y=`mt-5 min-h-[6.25rem] text-left`,b=h.ready?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,W.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map($)}):null]}):(0,W.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:s.cardSetupTitle}),(0,W.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Qe(n,s)}),o.length>0?(0,W.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:o.map(it)}):null]}),t[2]=a,t[3]=s,t[4]=r,t[5]=n,t[6]=c,t[7]=d,t[8]=l,t[9]=i,t[10]=h.enabled,t[11]=h.ready,t[12]=g,t[13]=_,t[14]=v,t[15]=y,t[16]=b,t[17]=x,t[18]=S}else g=t[12],_=t[13],v=t[14],y=t[15],b=t[16],x=t[17],S=t[18];let C;t[48]!==_||t[49]!==v||t[50]!==y||t[51]!==b?(C=(0,W.jsx)(`button`,{type:_,onClick:v,className:y,children:b}),t[48]=_,t[49]=v,t[50]=y,t[51]=b,t[52]=C):C=t[52];let w=a||o,T;t[53]!==a||t[54]!==o?(T=a||o?(0,W.jsx)(u,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=o,t[55]=T):T=t[55];let E;t[56]!==s||t[57]!==n||t[58]!==o||t[59]!==i?(E=o?s.restartingChannel:i===`stopped`?s.restartChannel:Ze(n,s),t[56]=s,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==g||t[62]!==T||t[63]!==E||t[64]!==w?(D=(0,W.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,W.jsxs)(p,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:g,disabled:w,children:[T,E]})}),t[61]=g,t[62]=T,t[63]=E,t[64]=w,t[65]=D):D=t[65];let O;return t[66]!==D||t[67]!==x||t[68]!==S||t[69]!==C?(O=(0,W.jsxs)(`article`,{className:x,children:[S,C,D]}),t[66]=D,t[67]=x,t[68]=S,t[69]=C,t[70]=O):O=t[70],O}function it(e){return(0,W.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function $(e){return(0,W.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function at(e){let t=(0,U.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:o,ch:s,onRestart:l,onCheck:d,onManageConnection:m}=e,h=n===`running`?c:n===`stopped`||n===`needs_setup`?j:u,g=n===`running`&&`text-emerald-600 dark:text-emerald-400`,_=n===`stopped`&&`text-red-600 dark:text-red-400`,v=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,y=n===`disabled`&&`text-fg-muted`,b=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,x;t[0]!==g||t[1]!==_||t[2]!==v||t[3]!==y||t[4]!==b?(x=f(`mt-0.5 size-5 shrink-0`,g,_,v,y,b),t[0]=g,t[1]=_,t[2]=v,t[3]=y,t[4]=b,t[5]=x):x=t[5];let S;t[6]!==h||t[7]!==x?(S=(0,W.jsx)(h,{className:x}),t[6]=h,t[7]=x,t[8]=S):S=t[8];let C;t[9]===s.connectionStatus?C=t[10]:(C=(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:s.connectionStatus}),t[9]=s.connectionStatus,t[10]=C);let w;t[11]!==s||t[12]!==n?(w=Be(n,s),t[11]=s,t[12]=n,t[13]=w):w=t[13];let T;t[14]===w?T=t[15]:(T=(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[14]=w,t[15]=T);let E;t[16]!==T||t[17]!==C?(E=(0,W.jsxs)(`div`,{children:[C,T]}),t[16]=T,t[17]=C,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==S?(D=(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[S,E]}),t[19]=E,t[20]=S,t[21]=D):D=t[21];let O=i||r,k;t[22]===i?k=t[23]:(k=i?(0,W.jsx)(u,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=k);let A=i?s.checkingConnection:s.checkConnection,M;t[24]!==d||t[25]!==O||t[26]!==k||t[27]!==A?(M=(0,W.jsxs)(p,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:O,onClick:d,children:[k,A]}),t[24]=d,t[25]=O,t[26]=k,t[27]=A,t[28]=M):M=t[28];let N;t[29]!==s.restartChannel||t[30]!==s.restartingChannel||t[31]!==i||t[32]!==l||t[33]!==r||t[34]!==n?(N=n===`stopped`?(0,W.jsxs)(p,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:l,children:[r?(0,W.jsx)(u,{className:`size-4 animate-spin`}):(0,W.jsx)(R,{className:`size-4`}),r?s.restartingChannel:s.restartChannel]}):null,t[29]=s.restartChannel,t[30]=s.restartingChannel,t[31]=i,t[32]=l,t[33]=r,t[34]=n,t[35]=N):N=t[35];let P;t[36]!==o||t[37]!==s.connectionOptions||t[38]!==s.hideConnectionOptions||t[39]!==i||t[40]!==m||t[41]!==r||t[42]!==a?(P=o?(0,W.jsx)(p,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:m,children:a?s.hideConnectionOptions:s.connectionOptions}):null,t[36]=o,t[37]=s.connectionOptions,t[38]=s.hideConnectionOptions,t[39]=i,t[40]=m,t[41]=r,t[42]=a,t[43]=P):P=t[43];let F;t[44]!==M||t[45]!==N||t[46]!==P?(F=(0,W.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[M,N,P]}),t[44]=M,t[45]=N,t[46]=P,t[47]=F):F=t[47];let I;return t[48]!==D||t[49]!==F?(I=(0,W.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[D,F]})}),t[48]=D,t[49]=F,t[50]=I):I=t[50],I}function ot(e){let t=(0,U.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=X(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,W.jsx)(V,{className:`mt-0.5 size-4 shrink-0`}),t[11]=u):u=t[11],o=`min-w-0`,t[12]===r.setupReadinessTitle?s=t[13]:(s=(0,W.jsx)(`h3`,{className:`text-sm font-semibold`,children:r.setupReadinessTitle}),t[12]=r.setupReadinessTitle,t[13]=s);let p=e.enabled?r.setupReadinessEnabledBody:r.setupReadinessDisabledBody;t[14]===p?c=t[15]:(c=(0,W.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-amber-900 dark:text-amber-200`,children:p}),t[14]=p,t[15]=c),i=`mt-2 list-disc space-y-1 pl-5 text-sm text-amber-900 dark:text-amber-200`;let m;t[16]===r?m=t[17]:(m=e=>(0,W.jsx)(`li`,{children:et(e,r)},`${e.code}:${e.fieldPath??``}`),t[16]=r,t[17]=m),a=e.issues.map(m)}t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;t[18]!==i||t[19]!==a?(p=(0,W.jsx)(`ul`,{className:i,children:a}),t[18]=i,t[19]=a,t[20]=p):p=t[20];let m;t[21]!==p||t[22]!==o||t[23]!==s||t[24]!==c?(m=(0,W.jsxs)(`div`,{className:o,children:[s,c,p]}),t[21]=p,t[22]=o,t[23]=s,t[24]=c,t[25]=m):m=t[25];let h;t[26]!==m||t[27]!==l||t[28]!==u?(h=(0,W.jsxs)(`div`,{className:l,children:[u,m]}),t[26]=m,t[27]=l,t[28]=u,t[29]=h):h=t[29];let g;return t[30]!==h||t[31]!==d?(g=(0,W.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function st(){let e=_(e=>e.language),t=h(e),n=g(e=>!!e.token),r=a(),{channelId:o}=i(),c=M(o),u=Oe(n,e),d=u.entries,{data:p,mutate:m,isValidating:b}=A(n?de():null,ue,{revalidateOnFocus:!0}),{data:x,mutate:S}=A(n?`channels-config-map`:null,Ie,{revalidateOnFocus:!1}),C=x?.channels??{},w=x?.bindings??[],{data:T}=A(n?`channel-routing-agents`:null,P,{revalidateOnFocus:!1}),E=re(e=>e.setPageHeader),D=re(e=>e.clearPageHeader),O=(0,H.useMemo)(()=>d.find(e=>e.id===c),[c,d]),k=O?Re(O):null,{data:j,mutate:L}=A(n&&k?Ne(k):null,()=>Pe(k)),[R,z]=(0,H.useState)(null),[B,V]=(0,H.useState)(!1),[ee,ne]=(0,H.useState)(null),[le,U]=(0,H.useState)(null),[pe,me]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[q,J]=(0,H.useState)(null),ge=R??j??{},Y=t.channelsSettings,ye=(0,H.useMemo)(()=>O?.configSchema??{type:`object`,properties:{}},[O?.configSchema]),xe=(0,H.useMemo)(()=>Ke(ye,Fe),[ye]),Ce=(0,H.useMemo)(()=>He(O),[O]),Ee=(0,H.useMemo)(()=>We(xe,Ce),[Ce,xe]),De=(0,H.useMemo)(()=>Ke(xe,Ce),[Ce,xe]),ke=(0,H.useMemo)(()=>qe(Ee),[Ee]),je=O?q??_e(w,O.id):``,Le=(0,H.useMemo)(()=>(T?.items??[]).map(e=>{let n=te(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[T?.items,t.agentsSettings]),Be=T?.items.find(e=>e.id===T.defaultId),Z=Be?te(Be,t.agentsSettings):T?.defaultId??``,Ue=(0,H.useMemo)(()=>({defaultBooleanLabel:Y.schemaBooleanDefault,unsupportedArrayType:Y.schemaUnsupportedArrayType,arrayAddPlaceholder:Y.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>Y.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[Y]),Ge=(0,H.useMemo)(()=>new Map((p??[]).map(e=>[e.name,e])),[p]),Je=p!==void 0,Ye=(0,H.useCallback)(e=>be(e,Ge.get(e.id),Je),[Ge,Je]),Q=(0,H.useCallback)(async()=>{await Promise.all([u.mutate(),m()])},[u,m]);Me((0,H.useCallback)(e=>{let t=Ae(e);t&&m(t,!1)},[m]),n);let Xe=(0,H.useMemo)(()=>n?(0,W.jsx)(we,{ch:Y,refreshing:u.isValidating||b,saveOk:!1,onRefresh:()=>void Q()}):null,[u.isValidating,Y,n,b,Q]);(0,H.useLayoutEffect)(()=>(E({startExtra:null,main:(0,W.jsx)(`div`,{className:`min-w-0`,children:(0,W.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>D()),[D,Xe,t.settingsSections.channels,E]);let Ze=(0,H.useCallback)(e=>{r(N(e)),z(null),J(null),K(null)},[r]),Qe=(0,H.useCallback)(()=>{r(I),z(null),J(null),K(null)},[r]),$e=(0,H.useCallback)(async e=>{U(e.id),K(null);try{let t=await v(y(`/api/channels/${encodeURIComponent(e.id)}/restart`),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}await Q()}catch(e){K(e instanceof Error?e.message:String(e))}finally{U(null)}},[Q]);(0,H.useEffect)(()=>{J(null),me(!1)},[O?.id]);let et=(0,H.useCallback)(async()=>{if(!O||!R&&q===null)return!1;let e=Re(O);V(!0),K(null);try{let t=await v(y(`/api/config`),{method:`PATCH`,body:JSON.stringify({...R?{channels:{[e]:R}}:{},...q===null?{}:{bindings:ve(w,O.id,q)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return R&&await L(R,!1),await S(),await u.mutate(),z(null),J(null),!0}catch(e){return K(e instanceof Error?e.message:String(e)),!1}finally{V(!1)}},[O,q,w,u,R,S,L]),it=(0,H.useCallback)(async e=>{let t=X(e),n=Re(e),r=O?.id===e.id?R:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}ne(e.id),K(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await v(y(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[n]:i}})});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??a.statusText)}await u.mutate(),await S(),await m(),O?.id===e.id&&(await L(),z(null))}catch(e){K(e instanceof Error?e.message:String(e))}finally{ne(null)}},[O?.id,u,R,S,L,m,Ze]),$=O?.ui?.modal,st=$?.placement!==`replace-config`,ct=O?Ye(O):`checking`,lt=O?!X(O).ready||pe:!1;return n?(0,W.jsxs)(oe,{gap:`gap-4`,children:[u.isLoading?(0,W.jsx)(se,{sections:2}):u.error?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(u.error)}):(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:d.map(e=>(0,W.jsx)(rt,{entry:e,config:C[Re(e)]?.config,runtime:Ye(e),busy:ee===e.id,restarting:le===e.id,ch:Y,onOpen:()=>Ze(e.id),onToggle:()=>void it(e),onRestart:()=>void $e(e)},e.id))}),G?(0,W.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:G}):null,(0,W.jsx)(Se,{presentation:`modal`,open:!!O,onOpenChange:e=>{e||Qe()},closeAriaLabel:Y.close,srTitle:O?.label??Y.selectChannel,srDescription:O?.description,wide:!0,footer:O?(0,W.jsx)(Te,{ch:Y,dirty:!!R||q!==null,saving:B,onCancel:Qe,onDiscard:()=>{z(null),J(null)},onSave:et}):null,children:O?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,W.jsx)(tt,{entry:O}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,W.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:O.label}),(0,W.jsx)(`span`,{className:f(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Ve(ct)),children:ze(ct,Y)})]}),(0,W.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-fg-muted`,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:!X(O).ready&&fe(O)?.[1].result===`qr`?Y.scanLoginHint.replace(`{{channel}}`,O.label):O.description}),O.docsPath?(0,W.jsxs)(`a`,{href:O.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[Y.docs,(0,W.jsx)(l,{className:`size-3.5`})]}):null]})]})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,W.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:X(O).enabled?Y.enabledLabel:Y.disabledLabel}),(0,W.jsx)(nt,{checked:X(O).enabled,disabled:ee===O.id,label:Y.toggleChannel.replace(`{{channel}}`,O.label),onToggle:()=>void it(O)})]})]})}),(0,W.jsx)(at,{runtime:ct,restarting:le===O.id,checking:b,showConnectionOptions:pe,canManageConnection:X(O).ready&&$?.placement!==`replace-config`,ch:Y,onRestart:()=>void $e(O),onCheck:()=>void Q(),onManageConnection:()=>me(e=>!e)}),(0,W.jsx)(ot,{entry:O,ch:Y}),lt&&$?.placement!==`replace-config`?(0,W.jsx)(he,{entry:O,locale:e,messages:Y,compact:!0,onChanged:async()=>{await L(),await Q(),await S()}},O.id):null,$?.entrypoint&&$.placement===`before-config`?(0,W.jsx)(F,{extensionId:O.extensionId,extensionName:O.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:O.id,entry:O,config:ge}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,W.jsx)(F,{extensionId:O.extensionId,extensionName:O.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:O.id,entry:O,config:ge}}):null,st&&ke?(0,W.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,W.jsxs)(`div`,{className:`mb-4`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.basicConfiguration}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.basicConfigurationHint})]}),(0,W.jsx)(ce,{schema:Ee,values:ge,onChange:e=>z(e),disabled:B,labels:Ue})]}):null,(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(ie,{className:`size-4 text-fg-muted`}),Y.messageHandling]}),(0,W.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,W.jsxs)(`div`,{className:`mb-3`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:Y.agentRouting}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:Y.messageHandlingHint})]}),(0,W.jsx)(s,{value:je,options:Le,placeholder:Y.agentRoutingSelect,emptyLabel:Y.agentRoutingDefault.replace(`{{agent}}`,Z||Y.agentRoutingSelect),ariaLabel:Y.agentRouting,disabled:B||!T,onChange:e=>J(e)})]})]}),st&&qe(De)?(0,W.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,W.jsx)(ie,{className:`size-4 text-fg-muted`}),Y.advancedConfiguration]}),(0,W.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,W.jsx)(ce,{schema:De,values:ge,onChange:e=>z(e),disabled:B,labels:Ue})})]}):null,G?(0,W.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:G}):null]}):null})]}):(0,W.jsxs)(oe,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,W.jsx)(ae,{title:t.settingsSections.channels}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:Y.tokenRequired})]})}export{st as ChannelsSettingsPanel};
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./plus-Q2yW6OE7.js";import{t as i}from"./x-B_N4OPjy.js";import{t as a}from"./button-CSEbl4zT.js";import{t as o}from"./messages-kx5W39dO.js";import{n as s}from"./locale-store-iKjqemWG.js";import{Ca as c,Ds as l,nt as u,rt as d,tt as f}from"./index-EvA8c7fo.js";var p=2,m=1,h=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(p,Math.floor(u/e.css.cell.width)),rows:Math.max(m,Math.floor(l/e.css.cell.height))}}},g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,ee=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},v=(e,t,n,r)=>{for(var i=r>1?void 0:r?_(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&g(t,n,i),i},y=(e,t)=>(n,r)=>t(n,r,e),te=`Terminal input`,ne={get:()=>te,set:e=>te=e},re=`Too much output to announce, navigate to rows manually to read`,b={get:()=>re,set:e=>re=e};function ie(e){return e.replace(/\r?\n/g,`\r`)}function ae(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function x(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function oe(e,t,n,r){e.stopPropagation(),e.clipboardData&&S(e.clipboardData.getData(`text/plain`),t,n,r)}function S(e,t,n,r){e=ie(e),e=ae(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function se(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function ce(e,t,n,r,i){se(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function C(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function w(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var le=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},ue=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}else this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},de=``,fe=` `,pe=class e{constructor(){this.fg=0,this.bg=0,this.extended=new me}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return(this.fg&50331648)==0}isBgDefault(){return(this.bg&50331648)==0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},me=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},T=class e extends pe{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new me,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?C(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},he=`di$target`,ge=`di$dependencies`,_e=new Map;function ve(e){return e[ge]||[]}function E(e){if(_e.has(e))return _e.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);ye(t,e,r)};return t._id=e,_e.set(e,t),t}function ye(e,t,n){t[he]===t?t[ge].push({id:e,index:n}):(t[ge]=[{id:e,index:n}],t[he]=t)}var D=E(`BufferService`),be=E(`CoreMouseService`),O=E(`CoreService`),xe=E(`CharsetService`),Se=E(`InstantiationService`),Ce=E(`LogService`),k=E(`OptionsService`),we=E(`OscLinkService`),Te=E(`UnicodeService`),Ee=E(`DecorationService`),De=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new T,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId)if(c===-1){c=t,s=a.extended.urlId;continue}else l=a.extended.urlId!==s;else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Oe(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};De=v([y(0,D),y(1,k),y(2,we)],De);function Oe(e,t){if(confirm(`Do you want to navigate to ${t}?
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./plus-Q2yW6OE7.js";import{t as i}from"./x-B_N4OPjy.js";import{t as a}from"./button-CSEbl4zT.js";import{t as o}from"./messages-kx5W39dO.js";import{n as s}from"./locale-store-iKjqemWG.js";import{Ca as c,Os as l,nt as u,rt as d,tt as f}from"./index-jqDCfet4.js";var p=2,m=1,h=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(p,Math.floor(u/e.css.cell.width)),rows:Math.max(m,Math.floor(l/e.css.cell.height))}}},g=Object.defineProperty,_=Object.getOwnPropertyDescriptor,ee=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},v=(e,t,n,r)=>{for(var i=r>1?void 0:r?_(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&g(t,n,i),i},y=(e,t)=>(n,r)=>t(n,r,e),te=`Terminal input`,ne={get:()=>te,set:e=>te=e},re=`Too much output to announce, navigate to rows manually to read`,b={get:()=>re,set:e=>re=e};function ie(e){return e.replace(/\r?\n/g,`\r`)}function ae(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function x(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function oe(e,t,n,r){e.stopPropagation(),e.clipboardData&&S(e.clipboardData.getData(`text/plain`),t,n,r)}function S(e,t,n,r){e=ie(e),e=ae(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function se(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function ce(e,t,n,r,i){se(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function C(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function w(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var le=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o);continue}i!==65279&&(t[r++]=i)}return r}},ue=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}else this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(c=(i&31)<<6|a&63,c<128){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},de=``,fe=` `,pe=class e{constructor(){this.fg=0,this.bg=0,this.extended=new me}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return(this.fg&50331648)==0}isBgDefault(){return(this.bg&50331648)==0}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==0:this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},me=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},T=class e extends pe{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new me,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?C(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},he=`di$target`,ge=`di$dependencies`,_e=new Map;function ve(e){return e[ge]||[]}function E(e){if(_e.has(e))return _e.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);ye(t,e,r)};return t._id=e,_e.set(e,t),t}function ye(e,t,n){t[he]===t?t[ge].push({id:e,index:n}):(t[ge]=[{id:e,index:n}],t[he]=t)}var D=E(`BufferService`),be=E(`CoreMouseService`),O=E(`CoreService`),xe=E(`CharsetService`),Se=E(`InstantiationService`),Ce=E(`LogService`),k=E(`OptionsService`),we=E(`OscLinkService`),Te=E(`UnicodeService`),Ee=E(`DecorationService`),De=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new T,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(!(c===-1&&!n.hasContent(t))){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId)if(c===-1){c=t,s=a.extended.urlId;continue}else l=a.extended.urlId!==s;else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):Oe(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};De=v([y(0,D),y(1,k),y(2,we)],De);function Oe(e,t){if(confirm(`Do you want to navigate to ${t}?
2
2
 
3
3
  WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var ke=E(`CharSizeService`),Ae=E(`CoreBrowserService`),je=E(`MouseService`),Me=E(`RenderService`),Ne=E(`SelectionService`),Pe=E(`CharacterJoinerService`),Fe=E(`ThemeService`),Ie=E(`LinkProviderService`),Le=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?Ue.isErrorNoTelemetry(e)?new Ue(e.message+`
4
4
 
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{l as i,p as a}from"./chunk-KS7C4IRE-BaASWQor.js";import{t as o}from"./check-DUBLcKHA.js";import{n as s,r as c,t as l}from"./popover-select-BzdnTy3h.js";import{t as u}from"./circle-check-C23XjkUj.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./plus-Q2yW6OE7.js";import{t as p}from"./search-DA7gz22f.js";import{t as m}from"./x-B_N4OPjy.js";import{t as h}from"./cn-JdwAhgNB.js";import{t as g}from"./button-CSEbl4zT.js";import{s as _}from"./form-field-width-DJw_jULe.js";import{n as v}from"./interaction-BmQogeqz.js";import{n as y}from"./copy-to-clipboard-HOJ79TWv.js";import{t as b}from"./messages-kx5W39dO.js";import{l as x,n as S,r as C,s as w}from"./locale-store-iKjqemWG.js";import{i as T,o as E}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{t as D}from"./electron-env-DH5wF8X8.js";import{a as O,i as k,n as A,o as j,r as M,s as N,t as P}from"./dist-BPoKqzeH.js";import{n as F,r as I}from"./gateway-config-swr-BzTbnu4O.js";import{a as L,i as R,n as z,o as B,r as V}from"./dist-DY4Af0fY.js";import{$s as H,$t as ee,At as U,Bs as W,Bt as te,Cs as G,Ct as K,Dl as q,Dt as ne,Es as re,Et as ie,Ft as ae,Gt as oe,Hr as se,Hs as ce,Ht as le,Is as ue,It as de,Jt as fe,Kr as pe,Kt as me,Lt as he,Mt as ge,Nc as _e,Nt as ve,Ot as ye,Pt as be,Qt as xe,Rt as Se,St as Ce,Tt as we,Ur as Te,Ut as J,Vr as Y,Vt as Ee,Wr as De,Ws as Oe,Wt as ke,Xt as Ae,Yt as je,Zs as Me,Zt as Ne,_s as Pe,cc as Fe,en as Ie,gl as Le,hl as Re,jl as ze,jt as Be,kt as Ve,ma as He,nl as Ue,qt as We,rs as Ge,sl as Ke,ss as qe,tn as Je,uo as Ye,wt as Xe,xt as Ze,zs as Qe,zt as $e}from"./index-jqDCfet4.js";import{t as et}from"./page-tabs-BaEQMYm_.js";var X=e(t(),1),Z=n(),Q=r();function tt(e){let t=(0,Z.c)(74),{connector:n,installed:r,onInstall:i,onOpenDetails:a,t:o}=e,s,c,l,d,f,p,m,_,v,y;if(t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a||t[4]!==o.connect||t[5]!==o.connectedBadge||t[6]!==o.connectorBeta||t[7]!==o.connectorCapabilityLabels||t[8]!==o.connectorExperimental||t[9]!==o.connectorVerified){let e=n.capabilities.filter(nt),b=e.slice(0,3),x=Math.max(0,e.length-b.length),S=o.connect,C=n.verificationLevel===`verified`?o.connectorVerified:n.verificationLevel===`beta`?o.connectorBeta:n.verificationLevel===`experimental`?o.connectorExperimental:null,w;t[20]!==S||t[21]!==n||t[22]!==i?(w=e=>(0,Q.jsxs)(g,{type:`button`,variant:`primary`,className:h(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:e=>{e.stopPropagation(),i(n)},children:[(0,Q.jsx)(Fe,{className:`size-4`}),S]}),t[20]=S,t[21]=n,t[22]=i,t[23]=w):w=t[23],s=w;let T;t[24]!==n||t[25]!==a?(T=e=>{!a||e.currentTarget!==e.target||e.key!==`Enter`&&e.key!==` `||(e.preventDefault(),a(n))},t[24]=n,t[25]=a,t[26]=T):T=t[26];let E=T,D=a?`cursor-pointer`:null;t[27]===D?p=t[28]:(p=h(`group flex min-h-[9.5rem] flex-col rounded-lg bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,D),t[27]=D,t[28]=p),m=a?`button`:void 0,_=a?0:void 0,t[29]!==n||t[30]!==a?(v=()=>a?.(n),t[29]=n,t[30]=a,t[31]=v):v=t[31],y=E,c=`flex min-w-0 flex-1 flex-col`;let O;t[32]===n?O=t[33]:(O=(0,Q.jsx)(Xe,{connector:n}),t[32]=n,t[33]=O);let k;t[34]===n.displayName?k=t[35]:(k=(0,Q.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[34]=n.displayName,t[35]=k);let A;t[36]===C?A=t[37]:(A=C?(0,Q.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:C}):null,t[36]=C,t[37]=A);let j;t[38]!==k||t[39]!==A?(j=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[k,A]}),t[38]=k,t[39]=A,t[40]=j):j=t[40];let M;t[41]!==O||t[42]!==j?(M=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[O,j]}),t[41]=O,t[42]=j,t[43]=M):M=t[43];let N;t[44]!==r||t[45]!==s?(N=r?null:(0,Q.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 transition-opacity sm:pointer-events-none sm:flex sm:opacity-0 sm:group-hover:pointer-events-auto sm:group-hover:opacity-100 sm:group-focus-within:pointer-events-auto sm:group-focus-within:opacity-100`,children:s()}),t[44]=r,t[45]=s,t[46]=N):N=t[46];let P;t[47]!==r||t[48]!==o.connectedBadge?(P=r?(0,Q.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,Q.jsx)(u,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[47]=r,t[48]=o.connectedBadge,t[49]=P):P=t[49];let F;t[50]!==N||t[51]!==P?(F=(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[N,P]}),t[50]=N,t[51]=P,t[52]=F):F=t[52],t[53]!==M||t[54]!==F?(l=(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[M,F]}),t[53]=M,t[54]=F,t[55]=l):l=t[55],t[56]===n.description?d=t[57]:(d=(0,Q.jsx)(`p`,{className:`mt-4 line-clamp-2 text-sm leading-6 text-fg-muted`,title:n.description,children:n.description}),t[56]=n.description,t[57]=d),f=b.length>0?(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-1.5`,children:[b.map(e=>(0,Q.jsx)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:o.connectorCapabilityLabels[e]??e},e)),x>0?(0,Q.jsxs)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,x]}):null]}):null,t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o.connect,t[5]=o.connectedBadge,t[6]=o.connectorBeta,t[7]=o.connectorCapabilityLabels,t[8]=o.connectorExperimental,t[9]=o.connectorVerified,t[10]=s,t[11]=c,t[12]=l,t[13]=d,t[14]=f,t[15]=p,t[16]=m,t[17]=_,t[18]=v,t[19]=y}else s=t[10],c=t[11],l=t[12],d=t[13],f=t[14],p=t[15],m=t[16],_=t[17],v=t[18],y=t[19];let b;t[58]!==c||t[59]!==l||t[60]!==d||t[61]!==f?(b=(0,Q.jsxs)(`div`,{className:c,children:[l,d,f]}),t[58]=c,t[59]=l,t[60]=d,t[61]=f,t[62]=b):b=t[62];let x;t[63]!==r||t[64]!==s?(x=r?null:(0,Q.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 border-t border-edge pt-3 sm:hidden`,children:s(`w-full`)}),t[63]=r,t[64]=s,t[65]=x):x=t[65];let S;return t[66]!==b||t[67]!==x||t[68]!==p||t[69]!==m||t[70]!==_||t[71]!==v||t[72]!==y?(S=(0,Q.jsxs)(`div`,{className:p,role:m,tabIndex:_,onClick:v,onKeyDown:y,children:[b,x]}),t[66]=b,t[67]=x,t[68]=p,t[69]=m,t[70]=_,t[71]=v,t[72]=y,t[73]=S):S=t[73],S}function nt(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}var rt=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function it(e,t){return t.some(t=>t.connectorId===e.id)}var at=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`;function ot(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(`div`,{className:h(`size-10 shrink-0 rounded-xl`,at)}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Q.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,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:[t,(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsx)(`div`,{className:h(`h-4 min-w-0 flex-1`,at)}),(0,Q.jsx)(`div`,{className:h(`h-8 w-[4.5rem] shrink-0 rounded-lg`,at)})]}),(0,Q.jsx)(`div`,{className:h(`h-3 w-full`,at)}),(0,Q.jsx)(`div`,{className:h(`h-3 w-[88%]`,at)})]})]})}),e[1]=n):n=e[1],n}var $=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`;function st(){let e=(0,Z.c)(4),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(`div`,{className:h(`size-10 shrink-0 rounded-xl`,$)}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,Q.jsx)(`div`,{className:h(`h-4 w-48 max-w-full`,$)}),(0,Q.jsx)(`div`,{className:h(`h-3 w-72 max-w-full`,$)})]}),e[1]=n):n=e[1];let r;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[t,(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-start justify-between gap-3`,children:[n,(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,Q.jsx)(`div`,{className:h(`h-9 w-20 rounded-lg`,$)}),(0,Q.jsx)(`div`,{className:h(`h-9 w-20 rounded-lg`,$)})]})]})]}),e[2]=r):r=e[2];let i;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.jsxs)(`div`,{className:`rounded-2xl bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:[r,(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,children:[(0,Q.jsx)(`div`,{className:h(`h-8 w-20 rounded-md`,$)}),(0,Q.jsx)(`div`,{className:h(`h-8 w-24 rounded-md`,$)}),(0,Q.jsx)(`div`,{className:h(`h-8 w-28 rounded-md`,$)})]}),(0,Q.jsx)(`div`,{className:h(`mt-3 h-20 rounded-xl`,$)})]}),e[3]=i):i=e[3],i}function ct(e,t){return Object.entries(t).reduce((e,[t,n])=>e.replaceAll(`{{${t}}}`,String(n)),e)}function lt(e,t){return t.connectorCapabilityLabels[e]??e}function ut(e,t){if(e.runtime.type===`mcp`)return ct(t.connectorRuntimeMcp,{serverId:e.runtime.serverId});let n=e.runtime.type===`composio`?e.runtime.toolkit:e.runtime.type===`channel`?e.runtime.channelId:e.runtime.type===`nativeTool`?e.runtime.toolsetId:e.runtime.sourceKind;return ct(t.connectorRuntimeGeneric,{runtime:e.runtime.type,id:n??e.runtime.type})}function dt(e,t){return e.auth.mode===`oauth`?t.connectorAuthOAuth:e.auth.mode===`apiKey`?t.connectorAuthApiKey:t.connectorAuthNone}function ft(e){return(e.setup.secrets??[]).filter(e=>e.required).length+(e.setup.config??[]).filter(e=>e.required).length}function pt(e){let t=(0,Z.c)(12),{title:n,items:r}=e;if(r.length===0)return null;let i;t[0]===n?i=t[1]:(i=(0,Q.jsx)(`div`,{className:`border-b border-edge px-3 py-2 text-xs font-semibold text-fg`,children:n}),t[0]=n,t[1]=i);let a;t[2]===r?a=t[3]:(a=r.slice(0,16).map(mt),t[2]=r,t[3]=a);let o;t[4]===r.length?o=t[5]:(o=r.length>16?(0,Q.jsxs)(`div`,{className:`px-3 py-2 text-xs text-fg-subtle`,children:[`+`,r.length-16]}):null,t[4]=r.length,t[5]=o);let s;t[6]!==a||t[7]!==o?(s=(0,Q.jsxs)(`div`,{className:`max-h-48 overflow-y-auto`,children:[a,o]}),t[6]=a,t[7]=o,t[8]=s):s=t[8];let c;return t[9]!==i||t[10]!==s?(c=(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base`,children:[i,s]}),t[9]=i,t[10]=s,t[11]=c):c=t[11],c}function mt(e){return(0,Q.jsxs)(`div`,{className:`border-b border-edge-subtle px-3 py-2 last:border-b-0`,children:[(0,Q.jsx)(`div`,{className:`break-words font-mono text-xs font-medium text-fg`,children:e.title}),e.description?(0,Q.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs leading-5 text-fg-muted`,children:e.description}):null]},e.id)}function ht({connector:e,installed:t,onClose:n,onInstall:r,t:i}){let[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(null),[l,f]=(0,X.useState)(null),p=ft(e),_=e.capabilities.slice(0,8),y=Math.max(0,e.capabilities.length-_.length),b=[...(e.setup.secrets??[]).map(e=>({key:`secret:${e.key}`,label:e.label,description:e.description,required:e.required,kind:i.connectorSetupSecret})),...(e.setup.config??[]).map(e=>({key:`config:${e.key}`,label:e.label,description:e.description,required:!!e.required,kind:i.connectorSetupConfig}))],x=async()=>{o(!0),f(null);try{c(await Ee(e))}catch(e){c(null),f(e instanceof Error?e.message:String(e))}finally{o(!1)}};return(0,Q.jsx)(P,{open:!0,onOpenChange:e=>{e||n()},children:(0,Q.jsxs)(j,{children:[(0,Q.jsx)(O,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,Q.jsxs)(M,{className:h(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,52rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float outline-none dark:border-edge`),children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,Q.jsx)(Xe,{connector:e,size:`lg`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[t?(0,Q.jsx)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md 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,Q.jsx)(u,{className:`size-3`,"aria-hidden":!0}),i.connectedBadge]})}):null,(0,Q.jsx)(N,{className:`text-base font-semibold text-fg`,children:e.displayName}),(0,Q.jsx)(k,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:e.description})]})]}),(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,v.focusRingPanel),"aria-label":i.modalClose,children:[(0,Q.jsx)(m,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`sr-only`,children:i.modalClose})]})})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,Q.jsx)(Ge,{className:`size-3.5`,"aria-hidden":!0}),i.detailTools]}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm font-semibold text-fg`,children:s?ct(i.connectorPreviewToolsCount,{count:s.toolCount}):i.connectorPreviewUnknown})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,Q.jsx)(_e,{className:`size-3.5`,"aria-hidden":!0}),i.detailPermissions]}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm font-semibold text-fg`,children:dt(e,i)})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,Q.jsx)(Ke,{className:`size-3.5`,"aria-hidden":!0}),i.connectorRequiredInputs]}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm font-semibold text-fg`,children:ct(i.connectorRequiredInputsCount,{count:p})})]})]}),(0,Q.jsxs)(`div`,{className:`mt-5 grid gap-5 lg:grid-cols-[minmax(0,1fr)_18rem]`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 space-y-5`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:i.connectorCapabilitiesTitle}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[_.map(e=>(0,Q.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-1 text-xs text-fg-muted`,children:lt(e,i)},e)),y>0?(0,Q.jsxs)(`span`,{className:`rounded-md border border-edge bg-surface-base px-2 py-1 text-xs text-fg-subtle`,children:[`+`,y]}):null]})]}),l?(0,Q.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:l}):null,s?(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:i.connectorPreviewTitle}),(0,Q.jsx)(`span`,{className:h(`rounded-full px-2 py-0.5 text-xs font-medium`,s.ok?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`),children:s.ok?i.healthStatusHealthy:i.healthStatusLabels[s.status]??s.status})]}),(0,Q.jsxs)(`div`,{className:`mb-3 grid gap-2 text-xs sm:grid-cols-3`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2`,children:[(0,Q.jsx)(`div`,{className:`font-semibold text-fg`,children:s.toolCount}),(0,Q.jsx)(`div`,{className:`text-fg-muted`,children:i.toolsMetric})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2`,children:[(0,Q.jsx)(`div`,{className:`font-semibold text-fg`,children:s.resourceCount}),(0,Q.jsx)(`div`,{className:`text-fg-muted`,children:i.resourcesMetric})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2`,children:[(0,Q.jsx)(`div`,{className:`font-semibold text-fg`,children:s.promptCount}),(0,Q.jsx)(`div`,{className:`text-fg-muted`,children:i.promptsMetric})]})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(pt,{title:i.detailTools,items:s.tools.map(e=>({id:e.name,title:e.shortName??e.name,description:e.description}))}),(0,Q.jsx)(pt,{title:i.detailResources,items:s.resources.map(e=>({id:e.uri,title:e.title??e.name??e.uri,description:e.description??e.uri}))}),(0,Q.jsx)(pt,{title:i.detailPrompts,items:s.prompts.map(e=>({id:e.name,title:e.title??e.name,description:e.description??ct(i.promptArgumentCount,{count:e.argumentCount})}))})]}),s.error?(0,Q.jsx)(`p`,{className:`mt-3 text-xs leading-5 text-fg-subtle`,children:s.error}):null,s.action?(0,Q.jsx)(`p`,{className:`mt-2 text-xs leading-5 text-fg-subtle`,children:s.action}):null]}):null]}),(0,Q.jsxs)(`aside`,{className:`space-y-3`,children:[(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(_e,{className:`size-4 text-accent`,"aria-hidden":!0}),i.detailPermissions]}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm font-medium text-fg`,children:dt(e,i)})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(Ke,{className:`size-4 text-accent`,"aria-hidden":!0}),i.connectorSetupTitle]}),b.length>0?(0,Q.jsx)(`div`,{className:`mt-3 divide-y divide-edge overflow-hidden rounded-lg border border-edge`,children:b.map(e=>(0,Q.jsxs)(`div`,{className:`bg-surface-panel px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.label}),(0,Q.jsx)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] text-fg-muted`,children:e.kind}),e.required?(0,Q.jsx)(`span`,{className:`rounded-md bg-amber-500/10 px-1.5 py-0.5 text-[11px] font-medium text-amber-700 dark:text-amber-300`,children:i.connectorSetupRequired}):null]}),e.description?(0,Q.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:e.description}):null]},e.key))}):(0,Q.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-fg-muted`,children:i.connectorSetupNone})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`h3`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(W,{className:`size-4 text-accent`,"aria-hidden":!0}),i.connectorRuntimeTitle]}),(0,Q.jsx)(`p`,{className:`mt-2 break-words text-xs leading-5 text-fg-muted`,children:ut(e,i)})]})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsx)(g,{variant:`secondary`,children:i.modalClose})}),(0,Q.jsxs)(g,{variant:`secondary`,disabled:a,onClick:()=>void x(),children:[a?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Ge,{className:`size-4`}),i.connectorPreviewButton]}),t?(0,Q.jsxs)(g,{variant:`secondary`,disabled:!0,children:[(0,Q.jsx)(H,{className:`size-4`}),i.connectedBadge]}):(0,Q.jsxs)(g,{variant:`primary`,onClick:()=>{r(e),n()},children:[(0,Q.jsx)(Fe,{className:`size-4`}),i.connect]})]})]})]})})}var gt=h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_);function _t(e){let t=(0,Z.c)(58),{open:n,sessionIdleTtlMinutes:r,saving:i,onChange:a,onSave:o,onClose:s,t:c,mcp:l}=e,u;t[0]===s?u=t[1]:(u=e=>{e||s()},t[0]=s,t[1]=u);let f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(O,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),t[2]=f):f=t[2];let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=h(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(32rem,calc(100vh-2rem))] w-[min(100%-2rem,38rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),t[3]=p):p=t[3];let _;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Q.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent-soft text-accent-fg`,children:(0,Q.jsx)(Me,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0})}),t[4]=_):_=t[4];let y;t[5]===c.runtimeSettingsTitle?y=t[6]:(y=(0,Q.jsx)(N,{className:`text-base font-semibold text-fg`,children:c.runtimeSettingsTitle}),t[5]=c.runtimeSettingsTitle,t[6]=y);let b;t[7]===c.runtimeSettingsHint?b=t[8]:(b=(0,Q.jsx)(k,{className:`mt-1 text-sm text-fg-muted`,children:c.runtimeSettingsHint}),t[7]=c.runtimeSettingsHint,t[8]=b);let x;t[9]!==y||t[10]!==b?(x=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[_,(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[y,b]})]}),t[9]=y,t[10]=b,t[11]=x):x=t[11];let S;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(S=h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,v.focusRingPanel),t[12]=S):S=t[12];let C;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(m,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[13]=C):C=t[13];let w;t[14]===c.modalClose?w=t[15]:(w=(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:S,"aria-label":c.modalClose,children:C})}),t[14]=c.modalClose,t[15]=w);let T;t[16]!==w||t[17]!==x?(T=(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[x,w]}),t[16]=w,t[17]=x,t[18]=T):T=t[18];let E;t[19]===l.idleTtlLabel?E=t[20]:(E=(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:l.idleTtlLabel}),t[19]=l.idleTtlLabel,t[20]=E);let D;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(D=h(gt,`w-40 flex-none`),t[21]=D):D=t[21];let F=r??``,I;t[22]===a?I=t[23]:(I=e=>{let t=e.currentTarget.value.trim();a(t===``?void 0:Number.parseInt(t,10))},t[22]=a,t[23]=I);let L;t[24]!==l.idleTtlPlaceholder||t[25]!==F||t[26]!==I?(L=(0,Q.jsx)(`input`,{type:`number`,min:0,className:D,value:F,placeholder:l.idleTtlPlaceholder,onChange:I}),t[24]=l.idleTtlPlaceholder,t[25]=F,t[26]=I,t[27]=L):L=t[27];let R;t[28]===l.idleTtlHint?R=t[29]:(R=(0,Q.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:l.idleTtlHint}),t[28]=l.idleTtlHint,t[29]=R);let z;t[30]!==E||t[31]!==L||t[32]!==R?(z=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:(0,Q.jsxs)(`label`,{className:`flex max-w-xl flex-col gap-1.5`,children:[E,L,R]})}),t[30]=E,t[31]=L,t[32]=R,t[33]=z):z=t[33];let B;t[34]!==s||t[35]!==i||t[36]!==c.modalCancel?(B=(0,Q.jsx)(g,{type:`button`,variant:`secondary`,disabled:i,onClick:s,children:c.modalCancel}),t[34]=s,t[35]=i,t[36]=c.modalCancel,t[37]=B):B=t[37];let V;t[38]===o?V=t[39]:(V=()=>void o(),t[38]=o,t[39]=V);let H;t[40]===i?H=t[41]:(H=i?(0,Q.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,t[40]=i,t[41]=H);let ee;t[42]!==l.save||t[43]!==i||t[44]!==V||t[45]!==H?(ee=(0,Q.jsxs)(g,{type:`button`,variant:`primary`,disabled:i,onClick:V,children:[H,l.save]}),t[42]=l.save,t[43]=i,t[44]=V,t[45]=H,t[46]=ee):ee=t[46];let U;t[47]!==B||t[48]!==ee?(U=(0,Q.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[B,ee]}),t[47]=B,t[48]=ee,t[49]=U):U=t[49];let W;t[50]!==T||t[51]!==z||t[52]!==U?(W=(0,Q.jsxs)(j,{children:[f,(0,Q.jsxs)(M,{className:p,children:[T,z,U]})]}),t[50]=T,t[51]=z,t[52]=U,t[53]=W):W=t[53];let te;return t[54]!==n||t[55]!==u||t[56]!==W?(te=(0,Q.jsx)(P,{open:n,onOpenChange:u,children:W}),t[54]=n,t[55]=u,t[56]=W,t[57]=te):te=t[57],te}var vt=(0,X.memo)(function(e){let t=(0,Z.c)(12),{value:n,onChange:r,placeholder:i,className:a}=e,o;t[0]===a?o=t[1]:(o=h(`relative flex min-h-9 min-w-0 flex-1 cursor-text items-center rounded-pill border border-edge bg-surface-panel py-1.5 pl-9 pr-3 shadow-surface`,a),t[0]=a,t[1]=o);let s;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Q.jsx)(p,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),t[2]=s):s=t[2];let c;t[3]===r?c=t[4]:(c=e=>r(e.currentTarget.value),t[3]=r,t[4]=c);let l;t[5]!==i||t[6]!==c||t[7]!==n?(l=(0,Q.jsx)(`input`,{type:`search`,enterKeyHint:`search`,value:n,onChange:c,placeholder:i,autoComplete:`off`,spellCheck:!1,className:`min-w-0 flex-1 appearance-none border-0 bg-transparent py-0.5 text-sm leading-normal text-fg caret-current placeholder:text-fg-disabled focus:border-0 focus:shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none`}),t[5]=i,t[6]=c,t[7]=n,t[8]=l):l=t[8];let u;return t[9]!==o||t[10]!==l?(u=(0,Q.jsxs)(`label`,{className:o,children:[s,l]}),t[9]=o,t[10]=l,t[11]=u):u=t[11],u}),yt=(0,X.memo)(function(e){let t=(0,Z.c)(30),{onBrowseCatalog:n,onAddCustomServer:r,onOpenRuntimeSettings:i,addLabel:a,browseLabel:o,customLabel:s,settingsLabel:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(Qe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[0]=l):l=t[0];let u;t[1]===c?u=t[2]:(u=(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:c}),t[1]=c,t[2]=u);let d;t[3]!==i||t[4]!==c||t[5]!==u?(d=(0,Q.jsxs)(g,{type:`button`,variant:`secondary`,className:`shrink-0 gap-2`,"aria-label":c,title:c,onClick:i,children:[l,u]}),t[3]=i,t[4]=c,t[5]=u,t[6]=d):d=t[6];let p;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(f,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[7]=p):p=t[7];let m;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(ze,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[8]=m):m=t[8];let _;t[9]===a?_=t[10]:(_=(0,Q.jsx)(pe,{asChild:!0,children:(0,Q.jsxs)(g,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,children:[p,a,m]})}),t[9]=a,t[10]=_);let y;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(y=h(`flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-fg outline-none data-[highlighted]:bg-surface-hover`,v.transition),t[11]=y):y=t[11];let b;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(G,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[12]=b):b=t[12];let x;t[13]!==o||t[14]!==n?(x=(0,Q.jsxs)(se,{className:y,onSelect:n,children:[b,o]}),t[13]=o,t[14]=n,t[15]=x):x=t[15];let S;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(S=h(`flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-fg outline-none data-[highlighted]:bg-surface-hover`,v.transition),t[16]=S):S=t[16];let C;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(Ge,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[17]=C):C=t[17];let w;t[18]!==s||t[19]!==r?(w=(0,Q.jsxs)(se,{className:S,onSelect:r,children:[C,s]}),t[18]=s,t[19]=r,t[20]=w):w=t[20];let T;t[21]!==w||t[22]!==x?(T=(0,Q.jsx)(Te,{children:(0,Q.jsxs)(Y,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-panel p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[x,w]})}),t[21]=w,t[22]=x,t[23]=T):T=t[23];let E;t[24]!==T||t[25]!==_?(E=(0,Q.jsxs)(De,{children:[_,T]}),t[24]=T,t[25]=_,t[26]=E):E=t[26];let D;return t[27]!==E||t[28]!==d?(D=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[d,E]}),t[27]=E,t[28]=d,t[29]=D):D=t[29],D}),bt=/^([^:=]+)[:=](.*)$/;function xt(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=bt.exec(t);r&&n.push({key:r[1].trim(),value:r[2].trim()})}return n.length>0?n:null}function St(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function Ct(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function wt(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 Tt(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=(t&&typeof t==`object`?t:{}).servers,r={};if(!n||typeof n!=`object`||Array.isArray(n))return r;for(let[e,t]of Object.entries(n))!t||typeof t!=`object`||Array.isArray(t)||wt(t)&&(r[e]=t);return r}function Et(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Dt(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 Ot(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=Et(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Dt(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),e.requestTimeoutMs!=null&&Number.isFinite(e.requestTimeoutMs)&&(t.requestTimeoutMs=e.requestTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=St(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),e.requestTimeoutMs!=null&&Number.isFinite(e.requestTimeoutMs)&&(t.requestTimeoutMs=e.requestTimeoutMs),t}function kt(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{clientKey:e,id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:Ct(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0,requestTimeoutMs:typeof t.requestTimeoutMs==`number`&&Number.isFinite(t.requestTimeoutMs)?t.requestTimeoutMs:void 0}}function At(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0,requestTimeoutMs:void 0}}function jt(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).flatMap(([e,t])=>!t||typeof t!=`object`||Array.isArray(t)||wt(t)?[]:[kt(e,t)]).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function Mt(e){return Ot(e)}async function Nt(e,t={}){let n={};for(let r of e.servers){let e=r.id.trim();if(e){if(t[e])throw Error(`Server id "${e}" is reserved by an installed connector.`);n[e]=Ot(r)}}let r={servers:{...t,...n}};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(r.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await w(C(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:r})}),F()}function Pt(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}function Ft(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.uri!=`string`||typeof e.name!=`string`)continue;let r=e.uri.trim(),i=e.name.trim();!r||!i||t.push({uri:r,name:i,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,mimeType:typeof e.mimeType==`string`&&e.mimeType.trim()?e.mimeType.trim():void 0})}return t}function It(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();r&&t.push({name:r,title:typeof e.title==`string`&&e.title.trim()?e.title.trim():void 0,description:typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0,argumentCount:typeof e.argumentCount==`number`?e.argumentCount:0})}return t}async function Lt(e,t){let n=await w(C(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=Pt(n.payload.tools),i=Ft(n.payload.resources),a=It(n.payload.prompts);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,resourceCount:typeof n.payload.resourceCount==`number`?n.payload.resourceCount:i.length,promptCount:typeof n.payload.promptCount==`number`?n.payload.promptCount:a.length,tools:r,resources:i,prompts:a}}function Rt(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function zt(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function Bt(e){return e.requestTimeoutMs==null||!Number.isFinite(e.requestTimeoutMs)?``:String(Math.round(e.requestTimeoutMs/1e3))}function Vt(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>14400))return n*1e3}function Ht(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function Ut({row:e,t,cs:n,onEdit:r,onRemove:i}){let[a,o]=(0,X.useState)(!1),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(null),[f,p]=(0,X.useState)(null),m=Ht(e),h=(0,X.useCallback)(async()=>{o(!0),p(null);try{let t=await Lt(e.id.trim());u({toolCount:t.toolCount,resourceCount:t.resourceCount,promptCount:t.promptCount})}catch(e){p(e instanceof Error?e.message:String(e))}finally{o(!1)}},[e.id]),_=(0,X.useCallback)(async()=>{c(!0),p(null);try{await i()}catch(e){p(e instanceof Error?e.message:String(e)),c(!1)}},[i]);return(0,Q.jsxs)(`div`,{className:`flex h-full min-h-[10.5rem] cursor-pointer flex-col rounded-lg bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`,onClick:r,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:e.id.trim()||t.cardUntitled}),(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:n.customBadge}),(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.transportLabels[e.transport]})]}),m?(0,Q.jsx)(`p`,{className:`mt-3 line-clamp-2 break-all font-mono text-xs leading-5 text-fg-subtle`,title:m,children:m}):null,f?(0,Q.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:f}):null,l?(0,Q.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:K(n.customCapabilitySummary,{tools:String(l.toolCount),resources:String(l.resourceCount),prompts:String(l.promptCount)})}):null]}),(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2 border-t border-edge pt-3`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.connectorDetails}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(g,{variant:`secondary`,disabled:a,onClick:()=>void h(),children:[a?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(H,{className:`size-4`}),t.testConnection]}),(0,Q.jsxs)(g,{variant:`ghost`,disabled:s,onClick:()=>void _(),children:[s?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Pe,{className:`size-4`}),t.removeServer]})]})]})]})}function Wt(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function Gt(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||Wt(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
2
+ `).toLowerCase().includes(r)}function Kt(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function qt(e){let t=(0,Z.c)(29),{tools:n,stripPrefix:r,searchPlaceholder:i,searchEmptyLabel:a}=e,[o,s]=(0,X.useState)(``),c;if(t[0]!==o||t[1]!==r||t[2]!==n){let e;t[4]!==o||t[5]!==r?(e=e=>Gt(e,o,r),t[4]=o,t[5]=r,t[6]=e):e=t[6],c=n.filter(e),t[0]=o,t[1]=r,t[2]=n,t[3]=c}else c=t[3];let l=c,u;t[7]===o?u=t[8]:(u=o.trim(),t[7]=o,t[8]=u);let d=u.length>0,f;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(p,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),t[9]=f):f=t[9];let m,g;t[10]===Symbol.for(`react.memo_cache_sentinel`)?(m=h(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,_),g=e=>s(e.target.value),t[10]=m,t[11]=g):(m=t[10],g=t[11]);let v;t[12]!==o||t[13]!==i?(v=(0,Q.jsxs)(`div`,{className:`relative`,children:[f,(0,Q.jsx)(`input`,{type:`search`,value:o,placeholder:i,"aria-label":i,className:m,onChange:g})]}),t[12]=o,t[13]=i,t[14]=v):v=t[14];let y;t[15]!==l.length||t[16]!==d||t[17]!==n.length?(y=d?(0,Q.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[l.length,` / `,n.length]}):null,t[15]=l.length,t[16]=d,t[17]=n.length,t[18]=y):y=t[18];let b;t[19]!==v||t[20]!==y?(b=(0,Q.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[v,y]}),t[19]=v,t[20]=y,t[21]=b):b=t[21];let x;t[22]!==l||t[23]!==a||t[24]!==r?(x=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:l.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:a}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:l.map((e,t)=>{let n=e.shortName||Kt(e.name,r)||e.name||`?`,i=e.name||`tool-${t}`;return(0,Q.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,Q.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,Q.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},i)})})}),t[22]=l,t[23]=a,t[24]=r,t[25]=x):x=t[25];let S;return t[26]!==b||t[27]!==x?(S=(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:[b,x]}),t[26]=b,t[27]=x,t[28]=S):S=t[28],S}function Jt(e){let t=(0,Z.c)(38),{open:n,onOpenChange:r,serverId:i,title:a,subtitle:o,searchPlaceholder:s,searchEmptyLabel:c,emptyLabel:l,closeLabel:u,tools:d,stripPrefix:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(O,{className:h(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,E)}),t[0]=p):p=t[0];let _;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(_=h(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,T,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[1]=_):_=t[1];let v;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Q.jsx)(Ge,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[2]=v):v=t[2];let y;t[3]===a?y=t[4]:(y=(0,Q.jsxs)(N,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[v,a]}),t[3]=a,t[4]=y);let b;t[5]!==i||t[6]!==o||t[7]!==d.length?(b=o.replace(`{{serverId}}`,i).replace(`{{count}}`,String(d.length)),t[5]=i,t[6]=o,t[7]=d.length,t[8]=b):b=t[8];let x;t[9]===b?x=t[10]:(x=(0,Q.jsx)(k,{className:`mt-1 text-sm text-fg-muted`,children:b}),t[9]=b,t[10]=x);let S;t[11]!==y||t[12]!==x?(S=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[y,x]}),t[11]=y,t[12]=x,t[13]=S):S=t[13];let C;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(m,{className:`size-4`,"aria-hidden":!0}),t[14]=C):C=t[14];let w;t[15]===u?w=t[16]:(w=(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsx)(g,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":u,children:C})}),t[15]=u,t[16]=w);let D;t[17]!==S||t[18]!==w?(D=(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[S,w]}),t[17]=S,t[18]=w,t[19]=D):D=t[19];let F;t[20]!==l||t[21]!==n||t[22]!==c||t[23]!==s||t[24]!==i||t[25]!==f||t[26]!==d?(F=d.length>0?(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,Q.jsx)(qt,{tools:d,stripPrefix:f,searchPlaceholder:s,searchEmptyLabel:c},`${i}-${n?`open`:`closed`}`)}):(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l})}),t[20]=l,t[21]=n,t[22]=c,t[23]=s,t[24]=i,t[25]=f,t[26]=d,t[27]=F):F=t[27];let I;t[28]===u?I=t[29]:(I=(0,Q.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsx)(g,{type:`button`,variant:`secondary`,children:u})})}),t[28]=u,t[29]=I);let L;t[30]!==D||t[31]!==F||t[32]!==I?(L=(0,Q.jsxs)(j,{children:[p,(0,Q.jsxs)(M,{className:_,children:[D,F,I]})]}),t[30]=D,t[31]=F,t[32]=I,t[33]=L):L=t[33];let R;return t[34]!==r||t[35]!==n||t[36]!==L?(R=(0,Q.jsx)(P,{open:n,onOpenChange:r,children:L}),t[34]=r,t[35]=n,t[36]=L,t[37]=R):R=t[37],R}function Yt(e){let t=e.connectedAt?Date.parse(e.connectedAt):0;return Number.isFinite(t)?t:0}function Xt(e,t){return e.status===`active`&&t.status!==`active`?-1:e.status!==`active`&&t.status===`active`?1:e.isCurrentAuthorization===t.isCurrentAuthorization?e.isDefault===t.isDefault?Yt(t)-Yt(e):e.isDefault?-1:1:e.isCurrentAuthorization?-1:1}function Zt(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(Xt);return{key:e,primary:n[0],authorizations:n}}).sort((e,t)=>Xt(e.primary,t.primary))}var Qt=h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_);function $t(e){return e.materialized.type===`composio`?e.materialized.toolkit:null}function en(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function tn(e,t){return e.errorCode===`missing_credential`?t.composioHealthMissingCredential:e.errorCode===`unauthorized`?t.composioHealthUnauthorized:e.errorCode===`forbidden`?t.composioHealthForbidden:e.errorCode===`network`?t.composioHealthNetwork:e.errorCode===`timeout`?t.composioHealthTimeout:t.composioHealthDegraded}function nn(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 rn(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 an({instance:e,t,onChanged:n}){let r=$t(e),[i,a]=(0,X.useState)([]),[l,u]=(0,X.useState)([]),[f,p]=(0,X.useState)([]),[_,v]=(0,X.useState)([]),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)([]),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(null),[O,k]=(0,X.useState)([]),[A,j]=(0,X.useState)({}),[M,N]=(0,X.useState)(`read`),[P,F]=(0,X.useState)(!1),[I,L]=(0,X.useState)(null),R=(0,X.useMemo)(()=>Zt(i),[i]),z=(0,X.useCallback)(async()=>{if(!(!r||e.materialized.type!==`composio`||e.materialized.role===`credential`)){F(!0),L(null);try{let[t,n,i,o,s,c,l,d,f]=await Promise.all([de().catch(()=>[]),he(r).catch(()=>[]),Se(20).catch(()=>[]),ve(r).catch(()=>`read`),$e().catch(()=>[]),ge(r).catch(()=>null),Be(r).catch(()=>null),te().catch(()=>[]),be(r).catch(()=>null)]);a(t.filter(e=>e.toolkit.toLowerCase()===r.toLowerCase())),u(n),p(i.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===r.toLowerCase())),N(o),v(s.filter(t=>t.connectorId===e.connectorId)),b(c?.policy??null),S(c?.agents??[]),w(l),k(d),E(f);let m=Zt(t.filter(e=>e.toolkit.toLowerCase()===r.toLowerCase())).map(e=>e.primary).filter(e=>!!e.accountId),h=await Promise.all(m.map(async e=>[e.accountId,await ae(e.accountId)]).map(e=>e.catch(()=>null)));j(Object.fromEntries(h.filter(e=>e!==null)))}catch(e){L(e instanceof Error?e.message:String(e))}finally{F(!1)}}},[e.connectorId,e.materialized,r]);(0,X.useEffect)(()=>{z()},[z]);let B=(0,X.useCallback)(async()=>{if(r){F(!0),L(null);try{let t=await fe(e.connectorId);if(!t.authorizationUrl)throw Error(`The authorization provider did not return an authorization URL.`);if(D()){let e=await window.electronAPI?.shell?.openExternalUrl(t.authorizationUrl);if(!e?.ok)throw Error(e?.error??`Could not open the system browser.`)}else window.open(t.authorizationUrl,`_blank`,`noopener,noreferrer`);let i=await Je(r,t.connectionId);if(!i.accountId)throw Error(`Connector account is unavailable.`);await We(i.accountId),await n?.(),await z()}catch(e){L(e instanceof Error?e.message:String(e))}finally{F(!1)}}},[e.connectorId,z,n,r]),V=(0,X.useCallback)(async t=>{F(!0),L(null);try{await ee(e.instanceId,{config:{...e.config??{},...t?{authConfigId:t}:{authConfigId:void 0}}}),await n?.(),await z()}catch(e){L(e instanceof Error?e.message:String(e))}finally{F(!1)}},[e.config,e.instanceId,z,n]),H=(0,X.useCallback)(async e=>{if(r){N(e);try{await me(r,e),await z()}catch(e){L(e instanceof Error?e.message:String(e))}}},[z,r]),U=(0,X.useCallback)(async(e,t)=>{F(!0),L(null);try{await ke(e,t),await z()}catch(e){L(e instanceof Error?e.message:String(e))}finally{F(!1)}},[z]),W=(0,X.useCallback)(async e=>{if(r){L(null);try{b(await xe(r,e))}catch(e){L(e instanceof Error?e.message:String(e))}}},[e.connectorId,r]),G=(0,X.useCallback)(e=>{y&&W({allowedAgentIds:y.allowedAgentIds.includes(e)?y.allowedAgentIds.filter(t=>t!==e):[...y.allowedAgentIds,e]})},[W,y]),q=(0,X.useCallback)(async e=>{F(!0),L(null);try{await e(),await z()}catch(e){L(e instanceof Error?e.message:String(e))}finally{F(!1)}},[z]);return r?e.materialized.type===`composio`&&e.materialized.role===`credential`?(0,Q.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:t.composioApiKeyStored}):(0,Q.jsxs)(`div`,{className:`mt-4 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-fg`,children:K(t.composioToolkitTitle,{toolkit:r})}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.composioScopeHint})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(g,{variant:`secondary`,disabled:P,onClick:()=>void B(),children:[P?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(_e,{className:`size-4`}),t.connectOAuth]}),(0,Q.jsx)(g,{variant:`ghost`,disabled:P,onClick:()=>void z(),children:t.refresh})]})]}),I?(0,Q.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:I}):null,T?(0,Q.jsxs)(`div`,{className:`mt-3 rounded-lg border border-edge bg-surface-panel p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-fg`,children:t.composioAuthConfigTitle}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:T.requiresCustomAuthConfig?t.composioAuthConfigRequiredHint:t.composioAuthConfigOptionalHint})]}),(0,Q.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,Q.jsxs)(s,{className:h(Qt,`mt-2 h-9 py-1`),value:typeof e.config?.authConfigId==`string`?e.config.authConfigId:``,disabled:P,onChange:e=>void V(e.currentTarget.value),children:[T.requiresCustomAuthConfig?null:(0,Q.jsx)(c,{value:``,children:t.composioAuthConfigManaged}),T.requiresCustomAuthConfig&&typeof e.config?.authConfigId!=`string`?(0,Q.jsx)(c,{value:``,disabled:!0,children:t.composioAuthConfigSelect}):null,T.authConfigs.filter(e=>e.status===`ENABLED`&&e.isEnabledForToolRouter).map(e=>(0,Q.jsxs)(c,{value:e.id,children:[e.name,` · `,e.authScheme??`OAuth`,` · `,e.id]},e.id))]}),T.requiresCustomAuthConfig&&T.authConfigs.every(e=>e.status!==`ENABLED`||!e.isEnabledForToolRouter)?(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-amber-700 dark:text-amber-300`,children:t.composioAuthConfigEmpty}):null]}):null,C?(0,Q.jsxs)(`div`,{className:h(`mt-3 flex flex-wrap items-center justify-between gap-2 rounded-lg border px-3 py-2 text-xs`,C.status===`connected`?`border-emerald-500/30 bg-emerald-500/5 text-emerald-700`:`border-amber-500/30 bg-amber-500/5 text-amber-700`),children:[(0,Q.jsx)(`span`,{children:C.status===`connected`?K(t.composioHealthConnected,{count:String(R.filter(e=>e.primary.status===`active`).length)}):C.status===`reauthorization_required`?t.composioHealthReconnect:C.status===`degraded`?tn(C,t):t.composioHealthDisconnected}),C.recovery===`none`?null:(0,Q.jsx)(g,{variant:`ghost`,disabled:P,onClick:()=>void(C.recovery===`retry`?z():B()),children:C.recovery===`retry`?t.composioRetry:t.connectOAuth}),C.status===`degraded`&&C.message?(0,Q.jsx)(`p`,{className:`basis-full break-words text-[11px] opacity-80`,children:C.message}):null]}):null,y?(0,Q.jsxs)(`div`,{className:`mt-4 grid gap-3 rounded-lg border border-edge bg-surface-panel p-3 md:grid-cols-3`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-medium text-fg-subtle`,children:[t.composioAccessTitle,(0,Q.jsxs)(s,{className:h(Qt,`mt-1 h-9 py-1`),value:M,onChange:e=>void H(e.currentTarget.value),children:[(0,Q.jsx)(c,{value:`read`,children:t.composioAccessReadOnly}),(0,Q.jsx)(c,{value:`write`,children:t.composioAccessReadWrite}),M===`admin`?(0,Q.jsx)(c,{value:`admin`,children:t.composioAccessAdminCurrent}):null]}),(0,Q.jsx)(`span`,{className:`mt-1 block font-normal leading-4 text-fg-muted`,children:M===`read`?t.composioAccessReadHint:M===`admin`?t.composioAccessAdminHint:t.composioAccessWriteHint})]}),(0,Q.jsxs)(`label`,{className:`text-xs font-medium text-fg-subtle`,children:[t.composioConfirmationPolicy,(0,Q.jsxs)(s,{className:h(Qt,`mt-1 h-9 py-1`),value:y.confirmationPolicy,onChange:e=>void W({confirmationPolicy:e.currentTarget.value}),children:[(0,Q.jsx)(c,{value:`writes`,children:t.composioConfirmWrites}),(0,Q.jsx)(c,{value:`always`,children:t.composioConfirmAlways}),y.confirmationPolicy===`never`?(0,Q.jsx)(c,{value:`never`,children:t.composioConfirmNever}):null]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-fg-subtle`,children:t.composioAllowedAgents}),(0,Q.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:y.allowedAgentIds.length?t.composioAllowedAgentsSelected:t.composioAllowedAgentsAll}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.map(e=>(0,Q.jsx)(`button`,{type:`button`,className:h(`rounded-full border px-2.5 py-1 text-xs transition-colors`,y.allowedAgentIds.includes(e.id)?`border-accent bg-accent/10 text-accent`:`border-edge text-fg-muted hover:text-fg`),onClick:()=>G(e.id),children:e.name},e.id))})]})]}):null,_.length?(0,Q.jsxs)(`div`,{className:`mt-4 space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioPendingApprovals}),_.map(e=>(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-amber-500/30 bg-amber-500/5 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`truncate font-mono text-xs font-medium text-fg`,children:e.actionId}),(0,Q.jsx)(`p`,{className:`mt-1 break-all font-mono text-xs text-fg-subtle`,children:JSON.stringify(e.argumentsPreview)}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:K(t.composioApprovalExpires,{time:new Date(e.expiresAt).toLocaleTimeString()})})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,Q.jsxs)(g,{variant:`secondary`,disabled:P,onClick:()=>void U(e.id,`denied`),children:[(0,Q.jsx)(m,{className:`size-4`}),t.composioDeny]}),(0,Q.jsxs)(g,{disabled:P,onClick:()=>void U(e.id,`approved`),children:[(0,Q.jsx)(o,{className:`size-4`}),t.approve]})]})]},e.id))]}):null,(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioConnections}),R.length?[{title:t.composioConnectedAccounts,items:R.filter(e=>e.primary.status===`active`)},{title:t.composioNeedsAttention,items:R.filter(e=>e.primary.status!==`active`)}].filter(e=>e.items.length>0).map(e=>(0,Q.jsxs)(`section`,{className:`mb-3 space-y-2`,children:[(0,Q.jsxs)(`h4`,{className:`text-xs font-medium text-fg-muted`,children:[e.title,` · `,e.items.length]}),e.items.map(e=>{let i=e.primary,a=O.find(e=>i.accountId?e.accountId===i.accountId:e.connectionId===i.id),o=i.accountId?A[i.accountId]:void 0;return(0,Q.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-edge bg-surface-panel p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:i.alias??i.workspace??i.accountEmail??i.username??t.composioUnnamedAuthorization}),i.connectedAt?(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:K(t.composioAuthorizedAt,{time:new Date(i.connectedAt).toLocaleString()})}):null,(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[K(t.composioAuthorizationCount,{count:String(e.authorizations.length)}),e.authorizations.length>1?` · ${K(t.composioDuplicateAuthorizations,{count:String(e.authorizations.length-1)})}`:``]})]}),(0,Q.jsxs)(`span`,{className:h(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,i.status===`active`?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`),children:[nn(i.status,t),i.isDefault?` · ${t.composioDefaultAccount}`:``]})]}),a||i.status===`active`?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-fg`,children:t.connectorLearningTitle}),(0,Q.jsx)(`p`,{className:h(`mt-1 text-xs`,a?.status===`failed`?`text-red-600`:`text-fg-subtle`),children:a?K(t.connectorLearningStatus,{status:rn(a,o,t),count:String(a.candidatesCreated)}):t.connectorLearningEmpty}),o?(0,Q.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-subtle`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o.scanEnabled,disabled:P,onChange:e=>void q(()=>Ie(i.accountId,{scanEnabled:e.currentTarget.checked}))}),t.connectorScheduledScan]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-subtle`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:o.proactiveEnabled,disabled:P||!o.scanEnabled,onChange:e=>void q(()=>Ie(i.accountId,{proactiveEnabled:e.currentTarget.checked}))}),t.connectorProactiveUse]}),o.scanEnabled?(0,Q.jsxs)(`label`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:[t.connectorScanInterval,(0,Q.jsxs)(s,{className:h(Qt,`mt-1 h-8 py-1 text-xs`),value:String(o.intervalMinutes??30),disabled:P,onChange:e=>void q(()=>Ie(i.accountId,{intervalMinutes:Number(e.currentTarget.value)})),children:[(0,Q.jsxs)(c,{value:`5`,children:[`5 `,t.connectorMinutes]}),(0,Q.jsxs)(c,{value:`15`,children:[`15 `,t.connectorMinutes]}),(0,Q.jsxs)(c,{value:`30`,children:[`30 `,t.connectorMinutes]}),(0,Q.jsxs)(c,{value:`60`,children:[`60 `,t.connectorMinutes]})]})]}):null]}):null]}):null,(0,Q.jsxs)(`details`,{className:`text-xs text-fg-subtle`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer`,children:t.composioAdvancedSettings}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-2 rounded-lg bg-surface-base p-2`,children:[e.authorizations.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`p`,{className:`min-w-0 break-all font-mono`,children:[t.composioAuthorizationId,`: `,e.providerConnectionId]}),(0,Q.jsx)(g,{variant:`ghost`,className:`size-7 shrink-0 p-0`,title:t.composioRevoke,disabled:P,onClick:()=>{window.confirm(t.composioRevokeConfirm)&&q(()=>oe(e.id))},children:(0,Q.jsx)(Pe,{className:`size-3.5 text-red-500`})})]},e.id)),(0,Q.jsx)(`input`,{className:h(Qt,`h-8 py-1 text-xs`),defaultValue:i.alias??``,placeholder:t.composioAccountAlias,onBlur:e=>{e.currentTarget.value!==(i.alias??``)&&q(()=>Ne(i.id,{alias:e.currentTarget.value}))}})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-1`,children:[(0,Q.jsx)(g,{variant:`ghost`,className:`size-8 p-0`,title:t.composioMakeDefault,disabled:P||i.isDefault||i.status!==`active`,onClick:()=>void q(async()=>{await Ne(i.id,{isDefault:!0}),r&&await xe(r,{selectedConnectionIds:[i.id]})}),children:(0,Q.jsx)(re,{className:h(`size-4`,i.isDefault&&`fill-current`)})}),(0,Q.jsx)(g,{variant:`ghost`,className:`size-8 p-0`,title:t.refresh,disabled:P,onClick:()=>void q(()=>le(i.id)),children:(0,Q.jsx)(Oe,{className:`size-4`})}),i.status===`active`?(0,Q.jsxs)(g,{variant:`secondary`,disabled:P,onClick:()=>void q(async()=>{if(!i.accountId)throw Error(`Connector account is unavailable.`);await We(i.accountId),await n?.()}),children:[P?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Oe,{className:`size-4`}),t.composioSyncNow]}):null]})]},e.key)})]},e.title)):(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioConnectionsEmpty})]})}),(0,Q.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-panel p-3`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-muted`,children:t.composioAdvancedSettings}),(0,Q.jsxs)(`div`,{className:`mt-4 grid gap-4 lg:grid-cols-2`,children:[(0,Q.jsx)(`div`,{className:`space-y-3`,children:(0,Q.jsxs)(`label`,{className:`block text-xs text-fg-subtle`,children:[t.composioAdvancedScope,(0,Q.jsxs)(s,{className:h(Qt,`mt-1 h-9 py-1`),value:M,onChange:e=>void H(e.currentTarget.value),children:[(0,Q.jsx)(c,{value:`read`,children:t.composioScopeRead}),(0,Q.jsx)(c,{value:`write`,children:t.composioScopeWrite}),(0,Q.jsx)(c,{value:`admin`,children:t.composioScopeAdmin})]})]})}),(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),l.length?l.slice(0,8).map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-2`,children:[(0,Q.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[en(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),f.length?f.slice(0,5).map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-2`,children:[(0,Q.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})]})]})]})]})]}):null}var on=h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_);function sn(e,t){return e?t.healthStatusLabels[e]??e:t.healthNotTested}function cn(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 ln(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 un(e){let t=(0,Z.c)(12),{title:n,description:r,meta:i}=e,a;t[0]===r?a=t[1]:(a=r?(0,Q.jsx)(R,{delayDuration:300,skipDelayDuration:100,children:(0,Q.jsxs)(L,{children:[(0,Q.jsx)(B,{asChild:!0,children:(0,Q.jsx)(`p`,{tabIndex:0,title:r,className:h(`mt-1 line-clamp-3 cursor-help text-xs leading-5 text-fg-muted`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`),children:r})}),(0,Q.jsx)(V,{children:(0,Q.jsx)(z,{side:`top`,align:`start`,sideOffset:6,collisionPadding:12,className:`!z-[10000] max-h-[min(16rem,45vh)] max-w-[min(32rem,calc(100vw-2rem))] overflow-y-auto rounded-md border border-edge bg-surface-panel px-2.5 py-2 text-left text-xs leading-5 text-fg shadow-popover`,children:(0,Q.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:r})})})]})}):null,t[0]=r,t[1]=a);let o=a,s;t[2]===n?s=t[3]:(s=(0,Q.jsx)(`p`,{className:`min-w-0 break-all font-mono text-xs font-medium leading-5 text-fg`,children:n}),t[2]=n,t[3]=s);let c;t[4]===i?c=t[5]:(c=i?(0,Q.jsx)(`span`,{className:`shrink-0 rounded-md bg-surface-hover px-1.5 py-0.5 text-[11px] leading-4 text-fg-subtle`,children:i}):null,t[4]=i,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start justify-between gap-3`,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;return t[9]!==o||t[10]!==l?(u=(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2.5`,children:[l,o]}),t[9]=o,t[10]=l,t[11]=u):u=t[11],u}function dn({instance:e,definition:t,onClose:n,onChanged:r,t:i,mcp:a}){let[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,f]=(0,X.useState)(!1),[p,_]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(e.materialized.type===`mcp`?`health`:`permissions`),[T,E]=(0,X.useState)(!1),[D,F]=(0,X.useState)(()=>cn(t,e)),[I,L]=(0,X.useState)(null),R=t?.setup.config??[],z=(e.materialized.type===`mcp`||e.materialized.type===`memorySource`)&&R.length>0&&(t?.setup.secrets??[]).length===0,B=x?x.toolCount:e.usage.lastToolCount,V=(0,X.useMemo)(()=>{let t=e.materialized.type===`mcp`?[[`health`,ue,i.detailHealth],[`tools`,Ge,`${i.detailTools} ${x?x.toolCount:e.usage.lastToolCount??``}`],[`resources`,Ke,`${i.detailResources} ${x?x.resourceCount:e.usage.lastResourceCount??``}`],[`prompts`,Ue,`${i.detailPrompts} ${x?x.promptCount:e.usage.lastPromptCount??``}`],[`permissions`,_e,i.detailPermissions]]:[[`permissions`,_e,i.detailPermissions]];return z?[...t,[`config`,Ke,i.connectorConfigLabel]]:t},[x,e.materialized.type,e.usage.lastPromptCount,e.usage.lastResourceCount,e.usage.lastToolCount,z,i]),U=(0,X.useCallback)(async()=>{s(!0),L(null);try{let t=await Ae(e.instanceId);S(t),t.toolCount>0&&w(`tools`),r()}catch(e){L(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e.instanceId,r]),W=(0,X.useCallback)(async()=>{l(!0),L(null);try{await J(e.instanceId),await r(),n()}catch(e){L(e instanceof Error?e.message:String(e)),l(!1)}},[e.instanceId,r,n]),te=(0,X.useCallback)(async()=>{if(!(!t||!z)){f(!0),L(null);try{let n={};for(let e of t.setup.config??[]){let t=ln(e.type,D[e.key]??``);t!==void 0&&(n[e.key]=t)}await ee(e.instanceId,{config:n}),await r(),w(`health`)}catch(e){L(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[D,t,e.instanceId,r,z]),G=(0,X.useCallback)(async()=>{_(!0),b(null),L(null);try{b((await je(e.connectorId)).recordIds.length),await r()}catch(e){L(e instanceof Error?e.message:String(e))}finally{_(!1)}},[e.connectorId,r]);return(0,Q.jsxs)(P,{open:!0,onOpenChange:e=>{e||n()},children:[(0,Q.jsxs)(j,{children:[(0,Q.jsx)(O,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,Q.jsxs)(M,{className:h(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,54rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float outline-none dark:border-edge`),children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,Q.jsx)(Xe,{connector:t,size:`lg`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(N,{className:`text-base font-semibold text-fg`,children:e.displayName}),(0,Q.jsx)(k,{className:`mt-1 text-sm text-fg-muted`,children:t?.description??(e.materialized.type===`mcp`?K(i.mcpServerRuntime,{serverId:e.materialized.serverId}):K(i.runtimeLabel,{runtime:e.materialized.type}))})]})]}),(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,v.focusRingPanel),"aria-label":i.modalClose,children:[(0,Q.jsx)(m,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`sr-only`,children:i.modalClose})]})})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:[I?(0,Q.jsx)(`p`,{className:`mb-4 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:I}):null,(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:V.map(([e,t,n])=>(0,Q.jsxs)(`button`,{type:`button`,className:h(`inline-flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs`,C===e?`border-accent bg-accent-soft text-accent-fg`:`border-edge bg-surface-base text-fg-muted hover:text-fg`),onClick:()=>w(e),children:[(0,Q.jsx)(t,{className:`size-3.5`,"aria-hidden":!0}),n]},e))}),(0,Q.jsxs)(`div`,{className:`mt-4 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[C===`health`?(0,Q.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,Q.jsxs)(`p`,{children:[i.statusLabel,` `,(0,Q.jsx)(`span`,{className:x?.ok?`font-medium text-emerald-700 dark:text-emerald-300`:`font-medium text-fg`,children:sn(x?.status??e.usage.lastHealthStatus,i)})]}),(0,Q.jsxs)(`p`,{children:[i.lastCheckLabel,` `,e.usage.lastHealthCheckAt?new Date(e.usage.lastHealthCheckAt).toLocaleString():i.never]}),x?.action?(0,Q.jsx)(`p`,{children:x.action}):null]}):null,C===`tools`?x?.tools.length?(0,Q.jsxs)(`div`,{className:`grid gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:K(i.toolsAvailable,{count:String(x.tools.length)})}),(0,Q.jsx)(g,{type:`button`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>E(!0),children:a.viewAllTools})]}),(0,Q.jsx)(`div`,{className:`grid gap-2`,children:x.tools.slice(0,8).map(e=>(0,Q.jsx)(un,{title:e.shortName??e.name,description:e.description},e.name))})]}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-fg-muted`,children:B?K(i.toolsLastCheckSummary,{count:String(B)}):i.toolsRunTestHint}),(0,Q.jsxs)(g,{type:`button`,variant:`secondary`,disabled:o,onClick:()=>void U(),children:[o?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(H,{className:`size-4`}),i.test]})]}):null,C===`resources`?x?.resources.length?(0,Q.jsx)(`div`,{className:`grid gap-2`,children:x.resources.slice(0,8).map(e=>(0,Q.jsx)(un,{title:e.title??e.name,description:e.uri,meta:e.mimeType},e.uri))}):(0,Q.jsx)(`p`,{className:`text-fg-muted`,children:i.resourcesRunTestHint}):null,C===`prompts`?x?.prompts.length?(0,Q.jsx)(`div`,{className:`grid gap-2`,children:x.prompts.slice(0,8).map(e=>(0,Q.jsx)(un,{title:e.title??e.name,description:e.description,meta:e.argumentCount?K(i.promptArgumentCount,{count:String(e.argumentCount)}):void 0},e.name))}):(0,Q.jsx)(`p`,{className:`text-fg-muted`,children:i.promptsRunTestHint}):null,C===`permissions`?(0,Q.jsxs)(`div`,{className:`space-y-1 text-fg-muted`,children:[(0,Q.jsx)(`p`,{children:K(i.secretsConfigured,{count:String(Object.values(e.secretStatus).filter(Boolean).length)})}),(0,Q.jsx)(`p`,{children:e.materialized.type===`mcp`?K(i.runtimeServerLabel,{runtime:e.materialized.type.toUpperCase(),serverId:e.materialized.serverId}):K(i.runtimeLabel,{runtime:e.materialized.type.toUpperCase()})}),(0,Q.jsx)(`p`,{children:e.materialized.type===`mcp`?i.mcpPolicyHint:i.connectorPolicyHint})]}):null,C===`config`&&z?(0,Q.jsx)(`div`,{className:`grid gap-3`,children:R.map(e=>(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.label}),e.description?(0,Q.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,Q.jsx)(`input`,{className:on,value:D[e.key]??``,placeholder:e.placeholder,onChange:t=>F(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key))}):null]}),e.materialized.type===`composio`?(0,Q.jsx)(an,{instance:e,t:i,onChanged:r}):null,e.materialized.type===`memorySource`?(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-fg`,children:i.connectedSourceSync}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t?.description}),y===null?null:(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-emerald-600`,children:K(i.connectedSourceSynced,{count:String(y)})})]}),(0,Q.jsxs)(g,{disabled:p,onClick:()=>void G(),children:[p?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Ke,{className:`size-4`}),i.composioSyncNow]})]}):null]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,Q.jsx)(g,{variant:`secondary`,onClick:n,children:i.modalClose}),C===`config`&&z?(0,Q.jsxs)(g,{variant:`primary`,disabled:u,onClick:()=>void te(),children:[u?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(ce,{className:`size-4`}),i.modalSave]}):null,e.materialized.type===`mcp`?(0,Q.jsxs)(g,{variant:`secondary`,disabled:o,onClick:()=>void U(),children:[o?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(H,{className:`size-4`}),i.test]}):null,(0,Q.jsxs)(g,{variant:`ghost`,disabled:c,onClick:()=>void W(),children:[c?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Pe,{className:`size-4`}),i.remove]})]})]})]}),e.materialized.type===`mcp`?(0,Q.jsx)(Jt,{open:T,onOpenChange:E,serverId:e.materialized.serverId,title:K(i.installedToolsDialogTitle,{name:e.displayName}),subtitle:i.installedToolsDialogSubtitle,searchPlaceholder:a.toolsDialogSearchPlaceholder,searchEmptyLabel:a.toolsDialogSearchEmpty,emptyLabel:i.toolsRunTestHint,closeLabel:a.toolsDialogClose,tools:x?.tools??[],stripPrefix:`${e.materialized.serverId}__`}):null]})}var fn=[`understand`,`act`,`reach`];function pn(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 mn(e){return pn(e)[0]??`act`}function hn(e,t){let n=t?mn(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 gn({instance:e,definition:t,highlighted:n=!1,onOpenDetails:r,onChanged:i,t:a}){let[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),m=(0,X.useCallback)(async()=>{s(!0),p(null);try{await Ae(e.instanceId),await i()}catch(e){p(e instanceof Error?e.message:String(e))}finally{s(!1)}},[e.instanceId,i]),_=(0,X.useCallback)(async()=>{l(!0),p(null);try{await J(e.instanceId),await i()}catch(e){p(e instanceof Error?e.message:String(e)),l(!1)}},[e.instanceId,i]),v=e.usage.lastHealthStatus?a.healthStatusLabels[e.usage.lastHealthStatus]??e.usage.lastHealthStatus:a.healthNotTested,y=e.usage.lastToolCount??0,b=!!(t?.setup.config?.length&&!t.setup.secrets?.length&&e.materialized.type===`mcp`),x=hn(e,t).state,S=x===`ready`?{label:a.connectionReady,Icon:u,className:`border-emerald-500/30 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`}:x===`needs_setup`?{label:a.connectionNeedsSetup,Icon:q,className:`border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-300`}:{label:a.connectionChecking,Icon:Re,className:`border-edge bg-surface-base text-fg-muted`};return(0,Q.jsxs)(`div`,{className:h(`flex h-full min-h-[10.5rem] cursor-pointer flex-col rounded-lg bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`,n&&`ring-2 ring-accent/45 ring-offset-2 ring-offset-surface-panel`),onClick:()=>r(e),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-start gap-3`,children:[(0,Q.jsx)(Xe,{connector:t}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:e.displayName}),(0,Q.jsxs)(`span`,{className:h(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] font-medium`,S.className),children:[(0,Q.jsx)(S.Icon,{className:`size-3`,"aria-hidden":!0}),S.label]}),b?(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:a.connectorConfigLabel}):null]}),t?.description?(0,Q.jsx)(`p`,{className:`mt-3 line-clamp-2 text-sm leading-5 text-fg-muted`,children:t.description}):null,(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2 text-xs text-fg-muted`,children:[(0,Q.jsxs)(`span`,{className:`rounded-md bg-surface-base px-2 py-1`,children:[a.statusLabel,` `,v]}),(0,Q.jsx)(`span`,{className:`rounded-md bg-surface-base px-2 py-1`,children:K(a.toolsAvailable,{count:String(y)})})]}),f?(0,Q.jsx)(`p`,{className:`mt-3 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:f}):null]})]}),(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-2 border-t border-edge pt-3`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:a.connectorDetails}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[x===`needs_setup`?(0,Q.jsxs)(g,{variant:`primary`,onClick:()=>r(e),children:[(0,Q.jsx)(q,{className:`size-4`}),a.connectionResolveAction]}):null,e.materialized.type===`mcp`?(0,Q.jsxs)(g,{variant:`secondary`,disabled:o,onClick:()=>void m(),children:[o?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(H,{className:`size-4`}),a.test]}):null,(0,Q.jsxs)(g,{variant:`ghost`,disabled:c,onClick:()=>void _(),children:[c?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(Pe,{className:`size-4`}),a.remove]})]})]})]})}function _n(e,t){let n=e.length+1,r=`server-${n}`,i=new Set([...e.map(e=>e.id.trim()),...t]);for(;i.has(r);)n+=1,r=`server-${n}`;return At(r)}function vn(e,t,n){let r=e.key.trim();if(r)return`key:${r}`;let i=e.value.trim();return i?`value:${i}`:`empty:${n.slice(0,t).filter(e=>!e.key.trim()&&!e.value.trim()).length}`}function yn(){return h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_)}function bn({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,keyPlaceholder:o,valuePlaceholder:s,headers:c,onChange:l}){let u=(e,t)=>{l(c.map((n,r)=>r===e?{...n,...t}:n))},d=()=>{l([...c,{key:``,value:``}])},f=e=>{let t=c.filter((t,n)=>n!==e);l(t.length>0?t:[{key:``,value:``}])},p=async()=>{try{let e=await y();if(!e){window.alert(a);return}let t=xt(e);if(!t?.length){window.alert(a);return}l(t)}catch{window.alert(a)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,Q.jsx)(`span`,{children:e}),t?(0,Q.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,Q.jsxs)(g,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void p(),children:[(0,Q.jsx)(Le,{className:`size-3.5`,"aria-hidden":!0}),i]})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{className:h(yn(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:o,onChange:e=>u(t,{key:e.target.value})}),(0,Q.jsx)(`input`,{className:h(yn(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:s,onChange:e=>u(t,{value:e.target.value})}),(0,Q.jsx)(g,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:c.length<=1&&!e.key&&!e.value,onClick:()=>f(t),"aria-label":r,children:(0,Q.jsx)(Pe,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},vn(e,t,c)))}),(0,Q.jsxs)(`button`,{type:`button`,className:h(`self-start text-sm text-accent hover:underline`,v.press),onClick:d,children:[`+ `,n]})]})}var xn=[`stdio`,`sse`,`streamable-http`];function Sn(e){let t=(0,Z.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,Q.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,Q.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function Cn(){return h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_)}function wn(e){let t=(0,Z.c)(35),{row:n,t:r,onUpdate:i,idConflictMessage:a,variant:o}=e,l=o===void 0?`all`:o,u=l===`all`||l===`basic`,d=l===`all`||l===`advanced`,f;t[0]!==a||t[1]!==i||t[2]!==n.id||t[3]!==n.transport||t[4]!==u||t[5]!==r?(f=u?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Sn,{label:r.transportLabel,required:!0,children:(0,Q.jsx)(s,{className:Cn(),value:n.transport,onChange:e=>i({transport:e.target.value}),children:xn.map(e=>(0,Q.jsx)(c,{value:e,children:r.transportLabels[e]},e))})}),(0,Q.jsxs)(Sn,{label:r.serverIdLabel,required:!0,children:[(0,Q.jsx)(`input`,{className:Cn(),value:n.id,placeholder:r.serverIdPlaceholder,onChange:e=>i({id:e.target.value})}),a?(0,Q.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-300`,children:a}):null]})]}):null,t[0]=a,t[1]=i,t[2]=n.id,t[3]=n.transport,t[4]=u,t[5]=r,t[6]=f):f=t[6];let p;t[7]!==i||t[8]!==n.argsText||t[9]!==n.command||t[10]!==n.cwd||t[11]!==n.envJson||t[12]!==n.headers||t[13]!==n.transport||t[14]!==n.url||t[15]!==d||t[16]!==u||t[17]!==r||t[18]!==l?(p=n.transport===`stdio`?(0,Q.jsxs)(Q.Fragment,{children:[u?(0,Q.jsx)(`div`,{className:l===`basic`?`md:col-span-2`:void 0,children:(0,Q.jsx)(Sn,{label:r.commandLabel,required:!0,children:(0,Q.jsx)(`input`,{className:Cn(),value:n.command,onChange:e=>i({command:e.target.value})})})}):null,d?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Sn,{label:r.argsLabel,description:r.argsHint,children:(0,Q.jsx)(`input`,{className:Cn(),value:n.argsText,onChange:e=>i({argsText:e.target.value})})}),(0,Q.jsx)(Sn,{label:r.cwdLabel,children:(0,Q.jsx)(`input`,{className:Cn(),value:n.cwd,onChange:e=>i({cwd:e.target.value})})}),(0,Q.jsx)(Sn,{label:r.envLabel,description:r.envHint,children:(0,Q.jsx)(`textarea`,{className:h(Cn(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>i({envJson:e.target.value})})})]}):null]}):(0,Q.jsxs)(Q.Fragment,{children:[u?(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:(0,Q.jsx)(Sn,{label:r.urlLabel,required:!0,children:(0,Q.jsx)(`input`,{className:h(Cn(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>i({url:e.target.value})})})}):null,d?(0,Q.jsx)(bn,{label:r.headersLabel,optionalLabel:r.optionalSuffix,addLabel:r.addHeader,removeHeaderAria:r.removeHeader,pasteLabel:r.pasteHeaders,pasteFailed:r.pasteHeadersFailed,keyPlaceholder:r.headerKeyPlaceholder,valuePlaceholder:r.headerValuePlaceholder,headers:n.headers,onChange:e=>i({headers:e})}):null]}),t[7]=i,t[8]=n.argsText,t[9]=n.command,t[10]=n.cwd,t[11]=n.envJson,t[12]=n.headers,t[13]=n.transport,t[14]=n.url,t[15]=d,t[16]=u,t[17]=r,t[18]=l,t[19]=p):p=t[19];let m;t[20]!==i||t[21]!==n||t[22]!==d||t[23]!==r?(m=d?(0,Q.jsx)(Sn,{label:r.timeoutLabel,description:r.timeoutHint,children:(0,Q.jsx)(`input`,{type:`number`,min:1,max:600,className:Cn(),value:Rt(n),placeholder:r.timeoutPlaceholder,onChange:e=>i({connectionTimeoutMs:zt(e.target.value)})})}):null,t[20]=i,t[21]=n,t[22]=d,t[23]=r,t[24]=m):m=t[24];let g;t[25]!==i||t[26]!==n||t[27]!==d||t[28]!==r?(g=d?(0,Q.jsx)(Sn,{label:r.requestTimeoutLabel,description:r.requestTimeoutHint,children:(0,Q.jsx)(`input`,{type:`number`,min:1,max:14400,className:Cn(),value:Bt(n),placeholder:r.requestTimeoutPlaceholder,onChange:e=>i({requestTimeoutMs:Vt(e.target.value)})})}):null,t[25]=i,t[26]=n,t[27]=d,t[28]=r,t[29]=g):g=t[29];let _;return t[30]!==f||t[31]!==p||t[32]!==m||t[33]!==g?(_=(0,Q.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[f,p,m,g]}),t[30]=f,t[31]=p,t[32]=m,t[33]=g,t[34]=_):_=t[34],_}function Tn(e,t){if(e.shortName)return e.shortName;let n=`${t.trim()}__`;return n&&e.name.startsWith(n)?e.name.slice(n.length):e.name}function En(e){let t=(0,Z.c)(13),{tool:n,serverId:r}=e,i;t[0]!==r||t[1]!==n?(i=Tn(n,r),t[0]=r,t[1]=n,t[2]=i):i=t[2];let a=i,o=n.name===a?a:n.name,s;t[3]===n.description?s=t[4]:(s=n.description?.trim(),t[3]=n.description,t[4]=s);let c=s,l;t[5]!==a||t[6]!==o?(l=(0,Q.jsx)(`p`,{className:`break-all font-mono text-xs font-medium leading-5 text-fg`,title:o,children:a}),t[5]=a,t[6]=o,t[7]=l):l=t[7];let u;t[8]===c?u=t[9]:(u=c?(0,Q.jsx)(R,{delayDuration:300,skipDelayDuration:100,children:(0,Q.jsxs)(L,{children:[(0,Q.jsx)(B,{asChild:!0,children:(0,Q.jsx)(`p`,{tabIndex:0,title:c,className:h(`mt-1 line-clamp-3 cursor-help text-xs leading-5 text-fg-muted`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`),children:c})}),(0,Q.jsx)(V,{children:(0,Q.jsx)(z,{side:`top`,align:`start`,sideOffset:6,collisionPadding:12,className:`!z-[10000] max-h-[min(16rem,45vh)] max-w-[min(32rem,calc(100vw-2rem))] overflow-y-auto rounded-md border border-edge bg-surface-panel px-2.5 py-2 text-left text-xs leading-5 text-fg shadow-popover`,children:(0,Q.jsx)(`span`,{className:`whitespace-pre-wrap break-words`,children:c})})})]})}):null,t[8]=c,t[9]=u);let d;return t[10]!==l||t[11]!==u?(d=(0,Q.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-edge bg-surface-panel px-3 py-2.5`,children:[l,u]}),t[10]=l,t[11]=u,t[12]=d):d=t[12],d}function Dn({open:e,mode:t,initialRow:n,existingCustomServers:r,sessionIdleTtlMinutes:i,config:a,managedServerIds:o,t:s,cs:c,onClose:l,onSaved:f}){let[p,_]=(0,X.useState)(n),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),[D,F]=(0,X.useState)({status:`idle`}),[I,L]=(0,X.useState)(null),R=n.id.trim(),z=p.id.trim()!==R&&o.has(p.id.trim())||o.has(p.id.trim())&&t===`add`?s.reservedServerId:void 0,B=p.id.trim()&&r.some(e=>e.clientKey!==n.clientKey&&e.id.trim()===p.id.trim())?c.duplicateServerId:void 0,V=p.id.trim().length>0&&!z&&!B&&(p.transport===`stdio`?p.command.trim().length>0:p.url.trim().length>0),ee=Ht(p),U=(0,X.useCallback)(async()=>{if(p.id.trim()){S(!0),w(null),F({status:`loading`});try{F({status:`ok`,tools:(await Lt(p.id.trim(),Mt(p))).tools})}catch(e){F({status:`error`,message:e instanceof Error?e.message:String(e)})}finally{S(!1)}}},[p]),te=(0,X.useCallback)(async()=>{if(!(!V||y)){b(!0),w(null);try{let e=r.filter(e=>!(t===`edit`&&e.clientKey===n.clientKey));e.push(p),await Nt({sessionIdleTtlMinutes:i,servers:e.sort((e,t)=>e.id.localeCompare(t.id))},Tt(a)),await f(),l()}catch(e){w(e instanceof Error?e.message:String(e))}finally{b(!1)}}},[V,a,r,n.clientKey,t,l,f,R,p,y,i]);return e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(P,{open:e,onOpenChange:e=>{e||l()},children:(0,Q.jsxs)(j,{children:[(0,Q.jsx)(O,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,Q.jsxs)(M,{className:h(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,44rem)] w-[min(100%-2rem,min(92vw,48rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-panel shadow-float dark:border-edge`),children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(N,{className:`text-base font-semibold text-fg`,children:t===`add`?c.addCustomServerTitle:c.editCustomServerTitle}),(0,Q.jsx)(k,{className:`mt-1 text-sm text-fg-muted`,children:t===`add`?c.addCustomServerHint:c.editCustomServerHint})]}),(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,v.focusRingPanel),"aria-label":c.modalClose,children:[(0,Q.jsx)(m,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c.modalClose})]})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,Q.jsx)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(W,{className:`size-4 text-accent`,"aria-hidden":!0}),p.id.trim()||s.cardUntitled]}),(0,Q.jsx)(`p`,{className:`mt-1 break-all font-mono text-xs leading-5 text-fg-muted`,children:ee||(p.transport===`stdio`?s.commandLabel:s.urlLabel)})]}),(0,Q.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:s.transportLabels[p.transport]})]})}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`div`,{className:`mb-3`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectorBasicConfigTitle}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:c.connectorBasicConfigHint})]}),(0,Q.jsx)(wn,{row:p,t:s,variant:`basic`,onUpdate:e=>{_(t=>({...t,...e})),w(null)},idConflictMessage:z??B})]}),D.status===`ok`?(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,Q.jsx)(Ge,{className:`size-4 text-accent`,"aria-hidden":!0}),D.tools.length===0?s.toolsEmpty:s.toolsTitle.replace(`{{count}}`,String(D.tools.length))]}),D.tools.length>0?(0,Q.jsx)(g,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>L(D.tools),children:s.viewAllTools}):null]}),D.tools.length>0?(0,Q.jsx)(`div`,{className:`mt-3 grid gap-2`,children:D.tools.slice(0,6).map((e,t)=>(0,Q.jsx)(En,{tool:e,serverId:p.id},e.name||`tool-${t}`))}):null]}):null,D.status===`error`?(0,Q.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:D.message}):null,C?(0,Q.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:C}):null,(0,Q.jsxs)(`details`,{open:T,onToggle:e=>E(e.currentTarget.open),className:`group rounded-xl border border-edge bg-surface-base`,children:[(0,Q.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg hover:text-fg [&::-webkit-details-marker]:hidden`,children:[(0,Q.jsx)(ze,{className:`size-4 text-fg-muted transition-transform group-open:rotate-180`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`group-open:hidden`,children:c.connectorShowAdvancedConfig}),(0,Q.jsx)(`span`,{className:`hidden group-open:inline`,children:c.connectorHideAdvancedConfig})]}),(0,Q.jsx)(`div`,{className:`border-t border-edge p-4`,children:(0,Q.jsx)(wn,{row:p,t:s,variant:`advanced`,onUpdate:e=>{_(t=>({...t,...e})),w(null)}})})]})]})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,Q.jsxs)(g,{variant:`secondary`,disabled:!p.id.trim()||x,onClick:()=>void U(),children:[x?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(H,{className:`size-4`}),s.testConnection]}),(0,Q.jsx)(A,{asChild:!0,children:(0,Q.jsx)(g,{variant:`secondary`,children:c.modalCancel})}),(0,Q.jsxs)(g,{variant:`primary`,disabled:!V||y,onClick:()=>void te(),children:[y?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):(0,Q.jsx)(u,{className:`size-4`}),y?s.saving:c.modalSave]})]})]})]})}),I?(0,Q.jsx)(Jt,{open:!0,onOpenChange:e=>{e||L(null)},serverId:p.id,title:s.toolsDialogTitle,subtitle:s.toolsDialogSubtitle,searchPlaceholder:s.toolsDialogSearchPlaceholder,searchEmptyLabel:s.toolsDialogSearchEmpty,emptyLabel:s.toolsEmpty,closeLabel:s.toolsDialogClose,tools:I,stripPrefix:`${p.id.trim()}__`}):null]}):null}var On=`builtin`,kn=`composio`,An=`xopc-store`;function jn(e){return On}function Mn(e){return!(e.runtime.type===`composio`&&e.runtime.role===`credential`)}function Nn(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.description,e.category,e.kind,e.source,...e.tags??[]].some(e=>e.toLowerCase().includes(n)):!0}function Pn(e,t,n){return e.filter(e=>Nn(e,t)).toSorted((e,t)=>n===`source`&&e.source!==t.source?e.source.localeCompare(t.source):e.displayName.localeCompare(t.displayName))}function Fn(e,t){let n=t.trim().toLowerCase();return n?[e.displayName,e.connectorId,e.instanceId,e.status,e.connectionStatus??``,e.materialized.type,e.materialized.type===`mcp`?e.materialized.serverId:e.materialized.id].some(e=>e.toLowerCase().includes(n)):!0}function In(e,t){let n=t.trim().toLowerCase();return n?[e.id,e.command??``,e.url??``,e.transport].some(e=>e.toLowerCase().includes(n)):!0}function Ln(e){let t=[`code`,`docs`,`browser`,`data`,`automation`,`custom`].includes(e.category??``)?e.category:`custom`;return{id:e.name,version:e.latestVersion??`store`,displayName:e.name,description:e.description,category:t,kind:`mcp`,source:`store`,capabilities:[`tools`,`runtime.mcp.streamableHttp`],tags:[`store`],auth:{mode:`none`},setup:{},runtime:{type:`mcp`,serverId:`store-${e.name}`.slice(0,64)}}}function Rn(e){return e.filter((e,t,n)=>n.findIndex(t=>t.id===e.id)===t)}function zn(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/you?tab=sources`}function Bn(){let e=b(S(e=>e.language)),t=e.connectorsSettings,n=e.mcpSettings,r=x(e=>e.token),o=!!r,s=i(),[c,u]=a(),f=c.get(`understanding`)===`1`,p=zn(c.get(`returnTo`)),m=c.get(`tab`),[_,v]=(0,X.useState)(!f&&m===`connected`?`connected`:`discover`),y=(0,X.useRef)(!1),[C,w]=(0,X.useState)({catalog:[],registryCatalog:[],instances:[],loading:!0,error:null,peopleGraph:null}),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(1),[j,M]=(0,X.useState)(void 0),[N,P]=(0,X.useState)(``),[F,L]=(0,X.useState)(``),[R,z]=(0,X.useState)(!1),[B,V]=(0,X.useState)(f?c.get(`connector`)??``:``),[H,ee]=(0,X.useState)(jn(f?`understanding`:`default`)),[W,te]=(0,X.useState)(`name`),[G,K]=(0,X.useState)(f?`understand`:`all`),[q,re]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(null),[se,ce]=(0,X.useState)(null),[le,ue]=(0,X.useState)(null),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(null),[he,ge]=(0,X.useState)(!1),[_e,ve]=(0,X.useState)(void 0),[be,xe]=(0,X.useState)(!1),{data:Se,mutate:Te}=I(o),J=Se?.payload?.config,Y=(0,X.useMemo)(()=>J===void 0?null:jt(J),[J]),Ee=Y?.servers??[],De=C.instances.length+Ee.length;(0,X.useEffect)(()=>{Y&&ve(Y.sessionIdleTtlMinutes)},[Y]);let Oe=(0,X.useCallback)(async()=>{if(!r){w({catalog:[],registryCatalog:[],instances:[],loading:!1,error:null,peopleGraph:null});return}w(e=>({...e,loading:!0,error:null}));try{let[e,t,n]=await Promise.all([ne(),ye(),ie(``,12).catch(()=>null)]);w(r=>({catalog:e,registryCatalog:r.registryCatalog,instances:t,loading:!1,error:null,peopleGraph:n}))}catch(e){w({catalog:[],registryCatalog:[],instances:[],loading:!1,error:e instanceof Error?e.message:String(e),peopleGraph:null})}},[r]);(0,X.useEffect)(()=>{Oe()},[Oe]),(0,X.useEffect)(()=>{if(!o||_!==`connected`)return;let e=!1,t=window.setTimeout(()=>{z(!0),ie(F,50).then(t=>{e||w(e=>({...e,peopleGraph:t}))}).catch(()=>{}).finally(()=>{e||z(!1)})},250);return()=>{e=!0,window.clearTimeout(t)}},[o,F,_]),(0,X.useEffect)(()=>{y.current||C.loading||o&&!Y||(v(f?`discover`:De>0?`connected`:`discover`),y.current=!0)},[o,De,Y,f,C.loading]);let ke=(0,X.useCallback)(e=>{y.current=!0,v(e)},[]),Ae=(0,X.useMemo)(()=>[{id:kn,displayName:t.composioSourceName},{id:An,displayName:t.storeSourceName}],[t.composioSourceName,t.storeSourceName]),je=(0,X.useCallback)(async e=>{if(!o||H===`builtin`){w(e=>({...e,registryCatalog:[]})),A(1),M(void 0);return}let t=B.trim(),n=Math.max(e?.page??1,1),r=e?.append??!1,i=H===`all`?Ae:Ae.filter(e=>e.id===H);if(i.length!==0){E(!0),r?w(e=>({...e,error:null})):(A(1),M(void 0),w(e=>({...e,registryCatalog:[],error:null})));try{let e=await Promise.all(i.map(async e=>{if(e.id===`composio`){let e=await we({q:t||void 0,page:n,pageSize:24,verification:`experimental`});return{connectors:e.connectors,totalPages:e.meta.totalPages}}let r=await Ve({q:t||void 0,page:n,pageSize:24,sort:W===`source`?`newest`:`downloads`});return{connectors:r.items.map(Ln),totalPages:r.meta.totalPages}})),a=Rn(e.flatMap(e=>e.connectors)),o=Math.max(1,...e.map(e=>e.totalPages??1));A(n),M(o),w(e=>({...e,registryCatalog:r?Rn([...e.registryCatalog,...a]):a}))}catch(e){w(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{E(!1)}}},[W,B,H,o,Ae]);(0,X.useEffect)(()=>{if(_!==`discover`||C.loading)return;if(H===`builtin`){w(e=>({...e,registryCatalog:[]})),A(1),M(void 0);return}let e=window.setTimeout(()=>{je()},B.trim()?350:0);return()=>window.clearTimeout(e)},[B,H,je,C.loading,_]);let Me=(0,X.useMemo)(()=>new Set(C.instances.map(e=>e.connectorId)),[C.instances]),Ne=(0,X.useMemo)(()=>new Map([...C.catalog,...C.registryCatalog].map(e=>[e.id,e])),[C.catalog,C.registryCatalog]);(0,X.useEffect)(()=>{if(C.loading)return;let e=c.get(`connector`),t=c.get(`instance`);if(!e&&!t)return;let n=C.instances.find(n=>t?n.instanceId===t:n.connectorId===e);if(n)y.current=!0,P(``),ce(n.instanceId),ue(n),v(`connected`);else if(e){let t=Ne.get(e);if(!t)return;y.current=!0,ee(jn(f?`understanding`:`default`)),V(``),oe(t),v(`discover`)}let r=new URLSearchParams(c);r.delete(`connector`),r.delete(`instance`),r.set(`tab`,n?`connected`:`discover`),u(r,{replace:!0})},[Ne,f,c,u,C.instances,C.loading]);let Pe=(0,X.useCallback)(async e=>{O(!0),w(e=>({...e,error:null}));try{let t=await U(e);re(Ze(t.definition,{packageName:t.packageName,version:t.version,permissions:t.permissions}))}catch(e){w(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{O(!1)}},[]),Fe=(0,X.useMemo)(()=>new Set(C.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[C.instances]),Ie=(0,X.useCallback)(async e=>{if(!Y||J===void 0)return;let t=Ee.filter(t=>t.clientKey!==e.clientKey);await Nt({sessionIdleTtlMinutes:Y.sessionIdleTtlMinutes,servers:t},Tt(J)),await Te(),await Oe()},[J,Ee,Oe,Y,Te]),Le=(0,X.useCallback)(()=>{me({mode:`add`,row:_n(Ee,Fe)})},[Ee,Fe]),Re=(0,X.useCallback)(async()=>{if(!(!Y||J===void 0||be)){xe(!0);try{await Nt({sessionIdleTtlMinutes:_e,servers:Ee},Tt(J)),await Te(),ge(!1)}finally{xe(!1)}}},[J,Ee,n.saved,Y,Te,_e,be]),ze=Ye(e=>e.setPageHeader),Be=Ye(e=>e.clearPageHeader),Ue=(0,X.useMemo)(()=>(0,Q.jsx)(yt,{onBrowseCatalog:()=>ke(`discover`),onAddCustomServer:Le,onOpenRuntimeSettings:()=>ge(!0),addLabel:t.addConnection,browseLabel:t.addFromCatalog,customLabel:t.addCustomServerAdvanced,settingsLabel:t.runtimeSettings}),[t,Le,ke]);(0,X.useLayoutEffect)(()=>(ze({startExtra:null,main:(0,Q.jsx)(`div`,{className:`min-w-0`,children:(0,Q.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.title})}),end:Ue}),()=>Be()),[Be,t.title,Ue,ze]);let We=(0,X.useMemo)(()=>C.instances.map(e=>({instance:e,value:hn(e,Ne.get(e.connectorId))})),[Ne,C.instances]),Ge=(0,X.useMemo)(()=>new Map(We.map(({instance:e,value:t})=>[e.instanceId,t])),[We]),Ke=(0,X.useMemo)(()=>C.instances.filter(e=>Fn(e,N)).sort((e,t)=>{let n={needs_setup:0,checking:1,ready:2},r=Ge.get(e.instanceId)?.state??`checking`,i=Ge.get(t.instanceId)?.state??`checking`;return n[r]-n[i]||e.displayName.localeCompare(t.displayName)}),[N,Ge,C.instances]),Je=(0,X.useMemo)(()=>Ee.filter(e=>In(e,N)),[N,Ee]),Xe=Ke.length+Je.length,Qe=(0,X.useMemo)(()=>C.catalog.filter(e=>e.source===`builtin`&&e.integrationStrategy?.preferred!==!1&&Mn(e)),[C.catalog]),$e=(0,X.useMemo)(()=>H===`builtin`?Qe:H===`all`?Rn([...Qe,...C.registryCatalog]):C.registryCatalog,[Qe,H,C.registryCatalog]),Z=(0,X.useMemo)(()=>{let e=f?$e.filter(e=>e.understanding?.mode===`activity`):$e;return Pn(G===`all`?e:e.filter(e=>pn(e).includes(G)),B,W)},[W,B,$e,f,G]),nt=(0,X.useMemo)(()=>fn.filter(e=>$e.some(t=>pn(t).includes(e))),[$e]);(0,X.useEffect)(()=>{G!==`all`&&!nt.includes(G)&&K(`all`)},[nt,G]);let at=_===`discover`&&H!==`builtin`&&!!(j&&k<j),$=(0,X.useMemo)(()=>C.instances.find(e=>e.instanceId===se)??le,[se,le,C.instances]),ct=(0,X.useMemo)(()=>[{value:`all`,label:t.discoverSourceAll},{value:On,label:t.discoverSourceBuiltin},...Ae.map(e=>({value:e.id,label:e.displayName}))],[t.discoverSourceAll,t.discoverSourceBuiltin,Ae]),lt=[{id:`connected`,label:t.tabConnected,count:De},{id:`discover`,label:t.tabDiscover}];return(0,Q.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,Q.jsxs)(`div`,{className:`flex w-full flex-col gap-6 px-3 py-6 sm:px-5 xl:px-6`,children:[o?null:(0,Q.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:t.tokenHint}),f?(0,Q.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,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:t.understandingSetupTitle}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:t.understandingSetupHint})]}),(0,Q.jsx)(g,{type:`button`,variant:`secondary`,className:`shrink-0`,onClick:()=>s(p),children:t.understandingSetupDone})]}):null,(0,Q.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`div`,{className:`border-b border-edge-subtle pb-3 dark:border-edge-subtle`,children:(0,Q.jsx)(et,{items:lt,activeTab:_,onChange:ke,ariaLabel:t.navAria,tabIdPrefix:`connectors-tab`,panelIdPrefix:`connectors-panel`,className:`flex-wrap`})}),C.error?(0,Q.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:C.error}):null,_===`connected`&&o?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,Q.jsx)(vt,{value:N,onChange:P,placeholder:t.connectedSearchPlaceholder,className:`max-w-xl`}),(0,Q.jsx)(He,{className:`size-9 shrink-0 p-0`,loading:C.loading,label:t.refreshConnections,title:t.refreshConnections,onClick:Oe})]}),C.peopleGraph&&(C.peopleGraph.people.length>0||F)?(0,Q.jsxs)(`section`,{className:`rounded-2xl border border-edge-subtle bg-surface-base p-5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(`div`,{className:`rounded-lg bg-accent-soft p-2 text-accent-fg`,children:(0,Q.jsx)(qe,{className:`size-4`,"aria-hidden":!0})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.peopleGraphTitle}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:t.peopleGraphHint.replace(`{{people}}`,String(C.peopleGraph.people.length)).replace(`{{sources}}`,String(new Set(C.peopleGraph.sourceEdges.map(e=>e.sourceInstanceId)).size))})]})]}),(0,Q.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Q.jsx)(vt,{value:F,onChange:L,placeholder:t.peopleGraphSearchPlaceholder}),R?(0,Q.jsx)(d,{className:`absolute right-3 top-2.5 size-4 animate-spin text-fg-subtle`,"aria-hidden":!0}):null]})]}),C.peopleGraph.people.length?(0,Q.jsx)(`div`,{className:`mt-4 grid gap-2 sm:grid-cols-2`,children:C.peopleGraph.people.slice(0,10).map(e=>{let t=[...new Set(C.peopleGraph.sourceEdges.filter(t=>t.personId===e.id).map(e=>e.toolkit??e.connectorId??e.sourceInstanceId))];return(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:e.label}),(0,Q.jsx)(`span`,{className:`shrink-0 text-xs text-fg-subtle`,children:e.mentionCount})]}),(0,Q.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-muted`,children:e.emails[0]??e.usernames[0]??e.roles.join(` · `)}),(0,Q.jsx)(`p`,{className:`mt-1 truncate text-[11px] text-fg-subtle`,children:t.join(` · `)})]},e.id)})}):(0,Q.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.peopleGraphSearchEmpty})]}):null,C.loading?(0,Q.jsx)(`div`,{className:`grid gap-3`,"aria-busy":`true`,"aria-label":t.loading,children:rt.slice(0,3).map(e=>(0,Q.jsx)(st,{},e))}):De===0?(0,Q.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connectionsEmpty}),(0,Q.jsx)(g,{type:`button`,variant:`primary`,className:`mt-4`,onClick:()=>ke(`discover`),children:t.addFromCatalog})]}):Xe===0?(0,Q.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.connectionsSearchEmpty}):(0,Q.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[Ke.map(e=>(0,Q.jsx)(gn,{instance:e,definition:Ne.get(e.connectorId),highlighted:e.instanceId===de,onOpenDetails:e=>{fe(null),ce(e.instanceId),ue(e)},onChanged:Oe,t},e.instanceId)),Je.map(e=>(0,Q.jsx)(Ut,{row:e,t:n,cs:t,onEdit:()=>me({mode:`edit`,row:structuredClone(e)}),onRemove:async()=>Ie(e)},e.clientKey))]})]}):null,_===`discover`&&o?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[f?null:(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`group`,"aria-label":t.taskFilterAria,children:[`all`,...nt].map(e=>(0,Q.jsx)(`button`,{type:`button`,className:h(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,G===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":G===e,onClick:()=>K(e),children:e===`all`?t.taskAll:t.connectorBenefitHeadings[e]},e))}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row lg:items-center`,children:[(0,Q.jsx)(vt,{value:B,onChange:V,placeholder:t.discoverSearchPlaceholder,className:`max-w-xl`}),(0,Q.jsxs)(`div`,{className:h(`grid min-w-0 grid-cols-1 gap-2 lg:ml-auto`,f?`lg:w-52`:`sm:grid-cols-2 lg:w-[26rem]`),children:[f?null:(0,Q.jsx)(l,{value:H,options:ct,placeholder:t.discoverSourceAll,allowEmpty:!1,ariaLabel:t.registrySourceAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:ee}),(0,Q.jsx)(l,{value:W,options:[{value:`name`,label:t.sortName},{value:`source`,label:t.sortSource}],placeholder:t.sortName,allowEmpty:!1,ariaLabel:t.sortAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:e=>te(e)})]})]}),(C.loading||T)&&Z.length===0?(0,Q.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":t.loading,children:rt.map(e=>(0,Q.jsx)(ot,{},e))}):Z.length===0?(0,Q.jsx)(`div`,{className:`rounded-2xl border border-dashed border-edge p-8 text-center text-sm text-fg-muted`,children:t.discoverEmpty}):(0,Q.jsxs)(`div`,{className:`relative`,children:[T?(0,Q.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":t.loading,children:(0,Q.jsx)(d,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,Q.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:Z.map(e=>(0,Q.jsx)(tt,{connector:e,installed:Me.has(e.id)||it(e,C.instances),onInstall:e=>{if(e.source===`store`){Pe(e.id);return}re(Ze(e))},onOpenDetails:e.source===`store`?void 0:oe,t},e.id))}),at?(0,Q.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,Q.jsxs)(g,{type:`button`,variant:`secondary`,disabled:T||D,onClick:()=>void je({page:k+1,append:!0}),children:[T?(0,Q.jsx)(d,{className:`size-4 animate-spin`}):null,t.loadMore]})}):null]})]}):null]}),q?(0,Q.jsx)(Ce,{draft:q,onChange:re,onClose:()=>re(null),t,onInstalled:async e=>{await Oe(),await Te(),fe(e.instanceId),ke(`connected`)}}):null,ae?(0,Q.jsx)(ht,{connector:ae,installed:Me.has(ae.id)||it(ae,C.instances),onClose:()=>oe(null),onInstall:e=>re(Ze(e)),t}):null,$?(0,Q.jsx)(dn,{instance:$,definition:Ne.get($.connectorId),onClose:()=>{ce(null),ue(null)},onChanged:Oe,t,mcp:n}):null,pe?(0,Q.jsx)(Dn,{open:!0,mode:pe.mode,initialRow:pe.row,existingCustomServers:Ee,sessionIdleTtlMinutes:_e,config:J,managedServerIds:Fe,t:n,cs:t,onClose:()=>me(null),onSaved:async()=>{await Te(),await Oe(),ke(`connected`)}},`${pe.mode}-${pe.row.clientKey}`):null,(0,Q.jsx)(_t,{open:he,sessionIdleTtlMinutes:_e,saving:be,onChange:ve,onSave:Re,onClose:()=>ge(!1),t,mcp:n})]})})}export{Bn as ConnectorsPage};