@xopcai/xopc 0.0.307 → 0.0.309

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 (261) hide show
  1. package/dist/browser-ext/_locales/en/messages.json +8 -0
  2. package/dist/browser-ext/_locales/zh_CN/messages.json +8 -0
  3. package/dist/browser-ext/dist/assets/{sidepanel-BbSQr-6P.css → sidepanel-DD6GEMvc.css} +16 -0
  4. package/dist/browser-ext/dist/sidepanel.html +1 -1
  5. package/dist/browser-ext/dist/sidepanel.js +537 -96
  6. package/dist/browser-ext/manifest.json +1 -1
  7. package/dist/extensions/telegram/xopc.extension.json +1 -1
  8. package/dist/gateway/static/root/assets/{activity-store-wgSB2HYK.js → activity-store-XKNYlFUI.js} +1 -1
  9. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-CZeQo09T.js → agent-avatar-dicebear-1S2TFECE.js} +1 -1
  10. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-f0-YFMUz.js +1 -0
  11. package/dist/gateway/static/root/assets/{agents-BlrHMbRx.js → agents-CPqUMtCL.js} +1 -1
  12. package/dist/gateway/static/root/assets/{api-BKHmTb0w.js → api-BEUEE4f2.js} +1 -1
  13. package/dist/gateway/static/root/assets/api-CN4id43t.js +1 -0
  14. package/dist/gateway/static/root/assets/{app-management-settings-panel-Bzw4fQP8.js → app-management-settings-panel-CgVBSqzu.js} +1 -1
  15. package/dist/gateway/static/root/assets/{appearance-settings-8GZpUXva.js → appearance-settings-CoWdCokb.js} +1 -1
  16. package/dist/gateway/static/root/assets/{apps-page-BkQQtIxH.js → apps-page-CexHOcWg.js} +1 -1
  17. package/dist/gateway/static/root/assets/{archive-plugin-CQ2NaoHb.js → archive-plugin-C3ZA6LRS.js} +1 -1
  18. package/dist/gateway/static/root/assets/{attachment-load-BFi1H7yJ.js → attachment-load-CdgS6_zy.js} +1 -1
  19. package/dist/gateway/static/root/assets/{automations-page-CDBXcii_.js → automations-page-BtHL2hpg.js} +1 -1
  20. package/dist/gateway/static/root/assets/automations-workspace-onJPfmO6.js +6 -0
  21. package/dist/gateway/static/root/assets/{binary-plugins-D07eWmOx.js → binary-plugins-CiDhtq_H.js} +1 -1
  22. package/dist/gateway/static/root/assets/{block-editor-CtVnjyYU.js → block-editor-Br00T83w.js} +3 -3
  23. package/dist/gateway/static/root/assets/{browser-automation-inputs-BzkJog8e.js → browser-automation-inputs-D2tILykA.js} +1 -1
  24. package/dist/gateway/static/root/assets/{browser-automations-page-DyrSbDdG.js → browser-automations-page-BVuEmryB.js} +1 -1
  25. package/dist/gateway/static/root/assets/browser-settings-page-BgVTyPFY.js +3 -0
  26. package/dist/gateway/static/root/assets/capabilities-settings-panel-Dra8wj1S.js +8 -0
  27. package/dist/gateway/static/root/assets/{channels-settings-DAD9qE3J.js → channels-settings-CkxiMDJ4.js} +1 -1
  28. package/dist/gateway/static/root/assets/{channels-status-swr-B2JwuTjG.js → channels-status-swr-Dtder4G_.js} +1 -1
  29. package/dist/gateway/static/root/assets/{chat-terminal-dock-B62SZdAo.js → chat-terminal-dock-JsMtzDao.js} +1 -1
  30. package/dist/gateway/static/root/assets/{computer-settings-page-ClSresNq.js → computer-settings-page-DHerePwo.js} +1 -1
  31. package/dist/gateway/static/root/assets/connector-service-page-DZFNUTiN.js +1 -0
  32. package/dist/gateway/static/root/assets/connectors-page-cl9ZrV4D.js +2 -0
  33. package/dist/gateway/static/root/assets/{cron-expression-CTMi_tql.js → cron-expression-DAhdv_Xv.js} +1 -1
  34. package/dist/gateway/static/root/assets/{date-picker-B71AJK50.js → date-picker-PacO1m3a.js} +1 -1
  35. package/dist/gateway/static/root/assets/{dependency-picker-DlyGK-kA.js → dependency-picker-B-BcuG1y.js} +1 -1
  36. package/dist/gateway/static/root/assets/{desktop-pet-DGkbTE8_.js → desktop-pet-CdBBhhdY.js} +1 -1
  37. package/dist/gateway/static/root/assets/{desktop-pet-settings-BY8r9j66.js → desktop-pet-settings-Gy03NgMI.js} +1 -1
  38. package/dist/gateway/static/root/assets/{device-pairing-wizard-DzRrgd59.js → device-pairing-wizard-aV25nKag.js} +1 -1
  39. package/dist/gateway/static/root/assets/{extension-debug-page-L8Mm1n3A.js → extension-debug-page-BFp5eKtY.js} +1 -1
  40. package/dist/gateway/static/root/assets/{extension-page-CFc4vSNU.js → extension-page-DL3vyyH6.js} +1 -1
  41. package/dist/gateway/static/root/assets/{extension-settings-page-B5zWyHr3.js → extension-settings-page-BXtvdAsY.js} +1 -1
  42. package/dist/gateway/static/root/assets/{gateway-config-swr-B6wHa6ZI.js → gateway-config-swr-xAOGtenO.js} +1 -1
  43. package/dist/gateway/static/root/assets/{gateway-realtime-B53R0CA4.js → gateway-realtime-BuaTsMSi.js} +1 -1
  44. package/dist/gateway/static/root/assets/gateway-realtime-store-BG95uGVW.js +1 -0
  45. package/dist/gateway/static/root/assets/{gateway-settings-D7qmTH4R.js → gateway-settings-Dcr2Ikeh.js} +1 -1
  46. package/dist/gateway/static/root/assets/{gateway-startup-retry-DRzGnEV-.js → gateway-startup-retry-BwDxKHd4.js} +1 -1
  47. package/dist/gateway/static/root/assets/{heartbeat-settings-Glsl3X5b.js → heartbeat-settings-DOy3alvT.js} +1 -1
  48. package/dist/gateway/static/root/assets/home-page-CDm3dGVy.js +1 -0
  49. package/dist/gateway/static/root/assets/{image-generation-api-Ck_pyDom.js → image-generation-api-wGMeI_yW.js} +1 -1
  50. package/dist/gateway/static/root/assets/{imports-page-ByBX7ome.js → imports-page-zexFT5Rq.js} +1 -1
  51. package/dist/gateway/static/root/assets/index-D-vczw_0.css +1 -0
  52. package/dist/gateway/static/root/assets/index-DJo4DimT.js +79 -0
  53. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-C45RlO8a.js → keyboard-shortcuts-settings-CutG9zLh.js} +1 -1
  54. package/dist/gateway/static/root/assets/{local-app-workbench-page-DP0x2jpR.js → local-app-workbench-page-CwLvTwjn.js} +2 -2
  55. package/dist/gateway/static/root/assets/{local-apps-page-C_AQc2bI.js → local-apps-page-CJy6I7Dt.js} +1 -1
  56. package/dist/gateway/static/root/assets/{locale-store-msTfRK8P.js → locale-store-DPZ79W1-.js} +1 -1
  57. package/dist/gateway/static/root/assets/{logs-page-DvM8Pyok.js → logs-page-egGcPHNi.js} +1 -1
  58. package/dist/gateway/static/root/assets/{management-settings-D1uwSutV.js → management-settings-BQhIOELc.js} +1 -1
  59. package/dist/gateway/static/root/assets/{markdown-view-BInabSKf.js → markdown-view-p2P5hP1U.js} +1 -1
  60. package/dist/gateway/static/root/assets/{media-plugins-C4mhf13f.js → media-plugins-CsBylqlN.js} +1 -1
  61. package/dist/gateway/static/root/assets/messages-BiYTyLJr.js +3 -0
  62. package/dist/gateway/static/root/assets/note-detail-panel-c2k5Uz6X.js +5 -0
  63. package/dist/gateway/static/root/assets/notes-page-BLQWJMhf.js +8 -0
  64. package/dist/gateway/static/root/assets/{page-tabs-1go_BtX1.js → page-tabs-ChQ4jJFs.js} +1 -1
  65. package/dist/gateway/static/root/assets/{preview-open-alternatives-DmoSC0j1.js → preview-open-alternatives-9B5W7nVE.js} +1 -1
  66. package/dist/gateway/static/root/assets/{proactive-page-xAjKTIID.js → proactive-page-iOjI0d_e.js} +1 -1
  67. package/dist/gateway/static/root/assets/{product-open-page-gmi5LLwM.js → product-open-page-BADxWEdP.js} +1 -1
  68. package/dist/gateway/static/root/assets/project-detail-page-BcxbQn2M.js +1 -0
  69. package/dist/gateway/static/root/assets/projects-page-BuSvld0O.js +1 -0
  70. package/dist/gateway/static/root/assets/{registry-api-BSWtko7U.js → registry-api-B_e_nZSN.js} +1 -1
  71. package/dist/gateway/static/root/assets/remote-access-hub-CFS8LQKW.js +1 -0
  72. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-ClkOoxDl.js → runtime-tools-settings-panel-D-pwiIyp.js} +1 -1
  73. package/dist/gateway/static/root/assets/{schema-form-BuEmLiaU.js → schema-form-IWmb05DX.js} +1 -1
  74. package/dist/gateway/static/root/assets/sessions-page-DZjc__ok.js +1 -0
  75. package/dist/gateway/static/root/assets/settings-advanced-gate-C1SM5B93.js +1 -0
  76. package/dist/gateway/static/root/assets/{settings-form-section-Dor39QON.js → settings-form-section-B0veRBZs.js} +1 -1
  77. package/dist/gateway/static/root/assets/{settings-page-Xj-yvIc8.js → settings-page-CxRWyWYe.js} +1 -1
  78. package/dist/gateway/static/root/assets/setup-status-panel-D9Rl7Tec.js +1 -0
  79. package/dist/gateway/static/root/assets/{share-preview-page-BFWZoXdm.js → share-preview-page-CirpgkfD.js} +1 -1
  80. package/dist/gateway/static/root/assets/shares-settings-CwCThBs0.js +1 -0
  81. package/dist/gateway/static/root/assets/skill-reload-api-DG6VGbOX.js +1 -0
  82. package/dist/gateway/static/root/assets/skills-page-BdRJ2vnL.js +2 -0
  83. package/dist/gateway/static/root/assets/{skills-page.utils-Ii8qeXhs.js → skills-page.utils-B42mpWKV.js} +1 -1
  84. package/dist/gateway/static/root/assets/{system-settings-panel-Di6OSO-0.js → system-settings-panel-DXIZpAvU.js} +1 -1
  85. package/dist/gateway/static/root/assets/task-detail-page-QXo9LJly.js +1 -0
  86. package/dist/gateway/static/root/assets/{theme-store-1SZ-HFHX.js → theme-store-BFbj_2Tu.js} +1 -1
  87. package/dist/gateway/static/root/assets/{tunnel-api-DDOlOYlj.js → tunnel-api-Db2guRdW.js} +1 -1
  88. package/dist/gateway/static/root/assets/{use-autosave-CQ8uWNnB.js → use-autosave-DDY9qoXZ.js} +1 -1
  89. package/dist/gateway/static/root/assets/user-model-page-CzPmMkaO.js +2 -0
  90. package/dist/gateway/static/root/assets/{voice-api-key-field-COTzshjL.js → voice-api-key-field-BZbKQ8HT.js} +1 -1
  91. package/dist/gateway/static/root/assets/{voice-config-api-DgJML_uM.js → voice-config-api-SKCeQLrH.js} +1 -1
  92. package/dist/gateway/static/root/assets/{work-discovery-overlay-_URrXbi4.js → work-discovery-overlay-BRVTTXNG.js} +1 -1
  93. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-CALs-1nd.js → workflow-run-setup-panel-D2kuwv5e.js} +2 -2
  94. package/dist/gateway/static/root/assets/workflows-page-CQXtiYtq.js +6 -0
  95. package/dist/gateway/static/root/index.html +12 -12
  96. package/dist/package.js +1 -1
  97. package/dist/packages/gateway-contract/src/notifications.js +1 -1
  98. package/dist/packages/gateway-contract/src/sessions.js +6 -1
  99. package/dist/src/agent/agent-manager.js +29 -4
  100. package/dist/src/agent/background-review/prompts.js +3 -1
  101. package/dist/src/agent/child-agent-factory.d.ts +1 -0
  102. package/dist/src/agent/child-agent-factory.js +18 -4
  103. package/dist/src/agent/coding/repository-instructions.d.ts +4 -0
  104. package/dist/src/agent/coding/repository-instructions.js +46 -2
  105. package/dist/src/agent/context/execution-context.js +4 -4
  106. package/dist/src/agent/data-acquisition/git.d.ts +17 -0
  107. package/dist/src/agent/data-acquisition/git.js +100 -0
  108. package/dist/src/agent/data-acquisition/render.d.ts +7 -0
  109. package/dist/src/agent/data-acquisition/render.js +79 -0
  110. package/dist/src/agent/data-acquisition/scheduler.d.ts +12 -0
  111. package/dist/src/agent/data-acquisition/scheduler.js +53 -0
  112. package/dist/src/agent/data-acquisition/schema.d.ts +75 -0
  113. package/dist/src/agent/data-acquisition/schema.js +206 -0
  114. package/dist/src/agent/data-acquisition/service.d.ts +10 -0
  115. package/dist/src/agent/data-acquisition/service.js +292 -0
  116. package/dist/src/agent/data-acquisition/types.d.ts +37 -0
  117. package/dist/src/agent/data-acquisition/types.js +5 -0
  118. package/dist/src/agent/embedded/run-turn.js +16 -4
  119. package/dist/src/agent/embedded/session-runner.d.ts +1 -0
  120. package/dist/src/agent/embedded/session-runner.js +3 -0
  121. package/dist/src/agent/embedded/tool-result-truncation.js +11 -0
  122. package/dist/src/agent/embedded/xopc-tools-bridge.js +2 -1
  123. package/dist/src/agent/external-tools/composio-provider.js +12 -1
  124. package/dist/src/agent/external-tools/gateway-tools.js +2 -1
  125. package/dist/src/agent/external-tools/index.js +8 -1
  126. package/dist/src/agent/external-tools/read-policy.d.ts +6 -0
  127. package/dist/src/agent/external-tools/read-policy.js +21 -0
  128. package/dist/src/agent/external-tools/service.d.ts +1 -0
  129. package/dist/src/agent/external-tools/service.js +4 -1
  130. package/dist/src/agent/external-tools/types.d.ts +2 -0
  131. package/dist/src/agent/memory/compaction-promotion.d.ts +1 -1
  132. package/dist/src/agent/memory/compaction-promotion.js +4 -3
  133. package/dist/src/agent/orchestration/agent-turn-policy.js +25 -10
  134. package/dist/src/agent/orchestration/delegation-scope.d.ts +9 -0
  135. package/dist/src/agent/orchestration/delegation-scope.js +11 -0
  136. package/dist/src/agent/prompt/sections/tooling.js +3 -1
  137. package/dist/src/agent/prompt/subagent-context.js +4 -2
  138. package/dist/src/agent/sandbox/fileAccess.d.ts +2 -0
  139. package/dist/src/agent/sandbox/fileAccess.js +31 -2
  140. package/dist/src/agent/tools/dataBatch.d.ts +4 -0
  141. package/dist/src/agent/tools/dataBatch.js +50 -0
  142. package/dist/src/agent/tools/delegate-tool.d.ts +6 -3
  143. package/dist/src/agent/tools/delegate-tool.js +65 -48
  144. package/dist/src/agent/tools/delegation-parent-policy.d.ts +7 -0
  145. package/dist/src/agent/tools/delegation-parent-policy.js +41 -0
  146. package/dist/src/agent/tools/delegation-policy.d.ts +16 -0
  147. package/dist/src/agent/tools/delegation-policy.js +93 -0
  148. package/dist/src/agent/tools/factory.d.ts +2 -0
  149. package/dist/src/agent/tools/factory.js +42 -3
  150. package/dist/src/agent/tools/fetch-text.d.ts +7 -0
  151. package/dist/src/agent/tools/fetch-text.js +86 -0
  152. package/dist/src/agent/tools/find.js +1 -1
  153. package/dist/src/agent/tools/grep.js +11 -23
  154. package/dist/src/agent/tools/index.d.ts +1 -0
  155. package/dist/src/agent/tools/index.js +2 -1
  156. package/dist/src/agent/tools/knowledge-memory-tool.d.ts +1 -1
  157. package/dist/src/agent/tools/knowledge-memory-tool.js +13 -5
  158. package/dist/src/agent/tools/read.js +7 -5
  159. package/dist/src/agent/tools/repository-search.d.ts +12 -2
  160. package/dist/src/agent/tools/repository-search.js +127 -74
  161. package/dist/src/agent/tools/user-context-tool.js +17 -7
  162. package/dist/src/agent/tools/web.js +19 -28
  163. package/dist/src/agent/workflow/subagent-runner.js +25 -3
  164. package/dist/src/agent/workflow/workflow-child-tools.js +13 -8
  165. package/dist/src/agent-config/schema.d.ts +7 -0
  166. package/dist/src/agent-config/schema.js +2 -0
  167. package/dist/src/chat-commands/builtins/understanding.js +1 -1
  168. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  169. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  170. package/dist/src/config/schema.d.ts +6 -4
  171. package/dist/src/config/schema.js +2 -2
  172. package/dist/src/connectors/connected-source-understanding.d.ts +1 -0
  173. package/dist/src/connectors/connected-source-understanding.js +1 -0
  174. package/dist/src/connectors/learning-coordinator.js +31 -9
  175. package/dist/src/gateway/agent-builtin-tools.d.ts +1 -1
  176. package/dist/src/gateway/heartbeat/service.js +2 -2
  177. package/dist/src/gateway/hono/lib/config-payload.d.ts +4 -2
  178. package/dist/src/gateway/hono/routes/connectors.js +1 -1
  179. package/dist/src/gateway/hono/routes/context-sources.js +0 -23
  180. package/dist/src/gateway/hono/routes/lazy-bundles.js +8 -0
  181. package/dist/src/gateway/hono/routes/projects.js +8 -0
  182. package/dist/src/gateway/hono/routes/sessions.js +141 -13
  183. package/dist/src/gateway/hono/routes/user-model-refresh.d.ts +5 -0
  184. package/dist/src/gateway/hono/routes/user-model-refresh.js +128 -0
  185. package/dist/src/gateway/hono/routes/user-model.js +12 -5
  186. package/dist/src/gateway/hono/routes/work-discovery.js +0 -30
  187. package/dist/src/gateway/service.js +6 -6
  188. package/dist/src/heartbeat/index.js +1 -1
  189. package/dist/src/infra/update-restart.js +1 -1
  190. package/dist/src/knowledge/connected-knowledge-pipeline.js +1 -1
  191. package/dist/src/knowledge-memory/index.js +2 -2
  192. package/dist/src/knowledge-memory/repository.d.ts +7 -0
  193. package/dist/src/knowledge-memory/repository.js +58 -8
  194. package/dist/src/memory-maintenance/service.js +61 -31
  195. package/dist/src/migrations/memory-config.d.ts +2 -0
  196. package/dist/src/migrations/memory-config.js +77 -0
  197. package/dist/src/migrations/runner.js +2 -2
  198. package/dist/src/notifications/planner.js +5 -5
  199. package/dist/src/notifications/service.d.ts +2 -2
  200. package/dist/src/notifications/service.js +1 -1
  201. package/dist/src/storage/sqlite/index.d.ts +1 -0
  202. package/dist/src/storage/sqlite/index.js +2 -1
  203. package/dist/src/storage/sqlite/migrations/184_memory_suppressions.sql +12 -0
  204. package/dist/src/storage/sqlite/migrations/185_understanding_refresh_batches.sql +6 -0
  205. package/dist/src/storage/sqlite/migrations/186_sidebar_layout.sql +16 -0
  206. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  207. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  208. package/dist/src/storage/sqlite/schema.js +1 -1
  209. package/dist/src/storage/sqlite/sidebar-layout-repository.d.ts +12 -0
  210. package/dist/src/storage/sqlite/sidebar-layout-repository.js +53 -0
  211. package/dist/src/user-context/config.d.ts +4 -9
  212. package/dist/src/user-context/config.js +7 -27
  213. package/dist/src/user-context/memory-suppression.d.ts +7 -0
  214. package/dist/src/user-context/memory-suppression.js +23 -0
  215. package/dist/src/user-context/relationship-continuity.js +1 -1
  216. package/dist/src/user-context/sources/refresh-service.d.ts +48 -0
  217. package/dist/src/user-context/sources/refresh-service.js +221 -0
  218. package/dist/src/user-context/sources/repository.js +1 -1
  219. package/dist/src/user-model/bootstrap.js +27 -24
  220. package/dist/src/user-model/capture/executor.d.ts +1 -1
  221. package/dist/src/user-model/capture/executor.js +17 -11
  222. package/dist/src/user-model/capture/semantic.js +1 -1
  223. package/dist/src/user-model/domain.d.ts +6 -2
  224. package/dist/src/user-model/index.js +3 -3
  225. package/dist/src/user-model/profile.js +1 -1
  226. package/dist/src/user-model/repository.d.ts +4 -1
  227. package/dist/src/user-model/repository.js +96 -6
  228. package/dist/src/user-model/usage-policy.d.ts +2 -0
  229. package/dist/src/user-model/usage-policy.js +6 -2
  230. package/dist/src/work-discovery/project-understanding.js +2 -1
  231. package/dist/src/work-discovery/service.d.ts +8 -24
  232. package/dist/src/work-discovery/service.js +138 -180
  233. package/package.json +1 -1
  234. package/dist/gateway/static/root/assets/agent-defaults-settings-panel-BPsRb9Ck.js +0 -1
  235. package/dist/gateway/static/root/assets/api-DFOlahZv.js +0 -1
  236. package/dist/gateway/static/root/assets/automations-workspace-CUpiTTiY.js +0 -6
  237. package/dist/gateway/static/root/assets/browser-settings-page-CqTxLpil.js +0 -3
  238. package/dist/gateway/static/root/assets/capabilities-settings-panel-BZ_-pnS6.js +0 -8
  239. package/dist/gateway/static/root/assets/connector-service-page-CPqVmNvx.js +0 -1
  240. package/dist/gateway/static/root/assets/connectors-page-BUQyg3CW.js +0 -2
  241. package/dist/gateway/static/root/assets/gateway-realtime-store-BLDgrJ30.js +0 -1
  242. package/dist/gateway/static/root/assets/home-page-s9hDQ8Hc.js +0 -1
  243. package/dist/gateway/static/root/assets/index-RBCkv8a_.js +0 -79
  244. package/dist/gateway/static/root/assets/index-cFU4S35z.css +0 -1
  245. package/dist/gateway/static/root/assets/messages-F74LVAiU.js +0 -3
  246. package/dist/gateway/static/root/assets/note-detail-panel-D35sErp2.js +0 -5
  247. package/dist/gateway/static/root/assets/notes-page-8jCDklDn.js +0 -8
  248. package/dist/gateway/static/root/assets/project-detail-page-BUMQHy_N.js +0 -1
  249. package/dist/gateway/static/root/assets/projects-page-DT-Mt7XR.js +0 -1
  250. package/dist/gateway/static/root/assets/remote-access-hub-Clz3byir.js +0 -1
  251. package/dist/gateway/static/root/assets/sessions-page-tQRwktKm.js +0 -1
  252. package/dist/gateway/static/root/assets/settings-advanced-gate-DqWg9XS5.js +0 -1
  253. package/dist/gateway/static/root/assets/setup-status-panel-BB_sMB7P.js +0 -1
  254. package/dist/gateway/static/root/assets/shares-settings-oDALm4b6.js +0 -1
  255. package/dist/gateway/static/root/assets/skill-reload-api-DmwelnfK.js +0 -1
  256. package/dist/gateway/static/root/assets/skills-page-BE9JXz4U.js +0 -2
  257. package/dist/gateway/static/root/assets/task-detail-page-D1AWszc7.js +0 -1
  258. package/dist/gateway/static/root/assets/user-model-page-C00i4ea0.js +0 -2
  259. package/dist/gateway/static/root/assets/workflows-page-BUiBjz6m.js +0 -6
  260. package/dist/src/migrations/knowledge-memory-read-policy-config.d.ts +0 -2
  261. package/dist/src/migrations/knowledge-memory-read-policy-config.js +0 -48
@@ -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{t as i}from"./x-B_N4OPjy.js";import{n as a}from"./locale-store-msTfRK8P.js";import{t as o}from"./messages-F74LVAiU.js";import{Mu as s,t as c}from"./index-RBCkv8a_.js";import{t as l}from"./desktop-pet-sprite-DTqXSpqf.js";var u=e(t(),1),d=n(),f=9e4,p=3e4,m=20*6e4,h=45e3,g=45*6e4,_=58;function v(e,t){return e.state===`running`&&t-(e.startedAt??e.timestamp)>=f}function y(e,t){return e.state===`running`&&t-e.timestamp>=p}function b(e,t,n){if(e.progress){let t=`${e.progress.completed}/${e.progress.total}`;return e.action.includes(t)?``:` · ${t}`}return e.detail&&!e.action.includes(e.detail)?n.replace(/\{\{detail\}\}/g,e.detail):e.state===`running`?` · ${Math.max(1,Math.floor((t-e.timestamp)/1e3))}s`:``}function x(e,t){if(e.state!==`success`||!e.publicSummary)return;let n=e.publicSummary.replace(/\s+/g,` `).trim(),r=n.length>_?`${n.slice(0,_-1)}…`:n;return t.replace(/\{\{summary\}\}/g,r)}function S(e,t,n){if(y(e,t))return n.stale;if(v(e,t))return n.longRunning}function ee(e,t){let n=e.feedback?.reassurance;return n?t[n]:void 0}function te(e){let t=e.now-e.lastActivityAt,n=t>=m?(t-m)%g:1/0;return e.bubbleEnabled&&e.behaviorMode!==`focus`&&e.proactiveTipsEnabled&&(!e.remindersPausedUntil||e.now>=e.remindersPausedUntil)&&!e.collapsed&&e.queuedCount===0&&e.activeCount===0&&n<=h&&e.now>=e.dismissedUntil}function C(e,t,n){return e.state===`waiting`||e.state===`error`?`action_required`:e.state===`success`?t===`focus`?`ambient`:`notice`:y(e,n)||t===`playful`||t===`companion`&&v(e,n)?`notice`:`ambient`}function w(e,t,n,r){let i=C(e,t,n);return i===`action_required`?!0:r&&n<r?!1:i===`notice`}var T=8e3;function E(e,t){let n=e?.runId===t.runId,r=t.feedback?.sensitivity===`private`;return{...n?e:void 0,...t,startedAt:n?e.startedAt??e.timestamp:t.timestamp,publicSummary:r?void 0:t.publicSummary??(n?e.publicSummary:void 0),feedback:t.feedback??(n?e.feedback:void 0),expiresAt:t.state===`success`?t.timestamp+T:void 0}}function D(e,t){let n={...e};for(let e of t){let t=n[e.conversationId];t?.runId===e.runId&&e.sequence<=t.sequence||(n[e.conversationId]=E(t,e))}return n}function O(e,t){return t?.runId===e.runId&&t.state===e.state}function k(e,t){let n={error:0,waiting:1,running:2,success:3};return e.filter(e=>!e.expiresAt||e.expiresAt>t).sort((e,t)=>n[e.state]-n[t.state]||t.timestamp-e.timestamp).slice(0,3)}function A(e){return e?`/chat/${e.conversationId}`:void 0}var j=r();function M(e){return e?e.state===`error`?`concern`:e.state===`success`?`success`:e.animation??c(e.phase):`idle`}function N(e,t){if(!e?.length)return;let n=t.sequence;for(let e of`${t.conversationId}:${t.runId}`)n=n*31+e.charCodeAt(0)>>>0;return e[n%e.length]}function P(e,t,n){let r=e.persona?.phrases??n;if(t.state===`success`)return N(r?.success,t);if(t.state===`waiting`)return N(r?.waiting,t);if(t.state===`error`)return N(r?.error,t)}function F(e,t,n){return e?n?`${e} · ${t}`:e:t}function I(e,t){let n=e.feedback?.nextAction?.type;if(n===`confirm`)return t.needsInput;if(n===`review_error`)return t.reviewIssue;if(n===`open_session`)return t.open;if(e.state===`waiting`)return t.needsInput;if(e.state===`error`)return t.reviewIssue;if(e.state===`success`)return t.open}function ne(){let e=Date.now();return{prefs:{enabled:!0,showOnStartup:!1,selectedPetId:`ember`,alwaysOnTop:!0,bubbleEnabled:!0,clickThroughWhenIdle:!1,muted:!1,behaviorMode:`companion`,proactiveTipsEnabled:!0,interactionEnabled:!0,reducedMotion:!1,sizePercent:100,collapsed:!1},relationship:{firstMetAt:e,lastSeenAt:e,completedTaskCount:0,unlockedReactions:[],recentCompletedRunIds:[]},pets:[],visible:!0,customPetsDir:``,petIssues:[],activities:[]}}function L(){let e=o(a(e=>e.language)).desktopPet,[t,n]=(0,u.useState)(ne),[r,c]=(0,u.useState)({}),[d,f]=(0,u.useState)({}),[p,m]=(0,u.useState)(Date.now()),[h,_]=(0,u.useState)(()=>Date.now()),[v,y]=(0,u.useState)(0),[C,T]=(0,u.useState)(null),E=(0,u.useRef)(null),L=(0,u.useRef)(!1),R=(0,u.useRef)(null),z=(0,u.useRef)(null),B=(0,u.useRef)(null),V=(0,u.useMemo)(()=>t.pets.find(e=>e.id===t.prefs.selectedPetId)??t.pets[0],[t]),H=Math.min(1.4,Math.max(.7,t.prefs.sizePercent/100)),U=(0,u.useMemo)(()=>k(Object.values(r),p),[r,p]),W=(0,u.useMemo)(()=>t.prefs.bubbleEnabled?U.filter(e=>!O(e,d[e.conversationId])&&w(e,t.prefs.behaviorMode,p,t.prefs.remindersPausedUntil)):[],[U,d,p,t.prefs.behaviorMode,t.prefs.bubbleEnabled,t.prefs.remindersPausedUntil]),G=(0,u.useMemo)(()=>t.prefs.bubbleEnabled?U.filter(e=>O(e,d[e.conversationId])&&w(e,t.prefs.behaviorMode,p,t.prefs.remindersPausedUntil)).length:0,[U,d,p,t.prefs.behaviorMode,t.prefs.bubbleEnabled,t.prefs.remindersPausedUntil]),K=W[0]??U[0],q=p-h>20*6e4&&(new Date(p).getHours()>=23||new Date(p).getHours()<7)?`sleep`:`idle`,J=C??(K?M(K):q),Y=e.personaPhrases[V?.persona?.tone??`calm`],X=te({bubbleEnabled:t.prefs.bubbleEnabled,behaviorMode:t.prefs.behaviorMode,proactiveTipsEnabled:t.prefs.proactiveTipsEnabled,remindersPausedUntil:t.prefs.remindersPausedUntil,collapsed:t.prefs.collapsed,queuedCount:W.length,activeCount:U.length,now:p,lastActivityAt:h,dismissedUntil:v});(0,u.useEffect)(()=>{document.documentElement.dataset.desktopPet=`true`;let e=window.electronAPI?.pet;if(!e)return;let t=e=>{n(e),c(t=>D(t,e.activities))};e.getState().then(t).catch(()=>{});let r=e.onStateChanged(t),i=e.onEvent(e=>c(t=>(_(Date.now()),D(t,[e])))),a=window.setInterval(()=>m(Date.now()),1e3);return()=>{delete document.documentElement.dataset.desktopPet,r(),i(),window.clearInterval(a)}},[]),(0,u.useEffect)(()=>{if(!t.relationshipMoment)return;T(t.relationshipMoment===`first_meeting`?`wake`:`greet`);let e=window.setTimeout(()=>T(null),1400);return()=>window.clearTimeout(e)},[t.relationshipMoment]),(0,u.useLayoutEffect)(()=>{let e=R.current,t=window.electronAPI?.pet;if(!e||!t)return;let n=()=>{let e=[z.current,B.current].filter(e=>e!==null).map(e=>e.getBoundingClientRect());if(!e.length)return;let n=Math.min(...e.map(e=>e.left)),r=Math.min(...e.map(e=>e.top)),i=Math.max(...e.map(e=>e.right)),a=Math.max(...e.map(e=>e.bottom));t.setContentSize({width:Math.ceil(i-n),height:Math.ceil(a-r)})},r=new ResizeObserver(n);return r.observe(e),z.current&&r.observe(z.current),B.current&&r.observe(B.current),n(),()=>r.disconnect()},[X,W.length,t.prefs.collapsed,H]);let Z=(e=K)=>{e&&e.state!==`running`&&(window.electronAPI?.pet?.acknowledgeEvent(e.conversationId,e.runId),c(t=>{let{[e.conversationId]:n,...r}=t;return r})),window.electronAPI?.pet?.openMainWindow(A(e))},re=async()=>{if(Object.keys(d).length>0&&(f({}),!t.prefs.collapsed))return;let e=await window.electronAPI?.pet?.setPrefs({collapsed:!t.prefs.collapsed});e&&n(e)},ie=(0,u.useCallback)(e=>{e.button===0&&(E.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,moved:!1},e.currentTarget.setPointerCapture(e.pointerId),window.electronAPI?.pet?.startDrag({screenX:e.screenX,screenY:e.screenY}))},[]),ae=(0,u.useCallback)(e=>{let t=E.current;!t||t.pointerId!==e.pointerId||Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y)>4&&(t.moved=!0,T(`pickedUp`),window.electronAPI?.pet?.drag({screenX:e.screenX,screenY:e.screenY}))},[]),Q=(0,u.useCallback)(e=>{let t=E.current;!t||t.pointerId!==e.pointerId||(E.current=null,window.electronAPI?.pet?.endDrag(),t.moved&&(T(`released`),window.setTimeout(()=>T(null),700),L.current=!0,window.setTimeout(()=>{L.current=!1},0)))},[]),oe=()=>{L.current||Z()};if(!V)return null;let se={"--desktop-pet-stage-size":`${Math.round(132*H)}px`,"--desktop-pet-menu-size":`${Math.round(28*H)}px`,"--desktop-pet-menu-left":`0px`,"--desktop-pet-menu-bottom":`${Math.round(12*H)}px`},$=t.prefs.collapsed?W.length:G;return(0,j.jsxs)(`div`,{ref:R,className:`desktop-pet-window`,style:se,children:[!t.prefs.collapsed&&W.length>0?(0,j.jsx)(`div`,{ref:z,className:`desktop-pet-bubble desktop-pet-queue`,children:W.map(t=>{let n=S(t,p,{longRunning:e.tipLongRunning,stale:e.tipStaleSignal}),r=x(t,e.tipCompleteSummary),a=ee(t,{making_progress:e.petReassuranceMakingProgress,waiting_safely:e.petReassuranceWaitingSafely,completed:e.petReassuranceCompleted,work_preserved:e.petReassuranceWorkPreserved,details_available:e.petReassuranceDetailsAvailable}),o=r??n??a??t.action,s=F(P(V,t,Y),o,!!(r||n||a)),c=I(t,{open:e.viewSession,needsInput:e.petCtaNeedsInput,reviewIssue:e.petCtaReviewIssue});return(0,j.jsxs)(`div`,{className:`desktop-pet-session desktop-pet-session--${t.state}${n?` desktop-pet-session--health`:``}`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`desktop-pet-session-open`,onClick:()=>Z(t),children:[(0,j.jsx)(`span`,{className:`desktop-pet-session-dot`}),(0,j.jsxs)(`span`,{className:`desktop-pet-session-main`,children:[(0,j.jsx)(`strong`,{children:t.sessionLabel}),(0,j.jsxs)(`span`,{children:[s,r||n?``:b(t,p,e.tipTargetSuffix)]})]}),c?(0,j.jsx)(`span`,{className:`desktop-pet-session-cta`,children:c}):null]}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-session-close`,"aria-label":e.dismissSession,onClick:()=>{window.electronAPI?.pet?.acknowledgeEvent(t.conversationId,t.runId),f(e=>({...e,[t.conversationId]:{runId:t.runId,state:t.state}}))},children:(0,j.jsx)(i,{size:12})})]},t.conversationId)})}):null,X?(0,j.jsx)(`div`,{ref:z,className:`desktop-pet-bubble desktop-pet-queue desktop-pet-idle-tip`,children:(0,j.jsxs)(`div`,{className:`desktop-pet-session desktop-pet-session--idle`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`desktop-pet-session-open`,onClick:()=>Z(),children:[(0,j.jsx)(`span`,{className:`desktop-pet-session-dot`}),(0,j.jsxs)(`span`,{className:`desktop-pet-session-main`,children:[(0,j.jsx)(`strong`,{children:e.idleTipTitle}),(0,j.jsx)(`span`,{children:N(V.persona?.phrases?.greeting??Y.greeting,{conversationId:`idle`,runId:`idle`,sessionLabel:``,sequence:0,timestamp:h,state:`running`,phase:`waiting`,action:e.idleTipBody})??e.idleTipBody})]})]}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-session-close`,"aria-label":e.dismissSession,onClick:()=>y(p+g),children:(0,j.jsx)(i,{size:12})})]})}):null,(0,j.jsxs)(`div`,{ref:B,className:`desktop-pet-stage`,children:[(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-menu-button`,onClick:()=>void re(),"aria-label":e.menu,children:$>0?(0,j.jsx)(`span`,{className:`desktop-pet-tip-count`,children:Math.min(99,$)}):(0,j.jsx)(s,{className:`desktop-pet-menu-chevron size-4`})}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-hit-area`,onClick:oe,onPointerEnter:()=>{!K&&t.prefs.interactionEnabled&&t.prefs.behaviorMode===`playful`&&T(`greet`)},onPointerLeave:()=>{E.current||T(null)},onPointerDown:ie,onPointerMove:ae,onPointerUp:Q,onPointerCancel:Q,title:e.openApp,children:(0,j.jsx)(l,{pet:V,action:J,reducedMotion:t.prefs.reducedMotion,displayHeight:Math.round(112*H)})})]})]})}function R(){let e=(0,d.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,j.jsx)(L,{}),e[0]=t):t=e[0],t}export{R as DesktopPetPage};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./x-B_N4OPjy.js";import{n as a}from"./locale-store-DPZ79W1-.js";import{t as o}from"./messages-BiYTyLJr.js";import{Mu as s,t as c}from"./index-DJo4DimT.js";import{t as l}from"./desktop-pet-sprite-DTqXSpqf.js";var u=e(t(),1),d=n(),f=9e4,p=3e4,m=20*6e4,h=45e3,g=45*6e4,_=58;function v(e,t){return e.state===`running`&&t-(e.startedAt??e.timestamp)>=f}function y(e,t){return e.state===`running`&&t-e.timestamp>=p}function b(e,t,n){if(e.progress){let t=`${e.progress.completed}/${e.progress.total}`;return e.action.includes(t)?``:` · ${t}`}return e.detail&&!e.action.includes(e.detail)?n.replace(/\{\{detail\}\}/g,e.detail):e.state===`running`?` · ${Math.max(1,Math.floor((t-e.timestamp)/1e3))}s`:``}function x(e,t){if(e.state!==`success`||!e.publicSummary)return;let n=e.publicSummary.replace(/\s+/g,` `).trim(),r=n.length>_?`${n.slice(0,_-1)}…`:n;return t.replace(/\{\{summary\}\}/g,r)}function S(e,t,n){if(y(e,t))return n.stale;if(v(e,t))return n.longRunning}function ee(e,t){let n=e.feedback?.reassurance;return n?t[n]:void 0}function te(e){let t=e.now-e.lastActivityAt,n=t>=m?(t-m)%g:1/0;return e.bubbleEnabled&&e.behaviorMode!==`focus`&&e.proactiveTipsEnabled&&(!e.remindersPausedUntil||e.now>=e.remindersPausedUntil)&&!e.collapsed&&e.queuedCount===0&&e.activeCount===0&&n<=h&&e.now>=e.dismissedUntil}function C(e,t,n){return e.state===`waiting`||e.state===`error`?`action_required`:e.state===`success`?t===`focus`?`ambient`:`notice`:y(e,n)||t===`playful`||t===`companion`&&v(e,n)?`notice`:`ambient`}function w(e,t,n,r){let i=C(e,t,n);return i===`action_required`?!0:r&&n<r?!1:i===`notice`}var T=8e3;function E(e,t){let n=e?.runId===t.runId,r=t.feedback?.sensitivity===`private`;return{...n?e:void 0,...t,startedAt:n?e.startedAt??e.timestamp:t.timestamp,publicSummary:r?void 0:t.publicSummary??(n?e.publicSummary:void 0),feedback:t.feedback??(n?e.feedback:void 0),expiresAt:t.state===`success`?t.timestamp+T:void 0}}function D(e,t){let n={...e};for(let e of t){let t=n[e.conversationId];t?.runId===e.runId&&e.sequence<=t.sequence||(n[e.conversationId]=E(t,e))}return n}function O(e,t){return t?.runId===e.runId&&t.state===e.state}function k(e,t){let n={error:0,waiting:1,running:2,success:3};return e.filter(e=>!e.expiresAt||e.expiresAt>t).sort((e,t)=>n[e.state]-n[t.state]||t.timestamp-e.timestamp).slice(0,3)}function A(e){return e?`/chat/${e.conversationId}`:void 0}var j=r();function M(e){return e?e.state===`error`?`concern`:e.state===`success`?`success`:e.animation??c(e.phase):`idle`}function N(e,t){if(!e?.length)return;let n=t.sequence;for(let e of`${t.conversationId}:${t.runId}`)n=n*31+e.charCodeAt(0)>>>0;return e[n%e.length]}function P(e,t,n){let r=e.persona?.phrases??n;if(t.state===`success`)return N(r?.success,t);if(t.state===`waiting`)return N(r?.waiting,t);if(t.state===`error`)return N(r?.error,t)}function F(e,t,n){return e?n?`${e} · ${t}`:e:t}function I(e,t){let n=e.feedback?.nextAction?.type;if(n===`confirm`)return t.needsInput;if(n===`review_error`)return t.reviewIssue;if(n===`open_session`)return t.open;if(e.state===`waiting`)return t.needsInput;if(e.state===`error`)return t.reviewIssue;if(e.state===`success`)return t.open}function ne(){let e=Date.now();return{prefs:{enabled:!0,showOnStartup:!1,selectedPetId:`ember`,alwaysOnTop:!0,bubbleEnabled:!0,clickThroughWhenIdle:!1,muted:!1,behaviorMode:`companion`,proactiveTipsEnabled:!0,interactionEnabled:!0,reducedMotion:!1,sizePercent:100,collapsed:!1},relationship:{firstMetAt:e,lastSeenAt:e,completedTaskCount:0,unlockedReactions:[],recentCompletedRunIds:[]},pets:[],visible:!0,customPetsDir:``,petIssues:[],activities:[]}}function L(){let e=o(a(e=>e.language)).desktopPet,[t,n]=(0,u.useState)(ne),[r,c]=(0,u.useState)({}),[d,f]=(0,u.useState)({}),[p,m]=(0,u.useState)(Date.now()),[h,_]=(0,u.useState)(()=>Date.now()),[v,y]=(0,u.useState)(0),[C,T]=(0,u.useState)(null),E=(0,u.useRef)(null),L=(0,u.useRef)(!1),R=(0,u.useRef)(null),z=(0,u.useRef)(null),B=(0,u.useRef)(null),V=(0,u.useMemo)(()=>t.pets.find(e=>e.id===t.prefs.selectedPetId)??t.pets[0],[t]),H=Math.min(1.4,Math.max(.7,t.prefs.sizePercent/100)),U=(0,u.useMemo)(()=>k(Object.values(r),p),[r,p]),W=(0,u.useMemo)(()=>t.prefs.bubbleEnabled?U.filter(e=>!O(e,d[e.conversationId])&&w(e,t.prefs.behaviorMode,p,t.prefs.remindersPausedUntil)):[],[U,d,p,t.prefs.behaviorMode,t.prefs.bubbleEnabled,t.prefs.remindersPausedUntil]),G=(0,u.useMemo)(()=>t.prefs.bubbleEnabled?U.filter(e=>O(e,d[e.conversationId])&&w(e,t.prefs.behaviorMode,p,t.prefs.remindersPausedUntil)).length:0,[U,d,p,t.prefs.behaviorMode,t.prefs.bubbleEnabled,t.prefs.remindersPausedUntil]),K=W[0]??U[0],q=p-h>20*6e4&&(new Date(p).getHours()>=23||new Date(p).getHours()<7)?`sleep`:`idle`,J=C??(K?M(K):q),Y=e.personaPhrases[V?.persona?.tone??`calm`],X=te({bubbleEnabled:t.prefs.bubbleEnabled,behaviorMode:t.prefs.behaviorMode,proactiveTipsEnabled:t.prefs.proactiveTipsEnabled,remindersPausedUntil:t.prefs.remindersPausedUntil,collapsed:t.prefs.collapsed,queuedCount:W.length,activeCount:U.length,now:p,lastActivityAt:h,dismissedUntil:v});(0,u.useEffect)(()=>{document.documentElement.dataset.desktopPet=`true`;let e=window.electronAPI?.pet;if(!e)return;let t=e=>{n(e),c(t=>D(t,e.activities))};e.getState().then(t).catch(()=>{});let r=e.onStateChanged(t),i=e.onEvent(e=>c(t=>(_(Date.now()),D(t,[e])))),a=window.setInterval(()=>m(Date.now()),1e3);return()=>{delete document.documentElement.dataset.desktopPet,r(),i(),window.clearInterval(a)}},[]),(0,u.useEffect)(()=>{if(!t.relationshipMoment)return;T(t.relationshipMoment===`first_meeting`?`wake`:`greet`);let e=window.setTimeout(()=>T(null),1400);return()=>window.clearTimeout(e)},[t.relationshipMoment]),(0,u.useLayoutEffect)(()=>{let e=R.current,t=window.electronAPI?.pet;if(!e||!t)return;let n=()=>{let e=[z.current,B.current].filter(e=>e!==null).map(e=>e.getBoundingClientRect());if(!e.length)return;let n=Math.min(...e.map(e=>e.left)),r=Math.min(...e.map(e=>e.top)),i=Math.max(...e.map(e=>e.right)),a=Math.max(...e.map(e=>e.bottom));t.setContentSize({width:Math.ceil(i-n),height:Math.ceil(a-r)})},r=new ResizeObserver(n);return r.observe(e),z.current&&r.observe(z.current),B.current&&r.observe(B.current),n(),()=>r.disconnect()},[X,W.length,t.prefs.collapsed,H]);let Z=(e=K)=>{e&&e.state!==`running`&&(window.electronAPI?.pet?.acknowledgeEvent(e.conversationId,e.runId),c(t=>{let{[e.conversationId]:n,...r}=t;return r})),window.electronAPI?.pet?.openMainWindow(A(e))},re=async()=>{if(Object.keys(d).length>0&&(f({}),!t.prefs.collapsed))return;let e=await window.electronAPI?.pet?.setPrefs({collapsed:!t.prefs.collapsed});e&&n(e)},ie=(0,u.useCallback)(e=>{e.button===0&&(E.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,moved:!1},e.currentTarget.setPointerCapture(e.pointerId),window.electronAPI?.pet?.startDrag({screenX:e.screenX,screenY:e.screenY}))},[]),ae=(0,u.useCallback)(e=>{let t=E.current;!t||t.pointerId!==e.pointerId||Math.abs(e.clientX-t.x)+Math.abs(e.clientY-t.y)>4&&(t.moved=!0,T(`pickedUp`),window.electronAPI?.pet?.drag({screenX:e.screenX,screenY:e.screenY}))},[]),Q=(0,u.useCallback)(e=>{let t=E.current;!t||t.pointerId!==e.pointerId||(E.current=null,window.electronAPI?.pet?.endDrag(),t.moved&&(T(`released`),window.setTimeout(()=>T(null),700),L.current=!0,window.setTimeout(()=>{L.current=!1},0)))},[]),oe=()=>{L.current||Z()};if(!V)return null;let se={"--desktop-pet-stage-size":`${Math.round(132*H)}px`,"--desktop-pet-menu-size":`${Math.round(28*H)}px`,"--desktop-pet-menu-left":`0px`,"--desktop-pet-menu-bottom":`${Math.round(12*H)}px`},$=t.prefs.collapsed?W.length:G;return(0,j.jsxs)(`div`,{ref:R,className:`desktop-pet-window`,style:se,children:[!t.prefs.collapsed&&W.length>0?(0,j.jsx)(`div`,{ref:z,className:`desktop-pet-bubble desktop-pet-queue`,children:W.map(t=>{let n=S(t,p,{longRunning:e.tipLongRunning,stale:e.tipStaleSignal}),r=x(t,e.tipCompleteSummary),a=ee(t,{making_progress:e.petReassuranceMakingProgress,waiting_safely:e.petReassuranceWaitingSafely,completed:e.petReassuranceCompleted,work_preserved:e.petReassuranceWorkPreserved,details_available:e.petReassuranceDetailsAvailable}),o=r??n??a??t.action,s=F(P(V,t,Y),o,!!(r||n||a)),c=I(t,{open:e.viewSession,needsInput:e.petCtaNeedsInput,reviewIssue:e.petCtaReviewIssue});return(0,j.jsxs)(`div`,{className:`desktop-pet-session desktop-pet-session--${t.state}${n?` desktop-pet-session--health`:``}`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`desktop-pet-session-open`,onClick:()=>Z(t),children:[(0,j.jsx)(`span`,{className:`desktop-pet-session-dot`}),(0,j.jsxs)(`span`,{className:`desktop-pet-session-main`,children:[(0,j.jsx)(`strong`,{children:t.sessionLabel}),(0,j.jsxs)(`span`,{children:[s,r||n?``:b(t,p,e.tipTargetSuffix)]})]}),c?(0,j.jsx)(`span`,{className:`desktop-pet-session-cta`,children:c}):null]}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-session-close`,"aria-label":e.dismissSession,onClick:()=>{window.electronAPI?.pet?.acknowledgeEvent(t.conversationId,t.runId),f(e=>({...e,[t.conversationId]:{runId:t.runId,state:t.state}}))},children:(0,j.jsx)(i,{size:12})})]},t.conversationId)})}):null,X?(0,j.jsx)(`div`,{ref:z,className:`desktop-pet-bubble desktop-pet-queue desktop-pet-idle-tip`,children:(0,j.jsxs)(`div`,{className:`desktop-pet-session desktop-pet-session--idle`,children:[(0,j.jsxs)(`button`,{type:`button`,className:`desktop-pet-session-open`,onClick:()=>Z(),children:[(0,j.jsx)(`span`,{className:`desktop-pet-session-dot`}),(0,j.jsxs)(`span`,{className:`desktop-pet-session-main`,children:[(0,j.jsx)(`strong`,{children:e.idleTipTitle}),(0,j.jsx)(`span`,{children:N(V.persona?.phrases?.greeting??Y.greeting,{conversationId:`idle`,runId:`idle`,sessionLabel:``,sequence:0,timestamp:h,state:`running`,phase:`waiting`,action:e.idleTipBody})??e.idleTipBody})]})]}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-session-close`,"aria-label":e.dismissSession,onClick:()=>y(p+g),children:(0,j.jsx)(i,{size:12})})]})}):null,(0,j.jsxs)(`div`,{ref:B,className:`desktop-pet-stage`,children:[(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-menu-button`,onClick:()=>void re(),"aria-label":e.menu,children:$>0?(0,j.jsx)(`span`,{className:`desktop-pet-tip-count`,children:Math.min(99,$)}):(0,j.jsx)(s,{className:`desktop-pet-menu-chevron size-4`})}),(0,j.jsx)(`button`,{type:`button`,className:`desktop-pet-hit-area`,onClick:oe,onPointerEnter:()=>{!K&&t.prefs.interactionEnabled&&t.prefs.behaviorMode===`playful`&&T(`greet`)},onPointerLeave:()=>{E.current||T(null)},onPointerDown:ie,onPointerMove:ae,onPointerUp:Q,onPointerCancel:Q,title:e.openApp,children:(0,j.jsx)(l,{pet:V,action:J,reducedMotion:t.prefs.reducedMotion,displayHeight:Math.round(112*H)})})]})]})}function R(){let e=(0,d.c)(1),t;return e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,j.jsx)(L,{}),e[0]=t):t=e[0],t}export{R as DesktopPetPage};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{n as a,r as o}from"./popover-select-9i-ZtHXL.js";import{t as s}from"./external-link-DjqjBmc3.js";import{t as c}from"./cn-JdwAhgNB.js";import{n as l}from"./locale-store-msTfRK8P.js";import{t as u}from"./messages-F74LVAiU.js";import{t as d}from"./skeleton-BwbyijEw.js";import{n as f}from"./electron-env-Dit0bHgy.js";import{Gc as p,Mc as m,jc as h,ku as g,ol as _,qs as v,xs as y}from"./index-RBCkv8a_.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=u(l(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]),!f()||!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)(d,{className:`h-14 rounded-xl`}),(0,T.jsx)(d,{className:`h-14 rounded-xl`}),(0,T.jsx)(d,{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)(d,{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.jsxs)(`button`,{type:`button`,className:c(`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 disabled:opacity-50`,y.press),disabled:C,onClick:()=>void M(),children:[(0,T.jsx)(m,{className:c(`size-3.5`,C&&`animate-spin`),strokeWidth:1.75}),e.refresh]}),(0,T.jsxs)(`button`,{type:`button`,className:c(`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`,y.press),onClick:()=>void A.openCustomPetsDir(),children:[(0,T.jsx)(s,{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:c(`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`,y.press),onClick:B,children:[(0,T.jsx)(_,{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:c(`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`,y.press),onClick:()=>V(t),children:[(0,T.jsx)(p,{className:`size-3.5`,strokeWidth:1.75}),e.optimizeInChat]}),(0,T.jsx)(`button`,{type:`button`,className:c(`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`,y.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)(s,{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)(g,{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:c(`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`,y.press),onClick:()=>H(t),children:[(0,T.jsx)(_,{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:c(`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`,y.press),disabled:C,onClick:()=>void A.resetPosition().then(r),children:[(0,T.jsx)(h,{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{d as i}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{n as a,r as o}from"./popover-select-9i-ZtHXL.js";import{t as s}from"./external-link-DjqjBmc3.js";import{t as c}from"./cn-JdwAhgNB.js";import{n as l}from"./locale-store-DPZ79W1-.js";import{t as u}from"./messages-BiYTyLJr.js";import{t as d}from"./skeleton-BwbyijEw.js";import{n as f}from"./electron-env-Dit0bHgy.js";import{Gc as p,Mc as m,jc as h,ku as g,ol as _,qs as v,xs as y}from"./index-DJo4DimT.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=u(l(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]),!f()||!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)(d,{className:`h-14 rounded-xl`}),(0,T.jsx)(d,{className:`h-14 rounded-xl`}),(0,T.jsx)(d,{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)(d,{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.jsxs)(`button`,{type:`button`,className:c(`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 disabled:opacity-50`,y.press),disabled:C,onClick:()=>void M(),children:[(0,T.jsx)(m,{className:c(`size-3.5`,C&&`animate-spin`),strokeWidth:1.75}),e.refresh]}),(0,T.jsxs)(`button`,{type:`button`,className:c(`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`,y.press),onClick:()=>void A.openCustomPetsDir(),children:[(0,T.jsx)(s,{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:c(`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`,y.press),onClick:B,children:[(0,T.jsx)(_,{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:c(`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`,y.press),onClick:()=>V(t),children:[(0,T.jsx)(p,{className:`size-3.5`,strokeWidth:1.75}),e.optimizeInChat]}),(0,T.jsx)(`button`,{type:`button`,className:c(`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`,y.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)(s,{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)(g,{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:c(`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`,y.press),onClick:()=>H(t),children:[(0,T.jsx)(_,{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:c(`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`,y.press),disabled:C,onClick:()=>void A.resetPosition().then(r),children:[(0,T.jsx)(h,{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{d as a}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{t as o}from"./circle-check-C23XjkUj.js";import{t as s}from"./download-Dk-ZjtO6.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./x-B_N4OPjy.js";import{t as u}from"./cn-JdwAhgNB.js";import{n as d}from"./locale-store-msTfRK8P.js";import{t as f}from"./messages-F74LVAiU.js";import{a as p,i as m,o as h,r as g,s as _,t as v}from"./dist-BGTk37IG.js";import{n as y}from"./app-link-BiBXVEvp.js";import{i as b}from"./vendor-swr-BIWyz7Rc.js";import{t as x}from"./button-CS04eWY9.js";import{t as S}from"./skeleton-BwbyijEw.js";import{i as C,o as w}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{Au as T,Fi as E,Jc as D,Ol as ee,_c as O,_u as k,ht as A,mt as j,pt as M,uo as N,vt as P,xt as F,yt as I}from"./index-RBCkv8a_.js";import{_ as te,a as ne,b as re,d as ie,f as ae,g as oe,i as se,l as L,m as ce,n as R,p as le,r as z,s as B,t as V,u as ue,y as de}from"./tunnel-api-DDOlOYlj.js";import{t as H}from"./browser-BLJWD7WI.js";var U=e(n(),1),W=r(),G=e(H(),1),K={width:240,margin:4,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function fe(e){let t=await G.toString(e,{...K,type:`svg`});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}var q=i();function pe(){let e=f(d(e=>e.language)),t=e.endpointToolsSettings.deviceAccess.flow,n=e.tunnelSettings,{data:r,error:i,mutate:a}=b(`tunnel-status`,R,{refreshInterval:1500}),[o,s]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),[p,m]=(0,U.useState)(!0),[h,g]=(0,U.useState)(`idle`),[_,v]=(0,U.useState)(null),[C,w]=(0,U.useState)(``),T=(0,U.useRef)(!0);(0,U.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let E=async()=>{if(!r)return;if(r.consentRequired&&!o){u(!0);return}let e=r.registrationSecret?.configured?null:A(),t,n=!1;v(null);try{if(r.consentRequired&&await ne(),!r.registrationSecret?.configured){g(`provisioning`);let r=!1;try{await se()}catch(e){if(!ue(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 F(`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 I(t);if(r.authUrl&&r.authUrl!==a&&(a=r.authUrl,await j(a,e)||w(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 se()}await a()}if(!T.current)return;g(`starting`),await B(),p&&await z({autoStart:!0}),await a(),n=!0}catch(e){n=!0,T.current&&v(L(e)===`tunnel_key_limit_reached`?`key-limit`:`failed`)}finally{M(e),n&&(sessionStorage.removeItem(`device-pairing-oauth`),t&&P(t).catch(()=>{})),T.current&&(g(`idle`),w(``))}};if(!r&&!i)return(0,q.jsxs)(`div`,{className:`space-y-5`,children:[(0,q.jsx)(S,{className:`h-5 w-4/5`}),(0,q.jsx)(S,{className:`h-24 w-full`})]});let D=h===`provisioning`||h===`starting`||r?.state===`connecting`||r?.state===`reconnecting`;return(0,q.jsxs)(`div`,{className:`flex min-h-full flex-col`,children:[(0,q.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:D?t.preparingHint:h===`authorizing`?t.authorizing:t.enableHint}),C&&h===`authorizing`?(0,q.jsx)(`a`,{href:C,target:`_blank`,rel:`noopener noreferrer`,className:`mt-4 inline-flex min-h-11 items-center text-sm text-accent`,children:t.openAuthorization}):null,D?(0,q.jsxs)(`div`,{className:`mt-8 space-y-3`,"aria-label":t.preparing,children:[(0,q.jsx)(S,{className:`h-2 w-full`}),(0,q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.preparing})]}):null,(l||r?.consentRequired)&&h===`idle`?(0,q.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,q.jsxs)(`details`,{open:l,className:`text-sm text-fg-muted`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer py-2`,children:t.details}),(0,q.jsx)(`p`,{className:`mt-2`,children:n.consentIntro}),(0,q.jsx)(`ul`,{className:`mt-3 list-disc space-y-2 pl-5`,children:[n.consentBullet1,n.consentBullet2,n.consentBullet3].map(e=>(0,q.jsx)(`li`,{children:e},e))})]}),(0,q.jsxs)(`label`,{className:`flex items-start gap-3 text-sm text-fg`,children:[(0,q.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,q.jsxs)(`div`,{role:`alert`,className:`mt-4 rounded-lg border border-warning/30 bg-warning/5 p-4`,children:[(0,q.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.routeKeyLimitTitle}),(0,q.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:t.routeKeyLimitHint}),(0,q.jsxs)(x,{variant:`secondary`,className:`mt-3`,onClick:()=>void y(V),children:[t.manageTunnelKeys,(0,q.jsx)(c,{className:`size-3`})]})]}):_||i||r?.state===`error`?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:t.routeSetupFailed}):null,(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`label`,{className:`my-5 flex items-center gap-3 text-sm text-fg-muted`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:p,disabled:h!==`idle`,onChange:e=>m(e.target.checked),className:`size-4 accent-accent`}),t.autoStart]}),(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:!r||h!==`idle`||D||l&&!o,onClick:()=>void E(),children:h===`authorizing`?t.authorizing:D?t.preparing:_?t.retry:t.enable}),i&&!r?(0,q.jsx)(x,{variant:`ghost`,onClick:()=>void a(),children:t.retry}):null]})}var J=t({DevicePairingWizard:()=>Y});function Y(e){let t=(0,W.c)(16),{open:n,onOpenChange:r,onPaired:i,targetKind:o}=e,s=a(),[c,l]=(0,U.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,U.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,q.jsx)(he,{targetKind:c,onClose:()=>p(!1),onPaired:i}):(0,q.jsx)(Z,{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,q.jsx)(v,{open:n,onOpenChange:p,children:m}),t[12]=p,t[13]=n,t[14]=m,t[15]=h):h=t[15],h}function X(e){let t=(0,W.c)(14),{icon:n,title:r,hint:i,onClick:a}=e,o;t[0]===n?o=t[1]:(o=(0,q.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent-soft text-accent-fg`,children:(0,q.jsx)(n,{className:`size-5`,"aria-hidden":`true`})}),t[0]=n,t[1]=o);let s;t[2]===r?s=t[3]:(s=(0,q.jsx)(`span`,{className:`block text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=s);let c;t[4]===i?c=t[5]:(c=(0,q.jsx)(`span`,{className:`mt-0.5 block text-xs leading-5 text-fg-muted`,children:i}),t[4]=i,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(T,{className:`size-4 shrink-0 text-fg-disabled transition-transform group-hover:translate-x-0.5 group-hover:text-fg-muted`,"aria-hidden":`true`}),t[9]=u):u=t[9];let d;return t[10]!==a||t[11]!==o||t[12]!==l?(d=(0,q.jsxs)(`button`,{type:`button`,className:`group flex min-h-18 w-full cursor-pointer items-center gap-4 rounded-xl border border-edge bg-surface-panel px-4 py-3.5 text-left shadow-surface transition-[background-color,border-color,box-shadow,transform] hover:border-edge-strong hover:bg-surface-active hover:shadow-elevated active:translate-y-px active:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel motion-reduce:active:translate-y-0`,onClick:a,children:[o,l,u]}),t[10]=a,t[11]=o,t[12]=l,t[13]=d):d=t[13],d}function Z(e){let t=(0,W.c)(40),{onChoose:n,onChooseLocalBrowser:r,onClose:i}=e,a=d(me),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,q.jsx)(p,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),t[2]=c):c=t[2];let v;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(v=u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(28rem,calc(100dvh-2rem))] w-[min(40rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,C),t[3]=v):v=t[3];let y;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,q.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),t[4]=y):y=t[4];let b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,q.jsx)(l,{className:`size-4`}),t[5]=b):b=t[5];let x;t[6]!==s.cancel||t[7]!==i?(x=(0,q.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[y,(0,q.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,q.jsx)(_,{className:`text-lg font-semibold tracking-tight text-fg sm:text-xl`,children:s.chooseTitle}),t[9]=s.chooseTitle,t[10]=S);let T;t[11]===s.chooseHint?T=t[12]:(T=(0,q.jsx)(m,{className:`mt-1.5 text-sm leading-6 text-fg-muted`,children:s.chooseHint}),t[11]=s.chooseHint,t[12]=T);let E;t[13]!==s.localBrowserHint||t[14]!==s.localBrowserTitle||t[15]!==r?(E=(0,q.jsx)(X,{icon:ee,title:s.localBrowserTitle,hint:s.localBrowserHint,onClick:r}),t[13]=s.localBrowserHint,t[14]=s.localBrowserTitle,t[15]=r,t[16]=E):E=t[16];let k;t[17]===n?k=t[18]:(k=()=>n(`mobile`),t[17]=n,t[18]=k);let A;t[19]!==s.mobileHint||t[20]!==s.mobileTitle||t[21]!==k?(A=(0,q.jsx)(X,{icon:O,title:s.mobileTitle,hint:s.mobileHint,onClick:k}),t[19]=s.mobileHint,t[20]=s.mobileTitle,t[21]=k,t[22]=A):A=t[22];let j;t[23]===n?j=t[24]:(j=()=>n(`browser`),t[23]=n,t[24]=j);let M;t[25]!==s.remoteBrowserHint||t[26]!==s.remoteBrowserTitle||t[27]!==j?(M=(0,q.jsx)(X,{icon:D,title:s.remoteBrowserTitle,hint:s.remoteBrowserHint,onClick:j}),t[25]=s.remoteBrowserHint,t[26]=s.remoteBrowserTitle,t[27]=j,t[28]=M):M=t[28];let N;t[29]!==A||t[30]!==M||t[31]!==E?(N=(0,q.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[E,A,M]}),t[29]=A,t[30]=M,t[31]=E,t[32]=N):N=t[32];let P;t[33]!==N||t[34]!==S||t[35]!==T?(P=(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-6 sm:px-8`,children:[S,T,N]}),t[33]=N,t[34]=S,t[35]=T,t[36]=P):P=t[36];let F;return t[37]!==P||t[38]!==x?(F=(0,q.jsxs)(h,{children:[c,(0,q.jsxs)(g,{className:v,children:[x,P]})]}),t[37]=P,t[38]=x,t[39]=F):F=t[39],F}function me(e){return e.language}function he({targetKind:e,onClose:t,onPaired:n}){let r=d(e=>e.language),i=f(r),a=i.endpointToolsSettings.deviceAccess,v=a.flow,[D,ee]=(0,U.useState)(!1),O=b(D?`device-pairing-readiness`:null,oe,{refreshInterval:1500}),[A,j]=(0,U.useState)(),[M,P]=(0,U.useState)(null),[F,I]=(0,U.useState)(!1),[ne,se]=(0,U.useState)(Date.now()),[L,R]=(0,U.useState)(null),z=(0,U.useRef)(!0),B=(0,U.useRef)(null),V=(0,U.useRef)(!1),ue=(0,U.useRef)(!1),H=b(A?[`device-pairing-setup`,A.id]:null,()=>te(A.id),{refreshInterval:1500}),W=H.data?.request,G=W?.status===`completed`,K=G&&W.connectedAt!==void 0,J=b(K&&window.electronAPI?.system?`system-behavior`:null,()=>window.electronAPI.system.getBehavior()),Y=A?.targetKind===`mobile`?A.universalLink:``,X=N(()=>fe(Y),[Y],{enabled:!!Y,initial:null,errorData:null}),Z=r===`zh`?`https://xopc.ai/zh#download`:`https://xopc.ai/en#download`,me=r===`zh`?`https://xopcai.github.io/xopc/zh/browser-extension`:`https://xopcai.github.io/xopc/browser-extension`,he=N(()=>fe(Z),[Z],{enabled:!D&&e===`mobile`,initial:null,errorData:null});(0,U.useEffect)(()=>{z.current=!0;let e=setInterval(()=>se(Date.now()),1e3);return()=>{z.current=!1,clearInterval(e),B.current&&ie(B.current).catch(()=>{})}},[]);let ge=(0,U.useCallback)(async()=>{if(!V.current){V.current=!0,I(!0),P(null);try{B.current&&await ie(B.current),B.current=null,j(void 0);let t=await ae(e);if(t.kind===`ready`){if(!z.current){await ie(t.setup.id);return}B.current=t.setup.id,j(t.setup)}else await O.mutate()}catch{z.current&&P(`create`)}finally{V.current=!1,z.current&&I(!1)}}},[O,e]);(0,U.useEffect)(()=>{O.data?.ready&&!A&&M!==`create`&&!V.current&&ge()},[O.data,A,M,ge]),(0,U.useEffect)(()=>{K&&!ue.current&&(ue.current=!0,n?.())},[K,n]);let _e=async e=>{if(W){I(!0),P(null);try{await le(W,e),await H.mutate()}catch{P(`decision`),await H.mutate()}finally{z.current&&I(!1)}}},ve=(0,U.useRef)(0);(0,U.useEffect)(()=>{H.data&&(ve.current=H.data.serverTime-Date.now())},[H.data]);let Q=ne+ve.current,ye=A&&Q>=A.expiresAt&&!W,be=W&&[`expired`,`rejected`,`cancelled`].includes(W.status),xe=A?A.expiresAt-Q<6e4:!1,Se=A?xe?`${Math.max(0,Math.ceil((A.expiresAt-Q)/1e3))}s`:v.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=D?K?$.success:W?.status===`pending`?$.allowTitle:G||W?.status===`approved`?v.waiting:A?$.connect:v.title:Ce,Ee=M===`create`?v.createFailed:M===`decision`?v.decisionFailed:M===`background`?v.backgroundFailed:M===`download`?a.browserDownloadFailed:null,De=async()=>{I(!0),P(null);try{await ce()}catch{P(`download`)}finally{z.current&&I(!1)}};return(0,q.jsxs)(h,{children:[(0,q.jsx)(p,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),(0,q.jsxs)(g,{className:u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(600px,calc(100dvh-48px))] w-[min(560px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,C),children:[(0,q.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[(0,q.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),(0,q.jsx)(`button`,{type:`button`,className:`flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover`,"aria-label":v.cancel,onClick:t,children:(0,q.jsx)(l,{className:`size-4`})})]}),(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-8 py-7`,children:[K?(0,q.jsx)(o,{className:`mb-5 size-7 text-success`}):null,(0,q.jsx)(_,{className:`text-xl font-semibold tracking-tight text-fg`,children:Te}),(0,q.jsx)(m,{className:`mt-2 text-sm leading-relaxed text-fg-muted`,children:D?K?$.successHint:G?v.waitingForDevice:W?W.displayName:A?$.connectHint:v.intro:we}),Ee?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:Ee}):null,D&&O.error?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:v.readinessFailed}):null,D&&H.error?(0,q.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-warning`,children:v.statusUnavailable}):null,D?O.data?K?(0,q.jsxs)(q.Fragment,{children:[J.data?(0,q.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,q.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":J.data.runInBackground??!1,disabled:!J.data.backgroundSupported,checked:J.data.runInBackground??!1,className:`size-5 accent-accent`,onChange:e=>{window.electronAPI.system.setBehavior({runInBackground:e.target.checked}).then(e=>J.mutate(e.behavior)).catch(()=>P(`background`))}})]}):null,(0,q.jsx)(`p`,{className:`mt-4 text-xs text-fg-muted`,children:a.sleep})]}):be||ye?(0,q.jsxs)(`div`,{className:`mt-10 space-y-5`,children:[(0,q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:ye||W?.status===`expired`?v.expired:v.declined}),(0,q.jsx)(x,{variant:`primary`,onClick:()=>void ge(),disabled:F,children:v.refresh})]}):W?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:v.scope}),(0,q.jsxs)(`p`,{className:`mt-10 font-mono text-4xl tracking-[0.16em] text-fg`,"aria-live":`polite`,children:[W.confirmationCode.slice(0,3),` `,W.confirmationCode.slice(3)]}),(0,q.jsx)(`p`,{className:`mt-3 text-xs text-fg-muted`,children:v.compare}),(0,q.jsxs)(`details`,{className:`mt-6 text-xs text-fg-muted`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer py-2`,children:v.access}),(0,q.jsx)(`p`,{children:v.accessHint})]})]}):A?.targetKind===`mobile`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`my-6 flex flex-col items-center`,children:[(0,q.jsx)(`div`,{className:`rounded-[1.75rem] border border-edge bg-surface-hover/55 p-2.5 shadow-surface`,children:(0,q.jsx)(`div`,{className:`rounded-[1.25rem] bg-white p-2 shadow-sm ring-1 ring-black/5`,children:X.data?(0,q.jsx)(`img`,{src:X.data,alt:a.qrAlt,width:240,height:240,className:`size-[240px] max-w-full rounded-xl bg-white`}):X.error?null:(0,q.jsx)(S,{className:`size-[240px] rounded-xl`})})}),X.error?null:(0,q.jsxs)(`p`,{className:u(`mt-4 inline-flex min-h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium`,xe?`bg-warning-soft text-warning`:`bg-surface-hover text-fg-muted`),"aria-live":`polite`,children:[(0,q.jsx)(k,{className:`size-3.5`,"aria-hidden":`true`}),Se]})]}),X.error?(0,q.jsx)(`p`,{role:`status`,className:`text-center text-sm text-warning`,children:v.qrFailed}):null,X.error?(0,q.jsx)(`div`,{className:`mt-5`,children:(0,q.jsx)(E,{text:A.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}):(0,q.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,q.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,q.jsx)(`span`,{children:v.fallback}),(0,q.jsx)(T,{className:`size-3.5 shrink-0 transition-transform group-open:rotate-90`,"aria-hidden":`true`})]}),(0,q.jsx)(`div`,{className:`border-t border-edge-subtle p-3`,children:(0,q.jsx)(E,{text:A.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})})]})]}):A?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`ol`,{className:`mt-7 space-y-2 text-sm leading-6 text-fg-muted`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserConnectStep1]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserConnectStep2]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserConnectStep3]})]}),(0,q.jsx)(`div`,{className:`mt-6`,children:(0,q.jsx)(E,{text:A.browserInvitation,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}),(0,q.jsx)(`p`,{className:`mt-3 text-center text-xs text-fg-muted`,children:A.expiresAt-Q<6e4?`${Math.max(0,Math.ceil((A.expiresAt-Q)/1e3))}s`:v.valid})]}):O.data.ready?(0,q.jsx)(`div`,{className:`mt-8`,children:(0,q.jsx)(S,{className:`mx-auto size-[216px]`})}):(0,q.jsxs)(`div`,{className:`mt-6 flex flex-1 flex-col`,children:[L===`tailscale`?(0,q.jsx)(re,{embedded:!0}):L===`https`?(0,q.jsx)(de,{}):L===`choices`?(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsx)(x,{variant:`secondary`,className:`w-full`,onClick:()=>R(`tailscale`),children:a.useTailscale}),(0,q.jsx)(x,{variant:`secondary`,className:`w-full`,onClick:()=>R(`https`),children:a.useOwnHttps})]}):(0,q.jsx)(pe,{}),(0,q.jsx)(x,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>R(L?null:`choices`),children:L?v.back:v.existing})]}):(0,q.jsxs)(`div`,{className:`mt-8 space-y-4`,children:[(0,q.jsx)(S,{className:`h-5 w-3/4`}),(0,q.jsx)(S,{className:`h-40 w-full`})]}):e===`mobile`?(0,q.jsxs)(`div`,{className:`mt-7 flex flex-col items-center`,children:[he.data?(0,q.jsx)(`img`,{src:he.data,alt:a.mobileDownloadQrAlt,width:144,height:144,className:`size-36 rounded-lg bg-white`}):(0,q.jsx)(S,{className:`size-36`}),(0,q.jsxs)(x,{variant:`secondary`,className:`mt-5 w-full`,onClick:()=>void y(Z),children:[(0,q.jsx)(c,{className:`size-4`}),a.mobileDownload]}),(0,q.jsx)(`p`,{className:`mt-3 text-center text-xs leading-5 text-fg-muted`,children:a.mobileDownloadHint})]}):(0,q.jsxs)(`div`,{className:`mt-7`,children:[(0,q.jsxs)(x,{variant:`secondary`,className:`w-full`,disabled:F,onClick:()=>void De(),children:[(0,q.jsx)(s,{className:`size-4`}),a.browserDownload]}),(0,q.jsxs)(`ol`,{className:`mt-5 space-y-3 text-sm leading-6 text-fg-muted`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserInstallStep1]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserInstallStep2]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserInstallStep3]})]}),(0,q.jsxs)(`button`,{type:`button`,className:`mt-5 inline-flex items-center gap-1 text-xs text-accent hover:underline`,onClick:()=>void y(me),children:[a.browserInstallHelp,(0,q.jsx)(c,{className:`size-3`})]})]})]}),!D||O.error||K||W?.status===`pending`||M===`create`||M===`decision`?(0,q.jsx)(`footer`,{className:`shrink-0 px-8 pb-6`,children:D?K?(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:t,children:v.done}):W?.status===`pending`?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:F,onClick:()=>void _e(`approve`),children:v.allow}),(0,q.jsx)(x,{className:`w-full`,variant:`ghost`,disabled:F,onClick:()=>void _e(`reject`),children:v.cancel})]}):O.error?(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:()=>void O.mutate(),children:v.retry}):(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:F,onClick:()=>void ge(),children:v.retry}):(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:()=>{P(null),ee(!0)},children:e===`mobile`?a.mobileReady:a.browserReady})}):null]})]})}export{J as n,Y 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{d as a}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{t as o}from"./circle-check-C23XjkUj.js";import{t as s}from"./download-Dk-ZjtO6.js";import{t as c}from"./external-link-DjqjBmc3.js";import{t as l}from"./x-B_N4OPjy.js";import{t as u}from"./cn-JdwAhgNB.js";import{n as d}from"./locale-store-DPZ79W1-.js";import{t as f}from"./messages-BiYTyLJr.js";import{a as p,i as m,o as h,r as g,s as _,t as v}from"./dist-BGTk37IG.js";import{n as y}from"./app-link-BiBXVEvp.js";import{i as b}from"./vendor-swr-BIWyz7Rc.js";import{t as x}from"./button-CS04eWY9.js";import{t as S}from"./skeleton-BwbyijEw.js";import{i as C,o as w}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{Au as T,Fi as E,Jc as D,Ol as ee,St as O,_c as k,_u as A,bt as j,gt as M,ht as N,mt as P,uo as F,yt as I}from"./index-DJo4DimT.js";import{_ as te,a as ne,b as re,d as ie,f as ae,g as oe,i as se,l as L,m as ce,n as R,p as le,r as z,s as B,t as V,u as ue,y as de}from"./tunnel-api-Db2guRdW.js";import{t as H}from"./browser-BLJWD7WI.js";var U=e(n(),1),W=r(),G=e(H(),1),K={width:240,margin:4,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function fe(e){let t=await G.toString(e,{...K,type:`svg`});return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(t)}`}var q=i();function pe(){let e=f(d(e=>e.language)),t=e.endpointToolsSettings.deviceAccess.flow,n=e.tunnelSettings,{data:r,error:i,mutate:a}=b(`tunnel-status`,R,{refreshInterval:1500}),[o,s]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),[p,m]=(0,U.useState)(!0),[h,g]=(0,U.useState)(`idle`),[_,v]=(0,U.useState)(null),[C,w]=(0,U.useState)(``),T=(0,U.useRef)(!0);(0,U.useEffect)(()=>(T.current=!0,()=>{T.current=!1}),[]);let E=async()=>{if(!r)return;if(r.consentRequired&&!o){u(!0);return}let e=r.registrationSecret?.configured?null:M(),t,n=!1;v(null);try{if(r.consentRequired&&await ne(),!r.registrationSecret?.configured){g(`provisioning`);let r=!1;try{await se()}catch(e){if(!ue(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 j(t);if(r.authUrl&&r.authUrl!==a&&(a=r.authUrl,await N(a,e)||w(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 se()}await a()}if(!T.current)return;g(`starting`),await B(),p&&await z({autoStart:!0}),await a(),n=!0}catch(e){n=!0,T.current&&v(L(e)===`tunnel_key_limit_reached`?`key-limit`:`failed`)}finally{P(e),n&&(sessionStorage.removeItem(`device-pairing-oauth`),t&&I(t).catch(()=>{})),T.current&&(g(`idle`),w(``))}};if(!r&&!i)return(0,q.jsxs)(`div`,{className:`space-y-5`,children:[(0,q.jsx)(S,{className:`h-5 w-4/5`}),(0,q.jsx)(S,{className:`h-24 w-full`})]});let D=h===`provisioning`||h===`starting`||r?.state===`connecting`||r?.state===`reconnecting`;return(0,q.jsxs)(`div`,{className:`flex min-h-full flex-col`,children:[(0,q.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:D?t.preparingHint:h===`authorizing`?t.authorizing:t.enableHint}),C&&h===`authorizing`?(0,q.jsx)(`a`,{href:C,target:`_blank`,rel:`noopener noreferrer`,className:`mt-4 inline-flex min-h-11 items-center text-sm text-accent`,children:t.openAuthorization}):null,D?(0,q.jsxs)(`div`,{className:`mt-8 space-y-3`,"aria-label":t.preparing,children:[(0,q.jsx)(S,{className:`h-2 w-full`}),(0,q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.preparing})]}):null,(l||r?.consentRequired)&&h===`idle`?(0,q.jsxs)(`div`,{className:`mt-6 space-y-4`,children:[(0,q.jsxs)(`details`,{open:l,className:`text-sm text-fg-muted`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer py-2`,children:t.details}),(0,q.jsx)(`p`,{className:`mt-2`,children:n.consentIntro}),(0,q.jsx)(`ul`,{className:`mt-3 list-disc space-y-2 pl-5`,children:[n.consentBullet1,n.consentBullet2,n.consentBullet3].map(e=>(0,q.jsx)(`li`,{children:e},e))})]}),(0,q.jsxs)(`label`,{className:`flex items-start gap-3 text-sm text-fg`,children:[(0,q.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,q.jsxs)(`div`,{role:`alert`,className:`mt-4 rounded-lg border border-warning/30 bg-warning/5 p-4`,children:[(0,q.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.routeKeyLimitTitle}),(0,q.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:t.routeKeyLimitHint}),(0,q.jsxs)(x,{variant:`secondary`,className:`mt-3`,onClick:()=>void y(V),children:[t.manageTunnelKeys,(0,q.jsx)(c,{className:`size-3`})]})]}):_||i||r?.state===`error`?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:t.routeSetupFailed}):null,(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`label`,{className:`my-5 flex items-center gap-3 text-sm text-fg-muted`,children:[(0,q.jsx)(`input`,{type:`checkbox`,checked:p,disabled:h!==`idle`,onChange:e=>m(e.target.checked),className:`size-4 accent-accent`}),t.autoStart]}),(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:!r||h!==`idle`||D||l&&!o,onClick:()=>void E(),children:h===`authorizing`?t.authorizing:D?t.preparing:_?t.retry:t.enable}),i&&!r?(0,q.jsx)(x,{variant:`ghost`,onClick:()=>void a(),children:t.retry}):null]})}var J=t({DevicePairingWizard:()=>Y});function Y(e){let t=(0,W.c)(16),{open:n,onOpenChange:r,onPaired:i,targetKind:o}=e,s=a(),[c,l]=(0,U.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,U.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,q.jsx)(he,{targetKind:c,onClose:()=>p(!1),onPaired:i}):(0,q.jsx)(Z,{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,q.jsx)(v,{open:n,onOpenChange:p,children:m}),t[12]=p,t[13]=n,t[14]=m,t[15]=h):h=t[15],h}function X(e){let t=(0,W.c)(14),{icon:n,title:r,hint:i,onClick:a}=e,o;t[0]===n?o=t[1]:(o=(0,q.jsx)(`span`,{className:`flex size-10 shrink-0 items-center justify-center rounded-xl bg-accent-soft text-accent-fg`,children:(0,q.jsx)(n,{className:`size-5`,"aria-hidden":`true`})}),t[0]=n,t[1]=o);let s;t[2]===r?s=t[3]:(s=(0,q.jsx)(`span`,{className:`block text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=s);let c;t[4]===i?c=t[5]:(c=(0,q.jsx)(`span`,{className:`mt-0.5 block text-xs leading-5 text-fg-muted`,children:i}),t[4]=i,t[5]=c);let l;t[6]!==s||t[7]!==c?(l=(0,q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[s,c]}),t[6]=s,t[7]=c,t[8]=l):l=t[8];let u;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,q.jsx)(T,{className:`size-4 shrink-0 text-fg-disabled transition-transform group-hover:translate-x-0.5 group-hover:text-fg-muted`,"aria-hidden":`true`}),t[9]=u):u=t[9];let d;return t[10]!==a||t[11]!==o||t[12]!==l?(d=(0,q.jsxs)(`button`,{type:`button`,className:`group flex min-h-18 w-full cursor-pointer items-center gap-4 rounded-xl border border-edge bg-surface-panel px-4 py-3.5 text-left shadow-surface transition-[background-color,border-color,box-shadow,transform] hover:border-edge-strong hover:bg-surface-active hover:shadow-elevated active:translate-y-px active:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel motion-reduce:active:translate-y-0`,onClick:a,children:[o,l,u]}),t[10]=a,t[11]=o,t[12]=l,t[13]=d):d=t[13],d}function Z(e){let t=(0,W.c)(40),{onChoose:n,onChooseLocalBrowser:r,onClose:i}=e,a=d(me),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,q.jsx)(p,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),t[2]=c):c=t[2];let v;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(v=u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(28rem,calc(100dvh-2rem))] w-[min(40rem,calc(100vw-2rem))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,C),t[3]=v):v=t[3];let y;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,q.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),t[4]=y):y=t[4];let b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,q.jsx)(l,{className:`size-4`}),t[5]=b):b=t[5];let x;t[6]!==s.cancel||t[7]!==i?(x=(0,q.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[y,(0,q.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,q.jsx)(_,{className:`text-lg font-semibold tracking-tight text-fg sm:text-xl`,children:s.chooseTitle}),t[9]=s.chooseTitle,t[10]=S);let T;t[11]===s.chooseHint?T=t[12]:(T=(0,q.jsx)(m,{className:`mt-1.5 text-sm leading-6 text-fg-muted`,children:s.chooseHint}),t[11]=s.chooseHint,t[12]=T);let E;t[13]!==s.localBrowserHint||t[14]!==s.localBrowserTitle||t[15]!==r?(E=(0,q.jsx)(X,{icon:ee,title:s.localBrowserTitle,hint:s.localBrowserHint,onClick:r}),t[13]=s.localBrowserHint,t[14]=s.localBrowserTitle,t[15]=r,t[16]=E):E=t[16];let O;t[17]===n?O=t[18]:(O=()=>n(`mobile`),t[17]=n,t[18]=O);let A;t[19]!==s.mobileHint||t[20]!==s.mobileTitle||t[21]!==O?(A=(0,q.jsx)(X,{icon:k,title:s.mobileTitle,hint:s.mobileHint,onClick:O}),t[19]=s.mobileHint,t[20]=s.mobileTitle,t[21]=O,t[22]=A):A=t[22];let j;t[23]===n?j=t[24]:(j=()=>n(`browser`),t[23]=n,t[24]=j);let M;t[25]!==s.remoteBrowserHint||t[26]!==s.remoteBrowserTitle||t[27]!==j?(M=(0,q.jsx)(X,{icon:D,title:s.remoteBrowserTitle,hint:s.remoteBrowserHint,onClick:j}),t[25]=s.remoteBrowserHint,t[26]=s.remoteBrowserTitle,t[27]=j,t[28]=M):M=t[28];let N;t[29]!==A||t[30]!==M||t[31]!==E?(N=(0,q.jsxs)(`div`,{className:`mt-5 flex flex-col gap-2.5`,children:[E,A,M]}),t[29]=A,t[30]=M,t[31]=E,t[32]=N):N=t[32];let P;t[33]!==N||t[34]!==S||t[35]!==T?(P=(0,q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-6 sm:px-8`,children:[S,T,N]}),t[33]=N,t[34]=S,t[35]=T,t[36]=P):P=t[36];let F;return t[37]!==P||t[38]!==x?(F=(0,q.jsxs)(h,{children:[c,(0,q.jsxs)(g,{className:v,children:[x,P]})]}),t[37]=P,t[38]=x,t[39]=F):F=t[39],F}function me(e){return e.language}function he({targetKind:e,onClose:t,onPaired:n}){let r=d(e=>e.language),i=f(r),a=i.endpointToolsSettings.deviceAccess,v=a.flow,[D,ee]=(0,U.useState)(!1),O=b(D?`device-pairing-readiness`:null,oe,{refreshInterval:1500}),[k,j]=(0,U.useState)(),[M,N]=(0,U.useState)(null),[P,I]=(0,U.useState)(!1),[ne,se]=(0,U.useState)(Date.now()),[L,R]=(0,U.useState)(null),z=(0,U.useRef)(!0),B=(0,U.useRef)(null),V=(0,U.useRef)(!1),ue=(0,U.useRef)(!1),H=b(k?[`device-pairing-setup`,k.id]:null,()=>te(k.id),{refreshInterval:1500}),W=H.data?.request,G=W?.status===`completed`,K=G&&W.connectedAt!==void 0,J=b(K&&window.electronAPI?.system?`system-behavior`:null,()=>window.electronAPI.system.getBehavior()),Y=k?.targetKind===`mobile`?k.universalLink:``,X=F(()=>fe(Y),[Y],{enabled:!!Y,initial:null,errorData:null}),Z=r===`zh`?`https://xopc.ai/zh#download`:`https://xopc.ai/en#download`,me=r===`zh`?`https://xopcai.github.io/xopc/zh/browser-extension`:`https://xopcai.github.io/xopc/browser-extension`,he=F(()=>fe(Z),[Z],{enabled:!D&&e===`mobile`,initial:null,errorData:null});(0,U.useEffect)(()=>{z.current=!0;let e=setInterval(()=>se(Date.now()),1e3);return()=>{z.current=!1,clearInterval(e),B.current&&ie(B.current).catch(()=>{})}},[]);let ge=(0,U.useCallback)(async()=>{if(!V.current){V.current=!0,I(!0),N(null);try{B.current&&await ie(B.current),B.current=null,j(void 0);let t=await ae(e);if(t.kind===`ready`){if(!z.current){await ie(t.setup.id);return}B.current=t.setup.id,j(t.setup)}else await O.mutate()}catch{z.current&&N(`create`)}finally{V.current=!1,z.current&&I(!1)}}},[O,e]);(0,U.useEffect)(()=>{O.data?.ready&&!k&&M!==`create`&&!V.current&&ge()},[O.data,k,M,ge]),(0,U.useEffect)(()=>{K&&!ue.current&&(ue.current=!0,n?.())},[K,n]);let _e=async e=>{if(W){I(!0),N(null);try{await le(W,e),await H.mutate()}catch{N(`decision`),await H.mutate()}finally{z.current&&I(!1)}}},ve=(0,U.useRef)(0);(0,U.useEffect)(()=>{H.data&&(ve.current=H.data.serverTime-Date.now())},[H.data]);let Q=ne+ve.current,ye=k&&Q>=k.expiresAt&&!W,be=W&&[`expired`,`rejected`,`cancelled`].includes(W.status),xe=k?k.expiresAt-Q<6e4:!1,Se=k?xe?`${Math.max(0,Math.ceil((k.expiresAt-Q)/1e3))}s`:v.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=D?K?$.success:W?.status===`pending`?$.allowTitle:G||W?.status===`approved`?v.waiting:k?$.connect:v.title:Ce,Ee=M===`create`?v.createFailed:M===`decision`?v.decisionFailed:M===`background`?v.backgroundFailed:M===`download`?a.browserDownloadFailed:null,De=async()=>{I(!0),N(null);try{await ce()}catch{N(`download`)}finally{z.current&&I(!1)}};return(0,q.jsxs)(h,{children:[(0,q.jsx)(p,{className:u(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,w)}),(0,q.jsxs)(g,{className:u(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(600px,calc(100dvh-48px))] w-[min(560px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-overlay`,C),children:[(0,q.jsxs)(`header`,{className:`flex shrink-0 items-center justify-between border-b border-edge-subtle px-6 py-3`,children:[(0,q.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-fg`,children:`xopc`}),(0,q.jsx)(`button`,{type:`button`,className:`flex size-10 items-center justify-center rounded-lg text-fg-muted hover:bg-surface-hover`,"aria-label":v.cancel,onClick:t,children:(0,q.jsx)(l,{className:`size-4`})})]}),(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto px-8 py-7`,children:[K?(0,q.jsx)(o,{className:`mb-5 size-7 text-success`}):null,(0,q.jsx)(_,{className:`text-xl font-semibold tracking-tight text-fg`,children:Te}),(0,q.jsx)(m,{className:`mt-2 text-sm leading-relaxed text-fg-muted`,children:D?K?$.successHint:G?v.waitingForDevice:W?W.displayName:k?$.connectHint:v.intro:we}),Ee?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:Ee}):null,D&&O.error?(0,q.jsx)(`p`,{role:`alert`,className:`mt-4 text-sm text-danger`,children:v.readinessFailed}):null,D&&H.error?(0,q.jsx)(`p`,{role:`status`,className:`mt-4 text-sm text-warning`,children:v.statusUnavailable}):null,D?O.data?K?(0,q.jsxs)(q.Fragment,{children:[J.data?(0,q.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,q.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":J.data.runInBackground??!1,disabled:!J.data.backgroundSupported,checked:J.data.runInBackground??!1,className:`size-5 accent-accent`,onChange:e=>{window.electronAPI.system.setBehavior({runInBackground:e.target.checked}).then(e=>J.mutate(e.behavior)).catch(()=>N(`background`))}})]}):null,(0,q.jsx)(`p`,{className:`mt-4 text-xs text-fg-muted`,children:a.sleep})]}):be||ye?(0,q.jsxs)(`div`,{className:`mt-10 space-y-5`,children:[(0,q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:ye||W?.status===`expired`?v.expired:v.declined}),(0,q.jsx)(x,{variant:`primary`,onClick:()=>void ge(),disabled:P,children:v.refresh})]}):W?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:v.scope}),(0,q.jsxs)(`p`,{className:`mt-10 font-mono text-4xl tracking-[0.16em] text-fg`,"aria-live":`polite`,children:[W.confirmationCode.slice(0,3),` `,W.confirmationCode.slice(3)]}),(0,q.jsx)(`p`,{className:`mt-3 text-xs text-fg-muted`,children:v.compare}),(0,q.jsxs)(`details`,{className:`mt-6 text-xs text-fg-muted`,children:[(0,q.jsx)(`summary`,{className:`cursor-pointer py-2`,children:v.access}),(0,q.jsx)(`p`,{children:v.accessHint})]})]}):k?.targetKind===`mobile`?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`my-6 flex flex-col items-center`,children:[(0,q.jsx)(`div`,{className:`rounded-[1.75rem] border border-edge bg-surface-hover/55 p-2.5 shadow-surface`,children:(0,q.jsx)(`div`,{className:`rounded-[1.25rem] bg-white p-2 shadow-sm ring-1 ring-black/5`,children:X.data?(0,q.jsx)(`img`,{src:X.data,alt:a.qrAlt,width:240,height:240,className:`size-[240px] max-w-full rounded-xl bg-white`}):X.error?null:(0,q.jsx)(S,{className:`size-[240px] rounded-xl`})})}),X.error?null:(0,q.jsxs)(`p`,{className:u(`mt-4 inline-flex min-h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium`,xe?`bg-warning-soft text-warning`:`bg-surface-hover text-fg-muted`),"aria-live":`polite`,children:[(0,q.jsx)(A,{className:`size-3.5`,"aria-hidden":`true`}),Se]})]}),X.error?(0,q.jsx)(`p`,{role:`status`,className:`text-center text-sm text-warning`,children:v.qrFailed}):null,X.error?(0,q.jsx)(`div`,{className:`mt-5`,children:(0,q.jsx)(E,{text:k.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}):(0,q.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,q.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,q.jsx)(`span`,{children:v.fallback}),(0,q.jsx)(T,{className:`size-3.5 shrink-0 transition-transform group-open:rotate-90`,"aria-hidden":`true`})]}),(0,q.jsx)(`div`,{className:`border-t border-edge-subtle p-3`,children:(0,q.jsx)(E,{text:k.universalLink,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})})]})]}):k?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`ol`,{className:`mt-7 space-y-2 text-sm leading-6 text-fg-muted`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserConnectStep1]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserConnectStep2]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserConnectStep3]})]}),(0,q.jsx)(`div`,{className:`mt-6`,children:(0,q.jsx)(E,{text:k.browserInvitation,labels:{copy:a.copy,copied:a.copied,copyFailed:i.clipboard.copyFailed}})}),(0,q.jsx)(`p`,{className:`mt-3 text-center text-xs text-fg-muted`,children:k.expiresAt-Q<6e4?`${Math.max(0,Math.ceil((k.expiresAt-Q)/1e3))}s`:v.valid})]}):O.data.ready?(0,q.jsx)(`div`,{className:`mt-8`,children:(0,q.jsx)(S,{className:`mx-auto size-[216px]`})}):(0,q.jsxs)(`div`,{className:`mt-6 flex flex-1 flex-col`,children:[L===`tailscale`?(0,q.jsx)(re,{embedded:!0}):L===`https`?(0,q.jsx)(de,{}):L===`choices`?(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsx)(x,{variant:`secondary`,className:`w-full`,onClick:()=>R(`tailscale`),children:a.useTailscale}),(0,q.jsx)(x,{variant:`secondary`,className:`w-full`,onClick:()=>R(`https`),children:a.useOwnHttps})]}):(0,q.jsx)(pe,{}),(0,q.jsx)(x,{variant:`ghost`,className:`mt-3 w-full`,onClick:()=>R(L?null:`choices`),children:L?v.back:v.existing})]}):(0,q.jsxs)(`div`,{className:`mt-8 space-y-4`,children:[(0,q.jsx)(S,{className:`h-5 w-3/4`}),(0,q.jsx)(S,{className:`h-40 w-full`})]}):e===`mobile`?(0,q.jsxs)(`div`,{className:`mt-7 flex flex-col items-center`,children:[he.data?(0,q.jsx)(`img`,{src:he.data,alt:a.mobileDownloadQrAlt,width:144,height:144,className:`size-36 rounded-lg bg-white`}):(0,q.jsx)(S,{className:`size-36`}),(0,q.jsxs)(x,{variant:`secondary`,className:`mt-5 w-full`,onClick:()=>void y(Z),children:[(0,q.jsx)(c,{className:`size-4`}),a.mobileDownload]}),(0,q.jsx)(`p`,{className:`mt-3 text-center text-xs leading-5 text-fg-muted`,children:a.mobileDownloadHint})]}):(0,q.jsxs)(`div`,{className:`mt-7`,children:[(0,q.jsxs)(x,{variant:`secondary`,className:`w-full`,disabled:P,onClick:()=>void De(),children:[(0,q.jsx)(s,{className:`size-4`}),a.browserDownload]}),(0,q.jsxs)(`ol`,{className:`mt-5 space-y-3 text-sm leading-6 text-fg-muted`,children:[(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`1.`}),a.browserInstallStep1]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`2.`}),a.browserInstallStep2]}),(0,q.jsxs)(`li`,{children:[(0,q.jsx)(`span`,{className:`mr-2 text-fg-subtle`,children:`3.`}),a.browserInstallStep3]})]}),(0,q.jsxs)(`button`,{type:`button`,className:`mt-5 inline-flex items-center gap-1 text-xs text-accent hover:underline`,onClick:()=>void y(me),children:[a.browserInstallHelp,(0,q.jsx)(c,{className:`size-3`})]})]})]}),!D||O.error||K||W?.status===`pending`||M===`create`||M===`decision`?(0,q.jsx)(`footer`,{className:`shrink-0 px-8 pb-6`,children:D?K?(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:t,children:v.done}):W?.status===`pending`?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void _e(`approve`),children:v.allow}),(0,q.jsx)(x,{className:`w-full`,variant:`ghost`,disabled:P,onClick:()=>void _e(`reject`),children:v.cancel})]}):O.error?(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:()=>void O.mutate(),children:v.retry}):(0,q.jsx)(x,{className:`w-full`,variant:`primary`,disabled:P,onClick:()=>void ge(),children:v.retry}):(0,q.jsx)(x,{className:`w-full`,variant:`primary`,onClick:()=>{N(null),ee(!0)},children:e===`mobile`?a.mobileReady:a.browserReady})}):null]})]})}export{J as n,Y 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{n as r}from"./locale-store-msTfRK8P.js";import{t as i}from"./messages-F74LVAiU.js";import{Ka as a}from"./index-RBCkv8a_.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=r(p),n;e[0]===t?n=e[1]:(n=i(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{n as r}from"./locale-store-DPZ79W1-.js";import{t as i}from"./messages-BiYTyLJr.js";import{Ka as a}from"./index-DJo4DimT.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=r(p),n;e[0]===t?n=e[1]:(n=i(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{p as i}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{Hr as a,Ka as o,Ya as s,do as c}from"./index-RBCkv8a_.js";var l=n(),u=e(t(),1),d=r();function f(){let e=(0,l.c)(26),{extensionId:t,pageId:n}=i(),r=o(),f=c(m),g=c(p),_,v,y;e[0]!==t||e[1]!==r||e[2]!==n?(_=t?r.find(e=>e.id===t&&s(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)(a,{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{p as i}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{Br as a,Ka as o,Ya as s,do as c}from"./index-DJo4DimT.js";var l=n(),u=e(t(),1),d=r();function f(){let e=(0,l.c)(26),{extensionId:t,pageId:n}=i(),r=o(),f=c(m),g=c(p),_,v,y;e[0]!==t||e[1]!==r||e[2]!==n?(_=t?r.find(e=>e.id===t&&s(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)(a,{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{p as i,t as a}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{n as o,r as s}from"./popover-select-9i-ZtHXL.js";import{t as c}from"./cn-JdwAhgNB.js";import{a as l,c as u,i as d,n as f,r as p}from"./locale-store-msTfRK8P.js";import{t as m}from"./messages-F74LVAiU.js";import{i as h}from"./vendor-swr-BIWyz7Rc.js";import{t as g}from"./button-CS04eWY9.js";import{Eo as _,Hr as v,Ka as y,To as b,wo as x}from"./index-RBCkv8a_.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-CQ8uWNnB.js";import{c as D,d as O,s as k}from"./voice-config-api-DgJML_uM.js";import{t as A}from"./voice-api-key-field-COTzshjL.js";import{t as j}from"./schema-form-BuEmLiaU.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 c(b,x)}function R(){return c(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,_,`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=m(f(e=>e.language)),i=r.voiceSettings,a=r.extensionSttMedia,l={maskedHelp:i.apiKeyMaskedHelp,copy:i.apiKeyCopy,copied:i.apiKeyCopied,show:i.apiKeyShow,hide:i.apiKeyHide,notInConfigFile:i.apiKeyNotInConfigFile,loadFailed:i.apiKeyRevealFailed},{data:u}=h(p(`/api/voice/stt-providers`),D,{revalidateOnFocus:!1}),d=(0,M.useMemo)(()=>u?.providers.find(t=>t.id===e),[e,u]),g=d?.configured??!1,_=d?.models??[],v=_[0]?.id??d?.fields.find(e=>e.key===`model`)?.defaultValue??``,y=(0,M.useMemo)(()=>z(t,e,v),[v,e,t]),b=(0,M.useRef)(!1),[S,C]=(0,M.useState)(null),w=S??y,k=(0,M.useRef)(w);k.current=w;let j=y,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),b.current=JSON.stringify(k.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:c(`rounded-full px-2 py-0.5 text-xs font-medium`,g?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-800 dark:text-amber-200`),children:g?a.configured:a.notConfigured})]})]}),(0,P.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,P.jsxs)(`div`,{className:c(`flex flex-col gap-1.5`,x),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=>{b.current=!0,C(t=>({...t??y,apiKey:e}))},labels:l,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:c(`flex flex-col gap-1.5`,x),children:[(0,P.jsx)(F,{children:i.stt.model}),I.length>0?(0,P.jsx)(o,{className:L(),value:w.model,onChange:e=>{b.current=!0,C(t=>({...t??y,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=>{b.current=!0,C(t=>({...t??y,model:e.target.value}))}})]})]})]})}function V(e){let t=(0,N.c)(13),{extensionId:n}=e,r=f(U),i=u(H),a;t[0]===n?a=t[1]:(a=()=>l(p(`/api/extensions/${encodeURIComponent(n)}`)),t[0]=n,t[1]=a);let{data:o,isLoading:s}=h(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 d=c,m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={revalidateOnFocus:!1},t[4]=m):m=t[4];let{data:g,mutate:_,isLoading:v}=h(i?`voice-settings-ext-stt`:null,k,m);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(!d){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(!g)return null;let y=`${n}:${d}`,b;return t[8]!==_||t[9]!==d||t[10]!==y||t[11]!==g?(b=(0,P.jsx)(B,{providerId:d,voiceSettings:g,mutateVoice:_},y),t[8]=_,t[9]=d,t[10]=y,t[11]=g,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=u(e=>!!e.conversationId),{data:n,error:r}=h(t&&e?`ext-detail-${e}`:null,()=>l(p(`/api/extensions/${encodeURIComponent(e)}`))),{data:i,mutate:a,error:o}=h(t&&e?`ext-cfg-${e}`:null,()=>l(p(`/api/extensions/${encodeURIComponent(e)}/config`))),s=n?.manifest?.configSchema,c=(0,M.useMemo)(()=>s&&s.type===`object`?G(s):{},[s]),f=(0,M.useMemo)(()=>({...c,...i??{}}),[c,i]),[m,_]=(0,M.useReducer)(K,{localValues:{},isDirty:!1}),v=(0,M.useRef)(!1),y=(0,M.useRef)(m.localValues);y.current=m.localValues;let b=(0,M.useRef)(f);!v.current&&b.current!==f&&(b.current=f,_({type:`sync`,value:f}));let x=(0,M.useCallback)(e=>{v.current=!0,_({type:`change`,value:e})},[]),S=(0,M.useCallback)(()=>{!s||s.type!==`object`||(v.current=!0,_({type:`reset-defaults`,value:{...G(s)}}))},[s]),C=(0,M.useCallback)(async t=>{if(!e)return;let n=await d(p(`/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),_({type:`saved`,value:t}),v.current=JSON.stringify(y.current)!==JSON.stringify(t)},[e,a]),w=E({value:m.localValues,dirty:m.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)(g,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:S,children:`Reset to defaults`})]})]}),(0,P.jsx)(j,{schema:s,values:m.localValues,onChange:x})]})}function J(){let e=(0,N.c)(38),t=f(Y),n;e[0]===t?n=e[1]:(n=m(t),e[0]=t,e[1]=n);let r=n.extensionSttMedia,{extensionId:o,panelId:s}=i(),c=y();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 l,u,d;if(e[3]!==o||e[4]!==c||e[5]!==s){d=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),l=c.find(t),!l){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),d=n;break bb0}let n=l.ui?.contributions?.settingsPanels;u=s?n?.find(e=>e.id===s||e.id===`${o}.${s}`):n?.[0]}e[3]=o,e[4]=c,e[5]=s,e[6]=l,e[7]=u,e[8]=d}else l=e[6],u=e[7],d=e[8];if(d!==Symbol.for(`react.early_return_sentinel`))return d;let p=u,h=!!(p&&l.ui),g=!!l.hasConfigSchema,_=l.kind===`media-provider`;if(!g&&!h&&!_){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 b=p?.title??`${l.name} Settings`,x;e[15]===b?x=e[16]:(x=(0,P.jsx)(S,{title:b}),e[15]=b,e[16]=x);let w;e[17]!==_||e[18]!==r?(w=_?(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]=_,e[18]=r,e[19]=w):w=e[19];let T;e[20]!==o||e[21]!==_?(T=_?(0,P.jsx)(V,{extensionId:o}):null,e[20]=o,e[21]=_,e[22]=T):T=e[22];let E;e[23]!==o||e[24]!==g?(E=g?(0,P.jsx)(q,{extensionId:o}):null,e[23]=o,e[24]=g,e[25]=E):E=e[25];let D;e[26]!==l.name||e[27]!==l.ui||e[28]!==o||e[29]!==h||e[30]!==p?(D=h&&p&&l.ui?(0,P.jsx)(`div`,{className:`overflow-hidden rounded-xl bg-surface-base shadow-surface`,children:(0,P.jsx)(v,{extensionId:o,extensionName:l.name,entrypoint:p.entrypoint,permissions:l.ui?.permissions,title:p.title,className:`w-full`,minHeight:120,maxHeight:2e3})}):null,e[26]=l.name,e[27]=l.ui,e[28]=o,e[29]=h,e[30]=p,e[31]=D):D=e[31];let O;return e[32]!==x||e[33]!==w||e[34]!==T||e[35]!==E||e[36]!==D?(O=(0,P.jsxs)(C,{gap:`gap-5`,children:[x,w,T,E,D]}),e[32]=x,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{p as i,t as a}from"./chunk-KS7C4IRE-Cq1tE_3b.js";import{n as o,r as s}from"./popover-select-9i-ZtHXL.js";import{t as c}from"./cn-JdwAhgNB.js";import{a as l,c as u,i as d,n as f,r as p}from"./locale-store-DPZ79W1-.js";import{t as m}from"./messages-BiYTyLJr.js";import{i as h}from"./vendor-swr-BIWyz7Rc.js";import{t as g}from"./button-CS04eWY9.js";import{Br as _,Eo as v,Ka as y,To as b,wo as x}from"./index-DJo4DimT.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-DDY9qoXZ.js";import{c as D,d as O,s as k}from"./voice-config-api-SKCeQLrH.js";import{t as A}from"./voice-api-key-field-BZbKQ8HT.js";import{t as j}from"./schema-form-IWmb05DX.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 c(b,x)}function R(){return c(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,v,`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=m(f(e=>e.language)),i=r.voiceSettings,a=r.extensionSttMedia,l={maskedHelp:i.apiKeyMaskedHelp,copy:i.apiKeyCopy,copied:i.apiKeyCopied,show:i.apiKeyShow,hide:i.apiKeyHide,notInConfigFile:i.apiKeyNotInConfigFile,loadFailed:i.apiKeyRevealFailed},{data:u}=h(p(`/api/voice/stt-providers`),D,{revalidateOnFocus:!1}),d=(0,M.useMemo)(()=>u?.providers.find(t=>t.id===e),[e,u]),g=d?.configured??!1,_=d?.models??[],v=_[0]?.id??d?.fields.find(e=>e.key===`model`)?.defaultValue??``,y=(0,M.useMemo)(()=>z(t,e,v),[v,e,t]),b=(0,M.useRef)(!1),[S,C]=(0,M.useState)(null),w=S??y,k=(0,M.useRef)(w);k.current=w;let j=y,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),b.current=JSON.stringify(k.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:c(`rounded-full px-2 py-0.5 text-xs font-medium`,g?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-amber-500/10 text-amber-800 dark:text-amber-200`),children:g?a.configured:a.notConfigured})]})]}),(0,P.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,P.jsxs)(`div`,{className:c(`flex flex-col gap-1.5`,x),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=>{b.current=!0,C(t=>({...t??y,apiKey:e}))},labels:l,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:c(`flex flex-col gap-1.5`,x),children:[(0,P.jsx)(F,{children:i.stt.model}),I.length>0?(0,P.jsx)(o,{className:L(),value:w.model,onChange:e=>{b.current=!0,C(t=>({...t??y,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=>{b.current=!0,C(t=>({...t??y,model:e.target.value}))}})]})]})]})}function V(e){let t=(0,N.c)(13),{extensionId:n}=e,r=f(U),i=u(H),a;t[0]===n?a=t[1]:(a=()=>l(p(`/api/extensions/${encodeURIComponent(n)}`)),t[0]=n,t[1]=a);let{data:o,isLoading:s}=h(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 d=c,m;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(m={revalidateOnFocus:!1},t[4]=m):m=t[4];let{data:g,mutate:_,isLoading:v}=h(i?`voice-settings-ext-stt`:null,k,m);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(!d){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(!g)return null;let y=`${n}:${d}`,b;return t[8]!==_||t[9]!==d||t[10]!==y||t[11]!==g?(b=(0,P.jsx)(B,{providerId:d,voiceSettings:g,mutateVoice:_},y),t[8]=_,t[9]=d,t[10]=y,t[11]=g,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=u(e=>!!e.conversationId),{data:n,error:r}=h(t&&e?`ext-detail-${e}`:null,()=>l(p(`/api/extensions/${encodeURIComponent(e)}`))),{data:i,mutate:a,error:o}=h(t&&e?`ext-cfg-${e}`:null,()=>l(p(`/api/extensions/${encodeURIComponent(e)}/config`))),s=n?.manifest?.configSchema,c=(0,M.useMemo)(()=>s&&s.type===`object`?G(s):{},[s]),f=(0,M.useMemo)(()=>({...c,...i??{}}),[c,i]),[m,_]=(0,M.useReducer)(K,{localValues:{},isDirty:!1}),v=(0,M.useRef)(!1),y=(0,M.useRef)(m.localValues);y.current=m.localValues;let b=(0,M.useRef)(f);!v.current&&b.current!==f&&(b.current=f,_({type:`sync`,value:f}));let x=(0,M.useCallback)(e=>{v.current=!0,_({type:`change`,value:e})},[]),S=(0,M.useCallback)(()=>{!s||s.type!==`object`||(v.current=!0,_({type:`reset-defaults`,value:{...G(s)}}))},[s]),C=(0,M.useCallback)(async t=>{if(!e)return;let n=await d(p(`/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),_({type:`saved`,value:t}),v.current=JSON.stringify(y.current)!==JSON.stringify(t)},[e,a]),w=E({value:m.localValues,dirty:m.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)(g,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:S,children:`Reset to defaults`})]})]}),(0,P.jsx)(j,{schema:s,values:m.localValues,onChange:x})]})}function J(){let e=(0,N.c)(38),t=f(Y),n;e[0]===t?n=e[1]:(n=m(t),e[0]=t,e[1]=n);let r=n.extensionSttMedia,{extensionId:o,panelId:s}=i(),c=y();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 l,u,d;if(e[3]!==o||e[4]!==c||e[5]!==s){d=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),l=c.find(t),!l){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),d=n;break bb0}let n=l.ui?.contributions?.settingsPanels;u=s?n?.find(e=>e.id===s||e.id===`${o}.${s}`):n?.[0]}e[3]=o,e[4]=c,e[5]=s,e[6]=l,e[7]=u,e[8]=d}else l=e[6],u=e[7],d=e[8];if(d!==Symbol.for(`react.early_return_sentinel`))return d;let p=u,h=!!(p&&l.ui),g=!!l.hasConfigSchema,v=l.kind===`media-provider`;if(!g&&!h&&!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 b=p?.title??`${l.name} Settings`,x;e[15]===b?x=e[16]:(x=(0,P.jsx)(S,{title:b}),e[15]=b,e[16]=x);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]!==g?(E=g?(0,P.jsx)(q,{extensionId:o}):null,e[23]=o,e[24]=g,e[25]=E):E=e[25];let D;e[26]!==l.name||e[27]!==l.ui||e[28]!==o||e[29]!==h||e[30]!==p?(D=h&&p&&l.ui?(0,P.jsx)(`div`,{className:`overflow-hidden rounded-xl bg-surface-base shadow-surface`,children:(0,P.jsx)(_,{extensionId:o,extensionName:l.name,entrypoint:p.entrypoint,permissions:l.ui?.permissions,title:p.title,className:`w-full`,minHeight:120,maxHeight:2e3})}):null,e[26]=l.name,e[27]=l.ui,e[28]=o,e[29]=h,e[30]=p,e[31]=D):D=e[31];let O;return e[32]!==x||e[33]!==w||e[34]!==T||e[35]!==E||e[36]!==D?(O=(0,P.jsxs)(C,{gap:`gap-5`,children:[x,w,T,E,D]}),e[32]=x,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{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-msTfRK8P.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-DPZ79W1-.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-msTfRK8P.js";import{a as t,c as n,i as r,l as i,m as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"./schemas-BaskVM5g.js";import{t as p}from"./gateway-realtime-store-BLDgrJ30.js";var ee=25*1024*1024,m=d([`web`,`desktop`,`mobile`,`browser`]),h=d([`foreground`,`background`]),te=d([`read`,`write`,`destructive`]),g=d([`never`,`always`]),_=d([`text`,`json`,`file`]),ne=d([`public`,`personal`]),v=f().min(1).max(160),re=f().min(32).max(160).regex(/^[A-Za-z0-9_-]+$/);r(`type`,[i({type:t(`endpoint`),endpointId:v}),i({type:t(`channel`),channel:f().min(1).max(64)}),i({type:t(`system`),source:d([`cli`,`automation`,`heartbeat`,`workflow`,`internal`])})]).options[0].extend({token:re});var ie=a(),y=s().int().nonnegative(),b=n(f(),c()),x=i({name:f().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120),title:f().min(1).max(120),description:f().min(1).max(2e3),inputSchema:b,outputSchema:b,policyId:f().regex(/^[a-z][a-z0-9_.-]+$/).max(120),sensitivity:ne,effect:te,confirmation:g,requiresForeground:l(),requiredPermissions:o(f().min(1).max(120)).max(20),timeoutMs:s().int().min(1e3).max(3e5),maxConcurrency:s().int().min(1).max(4),supportsCancellation:l(),idempotent:l(),resultKinds:o(_).min(1).max(3)});i({principalId:v,displayName:f().min(1).max(120),kind:m,platform:f().min(1).max(80),publicKey:f().min(32).max(2048)}),i({endpointId:v});var S=f().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120);i({jobId:a(),endpointId:v,capability:S,input:b,idempotencyKey:v,consentGrantId:v,createdAt:y,expiresAt:y}),i({jobId:a(),status:d([`queued`,`running`,`succeeded`,`failed`,`cancelled`]),updatedAt:y,output:b.optional(),error:i({code:v,message:f().min(1).max(2e3)}).optional()}),i({eventId:a(),endpointId:v,subscriptionId:v,eventType:S,data:b,occurredAt:y});var ae=i({principalId:v,endpointId:v,connectionInstanceId:a(),displayName:f().min(1).max(120),kind:m,platform:f().min(1).max(80),appVersion:f().min(1).max(80),availability:h,nonce:v,signedAt:y,signature:f().min(16).max(1024),tools:o(x).max(100)}),oe=i({invocationId:a(),toolCallId:v,toolName:x.shape.name,arguments:b,descriptorRevision:f().min(1).max(128),confirmationRequired:l(),deadlineAt:y,uploadGrant:i({path:f().startsWith(`/`).max(500),token:v,maxBytes:s().int().positive(),maxFiles:s().int().min(1).max(20),expiresAt:y}).optional()}),C=i({invocationId:a(),reason:f().min(1).max(500)}),w=i({invocationId:a()}),T=r(`type`,[i({type:t(`text`),text:f().max(256*1024)}),i({type:t(`json`),value:c()}),i({type:t(`file`),fileId:v,name:f().min(1).max(255),mimeType:f().min(1).max(255),size:s().int().nonnegative(),sha256:f().regex(/^[a-f0-9]{64}$/)})]),E=d([`ENDPOINT_OFFLINE`,`ENDPOINT_NOT_FOREGROUND`,`ENDPOINT_DISCONNECTED`,`TOOL_NOT_FOUND`,`TOOL_REVISION_MISMATCH`,`INVALID_ARGUMENTS`,`PERMISSION_DENIED`,`USER_DENIED`,`TOOL_BUSY`,`TOOL_TIMEOUT`,`TOOL_CANCELLED`,`RESULT_TOO_LARGE`,`PROTOCOL_ERROR`]),D=(e,n)=>i({protocolVersion:t(2),messageId:ie,type:t(e),sentAt:y,payload:n}),O=r(`type`,[D(`endpoint.availability_changed`,i({availability:h})),D(`tool.received`,w),D(`tool.progress`,i({invocationId:a(),message:f().max(500).optional(),percent:s().min(0).max(100).optional()})),D(`tool.result`,i({invocationId:a(),content:o(T).min(1).max(20),details:b.optional()})),D(`tool.error`,i({invocationId:a(),code:E,message:f().min(1).max(2e3)})),D(`tool.cancelled`,w)]),se=r(`type`,[D(`tool.invoke`,oe),D(`tool.cancel`,C)]),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=15e3,M=45e3,N=[`realtime.capability-negotiation.v1`],P=d([`web`,`desktop`,`mobile`,`browser_extension`,`tui`,`mcp`]),F=f().min(1).max(512),I=f().regex(/^[a-z][a-z0-9_.-]*$/).max(160),L=a(),R=s().int().nonnegative(),z=s().int().positive(),B=f().min(1).max(160),V=(e,n)=>u({protocolVersion:t(2),messageId:L,kind:t(e),sentAt:R,payload:n}),H=u({topic:F,afterSeq:s().int().nonnegative().optional()});r(`kind`,[V(`realtime.hello`,u({ticket:f().min(32).max(512),clientId:f().min(1).max(160),clientKind:P,subscriptions:o(H).max(100).default([]),capabilities:o(B).max(64).optional(),endpoint:ae.optional()})),V(`realtime.subscribe`,u({subscriptions:o(H).min(1).max(100)})),V(`realtime.unsubscribe`,u({topics:o(F).min(1).max(100)})),V(`realtime.ping`,u({})),V(`endpoint.message`,O)]);var U=u({topic:F,seq:z,event:I,data:c()}),W=r(`kind`,[V(`realtime.ready`,u({connectionId:a(),heartbeatIntervalMs:t(j),heartbeatTimeoutMs:t(M),negotiatedCapabilities:o(B).max(64).optional(),endpoint:u({endpointId:f().min(1).max(160),turnToken:f().min(32).max(160)}).optional()})),V(`realtime.event`,U),V(`realtime.subscribed`,u({topic:F,cursor:s().int().nonnegative()})),V(`realtime.gap`,u({topic:F,requestedSeq:s().int().nonnegative(),earliestSeq:z,recoverable:l()})),V(`realtime.pong`,u({})),V(`realtime.error`,u({code:f().min(1).max(80),message:f().min(1).max(500)})),V(`endpoint.message`,se)]);function ue(e){return W.parse(e)}var G=class extends Error{retryable;constructor(e,t){super(e),this.retryable=t,this.name=`RealtimeConnectionError`}};function de(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 fe(e){return e===1009||e===4400||e===4401||e===4409||e===4413}var pe=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=N.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(de(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})`,!fe(e.code))}}catch(e){s(e instanceof Error?e.message:`Realtime connection failed`,!(e instanceof G)||e.retryable)}}handleServerMessage(e){let t=ue(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);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){!this.socket||this.socket.readyState!==1||this.socket.send(JSON.stringify(e))}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}},me=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}))},me)}function he(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 ge(){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 $(){let t=new URL(e(`/api/realtime/v1/ws`));return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()}function _e(){let t=ge(),n=window.electronAPI?`desktop`:`web`,r=new pe({clientId:t,clientKind:n,getWebSocketUrl:$,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`)&&he(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 ve(e){return Q=e,Z?.setEndpoint(e),()=>{Q===e&&(Q=void 0,Z?.clearEndpoint(e))}}function ye(e){Z?.sendEndpointMessage(e)}function be(){Z?.reconnect()}function xe(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{xe as a,ee as c,A as d,T as f,_e as i,ce as l,be as n,J as o,ye as r,le as s,ve as t,k as u};
1
+ import{r as e}from"./locale-store-DPZ79W1-.js";import{a as t,c as n,i as r,l as i,m as a,n as o,o as s,p as c,r as l,s as u,t as d,u as f}from"./schemas-BaskVM5g.js";import{t as p}from"./gateway-realtime-store-BG95uGVW.js";var ee=25*1024*1024,m=d([`web`,`desktop`,`mobile`,`browser`]),h=d([`foreground`,`background`]),te=d([`read`,`write`,`destructive`]),g=d([`never`,`always`]),_=d([`text`,`json`,`file`]),ne=d([`public`,`personal`]),v=f().min(1).max(160),re=f().min(32).max(160).regex(/^[A-Za-z0-9_-]+$/);r(`type`,[i({type:t(`endpoint`),endpointId:v}),i({type:t(`channel`),channel:f().min(1).max(64)}),i({type:t(`system`),source:d([`cli`,`automation`,`heartbeat`,`workflow`,`internal`])})]).options[0].extend({token:re});var ie=a(),y=s().int().nonnegative(),b=n(f(),c()),x=i({name:f().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120),title:f().min(1).max(120),description:f().min(1).max(2e3),inputSchema:b,outputSchema:b,policyId:f().regex(/^[a-z][a-z0-9_.-]+$/).max(120),sensitivity:ne,effect:te,confirmation:g,requiresForeground:l(),requiredPermissions:o(f().min(1).max(120)).max(20),timeoutMs:s().int().min(1e3).max(3e5),maxConcurrency:s().int().min(1).max(4),supportsCancellation:l(),idempotent:l(),resultKinds:o(_).min(1).max(3)});i({principalId:v,displayName:f().min(1).max(120),kind:m,platform:f().min(1).max(80),publicKey:f().min(32).max(2048)}),i({endpointId:v});var S=f().regex(/^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/).max(120);i({jobId:a(),endpointId:v,capability:S,input:b,idempotencyKey:v,consentGrantId:v,createdAt:y,expiresAt:y}),i({jobId:a(),status:d([`queued`,`running`,`succeeded`,`failed`,`cancelled`]),updatedAt:y,output:b.optional(),error:i({code:v,message:f().min(1).max(2e3)}).optional()}),i({eventId:a(),endpointId:v,subscriptionId:v,eventType:S,data:b,occurredAt:y});var ae=i({principalId:v,endpointId:v,connectionInstanceId:a(),displayName:f().min(1).max(120),kind:m,platform:f().min(1).max(80),appVersion:f().min(1).max(80),availability:h,nonce:v,signedAt:y,signature:f().min(16).max(1024),tools:o(x).max(100)}),oe=i({invocationId:a(),toolCallId:v,toolName:x.shape.name,arguments:b,descriptorRevision:f().min(1).max(128),confirmationRequired:l(),deadlineAt:y,uploadGrant:i({path:f().startsWith(`/`).max(500),token:v,maxBytes:s().int().positive(),maxFiles:s().int().min(1).max(20),expiresAt:y}).optional()}),C=i({invocationId:a(),reason:f().min(1).max(500)}),w=i({invocationId:a()}),T=r(`type`,[i({type:t(`text`),text:f().max(256*1024)}),i({type:t(`json`),value:c()}),i({type:t(`file`),fileId:v,name:f().min(1).max(255),mimeType:f().min(1).max(255),size:s().int().nonnegative(),sha256:f().regex(/^[a-f0-9]{64}$/)})]),E=d([`ENDPOINT_OFFLINE`,`ENDPOINT_NOT_FOREGROUND`,`ENDPOINT_DISCONNECTED`,`TOOL_NOT_FOUND`,`TOOL_REVISION_MISMATCH`,`INVALID_ARGUMENTS`,`PERMISSION_DENIED`,`USER_DENIED`,`TOOL_BUSY`,`TOOL_TIMEOUT`,`TOOL_CANCELLED`,`RESULT_TOO_LARGE`,`PROTOCOL_ERROR`]),D=(e,n)=>i({protocolVersion:t(2),messageId:ie,type:t(e),sentAt:y,payload:n}),O=r(`type`,[D(`endpoint.availability_changed`,i({availability:h})),D(`tool.received`,w),D(`tool.progress`,i({invocationId:a(),message:f().max(500).optional(),percent:s().min(0).max(100).optional()})),D(`tool.result`,i({invocationId:a(),content:o(T).min(1).max(20),details:b.optional()})),D(`tool.error`,i({invocationId:a(),code:E,message:f().min(1).max(2e3)})),D(`tool.cancelled`,w)]),se=r(`type`,[D(`tool.invoke`,oe),D(`tool.cancel`,C)]),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=15e3,M=45e3,N=[`realtime.capability-negotiation.v1`],P=d([`web`,`desktop`,`mobile`,`browser_extension`,`tui`,`mcp`]),F=f().min(1).max(512),I=f().regex(/^[a-z][a-z0-9_.-]*$/).max(160),L=a(),R=s().int().nonnegative(),z=s().int().positive(),B=f().min(1).max(160),V=(e,n)=>u({protocolVersion:t(2),messageId:L,kind:t(e),sentAt:R,payload:n}),H=u({topic:F,afterSeq:s().int().nonnegative().optional()});r(`kind`,[V(`realtime.hello`,u({ticket:f().min(32).max(512),clientId:f().min(1).max(160),clientKind:P,subscriptions:o(H).max(100).default([]),capabilities:o(B).max(64).optional(),endpoint:ae.optional()})),V(`realtime.subscribe`,u({subscriptions:o(H).min(1).max(100)})),V(`realtime.unsubscribe`,u({topics:o(F).min(1).max(100)})),V(`realtime.ping`,u({})),V(`endpoint.message`,O)]);var U=u({topic:F,seq:z,event:I,data:c()}),W=r(`kind`,[V(`realtime.ready`,u({connectionId:a(),heartbeatIntervalMs:t(j),heartbeatTimeoutMs:t(M),negotiatedCapabilities:o(B).max(64).optional(),endpoint:u({endpointId:f().min(1).max(160),turnToken:f().min(32).max(160)}).optional()})),V(`realtime.event`,U),V(`realtime.subscribed`,u({topic:F,cursor:s().int().nonnegative()})),V(`realtime.gap`,u({topic:F,requestedSeq:s().int().nonnegative(),earliestSeq:z,recoverable:l()})),V(`realtime.pong`,u({})),V(`realtime.error`,u({code:f().min(1).max(80),message:f().min(1).max(500)})),V(`endpoint.message`,se)]);function ue(e){return W.parse(e)}var G=class extends Error{retryable;constructor(e,t){super(e),this.retryable=t,this.name=`RealtimeConnectionError`}};function de(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 fe(e){return e===1009||e===4400||e===4401||e===4409||e===4413}var pe=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=N.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(de(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})`,!fe(e.code))}}catch(e){s(e instanceof Error?e.message:`Realtime connection failed`,!(e instanceof G)||e.retryable)}}handleServerMessage(e){let t=ue(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);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){!this.socket||this.socket.readyState!==1||this.socket.send(JSON.stringify(e))}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}},me=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}))},me)}function he(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 ge(){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 $(){let t=new URL(e(`/api/realtime/v1/ws`));return t.protocol=t.protocol===`https:`?`wss:`:`ws:`,t.toString()}function _e(){let t=ge(),n=window.electronAPI?`desktop`:`web`,r=new pe({clientId:t,clientKind:n,getWebSocketUrl:$,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`)&&he(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 ve(e){return Q=e,Z?.setEndpoint(e),()=>{Q===e&&(Q=void 0,Z?.clearEndpoint(e))}}function ye(e){Z?.sendEndpointMessage(e)}function be(){Z?.reconnect()}function xe(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{xe as a,ee as c,A as d,T as f,_e as i,ce as l,be as n,J as o,ye as r,le as s,ve as t,k as u};
@@ -0,0 +1 @@
1
+ import{p as e}from"./locale-store-DPZ79W1-.js";var t=e(()=>({connectionState:`idle`,error:null}));function n(e){t.setState(e)}export{t as n,n as t};