@xopcai/xopc 0.0.363 → 0.0.366

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 (217) hide show
  1. package/dist/browser-ext/dist/sidepanel.js +16 -4
  2. package/dist/browser-ext/manifest.json +1 -1
  3. package/dist/extensions/telegram/xopc.extension.json +1 -1
  4. package/dist/gateway/static/root/assets/{activity-store-GvR2gZ0T.js → activity-store-SVmnh__i.js} +1 -1
  5. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DkcXyPH0.js → agent-avatar-dicebear-CS9lg5h2.js} +1 -1
  6. package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-B-l5AaYN.js → agent-defaults-settings-panel-CvUPtxS4.js} +1 -1
  7. package/dist/gateway/static/root/assets/{agent-plugin-dialog-BY6tPYOK.js → agent-plugin-dialog-1tRxDfjI.js} +1 -1
  8. package/dist/gateway/static/root/assets/{agents-admin-api-BkXb7VEZ.js → agents-admin-api-CVdFV-cU.js} +1 -1
  9. package/dist/gateway/static/root/assets/{agents-CdSEoeje.js → agents-gdT0whx9.js} +3 -3
  10. package/dist/gateway/static/root/assets/{app-management-settings-panel-BtD53cfe.js → app-management-settings-panel-CaxnUxvy.js} +1 -1
  11. package/dist/gateway/static/root/assets/{appearance-settings-BAweWgX_.js → appearance-settings-6NKquG3v.js} +1 -1
  12. package/dist/gateway/static/root/assets/{apps-page-CS6-hrIB.js → apps-page-BoB3MbsB.js} +1 -1
  13. package/dist/gateway/static/root/assets/{archive-plugin-CKe3qAaL.js → archive-plugin-BWtLZtK1.js} +1 -1
  14. package/dist/gateway/static/root/assets/{automations-page-CtE8r9Y2.js → automations-page-CNngHw2c.js} +1 -1
  15. package/dist/gateway/static/root/assets/{automations-workspace-pnMgR4Da.js → automations-workspace-BKHsdiQ8.js} +1 -1
  16. package/dist/gateway/static/root/assets/{binary-plugins-J51oS7-D.js → binary-plugins-fIhH-wg6.js} +1 -1
  17. package/dist/gateway/static/root/assets/{block-editor-D5hf6WcP.js → block-editor-BhstSZNE.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-automation-inputs-5B3qAdmb.js → browser-automation-inputs-B6sOBxVA.js} +1 -1
  19. package/dist/gateway/static/root/assets/{browser-automations-page-PZDQlXH4.js → browser-automations-page-HZAKkVVt.js} +1 -1
  20. package/dist/gateway/static/root/assets/{browser-settings-page-2YDV-ZWt.js → browser-settings-page-D8IpVQI6.js} +1 -1
  21. package/dist/gateway/static/root/assets/{capabilities-CT_ZW9fT.js → capabilities-C4grvUkw.js} +1 -1
  22. package/dist/gateway/static/root/assets/{capabilities-BKu9BqPe.js → capabilities-CAIQmCrH.js} +1 -1
  23. package/dist/gateway/static/root/assets/{capabilities-page-CB-iX3Fy.js → capabilities-page-DK8FJRW4.js} +2 -2
  24. package/dist/gateway/static/root/assets/{capabilities-settings-panel-BCTuWNaW.js → capabilities-settings-panel-BP2roWcM.js} +1 -1
  25. package/dist/gateway/static/root/assets/{capability-header-actions--aC5XB9E.js → capability-header-actions-BA1M7RRP.js} +1 -1
  26. package/dist/gateway/static/root/assets/{channels-JnAQP1bt.js → channels-EQGCxr8W.js} +1 -1
  27. package/dist/gateway/static/root/assets/{chat-terminal-dock-BFZEpvzn.js → chat-terminal-dock-KS_yk1H7.js} +1 -1
  28. package/dist/gateway/static/root/assets/{computer-settings-page-Dc9ooEM-.js → computer-settings-page-CGBR0KFw.js} +1 -1
  29. package/dist/gateway/static/root/assets/{connector-service-page-1_QB5D-t.js → connector-service-page-CY_3H_l9.js} +1 -1
  30. package/dist/gateway/static/root/assets/{connectors-page-Um_Jy5zh.js → connectors-page-CUOL6JX0.js} +1 -1
  31. package/dist/gateway/static/root/assets/{date-picker-C9ZqTPui.js → date-picker-CDSZ-PWV.js} +1 -1
  32. package/dist/gateway/static/root/assets/{dependency-picker-DBz0Pmyr.js → dependency-picker-CyNH4m20.js} +1 -1
  33. package/dist/gateway/static/root/assets/{desktop-pet-BLtp2MmX.js → desktop-pet-BsZQsQ2_.js} +1 -1
  34. package/dist/gateway/static/root/assets/{desktop-pet-settings-BNGbqwec.js → desktop-pet-settings-DMgkUy6g.js} +1 -1
  35. package/dist/gateway/static/root/assets/{device-pairing-wizard-7rdo-A7d.js → device-pairing-wizard-JjbUN8y-.js} +1 -1
  36. package/dist/gateway/static/root/assets/{directory-picker-path-field-BnilGgwM.js → directory-picker-path-field-CBTI3tKh.js} +1 -1
  37. package/dist/gateway/static/root/assets/{extension-debug-page-BGyJpRv4.js → extension-debug-page-C7nSpOKj.js} +1 -1
  38. package/dist/gateway/static/root/assets/{extension-page-DsrVktRN.js → extension-page-BYUjAvsZ.js} +1 -1
  39. package/dist/gateway/static/root/assets/{extension-provider-F9JzOWZ3.js → extension-provider-DaLt3bC-.js} +1 -1
  40. package/dist/gateway/static/root/assets/{extension-settings-page-jeb0ytRK.js → extension-settings-page-CRasspq0.js} +1 -1
  41. package/dist/gateway/static/root/assets/{fallback-models-bZcxkEDz.js → fallback-models-BLJFYASE.js} +1 -1
  42. package/dist/gateway/static/root/assets/{gateway-config-swr-CoRoOG1l.js → gateway-config-swr-DIIzvDLQ.js} +1 -1
  43. package/dist/gateway/static/root/assets/{gateway-realtime-D0ygm6bc.js → gateway-realtime-DD70L42G.js} +1 -1
  44. package/dist/gateway/static/root/assets/gateway-realtime-store-DeUVEPPE.js +1 -0
  45. package/dist/gateway/static/root/assets/{gateway-settings-A9SzLsGp.js → gateway-settings-B9n5naCr.js} +1 -1
  46. package/dist/gateway/static/root/assets/{gateway-startup-retry-FDS6S6qa.js → gateway-startup-retry-D_EwU7-6.js} +1 -1
  47. package/dist/gateway/static/root/assets/{home-page-CnHzaH9K.js → home-page-BP6qAgBt.js} +1 -1
  48. package/dist/gateway/static/root/assets/{image-generation-api-BPd76jW5.js → image-generation-api-BkK22JsL.js} +1 -1
  49. package/dist/gateway/static/root/assets/{imports-page-CzpsV6Vz.js → imports-page-YJKcTKKr.js} +1 -1
  50. package/dist/gateway/static/root/assets/index-6JNNrzCq.js +106 -0
  51. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-D90Dvlwo.js → keyboard-shortcuts-settings-BG_kM_Rm.js} +1 -1
  52. package/dist/gateway/static/root/assets/{local-app-workbench-page-_9IKMkV8.js → local-app-workbench-page-lHi21M1T.js} +1 -1
  53. package/dist/gateway/static/root/assets/{local-apps-page-D6gejARs.js → local-apps-page-jqthjcQO.js} +1 -1
  54. package/dist/gateway/static/root/assets/local-session-drafts-C4et6msJ.js +1 -0
  55. package/dist/gateway/static/root/assets/{locale-store-DId6-v2R.js → locale-store-CvNO-hbt.js} +1 -1
  56. package/dist/gateway/static/root/assets/{logs-page--t8d-oLb.js → logs-page-CH7W-dm5.js} +1 -1
  57. package/dist/gateway/static/root/assets/{management-settings-DVDmXzTg.js → management-settings-DVgI_KNm.js} +1 -1
  58. package/dist/gateway/static/root/assets/{markdown-view-DQZ51j9e.js → markdown-view-DDJlD5jR.js} +1 -1
  59. package/dist/gateway/static/root/assets/{media-plugins-XLewwq2q.js → media-plugins-C25mOgs2.js} +1 -1
  60. package/dist/gateway/static/root/assets/messages-pGa2qMzG.js +3 -0
  61. package/dist/gateway/static/root/assets/models-hub-cache-DzFiL4xV.js +1 -0
  62. package/dist/gateway/static/root/assets/{note-detail-panel-DuZAEfU1.js → note-detail-panel-kyX-n1db.js} +3 -3
  63. package/dist/gateway/static/root/assets/{notes-api-Byt65v3r.js → notes-api-CKLw9vjk.js} +1 -1
  64. package/dist/gateway/static/root/assets/{notes-page-CgWNESGp.js → notes-page-CLZygZlm.js} +1 -1
  65. package/dist/gateway/static/root/assets/{oauth-api-BYsCbyGZ.js → oauth-api-CC5KkSgG.js} +1 -1
  66. package/dist/gateway/static/root/assets/{page-context-capture-button-Z72eiQZn.js → page-context-capture-button-KX9mrcJW.js} +1 -1
  67. package/dist/gateway/static/root/assets/{personal-page-BtMatL9a.js → personal-page-DnXlcJNJ.js} +1 -1
  68. package/dist/gateway/static/root/assets/{product-open-page-w5Hdf0hQ.js → product-open-page-D7pknlCh.js} +1 -1
  69. package/dist/gateway/static/root/assets/{project-detail-page-CP6I3ZCV.js → project-detail-page-DhV9DPj8.js} +1 -1
  70. package/dist/gateway/static/root/assets/{projects-page-DYs6XrrK.js → projects-page-D181xkFw.js} +1 -1
  71. package/dist/gateway/static/root/assets/{registry-api-7F2WNEZC.js → registry-api-CiN49wvk.js} +1 -1
  72. package/dist/gateway/static/root/assets/{remote-access-hub-DjYoYAEw.js → remote-access-hub-CQnBARQW.js} +1 -1
  73. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Qar_DXLv.js → runtime-tools-settings-panel-wZjlSBiM.js} +1 -1
  74. package/dist/gateway/static/root/assets/{scenes-page-BSIcDCa-.js → scenes-page-DWt54veq.js} +1 -1
  75. package/dist/gateway/static/root/assets/{schema-form-C_cJLGgF.js → schema-form-CMB61TV1.js} +1 -1
  76. package/dist/gateway/static/root/assets/secret-input-D93UrW4C.js +1 -0
  77. package/dist/gateway/static/root/assets/{send-session-input-D1oc6BC6.js → send-session-input-jH6MQwdZ.js} +1 -1
  78. package/dist/gateway/static/root/assets/{session-api-N3N37MrR.js → session-api-CW2X7g_U.js} +1 -1
  79. package/dist/gateway/static/root/assets/{session-manager-CMGUwtbN.js → session-manager-BDpdi3lF.js} +2 -2
  80. package/dist/gateway/static/root/assets/{sessions-page-BBV5Z24a.js → sessions-page-DPEdjUdR.js} +1 -1
  81. package/dist/gateway/static/root/assets/settings-advanced-gate-B6WGnTLY.js +1 -0
  82. package/dist/gateway/static/root/assets/{settings-page-F2vGXBw7.js → settings-page-Ch71KQjb.js} +1 -1
  83. package/dist/gateway/static/root/assets/{setup-status-panel-DJxbjUOg.js → setup-status-panel-C7sLy8Hl.js} +1 -1
  84. package/dist/gateway/static/root/assets/{share-link-dialog-TBBGJPfT.js → share-link-dialog-DCSmx-Rl.js} +1 -1
  85. package/dist/gateway/static/root/assets/{share-preview-page-DyRLPsPv.js → share-preview-page-C93IM3QK.js} +1 -1
  86. package/dist/gateway/static/root/assets/{shares-api-DU0fHP2G.js → shares-api-B4rLfG3l.js} +1 -1
  87. package/dist/gateway/static/root/assets/{shares-settings-CJa6FBpP.js → shares-settings-C_6idV8e.js} +1 -1
  88. package/dist/gateway/static/root/assets/{skill-api-C340XD9d.js → skill-api-sKX8SSlQ.js} +1 -1
  89. package/dist/gateway/static/root/assets/{skill-reload-api-ClyFqHk7.js → skill-reload-api-Ro-s69NW.js} +1 -1
  90. package/dist/gateway/static/root/assets/{skills-page-C4lF94m5.js → skills-page-TsrjLYcI.js} +1 -1
  91. package/dist/gateway/static/root/assets/{system-settings-panel-CmJUu3lb.js → system-settings-panel-DIjaUlla.js} +1 -1
  92. package/dist/gateway/static/root/assets/{task-detail-page-De-Rr8W6.js → task-detail-page-B4Lby289.js} +1 -1
  93. package/dist/gateway/static/root/assets/{theme-store-OhcbFEUR.js → theme-store-DbRLBHVY.js} +1 -1
  94. package/dist/gateway/static/root/assets/tracing-settings-page-IgY26AYH.js +1 -0
  95. package/dist/gateway/static/root/assets/{tunnel-api-Bl4nrCuE.js → tunnel-api-CgARwbus.js} +1 -1
  96. package/dist/gateway/static/root/assets/{usage-page-QZEAaa8n.js → usage-page-CKju62Cm.js} +1 -1
  97. package/dist/gateway/static/root/assets/{use-autosave-veoM0dHn.js → use-autosave-C889OTsP.js} +1 -1
  98. package/dist/gateway/static/root/assets/{use-composer-attachments-DB0bBGzZ.js → use-composer-attachments-Dlm9EFTO.js} +1 -1
  99. package/dist/gateway/static/root/assets/{use-file-preview-expanded-Bope6MW6.js → use-file-preview-expanded-BOpcSApw.js} +2 -2
  100. package/dist/gateway/static/root/assets/{user-model-page-Crh2oNpZ.js → user-model-page-CTkCLRhE.js} +1 -1
  101. package/dist/gateway/static/root/assets/{voice-api-key-field-CwD6a3KQ.js → voice-api-key-field-evWflGY6.js} +1 -1
  102. package/dist/gateway/static/root/assets/{voice-config-api-Daexehmc.js → voice-config-api-CZoV2Lt4.js} +1 -1
  103. package/dist/gateway/static/root/assets/{work-discovery-overlay-9jnjEAaz.js → work-discovery-overlay-B2-2F39_.js} +1 -1
  104. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BAcPxdcT.js → workflow-run-setup-panel-cOGM8Nug.js} +1 -1
  105. package/dist/gateway/static/root/assets/{workflows-page-D8Zm-ooa.js → workflows-page-Csk8xrRk.js} +1 -1
  106. package/dist/gateway/static/root/assets/{workspace-api-Cs4sjV2A.js → workspace-api-B9M9ECTB.js} +2 -2
  107. package/dist/gateway/static/root/index.html +28 -28
  108. package/dist/package.js +1 -1
  109. package/dist/packages/gateway-contract/src/session-input-command.js +1 -0
  110. package/dist/src/agent/agent-manager.d.ts +1 -0
  111. package/dist/src/agent/agent-manager.js +34 -2
  112. package/dist/src/agent/context/execution-context.js +1 -1
  113. package/dist/src/agent/context/project-context.js +4 -4
  114. package/dist/src/agent/embedded/run-for-session.js +1 -1
  115. package/dist/src/agent/inbound/attachment-pipeline.js +1 -1
  116. package/dist/src/agent/prompt/voice-presentation.d.ts +1 -1
  117. package/dist/src/agent/prompt/voice-presentation.js +1 -1
  118. package/dist/src/agent/service/direct-turn-helpers.js +17 -1
  119. package/dist/src/agent/service.js +2 -2
  120. package/dist/src/agent/tools/delegation-parent-policy.js +2 -0
  121. package/dist/src/agent/tools/delegation-policy.js +2 -0
  122. package/dist/src/agent/tools/factory.d.ts +2 -0
  123. package/dist/src/agent/tools/factory.js +26 -4
  124. package/dist/src/agent/tools/index.d.ts +2 -2
  125. package/dist/src/agent/tools/index.js +3 -3
  126. package/dist/src/agent/tools/knowledge-memory-tool.d.ts +2 -0
  127. package/dist/src/agent/tools/knowledge-memory-tool.js +60 -1
  128. package/dist/src/agent/tools/personal-task-tool.d.ts +12 -8
  129. package/dist/src/agent/tools/personal-task-tool.js +35 -41
  130. package/dist/src/agent/tools/user-context-tool.d.ts +2 -0
  131. package/dist/src/agent/tools/user-context-tool.js +61 -2
  132. package/dist/src/agent-catalog/repository.d.ts +1 -0
  133. package/dist/src/agent-catalog/repository.js +3 -0
  134. package/dist/src/chat-commands/personal-command-policy.d.ts +2 -0
  135. package/dist/src/chat-commands/personal-command-policy.js +9 -0
  136. package/dist/src/chat-commands/registry.js +6 -0
  137. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  138. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  139. package/dist/src/gateway/hono/routes/observability.js +8 -0
  140. package/dist/src/gateway/hono/routes/projects.js +1 -1
  141. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +2 -0
  142. package/dist/src/gateway/hono/routes/session-input-handler.js +8 -0
  143. package/dist/src/gateway/hono/routes/sessions.js +1 -1
  144. package/dist/src/gateway/hono/routes/voice.js +1 -1
  145. package/dist/src/gateway/service/agent-runner.d.ts +1 -0
  146. package/dist/src/gateway/service/agent-runner.js +12 -1
  147. package/dist/src/gateway/service/run-gateway-agent.d.ts +1 -0
  148. package/dist/src/gateway/service/run-gateway-agent.js +15 -0
  149. package/dist/src/gateway/service/session-command-service.js +5 -3
  150. package/dist/src/gateway/service/session-input-coordinator.d.ts +12 -0
  151. package/dist/src/gateway/service/session-input-coordinator.js +63 -5
  152. package/dist/src/gateway/service/sessions-api.js +1 -1
  153. package/dist/src/gateway/service.d.ts +2 -0
  154. package/dist/src/gateway/service.js +28 -14
  155. package/dist/src/gateway/session-context-summary.js +1 -1
  156. package/dist/src/gateway/session-reset-service.js +1 -1
  157. package/dist/src/home-intelligence/host.js +2 -2
  158. package/dist/src/local-apps/service.js +1 -1
  159. package/dist/src/personal-agent/capability-service.js +3 -2
  160. package/dist/src/personal-agent/communication.d.ts +3 -2
  161. package/dist/src/personal-agent/communication.js +5 -4
  162. package/dist/src/personal-agent/conversation-state.d.ts +5 -0
  163. package/dist/src/personal-agent/conversation-state.js +17 -0
  164. package/dist/src/personal-agent/persona.d.ts +6 -0
  165. package/dist/src/personal-agent/persona.js +16 -0
  166. package/dist/src/personal-agent/policy.d.ts +3 -1
  167. package/dist/src/personal-agent/policy.js +26 -6
  168. package/dist/src/personal-agent/prompt-context.d.ts +10 -0
  169. package/dist/src/personal-agent/prompt-context.js +119 -0
  170. package/dist/src/personal-agent/prompts.d.ts +7 -0
  171. package/dist/src/personal-agent/prompts.js +124 -0
  172. package/dist/src/personal-agent/reply-composer.d.ts +22 -0
  173. package/dist/src/personal-agent/reply-composer.js +304 -0
  174. package/dist/src/personal-agent/reply-style.d.ts +2 -0
  175. package/dist/src/personal-agent/reply-style.js +14 -0
  176. package/dist/src/personal-agent/repository.d.ts +1 -1
  177. package/dist/src/personal-agent/repository.js +1 -1
  178. package/dist/src/personal-agent/request-delivery.d.ts +1 -1
  179. package/dist/src/personal-agent/request-delivery.js +18 -4
  180. package/dist/src/personal-agent/request-service.js +3 -3
  181. package/dist/src/personal-agent/service.d.ts +1 -2
  182. package/dist/src/personal-agent/service.js +4 -84
  183. package/dist/src/personal-agent/specialist-capabilities.d.ts +9 -0
  184. package/dist/src/personal-agent/specialist-capabilities.js +37 -0
  185. package/dist/src/session/init-session-turn.js +10 -0
  186. package/dist/src/session/store.js +1 -1
  187. package/dist/src/storage/sqlite/migrations/234_task_result_reply.sql +14 -0
  188. package/dist/src/storage/sqlite/migrations/235_personal_conversation_priority.sql +3 -0
  189. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  190. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  191. package/dist/src/storage/sqlite/schema.js +1 -1
  192. package/dist/src/storage/sqlite/session-input-repository.d.ts +2 -0
  193. package/dist/src/storage/sqlite/session-input-repository.js +18 -5
  194. package/dist/src/tasks/execution-context.js +1 -1
  195. package/dist/src/tasks/task-main-update-decision-service.js +1 -1
  196. package/dist/src/tasks/task-result-delivery-service.js +20 -4
  197. package/dist/src/voice/realtime/agentBroker.js +11 -2
  198. package/dist/src/voice/realtime/agentEngine.js +50 -17
  199. package/dist/src/voice/realtime/engine.d.ts +1 -0
  200. package/dist/src/voice/realtime/omniEngine.d.ts +1 -0
  201. package/dist/src/voice/realtime/omniEngine.js +21 -2
  202. package/dist/src/voice/realtime/playback-echo.d.ts +7 -0
  203. package/dist/src/voice/realtime/playback-echo.js +23 -1
  204. package/dist/src/voice/realtime/runtime.d.ts +1 -0
  205. package/dist/src/voice/realtime/runtime.js +5 -0
  206. package/dist/src/voice/realtime/runtime.types.d.ts +2 -0
  207. package/dist/src/work-discovery/service.js +1 -1
  208. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  209. package/package.json +4 -4
  210. package/dist/gateway/static/root/assets/gateway-realtime-store-DBvCRclh.js +0 -1
  211. package/dist/gateway/static/root/assets/index-BYNmHn-z.js +0 -106
  212. package/dist/gateway/static/root/assets/local-session-drafts-gbemPamv.js +0 -1
  213. package/dist/gateway/static/root/assets/messages-BHvpZNe9.js +0 -3
  214. package/dist/gateway/static/root/assets/models-hub-cache-B9SKjidc.js +0 -1
  215. package/dist/gateway/static/root/assets/secret-input-DPl3VYM8.js +0 -1
  216. package/dist/gateway/static/root/assets/settings-advanced-gate-DRc9IDJf.js +0 -1
  217. package/dist/gateway/static/root/assets/tracing-settings-page-DoBJ0TYY.js +0 -1
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{f as i}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{n as a,r as o}from"./popover-select-BgSdSbCL.js";import{t as s}from"./circle-alert-BEjgurr2.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./message-square-plus-XP0tGdlV.js";import{t as u}from"./rotate-ccw-JM1TBLpp.js";import{t as d}from"./messages-BHvpZNe9.js";import{t as f}from"./cn-JdwAhgNB.js";import{n as p}from"./locale-store-DId6-v2R.js";import{n as m}from"./interaction-BdhHBbYa.js";import{t as h}from"./skeleton-BwbyijEw.js";import{n as g}from"./electron-env-Dit0bHgy.js";import{Xo as _,no as v,ri as y}from"./index-BYNmHn-z.js";import{t as b}from"./desktop-pet-sprite-DTqXSpqf.js";import{n as x,r as S}from"./settings-page-layout-X1x-2Cp9.js";var C=n(),w=e(t(),1),T=r();function E(e){let t=(0,C.c)(16),{title:n,desc:r,checked:i,disabled:a,onChange:o}=e,s;t[0]===n?s=t[1]:(s=(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=s);let c;t[2]===r?c=t[3]:(c=(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r}),t[2]=r,t[3]=c);let l;t[4]!==s||t[5]!==c?(l=(0,T.jsxs)(`div`,{className:`min-w-0`,children:[s,c]}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;t[7]===o?u=t[8]:(u=e=>o(e.target.checked),t[7]=o,t[8]=u);let d;t[9]!==i||t[10]!==a||t[11]!==u?(d=(0,T.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:a,checked:i,onChange:u}),t[9]=i,t[10]=a,t[11]=u,t[12]=d):d=t[12];let f;return t[13]!==l||t[14]!==d?(f=(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[l,d]}),t[13]=l,t[14]=d,t[15]=f):f=t[15],f}function D(){let e=d(p(e=>e.language)).desktopPetSettings,t=i(),[n,r]=(0,w.useState)(null),[C,D]=(0,w.useState)(!1),[O,k]=(0,w.useState)(null),A=typeof window<`u`?window.electronAPI?.pet:void 0,j=(0,w.useMemo)(()=>n?.pets.find(e=>e.id===n.prefs.selectedPetId)??n?.pets[0],[n]),M=(0,w.useCallback)(async()=>{if(A){D(!0);try{r(await A.getState())}finally{D(!1)}}},[A]);if((0,w.useEffect)(()=>{if(A)return M(),A.onStateChanged(r)},[A,M]),!g()||!A)return null;if(!n)return(0,T.jsxs)(S,{gap:`gap-4`,children:[(0,T.jsx)(x,{title:e.title,subtitle:e.subtitle}),(0,T.jsx)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,"aria-busy":!0,"aria-label":e.loading,children:(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsx)(h,{className:`h-14 rounded-xl`}),(0,T.jsx)(h,{className:`h-14 rounded-xl`}),(0,T.jsx)(h,{className:`h-24 rounded-xl`}),(0,T.jsx)(`div`,{className:`space-y-2 pt-2`,children:Array.from({length:3}).map((e,t)=>(0,T.jsx)(h,{className:`h-16 rounded-xl`},t))})]})})]});let N=async e=>{D(!0);try{r(await A.setPrefs(e))}finally{D(!1)}},P=async e=>{e?(await A.show(),r(await A.getState())):r(await A.setPrefs({enabled:!1}))},F=e=>{N({selectedPetId:e})},I=t=>{if(t.builtin&&t.i18nKey){let n=e.builtinPets[t.i18nKey];if(n)return n}return{name:t.name,description:t.description}},L=e=>{t({pathname:`/chat/new`,search:`?draft=${encodeURIComponent(e)}`})},R=e=>{if(e.sourcePrompt?.trim())return e.sourcePrompt.trim();let{description:t}=I(e);return t.replace(/^Custom pet generated from:\s*/i,``).trim()||t},z=(e,t)=>Object.entries(t).reduce((e,[t,n])=>e.split(`{${t}}`).join(n),e),B=()=>{L(e.createChatDraft)},V=t=>{L(z(e.optimizeChatDraft,{id:t.id,name:I(t).name,description:I(t).description,sourcePrompt:R(t)}))},H=t=>{L(z(e.fixChatDraft,{dir:t.dir,reason:t.reason,details:t.details?.join(`; `)||e.noIssueDetails}))},U=O??n.prefs.sizePercent,W=Math.max(1,Math.floor((Date.now()-n.relationship.firstMetAt)/864e5)+1),G=async(e=U)=>{let t=Math.min(140,Math.max(70,Math.round(e/5)*5));k(null),t!==n.prefs.sizePercent&&await N({sizePercent:t})};return(0,T.jsxs)(S,{gap:`gap-4`,children:[(0,T.jsx)(x,{title:e.title,subtitle:e.subtitle,actions:(0,T.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,T.jsx)(y,{className:`size-9 shrink-0 p-0`,disabled:C,label:e.refresh,onClick:M}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,m.press),onClick:()=>void A.openCustomPetsDir(),children:[(0,T.jsx)(c,{className:`size-3.5`,strokeWidth:1.75}),e.openFolder]})]})}),(0,T.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(E,{title:e.enable,desc:e.enableDesc,checked:n.prefs.enabled,disabled:C,onChange:e=>void P(e)}),(0,T.jsx)(E,{title:e.showOnStartup,desc:e.showOnStartupDesc,checked:n.prefs.showOnStartup,disabled:C,onChange:e=>void N({showOnStartup:e})})]}),(0,T.jsx)(`div`,{className:`mt-5 rounded-xl bg-surface-base/55 p-3`,children:(0,T.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,T.jsx)(v,{className:`mt-0.5 size-4 text-accent-fg`,strokeWidth:1.8}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.createTitle}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.createDesc})]})]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex h-9 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 text-xs font-semibold text-on-accent hover:bg-accent/90`,m.press),onClick:B,children:[(0,T.jsx)(l,{className:`size-3.5`,strokeWidth:1.75}),e.createInChat]})]})}),(0,T.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 rounded-xl bg-surface-base/55 p-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.bondTitle}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.bondDesc})]}),(0,T.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent-soft px-2.5 py-1 text-xs font-medium text-accent-fg`,children:e.bondSummary.replace(`{days}`,String(W)).replace(`{tasks}`,String(n.relationship.completedTaskCount))})]}),(0,T.jsxs)(`div`,{className:`mt-5`,children:[(0,T.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.petList}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.petListDesc})]}),j?(0,T.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2.5 py-1 text-xs font-medium text-accent-fg`,children:I(j).name}):null]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-xl bg-surface-base/45 p-1 [&>*]:rounded-lg [&>*]:bg-surface-panel/55`,children:[n.pets.map(t=>{let r=t.id===n.prefs.selectedPetId,i=I(t);return(0,T.jsxs)(`div`,{className:`flex items-center gap-3 p-3`,children:[(0,T.jsx)(b,{pet:t,action:`idle`,size:`tiny`}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`p`,{className:`truncate text-sm font-semibold text-fg`,children:i.name}),t.builtin?null:(0,T.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:e.customBadge})]}),(0,T.jsx)(`p`,{className:`truncate text-xs text-fg-muted`,children:i.description})]}),(0,T.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t.builtin?null:(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,m.press),onClick:()=>V(t),children:[(0,T.jsx)(_,{className:`size-3.5`,strokeWidth:1.75}),e.optimizeInChat]}),(0,T.jsx)(`button`,{type:`button`,className:f(`rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors`,r?`bg-surface-hover text-fg-muted`:`bg-surface-panel text-fg hover:bg-surface-hover`,m.press),disabled:r||C,onClick:()=>F(t.id),children:r?e.selected:e.select})]})]},t.id)}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e.customPets}),(0,T.jsx)(`p`,{className:`font-mono text-xs text-fg-muted`,children:n.customPetsDir})]}),(0,T.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 text-xs font-medium text-fg-muted hover:text-fg`,onClick:()=>void A.openCustomPetsDir(),children:[e.openFolder,(0,T.jsx)(c,{className:`size-3.5`,strokeWidth:1.75})]})]})]}),n.petIssues.length>0?(0,T.jsxs)(`div`,{className:`mt-2 rounded-xl bg-danger/10 p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-semibold text-danger`,children:[(0,T.jsx)(s,{className:`size-3.5`,strokeWidth:1.8}),e.invalidPets]}),(0,T.jsx)(`div`,{className:`mt-2 space-y-2`,children:n.petIssues.map(t=>(0,T.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg bg-surface-base/70 p-2 text-xs text-fg-muted sm:flex-row sm:items-start sm:justify-between`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{className:`truncate font-mono text-[11px] text-fg`,children:t.dir}),(0,T.jsx)(`p`,{children:t.reason}),t.details?.length?(0,T.jsx)(`p`,{className:`line-clamp-2`,children:t.details.join(`; `)}):null]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg border border-danger/30 bg-surface-base px-2.5 text-xs font-medium text-danger hover:bg-danger/10`,m.press),onClick:()=>H(t),children:[(0,T.jsx)(l,{className:`size-3.5`,strokeWidth:1.75}),e.fixInChat]})]},`${t.dir}-${t.reason}`))})]}):null]}),(0,T.jsxs)(`div`,{className:`mt-5 grid gap-2`,children:[(0,T.jsxs)(`div`,{className:`rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.size}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.sizeDesc})]}),(0,T.jsxs)(`span`,{className:`text-xs font-medium text-fg-muted`,children:[U,`%`]})]}),(0,T.jsx)(`input`,{type:`range`,min:70,max:140,step:5,className:`mt-3 w-full accent-accent`,value:U,onChange:e=>k(Number(e.target.value)),onBlur:()=>void G(),onKeyUp:e=>{(e.key===`Enter`||e.key===` `||e.key.startsWith(`Arrow`))&&G()},onPointerUp:()=>void G()})]}),(0,T.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,T.jsx)(E,{title:e.alwaysOnTop,desc:e.alwaysOnTopDesc,checked:n.prefs.alwaysOnTop,disabled:C,onChange:e=>void N({alwaysOnTop:e})}),(0,T.jsx)(E,{title:e.bubbles,desc:e.bubblesDesc,checked:n.prefs.bubbleEnabled,disabled:C,onChange:e=>void N({bubbleEnabled:e})}),(0,T.jsx)(E,{title:e.proactiveTips,desc:e.proactiveTipsDesc,checked:n.prefs.proactiveTipsEnabled,disabled:C,onChange:e=>void N({proactiveTipsEnabled:e})}),(0,T.jsx)(E,{title:e.interactions,desc:e.interactionsDesc,checked:n.prefs.interactionEnabled,disabled:C,onChange:e=>void N({interactionEnabled:e})}),(0,T.jsx)(E,{title:e.reducedMotion,desc:e.reducedMotionDesc,checked:n.prefs.reducedMotion,disabled:C,onChange:e=>void N({reducedMotion:e})}),(0,T.jsx)(E,{title:e.clickThrough,desc:e.clickThroughDesc,checked:n.prefs.clickThroughWhenIdle,disabled:C,onChange:e=>void N({clickThroughWhenIdle:e})})]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.behaviorMode}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.behaviorModeDesc})]}),(0,T.jsxs)(a,{className:`w-full sm:w-40`,triggerClassName:`h-9 bg-surface-panel`,value:n.prefs.behaviorMode,onChange:e=>void N({behaviorMode:e.target.value}),children:[(0,T.jsx)(o,{value:`focus`,children:e.behaviorFocus}),(0,T.jsx)(o,{value:`companion`,children:e.behaviorCompanion}),(0,T.jsx)(o,{value:`playful`,children:e.behaviorPlayful})]})]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex w-fit items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-3 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,m.press),disabled:C,onClick:()=>void A.resetPosition().then(r),children:[(0,T.jsx)(u,{className:`size-3.5`,strokeWidth:1.75}),e.resetPosition]})]})]})]})}export{D as DesktopPetSettings};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{f as i}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{n as a,r as o}from"./popover-select-BgSdSbCL.js";import{t as s}from"./circle-alert-BEjgurr2.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./message-square-plus-XP0tGdlV.js";import{t as u}from"./rotate-ccw-JM1TBLpp.js";import{t as d}from"./messages-pGa2qMzG.js";import{t as f}from"./cn-JdwAhgNB.js";import{n as p}from"./locale-store-CvNO-hbt.js";import{n as m}from"./interaction-BdhHBbYa.js";import{t as h}from"./skeleton-BwbyijEw.js";import{n as g}from"./electron-env-Dit0bHgy.js";import{Xo as _,no as v,ri as y}from"./index-6JNNrzCq.js";import{t as b}from"./desktop-pet-sprite-DTqXSpqf.js";import{n as x,r as S}from"./settings-page-layout-X1x-2Cp9.js";var C=n(),w=e(t(),1),T=r();function E(e){let t=(0,C.c)(16),{title:n,desc:r,checked:i,disabled:a,onChange:o}=e,s;t[0]===n?s=t[1]:(s=(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=s);let c;t[2]===r?c=t[3]:(c=(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r}),t[2]=r,t[3]=c);let l;t[4]!==s||t[5]!==c?(l=(0,T.jsxs)(`div`,{className:`min-w-0`,children:[s,c]}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;t[7]===o?u=t[8]:(u=e=>o(e.target.checked),t[7]=o,t[8]=u);let d;t[9]!==i||t[10]!==a||t[11]!==u?(d=(0,T.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:a,checked:i,onChange:u}),t[9]=i,t[10]=a,t[11]=u,t[12]=d):d=t[12];let f;return t[13]!==l||t[14]!==d?(f=(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[l,d]}),t[13]=l,t[14]=d,t[15]=f):f=t[15],f}function D(){let e=d(p(e=>e.language)).desktopPetSettings,t=i(),[n,r]=(0,w.useState)(null),[C,D]=(0,w.useState)(!1),[O,k]=(0,w.useState)(null),A=typeof window<`u`?window.electronAPI?.pet:void 0,j=(0,w.useMemo)(()=>n?.pets.find(e=>e.id===n.prefs.selectedPetId)??n?.pets[0],[n]),M=(0,w.useCallback)(async()=>{if(A){D(!0);try{r(await A.getState())}finally{D(!1)}}},[A]);if((0,w.useEffect)(()=>{if(A)return M(),A.onStateChanged(r)},[A,M]),!g()||!A)return null;if(!n)return(0,T.jsxs)(S,{gap:`gap-4`,children:[(0,T.jsx)(x,{title:e.title,subtitle:e.subtitle}),(0,T.jsx)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,"aria-busy":!0,"aria-label":e.loading,children:(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsx)(h,{className:`h-14 rounded-xl`}),(0,T.jsx)(h,{className:`h-14 rounded-xl`}),(0,T.jsx)(h,{className:`h-24 rounded-xl`}),(0,T.jsx)(`div`,{className:`space-y-2 pt-2`,children:Array.from({length:3}).map((e,t)=>(0,T.jsx)(h,{className:`h-16 rounded-xl`},t))})]})})]});let N=async e=>{D(!0);try{r(await A.setPrefs(e))}finally{D(!1)}},P=async e=>{e?(await A.show(),r(await A.getState())):r(await A.setPrefs({enabled:!1}))},F=e=>{N({selectedPetId:e})},I=t=>{if(t.builtin&&t.i18nKey){let n=e.builtinPets[t.i18nKey];if(n)return n}return{name:t.name,description:t.description}},L=e=>{t({pathname:`/chat/new`,search:`?draft=${encodeURIComponent(e)}`})},R=e=>{if(e.sourcePrompt?.trim())return e.sourcePrompt.trim();let{description:t}=I(e);return t.replace(/^Custom pet generated from:\s*/i,``).trim()||t},z=(e,t)=>Object.entries(t).reduce((e,[t,n])=>e.split(`{${t}}`).join(n),e),B=()=>{L(e.createChatDraft)},V=t=>{L(z(e.optimizeChatDraft,{id:t.id,name:I(t).name,description:I(t).description,sourcePrompt:R(t)}))},H=t=>{L(z(e.fixChatDraft,{dir:t.dir,reason:t.reason,details:t.details?.join(`; `)||e.noIssueDetails}))},U=O??n.prefs.sizePercent,W=Math.max(1,Math.floor((Date.now()-n.relationship.firstMetAt)/864e5)+1),G=async(e=U)=>{let t=Math.min(140,Math.max(70,Math.round(e/5)*5));k(null),t!==n.prefs.sizePercent&&await N({sizePercent:t})};return(0,T.jsxs)(S,{gap:`gap-4`,children:[(0,T.jsx)(x,{title:e.title,subtitle:e.subtitle,actions:(0,T.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[(0,T.jsx)(y,{className:`size-9 shrink-0 p-0`,disabled:C,label:e.refresh,onClick:M}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,m.press),onClick:()=>void A.openCustomPetsDir(),children:[(0,T.jsx)(c,{className:`size-3.5`,strokeWidth:1.75}),e.openFolder]})]})}),(0,T.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,children:[(0,T.jsxs)(`div`,{className:`space-y-2`,children:[(0,T.jsx)(E,{title:e.enable,desc:e.enableDesc,checked:n.prefs.enabled,disabled:C,onChange:e=>void P(e)}),(0,T.jsx)(E,{title:e.showOnStartup,desc:e.showOnStartupDesc,checked:n.prefs.showOnStartup,disabled:C,onChange:e=>void N({showOnStartup:e})})]}),(0,T.jsx)(`div`,{className:`mt-5 rounded-xl bg-surface-base/55 p-3`,children:(0,T.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,T.jsx)(v,{className:`mt-0.5 size-4 text-accent-fg`,strokeWidth:1.8}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.createTitle}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.createDesc})]})]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex h-9 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-accent px-3 text-xs font-semibold text-on-accent hover:bg-accent/90`,m.press),onClick:B,children:[(0,T.jsx)(l,{className:`size-3.5`,strokeWidth:1.75}),e.createInChat]})]})}),(0,T.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 rounded-xl bg-surface-base/55 p-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.bondTitle}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.bondDesc})]}),(0,T.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent-soft px-2.5 py-1 text-xs font-medium text-accent-fg`,children:e.bondSummary.replace(`{days}`,String(W)).replace(`{tasks}`,String(n.relationship.completedTaskCount))})]}),(0,T.jsxs)(`div`,{className:`mt-5`,children:[(0,T.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:e.petList}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.petListDesc})]}),j?(0,T.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2.5 py-1 text-xs font-medium text-accent-fg`,children:I(j).name}):null]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1 rounded-xl bg-surface-base/45 p-1 [&>*]:rounded-lg [&>*]:bg-surface-panel/55`,children:[n.pets.map(t=>{let r=t.id===n.prefs.selectedPetId,i=I(t);return(0,T.jsxs)(`div`,{className:`flex items-center gap-3 p-3`,children:[(0,T.jsx)(b,{pet:t,action:`idle`,size:`tiny`}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`p`,{className:`truncate text-sm font-semibold text-fg`,children:i.name}),t.builtin?null:(0,T.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:e.customBadge})]}),(0,T.jsx)(`p`,{className:`truncate text-xs text-fg-muted`,children:i.description})]}),(0,T.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[t.builtin?null:(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,m.press),onClick:()=>V(t),children:[(0,T.jsx)(_,{className:`size-3.5`,strokeWidth:1.75}),e.optimizeInChat]}),(0,T.jsx)(`button`,{type:`button`,className:f(`rounded-lg px-2.5 py-1.5 text-xs font-medium transition-colors`,r?`bg-surface-hover text-fg-muted`:`bg-surface-panel text-fg hover:bg-surface-hover`,m.press),disabled:r||C,onClick:()=>F(t.id),children:r?e.selected:e.select})]})]},t.id)}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e.customPets}),(0,T.jsx)(`p`,{className:`font-mono text-xs text-fg-muted`,children:n.customPetsDir})]}),(0,T.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 text-xs font-medium text-fg-muted hover:text-fg`,onClick:()=>void A.openCustomPetsDir(),children:[e.openFolder,(0,T.jsx)(c,{className:`size-3.5`,strokeWidth:1.75})]})]})]}),n.petIssues.length>0?(0,T.jsxs)(`div`,{className:`mt-2 rounded-xl bg-danger/10 p-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-semibold text-danger`,children:[(0,T.jsx)(s,{className:`size-3.5`,strokeWidth:1.8}),e.invalidPets]}),(0,T.jsx)(`div`,{className:`mt-2 space-y-2`,children:n.petIssues.map(t=>(0,T.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg bg-surface-base/70 p-2 text-xs text-fg-muted sm:flex-row sm:items-start sm:justify-between`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`p`,{className:`truncate font-mono text-[11px] text-fg`,children:t.dir}),(0,T.jsx)(`p`,{children:t.reason}),t.details?.length?(0,T.jsx)(`p`,{className:`line-clamp-2`,children:t.details.join(`; `)}):null]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-lg border border-danger/30 bg-surface-base px-2.5 text-xs font-medium text-danger hover:bg-danger/10`,m.press),onClick:()=>H(t),children:[(0,T.jsx)(l,{className:`size-3.5`,strokeWidth:1.75}),e.fixInChat]})]},`${t.dir}-${t.reason}`))})]}):null]}),(0,T.jsxs)(`div`,{className:`mt-5 grid gap-2`,children:[(0,T.jsxs)(`div`,{className:`rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.size}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.sizeDesc})]}),(0,T.jsxs)(`span`,{className:`text-xs font-medium text-fg-muted`,children:[U,`%`]})]}),(0,T.jsx)(`input`,{type:`range`,min:70,max:140,step:5,className:`mt-3 w-full accent-accent`,value:U,onChange:e=>k(Number(e.target.value)),onBlur:()=>void G(),onKeyUp:e=>{(e.key===`Enter`||e.key===` `||e.key.startsWith(`Arrow`))&&G()},onPointerUp:()=>void G()})]}),(0,T.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,T.jsx)(E,{title:e.alwaysOnTop,desc:e.alwaysOnTopDesc,checked:n.prefs.alwaysOnTop,disabled:C,onChange:e=>void N({alwaysOnTop:e})}),(0,T.jsx)(E,{title:e.bubbles,desc:e.bubblesDesc,checked:n.prefs.bubbleEnabled,disabled:C,onChange:e=>void N({bubbleEnabled:e})}),(0,T.jsx)(E,{title:e.proactiveTips,desc:e.proactiveTipsDesc,checked:n.prefs.proactiveTipsEnabled,disabled:C,onChange:e=>void N({proactiveTipsEnabled:e})}),(0,T.jsx)(E,{title:e.interactions,desc:e.interactionsDesc,checked:n.prefs.interactionEnabled,disabled:C,onChange:e=>void N({interactionEnabled:e})}),(0,T.jsx)(E,{title:e.reducedMotion,desc:e.reducedMotionDesc,checked:n.prefs.reducedMotion,disabled:C,onChange:e=>void N({reducedMotion:e})}),(0,T.jsx)(E,{title:e.clickThrough,desc:e.clickThroughDesc,checked:n.prefs.clickThroughWhenIdle,disabled:C,onChange:e=>void N({clickThroughWhenIdle:e})})]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35 sm:flex-row sm:items-center sm:justify-between`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.behaviorMode}),(0,T.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.behaviorModeDesc})]}),(0,T.jsxs)(a,{className:`w-full sm:w-40`,triggerClassName:`h-9 bg-surface-panel`,value:n.prefs.behaviorMode,onChange:e=>void N({behaviorMode:e.target.value}),children:[(0,T.jsx)(o,{value:`focus`,children:e.behaviorFocus}),(0,T.jsx)(o,{value:`companion`,children:e.behaviorCompanion}),(0,T.jsx)(o,{value:`playful`,children:e.behaviorPlayful})]})]}),(0,T.jsxs)(`button`,{type:`button`,className:f(`inline-flex w-fit items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-3 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover disabled:opacity-50`,m.press),disabled:C,onClick:()=>void A.resetPosition().then(r),children:[(0,T.jsx)(u,{className:`size-3.5`,strokeWidth:1.75}),e.resetPosition]})]})]})]})}export{D as DesktopPetSettings};
@@ -1 +1 @@
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{f as a}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{t as o}from"./chevron-right-BweFrslA.js";import{t as s}from"./circle-check-C23XjkUj.js";import{t as c}from"./clock-3-DnrAnuyZ.js";import{t as l}from"./download-Dk-ZjtO6.js";import{t as u}from"./external-link-DjqjBmc3.js";import{t as d}from"./x-B_N4OPjy.js";import{t as f}from"./messages-BHvpZNe9.js";import{t as p}from"./cn-JdwAhgNB.js";import{n as m}from"./locale-store-DId6-v2R.js";import{a as h,i as g,o as _,r as v,s as y,t as b}from"./dist-BGTk37IG.js";import{n as x}from"./app-link-DRL0YnPs.js";import{i as S}from"./vendor-swr-BIWyz7Rc.js";import{t as C}from"./button-CS04eWY9.js";import{t as w}from"./skeleton-BwbyijEw.js";import{i as T,o as ee}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{t as E}from"./use-async-resource-GrnWNwMZ.js";import{t as D}from"./copy-text-row-BHDs3cBa.js";import{a as O,n as k,r as A}from"./oauth-api-BYsCbyGZ.js";import{At as j,Ds as te,Eo as M,Qo as N,jt as P,kt as F}from"./index-BYNmHn-z.js";import{_ as ne,a as re,d as ie,f as ae,g as oe,h as se,i as ce,l as I,m as le,n as L,p as ue,r as R,s as z,t as B,u as de,v as fe}from"./tunnel-api-Bl4nrCuE.js";import{t as V}from"./browser-BLJWD7WI.js";var H=e(n(),1),U=r(),W=e(V(),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=f(m(e=>e.language)),t=e.endpointToolsSettings.deviceAccess.flow,n=e.tunnelSettings,{data:r,error:i,mutate:a}=S(`tunnel-status`,L,{refreshInterval:1500}),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[d,p]=(0,H.useState)(!0),[h,g]=(0,H.useState)(`idle`),[_,v]=(0,H.useState)(null),[y,b]=(0,H.useState)(``),T=(0,H.useRef)(!0);(0,H.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let ee=async()=>{if(!r)return;if(r.consentRequired&&!o){l(!0);return}let e=r.registrationSecret?.configured?null:P(),t,n=!1;v(null);try{if(r.consentRequired&&await re(),!r.registrationSecret?.configured){g(`provisioning`);let r=!1;try{await ce()}catch(e){if(!de(e))throw e;r=!0}if(r){g(`authorizing`);let r=sessionStorage.getItem(`device-pairing-oauth`),i=r?JSON.parse(r):null;t=i&&i.expiresAt>Date.now()?i.sessionId:(await O(`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(;T.current&&Date.now()<o;){let r=await A(t);if(r.authUrl&&r.authUrl!==a&&(a=r.authUrl,await j(a,e)||b(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(!T.current)return;if(!s)throw Error(`Authorization expired`);await ce()}await a()}if(!T.current)return;g(`starting`),await z(),d&&await R({autoStart:!0}),await a(),n=!0}catch(e){n=!0,T.current&&v(I(e)===`tunnel_key_limit_reached`?`key-limit`:`failed`)}finally{F(e),n&&(sessionStorage.removeItem(`device-pairing-oauth`),t&&k(t).catch(()=>{})),T.current&&(g(`idle`),b(``))}};if(!r&&!i)return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsx)(w,{className:`h-5 w-4/5`}),(0,K.jsx)(w,{className:`h-24 w-full`})]});let E=h===`provisioning`||h===`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:E?t.preparingHint:h===`authorizing`?t.authorizing:t.enableHint}),y&&h===`authorizing`?(0,K.jsx)(`a`,{href:y,target:`_blank`,rel:`noopener noreferrer`,className:`mt-4 inline-flex min-h-11 items-center text-sm text-accent`,children:t.openAuthorization}):null,E?(0,K.jsxs)(`div`,{className:`mt-8 space-y-3`,"aria-label":t.preparing,children:[(0,K.jsx)(w,{className:`h-2 w-full`}),(0,K.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.preparing})]}):null,(c||r?.consentRequired)&&h===`idle`?(0,K.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,K.jsxs)(`details`,{open:c,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,_===`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)(C,{variant:`secondary`,className:`mt-3`,onClick:()=>void x(B),children:[t.manageTunnelKeys,(0,K.jsx)(u,{className:`size-3`})]})]}):_||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:d,disabled:h!==`idle`,onChange:e=>p(e.target.checked),className:`size-4 accent-accent`}),t.autoStart]}),(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:!r||h!==`idle`||E||c&&!o,onClick:()=>void ee(),children:h===`authorizing`?t.authorizing:E?t.preparing:_?t.retry:t.enable}),i&&!r?(0,K.jsx)(C,{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)(b,{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,s;t[0]===n?s=t[1]:(s=(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]=s);let c;t[2]===r?c=t[3]:(c=(0,K.jsx)(`span`,{className:`block text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=c);let l;t[4]===i?l=t[5]:(l=(0,K.jsx)(`span`,{className:`mt-0.5 block text-xs leading-5 text-fg-muted`,children:i}),t[4]=i,t[5]=l);let u;t[6]!==c||t[7]!==l?(u=(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[c,l]}),t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,K.jsx)(o,{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]=d):d=t[9];let f;return t[10]!==a||t[11]!==s||t[12]!==u?(f=(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:[s,u,d]}),t[10]=a,t[11]=s,t[12]=u,t[13]=f):f=t[13],f}function X(e){let t=(0,U.c)(40),{onChoose:n,onChooseLocalBrowser:r,onClose:i}=e,a=m(he),o;t[0]===a?o=t[1]:(o=f(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)(h,{className:p(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),t[2]=c):c=t[2];let l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=p(`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`,T),t[3]=l):l=t[3];let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,K.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),t[4]=u):u=t[4];let b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,K.jsx)(d,{className:`size-4`}),t[5]=b):b=t[5];let x;t[6]!==s.cancel||t[7]!==i?(x=(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[u,(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:b})]}),t[6]=s.cancel,t[7]=i,t[8]=x):x=t[8];let S;t[9]===s.chooseTitle?S=t[10]:(S=(0,K.jsx)(y,{className:`text-lg font-semibold tracking-tight text-fg sm:text-xl`,children:s.chooseTitle}),t[9]=s.chooseTitle,t[10]=S);let C;t[11]===s.chooseHint?C=t[12]:(C=(0,K.jsx)(g,{className:`mt-1.5 text-sm leading-6 text-fg-muted`,children:s.chooseHint}),t[11]=s.chooseHint,t[12]=C);let w;t[13]!==s.localBrowserHint||t[14]!==s.localBrowserTitle||t[15]!==r?(w=(0,K.jsx)(Y,{icon:te,title:s.localBrowserTitle,hint:s.localBrowserHint,onClick:r}),t[13]=s.localBrowserHint,t[14]=s.localBrowserTitle,t[15]=r,t[16]=w):w=t[16];let E;t[17]===n?E=t[18]:(E=()=>n(`mobile`),t[17]=n,t[18]=E);let D;t[19]!==s.mobileHint||t[20]!==s.mobileTitle||t[21]!==E?(D=(0,K.jsx)(Y,{icon:M,title:s.mobileTitle,hint:s.mobileHint,onClick:E}),t[19]=s.mobileHint,t[20]=s.mobileTitle,t[21]=E,t[22]=D):D=t[22];let O;t[23]===n?O=t[24]:(O=()=>n(`browser`),t[23]=n,t[24]=O);let k;t[25]!==s.remoteBrowserHint||t[26]!==s.remoteBrowserTitle||t[27]!==O?(k=(0,K.jsx)(Y,{icon:N,title:s.remoteBrowserTitle,hint:s.remoteBrowserHint,onClick:O}),t[25]=s.remoteBrowserHint,t[26]=s.remoteBrowserTitle,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==D||t[30]!==k||t[31]!==w?(A=(0,K.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[w,D,k]}),t[29]=D,t[30]=k,t[31]=w,t[32]=A):A=t[32];let j;t[33]!==A||t[34]!==S||t[35]!==C?(j=(0,K.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-6 sm:px-8`,children:[S,C,A]}),t[33]=A,t[34]=S,t[35]=C,t[36]=j):j=t[36];let P;return t[37]!==j||t[38]!==x?(P=(0,K.jsxs)(_,{children:[c,(0,K.jsxs)(v,{className:l,children:[x,j]})]}),t[37]=j,t[38]=x,t[39]=P):P=t[39],P}function he(e){return e.language}function ge({targetKind:e,onClose:t,onPaired:n}){let r=m(e=>e.language),i=f(r),a=i.endpointToolsSettings.deviceAccess,b=a.flow,[O,k]=(0,H.useState)(!1),A=S(O?`device-pairing-readiness`:null,se,{refreshInterval:1500}),[j,te]=(0,H.useState)(),[M,N]=(0,H.useState)(null),[P,F]=(0,H.useState)(!1),[re,ce]=(0,H.useState)(Date.now()),[I,L]=(0,H.useState)(null),R=(0,H.useRef)(!0),z=(0,H.useRef)(null),B=(0,H.useRef)(!1),de=(0,H.useRef)(!1),V=S(j?[`device-pairing-setup`,j.id]:null,()=>oe(j.id),{refreshInterval:1500}),U=V.data?.request,W=U?.status===`completed`,G=W&&U.connectedAt!==void 0,q=S(G&&window.electronAPI?.system?`system-behavior`:null,()=>window.electronAPI.system.getBehavior()),J=j?.targetKind===`mobile`?j.universalLink:``,Y=E(()=>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=E(()=>pe(X),[X],{enabled:!O&&e===`mobile`,initial:null,errorData:null});(0,H.useEffect)(()=>{R.current=!0;let e=setInterval(()=>ce(Date.now()),1e3);return()=>{R.current=!1,clearInterval(e),z.current&&ie(z.current).catch(()=>{})}},[]);let Z=(0,H.useCallback)(async()=>{if(!B.current){B.current=!0,F(!0),N(null);try{z.current&&await ie(z.current),z.current=null,te(void 0);let t=await ae(e);if(t.kind===`ready`){if(!R.current){await ie(t.setup.id);return}z.current=t.setup.id,te(t.setup)}else await A.mutate()}catch{R.current&&N(`create`)}finally{B.current=!1,R.current&&F(!1)}}},[A,e]);(0,H.useEffect)(()=>{A.data?.ready&&!j&&M!==`create`&&!B.current&&Z()},[A.data,j,M,Z]),(0,H.useEffect)(()=>{G&&!de.current&&(de.current=!0,n?.())},[G,n]);let _e=async e=>{if(U){F(!0),N(null);try{await ue(U,e),await V.mutate()}catch{N(`decision`),await V.mutate()}finally{R.current&&F(!1)}}},ve=(0,H.useRef)(0);(0,H.useEffect)(()=>{V.data&&(ve.current=V.data.serverTime-Date.now())},[V.data]);let Q=re+ve.current,ye=j&&Q>=j.expiresAt&&!U,be=U&&[`expired`,`rejected`,`cancelled`].includes(U.status),xe=j?j.expiresAt-Q<6e4:!1,Se=j?xe?`${Math.max(0,Math.ceil((j.expiresAt-Q)/1e3))}s`:b.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=O?G?$.success:U?.status===`pending`?$.allowTitle:W||U?.status===`approved`?b.waiting:j?$.connect:b.title:Ce,Ee=M===`create`?b.createFailed:M===`decision`?b.decisionFailed:M===`background`?b.backgroundFailed:M===`download`?a.browserDownloadFailed:null,De=async()=>{F(!0),N(null);try{await le()}catch{N(`download`)}finally{R.current&&F(!1)}};return(0,K.jsxs)(_,{children:[(0,K.jsx)(h,{className:p(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,K.jsxs)(v,{className:p(`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`,T),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":b.cancel,onClick:t,children:(0,K.jsx)(d,{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)(s,{className:`mb-5 size-7 text-success`}):null,(0,K.jsx)(y,{className:`text-xl font-semibold tracking-tight text-fg`,children:Te}),(0,K.jsx)(g,{className:`mt-2 text-sm leading-relaxed text-fg-muted`,children:O?G?$.successHint:W?b.waitingForDevice:U?U.displayName:j?$.connectHint:b.intro:we}),Ee?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:Ee}):null,O&&A.error?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:b.readinessFailed}):null,O&&V.error?(0,K.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-warning`,children:b.statusUnavailable}):null,O?A.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(()=>N(`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`?b.expired:b.declined}),(0,K.jsx)(C,{variant:`primary`,onClick:()=>void Z(),disabled:P,children:b.refresh})]}):U?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:b.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:b.compare}),(0,K.jsxs)(`details`,{className:`mt-6 text-xs text-fg-muted`,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer py-2`,children:b.access}),(0,K.jsx)(`p`,{children:b.accessHint})]})]}):j?.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)(w,{className:`size-[240px] rounded-xl`})})}),Y.error?null:(0,K.jsxs)(`p`,{className:p(`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)(c,{className:`size-3.5`,"aria-hidden":`true`}),Se]})]}),Y.error?(0,K.jsx)(`p`,{role:`status`,className:`text-center text-sm text-warning`,children:b.qrFailed}):null,Y.error?(0,K.jsx)(`div`,{className:`mt-5`,children:(0,K.jsx)(D,{text:j.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:b.fallback}),(0,K.jsx)(o,{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)(D,{text:j.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})})]})]}):j?(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)(D,{text:j.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:j.expiresAt-Q<6e4?`${Math.max(0,Math.ceil((j.expiresAt-Q)/1e3))}s`:b.valid})]}):A.data.ready?(0,K.jsx)(`div`,{className:`mt-8`,children:(0,K.jsx)(w,{className:`mx-auto size-[216px]`})}):(0,K.jsxs)(`div`,{className:`mt-6 flex flex-1 flex-col`,children:[I===`tailscale`?(0,K.jsx)(fe,{embedded:!0}):I===`https`?(0,K.jsx)(ne,{}):I===`choices`?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(C,{variant:`secondary`,className:`w-full`,onClick:()=>L(`tailscale`),children:a.useTailscale}),(0,K.jsx)(C,{variant:`secondary`,className:`w-full`,onClick:()=>L(`https`),children:a.useOwnHttps})]}):(0,K.jsx)(me,{}),(0,K.jsx)(C,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>L(I?null:`choices`),children:I?b.back:b.existing})]}):(0,K.jsxs)(`div`,{className:`mt-8 space-y-4`,children:[(0,K.jsx)(w,{className:`h-5 w-3/4`}),(0,K.jsx)(w,{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)(w,{className:`size-36`}),(0,K.jsxs)(C,{variant:`secondary`,className:`mt-5 w-full`,onClick:()=>void x(X),children:[(0,K.jsx)(u,{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)(C,{variant:`secondary`,className:`w-full`,disabled:P,onClick:()=>void De(),children:[(0,K.jsx)(l,{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 x(he),children:[a.browserInstallHelp,(0,K.jsx)(u,{className:`size-3`})]})]})]}),!O||A.error||G||U?.status===`pending`||M===`create`||M===`decision`?(0,K.jsx)(`footer`,{className:`shrink-0 px-8 pb-6`,children:O?G?(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:t,children:b.done}):U?.status===`pending`?(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void _e(`approve`),children:b.allow}),(0,K.jsx)(C,{className:`w-full`,variant:`ghost`,disabled:P,onClick:()=>void _e(`reject`),children:b.cancel})]}):A.error?(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:()=>void A.mutate(),children:b.retry}):(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void Z(),children:b.retry}):(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:()=>{N(null),k(!0)},children:e===`mobile`?a.mobileReady:a.browserReady})}):null]})]})}export{q as n,J as t};
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{f as a}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{t as o}from"./chevron-right-BweFrslA.js";import{t as s}from"./circle-check-C23XjkUj.js";import{t as c}from"./clock-3-DnrAnuyZ.js";import{t as l}from"./download-Dk-ZjtO6.js";import{t as u}from"./external-link-DjqjBmc3.js";import{t as d}from"./x-B_N4OPjy.js";import{t as f}from"./messages-pGa2qMzG.js";import{t as p}from"./cn-JdwAhgNB.js";import{n as m}from"./locale-store-CvNO-hbt.js";import{a as h,i as g,o as _,r as v,s as y,t as b}from"./dist-BGTk37IG.js";import{n as x}from"./app-link-DRL0YnPs.js";import{i as S}from"./vendor-swr-BIWyz7Rc.js";import{t as C}from"./button-CS04eWY9.js";import{t as w}from"./skeleton-BwbyijEw.js";import{i as T,o as ee}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{t as E}from"./use-async-resource-GrnWNwMZ.js";import{t as D}from"./copy-text-row-BHDs3cBa.js";import{a as O,n as k,r as A}from"./oauth-api-CC5KkSgG.js";import{At as j,Ds as te,Eo as M,Qo as N,jt as P,kt as F}from"./index-6JNNrzCq.js";import{_ as ne,a as re,d as ie,f as ae,g as oe,h as se,i as ce,l as I,m as le,n as L,p as ue,r as R,s as z,t as B,u as de,v as fe}from"./tunnel-api-CgARwbus.js";import{t as V}from"./browser-BLJWD7WI.js";var H=e(n(),1),U=r(),W=e(V(),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=f(m(e=>e.language)),t=e.endpointToolsSettings.deviceAccess.flow,n=e.tunnelSettings,{data:r,error:i,mutate:a}=S(`tunnel-status`,L,{refreshInterval:1500}),[o,s]=(0,H.useState)(!1),[c,l]=(0,H.useState)(!1),[d,p]=(0,H.useState)(!0),[h,g]=(0,H.useState)(`idle`),[_,v]=(0,H.useState)(null),[y,b]=(0,H.useState)(``),T=(0,H.useRef)(!0);(0,H.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let ee=async()=>{if(!r)return;if(r.consentRequired&&!o){l(!0);return}let e=r.registrationSecret?.configured?null:P(),t,n=!1;v(null);try{if(r.consentRequired&&await re(),!r.registrationSecret?.configured){g(`provisioning`);let r=!1;try{await ce()}catch(e){if(!de(e))throw e;r=!0}if(r){g(`authorizing`);let r=sessionStorage.getItem(`device-pairing-oauth`),i=r?JSON.parse(r):null;t=i&&i.expiresAt>Date.now()?i.sessionId:(await O(`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(;T.current&&Date.now()<o;){let r=await A(t);if(r.authUrl&&r.authUrl!==a&&(a=r.authUrl,await j(a,e)||b(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(!T.current)return;if(!s)throw Error(`Authorization expired`);await ce()}await a()}if(!T.current)return;g(`starting`),await z(),d&&await R({autoStart:!0}),await a(),n=!0}catch(e){n=!0,T.current&&v(I(e)===`tunnel_key_limit_reached`?`key-limit`:`failed`)}finally{F(e),n&&(sessionStorage.removeItem(`device-pairing-oauth`),t&&k(t).catch(()=>{})),T.current&&(g(`idle`),b(``))}};if(!r&&!i)return(0,K.jsxs)(`div`,{className:`space-y-5`,children:[(0,K.jsx)(w,{className:`h-5 w-4/5`}),(0,K.jsx)(w,{className:`h-24 w-full`})]});let E=h===`provisioning`||h===`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:E?t.preparingHint:h===`authorizing`?t.authorizing:t.enableHint}),y&&h===`authorizing`?(0,K.jsx)(`a`,{href:y,target:`_blank`,rel:`noopener noreferrer`,className:`mt-4 inline-flex min-h-11 items-center text-sm text-accent`,children:t.openAuthorization}):null,E?(0,K.jsxs)(`div`,{className:`mt-8 space-y-3`,"aria-label":t.preparing,children:[(0,K.jsx)(w,{className:`h-2 w-full`}),(0,K.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.preparing})]}):null,(c||r?.consentRequired)&&h===`idle`?(0,K.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,K.jsxs)(`details`,{open:c,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,_===`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)(C,{variant:`secondary`,className:`mt-3`,onClick:()=>void x(B),children:[t.manageTunnelKeys,(0,K.jsx)(u,{className:`size-3`})]})]}):_||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:d,disabled:h!==`idle`,onChange:e=>p(e.target.checked),className:`size-4 accent-accent`}),t.autoStart]}),(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:!r||h!==`idle`||E||c&&!o,onClick:()=>void ee(),children:h===`authorizing`?t.authorizing:E?t.preparing:_?t.retry:t.enable}),i&&!r?(0,K.jsx)(C,{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)(b,{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,s;t[0]===n?s=t[1]:(s=(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]=s);let c;t[2]===r?c=t[3]:(c=(0,K.jsx)(`span`,{className:`block text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=c);let l;t[4]===i?l=t[5]:(l=(0,K.jsx)(`span`,{className:`mt-0.5 block text-xs leading-5 text-fg-muted`,children:i}),t[4]=i,t[5]=l);let u;t[6]!==c||t[7]!==l?(u=(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[c,l]}),t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,K.jsx)(o,{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]=d):d=t[9];let f;return t[10]!==a||t[11]!==s||t[12]!==u?(f=(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:[s,u,d]}),t[10]=a,t[11]=s,t[12]=u,t[13]=f):f=t[13],f}function X(e){let t=(0,U.c)(40),{onChoose:n,onChooseLocalBrowser:r,onClose:i}=e,a=m(he),o;t[0]===a?o=t[1]:(o=f(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)(h,{className:p(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),t[2]=c):c=t[2];let l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=p(`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`,T),t[3]=l):l=t[3];let u;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,K.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),t[4]=u):u=t[4];let b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,K.jsx)(d,{className:`size-4`}),t[5]=b):b=t[5];let x;t[6]!==s.cancel||t[7]!==i?(x=(0,K.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[u,(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:b})]}),t[6]=s.cancel,t[7]=i,t[8]=x):x=t[8];let S;t[9]===s.chooseTitle?S=t[10]:(S=(0,K.jsx)(y,{className:`text-lg font-semibold tracking-tight text-fg sm:text-xl`,children:s.chooseTitle}),t[9]=s.chooseTitle,t[10]=S);let C;t[11]===s.chooseHint?C=t[12]:(C=(0,K.jsx)(g,{className:`mt-1.5 text-sm leading-6 text-fg-muted`,children:s.chooseHint}),t[11]=s.chooseHint,t[12]=C);let w;t[13]!==s.localBrowserHint||t[14]!==s.localBrowserTitle||t[15]!==r?(w=(0,K.jsx)(Y,{icon:te,title:s.localBrowserTitle,hint:s.localBrowserHint,onClick:r}),t[13]=s.localBrowserHint,t[14]=s.localBrowserTitle,t[15]=r,t[16]=w):w=t[16];let E;t[17]===n?E=t[18]:(E=()=>n(`mobile`),t[17]=n,t[18]=E);let D;t[19]!==s.mobileHint||t[20]!==s.mobileTitle||t[21]!==E?(D=(0,K.jsx)(Y,{icon:M,title:s.mobileTitle,hint:s.mobileHint,onClick:E}),t[19]=s.mobileHint,t[20]=s.mobileTitle,t[21]=E,t[22]=D):D=t[22];let O;t[23]===n?O=t[24]:(O=()=>n(`browser`),t[23]=n,t[24]=O);let k;t[25]!==s.remoteBrowserHint||t[26]!==s.remoteBrowserTitle||t[27]!==O?(k=(0,K.jsx)(Y,{icon:N,title:s.remoteBrowserTitle,hint:s.remoteBrowserHint,onClick:O}),t[25]=s.remoteBrowserHint,t[26]=s.remoteBrowserTitle,t[27]=O,t[28]=k):k=t[28];let A;t[29]!==D||t[30]!==k||t[31]!==w?(A=(0,K.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[w,D,k]}),t[29]=D,t[30]=k,t[31]=w,t[32]=A):A=t[32];let j;t[33]!==A||t[34]!==S||t[35]!==C?(j=(0,K.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-6 sm:px-8`,children:[S,C,A]}),t[33]=A,t[34]=S,t[35]=C,t[36]=j):j=t[36];let P;return t[37]!==j||t[38]!==x?(P=(0,K.jsxs)(_,{children:[c,(0,K.jsxs)(v,{className:l,children:[x,j]})]}),t[37]=j,t[38]=x,t[39]=P):P=t[39],P}function he(e){return e.language}function ge({targetKind:e,onClose:t,onPaired:n}){let r=m(e=>e.language),i=f(r),a=i.endpointToolsSettings.deviceAccess,b=a.flow,[O,k]=(0,H.useState)(!1),A=S(O?`device-pairing-readiness`:null,se,{refreshInterval:1500}),[j,te]=(0,H.useState)(),[M,N]=(0,H.useState)(null),[P,F]=(0,H.useState)(!1),[re,ce]=(0,H.useState)(Date.now()),[I,L]=(0,H.useState)(null),R=(0,H.useRef)(!0),z=(0,H.useRef)(null),B=(0,H.useRef)(!1),de=(0,H.useRef)(!1),V=S(j?[`device-pairing-setup`,j.id]:null,()=>oe(j.id),{refreshInterval:1500}),U=V.data?.request,W=U?.status===`completed`,G=W&&U.connectedAt!==void 0,q=S(G&&window.electronAPI?.system?`system-behavior`:null,()=>window.electronAPI.system.getBehavior()),J=j?.targetKind===`mobile`?j.universalLink:``,Y=E(()=>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=E(()=>pe(X),[X],{enabled:!O&&e===`mobile`,initial:null,errorData:null});(0,H.useEffect)(()=>{R.current=!0;let e=setInterval(()=>ce(Date.now()),1e3);return()=>{R.current=!1,clearInterval(e),z.current&&ie(z.current).catch(()=>{})}},[]);let Z=(0,H.useCallback)(async()=>{if(!B.current){B.current=!0,F(!0),N(null);try{z.current&&await ie(z.current),z.current=null,te(void 0);let t=await ae(e);if(t.kind===`ready`){if(!R.current){await ie(t.setup.id);return}z.current=t.setup.id,te(t.setup)}else await A.mutate()}catch{R.current&&N(`create`)}finally{B.current=!1,R.current&&F(!1)}}},[A,e]);(0,H.useEffect)(()=>{A.data?.ready&&!j&&M!==`create`&&!B.current&&Z()},[A.data,j,M,Z]),(0,H.useEffect)(()=>{G&&!de.current&&(de.current=!0,n?.())},[G,n]);let _e=async e=>{if(U){F(!0),N(null);try{await ue(U,e),await V.mutate()}catch{N(`decision`),await V.mutate()}finally{R.current&&F(!1)}}},ve=(0,H.useRef)(0);(0,H.useEffect)(()=>{V.data&&(ve.current=V.data.serverTime-Date.now())},[V.data]);let Q=re+ve.current,ye=j&&Q>=j.expiresAt&&!U,be=U&&[`expired`,`rejected`,`cancelled`].includes(U.status),xe=j?j.expiresAt-Q<6e4:!1,Se=j?xe?`${Math.max(0,Math.ceil((j.expiresAt-Q)/1e3))}s`:b.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=O?G?$.success:U?.status===`pending`?$.allowTitle:W||U?.status===`approved`?b.waiting:j?$.connect:b.title:Ce,Ee=M===`create`?b.createFailed:M===`decision`?b.decisionFailed:M===`background`?b.backgroundFailed:M===`download`?a.browserDownloadFailed:null,De=async()=>{F(!0),N(null);try{await le()}catch{N(`download`)}finally{R.current&&F(!1)}};return(0,K.jsxs)(_,{children:[(0,K.jsx)(h,{className:p(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,ee)}),(0,K.jsxs)(v,{className:p(`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`,T),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":b.cancel,onClick:t,children:(0,K.jsx)(d,{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)(s,{className:`mb-5 size-7 text-success`}):null,(0,K.jsx)(y,{className:`text-xl font-semibold tracking-tight text-fg`,children:Te}),(0,K.jsx)(g,{className:`mt-2 text-sm leading-relaxed text-fg-muted`,children:O?G?$.successHint:W?b.waitingForDevice:U?U.displayName:j?$.connectHint:b.intro:we}),Ee?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:Ee}):null,O&&A.error?(0,K.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:b.readinessFailed}):null,O&&V.error?(0,K.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-warning`,children:b.statusUnavailable}):null,O?A.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(()=>N(`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`?b.expired:b.declined}),(0,K.jsx)(C,{variant:`primary`,onClick:()=>void Z(),disabled:P,children:b.refresh})]}):U?(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:b.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:b.compare}),(0,K.jsxs)(`details`,{className:`mt-6 text-xs text-fg-muted`,children:[(0,K.jsx)(`summary`,{className:`cursor-pointer py-2`,children:b.access}),(0,K.jsx)(`p`,{children:b.accessHint})]})]}):j?.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)(w,{className:`size-[240px] rounded-xl`})})}),Y.error?null:(0,K.jsxs)(`p`,{className:p(`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)(c,{className:`size-3.5`,"aria-hidden":`true`}),Se]})]}),Y.error?(0,K.jsx)(`p`,{role:`status`,className:`text-center text-sm text-warning`,children:b.qrFailed}):null,Y.error?(0,K.jsx)(`div`,{className:`mt-5`,children:(0,K.jsx)(D,{text:j.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:b.fallback}),(0,K.jsx)(o,{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)(D,{text:j.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})})]})]}):j?(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)(D,{text:j.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:j.expiresAt-Q<6e4?`${Math.max(0,Math.ceil((j.expiresAt-Q)/1e3))}s`:b.valid})]}):A.data.ready?(0,K.jsx)(`div`,{className:`mt-8`,children:(0,K.jsx)(w,{className:`mx-auto size-[216px]`})}):(0,K.jsxs)(`div`,{className:`mt-6 flex flex-1 flex-col`,children:[I===`tailscale`?(0,K.jsx)(fe,{embedded:!0}):I===`https`?(0,K.jsx)(ne,{}):I===`choices`?(0,K.jsxs)(`div`,{className:`space-y-3`,children:[(0,K.jsx)(C,{variant:`secondary`,className:`w-full`,onClick:()=>L(`tailscale`),children:a.useTailscale}),(0,K.jsx)(C,{variant:`secondary`,className:`w-full`,onClick:()=>L(`https`),children:a.useOwnHttps})]}):(0,K.jsx)(me,{}),(0,K.jsx)(C,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>L(I?null:`choices`),children:I?b.back:b.existing})]}):(0,K.jsxs)(`div`,{className:`mt-8 space-y-4`,children:[(0,K.jsx)(w,{className:`h-5 w-3/4`}),(0,K.jsx)(w,{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)(w,{className:`size-36`}),(0,K.jsxs)(C,{variant:`secondary`,className:`mt-5 w-full`,onClick:()=>void x(X),children:[(0,K.jsx)(u,{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)(C,{variant:`secondary`,className:`w-full`,disabled:P,onClick:()=>void De(),children:[(0,K.jsx)(l,{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 x(he),children:[a.browserInstallHelp,(0,K.jsx)(u,{className:`size-3`})]})]})]}),!O||A.error||G||U?.status===`pending`||M===`create`||M===`decision`?(0,K.jsx)(`footer`,{className:`shrink-0 px-8 pb-6`,children:O?G?(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:t,children:b.done}):U?.status===`pending`?(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void _e(`approve`),children:b.allow}),(0,K.jsx)(C,{className:`w-full`,variant:`ghost`,disabled:P,onClick:()=>void _e(`reject`),children:b.cancel})]}):A.error?(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:()=>void A.mutate(),children:b.retry}):(0,K.jsx)(C,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void Z(),children:b.retry}):(0,K.jsx)(C,{className:`w-full`,variant:`primary`,onClick:()=>{N(null),k(!0)},children:e===`mobile`?a.mobileReady:a.browserReady})}):null]})]})}export{q as n,J as t};
@@ -1 +1 @@
1
- import{n as e,t}from"./vendor-react-BOUWij0V.js";import{t as n}from"./cn-JdwAhgNB.js";import{n as r}from"./interaction-BdhHBbYa.js";import{Ks as i,ai as a,oi as o,si as s}from"./index-BYNmHn-z.js";var c=e(),l=t();function u(e){let t=(0,c.c)(27),{value:a,onPick:o,disabled:u,placeholder:d,title:f,className:p,maxWidthClass:m,compact:h,"aria-label":g}=e,_=m===void 0?`max-w-[min(12rem,40vw)]`:m,v=h===void 0?!1:h,y,b;t[0]!==d||t[1]!==a?(b=a.trim(),y=b?s(b):d??``,t[0]=d,t[1]=a,t[2]=y,t[3]=b):(y=t[2],b=t[3]);let x=y,S=f??(b||void 0),C=g??f??x,w=v?`inline-flex size-9 shrink-0 items-center justify-center rounded-lg p-0`:`inline-flex min-h-8 min-w-0 shrink-0 items-center gap-1 rounded-lg px-2 py-1 text-xs`,T=!v&&_,E=u&&`cursor-not-allowed opacity-60`,D;t[4]!==p||t[5]!==w||t[6]!==T||t[7]!==E?(D=n(w,`border border-edge-subtle/80 bg-surface-hover/40 dark:border-edge-subtle`,r.transition,r.focusRingPanel,`cursor-pointer hover:bg-surface-hover/70 dark:hover:bg-surface-hover/50`,T,E,p),t[4]=p,t[5]=w,t[6]=T,t[7]=E,t[8]=D):D=t[8];let O;t[9]!==u||t[10]!==o?(O=e=>{e.stopPropagation(),u||o()},t[9]=u,t[10]=o,t[11]=O):O=t[11];let k=v?`size-4`:`size-3.5`,A;t[12]===k?A=t[13]:(A=n(`shrink-0 text-fg-muted`,k),t[12]=k,t[13]=A);let j;t[14]===A?j=t[15]:(j=(0,l.jsx)(i,{className:A,"aria-hidden":!0}),t[14]=A,t[15]=j);let M;t[16]!==v||t[17]!==x?(M=v?null:(0,l.jsx)(`span`,{className:`min-w-0 truncate text-left font-medium text-fg`,children:x}),t[16]=v,t[17]=x,t[18]=M):M=t[18];let N;return t[19]!==u||t[20]!==O||t[21]!==j||t[22]!==M||t[23]!==S||t[24]!==C||t[25]!==D?(N=(0,l.jsxs)(`button`,{type:`button`,disabled:u,title:S,"aria-label":C,className:D,onClick:O,children:[j,M]}),t[19]=u,t[20]=O,t[21]=j,t[22]=M,t[23]=S,t[24]=C,t[25]=D,t[26]=N):N=t[26],N}function d(e){let t=(0,c.c)(39),{value:r,onChange:i,disabled:s,wd:d,placeholder:f,inputAriaLabel:p,inputClassName:m,autoFocus:h,trailing:g}=e,_;t[0]!==i||t[1]!==r?(_={initialPath:r,onPicked:i},t[0]=i,t[1]=r,t[2]=_):_=t[2];let v=o(_),y;t[3]===r?y=t[4]:(y=r.trim(),t[3]=r,t[4]=y);let b=y,x=b?`${b}\n${d.chooseFolder}`:`${f??d.notSet}\n${d.selectWorkingDirectory}`,S;t[5]===m?S=t[6]:(S=n(`min-w-0 flex-1`,m),t[5]=m,t[6]=S);let C=s||v.picking,w;t[7]===i?w=t[8]:(w=e=>void i(e.target.value),t[7]=i,t[8]=w);let T=f??d.pathInputPlaceholder,E;t[9]!==h||t[10]!==p||t[11]!==S||t[12]!==C||t[13]!==w||t[14]!==T||t[15]!==r?(E=(0,l.jsx)(`input`,{type:`text`,className:S,value:r,disabled:C,onChange:w,placeholder:T,"aria-label":p,autoFocus:h,autoComplete:`off`,spellCheck:!1}),t[9]=h,t[10]=p,t[11]=S,t[12]=C,t[13]=w,t[14]=T,t[15]=r,t[16]=E):E=t[16];let D=s||v.picking,O;t[17]!==x||t[18]!==v.pick||t[19]!==D||t[20]!==r||t[21]!==d.selectWorkingDirectory?(O=(0,l.jsx)(u,{compact:!0,value:r,onPick:v.pick,disabled:D,title:x,"aria-label":d.selectWorkingDirectory}),t[17]=x,t[18]=v.pick,t[19]=D,t[20]=r,t[21]=d.selectWorkingDirectory,t[22]=O):O=t[22];let k;t[23]!==O||t[24]!==g?(k=(0,l.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[O,g]}),t[23]=O,t[24]=g,t[25]=k):k=t[25];let A;t[26]!==k||t[27]!==E?(A=(0,l.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[E,k]}),t[26]=k,t[27]=E,t[28]=A):A=t[28];let j;t[29]!==v.confirmPick||t[30]!==v.hasNativePicker||t[31]!==v.modalOpen||t[32]!==v.setModalOpen||t[33]!==b||t[34]!==d?(j=v.hasNativePicker?null:(0,l.jsx)(a,{open:v.modalOpen,onOpenChange:v.setModalOpen,initialAbsolutePath:b||void 0,onConfirm:v.confirmPick,wd:d}),t[29]=v.confirmPick,t[30]=v.hasNativePicker,t[31]=v.modalOpen,t[32]=v.setModalOpen,t[33]=b,t[34]=d,t[35]=j):j=t[35];let M;return t[36]!==A||t[37]!==j?(M=(0,l.jsxs)(l.Fragment,{children:[A,j]}),t[36]=A,t[37]=j,t[38]=M):M=t[38],M}export{d as t};
1
+ import{n as e,t}from"./vendor-react-BOUWij0V.js";import{t as n}from"./cn-JdwAhgNB.js";import{n as r}from"./interaction-BdhHBbYa.js";import{Ks as i,ai as a,oi as o,si as s}from"./index-6JNNrzCq.js";var c=e(),l=t();function u(e){let t=(0,c.c)(27),{value:a,onPick:o,disabled:u,placeholder:d,title:f,className:p,maxWidthClass:m,compact:h,"aria-label":g}=e,_=m===void 0?`max-w-[min(12rem,40vw)]`:m,v=h===void 0?!1:h,y,b;t[0]!==d||t[1]!==a?(b=a.trim(),y=b?s(b):d??``,t[0]=d,t[1]=a,t[2]=y,t[3]=b):(y=t[2],b=t[3]);let x=y,S=f??(b||void 0),C=g??f??x,w=v?`inline-flex size-9 shrink-0 items-center justify-center rounded-lg p-0`:`inline-flex min-h-8 min-w-0 shrink-0 items-center gap-1 rounded-lg px-2 py-1 text-xs`,T=!v&&_,E=u&&`cursor-not-allowed opacity-60`,D;t[4]!==p||t[5]!==w||t[6]!==T||t[7]!==E?(D=n(w,`border border-edge-subtle/80 bg-surface-hover/40 dark:border-edge-subtle`,r.transition,r.focusRingPanel,`cursor-pointer hover:bg-surface-hover/70 dark:hover:bg-surface-hover/50`,T,E,p),t[4]=p,t[5]=w,t[6]=T,t[7]=E,t[8]=D):D=t[8];let O;t[9]!==u||t[10]!==o?(O=e=>{e.stopPropagation(),u||o()},t[9]=u,t[10]=o,t[11]=O):O=t[11];let k=v?`size-4`:`size-3.5`,A;t[12]===k?A=t[13]:(A=n(`shrink-0 text-fg-muted`,k),t[12]=k,t[13]=A);let j;t[14]===A?j=t[15]:(j=(0,l.jsx)(i,{className:A,"aria-hidden":!0}),t[14]=A,t[15]=j);let M;t[16]!==v||t[17]!==x?(M=v?null:(0,l.jsx)(`span`,{className:`min-w-0 truncate text-left font-medium text-fg`,children:x}),t[16]=v,t[17]=x,t[18]=M):M=t[18];let N;return t[19]!==u||t[20]!==O||t[21]!==j||t[22]!==M||t[23]!==S||t[24]!==C||t[25]!==D?(N=(0,l.jsxs)(`button`,{type:`button`,disabled:u,title:S,"aria-label":C,className:D,onClick:O,children:[j,M]}),t[19]=u,t[20]=O,t[21]=j,t[22]=M,t[23]=S,t[24]=C,t[25]=D,t[26]=N):N=t[26],N}function d(e){let t=(0,c.c)(39),{value:r,onChange:i,disabled:s,wd:d,placeholder:f,inputAriaLabel:p,inputClassName:m,autoFocus:h,trailing:g}=e,_;t[0]!==i||t[1]!==r?(_={initialPath:r,onPicked:i},t[0]=i,t[1]=r,t[2]=_):_=t[2];let v=o(_),y;t[3]===r?y=t[4]:(y=r.trim(),t[3]=r,t[4]=y);let b=y,x=b?`${b}\n${d.chooseFolder}`:`${f??d.notSet}\n${d.selectWorkingDirectory}`,S;t[5]===m?S=t[6]:(S=n(`min-w-0 flex-1`,m),t[5]=m,t[6]=S);let C=s||v.picking,w;t[7]===i?w=t[8]:(w=e=>void i(e.target.value),t[7]=i,t[8]=w);let T=f??d.pathInputPlaceholder,E;t[9]!==h||t[10]!==p||t[11]!==S||t[12]!==C||t[13]!==w||t[14]!==T||t[15]!==r?(E=(0,l.jsx)(`input`,{type:`text`,className:S,value:r,disabled:C,onChange:w,placeholder:T,"aria-label":p,autoFocus:h,autoComplete:`off`,spellCheck:!1}),t[9]=h,t[10]=p,t[11]=S,t[12]=C,t[13]=w,t[14]=T,t[15]=r,t[16]=E):E=t[16];let D=s||v.picking,O;t[17]!==x||t[18]!==v.pick||t[19]!==D||t[20]!==r||t[21]!==d.selectWorkingDirectory?(O=(0,l.jsx)(u,{compact:!0,value:r,onPick:v.pick,disabled:D,title:x,"aria-label":d.selectWorkingDirectory}),t[17]=x,t[18]=v.pick,t[19]=D,t[20]=r,t[21]=d.selectWorkingDirectory,t[22]=O):O=t[22];let k;t[23]!==O||t[24]!==g?(k=(0,l.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[O,g]}),t[23]=O,t[24]=g,t[25]=k):k=t[25];let A;t[26]!==k||t[27]!==E?(A=(0,l.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[E,k]}),t[26]=k,t[27]=E,t[28]=A):A=t[28];let j;t[29]!==v.confirmPick||t[30]!==v.hasNativePicker||t[31]!==v.modalOpen||t[32]!==v.setModalOpen||t[33]!==b||t[34]!==d?(j=v.hasNativePicker?null:(0,l.jsx)(a,{open:v.modalOpen,onOpenChange:v.setModalOpen,initialAbsolutePath:b||void 0,onConfirm:v.confirmPick,wd:d}),t[29]=v.confirmPick,t[30]=v.hasNativePicker,t[31]=v.modalOpen,t[32]=v.setModalOpen,t[33]=b,t[34]=d,t[35]=j):j=t[35];let M;return t[36]!==A||t[37]!==j?(M=(0,l.jsxs)(l.Fragment,{children:[A,j]}),t[36]=A,t[37]=j,t[38]=M):M=t[38],M}export{d as t};
@@ -1 +1 @@
1
- import"./rolldown-runtime-aKtaBQYM.js";import{a as e,n as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./messages-BHvpZNe9.js";import{n as i}from"./locale-store-DId6-v2R.js";import{r as a}from"./extension-provider-F9JzOWZ3.js";import{n as o,r as s}from"./settings-page-layout-X1x-2Cp9.js";var c=t();e();var l=n();function u(){let e=(0,c.c)(40),t=i(p),n;e[0]===t?n=e[1]:(n=r(t),e[0]=t,e[1]=n);let u=n.extensionDebug,m=a(),h;e[2]===m?h=e[3]:(h=m.toSorted(f),e[2]=m,e[3]=h);let g=h,_;e[4]!==u.subtitle||e[5]!==u.title?(_=(0,l.jsx)(o,{title:u.title,subtitle:u.subtitle}),e[4]=u.subtitle,e[5]=u.title,e[6]=_):_=e[6];let v;e[7]===u.listHeading?v=e[8]:(v=(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:u.listHeading}),e[7]=u.listHeading,e[8]=v);let y;e[9]===u.colId?y=e[10]:(y=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colId}),e[9]=u.colId,e[10]=y);let b;e[11]===u.colName?b=e[12]:(b=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colName}),e[11]=u.colName,e[12]=b);let x;e[13]===u.colPermissions?x=e[14]:(x=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colPermissions}),e[13]=u.colPermissions,e[14]=x);let S;e[15]!==y||e[16]!==b||e[17]!==x?(S=(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{className:`text-xs uppercase text-fg-muted`,children:[y,b,x]})}),e[15]=y,e[16]=b,e[17]=x,e[18]=S):S=e[18];let C;e[19]===g?C=e[20]:(C=g.map(d),e[19]=g,e[20]=C);let w;e[21]===C?w=e[22]:(w=(0,l.jsx)(`tbody`,{children:C}),e[21]=C,e[22]=w);let T;e[23]!==S||e[24]!==w?(T=(0,l.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,l.jsxs)(`table`,{className:`w-full min-w-[32rem] border-separate border-spacing-y-1 text-left text-sm`,children:[S,w]})}),e[23]=S,e[24]=w,e[25]=T):T=e[25];let E;e[26]!==T||e[27]!==v?(E=(0,l.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,children:[v,T]}),e[26]=T,e[27]=v,e[28]=E):E=e[28];let D;e[29]===u.futureHeading?D=e[30]:(D=(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:u.futureHeading}),e[29]=u.futureHeading,e[30]=D);let O;e[31]===u.futureBody?O=e[32]:(O=(0,l.jsx)(`p`,{className:`mt-2`,children:u.futureBody}),e[31]=u.futureBody,e[32]=O);let k;e[33]!==D||e[34]!==O?(k=(0,l.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4 text-sm text-fg-muted`,children:[D,O]}),e[33]=D,e[34]=O,e[35]=k):k=e[35];let A;return e[36]!==E||e[37]!==k||e[38]!==_?(A=(0,l.jsxs)(s,{gap:`gap-5`,children:[_,E,k]}),e[36]=E,e[37]=k,e[38]=_,e[39]=A):A=e[39],A}function d(e){return(0,l.jsxs)(`tr`,{className:`bg-surface-base/55`,children:[(0,l.jsx)(`td`,{className:`rounded-l-lg px-3 py-2 font-mono text-xs text-fg`,children:e.id}),(0,l.jsx)(`td`,{className:`px-3 py-2 text-fg`,children:e.name}),(0,l.jsx)(`td`,{className:`rounded-r-lg px-3 py-2 font-mono text-xs text-fg-muted`,children:(e.ui?.permissions??[]).join(`, `)||`—`})]},e.id)}function f(e,t){return e.id.localeCompare(t.id)}function p(e){return e.language}export{u as ExtensionDebugPage};
1
+ import"./rolldown-runtime-aKtaBQYM.js";import{a as e,n as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./messages-pGa2qMzG.js";import{n as i}from"./locale-store-CvNO-hbt.js";import{r as a}from"./extension-provider-DaLt3bC-.js";import{n as o,r as s}from"./settings-page-layout-X1x-2Cp9.js";var c=t();e();var l=n();function u(){let e=(0,c.c)(40),t=i(p),n;e[0]===t?n=e[1]:(n=r(t),e[0]=t,e[1]=n);let u=n.extensionDebug,m=a(),h;e[2]===m?h=e[3]:(h=m.toSorted(f),e[2]=m,e[3]=h);let g=h,_;e[4]!==u.subtitle||e[5]!==u.title?(_=(0,l.jsx)(o,{title:u.title,subtitle:u.subtitle}),e[4]=u.subtitle,e[5]=u.title,e[6]=_):_=e[6];let v;e[7]===u.listHeading?v=e[8]:(v=(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:u.listHeading}),e[7]=u.listHeading,e[8]=v);let y;e[9]===u.colId?y=e[10]:(y=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colId}),e[9]=u.colId,e[10]=y);let b;e[11]===u.colName?b=e[12]:(b=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colName}),e[11]=u.colName,e[12]=b);let x;e[13]===u.colPermissions?x=e[14]:(x=(0,l.jsx)(`th`,{className:`px-3 py-2`,children:u.colPermissions}),e[13]=u.colPermissions,e[14]=x);let S;e[15]!==y||e[16]!==b||e[17]!==x?(S=(0,l.jsx)(`thead`,{children:(0,l.jsxs)(`tr`,{className:`text-xs uppercase text-fg-muted`,children:[y,b,x]})}),e[15]=y,e[16]=b,e[17]=x,e[18]=S):S=e[18];let C;e[19]===g?C=e[20]:(C=g.map(d),e[19]=g,e[20]=C);let w;e[21]===C?w=e[22]:(w=(0,l.jsx)(`tbody`,{children:C}),e[21]=C,e[22]=w);let T;e[23]!==S||e[24]!==w?(T=(0,l.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,l.jsxs)(`table`,{className:`w-full min-w-[32rem] border-separate border-spacing-y-1 text-left text-sm`,children:[S,w]})}),e[23]=S,e[24]=w,e[25]=T):T=e[25];let E;e[26]!==T||e[27]!==v?(E=(0,l.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4`,children:[v,T]}),e[26]=T,e[27]=v,e[28]=E):E=e[28];let D;e[29]===u.futureHeading?D=e[30]:(D=(0,l.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:u.futureHeading}),e[29]=u.futureHeading,e[30]=D);let O;e[31]===u.futureBody?O=e[32]:(O=(0,l.jsx)(`p`,{className:`mt-2`,children:u.futureBody}),e[31]=u.futureBody,e[32]=O);let k;e[33]!==D||e[34]!==O?(k=(0,l.jsxs)(`section`,{className:`rounded-xl bg-surface-hover/20 p-4 text-sm text-fg-muted`,children:[D,O]}),e[33]=D,e[34]=O,e[35]=k):k=e[35];let A;return e[36]!==E||e[37]!==k||e[38]!==_?(A=(0,l.jsxs)(s,{gap:`gap-5`,children:[_,E,k]}),e[36]=E,e[37]=k,e[38]=_,e[39]=A):A=e[39],A}function d(e){return(0,l.jsxs)(`tr`,{className:`bg-surface-base/55`,children:[(0,l.jsx)(`td`,{className:`rounded-l-lg px-3 py-2 font-mono text-xs text-fg`,children:e.id}),(0,l.jsx)(`td`,{className:`px-3 py-2 text-fg`,children:e.name}),(0,l.jsx)(`td`,{className:`rounded-r-lg px-3 py-2 font-mono text-xs text-fg-muted`,children:(e.ui?.permissions??[]).join(`, `)||`—`})]},e.id)}function f(e,t){return e.id.localeCompare(t.id)}function p(e){return e.language}export{u as ExtensionDebugPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{m as i}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{r as a,s as o}from"./extension-provider-F9JzOWZ3.js";import{Nr as s,Yi as c}from"./index-BYNmHn-z.js";var l=n(),u=e(t(),1),d=r();function f(){let e=(0,l.c)(26),{extensionId:t,pageId:n}=i(),r=a(),f=c(m),g=c(p),_,v,y;e[0]!==t||e[1]!==r||e[2]!==n?(_=t?r.find(e=>e.id===t&&o(e)):void 0,v=_?.ui?.contributions?.pages,y=t&&v?.length?n?v.find(e=>e.id===n||e.id===`${t}.${n}`):v[0]:void 0,e[0]=t,e[1]=r,e[2]=n,e[3]=_,e[4]=v,e[5]=y):(_=e[3],v=e[4],y=e[5]);let b=y,x,S;if(e[6]!==g||e[7]!==_||e[8]!==t||e[9]!==b||e[10]!==f?(x=()=>{if(!t||!_||!b)return g(),()=>g();let e=b.title?.trim()||_.name||t;return f({startExtra:null,main:(0,d.jsx)(`div`,{className:`w-full min-w-0 px-3 sm:px-5 xl:px-6`,children:(0,d.jsx)(`h1`,{className:`min-w-0 truncate text-base font-semibold tracking-tight text-fg`,title:e,children:e})}),end:null}),()=>g()},S=[g,_,t,b,f],e[6]=g,e[7]=_,e[8]=t,e[9]=b,e[10]=f,e[11]=x,e[12]=S):(x=e[11],S=e[12]),(0,u.useLayoutEffect)(x,S),!t){let t;return e[13]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,d.jsx)(h,{message:`No extension ID provided.`}),e[13]=t):t=e[13],t}if(!_){let n=`Extension "${t}" not found or has no UI.`,r;return e[14]===n?r=e[15]:(r=(0,d.jsx)(h,{message:n}),e[14]=n,e[15]=r),r}if(!v?.length){let n=`Extension "${t}" has no page contributions.`,r;return e[16]===n?r=e[17]:(r=(0,d.jsx)(h,{message:n}),e[16]=n,e[17]=r),r}if(!b){let r=`Page "${n}" not found in extension "${t}".`,i;return e[18]===r?i=e[19]:(i=(0,d.jsx)(h,{message:r}),e[18]=r,e[19]=i),i}let C=_.ui?.permissions,w;return e[20]!==_.name||e[21]!==t||e[22]!==b.entrypoint||e[23]!==b.title||e[24]!==C?(w=(0,d.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,d.jsx)(s,{extensionId:t,extensionName:_.name,entrypoint:b.entrypoint,permissions:C,title:b.title,className:`min-h-0 flex-1`,fixedHeight:void 0,maxHeight:99999})}),e[20]=_.name,e[21]=t,e[22]=b.entrypoint,e[23]=b.title,e[24]=C,e[25]=w):w=e[25],w}function p(e){return e.clearPageHeader}function m(e){return e.setPageHeader}function h(e){let t=(0,l.c)(2),{message:n}=e,r;return t[0]===n?r=t[1]:(r=(0,d.jsx)(`div`,{className:`flex min-h-[min(40vh,16rem)] flex-1 items-center justify-center`,children:(0,d.jsx)(`div`,{className:`text-center`,children:(0,d.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n})})}),t[0]=n,t[1]=r),r}export{f as ExtensionPage};
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}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{r as a,s as o}from"./extension-provider-DaLt3bC-.js";import{Nr as s,Yi as c}from"./index-6JNNrzCq.js";var l=n(),u=e(t(),1),d=r();function f(){let e=(0,l.c)(26),{extensionId:t,pageId:n}=i(),r=a(),f=c(m),g=c(p),_,v,y;e[0]!==t||e[1]!==r||e[2]!==n?(_=t?r.find(e=>e.id===t&&o(e)):void 0,v=_?.ui?.contributions?.pages,y=t&&v?.length?n?v.find(e=>e.id===n||e.id===`${t}.${n}`):v[0]:void 0,e[0]=t,e[1]=r,e[2]=n,e[3]=_,e[4]=v,e[5]=y):(_=e[3],v=e[4],y=e[5]);let b=y,x,S;if(e[6]!==g||e[7]!==_||e[8]!==t||e[9]!==b||e[10]!==f?(x=()=>{if(!t||!_||!b)return g(),()=>g();let e=b.title?.trim()||_.name||t;return f({startExtra:null,main:(0,d.jsx)(`div`,{className:`w-full min-w-0 px-3 sm:px-5 xl:px-6`,children:(0,d.jsx)(`h1`,{className:`min-w-0 truncate text-base font-semibold tracking-tight text-fg`,title:e,children:e})}),end:null}),()=>g()},S=[g,_,t,b,f],e[6]=g,e[7]=_,e[8]=t,e[9]=b,e[10]=f,e[11]=x,e[12]=S):(x=e[11],S=e[12]),(0,u.useLayoutEffect)(x,S),!t){let t;return e[13]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,d.jsx)(h,{message:`No extension ID provided.`}),e[13]=t):t=e[13],t}if(!_){let n=`Extension "${t}" not found or has no UI.`,r;return e[14]===n?r=e[15]:(r=(0,d.jsx)(h,{message:n}),e[14]=n,e[15]=r),r}if(!v?.length){let n=`Extension "${t}" has no page contributions.`,r;return e[16]===n?r=e[17]:(r=(0,d.jsx)(h,{message:n}),e[16]=n,e[17]=r),r}if(!b){let r=`Page "${n}" not found in extension "${t}".`,i;return e[18]===r?i=e[19]:(i=(0,d.jsx)(h,{message:r}),e[18]=r,e[19]=i),i}let C=_.ui?.permissions,w;return e[20]!==_.name||e[21]!==t||e[22]!==b.entrypoint||e[23]!==b.title||e[24]!==C?(w=(0,d.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:(0,d.jsx)(s,{extensionId:t,extensionName:_.name,entrypoint:b.entrypoint,permissions:C,title:b.title,className:`min-h-0 flex-1`,fixedHeight:void 0,maxHeight:99999})}),e[20]=_.name,e[21]=t,e[22]=b.entrypoint,e[23]=b.title,e[24]=C,e[25]=w):w=e[25],w}function p(e){return e.clearPageHeader}function m(e){return e.setPageHeader}function h(e){let t=(0,l.c)(2),{message:n}=e,r;return t[0]===n?r=t[1]:(r=(0,d.jsx)(`div`,{className:`flex min-h-[min(40vh,16rem)] flex-1 items-center justify-center`,children:(0,d.jsx)(`div`,{className:`text-center`,children:(0,d.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n})})}),t[0]=n,t[1]=r),r}export{f as ExtensionPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{a as i,c as a,i as o,r as s}from"./locale-store-DId6-v2R.js";import{f as c,l,p as u,r as d,t as f}from"./schemas-CObaziC7.js";import{t as p}from"./session-manager-CMGUwtbN.js";import{t as m}from"./capabilities-CT_ZW9fT.js";import{i as h}from"./vendor-swr-BIWyz7Rc.js";import{t as g}from"./activity-store-GvR2gZ0T.js";import{a as _}from"./gateway-realtime-D0ygm6bc.js";import{i as v}from"./theme-store-OhcbFEUR.js";import{t as y}from"./send-session-input-D1oc6BC6.js";var b=c({id:f([`xopc.notes.get`,`xopc.notes.list`,`xopc.tasks.get`,`xopc.tasks.list`,`xopc.notes.create`,`xopc.notes.update`,`xopc.notes.append`]),majorVersion:l().int().positive(),descriptorDigest:u().regex(/^[a-f0-9]{64}$/)});d(b).max(7).refine(e=>new Set(e.map(e=>e.id)).size===e.length,`Duplicate capability binding`);var x=e(t(),1),S=n(),C=`agent-stream-event`;function w(e){return e===`off`||e===`on`||e===`stream`}function T(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e,n=typeof t.conversationId==`string`?t.conversationId.trim():``,r=typeof t.runId==`string`?t.runId.trim():``;return n&&r?{conversationId:n,runId:r}:null}function E(e,t,n){return t&&typeof t==`object`&&!Array.isArray(t)?{...t,seq:n}:{type:e,seq:n,payload:t}}async function D(e){try{let t=await o(s(`/api/sessions/${encodeURIComponent(e)}/agent-config`));if(!t.ok)return`on`;let n=await t.json(),r=n.payload?.activityDetail?.effective;if(w(r))return r;let i=n.payload?.activityDetail?.default??n.payload?.reasoningLevel;return w(i)?i:`on`}catch{return`on`}}function O(e){window.dispatchEvent(new CustomEvent(C,{detail:e}))}function k(e={}){let t=e.subscribe??_,n=e.loadActivityDetailLevel??D,r=e.dispatch??O,i=new Map,a=!1,o=e=>{let o=T(e.detail);if(!o||i.has(o.runId))return;let s=`on`,c=!1,l,u=!1,d=!1,f=()=>{},p=()=>{u||(u=!0,f(),i.get(o.runId)===p&&i.delete(o.runId))},m=e=>{a||u||r({conversationId:o.conversationId,event:e,activityDetailLevel:s})};n(o.conversationId).then(e=>{s=e,c=!0,e===`stream`&&l&&!d&&m(l),l=void 0}),f=t(`run:${o.runId}`,{onEvent:e=>{if(u||d)return;let t=E(e.event,e.data,e.seq);e.event===`thinking_delta`&&!c?l=t:m(t),e.event===`run_end`&&(d=!0,l=void 0,queueMicrotask(p))},onGap:e=>{e.recoverable||p()}},0),i.set(o.runId,p)},s=e=>{let t=T(e.detail);t&&i.get(t.runId)?.()};return window.addEventListener(`run-started`,o),window.addEventListener(`run-completed`,s),window.addEventListener(`agent-run-ended`,s),()=>{a=!0,window.removeEventListener(`run-started`,o),window.removeEventListener(`run-completed`,s),window.removeEventListener(`agent-run-ended`,s);for(let e of[...i.values()])e()}}var A=function(e){return e[e.PermissionDenied=4001]=`PermissionDenied`,e[e.InvalidRequest=4002]=`InvalidRequest`,e[e.MethodNotFound=4003]=`MethodNotFound`,e[e.InternalError=4004]=`InternalError`,e[e.Timeout=4005]=`Timeout`,e[e.ExtensionNotFound=4006]=`ExtensionNotFound`,e[e.RateLimited=4007]=`RateLimited`,e}({}),j=[`--color-surface-base`,`--color-surface-panel`,`--color-surface-hover`,`--color-fg`,`--color-fg-muted`,`--color-fg-subtle`,`--color-accent`,`--color-accent-hover`,`--color-accent-soft`,`--color-edge`,`--color-edge-subtle`,`--color-danger`,`--color-success`,`--color-warning`,`--radius-sm`,`--radius-lg`,`--radius-xl`];function M(e){let t=getComputedStyle(document.documentElement),n={};for(let e of j){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return{mode:e,tokens:n,fontFamily:t.getPropertyValue(`font-family`).trim(),fontFamilyMono:t.getPropertyValue(`--font-mono`).trim()}}var N={"agent.sendMessage":`agent.send`,"session.list":`session.read`,"session.navigate":`session.read`,"config.get":`config.read`,"config.set":`config.write`,"storage.get":`storage`,"storage.set":`storage`,"storage.remove":`storage`,"storage.keys":`storage`,"ui.notification":`notification`,"theme.get":`theme`},P=class{iframes=new Map;byContentWindow=new WeakMap;handlers=new Map;extensionPermissions=new Map;releaseBindings=new Map;eventSubscribers=new Map;agentStreamSubscriptions=new Map;boundListener=e=>{this.onWindowMessage(e)};constructor(){window.addEventListener(`message`,this.boundListener)}dispose(){window.removeEventListener(`message`,this.boundListener),this.iframes.clear(),this.handlers.clear(),this.extensionPermissions.clear(),this.releaseBindings.clear(),this.eventSubscribers.clear(),this.agentStreamSubscriptions.clear()}registerIframe(e,t,n,r){let i=this.iframes.get(e);if(i&&i!==t&&i.contentWindow&&this.byContentWindow.delete(i.contentWindow),this.iframes.set(e,t),this.extensionPermissions.set(e,new Set(n)),this.releaseBindings.delete(e),r){let t=a.getState();this.releaseBindings.set(e,{digest:r,baseUrl:t.baseUrl,namespace:t.conversationId})}this.rememberIframeWindow(e,t)}unregisterIframe(e){let t=this.iframes.get(e);this.sendEvent(e,`panel.dispose`),t?.contentWindow&&this.byContentWindow.delete(t.contentWindow),this.iframes.delete(e),this.extensionPermissions.delete(e),this.releaseBindings.delete(e),this.agentStreamSubscriptions.delete(e)}rememberIframeWindow(e,t){let n=t.contentWindow;n&&this.byContentWindow.set(n,{extensionId:e,iframe:t})}subscribeAgentStream(e,t){let n=this.agentStreamSubscriptions.get(e);n||(n=new Set,this.agentStreamSubscriptions.set(e,n)),n.add(t)}unsubscribeAgentStream(e,t){this.agentStreamSubscriptions.get(e)?.delete(t)}forwardAgentStreamEvent(e,t){for(let[n,r]of this.agentStreamSubscriptions)r.has(e)&&this.sendEvent(n,`agent.stream.${e}`,t)}broadcastExtensionEvent(e,t,n){let r=t.startsWith(`ext.`)?t:`ext.${t}`;for(let[t]of this.iframes)t!==e&&this.sendEvent(t,r,n)}handleExtensionEvent(e,t,n){if(t.startsWith(`ext.`)){let r=t.slice(4);this.broadcastExtensionEvent(e,r,n);return}if(t===`agent.subscribe`||t===`agent.unsubscribe`){if(!(this.extensionPermissions.get(e)??new Set).has(`agent.subscribe`))return;let{conversationId:r}=n??{};if(typeof r!=`string`||!r.trim())return;let i=r.trim();t===`agent.subscribe`?this.subscribeAgentStream(e,i):this.unsubscribeAgentStream(e,i)}}registerMethod(e,t){this.handlers.set(e,t)}getReleaseDigest(e){let t=this.releaseBindings.get(e),n=a.getState();if(!t||t.baseUrl!==n.baseUrl||t.namespace!==n.conversationId)throw Error(`Extension release authorization is unavailable`);return t.digest}subscribeExtensionEvents(e,t){let n=this.eventSubscribers.get(e);return n||(n=new Set,this.eventSubscribers.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&this.eventSubscribers.delete(e)}}sendInit(e,t,n){let r=this.iframes.get(e);if(!r?.contentWindow)return;this.rememberIframeWindow(e,r);let i=[...this.extensionPermissions.get(e)??[]];r.contentWindow.postMessage({source:`xopc-host`,type:`init`,extensionId:e,permissions:i,theme:t,locale:n},`*`)}sendEvent(e,t,n){let r=this.iframes.get(e);r?.contentWindow&&r.contentWindow.postMessage({source:`xopc-host`,type:`event`,event:t,data:n},`*`)}broadcastEvent(e,t){for(let[,n]of this.iframes)n.contentWindow?.postMessage({source:`xopc-host`,type:`event`,event:e,data:t},`*`)}postResponse(e,t,n,r,i){let a=e.contentWindow,o={source:`xopc-host`,type:`response`,requestId:n,result:r,error:i};!a||a!==t?.source||a.postMessage(o,`*`)}async onWindowMessage(e){let t=e.data;if(!t||t.source!==`xopc-extension`||!e.source)return;let n=this.byContentWindow.get(e.source);if(!n)return;let{iframe:r,extensionId:i}=n;if(this.iframes.get(i)!==r||r.contentWindow!==e.source)return;if(t.type===`event`){this.handleExtensionEvent(i,t.event,t.data);let e=this.eventSubscribers.get(i);if(e){let n={event:t.event,data:t.data};for(let t of e)try{t(n)}catch{}}return}if(t.type!==`request`)return;let{requestId:o,method:s,params:c}=t;if(typeof o!=`string`||o.length>200||typeof s!=`string`||s.length>200)return;let l=this.handlers.get(s);if(!l){this.postResponse(r,e,o,void 0,{code:A.MethodNotFound,message:`Unknown method: ${s}`});return}let u=c&&typeof c==`object`&&`id`in c?c.id:void 0,d=s===`capability.describe`||s===`capability.call`?`capability:${typeof u==`string`?u:``}`:N[s],f=this.extensionPermissions.get(i)??new Set;if(d&&!f.has(d)){this.postResponse(r,e,o,void 0,{code:A.PermissionDenied,message:`Missing permission: ${d}`});return}let p=a.getState(),m=()=>this.iframes.get(i)===r&&r.contentWindow===e.source&&this.extensionPermissions.get(i)===f&&a.getState().baseUrl===p.baseUrl&&a.getState().conversationId===p.conversationId;try{let t=await l(i,c);if(!m())return;this.postResponse(r,e,o,t)}catch(t){if(!m())return;let n=t instanceof Error?t.message:String(t);this.postResponse(r,e,o,void 0,{code:A.InternalError,message:n})}}};function F(e){let t=c({id:b.shape.id}),n=t.extend({call:m});e.registerMethod(`capability.describe`,async(n,r)=>{let{id:a}=t.parse(r),o=e.getReleaseDigest(n),c=(await i(s(`/api/local-app-capabilities/${encodeURIComponent(n)}?manifestDigest=${encodeURIComponent(o)}`))).capabilities.find(e=>e.id===a);if(!c)throw Error(`Capability is unavailable for this release`);return c}),e.registerMethod(`capability.call`,async(t,r)=>{let{id:a,call:o}=n.parse(r),c=e.getReleaseDigest(t);return i(s(`/api/local-app-capabilities/${encodeURIComponent(t)}/${encodeURIComponent(a)}/invocations`),{method:`POST`,body:JSON.stringify({manifestDigest:c,call:o})})}),e.registerMethod(`theme.get`,async()=>M(v.getState().resolved)),e.registerMethod(`ui.navigate`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`path`in t?String(t.path??``):``;if(n){let e=n.startsWith(`/`)?n:`/${n}`;window.location.hash=`#${e}`}}),e.registerMethod(`ui.notification`,async(e,t)=>{if(!t||typeof t!=`object`)return;let n=t,r=typeof n.title==`string`?n.title.trim():``;r&&g({tone:n.type===`success`||n.type===`warning`||n.type===`error`||n.type===`info`?n.type:`info`,title:r,message:typeof n.message==`string`?n.message:void 0,source:e,dedupeKey:`extension:${e}:${r}`})}),e.registerMethod(`session.navigate`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`conversationId`in t?String(t.conversationId??``):``;n&&window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{conversationId:n},bubbles:!0}))}),e.registerMethod(`session.list`,async()=>{let e=await o(s(`/api/sessions`));if(!e.ok)throw Error(`Failed to list sessions: ${e.status}`);return((await e.json()).items??[]).map(e=>({conversationId:e.key,title:e.name,lastMessageAt:e.updatedAt??e.lastAccessedAt,messageCount:e.messageCount}))}),e.registerMethod(`agent.sendMessage`,async(e,t)=>{let{message:n,conversationId:r,newSession:i}=t,a=r?.trim()||``;return(i||!a)&&(a=(await new p().createSession()).key),await y(a,n),{conversationId:a}}),e.registerMethod(`config.get`,async e=>{let t=await o(s(`/api/extensions/${encodeURIComponent(e)}/config`));if(!t.ok)throw Error(`Failed to get config: ${t.status}`);return t.json()}),e.registerMethod(`config.set`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&!Array.isArray(t)?t:{},r=await o(s(`/api/extensions/${encodeURIComponent(e)}/config`),{method:`PATCH`,body:JSON.stringify(n)});if(!r.ok)throw Error(`Failed to set config: ${r.status}`)}),e.registerMethod(`storage.get`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`key`in t?String(t.key??``):``,r=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(n)}`));if(r.status!==404){if(!r.ok)throw Error(`Failed to get storage key: ${r.status}`);return(await r.json()).value}}),e.registerMethod(`storage.set`,async(e,t)=>{let n=t,r=n&&typeof n.key==`string`?n.key:``,i=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(r)}`),{method:`PUT`,body:JSON.stringify({value:n?.value})});if(!i.ok)throw Error(`Failed to set storage key: ${i.status}`)}),e.registerMethod(`storage.remove`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`key`in t?String(t.key??``):``,r=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(n)}`),{method:`DELETE`});if(r.status!==404&&!r.ok)throw Error(`Failed to remove storage key: ${r.status}`)}),e.registerMethod(`storage.keys`,async e=>{let t=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage`));if(!t.ok)throw Error(`Failed to list storage keys: ${t.status}`);return(await t.json()).keys??[]})}function I(e){return e.active||e.activationEligible===!0}function L(e){let t=e.ui?.contributions;return t?Array.isArray(t.pages)&&t.pages.length>0||Array.isArray(t.settingsPanels)&&t.settingsPanels.length>0||Array.isArray(t.chatWidgets)&&t.chatWidgets.length>0:!1}function R(e){return e.source===`bundled`&&e.hasUi===!0&&L(e)}function z(e){return e.kind===`image-generation`||e.kind===`media-provider`}function B(e){return I(e)?e.hasConfigSchema||z(e)?!0:e.hasUi?L(e):!1:!1}function V(e){return B(e)||R(e)}var H=r(),U=(0,x.createContext)(null);function W({children:e}){let t=(0,x.useRef)(null);if(!t.current){let e=new P;F(e),t.current=e}let n=t.current,{data:r,isLoading:o,mutate:c}=h(a(e=>!!e.conversationId)?`gateway-extensions-list`:null,()=>i(s(`/api/extensions`)),{revalidateOnFocus:!1}),l=r?.extensions??[],u=v(e=>e.resolved);(0,x.useEffect)(()=>{let e=()=>{c()};return window.addEventListener(`config-reload`,e),window.addEventListener(`registry-updated`,e),()=>{window.removeEventListener(`config-reload`,e),window.removeEventListener(`registry-updated`,e)}},[c]);let d=(0,x.useCallback)(e=>{let t=e.detail;t?.conversationId&&n.forwardAgentStreamEvent(t.conversationId,t.event??t)},[n]),f=(0,x.useRef)(d);f.current=d,(0,x.useEffect)(()=>{let e=e=>{f.current(e)};return window.addEventListener(C,e),()=>{window.removeEventListener(C,e)}},[]),(0,x.useEffect)(()=>{let e=M(u);n.broadcastEvent(`theme.changed`,e)},[u,n]);let p=(0,x.useRef)(n);p.current=n,(0,x.useEffect)(()=>()=>{p.current.dispose(),t.current=null},[]);let m=(0,x.useMemo)(()=>({router:n,extensions:l,loading:o}),[n,l,o]);return(0,H.jsx)(U.Provider,{value:m,children:e})}function G(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensionRouter must be used within ExtensionProvider`);return e.router}function K(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensions must be used within ExtensionProvider`);return e.extensions}function q(){let e=(0,S.c)(2),t=K(),n;return e[0]===t?n=e[1]:(n=t.filter(B),e[0]=t,e[1]=n),n}function J(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensionsLoading must be used within ExtensionProvider`);return e.loading}export{q as a,M as c,J as i,C as l,G as n,z as o,K as r,V as s,W as t,k as u};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{a as i,c as a,i as o,r as s}from"./locale-store-CvNO-hbt.js";import{f as c,l,p as u,r as d,t as f}from"./schemas-CObaziC7.js";import{t as p}from"./session-manager-BDpdi3lF.js";import{t as m}from"./capabilities-C4grvUkw.js";import{i as h}from"./vendor-swr-BIWyz7Rc.js";import{t as g}from"./activity-store-SVmnh__i.js";import{a as _}from"./gateway-realtime-DD70L42G.js";import{i as v}from"./theme-store-DbRLBHVY.js";import{t as y}from"./send-session-input-jH6MQwdZ.js";var b=c({id:f([`xopc.notes.get`,`xopc.notes.list`,`xopc.tasks.get`,`xopc.tasks.list`,`xopc.notes.create`,`xopc.notes.update`,`xopc.notes.append`]),majorVersion:l().int().positive(),descriptorDigest:u().regex(/^[a-f0-9]{64}$/)});d(b).max(7).refine(e=>new Set(e.map(e=>e.id)).size===e.length,`Duplicate capability binding`);var x=e(t(),1),S=n(),C=`agent-stream-event`;function w(e){return e===`off`||e===`on`||e===`stream`}function T(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e,n=typeof t.conversationId==`string`?t.conversationId.trim():``,r=typeof t.runId==`string`?t.runId.trim():``;return n&&r?{conversationId:n,runId:r}:null}function E(e,t,n){return t&&typeof t==`object`&&!Array.isArray(t)?{...t,seq:n}:{type:e,seq:n,payload:t}}async function D(e){try{let t=await o(s(`/api/sessions/${encodeURIComponent(e)}/agent-config`));if(!t.ok)return`on`;let n=await t.json(),r=n.payload?.activityDetail?.effective;if(w(r))return r;let i=n.payload?.activityDetail?.default??n.payload?.reasoningLevel;return w(i)?i:`on`}catch{return`on`}}function O(e){window.dispatchEvent(new CustomEvent(C,{detail:e}))}function k(e={}){let t=e.subscribe??_,n=e.loadActivityDetailLevel??D,r=e.dispatch??O,i=new Map,a=!1,o=e=>{let o=T(e.detail);if(!o||i.has(o.runId))return;let s=`on`,c=!1,l,u=!1,d=!1,f=()=>{},p=()=>{u||(u=!0,f(),i.get(o.runId)===p&&i.delete(o.runId))},m=e=>{a||u||r({conversationId:o.conversationId,event:e,activityDetailLevel:s})};n(o.conversationId).then(e=>{s=e,c=!0,e===`stream`&&l&&!d&&m(l),l=void 0}),f=t(`run:${o.runId}`,{onEvent:e=>{if(u||d)return;let t=E(e.event,e.data,e.seq);e.event===`thinking_delta`&&!c?l=t:m(t),e.event===`run_end`&&(d=!0,l=void 0,queueMicrotask(p))},onGap:e=>{e.recoverable||p()}},0),i.set(o.runId,p)},s=e=>{let t=T(e.detail);t&&i.get(t.runId)?.()};return window.addEventListener(`run-started`,o),window.addEventListener(`run-completed`,s),window.addEventListener(`agent-run-ended`,s),()=>{a=!0,window.removeEventListener(`run-started`,o),window.removeEventListener(`run-completed`,s),window.removeEventListener(`agent-run-ended`,s);for(let e of[...i.values()])e()}}var A=function(e){return e[e.PermissionDenied=4001]=`PermissionDenied`,e[e.InvalidRequest=4002]=`InvalidRequest`,e[e.MethodNotFound=4003]=`MethodNotFound`,e[e.InternalError=4004]=`InternalError`,e[e.Timeout=4005]=`Timeout`,e[e.ExtensionNotFound=4006]=`ExtensionNotFound`,e[e.RateLimited=4007]=`RateLimited`,e}({}),j=[`--color-surface-base`,`--color-surface-panel`,`--color-surface-hover`,`--color-fg`,`--color-fg-muted`,`--color-fg-subtle`,`--color-accent`,`--color-accent-hover`,`--color-accent-soft`,`--color-edge`,`--color-edge-subtle`,`--color-danger`,`--color-success`,`--color-warning`,`--radius-sm`,`--radius-lg`,`--radius-xl`];function M(e){let t=getComputedStyle(document.documentElement),n={};for(let e of j){let r=t.getPropertyValue(e).trim();r&&(n[e]=r)}return{mode:e,tokens:n,fontFamily:t.getPropertyValue(`font-family`).trim(),fontFamilyMono:t.getPropertyValue(`--font-mono`).trim()}}var N={"agent.sendMessage":`agent.send`,"session.list":`session.read`,"session.navigate":`session.read`,"config.get":`config.read`,"config.set":`config.write`,"storage.get":`storage`,"storage.set":`storage`,"storage.remove":`storage`,"storage.keys":`storage`,"ui.notification":`notification`,"theme.get":`theme`},P=class{iframes=new Map;byContentWindow=new WeakMap;handlers=new Map;extensionPermissions=new Map;releaseBindings=new Map;eventSubscribers=new Map;agentStreamSubscriptions=new Map;boundListener=e=>{this.onWindowMessage(e)};constructor(){window.addEventListener(`message`,this.boundListener)}dispose(){window.removeEventListener(`message`,this.boundListener),this.iframes.clear(),this.handlers.clear(),this.extensionPermissions.clear(),this.releaseBindings.clear(),this.eventSubscribers.clear(),this.agentStreamSubscriptions.clear()}registerIframe(e,t,n,r){let i=this.iframes.get(e);if(i&&i!==t&&i.contentWindow&&this.byContentWindow.delete(i.contentWindow),this.iframes.set(e,t),this.extensionPermissions.set(e,new Set(n)),this.releaseBindings.delete(e),r){let t=a.getState();this.releaseBindings.set(e,{digest:r,baseUrl:t.baseUrl,namespace:t.conversationId})}this.rememberIframeWindow(e,t)}unregisterIframe(e){let t=this.iframes.get(e);this.sendEvent(e,`panel.dispose`),t?.contentWindow&&this.byContentWindow.delete(t.contentWindow),this.iframes.delete(e),this.extensionPermissions.delete(e),this.releaseBindings.delete(e),this.agentStreamSubscriptions.delete(e)}rememberIframeWindow(e,t){let n=t.contentWindow;n&&this.byContentWindow.set(n,{extensionId:e,iframe:t})}subscribeAgentStream(e,t){let n=this.agentStreamSubscriptions.get(e);n||(n=new Set,this.agentStreamSubscriptions.set(e,n)),n.add(t)}unsubscribeAgentStream(e,t){this.agentStreamSubscriptions.get(e)?.delete(t)}forwardAgentStreamEvent(e,t){for(let[n,r]of this.agentStreamSubscriptions)r.has(e)&&this.sendEvent(n,`agent.stream.${e}`,t)}broadcastExtensionEvent(e,t,n){let r=t.startsWith(`ext.`)?t:`ext.${t}`;for(let[t]of this.iframes)t!==e&&this.sendEvent(t,r,n)}handleExtensionEvent(e,t,n){if(t.startsWith(`ext.`)){let r=t.slice(4);this.broadcastExtensionEvent(e,r,n);return}if(t===`agent.subscribe`||t===`agent.unsubscribe`){if(!(this.extensionPermissions.get(e)??new Set).has(`agent.subscribe`))return;let{conversationId:r}=n??{};if(typeof r!=`string`||!r.trim())return;let i=r.trim();t===`agent.subscribe`?this.subscribeAgentStream(e,i):this.unsubscribeAgentStream(e,i)}}registerMethod(e,t){this.handlers.set(e,t)}getReleaseDigest(e){let t=this.releaseBindings.get(e),n=a.getState();if(!t||t.baseUrl!==n.baseUrl||t.namespace!==n.conversationId)throw Error(`Extension release authorization is unavailable`);return t.digest}subscribeExtensionEvents(e,t){let n=this.eventSubscribers.get(e);return n||(n=new Set,this.eventSubscribers.set(e,n)),n.add(t),()=>{n.delete(t),n.size===0&&this.eventSubscribers.delete(e)}}sendInit(e,t,n){let r=this.iframes.get(e);if(!r?.contentWindow)return;this.rememberIframeWindow(e,r);let i=[...this.extensionPermissions.get(e)??[]];r.contentWindow.postMessage({source:`xopc-host`,type:`init`,extensionId:e,permissions:i,theme:t,locale:n},`*`)}sendEvent(e,t,n){let r=this.iframes.get(e);r?.contentWindow&&r.contentWindow.postMessage({source:`xopc-host`,type:`event`,event:t,data:n},`*`)}broadcastEvent(e,t){for(let[,n]of this.iframes)n.contentWindow?.postMessage({source:`xopc-host`,type:`event`,event:e,data:t},`*`)}postResponse(e,t,n,r,i){let a=e.contentWindow,o={source:`xopc-host`,type:`response`,requestId:n,result:r,error:i};!a||a!==t?.source||a.postMessage(o,`*`)}async onWindowMessage(e){let t=e.data;if(!t||t.source!==`xopc-extension`||!e.source)return;let n=this.byContentWindow.get(e.source);if(!n)return;let{iframe:r,extensionId:i}=n;if(this.iframes.get(i)!==r||r.contentWindow!==e.source)return;if(t.type===`event`){this.handleExtensionEvent(i,t.event,t.data);let e=this.eventSubscribers.get(i);if(e){let n={event:t.event,data:t.data};for(let t of e)try{t(n)}catch{}}return}if(t.type!==`request`)return;let{requestId:o,method:s,params:c}=t;if(typeof o!=`string`||o.length>200||typeof s!=`string`||s.length>200)return;let l=this.handlers.get(s);if(!l){this.postResponse(r,e,o,void 0,{code:A.MethodNotFound,message:`Unknown method: ${s}`});return}let u=c&&typeof c==`object`&&`id`in c?c.id:void 0,d=s===`capability.describe`||s===`capability.call`?`capability:${typeof u==`string`?u:``}`:N[s],f=this.extensionPermissions.get(i)??new Set;if(d&&!f.has(d)){this.postResponse(r,e,o,void 0,{code:A.PermissionDenied,message:`Missing permission: ${d}`});return}let p=a.getState(),m=()=>this.iframes.get(i)===r&&r.contentWindow===e.source&&this.extensionPermissions.get(i)===f&&a.getState().baseUrl===p.baseUrl&&a.getState().conversationId===p.conversationId;try{let t=await l(i,c);if(!m())return;this.postResponse(r,e,o,t)}catch(t){if(!m())return;let n=t instanceof Error?t.message:String(t);this.postResponse(r,e,o,void 0,{code:A.InternalError,message:n})}}};function F(e){let t=c({id:b.shape.id}),n=t.extend({call:m});e.registerMethod(`capability.describe`,async(n,r)=>{let{id:a}=t.parse(r),o=e.getReleaseDigest(n),c=(await i(s(`/api/local-app-capabilities/${encodeURIComponent(n)}?manifestDigest=${encodeURIComponent(o)}`))).capabilities.find(e=>e.id===a);if(!c)throw Error(`Capability is unavailable for this release`);return c}),e.registerMethod(`capability.call`,async(t,r)=>{let{id:a,call:o}=n.parse(r),c=e.getReleaseDigest(t);return i(s(`/api/local-app-capabilities/${encodeURIComponent(t)}/${encodeURIComponent(a)}/invocations`),{method:`POST`,body:JSON.stringify({manifestDigest:c,call:o})})}),e.registerMethod(`theme.get`,async()=>M(v.getState().resolved)),e.registerMethod(`ui.navigate`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`path`in t?String(t.path??``):``;if(n){let e=n.startsWith(`/`)?n:`/${n}`;window.location.hash=`#${e}`}}),e.registerMethod(`ui.notification`,async(e,t)=>{if(!t||typeof t!=`object`)return;let n=t,r=typeof n.title==`string`?n.title.trim():``;r&&g({tone:n.type===`success`||n.type===`warning`||n.type===`error`||n.type===`info`?n.type:`info`,title:r,message:typeof n.message==`string`?n.message:void 0,source:e,dedupeKey:`extension:${e}:${r}`})}),e.registerMethod(`session.navigate`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`conversationId`in t?String(t.conversationId??``):``;n&&window.dispatchEvent(new CustomEvent(`navigate-to-chat`,{detail:{conversationId:n},bubbles:!0}))}),e.registerMethod(`session.list`,async()=>{let e=await o(s(`/api/sessions`));if(!e.ok)throw Error(`Failed to list sessions: ${e.status}`);return((await e.json()).items??[]).map(e=>({conversationId:e.key,title:e.name,lastMessageAt:e.updatedAt??e.lastAccessedAt,messageCount:e.messageCount}))}),e.registerMethod(`agent.sendMessage`,async(e,t)=>{let{message:n,conversationId:r,newSession:i}=t,a=r?.trim()||``;return(i||!a)&&(a=(await new p().createSession()).key),await y(a,n),{conversationId:a}}),e.registerMethod(`config.get`,async e=>{let t=await o(s(`/api/extensions/${encodeURIComponent(e)}/config`));if(!t.ok)throw Error(`Failed to get config: ${t.status}`);return t.json()}),e.registerMethod(`config.set`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&!Array.isArray(t)?t:{},r=await o(s(`/api/extensions/${encodeURIComponent(e)}/config`),{method:`PATCH`,body:JSON.stringify(n)});if(!r.ok)throw Error(`Failed to set config: ${r.status}`)}),e.registerMethod(`storage.get`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`key`in t?String(t.key??``):``,r=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(n)}`));if(r.status!==404){if(!r.ok)throw Error(`Failed to get storage key: ${r.status}`);return(await r.json()).value}}),e.registerMethod(`storage.set`,async(e,t)=>{let n=t,r=n&&typeof n.key==`string`?n.key:``,i=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(r)}`),{method:`PUT`,body:JSON.stringify({value:n?.value})});if(!i.ok)throw Error(`Failed to set storage key: ${i.status}`)}),e.registerMethod(`storage.remove`,async(e,t)=>{let n=t&&typeof t==`object`&&t&&`key`in t?String(t.key??``):``,r=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage/${encodeURIComponent(n)}`),{method:`DELETE`});if(r.status!==404&&!r.ok)throw Error(`Failed to remove storage key: ${r.status}`)}),e.registerMethod(`storage.keys`,async e=>{let t=await o(s(`/api/extensions/${encodeURIComponent(e)}/storage`));if(!t.ok)throw Error(`Failed to list storage keys: ${t.status}`);return(await t.json()).keys??[]})}function I(e){return e.active||e.activationEligible===!0}function L(e){let t=e.ui?.contributions;return t?Array.isArray(t.pages)&&t.pages.length>0||Array.isArray(t.settingsPanels)&&t.settingsPanels.length>0||Array.isArray(t.chatWidgets)&&t.chatWidgets.length>0:!1}function R(e){return e.source===`bundled`&&e.hasUi===!0&&L(e)}function z(e){return e.kind===`image-generation`||e.kind===`media-provider`}function B(e){return I(e)?e.hasConfigSchema||z(e)?!0:e.hasUi?L(e):!1:!1}function V(e){return B(e)||R(e)}var H=r(),U=(0,x.createContext)(null);function W({children:e}){let t=(0,x.useRef)(null);if(!t.current){let e=new P;F(e),t.current=e}let n=t.current,{data:r,isLoading:o,mutate:c}=h(a(e=>!!e.conversationId)?`gateway-extensions-list`:null,()=>i(s(`/api/extensions`)),{revalidateOnFocus:!1}),l=r?.extensions??[],u=v(e=>e.resolved);(0,x.useEffect)(()=>{let e=()=>{c()};return window.addEventListener(`config-reload`,e),window.addEventListener(`registry-updated`,e),()=>{window.removeEventListener(`config-reload`,e),window.removeEventListener(`registry-updated`,e)}},[c]);let d=(0,x.useCallback)(e=>{let t=e.detail;t?.conversationId&&n.forwardAgentStreamEvent(t.conversationId,t.event??t)},[n]),f=(0,x.useRef)(d);f.current=d,(0,x.useEffect)(()=>{let e=e=>{f.current(e)};return window.addEventListener(C,e),()=>{window.removeEventListener(C,e)}},[]),(0,x.useEffect)(()=>{let e=M(u);n.broadcastEvent(`theme.changed`,e)},[u,n]);let p=(0,x.useRef)(n);p.current=n,(0,x.useEffect)(()=>()=>{p.current.dispose(),t.current=null},[]);let m=(0,x.useMemo)(()=>({router:n,extensions:l,loading:o}),[n,l,o]);return(0,H.jsx)(U.Provider,{value:m,children:e})}function G(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensionRouter must be used within ExtensionProvider`);return e.router}function K(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensions must be used within ExtensionProvider`);return e.extensions}function q(){let e=(0,S.c)(2),t=K(),n;return e[0]===t?n=e[1]:(n=t.filter(B),e[0]=t,e[1]=n),n}function J(){let e=(0,x.useContext)(U);if(!e)throw Error(`useExtensionsLoading must be used within ExtensionProvider`);return e.loading}export{q as a,M as c,J as i,C as l,G as n,z as o,K as r,V as s,W as t,k as u};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{m as i,t as a}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{n as o,r as s}from"./popover-select-BgSdSbCL.js";import{t as c}from"./messages-BHvpZNe9.js";import{t as l}from"./cn-JdwAhgNB.js";import{a as u,c as d,i as f,n as p,r as m}from"./locale-store-DId6-v2R.js";import{r as h}from"./extension-provider-F9JzOWZ3.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{t as _}from"./button-CS04eWY9.js";import{a as v,o as y,s as b}from"./form-field-width-DJw_jULe.js";import{Nr as x}from"./index-BYNmHn-z.js";import{n as S,r as C}from"./settings-page-layout-X1x-2Cp9.js";import{t as w}from"./settings-loading-skeleton-CAmWMaOT.js";import{n as T,t as E}from"./use-autosave-veoM0dHn.js";import{a as D,c as O,o as k}from"./voice-config-api-Daexehmc.js";import{t as A}from"./voice-api-key-field-CwD6a3KQ.js";import{t as j}from"./schema-form-C_cJLGgF.js";var M=e(t(),1),N=n(),P=r();function F(e){let t=(0,N.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,P.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function I(e){let t=e?.manifest?.mediaUnderstandingProviders?.[0];if(typeof t==`string`&&t.trim())return t.trim();let n=e?.manifest?.contracts?.mediaUnderstandingProviders?.[0];if(typeof n==`string`&&n.trim())return n.trim()}function L(){return l(y,v)}function R(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,b,`dark:border-edge`)}function z(e,t,n){if(!e||!t)return{apiKey:``,model:n};let r=e.stt.providers?.[t];return{apiKey:typeof r?.apiKey==`string`?r.apiKey:``,model:typeof r?.model==`string`?r.model:n}}function B({providerId:e,voiceSettings:t,mutateVoice:n}){let r=c(p(e=>e.language)),i=r.voiceSettings,a=r.extensionSttMedia,u={maskedHelp:i.apiKeyMaskedHelp,copy:i.apiKeyCopy,copied:i.apiKeyCopied,show:i.apiKeyShow,hide:i.apiKeyHide,notInConfigFile:i.apiKeyNotInConfigFile,loadFailed:i.apiKeyRevealFailed},{data:d}=g(m(`/api/voice/stt-providers`),k,{revalidateOnFocus:!1}),f=(0,M.useMemo)(()=>d?.providers.find(t=>t.id===e),[e,d]),h=f?.configured??!1,_=f?.models??[],y=_[0]?.id??f?.fields.find(e=>e.key===`model`)?.defaultValue??``,b=(0,M.useMemo)(()=>z(t,e,y),[y,e,t]),x=(0,M.useRef)(!1),[S,C]=(0,M.useState)(null),w=S??b,D=(0,M.useRef)(w);D.current=w;let j=b,N=E({value:w,dirty:w.apiKey!==j.apiKey||w.model!==j.model,onSave:(0,M.useCallback)(async r=>{let i=structuredClone(t);i.stt.enabled=!0,i.stt.provider=e,i.stt.providers={...i.stt.providers??{},[e]:{...i.stt.providers?.[e]??{},apiKey:r.apiKey,model:r.model}},await O(i),await n(i,!1),x.current=JSON.stringify(D.current)!==JSON.stringify(r),C(e=>e&&JSON.stringify(e)===JSON.stringify(r)?null:e)},[n,e,t])}),I=_.length>0?_:w.model?[{id:w.model,name:w.model}]:[];return(0,P.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-xl bg-surface-base p-4`,onBlurCapture:N.onBlurCapture,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:a.credentialsTitle}),(0,P.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.credentialsHint.replace(`{providerId}`,e)})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{status:N.status,error:N.error}),(0,P.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs font-medium`,h?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-800 dark:text-amber-200`),children:h?a.configured:a.notConfigured})]})]}),(0,P.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,P.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,v),children:[(0,P.jsx)(F,{children:i.stt.apiKey}),(0,P.jsx)(A,{kind:`stt`,providerId:e,fieldId:`ext-stt-${e}-api-key`,value:w.apiKey,onChange:e=>{x.current=!0,C(t=>({...t??b,apiKey:e}))},labels:u,placeholder:e===`groq`?`gsk_...`:`sk-...`}),(0,P.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[i.stt.apiKeyDesc,e===`groq`?` (GROQ_API_KEY)`:``]})]}),(0,P.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,v),children:[(0,P.jsx)(F,{children:i.stt.model}),I.length>0?(0,P.jsx)(o,{className:L(),value:w.model,onChange:e=>{x.current=!0,C(t=>({...t??b,model:e.target.value})),N.saveNow({...w,model:e.target.value})},children:I.map(e=>(0,P.jsx)(s,{value:e.id,children:e.name},e.id))}):(0,P.jsx)(`input`,{className:R(),value:w.model,onChange:e=>{x.current=!0,C(t=>({...t??b,model:e.target.value}))}})]})]})]})}function V(e){let t=(0,N.c)(13),{extensionId:n}=e,r=p(U),i=d(H),a;t[0]===n?a=t[1]:(a=()=>u(m(`/api/extensions/${encodeURIComponent(n)}`)),t[0]=n,t[1]=a);let{data:o,isLoading:s}=g(i&&n?`ext-stt-detail-${n}`:null,a),c;t[2]===o?c=t[3]:(c=I(o),t[2]=o,t[3]=c);let l=c,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f={revalidateOnFocus:!1},t[4]=f):f=t[4];let{data:h,mutate:_,isLoading:v}=g(i?`voice-settings-ext-stt`:null,D,f);if(!i)return null;if(s||v){let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,P.jsx)(w,{rows:2}),t[5]=e):e=t[5],e}if(!l){let e=r===`zh`?`该扩展未声明 mediaUnderstandingProviders。`:`This extension does not declare mediaUnderstandingProviders.`,n;return t[6]===e?n=t[7]:(n=(0,P.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e}),t[6]=e,t[7]=n),n}if(!h)return null;let y=`${n}:${l}`,b;return t[8]!==_||t[9]!==l||t[10]!==y||t[11]!==h?(b=(0,P.jsx)(B,{providerId:l,voiceSettings:h,mutateVoice:_},y),t[8]=_,t[9]=l,t[10]=y,t[11]=h,t[12]=b):b=t[12],b}function H(e){return!!e.conversationId}function U(e){return e.language}function W(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e){let t={};if(e.type!==`object`||!W(e.properties))return t;for(let[n,r]of Object.entries(e.properties))W(r)&&Object.prototype.hasOwnProperty.call(r,`default`)&&(t[n]=r.default);return t}function K(e,t){switch(t.type){case`sync`:return{localValues:t.value,isDirty:!1};case`change`:return{localValues:t.value,isDirty:!0};case`reset-defaults`:return{localValues:t.value,isDirty:!0};case`saved`:return JSON.stringify(e.localValues)===JSON.stringify(t.value)?{localValues:e.localValues,isDirty:!1}:e}}function q({extensionId:e}){let t=d(e=>!!e.conversationId),{data:n,error:r}=g(t&&e?`ext-detail-${e}`:null,()=>u(m(`/api/extensions/${encodeURIComponent(e)}`))),{data:i,mutate:a,error:o}=g(t&&e?`ext-cfg-${e}`:null,()=>u(m(`/api/extensions/${encodeURIComponent(e)}/config`))),s=n?.manifest?.configSchema,c=(0,M.useMemo)(()=>s&&s.type===`object`?G(s):{},[s]),l=(0,M.useMemo)(()=>({...c,...i??{}}),[c,i]),[p,h]=(0,M.useReducer)(K,{localValues:{},isDirty:!1}),v=(0,M.useRef)(!1),y=(0,M.useRef)(p.localValues);y.current=p.localValues;let b=(0,M.useRef)(l);!v.current&&b.current!==l&&(b.current=l,h({type:`sync`,value:l}));let x=(0,M.useCallback)(e=>{v.current=!0,h({type:`change`,value:e})},[]),S=(0,M.useCallback)(()=>{!s||s.type!==`object`||(v.current=!0,h({type:`reset-defaults`,value:{...G(s)}}))},[s]),C=(0,M.useCallback)(async t=>{if(!e)return;let n=await f(m(`/api/extensions/${encodeURIComponent(e)}/config`),{method:`PATCH`,body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error?.message??n.statusText)}await a(t,!1),h({type:`saved`,value:t}),v.current=JSON.stringify(y.current)!==JSON.stringify(t)},[e,a]),w=E({value:p.localValues,dirty:p.isDirty,onSave:C});if(!t)return null;if(r||o){let e=r??o;return(0,P.jsxs)(`p`,{className:`text-sm text-fg-muted`,children:[`Could not load extension settings: `,e instanceof Error?e.message:String(e)]})}return!s||s.type!==`object`?null:(0,P.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-hover/20 p-4`,onBlurCapture:w.onBlurCapture,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Configuration`}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{status:w.status,error:w.error}),(0,P.jsx)(_,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:S,children:`Reset to defaults`})]})]}),(0,P.jsx)(j,{schema:s,values:p.localValues,onChange:x})]})}function J(){let e=(0,N.c)(38),t=p(Y),n;e[0]===t?n=e[1]:(n=c(t),e[0]=t,e[1]=n);let r=n.extensionSttMedia,{extensionId:o,panelId:s}=i(),l=h();if(!o){let t;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,P.jsx)(X,{message:`No extension ID provided.`}),e[2]=t):t=e[2],t}let u,d,f;if(e[3]!==o||e[4]!==l||e[5]!==s){f=Symbol.for(`react.early_return_sentinel`);bb0:{let t;if(e[9]===o?t=e[10]:(t=e=>e.id===o,e[9]=o,e[10]=t),u=l.find(t),!u){let t=`Extension "${o}" not found or is not available in this workspace.`,n;e[11]===t?n=e[12]:(n=(0,P.jsx)(X,{message:t}),e[11]=t,e[12]=n),f=n;break bb0}let n=u.ui?.contributions?.settingsPanels;d=s?n?.find(e=>e.id===s||e.id===`${o}.${s}`):n?.[0]}e[3]=o,e[4]=l,e[5]=s,e[6]=u,e[7]=d,e[8]=f}else u=e[6],d=e[7],f=e[8];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let m=d,g=!!(m&&u.ui),_=!!u.hasConfigSchema,v=u.kind===`media-provider`;if(!_&&!g&&!v){let t=`Extension "${o}" has no settings panels or config schema.`,n;return e[13]===t?n=e[14]:(n=(0,P.jsx)(X,{message:t}),e[13]=t,e[14]=n),n}let y=m?.title??`${u.name} Settings`,b;e[15]===y?b=e[16]:(b=(0,P.jsx)(S,{title:y}),e[15]=y,e[16]=b);let w;e[17]!==v||e[18]!==r?(w=v?(0,P.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg bg-surface-base px-4 py-3 text-sm`,children:[(0,P.jsx)(`p`,{className:`leading-relaxed text-fg-muted`,children:r.banner}),(0,P.jsx)(a,{to:`/settings/capabilities/voice`,className:`w-fit font-medium text-accent hover:underline`,children:r.openVoice})]}):null,e[17]=v,e[18]=r,e[19]=w):w=e[19];let T;e[20]!==o||e[21]!==v?(T=v?(0,P.jsx)(V,{extensionId:o}):null,e[20]=o,e[21]=v,e[22]=T):T=e[22];let E;e[23]!==o||e[24]!==_?(E=_?(0,P.jsx)(q,{extensionId:o}):null,e[23]=o,e[24]=_,e[25]=E):E=e[25];let D;e[26]!==u.name||e[27]!==u.ui||e[28]!==o||e[29]!==g||e[30]!==m?(D=g&&m&&u.ui?(0,P.jsx)(`div`,{className:`overflow-hidden rounded-xl bg-surface-base shadow-surface`,children:(0,P.jsx)(x,{extensionId:o,extensionName:u.name,entrypoint:m.entrypoint,permissions:u.ui?.permissions,title:m.title,className:`w-full`,minHeight:120,maxHeight:2e3})}):null,e[26]=u.name,e[27]=u.ui,e[28]=o,e[29]=g,e[30]=m,e[31]=D):D=e[31];let O;return e[32]!==b||e[33]!==w||e[34]!==T||e[35]!==E||e[36]!==D?(O=(0,P.jsxs)(C,{gap:`gap-5`,children:[b,w,T,E,D]}),e[32]=b,e[33]=w,e[34]=T,e[35]=E,e[36]=D,e[37]=O):O=e[37],O}function Y(e){return e.language}function X(e){let t=(0,N.c)(2),{message:n}=e,r;return t[0]===n?r=t[1]:(r=(0,P.jsx)(C,{gap:`gap-3`,children:(0,P.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n})}),t[0]=n,t[1]=r),r}export{J as ExtensionSettingsPage};
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,t as a}from"./chunk-KS7C4IRE-BMYIfy9x.js";import{n as o,r as s}from"./popover-select-BgSdSbCL.js";import{t as c}from"./messages-pGa2qMzG.js";import{t as l}from"./cn-JdwAhgNB.js";import{a as u,c as d,i as f,n as p,r as m}from"./locale-store-CvNO-hbt.js";import{r as h}from"./extension-provider-DaLt3bC-.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{t as _}from"./button-CS04eWY9.js";import{a as v,o as y,s as b}from"./form-field-width-DJw_jULe.js";import{Nr as x}from"./index-6JNNrzCq.js";import{n as S,r as C}from"./settings-page-layout-X1x-2Cp9.js";import{t as w}from"./settings-loading-skeleton-CAmWMaOT.js";import{n as T,t as E}from"./use-autosave-C889OTsP.js";import{a as D,c as O,o as k}from"./voice-config-api-CZoV2Lt4.js";import{t as A}from"./voice-api-key-field-evWflGY6.js";import{t as j}from"./schema-form-CMB61TV1.js";var M=e(t(),1),N=n(),P=r();function F(e){let t=(0,N.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,P.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function I(e){let t=e?.manifest?.mediaUnderstandingProviders?.[0];if(typeof t==`string`&&t.trim())return t.trim();let n=e?.manifest?.contracts?.mediaUnderstandingProviders?.[0];if(typeof n==`string`&&n.trim())return n.trim()}function L(){return l(y,v)}function R(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,b,`dark:border-edge`)}function z(e,t,n){if(!e||!t)return{apiKey:``,model:n};let r=e.stt.providers?.[t];return{apiKey:typeof r?.apiKey==`string`?r.apiKey:``,model:typeof r?.model==`string`?r.model:n}}function B({providerId:e,voiceSettings:t,mutateVoice:n}){let r=c(p(e=>e.language)),i=r.voiceSettings,a=r.extensionSttMedia,u={maskedHelp:i.apiKeyMaskedHelp,copy:i.apiKeyCopy,copied:i.apiKeyCopied,show:i.apiKeyShow,hide:i.apiKeyHide,notInConfigFile:i.apiKeyNotInConfigFile,loadFailed:i.apiKeyRevealFailed},{data:d}=g(m(`/api/voice/stt-providers`),k,{revalidateOnFocus:!1}),f=(0,M.useMemo)(()=>d?.providers.find(t=>t.id===e),[e,d]),h=f?.configured??!1,_=f?.models??[],y=_[0]?.id??f?.fields.find(e=>e.key===`model`)?.defaultValue??``,b=(0,M.useMemo)(()=>z(t,e,y),[y,e,t]),x=(0,M.useRef)(!1),[S,C]=(0,M.useState)(null),w=S??b,D=(0,M.useRef)(w);D.current=w;let j=b,N=E({value:w,dirty:w.apiKey!==j.apiKey||w.model!==j.model,onSave:(0,M.useCallback)(async r=>{let i=structuredClone(t);i.stt.enabled=!0,i.stt.provider=e,i.stt.providers={...i.stt.providers??{},[e]:{...i.stt.providers?.[e]??{},apiKey:r.apiKey,model:r.model}},await O(i),await n(i,!1),x.current=JSON.stringify(D.current)!==JSON.stringify(r),C(e=>e&&JSON.stringify(e)===JSON.stringify(r)?null:e)},[n,e,t])}),I=_.length>0?_:w.model?[{id:w.model,name:w.model}]:[];return(0,P.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-xl bg-surface-base p-4`,onBlurCapture:N.onBlurCapture,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:a.credentialsTitle}),(0,P.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:a.credentialsHint.replace(`{providerId}`,e)})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{status:N.status,error:N.error}),(0,P.jsx)(`span`,{className:l(`rounded-full px-2 py-0.5 text-xs font-medium`,h?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-800 dark:text-amber-200`),children:h?a.configured:a.notConfigured})]})]}),(0,P.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,P.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,v),children:[(0,P.jsx)(F,{children:i.stt.apiKey}),(0,P.jsx)(A,{kind:`stt`,providerId:e,fieldId:`ext-stt-${e}-api-key`,value:w.apiKey,onChange:e=>{x.current=!0,C(t=>({...t??b,apiKey:e}))},labels:u,placeholder:e===`groq`?`gsk_...`:`sk-...`}),(0,P.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[i.stt.apiKeyDesc,e===`groq`?` (GROQ_API_KEY)`:``]})]}),(0,P.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,v),children:[(0,P.jsx)(F,{children:i.stt.model}),I.length>0?(0,P.jsx)(o,{className:L(),value:w.model,onChange:e=>{x.current=!0,C(t=>({...t??b,model:e.target.value})),N.saveNow({...w,model:e.target.value})},children:I.map(e=>(0,P.jsx)(s,{value:e.id,children:e.name},e.id))}):(0,P.jsx)(`input`,{className:R(),value:w.model,onChange:e=>{x.current=!0,C(t=>({...t??b,model:e.target.value}))}})]})]})]})}function V(e){let t=(0,N.c)(13),{extensionId:n}=e,r=p(U),i=d(H),a;t[0]===n?a=t[1]:(a=()=>u(m(`/api/extensions/${encodeURIComponent(n)}`)),t[0]=n,t[1]=a);let{data:o,isLoading:s}=g(i&&n?`ext-stt-detail-${n}`:null,a),c;t[2]===o?c=t[3]:(c=I(o),t[2]=o,t[3]=c);let l=c,f;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(f={revalidateOnFocus:!1},t[4]=f):f=t[4];let{data:h,mutate:_,isLoading:v}=g(i?`voice-settings-ext-stt`:null,D,f);if(!i)return null;if(s||v){let e;return t[5]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,P.jsx)(w,{rows:2}),t[5]=e):e=t[5],e}if(!l){let e=r===`zh`?`该扩展未声明 mediaUnderstandingProviders。`:`This extension does not declare mediaUnderstandingProviders.`,n;return t[6]===e?n=t[7]:(n=(0,P.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e}),t[6]=e,t[7]=n),n}if(!h)return null;let y=`${n}:${l}`,b;return t[8]!==_||t[9]!==l||t[10]!==y||t[11]!==h?(b=(0,P.jsx)(B,{providerId:l,voiceSettings:h,mutateVoice:_},y),t[8]=_,t[9]=l,t[10]=y,t[11]=h,t[12]=b):b=t[12],b}function H(e){return!!e.conversationId}function U(e){return e.language}function W(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function G(e){let t={};if(e.type!==`object`||!W(e.properties))return t;for(let[n,r]of Object.entries(e.properties))W(r)&&Object.prototype.hasOwnProperty.call(r,`default`)&&(t[n]=r.default);return t}function K(e,t){switch(t.type){case`sync`:return{localValues:t.value,isDirty:!1};case`change`:return{localValues:t.value,isDirty:!0};case`reset-defaults`:return{localValues:t.value,isDirty:!0};case`saved`:return JSON.stringify(e.localValues)===JSON.stringify(t.value)?{localValues:e.localValues,isDirty:!1}:e}}function q({extensionId:e}){let t=d(e=>!!e.conversationId),{data:n,error:r}=g(t&&e?`ext-detail-${e}`:null,()=>u(m(`/api/extensions/${encodeURIComponent(e)}`))),{data:i,mutate:a,error:o}=g(t&&e?`ext-cfg-${e}`:null,()=>u(m(`/api/extensions/${encodeURIComponent(e)}/config`))),s=n?.manifest?.configSchema,c=(0,M.useMemo)(()=>s&&s.type===`object`?G(s):{},[s]),l=(0,M.useMemo)(()=>({...c,...i??{}}),[c,i]),[p,h]=(0,M.useReducer)(K,{localValues:{},isDirty:!1}),v=(0,M.useRef)(!1),y=(0,M.useRef)(p.localValues);y.current=p.localValues;let b=(0,M.useRef)(l);!v.current&&b.current!==l&&(b.current=l,h({type:`sync`,value:l}));let x=(0,M.useCallback)(e=>{v.current=!0,h({type:`change`,value:e})},[]),S=(0,M.useCallback)(()=>{!s||s.type!==`object`||(v.current=!0,h({type:`reset-defaults`,value:{...G(s)}}))},[s]),C=(0,M.useCallback)(async t=>{if(!e)return;let n=await f(m(`/api/extensions/${encodeURIComponent(e)}/config`),{method:`PATCH`,body:JSON.stringify(t)});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error?.message??n.statusText)}await a(t,!1),h({type:`saved`,value:t}),v.current=JSON.stringify(y.current)!==JSON.stringify(t)},[e,a]),w=E({value:p.localValues,dirty:p.isDirty,onSave:C});if(!t)return null;if(r||o){let e=r??o;return(0,P.jsxs)(`p`,{className:`text-sm text-fg-muted`,children:[`Could not load extension settings: `,e instanceof Error?e.message:String(e)]})}return!s||s.type!==`object`?null:(0,P.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-hover/20 p-4`,onBlurCapture:w.onBlurCapture,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,P.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:`Configuration`}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{status:w.status,error:w.error}),(0,P.jsx)(_,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:S,children:`Reset to defaults`})]})]}),(0,P.jsx)(j,{schema:s,values:p.localValues,onChange:x})]})}function J(){let e=(0,N.c)(38),t=p(Y),n;e[0]===t?n=e[1]:(n=c(t),e[0]=t,e[1]=n);let r=n.extensionSttMedia,{extensionId:o,panelId:s}=i(),l=h();if(!o){let t;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,P.jsx)(X,{message:`No extension ID provided.`}),e[2]=t):t=e[2],t}let u,d,f;if(e[3]!==o||e[4]!==l||e[5]!==s){f=Symbol.for(`react.early_return_sentinel`);bb0:{let t;if(e[9]===o?t=e[10]:(t=e=>e.id===o,e[9]=o,e[10]=t),u=l.find(t),!u){let t=`Extension "${o}" not found or is not available in this workspace.`,n;e[11]===t?n=e[12]:(n=(0,P.jsx)(X,{message:t}),e[11]=t,e[12]=n),f=n;break bb0}let n=u.ui?.contributions?.settingsPanels;d=s?n?.find(e=>e.id===s||e.id===`${o}.${s}`):n?.[0]}e[3]=o,e[4]=l,e[5]=s,e[6]=u,e[7]=d,e[8]=f}else u=e[6],d=e[7],f=e[8];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let m=d,g=!!(m&&u.ui),_=!!u.hasConfigSchema,v=u.kind===`media-provider`;if(!_&&!g&&!v){let t=`Extension "${o}" has no settings panels or config schema.`,n;return e[13]===t?n=e[14]:(n=(0,P.jsx)(X,{message:t}),e[13]=t,e[14]=n),n}let y=m?.title??`${u.name} Settings`,b;e[15]===y?b=e[16]:(b=(0,P.jsx)(S,{title:y}),e[15]=y,e[16]=b);let w;e[17]!==v||e[18]!==r?(w=v?(0,P.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg bg-surface-base px-4 py-3 text-sm`,children:[(0,P.jsx)(`p`,{className:`leading-relaxed text-fg-muted`,children:r.banner}),(0,P.jsx)(a,{to:`/settings/capabilities/voice`,className:`w-fit font-medium text-accent hover:underline`,children:r.openVoice})]}):null,e[17]=v,e[18]=r,e[19]=w):w=e[19];let T;e[20]!==o||e[21]!==v?(T=v?(0,P.jsx)(V,{extensionId:o}):null,e[20]=o,e[21]=v,e[22]=T):T=e[22];let E;e[23]!==o||e[24]!==_?(E=_?(0,P.jsx)(q,{extensionId:o}):null,e[23]=o,e[24]=_,e[25]=E):E=e[25];let D;e[26]!==u.name||e[27]!==u.ui||e[28]!==o||e[29]!==g||e[30]!==m?(D=g&&m&&u.ui?(0,P.jsx)(`div`,{className:`overflow-hidden rounded-xl bg-surface-base shadow-surface`,children:(0,P.jsx)(x,{extensionId:o,extensionName:u.name,entrypoint:m.entrypoint,permissions:u.ui?.permissions,title:m.title,className:`w-full`,minHeight:120,maxHeight:2e3})}):null,e[26]=u.name,e[27]=u.ui,e[28]=o,e[29]=g,e[30]=m,e[31]=D):D=e[31];let O;return e[32]!==b||e[33]!==w||e[34]!==T||e[35]!==E||e[36]!==D?(O=(0,P.jsxs)(C,{gap:`gap-5`,children:[b,w,T,E,D]}),e[32]=b,e[33]=w,e[34]=T,e[35]=E,e[36]=D,e[37]=O):O=e[37],O}function Y(e){return e.language}function X(e){let t=(0,N.c)(2),{message:n}=e,r;return t[0]===n?r=t[1]:(r=(0,P.jsx)(C,{gap:`gap-3`,children:(0,P.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n})}),t[0]=n,t[1]=r),r}export{J as ExtensionSettingsPage};
@@ -1 +1 @@
1
- import"./rolldown-runtime-aKtaBQYM.js";import{a as e,n as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./x-B_N4OPjy.js";import{t as i}from"./skeleton-BwbyijEw.js";import{Wr as a}from"./index-BYNmHn-z.js";var o=t();e();var s=n();function c(e){let t=(0,o.c)(30),{primary:n,value:c,models:l,loading:u,error:d,zh:f,onChange:p}=e,m;if(t[0]!==l||t[1]!==n||t[2]!==c){let e;t[4]!==n||t[5]!==c?(e=e=>e.id!==n&&!c.includes(e.id),t[4]=n,t[5]=c,t[6]=e):e=t[6],m=l.filter(e),t[0]=l,t[1]=n,t[2]=c,t[3]=m}else m=t[3];let h=m,g=f?`回退顺序`:`Fallback order`,_;t[7]===g?_=t[8]:(_=(0,s.jsx)(`h4`,{className:`text-sm font-medium text-fg`,children:g}),t[7]=g,t[8]=_);let v=f?`主模型不可用时,按从左到右的顺序尝试。`:`Tried from left to right when the primary model is unavailable.`,y;t[9]===v?y=t[10]:(y=(0,s.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:v}),t[9]=v,t[10]=y);let b;t[11]!==_||t[12]!==y?(b=(0,s.jsx)(`div`,{className:`flex items-center justify-between gap-3`,children:(0,s.jsxs)(`div`,{children:[_,y]})}),t[11]=_,t[12]=y,t[13]=b):b=t[13];let x;t[14]!==l||t[15]!==p||t[16]!==c||t[17]!==f?(x=c.length>0?(0,s.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:c.map((e,t)=>(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full bg-surface-base/70 py-1 pl-2.5 pr-1 text-xs text-fg`,children:[(0,s.jsx)(`span`,{className:`text-fg-subtle`,children:t+1}),(0,s.jsx)(`span`,{children:l.find(t=>t.id===e)?.name??e}),(0,s.jsx)(`button`,{type:`button`,"aria-label":f?`移除 ${e}`:`Remove ${e}`,className:`rounded-full p-1 text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>p(c.filter(t=>t!==e)),children:(0,s.jsx)(r,{className:`size-3`})})]},e))}):(0,s.jsx)(`p`,{className:`mt-3 text-xs text-fg-subtle`,children:f?`未设置回退模型。`:`No fallback models configured.`}),t[14]=l,t[15]=p,t[16]=c,t[17]=f,t[18]=x):x=t[18];let S;t[19]!==h||t[20]!==d||t[21]!==u||t[22]!==p||t[23]!==c||t[24]!==f?(S=u?(0,s.jsx)(i,{className:`mt-3 h-11 w-full max-w-md rounded-lg`}):(0,s.jsx)(a,{value:``,models:h,modelsLoading:u,modelsError:d,placeholder:f?`添加回退模型`:`Add fallback model`,searchPlaceholder:f?`搜索模型或服务商`:`Search models or providers`,noMatches:f?`没有可添加的模型`:`No models available to add`,showProviderInTrigger:!1,contentAlign:`start`,className:`mt-3 w-full max-w-md`,ariaLabel:f?`添加回退模型`:`Add fallback model`,onChange:e=>{e&&p([...c,e])}}),t[19]=h,t[20]=d,t[21]=u,t[22]=p,t[23]=c,t[24]=f,t[25]=S):S=t[25];let C;return t[26]!==b||t[27]!==x||t[28]!==S?(C=(0,s.jsxs)(`div`,{children:[b,x,S]}),t[26]=b,t[27]=x,t[28]=S,t[29]=C):C=t[29],C}export{c as t};
1
+ import"./rolldown-runtime-aKtaBQYM.js";import{a as e,n as t,t as n}from"./vendor-react-BOUWij0V.js";import{t as r}from"./x-B_N4OPjy.js";import{t as i}from"./skeleton-BwbyijEw.js";import{Wr as a}from"./index-6JNNrzCq.js";var o=t();e();var s=n();function c(e){let t=(0,o.c)(30),{primary:n,value:c,models:l,loading:u,error:d,zh:f,onChange:p}=e,m;if(t[0]!==l||t[1]!==n||t[2]!==c){let e;t[4]!==n||t[5]!==c?(e=e=>e.id!==n&&!c.includes(e.id),t[4]=n,t[5]=c,t[6]=e):e=t[6],m=l.filter(e),t[0]=l,t[1]=n,t[2]=c,t[3]=m}else m=t[3];let h=m,g=f?`回退顺序`:`Fallback order`,_;t[7]===g?_=t[8]:(_=(0,s.jsx)(`h4`,{className:`text-sm font-medium text-fg`,children:g}),t[7]=g,t[8]=_);let v=f?`主模型不可用时,按从左到右的顺序尝试。`:`Tried from left to right when the primary model is unavailable.`,y;t[9]===v?y=t[10]:(y=(0,s.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:v}),t[9]=v,t[10]=y);let b;t[11]!==_||t[12]!==y?(b=(0,s.jsx)(`div`,{className:`flex items-center justify-between gap-3`,children:(0,s.jsxs)(`div`,{children:[_,y]})}),t[11]=_,t[12]=y,t[13]=b):b=t[13];let x;t[14]!==l||t[15]!==p||t[16]!==c||t[17]!==f?(x=c.length>0?(0,s.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:c.map((e,t)=>(0,s.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full bg-surface-base/70 py-1 pl-2.5 pr-1 text-xs text-fg`,children:[(0,s.jsx)(`span`,{className:`text-fg-subtle`,children:t+1}),(0,s.jsx)(`span`,{children:l.find(t=>t.id===e)?.name??e}),(0,s.jsx)(`button`,{type:`button`,"aria-label":f?`移除 ${e}`:`Remove ${e}`,className:`rounded-full p-1 text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>p(c.filter(t=>t!==e)),children:(0,s.jsx)(r,{className:`size-3`})})]},e))}):(0,s.jsx)(`p`,{className:`mt-3 text-xs text-fg-subtle`,children:f?`未设置回退模型。`:`No fallback models configured.`}),t[14]=l,t[15]=p,t[16]=c,t[17]=f,t[18]=x):x=t[18];let S;t[19]!==h||t[20]!==d||t[21]!==u||t[22]!==p||t[23]!==c||t[24]!==f?(S=u?(0,s.jsx)(i,{className:`mt-3 h-11 w-full max-w-md rounded-lg`}):(0,s.jsx)(a,{value:``,models:h,modelsLoading:u,modelsError:d,placeholder:f?`添加回退模型`:`Add fallback model`,searchPlaceholder:f?`搜索模型或服务商`:`Search models or providers`,noMatches:f?`没有可添加的模型`:`No models available to add`,showProviderInTrigger:!1,contentAlign:`start`,className:`mt-3 w-full max-w-md`,ariaLabel:f?`添加回退模型`:`Add fallback model`,onChange:e=>{e&&p([...c,e])}}),t[19]=h,t[20]=d,t[21]=u,t[22]=p,t[23]=c,t[24]=f,t[25]=S):S=t[25];let C;return t[26]!==b||t[27]!==x||t[28]!==S?(C=(0,s.jsxs)(`div`,{children:[b,x,S]}),t[26]=b,t[27]=x,t[28]=S,t[29]=C):C=t[29],C}export{c as t};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n}from"./vendor-react-BOUWij0V.js";import{a as r,r as i}from"./locale-store-DId6-v2R.js";import{i as a,o}from"./vendor-swr-BIWyz7Rc.js";var s=e(t(),1),c=n();function l(e){if(!(!e||typeof e!=`object`||!(`section`in e)))return e.section}function u(e){return l(e)===`skills`}function d(){return i(`/api/config`)}var f=null;async function p(){return f||(f=r(d()).finally(()=>{f=null}),f)}function m(e){let t=(0,c.c)(6),n;t[0]===e?n=t[1]:(n=e?d():null,t[0]=e,t[1]=n);let r=n,i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i={revalidateOnFocus:!1},t[2]=i):i=t[2];let l=a(r,p,i),f,m;return t[3]===e?(f=t[4],m=t[5]):(f=()=>{if(!e)return;let t=d(),n=e=>{u(e.detail)||o(t)};return window.addEventListener(`config-reload`,n),()=>window.removeEventListener(`config-reload`,n)},m=[e],t[3]=e,t[4]=f,t[5]=m),(0,s.useEffect)(f,m),l}function h(){return o(d())}export{u as a,l as i,h as n,m as r,p as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n}from"./vendor-react-BOUWij0V.js";import{a as r,r as i}from"./locale-store-CvNO-hbt.js";import{i as a,o}from"./vendor-swr-BIWyz7Rc.js";var s=e(t(),1),c=n();function l(e){if(!(!e||typeof e!=`object`||!(`section`in e)))return e.section}function u(e){return l(e)===`skills`}function d(){return i(`/api/config`)}var f=null;async function p(){return f||(f=r(d()).finally(()=>{f=null}),f)}function m(e){let t=(0,c.c)(6),n;t[0]===e?n=t[1]:(n=e?d():null,t[0]=e,t[1]=n);let r=n,i;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(i={revalidateOnFocus:!1},t[2]=i):i=t[2];let l=a(r,p,i),f,m;return t[3]===e?(f=t[4],m=t[5]):(f=()=>{if(!e)return;let t=d(),n=e=>{u(e.detail)||o(t)};return window.addEventListener(`config-reload`,n),()=>window.removeEventListener(`config-reload`,n)},m=[e],t[3]=e,t[4]=f,t[5]=m),(0,s.useEffect)(f,m),l}function h(){return o(d())}export{u as a,l as i,h as n,m as r,p as t};
@@ -1 +1 @@
1
- import{r as e}from"./locale-store-DId6-v2R.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-DBvCRclh.js";var m=25*1024*1024,h=u([`web`,`desktop`,`mobile`,`browser`]),g=u([`foreground`,`background`]),_=u([`read`,`write`,`destructive`]),ee=u([`never`,`always`]),te=u([`text`,`json`,`file`]),ne=u([`public`,`personal`]),v=s().min(1).max(160),re=s().min(32).max(160).regex(/^[A-Za-z0-9_-]+$/);t(`type`,[r({type:l(`endpoint`),endpointId:v}),r({type:l(`channel`),channel:s().min(1).max(64)}),r({type:l(`system`),source:u([`cli`,`automation`,`heartbeat`,`workflow`,`internal`,`task_update`])})]).options[0].extend({token:re});var ie=f(),y=o().int().nonnegative(),b=n(s(),i()),x=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:b,outputSchema:b,policyId:s().regex(/^[a-z][a-z0-9_.-]+$/).max(120),sensitivity:ne,effect:_,confirmation:ee,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(te).min(1).max(3)});r({principalId:v,displayName:s().min(1).max(120),kind:h,platform:s().min(1).max(80),publicKey:s().min(32).max(2048)}),r({endpointId:v});var S=s().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120);r({jobId:f(),endpointId:v,capability:S,input:b,idempotencyKey:v,consentGrantId:v,createdAt:y,expiresAt:y}),r({jobId:f(),status:u([`queued`,`running`,`succeeded`,`failed`,`cancelled`]),updatedAt:y,output:b.optional(),error:r({code:v,message:s().min(1).max(2e3)}).optional()}),r({eventId:f(),endpointId:v,subscriptionId:v,eventType:S,data:b,occurredAt:y});var C=r({principalId:v,endpointId:v,connectionInstanceId:f(),displayName:s().min(1).max(120),kind:h,platform:s().min(1).max(80),appVersion:s().min(1).max(80),availability:g,nonce:v,signedAt:y,signature:s().min(16).max(1024),tools:c(x).max(100)}),w=r({invocationId:f(),toolCallId:v,toolName:x.shape.name,arguments:b,descriptorRevision:s().min(1).max(128),confirmationRequired:a(),deadlineAt:y,uploadGrant:r({path:s().startsWith(`/`).max(500),token:v,maxBytes:o().int().positive(),maxFiles:o().int().min(1).max(20),expiresAt:y}).optional()}),ae=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:v,name:s().min(1).max(255),mimeType:s().min(1).max(255),size:o().int().nonnegative(),sha256:s().regex(/^[a-f0-9]{64}$/)})]),D=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`]),O=(e,t)=>r({protocolVersion:l(2),messageId:ie,type:l(e),sentAt:y,payload:t}),oe=t(`type`,[O(`endpoint.availability_changed`,r({availability:g})),O(`tool.received`,T),O(`tool.progress`,r({invocationId:f(),message:s().max(500).optional(),percent:o().min(0).max(100).optional()})),O(`tool.result`,r({invocationId:f(),content:c(E).min(1).max(20),details:b.optional()})),O(`tool.error`,r({invocationId:f(),code:D,message:s().min(1).max(2e3)})),O(`tool.cancelled`,T)]),se=t(`type`,[O(`tool.invoke`,w),O(`tool.cancel`,ae)]),ce={type:`array`,minItems:1,maxItems:20,items:{type:`object`,additionalProperties:!1,required:[`type`,`text`],properties:{type:{const:`text`},text:{type:`string`,maxLength:256*1024}}}},le={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}$`}}}};function k(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(k).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)}:${k(n[e])}`).join(`,`)}}`}function A(e){let{signature:t,...n}=e;return k(n)}var j=256*1024,M=15e3,N=45e3,P=[`realtime.capability-negotiation.v1`],F=u([`web`,`desktop`,`mobile`,`browser_extension`,`tui`,`mcp`]),I=s().min(1).max(512),L=s().regex(/^[a-z][a-z0-9_.-]*$/).max(160),R=f(),z=o().int().nonnegative(),B=o().int().positive(),V=s().min(1).max(160),H=(e,t)=>d({protocolVersion:l(2),messageId:R,kind:l(e),sentAt:z,payload:t}),U=d({topic:I,afterSeq:o().int().nonnegative().optional(),view:l(`compact`).optional()});t(`kind`,[H(`realtime.hello`,d({ticket:s().min(32).max(512),clientId:s().min(1).max(160),clientKind:F,subscriptions:c(U).max(100).default([]),capabilities:c(V).max(64).optional(),endpoint:C.optional()})),H(`realtime.subscribe`,d({subscriptions:c(U).min(1).max(100)})),H(`realtime.unsubscribe`,d({topics:c(I).min(1).max(100)})),H(`realtime.ping`,d({})),H(`endpoint.message`,oe)]);var W=d({topic:I,seq:B,event:L,data:i()}),ue=t(`kind`,[H(`realtime.ready`,d({connectionId:f(),heartbeatIntervalMs:l(M),heartbeatTimeoutMs:l(N),negotiatedCapabilities:c(V).max(64).optional(),endpoint:d({endpointId:s().min(1).max(160),turnToken:s().min(32).max(160)}).optional()})),H(`realtime.event`,W),H(`realtime.subscribed`,d({topic:I,cursor:o().int().nonnegative()})),H(`realtime.gap`,d({topic:I,requestedSeq:o().int().nonnegative(),earliestSeq:B,recoverable:a()})),H(`realtime.pong`,d({})),H(`realtime.error`,d({code:s().min(1).max(80),message:s().min(1).max(500)})),H(`endpoint.message`,se)]);function de(e){return ue.parse(e)}var G=class extends Error{retryable;constructor(e,t){super(e),this.retryable=t,this.name=`RealtimeConnectionError`}},fe=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 pe(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 me(e){return e===1009||e===4400||e===4401||e===4409||e===4413}var he=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 G(`CLIENT_UPDATE_REQUIRED`,!1);if(2>e.realtime.maxVersion)throw new G(`GATEWAY_UPDATE_REQUIRED`,!1);let l=P.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(pe(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})`,!me(e.code))}}catch(e){s(e instanceof Error?e.message:`Realtime connection failed`,!(e instanceof G)||e.retryable)}}handleServerMessage(e){let t=de(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 fe(n,j);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}},ge=500,K=null,q;function J(e){q=e,K!==null&&clearTimeout(K),K=setTimeout(()=>{K=null;let e=q;q=void 0,window.dispatchEvent(new CustomEvent(`config-reload`,{detail:e}))},ge)}function _e(e,t){if(e===`config.reload`){J(t);return}window.dispatchEvent(new CustomEvent(e.replace(/[._]/g,`-`),{detail:t}))}var Y=new Map,X=new Map,Z,Q;function $(){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 ve(){let t=new URL(e(`/api/realtime/v1/ws`));return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()}function ye(){let t=$(),n=window.electronAPI?`desktop`:`web`,r=new he({clientId:t,clientKind:n,getWebSocketUrl:ve,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`)&&_e(e.event,e.data);let t=X.get(e.topic);(t===void 0||e.seq>t)&&X.set(e.topic,e.seq);for(let t of Y.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=[...Y.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)}});Z?.disconnect(),Z=r,Q&&r.setEndpoint(Q),r.subscribe(`gateway`,X.get(`gateway`)),r.subscribe(`sessions`,X.get(`sessions`));for(let e of Y.keys())r.subscribe(e,X.get(e));return p({connectionState:`connecting`,error:null}),r.connect(),()=>{Z===r&&(r.disconnect(),Z=void 0)}}function be(e){return Q=e,Z?.setEndpoint(e),()=>{Q===e&&(Q=void 0,Z?.clearEndpoint(e))}}function xe(e){Z?.sendEndpointMessage(e)}function Se(){Z?.reconnect()}function Ce(e,t,n){let r=Y.get(e)??new Set,i=r.size===0,a=X.get(e),o={listener:t,cursor:n??a};if(r.add(o),Y.set(e,r),i){let t=n??a;X.set(e,t),Z?.subscribe(e,t)}else n!==void 0&&(a===void 0||n<a)&&Z?.subscribe(e,n);return()=>{let t=Y.get(e);t?.delete(o),(!t||t.size===0)&&(Y.delete(e),X.delete(e),Z?.unsubscribe(e))}}export{Ce as a,m as c,A as d,E as f,ye as i,ce as l,Se as n,J as o,xe as r,le as s,be as t,k as u};
1
+ import{r as e}from"./locale-store-CvNO-hbt.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-DeUVEPPE.js";var m=25*1024*1024,h=u([`web`,`desktop`,`mobile`,`browser`]),g=u([`foreground`,`background`]),_=u([`read`,`write`,`destructive`]),ee=u([`never`,`always`]),te=u([`text`,`json`,`file`]),ne=u([`public`,`personal`]),v=s().min(1).max(160),re=s().min(32).max(160).regex(/^[A-Za-z0-9_-]+$/);t(`type`,[r({type:l(`endpoint`),endpointId:v}),r({type:l(`channel`),channel:s().min(1).max(64)}),r({type:l(`system`),source:u([`cli`,`automation`,`heartbeat`,`workflow`,`internal`,`task_update`])})]).options[0].extend({token:re});var ie=f(),y=o().int().nonnegative(),b=n(s(),i()),x=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:b,outputSchema:b,policyId:s().regex(/^[a-z][a-z0-9_.-]+$/).max(120),sensitivity:ne,effect:_,confirmation:ee,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(te).min(1).max(3)});r({principalId:v,displayName:s().min(1).max(120),kind:h,platform:s().min(1).max(80),publicKey:s().min(32).max(2048)}),r({endpointId:v});var S=s().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120);r({jobId:f(),endpointId:v,capability:S,input:b,idempotencyKey:v,consentGrantId:v,createdAt:y,expiresAt:y}),r({jobId:f(),status:u([`queued`,`running`,`succeeded`,`failed`,`cancelled`]),updatedAt:y,output:b.optional(),error:r({code:v,message:s().min(1).max(2e3)}).optional()}),r({eventId:f(),endpointId:v,subscriptionId:v,eventType:S,data:b,occurredAt:y});var C=r({principalId:v,endpointId:v,connectionInstanceId:f(),displayName:s().min(1).max(120),kind:h,platform:s().min(1).max(80),appVersion:s().min(1).max(80),availability:g,nonce:v,signedAt:y,signature:s().min(16).max(1024),tools:c(x).max(100)}),w=r({invocationId:f(),toolCallId:v,toolName:x.shape.name,arguments:b,descriptorRevision:s().min(1).max(128),confirmationRequired:a(),deadlineAt:y,uploadGrant:r({path:s().startsWith(`/`).max(500),token:v,maxBytes:o().int().positive(),maxFiles:o().int().min(1).max(20),expiresAt:y}).optional()}),ae=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:v,name:s().min(1).max(255),mimeType:s().min(1).max(255),size:o().int().nonnegative(),sha256:s().regex(/^[a-f0-9]{64}$/)})]),D=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`]),O=(e,t)=>r({protocolVersion:l(2),messageId:ie,type:l(e),sentAt:y,payload:t}),oe=t(`type`,[O(`endpoint.availability_changed`,r({availability:g})),O(`tool.received`,T),O(`tool.progress`,r({invocationId:f(),message:s().max(500).optional(),percent:o().min(0).max(100).optional()})),O(`tool.result`,r({invocationId:f(),content:c(E).min(1).max(20),details:b.optional()})),O(`tool.error`,r({invocationId:f(),code:D,message:s().min(1).max(2e3)})),O(`tool.cancelled`,T)]),se=t(`type`,[O(`tool.invoke`,w),O(`tool.cancel`,ae)]),ce={type:`array`,minItems:1,maxItems:20,items:{type:`object`,additionalProperties:!1,required:[`type`,`text`],properties:{type:{const:`text`},text:{type:`string`,maxLength:256*1024}}}},le={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}$`}}}};function k(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(k).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)}:${k(n[e])}`).join(`,`)}}`}function A(e){let{signature:t,...n}=e;return k(n)}var j=256*1024,M=15e3,N=45e3,P=[`realtime.capability-negotiation.v1`],F=u([`web`,`desktop`,`mobile`,`browser_extension`,`tui`,`mcp`]),I=s().min(1).max(512),L=s().regex(/^[a-z][a-z0-9_.-]*$/).max(160),R=f(),z=o().int().nonnegative(),B=o().int().positive(),V=s().min(1).max(160),H=(e,t)=>d({protocolVersion:l(2),messageId:R,kind:l(e),sentAt:z,payload:t}),U=d({topic:I,afterSeq:o().int().nonnegative().optional(),view:l(`compact`).optional()});t(`kind`,[H(`realtime.hello`,d({ticket:s().min(32).max(512),clientId:s().min(1).max(160),clientKind:F,subscriptions:c(U).max(100).default([]),capabilities:c(V).max(64).optional(),endpoint:C.optional()})),H(`realtime.subscribe`,d({subscriptions:c(U).min(1).max(100)})),H(`realtime.unsubscribe`,d({topics:c(I).min(1).max(100)})),H(`realtime.ping`,d({})),H(`endpoint.message`,oe)]);var W=d({topic:I,seq:B,event:L,data:i()}),ue=t(`kind`,[H(`realtime.ready`,d({connectionId:f(),heartbeatIntervalMs:l(M),heartbeatTimeoutMs:l(N),negotiatedCapabilities:c(V).max(64).optional(),endpoint:d({endpointId:s().min(1).max(160),turnToken:s().min(32).max(160)}).optional()})),H(`realtime.event`,W),H(`realtime.subscribed`,d({topic:I,cursor:o().int().nonnegative()})),H(`realtime.gap`,d({topic:I,requestedSeq:o().int().nonnegative(),earliestSeq:B,recoverable:a()})),H(`realtime.pong`,d({})),H(`realtime.error`,d({code:s().min(1).max(80),message:s().min(1).max(500)})),H(`endpoint.message`,se)]);function de(e){return ue.parse(e)}var G=class extends Error{retryable;constructor(e,t){super(e),this.retryable=t,this.name=`RealtimeConnectionError`}},fe=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 pe(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 me(e){return e===1009||e===4400||e===4401||e===4409||e===4413}var he=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 G(`CLIENT_UPDATE_REQUIRED`,!1);if(2>e.realtime.maxVersion)throw new G(`GATEWAY_UPDATE_REQUIRED`,!1);let l=P.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(pe(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})`,!me(e.code))}}catch(e){s(e instanceof Error?e.message:`Realtime connection failed`,!(e instanceof G)||e.retryable)}}handleServerMessage(e){let t=de(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 fe(n,j);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}},ge=500,K=null,q;function J(e){q=e,K!==null&&clearTimeout(K),K=setTimeout(()=>{K=null;let e=q;q=void 0,window.dispatchEvent(new CustomEvent(`config-reload`,{detail:e}))},ge)}function _e(e,t){if(e===`config.reload`){J(t);return}window.dispatchEvent(new CustomEvent(e.replace(/[._]/g,`-`),{detail:t}))}var Y=new Map,X=new Map,Z,Q;function $(){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 ve(){let t=new URL(e(`/api/realtime/v1/ws`));return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()}function ye(){let t=$(),n=window.electronAPI?`desktop`:`web`,r=new he({clientId:t,clientKind:n,getWebSocketUrl:ve,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`)&&_e(e.event,e.data);let t=X.get(e.topic);(t===void 0||e.seq>t)&&X.set(e.topic,e.seq);for(let t of Y.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=[...Y.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)}});Z?.disconnect(),Z=r,Q&&r.setEndpoint(Q),r.subscribe(`gateway`,X.get(`gateway`)),r.subscribe(`sessions`,X.get(`sessions`));for(let e of Y.keys())r.subscribe(e,X.get(e));return p({connectionState:`connecting`,error:null}),r.connect(),()=>{Z===r&&(r.disconnect(),Z=void 0)}}function be(e){return Q=e,Z?.setEndpoint(e),()=>{Q===e&&(Q=void 0,Z?.clearEndpoint(e))}}function xe(e){Z?.sendEndpointMessage(e)}function Se(){Z?.reconnect()}function Ce(e,t,n){let r=Y.get(e)??new Set,i=r.size===0,a=X.get(e),o={listener:t,cursor:n??a};if(r.add(o),Y.set(e,r),i){let t=n??a;X.set(e,t),Z?.subscribe(e,t)}else n!==void 0&&(a===void 0||n<a)&&Z?.subscribe(e,n);return()=>{let t=Y.get(e);t?.delete(o),(!t||t.size===0)&&(Y.delete(e),X.delete(e),Z?.unsubscribe(e))}}export{Ce as a,m as c,A as d,E as f,ye as i,ce as l,Se as n,J as o,xe as r,le as s,be as t,k as u};
@@ -0,0 +1 @@
1
+ import{p as e}from"./locale-store-CvNO-hbt.js";var t=e(()=>({connectionState:`idle`,error:null}));function n(e){t.setState(e)}export{t as n,n as t};