@xopcai/xopc 0.0.415 → 0.0.416

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 (251) hide show
  1. package/dist/browser-ext/_locales/en/messages.json +4 -1
  2. package/dist/browser-ext/_locales/zh_CN/messages.json +4 -1
  3. package/dist/browser-ext/dist/assets/{page-context-MuzjMBlJ.js → page-context-CVvmTWZb.js} +33 -9
  4. package/dist/browser-ext/dist/background.js +39 -10
  5. package/dist/browser-ext/dist/sidepanel.html +1 -1
  6. package/dist/browser-ext/dist/sidepanel.js +22 -3
  7. package/dist/browser-ext/manifest.json +1 -1
  8. package/dist/extensions/telegram/xopc.extension.json +1 -1
  9. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CJFwitU2.js → agent-avatar-dicebear-CufU7cqe.js} +1 -1
  10. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-DHDAcss8.js +1 -0
  11. package/dist/gateway/static/root/assets/agents-BV3dAoa0.js +77 -0
  12. package/dist/gateway/static/root/assets/{app-management-settings-panel-DgwqNi5i.js → app-management-settings-panel-D4-n1uBg.js} +1 -1
  13. package/dist/gateway/static/root/assets/{appearance-settings-C0wJfFyz.js → appearance-settings-Cgn4eNsX.js} +1 -1
  14. package/dist/gateway/static/root/assets/apps-page-BOYzD7Zz.js +1 -0
  15. package/dist/gateway/static/root/assets/{archive-plugin-Ch7wolHE.js → archive-plugin-B4btCsiV.js} +1 -1
  16. package/dist/gateway/static/root/assets/{automations-page-DK7AU79v.js → automations-page-yb1EL_3N.js} +1 -1
  17. package/dist/gateway/static/root/assets/automations-workspace-J7LJ4RuV.js +8 -0
  18. package/dist/gateway/static/root/assets/{binary-plugins-B4HcHYsC.js → binary-plugins-DQT9e258.js} +1 -1
  19. package/dist/gateway/static/root/assets/{block-editor-BQAWEZF-.js → block-editor-B50rU9tL.js} +4 -4
  20. package/dist/gateway/static/root/assets/browser-automations-page-BiQz6lJA.js +3 -0
  21. package/dist/gateway/static/root/assets/browser-settings-page-W9kuxBbE.js +3 -0
  22. package/dist/gateway/static/root/assets/capabilities-page-iXe87MdG.js +2 -0
  23. package/dist/gateway/static/root/assets/capabilities-settings-panel-CRLSXe7Z.js +8 -0
  24. package/dist/gateway/static/root/assets/{capability-header-actions-D4Yq35fD.js → capability-header-actions-BMnbzHms.js} +1 -1
  25. package/dist/gateway/static/root/assets/channels-CrRJkOKX.js +1 -0
  26. package/dist/gateway/static/root/assets/{chat-terminal-dock-zdMySdMm.js → chat-terminal-dock-Bd3af4gL.js} +2 -2
  27. package/dist/gateway/static/root/assets/{computer-settings-page-C5Z6Jr0p.js → computer-settings-page-DXfqy7xh.js} +1 -1
  28. package/dist/gateway/static/root/assets/{connector-service-page-Cxus0qrZ.js → connector-service-page-B-cw0CPU.js} +1 -1
  29. package/dist/gateway/static/root/assets/connectors-page-DbFxc0Fd.js +1 -0
  30. package/dist/gateway/static/root/assets/{date-picker-DuyyD6jz.js → date-picker-CqzXevH6.js} +1 -1
  31. package/dist/gateway/static/root/assets/{dependency-picker-BZN72rrk.js → dependency-picker-pgT4Gyaf.js} +1 -1
  32. package/dist/gateway/static/root/assets/{desktop-pet-settings-BcyP7Z6v.js → desktop-pet-settings-Dy_-i2L8.js} +1 -1
  33. package/dist/gateway/static/root/assets/{desktop-pet-BtvTIDCi.js → desktop-pet-zICeqw9c.js} +1 -1
  34. package/dist/gateway/static/root/assets/device-pairing-wizard-ByGbxqkg.js +1 -0
  35. package/dist/gateway/static/root/assets/{directory-picker-path-field-DOusKz-O.js → directory-picker-path-field-C-aQ7qoM.js} +1 -1
  36. package/dist/gateway/static/root/assets/{extension-debug-page-Bt4FwsFu.js → extension-debug-page-2NwpYkS5.js} +1 -1
  37. package/dist/gateway/static/root/assets/{extension-page-0vsxX3FB.js → extension-page-y9J0z7_Q.js} +1 -1
  38. package/dist/gateway/static/root/assets/{extension-settings-page-5Pt5_ELc.js → extension-settings-page-BtowusUh.js} +1 -1
  39. package/dist/gateway/static/root/assets/gateway-realtime-C52ghnBK.js +1 -0
  40. package/dist/gateway/static/root/assets/gateway-settings-BYSKzUMR.js +1 -0
  41. package/dist/gateway/static/root/assets/highlight-code-Cz6eeDH5.js +1 -0
  42. package/dist/gateway/static/root/assets/{highlighted-body-KQOG7T2V-Cbk7eMlg.js → highlighted-body-KQOG7T2V-BiAa8HKC.js} +1 -1
  43. package/dist/gateway/static/root/assets/home-page-Cd1BjYHj.js +2 -0
  44. package/dist/gateway/static/root/assets/{image-generation-api-CAS8QVla.js → image-generation-api-gBFro48x.js} +1 -1
  45. package/dist/gateway/static/root/assets/{imports-page-BCLBYzV1.js → imports-page-BZQpXgjj.js} +1 -1
  46. package/dist/gateway/static/root/assets/index-Cy16gQST.css +1 -0
  47. package/dist/gateway/static/root/assets/index-DRyGCING.js +710 -0
  48. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-CM_kt5XN.js → keyboard-shortcuts-settings-CYunR34k.js} +1 -1
  49. package/dist/gateway/static/root/assets/local-app-workbench-page-B_Ac1lly.js +1 -0
  50. package/dist/gateway/static/root/assets/{local-apps-page-BTSOChhk.js → local-apps-page-w-J5bY02.js} +1 -1
  51. package/dist/gateway/static/root/assets/logs-page-Dnjvvx2i.js +2 -0
  52. package/dist/gateway/static/root/assets/management-settings-w1EDwgLW.js +1 -0
  53. package/dist/gateway/static/root/assets/{media-plugins-DYQDjCVQ.js → media-plugins-CIx1koXw.js} +1 -1
  54. package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-DISkHmEC.js +1 -0
  55. package/dist/gateway/static/root/assets/note-detail-panel-CNkxMTFU.js +5 -0
  56. package/dist/gateway/static/root/assets/note-image-lightbox-D5GH2wuC.js +1 -0
  57. package/dist/gateway/static/root/assets/notes-page-DZgKqFBG.js +8 -0
  58. package/dist/gateway/static/root/assets/{page-context-capture-button-DVn_dU83.js → page-context-capture-button-DusR2Itk.js} +1 -1
  59. package/dist/gateway/static/root/assets/personal-page-CR5JFkQ9.js +1 -0
  60. package/dist/gateway/static/root/assets/{personal-settings-panel-C16Iqe7X.js → personal-settings-panel-B7undvlr.js} +1 -1
  61. package/dist/gateway/static/root/assets/phone-model-picker-fWDltRUJ.js +1 -0
  62. package/dist/gateway/static/root/assets/phone-settings-page-CsOirAiy.js +1 -0
  63. package/dist/gateway/static/root/assets/plugin-details-dialog-BOBVIB3j.js +1 -0
  64. package/dist/gateway/static/root/assets/{preview-open-alternatives-RlHk76TI.js → preview-open-alternatives-CMxjsKSw.js} +1 -1
  65. package/dist/gateway/static/root/assets/{product-open-page-Dh-HqLrE.js → product-open-page-CrlyJx5M.js} +1 -1
  66. package/dist/gateway/static/root/assets/{product-preview-content-c3K-4DWc.js → product-preview-content-B-Jhzi7W.js} +1 -1
  67. package/dist/gateway/static/root/assets/project-detail-page-DoYUbtcI.js +7 -0
  68. package/dist/gateway/static/root/assets/{projects-page-B8HAt9sD.js → projects-page-xGQd9oAZ.js} +1 -1
  69. package/dist/gateway/static/root/assets/refresh-cw-BRlGaq2w.js +1 -0
  70. package/dist/gateway/static/root/assets/remote-access-hub-Gs0Xkws9.js +1 -0
  71. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-Bwg7U7TR.js +1 -0
  72. package/dist/gateway/static/root/assets/{schema-form-CXO1B1k4.js → schema-form-ByzTNR_C.js} +1 -1
  73. package/dist/gateway/static/root/assets/{session-manager-CA1NkTR_.js → session-manager-B_h0jlLb.js} +1 -1
  74. package/dist/gateway/static/root/assets/sessions-page-XzK1ftbR.js +1 -0
  75. package/dist/gateway/static/root/assets/settings-advanced-gate-D_8Mvnog.js +1 -0
  76. package/dist/gateway/static/root/assets/{settings-form-section-BQxKmbbJ.js → settings-form-section-Brgd8IOV.js} +1 -1
  77. package/dist/gateway/static/root/assets/{settings-page-DvVMpKiA.js → settings-page-B6Mv02eg.js} +1 -1
  78. package/dist/gateway/static/root/assets/settings-page-header-BWyxJKOG.js +1 -0
  79. package/dist/gateway/static/root/assets/{settings-page-layout-B20AfmFG.js → settings-page-layout-DLHcS-0T.js} +1 -1
  80. package/dist/gateway/static/root/assets/setup-status-panel-DSCj5yis.js +1 -0
  81. package/dist/gateway/static/root/assets/{share-preview-page-XgZk8Oa1.js → share-preview-page-DF8Of0aZ.js} +1 -1
  82. package/dist/gateway/static/root/assets/shares-settings-DXNPe4Tl.js +1 -0
  83. package/dist/gateway/static/root/assets/{skill-api-CV-WT2hj.js → skill-api-CKCDCHLq.js} +1 -1
  84. package/dist/gateway/static/root/assets/skill-reload-api-BH0WF6Br.js +1 -0
  85. package/dist/gateway/static/root/assets/skills-page-DFWMVRW4.js +2 -0
  86. package/dist/gateway/static/root/assets/system-settings-panel-DB-ttubV.js +1 -0
  87. package/dist/gateway/static/root/assets/task-detail-page-BJY7c8wb.js +2 -0
  88. package/dist/gateway/static/root/assets/{task-result-evidence-D-gGKNX9.js → task-result-evidence-B-vt1BgK.js} +1 -1
  89. package/dist/gateway/static/root/assets/{tracing-settings-page-CQw3G-FB.js → tracing-settings-page-Dt51Z_ws.js} +1 -1
  90. package/dist/gateway/static/root/assets/{tunnel-api-B2HnCi0U.js → tunnel-api-Dok3t7Qe.js} +1 -1
  91. package/dist/gateway/static/root/assets/usage-page-lJym5G7F.js +1 -0
  92. package/dist/gateway/static/root/assets/{use-autosave-Dc0nwUpX.js → use-autosave-D4EMIB-V.js} +1 -1
  93. package/dist/gateway/static/root/assets/user-model-page-BXdNkITp.js +2 -0
  94. package/dist/gateway/static/root/assets/{voice-api-key-field-BSWXZkGa.js → voice-api-key-field-CO3KuanA.js} +1 -1
  95. package/dist/gateway/static/root/assets/{work-discovery-overlay-H3cdwq3l.js → work-discovery-overlay-BJRtgQM3.js} +1 -1
  96. package/dist/gateway/static/root/assets/wrench-DFb4r8bH.js +1 -0
  97. package/dist/gateway/static/root/assets/xopc-cloud-account-card-CS-_GxHV.js +1 -0
  98. package/dist/gateway/static/root/browser-setup-test.html +5 -0
  99. package/dist/gateway/static/root/browser-setup-test.js +7 -0
  100. package/dist/gateway/static/root/index.html +7 -4
  101. package/dist/package.js +1 -1
  102. package/dist/packages/gateway-contract/src/browser-setup.js +6 -0
  103. package/dist/packages/gateway-contract/src/index.js +4 -0
  104. package/dist/packages/gateway-contract/src/phone-setup.js +6 -0
  105. package/dist/packages/realtime-client/src/index.js +1 -0
  106. package/dist/packages/realtime-protocol/src/index.js +1 -0
  107. package/dist/src/agent/agent-manager.d.ts +4 -0
  108. package/dist/src/agent/agent-manager.js +12 -1
  109. package/dist/src/agent/embedded/tool-search-extension.js +14 -1
  110. package/dist/src/agent/service.d.ts +1 -0
  111. package/dist/src/agent/service.js +5 -0
  112. package/dist/src/agent/service.types.d.ts +2 -0
  113. package/dist/src/agent/tool-manuals/phone.d.ts +1 -1
  114. package/dist/src/agent/tool-manuals/phone.js +1 -1
  115. package/dist/src/agent/tool-manuals/xopc-configuration.d.ts +2 -0
  116. package/dist/src/agent/tool-manuals/xopc-configuration.js +25 -0
  117. package/dist/src/agent/tools/browser/tool/browser-use-tool.d.ts +2 -0
  118. package/dist/src/agent/tools/browser/tool/browser-use-tool.js +6 -2
  119. package/dist/src/agent/tools/factory.d.ts +3 -0
  120. package/dist/src/agent/tools/factory.js +11 -1
  121. package/dist/src/agent/tools/phone-use-tool.d.ts +1 -0
  122. package/dist/src/agent/tools/phone-use-tool.js +9 -1
  123. package/dist/src/agent/tools/tool-manual-tool.d.ts +1 -1
  124. package/dist/src/agent/tools/tool-manual-tool.js +3 -1
  125. package/dist/src/agent/tools/toolExposure.js +3 -0
  126. package/dist/src/agent/tools/xopc-use-tool.d.ts +4 -2
  127. package/dist/src/agent/tools/xopc-use-tool.js +40 -2
  128. package/dist/src/browser/drivers/browser-driver.d.ts +2 -2
  129. package/dist/src/browser/drivers/extension-driver.d.ts +2 -2
  130. package/dist/src/browser/drivers/extension-driver.js +6 -3
  131. package/dist/src/browser/providers/browser-ext-install.js +2 -1
  132. package/dist/src/browser/runtime/browser-runtime.d.ts +4 -1
  133. package/dist/src/browser/runtime/browser-runtime.js +29 -17
  134. package/dist/src/browser/setup/repository.d.ts +5 -0
  135. package/dist/src/browser/setup/repository.js +42 -0
  136. package/dist/src/browser/setup/service.d.ts +152 -0
  137. package/dist/src/browser/setup/service.js +404 -0
  138. package/dist/src/browser/setup/types.d.ts +38 -0
  139. package/dist/src/browser/setup/types.js +1 -0
  140. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  141. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  142. package/dist/src/config/schema.d.ts +2 -0
  143. package/dist/src/connectors/connected-source-understanding.js +1 -1
  144. package/dist/src/connectors/learning-coordinator.js +1 -1
  145. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  146. package/dist/src/gateway/hono/routes/browser-setup.d.ts +3 -0
  147. package/dist/src/gateway/hono/routes/browser-setup.js +114 -0
  148. package/dist/src/gateway/hono/routes/browser.d.ts +2 -1
  149. package/dist/src/gateway/hono/routes/browser.js +1 -1
  150. package/dist/src/gateway/hono/routes/connectors.js +7 -7
  151. package/dist/src/gateway/hono/routes/home.js +1 -1
  152. package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
  153. package/dist/src/gateway/hono/routes/phone-dependencies.js +1 -1
  154. package/dist/src/gateway/hono/routes/phone-setup.d.ts +7 -0
  155. package/dist/src/gateway/hono/routes/phone-setup.js +162 -0
  156. package/dist/src/gateway/hono/routes/phone.js +3 -7
  157. package/dist/src/gateway/hono/routes/public-gateway.js +3 -1
  158. package/dist/src/gateway/provider-model-setup.js +1 -1
  159. package/dist/src/gateway/service/config-coordinator.d.ts +2 -0
  160. package/dist/src/gateway/service.d.ts +5 -0
  161. package/dist/src/gateway/service.js +57 -12
  162. package/dist/src/gateway/xopc-cloud-capability-setup.js +7 -1
  163. package/dist/src/home-intelligence/host.js +2 -2
  164. package/dist/src/infra/update-restart.js +1 -1
  165. package/dist/src/phone/adb-driver.d.ts +2 -0
  166. package/dist/src/phone/adb-driver.js +35 -17
  167. package/dist/src/phone/contracts.d.ts +40 -0
  168. package/dist/src/phone/contracts.js +17 -4
  169. package/dist/src/phone/model-adapter.d.ts +59 -2
  170. package/dist/src/phone/model-adapter.js +107 -13
  171. package/dist/src/phone/numeric-entry.d.ts +31 -0
  172. package/dist/src/phone/numeric-entry.js +126 -0
  173. package/dist/src/phone/planning.d.ts +27 -0
  174. package/dist/src/phone/planning.js +79 -0
  175. package/dist/src/phone/recovery.d.ts +37 -0
  176. package/dist/src/phone/recovery.js +81 -0
  177. package/dist/src/phone/repository.d.ts +1 -0
  178. package/dist/src/phone/repository.js +3 -0
  179. package/dist/src/phone/runtime.js +232 -54
  180. package/dist/src/phone/semantic-controls.d.ts +13 -0
  181. package/dist/src/phone/semantic-controls.js +76 -0
  182. package/dist/src/phone/setup/service.d.ts +148 -0
  183. package/dist/src/phone/setup/service.js +251 -0
  184. package/dist/src/providers/presentation.js +2 -2
  185. package/dist/src/providers/xopc-cloud-model-source.js +6 -2
  186. package/dist/src/realtime/runtime.js +1 -1
  187. package/dist/src/storage/sqlite/schema.d.ts +2 -2
  188. package/dist/src/storage/sqlite/schema.js +7 -7
  189. package/dist/src/storage/sqlite/schema.sql +10 -0
  190. package/dist/src/storage/sqlite/upgrades/260_browser_setup.sql +9 -0
  191. package/dist/src/user-context/sources/index.js +1 -1
  192. package/dist/src/work-discovery/service.js +2 -2
  193. package/package.json +6 -6
  194. package/skills/tools/configure-xopc/SKILL.md +47 -0
  195. package/skills/tools/configure-xopc/references/browser/acceptance.md +31 -0
  196. package/skills/tools/configure-xopc/references/browser/chrome-extension.md +19 -0
  197. package/skills/tools/configure-xopc/references/browser/overview.md +22 -0
  198. package/skills/tools/configure-xopc/references/browser/permissions.md +25 -0
  199. package/skills/tools/configure-xopc/references/browser/troubleshooting.md +24 -0
  200. package/skills/tools/configure-xopc/references/phone/acceptance.md +25 -0
  201. package/skills/tools/configure-xopc/references/phone/aliyun.md +29 -0
  202. package/skills/tools/configure-xopc/references/phone/dependencies.md +18 -0
  203. package/skills/tools/configure-xopc/references/phone/local.md +19 -0
  204. package/skills/tools/configure-xopc/references/phone/models.md +18 -0
  205. package/skills/tools/configure-xopc/references/phone/overview.md +30 -0
  206. package/skills/tools/configure-xopc/references/phone/troubleshooting.md +24 -0
  207. package/skills/tools/configure-xopc/references/scene-index.md +12 -0
  208. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-DclyJr1N.js +0 -1
  209. package/dist/gateway/static/root/assets/agents-jhErNtzi.js +0 -77
  210. package/dist/gateway/static/root/assets/apps-page-C0LcnI4h.js +0 -1
  211. package/dist/gateway/static/root/assets/automations-workspace-CBxiV34x.js +0 -8
  212. package/dist/gateway/static/root/assets/browser-automations-page-vJIrTxdi.js +0 -3
  213. package/dist/gateway/static/root/assets/browser-settings-page-in5Roh_E.js +0 -3
  214. package/dist/gateway/static/root/assets/capabilities-page-CiGx8wpQ.js +0 -2
  215. package/dist/gateway/static/root/assets/capabilities-settings-panel-a8kqjzQu.js +0 -8
  216. package/dist/gateway/static/root/assets/channels-C_CxcjKT.js +0 -1
  217. package/dist/gateway/static/root/assets/connectors-page-DCBO2CxK.js +0 -1
  218. package/dist/gateway/static/root/assets/device-pairing-wizard-Ctbgr50F.js +0 -1
  219. package/dist/gateway/static/root/assets/gateway-realtime-DkWCHVzI.js +0 -1
  220. package/dist/gateway/static/root/assets/gateway-settings-BsVOcmV5.js +0 -1
  221. package/dist/gateway/static/root/assets/highlight-code-C8eS9949.js +0 -1
  222. package/dist/gateway/static/root/assets/home-page-BZDZnmyc.js +0 -2
  223. package/dist/gateway/static/root/assets/index-Bys6njTY.js +0 -710
  224. package/dist/gateway/static/root/assets/index-Vsf0bj5e.css +0 -1
  225. package/dist/gateway/static/root/assets/local-app-workbench-page-Dk87jtcc.js +0 -1
  226. package/dist/gateway/static/root/assets/logs-page-D3gVdm8S.js +0 -2
  227. package/dist/gateway/static/root/assets/management-settings-BQNYFE4J.js +0 -1
  228. package/dist/gateway/static/root/assets/mermaid-MCJ5UELQ-ChweJKTv.js +0 -1
  229. package/dist/gateway/static/root/assets/note-detail-panel-CYKwUCte.js +0 -5
  230. package/dist/gateway/static/root/assets/note-image-lightbox-BTSZb9ZT.js +0 -1
  231. package/dist/gateway/static/root/assets/notes-page-CJ5nhWfL.js +0 -8
  232. package/dist/gateway/static/root/assets/personal-page-DcW14lqn.js +0 -1
  233. package/dist/gateway/static/root/assets/phone-dependencies-card-D3l9uPFM.js +0 -1
  234. package/dist/gateway/static/root/assets/phone-model-picker-DOv38vBn.js +0 -1
  235. package/dist/gateway/static/root/assets/phone-settings-page-DUHp1q_9.js +0 -1
  236. package/dist/gateway/static/root/assets/plugin-details-dialog-BpfgDlVa.js +0 -1
  237. package/dist/gateway/static/root/assets/project-detail-page-GD8TxKad.js +0 -7
  238. package/dist/gateway/static/root/assets/remote-access-hub-D3el7lHK.js +0 -1
  239. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-Dbskk6RG.js +0 -1
  240. package/dist/gateway/static/root/assets/sessions-page-07liaSHH.js +0 -1
  241. package/dist/gateway/static/root/assets/settings-advanced-gate-BGjU8rfN.js +0 -1
  242. package/dist/gateway/static/root/assets/settings-page-header-CYpuTXUW.js +0 -1
  243. package/dist/gateway/static/root/assets/setup-status-panel-DKo_VTx-.js +0 -1
  244. package/dist/gateway/static/root/assets/shares-settings-BODFqK8k.js +0 -1
  245. package/dist/gateway/static/root/assets/skill-reload-api-Ce6OUk2C.js +0 -1
  246. package/dist/gateway/static/root/assets/skills-page-B7ehOIML.js +0 -2
  247. package/dist/gateway/static/root/assets/system-settings-panel-CxJkZRT4.js +0 -1
  248. package/dist/gateway/static/root/assets/task-detail-page-CxRR0QuW.js +0 -2
  249. package/dist/gateway/static/root/assets/usage-page-uUEkO38r.js +0 -1
  250. package/dist/gateway/static/root/assets/user-model-page-ICUutbKL.js +0 -2
  251. package/dist/gateway/static/root/assets/xopc-cloud-account-card-CvT_W6YS.js +0 -1
@@ -1 +0,0 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{u as i}from"./chunk-KS7C4IRE-BvcCCgTW.js";import{s as a,t as o}from"./popover-select-DGKUpVsz.js";import{t as s}from"./circle-check-C23XjkUj.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./loader-circle-CifKLtgG.js";import{t as u}from"./messages-BYq0cPbn.js";import{t as d}from"./cn-0WouolD0.js";import{a as f,i as p,l as m,n as h,o as g}from"./locale-store-B7s2Hb35.js";import{i as _}from"./vendor-swr-BIWyz7Rc.js";import{t as v}from"./button-aIC072nz.js";import{t as y}from"./skeleton-BI5TyibZ.js";import{i as b,o as x}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{An as S,Bc as C,Dl as w,Fl as T,Fn as E,Hc as D,Ic as O,In as k,Jc as A,Kr as j,L as M,Lc as N,Ln as P,Rc as F,S as I,Sa as L,Vc as R,bn as ee,il as z,jd as te,ks as ne,pl as re,ta as ie,ya as ae,zc as oe,zl as se}from"./index-Bys6njTY.js";import{n as ce}from"./settings-page-header-CYpuTXUW.js";import"./settings-page-layout-B20AfmFG.js";import{t as le}from"./schema-form-CXO1B1k4.js";var B=e(t(),1),V=n();async function ue(){return(await g(p(`/api/channels/status`))).payload?.channels||[]}function de(){return p(`/api/channels/status`)}var fe=ue;function pe(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 me=e(M(),1),H=r();async function U(e){let t=await f(p(`/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 W(e){return e?.type===`poll`&&e.phase===`done`}function G(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function K(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function q(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,B.useMemo)(()=>pe(e),[e]),o=(0,B.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[u,f]=(0,B.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,B.useEffect)(()=>{f({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let p=(0,B.useCallback)(async(n,i)=>{f(e=>({...e,busy:!0,error:null}));try{let a=await U({channelId:e.id,actionId:n,locale:t,input:i});f(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.conversationId?{actionId:a.statusAction,conversationId:a.conversationId,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){f(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,B.useEffect)(()=>{let t=K(u.payload,e.id);if(!t){f(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return f(e=>e.generatedQr?{...e,generatedQr:null}:e),me.toDataURL(t,{width:220,margin:1}).then(e=>{n||f(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,u.payload]),(0,B.useEffect)(()=>{let n=u.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||U({channelId:e.id,actionId:n.actionId,locale:t,input:{conversationId:n.conversationId}}).then(async e=>{i||(f(t=>({...t,payload:e,poll:W(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),W(e)&&window.clearInterval(a))}).catch(e=>{i||f(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,u.poll]);let m=a?.[1].label??(e.configured?n.reconnect:n.connect),h=e.actions?.[`doctor.run`]?.label??n.diagnose,g=G(u.payload),_=K(u.payload,e.id),b=_?u.generatedQr:q(u.payload),x=a?.[1].result===`qr`&&(u.busy||u.payload?.type===`qr`||u.payload?.type===`poll`),S=u.payload?.type===`form`?u.payload:null,C=u.payload?.type===`diagnostics`?u.payload.checks:null;return(0,H.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:d(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,H.jsxs)(v,{type:`button`,variant:`primary`,disabled:u.busy,onClick:()=>void p(a[0]),children:[u.busy?(0,H.jsx)(l,{className:`size-4 animate-spin`}):(0,H.jsx)(se,{className:`size-4`}),m]}):null,e.actions?.[`doctor.run`]?(0,H.jsxs)(v,{type:`button`,variant:`secondary`,disabled:u.busy,onClick:()=>void p(`doctor.run`),children:[(0,H.jsx)(re,{className:`size-4`}),h]}):null]})]}),g?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:g}):null,u.error?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:u.error}):null,x?(0,H.jsxs)(`div`,{className:d(`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,H.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:b?(0,H.jsx)(`img`,{src:b,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,H.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,H.jsx)(y,{className:`size-48 rounded-md`})})}),(0,H.jsxs)(`div`,{className:d(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[b?(0,H.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,H.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,H.jsx)(y,{className:`h-4 w-48 max-w-full`}),(0,H.jsx)(y,{className:`h-4 w-36 max-w-full`})]}),_?(0,H.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:_,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,H.jsx)(c,{className:`size-3.5`})]}):null]})]}):null,u.payload?.type===`poll`&&u.payload.phase===`done`?(0,H.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,H.jsx)(s,{className:u.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,H.jsx)(`span`,{className:u.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:u.payload.message??(u.payload.ok?n.complete:n.failed)})]}):null,S?(0,H.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,H.jsx)(le,{schema:S.schema,values:u.formDraft,onChange:e=>f(t=>({...t,formDraft:e})),disabled:u.busy,labels:o}),(0,H.jsx)(v,{type:`button`,variant:`primary`,disabled:u.busy,onClick:()=>void p(S.submitAction,u.formDraft),children:n.saveSetup})]}):null,C?(0,H.jsx)(`div`,{className:`mt-4 space-y-2`,children:C.map((e,t)=>(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,H.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,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ge=40;function J(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function _e(e,t){return e.find(e=>e.id===J(t))?.agentId?.trim().toLowerCase()??``}function ve(e,t,n){let r=J(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`?d(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-overlay shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,b):d(`xopc-dialog-content 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)]`,b,`rounded-2xl border border-edge bg-surface-overlay outline-none dark:border-edge`)}function Se(e){let t=(0,V.c)(33),{presentation:n,open:r,onOpenChange:i,title:o,description:s,srTitle:c,srDescription:l,closeAriaLabel:u,children:f,footer:p,wide:m,headerExtra:h}=e,g=m===void 0?!1:m,_=n===`drawer`,[y,b]=(0,B.useState)(null),S;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,H.jsx)(C,{className:d(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,x)}),t[0]=S):S=t[0];let w;t[1]!==n||t[2]!==g?(w=xe(n,g),t[1]=n,t[2]=g,t[3]=w):w=t[3];let T;t[4]===c?T=t[5]:(T=c?(0,H.jsx)(D,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=T);let E;t[6]===l?E=t[7]:(E=l?(0,H.jsx)(oe,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=E);let k;t[8]!==u||t[9]!==s||t[10]!==h||t[11]!==_||t[12]!==o?(k=_?(0,H.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[o?(0,H.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:o}):null,s?(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:s}):null]}),(0,H.jsx)(N,{asChild:!0,children:(0,H.jsx)(v,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,H.jsx)(A,{className:`size-5`,strokeWidth:1.75})})})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(N,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:d(ne,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,H.jsx)(A,{className:`size-4`})})}),h]}),t[8]=u,t[9]=s,t[10]=h,t[11]=_,t[12]=o,t[13]=k):k=t[13];let j=_?`p-4`:`p-6`,M;t[14]===j?M=t[15]:(M=d(`min-h-0 flex-1 overflow-y-auto`,j),t[14]=j,t[15]=M);let P;t[16]!==f||t[17]!==M?(P=(0,H.jsx)(`div`,{className:M,children:f}),t[16]=f,t[17]=M,t[18]=P):P=t[18];let I;t[19]!==p||t[20]!==y||t[21]!==T||t[22]!==E||t[23]!==k||t[24]!==P?(I=(0,H.jsxs)(a,{layer:`modal`,portalContainer:y,children:[T,E,k,P,p]}),t[19]=p,t[20]=y,t[21]=T,t[22]=E,t[23]=k,t[24]=P,t[25]=I):I=t[25];let L;t[26]!==I||t[27]!==w?(L=(0,H.jsxs)(R,{children:[S,(0,H.jsx)(F,{ref:b,className:w,onOpenAutoFocus:Ce,children:I})]}),t[26]=I,t[27]=w,t[28]=L):L=t[28];let ee;return t[29]!==i||t[30]!==r||t[31]!==L?(ee=(0,H.jsx)(O,{open:r,onOpenChange:i,children:L}),t[29]=i,t[30]=r,t[31]=L,t[32]=ee):ee=t[32],ee}function Ce(e){return e.preventDefault()}var we=(0,B.memo)(function(e){let t=(0,V.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,H.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,H.jsx)(ie,{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,H.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,V.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,H.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,H.jsx)(v,{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,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,H.jsx)(v,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,H.jsx)(v,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let y;t[17]!==d||t[18]!==p||t[19]!==_?(y=(0,H.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=y):y=t[20];let b;return t[21]!==y||t[22]!==u?(b=(0,H.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-overlay 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 p(`/api/channels/catalog?locale=${encodeURIComponent(e)}`)}async function De(e){return(await g(Ee(e))).payload?.channels??[]}function Oe(e,t){let n=(0,V.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}=_(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,V.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,B.useEffect)(i,a)}function Ne(e){return e?p(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Pe(e){return(await g(p(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Fe=[`enabled`],Ie=`max-w-7xl`,Le=`px-4 pb-7 pt-3 sm:px-6 lg:px-8 lg:pb-9 lg:pt-4`;async function Re(){let e=await g(p(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function ze(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Be(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function Y(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 Ve(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function He(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Ue(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 We(e){if(!e)return[];let t=e.uiHints??{},n=X(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=Y(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=new Set([`dmPolicy`,`groupPolicy`,`allowFrom`,`groupAllowFrom`]),a=[...Object.keys(t).filter(e=>!e.includes(`*`)&&i.has(e.split(`.`).at(-1)??``)),...Object.keys(X(e.configSchema?.properties)?e.configSchema.properties:{}).filter(e=>i.has(e))],o=Object.entries(t).filter(([,e])=>!X(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([...o,...a,...n,...r])).filter(e=>!Fe.includes(e))}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function Ge(e,t){let n={...Z(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(!X(r)||!X(r[n]))break;let o=X(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Z(r[n]),properties:{}}),e===t.length-1){o[n]=Z(r[n]);break}i=r[n],a=o[n]}}return n}function Ke(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ke(n)&&delete t[e];return Object.keys(t).length===0}function qe(e,t){let n=Z(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!X(i))break;if(e===t.length-1){delete i[n];break}if(!X(i[n]))break;r=i[n]}}return Ke(n),n}function Je(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Q(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function Ye(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Xe(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 Ze(e,t,n){let r=[],i=Y(e);if(i.issues.length>0&&r.push($(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Xe(e,Q(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 Qe(e,t){let n=Y(e),r=pe(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 $e(e,t){let n=pe(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function et(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 $(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,n]=(0,B.useState)(!1),r=(0,B.useMemo)(()=>!e.ui?.icon||t?null:new URL(p(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${ze(e.ui.icon)}`)).toString(),[t,e.extensionId,e.ui?.icon]);return(0,H.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:r?(0,H.jsx)(`img`,{src:r,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>n(!0)}):(0,H.jsx)(L,{sourceChannel:e.id,className:`size-7`})})}function nt(e){let t=(0,V.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=d(`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`,f;t[5]===u?f=t[6]:(f=d(`size-5 rounded-full bg-white shadow-surface transition-transform`,u),t[5]=u,t[6]=f);let p;t[7]===f?p=t[8]:(p=(0,H.jsx)(`span`,{className:f}),t[7]=f,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,H.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,V.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:s,onOpen:c,onToggle:u,onRestart:f}=e,p;t[0]===n?p=t[1]:(p=Y(n),t[0]=n,t[1]=p);let m=p,h,g,_,y,b,x,S;if(t[2]!==a||t[3]!==s||t[4]!==r||t[5]!==n||t[6]!==c||t[7]!==f||t[8]!==u||t[9]!==i||t[10]!==m.enabled||t[11]!==m.ready){let e=Ze(n,r,s),o=et(n,s);h=!m.enabled&&m.ready?u:i===`stopped`?f: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 l;t[19]===n?l=t[20]:(l=(0,H.jsx)(tt,{entry:n}),t[19]=n,t[20]=l);let p;t[21]===n.label?p=t[22]:(p=(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=p);let v;t[23]===i?v=t[24]:(v=d(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Ue(i)),t[23]=i,t[24]=v);let C;t[25]!==s||t[26]!==i?(C=Ve(i,s),t[25]=s,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==v||t[29]!==C?(w=(0,H.jsx)(`span`,{className:v,children:C}),t[28]=v,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==p?(T=(0,H.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]!==l?(E=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[l,T]}),t[34]=T,t[35]=l,t[36]=E):E=t[36];let D=m.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]!==u||t[42]!==m.enabled||t[43]!==O?(k=(0,H.jsx)(nt,{checked:D,disabled:a,label:O,onToggle:u}),t[40]=a,t[41]=u,t[42]=m.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(S=(0,H.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],g=`button`,_=c,y=`mt-5 min-h-[6.25rem] text-left`,b=m.ready?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,H.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map(at)}):null]}):(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:s.cardSetupTitle}),(0,H.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??$e(n,s)}),o.length>0?(0,H.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]=f,t[8]=u,t[9]=i,t[10]=m.enabled,t[11]=m.ready,t[12]=h,t[13]=g,t[14]=_,t[15]=y,t[16]=b,t[17]=x,t[18]=S}else h=t[12],g=t[13],_=t[14],y=t[15],b=t[16],x=t[17],S=t[18];let C;t[48]!==g||t[49]!==_||t[50]!==y||t[51]!==b?(C=(0,H.jsx)(`button`,{type:g,onClick:_,className:y,children:b}),t[48]=g,t[49]=_,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,H.jsx)(l,{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:Qe(n,s),t[56]=s,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==h||t[62]!==T||t[63]!==E||t[64]!==w?(D=(0,H.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,H.jsxs)(v,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:h,disabled:w,children:[T,E]})}),t[61]=h,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,H.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,H.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function at(e){return(0,H.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function ot(e){let t=(0,V.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:o,ch:c,onRestart:u,onCheck:f,onManageConnection:p}=e,m=n===`running`?s:n===`stopped`||n===`needs_setup`?te:l,h=n===`running`&&`text-emerald-600 dark:text-emerald-400`,g=n===`stopped`&&`text-red-600 dark:text-red-400`,_=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]!==h||t[1]!==g||t[2]!==_||t[3]!==y||t[4]!==b?(x=d(`mt-0.5 size-5 shrink-0`,h,g,_,y,b),t[0]=h,t[1]=g,t[2]=_,t[3]=y,t[4]=b,t[5]=x):x=t[5];let S;t[6]!==m||t[7]!==x?(S=(0,H.jsx)(m,{className:x}),t[6]=m,t[7]=x,t[8]=S):S=t[8];let C;t[9]===c.connectionStatus?C=t[10]:(C=(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:c.connectionStatus}),t[9]=c.connectionStatus,t[10]=C);let w;t[11]!==c||t[12]!==n?(w=He(n,c),t[11]=c,t[12]=n,t[13]=w):w=t[13];let E;t[14]===w?E=t[15]:(E=(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:w}),t[14]=w,t[15]=E);let D;t[16]!==E||t[17]!==C?(D=(0,H.jsxs)(`div`,{children:[C,E]}),t[16]=E,t[17]=C,t[18]=D):D=t[18];let O;t[19]!==D||t[20]!==S?(O=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[S,D]}),t[19]=D,t[20]=S,t[21]=O):O=t[21];let k=i||r,A;t[22]===i?A=t[23]:(A=i?(0,H.jsx)(l,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=A);let j=i?c.checkingConnection:c.checkConnection,M;t[24]!==f||t[25]!==k||t[26]!==A||t[27]!==j?(M=(0,H.jsxs)(v,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:k,onClick:f,children:[A,j]}),t[24]=f,t[25]=k,t[26]=A,t[27]=j,t[28]=M):M=t[28];let N;t[29]!==c.restartChannel||t[30]!==c.restartingChannel||t[31]!==i||t[32]!==u||t[33]!==r||t[34]!==n?(N=n===`stopped`?(0,H.jsxs)(v,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:u,children:[r?(0,H.jsx)(l,{className:`size-4 animate-spin`}):(0,H.jsx)(T,{className:`size-4`}),r?c.restartingChannel:c.restartChannel]}):null,t[29]=c.restartChannel,t[30]=c.restartingChannel,t[31]=i,t[32]=u,t[33]=r,t[34]=n,t[35]=N):N=t[35];let P;t[36]!==o||t[37]!==c.connectionOptions||t[38]!==c.hideConnectionOptions||t[39]!==i||t[40]!==p||t[41]!==r||t[42]!==a?(P=o?(0,H.jsx)(v,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:p,children:a?c.hideConnectionOptions:c.connectionOptions}):null,t[36]=o,t[37]=c.connectionOptions,t[38]=c.hideConnectionOptions,t[39]=i,t[40]=p,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,H.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]!==O||t[49]!==F?(I=(0,H.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[O,F]})}),t[48]=O,t[49]=F,t[50]=I):I=t[50],I}function st(e){let t=(0,V.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=Y(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl bg-amber-50 px-4 py-3 text-amber-950 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,H.jsx)(z,{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,H.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,H.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,H.jsx)(`li`,{children:$(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,H.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,H.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,H.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,H.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function ct({channelId:e,onHeaderActionChange:t}){let n=h(e=>e.language),r=u(n),a=m(e=>!!e.conversationId),s=i(),l=P(e),g=Oe(a,n),v=g.entries,{data:y,mutate:b,isValidating:x}=_(a?de():null,fe,{revalidateOnFocus:!0}),{data:C,mutate:T}=_(a?`channels-config-map`:null,Re,{revalidateOnFocus:!1}),D=C?.channels??{},O=C?.bindings??[],{data:A}=_(a?`channel-routing-agents`:null,ae,{revalidateOnFocus:!1}),M=(0,B.useMemo)(()=>v.find(e=>e.id===l),[l,v]),N=M?Be(M):null,{data:F,mutate:L}=_(a&&N?Ne(N):null,()=>Pe(N)),[R,z]=(0,B.useState)(null),[te,ne]=(0,B.useState)(!1),[re,ie]=(0,B.useState)(null),[oe,se]=(0,B.useState)(null),[V,ue]=(0,B.useState)(!1),[me,U]=(0,B.useState)(null),[W,G]=(0,B.useState)(null),K=R??F??{},q=r.channelsSettings,ge=(0,B.useMemo)(()=>M?.configSchema??{type:`object`,properties:{}},[M?.configSchema]),J=(0,B.useMemo)(()=>qe(ge,Fe),[ge]),ye=(0,B.useMemo)(()=>We(M),[M]),xe=(0,B.useMemo)(()=>Ge(J,ye),[ye,J]),Ce=(0,B.useMemo)(()=>qe(J,ye),[ye,J]),Ee=(0,B.useMemo)(()=>Je(xe),[xe]),De=M?W??_e(O,M.id):``,ke=(0,B.useMemo)(()=>(A?.items??[]).map(e=>{let t=S(e,r.agentsSettings);return{value:e.id,label:t===e.id?t:`${t} · ${e.id}`}}),[A?.items,r.agentsSettings]),je=A?.items.find(e=>e.id===A.defaultId),ze=je?S(je,r.agentsSettings):A?.defaultId??``,He=(0,B.useMemo)(()=>({defaultBooleanLabel:q.schemaBooleanDefault,unsupportedArrayType:q.schemaUnsupportedArrayType,arrayAddPlaceholder:q.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>q.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[q]),X=(0,B.useMemo)(()=>new Map((y??[]).map(e=>[e.name,e])),[y]),Z=y!==void 0,Ke=(0,B.useCallback)(e=>be(e,X.get(e.id),Z),[X,Z]),Q=(0,B.useCallback)(async()=>{await Promise.all([g.mutate(),b()])},[g,b]);Me((0,B.useCallback)(e=>{let t=Ae(e);t&&b(t,!1)},[b]),a);let Ye=(0,B.useMemo)(()=>a?{secondary:(0,H.jsx)(we,{ch:q,refreshing:g.isValidating||x,saveOk:!1,onRefresh:()=>void Q()})}:null,[g.isValidating,q,a,x,Q]);(0,B.useLayoutEffect)(()=>(t?.(Ye),()=>t?.(null)),[Ye,t]);let Xe=(0,B.useCallback)(e=>{s(k(e)),z(null),G(null),U(null)},[s]),Ze=(0,B.useCallback)(()=>{s(E),z(null),G(null),U(null)},[s]),Qe=(0,B.useCallback)(async e=>{se(e.id),U(null);try{let t=await f(p(`/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){U(e instanceof Error?e.message:String(e))}finally{se(null)}},[Q]);(0,B.useEffect)(()=>{G(null),ue(!1)},[M?.id]);let $e=(0,B.useCallback)(async()=>{if(!M||!R&&W===null)return!1;let e=Be(M);ne(!0),U(null);try{let t=await f(p(`/api/config`),{method:`PATCH`,body:JSON.stringify({...R?{channels:{[e]:R}}:{},...W===null?{}:{bindings:ve(O,M.id,W)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return R&&await L(R,!1),await T(),await g.mutate(),z(null),G(null),!0}catch(e){return U(e instanceof Error?e.message:String(e)),!1}finally{ne(!1)}},[M,W,O,g,R,T,L]),et=(0,B.useCallback)(async e=>{let t=Y(e),n=Be(e),r=M?.id===e.id?R:null;if(!t.enabled&&!t.ready&&!r){Xe(e.id);return}ie(e.id),U(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await f(p(`/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 g.mutate(),await T(),await b(),M?.id===e.id&&(await L(),z(null))}catch(e){U(e instanceof Error?e.message:String(e))}finally{ie(null)}},[M?.id,g,R,T,L,b,Xe]),$=M?.ui?.modal,it=$?.placement!==`replace-config`,at=M?Ke(M):`checking`,ct=M?!Y(M).ready||V:!1;return a?(0,H.jsxs)(ce,{gap:`gap-4`,className:Ie,padding:Le,children:[g.isLoading?(0,H.jsx)(ee,{sections:2}):g.error?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(g.error)}):(0,H.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:v.map(e=>(0,H.jsx)(rt,{entry:e,config:D[Be(e)]?.config,runtime:Ke(e),busy:re===e.id,restarting:oe===e.id,ch:q,onOpen:()=>Xe(e.id),onToggle:()=>void et(e),onRestart:()=>void Qe(e)},e.id))}),me?(0,H.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:me}):null,(0,H.jsx)(Se,{presentation:`modal`,open:!!M,onOpenChange:e=>{e||Ze()},closeAriaLabel:q.close,srTitle:M?.label??q.selectChannel,srDescription:M?.description,wide:!0,footer:M?(0,H.jsx)(Te,{ch:q,dirty:!!R||W!==null,saving:te,onCancel:Ze,onDiscard:()=>{z(null),G(null)},onSave:$e}):null,children:M?(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,H.jsx)(tt,{entry:M}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:M.label}),(0,H.jsx)(`span`,{className:d(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Ue(at)),children:Ve(at,q)})]}),(0,H.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,H.jsx)(`span`,{className:`min-w-0 truncate`,children:!Y(M).ready&&pe(M)?.[1].result===`qr`?q.scanLoginHint.replace(`{{channel}}`,M.label):M.description}),M.docsPath?(0,H.jsxs)(`a`,{href:M.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[q.docs,(0,H.jsx)(c,{className:`size-3.5`})]}):null]})]})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,H.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:Y(M).enabled?q.enabledLabel:q.disabledLabel}),(0,H.jsx)(nt,{checked:Y(M).enabled,disabled:re===M.id,label:q.toggleChannel.replace(`{{channel}}`,M.label),onToggle:()=>void et(M)})]})]})}),(0,H.jsx)(ot,{runtime:at,restarting:oe===M.id,checking:x,showConnectionOptions:V,canManageConnection:Y(M).ready&&$?.placement!==`replace-config`,ch:q,onRestart:()=>void Qe(M),onCheck:()=>void Q(),onManageConnection:()=>ue(e=>!e)}),(0,H.jsx)(st,{entry:M,ch:q}),ct&&$?.placement!==`replace-config`?(0,H.jsx)(he,{entry:M,locale:n,messages:q,compact:!0,onChanged:async()=>{await L(),await Q(),await T()}},M.id):null,$?.entrypoint&&$.placement===`before-config`?(0,H.jsx)(j,{extensionId:M.extensionId,extensionName:M.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:M.id,entry:M,config:K}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,H.jsx)(j,{extensionId:M.extensionId,extensionName:M.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:M.id,entry:M,config:K}}):null,it&&Ee?(0,H.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:q.basicConfiguration}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:q.basicConfigurationHint})]}),(0,H.jsx)(le,{schema:xe,values:K,onChange:e=>z(e),disabled:te,labels:He})]}):null,(0,H.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,H.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,H.jsx)(w,{className:`size-4 text-fg-muted`}),q.messageHandling]}),(0,H.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:q.agentRouting}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:q.messageHandlingHint})]}),(0,H.jsx)(o,{value:De,options:ke,placeholder:q.agentRoutingSelect,emptyLabel:q.agentRoutingDefault.replace(`{{agent}}`,ze||q.agentRoutingSelect),ariaLabel:q.agentRouting,disabled:te||!A,onChange:e=>G(e)})]})]}),it&&Je(Ce)?(0,H.jsx)(I,{title:q.advancedConfiguration,summary:q.messageHandlingHint,children:(0,H.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,H.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,H.jsx)(w,{className:`size-4 text-fg-muted`}),q.advancedConfiguration]}),(0,H.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,H.jsx)(le,{schema:Ce,values:K,onChange:e=>z(e),disabled:te,labels:He})})]})}):null,me?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:me}):null]}):null})]}):(0,H.jsx)(ce,{gap:`gap-3`,className:Ie,padding:Le,children:(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:q.tokenRequired})})}export{ct as ChannelsSettingsPanel};
@@ -1 +0,0 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{m as i,u as a}from"./chunk-KS7C4IRE-BvcCCgTW.js";import{t as o}from"./chevron-down-ccbiQQz_.js";import{n as s,r as c,t as l}from"./popover-select-DGKUpVsz.js";import{t as u}from"./circle-check-C23XjkUj.js";import{t as d}from"./ellipsis-0k4rZLoy.js";import{t as f}from"./external-link-DjqjBmc3.js";import{t as p}from"./eye-CABVeTq0.js";import{t as m}from"./loader-circle-CifKLtgG.js";import{t as h}from"./messages-BYq0cPbn.js";import{t as g}from"./cn-0WouolD0.js";import{i as _,l as v,n as y,o as b}from"./locale-store-B7s2Hb35.js";import{n as x}from"./copy-to-clipboard-HOJ79TWv.js";import{i as S}from"./vendor-swr-BIWyz7Rc.js";import{t as C}from"./button-aIC072nz.js";import{t as w}from"./skeleton-BI5TyibZ.js";import{n as T,r as E}from"./gateway-config-swr-fQKBHBi1.js";import{n as D}from"./electron-env-Dit0bHgy.js";import{$a as O,$o as k,As as A,B as j,Bc as M,Bn as N,Cs as P,Dd as F,Ds as I,E as L,El as R,Es as z,F as B,G as V,H,Ha as U,Hc as ee,Hn as W,Ic as te,Il as G,Iu as ne,Jc as re,K as ie,Lc as ae,M as oe,Md as K,Ml as se,Mo as q,N as J,Ol as ce,Os as le,Qo as ue,R as de,Rc as Y,Sd as X,Ss as fe,T as pe,Ts as me,U as he,Ul as ge,Un as _e,V as ve,Vc as ye,Vn as be,W as Z,Wl as xe,Xo as Se,Yc as Ce,Zo as we,aa as Te,al as Ee,ao as De,as as Oe,bs as ke,ca as Ae,cs as je,dl as Me,ds as Ne,es as Pe,fd as Fe,fs as Ie,gs as Le,hs as Re,is as ze,jd as Be,ld as Ve,ll as He,ls as Ue,na as We,ns as Ge,oa as Ke,ps as qe,rs as Je,ru as Ye,sa as Xe,ss as Ze,ts as Qe,ua as $e,us as et,vs as tt,ws as nt,xd as rt,xs as it,yo as at,ys as ot,zc as st}from"./index-Bys6njTY.js";import{n as ct,t as lt}from"./capability-header-actions-D4Yq35fD.js";import{t as ut}from"./connector-service-page-Cxus0qrZ.js";import{t as dt}from"./number-input-DDeqHK-G.js";var Q=e(t(),1),ft=n(),$=r();function pt(e){let t=(0,ft.c)(57),{connector:n,installed:r,onInstall:i,onOpenDetails:a,t:o}=e,s,c,l,d,f,p;if(t[0]!==n||t[1]!==r||t[2]!==i||t[3]!==a||t[4]!==o){let e=n.capabilities.filter(mt),m=e.slice(0,2),h=Math.max(0,e.length-m.length),_=o.connect,v;t[11]!==n||t[12]!==o?(v=he(n,o),t[11]=n,t[12]=o,t[13]=v):v=t[13];let y=v,b=n.verificationLevel===`verified`?o.connectorVerified:n.verificationLevel===`beta`?o.connectorBeta:n.verificationLevel===`experimental`?o.connectorExperimental:null,x;t[14]!==_||t[15]!==n||t[16]!==i?(x=e=>(0,$.jsxs)(C,{type:`button`,variant:`secondary`,className:g(`h-8 justify-center px-2.5 text-xs font-medium`,e),onClick:()=>i(n),children:[(0,$.jsx)(Ye,{className:`size-4`}),_]}),t[14]=_,t[15]=n,t[16]=i,t[17]=x):x=t[17],s=x,p=`group flex min-h-[8.75rem] flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,c=`flex min-w-0 flex-1 flex-col`;let S;t[18]===n?S=t[19]:(S=(0,$.jsx)(ve,{connector:n}),t[18]=n,t[19]=S);let w;t[20]!==n||t[21]!==a?(w=a?(0,$.jsx)(`button`,{type:`button`,className:`block max-w-full truncate text-left text-sm font-semibold text-fg hover:underline`,onClick:()=>a(n),children:n.displayName}):(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,children:n.displayName}),t[20]=n,t[21]=a,t[22]=w):w=t[22];let T;t[23]===b?T=t[24]:(T=b?(0,$.jsx)(`span`,{className:`mt-1 inline-flex rounded-full border border-edge px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:b}):null,t[23]=b,t[24]=T);let E;t[25]!==T||t[26]!==w?(E=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[w,T]}),t[25]=T,t[26]=w,t[27]=E):E=t[27];let D;t[28]!==E||t[29]!==S?(D=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[S,E]}),t[28]=E,t[29]=S,t[30]=D):D=t[30];let O;t[31]!==r||t[32]!==s?(O=r?null:(0,$.jsx)(`div`,{className:`hidden shrink-0 items-center gap-1 sm:flex`,children:s()}),t[31]=r,t[32]=s,t[33]=O):O=t[33];let k;t[34]!==r||t[35]!==o.connectedBadge?(k=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(u,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[34]=r,t[35]=o.connectedBadge,t[36]=k):k=t[36];let A;t[37]!==O||t[38]!==k?(A=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start gap-2`,children:[O,k]}),t[37]=O,t[38]=k,t[39]=A):A=t[39],t[40]!==D||t[41]!==A?(l=(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[D,A]}),t[40]=D,t[41]=A,t[42]=l):l=t[42],t[43]===y?d=t[44]:(d=(0,$.jsx)(`p`,{className:`mt-3 line-clamp-2 text-sm leading-6 text-fg-muted`,title:y,children:y}),t[43]=y,t[44]=d),f=m.length>0?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[m.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-muted`,children:o.connectorCapabilityLabels[e]??e},e)),h>0?(0,$.jsxs)(`span`,{className:`rounded-md bg-surface-base px-2 py-0.5 text-[11px] text-fg-subtle`,children:[`+`,h]}):null]}):null,t[0]=n,t[1]=r,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=d,t[9]=f,t[10]=p}else s=t[5],c=t[6],l=t[7],d=t[8],f=t[9],p=t[10];let m;t[45]!==c||t[46]!==l||t[47]!==d||t[48]!==f?(m=(0,$.jsxs)(`div`,{className:c,children:[l,d,f]}),t[45]=c,t[46]=l,t[47]=d,t[48]=f,t[49]=m):m=t[49];let h;t[50]!==r||t[51]!==s?(h=r?null:(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 border-t border-edge pt-3 sm:hidden`,children:s(`w-full`)}),t[50]=r,t[51]=s,t[52]=h):h=t[52];let _;return t[53]!==p||t[54]!==m||t[55]!==h?(_=(0,$.jsxs)(`div`,{className:p,children:[m,h]}),t[53]=p,t[54]=m,t[55]=h,t[56]=_):_=t[56],_}function mt(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}var ht=[`c0`,`c1`,`c2`,`c3`,`c4`,`c5`];function gt(e,t){return t.some(t=>t.connectorId===e.id)}var _t=`animate-pulse motion-reduce:animate-none rounded-md bg-surface-hover dark:bg-surface-active/50`;function vt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(`div`,{className:g(`size-10 shrink-0 rounded-xl`,_t)}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsx)(`div`,{className:`flex h-full min-h-[9.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface`,"aria-hidden":!0,children:(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`div`,{className:g(`h-4 min-w-0 flex-1`,_t)}),(0,$.jsx)(`div`,{className:g(`h-8 w-[4.5rem] shrink-0 rounded-lg`,_t)})]}),(0,$.jsx)(`div`,{className:g(`h-3 w-full`,_t)}),(0,$.jsx)(`div`,{className:g(`h-3 w-[88%]`,_t)})]})]})}),e[1]=n):n=e[1],n}function yt(){let e=(0,ft.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(w,{className:`size-9 shrink-0 rounded-lg`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4`,"aria-hidden":!0,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[t,(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-2`,children:[(0,$.jsx)(w,{className:`h-4 w-28 max-w-full`}),(0,$.jsx)(w,{className:`h-3 w-20 max-w-full`})]})]}),(0,$.jsx)(w,{className:`mt-2 h-3 w-48 max-w-full`}),(0,$.jsx)(w,{className:`ml-auto mt-auto h-3 w-16`})]}),e[1]=n):n=e[1],n}var bt=[`understand`,`act`,`reach`];function xt(e){if(e.benefits?.length)return[...new Set(e.benefits)];let t=new Set(e.capabilities),n=[e.id,e.displayName,...e.tags??[]].join(` `).toLowerCase(),r=[];return(t.has(`context`)||t.has(`memory_source`)||t.has(`resources`)||e.category===`docs`||e.category===`data`||/notion|drive|document|confluence|airtable|database|knowledge|wiki/.test(n))&&r.push(`understand`),t.has(`tools`)&&r.push(`act`),(t.has(`channel`)||/slack|telegram|discord|teams|mail|message|wechat|weixin/.test(n))&&r.push(`reach`),r.length?[...new Set(r)]:[`act`]}function St(e){return xt(e)[0]??`act`}function Ct(e,t){let n=t?St(t):`act`,r=e.connectionStatus===`connected`||e.status===`connected`||e.usage.lastHealthStatus===`ok`,i=e.status===`not_configured`||e.status===`failed`||e.status===`degraded`||e.status===`unauthorized`||e.connectionStatus===`unauthorized`||e.connectionStatus===`error`,a=n===`understand`?e.usage.lastResourceCount:n===`act`?e.usage.lastToolCount:void 0;return{benefit:n,state:r?`ready`:i?`needs_setup`:`checking`,availableCount:a}}function wt(e,t){return t.connectorCapabilityLabels[e]??e}function Tt(e,t){if(e.runtime.type===`mcp`)return Z(t.connectorRuntimeMcp,{serverId:e.runtime.serverId});let n=e.runtime.type===`composio`?e.runtime.toolkit:e.runtime.type===`cli`?e.runtime.adapterId:e.runtime.sourceKind;return Z(t.connectorRuntimeGeneric,{runtime:e.runtime.type,id:n??e.runtime.type})}function Et(e,t){return e.auth.mode===`cli`?t.connectorAuthCli:e.auth.mode===`oauth`?t.connectorAuthOAuth:e.auth.mode===`apiKey`?t.connectorAuthApiKey:t.connectorAuthNone}function Dt(e){let t=(0,ft.c)(133),{connector:n,installed:r,onClose:i,onInstall:a,t:o}=e,s;t[0]!==n||t[1]!==o?(s=he(n,o),t[0]=n,t[1]=o,t[2]=s):s=t[2];let c=s,l,d,f,p,m,h,_,v,y,b,x,S,w,T,E,D;if(t[3]!==n||t[4]!==c||t[5]!==r||t[6]!==i||t[7]!==o){let e=xt(n),a;t[24]!==n.setup.config||t[25]!==n.setup.secrets?(a=[...(n.setup.secrets??[]).filter(At),...(n.setup.config??[]).filter(kt)],t[24]=n.setup.config,t[25]=n.setup.secrets,t[26]=a):a=t[26];let s=a,C=n.capabilities.filter(Ot);f=te,_=!0,t[27]===i?v=t[28]:(v=e=>{e||i()},t[27]=i,t[28]=v),d=ye,t[29]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,$.jsx)(M,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),t[29]=h):h=t[29],l=Y,t[30]===Symbol.for(`react.memo_cache_sentinel`)?(p=g(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex h-[min(100vh-2rem,42rem)] w-[min(100%-2rem,min(92vw,44rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),t[30]=p):p=t[30];let O;t[31]===n?O=t[32]:(O=(0,$.jsx)(ve,{connector:n,size:`lg`}),t[31]=n,t[32]=O);let k;t[33]===n.displayName?k=t[34]:(k=(0,$.jsx)(ee,{className:`text-base font-semibold text-fg`,children:n.displayName}),t[33]=n.displayName,t[34]=k);let j;t[35]!==r||t[36]!==o.connectedBadge?(j=r?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-emerald-500/10 px-2 py-0.5 text-[11px] font-medium text-emerald-700 dark:text-emerald-300`,children:[(0,$.jsx)(u,{className:`size-3`,"aria-hidden":!0}),o.connectedBadge]}):null,t[35]=r,t[36]=o.connectedBadge,t[37]=j):j=t[37];let N;t[38]!==k||t[39]!==j?(N=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[k,j]}),t[38]=k,t[39]=j,t[40]=N):N=t[40];let P;t[41]===c?P=t[42]:(P=(0,$.jsx)(st,{className:`mt-1 line-clamp-3 text-sm leading-6 text-fg-muted`,children:c}),t[41]=c,t[42]=P);let F;t[43]!==N||t[44]!==P?(F=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[N,P]}),t[43]=N,t[44]=P,t[45]=F):F=t[45];let I;t[46]!==O||t[47]!==F?(I=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[O,F]}),t[46]=O,t[47]=F,t[48]=I):I=t[48];let L;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(L=g(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,A.focusRingPanel),t[49]=L):L=t[49];let R;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(re,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),t[50]=R):R=t[50];let z;t[51]===o.modalClose?z=t[52]:(z=(0,$.jsx)(ae,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:L,"aria-label":o.modalClose,children:R})}),t[51]=o.modalClose,t[52]=z),t[53]!==I||t[54]!==z?(m=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-5 py-5 sm:px-6`,children:[I,z]}),t[53]=I,t[54]=z,t[55]=m):m=t[55],T=`min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-5 sm:px-6`,E=e.length?(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:o.connectorWhyConnect}),(0,$.jsx)(`div`,{className:`mt-3 divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorBenefitHeadings[e]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:o.connectorBenefitHints[e]})]},e))})]}):null;let B;t[56]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(ne,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`,"aria-hidden":!0}),t[56]=B):B=t[56];let V;t[57]===o.detailPermissions?V=t[58]:(V=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.detailPermissions}),t[57]=o.detailPermissions,t[58]=V);let H;t[59]!==n||t[60]!==o?(H=Et(n,o),t[59]=n,t[60]=o,t[61]=H):H=t[61];let U;t[62]===H?U=t[63]:(U=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:H}),t[62]=H,t[63]=U);let W;t[64]!==V||t[65]!==U?(W=(0,$.jsxs)(`div`,{className:`flex items-start gap-3 border-b border-edge-subtle px-4 py-3`,children:[B,(0,$.jsxs)(`div`,{children:[V,U]})]}),t[64]=V,t[65]=U,t[66]=W):W=t[66];let G;t[67]===o.connectorSetupTitle?G=t[68]:(G=(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:o.connectorSetupTitle}),t[67]=o.connectorSetupTitle,t[68]=G);let ie;t[69]!==s.length||t[70]!==o.connectorRequiredInputsCount||t[71]!==o.connectorSetupNone?(ie=s.length?Z(o.connectorRequiredInputsCount,{count:String(s.length)}):o.connectorSetupNone,t[69]=s.length,t[70]=o.connectorRequiredInputsCount,t[71]=o.connectorSetupNone,t[72]=ie):ie=t[72];let oe;t[73]===ie?oe=t[74]:(oe=(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:ie}),t[73]=ie,t[74]=oe);let K;t[75]!==G||t[76]!==oe?(K=(0,$.jsxs)(`div`,{className:`px-4 py-3`,children:[G,oe]}),t[75]=G,t[76]=oe,t[77]=K):K=t[77],t[78]!==W||t[79]!==K?(D=(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[W,K]}),t[78]=W,t[79]=K,t[80]=D):D=t[80],S=`rounded-xl border border-edge bg-surface-base`,t[81]===o.connectorTechnicalDetails?w=t[82]:(w=(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:o.connectorTechnicalDetails}),t[81]=o.connectorTechnicalDetails,t[82]=w),y=`space-y-5 border-t border-edge-subtle px-4 py-4`;let se;t[83]===Symbol.for(`react.memo_cache_sentinel`)?(se=(0,$.jsx)(ce,{className:`size-3.5`,"aria-hidden":!0}),t[83]=se):se=t[83];let q;t[84]===o.connectorRuntimeTitle?q=t[85]:(q=(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[se,o.connectorRuntimeTitle]}),t[84]=o.connectorRuntimeTitle,t[85]=q);let J;t[86]!==n||t[87]!==o?(J=Tt(n,o),t[86]=n,t[87]=o,t[88]=J):J=t[88];let le;t[89]===J?le=t[90]:(le=(0,$.jsx)(`p`,{className:`mt-1 break-words text-xs text-fg-subtle`,children:J}),t[89]=J,t[90]=le),t[91]!==q||t[92]!==le?(b=(0,$.jsxs)(`div`,{children:[q,le]}),t[91]=q,t[92]=le,t[93]=b):b=t[93],x=C.length?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,$.jsx)(`span`,{className:`rounded-md bg-surface-panel px-2 py-1 text-xs text-fg-muted`,children:wt(e,o)},e))}):null,t[3]=n,t[4]=c,t[5]=r,t[6]=i,t[7]=o,t[8]=l,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=_,t[15]=v,t[16]=y,t[17]=b,t[18]=x,t[19]=S,t[20]=w,t[21]=T,t[22]=E,t[23]=D}else l=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],_=t[14],v=t[15],y=t[16],b=t[17],x=t[18],S=t[19],w=t[20],T=t[21],E=t[22],D=t[23];let O;t[94]!==y||t[95]!==b||t[96]!==x?(O=(0,$.jsxs)(`div`,{className:y,children:[b,x]}),t[94]=y,t[95]=b,t[96]=x,t[97]=O):O=t[97];let k;t[98]!==O||t[99]!==S||t[100]!==w?(k=(0,$.jsxs)(`details`,{className:S,children:[w,O]}),t[98]=O,t[99]=S,t[100]=w,t[101]=k):k=t[101];let j;t[102]!==k||t[103]!==T||t[104]!==E||t[105]!==D?(j=(0,$.jsxs)(`div`,{className:T,children:[E,D,k]}),t[102]=k,t[103]=T,t[104]=E,t[105]=D,t[106]=j):j=t[106];let N;t[107]===o.modalClose?N=t[108]:(N=(0,$.jsx)(ae,{asChild:!0,children:(0,$.jsx)(C,{variant:`secondary`,children:o.modalClose})}),t[107]=o.modalClose,t[108]=N);let P;t[109]!==n||t[110]!==r||t[111]!==i||t[112]!==a||t[113]!==o.connect?(P=r?null:(0,$.jsxs)(C,{variant:`primary`,onClick:()=>{a(n),i()},children:[(0,$.jsx)(Ye,{className:`size-4`}),o.connect]}),t[109]=n,t[110]=r,t[111]=i,t[112]=a,t[113]=o.connect,t[114]=P):P=t[114];let F;t[115]!==N||t[116]!==P?(F=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge-subtle px-5 py-4 sm:px-6`,children:[N,P]}),t[115]=N,t[116]=P,t[117]=F):F=t[117];let I;t[118]!==l||t[119]!==p||t[120]!==m||t[121]!==j||t[122]!==F?(I=(0,$.jsxs)(l,{className:p,children:[m,j,F]}),t[118]=l,t[119]=p,t[120]=m,t[121]=j,t[122]=F,t[123]=I):I=t[123];let L;t[124]!==d||t[125]!==h||t[126]!==I?(L=(0,$.jsxs)(d,{children:[h,I]}),t[124]=d,t[125]=h,t[126]=I,t[127]=L):L=t[127];let R;return t[128]!==f||t[129]!==_||t[130]!==v||t[131]!==L?(R=(0,$.jsx)(f,{open:_,onOpenChange:v,children:L}),t[128]=f,t[129]=_,t[130]=v,t[131]=L,t[132]=R):R=t[132],R}function Ot(e){return!e.startsWith(`runtime.`)&&!e.startsWith(`auth.`)}function kt(e){return e.required}function At(e){return e.required}var jt=(0,Q.memo)(function(e){let t=(0,ft.c)(45),{onRefresh:n,refreshing:r,refreshLabel:i,onBrowseCatalog:a,onAddCustomServer:s,addLabel:c,browseLabel:l,customLabel:u,serviceLabel:f,moreActionsLabel:p}=e,[h,_]=(0,Q.useState)(!1),v;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(v=g(`touch-target flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-fg outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 data-[highlighted]:bg-surface-hover`,A.transition),t[0]=v):v=t[0];let y=v,b;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(ge,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),t[1]=b):b=t[1];let x;t[2]===c?x=t[3]:(x=(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:c}),t[2]=c,t[3]=x);let S;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(o,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t[4]=S):S=t[4];let w;t[5]!==c||t[6]!==x?(w=(0,$.jsx)($e,{asChild:!0,children:(0,$.jsxs)(C,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":c,children:[b,x,S]})}),t[5]=c,t[6]=x,t[7]=w):w=t[7];let T;t[8]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,$.jsx)(Me,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[8]=T):T=t[8];let E;t[9]!==l||t[10]!==a?(E=(0,$.jsxs)(Ke,{className:y,onSelect:a,children:[T,l]}),t[9]=l,t[10]=a,t[11]=E):E=t[11];let D;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(Ce,{className:`size-4 text-fg-muted`,strokeWidth:1.75,"aria-hidden":!0}),t[12]=D):D=t[12];let O;t[13]!==u||t[14]!==s?(O=(0,$.jsxs)(Ke,{className:y,onSelect:s,children:[D,u]}),t[13]=u,t[14]=s,t[15]=O):O=t[15];let k;t[16]!==E||t[17]!==O?(k=(0,$.jsx)(Xe,{children:(0,$.jsxs)(Te,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[E,O]})}),t[16]=E,t[17]=O,t[18]=k):k=t[18];let j;t[19]!==k||t[20]!==w?(j=(0,$.jsxs)(Ae,{children:[w,k]}),t[19]=k,t[20]=w,t[21]=j):j=t[21];let M;t[22]===h?M=t[23]:(M=(0,$.jsx)(ut,{open:h,onOpenChange:_,hideTrigger:!0}),t[22]=h,t[23]=M);let N;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(d,{className:`size-4`,"aria-hidden":!0}),t[24]=N):N=t[24];let P;t[25]===p?P=t[26]:(P=(0,$.jsx)($e,{asChild:!0,children:(0,$.jsx)(C,{type:`button`,variant:`secondary`,className:`size-9 shrink-0 p-0`,"aria-label":p,title:p,children:N})}),t[25]=p,t[26]=P);let F;t[27]!==n||t[28]!==i||t[29]!==r?(F=n?(0,$.jsxs)(Ke,{className:y,disabled:r,onSelect:n,children:[r?(0,$.jsx)(m,{className:`size-4 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),i]}):null,t[27]=n,t[28]=i,t[29]=r,t[30]=F):F=t[30];let I,L;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(I=()=>_(!0),L=(0,$.jsx)(R,{className:`size-4 text-fg-muted`,"aria-hidden":!0}),t[31]=I,t[32]=L):(I=t[31],L=t[32]);let z;t[33]===f?z=t[34]:(z=(0,$.jsxs)(Ke,{className:y,onSelect:I,children:[L,f]}),t[33]=f,t[34]=z);let B;t[35]!==F||t[36]!==z?(B=(0,$.jsx)(Xe,{children:(0,$.jsxs)(Te,{className:`z-50 min-w-[14rem] rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover dark:border-edge`,sideOffset:6,align:`end`,children:[F,z]})}),t[35]=F,t[36]=z,t[37]=B):B=t[37];let V;t[38]!==P||t[39]!==B?(V=(0,$.jsxs)(Ae,{children:[P,B]}),t[38]=P,t[39]=B,t[40]=V):V=t[40];let H;return t[41]!==j||t[42]!==M||t[43]!==V?(H=(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[j,M,V]}),t[41]=j,t[42]=M,t[43]=V,t[44]=H):H=t[44],H});function Mt(e=``,t=``){return{clientKey:crypto.randomUUID(),key:e,value:t}}var Nt=/^([^:=]+)[:=](.*)$/;function Pt(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return It(e)}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=Nt.exec(t);r&&n.push(Mt(r[1].trim(),r[2].trim()))}return n.length>0?n:null}function Ft(e){let t=Object.create(null);for(let n of e){let e=n.key.trim();e&&(t[e]=n.reference??n.value)}return Object.keys(t).length>0?t:void 0}function It(e){if(!e||typeof e!=`object`)return[Mt()];let t=Object.entries(e).map(([e,t])=>typeof t==`object`&&t&&!Array.isArray(t)?{...Mt(e),reference:t}:Mt(e,t==null?``:String(t)));return t.length>0?t:[Mt()]}function Lt(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e.xopcConnector;return!!(t&&typeof t==`object`&&!Array.isArray(t)&&t.managed===!0)}function Rt(e){let t=e.trim();if(!t)return;if(t.startsWith(`[`)){let e=JSON.parse(t);if(!Array.isArray(e)||e.some(e=>typeof e!=`string`))throw Error(`Command arguments must be a JSON array of strings.`);return e}let n=[],r=``,i=``,a=!1;for(let e=0;e<t.length;e++){let o=t[e];o===`\\`&&t[e+1]&&i!==`'`&&/[\s"'\\]/.test(t[e+1])?(r+=t[++e],a=!0):i?o===i?i=``:r+=o:o===`"`||o===`'`?(i=o,a=!0):/\s/.test(o)?a&&=(n.push(r),r=``,!1):(r+=o,a=!0)}if(i)throw Error(`Command arguments contain an unclosed quote.`);return a&&n.push(r),n}function zt(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Bt(e){let t={...e.extra,exposure:e.exposure};if(e.displayName?.trim()?t.displayName=e.displayName.trim():delete t.displayName,delete t.command,delete t.args,delete t.env,delete t.cwd,delete t.url,delete t.headers,delete t.type,e.transport===`stdio`){t.type=`stdio`,t.command=e.command.trim();let n=Rt(e.argsText);if(n&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envEntries){let n=new Set;for(let t of e.envEntries)if(!(!t.key.trim()&&!t.value&&!t.reference)){if(!t.key.trim()||n.has(t.key.trim()))throw Error(`Environment variable names must be non-empty and unique.`);n.add(t.key.trim())}let r=Ft(e.envEntries);r&&(t.env=r)}else e.envJson.trim()&&(t.env=zt(e.envJson));delete t.oauth,delete t.auth}else{t.type=`http`,t.url=e.url.trim();let n=Ft(e.headers);n&&(t.headers=n);let r={...t.oauth??{}};e.oauthClientId.trim()?r.clientId=e.oauthClientId.trim():delete r.clientId,Object.keys(r).length?t.oauth=r:delete t.oauth}return e.timeout===void 0?delete t.timeout:t.timeout=e.timeout,t}function Vt(e,t){let n=t.oauth;return{clientKey:e,id:e,displayName:typeof t.displayName==`string`?t.displayName:``,transport:typeof t.url==`string`?`streamable-http`:`stdio`,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?JSON.stringify(t.args):``,envJson:t.env?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:``,url:typeof t.url==`string`?t.url:``,headers:It(t.headers),oauthClientId:typeof n?.clientId==`string`?n.clientId:``,timeout:typeof t.timeout==`number`?t.timeout:void 0,exposure:t.exposure??`codemode`,extra:t}}function Ht(e,t){let n=`mcp`;try{n=e.transport===`streamable-http`?new URL(e.url).hostname:e.command.split(/[\\/]/).pop()||n}catch{}let r=n.replace(/[^a-zA-Z0-9_-]+/g,`_`).replace(/^_+|_+$/g,``)||`mcp`,i=new Set([...t].map(e=>e.replace(/-/g,`_`))),a=r;for(let e=2;i.has(a.replace(/-/g,`_`));e++)a=`${r}_${e}`;return a}function Ut(e){let t=e.trim(),n=new URL(/^[a-z][a-z\d+.-]*:/i.test(t)&&!/^[^/]+:\d+(?:[/?#]|$)/.test(t)?t:`${/^(localhost|127\.0\.0\.1)(:|\/|$)/i.test(t)?`http`:`https`}://${t}`);if(![`http:`,`https:`].includes(n.protocol)||n.username||n.password)throw Error(`Use an HTTP or HTTPS MCP address without embedded credentials.`);return n.href}function Wt(e){let t=JSON.parse(e);if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Expected a JSON object.`);let n=t.mcpServers??t.mcp?.servers??t.servers;if(n!==void 0&&(!n||typeof n!=`object`||Array.isArray(n)))throw Error(`Expected a server configuration object.`);let r=n?Object.entries(n):[[``,t]];if(!r.length)throw Error(`No MCP servers found.`);return r.map(([e,t])=>{if(!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid MCP server configuration.`);let n=t;if(typeof n.url!=`string`&&typeof n.command!=`string`)throw Error(`The configuration needs an MCP URL or command.`);if(n.args!==void 0&&(!Array.isArray(n.args)||n.args.some(e=>typeof e!=`string`)))throw Error(`Command arguments must be strings.`);let r=Vt(e,n);return r.clientKey=crypto.randomUUID(),r.url&&=Ut(r.url),r})}function Gt(e=``){return{clientKey:crypto.randomUUID(),id:e,transport:`streamable-http`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[],oauthClientId:``,timeout:void 0,exposure:`codemode`,extra:{}}}function Kt(e){let t=e?.mcp?.servers??{};return{servers:Object.entries(t).filter(([,e])=>!Lt(e)).map(([e,t])=>Vt(e,t)).sort((e,t)=>e.id.localeCompare(t.id))}}function qt(e){return Bt(e)}async function Jt(e,t){return(await b(_(`/api/mcp/servers/${encodeURIComponent(e)}/tools`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload.tools}async function Yt(e,t,n,r){return(await b(_(`/api/mcp/drafts`),{method:`POST`,signal:r,body:JSON.stringify({serverId:e.id,sourceServerId:t,expectedServer:n,server:Bt(e)})})).payload}async function Xt(e,t){return(await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/probe`),{method:`POST`,signal:AbortSignal.any([t,AbortSignal.timeout(95e3)])})).payload}async function Zt(e){await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}`),{method:`DELETE`})}async function Qt(e,t=!1){let n=await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/commit`),{method:`POST`,body:JSON.stringify({enable:t})});return T(),n.payload}async function $t(e){return(await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`POST`})).payload}async function en(e,t){return(await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{signal:t})).payload}async function tn(e){await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/auth`),{method:`DELETE`})}async function nn(e,t){await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/auth/redirect`),{method:`POST`,body:JSON.stringify({url:t})})}async function rn(e,t){return(await b(_(`/api/mcp/drafts/${encodeURIComponent(e)}/tools`),{signal:t})).payload.tools}async function an(e){let t=await b(_(`/api/mcp/servers`),{signal:e});return Object.fromEntries(t.payload.servers.filter(e=>e.lastCheck&&Number.isFinite(Date.parse(e.lastCheck.checkedAt))).map(e=>[e.id,e.lastCheck]))}async function on(e){let t=await b(_(`/api/mcp/servers/${encodeURIComponent(e.id)}`),{method:`DELETE`,body:JSON.stringify({expectedServer:e.extra})});return T(),t.payload}function sn(e){let t=(0,ft.c)(111),{serverId:n,displayName:r,returnFocusTo:i,draftId:a,t:o,onClose:s,onConfigure:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=[],t[0]=l):l=t[0];let[u,d]=(0,Q.useState)(l),[f,p]=(0,Q.useState)(!0),[m,h]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(0),b=(0,Q.useRef)(!1),x;t[1]!==a||t[2]!==n||t[3]!==o.setupAccessDenied||t[4]!==o.setupConflict||t[5]!==o.setupGatewayUnauthorized||t[6]!==o.setupRateLimited||t[7]!==o.toolsLoadFailed?(x=()=>{let e=new AbortController,t=!0;return p(!0),h(``),d([]),(a?rn(a,e.signal):Jt(n,e.signal)).then(e=>{t&&d(e)}).catch(e=>{let n=e?.status;t&&h(n===401?o.setupGatewayUnauthorized:n===403?o.setupAccessDenied:n===429?o.setupRateLimited:n===404||n===409?o.setupConflict:o.toolsLoadFailed)}).finally(()=>{t&&p(!1)}),()=>{t=!1,e.abort()}},t[1]=a,t[2]=n,t[3]=o.setupAccessDenied,t[4]=o.setupConflict,t[5]=o.setupGatewayUnauthorized,t[6]=o.setupRateLimited,t[7]=o.toolsLoadFailed,t[8]=x):x=t[8];let S;t[9]!==a||t[10]!==v||t[11]!==n||t[12]!==o?(S=[n,a,v,o],t[9]=a,t[10]=v,t[11]=n,t[12]=o,t[13]=S):S=t[13],(0,Q.useEffect)(x,S);let w,T,E,D,O,k,A,j,N,P,F,I,L;if(t[14]!==r||t[15]!==m||t[16]!==f||t[17]!==s||t[18]!==c||t[19]!==g||t[20]!==i||t[21]!==n||t[22]!==o.exposureLabels||t[23]!==o.setupConfigure||t[24]!==o.toolDetails||t[25]!==o.toolsClearSearch||t[26]!==o.toolsDialogSearchEmpty||t[27]!==o.toolsDialogSearchPlaceholder||t[28]!==o.toolsDialogSubtitle||t[29]!==o.toolsDialogTitle||t[30]!==o.toolsEmpty||t[31]!==o.toolsLoading||t[32]!==o.toolsRetryHint||t[33]!==o.toolsSearchSummary||t[34]!==o.toolsTitle||t[35]!==u){let e=g.trim().toLowerCase(),a;if(t[49]!==n){let e;t[51]===Symbol.for(`react.memo_cache_sentinel`)?(e=/-/g,t[51]=e):e=t[51],a=n.replace(e,`_`),t[49]=n,t[50]=a}else a=t[50];let l=`mcp__${a}__`,d=u.filter(t=>`${t.name} ${t.description}`.toLowerCase().includes(e));E=te,k=!0,t[52]===s?A=t[53]:(A=e=>{e||s()},t[52]=s,t[53]=A),T=ye,t[54]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(M,{className:`fixed inset-0 z-[60] bg-scrim`}),t[54]=O):O=t[54],w=Y,t[55]===i?I=t[56]:(I=e=>{(b.current||i)&&e.preventDefault(),!b.current&&i?.isConnected&&i.focus()},t[55]=i,t[56]=I),L=`fixed left-1/2 top-1/2 z-[60] flex h-[min(42rem,calc(100dvh-2rem))] w-[min(48rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`;let p;t[57]===o.toolsDialogTitle?p=t[58]:(p=(0,$.jsx)(ee,{className:`font-semibold`,children:o.toolsDialogTitle}),t[57]=o.toolsDialogTitle,t[58]=p);let h;t[59]!==r||t[60]!==m||t[61]!==f||t[62]!==n||t[63]!==o.toolsDialogSubtitle||t[64]!==u.length?(h=f||m?r||n:o.toolsDialogSubtitle.replace(`{{serverId}}`,r||n).replace(`{{count}}`,String(u.length)),t[59]=r,t[60]=m,t[61]=f,t[62]=n,t[63]=o.toolsDialogSubtitle,t[64]=u.length,t[65]=h):h=t[65];let v;t[66]===h?v=t[67]:(v=(0,$.jsx)(st,{className:`mt-1 break-words text-sm text-fg-muted`,children:h}),t[66]=h,t[67]=v);let y;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>_(e.target.value),t[68]=y):y=t[68];let x;t[69]!==g||t[70]!==o.toolsDialogSearchPlaceholder?(x=(0,$.jsx)(`input`,{className:`mt-4 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,value:g,onChange:y,placeholder:o.toolsDialogSearchPlaceholder,"aria-label":o.toolsDialogSearchPlaceholder}),t[69]=g,t[70]=o.toolsDialogSearchPlaceholder,t[71]=x):x=t[71];let S=e&&!f&&!m?(0,$.jsx)(`p`,{role:`status`,className:`mt-2 text-xs text-fg-muted`,children:o.toolsSearchSummary.replace(`{{visible}}`,String(d.length)).replace(`{{count}}`,String(u.length))}):null;t[72]!==p||t[73]!==v||t[74]!==x||t[75]!==S?(D=(0,$.jsxs)(`div`,{className:`shrink-0 border-b border-edge p-5`,children:[p,v,x,S]}),t[72]=p,t[73]=v,t[74]=x,t[75]=S,t[76]=D):D=t[76],j=`min-h-0 flex-1 overflow-y-auto p-5`,N=f,t[77]!==o.toolsTitle||t[78]!==u.length?(P=o.toolsTitle.replace(`{{count}}`,String(u.length)),t[77]=o.toolsTitle,t[78]=u.length,t[79]=P):P=t[79],F=f?(0,$.jsx)(`div`,{role:`status`,"aria-label":o.toolsLoading,className:`space-y-3`,children:[0,1,2].map(ln)}):m?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm text-danger`,children:m}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:o.toolsRetryHint}),c?(0,$.jsx)(C,{variant:`secondary`,onClick:()=>{b.current=!0,c()},children:o.setupConfigure}):null]}):d.length?(0,$.jsx)(`div`,{className:`space-y-3`,children:d.map(e=>(0,$.jsxs)(`article`,{className:`rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`h3`,{className:`break-all font-mono text-sm font-semibold text-fg`,children:e.name.startsWith(l)?e.name.slice(l.length):e.name}),e.exposure&&Object.hasOwn(o.exposureLabels,e.exposure)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o.exposureLabels[e.exposure]}):null,e.description?(0,$.jsx)(`p`,{className:`mt-2 whitespace-pre-wrap break-words text-sm text-fg-muted`,children:e.description}):null,(0,$.jsxs)(`details`,{className:`mt-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:o.toolDetails}),(0,$.jsx)(`p`,{className:`mt-2 break-all font-mono text-xs text-fg-muted`,children:e.name}),(0,$.jsx)(`pre`,{className:`mt-2 overflow-x-auto rounded-md bg-surface-panel p-3 text-xs text-fg`,children:JSON.stringify(e.inputSchema,null,2)})]})]},e.name))}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.length?o.toolsDialogSearchEmpty:o.toolsEmpty}),e?(0,$.jsx)(C,{variant:`secondary`,onClick:()=>_(``),children:o.toolsClearSearch}):null]}),t[14]=r,t[15]=m,t[16]=f,t[17]=s,t[18]=c,t[19]=g,t[20]=i,t[21]=n,t[22]=o.exposureLabels,t[23]=o.setupConfigure,t[24]=o.toolDetails,t[25]=o.toolsClearSearch,t[26]=o.toolsDialogSearchEmpty,t[27]=o.toolsDialogSearchPlaceholder,t[28]=o.toolsDialogSubtitle,t[29]=o.toolsDialogTitle,t[30]=o.toolsEmpty,t[31]=o.toolsLoading,t[32]=o.toolsRetryHint,t[33]=o.toolsSearchSummary,t[34]=o.toolsTitle,t[35]=u,t[36]=w,t[37]=T,t[38]=E,t[39]=D,t[40]=O,t[41]=k,t[42]=A,t[43]=j,t[44]=N,t[45]=P,t[46]=F,t[47]=I,t[48]=L}else w=t[36],T=t[37],E=t[38],D=t[39],O=t[40],k=t[41],A=t[42],j=t[43],N=t[44],P=t[45],F=t[46],I=t[47],L=t[48];let R;t[80]!==j||t[81]!==N||t[82]!==P||t[83]!==F?(R=(0,$.jsx)(`div`,{className:j,"aria-busy":N,"aria-label":P,children:F}),t[80]=j,t[81]=N,t[82]=P,t[83]=F,t[84]=R):R=t[84];let z;t[85]===Symbol.for(`react.memo_cache_sentinel`)?(z=()=>y(cn),t[85]=z):z=t[85];let B;t[86]!==f||t[87]!==o.refreshTools?(B=(0,$.jsx)(C,{variant:`secondary`,disabled:f,onClick:z,children:o.refreshTools}),t[86]=f,t[87]=o.refreshTools,t[88]=B):B=t[88];let V;t[89]!==s||t[90]!==o.toolsDialogClose?(V=(0,$.jsx)(ae,{asChild:!0,children:(0,$.jsx)(C,{onClick:s,children:o.toolsDialogClose})}),t[89]=s,t[90]=o.toolsDialogClose,t[91]=V):V=t[91];let H;t[92]!==B||t[93]!==V?(H=(0,$.jsxs)(`div`,{className:`flex shrink-0 justify-end gap-2 border-t border-edge p-4`,children:[B,V]}),t[92]=B,t[93]=V,t[94]=H):H=t[94];let U;t[95]!==w||t[96]!==D||t[97]!==R||t[98]!==H||t[99]!==I||t[100]!==L?(U=(0,$.jsxs)(w,{onCloseAutoFocus:I,className:L,children:[D,R,H]}),t[95]=w,t[96]=D,t[97]=R,t[98]=H,t[99]=I,t[100]=L,t[101]=U):U=t[101];let W;t[102]!==T||t[103]!==O||t[104]!==U?(W=(0,$.jsxs)(T,{children:[O,U]}),t[102]=T,t[103]=O,t[104]=U,t[105]=W):W=t[105];let G;return t[106]!==E||t[107]!==k||t[108]!==A||t[109]!==W?(G=(0,$.jsx)(E,{open:k,onOpenChange:A,children:W}),t[106]=E,t[107]=k,t[108]=A,t[109]=W,t[110]=G):G=t[110],G}function cn(e){return e+1}function ln(e){return(0,$.jsx)(w,{className:`h-24 w-full`},e)}function un(e){if(e.transport===`stdio`)return e.command.trim();try{let t=new URL(e.url);return`${t.protocol}//${t.host}${t.pathname}`}catch{return e.url.trim().split(/[?#]/,1)[0].replace(/\/\/[^/]*@/,`//`)}}function dn({row:e,lastCheck:t,t:n,cs:r,onEdit:i,onRemove:a}){let o=y(e=>e.language),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(null),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(``),_=e.displayName||e.id,v=un(e),b=e.extra.enabled===!1,x=b?F:t?u:rt,S=e.transport===`stdio`?He:ce,w=b?n.setupDisabled:t?r.customCheckSucceeded:r.customUnchecked,T=t?new Intl.DateTimeFormat(o,{dateStyle:`medium`,timeStyle:`short`}).format(new Date(t.checkedAt)):null;return(0,$.jsxs)(`li`,{className:`flex min-h-[8.75rem] min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 transition-colors hover:bg-surface-hover/45 focus-within:ring-2 focus-within:ring-accent/30`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(`div`,{title:n.transportLabels[e.transport],className:`flex size-9 shrink-0 items-center justify-center rounded-xl border border-edge-subtle bg-surface-inset text-fg-muted`,children:(0,$.jsx)(S,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-1`,children:[(0,$.jsx)(`h3`,{className:`min-w-0 max-w-full text-sm font-semibold text-fg`,children:(0,$.jsx)(`button`,{type:`button`,onClick:i,title:_,className:`block max-w-full truncate rounded text-left hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:_})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px]`,children:[(0,$.jsxs)(`span`,{title:T?r.customLastChecked.replace(`{{time}}`,T):void 0,"aria-label":T?`${w} · ${r.customLastChecked.replace(`{{time}}`,T)}`:w,className:g(`inline-flex shrink-0 items-center gap-1`,!b&&t?`text-emerald-700 dark:text-emerald-300`:`text-fg-muted`),children:[(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),w]}),t?(0,$.jsx)(`span`,{className:`text-fg-muted`,children:r.customToolCount.replace(`{{count}}`,String(t.toolCount))}):null]})]})})]}),(0,$.jsx)(`p`,{title:v,className:`mt-2 truncate font-mono text-xs leading-5 text-fg-muted`,children:v})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`mr-auto text-[11px] text-fg-subtle`,children:n.transportLabels[e.transport]}),(0,$.jsx)(C,{variant:`ghost`,className:`h-8 px-2 py-1 text-xs`,onClick:i,children:n.setupConfigure}),(0,$.jsx)(C,{ref:l,variant:`secondary`,className:`h-8 px-2 py-1 text-xs shadow-none sm:shadow-none`,disabled:b,onClick:()=>c(!0),children:n.viewTools}),(0,$.jsxs)(Ae,{children:[(0,$.jsx)($e,{asChild:!0,children:(0,$.jsx)(C,{variant:`ghost`,className:`size-8 p-0`,"aria-label":r.customManage.replace(`{{name}}`,_),title:r.customManage.replace(`{{name}}`,_),children:(0,$.jsx)(d,{className:`size-4`,"aria-hidden":!0})})}),(0,$.jsx)(Xe,{children:(0,$.jsx)(Te,{align:`end`,sideOffset:6,className:`z-50 min-w-36 rounded-xl border border-edge bg-surface-overlay p-1 shadow-popover`,children:(0,$.jsxs)(Ke,{onSelect:()=>p(!0),className:`flex cursor-pointer items-center gap-2 rounded-lg px-3 py-2 text-sm text-danger outline-none data-[highlighted]:bg-surface-hover`,children:[(0,$.jsx)(Ee,{className:`size-4`,"aria-hidden":!0}),n.removeServer]})})})]})]}),m?(0,$.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-danger`,children:m}):null,s?(0,$.jsx)(sn,{serverId:e.id,displayName:e.displayName,returnFocusTo:l.current,t:n,onClose:()=>c(!1),onConfigure:()=>{c(!1),i()}}):null,(0,$.jsx)(We,{open:f,title:r.removeConfirmTitle.replace(`{{name}}`,_),description:r.removeConfirmDescription,confirmLabel:n.removeServer,cancelLabel:r.modalCancel,destructive:!0,onCancel:()=>p(!1),onConfirm:()=>{p(!1),h(``),a().catch(()=>h(n.setupRemoveFailed))}})]})}function fn(e){let t=(0,ft.c)(30),{servers:n,lastChecks:r,t:i,cs:a,onAdd:o,onEdit:s,onRemove:c}=e,l;t[0]===a.customIntegrationsTitle?l=t[1]:(l=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:a.customIntegrationsTitle}),t[0]=a.customIntegrationsTitle,t[1]=l);let u;t[2]===n.length?u=t[3]:(u=(0,$.jsx)(`span`,{className:`rounded-md bg-surface-inset px-1.5 py-0.5 text-xs tabular-nums text-fg-muted`,children:n.length}),t[2]=n.length,t[3]=u);let d;t[4]!==l||t[5]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[l,u]}),t[4]=l,t[5]=u,t[6]=d):d=t[6];let f;t[7]===a.customIntegrationsHint?f=t[8]:(f=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.customIntegrationsHint}),t[7]=a.customIntegrationsHint,t[8]=f);let p;t[9]!==d||t[10]!==f?(p=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[d,f]}),t[9]=d,t[10]=f,t[11]=p):p=t[11];let m;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(ge,{className:`size-3.5`,"aria-hidden":!0}),t[12]=m):m=t[12];let h;t[13]!==a.customAdd||t[14]!==o?(h=(0,$.jsxs)(C,{variant:`secondary`,className:`shrink-0 text-xs shadow-none sm:shadow-none`,onClick:o,children:[m,a.customAdd]}),t[13]=a.customAdd,t[14]=o,t[15]=h):h=t[15];let g;t[16]!==p||t[17]!==h?(g=(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-center justify-between gap-3`,children:[p,h]}),t[16]=p,t[17]=h,t[18]=g):g=t[18];let _;t[19]!==a||t[20]!==r||t[21]!==s||t[22]!==c||t[23]!==n||t[24]!==i?(_=n.length?(0,$.jsx)(`ul`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:n.map(e=>(0,$.jsx)(dn,{row:e,lastCheck:r[e.id],t:i,cs:a,onEdit:()=>s(e),onRemove:()=>c(e)},e.clientKey))}):(0,$.jsx)(`p`,{className:`rounded-xl border border-dashed border-edge px-5 py-8 text-center text-sm text-fg-muted`,children:a.customEmpty}),t[19]=a,t[20]=r,t[21]=s,t[22]=c,t[23]=n,t[24]=i,t[25]=_):_=t[25];let v;return t[26]!==a.customIntegrationsTitle||t[27]!==g||t[28]!==_?(v=(0,$.jsxs)(`section`,{"aria-label":a.customIntegrationsTitle,children:[g,_]}),t[26]=a.customIntegrationsTitle,t[27]=g,t[28]=_,t[29]=v):v=t[29],v}function pn(e){return e.format===`agent-plugin`&&!!e.pluginId&&(!!e.setup?.authorizations?.length||e.authorizationStatus===`required`||!!e.components?.mcp.some(e=>e.type!==`stdio`))}function mn(e){let t=(0,ft.c)(54),{extension:n,language:r,onOpen:i}=e,a;t[0]===r?a=t[1]:(a=r.startsWith(`zh`),t[0]=r,t[1]=a);let o=a,s;t[2]===o?s=t[3]:(s=(e,t)=>o?e:t,t[2]=o,t[3]=s);let c=s,l=n.installationState===`preparing`,d=n.activationEligible===!1,f=n.authorizationStatus===`required`,p;t[4]!==d||t[5]!==n.readiness||t[6]!==f||t[7]!==l||t[8]!==c?(p=l?c(`准备未完成`,`Setup incomplete`):d?c(`已停用`,`Disabled`):f?c(`需要授权`,`Authorization required`):n.readiness===`blocked`||n.readiness===`degraded`?c(`需要处理`,`Needs attention`):c(`已连接`,`Connected`),t[4]=d,t[5]=n.readiness,t[6]=f,t[7]=l,t[8]=c,t[9]=p):p=t[9];let m=p,h;t[10]!==d||t[11]!==f||t[12]!==l||t[13]!==c?(h=l?c(`继续安装`,`Continue setup`):!d&&f?c(`去授权`,`Connect account`):c(`查看详情`,`View details`),t[10]=d,t[11]=f,t[12]=l,t[13]=c,t[14]=h):h=t[14];let _=h,v;t[15]===n.setup?.authorizations?v=t[16]:(v=n.setup?.authorizations??[],t[15]=n.setup?.authorizations,t[16]=v);let y=v,b=y.length===1?y[0].title:n.name,x=l||!d&&(f||n.readiness===`blocked`||n.readiness===`degraded`),S=l?rt:d?F:x?Be:u,C=x&&`border-amber-500/25`,w;t[17]===C?w=t[18]:(w=g(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left transition-colors hover:bg-surface-hover/45 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,C),t[17]=C,t[18]=w);let T=n.branding?.iconUrl,E;t[19]===T?E=t[20]:(E=(0,$.jsx)(B,{iconUrl:T,fallback:xe,className:`size-9`}),t[19]=T,t[20]=E);let D;t[21]===b?D=t[22]:(D=(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-fg`,title:b,children:b}),t[21]=b,t[22]=D);let O=x?`text-amber-700 dark:text-amber-300`:d?`text-fg-muted`:`text-emerald-700 dark:text-emerald-300`,k;t[23]===O?k=t[24]:(k=g(`mt-1 inline-flex items-center gap-1 text-[11px]`,O),t[23]=O,t[24]=k);let A;t[25]===S?A=t[26]:(A=(0,$.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),t[25]=S,t[26]=A);let j;t[27]!==m||t[28]!==k||t[29]!==A?(j=(0,$.jsxs)(`span`,{className:k,children:[A,m]}),t[27]=m,t[28]=k,t[29]=A,t[30]=j):j=t[30];let M;t[31]!==D||t[32]!==j?(M=(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[D,j]}),t[31]=D,t[32]=j,t[33]=M):M=t[33];let N;t[34]!==M||t[35]!==E?(N=(0,$.jsxs)(`span`,{className:`flex w-full min-w-0 items-start gap-3`,children:[E,M]}),t[34]=M,t[35]=E,t[36]=N):N=t[36];let P=n.name,I;t[37]===c?I=t[38]:(I=c(`由插件提供`,`Provided by plugin`),t[37]=c,t[38]=I);let L;t[39]!==n.name||t[40]!==I?(L=(0,$.jsxs)(`span`,{className:`mt-2 block w-full truncate text-xs leading-5 text-fg-muted`,title:P,children:[I,` · `,n.name]}),t[39]=n.name,t[40]=I,t[41]=L):L=t[41];let R=x?`text-accent-fg`:`text-fg-muted`,z;t[42]===R?z=t[43]:(z=g(`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs`,R),t[42]=R,t[43]=z);let V;t[44]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(K,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[44]=V):V=t[44];let H;t[45]!==_||t[46]!==z?(H=(0,$.jsxs)(`span`,{className:z,children:[_,V]}),t[45]=_,t[46]=z,t[47]=H):H=t[47];let U;return t[48]!==i||t[49]!==N||t[50]!==L||t[51]!==H||t[52]!==w?(U=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:w,children:[N,L,H]}),t[48]=i,t[49]=N,t[50]=L,t[51]=H,t[52]=w,t[53]=U):U=t[53],U}function hn(e){let t=e.connectedAt?Date.parse(e.connectedAt):0;return Number.isFinite(t)?t:0}function gn(e,t){return e.status===`active`&&t.status!==`active`?-1:e.status!==`active`&&t.status===`active`?1:e.isCurrentAuthorization===t.isCurrentAuthorization?hn(t)-hn(e):e.isCurrentAuthorization?-1:1}function _n(e){let t=new Map;for(let n of e){let e=n.accountId??n.identityKey??`authorization:${n.id}`;t.set(e,[...t.get(e)??[],n])}return[...t.entries()].map(([e,t])=>{let n=[...t].sort(gn);return{key:e,primary:n[0],authorizations:n}}).sort((e,t)=>gn(e.primary,t.primary))}var vn=g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,q);function yn(e){return e.materialized.type===`composio`?e.materialized.toolkit:null}function bn(e,t){return e===`write`?t.composioScopeWrite:e===`admin`?t.composioScopeAdmin:t.composioScopeRead}function xn(e,t,n){return e.status===`connected`?Z(n.composioHealthConnected,{count:String(t)}):e.status===`reauthorization_required`?n.composioHealthReconnect:e.status===`disconnected`?n.composioHealthDisconnected:e.errorCode===`missing_credential`?n.composioHealthMissingCredential:e.errorCode===`unauthorized`?n.composioHealthUnauthorized:e.errorCode===`forbidden`?n.composioHealthForbidden:e.errorCode===`network`?n.composioHealthNetwork:e.errorCode===`timeout`?n.composioHealthTimeout:n.composioHealthDegraded}function Sn(e,t){return e===`active`?t.composioConnectionHealthy:e===`pending`?t.composioConnectionPending:e===`expired`?t.composioConnectionExpired:e===`failed`?t.composioConnectionFailed:e===`revoked`||e===`disabled`?t.composioConnectionRevoked:t.composioConnectionUnknown}function Cn(e,t,n){return e.status===`paused`?t?.scanEnabled===!1?n.connectorLearningPausedByPolicy:n.connectorLearningPausedByFailure:e.status===`queued`?n.connectorLearningQueued:e.status===`running`?n.connectorLearningRunning:e.status===`completed`?n.connectorLearningCompleted:n.connectorLearningFailed}function wn({instance:e,t,onChanged:n}){let r=yn(e),i=y(e=>e.language)===`zh`,[a,o]=(0,Q.useState)([]),[l,d]=(0,Q.useState)([]),[f,p]=(0,Q.useState)([]),[h,_]=(0,Q.useState)(null),[v,b]=(0,Q.useState)([]),[x,S]=(0,Q.useState)(null),[T,E]=(0,Q.useState)(null),[O,k]=(0,Q.useState)([]),[A,j]=(0,Q.useState)({}),[M,N]=(0,Q.useState)(`read`),[F,L]=(0,Q.useState)(!1),[R,B]=(0,Q.useState)(null),[V,U]=(0,Q.useState)(!1),[ee,W]=(0,Q.useState)(null),[te,re]=(0,Q.useState)(null),[ie,ae]=(0,Q.useState)(!1),[oe,K]=(0,Q.useState)(!1),[se,q]=(0,Q.useState)(!1),J=(0,Q.useRef)(0),ce=(0,Q.useRef)(0),ue=(0,Q.useMemo)(()=>_n(a),[a]),de=(0,Q.useCallback)(e=>new Promise((t,n)=>{let r=window.setTimeout(()=>n(Error(i?`连接服务响应超时,请重试。`:`The connection service timed out. Please retry.`)),15e3);e.then(t,n).finally(()=>window.clearTimeout(r))}),[i]),Y=(0,Q.useCallback)(async()=>{if(!r||e.materialized.type!==`composio`||e.materialized.role===`credential`)return;L(!0),B(null);let t=++J.current;try{let e=(await Promise.allSettled([de(Ue()).then(e=>{t===J.current&&(o(e.filter(e=>e.toolkit.toLowerCase()===r.toLowerCase())),ae(!0))}),de(Oe(r)).then(e=>{t===J.current&&N(e)}),de(ze(r)).then(e=>{t===J.current&&(_(e.policy),b(e.agents))})])).find(e=>e.status===`rejected`);t===J.current&&e?.status===`rejected`&&B(String(e.reason instanceof Error?e.reason.message:e.reason))}finally{t===J.current&&L(!1)}},[e.materialized,r,de]);(0,Q.useEffect)(()=>(Y(),()=>{J.current++}),[Y]);let X=(0,Q.useCallback)(async()=>{if(!r)return;let e=++ce.current;q(!0),U(!1);let t=t=>n=>{e===ce.current&&t(n)},n=await Promise.allSettled([de(et(r)).then(t(d)),de(Ne(20)).then(t(e=>p(e.filter(e=>!e.toolkit||e.toolkit.toLowerCase()===r.toLowerCase())))),de(Ze(r)).then(t(E)),de(Je(r)).then(t(S))]);e===ce.current&&(U(n.some(e=>e.status===`rejected`)),q(!1))},[r,de]);(0,Q.useEffect)(()=>(oe&&X(),()=>{ce.current++}),[oe,X]),(0,Q.useEffect)(()=>{let e=!1,t=_n(a).map(e=>e.primary).filter(e=>e.supportsLearning&&e.accountId);if(t.length)return de(Ie()).then(t=>{e||k(t)}).catch(()=>{}),Promise.allSettled(t.map(async e=>[e.accountId,await de(je(e.accountId))])).then(t=>{e||j(Object.fromEntries(t.flatMap(e=>e.status===`fulfilled`?[e.value]:[])))}),()=>{e=!0}},[a,de]);let fe=(0,Q.useCallback)(async i=>{if(!r)return;let a=D()?null:window.open(`about:blank`,`_blank`);a&&(a.opener=null),L(!0),B(null);try{if(!D()&&!a)throw Error(`Allow popups to open the authorization page.`);let t=await ke(e.connectorId,i);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 a.location.href=t.authorizationUrl;let o=await le(r,t.connectionId,12e4,t.attemptId);if(i&&o.accountId!==i)throw Error(`A different account was authorized. The original account and its task bindings were not changed.`);await Promise.all([n?.(),Y()])}catch(e){B(H(e,t))}finally{a?.close(),L(!1)}},[e.connectorId,Y,n,t,r]),pe=(0,Q.useCallback)(async t=>{L(!0),B(null);try{await z(e.instanceId,{config:{...e.config??{},authConfigId:t||void 0}}),await Promise.all([n?.(),Y()])}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[e.config,e.instanceId,Y,n]),he=async e=>{let t=D()?null:window.open(`about:blank`,`_blank`);t&&(t.opener=null),B(null);try{let n=await Ge(e.id);if(n.authorizationUrl)if(D())await window.electronAPI?.shell?.openExternalUrl(n.authorizationUrl);else if(t)t.location.href=n.authorizationUrl;else throw Error(`Allow popups to reopen authorization.`);else t?.close(),await Y()}catch(e){t?.close(),B(e instanceof Error?e.message:String(e))}},ge=(0,Q.useCallback)(async e=>{if(r){N(e),B(null);try{await tt(r,e)}catch(e){B(e instanceof Error?e.message:String(e)),await Y()}}},[Y,r]),_e=(0,Q.useCallback)(async e=>{if(r){B(null);try{_(await me(r,e))}catch(e){B(e instanceof Error?e.message:String(e))}}},[r]),ve=(0,Q.useCallback)(e=>{if(!h)return;let t=h.allowedAgentIds.includes(e);t&&h.allowedAgentIds.length===1||_e({allowedAgentIds:t?h.allowedAgentIds.filter(t=>t!==e):[...h.allowedAgentIds,e]})},[_e,h]),ye=(0,Q.useCallback)(async e=>{L(!0),B(null);try{await e(),await Y()}catch(e){B(e instanceof Error?e.message:String(e))}finally{L(!1)}},[Y]);if(!r)return null;if(e.materialized.type===`composio`&&e.materialized.role===`credential`)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioApiKeyStored});let be=ue.filter(e=>e.primary.status===`active`).length,xe=be>0?t.composioAddAccount:t.composioConnectAccount,Ce=ie&&be>0,we=T?.requiresCustomAuthConfig===!0,Te=T?.authConfigs.filter(e=>e.status===`ENABLED`&&e.isEnabledForToolRouter)??[];return(0,$.jsxs)(`div`,{className:`space-y-5`,children:[(0,$.jsxs)(`section`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`span`,{className:g(`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 text-xs font-medium`,Ce?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`),children:[Ce?(0,$.jsx)(u,{className:`size-3.5`}):(0,$.jsx)(Be,{className:`size-3.5`}),Ce?t.connectionReady:ie||R?t.connectionNeedsSetup:t.connectionChecking]}),ie&&(0,$.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:Z(t.composioAccountCount,{count:String(ue.length)})})]}),(0,$.jsxs)(C,{variant:`primary`,className:`shrink-0`,disabled:F,onClick:()=>void fe(),children:[F?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(ne,{className:`size-4`}),xe]})]}),R?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center justify-between gap-2 rounded-xl border border-danger/20 bg-danger/5 px-3 py-2 text-sm text-danger`,children:[(0,$.jsx)(`p`,{children:R}),(0,$.jsx)(C,{variant:`secondary`,disabled:F,onClick:()=>void Y(),children:t.composioRetry})]}):null,x&&!Ce?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-amber-500/25 bg-amber-500/5 p-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:xn(x,be,t)}),x.recovery===`none`?null:(0,$.jsx)(C,{variant:`secondary`,disabled:F,onClick:()=>void(x.recovery===`retry`?Y():fe()),children:x.recovery===`retry`?t.composioRetry:t.composioReconnectAccount})]}):null,we&&Te.length===0?(0,$.jsx)(`p`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/5 px-4 py-3 text-sm text-amber-800 dark:text-amber-200`,children:t.composioAuthConfigEmpty}):null,h?(0,$.jsxs)(`section`,{className:`overflow-hidden rounded-xl border border-edge bg-surface-base`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-start`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAccessTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:M===`read`?t.composioAccessReadHint:M===`admin`?t.composioAccessAdminHint:t.composioAccessWriteHint})]}),(0,$.jsxs)(s,{value:M,onChange:e=>void ge(e.currentTarget.value),children:[(0,$.jsx)(c,{value:`read`,children:t.composioAccessReadOnly}),(0,$.jsx)(c,{value:`write`,children:t.composioAccessReadWrite}),M===`admin`?(0,$.jsx)(c,{value:`admin`,children:t.composioAccessAdminCurrent}):null]})]}),(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm text-fg-muted`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`grid gap-3 border-b border-edge-subtle px-4 py-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioConfirmationPolicy}),(0,$.jsxs)(s,{value:h.confirmationPolicy,onChange:e=>void _e({confirmationPolicy:e.currentTarget.value}),children:[(0,$.jsx)(c,{value:`writes`,children:t.composioConfirmWrites}),(0,$.jsx)(c,{value:`always`,children:t.composioConfirmAlways}),h.confirmationPolicy===`never`?(0,$.jsx)(c,{value:`never`,children:t.composioConfirmNever}):null]})]}),(0,$.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAllowedAgents}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:h.allowedAgentIds.length?t.composioAllowedAgentsSelected:t.composioAllowedAgentsAll}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:g(`rounded-full border px-2.5 py-1 text-xs transition-colors`,h.allowedAgentIds.length===0?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>void _e({allowedAgentIds:[]}),children:t.composioAllowedAgentsAllOption}),v.map(e=>(0,$.jsx)(`button`,{type:`button`,className:g(`rounded-full border px-2.5 py-1 text-xs transition-colors`,h.allowedAgentIds.includes(e.id)?`border-accent bg-accent/10 text-accent`:`border-edge bg-surface-panel text-fg-muted hover:text-fg`),onClick:()=>ve(e.id),children:e.name},e.id))]})]}),(0,$.jsxs)(`fieldset`,{className:`space-y-2 border-t border-edge-subtle p-4 text-xs text-fg-muted`,children:[(0,$.jsx)(`legend`,{children:i?`可用账号范围`:`Available accounts`}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:h.selectedAccountIds===null,disabled:F,onChange:e=>void _e({selectedAccountIds:e.currentTarget.checked?null:[]})}),i?`所有账号(包括以后新增)`:`All accounts, including new ones`]}),h.selectedAccountIds!==null&&ue.map(({primary:e})=>e.accountId&&(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:F,checked:h.selectedAccountIds.includes(e.accountId),onChange:t=>void _e({selectedAccountIds:t.currentTarget.checked?[...h.selectedAccountIds,e.accountId]:h.selectedAccountIds.filter(t=>t!==e.accountId)})}),e.alias??e.accountEmail??e.accountId]},e.accountId)),h.selectedAccountIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择账号,Agent 无法使用此应用。`:`No accounts selected. Agents cannot use this app.`})]})]})]}):null,(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.composioConnectedAccounts}),ie&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:Z(t.composioAccountCount,{count:String(ue.length)})})]}),(0,$.jsxs)(C,{variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:F,onClick:()=>void Y(),children:[(0,$.jsx)(G,{className:g(`size-3.5`,F&&`animate-spin`)}),t.refresh]})]}),ue.length?(0,$.jsx)(`div`,{className:`divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge bg-surface-base`,children:ue.map(e=>{let r=e.primary,a=O.find(e=>r.accountId?e.accountId===r.accountId:e.connectionId===r.id),o=r.accountId?A[r.accountId]:void 0;return(0,$.jsxs)(`article`,{className:`px-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-start justify-between gap-3 sm:flex-row`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:(0,$.jsx)(`p`,{className:`truncate text-sm font-medium text-fg`,children:r.alias??r.workspace??r.accountEmail??r.username??t.composioUnnamedAuthorization})}),(0,$.jsx)(`p`,{className:`mt-1 break-all text-xs text-fg-muted`,children:r.accountEmail??r.username??r.workspace??r.accountId}),r.backendLabel&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:r.backendLabel}),(0,$.jsx)(`p`,{className:g(`mt-1 text-xs`,r.status===`active`?`text-emerald-700 dark:text-emerald-300`:`text-amber-700 dark:text-amber-300`),children:r.accountEnabled===!1?i?`已暂停`:`Paused`:Sn(r.status,t)}),a?(0,$.jsx)(`p`,{className:g(`mt-1 text-xs`,a.status===`failed`?`text-red-600`:`text-fg-subtle`),children:Z(t.connectorLearningStatus,{status:Cn(a,o,t),count:String(a.candidatesCreated)})}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[r.status===`pending`&&(0,$.jsx)(C,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,onClick:()=>void he(r),children:i?`继续授权`:`Continue authorization`}),r.accountId&&(0,$.jsx)(C,{variant:`ghost`,className:`h-8 px-2.5 text-xs text-danger`,disabled:F,onClick:()=>re(r.accountId),children:i?`断开`:`Disconnect`}),r.accountId&&r.status!==`active`&&(0,$.jsx)(C,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:F,onClick:()=>void fe(r.accountId),children:t.composioReconnectAccount}),r.accountId&&(0,$.jsx)(C,{variant:`secondary`,className:`h-8 px-2.5 text-xs`,disabled:F,onClick:()=>void ye(()=>P(r.accountId,{enabled:r.accountEnabled===!1})),children:r.accountEnabled===!1?i?`启用`:`Enable`:i?`暂停`:`Pause`}),r.supportsLearning&&r.status===`active`&&r.accountEnabled!==!1?(0,$.jsxs)(C,{variant:`secondary`,className:`h-8 shrink-0 px-2.5 text-xs`,disabled:F,onClick:()=>void ye(async()=>{if(!r.accountId)throw Error(`Connector account is unavailable.`);await ot(r.accountId),await n?.()}),children:[(0,$.jsx)(G,{className:`size-3.5`}),t.composioSyncNow]}):null]})]}),(0,$.jsxs)(`details`,{className:`mt-3 text-xs text-fg-muted`,children:[(0,$.jsx)(`summary`,{className:`w-fit cursor-pointer font-medium hover:text-fg`,children:t.composioAccountSettings}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-4 rounded-lg bg-surface-panel p-3`,children:[r.accountId&&(0,$.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,$.jsx)(`legend`,{className:`mb-2 font-medium`,children:t.composioAllowedAgents}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:F,checked:r.allowedAgentIds==null,onChange:e=>void ye(()=>P(r.accountId,{allowedAgentIds:e.currentTarget.checked?null:[]}))}),t.composioAllowedAgentsAllOption]}),r.allowedAgentIds!=null&&v.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,disabled:F,checked:r.allowedAgentIds.includes(e.id),onChange:t=>{let n=t.currentTarget.checked;ye(()=>P(r.accountId,{allowedAgentIds:n?[...r.allowedAgentIds,e.id]:r.allowedAgentIds.filter(t=>t!==e.id)}))}}),e.name]},e.id)),r.allowedAgentIds?.length===0&&(0,$.jsx)(`p`,{children:i?`未选择 Agent:任何 Agent 都不能使用此账号。`:`No agents selected: this account is unavailable to all agents.`})]}),r.supportsLearning&&o?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:o.scanEnabled,disabled:F,onChange:e=>void ye(()=>I(r.accountId,{scanEnabled:e.currentTarget.checked}))}),t.connectorScheduledScan]}),o.scanEnabled?(0,$.jsxs)(`label`,{className:`sm:col-span-2`,children:[t.connectorScanInterval,(0,$.jsxs)(s,{className:`mt-1`,value:String(o.intervalMinutes??30),disabled:F,onChange:e=>void ye(()=>I(r.accountId,{intervalMinutes:Number(e.currentTarget.value)})),children:[(0,$.jsxs)(c,{value:`5`,children:[`5 `,t.connectorMinutes]}),(0,$.jsxs)(c,{value:`15`,children:[`15 `,t.connectorMinutes]}),(0,$.jsxs)(c,{value:`30`,children:[`30 `,t.connectorMinutes]}),(0,$.jsxs)(c,{value:`60`,children:[`60 `,t.connectorMinutes]})]})]}):null]}):null,(0,$.jsxs)(`label`,{className:`block`,children:[t.composioAccountAlias,(0,$.jsx)(`input`,{className:g(vn,`mt-1 h-8 py-1 text-xs`),defaultValue:r.alias??``,onBlur:e=>{e.currentTarget.value!==(r.alias??``)&&ye(()=>nt(r.id,{alias:e.currentTarget.value}))}})]}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.authorizations.map(e=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`p`,{className:`min-w-0 break-all font-mono text-fg-subtle`,children:[t.composioAuthorizationId,`: `,e.providerConnectionId]}),(0,$.jsx)(C,{variant:`ghost`,className:`size-7 shrink-0 p-0 text-danger`,title:t.composioRevoke,disabled:F,onClick:()=>W(e.id),children:(0,$.jsx)(Ee,{className:`size-3.5`})})]},e.id))}),(0,$.jsx)(`div`,{className:`flex justify-end gap-1`,children:(0,$.jsx)(C,{variant:`ghost`,className:`size-8 p-0`,title:t.refresh,disabled:F,onClick:()=>void ye(()=>qe(r.id)),children:(0,$.jsx)(G,{className:`size-4`})})})]})]})]},e.key)})}):F&&!ie?(0,$.jsxs)(`div`,{"aria-busy":`true`,"aria-label":t.connectionChecking,className:`space-y-3`,children:[(0,$.jsx)(w,{className:`h-16 w-full`}),(0,$.jsx)(w,{className:`h-16 w-full`})]}):ie?(0,$.jsx)(`div`,{className:`rounded-xl border border-dashed border-edge px-4 py-8 text-center`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.composioConnectionsEmpty})}):null]}),(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-base`,onToggle:e=>K(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-fg`,children:t.composioAdvancedSettings}),(0,$.jsxs)(`div`,{className:`space-y-5 border-t border-edge-subtle px-4 py-4`,children:[se?(0,$.jsx)(w,{"aria-label":t.connectionChecking,className:`h-16 w-full`}):null,V?(0,$.jsxs)(`p`,{className:`rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,children:[t.composioDiagnosticsUnavailable,(0,$.jsx)(C,{variant:`ghost`,disabled:se,onClick:()=>void X(),children:t.composioRetry})]}):null,T?.mode===`byok`?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.composioAuthConfigTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:we?t.composioAuthConfigRequiredHint:t.composioAuthConfigOptionalHint})]}),(0,$.jsx)(`a`,{className:`text-xs font-medium text-accent-fg hover:underline`,href:`https://app.composio.dev`,target:`_blank`,rel:`noreferrer`,children:t.composioAuthConfigManage})]}),(0,$.jsxs)(s,{className:`mt-3`,value:typeof e.config?.authConfigId==`string`?e.config.authConfigId:``,disabled:F,onChange:e=>void pe(e.currentTarget.value),children:[we?null:(0,$.jsx)(c,{value:``,children:t.composioAuthConfigManaged}),we&&typeof e.config?.authConfigId!=`string`?(0,$.jsx)(c,{value:``,disabled:!0,children:t.composioAuthConfigSelect}):null,Te.map(e=>(0,$.jsxs)(c,{value:e.id,children:[e.name,` · `,e.authScheme??`OAuth`]},e.id))]})]}):null,(0,$.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioAgentTools}),(0,$.jsx)(`div`,{className:`space-y-2`,children:l.length?l.slice(0,8).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate font-mono text-xs text-fg`,children:e.slug}),(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:[bn(e.scope,t),e.curated?``:` ${t.composioUncuratedSuffix}`]})]},e.slug)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioToolsEmpty})})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-xs font-medium uppercase tracking-wide text-fg-subtle`,children:t.composioRecentTriggers}),(0,$.jsx)(`div`,{className:`space-y-2`,children:f.length?f.slice(0,5).map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-fg`,children:e.trigger??e.id}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:new Date(e.at).toLocaleString()})]},`${e.id}-${e.at}`)):(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.composioTriggersEmpty})})]})]})]})]}),(0,$.jsx)(We,{open:te!==null,title:i?`断开账号`:`Disconnect account`,description:i?`停止此账号的工具使用和学习,并撤销其全部授权。已保存的数据不会删除。`:`Stop tool access and learning for this account and revoke all its authorizations. Saved data will not be deleted.`,confirmLabel:i?`断开`:`Disconnect`,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=te;re(null),e&&ye(()=>Se(e))},onCancel:()=>re(null)}),(0,$.jsx)(We,{open:ee!==null,title:t.composioRevoke,description:t.composioRevokeConfirm,confirmLabel:t.composioRevoke,cancelLabel:t.modalCancel,destructive:!0,onConfirm:()=>{let e=ee;W(null),e&&ye(()=>Le(e))},onCancel:()=>W(null)})]})}var Tn=g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,q);function En(e,t){let n={};for(let r of e?.setup.config??[]){let e=t.config?.[r.key]??r.defaultValue??``;n[r.key]=typeof e==`string`?e:JSON.stringify(e,null,2)}return n}function Dn(e,t){let n=t.trim();return e===`json`?n?JSON.parse(n):void 0:e===`number`?n?Number(n):void 0:e===`boolean`?n===`true`:n||void 0}function On({instance:e,definition:t,onClose:n,onChanged:r,t:i}){let[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,h]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(()=>En(t,e)),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),E=t?.setup.config??[],D=(e.materialized.type===`mcp`||e.materialized.type===`memorySource`)&&E.length>0&&(t?.setup.secrets??[]).length===0,O=e.materialized.type===`mcp`,k=e.materialized.type===`composio`,j=e.materialized.type===`memorySource`,N=t?he(t,i):null,P=(0,Q.useCallback)(async()=>{S(!0),b(null);try{let t=await fe(e.instanceId);T(t),t.ok||b(t.error??t.action??i.healthStatusLabels[t.status]),await r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{S(!1)}},[e.instanceId,r,i.healthStatusLabels]),F=(0,Q.useCallback)(async()=>{o(!0),b(null);try{await Re(e.instanceId),await r(),n()}catch(e){b(e instanceof Error?e.message:String(e)),o(!1)}},[e.instanceId,r,n]),I=(0,Q.useCallback)(async()=>{if(!(!t||!D)){u(!0),b(null);try{let n={};for(let e of t.setup.config??[]){let t=Dn(e.type,_[e.key]??``);t!==void 0&&(n[e.key]=t)}await z(e.instanceId,{config:n}),await r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[_,t,e.instanceId,r,D]),L=(0,Q.useCallback)(async()=>{f(!0),h(null),b(null);try{h((await it(e.connectorId)).recordIds.length),await r()}catch(e){b(e instanceof Error?e.message:String(e))}finally{f(!1)}},[e.connectorId,r]);return(0,$.jsxs)(te,{open:!0,onOpenChange:e=>{e||n()},children:[(0,$.jsxs)(ye,{children:[(0,$.jsx)(M,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(Y,{className:g(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] flex -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,k?`h-[min(100dvh-2rem,36rem)] w-[min(100%-2rem,40rem)]`:`h-[min(100dvh-2rem,44rem)] w-[min(100%-2rem,min(92vw,54rem))]`,`rounded-2xl border border-edge bg-surface-overlay shadow-float outline-none dark:border-edge`),children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-6 py-5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,$.jsx)(ve,{connector:t,size:`lg`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(ee,{className:`text-base font-semibold text-fg`,children:e.displayName}),(0,$.jsx)(st,{className:`mt-1 text-sm text-fg-muted`,children:N??(e.materialized.type===`mcp`?Z(i.mcpServerRuntime,{serverId:e.materialized.serverId}):Z(i.runtimeLabel,{runtime:e.materialized.type}))})]})]}),(0,$.jsx)(ae,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:g(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,A.focusRingPanel),"aria-label":i.modalClose,children:[(0,$.jsx)(re,{className:`size-5`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`sr-only`,children:i.modalClose})]})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-6 py-5`,children:[y?(0,$.jsx)(`p`,{className:`mb-4 rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:y}):null,O?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-edge bg-surface-base p-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-fg-muted`,role:`status`,children:w?.ok?Z(i.toolsAvailable,{count:String(w.toolCount)}):w?i.healthStatusLabels[w.status]:e.usage.lastHealthStatus?i.healthStatusLabels[e.usage.lastHealthStatus]:i.healthNotTested}),(0,$.jsxs)(C,{variant:`secondary`,"aria-busy":x,disabled:x||!e.enabled,onClick:()=>void P(),children:[x?(0,$.jsx)(m,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(G,{className:`size-4`,"aria-hidden":!0}),i.test]})]}),D?E.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key)):null]}):null,k?(0,$.jsx)(wn,{instance:e,t:i,onChanged:r}):null,j?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 rounded-xl border border-edge bg-surface-base p-4 text-sm`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:i.connectedSourceSync}),N?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:N}):null,p===null?null:(0,$.jsx)(`p`,{className:`mt-1 text-xs text-emerald-600`,children:Z(i.connectedSourceSynced,{count:String(p)})})]}),(0,$.jsxs)(C,{disabled:d,onClick:()=>void L(),children:[d?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(Fe,{className:`size-4`}),i.composioSyncNow]})]}),D?(0,$.jsx)(`div`,{className:`grid gap-3 rounded-xl border border-edge bg-surface-base p-4`,children:E.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:e.label}),e.description?(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.description}):null,(0,$.jsx)(`input`,{className:Tn,value:_[e.key]??``,placeholder:e.placeholder,onChange:t=>v(n=>({...n,[e.key]:t.currentTarget.value}))})]},e.key))}):null]}):null,!O&&!k&&!j?(0,$.jsx)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-4 text-sm text-fg-muted`,children:(0,$.jsx)(`p`,{children:i.connectorPolicyHint})}):null,(0,$.jsxs)(`details`,{className:`mt-5 rounded-xl border border-edge`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer px-4 py-3 text-sm font-medium text-fg-muted hover:text-danger`,children:i.dangerZone}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 border-t border-danger/15 px-4 py-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-fg-muted`,children:i.removeConnectorHint}),(0,$.jsxs)(C,{variant:`secondary`,className:`shrink-0 border-danger/30 text-danger hover:bg-danger/10`,disabled:a,onClick:()=>c(!0),children:[a?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(Ee,{className:`size-4`}),i.remove]})]})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge-subtle px-6 py-4`,children:[(0,$.jsx)(C,{variant:`secondary`,onClick:n,children:i.modalClose}),(O||j)&&D?(0,$.jsxs)(C,{variant:`primary`,disabled:l,onClick:()=>void I(),children:[l?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(se,{className:`size-4`}),i.modalSave]}):null]})]})]}),(0,$.jsx)(We,{open:s,title:Z(i.removeConfirmTitle,{name:e.displayName}),description:i.removeConfirmDescription,confirmLabel:i.removeConfirmAction,cancelLabel:i.modalCancel,destructive:!0,onConfirm:()=>{c(!1),F()},onCancel:()=>{a||c(!1)}})]})}function kn(e){let t=(0,ft.c)(2),n;return t[0]===e?n=t[1]:(n=e.instance.materialized.type===`cli`&&e.definition?(0,$.jsx)(V,{definition:e.definition,instance:e.instance,onClose:e.onClose,onChanged:e.onChanged}):(0,$.jsx)(On,{...e}),t[0]=e,t[1]=n),n}function An(e){let t=(0,ft.c)(59),{instance:n,definition:r,highlighted:i,onOpenDetails:a,t:o}=e,s=i===void 0?!1:i,c;t[0]!==r||t[1]!==n?(c=Ct(n,r),t[0]=r,t[1]=n,t[2]=c):c=t[2];let l=c.state,d;t[3]!==r||t[4]!==o?(d=r?he(r,o):null,t[3]=r,t[4]=o,t[5]=d):d=t[5];let f=d,p,m,h,_,v,y,b,x,S;if(t[6]!==l||t[7]!==r||t[8]!==s||t[9]!==n||t[10]!==a||t[11]!==o.connectionChecking||t[12]!==o.connectionNeedsSetup||t[13]!==o.connectionReady){p=l===`ready`?{label:o.connectionReady,Icon:u,className:`text-emerald-700 dark:text-emerald-300`}:l===`needs_setup`?{label:o.connectionNeedsSetup,Icon:Be,className:`text-amber-700 dark:text-amber-300`}:{label:o.connectionChecking,Icon:rt,className:`text-fg-muted`},S=`button`;let e=l===`needs_setup`&&`border-amber-500/25`,i=s&&`bg-accent-soft`;t[23]!==e||t[24]!==i?(m=g(`flex min-h-[8.75rem] w-full min-w-0 flex-col rounded-xl border border-edge bg-surface-panel p-4 text-left hover:bg-surface-hover/45`,A.transition,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,e,i),t[23]=e,t[24]=i,t[25]=m):m=t[25],t[26]!==n||t[27]!==a?(h=()=>a(n),t[26]=n,t[27]=a,t[28]=h):h=t[28],b=`flex w-full min-w-0 items-start gap-3`,t[29]===r?x=t[30]:(x=(0,$.jsx)(ve,{connector:r,size:`sm`}),t[29]=r,t[30]=x),v=`min-w-0 flex-1`,t[31]===n.displayName?y=t[32]:(y=(0,$.jsx)(`h3`,{className:`truncate text-sm font-semibold text-fg`,title:n.displayName,children:n.displayName}),t[31]=n.displayName,t[32]=y),_=g(`mt-1 inline-flex items-center gap-1 text-[11px]`,p.className),t[6]=l,t[7]=r,t[8]=s,t[9]=n,t[10]=a,t[11]=o.connectionChecking,t[12]=o.connectionNeedsSetup,t[13]=o.connectionReady,t[14]=p,t[15]=m,t[16]=h,t[17]=_,t[18]=v,t[19]=y,t[20]=b,t[21]=x,t[22]=S}else p=t[14],m=t[15],h=t[16],_=t[17],v=t[18],y=t[19],b=t[20],x=t[21],S=t[22];let C;t[33]===p.Icon?C=t[34]:(C=(0,$.jsx)(p.Icon,{className:`size-3.5`,"aria-hidden":!0}),t[33]=p.Icon,t[34]=C);let w;t[35]!==p.label||t[36]!==C||t[37]!==_?(w=(0,$.jsxs)(`span`,{className:_,children:[C,p.label]}),t[35]=p.label,t[36]=C,t[37]=_,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==v||t[41]!==y?(T=(0,$.jsxs)(`div`,{className:v,children:[y,w]}),t[39]=w,t[40]=v,t[41]=y,t[42]=T):T=t[42];let E;t[43]!==T||t[44]!==b||t[45]!==x?(E=(0,$.jsxs)(`div`,{className:b,children:[x,T]}),t[43]=T,t[44]=b,t[45]=x,t[46]=E):E=t[46];let D;t[47]===f?D=t[48]:(D=f?(0,$.jsx)(`p`,{className:`mt-2 w-full line-clamp-2 text-xs leading-5 text-fg-muted`,title:f,children:f}):null,t[47]=f,t[48]=D);let O;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(K,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t[49]=O):O=t[49];let k;t[50]===o.installedDetails?k=t[51]:(k=(0,$.jsxs)(`span`,{className:`mt-auto flex w-full items-center justify-end gap-1 pt-2 text-xs text-fg-muted`,children:[o.installedDetails,O]}),t[50]=o.installedDetails,t[51]=k);let j;return t[52]!==m||t[53]!==h||t[54]!==E||t[55]!==D||t[56]!==k||t[57]!==S?(j=(0,$.jsxs)(`button`,{type:S,className:m,onClick:h,children:[E,D,k]}),t[52]=m,t[53]=h,t[54]=E,t[55]=D,t[56]=k,t[57]=S,t[58]=j):j=t[58],j}function jn(e,t){return Gt()}function Mn(e){let t=e.headers.filter(e=>e.key.trim()),n=t.find(e=>e.key.toLowerCase()===`authorization`&&!e.reference&&/^Bearer\s/i.test(e.value)),r=e.extra.auth||t.some(e=>e.reference)||e.extra.oauth&&t.some(e=>e.key.toLowerCase()===`authorization`)?`existing`:e.extra.oauth?`oauth`:n?`bearer`:t.length?`headers`:`auto`;return{mode:r,token:n?.value.replace(/^Bearer\s+/i,``)??``,apiKey:``,headerName:``,customHeaders:t.length?t:[Mt()],additionalHeaders:r===`bearer`?t.filter(e=>e!==n):r===`oauth`?t:[]}}function Nn(e,t){if(e.transport===`stdio`||t.mode===`existing`)return{...e,extra:{...e.extra}};let n={...e.extra};delete n.auth,t.mode!==`oauth`&&delete n.oauth;let r=t.mode===`headers`?t.customHeaders:t.additionalHeaders;if(t.mode===`bearer`){let e=t.token.trim().replace(/^Bearer\s+/i,``);r=[...r,Mt(`Authorization`,`Bearer ${e}`)]}return t.mode===`apiKey`&&(r=[...r,Mt(t.headerName.trim(),t.apiKey.trim())]),{...e,extra:n,headers:r,oauthClientId:t.mode===`oauth`?e.oauthClientId:``}}function Pn(e){let t=new Set;return e.findIndex(e=>{let n=e.key.trim();if(!n&&!e.value&&!e.reference)return!1;if(!/^[!#$%&'*+.^_`|~\da-z-]+$/i.test(n)||/[\r\n]/.test(e.value))return!0;let r=n.toLowerCase();return t.has(r)?!0:(t.add(r),!1)})}function Fn(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,q)}function In({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,pasteFailedTitle:o,dismissLabel:s,keyPlaceholder:c,valuePlaceholder:l,headers:u,onChange:d,referenceLabel:f=`Existing credential reference`,showValueLabel:m=`Show value`,hideValueLabel:h=`Hide value`,allowPaste:_=!0}){let[v,y]=(0,Q.useState)(new Set),[b,S]=(0,Q.useState)(!1),w=(e,t)=>{d(u.map((n,r)=>r===e?{...n,...t}:n))},T=()=>{d([...u,Mt()])},E=e=>{let t=u.filter((t,n)=>n!==e);d(t.length>0?t:[Mt()])},D=async()=>{try{let e=await x();if(!e){S(!0);return}let t=Pt(e);if(!t?.length){S(!0);return}d(t)}catch{S(!0)}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,$.jsx)(`span`,{children:e}),t?(0,$.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),_?(0,$.jsxs)(C,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void D(),children:[(0,$.jsx)(X,{className:`size-3.5`,"aria-hidden":!0}),i]}):null]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:u.map((e,t)=>(0,$.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto_auto] items-center gap-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)_auto_auto]`,children:[(0,$.jsx)(`input`,{className:g(Fn(),`col-span-3 min-w-0 font-mono text-xs sm:col-span-1`),"aria-label":`${c} ${t+1}`,value:e.key,placeholder:c,onChange:e=>w(t,{key:e.target.value})}),(0,$.jsx)(`input`,{className:g(Fn(),`min-w-0 font-mono text-xs`),type:v.has(e.clientKey)?`text`:`password`,autoComplete:`off`,"aria-label":`${l} ${t+1}`,readOnly:!!e.reference,value:e.reference?f:e.value,placeholder:e.reference?f:l,onChange:e=>w(t,{value:e.target.value})}),(0,$.jsx)(C,{type:`button`,variant:`ghost`,className:`size-10 shrink-0 px-0`,disabled:!!e.reference,"aria-label":v.has(e.clientKey)?h:m,onClick:()=>y(t=>{let n=new Set(t);return n.has(e.clientKey)?n.delete(e.clientKey):n.add(e.clientKey),n}),children:v.has(e.clientKey)?(0,$.jsx)(Ve,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(p,{className:`size-4`,"aria-hidden":!0})}),(0,$.jsx)(C,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:u.length<=1&&!e.key&&!e.value,onClick:()=>E(t),"aria-label":r,children:(0,$.jsx)(Ee,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})}),e.reference?(0,$.jsx)(`p`,{className:`col-span-3 break-words text-xs text-fg-muted sm:col-span-4`,children:f}):null]},e.clientKey))}),(0,$.jsx)(We,{open:b,title:o,description:a,confirmLabel:s,onConfirm:()=>S(!1),onCancel:()=>S(!1)}),(0,$.jsxs)(`button`,{type:`button`,className:g(`self-start text-sm text-accent hover:underline`,A.press),onClick:T,children:[`+ `,n]})]})}var Ln=g(`w-full min-w-0 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,q);function Rn(e){let t=(0,ft.c)(20),{value:n,onChange:r,label:i,t:a,required:o}=e,s=o===void 0?!1:o,[c,l]=(0,Q.useState)(!1),u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=g(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=c?`text`:`password`,f;t[1]===r?f=t[2]:(f=e=>r(e.target.value),t[1]=r,t[2]=f);let m;t[3]!==s||t[4]!==d||t[5]!==f||t[6]!==n?(m=(0,$.jsx)(`input`,{className:u,type:d,value:n,required:s,autoComplete:`off`,onChange:f}),t[3]=s,t[4]=d,t[5]=f,t[6]=n,t[7]=m):m=t[7];let h;t[8]!==i||t[9]!==m?(h=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i,m]}),t[8]=i,t[9]=m,t[10]=h):h=t[10];let _;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(_=()=>l(zn),t[11]=_):_=t[11];let v;t[12]===c?v=t[13]:(v=c?(0,$.jsx)(Ve,{className:`size-4`,"aria-hidden":!0}):(0,$.jsx)(p,{className:`size-4`,"aria-hidden":!0}),t[12]=c,t[13]=v);let y=c?a.setupHideValue:a.setupShowValue,b;t[14]!==v||t[15]!==y?(b=(0,$.jsxs)(C,{type:`button`,variant:`ghost`,className:`gap-1.5 text-xs`,onClick:_,children:[v,y]}),t[14]=v,t[15]=y,t[16]=b):b=t[16];let x;return t[17]!==b||t[18]!==h?(x=(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[h,b]}),t[17]=b,t[18]=h,t[19]=x):x=t[19],x}function zn(e){return!e}function Bn(e){let t=(0,ft.c)(17),{headers:n,onChange:r,t:i,additional:a,environment:o}=e,s=a===void 0?!1:a,c=o===void 0?!1:o,l=c?i.envLabel:s?i.setupAdditionalHeaders:i.headersLabel,u=c?i.setupAddEnv:i.addHeader,d=c?i.setupRemoveEnv:i.removeHeader,f=c?i.setupEnvName:i.headerKeyPlaceholder,p=c?i.setupEnvValue:i.headerValuePlaceholder,m=!c,h;return t[0]!==n||t[1]!==r||t[2]!==i.optionalSuffix||t[3]!==i.pasteHeaders||t[4]!==i.pasteHeadersDismiss||t[5]!==i.pasteHeadersFailed||t[6]!==i.pasteHeadersFailedTitle||t[7]!==i.setupHideValue||t[8]!==i.setupReference||t[9]!==i.setupShowValue||t[10]!==l||t[11]!==u||t[12]!==d||t[13]!==f||t[14]!==p||t[15]!==m?(h=(0,$.jsx)(In,{label:l,optionalLabel:i.optionalSuffix,addLabel:u,removeHeaderAria:d,pasteLabel:i.pasteHeaders,pasteFailed:i.pasteHeadersFailed,pasteFailedTitle:i.pasteHeadersFailedTitle,dismissLabel:i.pasteHeadersDismiss,keyPlaceholder:f,valuePlaceholder:p,headers:n,onChange:r,referenceLabel:i.setupReference,showValueLabel:i.setupShowValue,hideValueLabel:i.setupHideValue,allowPaste:m}),t[0]=n,t[1]=r,t[2]=i.optionalSuffix,t[3]=i.pasteHeaders,t[4]=i.pasteHeadersDismiss,t[5]=i.pasteHeadersFailed,t[6]=i.pasteHeadersFailedTitle,t[7]=i.setupHideValue,t[8]=i.setupReference,t[9]=i.setupShowValue,t[10]=l,t[11]=u,t[12]=d,t[13]=f,t[14]=p,t[15]=m,t[16]=h):h=t[16],h}function Vn(e){let t=(0,ft.c)(52),{draft:n,onChange:r,t:i,allowExisting:a}=e,o=i.setupAuthLabel,l=i.setupAuthLabel,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=g(Ln,`mt-1.5`),t[0]=u):u=t[0];let d=n.mode,f;t[1]===r?f=t[2]:(f=e=>r({mode:e.target.value}),t[1]=r,t[2]=f);let p;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=[`auto`,`oauth`,`bearer`,`apiKey`,`headers`,`none`],t[3]=p):p=t[3];let m;t[4]===i.setupAuthModes?m=t[5]:(m=p.map(e=>(0,$.jsx)(c,{value:e,children:i.setupAuthModes[e]},e)),t[4]=i.setupAuthModes,t[5]=m);let h;t[6]!==a||t[7]!==n.mode||t[8]!==i.setupAuthModes?(h=a||n.mode===`existing`?(0,$.jsx)(c,{value:`existing`,children:i.setupAuthModes.existing}):null,t[6]=a,t[7]=n.mode,t[8]=i.setupAuthModes,t[9]=h):h=t[9];let _;t[10]!==n.mode||t[11]!==i.setupAuthLabel||t[12]!==f||t[13]!==m||t[14]!==h?(_=(0,$.jsxs)(s,{"aria-label":l,className:u,value:d,onChange:f,children:[m,h]}),t[10]=n.mode,t[11]=i.setupAuthLabel,t[12]=f,t[13]=m,t[14]=h,t[15]=_):_=t[15];let v;t[16]!==i.setupAuthLabel||t[17]!==_?(v=(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[o,_]}),t[16]=i.setupAuthLabel,t[17]=_,t[18]=v):v=t[18];let y;t[19]!==n.mode||t[20]!==i.setupAuthAutoHint?(y=n.mode===`auto`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthAutoHint}):null,t[19]=n.mode,t[20]=i.setupAuthAutoHint,t[21]=y):y=t[21];let b;t[22]!==n.mode||t[23]!==i.setupAuthOAuthHint?(b=n.mode===`oauth`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupAuthOAuthHint}):null,t[22]=n.mode,t[23]=i.setupAuthOAuthHint,t[24]=b):b=t[24];let x;t[25]!==n.mode||t[26]!==i.setupExistingHint?(x=n.mode===`existing`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupExistingHint}):null,t[25]=n.mode,t[26]=i.setupExistingHint,t[27]=x):x=t[27];let S;t[28]!==n.mode||t[29]!==n.token||t[30]!==r||t[31]!==i?(S=n.mode===`bearer`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Rn,{value:n.token,onChange:e=>r({token:e}),label:i.setupTokenLabel,t:i,required:!0}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupTokenHint})]}):null,t[28]=n.mode,t[29]=n.token,t[30]=r,t[31]=i,t[32]=S):S=t[32];let C;t[33]!==n.apiKey||t[34]!==n.headerName||t[35]!==n.mode||t[36]!==r||t[37]!==i?(C=n.mode===`apiKey`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[i.setupApiKeyHeader,(0,$.jsx)(`input`,{className:g(Ln,`mt-1.5`),placeholder:`x-api-key`,value:n.headerName,required:!0,onChange:e=>r({headerName:e.target.value})})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.setupApiKeyHint}),(0,$.jsx)(Rn,{value:n.apiKey,onChange:e=>r({apiKey:e}),label:`API Key`,t:i,required:!0})]}):null,t[33]=n.apiKey,t[34]=n.headerName,t[35]=n.mode,t[36]=r,t[37]=i,t[38]=C):C=t[38];let w;t[39]!==n.customHeaders||t[40]!==n.mode||t[41]!==r||t[42]!==i?(w=n.mode===`headers`?(0,$.jsx)(Bn,{headers:n.customHeaders,onChange:e=>r({customHeaders:e}),t:i}):null,t[39]=n.customHeaders,t[40]=n.mode,t[41]=r,t[42]=i,t[43]=w):w=t[43];let T;return t[44]!==v||t[45]!==y||t[46]!==b||t[47]!==x||t[48]!==S||t[49]!==C||t[50]!==w?(T=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[v,y,b,x,S,C,w]}),t[44]=v,t[45]=y,t[46]=b,t[47]=x,t[48]=S,t[49]=C,t[50]=w,t[51]=T):T=t[51],T}function Hn(e){let t=(0,ft.c)(8),{label:n,children:r,hint:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`span`,{children:n}),t[0]=n,t[1]=a);let o;t[2]===i?o=t[3]:(o=i?(0,$.jsx)(`span`,{className:`block text-xs font-normal text-fg-muted`,children:i}):null,t[2]=i,t[3]=o);let s;return t[4]!==r||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-fg`,children:[a,r,o]}),t[4]=r,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function Un({row:e,t,onUpdate:n}){let[r,i]=(0,Q.useState)(()=>It(e.envJson?JSON.parse(e.envJson):void 0)),[a,o]=(0,Q.useState)(!1),s=[];try{s=Rt(e.argsText)??[]}catch{}let c=e=>n({argsText:JSON.stringify(e)});return(0,$.jsxs)(`div`,{"data-field":`commandOptions`,className:`space-y-4`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.argsLabel}),(0,$.jsx)(C,{type:`button`,variant:`ghost`,onClick:()=>o(e=>!e),children:a?t.setupArgsRows:t.setupArgsPaste})]}),a?(0,$.jsx)(Hn,{label:t.setupArgsPaste,hint:t.argsHint,children:(0,$.jsx)(`input`,{className:Ln,value:e.argsText,onChange:e=>n({argsText:e.target.value})})}):s.map((e,n)=>(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`input`,{className:Ln,"aria-label":`${t.argsLabel} ${n+1}`,value:e,onChange:e=>c(s.map((t,r)=>r===n?e.target.value:t))}),(0,$.jsx)(C,{type:`button`,variant:`ghost`,"aria-label":t.setupRemoveArg,onClick:()=>c(s.filter((e,t)=>t!==n)),children:(0,$.jsx)(Ee,{className:`size-4`,"aria-hidden":!0})})]},n)),a?null:(0,$.jsxs)(C,{type:`button`,variant:`ghost`,onClick:()=>c([...s,``]),children:[(0,$.jsx)(ge,{className:`size-4`,"aria-hidden":!0}),t.setupAddArg]})]}),(0,$.jsx)(Bn,{environment:!0,headers:r,t,onChange:e=>{i(e),n({envEntries:e,envJson:JSON.stringify(Ft(e)??{})})}})]})}function Wn(e){let t=(0,ft.c)(15),{row:n,t:r,onUpdate:i,variant:a,showOAuth:o,idReadOnly:l}=e,u=a===void 0?`all`:a,d=o===void 0?!1:o,f=l===void 0?!1:l,p=u!==`advanced`,m=u!==`basic`,h;t[0]!==p||t[1]!==i||t[2]!==n||t[3]!==r?(h=p?(0,$.jsxs)($.Fragment,{children:[n.transport===`stdio`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:`${r.commandLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`command`,className:Ln,value:n.command,required:!0,onChange:e=>i({command:e.target.value})})}),(0,$.jsx)(Un,{row:n,t:r,onUpdate:i})]}):(0,$.jsx)(Hn,{label:`${r.urlLabel} *`,children:(0,$.jsx)(`input`,{"data-field":`url`,className:Ln,value:n.url,placeholder:`https://example.com/mcp`,required:!0,onChange:e=>i({url:e.target.value})})}),(0,$.jsx)(Hn,{label:r.setupNameLabel,hint:r.setupNameHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.displayName??``,placeholder:r.setupNamePlaceholder,onChange:e=>i({displayName:e.target.value})})})]}):null,t[0]=p,t[1]=i,t[2]=n,t[3]=r,t[4]=h):h=t[4];let g;t[5]!==m||t[6]!==f||t[7]!==i||t[8]!==n||t[9]!==d||t[10]!==r?(g=m?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Hn,{label:r.serverIdLabel,hint:r.setupIdHint,children:(0,$.jsx)(`input`,{className:Ln,readOnly:f,value:n.id,onChange:e=>i({id:e.target.value}),placeholder:r.serverIdPlaceholder})}),n.transport===`stdio`?(0,$.jsx)(Hn,{label:r.cwdLabel,children:(0,$.jsx)(`input`,{className:Ln,value:n.cwd,onChange:e=>i({cwd:e.target.value})})}):null,n.transport!==`stdio`&&d?(0,$.jsx)(Hn,{label:r.oauthClientIdLabel,hint:r.oauthClientIdHint,children:(0,$.jsx)(`input`,{className:Ln,value:n.oauthClientId,onChange:e=>i({oauthClientId:e.target.value})})}):null,(0,$.jsx)(Hn,{label:r.exposureLabel,hint:r.setupExposureHint,children:(0,$.jsx)(s,{"aria-label":r.exposureLabel,className:Ln,value:n.exposure,onChange:e=>i({exposure:e.target.value}),children:[`codemode`,`deferred`,`direct`,`hidden`].map(e=>(0,$.jsx)(c,{value:e,children:r.exposureLabels[e]},e))})}),(0,$.jsx)(Hn,{label:r.requestTimeoutLabel,children:(0,$.jsx)(dt,{allowEmpty:!0,type:`number`,min:1,className:Ln,value:n.timeout??``,placeholder:r.setupDefaultTimeout,onChange:e=>i({timeout:e.target.value?Number(e.target.value):void 0})})})]}):null,t[5]=m,t[6]=f,t[7]=i,t[8]=n,t[9]=d,t[10]=r,t[11]=g):g=t[11];let _;return t[12]!==h||t[13]!==g?(_=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[h,g]}),t[12]=h,t[13]=g,t[14]=_):_=t[14],_}function Gn(e,t){let n=e;if(n?.status===429)return t.setupRateLimited;if(n?.status===401)return t.setupGatewayUnauthorized;if(n?.status===404||n?.status===409)return t.setupConflict;if(n?.status&&n.status>=500)return t.setupGatewayCheckFailed;let r={command_missing:t.setupCommandMissing,connection_refused:t.setupConnectionRefused,host_not_found:t.setupHostNotFound,timeout:t.setupTimedOut,access_denied:t.setupAccessDenied,network:t.setupServiceNetworkFailed,tls:t.setupTlsFailed,invalid_response:t.setupInvalidResponse,not_found:t.setupEndpointNotFound,rate_limited:t.setupServiceRateLimited,configuration:t.setupInvalidConfig};if(n?.errorCode&&Object.hasOwn(r,n.errorCode))return r[n.errorCode];let i=e instanceof Error?e.message:typeof e==`string`?e:n?.error??``;return/ENOENT|command not found|executable.{0,30}not found/i.test(i)?t.setupCommandMissing:/ECONNREFUSED|connection refused/i.test(i)?t.setupConnectionRefused:/ENOTFOUND|EAI_AGAIN|could not resolve/i.test(i)?t.setupHostNotFound:/timeout|timed out/i.test(i)?t.setupTimedOut:/fetch failed|failed to fetch|network error|NetworkError/i.test(i)?n?.error===void 0?t.setupGatewayNetworkFailed:t.setupServiceNetworkFailed:/\b(?:401|403)\b|unauthorized|forbidden|permission denied/i.test(i)?t.setupAccessDenied:t.setupCheckFailed}function Kn(e,t){return JSON.stringify({id:e.id,config:qt(Nn(e,t))})}function qn(e,t){try{return Kn(e,t)}catch{return JSON.stringify({row:e,auth:t})}}function Jn(e){let{t,cs:n}=e,r=(0,Q.useId)(),[i,a]=(0,Q.useState)(e.initialRow),[o,l]=(0,Q.useState)(()=>Mn(e.initialRow)),[d,p]=(0,Q.useState)(`idle`),[h,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(),[S,w]=(0,Q.useState)(),[T,E]=(0,Q.useState)(),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(!1),[j,N]=(0,Q.useState)(``),[P,F]=(0,Q.useState)(``),[I,L]=(0,Q.useState)([]),[R,z]=(0,Q.useState)(`0`),[B,V]=(0,Q.useState)(0),[H,W]=(0,Q.useState)(``),[G,ne]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(!1),oe=e.mode===`edit`,[K,se]=(0,Q.useState)(``),q=(0,Q.useRef)(void 0),[J]=(0,Q.useState)(()=>qn(e.initialRow,Mn(e.initialRow))),ce=(0,Q.useRef)(e.mode===`edit`?e.initialRow.id:``),le=(0,Q.useRef)(void 0),ue=(0,Q.useRef)(void 0),de=(0,Q.useRef)(void 0),X=(0,Q.useRef)(null),fe=(0,Q.useRef)(``),pe=(0,Q.useRef)(!0),me=(0,Q.useRef)(null),he=(0,Q.useRef)(null),ge=(0,Q.useRef)(null),_e=(0,Q.useRef)(null),ve=(0,Q.useRef)(e.onSaved);ve.current=e.onSaved;let be=T?.state===`starting`||T?.state===`authorizing`,Z=d!==`idle`||be,xe=J!==qn(i,o),Se=i.extra.enabled===!1,Ce=!v&&(xe||!!j.trim());(0,Q.useEffect)(()=>(pe.current=!0,()=>{pe.current=!1,le.current?.abort(),X.current?.close(),q.current&&Zt(q.current).catch(()=>{})}),[]),(0,Q.useEffect)(()=>{if(!Ce)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ce]),(0,Q.useEffect)(()=>{if(!b)return;let e=ge.current?.querySelector(`[data-field="${b.field}"]`),t=e?.closest(`details`);t&&(t.open=!0);let n=e?.querySelector(`input,button,textarea`)??e;return n?.setAttribute(`aria-invalid`,`true`),n?.setAttribute(`aria-describedby`,r),b.focus!==!1&&(n??_e.current)?.focus(),()=>{n?.removeAttribute(`aria-invalid`),n?.removeAttribute(`aria-describedby`)}},[b,r]),(0,Q.useEffect)(()=>{if(!T||!be)return;let e=new AbortController;ue.current=e;let n;async function r(){try{let n=await en(q.current,e.signal);if(e.signal.aborted||(E(n),n.authorizationUrl&&fe.current!==n.authorizationUrl&&(fe.current=n.authorizationUrl,window.electronAPI?.shell?.openExternalUrl?!(await window.electronAPI.shell.openExternalUrl(n.authorizationUrl)).ok&&!e.signal.aborted&&_(t.oauthOpenFailed):X.current&&!X.current.closed&&X.current.location.replace(n.authorizationUrl)),e.signal.aborted))return;if(n.state===`connected`){de.current=void 0,X.current?.close(),w({state:`connected`,toolCount:n.toolCount}),_(``);return}if(n.state===`error`||n.state===`cancelled`){de.current=void 0,X.current?.close(),_(n.state===`cancelled`?t.setupCancelled:t.setupAuthFailed),/client.{0,20}(id|registration)|register|registration/i.test(n.error??``)&&O(!0);return}}catch{if(e.signal.aborted)return;we(),X.current?.close(),_(t.setupAuthFailed);return}n=setTimeout(()=>void r(),1200)}return r(),()=>{e.abort(),clearTimeout(n)}},[T?.id,be,t.oauthOpenFailed,t.setupCancelled,t.setupAuthFailed]);function we(){le.current?.abort(),ue.current?.abort(),q.current&&Zt(q.current).catch(()=>{}),q.current=void 0,se(``),ne(!1),w(void 0),E(void 0),_(``),x(void 0)}function Te(e){a(t=>({...t,...e})),we()}function Ee(e){l(t=>({...t,...e})),we()}function De(){d===`saving`||be||(d===`checking`&&(we(),p(`idle`)),Ce?ae(!0):e.onClose())}function Oe(){try{L(Wt(j)),z(`0`),F(``)}catch{F(t.setupImportError),L([])}}function ke(){let t=I[Number(R)];if(!t)return;let n={...t,id:ce.current||t.id,clientKey:e.initialRow.clientKey,extra:{...t.extra,...ce.current?{enabled:i.extra.enabled}:{}}};a(n),l(Mn(n)),we(),V(e=>e+1),A(!1),N(``),L([])}function Ae(e){function n(e,t){return x({field:e,message:t}),!1}if(e.transport===`streamable-http`){try{e.url=Ut(e.url)}catch{return n(`url`,t.setupAddressInvalid)}if(o.mode===`bearer`&&!o.token.trim().replace(/^Bearer\s*/i,``)||o.mode===`apiKey`&&(!o.apiKey.trim()||!o.headerName.trim()))return n(`auth`,t.setupCredentialRequired);if(Pn(e.headers)>=0)return n(`auth`,t.setupHeaderInvalid);if(o.mode===`oauth`&&e.headers.some(e=>e.key.trim().toLowerCase()===`authorization`))return n(`auth`,t.setupOAuthHeaderConflict);if(o.mode===`headers`&&!e.headers.some(e=>e.key.trim()&&(e.value.trim()||e.reference)))return n(`auth`,t.setupCredentialRequired)}else if(!e.command.trim())return n(`command`,t.setupCommandRequired);if(e.timeout!==void 0&&(!Number.isFinite(e.timeout)||e.timeout<=0))return n(`advanced`,t.setupInvalidConfig);try{qt(e)}catch(r){return n(e.transport===`stdio`?`commandOptions`:`advanced`,r instanceof Error&&r.message.startsWith(`Environment`)?t.setupEnvInvalid:t.setupInvalidConfig)}return!0}async function je(){_(``),p(`checking`),fe.current=``,window.electronAPI?.shell?.openExternalUrl||(X.current=window.open(`about:blank`,`_blank`),X.current&&(X.current.opener=null));try{let e=await $t(q.current);if(!pe.current){X.current?.close(),q.current&&Zt(q.current).catch(()=>{});return}de.current=e.id,E(e)}catch{X.current?.close(),pe.current&&_(t.setupAuthFailed)}finally{pe.current&&p(`idle`)}}async function Me(){let r=Nn(i,o);if(!Ae(r))return;let s=e.existingCustomServers.filter(t=>t.clientKey!==e.initialRow.clientKey&&t.id!==ce.current),c=new Set([...e.managedServerIds,...s.map(e=>e.id)]);if(r.id=ce.current||r.id.trim()||Ht(r,c),!/^[a-zA-Z0-9_-]+$/.test(r.id)||[...c].some(e=>e.replace(/-/g,`_`)===r.id.replace(/-/g,`_`))){x({field:`advanced`,message:n.duplicateServerId});return}we(),p(`checking`);let l=new AbortController;le.current=l;try{let n=await Yt(r,ce.current||void 0,e.initialRow.extra,l.signal);if(!pe.current||l.signal.aborted){Zt(n.id).catch(()=>{});return}q.current=n.id,a(r),se(qn(r,o));let i=await Xt(n.id,l.signal);if(!pe.current||l.signal.aborted)return;w(i),i.state===`error`&&_(Gn(i,t))}catch(e){pe.current&&!l.signal.aborted&&_(e.status===409?t.setupConflict:Gn(e,t))}finally{pe.current&&le.current===l&&p(`idle`)}}async function Ne(n=!1){if(!(!q.current||S?.state!==`connected`||K!==qn(i,o))){p(`saving`),_(``);try{let t=await Qt(q.current,n);q.current=void 0,await ve.current().catch(()=>{}),t?.reloadRequired?y(!0):e.onClose()}catch(e){let n=e.status;n===404||n===409?(we(),_(t.setupConflict)):_(t.setupSaveFailed)}finally{pe.current&&p(`idle`)}}}async function Pe(){ue.current?.abort();let e=q.current;de.current=void 0,E(void 0),X.current?.close(),_(t.setupCancelled),p(`checking`);try{e&&await tn(e)}catch{pe.current&&(we(),_(t.setupCancelled))}finally{pe.current&&p(`idle`)}}async function Fe(){T?.authorizationUrl&&(window.electronAPI?.shell?.openExternalUrl?(await window.electronAPI.shell.openExternalUrl(T.authorizationUrl)).ok||_(t.oauthOpenFailed):window.open(T.authorizationUrl,`_blank`,`noopener,noreferrer`))}async function Ie(){if(T)try{await nn(q.current,H),W(``),_(``)}catch{_(t.setupRedirectInvalid)}}let Le=!!q.current&&K===qn(i,o)&&(o.mode===`oauth`||o.mode===`auto`&&S?.state===`oauth_required`)&&S?.state!==`connected`,Re=/^(?:https?:\/\/)?(?:localhost|127\.0\.0\.1|\[::1\])(?=[:/]|$)/i.test(i.url.trim()),ze=I[Number(R)];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(te,{open:e.open,onOpenChange:e=>{e||De()},children:(0,$.jsxs)(ye,{children:[(0,$.jsx)(M,{className:`fixed inset-0 z-[60] bg-scrim`}),(0,$.jsxs)(Y,{ref:me,tabIndex:-1,className:`fixed left-1/2 top-1/2 z-[60] flex h-[min(44rem,calc(100dvh-2rem))] w-[min(42rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-overlay`,onOpenAutoFocus:e=>{e.preventDefault(),me.current?.focus()},children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge p-5`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ee,{className:`font-semibold`,children:e.mode===`edit`?t.setupEditTitle:t.setupTitle}),(0,$.jsx)(st,{className:`mt-1 text-sm text-fg-muted`,children:t.setupHint})]}),(0,$.jsx)(`button`,{type:`button`,disabled:d===`saving`||be,onClick:De,className:`rounded-lg p-2 text-fg-muted hover:bg-surface-hover disabled:opacity-50`,"aria-label":n.modalClose,children:(0,$.jsx)(re,{className:`size-5`,"aria-hidden":!0})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain p-5`,children:[k?(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(C,{variant:`ghost`,onClick:()=>A(!1),children:t.setupImportBack}),(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportEmpty}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium text-fg`,children:[t.setupImport,(0,$.jsx)(`textarea`,{className:g(Ln,`mt-1.5 min-h-40 font-mono text-xs`),value:j,placeholder:`{"mcpServers": {"docs": {"url": "https://example.com/mcp"}}}`,onChange:e=>{N(e.target.value),L([]),F(``)}})]}),(0,$.jsx)(C,{variant:`secondary`,disabled:!j.trim(),onClick:Oe,children:t.setupImportPreview}),P?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:P}):null,ze?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupImportScope}),(0,$.jsxs)(`label`,{className:`block text-sm font-medium`,children:[t.setupImportChoose,(0,$.jsx)(s,{"aria-label":t.setupImportChoose,className:g(Ln,`mt-1.5`),value:R,onChange:e=>z(e.target.value),children:I.map((e,t)=>(0,$.jsx)(c,{value:String(t),children:e.displayName||e.id||un(e)},t))})]}),(0,$.jsxs)(`p`,{className:`break-all text-sm text-fg-muted`,children:[ze.transport===`stdio`?t.setupUseCommand:t.setupUseUrl,` · `,un(ze)]})]}):null]}):(0,$.jsxs)(`form`,{ref:ge,noValidate:!0,onBlurCapture:e=>{if(e.target instanceof HTMLInputElement&&e.target.dataset.field===`url`&&i.url.trim())try{Ut(i.url)}catch{x({field:`url`,message:t.setupAddressInvalid,focus:!1})}},onSubmit:e=>{e.preventDefault(),Me()},children:[(0,$.jsxs)(`fieldset`,{disabled:Z||v,className:`min-w-0 space-y-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(U,{className:`flex gap-1`,role:`group`,"aria-label":t.transportLabel,children:[`streamable-http`,`stdio`].map(e=>(0,$.jsx)(C,{type:`button`,variant:i.transport===e?`secondary`:`ghost`,"aria-pressed":i.transport===e,onClick:()=>Te({transport:e}),children:e===`stdio`?t.setupUseCommand:t.setupUseUrl},e))}),(0,$.jsx)(C,{type:`button`,variant:`ghost`,onClick:()=>A(!0),children:t.setupImport})]}),(0,$.jsx)(`div`,{children:(0,$.jsx)(Wn,{row:i,t,variant:`basic`,onUpdate:Te},`${i.transport}-${B}`)}),i.transport===`streamable-http`?(0,$.jsx)(`div`,{"data-field":`auth`,children:(0,$.jsx)(Vn,{allowExisting:!!i.extra.auth||i.headers.some(e=>!!e.reference),draft:o,onChange:Ee,t})}):null,b?(0,$.jsx)(`p`,{id:r,ref:_e,tabIndex:-1,role:`alert`,className:`text-sm text-danger`,children:b.message}):null,(0,$.jsxs)(`details`,{"data-field":`advanced`,className:`rounded-lg border border-edge p-3`,open:D,onToggle:e=>O(e.currentTarget.open),children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg-muted`,children:t.setupAdvanced}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[(0,$.jsx)(Wn,{row:i,t,variant:`advanced`,idReadOnly:oe,showOAuth:o.mode===`oauth`,onUpdate:Te}),i.transport===`streamable-http`&&o.mode!==`headers`&&o.mode!==`existing`?(0,$.jsx)(Bn,{additional:!0,headers:o.additionalHeaders,onChange:e=>Ee({additionalHeaders:e}),t}):null]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-muted`,children:i.transport===`stdio`?t.setupCommandHostHint:Re?t.setupLocalhostHint:t.setupGatewayHint}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.setupTestNotice})]}),(0,$.jsx)(`button`,{type:`submit`,hidden:!0})]}),v?(0,$.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-fg`,children:t.setupReloadRequired}):null,!k&&!v?(0,$.jsxs)(`div`,{className:`mt-4 space-y-3`,"aria-live":`polite`,children:[d===`idle`?null:(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(m,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),d===`saving`?t.setupSaving:t.setupChecking]}),d===`idle`&&oe&&!xe&&!S&&!h&&!be?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:Se?t.setupDisabled:e.lastCheck?t.setupLastCheck.replace(`{{count}}`,String(e.lastCheck.toolCount)):t.setupSavedUnchecked}):null,S?.state===`connected`?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-success`,children:[(0,$.jsx)(u,{className:`size-4 shrink-0`,"aria-hidden":!0}),S.toolCount?t.setupConnected.replace(`{{count}}`,String(S.toolCount)):t.setupZeroTools]}),(0,$.jsx)(C,{ref:he,variant:`secondary`,onClick:()=>ne(!0),children:t.viewTools})]}):null,S?.state===`token_required`?(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-fg-muted`,children:t.setupNeedsAuth}):null,S?.state===`oauth_required`&&!be?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.setupOAuthRequired}):null,be?(0,$.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-edge p-4`,children:[(0,$.jsxs)(`p`,{role:`status`,className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(m,{className:`size-4 animate-spin motion-reduce:animate-none`,"aria-hidden":!0}),t.setupAuthorizing]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[T?.authorizationUrl?(0,$.jsxs)(C,{variant:`secondary`,onClick:()=>void Fe(),children:[(0,$.jsx)(f,{className:`size-4`,"aria-hidden":!0}),t.oauthOpenAuthorization]}):null,(0,$.jsx)(C,{variant:`ghost`,onClick:()=>void Pe(),children:t.setupCancelAuth})]}),T?.acceptsRedirect?(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm text-accent-fg`,children:t.setupRemoteFallback}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.setupRedirectHint}),(0,$.jsxs)(`label`,{className:`mt-2 block text-sm`,children:[t.setupRedirectLabel,(0,$.jsx)(`input`,{className:Ln,value:H,onChange:e=>W(e.target.value)})]}),(0,$.jsx)(C,{className:`mt-2`,disabled:!H.trim(),onClick:()=>void Ie(),children:t.setupContinue})]}):null]}):null,h?(0,$.jsxs)(`div`,{role:`alert`,className:`space-y-1 text-sm`,children:[(0,$.jsx)(`p`,{className:`text-danger`,children:h}),h!==t.setupSaveFailed&&d!==`saving`?(0,$.jsx)(`p`,{className:`text-fg-muted`,children:t.setupTestFailure}):null]}):null]}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-2 border-t border-edge p-4`,children:[(0,$.jsx)(C,{variant:`secondary`,disabled:d===`saving`||be,onClick:De,children:oe||v?t.setupClose:n.modalCancel}),v?null:k?(0,$.jsx)(C,{variant:`primary`,disabled:!ze,onClick:ke,children:t.setupImportApply}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(C,{variant:S?.state===`connected`?`secondary`:`primary`,disabled:Z,onClick:()=>Le?void je():void Me(),children:Le?t.setupSignIn:t.setupTestConnection}),S?.state===`connected`&&K===qn(i,o)?(0,$.jsxs)($.Fragment,{children:[Se?(0,$.jsx)(C,{variant:`secondary`,disabled:Z,onClick:()=>void Ne(!0),children:t.setupEnableSave}):null,(0,$.jsx)(C,{variant:`primary`,disabled:Z,"aria-busy":Z,onClick:()=>void Ne(),children:oe?t.setupSaveOnly:t.setupAddConnection})]}):null]})]})]})]})}),(0,$.jsx)(We,{open:ie,title:t.setupUnsavedTitle,description:t.setupUnsavedHint,confirmLabel:t.setupDiscard,cancelLabel:t.setupKeepEditing,onCancel:()=>ae(!1),onConfirm:e.onClose,overlayClassName:`z-[70]`,contentClassName:`z-[70]`}),G?(0,$.jsx)(sn,{draftId:q.current,serverId:i.id,displayName:i.displayName,returnFocusTo:he.current,t,onClose:()=>ne(!1)}):null]})}var Yn=`recommended`,Xn=`builtin`,Zn=`composio`,Qn=`xopc-store`;function $n(e,t=`en`){return e==="default"&&t.startsWith(`zh`)?Yn:Xn}function er(e,t){let n=e.connectorManifest;if(!n||typeof n!=`object`||Array.isArray(n))return null;let r=n;if(r.contractVersion!==1||r.id!==e.name)return null;let i=r.runtime,a=r.auth;if(!i||typeof i!=`object`||Array.isArray(i)||!a||typeof a!=`object`||Array.isArray(a))return null;let o=i,s=a;if(o.type!==`mcp`||typeof o.serverId!=`string`)return null;let c=[`code`,`docs`,`browser`,`data`,`automation`,`custom`].includes(String(r.category??``))?r.category:`custom`,l=s.mode===`oauth`?{mode:`oauth`,...typeof s.clientId==`string`?{clientId:s.clientId}:{}}:s.mode===`apiKey`?{mode:`apiKey`}:{mode:`none`},u=e.localizations?.[t===`zh`?`zh-CN`:`en`];return{id:e.name,version:e.latestVersion??`store`,displayName:u?.displayName??(typeof r.displayName==`string`?r.displayName:e.name),description:u?.description??(typeof r.description==`string`?r.description:e.description),category:c,kind:`mcp`,source:`store`,...e.branding?.iconUrl?{branding:{logoUrl:e.branding.iconUrl,source:`registry`}}:{},capabilities:Array.isArray(r.capabilities)?r.capabilities.filter(e=>typeof e==`string`):[],tags:Array.isArray(r.tags)?r.tags.filter(e=>typeof e==`string`):[`store`],auth:l,setup:r.setup&&typeof r.setup==`object`&&!Array.isArray(r.setup)?r.setup:{},runtime:{type:`mcp`,serverId:o.serverId}}}function tr(e){return J(e.map(e=>({connector:e,service:{id:e.id,source:e.source===`builtin`?`builtin-connector`:e.source===`store`?`store-connector`:`registry-connector`}})),`en`).map(e=>e.connector)}function nr(e){return e?.startsWith(`/`)&&!e.startsWith(`//`)?e:`/user-model`}function rr({embedded:e=!1,onHeaderActionChange:t}){let n=O().filter(pn),r=y(e=>e.language),o=h(r),s=o.connectorsSettings,c=o.mcpSettings,u=v(e=>e.conversationId),d=!!u,f=a(),[p,_]=i(),b=p.get(`understanding`)===`1`,x=nr(p.get(`returnTo`)),w=!!p.get(`returnTo`)&&!b,T=p.get(`tab`),[D,A]=(0,Q.useState)(!b&&T===`connected`?`connected`:`discover`),{data:M}=S(d&&D===`discover`&&!b?[`service-recommendations`,r]:null,()=>L(r),{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>new Set(M?.items.filter(e=>e.service?.source===`store-plugin`).map(e=>oe(e.id))??[]),[M]),F=(0,Q.useRef)(!1),[I,R]=(0,Q.useState)({catalog:[],registryCatalog:[],instances:[],loading:!0,error:null}),[z,B]=(0,Q.useState)(!1),[V,H]=(0,Q.useState)(!1),[ee,te]=(0,Q.useState)(1),[G,ne]=(0,Q.useState)(void 0),[re,ae]=(0,Q.useState)(``),[K,se]=(0,Q.useState)(b||w?p.get(`connector`)??``:``),[q,J]=(0,Q.useState)($n(b?`understanding`:`default`,r)),[ce,le]=(0,Q.useState)(`name`),[Y,X]=(0,Q.useState)(b?`understand`:`all`),[fe,me]=(0,Q.useState)(null),[he,ge]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(null),[Z,xe]=(0,Q.useState)(null),[Se,Ce]=(0,Q.useState)(null),[Te,Ee]=(0,Q.useState)(null),{data:Oe,mutate:ke}=E(d),Ae=Oe?.payload?.config,je=(0,Q.useMemo)(()=>Ae===void 0?null:Kt(Ae),[Ae]),Me=je?.servers??[],Ne=I.instances.length+Me.length+n.length,[Fe,Ie]=(0,Q.useState)({});(0,Q.useEffect)(()=>{if(Ie({}),!d||!Ae)return;let e=new AbortController;return an(e.signal).then(t=>{e.signal.aborted||Ie(t)}).catch(()=>{}),()=>e.abort()},[d,Ae]);let Le=(0,Q.useCallback)(async()=>{if(!u){R({catalog:[],registryCatalog:[],instances:[],loading:!1,error:null});return}R(e=>({...e,loading:!0,error:null}));try{let[e,t]=await Promise.all([ue(),k()]);R(n=>({catalog:e,registryCatalog:n.registryCatalog,instances:t,loading:!1,error:null}))}catch(e){R({catalog:[],registryCatalog:[],instances:[],loading:!1,error:e instanceof Error?e.message:String(e)})}},[u]);(0,Q.useEffect)(()=>{Le()},[Le]),(0,Q.useEffect)(()=>{F.current||I.loading||d&&!je||(A(b?`discover`:Ne>0?`connected`:`discover`),F.current=!0)},[d,Ne,je,b,I.loading]),(0,Q.useEffect)(()=>{J(e=>e===`builtin`||e===`recommended`?$n(b?`understanding`:`default`,r):e)},[r,b]);let Re=(0,Q.useCallback)(e=>{F.current=!0,A(e)},[]),ze=(0,Q.useMemo)(()=>[{id:Zn,displayName:s.composioSourceName},{id:Qn,displayName:s.storeSourceName}],[s.composioSourceName,s.storeSourceName]),Be=(0,Q.useCallback)(async e=>{if(!d||q===`builtin`||q===`recommended`){R(e=>({...e,registryCatalog:[]})),te(1),ne(void 0);return}let t=K.trim(),n=Math.max(e?.page??1,1),i=e?.append??!1,a=q===`all`?ze:ze.filter(e=>e.id===q);if(a.length!==0){B(!0),i?R(e=>({...e,error:null})):(te(1),ne(void 0),R(e=>({...e,registryCatalog:[],error:null})));try{let e=await Promise.all(a.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 i=await Pe({q:t||void 0,page:n,pageSize:24,sort:ce===`source`?`newest`:`downloads`});return{connectors:i.items.flatMap(e=>{let t=er(e,r);return t?[t]:[]}),totalPages:i.meta.totalPages}})),o=tr(e.flatMap(e=>e.connectors)),s=Math.max(1,...e.map(e=>e.totalPages??1));te(n),ne(s),R(e=>({...e,registryCatalog:i?tr([...e.registryCatalog,...o]):o}))}catch(e){R(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{B(!1)}}},[ce,K,q,d,ze,r]);(0,Q.useEffect)(()=>{if(D!==`discover`||I.loading)return;if(q===`builtin`||q===`recommended`){R(e=>({...e,registryCatalog:[]})),te(1),ne(void 0);return}let e=window.setTimeout(()=>{Be()},K.trim()?350:0);return()=>window.clearTimeout(e)},[K,q,Be,I.loading,D]);let Ve=(0,Q.useMemo)(()=>new Set(I.instances.map(e=>e.connectorId)),[I.instances]),He=(0,Q.useMemo)(()=>new Map([...I.catalog,...I.registryCatalog].map(e=>[e.id,e])),[I.catalog,I.registryCatalog]);(0,Q.useEffect)(()=>{if(I.loading)return;let e=p.get(`connector`),t=p.get(`instance`);if(!e&&!t)return;let n=I.instances.find(n=>t?n.instanceId===t:n.connectorId===e);if(n)F.current=!0,ae(``),ye(n.instanceId),xe(n),A(`connected`);else if(e){let t=He.get(e);if(!t)return;F.current=!0,J($n(b?`understanding`:`default`,r)),se(``),ge(t),A(`discover`)}let i=new URLSearchParams(p);i.delete(`connector`),i.delete(`instance`),i.set(`tab`,n?`connected`:`discover`),_(i,{replace:!0})},[He,b,r,p,_,I.instances,I.loading]);let Ue=(0,Q.useCallback)(async e=>{H(!0),R(e=>({...e,error:null}));try{let t=await Qe(e);me(ie(t.definition,{packageName:t.packageName,version:t.version,reviewHash:t.reviewHash,permissions:t.permissions}))}catch(e){R(t=>({...t,error:e instanceof Error?e.message:String(e)}))}finally{H(!1)}},[]);(0,Q.useEffect)(()=>{let e=p.get(`storeConnector`);if(!d||!e)return;let t=new URLSearchParams(p);t.delete(`storeConnector`),_(t,{replace:!0}),Ue(e)},[d,p,_,Ue]);let We=(0,Q.useMemo)(()=>new Set(I.instances.flatMap(e=>e.materialized.type===`mcp`?[e.materialized.serverId]:[])),[I.instances]),Ge=(0,Q.useCallback)(async e=>{let t=await on(e);await ke(),await Le(),t.reloadRequired&&R(e=>({...e,error:c.setupReloadRequired}))},[Le,ke,c.setupReloadRequired]),Ke=(0,Q.useCallback)(()=>{Ee({mode:`add`,row:jn(Me,We)})},[Me,We]),qe=De(e=>e.setPageHeader),Je=De(e=>e.clearPageHeader),Ye=(0,Q.useMemo)(()=>({searchLabel:D===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder,search:(0,$.jsx)(ct,{value:D===`connected`?re:K,onChange:D===`connected`?ae:se,placeholder:D===`connected`?s.connectedSearchPlaceholder:s.discoverSearchPlaceholder}),secondary:(0,$.jsx)(jt,{onRefresh:D===`connected`&&d?Le:void 0,refreshing:I.loading,refreshLabel:s.refreshConnections,onBrowseCatalog:()=>Re(`discover`),onAddCustomServer:Ke,addLabel:s.addConnection,browseLabel:s.addFromCatalog,customLabel:s.addCustomServerAdvanced,serviceLabel:r.startsWith(`zh`)?`应用连接服务`:`Connection service`,moreActionsLabel:o.capabilitiesHub.moreActions})}),[re,s,K,d,r,Le,o.capabilitiesHub.moreActions,Ke,Re,I.loading,D]);(0,Q.useLayoutEffect)(()=>e?(t?.(Ye),()=>t?.(null)):(qe({startExtra:null,main:(0,$.jsx)(`div`,{className:`min-w-0`,children:(0,$.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:s.title})}),end:(0,$.jsx)(lt,{contribution:Ye})}),()=>Je()),[Je,s.title,e,Ye,t,qe]);let Xe=(0,Q.useMemo)(()=>I.instances.map(e=>({instance:e,value:Ct(e,He.get(e.connectorId))})),[He,I.instances]),Ze=(0,Q.useMemo)(()=>new Map(Xe.map(({instance:e,value:t})=>[e.instanceId,t])),[Xe]),$e=(0,Q.useMemo)(()=>I.instances.filter(e=>W(e,re)).sort((e,t)=>{let n={needs_setup:0,checking:1,ready:2},r=Ze.get(e.instanceId)?.state??`checking`,i=Ze.get(t.instanceId)?.state??`checking`;return n[r]-n[i]||e.displayName.localeCompare(t.displayName)}),[re,Ze,I.instances]),et=(0,Q.useMemo)(()=>$e.filter(e=>Ze.get(e.instanceId)?.state===`needs_setup`),[Ze,$e]),tt=(0,Q.useMemo)(()=>$e.filter(e=>Ze.get(e.instanceId)?.state!==`needs_setup`),[Ze,$e]),nt=(0,Q.useMemo)(()=>Me.filter(e=>N(e,re)),[re,Me]),rt=(0,Q.useMemo)(()=>{let e=re.trim().toLowerCase();return n.filter(t=>[t.name,t.description,...(t.setup?.authorizations??[]).map(e=>e.title),...(t.components?.mcp??[]).map(e=>e.name)].filter(Boolean).join(` `).toLowerCase().includes(e))},[re,n]),it=$e.length+nt.length+rt.length,ot=(0,Q.useMemo)(()=>I.catalog.filter(e=>e.source===`builtin`&&e.integrationStrategy?.preferred!==!1&&_e(e)),[I.catalog]),st=(0,Q.useMemo)(()=>q===`recommended`?[]:q===`builtin`?ot:q===`all`?tr([...ot,...I.registryCatalog]):I.registryCatalog,[ot,q,I.registryCatalog]),ut=(0,Q.useMemo)(()=>{let e=b?st.filter(e=>e.understanding?.mode===`activity`):tr(st).filter(e=>!P.has(oe(e.id)));return be(Y===`all`?e:e.filter(e=>xt(e).includes(Y)),K,ce)},[ce,K,st,b,Y,P]),dt=(0,Q.useMemo)(()=>bt.filter(e=>st.some(t=>xt(t).includes(e))),[st]);(0,Q.useEffect)(()=>{Y!==`all`&&!dt.includes(Y)&&X(`all`)},[dt,Y]);let ft=D===`discover`&&q!==`builtin`&&!!(G&&ee<G),mt=(0,Q.useMemo)(()=>I.instances.find(e=>e.instanceId===ve)??Z,[ve,Z,I.instances]),_t=(0,Q.useMemo)(()=>[{value:Yn,label:r===`zh`?`推荐服务`:`Recommended services`},{value:`all`,label:s.discoverSourceAll},{value:Xn,label:s.discoverSourceBuiltin},...ze.map(e=>({value:e.id,label:e.displayName}))],[s.discoverSourceAll,s.discoverSourceBuiltin,ze,r]),St=[{id:`connected`,label:s.tabConnected,count:Ne},{id:`discover`,label:s.tabDiscover}];return(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:(0,$.jsxs)(`div`,{className:g(`mx-auto flex w-full max-w-7xl flex-col gap-6 px-4 sm:px-6 lg:px-8`,e?`pb-7 pt-3 lg:pb-9 lg:pt-4`:`py-7 lg:py-9`),children:[d?null:(0,$.jsx)(`p`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3 text-sm text-fg-muted`,children:s.tokenHint}),b?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.understandingSetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.understandingSetupHint})]}),(0,$.jsx)(C,{type:`button`,variant:`secondary`,className:`shrink-0`,onClick:()=>f(x),children:s.understandingSetupDone})]}):null,w?(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-accent/25 bg-accent-soft px-4 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-fg`,children:s.recoverySetupTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:s.recoverySetupHint})]}),(0,$.jsx)(C,{type:`button`,variant:`secondary`,className:`min-h-11 shrink-0`,onClick:()=>f(x),children:s.recoverySetupDone})]}):null,(0,$.jsxs)(`section`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(`div`,{className:`border-b border-edge-subtle pb-3 dark:border-edge-subtle`,children:(0,$.jsx)(at,{items:St,activeTab:D,onChange:Re,ariaLabel:s.navAria,tabIdPrefix:`connectors-tab`,panelIdPrefix:`connectors-panel`,className:`flex-wrap`})}),I.error?(0,$.jsx)(`p`,{className:`rounded-xl bg-red-500/10 px-3 py-2 text-sm text-red-600`,children:I.error}):null,D===`connected`&&d?(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:I.loading?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.slice(0,3).map(e=>(0,$.jsx)(yt,{},e))}):Ne===0?(0,$.jsxs)(`div`,{className:`py-14 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.connectionsEmpty}),(0,$.jsx)(C,{type:`button`,variant:`primary`,className:`mt-4`,onClick:()=>Re(`discover`),children:s.addFromCatalog})]}):it===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.connectionsSearchEmpty}):(0,$.jsxs)(`div`,{className:`space-y-6`,children:[et.length?(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:s.needsAttentionTitle}),(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-amber-700 dark:text-amber-300`,children:et.length})]}),(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:et.map(e=>(0,$.jsx)(An,{instance:e,definition:He.get(e.connectorId),highlighted:e.instanceId===Se,onOpenDetails:e=>{Ce(null),ye(e.instanceId),xe(e)},t:s},e.instanceId))})]}):null,tt.length||rt.length?(0,$.jsx)(`section`,{children:(0,$.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[tt.map(e=>(0,$.jsx)(An,{instance:e,definition:He.get(e.connectorId),highlighted:e.instanceId===Se,onOpenDetails:e=>{Ce(null),ye(e.instanceId),xe(e)},t:s},e.instanceId)),rt.map(e=>(0,$.jsx)(mn,{extension:e,language:r,onOpen:()=>f(de(e.pluginId,`connections`,e.authorizationStatus===`required`))},e.id))]})}):null,nt.length||!re.trim()?(0,$.jsx)(fn,{servers:nt,lastChecks:Fe,t:c,cs:s,onAdd:Ke,onEdit:e=>Ee({mode:`edit`,row:structuredClone(e)}),onRemove:Ge}):null]})}):null,D===`discover`&&d?(0,$.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[b?null:(0,$.jsx)(U,{className:`flex min-w-0 flex-1 basis-80 flex-wrap gap-2`,role:`group`,"aria-label":s.taskFilterAria,indicatorClassName:`rounded-lg bg-surface-active`,children:[`all`,...dt].map(e=>(0,$.jsx)(`button`,{type:`button`,className:g(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,Y===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":Y===e,onClick:()=>X(e),children:e===`all`?s.taskAll:s.connectorBenefitHeadings[e]},e))}),(0,$.jsxs)(`div`,{className:g(`ml-auto grid w-full gap-2 sm:flex sm:w-auto sm:justify-end`,b?`grid-cols-1`:`grid-cols-2`),children:[b?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(l,{value:q,options:_t,placeholder:s.discoverSourceAll,allowEmpty:!1,ariaLabel:s.registrySourceAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:J})}),q===`recommended`?null:(0,$.jsx)(`div`,{className:`min-w-0 sm:w-40`,children:(0,$.jsx)(l,{value:ce,options:[{value:`name`,label:s.sortName},{value:`source`,label:s.sortSource}],placeholder:s.sortName,allowEmpty:!1,ariaLabel:s.sortAria,triggerClassName:`h-9 bg-surface-panel text-xs`,onChange:e=>le(e)})})]})]}),q===`recommended`?(0,$.jsx)(pe,{layout:`cards`,initialCount:6,query:K,onChanged:async()=>{await Le(),await ke()}}):(I.loading||z)&&ut.length===0?(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,"aria-busy":`true`,"aria-label":s.loading,children:ht.map(e=>(0,$.jsx)(vt,{},e))}):ut.length===0?(0,$.jsx)(`div`,{className:`py-14 text-center text-sm text-fg-muted`,children:s.discoverEmpty}):(0,$.jsxs)(`div`,{className:`relative`,children:[z?(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-[1] flex justify-center bg-surface-panel/40 pt-[min(28vh,7.5rem)] backdrop-blur-[1px] motion-reduce:backdrop-blur-none dark:bg-surface-base/35`,"aria-busy":`true`,"aria-label":s.loading,children:(0,$.jsx)(m,{className:`size-8 shrink-0 animate-spin text-accent motion-reduce:animate-none`,strokeWidth:2,"aria-hidden":!0})}):null,(0,$.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:ut.map(e=>(0,$.jsx)(pt,{connector:e,installed:Ve.has(e.id)||gt(e,I.instances),onInstall:e=>{if(e.source===`store`){Ue(e.id);return}me(ie(e))},onOpenDetails:e.source===`store`?void 0:ge,t:s},e.id))}),ft?(0,$.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,$.jsxs)(C,{type:`button`,variant:`secondary`,disabled:z||V,onClick:()=>void Be({page:ee+1,append:!0}),children:[z?(0,$.jsx)(m,{className:`size-4 animate-spin`}):null,s.loadMore]})}):null]})]}):null]}),fe?(0,$.jsx)(j,{draft:fe,onChange:me,onClose:()=>me(null),t:s,onInstalled:async e=>{await Le(),await ke(),Ce(e.instanceId),Re(`connected`)}}):null,he?(0,$.jsx)(Dt,{connector:he,installed:Ve.has(he.id)||gt(he,I.instances),onClose:()=>ge(null),onInstall:e=>me(ie(e)),t:s}):null,mt?(0,$.jsx)(kn,{instance:mt,definition:He.get(mt.connectorId),onClose:()=>{ye(null),xe(null)},onChanged:Le,t:s,mcp:c}):null,Te?(0,$.jsx)(Jn,{open:!0,mode:Te.mode,initialRow:Te.row,lastCheck:Te.mode===`edit`?Fe[Te.row.id]:void 0,existingCustomServers:Me,config:Ae,managedServerIds:We,t:c,cs:s,onClose:()=>Ee(null),onSaved:async()=>{await ke(),await Le(),Re(`connected`)}},`${Te.mode}-${Te.row.clientKey}`):null]})})}export{rr as ConnectorsPage};
@@ -1 +0,0 @@
1
- import{i as e,n as t}from"./rolldown-runtime-aKtaBQYM.js";import{a as n,n as r,t as i}from"./vendor-react-BOUWij0V.js";import{u as a}from"./chunk-KS7C4IRE-BvcCCgTW.js";import{t as o}from"./circle-check-C23XjkUj.js";import{t as s}from"./download-Dk-ZjtO6.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./messages-BYq0cPbn.js";import{t as u}from"./cn-0WouolD0.js";import{n as d}from"./locale-store-B7s2Hb35.js";import{i as f}from"./vendor-swr-BIWyz7Rc.js";import{t as p}from"./button-aIC072nz.js";import{t as m}from"./skeleton-BI5TyibZ.js";import{i as h,o as g}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{At as _,Bc as ee,Hc as v,Ic as y,Ii as b,Jc as x,L as S,Md as C,Nt as w,Pc as T,Pu as E,Rc as te,Vc as D,bl as O,eu as k,f as A,io as j,jt as M,m as N,p as ne,xd as re,zc as ie}from"./index-Bys6njTY.js";import{_ as ae,a as oe,d as P,f as se,g as ce,h as le,i as F,l as I,m as ue,n as L,p as de,r as R,s as z,t as B,u as V,v as fe}from"./tunnel-api-B2HnCi0U.js";var H=e(n(),1),U=r(),W=e(S(),1),G={width:240,margin:4,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function pe(e){let t=await W.toString(e,{...G,type:`svg`});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}var K=i();function me(){let e=l(d(e=>e.language)),t=e.endpointToolsSettings.deviceAccess.flow,n=e.tunnelSettings,{data:r,error:i,mutate:a}=f(`tunnel-status`,L,{refreshInterval:1500}),[o,s]=(0,H.useState)(!1),[u,h]=(0,H.useState)(!1),[g,ee]=(0,H.useState)(!0),[v,y]=(0,H.useState)(`idle`),[b,x]=(0,H.useState)(null),[S,C]=(0,H.useState)(``),E=(0,H.useRef)(!0);(0,H.useEffect)(()=>(E.current=!0,()=>{E.current=!1}),[]);let te=async()=>{if(!r)return;if(r.consentRequired&&!o){h(!0);return}let e=r.registrationSecret?.configured?null:N(),t,n=!1;x(null);try{if(r.consentRequired&&await oe(),!r.registrationSecret?.configured){y(`provisioning`);let r=!1;try{await F()}catch(e){if(!V(e))throw e;r=!0}if(r){y(`authorizing`);let r=sessionStorage.getItem(`device-pairing-oauth`),i=r?JSON.parse(r):null;t=i&&i.expiresAt>Date.now()?i.sessionId:(await w(`xopc-tunnel`)).sessionId,sessionStorage.setItem(`device-pairing-oauth`,JSON.stringify({sessionId:t,expiresAt:i&&i.expiresAt>Date.now()?i.expiresAt:Date.now()+5*6e4}));let a=``,o=Date.now()+5*6e4,s=!1;for(;E.current&&Date.now()<o;){let r=await M(t);if(r.authUrl&&r.authUrl!==a&&(a=r.authUrl,await ne(a,e)||C(a)),r.status===`completed`){s=!0,n=!0;break}if(r.status===`failed`||r.status===`cancelled`)throw Error(`Authorization cancelled`);await new Promise(e=>setTimeout(e,1e3))}if(!E.current)return;if(!s)throw Error(`Authorization expired`);await F()}await a()}if(!E.current)return;y(`starting`),await z(),g&&await R({autoStart:!0}),await a(),n=!0}catch(e){n=!0,E.current&&x(I(e)===`tunnel_key_limit_reached`?`key-limit`:`failed`)}finally{A(e),n&&(sessionStorage.removeItem(`device-pairing-oauth`),t&&_(t).catch(()=>{})),E.current&&(y(`idle`),C(``))}};if(!r&&!i)return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsx)(m,{className:`h-5 w-4/5`}),(0,K.jsx)(m,{className:`h-24 w-full`})]});let D=v===`provisioning`||v===`starting`||r?.state===`connecting`||r?.state===`reconnecting`;return(0,K.jsxs)(`div`,{className:`flex min-h-full flex-col`,children:[(0,K.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:D?t.preparingHint:v===`authorizing`?t.authorizing:t.enableHint}),S&&v===`authorizing`?(0,K.jsx)(`a`,{href:S,target:`_blank`,rel:`noopener noreferrer`,className:`mt-4 inline-flex min-h-11 items-center text-sm text-accent`,children:t.openAuthorization}):null,D?(0,K.jsxs)(`div`,{className:`mt-8 space-y-3`,"aria-label":t.preparing,children:[(0,K.jsx)(m,{className:`h-2 w-full`}),(0,K.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.preparing})]}):null,(u||r?.consentRequired)&&v===`idle`?(0,K.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,K.jsxs)(`details`,{open:u,className:`text-sm text-fg-muted`,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer py-2`,children:t.details}),(0,K.jsx)(`p`,{className:`mt-2`,children:n.consentIntro}),(0,K.jsx)(`ul`,{className:`mt-3 list-disc space-y-2 pl-5`,children:[n.consentBullet1,n.consentBullet2,n.consentBullet3].map(e=>(0,K.jsx)(`li`,{children:e},e))})]}),(0,K.jsxs)(`label`,{className:`flex items-start gap-3 text-sm text-fg`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:o,onChange:e=>s(e.target.checked),className:`mt-1 size-4 accent-accent`}),n.consentCheckbox]})]}):null,b===`key-limit`?(0,K.jsxs)(`div`,{role:`alert`,className:`mt-4 rounded-lg border border-warning/30 bg-warning/5 p-4`,children:[(0,K.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.routeKeyLimitTitle}),(0,K.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:t.routeKeyLimitHint}),(0,K.jsxs)(p,{variant:`secondary`,className:`mt-3`,onClick:()=>void T(B),children:[t.manageTunnelKeys,(0,K.jsx)(c,{className:`size-3`})]})]}):b||i||r?.state===`error`?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:t.routeSetupFailed}):null,(0,K.jsx)(`div`,{className:`flex-1`}),(0,K.jsxs)(`label`,{className:`my-5 flex items-center gap-3 text-sm text-fg-muted`,children:[(0,K.jsx)(`input`,{type:`checkbox`,checked:g,disabled:v!==`idle`,onChange:e=>ee(e.target.checked),className:`size-4 accent-accent`}),t.autoStart]}),(0,K.jsx)(p,{className:`w-full`,variant:`primary`,disabled:!r||v!==`idle`||D||u&&!o,onClick:()=>void te(),children:v===`authorizing`?t.authorizing:D?t.preparing:b?t.retry:t.enable}),i&&!r?(0,K.jsx)(p,{variant:`ghost`,onClick:()=>void a(),children:t.retry}):null]})}var q=t({DevicePairingWizard:()=>J});function J(e){let t=(0,U.c)(16),{open:n,onOpenChange:r,onPaired:i,targetKind:o}=e,s=a(),[c,l]=(0,H.useState)(o),u,d;t[0]===o?(u=t[1],d=t[2]):(u=()=>{l(o)},d=[o],t[0]=o,t[1]=u,t[2]=d),(0,H.useEffect)(u,d);let f;t[3]!==r||t[4]!==o?(f=e=>{e||l(o),r(e)},t[3]=r,t[4]=o,t[5]=f):f=t[5];let p=f,m;t[6]!==p||t[7]!==s||t[8]!==i||t[9]!==n||t[10]!==c?(m=n?c?(0,K.jsx)(ge,{targetKind:c,onClose:()=>p(!1),onPaired:i}):(0,K.jsx)(X,{onChoose:l,onChooseLocalBrowser:()=>{p(!1),s(`/settings/agent-browser?driver=extension`)},onClose:()=>p(!1)}):null,t[6]=p,t[7]=s,t[8]=i,t[9]=n,t[10]=c,t[11]=m):m=t[11];let h;return t[12]!==p||t[13]!==n||t[14]!==m?(h=(0,K.jsx)(y,{open:n,onOpenChange:p,children:m}),t[12]=p,t[13]=n,t[14]=m,t[15]=h):h=t[15],h}function Y(e){let t=(0,U.c)(14),{icon:n,title:r,hint:i,onClick:a}=e,o;t[0]===n?o=t[1]:(o=(0,K.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent-soft text-accent-fg`,children:(0,K.jsx)(n,{className:`size-5`,"aria-hidden":`true`})}),t[0]=n,t[1]=o);let s;t[2]===r?s=t[3]:(s=(0,K.jsx)(`span`,{className:`block text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=s);let c;t[4]===i?c=t[5]:(c=(0,K.jsx)(`span`,{className:`mt-0.5 block text-xs leading-5 text-fg-muted`,children:i}),t[4]=i,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,K.jsx)(C,{className:`size-4 shrink-0 text-fg-disabled transition-transform group-hover:translate-x-0.5 group-hover:text-fg-muted`,"aria-hidden":`true`}),t[9]=u):u=t[9];let d;return t[10]!==a||t[11]!==o||t[12]!==l?(d=(0,K.jsxs)(`button`,{type:`button`,className:`group flex min-h-18 w-full cursor-pointer items-center gap-4 rounded-xl border border-edge bg-surface-panel px-4 py-3.5 text-left shadow-surface transition-[background-color,border-color,box-shadow,transform] hover:border-edge-strong hover:bg-surface-active hover:shadow-elevated active:translate-y-px active:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel motion-reduce:active:translate-y-0`,onClick:a,children:[o,l,u]}),t[10]=a,t[11]=o,t[12]=l,t[13]=d):d=t[13],d}function X(e){let t=(0,U.c)(40),{onChoose:n,onChooseLocalBrowser:r,onClose:i}=e,a=d(he),o;t[0]===a?o=t[1]:(o=l(a),t[0]=a,t[1]=o);let s=o.endpointToolsSettings.deviceAccess,c;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,K.jsx)(ee,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,g)}),t[2]=c):c=t[2];let f;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(f=u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(28rem,calc(100dvh-2rem))] w-[min(40rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,h),t[3]=f):f=t[3];let p;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,K.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),t[4]=p):p=t[4];let m;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,K.jsx)(x,{className:`size-4`}),t[5]=m):m=t[5];let _;t[6]!==s.cancel||t[7]!==i?(_=(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[p,(0,K.jsx)(`button`,{type:`button`,className:`flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover`,"aria-label":s.cancel,onClick:i,children:m})]}),t[6]=s.cancel,t[7]=i,t[8]=_):_=t[8];let y;t[9]===s.chooseTitle?y=t[10]:(y=(0,K.jsx)(v,{className:`text-lg font-semibold tracking-tight text-fg sm:text-xl`,children:s.chooseTitle}),t[9]=s.chooseTitle,t[10]=y);let b;t[11]===s.chooseHint?b=t[12]:(b=(0,K.jsx)(ie,{className:`mt-1.5 text-sm leading-6 text-fg-muted`,children:s.chooseHint}),t[11]=s.chooseHint,t[12]=b);let S;t[13]!==s.localBrowserHint||t[14]!==s.localBrowserTitle||t[15]!==r?(S=(0,K.jsx)(Y,{icon:E,title:s.localBrowserTitle,hint:s.localBrowserHint,onClick:r}),t[13]=s.localBrowserHint,t[14]=s.localBrowserTitle,t[15]=r,t[16]=S):S=t[16];let C;t[17]===n?C=t[18]:(C=()=>n(`mobile`),t[17]=n,t[18]=C);let w;t[19]!==s.mobileHint||t[20]!==s.mobileTitle||t[21]!==C?(w=(0,K.jsx)(Y,{icon:O,title:s.mobileTitle,hint:s.mobileHint,onClick:C}),t[19]=s.mobileHint,t[20]=s.mobileTitle,t[21]=C,t[22]=w):w=t[22];let T;t[23]===n?T=t[24]:(T=()=>n(`browser`),t[23]=n,t[24]=T);let A;t[25]!==s.remoteBrowserHint||t[26]!==s.remoteBrowserTitle||t[27]!==T?(A=(0,K.jsx)(Y,{icon:k,title:s.remoteBrowserTitle,hint:s.remoteBrowserHint,onClick:T}),t[25]=s.remoteBrowserHint,t[26]=s.remoteBrowserTitle,t[27]=T,t[28]=A):A=t[28];let j;t[29]!==w||t[30]!==A||t[31]!==S?(j=(0,K.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[S,w,A]}),t[29]=w,t[30]=A,t[31]=S,t[32]=j):j=t[32];let M;t[33]!==j||t[34]!==y||t[35]!==b?(M=(0,K.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-6 sm:px-8`,children:[y,b,j]}),t[33]=j,t[34]=y,t[35]=b,t[36]=M):M=t[36];let N;return t[37]!==M||t[38]!==_?(N=(0,K.jsxs)(D,{children:[c,(0,K.jsxs)(te,{className:f,children:[_,M]})]}),t[37]=M,t[38]=_,t[39]=N):N=t[39],N}function he(e){return e.language}function ge({targetKind:e,onClose:t,onPaired:n}){let r=d(e=>e.language),i=l(r),a=i.endpointToolsSettings.deviceAccess,_=a.flow,[y,S]=(0,H.useState)(!1),w=f(y?`device-pairing-readiness`:null,le,{refreshInterval:1500}),[E,O]=(0,H.useState)(),[k,A]=(0,H.useState)(null),[M,N]=(0,H.useState)(!1),[ne,oe]=(0,H.useState)(Date.now()),[F,I]=(0,H.useState)(null),L=(0,H.useRef)(!0),R=(0,H.useRef)(null),z=(0,H.useRef)(!1),B=(0,H.useRef)(!1),V=f(E?[`device-pairing-setup`,E.id]:null,()=>ce(E.id),{refreshInterval:1500}),U=V.data?.request,W=U?.status===`completed`,G=W&&U.connectedAt!==void 0,q=f(G&&window.electronAPI?.system?`system-behavior`:null,()=>window.electronAPI.system.getBehavior()),J=E?.targetKind===`mobile`?E.universalLink:``,Y=j(()=>pe(J),[J],{enabled:!!J,initial:null,errorData:null}),X=r===`zh`?`https://xopc.ai/zh#download`:`https://xopc.ai/en#download`,he=r===`zh`?`https://xopcai.github.io/xopc/zh/browser-extension`:`https://xopcai.github.io/xopc/browser-extension`,ge=j(()=>pe(X),[X],{enabled:!y&&e===`mobile`,initial:null,errorData:null});(0,H.useEffect)(()=>{L.current=!0;let e=setInterval(()=>oe(Date.now()),1e3);return()=>{L.current=!1,clearInterval(e),R.current&&P(R.current).catch(()=>{})}},[]);let Z=(0,H.useCallback)(async()=>{if(!z.current){z.current=!0,N(!0),A(null);try{R.current&&await P(R.current),R.current=null,O(void 0);let t=await se(e);if(t.kind===`ready`){if(!L.current){await P(t.setup.id);return}R.current=t.setup.id,O(t.setup)}else await w.mutate()}catch{L.current&&A(`create`)}finally{z.current=!1,L.current&&N(!1)}}},[w,e]);(0,H.useEffect)(()=>{w.data?.ready&&!E&&k!==`create`&&!z.current&&Z()},[w.data,E,k,Z]),(0,H.useEffect)(()=>{G&&!B.current&&(B.current=!0,n?.())},[G,n]);let _e=async e=>{if(U){N(!0),A(null);try{await de(U,e),await V.mutate()}catch{A(`decision`),await V.mutate()}finally{L.current&&N(!1)}}},ve=(0,H.useRef)(0);(0,H.useEffect)(()=>{V.data&&(ve.current=V.data.serverTime-Date.now())},[V.data]);let Q=ne+ve.current,ye=E&&Q>=E.expiresAt&&!U,be=U&&[`expired`,`rejected`,`cancelled`].includes(U.status),xe=E?E.expiresAt-Q<6e4:!1,Se=E?xe?`${Math.max(0,Math.ceil((E.expiresAt-Q)/1e3))}s`:_.valid:``,$=e===`mobile`?{connect:a.mobileScan,connectHint:a.mobileScanHint,allowTitle:a.mobileAllowTitle,success:a.mobileSuccess,successHint:a.mobileSuccessHint}:{connect:a.browserConnect,connectHint:a.browserConnectHint,allowTitle:a.browserAllowTitle,success:a.browserSuccess,successHint:a.browserSuccessHint},Ce=e===`mobile`?a.mobilePrepareTitle:a.browserPrepareTitle,we=e===`mobile`?a.mobilePrepareHint:a.browserPrepareHint,Te=y?G?$.success:U?.status===`pending`?$.allowTitle:W||U?.status===`approved`?_.waiting:E?$.connect:_.title:Ce,Ee=k===`create`?_.createFailed:k===`decision`?_.decisionFailed:k===`background`?_.backgroundFailed:k===`download`?a.browserDownloadFailed:null,De=async()=>{N(!0),A(null);try{await ue()}catch{A(`download`)}finally{L.current&&N(!1)}};return(0,K.jsxs)(D,{children:[(0,K.jsx)(ee,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,g)}),(0,K.jsxs)(te,{className:u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(600px,calc(100dvh-48px))] w-[min(560px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,h),children:[(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[(0,K.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),(0,K.jsx)(`button`,{type:`button`,className:`flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover`,"aria-label":_.cancel,onClick:t,children:(0,K.jsx)(x,{className:`size-4`})})]}),(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-8 py-7`,children:[G?(0,K.jsx)(o,{className:`mb-5 size-7 text-success`}):null,(0,K.jsx)(v,{className:`text-xl font-semibold tracking-tight text-fg`,children:Te}),(0,K.jsx)(ie,{className:`mt-2 text-sm leading-relaxed text-fg-muted`,children:y?G?$.successHint:W?_.waitingForDevice:U?U.displayName:E?$.connectHint:_.intro:we}),Ee?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:Ee}):null,y&&w.error?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:_.readinessFailed}):null,y&&V.error?(0,K.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-warning`,children:_.statusUnavailable}):null,y?w.data?G?(0,K.jsxs)(K.Fragment,{children:[q.data?(0,K.jsxs)(`label`,{className:`mt-8 flex items-center justify-between gap-4 border-y border-edge-subtle py-5 text-sm text-fg`,children:[a.background,(0,K.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":q.data.runInBackground??!1,disabled:!q.data.backgroundSupported,checked:q.data.runInBackground??!1,className:`size-5 accent-accent`,onChange:e=>{window.electronAPI.system.setBehavior({runInBackground:e.target.checked}).then(e=>q.mutate(e.behavior)).catch(()=>A(`background`))}})]}):null,(0,K.jsx)(`p`,{className:`mt-4 text-xs text-fg-muted`,children:a.sleep})]}):be||ye?(0,K.jsxs)(`div`,{className:`mt-10 space-y-5`,children:[(0,K.jsx)(`p`,{className:`text-sm text-fg-muted`,children:ye||U?.status===`expired`?_.expired:_.declined}),(0,K.jsx)(p,{variant:`primary`,onClick:()=>void Z(),disabled:M,children:_.refresh})]}):U?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:_.scope}),(0,K.jsxs)(`p`,{className:`mt-10 font-mono text-4xl tracking-[0.16em] text-fg`,"aria-live":`polite`,children:[U.confirmationCode.slice(0,3),` `,U.confirmationCode.slice(3)]}),(0,K.jsx)(`p`,{className:`mt-3 text-xs text-fg-muted`,children:_.compare}),(0,K.jsxs)(`details`,{className:`mt-6 text-xs text-fg-muted`,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer py-2`,children:_.access}),(0,K.jsx)(`p`,{children:_.accessHint})]})]}):E?.targetKind===`mobile`?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`div`,{className:`my-6 flex flex-col items-center`,children:[(0,K.jsx)(`div`,{className:`rounded-[1.75rem] border border-edge bg-surface-hover/55 p-2.5 shadow-surface`,children:(0,K.jsx)(`div`,{className:`rounded-[1.25rem] bg-white p-2 shadow-sm ring-1 ring-black/5`,children:Y.data?(0,K.jsx)(`img`,{src:Y.data,alt:a.qrAlt,width:240,height:240,className:`size-[240px] max-w-full rounded-xl bg-white`}):Y.error?null:(0,K.jsx)(m,{className:`size-[240px] rounded-xl`})})}),Y.error?null:(0,K.jsxs)(`p`,{className:u(`mt-4 inline-flex min-h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium`,xe?`bg-warning-soft text-warning`:`bg-surface-hover text-fg-muted`),"aria-live":`polite`,children:[(0,K.jsx)(re,{className:`size-3.5`,"aria-hidden":`true`}),Se]})]}),Y.error?(0,K.jsx)(`p`,{role:`status`,className:`text-center text-sm text-warning`,children:_.qrFailed}):null,Y.error?(0,K.jsx)(`div`,{className:`mt-5`,children:(0,K.jsx)(b,{text:E.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}):(0,K.jsxs)(`details`,{className:`group mx-auto mt-1 w-full max-w-sm rounded-xl border border-edge bg-surface-panel text-xs text-fg-muted`,children:[(0,K.jsxs)(`summary`,{className:`flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 rounded-xl px-3.5 transition-colors hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent [&::-webkit-details-marker]:hidden`,children:[(0,K.jsx)(`span`,{children:_.fallback}),(0,K.jsx)(C,{className:`size-3.5 shrink-0 transition-transform group-open:rotate-90`,"aria-hidden":`true`})]}),(0,K.jsx)(`div`,{className:`border-t border-edge-subtle p-3`,children:(0,K.jsx)(b,{text:E.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})})]})]}):E?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`ol`,{className:`mt-7 space-y-2 text-sm leading-6 text-fg-muted`,children:[(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserConnectStep1]}),(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserConnectStep2]}),(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserConnectStep3]})]}),(0,K.jsx)(`div`,{className:`mt-6`,children:(0,K.jsx)(b,{text:E.browserInvitation,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}),(0,K.jsx)(`p`,{className:`mt-3 text-center text-xs text-fg-muted`,children:E.expiresAt-Q<6e4?`${Math.max(0,Math.ceil((E.expiresAt-Q)/1e3))}s`:_.valid})]}):w.data.ready?(0,K.jsx)(`div`,{className:`mt-8`,children:(0,K.jsx)(m,{className:`mx-auto size-[216px]`})}):(0,K.jsxs)(`div`,{className:`mt-6 flex flex-1 flex-col`,children:[F===`tailscale`?(0,K.jsx)(fe,{embedded:!0}):F===`https`?(0,K.jsx)(ae,{}):F===`choices`?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(p,{variant:`secondary`,className:`w-full`,onClick:()=>I(`tailscale`),children:a.useTailscale}),(0,K.jsx)(p,{variant:`secondary`,className:`w-full`,onClick:()=>I(`https`),children:a.useOwnHttps})]}):(0,K.jsx)(me,{}),(0,K.jsx)(p,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>I(F?null:`choices`),children:F?_.back:_.existing})]}):(0,K.jsxs)(`div`,{className:`mt-8 space-y-4`,children:[(0,K.jsx)(m,{className:`h-5 w-3/4`}),(0,K.jsx)(m,{className:`h-40 w-full`})]}):e===`mobile`?(0,K.jsxs)(`div`,{className:`mt-7 flex flex-col items-center`,children:[ge.data?(0,K.jsx)(`img`,{src:ge.data,alt:a.mobileDownloadQrAlt,width:144,height:144,className:`size-36 rounded-lg bg-white`}):(0,K.jsx)(m,{className:`size-36`}),(0,K.jsxs)(p,{variant:`secondary`,className:`mt-5 w-full`,onClick:()=>void T(X),children:[(0,K.jsx)(c,{className:`size-4`}),a.mobileDownload]}),(0,K.jsx)(`p`,{className:`mt-3 text-center text-xs leading-5 text-fg-muted`,children:a.mobileDownloadHint})]}):(0,K.jsxs)(`div`,{className:`mt-7`,children:[(0,K.jsxs)(p,{variant:`secondary`,className:`w-full`,disabled:M,onClick:()=>void De(),children:[(0,K.jsx)(s,{className:`size-4`}),a.browserDownload]}),(0,K.jsxs)(`ol`,{className:`mt-5 space-y-3 text-sm leading-6 text-fg-muted`,children:[(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserInstallStep1]}),(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserInstallStep2]}),(0,K.jsxs)(`li`,{children:[(0,K.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserInstallStep3]})]}),(0,K.jsxs)(`button`,{type:`button`,className:`mt-5 inline-flex items-center gap-1 text-xs text-accent hover:underline`,onClick:()=>void T(he),children:[a.browserInstallHelp,(0,K.jsx)(c,{className:`size-3`})]})]})]}),!y||w.error||G||U?.status===`pending`||k===`create`||k===`decision`?(0,K.jsx)(`footer`,{className:`shrink-0 px-8 pb-6`,children:y?G?(0,K.jsx)(p,{className:`w-full`,variant:`primary`,onClick:t,children:_.done}):U?.status===`pending`?(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(p,{className:`w-full`,variant:`primary`,disabled:M,onClick:()=>void _e(`approve`),children:_.allow}),(0,K.jsx)(p,{className:`w-full`,variant:`ghost`,disabled:M,onClick:()=>void _e(`reject`),children:_.cancel})]}):w.error?(0,K.jsx)(p,{className:`w-full`,variant:`primary`,onClick:()=>void w.mutate(),children:_.retry}):(0,K.jsx)(p,{className:`w-full`,variant:`primary`,disabled:M,onClick:()=>void Z(),children:_.retry}):(0,K.jsx)(p,{className:`w-full`,variant:`primary`,onClick:()=>{A(null),S(!0)},children:e===`mobile`?a.mobileReady:a.browserReady})}):null]})]})}export{q as n,J as t};
@@ -1 +0,0 @@
1
- import{i as e}from"./locale-store-B7s2Hb35.js";import{a as t,d as n,f as r,g as i,i as a,l as o,p as s,r as c,s as l,t as u,u as d,v as f}from"./schemas-CObaziC7.js";import{t as p}from"./gateway-realtime-store-Bx9KCID-.js";var ee={type:`array`,minItems:1,maxItems:20,items:{type:`object`,additionalProperties:!1,required:[`type`,`fileId`,`name`,`mimeType`,`size`,`sha256`],properties:{type:{const:`file`},fileId:{type:`string`,minLength:1,maxLength:160},name:{type:`string`,minLength:1,maxLength:255},mimeType:{type:`string`,minLength:1,maxLength:255},size:{type:`integer`,minimum:0},sha256:{type:`string`,pattern:`^[a-f0-9]{64}$`}}}},te={type:`object`,properties:{},additionalProperties:!1},m=d({purpose:u([`weather`,`nearby`]),precision:u([`approximate`,`precise`]),category:u([`restaurant`,`cafe`,`pharmacy`,`park`]).optional()}).strict().superRefine((e,t)=>{e.purpose===`nearby`!=(e.category!==void 0)&&t.addIssue({code:`custom`,message:`Category is required only for nearby queries`})}),h={type:`object`,additionalProperties:!1,required:[`purpose`,`precision`],properties:{purpose:{enum:[`weather`,`nearby`]},precision:{enum:[`approximate`,`precise`]},category:{enum:[`restaurant`,`cafe`,`pharmacy`,`park`]}},allOf:[{if:{properties:{purpose:{const:`nearby`}},required:[`purpose`]},then:{properties:{category:{}},required:[`category`]},else:{not:{properties:{category:{}},required:[`category`]}}}]};d({latitude:o().min(-90).max(90),longitude:o().min(-180).max(180),accuracyMeters:o().min(0).max(1e5),capturedAt:o().int().nonnegative(),precision:u([`approximate`,`precise`]),coordinateSystem:l(`WGS84`)}).strict();var g={type:`array`,minItems:1,maxItems:1,items:{type:`object`,additionalProperties:!1,required:[`type`,`value`],properties:{type:{const:`json`},value:{type:`object`,additionalProperties:!1,required:[`latitude`,`longitude`,`accuracyMeters`,`capturedAt`,`precision`,`coordinateSystem`],properties:{latitude:{type:`number`,minimum:-90,maximum:90},longitude:{type:`number`,minimum:-180,maximum:180},accuracyMeters:{type:`number`,minimum:0,maximum:1e5},capturedAt:{type:`integer`,minimum:0},precision:{enum:[`approximate`,`precise`]},coordinateSystem:{const:`WGS84`}}}}}};function ne(e){return{name:`${e}.device.get_location`,title:`Use location once`,description:`With on-device consent, use one fresh WGS84 location for current weather (Open-Meteo) or nearby places (OpenStreetMap). Raw coordinates are consumed transiently by Gateway, never returned to the Agent or saved in history. Select approximate or precise; nearby requires a category. Each call requires new consent.`,inputSchema:h,outputSchema:g,policyId:`personal.foreground-read`,sensitivity:`personal`,effect:`read`,confirmation:`always`,requiresForeground:!0,requiredPermissions:[`location-read-once`],timeoutMs:9e4,maxConcurrency:1,supportsCancellation:!0,idempotent:!0,resultKinds:[`json`]}}var re=25*1024*1024,_=u([`web`,`desktop`,`mobile`,`browser`]),v=u([`foreground`,`background`]),ie=u([`read`,`write`,`destructive`]),y=u([`never`,`always`]),ae=u([`text`,`json`,`file`]),oe=u([`public`,`personal`]),b=s().min(1).max(160),se=s().min(32).max(160).regex(/^[A-Za-z0-9_-]+$/);t(`type`,[r({type:l(`endpoint`),endpointId:b}),r({type:l(`channel`),channel:s().min(1).max(64)}),r({type:l(`system`),source:u([`cli`,`automation`,`heartbeat`,`task`,`internal`,`task_update`])})]).options[0].extend({token:se});var ce=f(),x=o().int().nonnegative(),S=n(s(),i()),C=r({name:s().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120),title:s().min(1).max(120),description:s().min(1).max(2e3),inputSchema:S,outputSchema:S,policyId:s().regex(/^[a-z][a-z0-9_.-]+$/).max(120),sensitivity:oe,effect:ie,confirmation:y,requiresForeground:a(),requiredPermissions:c(s().min(1).max(120)).max(20),timeoutMs:o().int().min(1e3).max(3e5),maxConcurrency:o().int().min(1).max(4),supportsCancellation:a(),idempotent:a(),resultKinds:c(ae).min(1).max(3)});r({principalId:b,displayName:s().min(1).max(120),kind:_,platform:s().min(1).max(80),publicKey:s().min(32).max(2048)}),r({endpointId:b});var w=s().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120);r({jobId:f(),endpointId:b,capability:w,input:S,idempotencyKey:b,consentGrantId:b,createdAt:x,expiresAt:x}),r({jobId:f(),status:u([`queued`,`running`,`succeeded`,`failed`,`cancelled`]),updatedAt:x,output:S.optional(),error:r({code:b,message:s().min(1).max(2e3)}).optional()}),r({eventId:f(),endpointId:b,subscriptionId:b,eventType:w,data:S,occurredAt:x});var le=r({principalId:b,endpointId:b,connectionInstanceId:f(),displayName:s().min(1).max(120),kind:_,platform:s().min(1).max(80),appVersion:s().min(1).max(80),availability:v,nonce:b,signedAt:x,signature:s().min(16).max(1024),tools:c(C).max(100)}),ue=r({invocationId:f(),toolCallId:b,toolName:C.shape.name,arguments:S,descriptorRevision:s().min(1).max(128),confirmationRequired:a(),deadlineAt:x,uploadGrant:r({path:s().startsWith(`/`).max(500),token:b,maxBytes:o().int().positive(),maxFiles:o().int().min(1).max(20),expiresAt:x}).optional()}),de=r({invocationId:f(),reason:s().min(1).max(500)}),T=r({invocationId:f()}),E=t(`type`,[r({type:l(`text`),text:s().max(256*1024)}),r({type:l(`json`),value:i()}),r({type:l(`file`),fileId:b,name:s().min(1).max(255),mimeType:s().min(1).max(255),size:o().int().nonnegative(),sha256:s().regex(/^[a-f0-9]{64}$/)})]),fe=u([`ENDPOINT_OFFLINE`,`ENDPOINT_NOT_FOREGROUND`,`ENDPOINT_DISCONNECTED`,`TOOL_NOT_FOUND`,`TOOL_REVISION_MISMATCH`,`INVALID_ARGUMENTS`,`PERMISSION_DENIED`,`USER_DENIED`,`TOOL_BUSY`,`TOOL_TIMEOUT`,`TOOL_CANCELLED`,`RESULT_TOO_LARGE`,`PROTOCOL_ERROR`]),D=(e,t)=>r({protocolVersion:l(2),messageId:ce,type:l(e),sentAt:x,payload:t}),O=t(`type`,[D(`endpoint.availability_changed`,r({availability:v})),D(`tool.received`,T),D(`tool.progress`,r({invocationId:f(),message:s().max(500).optional(),percent:o().min(0).max(100).optional()})),D(`tool.result`,r({invocationId:f(),content:c(E).min(1).max(20),details:S.optional()})),D(`tool.error`,r({invocationId:f(),code:fe,message:s().min(1).max(2e3)})),D(`tool.cancelled`,T)]),k=t(`type`,[D(`tool.invoke`,ue),D(`tool.cancel`,de)]),A={type:`array`,minItems:1,maxItems:20,items:{type:`object`,additionalProperties:!1,required:[`type`,`text`],properties:{type:{const:`text`},text:{type:`string`,maxLength:256*1024}}}};function j(e){if(e===null)return`null`;if(typeof e==`string`||typeof e==`boolean`)return JSON.stringify(e);if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Canonical JSON only supports finite numbers`);return JSON.stringify(e)}if(typeof e!=`object`)throw Error(`Canonical JSON does not support ${typeof e}`);if(Array.isArray(e))return`[${e.map(j).join(`,`)}]`;let t=Object.getPrototypeOf(e);if(t!==Object.prototype&&t!==null)throw Error(`Canonical JSON only supports plain objects`);let n=e;return`{${Object.keys(n).sort().map(e=>`${JSON.stringify(e)}:${j(n[e])}`).join(`,`)}}`}function M(e){let{signature:t,...n}=e;return j(n)}var N={type:`array`,minItems:1,maxItems:1,items:{type:`object`,additionalProperties:!1,required:[`type`,`value`],properties:{type:{const:`json`},value:{type:`object`,additionalProperties:!1,required:[`capturedAt`,`platform`,`systemVersion`,`locale`,`timezone`],properties:{capturedAt:{type:`integer`,minimum:0},platform:{type:`string`,minLength:1,maxLength:40},systemVersion:{type:`string`,maxLength:80},locale:{type:`string`,maxLength:80},timezone:{type:`string`,maxLength:80},online:{type:`boolean`}}}}}},P={type:`array`,minItems:1,maxItems:1,items:{type:`object`,additionalProperties:!1,required:[`type`,`value`],properties:{type:{const:`json`},value:{type:`object`,additionalProperties:!1,required:[`capturedAt`,`levelPercent`,`charging`],properties:{capturedAt:{type:`integer`,minimum:0},levelPercent:{type:[`number`,`null`],minimum:0,maximum:100},charging:{type:[`boolean`,`null`]}}}}}};function F(e,t){return{name:`${e}.device.get_${t}`,title:t===`power`?`Read this device’s battery`:`Read this device’s environment`,description:t===`power`?`Read a fresh battery sample from the device that sent this user message. Unknown readings are null.`:`Read bounded platform, system version, language and timezone from the device that sent this user message. No files, page content, network addresses or identifiers are collected.`,inputSchema:te,outputSchema:t===`power`?P:N,policyId:`public.background-read`,sensitivity:`public`,effect:`read`,confirmation:`never`,requiresForeground:!1,requiredPermissions:[],timeoutMs:1e4,maxConcurrency:1,supportsCancellation:!0,idempotent:!0,resultKinds:[`json`]}}var I=256*1024,L=15e3,R=45e3,z=[`realtime.capability-negotiation.v1`],B=u([`web`,`desktop`,`mobile`,`browser_extension`,`tui`,`mcp`]),V=s().min(1).max(512),pe=s().regex(/^[a-z][a-z0-9_.-]*$/).max(160),me=f(),he=o().int().nonnegative(),H=o().int().positive(),U=s().min(1).max(160),W=(e,t)=>d({protocolVersion:l(2),messageId:me,kind:l(e),sentAt:he,payload:t}),G=d({topic:V,afterSeq:o().int().nonnegative().optional(),view:l(`compact`).optional()});t(`kind`,[W(`realtime.hello`,d({ticket:s().min(32).max(512),clientId:s().min(1).max(160),clientKind:B,subscriptions:c(G).max(100).default([]),capabilities:c(U).max(64).optional(),endpoint:le.optional()})),W(`realtime.subscribe`,d({subscriptions:c(G).min(1).max(100)})),W(`realtime.unsubscribe`,d({topics:c(V).min(1).max(100)})),W(`realtime.ping`,d({})),W(`endpoint.message`,O)]);var ge=d({topic:V,seq:H,event:pe,data:i()}),_e=t(`kind`,[W(`realtime.ready`,d({connectionId:f(),heartbeatIntervalMs:l(L),heartbeatTimeoutMs:l(R),negotiatedCapabilities:c(U).max(64).optional(),endpoint:d({endpointId:s().min(1).max(160),turnToken:s().min(32).max(160)}).optional()})),W(`realtime.event`,ge),W(`realtime.subscribed`,d({topic:V,cursor:o().int().nonnegative()})),W(`realtime.gap`,d({topic:V,requestedSeq:o().int().nonnegative(),earliestSeq:H,recoverable:a()})),W(`realtime.pong`,d({})),W(`realtime.error`,d({code:s().min(1).max(80),message:s().min(1).max(500)})),W(`endpoint.message`,k)]);function ve(e){return _e.parse(e)}var K=class extends Error{retryable;constructor(e,t){super(e),this.retryable=t,this.name=`RealtimeConnectionError`}},ye=class extends Error{bytes;maxBytes;constructor(e,t){super(`Realtime client frame is ${e} bytes; maximum is ${t} bytes`),this.bytes=e,this.maxBytes=t,this.name=`RealtimeFrameTooLargeError`}};function be(e){if(typeof e==`string`)return e;if(e instanceof ArrayBuffer)return new TextDecoder().decode(e);if(ArrayBuffer.isView(e)){let t=Uint8Array.from(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));return new TextDecoder().decode(t)}throw Error(`Realtime server sent a non-text frame`)}function xe(e){return e===1009||e===4400||e===4401||e===4409||e===4413}var Se=class{options;desiredSubscriptions=new Map;cursors=new Map;socket;reconnectTimer;heartbeatTimer;connectionTimer;ticketAbort;generation=0;reconnectAttempts=0;shouldReconnect=!1;ready=!1;lastServerMessageAt=0;endpointBinding;reconnectWhenSocketOpens=!1;offeredCapabilities=new Set;constructor(e){this.options=e}connect(){this.shouldReconnect||(this.shouldReconnect=!0,this.open(!1))}disconnect(){this.shouldReconnect=!1,this.reconnectWhenSocketOpens=!1,this.generation+=1,this.clearTimers(),this.ready=!1,this.offeredCapabilities.clear(),this.endpointBinding?.onDisconnected?.(),this.socket?.close(1e3,`Client disconnected`),this.socket=void 0,this.options.onStateChange?.(`disconnected`)}reconnect(){this.reconnectWhenSocketOpens=!1,this.generation+=1,this.clearTimers(),this.ready=!1,this.endpointBinding?.onDisconnected?.(),this.socket?.close(1e3,`Client reconnecting`),this.socket=void 0,this.reconnectAttempts=0,this.shouldReconnect=!0,this.open(!0)}subscribe(e,t){this.desiredSubscriptions.set(e,t),t!==void 0&&this.cursors.set(e,t),this.ready&&this.sendSubscriptions([{topic:e,afterSeq:this.cursors.get(e)??t}])}unsubscribe(e){this.desiredSubscriptions.delete(e),this.ready&&this.send(this.clientMessage(`realtime.unsubscribe`,{topics:[e]}))}sendEndpointMessage(e){if(!this.ready)throw Error(`Realtime connection is not ready`);this.send(this.clientMessage(`endpoint.message`,e))}setEndpoint(e){this.endpointBinding=e,this.refreshEndpointConnection()}clearEndpoint(e){if(e&&this.endpointBinding!==e)return;let t=this.endpointBinding;this.endpointBinding=void 0,t?.onDisconnected?.(),this.refreshEndpointConnection()}refreshEndpointConnection(){if(this.shouldReconnect){if(this.socket?.readyState===0){this.reconnectWhenSocketOpens=!0;return}this.reconnect()}}async open(e){let t=++this.generation,n=this.options.connectionTimeoutMs??15e3,r=new AbortController;this.ticketAbort?.abort(),this.ticketAbort=r;let i,a=!1,o,s=(e,n=!0)=>{a||t!==this.generation||(a=!0,this.clearConnectionTimer(),r.abort(),this.ticketAbort===r&&(this.ticketAbort=void 0),this.ready=!1,this.offeredCapabilities.clear(),this.endpointBinding?.onDisconnected?.(),this.clearHeartbeat(),this.socket===i&&(this.socket=void 0),i&&(i.onopen=null,i.onmessage=null,i.onerror=null,i.onclose=null,i.close(4e3,e.slice(0,120))),this.shouldReconnect&&n?this.scheduleReconnect(e):this.shouldReconnect?(this.shouldReconnect=!1,this.options.onStateChange?.(`error`,e)):this.options.onStateChange?.(`disconnected`))};this.connectionTimer=setTimeout(()=>s(`Realtime connection timed out`),n),this.options.onStateChange?.(e?`reconnecting`:`connecting`);try{let[e,n]=await Promise.all([this.options.issueTicket(r.signal),this.endpointBinding?.createHello()]),c=e.ticket;if(2<e.realtime.minVersion)throw new K(`CLIENT_UPDATE_REQUIRED`,!1);if(2>e.realtime.maxVersion)throw new K(`GATEWAY_UPDATE_REQUIRED`,!1);let l=z.filter(t=>e.realtime.capabilities.includes(t));if(a||!this.shouldReconnect||t!==this.generation)return;this.offeredCapabilities=new Set(l??[]),i=this.options.createWebSocket(this.options.getWebSocketUrl()),this.socket=i,i.onopen=()=>{if(t!==this.generation)return;if(this.reconnectWhenSocketOpens){this.reconnect();return}let e=[...this.desiredSubscriptions].map(([e,t])=>({topic:e,afterSeq:this.cursors.get(e)??t}));this.send(this.clientMessage(`realtime.hello`,{ticket:c,clientId:this.options.clientId,clientKind:this.options.clientKind,subscriptions:e,...l?.length?{capabilities:l}:{},...n?{endpoint:n}:{}}))},i.onmessage=e=>{if(t!==this.generation)return;let n=()=>{if(!(a||t!==this.generation))return this.handleServerMessage(be(e.data))};if(!o){try{let e=n();if(!e)return;let t=e.catch(e=>s(e instanceof Error?e.message:`Invalid realtime server message`)).then(()=>void 0);o=t,t.finally(()=>{o===t&&(o=void 0)})}catch(e){s(e instanceof Error?e.message:`Invalid realtime server message`)}return}let r=o.then(n).catch(e=>s(e instanceof Error?e.message:`Invalid realtime server message`)).then(()=>void 0);o=r,r.finally(()=>{o===r&&(o=void 0)})},i.onerror=()=>{},i.onclose=e=>{s(e.reason||`WebSocket closed (${e.code??0})`,!xe(e.code))}}catch(e){s(e instanceof Error?e.message:`Realtime connection failed`,!(e instanceof K)||e.retryable)}}handleServerMessage(e){let t=ve(JSON.parse(e));if(this.lastServerMessageAt=Date.now(),t.kind===`realtime.ready`){let e=t.payload.negotiatedCapabilities??[];if(e.some(e=>!this.offeredCapabilities.has(e)))throw Error(`Realtime server negotiated a capability the client did not offer`);this.ready=!0,this.reconnectAttempts=0,this.clearConnectionTimer(),this.ticketAbort=void 0,this.options.onStateChange?.(`connected`),this.options.onCapabilities?.(e),t.payload.endpoint&&this.endpointBinding?.onReady(t.payload.endpoint),this.clearHeartbeat(),this.heartbeatTimer=setInterval(()=>{if(this.ready){if(Date.now()-this.lastServerMessageAt>=t.payload.heartbeatTimeoutMs){this.reconnect();return}this.send(this.clientMessage(`realtime.ping`,{}))}},t.payload.heartbeatIntervalMs)}else if(t.kind===`realtime.event`){let e=this.cursors.get(t.payload.topic);if(e!==void 0&&t.payload.seq<=e)return;this.options.onEvent?.(t.payload),this.cursors.set(t.payload.topic,t.payload.seq)}else if(t.kind===`realtime.subscribed`)this.cursors.set(t.payload.topic,t.payload.cursor),this.options.onSubscribed?.(t.payload);else if(t.kind===`realtime.gap`)return this.cursors.set(t.payload.topic,t.payload.earliestSeq-1),this.options.onGap?.(t.payload);else t.kind===`realtime.error`?this.options.onStateChange?.(`error`,t.payload.message):t.kind===`endpoint.message`&&(this.endpointBinding?.onMessage(t.payload),this.options.onEndpointMessage?.(t.payload))}sendSubscriptions(e){this.send(this.clientMessage(`realtime.subscribe`,{subscriptions:e}))}clientMessage(e,t){let n=this.options.createMessageId?.()??globalThis.crypto?.randomUUID?.();if(!n)throw Error(`RealtimeClient requires createMessageId when crypto.randomUUID is unavailable`);return{protocolVersion:2,messageId:n,kind:e,sentAt:Date.now(),payload:t}}send(e){if(!this.socket||this.socket.readyState!==1)return;let t=JSON.stringify(e),n=new TextEncoder().encode(t).byteLength;if(n>262144)throw new ye(n,I);this.socket.send(t)}scheduleReconnect(e){if(!this.shouldReconnect)return;this.reconnectAttempts+=1;let t=this.options.maxReconnectAttempts;if(t!==void 0&&this.reconnectAttempts>t){this.shouldReconnect=!1,this.options.onStateChange?.(`error`,e);return}this.options.onStateChange?.(`reconnecting`,e);let n=Math.min(3e4,1e3*2**Math.min(this.reconnectAttempts-1,5)),r=Math.round(n*(.5+Math.random()*.5));this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=void 0,this.open(!0)},r)}clearHeartbeat(){this.heartbeatTimer&&clearInterval(this.heartbeatTimer),this.heartbeatTimer=void 0}clearTimers(){this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=void 0,this.clearConnectionTimer(),this.ticketAbort?.abort(),this.ticketAbort=void 0,this.clearHeartbeat()}clearConnectionTimer(){this.connectionTimer&&clearTimeout(this.connectionTimer),this.connectionTimer=void 0}},Ce=500,q=null,J;function Y(e){J=e,q!==null&&clearTimeout(q),q=setTimeout(()=>{q=null;let e=J;J=void 0,window.dispatchEvent(new CustomEvent(`config-reload`,{detail:e}))},Ce)}function we(e,t){if(e===`config.reload`){Y(t);return}window.dispatchEvent(new CustomEvent(e.replace(/[._]/g,`-`),{detail:t}))}var X=new Map,Z=new Map,Q,$;function Te(){let e=`xopc:realtime-client-id`,t=sessionStorage.getItem(e);if(t)return t;let n=crypto.randomUUID();return sessionStorage.setItem(e,n),n}function Ee(){let t=new URL(e(`/api/realtime/v1/ws`));return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()}function De(){let t=Te(),n=window.electronAPI?`desktop`:`web`,r=new Se({clientId:t,clientKind:n,getWebSocketUrl:Ee,issueTicket:async r=>{let i=await fetch(e(`/api/realtime/tickets`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({clientId:t,clientKind:n,protocolVersion:2}),signal:r}),a=await i.json().catch(()=>null);if(!i.ok||!a?.payload?.ticket||!a.payload.realtime)throw Error(a?.error?.message??`Realtime ticket failed (${i.status})`);return{ticket:a.payload.ticket,realtime:a.payload.realtime}},createWebSocket:e=>new WebSocket(e),onStateChange:(e,t)=>{p({connectionState:e,error:t??null}),e===`connected`&&window.dispatchEvent(new CustomEvent(`gateway-realtime-connected`))},onEvent:e=>{(e.topic===`gateway`||e.topic===`sessions`)&&we(e.event,e.data);let t=Z.get(e.topic);(t===void 0||e.seq>t)&&Z.set(e.topic,e.seq);for(let t of X.get(e.topic)??[])if(!(t.cursor!==void 0&&e.seq<=t.cursor))try{t.listener.onEvent(e)}catch(e){console.error(`[realtime] topic listener failed:`,e)}finally{t.cursor=Math.max(t.cursor??0,e.seq)}},onGap:async e=>{window.dispatchEvent(new CustomEvent(`realtime-gap`,{detail:e}));let t=[...X.get(e.topic)??[]].filter(t=>!e.recoverable||t.cursor===void 0||t.cursor<e.earliestSeq-1),n=await Promise.allSettled(t.map(t=>t.listener.onGap?.(e)));for(let e of n)e.status===`rejected`&&console.error(`[realtime] topic gap handler failed:`,e.reason)}});Q?.disconnect(),Q=r,$&&r.setEndpoint($),r.subscribe(`gateway`,Z.get(`gateway`)),r.subscribe(`sessions`,Z.get(`sessions`));for(let e of X.keys())r.subscribe(e,Z.get(e));return p({connectionState:`connecting`,error:null}),r.connect(),()=>{Q===r&&(r.disconnect(),Q=void 0)}}function Oe(e){return $=e,Q?.setEndpoint(e),()=>{$===e&&($=void 0,Q?.clearEndpoint(e))}}function ke(e){Q?.sendEndpointMessage(e)}function Ae(){Q?.reconnect()}function je(e,t,n){let r=X.get(e)??new Set,i=r.size===0,a=Z.get(e),o={listener:t,cursor:n??a};if(r.add(o),X.set(e,r),i){let t=n??a;Z.set(e,t),Q?.subscribe(e,t)}else n!==void 0&&(a===void 0||n<a)&&Q?.subscribe(e,n);return()=>{let t=X.get(e);t?.delete(o),(!t||t.size===0)&&(X.delete(e),Z.delete(e),Q?.unsubscribe(e))}}export{je as a,A as c,M as d,E as f,ee as h,De as i,j as l,m,Ae as n,Y as o,ne as p,ke as r,re as s,Oe as t,F as u};