@ensocode/server 0.3.2 → 0.3.4

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 (378) hide show
  1. package/README.md +10 -0
  2. package/out/node_modules/@earendil-works/pi-coding-agent/CHANGELOG.md +117 -0
  3. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/anthropic-messages-MGNURJ72.js +6 -0
  4. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{azure-openai-responses-FSC6BAW3.js → azure-openai-responses-4WDOP7MF.js} +1 -1
  5. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/bedrock-converse-stream.js +3 -3
  6. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-4KSTFUIK.js +19 -0
  7. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-4UNPP53I.js +55 -0
  8. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-CCYGJPSU.js +2 -0
  9. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-4EYXVSA5.js → chunk-FF6XOTWB.js} +9 -9
  10. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-FMPAMX2W.js +82 -0
  11. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-GFUN2N5K.js +2 -0
  12. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-C2WU32PX.js → chunk-H4W2F2IO.js} +1 -1
  13. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-IEBK4HQA.js +2 -0
  14. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-EOO47QGR.js → chunk-JLFZH7C6.js} +1 -1
  15. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-LCB5FO32.js +4 -0
  16. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-GN3QYODH.js → chunk-LQUBM7HF.js} +1 -1
  17. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-MABPTPMF.js +30 -0
  18. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-MPEFJ3RP.js +2 -0
  19. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-EBFHJFEE.js → chunk-PYBKJQVF.js} +1 -1
  20. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-VKJQ6CME.js +8 -0
  21. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-B46VJEHW.js → chunk-VUPOM3AH.js} +1 -1
  22. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-3TGLJEWK.js → chunk-WL4TUXY7.js} +1 -1
  23. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-V6KH5QG4.js → chunk-XM4MQFQV.js} +1 -1
  24. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{chunk-YZKQS34S.js → chunk-Y55SJART.js} +5 -1
  25. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
  26. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-ZKNSXGL5.js +1243 -0
  27. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{cli-MCOUW5WS.js → cli-35W4A75E.js} +7 -7
  28. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{cloudflare-workers-ai-system-one-WLAFJSP6.js → cloudflare-workers-ai-system-one-WKRH5HZA.js} +1 -1
  29. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/codemode-worker.js +2 -0
  30. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{easter-egg-3d-WMBNSJ4M.js → easter-egg-3d-GEVPKQF6.js} +1 -1
  31. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{execute-4CEBORGZ.js → execute-L2EEDV3L.js} +5 -3
  32. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/github-copilot.js +1 -1
  33. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{google-generative-ai-INGKNW72.js → google-generative-ai-VSMFCHJU.js} +1 -1
  34. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{google-vertex-IBTX6MBF.js → google-vertex-35UTLZJN.js} +1 -1
  35. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{llama-cpp-classify-V5U3QKXI.js → llama-cpp-classify-Z3SS4FP4.js} +1 -1
  36. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{mistral-conversations-S4OWXIXQ.js → mistral-conversations-LWJTUFIM.js} +1 -1
  37. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/openai-codex-responses-YYIXDJWF.js +10 -0
  38. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{openai-completions-EJNYB6IX.js → openai-completions-X2I4TQ2L.js} +3 -3
  39. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{openai-decisions-IXI34BYG.js → openai-decisions-GG3FBAIF.js} +1 -1
  40. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/openai-responses-5CX3GG6R.js +4 -0
  41. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{openrouter-images-PISKSFMS.js → openrouter-images-WHNK2UQG.js} +1 -1
  42. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{pi-messages-NORUKF4E.js → pi-messages-5CXWY5I7.js} +1 -1
  43. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{runtime-FQB7RU7U.js → runtime-J5ZSBGTX.js} +1 -1
  44. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/{typesafe-system-one-CHVC2UUI.js → typesafe-system-one-KA2SBSSD.js} +1 -1
  45. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/virtual-modules-7ZY53V4K.js +2 -0
  46. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/cli-runtime.js +1 -1
  47. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/index.js +1 -1
  48. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/rpc-entry.js +1 -1
  49. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/args.js +1 -1
  50. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-command.js +26 -2
  51. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-login.d.ts +15 -0
  52. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-login.js +232 -0
  53. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-logout.d.ts +14 -0
  54. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-logout.js +57 -0
  55. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-terminal.d.ts +17 -0
  56. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/auth-terminal.js +63 -0
  57. package/out/node_modules/@earendil-works/pi-coding-agent/dist/cli/config-selector.js +3 -1
  58. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.d.ts +5 -0
  59. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js +7 -0
  60. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.d.ts +25 -6
  61. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js +139 -50
  62. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js +3 -2
  63. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/bash-executor.js +3 -1
  64. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/cache-warmer.d.ts +4 -37
  65. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/cache-warmer.js +11 -89
  66. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/utils.js +2 -1
  67. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/index.d.ts +1 -1
  68. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js +10 -5
  69. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.d.ts +1 -0
  70. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.js +9 -1
  71. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/types.d.ts +28 -6
  72. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/keybindings.d.ts +2 -2
  73. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/keybindings.js +1 -1
  74. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/mcp-servers.d.ts +12 -37
  75. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/mcp-servers.js +42 -121
  76. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/model-config.d.ts +52 -0
  77. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/model-resolver.js +20 -19
  78. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/model-runtime.d.ts +5 -0
  79. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/model-runtime.js +11 -4
  80. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.d.ts +10 -1
  81. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +50 -5
  82. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/pi-ai-schemas.d.ts +4 -0
  83. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/preferred-providers.d.ts +17 -0
  84. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/preferred-providers.js +24 -0
  85. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js +18 -2
  86. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/provider-composer.js +3 -1
  87. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/provider-matching.d.ts +6 -0
  88. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/provider-matching.js +8 -0
  89. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/radius-mcp.d.ts +13 -0
  90. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/radius-mcp.js +29 -0
  91. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/remote-catalog-provider.js +2 -0
  92. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/runtime-credentials.d.ts +8 -0
  93. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/runtime-credentials.js +15 -1
  94. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-defaults.d.ts +1 -1
  95. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-defaults.js +1 -1
  96. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +35 -5
  97. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.d.ts +23 -14
  98. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js +182 -41
  99. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +8 -7
  100. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js +82 -36
  101. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.d.ts +5 -3
  102. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js +87 -75
  103. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js +2 -1
  104. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/powershell.js +15 -2
  105. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.d.ts +8 -0
  106. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js +141 -25
  107. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.d.ts +4 -14
  108. package/out/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +23 -29
  109. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/execute.js +4 -4
  110. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/tool.js +34 -12
  111. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/llama/client.d.ts +2 -0
  112. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/llama/client.js +23 -2
  113. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/llama/ui.js +15 -3
  114. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/cli.d.ts +2 -0
  115. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/cli.js +49 -14
  116. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/config.js +4 -7
  117. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/index.js +4 -3
  118. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/oauth.d.ts +11 -49
  119. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/oauth.js +56 -319
  120. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/resources.d.ts +1 -1
  121. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/resources.js +4 -3
  122. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/runtime.d.ts +4 -3
  123. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/runtime.js +7 -5
  124. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/tools.d.ts +2 -23
  125. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/mcp/tools.js +6 -58
  126. package/out/node_modules/@earendil-works/pi-coding-agent/dist/extensions/tool-search/tool.js +18 -6
  127. package/out/node_modules/@earendil-works/pi-coding-agent/dist/index.d.ts +1 -1
  128. package/out/node_modules/@earendil-works/pi-coding-agent/dist/main.js +46 -0
  129. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.d.ts +5 -1
  130. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js +12 -4
  131. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts +5 -1
  132. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js +12 -4
  133. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.d.ts +5 -2
  134. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.js +10 -3
  135. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/diff.js +11 -5
  136. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-selector.js +9 -1
  137. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +1 -18
  138. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/mermaid.d.ts +2 -1
  139. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/mermaid.js +25 -20
  140. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/model-selector.js +14 -6
  141. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/oauth-selector.d.ts +10 -3
  142. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js +32 -5
  143. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/provider-brand.d.ts +14 -0
  144. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/provider-brand.js +66 -0
  145. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/radius-login-selector.d.ts +1 -2
  146. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/radius-login-selector.js +6 -37
  147. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +5 -1
  148. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js +12 -4
  149. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts +1 -0
  150. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tree-selector.js +19 -10
  151. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +11 -1
  152. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +110 -63
  153. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js +4 -0
  154. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/print-mode.js +19 -10
  155. package/out/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js +53 -23
  156. package/out/node_modules/@earendil-works/pi-coding-agent/dist/package-manager-cli.js +39 -8
  157. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/changelog.d.ts +2 -2
  158. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/changelog.js +12 -6
  159. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js +3 -1
  160. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/terminal-question.d.ts +8 -0
  161. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/terminal-question.js +24 -0
  162. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/web-url.d.ts +12 -0
  163. package/out/node_modules/@earendil-works/pi-coding-agent/dist/utils/web-url.js +20 -0
  164. package/out/node_modules/@earendil-works/pi-coding-agent/docs/cli.md +14 -1
  165. package/out/node_modules/@earendil-works/pi-coding-agent/docs/extensions.md +27 -7
  166. package/out/node_modules/@earendil-works/pi-coding-agent/docs/keybindings.md +1 -1
  167. package/out/node_modules/@earendil-works/pi-coding-agent/docs/llama-cpp.md +4 -7
  168. package/out/node_modules/@earendil-works/pi-coding-agent/docs/models-configuration.md +6 -1
  169. package/out/node_modules/@earendil-works/pi-coding-agent/docs/models.md +2 -1
  170. package/out/node_modules/@earendil-works/pi-coding-agent/docs/prompt-templates.md +1 -1
  171. package/out/node_modules/@earendil-works/pi-coding-agent/docs/providers.md +1 -1
  172. package/out/node_modules/@earendil-works/pi-coding-agent/docs/rpc.md +4 -2
  173. package/out/node_modules/@earendil-works/pi-coding-agent/docs/settings.md +1 -1
  174. package/out/node_modules/@earendil-works/pi-coding-agent/docs/tui.md +1 -1
  175. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  176. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-anthropic/package.json +1 -1
  177. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  178. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/gondolin/package-lock.json +2 -2
  179. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/gondolin/package.json +1 -1
  180. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/plan-mode/index.ts +23 -13
  181. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/plan-mode/utils.ts +42 -16
  182. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/README.md +14 -11
  183. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/index.ts +392 -171
  184. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/with-deps/package-lock.json +2 -2
  185. package/out/node_modules/@earendil-works/pi-coding-agent/examples/extensions/with-deps/package.json +1 -1
  186. package/out/node_modules/@earendil-works/pi-coding-agent/examples/tsconfig.json +63 -35
  187. package/out/node_modules/@earendil-works/pi-coding-agent/package.json +7 -7
  188. package/out/node_modules/@earendil-works/pi-coding-agent/schemas/models.schema.json +29 -0
  189. package/out/node_modules/@earendil-works/pi-coding-agent/schemas/settings.schema.json +1 -1
  190. package/out/phone/assets/{abnfDiagram-VCTEODGH-7wNFPVNX.js → abnfDiagram-VCTEODGH-6JYofuK8.js} +1 -1
  191. package/out/phone/assets/architecture-7GRP2DOG-D7mwyuxS.js +1 -0
  192. package/out/phone/assets/{architectureDiagram-5GKGNRK7-CnuIop2x.js → architectureDiagram-5GKGNRK7-BeLeAQB1.js} +1 -1
  193. package/out/phone/assets/{blockDiagram-I7D4REHJ-JVET2iOX.js → blockDiagram-I7D4REHJ-uXn3vhT2.js} +1 -1
  194. package/out/phone/assets/{c4Diagram-7LVT6UL2-BLFmpm8Y.js → c4Diagram-7LVT6UL2-CjzMFRll.js} +1 -1
  195. package/out/phone/assets/channel-BsGN1oT0.js +1 -0
  196. package/out/phone/assets/{chunk-4HAMMTFA-t_CWzvX0.js → chunk-4HAMMTFA-BA8HaYy2.js} +1 -1
  197. package/out/phone/assets/{chunk-75Z2AOVW-Ck9s4XbN.js → chunk-75Z2AOVW-BhIfO9es.js} +1 -1
  198. package/out/phone/assets/{chunk-DU6HZSFF-Clg-W8ZP.js → chunk-DU6HZSFF-BTLBHwj-.js} +1 -1
  199. package/out/phone/assets/{chunk-F27PBJKO-Dg6DF7tm.js → chunk-F27PBJKO-CUw8NZk8.js} +1 -1
  200. package/out/phone/assets/{chunk-GMAD6QVW-tyN1lr56.js → chunk-GMAD6QVW-bZOKnRyM.js} +1 -1
  201. package/out/phone/assets/{chunk-GVQU2GXP-Cp6zlp3q.js → chunk-GVQU2GXP-B0WIm1dS.js} +1 -1
  202. package/out/phone/assets/{chunk-IMKFNOWR-DivN0qgp.js → chunk-IMKFNOWR-DWND4rEr.js} +1 -1
  203. package/out/phone/assets/{chunk-L3NEJ4N5-H6AVmtE_.js → chunk-L3NEJ4N5-DgMknY3k.js} +1 -1
  204. package/out/phone/assets/{chunk-OSK3NFVY-D8Gtw0_S.js → chunk-OSK3NFVY-C5aEouov.js} +1 -1
  205. package/out/phone/assets/{chunk-P2QGCYS3-RZSHAUZq.js → chunk-P2QGCYS3-D2ID3RxV.js} +1 -1
  206. package/out/phone/assets/{chunk-POPQ4Y6H-BVS8pZqz.js → chunk-POPQ4Y6H-C1lOuNpV.js} +1 -1
  207. package/out/phone/assets/{chunk-PWAF6VOD-D7FryQWf.js → chunk-PWAF6VOD-CfqWQZRE.js} +1 -1
  208. package/out/phone/assets/{chunk-SHT3W25Y-DGdqMpPQ.js → chunk-SHT3W25Y-p37Dlvn4.js} +1 -1
  209. package/out/phone/assets/{chunk-SVP7TREG-BwyiT08_.js → chunk-SVP7TREG-CSSqW-zb.js} +1 -1
  210. package/out/phone/assets/{chunk-TICWLB2K-CY7mq27-.js → chunk-TICWLB2K-Bse5ne4b.js} +1 -1
  211. package/out/phone/assets/classDiagram-ZZMXUADV-a1PUvjC2.js +1 -0
  212. package/out/phone/assets/classDiagram-v2-VYDZK3BY-a1PUvjC2.js +1 -0
  213. package/out/phone/assets/{cynefin-OW5HDTMX-ep90c-ad.js → cynefin-OW5HDTMX-BGQqPhYk.js} +1 -1
  214. package/out/phone/assets/{cynefinDiagram-5FMLGOSQ-M8djyXi6.js → cynefinDiagram-5FMLGOSQ-Cz3XWaxY.js} +1 -1
  215. package/out/phone/assets/{dagre-GXQ25YYZ-Qp6_rUFB.js → dagre-GXQ25YYZ-CjAF6lSz.js} +1 -1
  216. package/out/phone/assets/desk-1McWacjU.js +2 -0
  217. package/out/phone/assets/{diagram-S7CK7UJ4-78nJmih8.js → diagram-S7CK7UJ4-B135cp5a.js} +1 -1
  218. package/out/phone/assets/{diagram-UQ7AKVKN-DK3Lux6Z.js → diagram-UQ7AKVKN-C4pCe0fQ.js} +1 -1
  219. package/out/phone/assets/{diagram-VSXAHHWV-8uHrV5vL.js → diagram-VSXAHHWV-CYkCrin2.js} +1 -1
  220. package/out/phone/assets/{diagram-VX7I27RA-DM2jP_ep.js → diagram-VX7I27RA-CT_vufh_.js} +1 -1
  221. package/out/phone/assets/{diagram-Z3DM3KII-Dk6weE7F.js → diagram-Z3DM3KII-XEkkXu3P.js} +1 -1
  222. package/out/phone/assets/{ebnfDiagram-PWID7BFC-CcOU0Q-s.js → ebnfDiagram-PWID7BFC-DfLyeXjw.js} +1 -1
  223. package/out/phone/assets/{erDiagram-RLTQ6QDP-Cv4zHR88.js → erDiagram-RLTQ6QDP-pKNbKkAP.js} +1 -1
  224. package/out/phone/assets/eventmodeling-NTZA5JFV-DcUsfQiW.js +1 -0
  225. package/out/phone/assets/flowDiagram-HODETNUW-sUobw8zi.js +1 -0
  226. package/out/phone/assets/{ganttDiagram-EL5Y4UJY-DpMAd_jd.js → ganttDiagram-EL5Y4UJY-Df4E50Mj.js} +1 -1
  227. package/out/phone/assets/{gitGraph-4MIJSDKK-CeZWGC9r.js → gitGraph-4MIJSDKK-CkjzZeFD.js} +1 -1
  228. package/out/phone/assets/{gitGraphDiagram-WWUBYQGX-6QsSrkNy.js → gitGraphDiagram-WWUBYQGX-CBxfRAfy.js} +1 -1
  229. package/out/phone/assets/{info-A6RAGUB7-C-8QwtyE.js → info-A6RAGUB7-CHFXa2pw.js} +1 -1
  230. package/out/phone/assets/{infoDiagram-27XIBGKW-BEywxx6y.js → infoDiagram-27XIBGKW-K0DnZhi4.js} +1 -1
  231. package/out/phone/assets/{ishikawaDiagram-5VMMS53U-Dv5MWe8O.js → ishikawaDiagram-5VMMS53U-DTQF2ZuR.js} +1 -1
  232. package/out/phone/assets/{journeyDiagram-3NMN7TZE-rZqFk8KG.js → journeyDiagram-3NMN7TZE-wBltkU2i.js} +1 -1
  233. package/out/phone/assets/{kanban-definition-UXKFOSKX-Vbp8P778.js → kanban-definition-UXKFOSKX-BZpcOajP.js} +1 -1
  234. package/out/phone/assets/{line-DtO-RzWq.js → line-BflnZFgp.js} +1 -1
  235. package/out/phone/assets/main-CnA1zWP8.css +1 -0
  236. package/out/phone/assets/main-Crtf_g8h.js +1643 -0
  237. package/out/phone/assets/{mermaid-parser.core-CZ9_GWM0.js → mermaid-parser.core-BiCTmcqa.js} +3 -3
  238. package/out/phone/assets/{mermaid.core-B15T44DF.js → mermaid.core-D3TwYaLF.js} +4 -4
  239. package/out/phone/assets/{mindmap-definition-YA3MSWOX-BgFUJmH3.js → mindmap-definition-YA3MSWOX-Cz0aS_6Y.js} +1 -1
  240. package/out/phone/assets/{packet-AYTQ26CC--RETlRVk.js → packet-AYTQ26CC-DW-djbhd.js} +1 -1
  241. package/out/phone/assets/{pegDiagram-XKGWAZYB-D7jmN93W.js → pegDiagram-XKGWAZYB-CE0sZZAE.js} +1 -1
  242. package/out/phone/assets/{pie-WAS4IAKB-CxG1AbYJ.js → pie-WAS4IAKB-CKGFlXok.js} +1 -1
  243. package/out/phone/assets/{pieDiagram-E7YTZNPT-CHxSdknk.js → pieDiagram-E7YTZNPT-BrnQ32_6.js} +1 -1
  244. package/out/phone/assets/{quadrantDiagram-AXDQQJYC-707LGShZ.js → quadrantDiagram-AXDQQJYC-BrxDAygB.js} +1 -1
  245. package/out/phone/assets/{radar-RG4KPBEZ-BBg9aR2Q.js → radar-RG4KPBEZ-Bo2f5QyA.js} +1 -1
  246. package/out/phone/assets/{railroad-74A4TZTK-BvqQaIGQ.js → railroad-74A4TZTK-BZEmm0Ha.js} +1 -1
  247. package/out/phone/assets/railroad-abnf-HS5TGJTU-CGiIT1ZV.js +1 -0
  248. package/out/phone/assets/railroad-ebnf-LZEXJU2U-C85Q3c0J.js +1 -0
  249. package/out/phone/assets/railroad-peg-WCYAUIDC-8qPPCLgU.js +1 -0
  250. package/out/phone/assets/{railroadDiagram-O6MQD6OU-BQUOk6Jm.js → railroadDiagram-O6MQD6OU-BvOyUNMC.js} +1 -1
  251. package/out/phone/assets/{requirementDiagram-BXWQKSXE-ByuJLR7x.js → requirementDiagram-BXWQKSXE-T42N3TW5.js} +1 -1
  252. package/out/phone/assets/{sankeyDiagram-P5KCCOFB-CaWA3qV1.js → sankeyDiagram-P5KCCOFB-0us9ErVV.js} +1 -1
  253. package/out/phone/assets/{sequenceDiagram-WJ2MYXX4--wDiyJo9.js → sequenceDiagram-WJ2MYXX4-BMcYh2ll.js} +1 -1
  254. package/out/phone/assets/{stateDiagram-D77RDMKH-ScVywISP.js → stateDiagram-D77RDMKH-CgP9dUc3.js} +1 -1
  255. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-WM4CNSf-.js +1 -0
  256. package/out/phone/assets/storage-CahQ0cyN.js +1 -0
  257. package/out/phone/assets/{swimlanes-42K2YHIH-Da4TbCnQ.js → swimlanes-42K2YHIH-VnE4ceCW.js} +1 -1
  258. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-65AiMWVp.js +8 -0
  259. package/out/phone/assets/{timeline-definition-24CTP7MA-Csp8wyPz.js → timeline-definition-24CTP7MA-tH3izgae.js} +1 -1
  260. package/out/phone/assets/{treeView-Q6P3EWNA-DP_TpAnB.js → treeView-Q6P3EWNA-CVFDOC7i.js} +1 -1
  261. package/out/phone/assets/{treemap-WGGIJYW6-CDX7X9Iz.js → treemap-WGGIJYW6-vmikHzt3.js} +1 -1
  262. package/out/phone/assets/{vennDiagram-4TSXK5OY-DU4FDr9s.js → vennDiagram-4TSXK5OY-b8ttDCR-.js} +1 -1
  263. package/out/phone/assets/{wardley-WFR3VGLG-DJY3i8km.js → wardley-WFR3VGLG-D32vKoC1.js} +1 -1
  264. package/out/phone/assets/{wardleyDiagram-VM6X3IG4-CDWkRMg4.js → wardleyDiagram-VM6X3IG4-CMkaIPVH.js} +1 -1
  265. package/out/phone/assets/{xychartDiagram-S5SC5T6Z-DAWohWCi.js → xychartDiagram-S5SC5T6Z-pLYDcql3.js} +1 -1
  266. package/out/phone/desk.html +2 -2
  267. package/out/phone/index.html +3 -3
  268. package/out/renderer/assets/{abnfDiagram-VCTEODGH-CyBOQPqT.js → abnfDiagram-VCTEODGH-N6OiVFQx.js} +1 -1
  269. package/out/renderer/assets/{arc-JLdYPu0k.js → arc-CXVc3U0J.js} +1 -1
  270. package/out/renderer/assets/{architectureDiagram-5GKGNRK7-Bq5gy8K8.js → architectureDiagram-5GKGNRK7-BT5CXpcQ.js} +1 -1
  271. package/out/renderer/assets/{blockDiagram-I7D4REHJ-Bno0lw2B.js → blockDiagram-I7D4REHJ-C32Vqzip.js} +1 -1
  272. package/out/renderer/assets/{c4Diagram-7LVT6UL2-BC6INPz6.js → c4Diagram-7LVT6UL2-qjwL2BP8.js} +1 -1
  273. package/out/renderer/assets/channel-B1Cv56hA.js +1 -0
  274. package/out/renderer/assets/{chunk-2Q5K7J3B-CcyqDHha.js → chunk-2Q5K7J3B-YC6CQiyD.js} +1 -1
  275. package/out/renderer/assets/{chunk-5VM5RSS4-QSbyABj3.js → chunk-5VM5RSS4-E-kluPz3.js} +1 -1
  276. package/out/renderer/assets/{chunk-F27PBJKO-4574JVSg.js → chunk-F27PBJKO-Bhx1_P75.js} +1 -1
  277. package/out/renderer/assets/{chunk-IMKFNOWR-DCaKjC49.js → chunk-IMKFNOWR-Dgb_730B.js} +1 -1
  278. package/out/renderer/assets/{chunk-JWPE2WC7-CbFsKOIM.js → chunk-JWPE2WC7-COQNHw4u.js} +1 -1
  279. package/out/renderer/assets/{chunk-POPQ4Y6H-B6j8RfR6.js → chunk-POPQ4Y6H-CQz4hRgP.js} +1 -1
  280. package/out/renderer/assets/{chunk-SVP7TREG-kRAl0a5G.js → chunk-SVP7TREG-DGp9XQFd.js} +1 -1
  281. package/out/renderer/assets/{chunk-TICWLB2K-BgG8vTk6.js → chunk-TICWLB2K-CovR1uHr.js} +1 -1
  282. package/out/renderer/assets/{chunk-XXDRQBXY-DdqB8mBq.js → chunk-XXDRQBXY-gVmqSU5b.js} +1 -1
  283. package/out/renderer/assets/classDiagram-ZZMXUADV-CDWgELaf.js +1 -0
  284. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-CDWgELaf.js +1 -0
  285. package/out/renderer/assets/{cose-bilkent-JH36ORCC-HfctEoii.js → cose-bilkent-JH36ORCC-DD4PEqt_.js} +1 -1
  286. package/out/renderer/assets/{cynefin-OW5HDTMX-BNigpbGU.js → cynefin-OW5HDTMX-DNsYCrBx.js} +1 -1
  287. package/out/renderer/assets/{cynefinDiagram-5FMLGOSQ-CL-lRXZ7.js → cynefinDiagram-5FMLGOSQ-CoSzqs25.js} +1 -1
  288. package/out/renderer/assets/{cytoscape-fcose-B40eUKiT.js → cytoscape-fcose-CV0MpCmk.js} +1 -1
  289. package/out/renderer/assets/{dagre-GXQ25YYZ-D7VwJTHe.js → dagre-GXQ25YYZ-BxpTPeHN.js} +1 -1
  290. package/out/renderer/assets/{diagram-S7CK7UJ4-CAp3JWMB.js → diagram-S7CK7UJ4-Df_OM1vW.js} +1 -1
  291. package/out/renderer/assets/{diagram-UQ7AKVKN-H_c4KXAy.js → diagram-UQ7AKVKN-iovjmny_.js} +1 -1
  292. package/out/renderer/assets/{diagram-VSXAHHWV-CsEX84Cq.js → diagram-VSXAHHWV-BMrwlcQx.js} +1 -1
  293. package/out/renderer/assets/{diagram-VX7I27RA-ebIy3O1D.js → diagram-VX7I27RA-DqLh449X.js} +1 -1
  294. package/out/renderer/assets/{diagram-Z3DM3KII-BtVfEzv9.js → diagram-Z3DM3KII-CH_W77UO.js} +1 -1
  295. package/out/renderer/assets/{ebnfDiagram-PWID7BFC-C25YK-UV.js → ebnfDiagram-PWID7BFC-yjzodXoL.js} +1 -1
  296. package/out/renderer/assets/{erDiagram-RLTQ6QDP-1imAb8Go.js → erDiagram-RLTQ6QDP-DXxhvHYS.js} +1 -1
  297. package/out/renderer/assets/{flowDiagram-HODETNUW-OwceYbhd.js → flowDiagram-HODETNUW-b2AWCAaB.js} +1 -1
  298. package/out/renderer/assets/{ganttDiagram-EL5Y4UJY-DDoN4Uki.js → ganttDiagram-EL5Y4UJY-COkyXL3K.js} +1 -1
  299. package/out/renderer/assets/{gitGraphDiagram-WWUBYQGX-yrrX43-g.js → gitGraphDiagram-WWUBYQGX-BYPqy5fh.js} +1 -1
  300. package/out/renderer/assets/globals-DX-8GWfJ.css +1 -0
  301. package/out/renderer/assets/globals-y5_C1IiJ.js +2539 -0
  302. package/out/renderer/assets/index-CHJ6mVl2.js +117 -0
  303. package/out/renderer/assets/{infoDiagram-27XIBGKW-BoYY6yGv.js → infoDiagram-27XIBGKW-DNg-VxlH.js} +1 -1
  304. package/out/renderer/assets/{ishikawaDiagram-5VMMS53U-BbtGOrLg.js → ishikawaDiagram-5VMMS53U-DProTI6a.js} +1 -1
  305. package/out/renderer/assets/{journeyDiagram-3NMN7TZE-BWTb58Kr.js → journeyDiagram-3NMN7TZE-BWhC4n3f.js} +1 -1
  306. package/out/renderer/assets/{kanban-definition-UXKFOSKX-BSN2oIEH.js → kanban-definition-UXKFOSKX-CHJRR0qi.js} +1 -1
  307. package/out/renderer/assets/{layout-k2BpK8-6.js → layout-D8t6q8k0.js} +1 -1
  308. package/out/renderer/assets/{linear-DFArNkXT.js → linear-Cxb1p4iF.js} +1 -1
  309. package/out/renderer/assets/{mermaid.core-DthanE8x.js → mermaid.core-CFNOEUmc.js} +5 -5
  310. package/out/renderer/assets/{mindmap-definition-YA3MSWOX-BhETDMxE.js → mindmap-definition-YA3MSWOX-Ba78cyY4.js} +1 -1
  311. package/out/renderer/assets/{pegDiagram-XKGWAZYB-B9w_o-Iv.js → pegDiagram-XKGWAZYB-C7zqoWMk.js} +1 -1
  312. package/out/renderer/assets/{pieDiagram-E7YTZNPT-klH2bEkC.js → pieDiagram-E7YTZNPT-g304yFeX.js} +1 -1
  313. package/out/renderer/assets/{quadrantDiagram-AXDQQJYC-DerYxAqw.js → quadrantDiagram-AXDQQJYC-Bwn3gGTO.js} +1 -1
  314. package/out/renderer/assets/{railroadDiagram-O6MQD6OU-D4EFSRd0.js → railroadDiagram-O6MQD6OU-DRetS8pv.js} +1 -1
  315. package/out/renderer/assets/{requirementDiagram-BXWQKSXE-C4O9MABZ.js → requirementDiagram-BXWQKSXE-CHz0FVZ7.js} +1 -1
  316. package/out/renderer/assets/{sankeyDiagram-P5KCCOFB-ILgR3far.js → sankeyDiagram-P5KCCOFB-BYGRDIG9.js} +1 -1
  317. package/out/renderer/assets/{sequenceDiagram-WJ2MYXX4-SHHY6jka.js → sequenceDiagram-WJ2MYXX4-B60RuFFk.js} +1 -1
  318. package/out/renderer/assets/settings-Cd128yRb.js +34 -0
  319. package/out/renderer/assets/{sizeCapture-INFHLROL-CX9hC7Eu.js → sizeCapture-INFHLROL-CB-i3Fmz.js} +1 -1
  320. package/out/renderer/assets/{stateDiagram-D77RDMKH-CZ1zq3yT.js → stateDiagram-D77RDMKH-CJOcikAJ.js} +1 -1
  321. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-BosPi5SR.js +1 -0
  322. package/out/renderer/assets/{swimlanes-42K2YHIH-BxCpUxk0.js → swimlanes-42K2YHIH-Buap2upT.js} +1 -1
  323. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N-B7TQEEbL.js +8 -0
  324. package/out/renderer/assets/{timeline-definition-24CTP7MA-BZrSf5qo.js → timeline-definition-24CTP7MA-BdQta3QT.js} +1 -1
  325. package/out/renderer/assets/{vennDiagram-4TSXK5OY-g01Cyb5O.js → vennDiagram-4TSXK5OY-BynM2l28.js} +1 -1
  326. package/out/renderer/assets/{wardleyDiagram-VM6X3IG4-Bt_RS10y.js → wardleyDiagram-VM6X3IG4-FZjDO9FY.js} +1 -1
  327. package/out/renderer/assets/{xychartDiagram-S5SC5T6Z-DuwmVyP6.js → xychartDiagram-S5SC5T6Z-pJPSISxM.js} +1 -1
  328. package/out/renderer/index.html +3 -3
  329. package/out/renderer/plugin-view.html +66 -0
  330. package/out/renderer/settings.html +4 -4
  331. package/out/renderer/web-preload.js +1 -1
  332. package/out/server/agent.js +2355 -469
  333. package/out/server/chunks/{agent-D37_gFfr.js → agent--Q7N17bY.js} +567 -183
  334. package/out/server/chunks/{gpuBackendInstall-FekvL7Rv.js → gpuBackendInstall-P7COXJlD.js} +6 -5
  335. package/out/server/chunks/{loadProvider-CSeEHHnd.js → loadProvider-DvvFIF6F.js} +2 -2
  336. package/out/server/chunks/{manifest-Bj0K5UgY.js → manifest-BvEa5QR3.js} +220 -22
  337. package/out/server/chunks/{workflowPresets-DBDQwf8e.js → workflowPresets-CuLnfQqa.js} +3936 -675
  338. package/out/server/index.js +5666 -851
  339. package/out/server/plugin-host.js +42 -6
  340. package/package.json +7 -7
  341. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/anthropic-messages-BWGCKOF4.js +0 -6
  342. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-44DLKSKE.js +0 -1234
  343. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-62VOPMLK.js +0 -65
  344. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-7O7QKK6A.js +0 -2
  345. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-CHWNPHIS.js +0 -82
  346. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-NL4X6LBY.js +0 -4
  347. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-NZY7EIPA.js +0 -4
  348. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-R2EGYMOO.js +0 -7
  349. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-UKVNB6C4.js +0 -2
  350. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-USJZMAIR.js +0 -2
  351. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/chunk-VOLAXWGI.js +0 -2
  352. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/openai-codex-responses-QAWLOQSN.js +0 -10
  353. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/openai-responses-MD3562FB.js +0 -4
  354. package/out/node_modules/@earendil-works/pi-coding-agent/dist/bundle/chunks/virtual-modules-O76XM3OB.js +0 -2
  355. package/out/phone/assets/architecture-7GRP2DOG-_byK4-L4.js +0 -1
  356. package/out/phone/assets/channel-Dgd_LVvp.js +0 -1
  357. package/out/phone/assets/classDiagram-ZZMXUADV-C83rE770.js +0 -1
  358. package/out/phone/assets/classDiagram-v2-VYDZK3BY-C83rE770.js +0 -1
  359. package/out/phone/assets/desk-DOJjOIls.js +0 -2
  360. package/out/phone/assets/eventmodeling-NTZA5JFV-7mnBgbcg.js +0 -1
  361. package/out/phone/assets/flowDiagram-HODETNUW-sLsydHyr.js +0 -1
  362. package/out/phone/assets/main-CX13EK2l.js +0 -1636
  363. package/out/phone/assets/main-DZEEX8Mv.css +0 -1
  364. package/out/phone/assets/railroad-abnf-HS5TGJTU-Cm1qeEMZ.js +0 -1
  365. package/out/phone/assets/railroad-ebnf-LZEXJU2U-MFhpnZ_W.js +0 -1
  366. package/out/phone/assets/railroad-peg-WCYAUIDC-DCsilESk.js +0 -1
  367. package/out/phone/assets/stateDiagram-v2-MP3YSRHH-D1LtnHXy.js +0 -1
  368. package/out/phone/assets/storage-DBoRTPSQ.js +0 -1
  369. package/out/phone/assets/swimlanesDiagram-VR7AAH4N-C2SWpfVX.js +0 -8
  370. package/out/renderer/assets/channel-C0GtgNRj.js +0 -1
  371. package/out/renderer/assets/classDiagram-ZZMXUADV-DUyds1A3.js +0 -1
  372. package/out/renderer/assets/classDiagram-v2-VYDZK3BY-DUyds1A3.js +0 -1
  373. package/out/renderer/assets/globals-C6gFTVZy.css +0 -1
  374. package/out/renderer/assets/globals-CYDlkaHa.js +0 -2509
  375. package/out/renderer/assets/index-D1rFnBbz.js +0 -116
  376. package/out/renderer/assets/settings-DB_fAikP.js +0 -33
  377. package/out/renderer/assets/stateDiagram-v2-MP3YSRHH-NCbr7wNQ.js +0 -1
  378. package/out/renderer/assets/swimlanesDiagram-VR7AAH4N--ymqRTT2.js +0 -8
@@ -1,33 +0,0 @@
1
- import{c as Me,j as e,A as fi,r as m,u as Gr,a as Hr,b as jn,d as Wr,t as Jr,C as Gn,e as K,I as J,f as gi,X as Ct,h as ji,i as vi,Z as Qe,k as bi,S as yi,l as wi,m as Ni,n as ki,o as Ci,p as U,q as b,B as A,D as pe,s as fe,v as ge,w as je,x as Ue,y as Se,z as We,E as Ie,F as Yr,G as Be,H as Hn,J as Si,K as Gt,L as Ht,M as ee,N as te,O as se,P as ne,Q as X,R as Ii,T as qe,U as Ai,V as Ei,W as Qr,Y as Mi,_ as ds,$ as Xr,a0 as Pi,a1 as Zr,a2 as Ti,a3 as Wn,a4 as eo,a5 as Ri,a6 as Oi,a7 as Di,a8 as Jn,a9 as Li,aa as zi,ab as Bi,ac as _i,ad as Fi,ae as Ui,af as $i,ag as Vi,ah as Ki,ai as qi,aj as Gi,ak as us,al as Hi,am as Wi,an as Ji,ao as Yi,ap as Qi,aq as Xi,ar as Te,as as vn,at as Jt,au as De,av as to,aw as wt,ax as Le,ay as _e,az as bn,aA as St,aB as yn,aC as wn,aD as Nn,aE as kn,aF as Cn,aG as Sn,aH as In,aI as Je,aJ as Yn,aK as Qn,aL as $e,aM as Ze,aN as Zi,aO as el,aP as so,aQ as oe,aR as Xn,aS as ms,aT as Zn,aU as ea,aV as ta,aW as tl,aX as sl,aY as hs,aZ as Lt,a_ as no,a$ as An,b0 as nl,b1 as En,b2 as ao,b3 as al,b4 as rl,b5 as ol,b6 as ro,b7 as il,b8 as ll,b9 as cl,ba as oo,bb as At,bc as Ft,bd as dl,be as Mn,bf as rt,bg as ul,bh as ml,bi as hl,bj as io,bk as Pn,bl as Ee,bm as Z,bn as Ae,bo as xl,bp as pl,bq as fl,br as gl,bs as jl,bt as sa,bu as vl,bv as bl,bw as zt,bx as Bt,by as Ke,bz as Tt,bA as nn,bB as yl,bC as wl,bD as an,bE as ot,bF as lo,bG as Nl,bH as kl,bI as co,bJ as Cl,bK as na,bL as uo,bM as Sl,bN as Il,bO as mo,bP as ze,bQ as ho,bR as Al,bS as Yt,bT as El,bU as aa,bV as Ml,bW as Pl,bX as Tl,bY as Xe,bZ as Rl,b_ as ra,b$ as oa,c0 as Ol,c1 as ia,c2 as Dl,c3 as Ll,c4 as zl,c5 as Bl,c6 as Fe,c7 as xs,c8 as la,c9 as _l,ca as xo,cb as Fl,cc as po,cd as Ul,ce as $l,cf as Vl,cg as Kl,ch as Tn,ci as ql,cj as fo,ck as Gl,cl as ss,cm as Hl,cn as Wl,co as Jl,g as Yl,cp as rn,cq as go,cr as Ut,cs as Ql,ct as Xl,cu as ce,cv as de,cw as ns,cx as Rn,cy as On,cz as Zl,cA as ca,cB as da,cC as ua,cD as ec,cE as tc,cF as sc,cG as nc,cH as ac,cI as rc,cJ as oc,cK as ic,cL as lc,cM as cc,cN as dc,cO as uc,cP as ma,cQ as jo,cR as vo,cS as bo,cT as yo,cU as mc,cV as hc,cW as It,cX as wo,cY as No,cZ as ko,c_ as xc,c$ as pc,d0 as fc,d1 as Nt,d2 as gc,d3 as jc,d4 as vc,d5 as bc,d6 as yc,d7 as wc,d8 as Nc,d9 as kc,da as Cc,db as Sc,dc as Ic,dd as on,de as Ac,df as Qt,dg as Ec,dh as Dn,di as Co,dj as So,dk as Ln,dl as Io,dm as Ao,dn as Eo,dp as Mo,dq as Po,dr as zn,ds as Mc,dt as Pc,du as Tc,dv as Rc,dw as Oc,dx as Dc,dy as Lc,dz as zc,dA as Bc,dB as _c,dC as Fc,dD as Uc,dE as $c,dF as Vc,dG as Kc,dH as To,dI as Ro,dJ as Oo,dK as qc,dL as Do,dM as Gc,dN as Hc,dO as Wc,dP as Lo,dQ as Jc,dR as Yc,dS as Qc,dT as Xc,dU as Xt,dV as Zc,dW as ed,dX as td,dY as sd,dZ as tt,d_ as nd,d$ as zo,e0 as ad,e1 as ps,e2 as rd,e3 as od,e4 as id,e5 as ld,e6 as cd,e7 as dd,e8 as ud,e9 as md,ea as hd,eb as Bo,ec as xd,ed as pd,ee as fd,ef as gd,eg as jd,eh as vd,ei as bd,ej as yd,ek as wd,el as Nd,em as kd,en as Cd,eo as Sd,ep as Id,eq as Ad,er as Ed,es as ha,et as Md,eu as xa,ev as Pd,ew as pa,ex as Td}from"./globals-CYDlkaHa.js";import{c as _o}from"./cytoscape.esm-DzSz-X2X.js";import{f as Rd}from"./cytoscape-fcose-B40eUKiT.js";const Od=[["path",{d:"M10 22V7a1 1 0 0 0-1-1H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-5a1 1 0 0 0-1-1H2",key:"1ah6g2"}],["rect",{x:"14",y:"2",width:"8",height:"8",rx:"1",key:"88lufb"}]],Dd=Me("blocks",Od);const Ld=[["path",{d:"M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z",key:"hh9hay"}],["path",{d:"m3.3 7 8.7 5 8.7-5",key:"g66t2b"}],["path",{d:"M12 22V12",key:"d0xqtd"}]],zd=Me("box",Ld);const Bd=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],_d=Me("chart-column",Bd);const Fd=[["path",{d:"M13.659 22H18a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v11.5",key:"4pqfef"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 12v-1",key:"1ej8lb"}],["path",{d:"M8 18v-2",key:"qcmpov"}],["path",{d:"M8 7V6",key:"1nbb54"}],["circle",{cx:"8",cy:"20",r:"2",key:"ckkr5m"}]],Ud=Me("file-archive",Fd);const $d=[["path",{d:"M14.364 13.634a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506l4.013-4.009a1 1 0 0 0-3.004-3.004z",key:"ukzhwg"}],["path",{d:"M14.487 7.858A1 1 0 0 1 14 7V2",key:"1klhew"}],["path",{d:"M20 19.645V20a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l2.516 2.516",key:"rxaxab"}],["path",{d:"M8 18h1",key:"13wk12"}]],Vd=Me("file-pen-line",$d);const Kd=[["path",{d:"M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528",key:"1jaruq"}]],qd=Me("flag",Kd);const Gd=[["path",{d:"M12 22v-6",key:"6o8u61"}],["path",{d:"M12 8V2",key:"1wkif3"}],["path",{d:"M4 12H2",key:"rhcxmi"}],["path",{d:"M10 12H8",key:"s88cx1"}],["path",{d:"M16 12h-2",key:"10asgb"}],["path",{d:"M22 12h-2",key:"14jgyd"}],["path",{d:"m15 19-3-3-3 3",key:"e37ymu"}],["path",{d:"m15 5-3 3-3-3",key:"19d6lf"}]],Hd=Me("fold-vertical",Gd);const Wd=[["path",{d:"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5",key:"mvr1a0"}]],fa=Me("heart",Wd);const Jd=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]],Yd=Me("image",Jd);const Qd=[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]],Fo=Me("link-2",Qd);const Xd=[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]],Uo=Me("lock-keyhole",Xd);const Zd=[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]],eu=Me("palette",Zd);const tu=[["path",{d:"m15 15 6 6m-6-6v4.8m0-4.8h4.8",key:"17vawe"}],["path",{d:"M9 19.8V15m0 0H4.2M9 15l-6 6",key:"chjx8e"}],["path",{d:"M15 4.2V9m0 0h4.8M15 9l6-6",key:"lav6yq"}],["path",{d:"M9 4.2V9m0 0H4.2M9 9 3 3",key:"1pxi2q"}]],su=Me("shrink",tu);const nu=[["path",{d:"M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5",key:"slp6dd"}],["path",{d:"M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244",key:"o0xfot"}],["path",{d:"M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05",key:"wn3emo"}]],au=Me("store",nu);const ru=[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]],ou=Me("sun",ru);const iu=[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]],$o=Me("upload",iu);function lu(t){const{multiple:s=!1,defaultValue:n,value:a,onValueChange:r,autoComplete:o,...i}=t;return e.jsx(fi,{...i,selectionMode:s?"multiple":"single",selectedValue:a,defaultSelectedValue:n,onSelectedValueChange:r,formAutoComplete:o})}const cu=m.forwardRef(function(s,n){const{selected:a}=Gr();return s.keepMounted||a?e.jsx(du,{...s,ref:n}):null}),du=m.memo(m.forwardRef((t,s)=>{const{render:n,className:a,style:r,keepMounted:o,...i}=t,{selected:c}=Gr(),d=m.useRef(null),{transitionStatus:x,setMounted:h}=Hr(c),p=jn("span",t,{ref:[s,d],state:{selected:c,transitionStatus:x},props:[{"aria-hidden":!0,children:"✔️"},i],stateAttributesMapping:Jr});return Wr({open:c,ref:d,onComplete(){c||h(!1)}}),p})),Bn=m.createContext({chipsRef:null,multiple:!1,rootRef:null});function uu(t){const s=m.useRef(null),n=m.useRef(null);return e.jsx(Bn.Provider,{value:{chipsRef:s,multiple:!!t.multiple,rootRef:n},children:e.jsx("div",{ref:n,className:"contents",children:e.jsx(lu,{...t})})})}function mu({className:t,showTrigger:s=!0,showClear:n=!1,startAddon:a,size:r,...o}){const{multiple:i}=m.useContext(Bn),c=r??"default";return i?e.jsx(Gn,{className:K("min-w-12 flex-1 text-base outline-none sm:text-sm [[data-slot=combobox-chip]+&]:ps-0.5",c==="sm"?"ps-1.5":"ps-2",t),"data-size":typeof c=="string"?c:void 0,"data-slot":"combobox-input",size:typeof c=="number"?c:void 0,...o}):e.jsxs("div",{className:"relative w-full has-disabled:opacity-64",children:[a&&e.jsx("div",{"aria-hidden":"true",className:"[&_svg]:-mx-0.5 pointer-events-none absolute inset-y-0 start-px z-10 flex items-center ps-[calc(--spacing(3)-1px)] opacity-80 has-[+[data-size=sm]]:ps-[calc(--spacing(2.5)-1px)] [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4","data-slot":"combobox-start-addon",children:a}),e.jsx(Gn,{className:K(a&&"data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7.5)-1px)] *:data-[slot=combobox-input]:ps-[calc(--spacing(8.5)-1px)] sm:data-[size=sm]:*:data-[slot=combobox-input]:ps-[calc(--spacing(7)-1px)] sm:*:data-[slot=combobox-input]:ps-[calc(--spacing(8)-1px)]",c==="sm"?"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-6.5":"has-[+[data-slot=combobox-trigger],+[data-slot=combobox-clear]]:*:data-[slot=combobox-input]:pe-7",t),"data-slot":"combobox-input",render:e.jsx(J,{className:"has-disabled:opacity-100",size:c}),...o}),s&&e.jsx(hu,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",c==="sm"?"end-0":"end-0.5"),children:e.jsx(gi,{})}),n&&e.jsx(gu,{className:K("-translate-y-1/2 absolute top-1/2 inline-flex size-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-transparent opacity-80 outline-none transition-opacity pointer-coarse:after:absolute pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 hover:opacity-100 has-[+[data-slot=combobox-clear]]:hidden sm:size-7 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",c==="sm"?"end-0":"end-0.5"),children:e.jsx(Ct,{})})]})}function hu({className:t,...s}){return e.jsx(ki,{className:t,"data-slot":"combobox-trigger",...s})}function xu({className:t,children:s,sideOffset:n=4,zIndex:a,...r}){const{chipsRef:o,rootRef:i}=m.useContext(Bn);let c=Qe.DROPDOWN;if(a!==void 0)c=a;else{const d=i?.current;d&&(d.closest('[data-slot="dialog-popup"] [data-slot="dialog-popup"]')?c=Qe.DROPDOWN_IN_NESTED_MODAL:d.closest('[data-slot="dialog-popup"]')&&(c=Qe.DROPDOWN_IN_MODAL))}return e.jsx(ji,{children:e.jsx(vi,{anchor:o,className:"select-none",style:{zIndex:c},"data-slot":"combobox-positioner",sideOffset:n,children:e.jsx("span",{className:K("relative flex max-h-full origin-(--transform-origin) rounded-lg border bg-popover bg-clip-padding transition-[scale,opacity] before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] before:shadow-lg has-data-starting-style:scale-98 has-data-starting-style:opacity-0 dark:not-in-data-[slot=group]:bg-clip-border",t),children:e.jsx(bi,{className:"flex max-h-[min(var(--available-height),23rem)] w-(--anchor-width) max-w-(--available-width) flex-col","data-slot":"combobox-popup",...r,children:s})})})})}function pu({className:t,children:s,endAddon:n,...a}){return e.jsxs(Ni,{className:K("grid min-h-8 in-data-[side=none]:min-w-[calc(var(--anchor-width)+1.25rem)] cursor-default grid-cols-[1rem_1fr_auto] items-center gap-2 rounded-sm py-1 ps-2 pe-4 text-base outline-none data-disabled:pointer-events-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",t),"data-slot":"combobox-item",...a,children:[e.jsx(cu,{className:"col-start-1",children:e.jsx("svg",{"aria-hidden":"true",fill:"none",height:"24",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",viewBox:"0 0 24 24",width:"24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M5.252 12.7 10.2 18.63 18.748 5.37"})})}),e.jsx("div",{className:"col-start-2",children:s}),n&&e.jsx("div",{className:"col-start-3 flex items-center",children:n})]})}function fu({className:t,...s}){return e.jsx(yi,{scrollbarGutter:!0,scrollFade:!0,children:e.jsx(wi,{className:K("not-empty:scroll-py-1 not-empty:px-1 not-empty:py-1 in-data-has-overflow-y:pe-3",t),"data-slot":"combobox-list",...s})})}function gu({className:t,...s}){return e.jsx(Ci,{className:t,"data-slot":"combobox-clear",...s})}function ju(){const{t}=U(),s=b(l=>l.contextMenuOpen),n=b(l=>l.setContextMenuOpen),[a,r]=m.useState(!1),[o,i]=m.useState(!1),c=l=>l.target==="reveal"?t("File manager"):l.target==="vscode"?t("VS Code"):l.applicationPath.split(/[/\\]/).at(-1)?.replace(/\.(exe|app)$/i,"")||l.applicationPath,d=s.filter(l=>l.enabled).map(c),x=d.length?`${d.slice(0,2).join(", ")}${d.length>2?` +${d.length-2}`:""}`:t("No opening methods enabled"),h=l=>{if(l.length>32){Be({type:"error",title:t("Context menu opening"),description:t("You can configure up to 32 opening methods.")});return}n(l)},u=(l,f)=>{const g=b.getState().contextMenuOpen;n(g.map(y=>y.id===l.id?{...y,enabled:f}:y))},p=async()=>{i(!0);try{const l=await window.electronAPI.dialog.selectFile();if(!l)return;if(!Yr(l)){Be({type:"error",title:t("Context menu opening"),description:t("The selected application path is invalid.")});return}const f=b.getState().contextMenuOpen,g=Hn(l),y=f.find(N=>N.target==="application"&&Hn(N.applicationPath)===g);if(y){h(f.map(N=>N.id===y.id?{...N,enabled:!0}:N));return}h([...f,{id:crypto.randomUUID(),target:"application",applicationPath:l,enabled:!0}])}catch(l){Be({type:"error",title:t("Context menu opening"),description:l instanceof Error?l.message:String(l)})}finally{i(!1)}};return e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h5",{className:"text-sm font-medium",children:t("Context menu opening")}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>r(!0),children:t("Configure list")})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:d.join(", "),children:x}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsxs(fe,{zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Context menu opening")}),e.jsx(Ue,{children:t("Select the opening methods shown in file link context menus. You can add multiple applications.")})]}),e.jsxs(Se,{className:"space-y-2",children:[s.length===0&&e.jsx("p",{className:"py-6 text-center text-sm text-muted-foreground",children:t("No opening methods enabled")}),s.map(l=>{const f=c(l);return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border p-3",children:[e.jsxs("label",{className:"flex min-w-0 flex-1 cursor-pointer items-center gap-3",children:[e.jsx(We,{checked:l.enabled,disabled:o,"aria-label":f,onCheckedChange:g=>u(l,g)}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-sm",title:f,children:f}),l.target==="application"&&e.jsx("span",{className:"block truncate text-xs text-muted-foreground",title:l.applicationPath,children:l.applicationPath})]})]}),e.jsx(A,{variant:"ghost",size:"sm",disabled:o,onClick:()=>n(b.getState().contextMenuOpen.filter(g=>g.id!==l.id)),children:t("Delete")})]},l.id)})]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",disabled:o,onClick:()=>{p()},children:t("Add application")}),e.jsx(A,{onClick:()=>r(!1),children:t("Close")})]})]})})]})}const ga=["internal","reveal","system","application"];function ja({extension:t,value:s,disabled:n,onChange:a}){const{t:r}=U(),o={internal:r("Open inside EnsoCode"),reveal:r("Reveal in file manager"),system:r("System default application"),application:r("Selected application")},i=Gt(`file${t}`),c=Ht(`file${t}`)!==null,d=i?c?["internal","reveal"]:["reveal"]:ga,x=i&&(!c||s==="system"||s==="application")?"reveal":s;return e.jsxs(ee,{items:Object.fromEntries(d.map(h=>[h,o[h]])),value:x,disabled:n,onValueChange:h=>{ga.includes(h)&&a(h)},children:[e.jsx(te,{className:"w-52","aria-label":r("File opening"),children:e.jsx(se,{})}),e.jsx(ne,{children:d.map(h=>e.jsx(X,{value:h,disabled:h==="internal"&&!c,children:o[h]},h))})]})}function vu(){const{t}=U(),s=b(v=>v.fileOpenRules),n=b(v=>v.setFileOpenRules),[a,r]=m.useState(""),[o,i]=m.useState("internal"),[c,d]=m.useState(),[x,h]=m.useState(null),[u,p]=m.useState(!1),l=Si([{extension:a,target:"reveal"}])[0]?.extension,f=v=>{Be({type:"error",title:t("File opening"),description:v})},g=async v=>{p(!0);try{const k=await window.electronAPI.dialog.selectFile();if(k){if(!Yr(k)){f(t("The selected application path is invalid."));return}v(k)}}catch(k){f(k instanceof Error?k.message:String(k))}finally{p(!1)}},y=v=>{const k=Ii(v);return k?(n(k),!0):(f(t("Could not complete the file action.")),!1)},N=(v,k,R)=>{if(k==="internal"&&!Ht(`file${v.extension}`)){f(t("This extension does not support internal preview."));return}y(s.map(L=>L.extension===v.extension?{extension:v.extension,target:k,...k==="application"?{applicationPath:R}:{}}:L))},j=()=>{if(!l){h(t("Enter a valid file extension, for example .md."));return}if(s.some(L=>L.extension===l)){h(t("This extension already has an opening rule."));return}const v=Gt(`file${l}`),k=Ht(`file${l}`)!==null,R=v&&(!k||o==="system"||o==="application")?"reveal":o;if(R==="internal"&&!Ht(`file${l}`)){f(t("This extension does not support internal preview."));return}if(R==="application"&&!c){h(t("Choose an application before saving this rule."));return}y([...s,{extension:l,target:R,...R==="application"?{applicationPath:c}:{}}])&&(r(""),d(void 0),h(null))};return e.jsxs("section",{className:"space-y-3","data-settings-row":"appearance.fileOpening",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("File opening")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Configure how local workspace file links open by extension.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("By default, supported files open inside EnsoCode; other files are revealed in the file manager.")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Executable and installer files are always revealed in the file manager.")})]}),e.jsx(ju,{}),s.map(v=>e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-md border px-3 py-2",children:[e.jsx("span",{className:"w-20 shrink-0 font-mono text-sm",children:v.extension}),e.jsx(ja,{extension:v.extension,value:v.target,disabled:u,onChange:k=>{k==="application"?g(R=>N(v,k,R)):N(v,k)}}),v.target==="application"&&!Gt(`file${v.extension}`)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"min-w-0 flex-1 truncate text-xs text-muted-foreground",title:v.applicationPath,children:v.applicationPath}),e.jsx(A,{variant:"outline",size:"sm",disabled:u,onClick:()=>{g(k=>N(v,"application",k))},children:t("Choose application")})]}),e.jsx(A,{variant:"ghost",size:"sm",disabled:u,onClick:()=>y(s.filter(k=>k.extension!==v.extension)),children:t("Delete")})]},v.extension)),e.jsxs("div",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(J,{className:"w-24",value:a,placeholder:".md","aria-label":t("File extension"),disabled:u,onChange:v=>{r(v.target.value),h(null)},onKeyDown:v=>{v.key==="Enter"&&j()}}),e.jsx(ja,{extension:l??".md",value:o,disabled:u,onChange:v=>{i(v),h(null)}}),e.jsx(A,{variant:"outline",size:"sm",disabled:u,onClick:j,children:t("Add")})]}),o==="application"&&!Gt(`file${l??".md"}`)&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",disabled:u,onClick:()=>{g(v=>{d(v),h(null)})},children:t("Choose application")}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",title:c,children:c})]}),x&&e.jsx("p",{role:"alert",className:"text-xs text-destructive",children:x})]})]})}function bu(t){return/^\//.test(t)||/^[A-Za-z]:[\\/]/.test(t)||/^\\\\[^\\]/.test(t)}const yu=16384,Vo=4096,Ko=65536;function wu(t){return t===null?null:typeof t=="number"&&Number.isInteger(t)&&t>=Vo&&t<=Ko?t:void 0}function Nu(t){const s=t.trim();return s?/^\d+$/.test(s)?wu(Number(s)):void 0:null}function ku(){const{t}=U(),[s,n]=m.useState(null),[a,r]=m.useState(""),[o,i]=m.useState(null);m.useEffect(()=>{let d=!1;return window.electronAPI.compaction.getReserveTokens().then(x=>{d||(n(x),r(x===null?"":String(x)))}),()=>{d=!0}},[]);const c=async()=>{const d=Nu(a);if(d===void 0){i(t("Enter a whole number between {{min}} and {{max}}, or leave it empty.",{min:Vo,max:Ko}));return}if(i(null),d===s)return;if(!(await window.electronAPI.compaction.setReserveTokens(d)).ok){i(t("Could not save. Check that pi-agent/settings.json is valid JSON."));return}n(d),r(d===null?"":String(d))};return e.jsxs("div",{className:"flex items-start justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.compactReserveTokens",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Compaction reserve tokens"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Compaction runs when context exceeds the model window minus this value. Larger values compact earlier. Do not set it close to the window of small-context models, or every request compacts first. Leave empty for the default.")})]}),e.jsxs("div",{className:"w-32 shrink-0 space-y-1",children:[e.jsx(J,{inputMode:"numeric",value:a,placeholder:String(yu),"aria-label":t("Compaction reserve tokens"),onChange:d=>r(d.target.value),onBlur:()=>{c()},onKeyDown:d=>{d.key==="Enter"&&c()}}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function ln({className:t,render:s,...n}){const a={className:K("inline-flex items-center gap-2 text-base/4.5 sm:text-sm/4 font-medium",t),"data-slot":"label"};return Ai({defaultTagName:"label",props:Ei(a,n),render:s})}const cn={checked(t){return t?{"data-checked":""}:{"data-unchecked":""}},...Jr,...Qr},qo=m.createContext(void 0);function Cu(){return m.useContext(qo)}const Go=m.createContext(void 0);function Su(){const t=m.useContext(Go);if(t===void 0)throw new Error(Mi(52));return t}const Iu=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o=!1,readOnly:i=!1,required:c=!1,"aria-labelledby":d,value:x,inputRef:h,nativeButton:u=!1,id:p,style:l,...f}=s,g=Cu(),{disabled:y,readOnly:N,required:j,form:v,checkedValue:k,touched:R=!1,validation:L,name:S,setCheckedValue:O=ds,setTouched:w=ds,registerInputRef:M=ds}=g??{},{setTouched:E,setFilled:I,state:B,disabled:C}=Xr(),_=Pi(),{labelId:V,getDescriptionProps:H}=Zr(),$=C||_.disabled||y||o,re=N||i,D=j||c,q=v,P=g?k===x:x==="",Y=m.useRef(null),ae=m.useRef(null),le=L?.registerInput,z=m.useCallback(xe=>le?.(xe,{controlRef:Y,value:void 0}),[le]),ue=Ti(h,ae,M,z);Wn(()=>{ae.current?.checked&&I(!0)},[I]),Wn(()=>{if(ae.current){if($&&P){M(null);return}M(ae.current)}},[P,$,M]);const me=eo(),ye=Ri({id:p,implicit:!1,controlRef:Y}),we=u?void 0:ye,Ve=Oi(d,V,ae,!u,we),F={role:"radio","aria-checked":P,"aria-labelledby":Ve,[Ui]:P?"":void 0,id:u?ye:me,onKeyDown(xe){xe.key==="Enter"&&xe.preventDefault()},onClick(xe){if(xe.defaultPrevented||$||re)return;xe.preventDefault();const et=ae.current;et&&Fi(et,xe)},onFocus(xe){xe.defaultPrevented||$||re||!R||(ae.current?.click(),w(!1))}},{getButtonProps:Q,buttonRef:W}=Di({disabled:$,native:u,composite:!1}),he={type:"radio",ref:ue,form:q,id:we,name:S,tabIndex:-1,style:S?Bi:_i,"aria-hidden":!0,...x!==void 0?{value:Li(x)}:Jn,disabled:$,checked:P,required:D,readOnly:re,onChange(xe){if(xe.nativeEvent.defaultPrevented||$||re||x===void 0)return;const et=$i(Vi,xe.nativeEvent);O(x,et),!et.isCanceled&&E(!0)},onClick(xe){xe.stopPropagation()},onFocus(){Y.current?.focus()}},Ne=m.useMemo(()=>({...B,required:D,disabled:$,readOnly:re,checked:P}),[B,$,re,P,D]),xt=Ne,G=g!==void 0,ke=[n,Y,W],Ce=[F,f,Q,H,L?xe=>L.getValidationProps($,xe):Jn],Oe=jn("span",s,{enabled:!G,state:Ne,ref:ke,props:Ce,stateAttributesMapping:cn});return e.jsxs(Go.Provider,{value:xt,children:[G?e.jsx(zi,{tag:"span",render:a,className:r,style:l,state:Ne,refs:ke,props:Ce,stateAttributesMapping:cn}):Oe,e.jsx("input",{...he,suppressHydrationWarning:!0})]})}),Au=m.forwardRef(function(s,n){const{render:a,className:r,style:o,keepMounted:i=!1,...c}=s,d=Su(),x=d.checked,{mounted:h,transitionStatus:u,setMounted:p}=Hr(x),l={...d,transitionStatus:u},f=m.useRef(null),g=i||h,y=jn("span",s,{ref:[n,f],state:l,props:c,stateAttributesMapping:cn});return Wr({open:x,ref:f,onComplete(){x||p(!1)}}),g?y:null}),Eu=[Qi],Mu=m.forwardRef(function(s,n){const{render:a,className:r,disabled:o,readOnly:i,required:c,onValueChange:d,value:x,defaultValue:h,form:u,name:p,inputRef:l,id:f,style:g,...y}=s,{setTouched:N,setFocused:j,validationMode:v,name:k,disabled:R,state:L,validation:S,setDirty:O,setFilled:w,validityData:M}=Xr(),{labelId:E}=Zr(),{clearErrors:I,elementRef:B}=Ki(),C=qi(!0),_=R||o,V=k??p,H=eo(f),[$,re]=Gi({controlled:x,default:h,name:"RadioGroup",state:"value"}),[D,q]=m.useState(!1),P=us((W,he)=>{d?.(W,he),!he.isCanceled&&re(W)}),Y=S.getInputControl,ae=m.useMemo(()=>({get current(){return Y()}}),[Y]),le=m.useRef(null),z=m.useRef(null);function ue(W){let he;return l&&(typeof l=="function"?he=l(W):l.current=W),le.current=W,he}const me=us(W=>{if(!W||W.disabled)return;z.current||(z.current=W);const he=le.current,Ne=W.checked||he==null||he.disabled?ue(W):void 0;return()=>{z.current===W&&(z.current=null),le.current===W?Ne?(Ne(),le.current=null):ue(null):Ne?.()}}),ye=us(()=>{const W=B.current;if(!W)return $??null;for(const he of S.registeredInputs.keys())if(he.checked&&Hi(he,W))return $??null;return null});Wi(ae,H,$??null,ye,!_,p),Ji($,()=>{I(V),O($!==M.initialValue),w($!=null),S.change($);const W=z.current;$==null&&W&&!W.disabled&&ue(W)});const we=E??C?.legendId,Ve={...L,disabled:_??!1,required:c??!1,readOnly:i??!1},F=m.useMemo(()=>({checkedValue:$,disabled:_,form:u,validation:S,name:V,readOnly:i,registerInputRef:me,required:c,setCheckedValue:P,setTouched:q,touched:D}),[$,_,u,S,V,i,me,c,P,q,D]),Q={id:f,role:"radiogroup","aria-required":c||void 0,"aria-disabled":_||void 0,"aria-readonly":i||void 0,"aria-labelledby":we,onFocus(){j(!0)},onBlur(W){Xi(W.currentTarget,W.relatedTarget)||(N(!0),j(!1),v==="onBlur"&&S.commit($))},onKeyDownCapture(W){W.key.startsWith("Arrow")&&(q(!0),j(!0))}};return e.jsx(qo.Provider,{value:F,children:e.jsx(Yi,{render:a,className:r,style:g,state:Ve,props:[Q,y,W=>S.getValidationProps(_??!1,W)],refs:[n],stateAttributesMapping:Qr,enableHomeAndEndKeys:!1,modifierKeys:Eu})})});function Pu({className:t,...s}){return e.jsx(Mu,{className:K("flex flex-col gap-3",t),"data-slot":"radio-group",...s})}function va({className:t,...s}){return e.jsx(Iu,{className:K("relative inline-flex size-4.5 shrink-0 items-center justify-center rounded-full border border-input bg-background bg-clip-padding shadow-xs outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-full not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_1px_--theme(--color-black/4%)] focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/48 data-disabled:opacity-64 sm:size-4 dark:not-data-checked:bg-input/32 dark:bg-clip-border dark:aria-invalid:ring-destructive/24 dark:not-data-disabled:not-data-checked:not-aria-invalid:before:shadow-[0_-1px_--theme(--color-white/8%)] [[data-disabled],[data-checked],[aria-invalid]]:shadow-none",t),"data-slot":"radio",...s,children:e.jsx(Au,{className:"-inset-px absolute flex size-4.5 items-center justify-center rounded-full before:size-2 before:rounded-full before:bg-primary-foreground data-unchecked:hidden data-checked:bg-primary sm:size-4 sm:before:size-1.5","data-slot":"radio-indicator"})})}const Tu=[{category:"providers",label:"Model Providers"},{category:"presets",label:"Presets"},{category:"agentTypes",label:"Agent types"},{category:"skills",label:"Skills"},{category:"mcpServers",label:"MCP Servers"},{category:"instructions",label:"Instruction Files"},{category:"subagentModels",label:"Subagent Models"},{category:"settings",label:"Scalar settings"}];function Ru(){const{t}=U(),[s,n]=m.useState(!1),[a,r]=m.useState(!1),[o,i]=m.useState(null),[c,d]=m.useState(null),x=()=>{i(null),n(!0)},h=async()=>{r(!0),i(null);try{const u=await window.electronAPI.configSync.openImport();if(!u.ok){i({kind:u.cancelled?"cancelled":"error",text:u.cancelled?t("Import cancelled."):t(u.error)});return}d(u)}catch{i({kind:"error",text:t("Could not open configuration package.")})}finally{r(!1)}};return e.jsxs("section",{className:"space-y-3","data-settings-row":"general.configSync",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Configuration transfer")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move models, presets, agent types, skills, MCP servers and instruction files between devices.")})]}),e.jsxs("div",{className:"rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx(Ud,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:t("Portable Enso configuration")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Export a package or preview one before importing it.")})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(A,{variant:"outline",size:"sm",disabled:a,onClick:h,children:[a?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(vn,{className:"h-3.5 w-3.5"}),t("Import configuration")]}),e.jsxs(A,{size:"sm",disabled:a,onClick:x,children:[e.jsx($o,{className:"h-3.5 w-3.5"}),t("Export configuration")]})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-2 border-t pt-3 text-xs text-muted-foreground",children:[e.jsx(Jt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsx("p",{children:t("OAuth login sessions are never transferred. Skill, instruction, and system prompt contents require an encrypted export.")})]}),o&&e.jsx("p",{className:o.kind==="error"?"mt-2 text-xs text-destructive":"mt-2 text-xs text-muted-foreground",role:o.kind==="error"?"alert":"status",children:o.text})]}),e.jsx(Ou,{open:s,onOpenChange:n}),c&&e.jsx(Du,{file:c,onClose:()=>d(null)})]})}function Ou({open:t,onOpenChange:s}){const{t:n}=U(),[a,r]=m.useState(!1),[o,i]=m.useState(""),[c,d]=m.useState(""),[x,h]=m.useState(!1),[u,p]=m.useState(null),[l,f]=m.useState(!1),[g,y]=m.useState(null),[N,j]=m.useState([]);m.useEffect(()=>{t&&(r(!1),i(""),d(""),h(!1),p(null),f(!1),y(null),j([]))},[t]);const v=()=>{x||(i(""),d(""),s(!1))},k=async()=>{if(a&&o.length<8){p(n("Password must be at least 8 characters."));return}if(a&&o!==c){p(n("Passwords do not match."));return}h(!0),p(null),f(!1);try{const R=await window.electronAPI.configSync.exportConfig({includeSecrets:a,...a?{password:o}:{}});if(i(""),d(""),!R.ok){R.cancelled?f(!0):p(n(R.error));return}y(R.filePath),j(R.skippedInstructions??[])}catch{i(""),d(""),p(n("Could not export configuration."))}finally{h(!1)}};return e.jsx(pe,{open:t,onOpenChange:R=>!R&&v(),children:e.jsxs(fe,{className:"max-w-xl",showCloseButton:!x,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n("Export configuration")}),e.jsx(Ue,{children:n("Create a portable .enso-config package for another device.")})]}),e.jsx(Se,{className:"max-h-[55vh] space-y-4",children:g?e.jsxs(e.Fragment,{children:[e.jsxs(De,{variant:"success",children:[e.jsx(to,{}),e.jsx(wt,{children:n("Configuration exported")}),e.jsxs(Le,{children:[e.jsx("p",{children:n("Saved package:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:g})]})]}),N.length>0&&e.jsxs(De,{variant:"warning",children:[e.jsx(_e,{}),e.jsxs(Le,{children:[e.jsx("p",{children:n("These instructions were skipped because their source files are missing or unreadable:")}),e.jsx("p",{className:"break-all text-foreground",children:N.join(", ")})]})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(De,{variant:"warning",children:[e.jsx(bn,{}),e.jsx(wt,{children:n("File contents can be private")}),e.jsx(Le,{children:n("Skill and instruction file contents may contain private data, so configurations containing them can only be exported with encryption.")})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border px-3 py-2.5",children:[e.jsx(We,{checked:a,onCheckedChange:R=>{const L=R===!0;r(L),p(null),L||(i(""),d(""))}}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Include sensitive configuration")}),e.jsx("span",{className:"mt-0.5 block text-xs text-muted-foreground",children:n("Encrypt the entire package with a password. OAuth login sessions are still excluded.")})]})]}),!a&&e.jsxs(De,{variant:"info",children:[e.jsx(Jt,{}),e.jsx(Le,{children:n("API keys, provider account links, MCP arguments and environment values, plus credentials and private URL parts in MCP endpoints, will be omitted. Configurations containing skill or instruction files require encryption.")})]}),a&&e.jsxs("div",{className:"space-y-3 rounded-md border px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(Uo,{className:"h-4 w-4 text-muted-foreground"}),n("Encryption password")]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ln,{htmlFor:"config-export-password",children:n("Password")}),e.jsx(J,{id:"config-export-password",type:"password",autoComplete:"new-password",value:o,"aria-invalid":!!(u&&o.length<8),onChange:R=>{i(R.target.value),p(null)}})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ln,{htmlFor:"config-export-confirmation",children:n("Confirm password")}),e.jsx(J,{id:"config-export-confirmation",type:"password",autoComplete:"new-password",value:c,"aria-invalid":!!(u&&c!==o),onChange:R=>{d(R.target.value),p(null)}})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use at least 8 characters. This password cannot be recovered.")})]}),l&&e.jsx("p",{className:"text-xs text-muted-foreground",role:"status",children:n("Export cancelled.")}),u&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),u]})]})}),e.jsx(Ie,{children:g?e.jsx(A,{size:"sm",onClick:v,children:n("Done")}):e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",size:"sm",disabled:x,onClick:v,children:n("Cancel")}),e.jsxs(A,{size:"sm",disabled:x,onClick:()=>{k()},children:[x?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx($o,{className:"h-3.5 w-3.5"}),n(x?"Exporting…":"Export")]})]})})]})})}function Du({file:t,onClose:s}){const{t:n}=U(),[a,r]=m.useState(t.encrypted?"password":"preview"),[o,i]=m.useState(""),[c,d]=m.useState("merge"),[x,h]=m.useState(null),[u,p]=m.useState([]),[l,f]=m.useState(null),[g,y]=m.useState(!1),[N,j]=m.useState(null),[v,k]=m.useState(null),[R,L]=m.useState(!1),S=m.useRef(0),O=m.useCallback(async(C,_)=>{const V=++S.current;j("preview"),k(null),h(null),p([]);try{const H=await window.electronAPI.configSync.previewImport({token:t.token,mode:C,..._?{password:_}:{}});if(V!==S.current)return;if(i(""),!H.ok){k(n(H.error));return}d(H.mode),h(H.summary),p(H.warnings),r("preview")}catch{V===S.current&&(i(""),k(n("Could not preview configuration package.")))}finally{V===S.current&&j(null)}},[t.token,n]);m.useEffect(()=>{t.encrypted||O("merge")},[t.encrypted,O]);const w=()=>{N||(S.current+=1,L(!1),i(""),window.electronAPI.configSync.cancelImport(t.token).catch(()=>{}),s())},M=C=>{C===c||N||(d(C),O(C))},E=!!x?.some(C=>(C.category==="skills"||C.category==="mcpServers")&&C.added+C.updated+C.skipped>0),I=x!==null,B=async()=>{if(x){j("commit"),k(null);try{const C=await window.electronAPI.configSync.commitImport({token:t.token,mode:c});if(!C.ok){h(null),p([]),k(n(C.error));return}i("");try{await b.persist.rehydrate()}catch{y(!0)}p(C.warnings),f(C.backupPath),r("success")}catch{h(null),p([]),k(n("Could not import configuration."))}finally{j(null)}}};return e.jsxs(pe,{open:!0,onOpenChange:C=>!C&&w(),children:[e.jsxs(fe,{className:"max-w-2xl",showCloseButton:N===null,children:[e.jsxs(ge,{children:[e.jsx(je,{children:n(a==="success"?"Configuration imported":"Import configuration")}),e.jsx(Ue,{children:a==="success"?n(g?"Configuration was imported, but this window could not refresh automatically.":"This window has been refreshed with the imported settings."):n("Review {{fileName}} before changing this device.",{fileName:t.fileName})})]}),a==="password"&&e.jsxs(Se,{className:"space-y-4",children:[e.jsxs(De,{variant:"info",children:[e.jsx(Uo,{}),e.jsx(wt,{children:n("Encrypted configuration package")}),e.jsx(Le,{children:n("Enter the export password to decrypt and preview this package.")})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(ln,{htmlFor:"config-import-password",children:n("Password")}),e.jsx(J,{id:"config-import-password",type:"password",autoFocus:!0,autoComplete:"current-password",value:o,"aria-invalid":!!v,onChange:C=>{i(C.target.value),k(null)},onKeyDown:C=>{C.key==="Enter"&&o.length>0&&!N&&O("merge",o)}})]}),v&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-destructive",role:"alert",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),v]})]}),a==="preview"&&e.jsxs(Se,{className:"max-h-[58vh] space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:n("Import mode")}),e.jsxs(Pu,{value:c,onValueChange:C=>M(C),className:"grid gap-2 sm:grid-cols-2","aria-label":n("Import mode"),children:[e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(va,{value:"merge",disabled:N!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Merge")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Add and update matching items while keeping items only on this device.")})]})]}),e.jsxs("label",{className:"flex cursor-pointer items-start gap-2.5 rounded-md border px-3 py-2.5",children:[e.jsx(va,{value:"replace",disabled:N!==null}),e.jsxs("span",{children:[e.jsx("span",{className:"block text-sm font-medium",children:n("Replace")}),e.jsx("span",{className:"block text-xs text-muted-foreground",children:n("Replace transferred item categories, removing local-only items in them.")})]})]})]})]}),N==="preview"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 rounded-md border border-dashed py-10",children:[e.jsx(Te,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:n("Preparing preview…")})]}),!N&&x&&e.jsx("div",{className:"overflow-hidden rounded-md border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-xs text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 text-left font-medium",children:n("Category")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Added")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Updated")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Skipped")}),e.jsx("th",{scope:"col",className:"px-3 py-2 text-right font-medium",children:n("Removed")})]})}),e.jsx("tbody",{children:Tu.map(({category:C,label:_})=>{const V=x.find(H=>H.category===C);return e.jsxs("tr",{className:"border-t first:border-t-0",children:[e.jsx("th",{scope:"row",className:"px-3 py-2 text-left font-medium",children:n(_)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.added??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.updated??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.skipped??0}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:V?.removed??0})]},C)})})]})}),!N&&x?.find(C=>C.category==="settings")?.fields?.length?e.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Portable settings changed:")," ",x.find(C=>C.category==="settings")?.fields?.join(", ")]}):null,c==="replace"&&x&&!N&&e.jsxs(De,{variant:"error",children:[e.jsx(_e,{}),e.jsx(wt,{children:n("Local-only configuration will be deleted")}),e.jsx(Le,{children:n("Items in transferred collections that exist only on this device will be removed. Removed counts are shown above. Included portable preferences are overwritten. A complete backup is created first.")})]}),u.map(C=>e.jsxs(De,{variant:"warning",children:[e.jsx(_e,{}),e.jsx(Le,{children:n(C)})]},C)),x&&!N&&e.jsxs(De,{variant:"warning",children:[e.jsx(bn,{}),e.jsx(wt,{children:n("Only import packages you trust")}),e.jsx(Le,{children:n("An imported package can change portable preferences and configuration. Skills and MCP servers may also run commands later when you use them. Previewing does not execute them; continue only if you trust the package.")})]}),v&&e.jsxs(De,{variant:"error",children:[e.jsx(St,{}),e.jsx(Le,{children:v})]})]}),a==="success"&&l&&e.jsxs(Se,{className:"space-y-4",children:[e.jsxs(De,{variant:"success",children:[e.jsx(to,{}),e.jsx(wt,{children:n("Import complete")}),e.jsxs(Le,{children:[e.jsx("p",{children:n("Backup of previous settings:")}),e.jsx("p",{className:"break-all font-mono text-xs text-foreground",children:l})]})]}),g&&e.jsxs(De,{variant:"warning",children:[e.jsx(_e,{}),e.jsx(Le,{children:n("Reopen Settings to load the imported configuration in this window.")})]}),u.map(C=>e.jsxs(De,{variant:"warning",children:[e.jsx(_e,{}),e.jsx(Le,{children:n(C)})]},C))]}),e.jsxs(Ie,{children:[a==="password"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",size:"sm",disabled:N!==null,onClick:w,children:n("Cancel")}),e.jsxs(A,{size:"sm",disabled:N!==null||o.length===0,onClick:()=>{O("merge",o)},children:[N==="preview"&&e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}),n("Preview")]})]}),a==="preview"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",size:"sm",disabled:N!==null,onClick:w,children:n("Cancel")}),v&&!x?e.jsx(A,{size:"sm",disabled:N!==null,onClick:()=>{O(c)},children:n("Refresh preview")}):e.jsxs(A,{variant:c==="replace"?"destructive":"default",size:"sm",disabled:N!==null||!x,onClick:()=>{x&&(I?L(!0):B())},children:[N==="commit"?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(vn,{className:"h-3.5 w-3.5"}),n(N==="commit"?"Importing…":"Import")]})]}),a==="success"&&e.jsx(A,{size:"sm",onClick:w,children:n("Done")})]})]}),e.jsx(Lu,{open:R,mode:c,hasImportedExecutableResources:E,onOpenChange:L,onConfirm:()=>{B()}})]})}function Lu({open:t,mode:s,hasImportedExecutableResources:n,onOpenChange:a,onConfirm:r}){const{t:o}=U();return e.jsx(yn,{open:t,onOpenChange:a,children:e.jsxs(wn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Nn,{children:[e.jsxs(kn,{className:"flex items-start gap-2 text-base",children:[e.jsx(_e,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),o("Confirm configuration import")]}),e.jsxs(Cn,{className:"space-y-2",children:[e.jsx("span",{className:"block",children:o("This package can change portable preferences and configuration. Continue only if you trust this package.")}),n&&e.jsx("span",{className:"block",children:o("It includes skills or MCP servers that may execute commands when you use them.")}),s==="replace"&&e.jsx("span",{className:"block",children:o("Replace mode removes local-only items from transferred collections and overwrites included portable preferences. A complete backup will be created first.")}),e.jsx("span",{className:"block",children:o("Do you want to continue with this import?")})]})]}),e.jsxs(Sn,{variant:"bare",children:[e.jsx(In,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:o("Cancel")}),e.jsx(A,{variant:s==="replace"?"destructive":"default",size:"sm",onClick:()=>{a(!1),r()},children:o("Confirm import")})]})]})})}const ba={auto:"Auto (by usage)",fast:"Fast",balanced:"Balanced",thorough:"Thorough"},ya={standard:"Standard",smart:"Smart compaction","codex-native":"Codex native compaction","continuous-memory":"Continuous memory (experimental)"};function zu(){const{t}=U(),s=b(l=>l.compactStrategy),n=b(l=>l.smartCompactEnabled),a=Zi(s,n),r=b(l=>l.setCompactStrategy),o=a!=="standard",i=b(l=>l.smartCompactModel),c=b(l=>l.setSmartCompactModel),d=b(l=>l.smartCompactMode),x=b(l=>l.setSmartCompactMode),h=Je(),u=i?h.find(l=>l.id===i.providerId):void 0,p=u?.models.find(l=>l.id===i?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3","data-settings-row":"general.smartCompactEnabled",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h4",{className:"font-medium text-sm",children:[t("Context compaction strategy"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Standard uses default compact. Smart compaction uses Enso verified summary at compact time. Codex native compaction additionally stores an official Codex checkpoint on Codex models and uses smart compaction otherwise. Continuous memory records observations in the background so compact keeps more context; all fall back to default compact on failure. Switching strategy takes effect on the next session. The summary model and compaction mode apply to open conversations on the next compaction.")})]}),e.jsxs(ee,{items:Object.fromEntries(Yn.map(l=>[l,t(ya[l])])),value:a,onValueChange:l=>r(l),children:[e.jsx(te,{className:"w-52",children:e.jsx(se,{})}),e.jsx(ne,{children:Yn.map(l=>e.jsx(X,{value:l,children:t(ya[l])},l))})]})]}),(a==="smart"||a==="codex-native")&&e.jsxs("div",{className:"flex items-center justify-between gap-4","data-smart-compact-mode":d,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Compaction mode")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground/80 text-[11px]",children:t("Mode changes summary budget and how much recent tail to keep. It does not decide whether compact runs.")})]}),e.jsxs(ee,{items:Object.fromEntries(Qn.map(l=>[l,t(ba[l])])),value:d,onValueChange:l=>x(l),children:[e.jsx(te,{className:"w-36",children:e.jsx(se,{})}),e.jsx(ne,{children:Qn.map(l=>e.jsx(X,{value:l,children:t(ba[l])},l))})]})]}),o&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t(a==="continuous-memory"?"Background memory model":"Summary model")}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx($e,{providers:h,providerId:u?.id??"",modelId:p?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the session model"),side:"bottom",triggerClassName:Ze,onSelect:(l,f)=>c({providerId:l,modelId:f}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),i&&(!u||!p)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the session model.")}),i&&e.jsx(A,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>c(null),children:t("Follow session model")})]})]})}const Bu={cmd:"Command Prompt",powershell:"Windows PowerShell",pwsh:"PowerShell 7 (pwsh)","git-bash":"Git Bash",zsh:"zsh",bash:"bash",fish:"fish"};function _u(){const{language:t,setLanguage:s}=b(),{t:n}=U();return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:n("General")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:n("General application settings")})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Application")}),e.jsxs("div",{className:"flex items-center gap-3","data-settings-row":"general.language",children:[e.jsx("span",{className:"text-sm font-medium",children:n("Language")}),e.jsxs(ee,{items:{en:"English",zh:"简体中文"},value:t,onValueChange:a=>s(a),children:[e.jsx(te,{className:"w-48",children:e.jsx(se,{})}),e.jsxs(ne,{children:[e.jsx(X,{value:"en",children:"English"}),e.jsx(X,{value:"zh",children:"简体中文"})]})]})]}),e.jsx(Fu,{}),e.jsx(Wu,{}),e.jsx(Ru,{}),e.jsx(Ju,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Agent runtime")}),e.jsx(Uu,{}),e.jsx($u,{}),e.jsx(zu,{}),e.jsx(ku,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Sessions & worktrees")}),e.jsx(Ku,{}),e.jsx(Vu,{}),e.jsx(Gu,{})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:n("Terminal")}),e.jsx(Hu,{}),e.jsx(qu,{})]})]})}function Fu(){const{t}=U(),s=b(a=>a.notifyMainAgentOnly),n=b(a=>a.setNotifyMainAgentOnly);return e.jsx(Pe,{rowId:"general.notifyMainAgentOnly",title:t("Notify only for the main agent"),description:t("Skip coworker completion and failure notifications on this computer and the paired phone. Questions and approvals still notify."),checked:s,onChange:n})}function Uu(){const{t}=U(),s=b(a=>a.generationStallTimeoutMin),n=b(a=>a.setGenerationStallTimeoutMin);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.generationStallTimeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Stop if no output")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Abort and retry the run when no tokens or tool results arrive for this long. Thinking counts as output.")})]}),e.jsxs(ee,{items:Object.fromEntries(Xn.map(a=>[String(a),a===0?t("Never"):t("{{count}} min",{count:a})])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-28",children:e.jsx(se,{})}),e.jsx(ne,{children:Xn.map(a=>e.jsx(X,{value:String(a),children:a===0?t("Never"):t("{{count}} min",{count:a})},a))})]})]})}function $u(){const{t}=U(),s=b(o=>o.autoRetryLimit),n=b(o=>o.setAutoRetryLimit),a=ms.some(o=>o===s)?[...ms]:[...ms,s].sort((o,i)=>o===hs?1:i===hs?-1:o-i),r=o=>o===0?t("Off"):o===hs?t("Unlimited"):t("{{count}} times",{count:o});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoRetryLimit",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Auto-retry on transient errors")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Retry with backoff (up to 60s apart) after 429, 5xx or network errors. Quota and billing errors are never retried. Unlimited keeps retrying until you cancel.")})]}),e.jsxs(ee,{items:Object.fromEntries(a.map(o=>[String(o),r(o)])),value:String(s),onValueChange:o=>n(Number(o)),children:[e.jsx(te,{className:"w-28",children:e.jsx(se,{})}),e.jsx(ne,{children:a.map(o=>e.jsx(X,{value:String(o),children:r(o)},o))})]})]})}function Vu(){const{t}=U(),s=b(r=>r.activeRetentionMinutes),n=b(r=>r.setActiveRetentionMinutes),a=r=>r===0?t("Off"):t("{{count}} min",{count:r});return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.activeRetentionMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Keep in Active after last message")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Viewed conversations stay in Active for this long after their last message or your last open while still in Active, then leave. Unviewed ones stay until you open them.")})]}),e.jsxs(ee,{items:Object.fromEntries(ta.map(r=>[String(r),a(r)])),value:String(s),onValueChange:r=>n(Number(r)),children:[e.jsx(te,{className:"w-28",children:e.jsx(se,{})}),e.jsx(ne,{children:ta.map(r=>e.jsx(X,{value:String(r),children:a(r)},r))})]})]})}function $t(t,s){return s===0?t("Never"):s===1?t("{{count}} day",{count:s}):t("{{count}} days",{count:s})}function Ku(){const{t}=U(),s=b(c=>c.autoArchiveIdleDays),n=b(c=>c.setAutoArchiveIdleDays),a=b(c=>c.autoArchiveMergedWorktrees),r=b(c=>c.setAutoArchiveMergedWorktrees),o=b(c=>c.autoDeleteArchivedDays),i=b(c=>c.setAutoDeleteArchivedDays);return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoArchiveIdleDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Archive idle conversations")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Move conversations that have been idle this long into Archived. Does not delete them.")})]}),e.jsxs(ee,{items:Object.fromEntries(Zn.map(c=>[String(c),$t(t,c)])),value:String(s),onValueChange:c=>n(Number(c)),children:[e.jsx(te,{className:"w-28",children:e.jsx(se,{})}),e.jsx(ne,{children:Zn.map(c=>e.jsx(X,{value:String(c),children:$t(t,c)},c))})]})]}),e.jsx(Pe,{rowId:"general.autoArchiveMergedWorktrees",title:t("Clean up merged worktrees"),description:t("When archiving idle conversations, also remove isolated worktrees that are merged and clean."),checked:a,onChange:r}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.autoDeleteArchivedDays",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Delete archived conversations after")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Permanently delete conversations that have been archived longer than this. This cannot be undone. Choosing a positive value deletes already-overdue archived conversations immediately.")})]}),e.jsxs(ee,{items:Object.fromEntries(ea.map(c=>[String(c),$t(t,c)])),value:String(o),onValueChange:c=>i(Number(c)),children:[e.jsx(te,{className:"w-28",children:e.jsx(se,{})}),e.jsx(ne,{children:ea.map(c=>e.jsx(X,{value:String(c),children:$t(t,c)},c))})]})]})]})}function qu(){const{t}=U(),s=b(o=>o.terminalShell),n=b(o=>o.setTerminalShell),a=tl(window.electronAPI.env.platform),r=Object.fromEntries(a.map(o=>[o,o==="auto"?t("System default"):Bu[o]]));return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.terminalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Terminal shell")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Applies to new side panel terminals. SSH projects keep the remote login shell.")})]}),e.jsxs(ee,{items:r,value:s,onValueChange:o=>n(o),children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsx(ne,{children:a.map(o=>e.jsx(X,{value:o,children:r[o]},o))})]})]})}function Gu(){const{t}=U(),s=b(x=>x.worktreeRoot),n=b(x=>x.setWorktreeRoot),[a,r]=m.useState(s),[o,i]=m.useState(null);m.useEffect(()=>{r(s)},[s]);const c=x=>{const h=x.trim();if(h&&!bu(h)){i(t("Enter an absolute path"));return}i(null),n(h)},d=async()=>{const x=await window.electronAPI.dialog.selectDirectory();x&&(r(x),c(x))};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.worktreeRoot",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Worktree root directory")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Where isolated session worktrees are created. Leave empty to use the app data directory. Existing worktrees stay where they are.")})]}),e.jsxs("div",{className:"w-72 shrink-0 space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a,placeholder:t("Default location"),onChange:x=>r(x.target.value),onBlur:()=>c(a),onKeyDown:x=>{x.key==="Enter"&&c(a)}}),e.jsx(A,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>{d()},children:t("Browse")})]}),o&&e.jsx("p",{className:"text-xs text-destructive",children:o})]})]})}function Hu(){const{t}=U(),s=b(r=>r.windowsLocalShell),n=b(r=>r.setWindowsLocalShell),a={auto:t("Windows default (PowerShell)"),powershell:t("PowerShell"),bash:t("Git Bash")};return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"general.windowsLocalShell",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Windows local command shell"),e.jsx(qe,{})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Only the Windows local agent command tool. SSH and other platforms stay on bash. Takes effect on the next session.")})]}),e.jsxs(ee,{items:a,value:s,onValueChange:r=>n(r),children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsx(ne,{children:Object.keys(a).map(r=>e.jsx(X,{value:r,children:a[r]},r))})]})]})}function Pe({title:t,description:s,checked:n,onChange:a,rowId:r}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(oe,{checked:n,onCheckedChange:o=>a(o===!0)})]})}function wa(t,s){window.electronAPI.proxy.apply({mode:t,customUrl:s})}function Wu(){const{t}=U(),s=b(u=>u.proxyMode),n=b(u=>u.customProxyUrl),a=b(u=>u.setProxyMode),r=b(u=>u.setCustomProxyUrl),[o,i]=m.useState(n),[c,d]=m.useState(null);m.useEffect(()=>{i(n)},[n]);const x=u=>{a(u),wa(u,n)},h=()=>{const u=o.trim();if(u&&!sl(u)){d(t("Enter an http(s) proxy URL"));return}d(null),r(u),wa(s,u)};return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.proxy",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Network proxy")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Used by model requests, the built-in browser, and agent tools")})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Proxy mode")}),e.jsxs(ee,{items:{system:t("Follow system proxy"),none:t("No proxy"),custom:t("Custom proxy")},value:s,onValueChange:u=>x(u),children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsxs(ne,{children:[e.jsx(X,{value:"system",children:t("Follow system proxy")}),e.jsx(X,{value:"none",children:t("No proxy")}),e.jsx(X,{value:"custom",children:t("Custom proxy")})]})]})]}),s==="custom"&&e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"pt-1.5 text-sm font-medium",children:t("Proxy URL")}),e.jsxs("div",{className:"min-w-0 space-y-1",children:[e.jsx(J,{value:o,placeholder:"http://127.0.0.1:7890",onChange:u=>i(u.target.value),onBlur:h,onKeyDown:u=>{u.key==="Enter"&&h()}}),c&&e.jsx("p",{className:"text-xs text-destructive",children:c})]})]})]})}function Ju(){const{t}=U(),s=b(v=>v.autoUpdate),n=b(v=>v.setAutoUpdate),a=b(v=>v.autoRestartWhenIdle),r=b(v=>v.setAutoRestartWhenIdle),[o,i]=m.useState(null),[c,d]=m.useState(null),[x,h]=m.useState(!1),[u,p]=m.useState(!1);m.useEffect(()=>{let v=!0;window.electronAPI.updater.getState().then(R=>{v&&(d(R),R.status&&i(L=>L??R.status))}).catch(()=>{});const k=window.electronAPI.updater.onStatus(i);return()=>{v=!1,k()}},[]);const l=c?.host==="server"?c:null,f=c?.host==="desktop"||l!==null&&l.mode!=="manual",g=(o?.status==="available"||o?.status==="downloaded")&&!!o.info,N=(()=>{if(!o)return null;switch(o.status){case"checking":return t("Checking for updates…");case"available":return t("New version {{version}} found",{version:o.info?.version??""});case"not-available":return t("You are on the latest version");case"downloading":return t("Downloading update… {{percent}}%",{percent:Math.round(o.progress?.percent??0)});case"downloaded":return t("New version {{version}} is ready — restart to update.",{version:o.info?.version??""});case"error":return l&&o.error?t("Update failed: {{error}}",{error:o.error}):t("Update check failed");default:return null}})(),j=o?.status==="checking"||o?.status==="downloading";return e.jsxs("div",{className:"space-y-3","data-settings-row":"general.updates",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-medium",children:t("Updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l?Yu(l.mode,t):t("Application update settings")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm",children:[t("Current version")," · ",Qu]}),N&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:N})]}),g&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>p(!0),className:"ml-auto shrink-0",children:t("Release notes")}),o?.status==="downloaded"?e.jsx(A,{size:"sm",onClick:()=>{window.electronAPI.updater.quitAndInstall()},className:"shrink-0",children:t("Restart to update")}):f&&o?.status==="available"?e.jsx(A,{size:"sm",onClick:()=>{window.electronAPI.updater.downloadUpdate()},className:"shrink-0",children:t("Download update")}):e.jsx(A,{variant:"outline",size:"sm",disabled:j,onClick:()=>{window.electronAPI.updater.checkForUpdates()},className:"shrink-0",children:t("Check for updates")}),e.jsx(el,{open:u,onOpenChange:p,status:o,canDownload:f})]}),l?.canRestart&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart server")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Running tasks are interrupted; this page reconnects after the server is back.")})]}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>h(!0),className:"shrink-0",children:t("Restart")}),e.jsx(so,{open:x,onOpenChange:h,title:t("Restart server?"),description:t("Running tasks are interrupted; this page reconnects after the server is back."),confirmLabel:t("Restart"),onConfirm:()=>{h(!1),window.electronAPI.updater.restart()}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Automatic updates")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Download and install updates automatically")})]}),e.jsx(oe,{checked:s,onCheckedChange:v=>{n(v),window.electronAPI.updater.setAutoUpdateEnabled(v)}})]}),e.jsxs("div",{className:`flex items-center justify-between gap-3 rounded-md border px-3 py-2.5 ${s?"":"opacity-60"}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Restart and apply when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("After the update is downloaded, restart automatically if no agent is running, nothing is queued, and there are no pending questions or approvals. The idle state must last 5 minutes, and a focused window also blocks it.")})]}),e.jsx(oe,{checked:s&&a,disabled:!s,onCheckedChange:v=>{r(v),window.electronAPI.updater.setAutoRestartWhenIdle(v)}})]})]})}function Yu(t,s){return s(t==="npm"?"Server updates install the new version with npm and restart.":"This server must be updated on the machine itself.")}const Qu="0.3.2",Xu=["100%","100%","70%","100%","55%"],Zu=["100%","85%","60%"];function em({palette:t}){return e.jsxs("div",{className:"flex h-[88px] gap-1.5 p-[7px]",style:{background:t.canvas},children:[e.jsxs("div",{className:"flex w-[30%] flex-col gap-[5px] px-0.5 py-1",children:[e.jsx("i",{className:"block h-[9px] rounded-[3px] opacity-[.18]",style:{background:t.text}}),Xu.slice(1).map((s,n)=>e.jsx("i",{className:"block h-[5px] rounded-[3px] opacity-55",style:{background:t.textSubtle,width:s}},n))]}),e.jsxs("div",{className:"flex flex-1 flex-col gap-[5px] rounded-md px-2.5 py-2",style:{background:t.surface,boxShadow:`0 0 0 1px ${t.border}`},children:[e.jsx("i",{className:"block h-1 w-[70%] rounded-sm opacity-75",style:{background:t.text}}),Zu.map(s=>e.jsx("i",{className:"block h-1 rounded-sm opacity-50",style:{background:t.textSubtle,width:s}},s)),e.jsx("b",{className:"mt-auto flex h-3.5 justify-end rounded-full p-[3px]",style:{background:t.sunken,boxShadow:`0 0 0 1px ${t.border}`},children:e.jsx("span",{"data-theme-accent":!0,className:"size-2 rounded-full",style:{background:t.accent}})})]})]})}const Na="overflow-hidden rounded-lg border text-left transition-shadow";function tm({themes:t,selected:s,mode:n,onSelect:a,onGetMore:r}){const{t:o}=U();return e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[t.map(i=>{const c=i.id===s;return e.jsxs("button",{type:"button","data-theme-card":i.id,"aria-pressed":c,onClick:()=>a(i.id),className:K(Na,"bg-card",c?"border-transparent shadow-[0_0_0_2px_var(--brand)]":"hover:border-input"),children:[e.jsx(em,{palette:i[n]}),e.jsxs("div",{className:"flex items-center gap-1.5 border-t px-2.5 py-[7px] text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:i.name}),e.jsx("span",{className:K("ml-auto shrink-0 truncate rounded-full px-1.5 py-px text-[10.5px]",i.source.kind==="plugin"?"max-w-[60%] bg-brand/12 text-brand":"bg-muted text-subtle-foreground"),children:i.source.kind==="plugin"?o("Plugin · {{name}}",{name:i.source.pluginName}):o("Built-in")})]})]},i.id)}),r&&e.jsxs("button",{type:"button",onClick:r,className:K(Na,"flex min-h-[124px] flex-col items-center justify-center gap-1.5 border-dashed text-sm text-subtle-foreground hover:border-input hover:text-foreground"),children:[e.jsx(Lt,{className:"size-[18px]"}),o("Get more themes")]})]})}function dn({rowId:t,title:s,description:n,children:a}){return e.jsxs("div",{"data-settings-row":t,className:"flex min-h-12 items-center justify-between gap-4 px-3.5 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:s}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:a})]})}function sm({children:t}){return e.jsx("div",{className:"divide-y rounded-lg border bg-card",children:t})}function ct({label:t,value:s,onCommit:n,min:a=0,max:r=100,unit:o="%"}){const[i,c]=m.useState(s);return m.useEffect(()=>{c(s)},[s]),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(hl,{min:a,max:r,value:i,onValueChange:d=>c(Array.isArray(d)?d[0]:d),onValueCommitted:d=>n(Array.isArray(d)?d[0]:d)}),e.jsxs("span",{className:"w-12 shrink-0 text-right text-sm text-muted-foreground",children:[i,o]})]})]})}function nm(){const{t}=U(),s=b(z=>z.backgroundImageEnabled),n=b(z=>z.setBackgroundImageEnabled),a=b(z=>z.backgroundSourceType),r=b(z=>z.setBackgroundSourceType),o=b(z=>z.backgroundImagePath),i=b(z=>z.setBackgroundImagePath),c=b(z=>z.backgroundFolderPath),d=b(z=>z.setBackgroundFolderPath),x=b(z=>z.backgroundUrlPath),h=b(z=>z.setBackgroundUrlPath),u=b(z=>z.backgroundRandomEnabled),p=b(z=>z.setBackgroundRandomEnabled),l=b(z=>z.backgroundRandomInterval),f=b(z=>z.setBackgroundRandomInterval),g=b(z=>z.backgroundOpacity),y=b(z=>z.setBackgroundOpacity),N=b(z=>z.backgroundBlur),j=b(z=>z.setBackgroundBlur),v=b(z=>z.backgroundBrightness),k=b(z=>z.setBackgroundBrightness),R=b(z=>z.backgroundSaturation),L=b(z=>z.setBackgroundSaturation),S=b(z=>z.backgroundMask),O=b(z=>z.setBackgroundMask),w=b(z=>z.backgroundComposerOpacity),M=b(z=>z.setBackgroundComposerOpacity),E=b(z=>z.backgroundCodeOpacity),I=b(z=>z.setBackgroundCodeOpacity),B=b(z=>z.backgroundSizeMode),C=b(z=>z.setBackgroundSizeMode),_=b(z=>z.bumpBackgroundRefresh),V=a==="file"?o:a==="folder"?c:x,[H,$]=m.useState(V);m.useEffect(()=>{$(V)},[V]);const re=m.useCallback(()=>{const z=H.trim();a==="file"?i(z):a==="folder"?d(z):h(z)},[H,a,i,d,h]),[D,q]=m.useState(l);m.useEffect(()=>{q(l)},[l]);const P=async()=>{if(a==="folder"){const z=await window.electronAPI.dialog.selectDirectory();z&&d(z)}else{const z=await window.electronAPI.dialog.selectFile([...ul,...ml]);z&&i(z)}},Y=[{value:"file",label:t("Single image")},{value:"folder",label:t("Folder (random)")},{value:"url",label:t("Remote URL")}],ae=[{value:"cover",label:t("Cover")},{value:"contain",label:t("Contain")},{value:"repeat",label:t("Repeat")},{value:"center",label:t("Center")}],le=t(a==="file"?"Image path":a==="folder"?"Folder path":"Image URL");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between border-t pt-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Background image")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Show a custom image behind the interface")})]}),e.jsx(oe,{checked:s,onCheckedChange:z=>n(z===!0)})]}),s&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Source type")}),e.jsxs(ee,{items:Y,value:a,onValueChange:z=>r(z),children:[e.jsx(te,{className:"w-48",children:e.jsx(se,{})}),e.jsx(ne,{children:Y.map(z=>e.jsx(X,{value:z.value,children:z.label},z.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:le}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:H,onChange:z=>$(z.target.value),onBlur:re,onKeyDown:z=>{z.nativeEvent.isComposing||z.key==="Enter"&&(re(),z.currentTarget.blur())},placeholder:a==="url"?"https://example.com/image.jpg":"",className:"flex-1"}),a!=="url"&&e.jsx(A,{variant:"outline",size:"icon",onClick:P,"aria-label":t("Browse"),children:a==="folder"?e.jsx(Mn,{className:"h-4 w-4"}):e.jsx(Yd,{className:"h-4 w-4"})}),a!=="file"&&e.jsx(A,{variant:"outline",size:"icon",onClick:_,"aria-label":t("Refresh now"),children:e.jsx(rt,{className:"h-4 w-4"})})]})]}),a!=="file"&&e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Auto switch")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{checked:u,onCheckedChange:z=>p(z===!0)}),u&&e.jsxs(e.Fragment,{children:[e.jsx(J,{type:"number",min:5,max:86400,value:D,onChange:z=>q(Number(z.target.value)),onBlur:()=>f(D),onKeyDown:z=>{z.key==="Enter"&&(f(D),z.currentTarget.blur())},className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:t("seconds")})]})]})]}),e.jsx(ct,{label:t("Background visibility"),value:Math.round(g*100),onCommit:z=>y(z/100)}),e.jsx(ct,{label:t("Blur"),value:N,onCommit:j,max:20,unit:"px"}),e.jsx(ct,{label:t("Brightness"),value:Math.round(v*100),onCommit:z=>k(z/100),max:200}),e.jsx(ct,{label:t("Saturation"),value:Math.round(R*100),onCommit:z=>L(z/100),max:200}),e.jsx(ct,{label:t("Overlay"),value:Math.round(S*100),onCommit:z=>O(z/100)}),e.jsx(ct,{label:t("Composer opacity"),value:Math.round(w*100),onCommit:z=>M(z/100)}),e.jsx(ct,{label:t("Code block opacity"),value:Math.round(E*100),onCommit:z=>I(z/100)}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:t("Size mode")}),e.jsxs(ee,{items:ae,value:B,onValueChange:z=>C(z),children:[e.jsx(te,{className:"w-48",children:e.jsx(se,{})}),e.jsx(ne,{children:ae.map(z=>e.jsx(X,{value:z.value,children:z.label},z.value))})]})]})]})]})}function am({theme:t,fontSize:s,fontFamily:n,fontWeight:a}){const r=[{id:"prompt1",text:"$ ",color:t.green},{id:"cmd1",text:"ls -la",color:t.foreground},{id:"nl1",text:`
2
- `},{id:"perm1",text:"drwxr-xr-x ",color:t.blue},{id:"meta1",text:"5 user staff 160 Dec 23 ",color:t.foreground},{id:"dir1",text:"Documents",color:t.cyan},{id:"nl2",text:`
3
- `},{id:"perm2",text:"-rw-r--r-- ",color:t.foreground},{id:"meta2",text:"1 user staff 2048 Dec 22 ",color:t.foreground},{id:"file1",text:"config.json",color:t.yellow},{id:"nl3",text:`
4
-
5
- `},{id:"prompt2",text:"$ ",color:t.green},{id:"cmd2",text:'echo "Hello, World!"',color:t.foreground},{id:"nl4",text:`
6
- `},{id:"output1",text:"Hello, World!",color:t.magenta}];return e.jsxs("div",{className:"rounded-lg border p-4 h-40 overflow-auto",style:{backgroundColor:t.background,fontSize:`${s}px`,fontFamily:n,fontWeight:a},children:[r.map(o=>o.text===`
7
- `?e.jsx("br",{},o.id):o.text===`
8
-
9
- `?e.jsxs(m.Fragment,{children:[e.jsx("br",{}),e.jsx("br",{})]},o.id):e.jsx("span",{style:{color:o.color},children:o.text},o.id)),e.jsx("span",{className:"inline-block w-2 h-4 animate-pulse",style:{backgroundColor:t.cursor}})]})}function rm({isFavorite:t,onClick:s,ariaLabel:n}){return e.jsx("button",{type:"button","aria-label":n,"aria-pressed":t,onClick:a=>{a.stopPropagation(),a.preventDefault(),s(a)},className:"p-1 hover:text-red-500 transition-colors",children:t?e.jsx(fa,{className:"h-4 w-4 fill-red-500 text-red-500"}):e.jsx(fa,{className:"h-4 w-4"})})}function om({value:t,onValueChange:s,themes:n,favoriteThemes:a,onToggleFavorite:r,onThemeHover:o,showFavoritesOnly:i,onShowFavoritesOnlyChange:c,showEmptyFavoritesHint:d}){const{t:x}=U(),[h,u]=m.useState(t),[p,l]=m.useState(t),[f,g]=m.useState(!1),y=m.useRef(void 0),N=m.useRef(null),j=m.useRef(t),v=m.useRef(!1),k=m.useMemo(()=>new Set(a),[a]);m.useEffect(()=>{f||(u(t),l(t))},[t,f]);const R=m.useMemo(()=>{if(!p||p===h)return n;const M=p.toLowerCase();return n.filter(E=>E.toLowerCase().includes(M))},[n,p,h]),L=M=>{M&&(v.current=!0,u(M),l(M)),s(M)},S=M=>{g(M),M?(j.current=t,v.current=!1,u(t),l(t)):v.current||o?.(j.current)},O=M=>{clearTimeout(y.current),y.current=setTimeout(()=>{o?.(M)},50)},w=()=>{clearTimeout(y.current)};return m.useEffect(()=>{if(!f)return;const M=E=>{(E.key==="ArrowDown"||E.key==="ArrowUp")&&requestAnimationFrame(()=>{const I=N.current?.querySelector("[data-highlighted]");if(I){const B=I.getAttribute("data-value");B&&o?.(B)}})};return document.addEventListener("keydown",M,!0),()=>{document.removeEventListener("keydown",M,!0)}},[f,o]),m.useEffect(()=>()=>{clearTimeout(y.current)},[]),e.jsxs(uu,{value:h,onValueChange:L,inputValue:p,onInputValueChange:l,open:f,onOpenChange:S,children:[e.jsxs("div",{className:"relative",children:[e.jsx(mu,{placeholder:x("Search themes...")}),e.jsxs("div",{className:"absolute right-8 top-1/2 -translate-y-1/2 flex items-center gap-1.5",children:[e.jsx(We,{id:"show-favorites-only-inner",checked:i,onCheckedChange:M=>c(M===!0),onClick:M=>M.stopPropagation()}),e.jsx("label",{htmlFor:"show-favorites-only-inner",className:"text-xs text-muted-foreground cursor-pointer whitespace-nowrap",onClick:M=>M.stopPropagation(),onKeyDown:M=>M.stopPropagation(),children:x("Show favorites only")})]})]}),e.jsx(xu,{children:e.jsxs(fu,{ref:N,children:[R.length===0&&e.jsx("div",{className:"py-6 text-center text-sm text-muted-foreground",children:x(d?"No favorite themes yet. Click the heart icon to add favorites.":"No themes found")}),R.map(M=>e.jsx(pu,{value:M,"data-value":M,onMouseEnter:()=>O(M),onMouseLeave:w,endAddon:e.jsx(rm,{isFavorite:k.has(M),onClick:()=>r(M),ariaLabel:k.has(M)?x("Remove from favorites"):x("Add to favorites")}),children:M},M))]})})]})}const im={theme:"Follow theme",violet:"Violet",indigo:"Indigo",teal:"Teal",amber:"Amber",graphite:"Graphite"};function lm(){const{t}=U(),s=b(g=>g.openChangesOnFileEdit),n=b(g=>g.setOpenChangesOnFileEdit),a=b(g=>g.compactReadOnlyTools),r=b(g=>g.setCompactReadOnlyTools),o=b(g=>g.expandLiveEdits),i=b(g=>g.setExpandLiveEdits),c=b(g=>g.expandLiveReasoning),d=b(g=>g.setExpandLiveReasoning),x=b(g=>g.autoCollapseTurns),h=b(g=>g.setAutoCollapseTurns),u=b(g=>g.collapseCompletedActivity),p=b(g=>g.setCollapseCompletedActivity),l=b(g=>g.pinUnfinishedTodos),f=b(g=>g.setPinUnfinishedTodos);return e.jsxs("div",{className:"space-y-6",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Conversation display")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pe,{rowId:"appearance.openChangesOnFileEdit",title:t("Open Changes when files are edited"),description:t("Automatically show the side panel Changes tab after the agent edits a file"),checked:s,onChange:n}),e.jsx(Pe,{rowId:"appearance.compactReadOnlyTools",title:t("Compact read-only tool calls"),description:t("Show read/grep/find/ls as one-line rows and fold consecutive tool calls while the agent is still running"),checked:a,onChange:r}),e.jsx(Pe,{rowId:"appearance.expandLiveEdits",title:t("Expand file edits while running"),description:t("Automatically unfold diffs or written content from file modification tools while the agent is still running"),checked:o,onChange:i}),e.jsx(Pe,{rowId:"appearance.expandLiveReasoning",title:t("Expand reasoning while streaming"),description:t("Automatically unfold the thinking block while the model is still reasoning. It collapses again when reasoning ends."),checked:c,onChange:d}),e.jsx(Pe,{rowId:"appearance.autoCollapseTurns",title:t("Auto-collapse previous turns"),description:t("After you send a new message, fold earlier turns down to the question, timestamp and duration; the latest turn stays expanded"),checked:x,onChange:h}),e.jsx(Pe,{rowId:"appearance.collapseCompletedActivity",title:t("Collapse activity after reply"),description:t("When a reply finishes, fold consecutive thinking and tool calls (including edits and commands) into one summary row; failed calls stay visible"),checked:u,onChange:p}),e.jsx(Pe,{rowId:"appearance.pinUnfinishedTodos",title:t("Pin unfinished todos"),description:t("Keep the latest todo list above the input while it has unfinished items, so it does not scroll away with the timeline"),checked:l,onChange:f})]}),e.jsx(vu,{})]})}function cm({onOpenPlugins:t}){const{t:s}=U(),n=b(i=>i.themeId),a=b(i=>i.setThemeId),r=An(i=>i.themes),o=no();return e.jsxs("section",{"data-settings-row":"appearance.themeGallery",className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Theme")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Built-in and plugin themes; each one is a set of color tokens")})]}),e.jsx(tm,{themes:ro(r),selected:n,mode:o,onSelect:a,onGetMore:t})]})}function dm(){const{t}=U(),s=b(r=>r.userCssEnabled),n=b(r=>r.setUserCssEnabled),a=async()=>{const r=await window.electronAPI.appearance.openUserCss();r.ok||Be({type:"error",title:t("Cannot open user.css"),description:r.error})};return e.jsxs(dn,{rowId:"appearance.userCss",title:t("Custom CSS"),description:t("Inject user.css into every window; saved changes apply immediately"),children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>{a()},children:[e.jsx(dl,{}),t("Open user.css")]}),e.jsx(oe,{checked:s,onCheckedChange:r=>n(r===!0),"aria-label":t("Custom CSS")})]})}function um({onOpenPlugins:t}={}){const{theme:s,setTheme:n,themeId:a,accentColor:r,setAccentColor:o,terminalTheme:i,setTerminalTheme:c,terminalFontSize:d,setTerminalFontSize:x,terminalFontFamily:h,setTerminalFontFamily:u,terminalFontWeight:p,setTerminalFontWeight:l,terminalFontWeightBold:f,setTerminalFontWeightBold:g,favoriteTerminalThemes:y,toggleFavoriteTerminalTheme:N}=b(),{t:j}=U(),v=no(),k=An(P=>P.themes),R=[{value:"light",icon:ou,label:j("Light")},{value:"dark",icon:nl,label:j("Dark")},{value:"system",icon:En,label:j("System")},{value:"sync-terminal",icon:ao,label:j("Sync terminal theme")}],L=al.map(P=>({value:P,label:j(im[P]),swatch:P==="theme"?ol(a,ro(k))[v].accent:rl[P][v]})),[S,O]=m.useState(d),[w,M]=m.useState(h),[E,I]=m.useState(!1);m.useEffect(()=>{O(d)},[d]),m.useEffect(()=>{M(h)},[h]);const B=m.useCallback(()=>{const P=Math.max(8,Math.min(32,S||8));P!==S&&O(P),P!==d&&x(P)},[S,d,x]),C=m.useCallback(()=>{const P=w.trim()||h;P!==w&&M(P),P!==h&&u(P)},[w,h,u]),_=m.useMemo(()=>il(),[]),V=m.useMemo(()=>{if(!E)return _;const P=_.filter(Y=>y.includes(Y));return y.includes(i)?P:[i,...P]},[_,E,y,i]),H=E&&y.length===0,$=m.useMemo(()=>cl(i)??ll,[i]),re=P=>{P&&c(P)},D=()=>{const P=E?V:_,Y=P.indexOf(i),ae=Y<=0?P.length-1:Y-1;c(P[ae])},q=()=>{const P=E?V:_,Y=P.indexOf(i),ae=Y>=P.length-1?0:Y+1;c(P[ae])};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(cm,{onOpenPlugins:t}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:j("Personalization")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j("Applied on top of any theme")})]}),e.jsxs(sm,{children:[e.jsx(dn,{rowId:"appearance.theme",title:j("Theme mode"),children:e.jsx("div",{className:"flex rounded-lg bg-muted p-0.5",children:R.map(P=>e.jsxs("button",{type:"button",onClick:()=>n(P.value),"aria-pressed":s===P.value,className:K("flex h-7 items-center gap-1.5 rounded-md px-2.5 text-xs transition-colors",s===P.value?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:text-foreground"),children:[e.jsx(P.icon,{className:"size-3.5"}),P.label]},P.value))})}),e.jsx(dn,{rowId:"appearance.accent",title:j("Accent color"),description:j("Used for running state, checkmarks and plan mode"),children:L.map(P=>P.value==="theme"?e.jsxs("button",{type:"button",onClick:()=>o(P.value),"aria-pressed":r===P.value,className:K("flex h-6 items-center gap-1.5 rounded-full border px-2 text-xs transition-shadow",r===P.value&&"border-transparent ring-2 ring-foreground/60"),children:[e.jsx("span",{"data-theme-accent":!0,className:"size-2.5 rounded-full",style:{backgroundColor:P.swatch}}),P.label]},P.value):e.jsx("button",{type:"button",onClick:()=>o(P.value),title:P.label,"aria-label":P.label,"aria-pressed":r===P.value,style:{backgroundColor:P.swatch},className:K("size-5 rounded-full transition-shadow",r===P.value&&"ring-2 ring-offset-2 ring-offset-card ring-foreground/60")},P.value))}),e.jsx(dm,{})]})]}),e.jsx(lm,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:j("Terminal")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j("Terminal appearance")})]}),e.jsx(am,{theme:$,fontSize:S,fontFamily:w,fontWeight:p}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-card p-3.5",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:j("Color scheme")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{variant:"outline",size:"icon",onClick:D,children:e.jsx(oo,{className:"h-4 w-4"})}),e.jsx("div",{className:"flex-1",children:e.jsx(om,{value:i,onValueChange:re,themes:V,favoriteThemes:y,onToggleFavorite:N,onThemeHover:c,showFavoritesOnly:E,onShowFavoritesOnlyChange:I,showEmptyFavoritesHint:H})}),e.jsx(A,{variant:"outline",size:"icon",onClick:q,children:e.jsx(At,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:j("Font")}),e.jsx(J,{value:w,onChange:P=>M(P.target.value),onBlur:C,onKeyDown:P=>{P.nativeEvent.isComposing||P.key==="Enter"&&(C(),P.currentTarget.blur())},placeholder:"JetBrains Mono, monospace"})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:j("Font size")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:"number",value:S,onChange:P=>O(Number(P.target.value)),onBlur:B,onKeyDown:P=>{P.key==="Enter"&&(B(),P.currentTarget.blur())},min:8,max:32,className:"w-20"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"px"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:j("Font weight")}),e.jsxs(ee,{items:Ft,value:p,onValueChange:P=>l(P),children:[e.jsx(te,{className:"w-48",children:e.jsx(se,{})}),e.jsx(ne,{children:Ft.map(P=>e.jsx(X,{value:P.value,children:P.label},P.value))})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] items-center gap-4",children:[e.jsx("span",{className:"text-sm font-medium",children:j("Bold font weight")}),e.jsxs(ee,{items:Ft,value:f,onValueChange:P=>g(P),children:[e.jsx(te,{className:"w-48",children:e.jsx(se,{})}),e.jsx(ne,{children:Ft.map(P=>e.jsx(X,{value:P.value,children:P.label},P.value))})]})]})]}),e.jsx(nm,{})]})}const ka=15e3,mm=3e3;function hm(t){return!t||!t.timeoutSet&&t.timeoutMs===mm?ka:t.timeoutMs}const Ca=()=>{},fs="off",gs=t=>({timeoutMs:t?.timeoutMs??xl,...t?.timeoutSet&&{timeoutSet:!0}});function xm({classifier:t,effectiveMs:s,hint:n,onChange:a}){const{t:r}=U(),[o,i]=m.useState(String(s/1e3));m.useEffect(()=>i(String(s/1e3)),[s]);const c=()=>{const d=Number(o);if(!o.trim()||!Number.isFinite(d))return i(String(s/1e3));const x=gl(d*1e3);i(String(x/1e3)),x!==s&&a({...t,timeoutMs:x,timeoutSet:!0})};return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs",children:r("Timeout")}),e.jsx(J,{type:"number",value:o,min:fl/1e3,max:pl/1e3,step:.5,className:"h-7 w-20 text-xs",onChange:d=>i(d.target.value),onBlur:c,onKeyDown:d=>{d.key==="Enter"&&d.currentTarget.blur()}}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r("seconds")}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:n})]})}function Wt({providers:t,value:s,emptyLabel:n,onSelect:a}){return e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx($e,{providers:t,providerId:s?.providerId??"",modelId:s?.modelId??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:n,side:"bottom",triggerClassName:Ze,onSelect:(r,o)=>a({providerId:r,modelId:o}),onReasoningChange:Ca,onThinkingChange:Ca})})}function Vt({label:t,hint:s,children:n}){return e.jsxs("div",{className:"grid grid-cols-[6rem_1fr] items-start gap-2",children:[e.jsxs("div",{className:"pt-1.5 text-xs",children:[e.jsx("div",{children:t}),s&&e.jsx("div",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx("div",{className:"min-w-0 space-y-1",children:n})]})}function Ho({value:t,onChange:s,providers:n,classifierProviders:a,offLabel:r,judgeLabel:o,judgeSeed:i,description:c,effectiveTimeoutMs:d,timeoutHint:x}){const{t:h}=U(),u=t,[p,l]=m.useState(!1),f=u?.source??(p?"judge":fs),g=u?.source==="pi-classifier"?u.model.providerId:"",[y,N]=m.useState([]),[j,v]=m.useState(!1);m.useEffect(()=>{if(!g){N([]);return}let S=!1;return window.electronAPI.providers.classifierModels(g).then(O=>{S||N(O)}),()=>{S=!0}},[g]);const k=async S=>{const w=(await window.electronAPI.providers.classifierModels(S))[0];v(!w),w&&s({source:"pi-classifier",model:{providerId:S,modelId:w.id},...gs(u)})},R=S=>{if(v(!1),l(S==="judge"&&!i),S===fs)return s(void 0);if(S==="judge")return s(i?{source:"judge",model:i,...gs(u)}:void 0);const O=a[0];O&&k(O.id)},L=[{value:fs,label:r},{value:"judge",label:o},...a.length>0?[{value:"pi-classifier",label:h("Classifier model")}]:[]];return e.jsxs("div",{className:"space-y-1",children:[e.jsxs(ee,{items:L,value:f,onValueChange:S=>R(String(S)),children:[e.jsx(te,{size:"sm",className:"w-48",children:e.jsx(se,{})}),e.jsx(ne,{children:L.map(S=>e.jsx(X,{value:S.value,children:S.label},S.value))})]}),f==="judge"&&e.jsx(Wt,{providers:n,value:u?.source==="judge"?u.model:void 0,emptyLabel:h("Select model"),onSelect:S=>{l(!1),s({source:"judge",model:S,...gs(u)})}}),u?.source==="pi-classifier"&&e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(ee,{items:a.map(S=>({value:S.id,label:S.name})),value:u.model.providerId,onValueChange:S=>{k(String(S))},children:[e.jsx(te,{size:"sm",className:"w-40",children:e.jsx(se,{})}),e.jsx(ne,{children:a.map(S=>e.jsx(X,{value:S.id,children:S.name},S.id))})]}),e.jsxs(ee,{items:y.map(S=>({value:S.id,label:S.name})),value:u.model.modelId||null,onValueChange:S=>s({...u,model:{providerId:u.model.providerId,modelId:String(S)}}),children:[e.jsx(te,{size:"sm",className:"min-w-0 flex-1",children:e.jsx(se,{placeholder:h("Select model")})}),e.jsx(ne,{children:y.map(S=>e.jsx(X,{value:S.id,children:S.name},S.id))})]})]}),j&&e.jsx("p",{className:"text-[10px] text-destructive",children:h("No classifier models available")}),u&&e.jsx(xm,{classifier:u,effectiveMs:d??u.timeoutMs,hint:x,onChange:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:c})]})}function pm({entry:t,providers:s,classifierProviders:n,update:a}){const{t:r}=U();return t.fast?e.jsx(Ho,{value:t.classifier,onChange:o=>a({classifier:o}),providers:s,classifierProviders:n,offLabel:r("Off"),judgeLabel:r("Fast model judges"),judgeSeed:t.fast,description:r("Classifies each new turn: simple turns use the fast model, complex ones the primary model. Adds a short delay before the reply."),timeoutHint:r("Uses the primary model on timeout.")}):e.jsx("p",{className:"pt-1.5 text-[11px] text-muted-foreground",children:r("Set a fast model first")})}function fm({entry:t,providers:s,classifierProviders:n}){const{t:a}=U(),r=b(x=>x.updateVirtualModel),o=b(x=>x.removeVirtualModel),i=[t.primary,...t.fast?[t.fast]:[],...t.fallbacks];let c;for(const x of s){const h=x.models.find(u=>u.enabled!==!1&&!i.some(p=>p.providerId===x.id&&p.modelId===u.id));if(h){c={providerId:x.id,modelId:h.id};break}}const d=x=>r(t.id,x);return e.jsxs("div",{"data-slot":"virtual-model-card",className:K("space-y-2 rounded-md border p-2",!t.enabled&&"bg-muted/50 text-muted-foreground"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{"aria-label":a("Enable virtual model"),checked:t.enabled,onCheckedChange:x=>d({enabled:x})}),e.jsx(J,{value:t.name,maxLength:60,placeholder:"Auto",className:"h-7 flex-1 text-xs",onChange:x=>d({name:x.target.value})}),!t.enabled&&e.jsx(Z,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:a("Disabled")}),e.jsx(A,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>o(t.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]}),e.jsx(Vt,{label:a("Primary model"),hint:a("Default for each new turn"),children:e.jsx(Wt,{providers:s,value:t.primary,onSelect:x=>d({primary:x,fallbacks:t.fallbacks.filter(h=>h.providerId!==x.providerId||h.modelId!==x.modelId)})})}),e.jsx(Vt,{label:a("Fast model"),hint:a("Summaries and simple turns"),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Wt,{providers:s,value:t.fast,emptyLabel:a("Not used"),onSelect:x=>d({fast:x})}),t.fast&&e.jsx(A,{type:"button",variant:"ghost",size:"icon","aria-label":a("Clear"),className:"h-6 w-6 shrink-0 text-muted-foreground",onClick:()=>d({fast:void 0}),children:e.jsx(Ct,{className:"h-3.5 w-3.5"})})]})}),e.jsxs(Vt,{label:a("Fallback models"),hint:a("Used in order when a model is rate limited or down"),children:[t.fallbacks.map((x,h)=>e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Wt,{providers:s,value:x,onSelect:u=>d({fallbacks:t.fallbacks.map((p,l)=>l===h?u:p)})}),e.jsx(A,{type:"button",variant:"ghost",size:"icon","aria-label":a("Delete"),className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>d({fallbacks:t.fallbacks.filter((u,p)=>p!==h)}),children:e.jsx(Ct,{className:"h-3.5 w-3.5"})})]},`${x.providerId}/${x.modelId}`)),e.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!c||t.fallbacks.length>=8,onClick:()=>{c&&d({fallbacks:[...t.fallbacks,c]})},children:[e.jsx(Ee,{className:"mr-1 h-3.5 w-3.5"}),a("Add fallback")]})]}),e.jsx(Vt,{label:a("Difficulty routing"),children:e.jsx(pm,{entry:t,providers:s,classifierProviders:n,update:d})})]})}function gm(){const{t}=U(),s=b(d=>d.virtualModels),n=b(d=>d.addVirtualModel),a=b(d=>d.defaultModel),r=Je(),o=m.useMemo(()=>r.filter(io),[r]),i=Pn(),c=m.useMemo(()=>{if(a&&o.find(x=>x.id===a.providerId)?.models.some(x=>x.id===a.modelId&&x.enabled!==!1))return a;for(const d of o){const x=d.models.find(h=>h.enabled!==!1);if(x)return{providerId:d.id,modelId:x.id}}return null},[o,a]);return e.jsxs("section",{"data-slot":"virtual-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Virtual models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("A virtual model appears as one model in the picker and routes each request to a real model: fallbacks on rate limits or outages, image-capable or larger-context members when needed, and the fast model for summaries.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"space-y-2",children:[s.map(d=>e.jsx(fm,{entry:d,providers:o,classifierProviders:i},d.id)),e.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!c,onClick:()=>{c&&n({name:"Auto",enabled:!0,primary:c,fallbacks:[]})},children:[e.jsx(Ee,{className:"mr-1 h-3.5 w-3.5"}),t("New virtual model")]}),!c&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function jm(){const{t}=U();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot mode")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Settings shared by all members and group chats.")})]}),e.jsx(bm,{}),e.jsx(ym,{}),e.jsx(vm,{})]})}const Sa=Array.from({length:jl-sa+1},(t,s)=>sa+s);function vm(){const{t}=U(),s=b(a=>a.botMaxRunningTurns),n=b(a=>a.setBotMaxRunningTurns);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"bots.maxRunningTurns",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Bot concurrency limit")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Shared by private chats, group chats, delegations and routines. Lowering it never interrupts running work; raising it may hit model rate limits.")})]}),e.jsxs(ee,{items:Object.fromEntries(Sa.map(a=>[String(a),String(a)])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-20",children:e.jsx(se,{})}),e.jsx(ne,{children:Sa.map(a=>e.jsx(X,{value:String(a),children:a},a))})]})]})}function bm(){const{t}=U(),s=b(i=>i.botAssistantModel),n=b(i=>i.setBotAssistantModel),a=Je(),r=s?a.find(i=>i.id===s.providerId):void 0,o=r?.models.find(i=>i.id===s?.modelId);return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.assistantModel",children:[e.jsx("p",{className:"text-sm",children:t("Bot assistant model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("Used for helper tasks such as auto-configuring member abilities.")}),e.jsx($e,{providers:a,providerId:o?r?.id??"":"",modelId:o?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ze,onSelect:(i,c)=>n({providerId:i,modelId:c}),onReasoningChange:()=>{},onThinkingChange:()=>{}}),s&&!o&&e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),s&&e.jsx(A,{variant:"ghost",size:"sm",className:"mt-1",onClick:()=>n(null),children:t("Follow default model")})]})}function ym(){const{t}=U(),s=b(i=>i.botRouteClassifier),n=b(i=>i.setBotRouteClassifier),a=Je(),r=m.useMemo(()=>a.filter(io),[a]),o=Pn();return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":"bots.routeClassifier",children:[e.jsx("p",{className:"text-sm",children:t("Group reply picker model")}),e.jsx("p",{className:"mb-2 text-xs text-muted-foreground",children:t("When nobody is @-mentioned in a smart-routing group, this model picks which member replies.")}),e.jsx(Ho,{value:s??void 0,onChange:i=>n(i??null),providers:r,classifierProviders:o,offLabel:t("Default (title model)"),judgeLabel:t("Fast chat model"),description:t("Falls back to the group owner on timeout, error or an unclear answer."),effectiveTimeoutMs:s?hm(s):void 0,timeoutHint:t("Handed to the group owner on timeout.")})]})}const wm=()=>({name:"",title:"",scope:"",summary:"",persona:"",color:an[0],tools:"all",approvalMode:"auto-edits"}),un=(t,s)=>({key:t,name:"",title:"",scope:"",persona:"",color:an[s%an.length],tools:"all",approvalMode:"auto-edits",canDelegateTo:[],acceptFrom:[]}),Nm=()=>({title:"",summary:"",bossKey:"m1",workspace:"chat-home",members:[un("m1",0),un("m2",1)]});function km(t,s){const n=URL.createObjectURL(new Blob([JSON.stringify(s,null,2)],{type:"application/json"})),a=document.createElement("a");a.href=n,a.download=t,a.click(),URL.revokeObjectURL(n)}function Cm(){const{t}=U(),s=vl(!0),n=bl(!0),[a,r]=m.useState(null),[o,i]=m.useState(null),c=m.useRef(null),d=async(f,g)=>{const y=await Rl(N=>({...N,[f]:g(N[f])}));return y||Be({type:"error",title:t("Could not save templates")}),y},x=(f,g)=>d("members",y=>f?ra(y,f,g,zl):oa(y,g,crypto.randomUUID())),h=(f,g)=>d("teams",y=>f?ra(y,f,g,Bl):oa(y,g,crypto.randomUUID())),u=async f=>{const g=Cl(await f.text());if(!g.ok){Be({type:"error",title:na(g.error,t)});return}const y=uo(Sl(g.team));if(!y){Be({type:"error",title:na("invalid",t)});return}await h(void 0,y)&&Be({type:"success",title:t("Imported as a custom team template")})},p=(f,g)=>d(f==="members"?"members":"teams",g),l=(f,g,y)=>e.jsxs(e.Fragment,{children:[e.jsx(ut,{label:t("Edit"),onClick:()=>y({id:g.id,data:g.data}),children:e.jsx(ot,{})}),e.jsx(ut,{label:t("Duplicate as custom"),onClick:()=>y({data:g.data}),children:e.jsx(lo,{})}),g.source==="builtin"&&e.jsx(ut,{label:g.hidden?t("Show"):t("Hide"),onClick:()=>{p(f,N=>Ol(N,g.id,!g.hidden))},children:g.hidden?e.jsx(Nl,{}):e.jsx(kl,{})}),g.modified&&e.jsx(ut,{label:t("Restore default"),onClick:()=>{p(f,N=>ia(N,g.id))},children:e.jsx(co,{})}),g.source==="custom"&&e.jsx(ut,{label:t("Delete"),onClick:()=>{p(f,N=>ia(N,g.id))},children:e.jsx(Ae,{})})]});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Bot templates")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Templates used when creating members and teams. Built-in templates can be edited, hidden or restored.")})]}),e.jsxs(zt,{defaultValue:"members",children:[e.jsxs(Bt,{variant:"underline",children:[e.jsx(Ke,{value:"members",children:t("Member templates")}),e.jsx(Ke,{value:"teams",children:t("Team templates")})]}),e.jsxs(Tt,{value:"members",className:"space-y-2 pt-3",children:[e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>r({data:wm()}),children:[e.jsx(Ee,{}),t("New member template")]}),s.map(f=>e.jsx(Ia,{item:f,avatar:e.jsx(nn,{bot:{name:f.data.name,avatar:{color:f.data.color}}}),title:f.data.name,subtitle:f.data.title,summary:f.data.summary,actions:l("members",f,r)},f.id))]}),e.jsxs(Tt,{value:"teams",className:"space-y-2 pt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>i({data:Nm()}),children:[e.jsx(Ee,{}),t("New team template")]}),e.jsxs(A,{size:"sm",variant:"outline",onClick:()=>c.current?.click(),children:[e.jsx(yl,{}),t("Import team (JSON)")]}),e.jsx("input",{ref:c,type:"file",accept:".json,application/json",hidden:!0,onChange:f=>{const g=f.target.files?.[0];f.target.value="",g&&u(g)}})]}),n.map(f=>e.jsx(Ia,{item:f,avatar:e.jsx("div",{className:"-space-x-1.5 flex shrink-0",children:f.data.members.slice(0,4).map(g=>e.jsx(nn,{size:"sm",bot:{name:g.name,avatar:{color:g.color}}},g.key))}),title:f.data.title,subtitle:t("{{n}} members",{n:f.data.members.length}),summary:f.data.summary,actions:e.jsxs(e.Fragment,{children:[e.jsx(ut,{label:t("Export JSON"),onClick:()=>km(`${f.data.title||"team"}.team.json`,{format:Ll,version:Dl,exportedAt:new Date().toISOString(),team:wl(f.data)}),children:e.jsx(vn,{})}),l("teams",f,i)]})},f.id))]})]}),a&&e.jsx(Sm,{initial:a.data,onClose:()=>r(null),onSave:async f=>{await x(a.id,f)&&r(null)}}),o&&e.jsx(Am,{initial:o.data,onClose:()=>i(null),onSave:async f=>{await h(o.id,f)&&i(null)}})]})}function ut({label:t,onClick:s,disabled:n,children:a}){return e.jsx(A,{variant:"ghost",size:"icon-sm",title:t,"aria-label":t,disabled:n,onClick:s,children:a})}function Ia({item:t,avatar:s,title:n,subtitle:a,summary:r,actions:o}){const{t:i}=U();return e.jsxs("div",{className:"flex items-center gap-3 rounded-md border px-3 py-2.5","data-template-id":t.id,children:[e.jsxs("div",{className:K("flex min-w-0 flex-1 items-center gap-3",t.hidden&&"opacity-50"),children:[s,e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx("span",{className:"truncate",children:n}),e.jsx("span",{className:"truncate font-normal text-muted-foreground text-xs",children:a}),e.jsx(Z,{variant:"secondary",children:t.source==="custom"?i("Custom"):i("Built-in")}),t.modified&&e.jsx(Z,{variant:"outline",children:i("Modified")}),t.hidden&&e.jsx(Z,{variant:"outline",children:i("Hidden")})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center",children:o})]})}function Wo({title:t,error:s,onClose:n,onSave:a,children:r}){const{t:o}=U(),[i,c]=m.useState(!1);return e.jsx(pe,{open:!0,onOpenChange:d=>!d&&n(),children:e.jsxs(fe,{className:"max-h-[85vh] max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:t})}),e.jsxs(Se,{className:"space-y-3",children:[r,s&&e.jsx("p",{className:"text-destructive text-xs",children:s})]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:n,children:o("Cancel")}),e.jsx(A,{size:"sm",disabled:i||!!s,onClick:()=>{c(!0),a().finally(()=>c(!1))},children:o("Save")})]})]})})}function Jo({value:t,onChange:s}){const{t:n}=U(),a=t.name?mo(t.name,[],n):null;return e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(ze,{children:n("Name")}),e.jsx(J,{value:t.name,onChange:r=>s({name:r.target.value})}),a&&e.jsx("p",{className:"mt-1 text-destructive text-xs",children:a})]}),e.jsxs("div",{children:[e.jsx(ze,{children:n("Title")}),e.jsx(J,{value:t.title,onChange:r=>s({title:r.target.value})})]}),e.jsxs("div",{children:[e.jsx(ze,{children:n("Avatar color")}),e.jsx(Pl,{value:t.color,onChange:r=>s({color:r})})]}),e.jsxs("div",{children:[e.jsx(ze,{children:n("Tools")}),e.jsx(ho,{value:t.tools,options:[{value:"all",label:n("All tools")},{value:"readonly",label:n("Read-only")}],onChange:r=>s({tools:r})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{children:n("Approval mode")}),e.jsx(Tl,{value:t.approvalMode,onChange:r=>s({approvalMode:r}),zIndex:Qe.DROPDOWN_IN_MODAL})]}),t.summary!==void 0&&e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{hint:n("Shown on the template card"),children:n("Summary")}),e.jsx(J,{value:t.summary,onChange:r=>s({summary:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{children:n("Responsibilities")}),e.jsx(J,{value:t.scope,onChange:r=>s({scope:r.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{children:n("Persona")}),e.jsx(Xe,{rows:6,value:t.persona,onChange:r=>s({persona:r.target.value})})]})]})}function Sm({initial:t,onClose:s,onSave:n}){const{t:a}=U(),[r,o]=m.useState(t),i=Il(r);return e.jsx(Wo,{title:a("Member template"),error:mo(r.name,[],a)??(i?null:a("Check the template fields")),onClose:s,onSave:()=>i?n(i):Promise.resolve(),children:e.jsx(Jo,{value:r,onChange:c=>o(d=>({...d,...c}))})})}function Im(t,s){switch(t){case"title":return s("Enter a team title");case"members":return s("A team needs 2–12 members");case"name":return s("Every member needs a valid name");case"invalid":return s("Check the template fields");default:return null}}function Am({initial:t,onClose:s,onSave:n}){const{t:a}=U(),[r,o]=m.useState(t),[i,c]=m.useState(null),d=f=>r.members.find(g=>g.key===f)?.name||f,x=f=>o(g=>({...g,...f})),h=(f,g)=>o(y=>({...y,members:y.members.map(N=>N.key===f?{...N,...g}:N)})),u=()=>{const f=new Set(r.members.map(N=>N.key));let g=r.members.length+1;for(;f.has(`m${g}`);)g++;const y=`m${g}`;x({members:[...r.members,un(y,r.members.length)]}),c(y)},p=f=>{const g=y=>y==="any"?"any":y.filter(N=>N!==f);x({members:r.members.filter(y=>y.key!==f).map(y=>({...y,canDelegateTo:g(y.canDelegateTo),acceptFrom:g(y.acceptFrom)}))})},l=uo(r);return e.jsxs(Wo,{title:a("Team template"),error:Im(Ml(r),a),onClose:s,onSave:()=>l?n(l):Promise.resolve(),children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(ze,{children:a("Group name")}),e.jsx(J,{value:r.title,onChange:f=>x({title:f.target.value})})]}),e.jsxs("div",{children:[e.jsx(ze,{children:a("Owner")}),e.jsxs(ee,{items:r.members.map(f=>({value:f.key,label:d(f.key)})),value:r.bossKey,onValueChange:f=>x({bossKey:f}),children:[e.jsx(te,{className:"w-full",children:e.jsx(se,{})}),e.jsx(ne,{zIndex:Qe.DROPDOWN_IN_MODAL,children:r.members.map(f=>e.jsx(X,{value:f.key,children:d(f.key)},f.key))})]})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{hint:a("Shown on the template card"),children:a("Summary")}),e.jsx(J,{value:r.summary,onChange:f=>x({summary:f.target.value})})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(ze,{children:a("Shared workspace")}),e.jsx(ho,{value:r.workspace,options:[{value:"chat-home",label:a("Standalone workspace")},{value:"project",label:a("Based on a Code project")}],onChange:f=>x({workspace:f})})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground text-xs",children:a("Members")}),e.jsxs(A,{size:"xs",variant:"outline",disabled:r.members.length>=Al,onClick:u,children:[e.jsx(Ee,{}),a("Add member")]})]}),e.jsx("div",{className:"space-y-1.5",children:r.members.map(f=>{const g=i===f.key,y=f.key===r.bossKey,N=r.members.filter(j=>j.key!==f.key).map(j=>j.key);return e.jsxs("div",{className:"rounded-lg border","data-member-key":f.key,children:[e.jsxs("div",{className:"flex items-center gap-2 px-2.5 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>c(g?null:f.key),children:[g?e.jsx(Yt,{className:"h-3.5 w-3.5 shrink-0"}):e.jsx(At,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx(nn,{bot:{name:f.name,avatar:{color:f.color}},size:"sm"}),e.jsx("span",{className:"truncate text-sm",children:f.name||a("Unnamed")}),e.jsx("span",{className:"truncate text-muted-foreground text-xs",children:f.title}),y&&e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground",children:[e.jsx(El,{className:"h-3 w-3"}),a("Owner")]})]}),e.jsx(ut,{label:a("Remove"),disabled:y||r.members.length<=2,onClick:()=>p(f.key),children:e.jsx(Ae,{})})]}),g&&e.jsxs("div",{className:"space-y-3 border-t p-2.5",children:[e.jsx(Jo,{value:f,onChange:j=>h(f.key,j)}),e.jsx(aa,{label:a("Can delegate to"),value:f.canDelegateTo,options:N,nameOf:d,onChange:j=>h(f.key,{canDelegateTo:j})}),e.jsx(aa,{label:a("Accepts delegation from"),value:f.acceptFrom,options:N,nameOf:d,onChange:j=>h(f.key,{acceptFrom:j})})]})]},f.key)})})]})]})}function Yo(t){return t.capturePermission==="unsupported"&&t.axPermission==="unsupported"?"unsupported":t.capturePermission==="granted"&&(t.axPermission==="granted"||t.axPermission==="unsupported")?"ready":"needs-permission"}const Em=[{id:"collaboration",label:"Collaboration & planning"},{id:"web",label:"Web"},{id:"execution",label:"Execution"},{id:"context",label:"Context & memory"},{id:"safety",label:"Safety"}],Aa={subagent:"collaboration",workflow:"collaboration",todo:"collaboration",plan:"collaboration",ask_user:"collaboration",browser:"web",web:"web",background_tasks:"execution",isolated_sandbox:"execution",computer:"execution",memory:"context"};function Mm(t,s){return t.filter(n=>Object.hasOwn(Aa,n.id)?Aa[n.id]===s:!1)}function Ea(t){return t.bundleId||t.path}function Pm(){const{t}=U(),[s,n]=m.useState(null),a=b(i=>i.computerAllowAllApps),r=b(i=>i.setComputerAllowAllApps);m.useEffect(()=>{let i=!1;return window.electronAPI.computer.allowedApps().then(c=>{i||n(c)}),()=>{i=!0}},[]);const o=async i=>{await window.electronAPI.computer.revokeApp(Ea(i)),n(await window.electronAPI.computer.allowedApps())};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.computerApps",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Apps the AI may control")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The first time the AI clicks or types in an app, EnsoCode asks you. Apps you always allow are listed here; it can then read everything in their windows.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Allow all apps")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The AI can click, type and read in any app without asking. It can see everything in their windows, including chats and passwords.")})]}),e.jsx(oe,{checked:a,onCheckedChange:r})]}),s&&s.length===0?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("No apps are always allowed yet.")}):null,s&&s.length>0?e.jsx("ul",{className:"divide-y rounded-md border",children:s.map(i=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:i.name}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",title:i.path,children:i.bundleId||i.path})]}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{o(i)},children:t("Revoke")})]},Ea(i)))}):null]})}function Tm(t){return Object.fromEntries(t.map(s=>[s.id,s]))}function as(t,s){return t.reduce((n,a)=>{const r=s[a]?.tokens;return r==null?n:n+r},0)}function rs({row:t,pending:s}){const{t:n}=U(),a=s?"…":t?.tokens==null?"—":Fe(t.tokens);return e.jsx("span",{className:"w-12 shrink-0 text-right text-muted-foreground text-xs tabular-nums",title:t?.error||n("Estimate"),children:a})}function os({tokens:t}){return t<=0?null:e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs tabular-nums",children:Fe(t)})}function is(t,s){const[n,a]=m.useState({}),[r,o]=m.useState(()=>t.length>0),i=t.join("\0"),c=m.useRef(s);return c.current=s,m.useEffect(()=>{let d=!1;const x=i.length===0?[]:i.split("\0");if(x.length===0){a({}),o(!1);return}return o(!0),c.current(x).then(h=>{d||a(Tm(h))}).finally(()=>{d||o(!1)}),()=>{d=!0}},[i]),{rows:n,pending:r}}const Ma={replace:"Text replacement",apply_patch:"Apply patch (default)"},Rm={subagent:ql,workflow:Tn,todo:Kl,plan:Vl,ask_user:$l,browser:Ul,web:po,background_tasks:Fl,memory:xo,isolated_sandbox:zd,computer:En};function yt({icon:t,title:s,description:n,control:a,children:r,rowId:o,newSession:i}){return e.jsxs("div",{className:"rounded-md border px-3 py-2.5","data-settings-row":o,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(t,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-medium",children:[s,i&&e.jsx(qe,{note:typeof i=="string"?i:void 0})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n})]}),a]}),r?e.jsx("div",{className:"mt-2 space-y-2 pl-7",children:r}):null]})}function Om({disabled:t}){const{t:s}=U(),n=b(u=>u.webSearchChain),a=b(u=>u.setWebSearchChain),r=ss(),o=m.useMemo(()=>Hl(r),[r]),[i,c]=m.useState(null),d=(u,p)=>{a(n.map((l,f)=>f===u?{...l,...p}:l))},x=u=>a(n.filter((p,l)=>l!==u)),h=(u,p)=>{if(u===p)return;const l=[...n],[f]=l.splice(u,1);f&&(l.splice(p,0,f),a(l))};return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.webSearchChain",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Try these models' built-in search in order. Credentials resolve at call time; if all fail, the keyless Exa service is the permanent fallback.")}),n.length===0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Default: use the current session model's built-in search when available, otherwise Exa.")}),n.map((u,p)=>e.jsxs("div",{className:"flex items-center gap-2 rounded-md border px-2 py-1.5",draggable:!t,onDragStart:l=>{l.dataTransfer.effectAllowed="move",c(p)},onDragEnd:()=>c(null),onDragOver:l=>{i!==null&&i!==p&&l.preventDefault()},onDrop:l=>{l.preventDefault(),i!==null&&h(i,p),c(null)},children:[e.jsx(Wl,{className:"h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground"}),e.jsx("span",{className:"w-4 shrink-0 text-center text-muted-foreground text-xs",children:p+1}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx($e,{providers:o,providerId:u.providerId,modelId:u.modelId,reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,onSelect:(l,f)=>d(p,{providerId:l,modelId:f}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0",disabled:t,onClick:()=>x(p),"aria-label":s("Remove"),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]},`${u.providerId}/${u.modelId}`)),n.length<Jl&&e.jsx("div",{className:"max-w-xs",children:e.jsx($e,{providers:o,providerId:"",modelId:"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,triggerLabel:`+ ${s("Add candidate")}`,onSelect:(u,p)=>a([...n,{providerId:u,modelId:p}]),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Final fallback: Exa (keyless hosted search). Not a chain entry; always last.")})]})}function Dm(){const{t}=U(),s=b(I=>I.disabledBuiltinTools),n=b(I=>I.toggleBuiltinTool),a=b(I=>I.subagentAllowedModes),r=b(I=>I.setSubagentAllowedModes),o=b(I=>I.exploreFoldEnabled),i=b(I=>I.setExploreFoldEnabled),c=b(I=>I.rtkEnabled),d=b(I=>I.computerPreview),x=b(I=>I.setComputerPreview),h=b(I=>I.setRtkEnabled),u=b(I=>I.protectedActionsInCode),p=b(I=>I.setProtectedActionsInCode),l=b(I=>I.editMode),f=b(I=>I.setEditMode),g=is(xs.map(I=>I.id),()=>window.electronAPI.assets.builtinToolOccupancy()),y=as(xs.filter(I=>!s.includes(I.id)).map(I=>I.id),g.rows),[N,j]=m.useState(null),v=!s.includes("subagent"),k=(I,B)=>{r(B?[...new Set([...a,I])]:a.filter(C=>C!==I))},R=async I=>{await window.electronAPI.browser.clearData(I),j(I),setTimeout(()=>j(null),2e3)},L=!s.includes("computer"),[S,O]=m.useState(null),[w,M]=m.useState(!1);m.useEffect(()=>{if(!L){O(null);return}let I=!1;return window.electronAPI.computer.capabilities().then(B=>{!I&&B.ok&&O(B.capabilities)}),()=>{I=!0}},[L]),m.useEffect(()=>{if(!w)return;let I=!1;const B=()=>{window.electronAPI.computer.capabilities().then(_=>{!I&&_.ok&&O(_.capabilities)})};B();const C=window.setInterval(B,2e3);return()=>{I=!0,window.clearInterval(C)}},[w]);const E={collaboration:null,web:null,execution:e.jsx(yt,{rowId:"tools.editMode",newSession:!0,icon:Vd,title:t("File edit mode"),description:t("Choose how files are modified. Apply patch is the default. New and cold-restored sessions use this mode; already warm sessions keep their current mode."),control:e.jsxs(ee,{items:Object.fromEntries(la.map(I=>[I,t(Ma[I])])),value:l,onValueChange:I=>{_l(I)&&f(I)},children:[e.jsx(te,{className:"w-44 shrink-0","aria-label":t("File edit mode"),children:e.jsx(se,{})}),e.jsx(ne,{children:la.map(I=>e.jsx(X,{value:I,children:t(Ma[I])},I))})]})}),context:e.jsxs(e.Fragment,{children:[e.jsx(yt,{icon:Hd,newSession:!0,title:t("Explore fold"),description:t("Let the agent mark exploratory reads and keep only a short report in later model context. Timeline stays intact."),control:e.jsx(oe,{checked:o,onCheckedChange:i})}),e.jsx(yt,{rowId:"tools.rtkEnabled",newSession:!0,icon:su,title:t("RTK command compression"),description:t("Compress supported command output before it enters the model context. Takes effect on new conversations."),control:e.jsx(oe,{checked:c,onCheckedChange:h})})]}),safety:e.jsxs(e.Fragment,{children:[e.jsx(yt,{icon:bn,newSession:!0,title:t("Protected action confirmation"),description:t("Even in full-access mode, ask before external sends, deletions, payments, deployments and secret-file access. Always on for Bot members not set to Full access. Takes effect on new conversations."),control:e.jsx(oe,{checked:u,onCheckedChange:p})}),e.jsx(Lm,{})]})};return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{"data-settings-row":"tools.root",children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Built-in tools"),e.jsx(os,{tokens:y})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Toggle the built-in tools available to agents.")})]}),Em.map(I=>e.jsxs("section",{className:"space-y-3",children:[e.jsx("h4",{className:"border-b pb-2 text-base font-semibold",children:t(I.label)}),Mm(xs,I.id).map(B=>e.jsxs(yt,{icon:Rm[B.id]??fo,title:t(B.name),description:t(B.description),newSession:B.id==="isolated_sandbox"?t("Isolated sandbox switches between script and tool-search mode, so open sessions keep the mode they started with."):void 0,control:e.jsxs(e.Fragment,{children:[e.jsx(rs,{row:g.rows[B.id],pending:g.pending&&!g.rows[B.id]}),e.jsx(oe,{checked:!s.includes(B.id),onCheckedChange:C=>{n(B.id,C),B.id==="computer"&&C&&M(!0)}})]}),children:[B.id==="web"?e.jsx(Om,{disabled:s.includes("web")}):null,B.id==="subagent"?e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.subagentModes",children:[[["task","One-shot task agents"],["coworker","Persistent coworkers"]].map(([C,_])=>e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-sm",children:t(_)}),e.jsx(oe,{checked:a.includes(C),disabled:!v,onCheckedChange:V=>k(C,V)})]},C)),!v&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The unified subagent tool is off. Re-enabling it keeps this mode selection.")})]}):null,B.id==="computer"&&L?e.jsx("div",{className:"space-y-2","data-settings-row":"tools.computer",children:S&&Yo(S)==="unsupported"?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("This platform cannot operate the desktop yet.")}):e.jsxs(e.Fragment,{children:[S?.platform==="darwin"&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")}),S&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[t(S.capturePermission==="granted"?"Capture: granted":"Capture: denied"),S.axPermission!=="unsupported"&&e.jsxs(e.Fragment,{children:[" · ",t(S.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied")]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>M(!0),children:t("Show permission guide")}),S?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:t("Open Screen Recording settings")}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:t("Open Accessibility settings")})]})]}),S?.platform==="darwin"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-sm",children:t("Show the app being operated")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("While the AI works in an app in the background, a small floating window shows that app live. Close it any time.")})]}),e.jsx(oe,{checked:d,onCheckedChange:x})]}),e.jsx(Pm,{})]})]})}):null,B.id==="browser"?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Cookies and site storage of the built-in browser, separate from the app itself.")}),e.jsx("div",{className:"flex flex-wrap gap-2",children:["cookies","cache","all"].map(C=>e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{R(C)},children:t(N===C?"Cleared":C==="cookies"?"Clear cookies":C==="cache"?"Clear cache":"Clear all browsing data")},C))})]}):null]},B.id)),E[I.id]]},I.id)),e.jsx(zm,{open:w,capabilities:S,onOpenChange:M})]})}function Lm(){const{t}=U(),s=b(l=>l.dcgEnabled),n=b(l=>l.setDcgEnabled),[a,r]=m.useState(null),[o,i]=m.useState(!1),[c,d]=m.useState(null),[x,h]=m.useState(!1);m.useEffect(()=>{let l=!1;return window.electronAPI.dcg.status().then(f=>{l||r(f)}),()=>{l=!0}},[]);const u=async l=>{h(!1),i(!0),d(null);const f=await window.electronAPI.dcg[l]();r(f.status),f.ok?n(l==="install"):d(f.error??t("Operation failed")),i(!1)},p=a?.installed===!0;return e.jsxs(yt,{rowId:"tools.dcgEnabled",newSession:!0,icon:Gl,title:t("Destructive command guard (dcg)"),description:t("Check bash and PowerShell commands with dcg before running. Matches such as git reset --hard or recursive deletes always require your confirmation, even in full-access mode. Takes effect on new conversations."),control:e.jsx(oe,{checked:s&&p,disabled:!p,onCheckedChange:n}),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:a?a.supported?p?t("Installed v{{version}}",{version:a.version}):t("Not installed"):t("Not available on this platform"):t("Loading…")}),a?.supported&&(p?e.jsx(A,{variant:"outline",size:"xs",disabled:o,onClick:()=>{u("uninstall")},children:t("Uninstall")}):e.jsx(A,{variant:"outline",size:"xs",disabled:o,onClick:()=>h(!0),children:t(o?"Installing…":"Install")}))]}),c&&e.jsx("p",{className:"text-destructive text-xs",children:c}),e.jsx(pe,{open:x,onOpenChange:h,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:t("Install dcg")}),e.jsx(Ue,{children:t("Downloads dcg v{{version}} from its GitHub release and verifies the checksum. dcg is a third-party tool, not part of EnsoCode.",{version:a?.version??""})})]}),e.jsx(Se,{children:e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(_e,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:t("dcg is licensed under MIT with an additional rider: no rights are granted to OpenAI, Anthropic, their affiliates, or anyone acting on their behalf. Install only if this restriction does not apply to you.")})]})}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>h(!1),children:t("Cancel")}),e.jsx(A,{size:"sm",onClick:()=>{u("install")},children:t("Agree and install")})]})]})})]})}function zm({open:t,capabilities:s,onOpenChange:n}){const{t:a}=U(),r=s?Yo(s):null;return e.jsx(pe,{open:t,onOpenChange:n,children:e.jsxs(fe,{className:"max-w-md",zIndexLevel:"nested",children:[e.jsxs(ge,{children:[e.jsx(je,{children:a("Grant Computer permissions")}),e.jsx(Ue,{children:a(r==="unsupported"?"This platform cannot operate the desktop yet.":r==="ready"?"Computer is ready. Open sessions can use it from their next step.":"The agent can screenshot windows and control the mouse and keyboard. Grant Screen Recording and Accessibility to EnsoCode, then restart.")})]}),e.jsxs(Se,{className:"space-y-3",children:[!s&&e.jsx("p",{className:"text-muted-foreground text-sm",children:a("Loading…")}),r==="needs-permission"&&e.jsxs("div",{className:"flex gap-2 rounded-md border border-destructive/32 bg-destructive/8 p-3 text-sm",children:[e.jsx(_e,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("p",{children:a("Computer needs Screen Recording to capture windows and Accessibility to inspect or click them. Grant both to EnsoCode, then restart the app.")})]}),s?.platform==="darwin"&&r!=="unsupported"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-muted-foreground text-xs",children:[a(s.capturePermission==="granted"?"Capture: granted":"Capture: denied")," · ",a(s.axPermission==="granted"?"Input/AX: granted":"Input/AX: denied"),s.detail?` · ${s.detail}`:""]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("screen")},children:a("Open Screen Recording settings")}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.computer.openPermissions("accessibility")},children:a("Open Accessibility settings")})]})]})]}),e.jsx(Ie,{className:"sm:justify-end",children:e.jsx(A,{size:"sm",onClick:()=>n(!1),children:a("Done")})})]})})}function Bm(t){if(t==null||!Number.isFinite(t)||t<0)return null;const s=Math.round(t);return s<1?"<1ms":`${s}ms`}var gt={},js,Pa;function _m(){return Pa||(Pa=1,js=function(){return typeof Promise=="function"&&Promise.prototype&&Promise.prototype.then}),js}var vs={},st={},Ta;function mt(){if(Ta)return st;Ta=1;let t;const s=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];return st.getSymbolSize=function(a){if(!a)throw new Error('"version" cannot be null or undefined');if(a<1||a>40)throw new Error('"version" should be in range from 1 to 40');return a*4+17},st.getSymbolTotalCodewords=function(a){return s[a]},st.getBCHDigit=function(n){let a=0;for(;n!==0;)a++,n>>>=1;return a},st.setToSJISFunction=function(a){if(typeof a!="function")throw new Error('"toSJISFunc" is not a valid function.');t=a},st.isKanjiModeEnabled=function(){return typeof t<"u"},st.toSJIS=function(a){return t(a)},st}var bs={},Ra;function _n(){return Ra||(Ra=1,(function(t){t.L={bit:1},t.M={bit:0},t.Q={bit:3},t.H={bit:2};function s(n){if(typeof n!="string")throw new Error("Param is not a string");switch(n.toLowerCase()){case"l":case"low":return t.L;case"m":case"medium":return t.M;case"q":case"quartile":return t.Q;case"h":case"high":return t.H;default:throw new Error("Unknown EC Level: "+n)}}t.isValid=function(a){return a&&typeof a.bit<"u"&&a.bit>=0&&a.bit<4},t.from=function(a,r){if(t.isValid(a))return a;try{return s(a)}catch{return r}}})(bs)),bs}var ys,Oa;function Fm(){if(Oa)return ys;Oa=1;function t(){this.buffer=[],this.length=0}return t.prototype={get:function(s){const n=Math.floor(s/8);return(this.buffer[n]>>>7-s%8&1)===1},put:function(s,n){for(let a=0;a<n;a++)this.putBit((s>>>n-a-1&1)===1)},getLengthInBits:function(){return this.length},putBit:function(s){const n=Math.floor(this.length/8);this.buffer.length<=n&&this.buffer.push(0),s&&(this.buffer[n]|=128>>>this.length%8),this.length++}},ys=t,ys}var ws,Da;function Um(){if(Da)return ws;Da=1;function t(s){if(!s||s<1)throw new Error("BitMatrix size must be defined and greater than 0");this.size=s,this.data=new Uint8Array(s*s),this.reservedBit=new Uint8Array(s*s)}return t.prototype.set=function(s,n,a,r){const o=s*this.size+n;this.data[o]=a,r&&(this.reservedBit[o]=!0)},t.prototype.get=function(s,n){return this.data[s*this.size+n]},t.prototype.xor=function(s,n,a){this.data[s*this.size+n]^=a},t.prototype.isReserved=function(s,n){return this.reservedBit[s*this.size+n]},ws=t,ws}var Ns={},La;function $m(){return La||(La=1,(function(t){const s=mt().getSymbolSize;t.getRowColCoords=function(a){if(a===1)return[];const r=Math.floor(a/7)+2,o=s(a),i=o===145?26:Math.ceil((o-13)/(2*r-2))*2,c=[o-7];for(let d=1;d<r-1;d++)c[d]=c[d-1]-i;return c.push(6),c.reverse()},t.getPositions=function(a){const r=[],o=t.getRowColCoords(a),i=o.length;for(let c=0;c<i;c++)for(let d=0;d<i;d++)c===0&&d===0||c===0&&d===i-1||c===i-1&&d===0||r.push([o[c],o[d]]);return r}})(Ns)),Ns}var ks={},za;function Vm(){if(za)return ks;za=1;const t=mt().getSymbolSize,s=7;return ks.getPositions=function(a){const r=t(a);return[[0,0],[r-s,0],[0,r-s]]},ks}var Cs={},Ba;function Km(){return Ba||(Ba=1,(function(t){t.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};const s={N1:3,N2:3,N3:40,N4:10};t.isValid=function(r){return r!=null&&r!==""&&!isNaN(r)&&r>=0&&r<=7},t.from=function(r){return t.isValid(r)?parseInt(r,10):void 0},t.getPenaltyN1=function(r){const o=r.size;let i=0,c=0,d=0,x=null,h=null;for(let u=0;u<o;u++){c=d=0,x=h=null;for(let p=0;p<o;p++){let l=r.get(u,p);l===x?c++:(c>=5&&(i+=s.N1+(c-5)),x=l,c=1),l=r.get(p,u),l===h?d++:(d>=5&&(i+=s.N1+(d-5)),h=l,d=1)}c>=5&&(i+=s.N1+(c-5)),d>=5&&(i+=s.N1+(d-5))}return i},t.getPenaltyN2=function(r){const o=r.size;let i=0;for(let c=0;c<o-1;c++)for(let d=0;d<o-1;d++){const x=r.get(c,d)+r.get(c,d+1)+r.get(c+1,d)+r.get(c+1,d+1);(x===4||x===0)&&i++}return i*s.N2},t.getPenaltyN3=function(r){const o=r.size;let i=0,c=0,d=0;for(let x=0;x<o;x++){c=d=0;for(let h=0;h<o;h++)c=c<<1&2047|r.get(x,h),h>=10&&(c===1488||c===93)&&i++,d=d<<1&2047|r.get(h,x),h>=10&&(d===1488||d===93)&&i++}return i*s.N3},t.getPenaltyN4=function(r){let o=0;const i=r.data.length;for(let d=0;d<i;d++)o+=r.data[d];return Math.abs(Math.ceil(o*100/i/5)-10)*s.N4};function n(a,r,o){switch(a){case t.Patterns.PATTERN000:return(r+o)%2===0;case t.Patterns.PATTERN001:return r%2===0;case t.Patterns.PATTERN010:return o%3===0;case t.Patterns.PATTERN011:return(r+o)%3===0;case t.Patterns.PATTERN100:return(Math.floor(r/2)+Math.floor(o/3))%2===0;case t.Patterns.PATTERN101:return r*o%2+r*o%3===0;case t.Patterns.PATTERN110:return(r*o%2+r*o%3)%2===0;case t.Patterns.PATTERN111:return(r*o%3+(r+o)%2)%2===0;default:throw new Error("bad maskPattern:"+a)}}t.applyMask=function(r,o){const i=o.size;for(let c=0;c<i;c++)for(let d=0;d<i;d++)o.isReserved(d,c)||o.xor(d,c,n(r,d,c))},t.getBestMask=function(r,o){const i=Object.keys(t.Patterns).length;let c=0,d=1/0;for(let x=0;x<i;x++){o(x),t.applyMask(x,r);const h=t.getPenaltyN1(r)+t.getPenaltyN2(r)+t.getPenaltyN3(r)+t.getPenaltyN4(r);t.applyMask(x,r),h<d&&(d=h,c=x)}return c}})(Cs)),Cs}var Kt={},_a;function Qo(){if(_a)return Kt;_a=1;const t=_n(),s=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],n=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];return Kt.getBlocksCount=function(r,o){switch(o){case t.L:return s[(r-1)*4+0];case t.M:return s[(r-1)*4+1];case t.Q:return s[(r-1)*4+2];case t.H:return s[(r-1)*4+3];default:return}},Kt.getTotalCodewordsCount=function(r,o){switch(o){case t.L:return n[(r-1)*4+0];case t.M:return n[(r-1)*4+1];case t.Q:return n[(r-1)*4+2];case t.H:return n[(r-1)*4+3];default:return}},Kt}var Ss={},Mt={},Fa;function qm(){if(Fa)return Mt;Fa=1;const t=new Uint8Array(512),s=new Uint8Array(256);return(function(){let a=1;for(let r=0;r<255;r++)t[r]=a,s[a]=r,a<<=1,a&256&&(a^=285);for(let r=255;r<512;r++)t[r]=t[r-255]})(),Mt.log=function(a){if(a<1)throw new Error("log("+a+")");return s[a]},Mt.exp=function(a){return t[a]},Mt.mul=function(a,r){return a===0||r===0?0:t[s[a]+s[r]]},Mt}var Ua;function Gm(){return Ua||(Ua=1,(function(t){const s=qm();t.mul=function(a,r){const o=new Uint8Array(a.length+r.length-1);for(let i=0;i<a.length;i++)for(let c=0;c<r.length;c++)o[i+c]^=s.mul(a[i],r[c]);return o},t.mod=function(a,r){let o=new Uint8Array(a);for(;o.length-r.length>=0;){const i=o[0];for(let d=0;d<r.length;d++)o[d]^=s.mul(r[d],i);let c=0;for(;c<o.length&&o[c]===0;)c++;o=o.slice(c)}return o},t.generateECPolynomial=function(a){let r=new Uint8Array([1]);for(let o=0;o<a;o++)r=t.mul(r,new Uint8Array([1,s.exp(o)]));return r}})(Ss)),Ss}var Is,$a;function Hm(){if($a)return Is;$a=1;const t=Gm();function s(n){this.genPoly=void 0,this.degree=n,this.degree&&this.initialize(this.degree)}return s.prototype.initialize=function(a){this.degree=a,this.genPoly=t.generateECPolynomial(this.degree)},s.prototype.encode=function(a){if(!this.genPoly)throw new Error("Encoder not initialized");const r=new Uint8Array(a.length+this.degree);r.set(a);const o=t.mod(r,this.genPoly),i=this.degree-o.length;if(i>0){const c=new Uint8Array(this.degree);return c.set(o,i),c}return o},Is=s,Is}var As={},Es={},Ms={},Va;function Xo(){return Va||(Va=1,Ms.isValid=function(s){return!isNaN(s)&&s>=1&&s<=40}),Ms}var Ge={},Ka;function Zo(){if(Ka)return Ge;Ka=1;const t="[0-9]+",s="[A-Z $%*+\\-./:]+";let n="(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+";n=n.replace(/u/g,"\\u");const a="(?:(?![A-Z0-9 $%*+\\-./:]|"+n+`)(?:.|[\r
10
- ]))+`;Ge.KANJI=new RegExp(n,"g"),Ge.BYTE_KANJI=new RegExp("[^A-Z0-9 $%*+\\-./:]+","g"),Ge.BYTE=new RegExp(a,"g"),Ge.NUMERIC=new RegExp(t,"g"),Ge.ALPHANUMERIC=new RegExp(s,"g");const r=new RegExp("^"+n+"$"),o=new RegExp("^"+t+"$"),i=new RegExp("^[A-Z0-9 $%*+\\-./:]+$");return Ge.testKanji=function(d){return r.test(d)},Ge.testNumeric=function(d){return o.test(d)},Ge.testAlphanumeric=function(d){return i.test(d)},Ge}var qa;function ht(){return qa||(qa=1,(function(t){const s=Xo(),n=Zo();t.NUMERIC={id:"Numeric",bit:1,ccBits:[10,12,14]},t.ALPHANUMERIC={id:"Alphanumeric",bit:2,ccBits:[9,11,13]},t.BYTE={id:"Byte",bit:4,ccBits:[8,16,16]},t.KANJI={id:"Kanji",bit:8,ccBits:[8,10,12]},t.MIXED={bit:-1},t.getCharCountIndicator=function(o,i){if(!o.ccBits)throw new Error("Invalid mode: "+o);if(!s.isValid(i))throw new Error("Invalid version: "+i);return i>=1&&i<10?o.ccBits[0]:i<27?o.ccBits[1]:o.ccBits[2]},t.getBestModeForData=function(o){return n.testNumeric(o)?t.NUMERIC:n.testAlphanumeric(o)?t.ALPHANUMERIC:n.testKanji(o)?t.KANJI:t.BYTE},t.toString=function(o){if(o&&o.id)return o.id;throw new Error("Invalid mode")},t.isValid=function(o){return o&&o.bit&&o.ccBits};function a(r){if(typeof r!="string")throw new Error("Param is not a string");switch(r.toLowerCase()){case"numeric":return t.NUMERIC;case"alphanumeric":return t.ALPHANUMERIC;case"kanji":return t.KANJI;case"byte":return t.BYTE;default:throw new Error("Unknown mode: "+r)}}t.from=function(o,i){if(t.isValid(o))return o;try{return a(o)}catch{return i}}})(Es)),Es}var Ga;function Wm(){return Ga||(Ga=1,(function(t){const s=mt(),n=Qo(),a=_n(),r=ht(),o=Xo(),i=7973,c=s.getBCHDigit(i);function d(p,l,f){for(let g=1;g<=40;g++)if(l<=t.getCapacity(g,f,p))return g}function x(p,l){return r.getCharCountIndicator(p,l)+4}function h(p,l){let f=0;return p.forEach(function(g){const y=x(g.mode,l);f+=y+g.getBitsLength()}),f}function u(p,l){for(let f=1;f<=40;f++)if(h(p,f)<=t.getCapacity(f,l,r.MIXED))return f}t.from=function(l,f){return o.isValid(l)?parseInt(l,10):f},t.getCapacity=function(l,f,g){if(!o.isValid(l))throw new Error("Invalid QR Code version");typeof g>"u"&&(g=r.BYTE);const y=s.getSymbolTotalCodewords(l),N=n.getTotalCodewordsCount(l,f),j=(y-N)*8;if(g===r.MIXED)return j;const v=j-x(g,l);switch(g){case r.NUMERIC:return Math.floor(v/10*3);case r.ALPHANUMERIC:return Math.floor(v/11*2);case r.KANJI:return Math.floor(v/13);case r.BYTE:default:return Math.floor(v/8)}},t.getBestVersionForData=function(l,f){let g;const y=a.from(f,a.M);if(Array.isArray(l)){if(l.length>1)return u(l,y);if(l.length===0)return 1;g=l[0]}else g=l;return d(g.mode,g.getLength(),y)},t.getEncodedBits=function(l){if(!o.isValid(l)||l<7)throw new Error("Invalid QR Code version");let f=l<<12;for(;s.getBCHDigit(f)-c>=0;)f^=i<<s.getBCHDigit(f)-c;return l<<12|f}})(As)),As}var Ps={},Ha;function Jm(){if(Ha)return Ps;Ha=1;const t=mt(),s=1335,n=21522,a=t.getBCHDigit(s);return Ps.getEncodedBits=function(o,i){const c=o.bit<<3|i;let d=c<<10;for(;t.getBCHDigit(d)-a>=0;)d^=s<<t.getBCHDigit(d)-a;return(c<<10|d)^n},Ps}var Ts={},Rs,Wa;function Ym(){if(Wa)return Rs;Wa=1;const t=ht();function s(n){this.mode=t.NUMERIC,this.data=n.toString()}return s.getBitsLength=function(a){return 10*Math.floor(a/3)+(a%3?a%3*3+1:0)},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(a){let r,o,i;for(r=0;r+3<=this.data.length;r+=3)o=this.data.substr(r,3),i=parseInt(o,10),a.put(i,10);const c=this.data.length-r;c>0&&(o=this.data.substr(r),i=parseInt(o,10),a.put(i,c*3+1))},Rs=s,Rs}var Os,Ja;function Qm(){if(Ja)return Os;Ja=1;const t=ht(),s=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":"];function n(a){this.mode=t.ALPHANUMERIC,this.data=a}return n.getBitsLength=function(r){return 11*Math.floor(r/2)+6*(r%2)},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(r){let o;for(o=0;o+2<=this.data.length;o+=2){let i=s.indexOf(this.data[o])*45;i+=s.indexOf(this.data[o+1]),r.put(i,11)}this.data.length%2&&r.put(s.indexOf(this.data[o]),6)},Os=n,Os}var Ds,Ya;function Xm(){if(Ya)return Ds;Ya=1;const t=ht();function s(n){this.mode=t.BYTE,typeof n=="string"?this.data=new TextEncoder().encode(n):this.data=new Uint8Array(n)}return s.getBitsLength=function(a){return a*8},s.prototype.getLength=function(){return this.data.length},s.prototype.getBitsLength=function(){return s.getBitsLength(this.data.length)},s.prototype.write=function(n){for(let a=0,r=this.data.length;a<r;a++)n.put(this.data[a],8)},Ds=s,Ds}var Ls,Qa;function Zm(){if(Qa)return Ls;Qa=1;const t=ht(),s=mt();function n(a){this.mode=t.KANJI,this.data=a}return n.getBitsLength=function(r){return r*13},n.prototype.getLength=function(){return this.data.length},n.prototype.getBitsLength=function(){return n.getBitsLength(this.data.length)},n.prototype.write=function(a){let r;for(r=0;r<this.data.length;r++){let o=s.toSJIS(this.data[r]);if(o>=33088&&o<=40956)o-=33088;else if(o>=57408&&o<=60351)o-=49472;else throw new Error("Invalid SJIS character: "+this.data[r]+`
11
- Make sure your charset is UTF-8`);o=(o>>>8&255)*192+(o&255),a.put(o,13)}},Ls=n,Ls}var zs={exports:{}},Xa;function eh(){return Xa||(Xa=1,(function(t){var s={single_source_shortest_paths:function(n,a,r){var o={},i={};i[a]=0;var c=s.PriorityQueue.make();c.push(a,0);for(var d,x,h,u,p,l,f,g,y;!c.empty();){d=c.pop(),x=d.value,u=d.cost,p=n[x]||{};for(h in p)p.hasOwnProperty(h)&&(l=p[h],f=u+l,g=i[h],y=typeof i[h]>"u",(y||g>f)&&(i[h]=f,c.push(h,f),o[h]=x))}if(typeof r<"u"&&typeof i[r]>"u"){var N=["Could not find a path from ",a," to ",r,"."].join("");throw new Error(N)}return o},extract_shortest_path_from_predecessor_list:function(n,a){for(var r=[],o=a;o;)r.push(o),n[o],o=n[o];return r.reverse(),r},find_path:function(n,a,r){var o=s.single_source_shortest_paths(n,a,r);return s.extract_shortest_path_from_predecessor_list(o,r)},PriorityQueue:{make:function(n){var a=s.PriorityQueue,r={},o;n=n||{};for(o in a)a.hasOwnProperty(o)&&(r[o]=a[o]);return r.queue=[],r.sorter=n.sorter||a.default_sorter,r},default_sorter:function(n,a){return n.cost-a.cost},push:function(n,a){var r={value:n,cost:a};this.queue.push(r),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t.exports=s})(zs)),zs.exports}var Za;function th(){return Za||(Za=1,(function(t){const s=ht(),n=Ym(),a=Qm(),r=Xm(),o=Zm(),i=Zo(),c=mt(),d=eh();function x(N){return unescape(encodeURIComponent(N)).length}function h(N,j,v){const k=[];let R;for(;(R=N.exec(v))!==null;)k.push({data:R[0],index:R.index,mode:j,length:R[0].length});return k}function u(N){const j=h(i.NUMERIC,s.NUMERIC,N),v=h(i.ALPHANUMERIC,s.ALPHANUMERIC,N);let k,R;return c.isKanjiModeEnabled()?(k=h(i.BYTE,s.BYTE,N),R=h(i.KANJI,s.KANJI,N)):(k=h(i.BYTE_KANJI,s.BYTE,N),R=[]),j.concat(v,k,R).sort(function(S,O){return S.index-O.index}).map(function(S){return{data:S.data,mode:S.mode,length:S.length}})}function p(N,j){switch(j){case s.NUMERIC:return n.getBitsLength(N);case s.ALPHANUMERIC:return a.getBitsLength(N);case s.KANJI:return o.getBitsLength(N);case s.BYTE:return r.getBitsLength(N)}}function l(N){return N.reduce(function(j,v){const k=j.length-1>=0?j[j.length-1]:null;return k&&k.mode===v.mode?(j[j.length-1].data+=v.data,j):(j.push(v),j)},[])}function f(N){const j=[];for(let v=0;v<N.length;v++){const k=N[v];switch(k.mode){case s.NUMERIC:j.push([k,{data:k.data,mode:s.ALPHANUMERIC,length:k.length},{data:k.data,mode:s.BYTE,length:k.length}]);break;case s.ALPHANUMERIC:j.push([k,{data:k.data,mode:s.BYTE,length:k.length}]);break;case s.KANJI:j.push([k,{data:k.data,mode:s.BYTE,length:x(k.data)}]);break;case s.BYTE:j.push([{data:k.data,mode:s.BYTE,length:x(k.data)}])}}return j}function g(N,j){const v={},k={start:{}};let R=["start"];for(let L=0;L<N.length;L++){const S=N[L],O=[];for(let w=0;w<S.length;w++){const M=S[w],E=""+L+w;O.push(E),v[E]={node:M,lastCount:0},k[E]={};for(let I=0;I<R.length;I++){const B=R[I];v[B]&&v[B].node.mode===M.mode?(k[B][E]=p(v[B].lastCount+M.length,M.mode)-p(v[B].lastCount,M.mode),v[B].lastCount+=M.length):(v[B]&&(v[B].lastCount=M.length),k[B][E]=p(M.length,M.mode)+4+s.getCharCountIndicator(M.mode,j))}}R=O}for(let L=0;L<R.length;L++)k[R[L]].end=0;return{map:k,table:v}}function y(N,j){let v;const k=s.getBestModeForData(N);if(v=s.from(j,k),v!==s.BYTE&&v.bit<k.bit)throw new Error('"'+N+'" cannot be encoded with mode '+s.toString(v)+`.
12
- Suggested mode is: `+s.toString(k));switch(v===s.KANJI&&!c.isKanjiModeEnabled()&&(v=s.BYTE),v){case s.NUMERIC:return new n(N);case s.ALPHANUMERIC:return new a(N);case s.KANJI:return new o(N);case s.BYTE:return new r(N)}}t.fromArray=function(j){return j.reduce(function(v,k){return typeof k=="string"?v.push(y(k,null)):k.data&&v.push(y(k.data,k.mode)),v},[])},t.fromString=function(j,v){const k=u(j,c.isKanjiModeEnabled()),R=f(k),L=g(R,v),S=d.find_path(L.map,"start","end"),O=[];for(let w=1;w<S.length-1;w++)O.push(L.table[S[w]].node);return t.fromArray(l(O))},t.rawSplit=function(j){return t.fromArray(u(j,c.isKanjiModeEnabled()))}})(Ts)),Ts}var er;function sh(){if(er)return vs;er=1;const t=mt(),s=_n(),n=Fm(),a=Um(),r=$m(),o=Vm(),i=Km(),c=Qo(),d=Hm(),x=Wm(),h=Jm(),u=ht(),p=th();function l(L,S){const O=L.size,w=o.getPositions(S);for(let M=0;M<w.length;M++){const E=w[M][0],I=w[M][1];for(let B=-1;B<=7;B++)if(!(E+B<=-1||O<=E+B))for(let C=-1;C<=7;C++)I+C<=-1||O<=I+C||(B>=0&&B<=6&&(C===0||C===6)||C>=0&&C<=6&&(B===0||B===6)||B>=2&&B<=4&&C>=2&&C<=4?L.set(E+B,I+C,!0,!0):L.set(E+B,I+C,!1,!0))}}function f(L){const S=L.size;for(let O=8;O<S-8;O++){const w=O%2===0;L.set(O,6,w,!0),L.set(6,O,w,!0)}}function g(L,S){const O=r.getPositions(S);for(let w=0;w<O.length;w++){const M=O[w][0],E=O[w][1];for(let I=-2;I<=2;I++)for(let B=-2;B<=2;B++)I===-2||I===2||B===-2||B===2||I===0&&B===0?L.set(M+I,E+B,!0,!0):L.set(M+I,E+B,!1,!0)}}function y(L,S){const O=L.size,w=x.getEncodedBits(S);let M,E,I;for(let B=0;B<18;B++)M=Math.floor(B/3),E=B%3+O-8-3,I=(w>>B&1)===1,L.set(M,E,I,!0),L.set(E,M,I,!0)}function N(L,S,O){const w=L.size,M=h.getEncodedBits(S,O);let E,I;for(E=0;E<15;E++)I=(M>>E&1)===1,E<6?L.set(E,8,I,!0):E<8?L.set(E+1,8,I,!0):L.set(w-15+E,8,I,!0),E<8?L.set(8,w-E-1,I,!0):E<9?L.set(8,15-E-1+1,I,!0):L.set(8,15-E-1,I,!0);L.set(w-8,8,1,!0)}function j(L,S){const O=L.size;let w=-1,M=O-1,E=7,I=0;for(let B=O-1;B>0;B-=2)for(B===6&&B--;;){for(let C=0;C<2;C++)if(!L.isReserved(M,B-C)){let _=!1;I<S.length&&(_=(S[I]>>>E&1)===1),L.set(M,B-C,_),E--,E===-1&&(I++,E=7)}if(M+=w,M<0||O<=M){M-=w,w=-w;break}}}function v(L,S,O){const w=new n;O.forEach(function(C){w.put(C.mode.bit,4),w.put(C.getLength(),u.getCharCountIndicator(C.mode,L)),C.write(w)});const M=t.getSymbolTotalCodewords(L),E=c.getTotalCodewordsCount(L,S),I=(M-E)*8;for(w.getLengthInBits()+4<=I&&w.put(0,4);w.getLengthInBits()%8!==0;)w.putBit(0);const B=(I-w.getLengthInBits())/8;for(let C=0;C<B;C++)w.put(C%2?17:236,8);return k(w,L,S)}function k(L,S,O){const w=t.getSymbolTotalCodewords(S),M=c.getTotalCodewordsCount(S,O),E=w-M,I=c.getBlocksCount(S,O),B=w%I,C=I-B,_=Math.floor(w/I),V=Math.floor(E/I),H=V+1,$=_-V,re=new d($);let D=0;const q=new Array(I),P=new Array(I);let Y=0;const ae=new Uint8Array(L.buffer);for(let ye=0;ye<I;ye++){const we=ye<C?V:H;q[ye]=ae.slice(D,D+we),P[ye]=re.encode(q[ye]),D+=we,Y=Math.max(Y,we)}const le=new Uint8Array(w);let z=0,ue,me;for(ue=0;ue<Y;ue++)for(me=0;me<I;me++)ue<q[me].length&&(le[z++]=q[me][ue]);for(ue=0;ue<$;ue++)for(me=0;me<I;me++)le[z++]=P[me][ue];return le}function R(L,S,O,w){let M;if(Array.isArray(L))M=p.fromArray(L);else if(typeof L=="string"){let _=S;if(!_){const V=p.rawSplit(L);_=x.getBestVersionForData(V,O)}M=p.fromString(L,_||40)}else throw new Error("Invalid data");const E=x.getBestVersionForData(M,O);if(!E)throw new Error("The amount of data is too big to be stored in a QR Code");if(!S)S=E;else if(S<E)throw new Error(`
13
- The chosen QR Code version cannot contain this amount of data.
14
- Minimum version required to store current data is: `+E+`.
15
- `);const I=v(S,O,M),B=t.getSymbolSize(S),C=new a(B);return l(C,S),f(C),g(C,S),N(C,O,0),S>=7&&y(C,S),j(C,I),isNaN(w)&&(w=i.getBestMask(C,N.bind(null,C,O))),i.applyMask(w,C),N(C,O,w),{modules:C,version:S,errorCorrectionLevel:O,maskPattern:w,segments:M}}return vs.create=function(S,O){if(typeof S>"u"||S==="")throw new Error("No input text");let w=s.M,M,E;return typeof O<"u"&&(w=s.from(O.errorCorrectionLevel,s.M),M=x.from(O.version),E=i.from(O.maskPattern),O.toSJISFunc&&t.setToSJISFunction(O.toSJISFunc)),R(S,M,w,E)},vs}var Bs={},_s={},tr;function ei(){return tr||(tr=1,(function(t){function s(n){if(typeof n=="number"&&(n=n.toString()),typeof n!="string")throw new Error("Color should be defined as hex string");let a=n.slice().replace("#","").split("");if(a.length<3||a.length===5||a.length>8)throw new Error("Invalid hex color: "+n);(a.length===3||a.length===4)&&(a=Array.prototype.concat.apply([],a.map(function(o){return[o,o]}))),a.length===6&&a.push("F","F");const r=parseInt(a.join(""),16);return{r:r>>24&255,g:r>>16&255,b:r>>8&255,a:r&255,hex:"#"+a.slice(0,6).join("")}}t.getOptions=function(a){a||(a={}),a.color||(a.color={});const r=typeof a.margin>"u"||a.margin===null||a.margin<0?4:a.margin,o=a.width&&a.width>=21?a.width:void 0,i=a.scale||4;return{width:o,scale:o?4:i,margin:r,color:{dark:s(a.color.dark||"#000000ff"),light:s(a.color.light||"#ffffffff")},type:a.type,rendererOpts:a.rendererOpts||{}}},t.getScale=function(a,r){return r.width&&r.width>=a+r.margin*2?r.width/(a+r.margin*2):r.scale},t.getImageWidth=function(a,r){const o=t.getScale(a,r);return Math.floor((a+r.margin*2)*o)},t.qrToImageData=function(a,r,o){const i=r.modules.size,c=r.modules.data,d=t.getScale(i,o),x=Math.floor((i+o.margin*2)*d),h=o.margin*d,u=[o.color.light,o.color.dark];for(let p=0;p<x;p++)for(let l=0;l<x;l++){let f=(p*x+l)*4,g=o.color.light;if(p>=h&&l>=h&&p<x-h&&l<x-h){const y=Math.floor((p-h)/d),N=Math.floor((l-h)/d);g=u[c[y*i+N]?1:0]}a[f++]=g.r,a[f++]=g.g,a[f++]=g.b,a[f]=g.a}}})(_s)),_s}var sr;function nh(){return sr||(sr=1,(function(t){const s=ei();function n(r,o,i){r.clearRect(0,0,o.width,o.height),o.style||(o.style={}),o.height=i,o.width=i,o.style.height=i+"px",o.style.width=i+"px"}function a(){try{return document.createElement("canvas")}catch{throw new Error("You need to specify a canvas element")}}t.render=function(o,i,c){let d=c,x=i;typeof d>"u"&&(!i||!i.getContext)&&(d=i,i=void 0),i||(x=a()),d=s.getOptions(d);const h=s.getImageWidth(o.modules.size,d),u=x.getContext("2d"),p=u.createImageData(h,h);return s.qrToImageData(p.data,o,d),n(u,x,h),u.putImageData(p,0,0),x},t.renderToDataURL=function(o,i,c){let d=c;typeof d>"u"&&(!i||!i.getContext)&&(d=i,i=void 0),d||(d={});const x=t.render(o,i,d),h=d.type||"image/png",u=d.rendererOpts||{};return x.toDataURL(h,u.quality)}})(Bs)),Bs}var Fs={},nr;function ah(){if(nr)return Fs;nr=1;const t=ei();function s(r,o){const i=r.a/255,c=o+'="'+r.hex+'"';return i<1?c+" "+o+'-opacity="'+i.toFixed(2).slice(1)+'"':c}function n(r,o,i){let c=r+o;return typeof i<"u"&&(c+=" "+i),c}function a(r,o,i){let c="",d=0,x=!1,h=0;for(let u=0;u<r.length;u++){const p=Math.floor(u%o),l=Math.floor(u/o);!p&&!x&&(x=!0),r[u]?(h++,u>0&&p>0&&r[u-1]||(c+=x?n("M",p+i,.5+l+i):n("m",d,0),d=0,x=!1),p+1<o&&r[u+1]||(c+=n("h",h),h=0)):d++}return c}return Fs.render=function(o,i,c){const d=t.getOptions(i),x=o.modules.size,h=o.modules.data,u=x+d.margin*2,p=d.color.light.a?"<path "+s(d.color.light,"fill")+' d="M0 0h'+u+"v"+u+'H0z"/>':"",l="<path "+s(d.color.dark,"stroke")+' d="'+a(h,x,d.margin)+'"/>',f='viewBox="0 0 '+u+" "+u+'"',y='<svg xmlns="http://www.w3.org/2000/svg" '+(d.width?'width="'+d.width+'" height="'+d.width+'" ':"")+f+' shape-rendering="crispEdges">'+p+l+`</svg>
16
- `;return typeof c=="function"&&c(null,y),y},Fs}var ar;function rh(){if(ar)return gt;ar=1;const t=_m(),s=sh(),n=nh(),a=ah();function r(o,i,c,d,x){const h=[].slice.call(arguments,1),u=h.length,p=typeof h[u-1]=="function";if(!p&&!t())throw new Error("Callback required as last argument");if(p){if(u<2)throw new Error("Too few arguments provided");u===2?(x=c,c=i,i=d=void 0):u===3&&(i.getContext&&typeof x>"u"?(x=d,d=void 0):(x=d,d=c,c=i,i=void 0))}else{if(u<1)throw new Error("Too few arguments provided");return u===1?(c=i,i=d=void 0):u===2&&!i.getContext&&(d=c,c=i,i=void 0),new Promise(function(l,f){try{const g=s.create(c,d);l(o(g,i,d))}catch(g){f(g)}})}try{const l=s.create(c,d);x(null,o(l,i,d))}catch(l){x(l)}}return gt.create=s.create,gt.toCanvas=r.bind(null,n.render),gt.toDataURL=r.bind(null,n.renderToDataURL),gt.toString=r.bind(null,function(o,i,c){return a.render(o,c)}),gt}var oh=rh();const ih=Yl(oh);function lh(){return e.jsxs("div",{className:"space-y-10",children:[e.jsx(ch,{}),e.jsx(dh,{}),e.jsx(hh,{})]})}function ch(){const{t}=U(),[s,n]=m.useState(null),[a,r]=m.useState(null),[o,i]=m.useState(!1),[c,d]=m.useState(null),[x,h]=m.useState(null),[u,p]=m.useState(!1),l=s?.pairingExpiresAt;m.useEffect(()=>{if(!l){h(null);return}const N=()=>h(Math.max(0,Math.ceil((l-Date.now())/1e3)));N();const j=setInterval(N,1e3);return()=>clearInterval(j)},[l]);const f=N=>{navigator.clipboard.writeText(N).then(()=>{p(!0),setTimeout(()=>p(!1),1500)})};m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(N=>{n(N),(N.pairing||N.devices.length>0)&&d(null)})),[]),m.useEffect(()=>{const N=s?.inviteUri;if(!N){r(null);return}ih.toDataURL(N,{width:320,margin:1}).then(r).catch(()=>{})},[s?.inviteUri]);const g=async()=>{i(!0),d(null);const N=await window.electronAPI.pair.start();i(!1),N.ok||d(N.error??t("Failed to start pairing"))},y=s?.devices??[];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"phone.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Allow connections")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Let your phone or another EnsoCode desktop connect to this computer. Keep this app running.")})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-2",children:s?.pairing?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.pair.cancel()},children:t("Cancel pairing")}):e.jsxs(A,{variant:"outline",size:"sm",disabled:o,onClick:()=>{g()},children:[o?e.jsx(Te,{className:"mr-1.5 h-4 w-4 animate-spin"}):e.jsx(rn,{className:"mr-1.5 h-4 w-4"}),t("Generate pairing code")]})})]}),s&&!s.secureStorage&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(_e,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),c&&e.jsx("p",{className:"text-destructive text-xs",children:c}),s?.pairing&&e.jsxs("div",{className:"space-y-3 rounded-md border border-dashed px-3 py-6",children:[e.jsxs("div",{className:"text-center",children:[a?e.jsx("img",{src:a,alt:t("Pairing QR code"),className:"mx-auto h-52 w-52"}):e.jsx(Te,{className:"mx-auto h-5 w-5 animate-spin text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("Scan with your phone camera")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Scanning opens the app and pairs it. To keep it handy, add it to your home screen.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("On another EnsoCode desktop, paste the link below into Settings → Devices → Connect to a node.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:x===null?t("The code expires in 60 seconds and can only be used once."):x>0?t("Expires in {{seconds}}s · single use",{seconds:x}):t("Code expired")})]}),s.inviteUri&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("code",{className:"min-w-0 flex-1 truncate rounded bg-muted px-2 py-1.5 font-mono text-[11px] text-muted-foreground",children:s.inviteUri}),e.jsxs(A,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>f(s.inviteUri),children:[u?e.jsx(go,{className:"mr-1.5 h-3.5 w-3.5"}):e.jsx(lo,{className:"mr-1.5 h-3.5 w-3.5"}),t(u?"Copied":"Copy")]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Paired devices")}),y.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(rn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No paired devices")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Generate a pairing code to let a phone or another desktop connect.")})]}):e.jsx("div",{className:"space-y-1",children:y.map(N=>e.jsx(uh,{device:N},N.pairId))})]})]})}function dh(){const{t}=U(),s=Ut(i=>i.nodes),n=Ut(i=>i.secureStorage),a=Ut(i=>i.refresh),[r,o]=m.useState(!1);return m.useEffect(()=>Ut.getState().bind(),[]),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Connect to a node")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Browse and drive conversations on another EnsoCode desktop. Its agent, keys and history stay there.")})]}),e.jsxs(A,{variant:"outline",size:"sm",className:"shrink-0",onClick:()=>o(!0),children:[e.jsx(Ee,{className:"mr-1.5 h-4 w-4"}),t("Connect to a node")]})]}),!n&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-dashed px-3 py-2 text-xs",children:[e.jsx(_e,{className:"mt-0.5 h-4 w-4 shrink-0 text-destructive"}),e.jsx("span",{className:"text-muted-foreground",children:t("Secure storage is unavailable on this system, so pairing keys are stored unencrypted.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Connected nodes")}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(En,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No connected nodes")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Each connecting computer needs its own pairing code from the other desktop.")})]}):e.jsx("div",{className:"space-y-1",children:s.map(i=>e.jsx(mh,{node:i,onChanged:()=>{a()}},i.nodeId))})]}),e.jsx(Ql,{open:r,onOpenChange:o,switchOnSuccess:!1})]})}function ti({transport:t,rttMs:s}){const{t:n}=U(),a=t==="direct",r=Bm(s);return e.jsxs("span",{className:K("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none",a?"bg-emerald-500/15 text-emerald-600":"bg-muted text-muted-foreground"),children:[n(a?"Direct link":"Via relay"),r?` · ${r}`:""]})}function uh({device:t}){const{t:s}=U(),[n,a]=m.useState(null),r=async()=>{n!==null&&(n.trim()&&n.trim()!==t.deviceName&&await window.electronAPI.pair.rename(t.pairId,n),a(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:K("h-2 w-2 shrink-0 rounded-full",t.phoneOnline?"bg-emerald-500":t.connected?"bg-amber-500":"bg-muted-foreground/40")}),n===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.deviceName}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.phoneOnline?s("Online"):t.connected?s("Waiting for device"):s("Offline")}),t.phoneOnline&&e.jsx(ti,{transport:t.transport,rttMs:t.rttMs}),e.jsx("button",{type:"button",title:s("Click to switch: view-only devices cannot send, approve or stop."),onClick:()=>{window.electronAPI.pair.setScope(t.pairId,t.scope==="read"?"operate":"read")},className:K("shrink-0 rounded px-1.5 py-0.5 text-[10px] leading-none transition-colors",t.scope==="read"?"bg-amber-500/15 text-amber-600 hover:bg-amber-500/25":"bg-muted text-muted-foreground hover:bg-accent"),children:t.scope==="read"?s("View only"):s("Can operate")})]}):e.jsx(J,{value:n,autoFocus:!0,onChange:o=>a(o.target.value),onBlur:()=>{r()},onKeyDown:o=>{o.key==="Enter"&&r(),o.key==="Escape"&&a(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:s("Rename"),onClick:()=>a(t.deviceName),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.pair.revoke(t.pairId)},children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]})}function mh({node:t,onChanged:s}){const{t:n}=U(),[a,r]=m.useState(null),o=async()=>{a!==null&&(a.trim()&&a.trim()!==t.label&&(await window.electronAPI.nodes.rename(t.nodeId,a),s()),r(null))};return e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx(Xl,{node:t}),a===null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"truncate font-medium text-sm",children:t.label}),t.hostname&&t.hostname!==t.label&&e.jsx("span",{className:"shrink-0 truncate font-mono text-[10px] text-muted-foreground",children:t.hostname}),e.jsx("span",{className:"shrink-0 text-muted-foreground text-xs",children:t.hostOnline?n("Online"):t.connected?n("Remote desktop is offline"):n("Offline")}),t.hostOnline&&e.jsx(ti,{transport:t.transport,rttMs:t.rttMs})]}):e.jsx(J,{value:a,autoFocus:!0,onChange:i=>r(i.target.value),onBlur:()=>{o()},onKeyDown:i=>{i.key==="Enter"&&o(),i.key==="Escape"&&r(null)},className:"h-7 text-sm"})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground",title:n("Rename"),onClick:()=>r(t.label),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",title:n("Disconnect"),onClick:()=>{window.electronAPI.nodes.remove(t.nodeId).then(s)},children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]})}function hh(){const{t}=U(),[s,n]=m.useState(null),[a,r]=m.useState(null);m.useEffect(()=>(window.electronAPI.pair.status().then(n),window.electronAPI.pair.onStatusChanged(n)),[]);const o=async()=>{a!==null&&(n(await window.electronAPI.pair.setRelayUrl(a)),r(null))};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"font-medium text-sm",children:t("Relay server")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("The relay only forwards encrypted frames and cannot read your messages.")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:a??s?.relayUrl??"",onChange:i=>r(i.target.value),placeholder:"https://relay.example.com",className:"font-mono text-xs"}),a===null?e.jsx(A,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0 text-muted-foreground",onClick:()=>r(s?.relayUrl??""),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}):e.jsxs(A,{size:"sm",className:"shrink-0",onClick:()=>{o()},children:[e.jsx(go,{className:"mr-1.5 h-3.5 w-3.5"}),t("Save")]})]})]})})}function xh({onOpenBots:t}){const{t:s}=U(),n=b(i=>i.botModeEnabled),a=b(i=>i.setBotModeEnabled),r=b(i=>i.scratchSessionsEnabled),o=b(i=>i.setScratchSessionsEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:s("Experimental")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Features still being tested. They may change or be removed.")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Pe,{rowId:"experimental.botMode",title:s("Bot mode"),description:s("Adds a Code | Bot switch to the sidebar. Create members with their own persona, model and tools, and chat with them alone or in groups."),checked:n,onChange:a}),n&&e.jsx(A,{variant:"outline",size:"sm",onClick:t,children:s("Bot mode settings")}),e.jsx(Pe,{rowId:"experimental.scratchSessions",title:s("Temporary chats"),description:s("Chats that are not tied to a project. Tools follow your global settings."),checked:r,onChange:o})]})]})}function ph({instruction:t,onClose:s}){const{t:n}=U(),a=b(S=>S.addInstructions),r=b(S=>S.updateInstruction),o=t==="new",i=o||!t?null:t,[c,d]=m.useState(""),[x,h]=m.useState(""),[u,p]=m.useState(!1),[l,f]=m.useState(!1),[g,y]=m.useState(null),[N,j]=m.useState(!1),[v,k]=m.useState(!1);m.useEffect(()=>{if(t){if(t==="new"){d(""),h(""),j(!1),y(null),k(!1),p(!1);return}d(t.name),j(!1),y(null),k(!1),p(!0),window.electronAPI.instructions.read(t.id,t.local,t.sourcePath).then(S=>{S.ok?h(S.content):(h(""),y(S.error??n("Failed to read content")))}).finally(()=>p(!1))}},[t,n]);const R=!!(i&&!i.local&&i.sourcePath),L=async()=>{if(!t||!c.trim())return;if(f(!0),o){const O=crypto.randomUUID(),w=await window.electronAPI.instructions.write(O,x);if(!w.ok){f(!1),y(n("Failed to save"));return}const M=a([{id:O,name:c.trim(),source:"Manual",local:!0,bytes:w.bytes,enabled:!0}]);if(f(!1),M===0){window.electronAPI.instructions.delete(O),y(n("An instruction with this name already exists"));return}s();return}if(!i){f(!1);return}if(R&&v&&i.sourcePath){const O=await window.electronAPI.instructions.writeSource(i.id,i.sourcePath,x);if(f(!1),!O.ok){y(O.error??n("Failed to save"));return}r(i.id,{name:c.trim(),bytes:O.bytes}),s();return}const S=await window.electronAPI.instructions.write(i.id,x);if(f(!1),!S.ok){y(n("Failed to save"));return}r(i.id,{name:c.trim(),local:!0,bytes:S.bytes}),s()};return e.jsx(pe,{open:t!==null,onOpenChange:S=>!S&&s(),children:e.jsxs(fe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add Instruction":"Edit Instruction")})}),e.jsxs(Se,{className:"space-y-4",children:[o?null:R?e.jsxs("div",{className:K("w-full rounded-md border px-3 py-2.5 transition-colors",v?"border-destructive/32 bg-destructive/8":"border-amber-500/32 bg-amber-500/8"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[v?e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0 text-destructive"}):e.jsx(Jt,{className:"h-3.5 w-3.5 shrink-0 text-amber-600 dark:text-amber-500"}),e.jsx("span",{className:"font-medium text-xs",children:n("Write back to original file")})]}),e.jsx(oe,{checked:v,onCheckedChange:k})]}),e.jsx("p",{className:"mt-1.5 pl-5.5 text-muted-foreground text-xs leading-relaxed",children:v?n("Saving overwrites {{path}} directly — {{source}} will pick up the change.",{path:i?.sourcePath??"",source:i?.source??""}):n("Saving creates a local copy — {{path}} is left untouched, and this entry stops following its updates.",{path:i?.sourcePath??""})})]}):e.jsxs("div",{className:"flex w-full items-start gap-2 rounded-md border bg-muted/50 px-3 py-2",children:[e.jsx(Jt,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground text-xs leading-relaxed",children:n("Local copy — edits stay in this app.")})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Name")}),e.jsx(J,{value:c,onChange:S=>d(S.target.value)})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Content")}),u?e.jsxs("div",{className:"flex w-full items-center justify-center gap-2 rounded-md border py-12",children:[e.jsx(Te,{className:"h-4 w-4 animate-spin text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n("Loading...")})]}):e.jsx(Xe,{value:x,onChange:S=>{h(S.target.value),j(!0)},rows:16,className:"font-mono text-xs"})]}),g&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),g]})]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsxs(A,{size:"sm",variant:R&&v?"destructive":"default",disabled:!c.trim()||u||l,onClick:L,children:[l&&e.jsx(Te,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),n(R?v?"Overwrite original":N?"Save as local copy":"Save":"Save")]})]})]})})}const rr=t=>t<1024?`${t} B`:`${(t/1024).toFixed(1)} KB`;function fh(){const{t}=U(),s=b(u=>u.instructions),n=b(u=>u.updateInstruction),a=b(u=>u.removeInstruction),[r,o]=m.useState(!1),[i,c]=m.useState(null),d=s.map(u=>u.id),x=is(d,u=>window.electronAPI.assets.instructionOccupancy(u)),h=as(s.filter(u=>u.enabled).map(u=>u.id),x.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"instructions.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Instruction Files"),e.jsx(os,{tokens:h}),e.jsx(qe,{})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Global CLAUDE.md / AGENTS.md style files from local AI tools")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only one file is active at a time; enabling one disables the others")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>o(!0),children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>c("new"),children:[e.jsx(Ee,{className:"mr-1.5 h-4 w-4"}),t("Add instruction")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Rn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No instruction files yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import instruction files from local apps or add one manually to get started")})]}):e.jsx("div",{className:"space-y-1",children:s.map(u=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`instructions.${u.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:K("shrink-0 font-medium text-sm",!u.enabled&&"text-muted-foreground line-through"),children:u.name}),e.jsx(Z,{variant:"secondary",className:"shrink-0 text-[11px]",children:u.source}),!u.local&&e.jsxs(Z,{variant:"outline",className:"shrink-0 gap-1 text-[11px]",children:[e.jsx(Fo,{className:"h-3 w-3"}),t("Linked")]}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:u.local?`${t("Local copy")} · ${rr(u.bytes)}`:`${u.sourcePath} · ${rr(u.bytes)}`})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(rs,{row:x.rows[u.id],pending:x.pending&&!x.rows[u.id]}),e.jsx(oe,{checked:u.enabled,onCheckedChange:p=>n(u.id,{enabled:p})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>c(u),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>a(u.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]},u.id))}),e.jsx(On,{kind:"instruction",open:r,onOpenChange:o}),e.jsx(ph,{instruction:i,onClose:()=>c(null)})]})}function gh(){const{t}=U();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{"data-settings-row":"shortcuts.root",children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Shortcuts")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Click a shortcut to rebind it. Backspace removes it; Esc cancels.")})]}),e.jsx(jh,{})]})}function jh(){const{t}=U(),s=b(h=>h.keybindings),n=b(h=>h.setKeybinding),a=b(h=>h.resetKeybinding),[r,o]=m.useState(null),[i,c]=m.useState(null),d=Zl(s),x=h=>{if(h.preventDefault(),h.stopPropagation(),!r)return;if(h.key==="Escape"){o(null),c(null);return}if(h.key==="Backspace"||h.key==="Delete"){n(r,""),o(null),c(null);return}const u=sc(h,{allowBare:r==="send-message"||r==="voice-hold"});if(!u)return;const p=ca.find(l=>l!==r&&d[l]===u);if(p){c(p);return}u===nc[r]?a(r):n(r,u),o(null),c(null)};return e.jsx("div",{className:"divide-y rounded-md border",children:ca.map(h=>{const u=r===h,p=s[h]!==void 0,l=d[h];return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm",children:t(ua[h])}),da[h]&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t(da[h])})]}),u&&i&&e.jsx("span",{className:"text-xs text-destructive",children:t('Already used by "{{label}}"',{label:t(ua[i])})}),l&&!u&&e.jsx("button",{type:"button",title:t("Remove shortcut"),onClick:()=>n(h,""),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(Ct,{className:"h-3.5 w-3.5"})}),p&&!u&&e.jsx("button",{type:"button",title:t("Reset to default"),onClick:()=>a(h),className:"rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(co,{className:"h-3.5 w-3.5"})}),e.jsx("button",{type:"button",onClick:()=>{o(h),c(null)},onKeyDown:u?x:void 0,onBlur:()=>{u&&(o(null),c(null))},autoFocus:u,className:K("rounded-md px-1 py-0.5 transition-colors",u?"ring-1 ring-ring":"hover:bg-muted"),children:u?e.jsx("span",{className:"text-xs text-muted-foreground",children:t("Press shortcut…")}):l?e.jsx(ec,{children:tc(l)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:t("No shortcut")})})]},h)})})}function vh(t){return t.serverId??t.serverName}function si(t,s){const n={...t};return s.serverId&&delete n[s.serverName],n[vh(s)]={state:s.state,...s.toolCount!==void 0?{toolCount:s.toolCount}:{},...s.error?{error:s.error}:{}},n}function bh(t){return t.reduce((s,n)=>si(s,n),{})}function yh(t,s){return{...t,[s]:{state:"connecting"}}}function wh(t,s,n){return{...t,[s]:{state:"error",...n?{error:n}:{}}}}const Us=(t,s)=>{const n={...t};return delete n[s],n},dt=ac()((t,s)=>({statuses:{},authorized:{},pending:{},bind:()=>(window.electronAPI.mcp.authState().then(n=>t({authorized:n})).catch(()=>{}),window.electronAPI.mcp.statusSnapshot().then(n=>t({statuses:{...s().statuses,...bh(n)}})).catch(()=>{}),window.electronAPI.mcp.onStatus(n=>{if(n.type==="mcp-status-cleared"){t({statuses:{}});return}t({statuses:si(s().statuses,n)}),window.electronAPI.mcp.authState().then(a=>t({authorized:a})).catch(()=>{})})),authorize:async n=>{t({statuses:yh(s().statuses,n),pending:{...s().pending,[n]:!0}});let a;try{a=await window.electronAPI.mcp.authorize(n)}catch(r){a={ok:!1,error:r instanceof Error?r.message:String(r)}}t({pending:Us(s().pending,n),...a.ok?{authorized:{...s().authorized,[n]:!0}}:{statuses:wh(s().statuses,n,a.error)}})},revoke:async n=>{await window.electronAPI.mcp.revoke(n),t({authorized:Us(s().authorized,n),statuses:Us(s().statuses,n)})}})),He=t=>typeof t=="string"?t.trim():"",Nh=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[],ni=t=>{if(!t||typeof t!="object")return{};const s={};for(const[n,a]of Object.entries(t))typeof a=="string"&&(s[n]=a);return s};function kh(t){const s=ni(t);return delete s[""],Object.keys(s).length>0?s:void 0}function or(t){const s={};for(const n of t.split(`
17
- `)){const a=n.indexOf(":"),r=a>0?n.slice(0,a).trim():"";r&&(s[r]=n.slice(a+1).trim())}return Object.keys(s).length>0?s:void 0}const ir=t=>Object.entries(t??{}).map(([s,n])=>`${s}: ${n}`).join(`
18
- `);function Ch(t,s){const n=He(t).toLowerCase();return n==="sse"?"sse":n==="http"||n==="streamable-http"?"http":n==="stdio"?"stdio":s?"http":"stdio"}function lr(t){if(!t||typeof t!="object")return[];const s=[];for(const[n,a]of Object.entries(t)){if(!a||typeof a!="object")continue;const r=a,o=He(r.url)||He(r.serverUrl),i=He(r.command);if(!i&&!o)continue;const c=i?void 0:kh(r.headers);s.push({name:n,transport:Ch(r.type??r.transport,o),command:i||void 0,args:i?Nh(r.args):void 0,env:i?ni(r.env):void 0,url:o||void 0,...c?{headers:c}:{}})}return s}const Sh=t=>{const s=t.trim();return(s.match(/^```(?:json)?\s*([\s\S]*?)\s*```$/i)?.[1]??s).trim()},Ih=t=>t.startsWith('"')&&!t.startsWith("{")&&!t.startsWith("[")?`{${t}}`:t,Ah=t=>{if(!t||typeof t!="object"||Array.isArray(t))return t;const s=t;if(s.mcpServers!=null)return s.mcpServers;if(s.mcp_servers!=null)return s.mcp_servers;if(s.servers!=null)return s.servers;const n=s.mcp;if(n&&typeof n=="object"&&!Array.isArray(n)){const a=n.servers;if(a!=null)return a}return t},Eh=t=>{if(!t||typeof t!="object"||Array.isArray(t))return!1;const s=t;return!!(He(s.command)||He(s.url)||He(s.serverUrl))},Mh=t=>{const s=He(t.command);return s&&s.split(/[\\/]/).pop()?.trim()||"mcp"},mn=t=>{if(Array.isArray(t))return t.flatMap(mn);if(Eh(t)){const s=He(t.name)||He(t.id)||Mh(t);return lr({[s]:t})}return lr(t)};function $s(t){let s;try{s=JSON.parse(Ih(Sh(t)))}catch{return{ok:!1,error:"invalid-json"}}const n=Array.isArray(s)?s.flatMap(mn):mn(Ah(s));return n.length===0?{ok:!1,error:"empty"}:{ok:!0,servers:n}}const Ph=1e4,Th=12e4,Rh=600,Oh=3600;function cr(t,s){let n;if(typeof t=="string"){const a=t.trim();if(!a||!/^\d+$/.test(a))return;n=Number(a)}else if(typeof t=="number")n=t;else return;if(!(!Number.isInteger(n)||n<=0))return s===void 0?n:Math.min(n,s)}const Dh={theme:oc,disableFileHeader:!0,overflow:"scroll",preferredHighlighter:"shiki-js"};function Lh(t){return new uc(t)}function ai({fileName:t,value:s,epoch:n,onChange:a,className:r="h-60"}){const{t:o}=U(),[i,c]=m.useState(!1),d=rc(Dh),x=m.useRef(a);x.current=a;const h=m.useMemo(()=>({onChange(u){x.current(u.contents)}}),[]);return m.useEffect(()=>{let u=!0;return ic().then(()=>{u&&c(!0)}),()=>{u=!1}},[]),i?e.jsx("div",{className:K("w-full overflow-hidden rounded-lg border border-input",r),children:e.jsx(lc,{createEditor:Lh,children:e.jsx(cc,{style:{height:"100%",overflow:"auto"},children:e.jsx(dc,{file:{name:t,contents:s},disableWorkerPool:!0,edit:!0,editorOptions:h,options:d},n)})})}):e.jsx("div",{className:K("flex w-full items-center justify-center rounded-lg border border-input text-muted-foreground text-xs",r),children:o("Loading...")})}const dr=t=>{const s=t.split(`
19
- `).map(n=>n.trim()).filter(Boolean);return s.length>0?s:void 0},ur=t=>{const s={};for(const n of t.split(`
20
- `)){const a=n.trim();if(!a)continue;const r=a.indexOf("=");r<=0||(s[a.slice(0,r).trim()]=a.slice(r+1))}return Object.keys(s).length>0?s:void 0},mr=t=>t?Object.entries(t).map(([s,n])=>`${s}=${n}`).join(`
21
- `):"",hr=t=>{const s={type:t.transport};return t.command&&(s.command=t.command),t.args&&t.args.length>0&&(s.args=t.args),t.env&&Object.keys(t.env).length>0&&(s.env=t.env),t.url&&(s.url=t.url),t.headers&&Object.keys(t.headers).length>0&&(s.headers=t.headers),s};function zh({server:t,onClose:s}){const{t:n}=U(),a=b(F=>F.addMcpServers),r=b(F=>F.updateMcpServer),o=t==="new",[i,c]=m.useState("form"),[d,x]=m.useState(""),[h,u]=m.useState(""),[p,l]=m.useState(""),[f,g]=m.useState(""),[y,N]=m.useState("stdio"),[j,v]=m.useState(""),[k,R]=m.useState(""),[L,S]=m.useState(""),[O,w]=m.useState(""),[M,E]=m.useState(""),[I,B]=m.useState(""),[C,_]=m.useState(""),[V,H]=m.useState(""),[$,re]=m.useState(0),[D,q]=m.useState(null),P=()=>({description:h.trim()||void 0,oauthClientName:y!=="stdio"&&p.trim()||void 0,oauthMetadataUrl:y!=="stdio"&&f.trim()||void 0,connectTimeoutSec:cr(I,Rh),callTimeoutSec:cr(C,Oh)}),Y=F=>{x(F.name),N(F.transport),v(F.command??""),R((F.args??[]).join(`
22
- `)),S(mr(F.env&&Object.keys(F.env).length>0?F.env:void 0)),w(F.url??""),E(ir(F.headers))},ae=()=>{const F={type:y};if(y==="stdio"){F.command=j.trim();const Q=dr(k);Q&&(F.args=Q);const W=ur(L);W&&(F.env=W)}else{F.url=O.trim();const Q=or(M);Q&&(F.headers=Q)}return JSON.stringify(F,null,2)},le=(F,Q)=>{const W=(Q??F.name).trim(),he=F.env&&Object.keys(F.env).length>0?F.env:void 0,Ne=F.args&&F.args.length>0?F.args:void 0;return F.transport==="stdio"?{name:W,transport:F.transport,command:(F.command??"").trim(),args:Ne,env:he,url:void 0,headers:void 0,...P()}:{name:W,transport:F.transport,url:(F.url??"").trim(),headers:F.headers&&Object.keys(F.headers).length>0?F.headers:void 0,command:void 0,args:void 0,env:void 0,...P()}};m.useEffect(()=>{if(!t)return;const F=t==="new"?null:t;c("form"),x(F?.name??""),u(F?.description??""),l(F?.oauthClientName??""),g(F?.oauthMetadataUrl??""),N(F?.transport??"stdio"),v(F?.command??""),R((F?.args??[]).join(`
23
- `)),S(mr(F?.env)),w(F?.url??""),E(ir(F?.headers)),B(F?.connectTimeoutSec?.toString()??""),_(F?.callTimeoutSec?.toString()??""),H(""),re(Q=>Q+1),q(null)},[t]);const z=F=>n(F==="invalid-json"?"Invalid JSON":"No MCP servers found in JSON"),ue=F=>{if(F===i)return;if(F==="json"){H(ae()),re(he=>he+1),q(null),c("json");return}const Q=$s(V);if(!Q.ok){if(Q.error==="invalid-json"&&V.trim()){q(z(Q.error));return}q(null),c("form");return}if(Q.servers.length!==1){q(n("JSON must describe a single MCP server to switch to the form"));return}const W=Q.servers[0];Y({...W,name:d.trim()||W.name}),q(null),c("form")},me=()=>{const F=$s(V);if(!F.ok){q(z(F.error));return}if(F.servers.length===1){const[Q]=F.servers;H(JSON.stringify(hr(Q),null,2)),re(W=>W+1),d.trim()||x(Q.name)}else H(JSON.stringify({mcpServers:Object.fromEntries(F.servers.map(Q=>[Q.name,hr(Q)]))},null,2)),re(Q=>Q+1);q(null)},ye=!!d.trim()&&(y==="stdio"?!!j.trim():!!O.trim()),we=i==="json"?!!V.trim():ye,Ve=()=>{if(!t||!we)return;if(i==="json"){const Q=$s(V);if(!Q.ok){q(z(Q.error));return}if(!o&&Q.servers.length!==1){q(n("JSON must describe a single MCP server"));return}if(o){const W=Q.servers.length===1;if(a(Q.servers.map(Ne=>({...le(Ne,W&&d.trim()?d:Ne.name),...W?{}:{description:void 0},id:crypto.randomUUID(),source:"Manual",enabled:!0})))===0){q(n("This MCP server already exists"));return}}else r(t.id,le(Q.servers[0],d.trim()||Q.servers[0].name));s();return}const F=y==="stdio"?{name:d.trim(),transport:y,command:j.trim(),args:dr(k),env:ur(L),url:void 0,headers:void 0,...P()}:{name:d.trim(),transport:y,url:O.trim(),headers:or(M),command:void 0,args:void 0,env:void 0,...P()};if(o){if(a([{...F,id:crypto.randomUUID(),source:"Manual",enabled:!0}])===0){q(n("This MCP server already exists"));return}}else r(t.id,F);s()};return e.jsx(pe,{open:t!==null,onOpenChange:F=>!F&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:n(o?"Add MCP Server":"Edit MCP Server")})}),e.jsxs(Se,{className:"space-y-4",children:[e.jsx(zt,{value:i,onValueChange:F=>ue(F),children:e.jsxs(Bt,{children:[e.jsx(Ke,{value:"form",children:n("Form")}),e.jsx(Ke,{value:"json",children:n("JSON")})]})}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Name")}),e.jsx(J,{value:d,onChange:F=>x(F.target.value)})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Description (optional)")}),e.jsx(J,{value:h,onChange:F=>u(F.target.value),placeholder:n("One line telling the model what this server is for")})]}),i==="json"?e.jsxs(ce,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx(de,{children:n("JSON configuration")}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-7 px-2",onClick:me,children:n("Format")})]}),e.jsx(ai,{fileName:"mcp.json",value:V,epoch:$,onChange:H}),e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Paste a server object or mcpServers JSON from Cursor / Claude Desktop")})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ce,{children:[e.jsx(de,{children:n("Transport")}),e.jsxs(ee,{items:ma.map(F=>({value:F,label:F})),value:y,onValueChange:F=>N(F),children:[e.jsx(te,{className:"w-full",children:e.jsx(se,{})}),e.jsx(ne,{zIndex:Qe.DROPDOWN_IN_MODAL,children:ma.map(F=>e.jsx(X,{value:F,children:F},F))})]})]}),y==="stdio"?e.jsxs(e.Fragment,{children:[e.jsxs(ce,{children:[e.jsx(de,{children:n("Command")}),e.jsx(J,{value:j,onChange:F=>v(F.target.value),placeholder:"npx",className:"font-mono text-xs"})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Arguments (one per line)")}),e.jsx(Xe,{value:k,onChange:F=>R(F.target.value),rows:3,className:"font-mono text-xs"})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Environment variables (KEY=VALUE, one per line)")}),e.jsx(Xe,{value:L,onChange:F=>S(F.target.value),rows:3,className:"font-mono text-xs"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(ce,{children:[e.jsx(de,{children:n("URL")}),e.jsx(J,{value:O,onChange:F=>w(F.target.value),placeholder:"https://...",className:"font-mono text-xs"})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Headers (Name: value, one per line)")}),e.jsx(Xe,{value:M,onChange:F=>E(F.target.value),rows:2,placeholder:"Authorization: Bearer <token>",className:"font-mono text-xs"})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("OAuth client name (optional)")}),e.jsx(J,{value:p,onChange:F=>l(F.target.value),placeholder:n("For servers that only accept known OAuth clients")})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("OAuth authorization server metadata URL (optional)")}),e.jsx(J,{value:f,onChange:F=>g(F.target.value),placeholder:n("Use when the server advertises a wrong authorization server or none"),className:"font-mono text-xs"})]})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Connection timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:I,onChange:F=>B(F.target.value),placeholder:String(Ph/1e3)})]}),e.jsxs(ce,{children:[e.jsx(de,{children:n("Tool call timeout (seconds)")}),e.jsx(J,{inputMode:"numeric",value:C,onChange:F=>_(F.target.value),placeholder:String(Th/1e3)})]})]}),D&&e.jsx("p",{className:"t-shake-in text-destructive text-xs",children:D},D)]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:s,children:n("Cancel")}),e.jsx(A,{size:"sm",disabled:!we,onClick:Ve,children:n("Save")})]})]})})}function Bh({status:t}){const{t:s}=U();return t.state==="connecting"?e.jsx(Z,{variant:"outline",className:"shrink-0 animate-pulse text-[11px] text-muted-foreground",children:s("Connecting")}):t.state==="ready"?e.jsx(Z,{variant:"success",className:"shrink-0 text-[11px]",children:s("{{count}} tools",{count:t.toolCount??0})}):t.state==="unauthorized"?e.jsx(Z,{variant:"warning",className:"shrink-0 text-[11px]",children:s("Not authorized")}):t.state==="idle"?e.jsx(Z,{variant:"outline",className:"shrink-0 text-[11px] text-muted-foreground",children:s("Authorized, pending connection")}):e.jsx(Z,{variant:"error",className:"shrink-0 text-[11px]",title:t.error,children:s("Connection failed")})}function _h(){const{t}=U(),s=b(E=>E.mcpServers),n=b(E=>E.updateMcpServer),a=b(E=>E.setMcpServersEnabled),r=b(E=>E.removeMcpServer),o=dt(E=>E.statuses),i=dt(E=>E.authorized),c=dt(E=>E.pending),d=dt(E=>E.authorize),x=dt(E=>E.revoke);m.useEffect(()=>dt.getState().bind(),[]);const[h,u]=m.useState(!1),[p,l]=m.useState(null),f=async E=>{await d(E),l(dt.getState().authorized[E]===!0?E:null)},[g,y]=m.useState(null),[N,j]=m.useState(""),v=s.filter(E=>jo(N,[E.name,E.source,E.transport,E.url,E.command,...E.args??[]])),k=v.map(E=>E.id),R=vo(k),L=s.filter(E=>E.enabled).length,S=s.filter(E=>E.enabled).map(E=>E.id),O=is(S,E=>window.electronAPI.assets.mcpOccupancy(E)),w=s.filter(E=>E.enabled&&E.loadMode!=="deferred").map(E=>E.id),M=as(w,O.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"mcp.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("MCP Servers"),e.jsx(qe,{}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:L,total:s.length}),e.jsx(os,{tokens:M})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Model Context Protocol servers available to this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>u(!0),children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>y("new"),children:[e.jsx(Ee,{className:"mr-1.5 h-4 w-4"}),t("Add MCP server")]})]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(bo,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No MCP servers yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import MCP servers from local apps or add one manually to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(yo,{query:N,onQueryChange:j,placeholder:t("Filter MCP servers..."),allSelected:R.allSelected,someSelected:R.someSelected,onToggleSelectAll:R.toggleAll,onEnable:()=>a(R.selectedIds,!0),onDisable:()=>a(R.selectedIds,!1),selectDisabled:v.length===0,actionDisabled:R.selectedIds.length===0}),v.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:v.map(E=>{const I=o[E.id]??o[E.name],B=c[E.id]===!0,C=E.transport!=="stdio"&&i[E.id]!==!0,_=E.loadMode==="deferred";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`mcp.${E.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(We,{checked:R.isSelected(E.id),onCheckedChange:V=>R.toggleOne(E.id,V)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!E.enabled&&"text-muted-foreground line-through"),children:E.name}),e.jsx(Z,{variant:"outline",className:"shrink-0 text-[11px]",children:E.transport}),e.jsx(Z,{variant:"secondary",className:"shrink-0 text-[11px]",children:E.source}),I&&e.jsx(Bh,{status:I}),e.jsx("span",{className:"min-w-0 truncate font-mono text-muted-foreground text-xs",children:E.url??[E.command,...E.args??[]].join(" ")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[(C||I?.state==="unauthorized")&&e.jsxs(A,{variant:"outline",size:"sm",className:"h-7",disabled:B,onClick:()=>{f(E.id)},children:[B?e.jsx(Te,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):e.jsx(mc,{className:"mr-1.5 h-3.5 w-3.5"}),t(B?"Authorizing":"Authorize")]}),i[E.id]===!0&&e.jsx(A,{variant:"ghost",size:"icon",title:t("Revoke authorization"),className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>{x(E.id)},children:e.jsx(hc,{className:"h-3.5 w-3.5"})}),e.jsx(rs,{row:O.rows[E.id],pending:E.enabled&&O.pending&&!O.rows[E.id]}),e.jsx(zt,{value:_?"deferred":"direct",onValueChange:V=>n(E.id,{loadMode:V==="deferred"?"deferred":"direct"}),title:t("On demand: tool descriptions are not preloaded into context; the model connects through the mcp tool when needed. Suits servers with many or rarely used tools. Takes effect in new conversations."),children:e.jsxs(Bt,{"aria-label":t("Load mode"),children:[e.jsx(Ke,{value:"direct",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("Always loaded")}),e.jsx(Ke,{value:"deferred",className:"h-6 px-2 text-xs sm:h-6 sm:text-xs",children:t("On demand")})]})}),e.jsx(oe,{checked:E.enabled,onCheckedChange:V=>n(E.id,{enabled:V})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>y(E),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(E.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]}),p===E.id&&e.jsx("p",{className:"px-3 text-muted-foreground text-xs",children:t("Authorized. Conversations that already include this server can use it on the next message.")})]},E.id)})})]}),e.jsx(On,{kind:"mcp",open:h,onOpenChange:u}),e.jsx(zh,{server:g,onClose:()=>y(null)})]})}const Fh=["fact","preference","decision","plan","procedure","learning","context","event"],Uh=.9,$h=.7,Vh=.5;function Kh(t){return Number.isFinite(t)?t>=Uh?"critical":t>=$h?"important":t>=Vh?"useful":"low":"low"}const xr=3,pr={PERSON:340,ORGANIZATION:20,TEAM:20,PRODUCT:210,TOOL:210,SYSTEM:250,SERVICE:250,PLATFORM:250,CONCEPT:160,METHOD:160,TECHNIQUE:160,EVENT:40,PROJECT:280,DOCUMENT:90,TERM:190};function ri(t){if(pr[t]!==void 0)return pr[t];let s=0;for(let n=0;n<t.length;n++)s=s*17+t.charCodeAt(n)>>>0;return s%360}const Vs=22,qh=64;function Gh(t,s){if(s<=1)return Vs;const n=Math.sqrt(Math.max(1,t))/Math.sqrt(s);return Math.round(Vs+(qh-Vs)*Math.min(1,n))}function Hh(t,s,n){const a=Math.max(1,...t.map(o=>o.memoryCount)),r=new Set(t.map(o=>o.id));return[...t.map(o=>({data:{id:o.id,label:o.name,size:Gh(o.memoryCount,a),color:oi(ri(o.entityType),n),entityType:o.entityType,memoryCount:o.memoryCount,spaceLabel:o.spaceLabel}})),...s.filter(o=>r.has(o.source)&&r.has(o.target)&&o.source!==o.target).map(o=>({data:{id:`${o.source}->${o.target}:${o.relation}`,source:o.source,target:o.target,label:o.relation.replace(/_/g," ").toLowerCase(),width:1+o.strength*2.5}}))]}function Wh(t,s){const n=new Map;for(const a of t)n.set(a.entityType,(n.get(a.entityType)??0)+1);return[...n.entries()].map(([a,r])=>({entityType:a,count:r,color:oi(ri(a),s)})).sort((a,r)=>r.count-a.count||a.entityType.localeCompare(r.entityType))}function Jh(t){const s=t?"#e7e7e9":"#1c1c1f";return[{selector:"node",style:{"background-color":"data(color)","background-opacity":.85,width:"data(size)",height:"data(size)",label:"data(label)","font-size":11,color:s,"text-valign":"bottom","text-margin-y":4,"text-max-width":"120px","text-wrap":"ellipsis","border-width":0,"transition-property":"opacity, border-width","transition-duration":150}},{selector:"edge",style:{width:"data(width)","line-color":t?"#4b4b52":"#c9c9d1","curve-style":"bezier",opacity:.65,"font-size":9,color:s,"text-opacity":0}},{selector:"edge:selected, edge.highlighted",style:{"text-opacity":.85,opacity:1}},{selector:"node:selected",style:{"border-width":3,"border-color":s,"background-opacity":1}},{selector:".dimmed",style:{opacity:.18,"text-opacity":.25}}]}function oi(t,s){return Yh(t,s?.62:.68,s?.58:.52)}function Yh(t,s,n){const a=(1-Math.abs(2*n-1))*s,r=a*(1-Math.abs(t/60%2-1)),o=n-a/2,[i,c,d]=t<60?[a,r,0]:t<120?[r,a,0]:t<180?[0,a,r]:t<240?[0,r,a]:t<300?[r,0,a]:[a,0,r],x=h=>Math.round((h+o)*255).toString(16).padStart(2,"0");return`#${x(i)}${x(c)}${x(d)}`}let fr=!1;function Qh(){fr||(_o.use(Rd),fr=!0)}const gr={name:"fcose",animate:!1,randomize:!1,nodeRepulsion:8e3,idealEdgeLength:90,nodeSeparation:90,padding:24,fit:!0};function Xh({graph:t,selectedId:s,onSelect:n,memories:a,loading:r,onInterpret:o,interpreting:i}){const{t:c}=U(),d=m.useRef(null),x=m.useRef(null),h=m.useRef(n);h.current=n;const[u,p]=m.useState(null),l=m.useMemo(()=>typeof document<"u"&&document.documentElement.classList.contains("dark"),[]);m.useEffect(()=>{const y=d.current;if(!y||t.nodes.length===0)return;Qh();const N=_o({container:y,elements:Hh(t.nodes,t.edges,l),style:Jh(l),minZoom:.2,maxZoom:2.5,wheelSensitivity:.2});return N.layout(gr).run(),N.on("tap","node",j=>h.current(j.target.id())),N.on("tap",j=>{j.target===N&&h.current(null)}),x.current=N,()=>{N.destroy(),x.current=null}},[t.nodes,t.edges,l]),m.useEffect(()=>{const y=x.current;y&&y.batch(()=>{if(y.elements().removeClass("dimmed").unselect(),!s)return;const N=y.getElementById(s);if(N.empty())return;const j=N.closedNeighborhood();y.elements().difference(j).addClass("dimmed"),N.select()})},[s]);const f=m.useMemo(()=>Wh(t.nodes,l),[t.nodes,l]),g=t.nodes.find(y=>y.id===s)??null;return m.useEffect(()=>{const y=x.current;!y||s||y.batch(()=>{y.elements().removeClass("dimmed"),u&&y.nodes().filter(N=>N.data("entityType")!==u).addClass("dimmed")})},[u,s]),t.nodes.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:c(r?"Loading…":"No entities yet. Turn on entity extraction and store a few memories first.")}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-lg border bg-muted/20",children:[e.jsx("div",{ref:d,className:"h-[440px] w-full"}),e.jsxs("div",{className:"absolute right-2 bottom-2 flex gap-1",children:[e.jsx(A,{size:"sm",variant:"outline",onClick:()=>x.current?.fit(void 0,24),title:c("Fit to view"),children:c("Fit")}),e.jsx(A,{size:"sm",variant:"outline",onClick:()=>x.current?.layout(gr).run(),title:c("Re-run layout"),children:c("Relayout")})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:c("Colour = entity type · size = how many memories mention it",{})}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:f.map(y=>e.jsxs("button",{type:"button",onClick:()=>p(u===y.entityType?null:y.entityType),className:K("inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-xs transition-colors",u===y.entityType?"border-foreground/40 bg-accent":"hover:bg-accent/50"),children:[e.jsx("span",{className:"size-2.5 shrink-0 rounded-full",style:{backgroundColor:y.color}}),e.jsx("span",{className:"text-muted-foreground",children:y.entityType.toLowerCase()}),e.jsx("span",{className:"tabular-nums",children:y.count})]},y.entityType))}),e.jsx("p",{className:"text-muted-foreground text-xs",children:c("{{shown}} of {{total}} entities",{shown:String(t.nodes.length),total:String(t.totalEntities)})})]}),g&&e.jsxs("section",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:g.name}),e.jsx(Z,{variant:"secondary",children:g.entityType})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:c("{{count}} memories · {{space}}",{count:String(g.memoryCount),space:g.spaceLabel})})]}),e.jsx(A,{size:"sm",variant:"outline",disabled:i,onClick:()=>o(g.id),children:c(i?"Interpreting…":"Interpret")})]}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[a.length===0&&e.jsx("li",{className:"px-3 py-4 text-muted-foreground text-sm",children:c("Loading…")}),a.map(y=>e.jsxs("li",{className:"space-y-0.5 px-3 py-2",children:[e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[y.isCrystal&&e.jsx("span",{title:c("Crystal"),children:"★"}),e.jsx("span",{className:"truncate",children:y.title}),e.jsx(Z,{variant:"secondary",children:y.unitType})]}),e.jsx("p",{className:"line-clamp-2 text-muted-foreground text-xs",children:y.contentSummary})]},y.id))]})]})]})}function Zh({tree:t,loading:s,selected:n,onToggle:a,onInterpretGroup:r,interpreting:o}){const{t:i}=U(),[c,d]=m.useState(new Set);return t.length===0?e.jsx("p",{className:"rounded-lg border px-3 py-6 text-muted-foreground text-sm",children:i(s?"Loading…":"No memories yet.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:t.map(x=>{const h=c.has(x.id),u=(x.children??[]).map(p=>p.memoryId).filter(p=>!!p);return e.jsxs("li",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>{const p=new Set(c);p.delete(x.id)||p.add(x.id),d(p)},children:e.jsxs("p",{className:"flex items-center gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:h?"▾":"▸"}),e.jsx("span",{className:"truncate",children:x.label}),e.jsx(Z,{variant:"secondary",children:x.count})]})}),e.jsx(A,{size:"sm",variant:"ghost",className:"shrink-0",disabled:o||u.length===0,onClick:()=>r(x),children:i("Interpret")})]}),h&&e.jsxs("ul",{className:"divide-y border-t bg-muted/20",children:[(x.children??[]).map(p=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[p.memoryId&&e.jsx(We,{checked:n.has(p.memoryId),onCheckedChange:()=>p.memoryId&&a(p.memoryId),"aria-label":i("Select memory")}),e.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2",children:[p.isCrystal&&e.jsx("span",{title:i("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:p.label})]})]},p.id)),x.count>(x.children?.length??0)&&e.jsx("li",{className:"px-3 py-2 text-muted-foreground text-xs",children:i("Showing {{shown}} of {{total}}",{shown:String(x.children?.length??0),total:String(x.count)})})]})]},x.id)})})}const ex=120,tx=30,sx={nodes:[],edges:[],totalEntities:0};function nx({revision:t=0}={}){const{t:s}=U(),[n,a]=m.useState("graph"),[r,o]=m.useState("unitType"),[i,c]=m.useState(sx),[d,x]=m.useState([]),[h,u]=m.useState(!0),[p,l]=m.useState(null),[f,g]=m.useState([]),[y,N]=m.useState(new Set),[j,v]=m.useState(null),[k,R]=m.useState(!1),[L,S]=m.useState(null),[O,w]=m.useState(!1),M=m.useCallback(()=>{u(!0);const $=()=>u(!1);n==="graph"?window.electronAPI.memory.graph({limit:ex,minMemories:1}).then(c).finally($):window.electronAPI.memory.tree({groupBy:r,limitPerGroup:tx}).then(x).finally($)},[n,r]);m.useEffect(M,[M]);const E=m.useRef(M);E.current=M,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>E.current()),[]);const I=m.useRef(t);m.useEffect(()=>{I.current!==t&&(I.current=t,M())},[t,M]),m.useEffect(()=>{if(!p){g([]);return}window.electronAPI.memory.graphEntity(p).then(g)},[p]);const B=async $=>{R(!0),v(null);try{v(await window.electronAPI.memory.insight($))}finally{R(!1)}},C=async()=>{w(!0);try{const $=await window.electronAPI.memory.crystallize({memoryIds:[...y]});S($),$.ok&&N(new Set)}finally{w(!1)}},_=[{value:"graph",label:s("Graph")},{value:"tree",label:s("Tree")}],V=[{value:"unitType",label:s("By type")},{value:"entity",label:s("By entity")},{value:"time",label:s("By month")}],H=y.size>=xr;return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.knowledge",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Knowledge")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Browse what the agent knows as a graph or a tree, ask for an interpretation, and consolidate related memories into a crystal.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(ee,{value:n,items:_,onValueChange:$=>a($==="tree"?"tree":"graph"),children:[e.jsx(te,{size:"sm",className:"w-32",children:e.jsx(se,{})}),e.jsx(ne,{children:_.map($=>e.jsx(X,{value:$.value,children:$.label},$.value))})]}),n==="tree"&&e.jsxs(ee,{value:r,items:V,onValueChange:$=>o($),children:[e.jsx(te,{size:"sm",className:"w-36",children:e.jsx(se,{})}),e.jsx(ne,{children:V.map($=>e.jsx(X,{value:$.value,children:$.label},$.value))})]}),e.jsx("span",{className:"flex-1"}),n==="tree"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:K("text-xs",H?"text-foreground":"text-muted-foreground"),children:s("{{count}} selected",{count:String(y.size)})}),e.jsx(A,{size:"sm",variant:"outline",disabled:!H||O,onClick:()=>{C()},children:O?s("Synthesizing…"):s("Crystallize ({{min}}+)",{min:String(xr)})})]})]}),n==="graph"?e.jsx(Xh,{graph:i,loading:h,selectedId:p,onSelect:l,memories:f,interpreting:k,onInterpret:$=>{B({entityId:$})}}):e.jsx(Zh,{tree:d,loading:h,selected:y,interpreting:k,onToggle:$=>{const re=new Set(y);re.delete($)||re.add($),N(re)},onInterpretGroup:$=>{const re=($.children??[]).map(D=>D.memoryId).filter(D=>!!D);B({memoryIds:re})}}),e.jsx(pe,{open:j!==null,onOpenChange:$=>!$&&v(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Interpretation")}),j?.ok&&e.jsx(Ue,{children:s("Based on {{count}} memories",{count:String(j.sourceCount??0)})})]}),e.jsx(Se,{children:j?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:j.text}):e.jsx("p",{className:"text-destructive text-sm",children:j?.error})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:s("Close")})})]})}),e.jsx(pe,{open:L!==null,onOpenChange:$=>!$&&S(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:L?.ok?s("Crystal created"):s("Nothing was written")}),L?.ok&&e.jsx(Ue,{children:L.title})]}),e.jsx(Se,{className:"space-y-3",children:L?.ok?e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:L.content}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-destructive text-sm",children:L?.error}),L?.candidates&&L.candidates.length>0&&e.jsx("ul",{className:"divide-y rounded-lg border",children:L.candidates.map($=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:$.title}),e.jsxs(Z,{variant:"secondary",children:[($.similarity*100).toFixed(0),"%"]})]},$.id))})]})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:s("Close")})})]})})]})}function hn(t){return t==="fast"||t==="deep"}const jt=25,nt="__all__";function ii(t){return t.slice(0,10)}function ax(t,s){return t===!1&&!s}function rx(t,s,n,a){return hn(t)&&!s.trim()?"needs-query":ax(n,a)?"library-empty":"no-match"}function ox({items:t,onOpen:s,t:n,selected:a,onToggle:r,emptyLabel:o}){return e.jsxs("ul",{className:"divide-y rounded-lg border",children:[t.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:o}),t.map(i=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[r&&e.jsx(We,{checked:a?.has(i.id)??!1,onCheckedChange:()=>r(i.id),"aria-label":n("Select memory")}),e.jsxs("button",{type:"button",onClick:()=>s(i.id),className:"min-w-0 flex-1 space-y-0.5 text-left",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[i.isCrystal&&e.jsx("span",{title:n("Crystal"),children:"★"}),e.jsx("span",{className:"truncate text-sm",children:i.title}),e.jsx(Z,{variant:"secondary",children:i.unitType}),e.jsx(lx,{importance:i.importance,t:n}),i.lifecycleState==="archived"&&e.jsx(Z,{variant:"outline",children:n("Archived")})]}),e.jsx("span",{className:"line-clamp-2 text-muted-foreground text-xs",children:i.contentSummary}),e.jsxs("span",{className:"block text-muted-foreground text-xs",children:[ii(i.updatedAt)," · ",i.spaceLabel," ·"," ",n("Retrieved {{count}} times",{count:String(i.appearances)})]})]})]},i.id))]})}const ix={critical:{variant:"warning",label:"critical"},important:{variant:"info",label:"important"},useful:{variant:"outline",label:"useful"},low:{variant:"outline",label:"low"}};function lx({importance:t,t:s}){const n=Kh(t),a=ix[n];return e.jsx(Z,{variant:a.variant,className:n==="low"?"text-muted-foreground":void 0,title:s("Importance {{value}}",{value:t.toFixed(2)}),children:s(a.label)})}function cx({edges:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.review",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Needs review")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Reviewing only records your judgement. Nothing is deleted and no memory is superseded.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{variant:"outline",children:a.relation}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[a.olderId.slice(0,8)," → ",a.newerId.slice(0,8)]})]}),a.reason&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a.reason}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{size:"sm",variant:"outline",onClick:()=>s(a.id,"accepted"),children:n("Accept")}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"rejected"),children:n("Dismiss")})]})]},a.id))]})}function dx({writes:t,onReview:s,t:n}){return t.length===0?null:e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.pending-writes",children:[e.jsx("h3",{className:"text-sm font-medium",children:n("Memory writes awaiting approval")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Bot members need your approval before writing to project or global memory.")}),t.map(a=>e.jsxs("div",{className:"space-y-1 rounded-lg border px-3 py-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[a.originLabel&&e.jsx("span",{className:"text-foreground",children:a.originLabel}),e.jsxs("span",{children:["→ ",a.spaceLabel]}),a.redacted&&e.jsxs("span",{children:["· ",n("Secrets redacted")]})]}),a.title&&e.jsx("div",{className:"text-sm font-medium",children:a.title}),e.jsx("p",{className:"whitespace-pre-wrap text-xs",children:a.content}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{size:"sm",variant:"outline",onClick:()=>s(a.id,"approve"),children:n("Approve")}),e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>s(a.id,"reject"),children:n("Reject")})]})]},a.id))]})}function ux({t}){const s=xc(),n=pc(a=>a.review);return e.jsx(dx,{writes:s,t,onReview:(a,r)=>{n(a,r)}})}function mx({revision:t=0}={}){const{t:s}=U(),[n,a]=m.useState(""),[r,o]=m.useState(nt),[i,c]=m.useState(nt),[d,x]=m.useState(!1),[h,u]=m.useState(0),[p,l]=m.useState("exact"),[f,g]=m.useState(!1),[y,N]=m.useState(!0),[j,v]=m.useState([]),[k,R]=m.useState(0),[L,S]=m.useState([]),[O,w]=m.useState(null),[M,E]=m.useState(null),[I,B]=m.useState(null),[C,_]=m.useState(new Set),[V,H]=m.useState(!1),[$,re]=m.useState(!1),[D,q]=m.useState([]),P=m.useRef(!1),Y=m.useRef(0),ae=m.useRef(0);m.useEffect(()=>(P.current=!0,()=>{P.current=!1,Y.current++,ae.current++}),[]);const le=m.useCallback(()=>{if(!P.current)return;const G=++Y.current,ke=()=>P.current&&G===Y.current;if(hn(p)&&!n.trim()){v([]),R(0),g(!0),N(!0);return}window.electronAPI.memory.list({query:n.trim()||void 0,spaceId:r===nt?void 0:r,unitType:i===nt?void 0:i,includeArchived:d,limit:jt,offset:h,mode:p}).then(Ce=>{ke()&&(v(Ce.items),R(Ce.total),g(Ce.approximate===!0),N(Ce.vectorsUsed!==!1))}),window.electronAPI.memory.stats().then(Ce=>{P.current&&(S(Object.keys(Ce.bySpace).map(Oe=>({id:Oe,label:Ce.spaceLabels[Oe]??Oe}))),w(Ce.total>0))}),window.electronAPI.memory.evolvesPending().then(Ce=>{P.current&&q(Ce)})},[n,r,i,d,h,p]);m.useEffect(()=>(le(),()=>{Y.current++}),[le]);const z=m.useRef(le);z.current=le,m.useEffect(()=>window.electronAPI.memory.onChanged(()=>z.current()),[]);const ue=m.useRef(t);m.useEffect(()=>{ue.current!==t&&(ue.current=t,le())},[t,le]);const me=G=>{const ke=++ae.current;window.electronAPI.memory.detail(G).then(Ce=>{P.current&&ke===ae.current&&E(Ce)})},ye=()=>{ae.current++,E(null)},we=async G=>{re(!0);try{for(const ke of C)await G(ke)}finally{P.current&&(re(!1),_(new Set),H(!1),z.current())}},Ve=()=>{we(G=>window.electronAPI.memory.archive(G))},F=()=>{we(G=>window.electronAPI.memory.delete(G))},Q=G=>{G.then(()=>{P.current&&(ye(),B(null),z.current())})},W=n.trim()!==""||r!==nt||i!==nt||d===!0,he=[{value:nt,label:s("All spaces")},...L.map(G=>({value:G.id,label:G.label}))],Ne=[{value:nt,label:s("All types")},...Fh.map(G=>({value:G,label:G}))],xt=[{value:"exact",label:s("Exact match")},{value:"fast",label:s("Fast retrieval")},{value:"deep",label:s("Deep retrieval")}];return e.jsxs("div",{className:"space-y-4","data-settings-row":"memory.library",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Stored memories")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Everything the agent has saved. Archiving hides a memory from search but keeps it.")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(wo,{className:"w-full sm:w-96","data-size":"sm",children:[e.jsx(No,{value:n,placeholder:s("Search memories"),onChange:G=>{u(0),a(G.target.value)}}),e.jsx(ko,{align:"inline-end",className:"pe-1",children:e.jsxs(ee,{value:p,items:xt,onValueChange:G=>{u(0),l(G==="deep"?"deep":G==="fast"?"fast":"exact")},children:[e.jsx(te,{size:"sm",className:"w-auto min-w-0 gap-1 border-0 bg-transparent px-2 shadow-none before:hidden",children:e.jsx(se,{})}),e.jsx(ne,{children:xt.map(G=>e.jsx(X,{value:G.value,children:G.label},G.value))})]})})]}),e.jsxs(ee,{value:r,items:he,onValueChange:G=>{u(0),o(String(G))},children:[e.jsx(te,{size:"sm",className:"w-36",children:e.jsx(se,{})}),e.jsx(ne,{children:he.map(G=>e.jsx(X,{value:G.value,children:G.label},G.value))})]}),e.jsxs(ee,{value:i,items:Ne,onValueChange:G=>{u(0),c(String(G))},children:[e.jsx(te,{size:"sm",className:"w-36",children:e.jsx(se,{})}),e.jsx(ne,{children:Ne.map(G=>e.jsx(X,{value:G.value,children:G.label},G.value))})]}),p==="exact"&&e.jsxs("label",{className:"flex items-center gap-2 text-muted-foreground text-sm",children:[e.jsx(oe,{checked:d,onCheckedChange:G=>{u(0),x(G===!0)}}),s("Show archived")]})]}),hn(p)&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s(p==="deep"?"Same recall as Fast, plus intent-weighted fusion and an optional short-timeout LLM rerank. Failures fall back; archived memories are excluded.":"Same path the agent uses: full-text, vectors and entities merged by relevance. Shows the top matches only — no exact count, and archived memories are excluded."),!y&&` ${s("Embedding model is not ready, so vectors are skipped.")}`]}),C.size>0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border bg-accent/30 px-3 py-2",children:[e.jsx("span",{className:"text-sm",children:s("{{count}} selected",{count:String(C.size)})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{variant:"ghost",size:"sm",disabled:$,onClick:()=>_(new Set),children:s("Clear selection")}),e.jsx(A,{variant:"outline",size:"sm",disabled:$,onClick:()=>Ve(),children:s("Archive selected")}),e.jsx("button",{type:"button",disabled:$,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-50",onClick:()=>H(!0),children:s("Delete permanently")})]})]}),e.jsx(ox,{items:j,onOpen:me,t:s,selected:C,emptyLabel:{"needs-query":s("Type a query to search by meaning."),"library-empty":s("No memories yet. They appear here once the agent stores something."),"no-match":s("No memories match these filters.")}[rx(p,n,O,W)],onToggle:G=>{const ke=new Set(C);ke.delete(G)||ke.add(G),_(ke)}}),!f&&k>jt&&e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsx(A,{variant:"outline",size:"sm",disabled:h===0,onClick:()=>u(Math.max(0,h-jt)),children:s("Previous")}),e.jsxs("span",{children:[h+1,"–",Math.min(h+jt,k)," / ",k]}),e.jsx(A,{variant:"outline",size:"sm",disabled:h+jt>=k,onClick:()=>u(h+jt),children:s("Next")})]}),e.jsx(ux,{t:s}),e.jsx(cx,{edges:D,t:s,onReview:(G,ke)=>Q(window.electronAPI.memory.evolvesReview(G,ke))}),e.jsx(pe,{open:M!==null,onOpenChange:G=>!G&&ye(),children:e.jsx(fe,{children:M&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:M.title}),e.jsx(Ue,{children:[M.unitType,M.spaceLabel,ii(M.createdAt)].join(" · ")})]}),e.jsxs(Se,{className:"space-y-4",children:[e.jsx("p",{className:"whitespace-pre-wrap text-sm",children:M.content}),e.jsxs("dl",{className:"grid grid-cols-2 gap-x-4 gap-y-3",children:[e.jsx(Ks,{label:s("Importance"),value:M.importance.toFixed(2)}),e.jsx(Ks,{label:s("Embedding"),value:M.embeddingModel??s("Not vectorized")}),M.eventStart&&e.jsx(Ks,{label:s("Event date"),value:`${M.eventStart}${M.eventEnd?` → ${M.eventEnd}`:""}`})]}),M.entityNames.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Entities")}),e.jsx("div",{className:"flex flex-wrap gap-1",children:M.entityNames.map(G=>e.jsx(Z,{variant:"secondary",children:G},G))})]}),M.crystalSources.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Synthesized from")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:M.crystalSources.map(G=>e.jsxs("li",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsx("span",{className:"truncate text-sm",children:G.title}),e.jsxs("span",{className:"shrink-0 text-muted-foreground text-xs",children:[(G.contributionWeight*100).toFixed(0),"%"]})]},G.id))})]}),M.evolves.length>0&&e.jsxs("section",{className:"space-y-1.5",children:[e.jsx("p",{className:"font-medium text-xs",children:s("Related versions")}),e.jsx("ul",{className:"divide-y rounded-lg border",children:M.evolves.map(G=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2",children:[e.jsx(Z,{variant:"outline",children:G.relation}),e.jsx("span",{className:"text-muted-foreground text-xs",children:G.reviewState})]},G.id))})]})]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"ghost",size:"sm",className:"sm:me-auto",onClick:()=>B(M.id),children:s("Delete permanently")}),M.lifecycleState==="archived"?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>Q(window.electronAPI.memory.restore(M.id)),children:s("Restore")}):e.jsx(A,{variant:"outline",size:"sm",onClick:()=>Q(window.electronAPI.memory.archive(M.id)),children:s("Archive")})]})]})})}),e.jsx(pe,{open:V,onOpenChange:G=>!G&&H(!1),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete {{count}} memories permanently?",{count:String(C.size)})}),e.jsx(Ue,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(A,{variant:"destructive",size:"sm",disabled:$,onClick:F,children:s("Delete permanently")})]})]})}),e.jsx(pe,{open:I!==null,onOpenChange:G=>!G&&B(null),children:e.jsxs(fe,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Delete this memory permanently?")}),e.jsx(Ue,{children:s("This cannot be undone. Archiving keeps the memory out of search while preserving it.")})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:s("Cancel")}),e.jsx(A,{variant:"destructive",size:"sm",onClick:()=>I&&Q(window.electronAPI.memory.delete(I)),children:s("Delete permanently")})]})]})})]})}function Ks({label:t,value:s}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground text-xs",children:t}),e.jsx("dd",{className:"truncate text-sm",children:s})]})}const jr=t=>t.slice(0,8);function qs(t,s){return t==="pending"||t==="running"?"running":t==="cancelled"?"cancelled":s?"failed":"done"}const hx={low_importance:"importance too low",candidates_found:"similar memory already exists",deduplicated:"identical to an existing memory",rejected:"rejected"};function xx(t){const s=[];for(const r of t.distill){const o=qs(r.status,r.error);s.push({key:`distill:${r.id}`,kind:"distill",target:r.sessionTitle||jr(r.sessionId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"superseded":o==="running"?r.attempts>1?`retry ${r.attempts}`:"queued":`${r.done} stored`,notes:(r.notes??[]).map(i=>[i.title,hx[i.kind]??i.kind].filter(Boolean).join(" — ")),updatedAt:r.updatedAt})}for(const r of t.kg){const o=qs(r.status,r.error);s.push({key:`kg:${r.id}`,kind:"kg",target:r.memoryTitle||jr(r.memoryId),state:o,detail:o==="failed"?r.error??"":o==="cancelled"?"memory changed":o==="running"?"extracting":`${r.total} entities · ${r.done} links`,notes:[],updatedAt:r.updatedAt})}const n=t.reembed;if(n){const r=qs(n.status,n.error);s.push({key:`reembed:${n.id}`,kind:"reembed",target:n.target,state:r,detail:r==="failed"?n.error??"":r==="running"?`${n.done}/${n.total}`:`${n.done} vectorized${n.failed>0?` · ${n.failed} failed`:""}`,notes:[],updatedAt:n.updatedAt})}const a=r=>r.state==="running"?0:r.state==="failed"?1:2;return s.sort((r,o)=>a(r)-a(o)||o.updatedAt.localeCompare(r.updatedAt))}const Rt="remote:openai-compatible",Zt="remote:";function vr(t){return t.id==="none"?"None (full-text only)":t.id.replace(/^(local|remote):/,"")}function ls(t){return t.startsWith(Zt)&&t.length>Zt.length}function px(t){return ls(t)?Rt:t}function fx(t){return!ls(t)||t===Rt?null:t.slice(Zt.length)}function gx(t){return`${Zt}${t}`}function jx(t,s){return s===Rt?ls(t)?t:Rt:s}const vx=4e3,bx=800,br=6,yx={distill:"job:distill",kg:"job:entities",reembed:"job:vectors"},yr={distill:[],kg:[],reembed:null,kgFailed:0};function wx(t){return t.some(s=>s.distilled)}function wr(t){return!t||t.total===0||t.embedded>=t.total?null:t.embeddingError??null}function Nr(t){return t?.downloadable&&(t.state==="missing"||t.state==="downloading")?t.state:null}function Nx(t,s){if(t.done===0||t.done>=t.total)return null;const n=(s-t.startedAt)/t.done;return Math.round(n*(t.total-t.done))}function kx(t){const s=Math.max(1,Math.round(t/1e3));if(s<60)return`${s}s`;const n=Math.floor(s/60);return s%60===0?`${n}m`:`${n}m ${s%60}s`}function Cx(t){const s=new Map;for(const a of t){const r=a.projectId??"",o=s.get(r);if(o){o.sessions.push(a);continue}s.set(r,{key:r,name:a.projectName??"No project",sessions:[a]})}const n=[...s.values()];return[...n.filter(a=>a.key),...n.filter(a=>!a.key)]}function ie(t){if(t<=0)return"0 B";const s=["B","KB","MB","GB"],n=Math.min(Math.floor(Math.log(t)/Math.log(1024)),s.length-1);return`${(t/1024**n).toFixed(n===0?0:1)} ${s[n]}`}function Gs({title:t,description:s,checked:n,onChange:a,rowId:r,disabled:o}){return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":r,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s})]}),e.jsx(oe,{checked:n,disabled:o,onCheckedChange:i=>a(i===!0)})]})}function Sx({onLibraryChanged:t}={}){const{t:s}=U(),n=b(T=>T.disabledBuiltinTools),a=b(T=>T.memoryEmbeddingModel),r=b(T=>T.setMemoryEmbeddingModel),o=b(T=>T.memoryEmbeddingAutoDownload),i=b(T=>T.setMemoryEmbeddingAutoDownload),c=b(T=>T.memoryModelIdleMinutes),d=b(T=>T.setMemoryModelIdleMinutes),x=b(T=>T.memoryEmbeddingRemoteProviderId),h=b(T=>T.setMemoryEmbeddingRemoteProviderId),u=b(T=>T.memoryDistillEnabled),p=b(T=>T.setMemoryDistillEnabled),l=b(T=>T.memoryKgEnabled),f=b(T=>T.setMemoryKgEnabled),g=b(T=>T.memoryDistillModel),y=b(T=>T.setMemoryDistillModel),N=b(T=>T.memoryChatModel)||"remote",j=b(T=>T.setMemoryChatModel),v=b(T=>T.memoryLanguage),k=b(T=>T.setMemoryLanguage),R=Je(),L=g?R.find(T=>T.id===g.providerId):void 0,S=L?.models.find(T=>T.id===g?.modelId),O=fx(a),w=x?R.find(T=>T.id===x):void 0,M=w?.models.find(T=>T.id===O),E=!n.includes("memory"),[I,B]=m.useState(null),[C,_]=m.useState(yr),[V,H]=m.useState([]),[$,re]=m.useState(null),[D,q]=m.useState([]),[P,Y]=m.useState(null),[ae,le]=m.useState([]),[z,ue]=m.useState(null),[me,ye]=m.useState(null),[we,Ve]=m.useState(null),[F,Q]=m.useState(null),[W,he]=m.useState(!1),[Ne,xt]=m.useState(!1),G=m.useRef(!1);G.current=W;const ke=m.useRef(null),Ce=m.useCallback(()=>{window.electronAPI.memory.distillableSessions().then(le)},[]);m.useEffect(()=>{E&&Ce()},[E,Ce]);const Oe=m.useCallback(()=>{window.electronAPI.memory.models().then(H)},[]);m.useEffect(()=>(Oe(),window.electronAPI.memory.onModelProgress(T=>{re(T.done?null:T),T.done&&Oe()})),[Oe]);const xe=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(T=>q(T.filter(be=>!be.purpose)))},[]);m.useEffect(()=>(xe(),window.electronAPI.memory.onChatModelProgress(T=>{Y(T.done?null:T),T.done&&xe()})),[xe]),m.useEffect(()=>{if(!E){B(null),_(yr);return}let T=!1;const be=()=>{window.electronAPI.memory.stats().then(Ye=>{T||B(Ye)}),window.electronAPI.memory.jobs().then(Ye=>{T||(_(Ye),G.current&&Ye.reembed?.status!=="running"&&he(!1))})};ke.current=be,be();const lt=window.electronAPI.memory.onChanged(be),Et=window.setInterval(be,W?bx:vx);return()=>{T=!0,ke.current=null,lt(),window.clearInterval(Et)}},[E,W]);const et=Cx(ae),Fn=ae.filter(T=>!T.distilled),Un=(T,be,lt)=>{const Et=T.filter(Ye=>!Ye.distilled);if(!wx(T)){_t(T,be);return}Q({token:be,label:lt,scope:T,pending:Et})},_t=async(T,be,lt=!1)=>{const Et=D.find(ft=>ft.id===N)??null;if(Nr(Et))return;ue(be);const Ye=Date.now();Ve({done:0,total:T.length,startedAt:Ye});try{for(let ft=0;ft<T.length;ft++)await window.electronAPI.memory.distillSession(T[ft].sessionId,lt),Ve({done:ft+1,total:T.length,startedAt:Ye})}finally{ue(null),Ve(null),Ce(),t?.()}},ve=V.find(T=>T.id===a)??null,Re=D.find(T=>T.id===N)??null,it=Nr(Re),$n=D.map(T=>({value:T.id,label:T.id==="remote"?s("Remote (API model)"):T.label})),Vn=[...V.map(T=>({value:T.id,label:vr(T)})),{value:Rt,label:s("Remote (OpenAI-compatible)")}],Kn=fc.map(T=>({value:String(T),label:T===0?s("Never"):s("{{count}} min",{count:T})})),qn=[{value:"en",label:s("English")},{value:"zh",label:s("Simplified Chinese")},{value:"auto",label:s("Follow conversation")}],cs=ls(a)||ve?.runtime==="openai-compatible",pt=m.useMemo(()=>xx(C),[C]);return e.jsxs("div",{className:"space-y-6","data-settings-row":"memory.root",children:[e.jsxs("section",{className:"space-y-2",children:[e.jsx("h2",{className:"text-base font-medium",children:s("Memory")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Durable knowledge the agent can search and write across sessions. Stored locally in a SQLite database.")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("Turn memory off in Built-in tools.")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.modelIdleMinutes",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Unload automatically when idle")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Release local model memory after this idle period. Models load automatically the next time they are needed.")})]}),e.jsxs(ee,{value:String(c),items:Kn,onValueChange:T=>{T!==null&&d(Number(T))},disabled:!E,children:[e.jsx(te,{className:"w-56 shrink-0","aria-label":s("Unload automatically when idle"),children:e.jsx(se,{})}),e.jsx(ne,{children:Kn.map(T=>e.jsx(X,{value:T.value,children:T.label},T.value))})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Embedding model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Used for semantic search and near-duplicate detection. Without it search still works using full-text only.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.embeddingModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:ve?vr(ve):O??(cs?s("Remote (OpenAI-compatible)"):a)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ve?[ve.dim?`${ve.dim}d`:null,ve.downloadable?ie(ve.approxBytes):null,ve.runtime].filter(Boolean).join(" · "):cs?"openai-compatible":s("Unknown model; the default is used instead.")})]}),e.jsxs(ee,{value:px(a),items:Vn,onValueChange:T=>{T!==null&&r(jx(a,String(T)))},disabled:!E,children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsx(ne,{children:Vn.map(T=>e.jsx(X,{value:T.value,children:T.label},T.value))})]})]}),ve?.downloadable&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.download",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:ve.state==="ready"?s("Model downloaded"):ve.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:$&&$.modelId===ve.id?`${$.file} · ${ie($.received)}${$.total?` / ${ie($.total)}`:""} (${$.fileIndex+1}/${$.fileCount})`:ve.state==="ready"?ie(ve.downloadedBytes):s("Semantic search stays off until the model is on disk.")})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:ve.state==="downloading"?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelModelDownload(ve.id).then(Oe)},children:s("Cancel")}):ve.state==="ready"?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteModel(ve.id).then(Oe)},children:s("Remove")}):e.jsx(A,{size:"sm",disabled:!E,onClick:()=>{window.electronAPI.memory.downloadModel(ve.id).then(Oe)},children:s("Download")})})]}),cs&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.remoteModel",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Remote model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Credentials stay in the main process and are never sent to the renderer.")})]}),R.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx($e,{providers:R,providerId:w?.id??x??"",modelId:M?.id??O??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Select model"),side:"bottom",triggerClassName:Ze,onSelect:(T,be)=>{h(T),r(gx(be))},onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),e.jsx(Gs,{rowId:"memory.autoDownload",title:s("Download models automatically"),description:s("Off by default, so a model is only fetched when you press Download. While a model is missing, search degrades to full-text; existing memories are re-embedded once it arrives."),checked:o,onChange:i,disabled:!E})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillModel",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distillation")}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Completion backend")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Local GGUF runs on this machine. Remote uses the model below.")})]}),e.jsxs(ee,{value:N,items:$n,onValueChange:T=>j(String(T)),disabled:!E,children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsx(ne,{children:$n.map(T=>e.jsx(X,{value:T.value,children:T.label},T.value))})]})]}),Re?.downloadable&&e.jsxs("div",{className:K("flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",it==="missing"&&"border-destructive/50"),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:Re.state==="ready"?s("Model downloaded"):Re.state==="downloading"?s("Downloading…"):s("Model not downloaded")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:P&&P.modelId===Re.id?`${P.file} · ${ie(P.received)}${P.total?` / ${ie(P.total)}`:""}`:Re.state==="ready"?ie(Re.downloadedBytes):ie(Re.approxBytes)})]}),e.jsx("div",{className:"flex shrink-0 gap-2",children:Re.state==="downloading"?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.cancelChatModelDownload(Re.id).then(xe)},children:s("Cancel")}):Re.state==="ready"?e.jsx(A,{variant:"outline",size:"sm",onClick:()=>{window.electronAPI.memory.deleteChatModel(Re.id).then(xe)},children:s("Remove")}):e.jsx(A,{size:"sm",disabled:!E,onClick:()=>{window.electronAPI.memory.downloadChatModel(Re.id).then(xe)},children:s("Download")})})]}),it==="missing"&&e.jsx("p",{className:"text-xs text-destructive",children:s("Local model selected but the weights are not on disk. Distillation and interpretation will wait until you click Download.")}),it==="downloading"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Download in progress. Distillation waits until the model is ready.")}),N==="remote"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Distillation model")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Reads finished sessions and writes the memories.")})]}),R.length>0&&e.jsx("div",{className:"w-56 shrink-0",children:e.jsx($e,{providers:R,providerId:L?.id??"",modelId:S?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:s("Follows the title-summary model"),side:"bottom",triggerClassName:Ze,onSelect:(T,be)=>y({providerId:T,modelId:be}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]}),g&&e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>y(null),children:s("Follows the title-summary model")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-lg border px-3 py-2.5","data-settings-row":"memory.language",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:s("Memory language")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("English keeps retrieval and near-duplicate detection stable across languages. Choose Follow conversation if your team only works in one language.")})]}),e.jsxs(ee,{value:v,items:qn,onValueChange:T=>k(String(T)),disabled:!E,children:[e.jsx(te,{className:"w-56",children:e.jsx(se,{})}),e.jsx(ne,{children:qn.map(T=>e.jsx(X,{value:T.value,children:T.label},T.value))})]})]})]}),e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Background processing")}),e.jsx(Gs,{rowId:"memory.distill",title:s("Distill sessions automatically"),description:s("When a session ends, or goes idle for 30 minutes and is reclaimed, extract 1-3 durable memories from it in the background."),checked:u,onChange:p,disabled:!E}),u&&it&&e.jsx("p",{className:"text-xs text-destructive",children:s("Automatic distillation is on, but the local model is not ready. Sessions will queue until you download it.")}),e.jsx(Gs,{rowId:"memory.kg",title:s("Extract entities"),description:s("Build an entity graph so a memory can be recalled by a name it does not literally contain."),checked:l,onChange:f,disabled:!E})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.stats",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Library")}),I===null||I.total===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:s("No memories stored yet.")}):e.jsxs(e.Fragment,{children:[wr(I)&&e.jsx("p",{className:"text-xs text-destructive",children:s("Vectors unavailable: {{reason}}",{reason:wr(I)??""})}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(vt,{label:s("Memories"),value:String(I.total)}),e.jsx(vt,{label:s("Crystals"),value:String(I.crystals)}),e.jsx(vt,{label:s("Entities"),value:String(I.entities)}),e.jsx(vt,{label:s("With vectors"),value:`${I.embedded}/${I.total}`,action:I.embedded<I.total?e.jsx("button",{type:"button",disabled:W,className:"text-xs text-muted-foreground underline-offset-2 hover:underline disabled:opacity-60",onClick:()=>{he(!0),window.electronAPI.memory.reembed().then(()=>ke.current?.())},children:s(W?"Backfilling…":"Backfill")}):null}),e.jsx(vt,{label:s("Database size"),value:ie(I.databaseBytes)}),e.jsx(vt,{label:s("Spaces"),value:String(Object.keys(I.bySpace).length)})]})]})]}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.distillSessions",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-medium",children:s("Distill past sessions")}),Fn.length>0&&e.jsx(A,{size:"sm",variant:"outline",disabled:!E||z!==null||it!==null,onClick:()=>Un(ae,"all",s("All sessions")),children:z==="all"?s("Distilling…"):s("Distill all ({{count}})",{count:String(Fn.length)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("The automatic switch only covers sessions that end from now on. Distill earlier sessions here to fill the library.")}),we&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s("{{done}}/{{total}} done",{done:String(we.done),total:String(we.total)}),(()=>{const T=Nx(we,Date.now());return T===null?"":` · ${s("about {{time}} left",{time:kx(T)})}`})()]}),et.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("No recorded sessions found.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:et.map(T=>{const be=T.sessions.filter(lt=>!lt.distilled);return e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm",children:T.name}),e.jsx("p",{className:"text-muted-foreground text-xs",children:s("{{total}} sessions · {{pending}} not distilled",{total:String(T.sessions.length),pending:String(be.length)})})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>ye(T),children:s("View sessions")}),e.jsx(A,{size:"sm",variant:"outline",disabled:!E||z!==null||T.sessions.length===0||it!==null,onClick:()=>Un(T.sessions,T.key,T.name),children:z===T.key?s("Distilling…"):s("Distill project")})]})]},T.key)})})]}),e.jsx(pe,{open:me!==null,onOpenChange:T=>!T&&ye(null),children:e.jsx(fe,{children:me&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:me.name}),e.jsx(Ue,{children:s("{{total}} sessions · {{pending}} not distilled",{total:String(me.sessions.length),pending:String(me.sessions.filter(T=>!T.distilled).length)})})]}),e.jsx(Se,{children:e.jsx("ul",{className:"divide-y rounded-lg border",children:me.sessions.map(T=>e.jsxs("li",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm",children:T.title}),e.jsxs("p",{className:"text-muted-foreground text-xs",children:[T.updatedAt?T.updatedAt.slice(0,10):"",T.distilled?` · ${s("Already distilled")}`:""]})]}),e.jsx(A,{size:"sm",variant:"ghost",className:"shrink-0",disabled:!E||z!==null||it!==null,onClick:()=>{_t([T],T.sessionId,T.distilled)},children:z===T.sessionId?s("Distilling…"):T.distilled?s("Distill again"):s("Distill")})]},T.sessionId))})}),e.jsx(Ie,{children:e.jsx(It,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:s("Close")})})]})})}),e.jsx(pe,{open:F!==null,onOpenChange:T=>!T&&Q(null),children:e.jsx(fe,{children:F&&e.jsxs(e.Fragment,{children:[e.jsxs(ge,{children:[e.jsx(je,{children:s("Some sessions were already distilled")}),e.jsx(Ue,{children:s("{{label}}: {{total}} sessions, {{done}} already distilled. Re-distilling runs the model again and may add new memories alongside the existing ones.",{label:F.label,total:String(F.scope.length),done:String(F.scope.length-F.pending.length)})})]}),e.jsxs(Ie,{children:[e.jsx(It,{render:e.jsx(A,{variant:"ghost",size:"sm"}),children:s("Cancel")}),e.jsx(A,{variant:F.pending.length>0?"default":"outline",size:"sm",disabled:F.pending.length===0,onClick:()=>{const T=F;Q(null),_t(T.pending,T.token)},children:s("Only the {{count}} remaining",{count:String(F.pending.length)})}),e.jsx(A,{variant:F.pending.length>0?"outline":"default",size:"sm",onClick:()=>{const T=F;Q(null),_t(T.scope,T.token,!0)},children:s("Re-distill all {{count}}",{count:String(F.scope.length)})})]})]})})}),e.jsxs("section",{className:"space-y-2","data-settings-row":"memory.jobs",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"font-medium text-sm",children:s("Background tasks")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[C.kgFailed>0&&e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>{window.electronAPI.memory.retryFailedKgJobs().then(()=>ke.current?.())},children:s("Retry failed extractions ({{count}})",{count:String(C.kgFailed)})}),pt.some(T=>T.state!=="running")&&e.jsx(A,{size:"sm",variant:"ghost",title:s("Removes completed and cancelled jobs. Running tasks are kept. Sessions will show as not distilled again, since that flag is derived from job history — re-distilling is deduplicated, so it will not create duplicate memories."),onClick:()=>{window.electronAPI.memory.clearJobs()},children:s("Clear finished tasks")}),pt.length>br&&e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>xt(!Ne),children:Ne?s("Show less"):s("Show all {{count}}",{count:String(pt.length)})})]})]}),pt.length===0?e.jsx("p",{className:"text-muted-foreground text-sm",children:s("Nothing running.")}):e.jsx("ul",{className:"divide-y rounded-lg border",children:(Ne?pt:pt.slice(0,br)).map(T=>e.jsxs("li",{className:"space-y-1 px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Z,{variant:T.state==="failed"?"destructive":"secondary",children:s(yx[T.kind])}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:T.target}),e.jsx("span",{className:K("shrink-0 text-xs",T.state==="failed"?"text-destructive":"text-muted-foreground"),children:T.state==="running"?`⋯ ${T.detail}`:T.detail})]}),T.notes.map(be=>e.jsxs("p",{className:"pl-1 text-muted-foreground text-xs",children:["· ",be]},be))]},T.key))})]})]})}function vt({label:t,value:s,action:n}){return e.jsxs("div",{className:"rounded-lg border px-3 py-2",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-sm",children:s}),n]})]})}function Ix(t,s){if(s===null)return{ok:!0,value:null};if(t.type==="boolean")return typeof s=="boolean"?{ok:!0,value:s}:s==="true"||s==="false"?{ok:!0,value:s==="true"}:{ok:!1,error:"需要打开或关闭"};if(typeof s!="string")return{ok:!1,error:"值不合法"};if(t.type==="number"){const n=s.trim();if(!/^-?\d+(\.\d+)?$/.test(n))return{ok:!1,error:"需要数字"};const a=Number(n);return Number.isFinite(a)?t.min!==void 0&&a<t.min?{ok:!1,error:"小于最小值"}:t.max!==void 0&&a>t.max?{ok:!1,error:"大于最大值"}:{ok:!0,value:a}:{ok:!1,error:"需要数字"}}return t.type==="enum"?t.options?.includes(s)?{ok:!0,value:s}:{ok:!1,error:"不在可选项里"}:s.length>4096||s.includes("\0")?{ok:!1,error:"值不合法"}:{ok:!0,value:s}}const Ax={"agent.tool":"运行 Agent 工具","ui.slot":"在界面挂载组件","ui.view":"打开侧栏页面","ui.notify":"发送系统通知","composer.draft":"读写输入框草稿","fs.read":"读取声明的文件","fs.write":"写入声明的文件","net.fetch":"访问声明的域名","mcp.server":"启动声明的 MCP 服务","mcp.call":"调用宿主 MCP 工具","agent.observe":"观察会话事件","agent.intercept":"拦截并改写会话事件","agent.inject":"向会话发送消息,并可触发该会话继续执行;默认只发到发起调用的会话,允许后可发到任意运行中的会话","process.background":"常驻后台并拉起子进程","plugin.call":"调用其他插件","ui.clipboard":"写入剪贴板","ui.openExternal":"用浏览器打开链接","session.read":"查看本项目的会话列表与运行状态(标题、活动时间、是否在等你)","session.readAll":"查看所有项目的会话列表与运行状态","session.focus":"在你点击时切换到本项目的会话","session.create":"在你点击时于本项目新建会话"};function li(t){return Ax[t]??t}function Ex(t){const s=new Set;for(const n of t)for(const a of n.tags){const r=a.trim();r&&s.add(r)}return[...s].sort((n,a)=>n.localeCompare(a))}function Mx(t,s){const n=s.query.trim().toLowerCase(),a=s.category?.trim()||null;return t.filter(r=>a&&!r.tags.some(o=>o.trim()===a)?!1:n?[r.id,r.name,r.description,...r.tags].some(o=>o.toLowerCase().includes(n)):!0)}function Px({disabled:t,installedKey:s,onInstall:n}){const{t:a}=U(),r=window.electronAPI.extensionPlugins,[o,i]=m.useState(null),[c,d]=m.useState(!1),[x,h]=m.useState(""),[u,p]=m.useState(null),l=m.useCallback(async v=>{d(!0);try{i(await r.marketList(v))}catch(k){i({ok:!1,error:k instanceof Error?k.message:String(k),chinaMirror:!1})}finally{d(!1)}},[r]);m.useEffect(()=>{l(!1)},[l,s]);const f=async v=>{await r.setMarketChinaMirror(v),await l(!0)},g=o?.ok===!0?o.plugins:[],y=Ex(g),N=u!==null&&y.includes(u)?u:null,j=Mx(g,{query:x,category:N});return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{value:x,placeholder:a("Search plugins"),onChange:v=>h(v.target.value)}),e.jsxs("label",{className:"flex shrink-0 items-center gap-1.5 text-muted-foreground text-xs",children:[e.jsx(oe,{checked:o?.chinaMirror??!1,disabled:c,onCheckedChange:v=>{f(v)}}),a("China mirror")]}),e.jsx(A,{size:"sm",variant:"ghost",disabled:c,onClick:()=>{l(!0)},children:c?e.jsx(Nt,{}):a("Refresh")})]}),y.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1",children:[e.jsx(A,{size:"xs",variant:N===null?"secondary":"outline","aria-pressed":N===null,onClick:()=>p(null),children:a("All")}),y.map(v=>e.jsx(A,{size:"xs",variant:N===v?"secondary":"outline","aria-pressed":N===v,onClick:()=>p(v),children:v},v))]}),o?.ok===!1&&e.jsx("p",{className:"text-destructive text-sm",children:o.error}),o?.ok===!0&&o.stale&&e.jsx("p",{className:"text-muted-foreground text-xs",children:a("Could not reach the marketplace; showing the last saved list.")}),o?.ok===!0&&j.length===0&&e.jsx("p",{className:"text-muted-foreground text-sm",children:a("No matching plugins")}),j.map(v=>e.jsxs("div",{className:"flex items-start gap-3 py-1",children:[e.jsx(Tx,{src:v.icon}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-0.5",children:[e.jsxs("p",{className:"truncate text-sm",children:[v.name,e.jsx("span",{className:"ml-2 text-muted-foreground text-xs",children:v.latest}),e.jsx(Z,{variant:v.tier==="official"?"secondary":"outline",className:"ml-2",children:v.tier==="official"?a("Official"):a("Community")})]}),v.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:v.description}),v.permissions.length>0&&e.jsx("p",{className:"text-muted-foreground text-xs",children:v.permissions.map(k=>li(k)).join("、")})]}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx(A,{"aria-hidden":!0,tabIndex:-1,size:"sm",variant:"outline",className:"pointer-events-none invisible",children:a("Installed")}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:v.installedVersion&&!v.updateAvailable?e.jsx("span",{className:"whitespace-nowrap font-medium text-base text-muted-foreground sm:text-sm",children:a("Installed")}):e.jsx(A,{size:"sm",variant:"outline",className:"size-full",disabled:t,onClick:()=>n(v.id),children:v.updateAvailable?a("Update"):a("Install")})})]})]},v.id))]})}function Tx({src:t}){const[s,n]=m.useState(!1);return e.jsx("div",{className:"flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",children:t&&!s?e.jsx("img",{src:t,alt:"",className:"size-5 object-contain",onError:()=>n(!0)}):e.jsx(Lt,{className:"size-4 text-muted-foreground"})})}function Rx(t){const{notice:s,remote:n,onDismiss:a}=t;return e.jsxs("div",{className:"space-y-1 rounded-md border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-amber-700 text-sm dark:text-amber-400",children:[s.unreadable&&e.jsx("p",{children:"插件登记表曾读取失败,下面的列表可能不全。插件文件没有删除,原文保存在数据目录的 extension-plugins/registry.json.unreadable。"}),s.discarded.length>0&&e.jsxs("p",{children:["检测到旧格式的登记记录,已丢弃并清理,请重新安装:",e.jsx("span",{className:"font-mono",children:s.discarded.join(", ")})]}),n?e.jsx("p",{className:"text-muted-foreground",children:"请在桌面端点「知道了」,或运行 enso-server plugin notice-dismiss 清除此提示。"}):e.jsx(A,{size:"sm",variant:"outline",onClick:a,children:"知道了"})]})}function Ox({pluginId:t,plain:s}){const{t:n}=U(),[a,r]=m.useState([]),[o,i]=m.useState({}),[c,d]=m.useState(null),x=m.useCallback(async()=>{const l=await window.electronAPI.extensionPlugins.configGet(t);l.ok?r(l.fields):d({error:!0,text:l.error}),i({})},[t]);m.useEffect(()=>{x()},[x]);const h=async()=>{const l={};for(const[g,y]of Object.entries(o)){const N=a.find(v=>v.key===g);if(!N||N.secret&&y==="")continue;const j=Ix(N,y);if(!j.ok){d({error:!0,text:`${N.title}:${j.error}`});return}l[g]=j.value}const f=await window.electronAPI.extensionPlugins.configSet(t,l);d(f.ok?{error:!1,text:n("Saved. New calls use it right away.")}:{error:!0,text:f.error??""}),f.ok&&await x()},u=l=>{const f=o[l.key];return typeof f=="string"?f:f===null||l.secret?"":l.value??(l.default!==void 0?String(l.default):"")},p=l=>{const f=o[l.key];return typeof f=="boolean"?f:(l.value??(typeof l.default=="boolean"?String(l.default):"false"))==="true"};return e.jsxs("div",{className:K("space-y-2",s?"":"rounded-md border border-border p-3"),children:[a.map(l=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-sm",children:[l.title,e.jsx("span",{className:"ml-2 font-mono text-muted-foreground text-xs",children:l.key})]}),l.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:l.description}),l.secret||l.type==="string"||l.type==="number"||l.type==="path"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{type:l.secret?"password":l.type==="number"?"number":"text",autoComplete:"off",inputMode:l.type==="number"?"decimal":void 0,min:l.type==="number"?l.min:void 0,max:l.type==="number"?l.max:void 0,value:u(l),placeholder:l.secret&&l.set?n("Set (leave blank to keep)"):n("Not set"),onChange:f=>i(g=>({...g,[l.key]:f.target.value}))}),l.type==="path"&&!l.secret&&!window.electronAPI.remote&&e.jsx(A,{size:"sm",variant:"outline",onClick:()=>{window.electronAPI.extensionPlugins.pickPath(l.pathKind==="directory"?"directory":"file").then(f=>{f.ok&&"path"in f&&i(g=>({...g,[l.key]:f.path}))})},children:l.pathKind==="directory"?"选择文件夹":"选择文件"}),l.set&&e.jsx(A,{size:"sm",variant:"ghost",onClick:()=>i(f=>({...f,[l.key]:null})),children:n("Clear value")})]}):l.type==="boolean"?e.jsx(oe,{checked:p(l),onCheckedChange:f=>i(g=>({...g,[l.key]:f}))}):e.jsxs(ee,{items:Object.fromEntries((l.options??[]).map(f=>[f,f])),value:u(l),onValueChange:f=>{typeof f=="string"&&i(g=>({...g,[l.key]:f}))},children:[e.jsx(te,{children:e.jsx(se,{placeholder:"请选择"})}),e.jsx(ne,{children:(l.options??[]).map(f=>e.jsx(X,{value:f,children:f},f))})]})]},l.key)),c&&e.jsx("p",{className:K("text-xs",c.error?"text-destructive":"text-muted-foreground"),children:c.text}),e.jsx(A,{size:"sm",disabled:Object.keys(o).length===0,onClick:()=>{h()},children:n("Save")})]})}function Dx({pluginId:t,plain:s}){const{t:n}=U(),[a,r]=m.useState(null),o=m.useCallback(async()=>{const i=await window.electronAPI.extensionPlugins.logs(t);r(i.ok?i.text:i.error)},[t]);return m.useEffect(()=>{o()},[o]),e.jsxs("div",{className:K("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:n("Plugin logs")}),e.jsx(A,{size:"icon",variant:"ghost","aria-label":n("Refresh"),onClick:()=>{o()},children:e.jsx(rt,{className:"size-4"})})]}),e.jsx("pre",{className:"max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-muted-foreground text-xs",children:a===null?"":a||n("No logs yet")})]})}function kr({message:t}){const[s,n]=m.useState(!1);return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:K("select-text break-all font-mono text-destructive text-xs",s?"max-h-48 overflow-auto whitespace-pre-wrap":"line-clamp-2"),children:t}),t.length>120&&e.jsx("button",{type:"button",className:"text-muted-foreground text-xs hover:text-foreground",onClick:()=>n(a=>!a),children:s?"收起":"展开全部"})]})}function ci({permissions:t,styles:s=!1}){return t.length===0?s?null:e.jsx("p",{className:"text-muted-foreground text-xs",children:"无特殊权限"}):e.jsx("ul",{className:"space-y-0.5",children:t.map(n=>e.jsxs("li",{className:"text-xs",children:[e.jsx("span",{className:"font-mono text-muted-foreground",children:n}),e.jsx("span",{className:"ml-2",children:li(n)})]},n))})}function Lx(t){const s=t.intervalSeconds>=60&&t.intervalSeconds%60===0?`每 ${t.intervalSeconds/60} 分钟`:`每 ${t.intervalSeconds} 秒`,n=t.lastRunAt?` · 最近 ${new Date(t.lastRunAt).toLocaleString()}`:"";return`${t.id} · ${s}${n}${t.lastError?` · ${t.lastError}`:""}`}function Cr(t){return[t.permissions.length>0?`${t.permissions.length} 项权限`:"",(t.events?.length??0)>0?`${t.events?.length} 个事件`:"",(t.schedules?.length??0)>0?`${t.schedules?.length} 个定时任务`:"",t.crossSessionInject!==void 0?"跨会话投递开关":""].filter(Boolean).join(" · ")}function Sr({permissions:t,env:s,interop:n,resident:a,running:r,styles:o,events:i,schedules:c}){return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ci,{permissions:t,styles:o}),a&&e.jsxs("p",{className:"text-xs",children:["常驻进程",r===void 0?"":r?":运行中":":未运行"]}),o&&e.jsx("p",{className:"text-xs",children:"修改界面样式:主题 CSS 可以改变应用的任意界面"}),(s?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["环境变量:",e.jsx("span",{className:"font-mono",children:s?.join(", ")})]}),(n?.length??0)>0&&e.jsxs("p",{className:"text-xs",children:["可调用插件:",e.jsx("span",{className:"font-mono",children:n?.join(", ")})]}),i?.map(d=>e.jsxs("p",{className:"text-xs",children:["事件 ",d.event," · ",d.mode==="intercept"?"拦截":"观察",d.failClosed?" · 失败即拒绝":""]},`${d.event}:${d.mode}`)),c?.map(d=>e.jsxs("p",{className:"text-xs",children:["定时任务 ",Lx(d)]},d.id))]})}function zx({pluginId:t,plain:s}){const[n,a]=m.useState(null),[r,o]=m.useState(null),i=m.useCallback(async()=>{const c=await window.electronAPI.extensionPlugins.artifactsList(t);c.ok?(a(c.artifacts),o(null)):o(c.error)},[t]);return m.useEffect(()=>{i()},[i]),e.jsxs("div",{className:K("space-y-2",s?"":"rounded-md border border-border p-3"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-sm",children:"产出文件"}),e.jsx(A,{size:"icon",variant:"ghost","aria-label":"刷新",onClick:()=>{i()},children:e.jsx(rt,{className:"size-4"})})]}),r&&e.jsx("p",{className:"text-destructive text-xs",children:r}),e.jsx(wc,{artifacts:n??[],onDelete:c=>{window.electronAPI.extensionPlugins.artifactDelete(c).then(d=>{d.ok?i():o(d.error??"删除失败")})}})]})}const Hs=new Set;function Bx({requestedInstallUrl:t=null,onRequestedInstallUrlConsumed:s}={}){const{t:n}=U(),[a,r]=m.useState([]),o=An(D=>D.errors),[i,c]=m.useState(null),[d,x]=m.useState(null),[h,u]=m.useState([]),[p,l]=m.useState(!1),[f,g]=m.useState(null),[y,N]=m.useState(""),[j,v]=m.useState(!1),[k,R]=m.useState(!1),[L,S]=m.useState(null),[O,w]=m.useState(null),[M,E]=m.useState(!1),I=m.useCallback(async()=>{try{r(await window.electronAPI.extensionPlugins.list())}catch{r([])}},[]);m.useEffect(()=>(I(),window.electronAPI.extensionPlugins.registryNotice().then(w).catch(()=>w(null)),window.electronAPI.extensionPlugins.onChanged(()=>{I()})),[I]);const B=async D=>{g(null),i&&window.electronAPI.extensionPlugins.discard(i.token),c(null);const q=await window.electronAPI.extensionPlugins.pickAndStage(D);q.ok?"cancelled"in q||c(q.preview):g(q.error)},C=async D=>{const q=(D??y).trim();if(!q)return;g(null),v(!0),i&&window.electronAPI.extensionPlugins.discard(i.token),c(null);const P=await window.electronAPI.extensionPlugins.stageFromUrl(q).finally(()=>{v(!1)});P.ok?c(P.preview):g(P.error)},_=m.useRef(C);_.current=C,m.useEffect(()=>{if(!t)return;const D=t;let q=!1;const P=window.setTimeout(()=>{q||Hs.has(D)||(Hs.add(D),N(D),s?.(),_.current(D).finally(()=>{Hs.delete(D)}))},0);return()=>{q=!0,window.clearTimeout(P)}},[t,s]);const V=async(D,q=!1)=>{g(null),i&&window.electronAPI.extensionPlugins.discard(i.token),c(null),v(!0);const P=window.electronAPI.extensionPlugins,Y=await(q?P.marketStage(D):P.restage(D)).finally(()=>{v(!1)});Y.ok?c(Y.preview):g(Y.error)},H=async()=>{R(!0),S(null);try{const D=await window.electronAPI.extensionPlugins.checkUpdates();S(D.checked===0?n("No plugins installed from GitHub to check"):D.available>0?n("{{count}} update(s) available",{count:D.available}):n("All plugins are up to date"))}finally{R(!1)}},$=async()=>{if(!i)return;l(!0);const D=await window.electronAPI.extensionPlugins.commit(i.token);if(l(!1),!D.ok)g(D.error??n("Install failed"));else{N("");const q=i.existingVersion?{ok:!0}:await window.electronAPI.extensionPlugins.setEnabled(i.id,!0);Be({type:q.ok?"success":"warning",title:n("{{name}} installed",{name:i.name}),description:q.ok?void 0:q.error})}c(null)},re=()=>{i&&window.electronAPI.extensionPlugins.discard(i.token),c(null)};return e.jsxs("div",{className:"space-y-5","data-settings-row":"plugins.enso",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[n("Enso plugins"),e.jsx(qe,{})]}),e.jsx("p",{className:"mt-1 text-muted-foreground text-sm",children:n("Installing a plugin lets it run code on this machine. Review what it asks for before confirming.")})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[a.some(D=>D.source?.kind==="url"||D.source?.kind==="market")&&e.jsxs(A,{size:"sm",variant:"outline",disabled:k,onClick:()=>{H()},children:[k?e.jsx(Nt,{}):e.jsx(rt,{className:"size-4"}),n("Check for updates")]}),e.jsxs(A,{size:"sm",onClick:()=>E(!0),children:[e.jsx(au,{className:"size-4"}),n("Marketplace")]})]})]}),e.jsxs("div",{className:"space-y-2.5 rounded-lg border bg-muted/30 p-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(wo,{className:"flex-1",children:[e.jsx(ko,{children:e.jsx(Fo,{className:"size-4 text-muted-foreground"})}),e.jsx(No,{value:y,placeholder:n("https://github.com/owner/repo"),onChange:D=>N(D.target.value),onKeyDown:D=>{D.key==="Enter"&&C()}})]}),e.jsx(A,{size:"sm",variant:"outline",disabled:p||j||y.trim()==="",onClick:()=>{C()},children:j?e.jsx(Nt,{}):n("Install from URL")})]}),e.jsxs("div",{className:"flex items-center gap-1 text-muted-foreground text-xs",children:[e.jsx("span",{className:"mr-1",children:n("Or install from")}),e.jsxs(A,{size:"xs",variant:"ghost",disabled:p||j,onClick:()=>{B("dir")},children:[e.jsx(Mn,{className:"size-3.5"}),n("Install from folder")]}),e.jsxs(A,{size:"xs",variant:"ghost",disabled:p||j,onClick:()=>{B("zip")},children:[e.jsx(gc,{className:"size-3.5"}),n("Install from zip")]})]})]}),f&&e.jsx("p",{className:"text-destructive text-sm",children:f}),e.jsx(pe,{open:M,onOpenChange:E,children:e.jsxs(fe,{className:"max-w-2xl",children:[e.jsx(ge,{children:e.jsx(je,{children:n("Marketplace")})}),e.jsx(Se,{children:e.jsx(Px,{disabled:p||j,installedKey:a.map(D=>`${D.id}@${D.version}`).join(","),onInstall:D=>{E(!1),V(D,!0)}})})]})}),L&&e.jsx("p",{className:"text-muted-foreground text-sm",children:L}),O&&e.jsx(Rx,{notice:O,remote:!!window.electronAPI.remote,onDismiss:()=>{window.electronAPI.extensionPlugins.dismissRegistryNotice().then(()=>w(null)).catch(D=>g(D instanceof Error?D.message:String(D)))}}),e.jsx(pe,{open:i!==null,onOpenChange:D=>!D&&!p&&re(),children:e.jsx(fe,{children:i&&e.jsxs(e.Fragment,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[i.name," ",i.version,i.existingVersion&&e.jsx("span",{className:"ml-2 text-base text-muted-foreground",children:n("updating from {{version}}",{version:i.existingVersion})})]})}),e.jsxs(Se,{className:"space-y-3",children:[e.jsx(Sr,{permissions:i.permissions,env:i.env,interop:i.interop,resident:i.resident,styles:i.styles,events:i.events,schedules:i.schedules}),i.mcpServers.map(D=>e.jsxs("p",{className:"font-mono text-xs",children:[D.command," ",D.args.join(" ")]},D.name)),i.mcpTools.length>0&&e.jsxs("p",{className:"text-muted-foreground text-xs",children:[n("Host MCP tools it may call"),":",e.jsx("span",{className:"font-mono",children:i.mcpTools.join(", ")})]}),i.warnings.map(D=>e.jsx("p",{className:"text-muted-foreground text-xs",children:D},D))]}),e.jsxs(Ie,{children:[e.jsx(A,{size:"sm",variant:"ghost",disabled:p,onClick:re,children:n("Cancel")}),e.jsx(A,{size:"sm",disabled:p,onClick:()=>{$()},children:p?e.jsx(Nt,{}):n("Install")})]})]})})}),a.length===0&&!i&&e.jsxs("div",{className:"rounded-lg border border-dashed px-3 py-10 text-center",children:[e.jsx(Lt,{className:"mx-auto size-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:n("No Enso plugins installed")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:n("Browse the marketplace or install from a GitHub URL, folder or zip.")})]}),e.jsx("div",{className:"space-y-2",children:a.map(D=>e.jsxs("div",{className:K("overflow-hidden rounded-lg border bg-card transition-colors",D.state==="crashed"&&"border-destructive/50"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 p-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("div",{className:K("flex size-9 shrink-0 items-center justify-center rounded-md bg-muted",D.state==="enabled"?"text-foreground":"text-muted-foreground"),children:e.jsx(jc,{pluginId:D.id,icon:D.icon,className:"size-4"})}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[e.jsx("span",{className:"truncate font-medium",children:D.name}),e.jsx(Z,{variant:"outline",className:"text-[11px]",children:D.version}),D.state==="crashed"&&e.jsx(Z,{variant:"destructive",className:"text-[11px]",children:n("Stopped after crashes")}),D.availableVersion&&e.jsx(Z,{className:"text-[11px]",children:n("Update")}),D.pendingVersion&&e.jsx(Z,{variant:"warning",className:"text-[11px]",children:"待授权"}),D.resident&&e.jsx(Z,{variant:D.running?"secondary":"outline",className:"text-[11px]",children:D.running?"常驻运行中":"常驻未运行"})]}),e.jsx("p",{className:"truncate font-mono text-muted-foreground text-xs",children:D.id}),D.availableVersion&&e.jsxs("p",{className:"mt-1 flex items-center gap-2 text-primary text-xs",children:[n("Version {{version}} is available",{version:D.availableVersion}),e.jsx(A,{size:"xs",disabled:p||j,onClick:()=>{V(D.id)},children:j?e.jsx(Nt,{}):n("Update")})]}),D.updateCheckError&&e.jsx("p",{className:"text-muted-foreground text-xs",children:n("Update check failed: {{reason}}",{reason:D.updateCheckError})}),D.lastError&&e.jsx(kr,{message:D.lastError.message}),o[D.id]?.map(q=>e.jsx(kr,{message:`主题加载失败:${q}`},q)),D.pendingVersion&&e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 rounded-md border border-amber-500/50 bg-amber-500/10 px-2 py-1.5 text-amber-700 text-xs dark:text-amber-400",children:[n("{{version}} asks for more and is waiting for approval",{version:D.pendingVersion}),e.jsx(A,{size:"xs",onClick:()=>{window.electronAPI.extensionPlugins.approvePending(D.id)},children:n("Allow")}),e.jsx(A,{size:"xs",variant:"ghost",onClick:()=>{window.electronAPI.extensionPlugins.rejectPending(D.id)},children:n("Keep current")})]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[D.source&&e.jsx(A,{size:"icon",variant:"ghost",disabled:p||j,"aria-label":n("Reinstall from source"),title:D.source.kind==="url"?`${n("Reinstall from source")}: ${D.source.url}`:n("Reinstall from source"),onClick:()=>{V(D.id)},children:e.jsx(vc,{className:"size-4"})}),e.jsx(A,{size:"icon",variant:"ghost","aria-label":"产出文件",title:"产出文件",onClick:()=>x({kind:"artifacts",pluginId:D.id,pluginName:D.name}),children:e.jsx(bc,{className:"size-4"})}),e.jsx(A,{size:"icon",variant:"ghost","aria-label":n("Plugin logs"),title:n("Plugin logs"),onClick:()=>x({kind:"logs",pluginId:D.id,pluginName:D.name}),children:e.jsx(Rn,{className:"size-4"})}),D.configurable&&e.jsx(A,{size:"icon",variant:"ghost","aria-label":n("Configure"),title:n("Configure"),onClick:()=>x({kind:"config",pluginId:D.id,pluginName:D.name}),children:e.jsx(yc,{className:"size-4"})}),e.jsx(A,{size:"icon",variant:"ghost","aria-label":n("Uninstall"),title:n("Uninstall"),className:"text-muted-foreground hover:text-destructive",onClick:()=>{window.electronAPI.extensionPlugins.uninstall(D.id)},children:e.jsx(Ae,{className:"size-4"})}),e.jsx("div",{className:"mx-1.5 h-5 w-px bg-border"}),e.jsx(oe,{checked:D.state==="enabled",onCheckedChange:q=>{window.electronAPI.extensionPlugins.setEnabled(D.id,q)}})]})]}),e.jsxs("button",{type:"button","aria-expanded":h.includes(D.id),className:K("flex w-full items-center gap-1 border-t bg-muted/20 px-3 py-1.5 text-left text-xs","text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground"),onClick:()=>u(q=>q.includes(D.id)?q.filter(P=>P!==D.id):[...q,D.id]),children:[h.includes(D.id)?e.jsx(Yt,{className:"size-3"}):e.jsx(At,{className:"size-3"}),h.includes(D.id)?"收起详情":"详情",!h.includes(D.id)&&Cr(D)&&e.jsx("span",{className:"ml-1 opacity-70",children:Cr(D)})]}),h.includes(D.id)&&e.jsxs("div",{className:"space-y-3 border-t px-3 py-3",children:[D.interceptBreakers?.map(q=>e.jsxs("p",{className:"text-amber-600 text-xs dark:text-amber-400",children:[q.event," 检查连续失败,临时放行到"," ",new Date(q.until).toLocaleTimeString()]},q.event)),e.jsx(Sr,{permissions:D.permissions,resident:D.resident,running:D.running,styles:D.themes.some(q=>q.css!==void 0),events:D.events,schedules:D.schedules}),D.crossSessionInject!==void 0&&e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[e.jsxs("span",{children:[e.jsx("span",{className:"block",children:"允许向任意运行中的会话发送消息"}),e.jsx("span",{className:"block text-muted-foreground",children:"关闭时只能发到发起调用的会话;开启后定时任务、常驻进程也能向其他项目和窗口的会话发消息并触发执行"})]}),e.jsx(oe,{"aria-label":"允许向任意运行中的会话发送消息",checked:D.crossSessionInject,onCheckedChange:q=>{window.electronAPI.extensionPlugins.setCrossSessionInject(D.id,q)}})]}),D.pendingPermissions&&D.pendingPermissions.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:"待同意的权限"}),e.jsx(ci,{permissions:D.pendingPermissions})]})]})]},D.id))}),e.jsx(pe,{open:d!==null,onOpenChange:D=>!D&&x(null),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsxs(je,{children:[d?.kind==="config"?n("Configure"):d?.kind==="logs"?n("Plugin logs"):"产出文件",d?` · ${d.pluginName}`:""]})}),e.jsxs(Se,{className:"space-y-4",children:[d?.kind==="config"&&e.jsx(Ox,{pluginId:d.pluginId,plain:!0}),d?.kind==="logs"&&e.jsx(Dx,{pluginId:d.pluginId,plain:!0}),d?.kind==="artifacts"&&e.jsx(zx,{pluginId:d.pluginId,plain:!0})]})]})})]})}function _x(t,s){return[[t.skills.length,s("Skills")],[t.commands.length,s("Commands")],[t.agents.length,s("Agent types")],[t.mcpServers.length,"MCP"],[t.hooks.length,"Hooks"]].filter(([n])=>n>0).map(([n,a])=>`${a} ${n}`).join(" · ")}function bt({label:t,items:s}){return s.length===0?null:e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t}),s.map(n=>e.jsx("p",{className:"break-all font-mono text-[11px]",children:n},n))]})}function Fx({plugin:t,entry:s,onToggle:n}){const{t:a}=U(),[r,o]=m.useState(!1),{components:i}=t,c=_x(i,a);return e.jsxs("div",{className:"rounded-md border","data-settings-row":`plugins.${t.key}`,children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 px-3 py-2",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>o(d=>!d),children:[e.jsx(At,{className:K("h-4 w-4 shrink-0 text-muted-foreground transition-transform",r&&"rotate-90")}),e.jsx("span",{className:"shrink-0 font-medium text-sm",children:t.name}),t.version&&e.jsx(Z,{variant:"outline",className:"shrink-0 text-[11px]",children:t.version}),t.marketplace&&e.jsx(Z,{variant:"secondary",className:"shrink-0 text-[11px]",children:t.marketplace}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:c||(i.unsupported.length>0?`${a("Not supported")}: ${i.unsupported.join(", ")}`:a("No supported components"))})]}),e.jsx(oe,{checked:s?.enabled===!0,onCheckedChange:n})]}),r&&e.jsxs("div",{className:"space-y-2 border-t px-3 py-2",children:[t.description&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t.description}),e.jsx(bt,{label:a("Skills"),items:i.skills}),e.jsx(bt,{label:a("Commands"),items:i.commands.map(d=>`/${d}`)}),e.jsx(bt,{label:a("Agent types"),items:i.agents}),e.jsx(bt,{label:a("MCP servers (run when a session starts)"),items:i.mcpServers.map(d=>`${d.name}: ${d.target}`)}),e.jsx(bt,{label:a("Hooks (run automatically on local sessions)"),items:i.hooks.map(d=>`${d.event}: ${d.command}`)}),e.jsx(bt,{label:a("Not supported"),items:i.unsupported})]})]})}function Ux(){const{t}=U(),s=b(l=>l.plugins),n=b(l=>l.addPlugins),a=b(l=>l.setPluginEnabled),r=b(l=>l.removePlugin),[o,i]=m.useState(null),c=m.useCallback(async()=>{i(null);try{i(await window.electronAPI.assets.listInstalledPlugins())}catch{i([])}},[]);m.useEffect(()=>{c()},[c]);const d=new Map(s.map(l=>[l.key,l])),x=new Set((o??[]).map(l=>l.key)),h=o?s.filter(l=>!x.has(l.key)):[],u=s.filter(l=>l.enabled).length,p=(l,f)=>{const g=d.get(l.key);if(g){a(g.id,f);return}n([{id:crypto.randomUUID(),key:l.key,name:l.name,description:l.description,...l.version?{version:l.version}:{},source:l.marketplace||"Claude Code",enabled:f}])};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"plugins.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Claude Code plugins"),e.jsx(qe,{}),u>0&&e.jsx("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:t("{{count}} enabled",{count:u})})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Plugins installed in Claude Code. Each one is switched on or off as a whole here; changes apply to new sessions.")})]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:c,disabled:o===null,children:[e.jsx(rt,{className:"mr-1.5 h-4 w-4"}),t("Rescan")]})]}),o===null?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(Nt,{className:"size-5"})}):o.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Lt,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No Claude Code plugins found")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Install plugins with /plugin in Claude Code, then rescan.")})]}):e.jsx("div",{className:"space-y-2",children:o.map(l=>e.jsx(Fx,{plugin:l,entry:d.get(l.key),onToggle:f=>p(l,f)},l.key))}),h.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground text-xs",children:t("No longer installed in Claude Code")}),h.map(l=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 hover:bg-accent/50",children:[e.jsx("span",{className:"text-muted-foreground text-sm line-through",children:l.name}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive",onClick:()=>r(l.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]},l.id))]})]})}const Ot={mask:"Mask",warn:"Warn only",block:"Block"},$x={email:"Email",phone:"Phone number",idCard:"ID card number",bankCard:"Bank card number",ip:"IP address"},xn={mask:"text-sky-600 dark:text-sky-400",warn:"text-amber-600 dark:text-amber-400",block:"text-red-600 dark:text-red-400"},Vx=[1,7,30],Kx={1:"Today",7:"7D",30:"30D"};function qx(t){const s=new Map;for(const n of t.report.hits){const a=s.get(n.token);a?a.count+=n.count:s.set(n.token,{label:`${n.kind} ${n.preview}`,count:n.count})}return[...s.values()].map(n=>n.count>1?`${n.label} ×${n.count}`:n.label).join(", ")}function Ws({value:t,onChange:s}){const{t:n}=U(),a=Object.fromEntries(Object.keys(Ot).map(r=>[r,n(Ot[r])]));return e.jsxs(ee,{items:a,value:t,onValueChange:r=>s(r),children:[e.jsx(te,{className:"w-32",children:e.jsx(se,{})}),e.jsx(ne,{children:Object.entries(a).map(([r,o])=>e.jsx(X,{value:r,children:o},r))})]})}function Js({label:t,hint:s,value:n,onCommit:a,rowId:r}){const[o,i]=m.useState(n.join(`
24
- `));return m.useEffect(()=>i(n.join(`
25
- `)),[n]),e.jsxs("div",{className:"space-y-1.5","data-settings-row":r,children:[e.jsx("p",{className:"text-sm",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s}),e.jsx(Xe,{rows:3,value:o,onChange:c=>i(c.target.value),onBlur:()=>a(o.split(`
26
- `))})]})}function kt({title:t,children:s}){return e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsx("p",{className:"text-sm font-medium",children:t}),s]})}function Gx({settings:t}){const{t:s}=U(),[n,a]=m.useState(""),r=m.useMemo(()=>kc(n,t),[n,t]);return e.jsxs(kt,{title:s("Try it"),children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("Runs locally. Nothing is remembered or sent anywhere.")}),e.jsx(Xe,{rows:3,value:n,placeholder:s("Paste some text, e.g. an .env file"),onChange:o=>a(o.target.value)}),n&&e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-48 overflow-auto whitespace-pre-wrap rounded bg-muted p-2 text-xs",children:r.text}),e.jsxs("ul",{className:"space-y-0.5 text-xs",children:[r.report.hits.map(o=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:K("font-medium",xn[o.action]),children:s(Ot[o.action])}),e.jsx("span",{children:o.kind}),e.jsx("span",{className:"text-muted-foreground",children:o.preview}),o.count>1&&e.jsxs("span",{className:"text-muted-foreground",children:["×",o.count]})]},`${o.token}-${o.action}`)),r.report.hits.length===0&&e.jsx("li",{className:"text-muted-foreground",children:s("Nothing matched")})]})]})]})}function Hx(){const{t}=U(),[s,n]=m.useState(7),[a,r]=m.useState(null),[o,i]=m.useState(!1),c=m.useRef(0),d=Cc(p=>p.conversations),x=m.useCallback(async p=>{const l=++c.current;i(!0);const f=await window.electronAPI.privacyMask.records(p).catch(()=>[]);l===c.current&&(i(!1),r(f))},[]);m.useEffect(()=>{x(s)},[s,x]);const h=m.useMemo(()=>{const p={mask:0,warn:0,block:0},l=new Map;for(const f of a??[]){const g=new Set;for(const y of f.report.hits){const N=`${y.action}:${y.token}`;g.has(N)||(g.add(N),p[y.action]+=1,l.set(y.kind,(l.get(y.kind)??0)+1))}}return{byAction:p,byKind:[...l].sort((f,g)=>g[1]-f[1])}},[a]),u=p=>{if(p.source==="aux")return t("Auxiliary request");const l=p.sessionId?d[p.sessionId]?.title:void 0,f=p.source==="compaction"?t("Compaction"):t("Session");return l?`${f} · ${l}`:f};return e.jsxs(kt,{title:t("Records"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex gap-1",children:Vx.map(p=>e.jsx(A,{size:"sm",variant:p===s?"secondary":"ghost",onClick:()=>n(p),children:t(Kx[p])},p))}),e.jsx(A,{variant:"ghost",size:"icon-sm",onClick:()=>{x(s)},disabled:o,"aria-label":t("Refresh"),children:e.jsx(rt,{className:K("size-4",o&&"animate-spin")})})]}),e.jsx("div",{className:"flex flex-wrap gap-4 text-sm",children:Object.keys(Ot).map(p=>e.jsxs("span",{children:[e.jsx("span",{className:xn[p],children:t(Ot[p])})," ",e.jsx("span",{className:"font-medium tabular-nums",children:h.byAction[p]})]},p))}),h.byKind.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:h.byKind.map(([p,l])=>e.jsxs("span",{className:"rounded bg-muted px-1.5 py-0.5",children:[p," ",l]},p))}),e.jsxs("div",{className:"max-h-80 overflow-auto",children:[e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"text-left text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Requested at")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Source")}),e.jsx("th",{className:"py-1 pr-2 font-normal",children:t("Model")}),e.jsx("th",{className:"py-1 font-normal",children:t("Hits")})]})}),e.jsx("tbody",{children:(a??[]).slice(0,200).map(p=>{const l=Sc(p.report),f=`${p.at}:${p.sessionId??p.source}:${p.model}:${p.report.hits.map(g=>g.token).join(",")}`;return e.jsxs("tr",{className:"border-t align-top",children:[e.jsx("td",{className:"py-1 pr-2 whitespace-nowrap tabular-nums",children:new Date(p.at).toLocaleString()}),e.jsx("td",{className:"py-1 pr-2",children:u(p)}),e.jsx("td",{className:"py-1 pr-2 break-all",children:p.model}),e.jsxs("td",{className:K("py-1",l&&xn[l]),children:[qx(p),p.report.blocked&&` · ${t("Request blocked")}`]})]},f)})})]}),a?.length===0&&e.jsx("p",{className:"py-4 text-center text-xs text-muted-foreground",children:t("No records yet")})]})]})}function Wx(){const{t}=U(),s=b(r=>r.privacyMasking),n=b(r=>r.setPrivacyMasking),a=r=>n({...s,...r});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Privacy")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Replace API keys and personal data with placeholders before requests leave this device, and restore them in replies. Original values stay in memory on this device only.")})]}),e.jsx(Pe,{rowId:"privacy.enabled",title:t("Privacy masking"),description:t("Applies to chats, compaction, bot members and helper requests."),checked:s.enabled,onChange:r=>a({enabled:r})}),s.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs(kt,{title:t("Secrets"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("API keys, tokens, private keys, passwords in URLs and config files.")}),e.jsx(Ws,{value:s.secrets.action,onChange:r=>a({secrets:{...s.secrets,action:r}})})]}),e.jsx(Pe,{rowId:"privacy.secrets",title:t("Detect secrets"),description:t("Recommended. Covers common vendor key formats."),checked:s.secrets.enabled,onChange:r=>a({secrets:{...s.secrets,enabled:r}})}),e.jsx(Pe,{rowId:"privacy.shape",title:t("Send look-alike keys"),description:t("Replace keys with fake keys of the same format instead of placeholders, so the model treats them as real keys."),checked:s.secrets.shape,onChange:r=>a({secrets:{...s.secrets,shape:r}})})]}),e.jsxs(kt,{title:t("Personal data"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Emails, phone numbers, ID and bank card numbers, IP addresses.")}),e.jsx(Ws,{value:s.personal.action,onChange:r=>a({personal:{...s.personal,action:r}})})]}),e.jsx(Pe,{rowId:"privacy.personal",title:t("Detect personal data"),description:t("Matches are validated (checksums, real domains) to limit false hits."),checked:s.personal.enabled,onChange:r=>a({personal:{...s.personal,enabled:r}})}),s.personal.enabled&&e.jsx("div",{className:"flex flex-wrap gap-4",children:Nc.map(r=>e.jsxs("label",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(We,{checked:s.personal.kinds.includes(r),onCheckedChange:o=>a({personal:{...s.personal,kinds:o?[...s.personal.kinds,r]:s.personal.kinds.filter(i=>i!==r)}})}),t($x[r])]},r))})]}),e.jsxs(kt,{title:t("Custom rules"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Words and patterns specific to your work.")}),e.jsx(Ws,{value:s.custom.action,onChange:r=>a({custom:{...s.custom,action:r}})})]}),e.jsx(Js,{rowId:"privacy.words",label:t("Words"),hint:t("One per line, case-insensitive. Project codenames, customer names…"),value:s.custom.words,onCommit:r=>a({custom:{...s.custom,words:r}})}),e.jsx(Js,{rowId:"privacy.rules",label:t("Prefixes or patterns"),hint:t("One per line. A prefix like corp_ or a regex like /INC-\\d{4}/i."),value:s.custom.rules,onCommit:r=>a({custom:{...s.custom,rules:r}})})]}),e.jsx(kt,{title:t("Allow list"),children:e.jsx(Js,{rowId:"privacy.allow",label:t("Never mask"),hint:t("Exact values, one per line. Team emails, test keys…"),value:s.allow,onCommit:r=>a({allow:r})})}),e.jsx(Gx,{settings:s})]}),e.jsx(Hx,{})]})}function Jx(){const{t}=U(),s=b(l=>l.approvalReviewer),n=b(l=>l.setApprovalReviewer),a=b(l=>l.approvalAutoManage),r=b(l=>l.setApprovalAutoManage),o=Ic(b(l=>l.approvalAllowThreshold)),i=b(l=>l.setApprovalAllowThreshold),c={"0.85":t("0.85 (looser)"),"0.9":t("0.9 (default)"),"0.95":t("0.95 (stricter)")},d=Je(),x=Pn(),h=m.useMemo(()=>[...d,...x.filter(on)],[d,x]),u=s?h.find(l=>l.id===s.providerId):void 0,p=u?.models.find(l=>l.id===s?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Assistant approval model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Required before Assistant approval can be selected. Does not fall back to the chat model.")})]}),h.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx($e,{providers:h,providerId:u?.id??"",modelId:p?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("No assistant approval model selected"),side:"bottom",triggerClassName:Ze,onSelect:(l,f)=>n({providerId:l,modelId:f}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),u&&on(u)&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t(a?"Auto-managed: runs only when the decision model is highly confident it is safe. Everything else is denied and the agent tries another way. Protected actions still ask you.":"Decision models only allow or block when highly confident. Everything else asks you.")}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-manage approvals")}),e.jsx(oe,{"aria-label":t("Auto-manage approvals"),checked:a,onCheckedChange:r})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("span",{className:"text-sm",children:t("Auto-allow threshold")}),e.jsxs(ee,{items:c,value:String(o),onValueChange:l=>i(Number(l)),children:[e.jsx(te,{className:"w-36","aria-label":t("Auto-allow threshold"),children:e.jsx(se,{})}),e.jsx(ne,{children:Ac.map(l=>e.jsx(X,{value:String(l),children:c[String(l)]},l))})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Only runs automatically when the allow probability reaches this value. Operations near the threshold may be allowed one time and not the next.")})]}),s&&(!u||!p)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable")}),s&&e.jsx(A,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>n(null),children:t("Clear")})]})}function Ir(t,s){const n=s.find(r=>r.id===t.providerId),a=n?.models.find(r=>r.id===t.modelId);return`${n?.name??t.providerId} / ${a?.label??t.modelId}`}function Yx(){const{t}=U(),s=ss(),n=b(R=>R.virtualModels),a=b(R=>R.defaultModel),r=b(R=>R.setDefaultModel),o=b(R=>R.defaultModelFollowLast),i=b(R=>R.setDefaultModelFollowLast),c=b(R=>R.defaultReasoningEnabled),d=b(R=>R.defaultThinkingLevel),x=b(R=>R.setDefaultReasoningEnabled),h=b(R=>R.setDefaultThinkingLevel),u=Qt(R=>R.snapshot),p=Ec(R=>R.latest),l=Je(),f=a?l.find(R=>R.id===a.providerId):void 0,g=f?.models.find(R=>R.id===a?.modelId),y=s.some(R=>!!R.oauthAccountKey),N=y&&(u.availability.status==="unloaded"||u.availability.status==="loading"),j=y&&u.availability.status==="error"?u.availability.error:null,v=p?.notice,k=v?t("Default model changed: {{previous}} → {{next}}",{previous:Ir(v.previous,s),next:v.next?Ir(v.next,s):t("No default model")}):null;return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Default model")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t(o?"New conversations use the last model you picked.":"Used for new conversations.")})]}),l.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx($e,{providers:l,virtualModels:n,providerId:f?.id??a?.providerId??"",modelId:g?.id??a?.modelId??"",reasoningEnabled:c,thinkingLevel:d,emptyLabel:t("Select model"),triggerLabel:o?t("Follow last selection"):void 0,side:"bottom",triggerClassName:Ze,onSelect:(R,L)=>r({providerId:R,modelId:L}),onReasoningChange:x,onThinkingChange:h,showReasoningControls:!o})}),!o&&l.length>0&&e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"self-start",onClick:()=>i(!0),children:t("Follow last selection")}),l.length===0&&e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-5 text-center",children:[e.jsx(Dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-2 font-medium text-sm",children:t("No usable models")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]}),(N||j)&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-muted px-2.5 py-2 text-xs",children:[e.jsx(St,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:j?t("Subscription credentials could not be loaded: {{error}}",{error:j}):t("Subscription credentials are loading. API-key models remain available.")})]}),k&&e.jsx("p",{className:"rounded-md bg-muted px-2.5 py-2 text-muted-foreground text-xs",children:k})]})}function Qx({provider:t,onClose:s}){const{t:n}=U(),a=b(g=>g.providers),r=b(g=>g.updateProvider),o=Co(g=>g.snapshot),i=m.useMemo(()=>So([t],o)[0]?.models??t.models,[t,o]),c=Qt(g=>g.snapshot.availability),d=Qt(g=>g.snapshot.revision),[x,h]=m.useState([]),[u,p]=m.useState(t.oauthAccountPool?.accountKeys??[]);m.useEffect(()=>{let g=!1;return window.electronAPI.providers.listOauth().then(y=>{g||h(y)}).catch(y=>{g||(h([]),console.error("Failed to load OAuth account metadata",y))}),()=>{g=!0}},[d]);const l=Po(a),f=[...l.flatMap(g=>g.oauthAccountKey??[]),...u.filter(g=>!l.some(y=>y.oauthAccountKey===g))];return e.jsx(Io,{initialValue:{...t,name:Ln(t,n),models:i},oauth:!0,hideName:!0,saveDisabled:u.length===0,oauthAccountKey:t.oauthAccountKey,onCancel:s,extraFields:e.jsxs(ce,{children:[e.jsx(de,{children:n("Pool members")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n("Use enabled, signed-in accounts in the listed order. Model and reasoning stay unchanged. Main agents and subagents share this pool.")}),e.jsx("div",{className:"mt-2 w-full space-y-1 rounded-md border p-1",children:f.map((g,y)=>{const N=l.find(v=>v.oauthAccountKey===g),j=x.flatMap(v=>v.accounts).find(v=>v.key===g);return e.jsxs("label",{className:"flex min-w-0 items-center gap-2 px-2 py-1.5 text-sm",children:[e.jsx(We,{checked:u.includes(g),onCheckedChange:v=>p(k=>v?[...k,g]:k.filter(R=>R!==g))}),e.jsxs("span",{className:"shrink-0 text-xs text-muted-foreground",children:[y+1,"."]}),e.jsx("span",{className:"min-w-0 truncate",children:j?.email??g}),!N?.enabled&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account disabled")}),c.status==="ready"&&!c.authenticatedAccountKeys.has(g)&&e.jsx("span",{className:"shrink-0 text-xs text-muted-foreground",children:n("Account signed out")})]},g)})})]}),onSave:g=>{u.length!==0&&(r(t.id,{models:Ao(g.models,Mo(o,t.oauthAccountKey??"")?.models,Eo(b.getState(),t.id)),oauthAccountPool:{accountKeys:f.filter(y=>u.includes(y))}}),s())}})}function Xx({provider:t,onClose:s}){const{t:n}=U(),a=b(i=>i.updateProvider),r=Co(i=>i.snapshot),o=m.useMemo(()=>t?.oauthAccountKey?So([t],r)[0]?.models??t.models:t?.models,[t,r]);return e.jsx(pe,{open:t!==null,onOpenChange:i=>!i&&s(),children:e.jsxs(fe,{children:[e.jsx(ge,{children:e.jsx(je,{children:t?.oauthAccountPool?Ln(t,n):n("Edit Provider")})}),t?.oauthAccountPool?e.jsx(Qx,{provider:t,onClose:s},t.id):t&&e.jsx(Io,{initialValue:{name:t.name,api:t.api,apiKey:t.apiKey,baseUrl:t.baseUrl,models:o??t.models},oauth:!!t.oauthAccountKey,oauthAccountKey:t.oauthAccountKey,onCancel:s,onSave:i=>{a(t.id,t.oauthAccountKey?{name:i.name,models:Ao(i.models,Mo(r,t.oauthAccountKey)?.models,Eo(b.getState(),t.id))}:i),s()}},t.id)]})})}const Zx=(t,s)=>t.models.some(n=>n.id===s&&n.enabled!==!1),Ar=()=>{};function Er(t){return t==="on"||t==="off"}function Ys(t){return typeof t=="string"&&Rc.includes(t)}function ep(){const{t}=U(),s=b(u=>u.subagentModelsEnabled),n=b(u=>u.subagentModels),a=b(u=>u.setSubagentModelsEnabled),r=b(u=>u.addSubagentModel),o=b(u=>u.updateSubagentModel),i=b(u=>u.removeSubagentModel),c=b(u=>u.defaultModel),d=Je(),x=m.useMemo(()=>{if(c){const u=d.find(p=>p.id===c.providerId);if(u&&Zx(u,c.modelId))return c}for(const u of d){const p=u.models.find(l=>l.enabled!==!1);if(p)return{providerId:u.id,modelId:p.id}}return null},[d,c]),h=()=>{window.electronAPI.window.summonAgent({typeKey:Pc,prompt:t(Tc)})};return e.jsxs("section",{"data-slot":"subagent-models",className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Let the agent pick subagent models")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("The main agent can pick one of these models when dispatching subagents or coworkers. The description tells it when to use each model.")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Applies to newly started conversations.")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2.5",children:[e.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-7 gap-1 px-2.5 text-xs",onClick:h,children:[e.jsx(zn,{className:"h-3.5 w-3.5 text-primary"}),t("Auto configure with AI")]}),e.jsx(oe,{checked:s,onCheckedChange:a})]})]}),s&&e.jsxs("div",{className:"space-y-1.5",children:[n.map(u=>e.jsxs("div",{"data-slot":"subagent-model-row",className:K("flex items-center gap-2 rounded-md border px-2 py-1.5",u.enabled===!1&&"bg-muted/50 text-muted-foreground"),children:[e.jsx(oe,{"data-slot":"subagent-model-enabled","aria-label":t("Enable subagent model"),title:t("Make this model available to subagents"),checked:u.enabled!==!1,onCheckedChange:p=>o(u.id,{enabled:p})}),u.enabled===!1&&e.jsx(Z,{variant:"outline",className:"shrink-0 text-[10px] text-muted-foreground",children:t("Disabled")}),e.jsx("div",{className:"shrink-0 rounded-md border bg-background",children:e.jsx($e,{providers:d,providerId:u.providerId,modelId:u.modelId,modelCapabilityOverrides:Mc(u),reasoningMode:Er(u.reasoning)?u.reasoning:"follow",reasoningEnabled:u.reasoning==="on",thinkingLevel:Ys(u.thinkingLevel)?u.thinkingLevel:"medium",onReasoningModeChange:(p,l)=>{p==="follow"?o(u.id,{reasoning:void 0,thinkingLevel:void 0}):p==="on"&&!Ys(u.thinkingLevel)?o(u.id,{reasoning:"on",thinkingLevel:l}):o(u.id,{reasoning:p})},onSelect:(p,l)=>o(u.id,{providerId:p,modelId:l}),onReasoningChange:p=>o(u.id,{reasoning:p?"on":"off"}),onThinkingChange:p=>o(u.id,{thinkingLevel:p}),onReasoningNormalize:Er(u.reasoning)?p=>o(u.id,{reasoning:p?"on":"off"}):Ar,onThinkingNormalize:Ys(u.thinkingLevel)?p=>o(u.id,{thinkingLevel:p}):Ar})}),e.jsx(J,{value:u.description,placeholder:t("When to use it, e.g. cheap and fast for simple subtasks"),className:"h-7 flex-1 text-xs",onChange:p=>o(u.id,{description:p.target.value})}),e.jsx(A,{type:"button",variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 text-muted-foreground hover:text-destructive",onClick:()=>i(u.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]},u.id)),e.jsxs(A,{type:"button",variant:"outline",size:"sm",className:"h-7 text-xs",disabled:!x,onClick:()=>{x&&r({...x,description:""})},children:[e.jsx(Ee,{className:"mr-1 h-3.5 w-3.5"}),t("Add model")]}),!x&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Enable a model and configure valid provider credentials first.")})]})]})}function tp(){const{t}=U(),s=b(d=>d.titleSummaryEnabled),n=b(d=>d.setTitleSummaryEnabled),a=b(d=>d.titleSummaryModel),r=b(d=>d.setTitleSummaryModel),o=Je(),i=a?o.find(d=>d.id===a.providerId):void 0,c=i?.models.find(d=>d.id===a?.modelId);return e.jsxs("section",{className:"space-y-2 rounded-lg border bg-card p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h4",{className:"font-medium text-sm",children:t("Conversation title summary")}),e.jsx("p",{className:"mt-0.5 text-muted-foreground text-xs",children:t("Generate a short AI title from the first message of a new conversation.")})]}),e.jsx(oe,{checked:s,onCheckedChange:n})]}),s&&e.jsxs("div",{className:"space-y-2",children:[o.length>0&&e.jsx("div",{className:"w-full min-w-0",children:e.jsx($e,{providers:o,providerId:i?.id??"",modelId:c?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the default model"),side:"bottom",triggerClassName:Ze,onSelect:(d,x)=>r({providerId:d,modelId:x}),onReasoningChange:()=>{},onThinkingChange:()=>{}})}),a&&(!i||!c)&&e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Selected model is unavailable — falls back to the default model.")}),a&&e.jsx(A,{variant:"ghost",size:"sm",className:"self-start",onClick:()=>r(null),children:t("Follow default model")})]})]})}function sp({accountKey:t}){const s=$c(t);return!s||s.error?null:e.jsx(Vc,{info:s})}function np(){const{t}=U(),s=b(w=>w.providers),n=ss(),a=b(w=>w.updateProvider),r=b(w=>w.addProviders),o=b(w=>w.removeProvider),[i,c]=m.useState(!1),[d,x]=m.useState(!1),[h,u]=m.useState(null),[p,l]=m.useState(null),[f,g]=m.useState(null),[y,N]=m.useState(null),j=Qt(w=>w.snapshot.revision),[v,k]=m.useState([]);m.useEffect(()=>{let w=!1;return window.electronAPI.providers.listOauth().then(M=>{w||k(M)}),()=>{w=!0}},[j]);const R=m.useMemo(()=>Oc(s,v),[s,v]),L=m.useMemo(()=>{const w=new Map;for(const M of n)w.set(M.id,M.models.length);return w},[n]),S=async(w,M)=>{if(g(w.id),N(null),w.oauthAccountKey&&!w.oauthAccountPool&&!M?.skipLogout)try{await window.electronAPI.providers.oauthLogout(w.oauthAccountKey),await Kc()}catch(E){g(null),N({providerId:w.id,message:E instanceof Error?E.message:String(E)});return}o(w.id),g(null),N(null)},O=()=>{const w=p;w&&S(w)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"providers.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-lg font-medium",children:[t("Model Providers"),e.jsx(qe,{note:t("Newly enabled models can be picked right away. After changing a key or address, an open session uses it once you switch its model or start a new session.")})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Manage model API providers for this app")})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>c(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1.5"}),t("Import from local apps")]}),e.jsxs(A,{size:"sm",onClick:()=>x(!0),children:[e.jsx(Ee,{className:"h-4 w-4 mr-1.5"}),t("Add model or provider")]})]})]}),e.jsx(Yx,{}),e.jsx(gm,{}),e.jsx(tp,{}),e.jsx(Jx,{}),e.jsx(ep,{}),Po(s).length>0&&!s.some(w=>w.oauthAccountPool)&&e.jsxs("div",{className:"space-y-1.5 rounded-md border p-3",children:[e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>{const w=Dc(s,crypto.randomUUID());w&&r([w])>0&&u(w)},children:[e.jsx(Ee,{className:"mr-1.5 h-3.5 w-3.5"}),t("Create ChatGPT account pool")]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Pool entries do not show a single account quota. Fixed-account entries remain unchanged.")})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Dn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 text-sm font-medium",children:t("No providers yet")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Import providers from local apps or use the unified setup to get started")})]}):e.jsx("div",{className:"space-y-1",children:R.map(w=>{const M=v.find(I=>I.id===w.vendorId),E=w.vendorId===Lc?t("Custom"):w.label;return e.jsxs("div",{className:"rounded-md px-3 py-2",children:[e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-semibold tracking-wide text-muted-foreground",children:E}),e.jsx("span",{className:"text-[11px] text-muted-foreground/60",children:w.providers.length})]}),e.jsx("div",{className:"mt-1.5 space-y-1 border-l pl-3",children:w.providers.map(I=>{const B=!!I.oauthAccountKey,C=L.get(I.id)??I.models.length,_=I.oauthAccountKey&&!I.oauthAccountPool?M?.accounts.find(H=>H.key===I.oauthAccountKey):void 0,V=I.oauthAccountPool?Ln(I,t):B?_?.email??I.oauthAccountKey??I.name:I.name;return e.jsxs(m.Fragment,{children:[e.jsxs("div",{className:"group flex items-start justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`providers.${I.id}`,children:[e.jsxs("div",{className:"min-w-0 flex-1 overflow-hidden",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[B?e.jsx(zc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Bc,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsx("span",{className:K("truncate text-sm font-medium",!I.enabled&&"text-muted-foreground line-through"),children:V}),B?_?.plan&&e.jsx(Z,{variant:"outline",className:"shrink-0 text-[10px] uppercase",children:_.plan}):e.jsx(Z,{variant:"outline",className:"shrink-0 text-[11px]",children:_c[I.api]??I.api}),I.importedFrom&&e.jsx(Z,{variant:"secondary",className:"shrink-0 text-[11px]",children:I.importedFrom}),e.jsx("span",{className:"min-w-0 truncate text-xs text-muted-foreground",children:[B?void 0:I.baseUrl,I.oauthAccountPool?t("{{count}} accounts",{count:I.oauthAccountPool.accountKeys.length}):void 0,C>0?t("{{count}} models",{count:C}):void 0].filter(Boolean).join(" · ")})]}),on(I)&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t("Classification only, not for chat")}),I.oauthAccountKey&&!I.oauthAccountPool&&e.jsx(sp,{accountKey:I.oauthAccountKey})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1 pt-0.5",children:[e.jsx(oe,{checked:I.enabled,onCheckedChange:H=>a(I.id,{enabled:H})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",onClick:()=>u(I),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",disabled:f===I.id,className:K("h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",f===I.id&&"opacity-100"),onClick:()=>l(I),children:f===I.id?e.jsx(Te,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]}),y?.providerId===I.id&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-destructive/30 bg-destructive/5 px-3 py-1.5 text-xs text-destructive",children:[e.jsx("span",{className:"min-w-0 truncate",children:t("Sign-out failed: {{message}}",{message:y.message})}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(A,{variant:"outline",size:"sm",className:"h-6 px-2 text-[11px]",onClick:()=>{S(I)},children:t("Retry")}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[11px] text-destructive hover:text-destructive",onClick:()=>{S(I,{skipLogout:!0})},children:t("Delete anyway")})]})]})]},I.id)})})]},w.vendorId)})}),e.jsx(Fc,{open:i,onOpenChange:c}),e.jsx(Uc,{open:d,onOpenChange:x}),e.jsx(Xx,{provider:h,onClose:()=>u(null)}),e.jsx(so,{open:p!==null,onOpenChange:w=>{w||l(null)},title:t("Remove provider?"),description:p?p.oauthAccountKey&&!p.oauthAccountPool?t("Removing this also signs out {{name}}. Other accounts for the same vendor stay signed in.",{name:p.name}):t('This permanently deletes the "{{name}}" provider configuration.',{name:p.name}):void 0,confirmLabel:t("Remove"),onConfirm:O})]})}const ap=2e3,Mr=50,Pt="",rp=[{id:"app",label:"App processes"},{id:"agent",label:"Agent and tools"},{id:"child",label:"Other child processes"}],pn={sessions:["Conversation history","Conversation transcripts and usage ledger."],coworkers:["Coworker transcripts","Coworker journals; only those of deleted conversations are cleaned."],toolOutputs:["Tool outputs","Saved long tool outputs; only those of deleted conversations are cleaned."],memory:["Memory","Memory database and working memory."],models:["Local models","Downloaded embedding, chat and speech models."],runtimes:["Runtimes","Bundled tools, speech runtime and GPU backends."],worktrees:["Worktrees","Isolated worktrees created for conversations."],snapshots:["Change snapshots","Baselines for the Changes panel."],browser:["Browser data","Cookies, storage and cache of the built-in browser."],cache:["Cache","Rebuildable caches; cleaning is safe."],logs:["Logs","Task and memory logs; files written in the last 24 hours are kept."],backups:["Backups","Configuration backup files; files from the last 24 hours are kept."],config:["Configuration","Settings, instructions, prompts and credentials."],other:["Other","Chromium profile data and other files."]};function op(t,s){switch(t){case"main":return s("Main process");case"window":return s("Window");case"browser":return s("Built-in browser");case"gpu":return"GPU";case"service":return s("Service");case"agent":return"Agent";case"tool":return s("Tool");default:return s("Child process")}}function ip(t,s){return t.id==="data"?s("App data"):s("Worktree directory")}function lp(t,s){return t.role!=="window"?t.name:t.name==="Main window"?s("Main window"):t.name==="Settings"?s("Settings"):t.name}function cp(t){return`${t.toFixed(1)}%`}function dp(){const{t}=U(),[s,n]=m.useState("cpu");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Resources")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("CPU, memory and disk usage of EnsoCode and the processes it started.")})]}),e.jsxs(zt,{value:s,onValueChange:a=>n(a),children:[e.jsxs(Bt,{children:[e.jsx(Ke,{value:"cpu",children:"CPU"}),e.jsx(Ke,{value:"memory",children:t("RAM")}),e.jsx(Ke,{value:"storage",children:t("Storage")})]}),e.jsx(Tt,{value:"cpu",className:"pt-4",children:s==="cpu"&&e.jsx(Pr,{metric:"cpu"})}),e.jsx(Tt,{value:"memory",className:"pt-4",children:s==="memory"&&e.jsx(Pr,{metric:"memory"})}),e.jsx(Tt,{value:"storage",className:"pt-4",children:s==="storage"&&e.jsx(mp,{})})]})]})}function Pr({metric:t}){const{t:s}=U(),[n,a]=m.useState(null),[r,o]=m.useState(null);if(m.useEffect(()=>{let x=!1,h;const u=async()=>{try{const p=await window.electronAPI.resources.sample();if(x)return;a(p),o(null)}catch(p){x||o(p instanceof Error?p.message:String(p))}x||(h=setTimeout(u,ap))};return u(),()=>{x=!0,clearTimeout(h)}},[]),r&&!n)return e.jsx("p",{className:"text-sm text-destructive",children:r});if(!n)return e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Loading...")});const i=t==="cpu"?cp:ie,c=t==="cpu"?{app:n.cpu.app,system:n.cpu.system,total:100}:n.memory,d=x=>t==="cpu"?x.cpu:x.memory;return e.jsxs("div",{className:"space-y-4",children:[e.jsx(di,{app:c.app,system:Math.max(c.system,c.app),total:c.total,format:i}),rp.map(x=>{const h=n.processes.filter(u=>u.group===x.id).sort((u,p)=>d(p)-d(u));return h.length===0?null:e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-3 py-2 text-sm font-medium",children:[e.jsx("span",{children:s(x.label)}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i(h.reduce((u,p)=>u+d(p),0))})]}),e.jsx("div",{className:"divide-y",children:h.map(u=>e.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 truncate text-xs text-muted-foreground",children:op(u.role,s)}),e.jsx("span",{className:"min-w-0 flex-1 truncate",title:u.command??u.name,children:lp(u,s)}),e.jsx("span",{className:"w-16 text-right font-mono text-xs text-muted-foreground",children:u.pid}),e.jsx("span",{className:"w-20 text-right font-mono text-xs",children:i(d(u))})]},u.pid))})]},x.id)})]})}function di({app:t,system:s,total:n,format:a}){const{t:r}=U(),o=i=>`${n>0?Math.min(100,i/n*100):0}%`;return e.jsxs("div",{className:"space-y-3 rounded-lg border p-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"EnsoCode"}),e.jsx("div",{className:"font-mono text-2xl font-semibold",children:a(t)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:r("System")}),e.jsxs("div",{className:"font-mono text-sm",children:[a(s)," / ",a(n)]})]})]}),e.jsxs("div",{className:"relative h-2 overflow-hidden rounded-full bg-muted",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground/25",style:{width:o(s)}}),e.jsx("div",{className:"absolute inset-y-0 left-0 bg-foreground",style:{width:o(t)}})]})]})}function up(t,s){const n=[s("Freed {{size}}",{size:ie(t.freedBytes)})];return t.removed>0&&n.push(s("{{count}} files removed",{count:t.removed})),t.skipped>0&&n.push(s("{{count}} kept",{count:t.skipped})),t.failed>0&&n.push(s("{{count}} failed",{count:t.failed})),n.join(" · ")}function mp(){const{t}=U(),[s,n]=m.useState(null),[a,r]=m.useState("scan"),[o,i]=m.useState(null),[c,d]=m.useState(null),[x,h]=m.useState(null),[u,p]=m.useState(null),l=m.useCallback(async(j,v)=>{r(j),d(null),i(null);try{n(await v())}catch(k){const R=k instanceof Error?k.message:String(k);R.includes("Scan cancelled")||d(R)}finally{r(null),i(null)}},[]),f=m.useCallback(()=>l("scan",()=>window.electronAPI.resources.scanStorage()),[l]),g=j=>l(j,async()=>{const v=await window.electronAPI.resources.cleanStorage(j);return Be({type:v.failed>0?"warning":"success",title:t("{{name}} cleaned",{name:t(pn[j][0])}),description:up(v,t)}),v.snapshot});m.useEffect(()=>{const j=window.electronAPI.resources.onScanProgress(i);return window.electronAPI.resources.lastStorage().then(v=>{v&&n(k=>k??v)}),f(),()=>{j(),window.electronAPI.resources.cancelScan()}},[f]);const y=s?[...s.categories].filter(j=>j.bytes>0).sort((j,v)=>v.bytes-j.bytes):[],N=m.useMemo(()=>{const j=new Map;for(const v of s?.roots??[])j.set(v.volumeId,[...j.get(v.volumeId)??[],v]);return[...j.values()]},[s]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("p",{className:"min-w-0 truncate text-xs text-muted-foreground",children:a==="scan"?o?t("Scanning {{count}} files · {{size}}",{count:o.files.toLocaleString(),size:ie(o.bytes)}):t("Scanning..."):s?t("Scanned at {{time}} · took {{seconds}}s",{time:new Date(s.scannedAt).toLocaleTimeString(),seconds:(s.durationMs/1e3).toFixed(1)}):null}),a==="scan"?e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>{window.electronAPI.resources.cancelScan()},children:t("Cancel")}):e.jsx(A,{variant:"ghost",size:"icon-sm",onClick:()=>{f()},disabled:a!==null,"aria-label":t("Refresh"),children:e.jsx(rt,{})})]}),c&&e.jsx("p",{className:"text-sm text-destructive",children:c}),s&&s.errorCount>0&&e.jsxs("p",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",title:s.errors.join(`
27
- `),children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),t("{{count}} paths could not be read and are not counted.",{count:s.errorCount})]}),s&&e.jsxs(e.Fragment,{children:[N.map(j=>{const v=j[0]?.volume,k=j.reduce((R,L)=>R+L.bytes,0);return e.jsxs("div",{className:"space-y-2",children:[v?e.jsx(di,{app:k,system:v.total-v.free,total:v.total,format:ie}):e.jsx("div",{className:"rounded-lg border p-4 font-mono text-2xl font-semibold",children:ie(k)}),j.map(R=>e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs",children:[e.jsx("span",{className:"shrink-0 text-muted-foreground",children:ip(R,t)}),e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono",title:R.path,children:R.path}),e.jsx("span",{className:"font-mono",children:ie(R.bytes)})]},R.id))]},j[0]?.volumeId)}),e.jsx("div",{className:"divide-y rounded-lg border",children:y.map(j=>e.jsx(hp,{category:j,share:s.totalBytes>0?j.bytes/s.totalBytes:0,expanded:x===j.id,onToggle:()=>h(x===j.id?null:j.id),cleaning:a===j.id,disabled:a!==null,onClean:()=>To[j.id]==="confirm"?p(j.id):void g(j.id)},j.id))}),e.jsx(xp,{sessions:s.sessions,busy:a==="sessions",disabled:a!==null,onClean:j=>l("sessions",async()=>{const v=await window.electronAPI.resources.cleanSessions(j);return Be({type:"success",title:t("{{count}} conversations deleted",{count:v.removed})}),v.snapshot})})]}),e.jsx(yn,{open:u!==null,onOpenChange:j=>!j&&p(null),children:e.jsxs(wn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Nn,{children:[e.jsx(kn,{className:"text-base",children:t("Clean {{name}}?",{name:u?t(pn[u][0]):""})}),e.jsx(Cn,{children:t(u==="browser"?"You will be signed out of sites opened in the built-in browser.":"Deleted files cannot be restored.")})]}),e.jsxs(Sn,{variant:"bare",children:[e.jsx(In,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:t("Cancel")}),e.jsx(A,{variant:"destructive",size:"sm",onClick:()=>{const j=u;p(null),j&&g(j)},children:t("Clean")})]})]})})]})}function hp({category:t,share:s,expanded:n,onToggle:a,cleaning:r,disabled:o,onClean:i}){const{t:c}=U(),[d,x]=pn[t.id];return e.jsxs("div",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:a,className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[e.jsx(At,{className:K("h-4 w-4 shrink-0 transition-transform",n&&"rotate-90")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"font-medium",children:c(d)}),e.jsx("span",{className:"font-mono text-xs",children:ie(t.bytes)})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:c(x)}),e.jsx("div",{className:"mt-1 h-1 overflow-hidden rounded-full bg-muted",children:e.jsx("div",{className:"h-full bg-foreground/60",style:{width:`${s*100}%`}})})]})]}),To[t.id]!=="none"&&e.jsx(A,{variant:"outline",size:"sm",disabled:o,onClick:i,children:c(r?"Cleaning...":"Clean")})]}),n&&e.jsx("div",{className:"mt-2 space-y-0.5 pl-6",children:t.entries.map(h=>e.jsxs("div",{className:"group flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-muted-foreground",children:h.root==="data"?h.path:`${c("Worktree directory")}/${h.path}`}),e.jsx("span",{className:"font-mono",children:ie(h.bytes)}),e.jsx(A,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100","aria-label":c("Show in folder"),onClick:()=>{window.electronAPI.resources.revealStorage(h.root,h.path)},children:e.jsx(Mn,{})})]},`${h.root}:${h.path}`))})]})}function xp({sessions:t,busy:s,disabled:n,onClean:a}){const{t:r}=U(),[o,i]=m.useState(!1),[c,d]=m.useState(!1),[x,h]=m.useState(null),[u,p]=m.useState(Pt),l=m.useMemo(()=>new Map(t.map(w=>[w.id,w])),[t]),f=m.useMemo(()=>{const w=new Map;for(const M of t){const E=w.get(M.projectId)??{name:M.projectName,bytes:0,count:0};E.bytes+=M.bytes,E.count+=1,w.set(M.projectId,E)}return[...w].sort((M,E)=>E[1].bytes-M[1].bytes)},[t]),g=f.some(([w])=>w===u)?u:Pt,y=g?t.filter(w=>w.projectId===g):t,N=w=>{const M=Jc(t,w,Date.now());return{request:w,count:M.length,bytes:M.reduce((E,I)=>E+(l.get(I)?.bytes??0),0)}},j=w=>N({kind:"stale",days:w,includeUnarchived:o,...g?{projectId:g}:{}}),v=y.reduce((w,M)=>w+M.bytes,0),k=c?y:y.slice(0,Mr),R=(w,M)=>M||(w?w.slice(0,8):r("No project")),L=x?.request.kind==="one"?l.get(x.request.id):void 0,S=x?.request.kind==="stale"?x.request.projectId:void 0,O=S===void 0?void 0:R(S,f.find(([w])=>w===S)?.[1].name??"");return e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b px-3 py-2",children:[e.jsxs("div",{className:"shrink-0 text-sm font-medium",children:[r("Conversations"),e.jsxs("span",{className:"ml-2 font-mono text-xs text-muted-foreground",children:[y.length," · ",ie(v)]})]}),e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsxs(ee,{items:{[Pt]:r("All projects"),...Object.fromEntries(f.map(([w,M])=>[w,R(w,M.name)]))},value:g,onValueChange:w=>p(w??Pt),children:[e.jsx(te,{size:"sm",className:"w-48 min-w-0",children:e.jsx(se,{})}),e.jsxs(ne,{children:[e.jsx(X,{value:Pt,children:r("All projects")}),f.map(([w,M])=>e.jsx(X,{value:w,children:e.jsxs("span",{className:"flex w-full items-center gap-3",children:[e.jsx("span",{className:"flex-1 truncate",children:R(w,M.name)}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[M.count," · ",ie(M.bytes)]})]})},w))]})]}),e.jsxs(Ro,{children:[e.jsxs(Oo,{render:e.jsx(A,{variant:"outline",size:"sm",disabled:n||y.length===0}),children:[e.jsx(qc,{}),r(s?"Cleaning...":"Clean")]}),e.jsxs(Do,{align:"end",className:"min-w-48",children:[e.jsx(Gc,{checked:o,onCheckedChange:i,closeOnClick:!1,children:r("Include unarchived")}),e.jsx(Hc,{}),[...Wc,0].map(w=>{const M=j(w);return e.jsxs(Lo,{variant:"destructive",disabled:M.count===0,onClick:()=>h(M),children:[e.jsx("span",{className:"flex-1",children:w>0?r("Older than {{days}} days",{days:w}):r("All")}),e.jsx("span",{className:"font-mono text-xs opacity-70",children:M.count})]},w)})]})]})]})]}),e.jsx("div",{className:"max-h-96 divide-y overflow-y-auto",children:k.map(w=>e.jsxs("div",{className:"group flex items-center gap-3 px-3 py-1.5 text-sm",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",title:w.title,children:w.title||r("Untitled")}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:[w.projectName,w.archived?r("Archived"):null,new Date(w.lastActiveAt).toLocaleDateString()].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-xs",children:ie(w.bytes)}),e.jsx(A,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover:opacity-100",disabled:n,"aria-label":r("Delete"),onClick:()=>h({request:{kind:"one",id:w.id},count:1,bytes:w.bytes}),children:e.jsx(Ae,{})})]},w.id))}),y.length>Mr&&e.jsx("button",{type:"button",onClick:()=>d(!c),className:"w-full border-t px-3 py-1.5 text-xs text-muted-foreground hover:text-foreground",children:r(c?"Show less":"Show all")}),e.jsx(yn,{open:x!==null,onOpenChange:w=>!w&&h(null),children:e.jsxs(wn,{className:"sm:max-w-md",zIndexLevel:"nested",children:[e.jsxs(Nn,{children:[e.jsx(kn,{className:"text-base",children:L?r('Delete "{{title}}"?',{title:L.title||r("Untitled")}):O!==void 0?r("Delete {{count}} conversations in {{project}}?",{count:x?.count??0,project:O}):r("Delete {{count}} conversations?",{count:x?.count??0})}),e.jsxs(Cn,{children:[r("About {{size}} of history, tool output and isolated worktrees will be removed and cannot be restored.",{size:ie(x?.bytes??0)}),!L&&` ${r("Open, running and waiting conversations are skipped.")}`]})]}),e.jsxs(Sn,{variant:"bare",children:[e.jsx(In,{render:e.jsx(A,{variant:"outline",size:"sm"}),children:r("Cancel")}),e.jsx(A,{variant:"destructive",size:"sm",onClick:()=>{const w=x?.request;h(null),w&&a(w)},children:r("Delete")})]})]})})]})}function pp(){const{t}=U(),s=b(k=>k.skills),n=b(k=>k.updateSkill),a=b(k=>k.setSkillsEnabled),r=b(k=>k.removeSkill),o=b(k=>k.loadLocalSkills),i=b(k=>k.setLoadLocalSkills),c=b(k=>k.loadHarnessAssets),d=b(k=>k.setLoadHarnessAssets),[x,h]=m.useState(!1),[u,p]=m.useState(""),l=s.filter(k=>jo(u,[k.name,k.source,k.description,k.path])),f=l.map(k=>k.id),g=vo(f),y=s.filter(k=>k.enabled).length,N=s.map(k=>k.id),j=is(N,k=>window.electronAPI.assets.skillOccupancy(k)),v=as(s.filter(k=>k.enabled).map(k=>k.id),j.rows);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load local skills")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Let the agent auto-discover skills under .agents/skills and .pi/skills")})]}),e.jsx(oe,{checked:o,onCheckedChange:i})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 rounded-lg border px-3 py-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:t("Load project harness assets")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Also load skills from .claude/.codex/.cursor and rule files (.cursorrules, .cursor/rules, .claude/rules) in the project")})]}),e.jsx(oe,{checked:c,onCheckedChange:d})]}),e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"skills.root",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"font-medium text-lg",children:[t("Skills"),e.jsx(qe,{note:t("The / menu updates right away, but open sessions keep the skills they loaded. Start a new session to load the change.")}),s.length>0&&e.jsxs("span",{className:"ml-2 font-normal text-muted-foreground text-xs",children:[t("{{enabled}}/{{total}} enabled",{enabled:y,total:s.length}),e.jsx(os,{tokens:v})]})]}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Skills registered by reference; files stay in their original location")})]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>h(!0),children:[e.jsx(ns,{className:"mr-1.5 h-4 w-4"}),t("Import from local apps")]})]}),s.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(zn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No skills yet")}),e.jsx("p",{className:"mt-1 text-muted-foreground text-xs",children:t("Import skills from Claude Code, Codex or Cursor to get started")})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(yo,{query:u,onQueryChange:p,placeholder:t("Filter skills..."),allSelected:g.allSelected,someSelected:g.someSelected,onToggleSelectAll:g.toggleAll,onEnable:()=>a(g.selectedIds,!0),onDisable:()=>a(g.selectedIds,!1),selectDisabled:l.length===0,actionDisabled:g.selectedIds.length===0}),l.length===0?e.jsx("p",{className:"px-3 py-6 text-center text-muted-foreground text-xs",children:t("No results")}):e.jsx("div",{className:"space-y-1",children:l.map(k=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`skills.${k.id}`,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(We,{checked:g.isSelected(k.id),onCheckedChange:R=>g.toggleOne(k.id,R)}),e.jsx("span",{className:K("shrink-0 font-medium text-sm",!k.enabled&&"text-muted-foreground line-through"),children:k.name}),e.jsx(Z,{variant:"secondary",className:"shrink-0 text-[11px]",children:k.source}),e.jsx("span",{className:"min-w-0 truncate text-muted-foreground text-xs",children:k.description||k.path})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(rs,{row:j.rows[k.id],pending:j.pending&&!j.rows[k.id]}),e.jsx(oe,{checked:k.enabled,onCheckedChange:R=>n(k.id,{enabled:R})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100",onClick:()=>r(k.id),children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]},k.id))})]}),e.jsx(On,{kind:"skill",open:x,onOpenChange:h})]})}const Tr=[10,15,30,60,120,300];function fp(){const{t}=U(),[s,n]=m.useState([]),[a,r]=m.useState(!1),[o,i]=m.useState(null),[c,d]=m.useState(""),[x,h]=m.useState(""),[u,p]=m.useState(""),[l,f]=m.useState(""),[g,y]=m.useState("key"),[N,j]=m.useState(""),[v,k]=m.useState(!1),[R,L]=m.useState(null),[S,O]=m.useState(null),[w,M]=m.useState(null),[E,I]=m.useState(null),[B,C]=m.useState(!1),_=m.useCallback(()=>{window.electronAPI.sshConnections.list().then(n)},[]);m.useEffect(()=>{_()},[_]);const V=()=>{i(null),d(""),h(""),p(""),f(""),y("key"),j(""),O(null),r(!0)},H=P=>{i(P),d(P.name),h(P.host),p(P.user??""),f(P.port?String(P.port):""),y(P.auth),j(""),O(null),r(!0)},$=async P=>{P.preventDefault(),k(!0),O(null);const Y=l.trim()?Number(l):void 0,ae=await window.electronAPI.sshConnections.upsert({...o?{id:o.id}:{},name:c.trim(),host:x.trim(),...u.trim()?{user:u.trim()}:{},...Y&&Number.isInteger(Y)?{port:Y}:{},auth:g,...g==="password"&&N?{password:N}:{}});if(k(!1),!ae.ok){O(ae.error);return}r(!1),_()},re=async P=>{const Y=await window.electronAPI.sshConnections.delete(P);if(!Y.ok){M(Y.error);return}M(null),_()},D=async(P,Y=!0)=>{L(P),M(null);const ae=await window.electronAPI.sshConnections.test(P);if(L(null),!ae.ok){const le=s.find(ue=>ue.id===P),z=Qc(ae,le);if(z&&Y){I({id:P,challenge:z});return}}M(ae.ok?t("SSH connection succeeded"):ae.error)},q=async()=>{if(!E)return;C(!0);const P=E.id,Y=await window.electronAPI.sshConnections.trustHost(P);if(C(!1),I(null),!Y.ok){M(Y.error||t("Could not save host key."));return}await D(P,!1)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"ssh.root",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-medium",children:[t("SSH"),e.jsx(qe,{note:t("The file panel and terminal use the change right away. Agents in open sessions keep the previous connection settings.")})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t("Saved hosts for remote projects. Passwords stay in the system keychain.")})]}),e.jsxs(A,{size:"sm",onClick:V,children:[e.jsx(Ee,{className:"h-4 w-4"}),t("Add connection")]})]}),w&&e.jsx("p",{className:"text-sm text-muted-foreground",children:w}),e.jsxs("ul",{className:"divide-y rounded-lg border",children:[s.length===0&&e.jsx("li",{className:"px-3 py-6 text-sm text-muted-foreground",children:t("No SSH connections yet")}),s.map(P=>e.jsxs("li",{className:"flex items-center gap-2 px-3 py-2","data-settings-row":`ssh.${P.id}`,children:[e.jsxs("button",{type:"button",className:"min-w-0 flex-1 text-left",onClick:()=>H(P),children:[e.jsx("div",{className:"truncate text-sm font-medium",children:P.name}),e.jsxs("div",{className:"truncate text-xs text-muted-foreground",children:[P.user?`${P.user}@`:"",P.host,P.port?`:${P.port}`:""," ·"," ",P.auth==="password"?t("Password"):t("Key / agent")]})]}),e.jsx(A,{size:"sm",variant:"outline",disabled:R===P.id,onClick:()=>{D(P.id)},children:R===P.id?e.jsx(Te,{className:"h-4 w-4 animate-spin"}):t("Test")}),e.jsx(A,{size:"icon-sm",variant:"ghost",onClick:()=>{re(P.id)},children:e.jsx(Ae,{className:"h-4 w-4"})})]},P.id))]}),e.jsx(gp,{}),e.jsx(pe,{open:a,onOpenChange:r,children:e.jsx(fe,{className:"max-w-md",children:e.jsxs("form",{onSubmit:P=>{$(P)},className:"flex flex-col",children:[e.jsx(ge,{children:e.jsx(je,{children:t(o?"Edit SSH connection":"Add SSH connection")})}),e.jsxs(Se,{className:"space-y-3",children:[e.jsxs(ce,{children:[e.jsx(de,{children:t("Name")}),e.jsx(J,{value:c,onChange:P=>d(P.target.value),required:!0})]}),e.jsxs(ce,{children:[e.jsx(de,{children:t("Host")}),e.jsx(J,{value:x,onChange:P=>h(P.target.value),placeholder:"example.com",required:!0})]}),e.jsxs(ce,{children:[e.jsx(de,{children:t("User (optional)")}),e.jsx(J,{value:u,onChange:P=>p(P.target.value)})]}),e.jsxs(ce,{children:[e.jsx(de,{children:t("Port (optional)")}),e.jsx(J,{value:l,onChange:P=>f(P.target.value),placeholder:"22"})]}),e.jsxs(ce,{children:[e.jsx(de,{children:t("Authentication")}),e.jsxs(ee,{items:[{value:"key",label:t("Key / agent")},{value:"password",label:t("Password")}],value:g,onValueChange:P=>y(P),children:[e.jsx(te,{className:"w-full",children:e.jsx(se,{})}),e.jsxs(ne,{zIndex:Qe.DROPDOWN_IN_MODAL,children:[e.jsx(X,{value:"key",children:t("Key / agent")}),e.jsx(X,{value:"password",children:t("Password")})]})]})]}),g==="password"&&e.jsxs(ce,{children:[e.jsx(de,{children:o?.hasPassword?t("Password (leave blank to keep)"):t("Password")}),e.jsx(J,{type:"password",value:N,onChange:P=>j(P.target.value),required:!o?.hasPassword})]}),S&&e.jsx("p",{className:"text-sm text-destructive",children:S})]}),e.jsxs(Ie,{children:[e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!1),children:t("Cancel")}),e.jsx(A,{type:"submit",size:"sm",disabled:v,children:t("Save")})]})]})})}),e.jsx(Yc,{challenge:E?.challenge??null,busy:B,onTrust:()=>{q()},onDismiss:()=>!B&&I(null)})]})}function gp(){const{t}=U(),s=b(a=>a.sshTimeoutSeconds),n=b(a=>a.setSshTimeoutSeconds);return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2.5","data-settings-row":"ssh.timeout",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("SSH timeout")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("Time limit for connection tests, loading remote AGENTS.md, remote folder browsing and file panel actions. Agent tool commands are not affected.")})]}),e.jsxs(ee,{items:Object.fromEntries(Tr.map(a=>[String(a),`${a}s`])),value:String(s),onValueChange:a=>n(Number(a)),children:[e.jsx(te,{className:"w-24",children:e.jsx(se,{})}),e.jsx(ne,{children:Tr.map(a=>e.jsx(X,{value:String(a),children:`${a}s`},a))})]})]})}const jp={memory:"memory",workflows:"workflow"},ui=["bots","botTemplates"],vp=[{id:"app",label:"Application",categories:["general","appearance","shortcuts","voice","privacy"]},{id:"agent",label:"Models & agents",categories:["providers","presets","agents","instructions","memory"]},{id:"extensions",label:"Tools & extensions",categories:["tools","workflows","skills","mcp","plugins","claudePlugins"]},{id:"connections",label:"Connections",categories:["phone","ssh"]},{id:"system",label:"System",categories:["usage","resources","experimental","bots","botTemplates"]}];function bp(t){const s=new Map(t.map(n=>[n.id,n]));return vp.flatMap(n=>{const a=n.categories.flatMap(r=>{const o=s.get(r);return o?[o]:[]});return a.length>0?[{id:n.id,label:n.label,items:a}]:[]})}function mi(t,s,n=!1){if(ui.includes(t))return n;const a=jp[t];return!a||!s.includes(a)}function yp(t,s,n=!1){return t.filter(a=>mi(a.id,s,n))}function wp(t,s,n=!1){return mi(t,s,n)?t:ui.includes(t)?"experimental":"tools"}function Np(t,s,n,a){const r=n.trim();if(!r)return t.map(d=>({...d,hits:[]}));const o=Xc([...s,...t.map(d=>({id:`${d.id}.root`,category:d.id,title:d.label}))],r,{translate:a,limit:Number.POSITIVE_INFINITY}),i=new Set,c=new Map;for(const d of o){if(i.add(d.category),d.id.endsWith(".root"))continue;const x=c.get(d.category);x?x.push(d):c.set(d.category,[d])}return t.flatMap(d=>i.has(d.id)?[{...d,hits:c.get(d.id)??[]}]:[])}const kp=[1,7,30,90],Rr=640,qt=180,Or=8,Dr=18,Cp=.3,Sp=2;function Ip(t){const[,s,n]=t.split("-");return`${Number(s)}/${Number(n)}`}const Ap=[{id:"cache",cls:"fill-foreground/15",swatch:"bg-foreground/15"},{id:"input",cls:"fill-foreground/45",swatch:"bg-foreground/45"},{id:"output",cls:"fill-foreground",swatch:"bg-foreground"}];function Ep({daily:t}){const{t:s}=U(),[n,a]=m.useState("tokens"),[r,o]=m.useState(null),[i,c]=m.useState({output:!0,input:!0,cache:!0}),d=j=>{c(v=>{const k={...v,[j]:!v[j]};return!k.output&&!k.input&&!k.cache?v:k})},x=t.map(j=>n==="cost"?j.cost??0:(i.output?j.output:0)+(i.input?j.input:0)+(i.cache?j.cache:0)),h=Math.max(0,...x),u=Math.max(1,t.length),p=Rr/u,l=Math.min(p*(1-Cp),64),f=qt-Or-Dr,g=j=>h>0?j/h*f:0,y=Math.max(1,Math.ceil(u/12)),N=r!==null?t[r]:null;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Daily trend")}),e.jsxs("div",{className:"flex items-center gap-3",children:[n==="tokens"&&e.jsxs("div",{className:"flex items-center gap-3 text-[11px] text-muted-foreground",children:[e.jsx(Qs,{className:"bg-foreground",label:s("Output"),pressed:i.output,onClick:()=>d("output")}),e.jsx(Qs,{className:"bg-foreground/45",label:s("Input"),pressed:i.input,onClick:()=>d("input")}),e.jsx(Qs,{className:"bg-foreground/15",label:s("Cache"),pressed:i.cache,onClick:()=>d("cache")})]}),e.jsx(Mp,{value:n,onChange:a})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"pointer-events-none absolute left-0 top-0 font-mono text-[10px] text-muted-foreground",children:n==="tokens"?Fe(h):Xt(h>0?h:null)}),N&&e.jsxs("div",{className:"pointer-events-none absolute right-0 top-0 rounded bg-popover px-2 py-1 font-mono text-[11px] text-popover-foreground shadow-sm ring-1 ring-border",children:[N.day,n==="tokens"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[s("Output")," ",Fe(N.output)]}),e.jsxs("div",{children:[s("Input")," ",Fe(N.input)]}),e.jsxs("div",{children:[s("Cache")," ",Fe(N.cache)]})]}):e.jsxs(e.Fragment,{children:[" · ",Xt(N.cost)]})]}),e.jsx("svg",{viewBox:`0 0 ${Rr} ${qt}`,className:"mt-4 block h-[180px] w-full",role:"img","aria-label":s("Daily trend"),onMouseLeave:()=>o(null),children:t.map((j,v)=>{const k=v*p+(p-l)/2,R=qt-Dr,L=n==="tokens"?Ap.filter(O=>i[O.id]).map(O=>({v:j[O.id],cls:O.cls})):[{v:j.cost??0,cls:"fill-emerald-600 dark:fill-emerald-500"}];let S=R;return e.jsxs("g",{onMouseEnter:()=>o(v),children:[e.jsx("rect",{x:k,y:Or,width:l,height:f,className:"fill-transparent"}),L.map(O=>{const w=O.v>0?Math.max(Sp,g(O.v)):0;return S-=w,e.jsx("rect",{x:k,y:S,width:l,height:w,rx:1,className:K(O.cls,r===v&&"opacity-80")},O.cls)}),v%y===0&&e.jsx("text",{x:k+l/2,y:qt-4,textAnchor:"middle",className:"fill-muted-foreground font-mono text-[10px]",children:Ip(j.day)})]},j.day)})})]})]})}function Qs({className:t,label:s,pressed:n,onClick:a}){return e.jsxs("button",{type:"button","aria-pressed":n,onClick:a,className:K("flex items-center gap-1 rounded px-0.5 transition-opacity",n?"opacity-100":"opacity-40"),children:[e.jsx("span",{className:K("inline-block h-2.5 w-2.5 rounded-sm",t)}),s]})}function Mp({value:t,onChange:s}){const{t:n}=U(),a=[{id:"tokens",label:n("Token")},{id:"cost",label:n("Cost")}];return e.jsx("div",{className:"flex rounded-md bg-muted p-0.5",children:a.map(r=>e.jsx("button",{type:"button",onClick:()=>s(r.id),className:K("rounded px-2 py-0.5 text-[11px] transition-colors",t===r.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:r.label},r.id))})}const Xs=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Lr=Array.from({length:24},(t,s)=>String(s).padStart(2,"0")),es=["bg-foreground/[0.06]","bg-foreground/20","bg-foreground/40","bg-foreground/60","bg-foreground/80","bg-foreground"];function Pp(t,s){return t<=0||s<=0?0:1+Math.min(es.length-2,Math.floor(t/s*(es.length-1)))}function Tp({heatmap:t}){const{t:s}=U(),n=Math.max(0,...t.flat());return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:s("Activity by hour")}),e.jsxs("div",{className:"flex items-center gap-1 text-[10px] text-muted-foreground",children:[e.jsx("span",{children:s("Less")}),es.map(a=>e.jsx("span",{className:K("inline-block h-2.5 w-2.5 rounded-[2px]",a)},a)),e.jsx("span",{children:s("More")})]})]}),e.jsxs("div",{className:"grid grid-cols-[28px_1fr] gap-x-2 gap-y-1",children:[t.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("span",{className:"self-center text-[10px] text-muted-foreground",children:s(Xs[r])}),e.jsx("div",{className:"grid grid-cols-24 gap-[3px]",children:Lr.map((o,i)=>e.jsx("span",{title:`${s(Xs[r])} ${o}:00 · ${Fe(a[i]??0)}`,className:K("aspect-square rounded-[2px]",es[Pp(a[i]??0,n)])},o))})]},Xs[r])),e.jsx("span",{}),e.jsx("div",{className:"grid grid-cols-24 font-mono text-[10px] text-muted-foreground",children:Lr.map((a,r)=>e.jsx("span",{className:K(r%3!==0&&"invisible"),children:a},a))})]})]})}function Zs({title:t,countLabel:s,rows:n,emptyLabel:a,limit:r=8}){const{t:o}=U(),[i,c]=m.useState(!1),d=n.reduce((u,p)=>u+p.tokens,0),x=n.length>r,h=x&&!i?n.slice(0,r):n;return e.jsxs("div",{className:"rounded-lg border bg-card p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium",children:t}),x&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:i?o("{{total}} items",{total:n.length}):o("Top {{count}} of {{total}}",{count:r,total:n.length})})]}),h.length===0?e.jsx("p",{className:"py-6 text-center text-xs text-muted-foreground",children:a}):e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:o("Name")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Cost")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:o("Token")}),e.jsx("th",{className:"pb-2 text-right font-normal",children:s})]})}),e.jsx("tbody",{children:h.map(u=>{const p=d>0?u.tokens/d:0;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-2 pr-3",children:[e.jsx("div",{className:"truncate",title:u.name,children:u.name||o("(no project)")}),e.jsx("div",{className:"mt-1 h-1 w-full rounded-full bg-foreground/[0.06]",children:e.jsx("div",{className:"h-1 rounded-full bg-foreground/70",style:{width:`${Math.max(1,p*100)}%`}})})]}),e.jsx("td",{className:K("py-2 text-right font-mono tabular-nums",u.cost===null&&"text-muted-foreground"),children:Xt(u.cost)}),e.jsxs("td",{className:"py-2 text-right font-mono tabular-nums",children:[Fe(u.tokens),e.jsxs("span",{className:"ml-1 text-muted-foreground",children:[(p*100).toFixed(0),"%"]})]}),e.jsx("td",{className:"py-2 text-right font-mono tabular-nums",children:u.count})]},u.key)})})]}),x&&e.jsx(A,{variant:"ghost",size:"xs",className:"mt-2 w-full text-muted-foreground",onClick:()=>c(u=>!u),children:o(i?"Collapse":"Show all")})]})}function Rp({value:t,className:s}){const n=t.split("");return e.jsx("span",{className:K("t-digit-group is-animating",s),children:n.map((a,r)=>e.jsx("span",{className:"t-digit","data-stagger":r===n.length-2?"1":r===n.length-1?"2":void 0,children:a},`${r}:${a}`))},t)}const Op={default:"text-foreground",success:"text-emerald-600 dark:text-emerald-400",info:"text-sky-600 dark:text-sky-400",muted:"text-muted-foreground"};function at({label:t,value:s,delta:n,tone:a="default"}){return e.jsxs("div",{className:"min-w-0 overflow-hidden rounded-lg border bg-card px-4 py-3",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"min-w-0 text-xs text-muted-foreground",children:t}),n&&e.jsx("span",{className:"shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",children:n})]}),e.jsx("div",{className:K("mt-1 truncate font-mono text-xl font-semibold leading-tight tabular-nums sm:text-2xl",Op[a]),title:s,children:e.jsx(Rp,{value:s})})]})}const en={input:0,output:0,cacheRead:0,cacheWrite:0},ts=["input","output","cacheRead","cacheWrite"];function tn(t){return{input:String(t.input),output:String(t.output),cacheRead:String(t.cacheRead),cacheWrite:String(t.cacheWrite)}}function Dp(t){return sd({id:Object.fromEntries(ts.map(n=>[n,Number(t[n])]))}).id??null}function Lp(t){return t===void 0?"—":String(t)}function zr({rows:t,editing:s,draft:n,overrides:a,onDraft:r,onEdit:o,onSave:i}){const{t:c}=U();return e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-[11px] text-muted-foreground",children:[e.jsx("th",{className:"pb-2 text-left font-normal",children:c("Name")}),ts.map(d=>e.jsx("th",{className:"pb-2 text-right font-normal",children:d},d)),e.jsx("th",{className:"w-14 pb-2"})]})}),e.jsx("tbody",{children:t.map(d=>{const x=s===d.model,h=d.model in a;return e.jsxs("tr",{className:"border-t border-border/60",children:[e.jsxs("td",{className:"py-1.5 pr-3 align-middle",children:[e.jsx("span",{className:"font-mono text-xs",title:d.model,children:d.model}),h&&e.jsx("span",{className:"ml-1.5 text-[10px] text-muted-foreground",children:c("Custom")})]}),ts.map(u=>e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(J,{size:"sm",inputMode:"decimal",className:"ml-auto w-16 [&_input]:text-right",value:n[u],onChange:p=>r({...n,[u]:p.target.value})}):e.jsx("span",{className:K("font-mono tabular-nums",d.pricing==null&&"text-muted-foreground"),children:Lp(d.pricing?.[u])})},u)),e.jsx("td",{className:"py-1.5 text-right align-middle",children:x?e.jsx(A,{size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>i(d.model),children:c("Save")}):e.jsx(A,{variant:"ghost",size:"sm",className:"h-6 px-1.5 text-[11px]",onClick:()=>o(d.model,d.pricing),children:c("Edit")})})]},d.model)})})]})}function zp({models:t,catalog:s,onChanged:n}){const{t:a}=U(),r=b(C=>C.usageModelPricing),o=ss(),i=b(C=>C.setUsageModelPricing),[c,d]=m.useState(!1),[x,h]=m.useState(!1),[u,p]=m.useState(null),[l,f]=m.useState(tn(en)),[g,y]=m.useState(null),[N,j]=m.useState(!1),[v,k]=m.useState(""),[R,L]=m.useState(""),S=new Set(t.map(C=>C.model)),O=new Set;for(const C of o)for(const _ of C.models)O.add(_.id);for(const C of Object.keys(r))O.add(C);const w=R.trim().toLowerCase(),M=t.filter(C=>!w||C.model.toLowerCase().includes(w)).map(C=>({model:C.model,pricing:C.pricing})),E=[...O].filter(C=>!S.has(C)&&(!w||C.toLowerCase().includes(w))).sort().map(C=>({model:C,pricing:r[C]??s[C]??null})),I=(C,_)=>{j(!1),p(C),f(tn(_??en)),y(null)},B=C=>{const _=Dp(l);return!_||!i(C,_)?(y(a("Enter a model id and non-negative rates.")),!1):(y(null),p(null),j(!1),k(""),n(),!0)};return e.jsxs(Zc,{open:c,onOpenChange:d,className:"rounded-lg border bg-card",children:[e.jsxs(ed,{className:"flex w-full items-center justify-between gap-3 px-4 py-3 text-left",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium",children:a("Unit prices")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("Rates used for cost estimates ($/M tokens).")})]}),e.jsx(Yt,{className:K("h-4 w-4 shrink-0 text-muted-foreground transition-transform",c&&"rotate-180")})]}),e.jsx(td,{children:e.jsxs("div",{className:"space-y-3 border-t px-4 py-3",children:[e.jsx(J,{size:"sm",value:R,onChange:C=>L(C.target.value),placeholder:a("Search models")}),M.length===0&&!N?e.jsx("p",{className:"text-xs text-muted-foreground",children:a(w?"No matching models":"No usage in this period")}):e.jsx(zr,{rows:M,editing:u,draft:l,overrides:r,onDraft:f,onEdit:I,onSave:B}),E.length>0&&(x||!!w)&&e.jsx(zr,{rows:E,editing:u,draft:l,overrides:r,onDraft:f,onEdit:I,onSave:B}),N?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"grid min-w-36 gap-1 text-[11px] text-muted-foreground",children:[a("Model id"),e.jsx(J,{size:"sm",value:v,onChange:C=>k(C.target.value),placeholder:"qwen-3.8-27b"})]}),ts.map(C=>e.jsxs("label",{className:"grid min-w-16 gap-1 text-[11px] text-muted-foreground",children:[C,e.jsx(J,{size:"sm",inputMode:"decimal",value:l[C],onChange:_=>f(V=>({...V,[C]:_.target.value}))})]},C))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{size:"sm",className:"h-7",onClick:()=>B(v),children:a("Save")}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!1),k(""),y(null)},children:a("Cancel")})]})]}):e.jsxs("div",{className:"flex justify-end gap-2",children:[E.length>0&&e.jsxs(A,{variant:"ghost",size:"sm",className:"h-7 text-muted-foreground",onClick:()=>h(C=>!C),children:[a("Show all"),e.jsx(Yt,{className:K("ml-1 h-3.5 w-3.5 transition-transform",x&&"rotate-180")})]}),e.jsx(A,{variant:"ghost",size:"sm",className:"h-7",onClick:()=>{j(!0),f(tn(en)),y(null)},children:a("Add")})]}),g&&e.jsx("p",{className:"text-xs text-destructive",children:g})]})})]})}const Bp={1:"Today",7:"7D",30:"30D",90:"90D"};function _p(){const{t}=U(),[s,n]=m.useState(7),[a,r]=m.useState(null),o=b(f=>f.botModeEnabled),[i,c]=m.useState(null),[d,x]=m.useState(null),[h,u]=m.useState(!1),p=m.useRef(0),l=m.useCallback(async f=>{const g=++p.current;u(!0);const[y,N]=await Promise.all([window.electronAPI.usage.summary(f),o?window.electronAPI.bots.usageSummary(f).catch(()=>null):null]);g===p.current&&(u(!1),c(N?.ok?N.rows:null),y.ok?(r(y.summary),x(null)):(r(null),x(y.error)))},[o]);return m.useEffect(()=>{l(s)},[s,l]),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:t("Usage")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("Token usage across all local sessions; cost is estimated from catalog prices.")})]}),e.jsx(A,{variant:"ghost",size:"icon-sm",onClick:()=>{l(s)},disabled:h,"aria-label":t("Refresh"),children:e.jsx(rt,{className:K(h&&"animate-spin")})})]}),e.jsx(Fp,{value:s,onChange:n}),d&&e.jsx("p",{className:"text-sm text-destructive",children:d}),a&&e.jsxs(e.Fragment,{children:[e.jsx(Up,{totals:a.totals,previous:a.previous}),e.jsx(Ep,{daily:a.daily}),e.jsx(Tp,{heatmap:a.heatmap}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(Zs,{title:t("By model"),countLabel:t("Messages"),emptyLabel:t("No usage in this period"),rows:a.byModel.map(f=>({key:f.model,name:f.model,cost:f.cost,tokens:f.tokens,count:f.messages}))}),e.jsx(Zs,{title:t("By project"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:a.byProject.map(f=>({key:f.project||"#",name:f.project,cost:f.cost,tokens:f.tokens,count:f.sessions}))})]}),o&&i&&e.jsx(Zs,{title:t("By member"),countLabel:t("Sessions"),emptyLabel:t("No usage in this period"),rows:i.map(f=>({key:f.botId,name:f.name||t("Deleted member"),cost:f.cost,tokens:f.tokens,count:f.sessions}))}),a.unpricedModels.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:t("No catalog price for: {{models}}. Their cost is not included.",{models:a.unpricedModels.join(", ")})})]}),e.jsx(zp,{models:a?.byModel??[],catalog:a?.pricing??{},onChanged:()=>{l(s)}})]})}function Fp({value:t,onChange:s}){const{t:n}=U();return e.jsx("div",{className:"flex items-center gap-1.5",children:kp.map(a=>e.jsx("button",{type:"button",onClick:()=>s(a),className:K("rounded-full px-3 py-1 font-mono text-xs transition-colors",t===a?"bg-foreground text-background":"bg-muted text-muted-foreground hover:text-foreground"),children:n(Bp[a])},a))})}function Up({totals:t,previous:s}){const{t:n}=U(),a=t.cacheRead+t.cacheWrite,r=s.cacheRead+s.cacheWrite;return e.jsxs("div",{className:"grid grid-cols-2 gap-3 md:grid-cols-4",children:[e.jsx(at,{label:n("Estimated cost"),value:Xt(t.cost),delta:tt(s.cost,t.cost),tone:"success"}),e.jsx(at,{label:n("Total tokens"),value:Fe(t.tokens),delta:tt(s.tokens,t.tokens)}),e.jsx(at,{label:n("Input tokens"),value:Fe(t.input),delta:tt(s.input,t.input)}),e.jsx(at,{label:n("Output tokens"),value:Fe(t.output),delta:tt(s.output,t.output)}),e.jsx(at,{label:n("Cache tokens"),value:Fe(a),delta:tt(r,a),tone:"muted"}),e.jsx(at,{label:n("Active time"),value:nd(t.activeMs),delta:tt(s.activeMs,t.activeMs),tone:"info"}),e.jsx(at,{label:n("Sessions"),value:String(t.sessions),delta:tt(s.sessions,t.sessions)}),e.jsx(at,{label:n("Messages"),value:t.messages.toLocaleString(),delta:tt(s.messages,t.messages)})]})}const Br={"x-asr-streaming":{name:"X-ASR Streaming",description:"Text appears while you speak. Chinese and English."},"x-asr":{name:"X-ASR",description:"Most accurate on everyday speech. Chinese and English."},"qwen3-asr":{name:"Qwen3-ASR 0.6B",description:"Best with mixed Chinese-English and code terms. Slower and uses more memory."},"sense-voice":{name:"SenseVoice",description:"Chinese, English, Japanese, Korean and Cantonese."},hanbao:{name:"Hanbao",description:"Runs fully offline. Chinese and English."},"gemini-live":{name:"Gemini Transcribe Live",description:"Google cloud recognition, most accurate with mixed Chinese-English and code terms. Needs a Gemini API key."},wetype:{name:"WeType",description:"WeChat Keyboard cloud recognition. Chinese and English, no setup needed."}};function hi({state:t,onDownload:s,onCancel:n,onRemove:a}){const{t:r}=U();return t==="unavailable"?null:t==="downloading"?e.jsx(A,{variant:"outline",size:"sm",onClick:n,children:r("Cancel")}):t==="ready"?e.jsx(A,{variant:"ghost",size:"sm",onClick:a,children:r("Remove")}):e.jsx(A,{variant:"outline",size:"sm",onClick:s,children:r("Download")})}function $p(){const{t}=U(),s=b(h=>h.voiceModel),n=b(h=>h.setVoiceModel),{status:a,progress:r,error:o,refresh:i}=ad();if(!a)return null;if(a.state==="unsupported")return e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Voice input is not available on this platform.")});const c=window.electronAPI.speech,d=h=>{const u=r[h.id];return u?`${u.file} · ${ie(u.received)}${u.total?` / ${ie(u.total)}`:""} (${u.fileIndex+1}/${u.fileCount})`:o?.modelId===h.id?`${t("Download failed")}: ${o.message}`:h.id==="wetype"?t("Audio is uploaded to Tencent WeChat Keyboard servers."):h.remote?h.state==="ready"?t("Audio is uploaded to Google. On the free tier Google may use it to improve its products."):t("Enter a Gemini API key below first."):t("Download {{size}} · Memory about {{memory}}",{size:ie(h.approxBytes),memory:ie(h.memoryBytes)})},x=a.models.find(h=>h.id===s);return e.jsxs("div",{className:"space-y-1.5","data-settings-row":"tools.voiceModel",children:[e.jsx("p",{className:"text-sm",children:t("Speech model")}),e.jsx("div",{role:"radiogroup",className:"divide-y rounded-md border",children:a.models.map(h=>{const u=h.id===s;return e.jsxs("div",{className:K("flex items-center gap-3 px-3 py-2",u&&"bg-accent/40"),children:[e.jsxs("button",{type:"button",role:"radio","aria-checked":u,onClick:()=>n(h.id),className:"flex min-w-0 flex-1 items-start gap-2.5 text-left",children:[e.jsx("span",{className:K("mt-1 flex size-3.5 shrink-0 items-center justify-center rounded-full border",u&&"border-primary"),children:u?e.jsx("span",{className:"size-2 rounded-full bg-primary"}):null}),e.jsxs("span",{className:"min-w-0",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-sm",children:[t(Br[h.id].name),h.remote?e.jsx(Z,{variant:"warning",size:"sm",children:t("Cloud")}):null,e.jsx(Z,{variant:h.streaming?"info":"secondary",size:"sm",children:h.streaming?t("Streaming"):t("Sentence by sentence")}),h.state==="ready"&&!h.remote?e.jsx(Z,{variant:"success",size:"sm",children:t("Downloaded")}):null]}),e.jsx("span",{className:"block text-muted-foreground text-xs",children:t(Br[h.id].description)}),e.jsx("span",{className:K("block text-xs",o?.modelId===h.id?"text-destructive":h.remote?"text-warning":"text-muted-foreground"),children:d(h)})]})]}),e.jsx(hi,{state:h.remote?"unavailable":h.state,onDownload:()=>{n(h.id),c.download(h.id).then(i)},onCancel:()=>{c.cancelDownload(h.id).then(i)},onRemove:()=>{c.remove(h.id).then(i)}})]},h.id)})}),a.state!=="ready"&&a.state!=="downloading"&&!x?.remote?e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Download the selected model to start using voice input.")}):null,x?.id==="gemini-live"?e.jsxs(e.Fragment,{children:[e.jsx(Vp,{}),e.jsx(Kp,{})]}):null]})}function Vp(){const{t}=U(),s=b(a=>a.voiceGeminiApiKey),n=b(a=>a.setVoiceGeminiApiKey);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.geminiApiKey",children:[e.jsx("p",{className:"text-sm",children:t("Gemini API key")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Create one for free in Google AI Studio.")}),e.jsx(J,{type:"password",autoComplete:"off",spellCheck:!1,value:s,onChange:a=>n(a.target.value),placeholder:"AIza…",className:"font-mono"})]})}function Kp(){const{t}=U(),s=b(a=>a.voiceVocabulary),n=b(a=>a.setVoiceVocabulary);return e.jsxs("div",{className:"space-y-1.5 pt-2","data-settings-row":"voice.vocabulary",children:[e.jsx("p",{className:"text-sm",children:t("Custom vocabulary")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("One term per line, up to 100. Helps with names and code terms such as useEffect or pnpm.")}),e.jsx(Xe,{size:"sm",value:s,onChange:a=>n(a.target.value),placeholder:`useEffect
28
- pnpm
29
- TypeScript`,className:"font-mono"})]})}function qp(){const{t}=U(),s=b(j=>j.voiceCorrectionEnabled),n=b(j=>j.setVoiceCorrectionEnabled),a=b(j=>j.voiceCorrectionModel)||"remote",r=b(j=>j.setVoiceCorrectionModel),o=b(j=>j.voiceCorrectionRemoteModel),i=b(j=>j.setVoiceCorrectionRemoteModel),c=Je(),[d,x]=m.useState([]),[h,u]=m.useState(null),p=m.useCallback(()=>{window.electronAPI.memory.chatModels().then(x)},[]);m.useEffect(()=>(p(),window.electronAPI.memory.onChatModelProgress(j=>{u(j.done?null:j),j.done&&p()})),[p]);const l=d.find(j=>j.id===a)??null,f=d.map(j=>({value:j.id,label:j.id==="remote"?t("Remote (API model)"):`${j.label}${j.purpose?` · ${t("tuned for voice")}`:""} · ${ie(j.approxBytes)}`})),g=o?c.find(j=>j.id===o.providerId):void 0,y=g?.models.find(j=>j.id===o?.modelId),N=window.electronAPI.memory;return e.jsxs("div",{className:"space-y-2","data-settings-row":"tools.voiceCorrection",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm",children:t("Correct with a language model")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Fixes homophones, code terms and number formats after recognition. Adds about 1-3 seconds; the raw text is kept if it fails.")})]}),e.jsx(oe,{checked:s,onCheckedChange:n})]}),s?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-sm",children:t("Correction model")}),e.jsxs(ee,{value:a,items:f,onValueChange:j=>r(String(j)),children:[e.jsx(te,{className:"w-64",children:e.jsx(se,{})}),e.jsx(ne,{children:f.map(j=>e.jsx(X,{value:j.value,children:j.label},j.value))})]})]}),l?.downloadable?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:K("text-xs",l.state==="missing"?"text-destructive":"text-muted-foreground"),children:h?.modelId===l.id?`${ie(h.received)}${h.total?` / ${ie(h.total)}`:""}`:l.state==="ready"?t("Model downloaded"):l.state==="downloading"?t("Downloading…"):t("Not downloaded yet. Correction is skipped until it is.")}),e.jsx(hi,{state:l.state,onDownload:()=>{N.downloadChatModel(l.id).then(p)},onCancel:()=>{N.cancelChatModelDownload(l.id).then(p)},onRemove:()=>{N.deleteChatModel(l.id).then(p)}})]}):null,a==="remote"&&c.length>0?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("p",{className:"text-muted-foreground text-xs",children:t("A fast, inexpensive model is enough.")}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[o?e.jsx(A,{variant:"ghost",size:"sm",onClick:()=>i(null),children:t("Reset")}):null,e.jsx("div",{className:"w-56",children:e.jsx($e,{providers:c,providerId:g?.id??"",modelId:y?.id??"",reasoningEnabled:!1,thinkingLevel:"medium",showReasoningControls:!1,emptyLabel:t("Follows the title-summary model"),side:"bottom",triggerClassName:Ze,onSelect:(j,v)=>i({providerId:j,modelId:v}),onReasoningChange:()=>{},onThinkingChange:()=>{}})})]})]}):null]}):null]})}function Gp(){const{t}=U(),s=b(a=>a.voiceInputEnabled),n=b(a=>a.setVoiceInputEnabled);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4","data-settings-row":"voice.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Voice input")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Adds a microphone to the composer on this computer and on paired phones. Local models transcribe speech on this computer.")})]}),e.jsx(oe,{checked:s,onCheckedChange:n,"aria-label":t("Voice input"),className:"mt-1 shrink-0"})]}),s?e.jsxs(e.Fragment,{children:[e.jsx(Wp,{}),e.jsx($p,{}),e.jsx(qp,{})]}):null]})}function Hp(){const[t,s]=m.useState([]);return m.useEffect(()=>{const n=navigator.mediaDevices;if(!n?.enumerateDevices)return;let a=!0;const r=()=>{n.enumerateDevices().then(o=>{a&&s(o.filter(i=>i.kind==="audioinput"&&i.deviceId!==zo&&i.deviceId!=="communications"))})};return r(),n.addEventListener("devicechange",r),()=>{a=!1,n.removeEventListener("devicechange",r)}},[]),t}function Wp(){const{t}=U(),s=b(o=>o.voiceInputDevice),n=b(o=>o.setVoiceInputDevice),a=Hp(),r=[{value:zo,label:t("System default")},...a.map((o,i)=>({value:o.deviceId,label:o.label||t("Microphone {{n}}",{n:i+1})}))];return r.some(o=>o.value===s)||r.push({value:s,label:t("Disconnected, using the system default")}),e.jsxs("div",{className:"flex items-center justify-between gap-3","data-settings-row":"voice.microphone",children:[e.jsx("p",{className:"text-sm",children:t("Microphone")}),e.jsxs(ee,{value:s,items:r,onValueChange:o=>n(String(o)),children:[e.jsx(te,{className:"w-64",children:e.jsx(se,{})}),e.jsx(ne,{children:r.map(o=>e.jsx(X,{value:o.value,children:o.label},o.value))})]})]})}const Jp=32,Yp=/^[A-Za-z0-9][A-Za-z0-9_:-]{0,127}$/,Qp=/^[A-Za-z_][A-Za-z0-9_]{0,31}$/,Xp=/\{\{\s*(?:args\.([A-Za-z_][A-Za-z0-9_]{0,31})|(prev))\s*\}\}/g;function fn(t,s){if(typeof t!="string")return null;const n=t.trim();return n&&n.length<=s?n:null}function Zp(t,s){const n=[...new Set(t)].filter(a=>Qp.test(a)).map(a=>({kind:"arg",key:a,token:`{{args.${a}}}`}));return s>0&&n.push({kind:"prev",token:"{{prev}}"}),n}function ef(t,s,n,a){const r=Math.min(Math.max(s,0),t.length),o=Math.min(Math.max(n,r),t.length);return{text:t.slice(0,r)+a+t.slice(o),cursor:r+a.length}}function tf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=fn(s.label,80),a=fn(s.prompt,8e3),r=typeof s.agentType=="string"?s.agentType.trim():"";return!n||!a||r&&!Yp.test(r)?null:{label:n,agentType:r,prompt:a}}function sf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t,n=fn(s.title,80);if(!n||!Array.isArray(s.steps)||s.steps.length===0)return null;const a=s.steps.map(tf);return a.every(r=>r!==null)?{title:n,steps:a}:null}function nf(t){if(!t||typeof t!="object"||Array.isArray(t))return null;const s=t.phases;if(!Array.isArray(s)||s.length===0)return null;const n=s.map(sf);return n.every(r=>r!==null)&&n.reduce((r,o)=>r+o.steps.length,0)<=Jp?{phases:n}:null}function xi(t){const s=[];let n=0;for(const a of t.matchAll(Xp))a.index>n&&s.push({kind:"text",text:t.slice(n,a.index)}),s.push(a[1]?{kind:"arg",key:a[1]}:{kind:"prev"}),n=a.index+a[0].length;return n<t.length&&s.push({kind:"text",text:t.slice(n)}),s}function af(t){const s=xi(t).map(n=>n.kind==="text"?JSON.stringify(n.text):n.kind==="arg"?`String(args.${n.key} ?? '')`:"prev");return s.length>0?s.join(" + "):'""'}function rf({label:t,agentType:s,prompt:n}){const a=[`label: ${JSON.stringify(t)}`];return s&&a.push(`agentType: ${JSON.stringify(s)}`),` () => agent(${af(n)}, { ${a.join(", ")} }),`}function pi(t){const s=["// Generated by the workflow designer. Editing this code detaches it from the designer.","const collect = (labels, outputs) =>"," labels.map((label, i) => '## ' + label + '\\n\\n' + (outputs[i] ?? '(failed)')).join('\\n\\n');","let prev = '';"];for(const n of t.phases){const a=JSON.stringify(n.steps.map(r=>r.label));s.push("",`await phase(${JSON.stringify(n.title)});`,`prev = collect(${a}, await parallel([`,...n.steps.map(rf),"]));")}return s.push("","return prev;",""),s.join(`
30
- `)}async function of(t){const[s,n,a]=await Promise.all([ps(()=>import("./standalone-oyxre9MX.js"),[],import.meta.url),ps(()=>import("./babel-BktJt1uC.js"),[],import.meta.url),ps(()=>import("./estree-C_HWBWad.js"),[],import.meta.url)]);try{return{ok:!0,code:await s.format(t,{parser:"babel",plugins:[n,a],singleQuote:!0,printWidth:100,trailingComma:"es5"})}}catch(r){const o=r instanceof Error?r.message:String(r);return{ok:!1,error:o.split(`
31
- `)[0]??o}}}const lf=32,Dt=(t,s)=>Math.max(0,Math.min(t,s));function cf(t){return t.phases.reduce((s,n)=>s+n.steps.length,0)<lf}function df(t,s,n){const a=t.phases.map((r,o)=>o===s?{...r,steps:[...r.steps,n]}:r);return{design:{phases:a},selection:{kind:"step",phase:s,step:(a[s]?.steps.length??1)-1}}}function uf(t,s,n){const a=Dt(s,t.phases.length),r=[...t.phases];return r.splice(a,0,n),{design:{phases:r},selection:{kind:"phase",phase:a}}}function _r(t,s){const n=t.phases[s.phase];if(!n)return null;if(s.kind==="step"&&n.steps.length>1){const r=n.steps.filter((o,i)=>i!==s.step);return{design:{phases:t.phases.map((o,i)=>i===s.phase?{...o,steps:r}:o)},selection:{kind:"step",phase:s.phase,step:Dt(s.step,r.length-1)}}}if(t.phases.length===1)return null;const a=t.phases.filter((r,o)=>o!==s.phase);return{design:{phases:a},selection:{kind:"phase",phase:Dt(s.phase,a.length-1)}}}function Fr(t,s,n){const a=s+n;if(a<0||a>=t.phases.length||!t.phases[s])return{design:t,selection:{kind:"phase",phase:s}};const r=[...t.phases],[o]=r.splice(s,1);return o&&r.splice(a,0,o),{design:{phases:r},selection:{kind:"phase",phase:a}}}function mf(t,s){const n=Dt(s.phase,t.phases.length-1);if(s.kind==="phase")return{kind:"phase",phase:n};const a=t.phases[n]?.steps.length??1;return{kind:"step",phase:n,step:Dt(s.step,a-1)}}const sn="__default__",Ur=(t="scout")=>({label:"",agentType:t,prompt:""});function hf({value:t,tokens:s,args:n,onChange:a}){const{t:r}=U(),o=m.useRef(null),i=()=>o.current?.querySelector("textarea")??null,c=x=>{const h=i(),u=t.length,p=ef(t,h?.selectionStart??u,h?.selectionEnd??u,x);a(p.text),requestAnimationFrame(()=>{h?.focus(),h?.setSelectionRange(p.cursor,p.cursor)})},d=x=>x.kind==="prev"?r("Previous phase output"):n.find(h=>h.key.trim()===x.key)?.label.trim()||x.key;return e.jsxs("div",{ref:o,className:"space-y-1",children:[e.jsx(Xe,{rows:5,className:"text-xs",placeholder:r("Prompt"),value:t,onChange:x=>a(x.target.value)}),e.jsxs(Ro,{children:[e.jsxs(Oo,{disabled:s.length===0,className:"inline-flex h-6 items-center gap-1 rounded-md px-1.5 text-muted-foreground text-xs hover:bg-accent hover:text-foreground disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(ld,{className:"h-3.5 w-3.5"}),r("Insert argument")]}),e.jsx(Do,{align:"start",zIndex:Qe.DROPDOWN_IN_MODAL,finalFocus:i,children:s.map(x=>e.jsxs(Lo,{onClick:()=>c(x.token),children:[d(x),e.jsx("span",{className:"ml-auto pl-4 font-mono text-muted-foreground text-xs",children:x.token})]},x.token))})]})]})}const $r=(t,s,n,a)=>{const r=Math.max((n-t)/2,8);return`M${t},${s} C${t+r},${s} ${n-r},${a} ${n},${a}`};function xf(t,s){const[n,a]=m.useState([]);return m.useLayoutEffect(()=>{const r=t.current;if(!r)return;const o=()=>{const c=r.getBoundingClientRect(),d=r.offsetWidth?c.width/r.offsetWidth:1,x=p=>{const l=r.querySelector(p)?.getBoundingClientRect();return l?{left:(l.left-c.left)/d,right:(l.right-c.left)/d,y:(l.top-c.top+l.height/2)/d}:null},h=(p,l)=>p<0||p>=s.phases.length?[`[data-node="${l}"]`]:(s.phases[p]?.steps??[]).map((f,g)=>`[data-node="s-${p}-${g}"]`),u=[];for(let p=0;p<=s.phases.length;p++){const l=x(`[data-gap="${p}"]`);if(l){for(const f of h(p-1,"start")){const g=x(f);g&&u.push({d:$r(g.right,g.y,l.left,l.y),arrow:!1})}for(const f of h(p,"end")){const g=x(f);g&&u.push({d:$r(l.right,l.y,g.left-2,g.y),arrow:!0})}}}a(u)};o();const i=new ResizeObserver(o);return i.observe(r),()=>i.disconnect()},[t,s]),n}function Vr({node:t,icon:s,title:n,detail:a}){return e.jsxs("div",{"data-node":t,className:"flex w-24 shrink-0 flex-col items-center gap-0.5 rounded-full border bg-background px-3 py-1.5 text-center shadow-xs",children:[e.jsxs("span",{className:"flex items-center gap-1 font-medium text-xs",children:[s,n]}),e.jsx("span",{className:"w-full truncate text-[10px] text-muted-foreground",children:a})]})}function pf({prompt:t,args:s}){const{t:n}=U(),a=xi(t.trim());return a.length===0?e.jsx(e.Fragment,{children:n("No prompt yet")}):e.jsx(e.Fragment,{children:a.map((r,o)=>r.kind==="text"?e.jsx(m.Fragment,{children:r.text},o):e.jsx("span",{className:"rounded bg-primary/10 px-1 font-medium text-primary",children:r.kind==="prev"?n("Previous phase output"):s.find(i=>i.key.trim()===r.key)?.label.trim()||r.key},o))})}function ff({design:t,agentTypes:s,args:n,onChange:a}){const{t:r}=U(),[o,i]=m.useState({kind:"step",phase:0,step:0}),c=m.useRef(null),d=m.useId(),x=xf(c,t),h=t.phases,u=mf(t,o),p=h[u.phase],l=u.kind==="step"?p?.steps[u.step]:void 0,f=s.includes("scout")?"scout":"",g=n.map(S=>S.key.trim()).filter(Boolean),y=cf(t),N=_r(t,u)!==null,j=S=>{S&&(a(S.design),i(S.selection))},v=S=>a({phases:h.map((O,w)=>w===u.phase?{...O,...S}:O)}),k=S=>u.kind==="step"&&v({steps:(p?.steps??[]).map((O,w)=>w===u.step?{...O,...S}:O)}),R=S=>{const O=S&&!s.includes(S)?[...s,S]:s;return[{value:sn,label:r("Default (worker)")},...O.map(w=>({value:w,label:w}))]},L=S=>e.jsx("div",{className:"flex w-10 shrink-0 items-center justify-center self-stretch",children:e.jsx("button",{type:"button","data-gap":S,disabled:!y,"aria-label":r("Insert phase here"),title:r("Insert phase here"),onClick:()=>j(uf(t,S,{title:"",steps:[Ur(f)]})),className:"relative z-30 flex h-5 w-5 items-center justify-center rounded-full border bg-background text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:e.jsx(Ee,{className:"h-3 w-3"})})});return e.jsxs("div",{className:"w-full space-y-2",children:[e.jsx("div",{className:"overflow-x-auto rounded-lg border bg-muted/30",children:e.jsxs("div",{ref:c,className:"relative flex w-max min-w-full items-center justify-center px-3 py-5",children:[e.jsxs("svg",{"aria-hidden":!0,className:"pointer-events-none absolute inset-0 z-20 h-full w-full overflow-visible text-muted-foreground/50",children:[e.jsx("defs",{children:e.jsx("marker",{id:d,viewBox:"0 0 6 6",refX:"5",refY:"3",markerWidth:"6",markerHeight:"6",orient:"auto",children:e.jsx("path",{d:"M0,0 L6,3 L0,6 z",fill:"currentColor"})})}),x.map(S=>e.jsx("path",{d:S.d,fill:"none",stroke:"currentColor",strokeWidth:1.25,markerEnd:S.arrow?`url(#${d})`:void 0},S.d))]}),e.jsx(Vr,{node:"start",icon:e.jsx(rd,{className:"h-3 w-3"}),title:r("Start"),detail:g.length>0?g.join(", "):r("No arguments")}),h.map((S,O)=>e.jsxs(m.Fragment,{children:[L(O),e.jsxs("div",{className:K("flex w-44 shrink-0 flex-col gap-1.5 rounded-xl border border-dashed bg-background/60 p-2",u.kind==="phase"&&u.phase===O&&"border-primary border-solid"),children:[e.jsxs("button",{type:"button",onClick:()=>i({kind:"phase",phase:O}),className:K("flex min-w-0 items-center gap-1 rounded px-1 text-left text-[11px] hover:text-foreground",S.title.trim()?"text-muted-foreground":"text-destructive"),children:[e.jsx("span",{className:"shrink-0",children:r("Phase {{n}}",{n:O+1})}),e.jsx("span",{className:"truncate font-medium text-foreground",children:S.title.trim()||r("Untitled phase")})]}),S.steps.map((w,M)=>{const E=u.kind==="step"&&u.phase===O&&u.step===M,I=!w.label.trim()||!w.prompt.trim();return e.jsxs("button",{type:"button","data-node":`s-${O}-${M}`,onClick:()=>i({kind:"step",phase:O,step:M}),className:K("block w-full rounded-lg border bg-background px-2.5 py-1.5 text-left shadow-xs transition-colors hover:border-primary/60",E&&"border-primary ring-2 ring-primary/20",I&&!E&&"border-destructive/50"),children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate font-medium text-xs",children:w.label.trim()||r("Untitled step")}),e.jsx("span",{className:"ml-auto shrink-0 rounded bg-muted px-1 text-[10px] text-muted-foreground",children:w.agentType||"worker"})]}),e.jsx("span",{className:"mt-0.5 line-clamp-2 break-words text-[11px] text-muted-foreground",children:e.jsx(pf,{prompt:w.prompt,args:n})})]},M)}),e.jsxs("button",{type:"button",disabled:!y,onClick:()=>j(df(t,O,Ur(f))),className:"flex items-center justify-center gap-1 rounded-lg border border-dashed py-1 text-[11px] text-muted-foreground transition-colors hover:border-primary hover:text-primary disabled:pointer-events-none disabled:opacity-50",children:[e.jsx(Ee,{className:"h-3 w-3"}),r("Parallel step")]})]})]},O)),L(h.length),e.jsx(Vr,{node:"end",icon:e.jsx(qd,{className:"h-3 w-3"}),title:r("Result"),detail:r("Last phase output")})]})}),e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium text-xs",children:u.kind==="phase"?r("Phase {{n}}",{n:u.phase+1}):r("Phase {{n}} · Step {{m}}",{n:u.phase+1,m:u.step+1})}),e.jsxs("span",{className:"ml-auto flex items-center",children:[u.kind==="phase"&&e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"ghost",size:"icon-xs","aria-label":r("Move left"),disabled:u.phase===0,onClick:()=>j(Fr(t,u.phase,-1)),children:e.jsx(od,{})}),e.jsx(A,{variant:"ghost",size:"icon-xs","aria-label":r("Move right"),disabled:u.phase===h.length-1,onClick:()=>j(Fr(t,u.phase,1)),children:e.jsx(id,{})})]}),e.jsx(A,{variant:"ghost",size:"icon-xs","aria-label":r("Delete"),disabled:!N,onClick:()=>j(_r(t,u)),children:e.jsx(Ae,{})})]})]}),u.kind==="phase"||!l?e.jsx(J,{size:"sm",placeholder:r("Phase title"),value:p?.title??"",onChange:S=>v({title:S.target.value})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"min-w-0 flex-1",placeholder:r("Label"),value:l.label,onChange:S=>k({label:S.target.value})}),e.jsxs(ee,{items:R(l.agentType),value:l.agentType||sn,onValueChange:S=>k({agentType:S===sn?"":String(S??"")}),children:[e.jsx(te,{size:"sm",className:"w-36 min-w-0 shrink-0",children:e.jsx(se,{})}),e.jsx(ne,{zIndex:Qe.DROPDOWN_IN_MODAL,children:R(l.agentType).map(S=>e.jsx(X,{value:S.value,children:S.label},S.value))})]})]}),e.jsx(hf,{value:l.prompt,tokens:Zp(g,u.phase),args:n,onChange:S=>k({prompt:S})})]})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:r("Click a node to edit it. Steps in a column run in parallel; columns run from left to right.")})]})}const gn={phases:[{title:"Investigate",steps:[{label:"code",agentType:"scout",prompt:"Investigate {{args.topic}} in the source code."},{label:"tests",agentType:"scout",prompt:"Investigate {{args.topic}} in the tests."}]},{title:"Summarize",steps:[{label:"summary",agentType:"scout",prompt:`Merge these findings about {{args.topic}} into one short report:
32
-
33
- {{prev}}`}]}]},Kr={name:"",description:"",args:[{key:"topic",label:"Topic",required:!0}],design:gn,script:pi(gn)};function gf(t){return t.map(({key:s,label:n,default:a,required:r})=>({key:s.trim(),label:n.trim()||s.trim(),...a?.trim()?{default:a}:{},...r?{required:!0}:{}}))}function jf({target:t,onClose:s,onSaved:n}){const{t:a}=U(),[r,o]=m.useState(Kr),[i,c]=m.useState("design"),[d,x]=m.useState(0),h=m.useRef(null),[u,p]=m.useState(!1),[l,f]=m.useState(!1),[g,y]=m.useState(!1),[N,j]=m.useState(null),v=b(C=>C.disabledBuiltinAgentTypes),k=b(C=>C.agentTypes),R=m.useMemo(()=>[...cd.map(C=>C.name).filter(C=>!v.includes(C)),...k.map(C=>C.name)],[v,k]);m.useEffect(()=>{if(j(null),t===null)return;if(h.current=null,x(_=>_+1),t==="new"){o(Kr),c("design");return}let C=!1;return p(!0),window.electronAPI.workflowPresets.read(t).then(_=>{if(!C)if(_){const{id:V,...H}=_;o(H),c(H.design?"design":"code"),x($=>$+1)}else j(a("Failed to read content"))}).finally(()=>{C||p(!1)}),()=>{C=!0}},[t,a]);const L=C=>o(_=>({..._,...C})),S=(C,_)=>L({args:r.args.map((V,H)=>H===C?{...V,..._}:V)}),O=C=>L({design:C,script:pi(C)}),w=C=>{C!==r.script&&(r.design&&(h.current=r.design),o(_=>({..._,script:C,design:void 0})))},M=async()=>{y(!0);const C=await of(r.script);if(y(!1),!C.ok){j(a("Format failed: {{error}}",{error:C.error}));return}j(null),C.code!==r.script&&(w(C.code),x(_=>_+1))},E=!r.design||nf(r.design)!==null,I=!u&&!l&&r.name.trim()!==""&&r.description.trim()!==""&&E&&r.script.trim()!=="",B=async()=>{if(!I||t===null)return;f(!0);const C=await window.electronAPI.workflowPresets.save({...r,args:gf(r.args)},t==="new"?void 0:t);if(f(!1),!C.ok){j(a(C.error));return}n(),s()};return e.jsx(pe,{open:t!==null,onOpenChange:C=>!C&&s(),children:e.jsxs(fe,{className:"max-w-4xl",children:[e.jsx(ge,{children:e.jsx(je,{children:a(t==="new"?"Add workflow preset":"Edit workflow preset")})}),e.jsxs(Se,{className:"space-y-4",children:[e.jsxs(ce,{children:[e.jsx(de,{children:a("Name")}),e.jsx(J,{value:r.name,onChange:C=>L({name:C.target.value})})]}),e.jsxs(ce,{children:[e.jsx(de,{children:a("Description")}),e.jsx(J,{value:r.description,onChange:C=>L({description:C.target.value})})]}),e.jsxs(ce,{children:[e.jsx(de,{children:a("Arguments")}),e.jsxs("div",{className:"w-full space-y-1.5",children:[r.args.map((C,_)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(J,{size:"sm",className:"w-28 font-mono",placeholder:"key",value:C.key,onChange:V=>S(_,{key:V.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Label"),value:C.label,onChange:V=>S(_,{label:V.target.value})}),e.jsx(J,{size:"sm",className:"flex-1",placeholder:a("Default value"),value:C.default??"",onChange:V=>S(_,{default:V.target.value})}),e.jsxs("span",{className:"flex shrink-0 items-center gap-1 text-muted-foreground text-xs",children:[e.jsx(We,{checked:C.required===!0,onCheckedChange:V=>S(_,{required:V===!0})}),a("Required")]}),e.jsx(A,{variant:"ghost",size:"icon-xs","aria-label":a("Remove"),onClick:()=>L({args:r.args.filter((V,H)=>H!==_)}),children:e.jsx(Ct,{})})]},_)),e.jsxs(A,{variant:"outline",size:"xs",disabled:r.args.length>=8,onClick:()=>L({args:[...r.args,{key:"",label:""}]}),children:[e.jsx(Ee,{}),a("Add argument")]})]})]}),e.jsxs(ce,{children:[e.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx(de,{children:a("Steps")}),i==="code"&&e.jsxs(A,{variant:"ghost",size:"xs",className:"ml-auto",disabled:u||g||!!r.design||!r.script.trim(),title:r.design?a("Generated code is already formatted"):void 0,onClick:M,children:[g?e.jsx(Te,{className:"animate-spin"}):e.jsx(dd,{}),a("Format")]}),e.jsx(zt,{value:i,onValueChange:C=>c(C),children:e.jsxs(Bt,{children:[e.jsx(Ke,{value:"design",children:a("Design")}),e.jsx(Ke,{value:"code",children:a("Code")})]})})]}),u?e.jsx("div",{className:"flex w-full items-center justify-center rounded-md border py-12",children:e.jsx(Te,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):i==="design"?r.design?e.jsx(ff,{design:r.design,agentTypes:R,args:r.args,onChange:O}):e.jsxs("div",{className:"flex w-full flex-col items-center gap-2 rounded-md border border-dashed py-8 text-center",children:[e.jsx("p",{className:"max-w-md text-muted-foreground text-xs",children:a("This preset is plain code and cannot be shown in the designer. Using the designer replaces the current script.")}),e.jsx(A,{variant:"outline",size:"xs",onClick:()=>O(h.current??gn),children:a("Use the designer")})]}):e.jsx(ai,{fileName:"workflow.js",className:"h-80",value:r.script,epoch:d,onChange:w}),e.jsx("p",{className:"text-muted-foreground text-xs",children:i==="design"?!E&&a("Every phase needs a title and every step needs a label and a prompt."):r.design?a("Generated from the design. Editing the code detaches it from the designer."):a("Plain JavaScript with top-level await; end with return. Available: agent(prompt, opts), parallel, pipeline, phase, log, args.")})]}),N&&e.jsxs("p",{className:"flex items-center gap-1.5 text-destructive text-xs",children:[e.jsx(St,{className:"h-3.5 w-3.5 shrink-0"}),N]})]}),e.jsxs(Ie,{children:[e.jsx(A,{variant:"outline",size:"sm",onClick:s,children:a("Cancel")}),e.jsxs(A,{size:"sm",disabled:!I,onClick:B,children:[l&&e.jsx(Te,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}),a("Save")]})]})]})})}function vf(){const{t}=U(),[s,n]=m.useState([]),[a,r]=m.useState(null),o=b(h=>h.disabledWorkflowPresets),i=b(h=>h.toggleWorkflowPreset),c=m.useCallback(()=>{window.electronAPI.workflowPresets.list().then(n)},[]);m.useEffect(c,[c]);const d=s.filter(h=>h.source!=="builtin"),x=s.filter(h=>h.source==="builtin");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-end justify-between gap-4","data-settings-row":"workflows.root",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-lg",children:t("Workflows")}),e.jsx("p",{className:"text-muted-foreground text-sm",children:t("Preset workflows you can run from the Workflow side panel")}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t("Project .agents/workflows files take precedence over these; ~/.agents/workflows and built-in presets come after.")})]}),e.jsxs(A,{variant:"outline",size:"sm",onClick:()=>r("new"),children:[e.jsx(Ee,{className:"mr-1.5 h-4 w-4"}),t("Add workflow preset")]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Custom presets")}),d.length===0?e.jsxs("div",{className:"rounded-md border border-dashed px-3 py-8 text-center",children:[e.jsx(Tn,{className:"mx-auto h-5 w-5 text-muted-foreground"}),e.jsx("p",{className:"mt-3 font-medium text-sm",children:t("No custom workflow presets yet")})]}):e.jsx("div",{className:"space-y-1",children:d.map(h=>e.jsxs("div",{className:"group flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:h.name}),e.jsx(Z,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"truncate text-muted-foreground text-xs",children:h.description})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100","aria-label":t("Edit"),onClick:()=>r(h.id),children:e.jsx(ot,{className:"h-3.5 w-3.5"})}),e.jsx(A,{variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground opacity-0 transition-opacity hover:text-destructive group-hover:opacity-100","aria-label":t("Delete"),onClick:()=>{window.electronAPI.workflowPresets.delete(h.id).then(c)},children:e.jsx(Ae,{className:"h-3.5 w-3.5"})})]})]},h.id))})]}),x.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium text-muted-foreground text-xs",children:t("Built-in presets")}),e.jsx("div",{className:"space-y-1",children:x.map(h=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md px-3 py-2 transition-colors hover:bg-accent/50","data-settings-row":`workflows.builtin.${h.id}`,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:t(h.name)}),e.jsx(Z,{variant:"secondary",className:"shrink-0 font-mono text-[11px]",children:h.id})]}),e.jsx("p",{className:"text-muted-foreground text-xs",children:t(h.description)}),h.args.length>0&&e.jsxs("p",{className:"mt-0.5 text-muted-foreground text-xs",children:[t("Arguments"),":"," ",h.args.map(u=>`${t(u.label)}${u.required?" *":""}`).join(" · ")]})]}),e.jsx(oe,{"aria-label":t(h.name),checked:!o.includes(h.id),onCheckedChange:u=>i(h.id,u)})]},h.id))})]}),e.jsx(jf,{target:a,onClose:()=>r(null),onSaved:c})]})}function bf(t){window.requestAnimationFrame(()=>{const s=document.querySelector(`[data-settings-row="${CSS.escape(t)}"]`);s instanceof HTMLElement&&(s.scrollIntoView({block:"center"}),s.dataset.settingsFlash="true",window.setTimeout(()=>{delete s.dataset.settingsFlash},1600))})}function qr(){const{t}=U(),[s,n]=m.useState("general"),[a,r]=m.useState(null),[o,i]=m.useState(null),[c,d]=m.useState(0),x=ud(),[h,u]=m.useState(!0),[p,l]=m.useState(""),[f,g]=m.useState([]),y=_=>{n(_),u(!1)},N=b(_=>_.disabledBuiltinTools),j=b(_=>_.botModeEnabled),v=m.useSyncExternalStore(_=>b.persist?.onFinishHydration?.(_)??(()=>{}),()=>b.persist?.hasHydrated?.()??!0),k=m.useCallback(_=>{n(_.category),u(!1),r(_.rowId),_.pluginInstallUrl&&i(_.pluginInstallUrl)},[]);m.useEffect(()=>(window.electronAPI.window.consumeSettingsDeepLink().then(_=>{_&&k(_)}),window.electronAPI.window.onSettingsDeepLink(k)),[k]),m.useEffect(()=>{let _=!0;return window.electronAPI.sshConnections.list().then(V=>{_&&g(V.map(H=>({id:H.id,name:H.name})))}).catch(()=>{_&&g([])}),()=>{_=!1}},[]);const R=md(f);m.useLayoutEffect(()=>{if(!a)return;bf(a);const _=window.setTimeout(()=>r(null),1600);return()=>window.clearTimeout(_)},[a]);const S=yp([{id:"general",icon:gd,label:"General"},{id:"shortcuts",icon:jd,label:"Shortcuts"},{id:"voice",icon:vd,label:"Voice input"},{id:"appearance",icon:eu,label:"Appearance"},{id:"providers",icon:Dn,label:"Model Providers"},{id:"presets",icon:bd,label:"Presets"},{id:"agents",icon:yd,label:"Agent types"},{id:"tools",icon:fo,label:"Built-in tools"},{id:"workflows",icon:Tn,label:"Workflows"},{id:"memory",icon:xo,label:"Memory"},{id:"privacy",icon:wd,label:"Privacy"},{id:"skills",icon:zn,label:"Skills"},{id:"plugins",icon:Lt,label:"Enso plugins"},{id:"claudePlugins",icon:Dd,label:"Claude Code plugins"},{id:"mcp",icon:bo,label:"MCP Servers"},{id:"instructions",icon:Rn,label:"Instruction Files"},{id:"phone",icon:rn,label:"Devices"},{id:"ssh",icon:ao,label:"SSH"},{id:"usage",icon:_d,label:"Usage"},{id:"resources",icon:Nd,label:"Resources"},{id:"experimental",icon:kd,label:"Experimental"},{id:"bots",icon:Cd,label:"Bot mode",sub:!0},{id:"botTemplates",icon:Sd,label:"Bot templates",sub:!0}],N,j),O=bp(Np(S,R,p,t)),w=wp(s,N,j||!v);m.useEffect(()=>{w!==s&&n(w)},[w,s]);const M=!x||h,E=!x||!h,I=S.find(_=>_.id===s)?.label,B=hd(),C=Bo();return e.jsxs("div",{className:"flex h-full w-full",children:[M&&e.jsxs("nav",{"data-enso":"settings-nav",className:K("flex min-h-0 shrink-0 flex-col",x?"w-full":B?"w-56":"w-56 border-r"),children:[B&&C==="mac"&&e.jsx("div",{"aria-hidden":!0,className:"drag-region -mb-2 h-[44px] shrink-0"}),e.jsx("div",{className:K("sticky top-0 z-10 px-2 pt-2",!B&&"bg-background"),children:e.jsxs("div",{className:"relative",children:[e.jsx(po,{className:"pointer-events-none absolute top-1/2 left-2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:p,onChange:_=>l(_.target.value),onKeyDown:_=>{_.key!=="Escape"||p.length===0||(_.preventDefault(),_.stopPropagation(),l(""))},placeholder:t("Search settings"),className:"h-8 w-full rounded-md border bg-transparent pr-2 pl-7 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-ring"})]})}),e.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto p-2",children:p.trim()&&O.length===0?e.jsx("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:t("No results")}):O.map((_,V)=>e.jsxs("div",{className:K(V>0&&"mt-4"),children:[e.jsx("div",{className:"px-2 pb-1.5 text-xs font-semibold text-foreground/55",children:t(_.label)}),e.jsx("div",{className:"space-y-0.5 rounded-lg bg-muted/60 p-1",children:_.items.map(H=>e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>y(H.id),className:K("flex w-full items-center gap-2 rounded-md px-3 text-sm transition-colors",x?"py-3":"py-1.5",H.sub&&"pl-8",s===H.id&&!x?"bg-background text-foreground shadow-xs":"text-muted-foreground hover:bg-background/60 hover:text-foreground"),children:[e.jsx(H.icon,{className:"h-4 w-4"}),t(H.label),x&&e.jsx(At,{className:"ml-auto h-4 w-4 opacity-60"})]}),H.hits.map($=>e.jsx("button",{type:"button",onClick:()=>{y(H.id),r($.id)},className:K("block w-full truncate rounded-md pr-3 text-left text-xs text-muted-foreground hover:bg-background/60 hover:text-foreground",H.sub?"pl-14":"pl-9",x?"py-2":"py-1"),children:t($.title)},$.id))]},H.id))})]},_.id))})]}),E&&e.jsxs("div",{"data-enso":"settings-content",className:K("flex min-w-0 flex-1 flex-col",B&&"my-[8px] mr-[8px] overflow-hidden rounded-[10px] bg-background shadow-surface"),children:[B&&e.jsx(xd,{"data-enso":"title-bar"}),e.jsxs("div",{className:K("min-h-0 flex-1 overflow-y-auto",x?"px-4 pb-6":B?"px-6 pb-6":"p-6"),children:[x&&e.jsxs("button",{type:"button",onClick:()=>u(!0),className:"sticky top-0 z-10 -mx-4 mb-3 flex w-[calc(100%+2rem)] items-center gap-1 border-b bg-background px-2 py-2.5 text-sm font-medium",children:[e.jsx(oo,{className:"h-5 w-5 text-muted-foreground"}),I?t(I):null]}),s==="general"&&e.jsx(_u,{}),s==="shortcuts"&&e.jsx(gh,{}),s==="appearance"&&e.jsx(um,{onOpenPlugins:()=>y("plugins")}),s==="providers"&&e.jsx(np,{}),s==="skills"&&e.jsx(pp,{}),s==="plugins"&&e.jsx(Bx,{requestedInstallUrl:o,onRequestedInstallUrlConsumed:()=>i(null)}),s==="claudePlugins"&&e.jsx(Ux,{}),s==="mcp"&&e.jsx(_h,{}),s==="instructions"&&e.jsx(fh,{}),s==="presets"&&e.jsx(pd,{}),s==="agents"&&e.jsx(fd,{}),s==="workflows"&&e.jsx(vf,{}),s==="tools"&&e.jsx(Dm,{}),s==="memory"&&e.jsxs("div",{className:"space-y-8",children:[e.jsx(Sx,{onLibraryChanged:()=>d(_=>_+1)}),e.jsx(nx,{revision:c}),e.jsx(mx,{revision:c})]}),s==="phone"&&e.jsx(lh,{}),s==="ssh"&&e.jsx(fp,{}),s==="usage"&&e.jsx(_p,{}),s==="privacy"&&e.jsx(Wx,{}),s==="resources"&&e.jsx(dp,{}),s==="voice"&&e.jsx(Gp,{}),s==="experimental"&&e.jsx(xh,{onOpenBots:()=>n("bots")}),s==="bots"&&e.jsx(jm,{}),s==="botTemplates"&&e.jsx(Cm,{})]})]})]})}Id();Ad();function yf(){const{t}=U(),s=Bo();return s!=="mobile"?e.jsxs("div",{"data-enso":"canvas",className:"flex h-screen overflow-hidden bg-canvas",children:[e.jsx(ha,{}),e.jsx(Md.Provider,{value:{trailing:e.jsxs(e.Fragment,{children:[e.jsx(xa,{label:!1}),e.jsx(Pd,{kind:s,edgeGap:8})]})},children:e.jsx(qr,{})}),e.jsx(pa,{})]}):e.jsxs("div",{className:"flex h-screen flex-col overflow-hidden",children:[e.jsx(ha,{}),e.jsx(Td,{title:t("Settings"),actions:e.jsxs(e.Fragment,{children:[e.jsx(xa,{label:!1}),window.electronAPI.remote&&e.jsx("button",{type:"button",className:"flex h-7 w-7 items-center justify-center rounded-md hover:bg-muted",onClick:()=>{window.electronAPI.window.close()},"aria-label":t("Close"),title:t("Close"),children:e.jsx(Ct,{className:"h-4 w-4"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 overflow-hidden",children:e.jsx(qr,{})}),e.jsx(pa,{})]})}Ed.createRoot(document.getElementById("root")).render(e.jsx(m.StrictMode,{children:e.jsx(yf,{})}));