profclaw 0.0.1-beta.1

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 (942) hide show
  1. package/.env.example +215 -0
  2. package/CHANGELOG.md +49 -0
  3. package/CONTRIBUTING.md +119 -0
  4. package/Dockerfile +107 -0
  5. package/LICENSE +661 -0
  6. package/README.md +196 -0
  7. package/config/agents.yml +55 -0
  8. package/config/budget.yml +15 -0
  9. package/config/pricing.yml +46 -0
  10. package/config/settings.yml +168 -0
  11. package/dist/adapters/claude-code.d.ts +46 -0
  12. package/dist/adapters/claude-code.js +215 -0
  13. package/dist/adapters/index.d.ts +4 -0
  14. package/dist/adapters/index.js +4 -0
  15. package/dist/adapters/ollama.d.ts +45 -0
  16. package/dist/adapters/ollama.js +277 -0
  17. package/dist/adapters/openclaw.d.ts +60 -0
  18. package/dist/adapters/openclaw.js +289 -0
  19. package/dist/adapters/registry.d.ts +56 -0
  20. package/dist/adapters/registry.js +163 -0
  21. package/dist/agents/executor.d.ts +78 -0
  22. package/dist/agents/executor.js +657 -0
  23. package/dist/agents/index.d.ts +10 -0
  24. package/dist/agents/index.js +27 -0
  25. package/dist/agents/stop-conditions.d.ts +108 -0
  26. package/dist/agents/stop-conditions.js +299 -0
  27. package/dist/agents/types.d.ts +185 -0
  28. package/dist/agents/types.js +14 -0
  29. package/dist/ai/embedding-service.d.ts +96 -0
  30. package/dist/ai/embedding-service.js +333 -0
  31. package/dist/auth/api-tokens.d.ts +71 -0
  32. package/dist/auth/api-tokens.js +235 -0
  33. package/dist/auth/auth-service.d.ts +75 -0
  34. package/dist/auth/auth-service.js +557 -0
  35. package/dist/auth/device-identity.d.ts +96 -0
  36. package/dist/auth/device-identity.js +250 -0
  37. package/dist/auth/github-oauth.d.ts +20 -0
  38. package/dist/auth/github-oauth.js +59 -0
  39. package/dist/auth/jira-oauth.d.ts +25 -0
  40. package/dist/auth/jira-oauth.js +75 -0
  41. package/dist/auth/linear-oauth.d.ts +21 -0
  42. package/dist/auth/linear-oauth.js +59 -0
  43. package/dist/auth/middleware.d.ts +44 -0
  44. package/dist/auth/middleware.js +190 -0
  45. package/dist/auth/pairing-codes.d.ts +109 -0
  46. package/dist/auth/pairing-codes.js +274 -0
  47. package/dist/auth/password.d.ts +53 -0
  48. package/dist/auth/password.js +126 -0
  49. package/dist/auth/qr-pairing.d.ts +36 -0
  50. package/dist/auth/qr-pairing.js +138 -0
  51. package/dist/auth/slack-oauth.d.ts +31 -0
  52. package/dist/auth/slack-oauth.js +80 -0
  53. package/dist/backup/index.d.ts +50 -0
  54. package/dist/backup/index.js +184 -0
  55. package/dist/browser/adapters.d.ts +25 -0
  56. package/dist/browser/adapters.js +32 -0
  57. package/dist/browser/cli.d.ts +19 -0
  58. package/dist/browser/cli.js +277 -0
  59. package/dist/browser/compression.d.ts +32 -0
  60. package/dist/browser/compression.js +269 -0
  61. package/dist/browser/extensions.d.ts +144 -0
  62. package/dist/browser/extensions.js +251 -0
  63. package/dist/browser/index.d.ts +37 -0
  64. package/dist/browser/index.js +43 -0
  65. package/dist/browser/refs.d.ts +46 -0
  66. package/dist/browser/refs.js +120 -0
  67. package/dist/browser/search.d.ts +36 -0
  68. package/dist/browser/search.js +193 -0
  69. package/dist/browser/service.d.ts +94 -0
  70. package/dist/browser/service.js +358 -0
  71. package/dist/browser/snapshot.d.ts +19 -0
  72. package/dist/browser/snapshot.js +250 -0
  73. package/dist/browser/tools.d.ts +259 -0
  74. package/dist/browser/tools.js +463 -0
  75. package/dist/browser/types.d.ts +134 -0
  76. package/dist/browser/types.js +17 -0
  77. package/dist/chat/agentic-executor.d.ts +108 -0
  78. package/dist/chat/agentic-executor.js +739 -0
  79. package/dist/chat/api-key-detector.d.ts +41 -0
  80. package/dist/chat/api-key-detector.js +290 -0
  81. package/dist/chat/auto-reply.d.ts +90 -0
  82. package/dist/chat/auto-reply.js +272 -0
  83. package/dist/chat/conversations.d.ts +91 -0
  84. package/dist/chat/conversations.js +297 -0
  85. package/dist/chat/execution/audit.d.ts +192 -0
  86. package/dist/chat/execution/audit.js +323 -0
  87. package/dist/chat/execution/executor.d.ts +56 -0
  88. package/dist/chat/execution/executor.js +654 -0
  89. package/dist/chat/execution/guardrails.d.ts +98 -0
  90. package/dist/chat/execution/guardrails.js +571 -0
  91. package/dist/chat/execution/index.d.ts +61 -0
  92. package/dist/chat/execution/index.js +129 -0
  93. package/dist/chat/execution/model-capability.d.ts +34 -0
  94. package/dist/chat/execution/model-capability.js +96 -0
  95. package/dist/chat/execution/process-pool.d.ts +110 -0
  96. package/dist/chat/execution/process-pool.js +290 -0
  97. package/dist/chat/execution/pty.d.ts +92 -0
  98. package/dist/chat/execution/pty.js +285 -0
  99. package/dist/chat/execution/rate-limiter.d.ts +87 -0
  100. package/dist/chat/execution/rate-limiter.js +305 -0
  101. package/dist/chat/execution/registry.d.ts +54 -0
  102. package/dist/chat/execution/registry.js +220 -0
  103. package/dist/chat/execution/sandbox.d.ts +109 -0
  104. package/dist/chat/execution/sandbox.js +684 -0
  105. package/dist/chat/execution/secrets.d.ts +45 -0
  106. package/dist/chat/execution/secrets.js +338 -0
  107. package/dist/chat/execution/security.d.ts +179 -0
  108. package/dist/chat/execution/security.js +739 -0
  109. package/dist/chat/execution/self-correction.d.ts +162 -0
  110. package/dist/chat/execution/self-correction.js +557 -0
  111. package/dist/chat/execution/session-manager.d.ts +79 -0
  112. package/dist/chat/execution/session-manager.js +356 -0
  113. package/dist/chat/execution/session-spawn/config.d.ts +37 -0
  114. package/dist/chat/execution/session-spawn/config.js +83 -0
  115. package/dist/chat/execution/session-spawn/index.d.ts +10 -0
  116. package/dist/chat/execution/session-spawn/index.js +10 -0
  117. package/dist/chat/execution/session-spawn/manager.d.ts +35 -0
  118. package/dist/chat/execution/session-spawn/manager.js +418 -0
  119. package/dist/chat/execution/session-spawn/types.d.ts +117 -0
  120. package/dist/chat/execution/session-spawn/types.js +16 -0
  121. package/dist/chat/execution/smart-prompts.d.ts +34 -0
  122. package/dist/chat/execution/smart-prompts.js +151 -0
  123. package/dist/chat/execution/stream-results.d.ts +65 -0
  124. package/dist/chat/execution/stream-results.js +156 -0
  125. package/dist/chat/execution/tool-router.d.ts +76 -0
  126. package/dist/chat/execution/tool-router.js +296 -0
  127. package/dist/chat/execution/tools/agents-list.d.ts +49 -0
  128. package/dist/chat/execution/tools/agents-list.js +165 -0
  129. package/dist/chat/execution/tools/browser.d.ts +12 -0
  130. package/dist/chat/execution/tools/browser.js +14 -0
  131. package/dist/chat/execution/tools/canvas.d.ts +61 -0
  132. package/dist/chat/execution/tools/canvas.js +150 -0
  133. package/dist/chat/execution/tools/complete-task.d.ts +72 -0
  134. package/dist/chat/execution/tools/complete-task.js +104 -0
  135. package/dist/chat/execution/tools/cron-tool.d.ts +204 -0
  136. package/dist/chat/execution/tools/cron-tool.js +680 -0
  137. package/dist/chat/execution/tools/discord-actions.d.ts +120 -0
  138. package/dist/chat/execution/tools/discord-actions.js +361 -0
  139. package/dist/chat/execution/tools/exec.d.ts +43 -0
  140. package/dist/chat/execution/tools/exec.js +223 -0
  141. package/dist/chat/execution/tools/file-ops.d.ts +175 -0
  142. package/dist/chat/execution/tools/file-ops.js +723 -0
  143. package/dist/chat/execution/tools/git.d.ts +143 -0
  144. package/dist/chat/execution/tools/git.js +395 -0
  145. package/dist/chat/execution/tools/github.d.ts +42 -0
  146. package/dist/chat/execution/tools/github.js +184 -0
  147. package/dist/chat/execution/tools/glinr-ops.d.ts +202 -0
  148. package/dist/chat/execution/tools/glinr-ops.js +694 -0
  149. package/dist/chat/execution/tools/image-analyze.d.ts +29 -0
  150. package/dist/chat/execution/tools/image-analyze.js +127 -0
  151. package/dist/chat/execution/tools/index.d.ts +64 -0
  152. package/dist/chat/execution/tools/index.js +245 -0
  153. package/dist/chat/execution/tools/integrations.d.ts +109 -0
  154. package/dist/chat/execution/tools/integrations.js +237 -0
  155. package/dist/chat/execution/tools/link-understand.d.ts +34 -0
  156. package/dist/chat/execution/tools/link-understand.js +307 -0
  157. package/dist/chat/execution/tools/maintenance.d.ts +29 -0
  158. package/dist/chat/execution/tools/maintenance.js +105 -0
  159. package/dist/chat/execution/tools/memory-tools.d.ts +76 -0
  160. package/dist/chat/execution/tools/memory-tools.js +278 -0
  161. package/dist/chat/execution/tools/openai-image-gen.d.ts +51 -0
  162. package/dist/chat/execution/tools/openai-image-gen.js +212 -0
  163. package/dist/chat/execution/tools/profclaw-ops.d.ts +204 -0
  164. package/dist/chat/execution/tools/profclaw-ops.js +665 -0
  165. package/dist/chat/execution/tools/session-spawn.d.ts +146 -0
  166. package/dist/chat/execution/tools/session-spawn.js +544 -0
  167. package/dist/chat/execution/tools/session-status.d.ts +38 -0
  168. package/dist/chat/execution/tools/session-status.js +185 -0
  169. package/dist/chat/execution/tools/sessions-list.d.ts +49 -0
  170. package/dist/chat/execution/tools/sessions-list.js +153 -0
  171. package/dist/chat/execution/tools/sessions-send.d.ts +48 -0
  172. package/dist/chat/execution/tools/sessions-send.js +207 -0
  173. package/dist/chat/execution/tools/sessions-spawn.d.ts +51 -0
  174. package/dist/chat/execution/tools/sessions-spawn.js +137 -0
  175. package/dist/chat/execution/tools/slack-actions.d.ts +90 -0
  176. package/dist/chat/execution/tools/slack-actions.js +272 -0
  177. package/dist/chat/execution/tools/subagent-orchestrate.d.ts +66 -0
  178. package/dist/chat/execution/tools/subagent-orchestrate.js +313 -0
  179. package/dist/chat/execution/tools/system.d.ts +121 -0
  180. package/dist/chat/execution/tools/system.js +415 -0
  181. package/dist/chat/execution/tools/telegram-actions.d.ts +126 -0
  182. package/dist/chat/execution/tools/telegram-actions.js +339 -0
  183. package/dist/chat/execution/tools/test-run.d.ts +43 -0
  184. package/dist/chat/execution/tools/test-run.js +391 -0
  185. package/dist/chat/execution/tools/tts-speak.d.ts +39 -0
  186. package/dist/chat/execution/tools/tts-speak.js +199 -0
  187. package/dist/chat/execution/tools/web-fetch.d.ts +42 -0
  188. package/dist/chat/execution/tools/web-fetch.js +247 -0
  189. package/dist/chat/execution/tools/web-search.d.ts +53 -0
  190. package/dist/chat/execution/tools/web-search.js +130 -0
  191. package/dist/chat/execution/types.d.ts +337 -0
  192. package/dist/chat/execution/types.js +8 -0
  193. package/dist/chat/execution/workflows/built-in.d.ts +10 -0
  194. package/dist/chat/execution/workflows/built-in.js +249 -0
  195. package/dist/chat/execution/workflows/executor.d.ts +13 -0
  196. package/dist/chat/execution/workflows/executor.js +259 -0
  197. package/dist/chat/execution/workflows/index.d.ts +5 -0
  198. package/dist/chat/execution/workflows/index.js +5 -0
  199. package/dist/chat/execution/workflows/trigger.d.ts +15 -0
  200. package/dist/chat/execution/workflows/trigger.js +111 -0
  201. package/dist/chat/execution/workflows/types.d.ts +80 -0
  202. package/dist/chat/execution/workflows/types.js +2 -0
  203. package/dist/chat/failover/error.d.ts +73 -0
  204. package/dist/chat/failover/error.js +412 -0
  205. package/dist/chat/failover/index.d.ts +10 -0
  206. package/dist/chat/failover/index.js +11 -0
  207. package/dist/chat/failover/model-fallback.d.ts +97 -0
  208. package/dist/chat/failover/model-fallback.js +328 -0
  209. package/dist/chat/failover/types.d.ts +47 -0
  210. package/dist/chat/failover/types.js +8 -0
  211. package/dist/chat/format/chunk.d.ts +59 -0
  212. package/dist/chat/format/chunk.js +253 -0
  213. package/dist/chat/format/index.d.ts +7 -0
  214. package/dist/chat/format/index.js +7 -0
  215. package/dist/chat/format/tool-result-formatter.d.ts +30 -0
  216. package/dist/chat/format/tool-result-formatter.js +177 -0
  217. package/dist/chat/group.d.ts +232 -0
  218. package/dist/chat/group.js +311 -0
  219. package/dist/chat/index.d.ts +21 -0
  220. package/dist/chat/index.js +30 -0
  221. package/dist/chat/memory.d.ts +108 -0
  222. package/dist/chat/memory.js +343 -0
  223. package/dist/chat/message-handler.d.ts +38 -0
  224. package/dist/chat/message-handler.js +274 -0
  225. package/dist/chat/proactive/index.d.ts +167 -0
  226. package/dist/chat/proactive/index.js +721 -0
  227. package/dist/chat/prompt-adapter.d.ts +52 -0
  228. package/dist/chat/prompt-adapter.js +245 -0
  229. package/dist/chat/providers/dingtalk/index.d.ts +69 -0
  230. package/dist/chat/providers/dingtalk/index.js +225 -0
  231. package/dist/chat/providers/discord/index.d.ts +264 -0
  232. package/dist/chat/providers/discord/index.js +657 -0
  233. package/dist/chat/providers/feishu/index.d.ts +97 -0
  234. package/dist/chat/providers/feishu/index.js +362 -0
  235. package/dist/chat/providers/googlechat/index.d.ts +269 -0
  236. package/dist/chat/providers/googlechat/index.js +634 -0
  237. package/dist/chat/providers/imessage/index.d.ts +61 -0
  238. package/dist/chat/providers/imessage/index.js +166 -0
  239. package/dist/chat/providers/index.d.ts +76 -0
  240. package/dist/chat/providers/index.js +430 -0
  241. package/dist/chat/providers/irc/index.d.ts +101 -0
  242. package/dist/chat/providers/irc/index.js +557 -0
  243. package/dist/chat/providers/line/index.d.ts +113 -0
  244. package/dist/chat/providers/line/index.js +434 -0
  245. package/dist/chat/providers/matrix/index.d.ts +161 -0
  246. package/dist/chat/providers/matrix/index.js +559 -0
  247. package/dist/chat/providers/mattermost/index.d.ts +106 -0
  248. package/dist/chat/providers/mattermost/index.js +425 -0
  249. package/dist/chat/providers/msteams/index.d.ts +198 -0
  250. package/dist/chat/providers/msteams/index.js +694 -0
  251. package/dist/chat/providers/nextcloud/index.d.ts +52 -0
  252. package/dist/chat/providers/nextcloud/index.js +156 -0
  253. package/dist/chat/providers/nostr/index.d.ts +60 -0
  254. package/dist/chat/providers/nostr/index.js +200 -0
  255. package/dist/chat/providers/qq/index.d.ts +57 -0
  256. package/dist/chat/providers/qq/index.js +260 -0
  257. package/dist/chat/providers/registry.d.ts +89 -0
  258. package/dist/chat/providers/registry.js +213 -0
  259. package/dist/chat/providers/signal/index.d.ts +88 -0
  260. package/dist/chat/providers/signal/index.js +357 -0
  261. package/dist/chat/providers/slack/index.d.ts +52 -0
  262. package/dist/chat/providers/slack/index.js +477 -0
  263. package/dist/chat/providers/synology/index.d.ts +50 -0
  264. package/dist/chat/providers/synology/index.js +138 -0
  265. package/dist/chat/providers/telegram/index.d.ts +148 -0
  266. package/dist/chat/providers/telegram/index.js +492 -0
  267. package/dist/chat/providers/tlon/index.d.ts +44 -0
  268. package/dist/chat/providers/tlon/index.js +243 -0
  269. package/dist/chat/providers/twitch/index.d.ts +79 -0
  270. package/dist/chat/providers/twitch/index.js +349 -0
  271. package/dist/chat/providers/types.d.ts +437 -0
  272. package/dist/chat/providers/types.js +14 -0
  273. package/dist/chat/providers/webchat/index.d.ts +38 -0
  274. package/dist/chat/providers/webchat/index.js +214 -0
  275. package/dist/chat/providers/wecom/index.d.ts +62 -0
  276. package/dist/chat/providers/wecom/index.js +228 -0
  277. package/dist/chat/providers/whatsapp/index.d.ts +147 -0
  278. package/dist/chat/providers/whatsapp/index.js +396 -0
  279. package/dist/chat/providers/zalo/index.d.ts +54 -0
  280. package/dist/chat/providers/zalo/index.js +158 -0
  281. package/dist/chat/providers/zalo-personal/index.d.ts +53 -0
  282. package/dist/chat/providers/zalo-personal/index.js +212 -0
  283. package/dist/chat/skills.d.ts +82 -0
  284. package/dist/chat/skills.js +410 -0
  285. package/dist/chat/system-prompts.d.ts +76 -0
  286. package/dist/chat/system-prompts.js +407 -0
  287. package/dist/chat/tool-handler.d.ts +57 -0
  288. package/dist/chat/tool-handler.js +336 -0
  289. package/dist/chat/tools.d.ts +373 -0
  290. package/dist/chat/tools.js +512 -0
  291. package/dist/cli/commands/agent.d.ts +3 -0
  292. package/dist/cli/commands/agent.js +108 -0
  293. package/dist/cli/commands/auth.d.ts +12 -0
  294. package/dist/cli/commands/auth.js +301 -0
  295. package/dist/cli/commands/browser.d.ts +3 -0
  296. package/dist/cli/commands/browser.js +138 -0
  297. package/dist/cli/commands/canvas.d.ts +3 -0
  298. package/dist/cli/commands/canvas.js +155 -0
  299. package/dist/cli/commands/channels.d.ts +3 -0
  300. package/dist/cli/commands/channels.js +167 -0
  301. package/dist/cli/commands/chat.d.ts +9 -0
  302. package/dist/cli/commands/chat.js +360 -0
  303. package/dist/cli/commands/completion.d.ts +3 -0
  304. package/dist/cli/commands/completion.js +170 -0
  305. package/dist/cli/commands/config.d.ts +3 -0
  306. package/dist/cli/commands/config.js +193 -0
  307. package/dist/cli/commands/cost.d.ts +3 -0
  308. package/dist/cli/commands/cost.js +134 -0
  309. package/dist/cli/commands/daemon.d.ts +3 -0
  310. package/dist/cli/commands/daemon.js +381 -0
  311. package/dist/cli/commands/devices.d.ts +3 -0
  312. package/dist/cli/commands/devices.js +150 -0
  313. package/dist/cli/commands/doctor.d.ts +3 -0
  314. package/dist/cli/commands/doctor.js +295 -0
  315. package/dist/cli/commands/logs.d.ts +3 -0
  316. package/dist/cli/commands/logs.js +139 -0
  317. package/dist/cli/commands/mcp.d.ts +15 -0
  318. package/dist/cli/commands/mcp.js +157 -0
  319. package/dist/cli/commands/memory.d.ts +3 -0
  320. package/dist/cli/commands/memory.js +170 -0
  321. package/dist/cli/commands/models.d.ts +3 -0
  322. package/dist/cli/commands/models.js +197 -0
  323. package/dist/cli/commands/nodes.d.ts +3 -0
  324. package/dist/cli/commands/nodes.js +193 -0
  325. package/dist/cli/commands/onboard.d.ts +13 -0
  326. package/dist/cli/commands/onboard.js +360 -0
  327. package/dist/cli/commands/plugin.d.ts +15 -0
  328. package/dist/cli/commands/plugin.js +226 -0
  329. package/dist/cli/commands/provider.d.ts +16 -0
  330. package/dist/cli/commands/provider.js +320 -0
  331. package/dist/cli/commands/security.d.ts +3 -0
  332. package/dist/cli/commands/security.js +180 -0
  333. package/dist/cli/commands/serve.d.ts +3 -0
  334. package/dist/cli/commands/serve.js +179 -0
  335. package/dist/cli/commands/session.d.ts +3 -0
  336. package/dist/cli/commands/session.js +172 -0
  337. package/dist/cli/commands/setup.d.ts +13 -0
  338. package/dist/cli/commands/setup.js +636 -0
  339. package/dist/cli/commands/skill.d.ts +15 -0
  340. package/dist/cli/commands/skill.js +191 -0
  341. package/dist/cli/commands/status.d.ts +3 -0
  342. package/dist/cli/commands/status.js +71 -0
  343. package/dist/cli/commands/summary.d.ts +3 -0
  344. package/dist/cli/commands/summary.js +160 -0
  345. package/dist/cli/commands/task.d.ts +3 -0
  346. package/dist/cli/commands/task.js +170 -0
  347. package/dist/cli/commands/ticket.d.ts +3 -0
  348. package/dist/cli/commands/ticket.js +421 -0
  349. package/dist/cli/commands/tools.d.ts +9 -0
  350. package/dist/cli/commands/tools.js +508 -0
  351. package/dist/cli/commands/tui.d.ts +3 -0
  352. package/dist/cli/commands/tui.js +158 -0
  353. package/dist/cli/commands/tunnel.d.ts +3 -0
  354. package/dist/cli/commands/tunnel.js +135 -0
  355. package/dist/cli/commands/webhooks.d.ts +3 -0
  356. package/dist/cli/commands/webhooks.js +191 -0
  357. package/dist/cli/index.d.ts +3 -0
  358. package/dist/cli/index.js +127 -0
  359. package/dist/cli/utils/api.d.ts +17 -0
  360. package/dist/cli/utils/api.js +63 -0
  361. package/dist/cli/utils/config.d.ts +31 -0
  362. package/dist/cli/utils/config.js +81 -0
  363. package/dist/cli/utils/output.d.ts +58 -0
  364. package/dist/cli/utils/output.js +148 -0
  365. package/dist/core/deployment.d.ts +30 -0
  366. package/dist/core/deployment.js +114 -0
  367. package/dist/core/sandbox-config.d.ts +63 -0
  368. package/dist/core/sandbox-config.js +148 -0
  369. package/dist/costs/budget.d.ts +28 -0
  370. package/dist/costs/budget.js +57 -0
  371. package/dist/costs/persistence.d.ts +77 -0
  372. package/dist/costs/persistence.js +210 -0
  373. package/dist/costs/pricing.d.ts +16 -0
  374. package/dist/costs/pricing.js +39 -0
  375. package/dist/costs/token-tracker.d.ts +34 -0
  376. package/dist/costs/token-tracker.js +141 -0
  377. package/dist/cron/heartbeat.d.ts +23 -0
  378. package/dist/cron/heartbeat.js +109 -0
  379. package/dist/cron/index.d.ts +22 -0
  380. package/dist/cron/index.js +37 -0
  381. package/dist/cron/issue-poller.d.ts +15 -0
  382. package/dist/cron/issue-poller.js +174 -0
  383. package/dist/cron/scheduler.d.ts +315 -0
  384. package/dist/cron/scheduler.js +1008 -0
  385. package/dist/cron/stale-checker.d.ts +16 -0
  386. package/dist/cron/stale-checker.js +61 -0
  387. package/dist/cron/templates.d.ts +107 -0
  388. package/dist/cron/templates.js +395 -0
  389. package/dist/diagnostics/exporters.d.ts +21 -0
  390. package/dist/diagnostics/exporters.js +138 -0
  391. package/dist/diagnostics/index.d.ts +10 -0
  392. package/dist/diagnostics/index.js +9 -0
  393. package/dist/diagnostics/middleware.d.ts +12 -0
  394. package/dist/diagnostics/middleware.js +58 -0
  395. package/dist/diagnostics/tracer.d.ts +133 -0
  396. package/dist/diagnostics/tracer.js +257 -0
  397. package/dist/discovery/index.d.ts +8 -0
  398. package/dist/discovery/index.js +7 -0
  399. package/dist/discovery/mdns.d.ts +40 -0
  400. package/dist/discovery/mdns.js +249 -0
  401. package/dist/gateway/index.d.ts +35 -0
  402. package/dist/gateway/index.js +36 -0
  403. package/dist/gateway/router.d.ts +110 -0
  404. package/dist/gateway/router.js +649 -0
  405. package/dist/gateway/types.d.ts +275 -0
  406. package/dist/gateway/types.js +2 -0
  407. package/dist/gateway/workflows.d.ts +37 -0
  408. package/dist/gateway/workflows.js +748 -0
  409. package/dist/hooks/agent-webhook.d.ts +277 -0
  410. package/dist/hooks/agent-webhook.js +197 -0
  411. package/dist/hooks/index.d.ts +13 -0
  412. package/dist/hooks/index.js +15 -0
  413. package/dist/hooks/prompt-submit.d.ts +45 -0
  414. package/dist/hooks/prompt-submit.js +111 -0
  415. package/dist/hooks/schemas.d.ts +563 -0
  416. package/dist/hooks/schemas.js +108 -0
  417. package/dist/hooks/session-end.d.ts +25 -0
  418. package/dist/hooks/session-end.js +153 -0
  419. package/dist/hooks/tool-use.d.ts +41 -0
  420. package/dist/hooks/tool-use.js +201 -0
  421. package/dist/hooks/types.d.ts +76 -0
  422. package/dist/hooks/types.js +7 -0
  423. package/dist/integrations/cloudflare-tunnel.d.ts +78 -0
  424. package/dist/integrations/cloudflare-tunnel.js +268 -0
  425. package/dist/integrations/github-client.d.ts +27 -0
  426. package/dist/integrations/github-client.js +79 -0
  427. package/dist/integrations/github-projects.d.ts +97 -0
  428. package/dist/integrations/github-projects.js +433 -0
  429. package/dist/integrations/github-ticket-sync.d.ts +82 -0
  430. package/dist/integrations/github-ticket-sync.js +352 -0
  431. package/dist/integrations/github.d.ts +11 -0
  432. package/dist/integrations/github.js +241 -0
  433. package/dist/integrations/jira-client.d.ts +30 -0
  434. package/dist/integrations/jira-client.js +67 -0
  435. package/dist/integrations/jira.d.ts +13 -0
  436. package/dist/integrations/jira.js +108 -0
  437. package/dist/integrations/linear-client.d.ts +23 -0
  438. package/dist/integrations/linear-client.js +52 -0
  439. package/dist/integrations/linear.d.ts +15 -0
  440. package/dist/integrations/linear.js +312 -0
  441. package/dist/integrations/tailscale.d.ts +68 -0
  442. package/dist/integrations/tailscale.js +173 -0
  443. package/dist/integrations/web-search.d.ts +112 -0
  444. package/dist/integrations/web-search.js +287 -0
  445. package/dist/intelligence/index.d.ts +8 -0
  446. package/dist/intelligence/index.js +8 -0
  447. package/dist/intelligence/ollama.d.ts +50 -0
  448. package/dist/intelligence/ollama.js +213 -0
  449. package/dist/intelligence/rules.d.ts +39 -0
  450. package/dist/intelligence/rules.js +308 -0
  451. package/dist/labels/index.d.ts +93 -0
  452. package/dist/labels/index.js +248 -0
  453. package/dist/mcp/browser-tools.d.ts +10 -0
  454. package/dist/mcp/browser-tools.js +16 -0
  455. package/dist/mcp/client.d.ts +54 -0
  456. package/dist/mcp/client.js +153 -0
  457. package/dist/mcp/index.d.ts +12 -0
  458. package/dist/mcp/index.js +13 -0
  459. package/dist/mcp/server.d.ts +40 -0
  460. package/dist/mcp/server.js +826 -0
  461. package/dist/mcp/tool-adapter.d.ts +49 -0
  462. package/dist/mcp/tool-adapter.js +193 -0
  463. package/dist/memory/experience-store.d.ts +121 -0
  464. package/dist/memory/experience-store.js +439 -0
  465. package/dist/memory/index.d.ts +8 -0
  466. package/dist/memory/index.js +25 -0
  467. package/dist/memory/memory-service.d.ts +312 -0
  468. package/dist/memory/memory-service.js +1172 -0
  469. package/dist/memory/memory-watcher.d.ts +116 -0
  470. package/dist/memory/memory-watcher.js +239 -0
  471. package/dist/middleware/logging.d.ts +34 -0
  472. package/dist/middleware/logging.js +184 -0
  473. package/dist/middleware/rate-limit.d.ts +29 -0
  474. package/dist/middleware/rate-limit.js +91 -0
  475. package/dist/notifications/in-app.d.ts +28 -0
  476. package/dist/notifications/in-app.js +53 -0
  477. package/dist/notifications/index.d.ts +3 -0
  478. package/dist/notifications/index.js +3 -0
  479. package/dist/notifications/push.d.ts +74 -0
  480. package/dist/notifications/push.js +175 -0
  481. package/dist/notifications/slack.d.ts +32 -0
  482. package/dist/notifications/slack.js +157 -0
  483. package/dist/plugins/clawhub.d.ts +70 -0
  484. package/dist/plugins/clawhub.js +260 -0
  485. package/dist/plugins/loader.d.ts +23 -0
  486. package/dist/plugins/loader.js +140 -0
  487. package/dist/plugins/marketplace.d.ts +77 -0
  488. package/dist/plugins/marketplace.js +275 -0
  489. package/dist/plugins/registry.d.ts +122 -0
  490. package/dist/plugins/registry.js +352 -0
  491. package/dist/plugins/sandbox.d.ts +77 -0
  492. package/dist/plugins/sandbox.js +287 -0
  493. package/dist/plugins/scaffolder.d.ts +28 -0
  494. package/dist/plugins/scaffolder.js +409 -0
  495. package/dist/plugins/sdk.d.ts +35 -0
  496. package/dist/plugins/sdk.js +8 -0
  497. package/dist/plugins/search/brave.d.ts +9 -0
  498. package/dist/plugins/search/brave.js +157 -0
  499. package/dist/plugins/search/duckduckgo.d.ts +9 -0
  500. package/dist/plugins/search/duckduckgo.js +171 -0
  501. package/dist/plugins/search/index.d.ts +13 -0
  502. package/dist/plugins/search/index.js +23 -0
  503. package/dist/plugins/search/searxng.d.ts +9 -0
  504. package/dist/plugins/search/searxng.js +170 -0
  505. package/dist/plugins/search/serper.d.ts +9 -0
  506. package/dist/plugins/search/serper.js +135 -0
  507. package/dist/plugins/search/tavily.d.ts +9 -0
  508. package/dist/plugins/search/tavily.js +146 -0
  509. package/dist/plugins/types.d.ts +174 -0
  510. package/dist/plugins/types.js +8 -0
  511. package/dist/projects/index.d.ts +133 -0
  512. package/dist/projects/index.js +897 -0
  513. package/dist/projects/types.d.ts +444 -0
  514. package/dist/projects/types.js +207 -0
  515. package/dist/providers/adapters/anthropic.d.ts +26 -0
  516. package/dist/providers/adapters/anthropic.js +306 -0
  517. package/dist/providers/adapters/base.d.ts +53 -0
  518. package/dist/providers/adapters/base.js +99 -0
  519. package/dist/providers/adapters/ollama.d.ts +30 -0
  520. package/dist/providers/adapters/ollama.js +292 -0
  521. package/dist/providers/ai-sdk.d.ts +178 -0
  522. package/dist/providers/ai-sdk.js +1552 -0
  523. package/dist/providers/core/index.d.ts +8 -0
  524. package/dist/providers/core/index.js +10 -0
  525. package/dist/providers/core/models.d.ts +31 -0
  526. package/dist/providers/core/models.js +949 -0
  527. package/dist/providers/core/types.d.ts +117 -0
  528. package/dist/providers/core/types.js +83 -0
  529. package/dist/providers/index.d.ts +7 -0
  530. package/dist/providers/index.js +7 -0
  531. package/dist/providers/registry.d.ts +93 -0
  532. package/dist/providers/registry.js +228 -0
  533. package/dist/providers/schema-utils.d.ts +23 -0
  534. package/dist/providers/schema-utils.js +545 -0
  535. package/dist/providers/types.d.ts +609 -0
  536. package/dist/providers/types.js +279 -0
  537. package/dist/queue/failure-handler.d.ts +93 -0
  538. package/dist/queue/failure-handler.js +379 -0
  539. package/dist/queue/index.d.ts +23 -0
  540. package/dist/queue/index.js +86 -0
  541. package/dist/queue/memory-queue.d.ts +30 -0
  542. package/dist/queue/memory-queue.js +429 -0
  543. package/dist/queue/notifications.d.ts +6 -0
  544. package/dist/queue/notifications.js +128 -0
  545. package/dist/queue/task-queue.d.ts +55 -0
  546. package/dist/queue/task-queue.js +518 -0
  547. package/dist/queue/webhook-queue.d.ts +47 -0
  548. package/dist/queue/webhook-queue.js +158 -0
  549. package/dist/routes/agents.d.ts +4 -0
  550. package/dist/routes/agents.js +45 -0
  551. package/dist/routes/auth.d.ts +19 -0
  552. package/dist/routes/auth.js +492 -0
  553. package/dist/routes/backup.d.ts +6 -0
  554. package/dist/routes/backup.js +71 -0
  555. package/dist/routes/chat.d.ts +10 -0
  556. package/dist/routes/chat.js +1678 -0
  557. package/dist/routes/clawhub.d.ts +8 -0
  558. package/dist/routes/clawhub.js +89 -0
  559. package/dist/routes/costs.d.ts +4 -0
  560. package/dist/routes/costs.js +78 -0
  561. package/dist/routes/cron.d.ts +11 -0
  562. package/dist/routes/cron.js +708 -0
  563. package/dist/routes/devices.d.ts +9 -0
  564. package/dist/routes/devices.js +490 -0
  565. package/dist/routes/discord.d.ts +15 -0
  566. package/dist/routes/discord.js +524 -0
  567. package/dist/routes/dlq.d.ts +4 -0
  568. package/dist/routes/dlq.js +64 -0
  569. package/dist/routes/gateway.d.ts +4 -0
  570. package/dist/routes/gateway.js +253 -0
  571. package/dist/routes/health.d.ts +29 -0
  572. package/dist/routes/health.js +296 -0
  573. package/dist/routes/hooks.d.ts +4 -0
  574. package/dist/routes/hooks.js +170 -0
  575. package/dist/routes/import.d.ts +9 -0
  576. package/dist/routes/import.js +540 -0
  577. package/dist/routes/index.d.ts +38 -0
  578. package/dist/routes/index.js +39 -0
  579. package/dist/routes/integrations.d.ts +10 -0
  580. package/dist/routes/integrations.js +200 -0
  581. package/dist/routes/labels.d.ts +8 -0
  582. package/dist/routes/labels.js +240 -0
  583. package/dist/routes/mcp.d.ts +14 -0
  584. package/dist/routes/mcp.js +125 -0
  585. package/dist/routes/memory.d.ts +10 -0
  586. package/dist/routes/memory.js +622 -0
  587. package/dist/routes/notifications.d.ts +9 -0
  588. package/dist/routes/notifications.js +154 -0
  589. package/dist/routes/oobe.d.ts +10 -0
  590. package/dist/routes/oobe.js +405 -0
  591. package/dist/routes/openapi.d.ts +9 -0
  592. package/dist/routes/openapi.js +537 -0
  593. package/dist/routes/plugins.d.ts +8 -0
  594. package/dist/routes/plugins.js +108 -0
  595. package/dist/routes/projects.d.ts +8 -0
  596. package/dist/routes/projects.js +592 -0
  597. package/dist/routes/push.d.ts +8 -0
  598. package/dist/routes/push.js +75 -0
  599. package/dist/routes/search.d.ts +4 -0
  600. package/dist/routes/search.js +189 -0
  601. package/dist/routes/security.d.ts +10 -0
  602. package/dist/routes/security.js +189 -0
  603. package/dist/routes/settings.d.ts +4 -0
  604. package/dist/routes/settings.js +119 -0
  605. package/dist/routes/setup.d.ts +11 -0
  606. package/dist/routes/setup.js +525 -0
  607. package/dist/routes/skills.d.ts +13 -0
  608. package/dist/routes/skills.js +152 -0
  609. package/dist/routes/slack.d.ts +12 -0
  610. package/dist/routes/slack.js +999 -0
  611. package/dist/routes/states.d.ts +8 -0
  612. package/dist/routes/states.js +123 -0
  613. package/dist/routes/stats.d.ts +6 -0
  614. package/dist/routes/stats.js +369 -0
  615. package/dist/routes/summaries.d.ts +4 -0
  616. package/dist/routes/summaries.js +344 -0
  617. package/dist/routes/sync.d.ts +13 -0
  618. package/dist/routes/sync.js +268 -0
  619. package/dist/routes/tasks.d.ts +4 -0
  620. package/dist/routes/tasks.js +473 -0
  621. package/dist/routes/telegram.d.ts +14 -0
  622. package/dist/routes/telegram.js +420 -0
  623. package/dist/routes/tickets.d.ts +4 -0
  624. package/dist/routes/tickets.js +1090 -0
  625. package/dist/routes/tokens.d.ts +4 -0
  626. package/dist/routes/tokens.js +83 -0
  627. package/dist/routes/tools.d.ts +14 -0
  628. package/dist/routes/tools.js +790 -0
  629. package/dist/routes/tunnels.d.ts +8 -0
  630. package/dist/routes/tunnels.js +145 -0
  631. package/dist/routes/users.d.ts +15 -0
  632. package/dist/routes/users.js +998 -0
  633. package/dist/routes/voice.d.ts +8 -0
  634. package/dist/routes/voice.js +127 -0
  635. package/dist/routes/webchat.d.ts +11 -0
  636. package/dist/routes/webchat.js +173 -0
  637. package/dist/routes/webhook-dedup.d.ts +11 -0
  638. package/dist/routes/webhook-dedup.js +49 -0
  639. package/dist/routes/webhooks.d.ts +4 -0
  640. package/dist/routes/webhooks.js +71 -0
  641. package/dist/routes/whatsapp.d.ts +14 -0
  642. package/dist/routes/whatsapp.js +391 -0
  643. package/dist/security/audit-scanner.d.ts +32 -0
  644. package/dist/security/audit-scanner.js +217 -0
  645. package/dist/security/fs-guard.d.ts +41 -0
  646. package/dist/security/fs-guard.js +206 -0
  647. package/dist/security/prompt-guard.d.ts +47 -0
  648. package/dist/security/prompt-guard.js +198 -0
  649. package/dist/security/ssrf-guard.d.ts +38 -0
  650. package/dist/security/ssrf-guard.js +266 -0
  651. package/dist/security/types.d.ts +92 -0
  652. package/dist/security/types.js +8 -0
  653. package/dist/server/route-loader.d.ts +15 -0
  654. package/dist/server/route-loader.js +135 -0
  655. package/dist/server.d.ts +5 -0
  656. package/dist/server.js +835 -0
  657. package/dist/settings/index.d.ts +841 -0
  658. package/dist/settings/index.js +451 -0
  659. package/dist/skills/compiler.d.ts +83 -0
  660. package/dist/skills/compiler.js +358 -0
  661. package/dist/skills/frontmatter.d.ts +33 -0
  662. package/dist/skills/frontmatter.js +175 -0
  663. package/dist/skills/index.d.ts +19 -0
  664. package/dist/skills/index.js +24 -0
  665. package/dist/skills/installer.d.ts +22 -0
  666. package/dist/skills/installer.js +220 -0
  667. package/dist/skills/loader.d.ts +72 -0
  668. package/dist/skills/loader.js +484 -0
  669. package/dist/skills/prompt-builder.d.ts +48 -0
  670. package/dist/skills/prompt-builder.js +135 -0
  671. package/dist/skills/registry.d.ts +115 -0
  672. package/dist/skills/registry.js +225 -0
  673. package/dist/skills/types.d.ts +202 -0
  674. package/dist/skills/types.js +24 -0
  675. package/dist/states/index.d.ts +64 -0
  676. package/dist/states/index.js +142 -0
  677. package/dist/storage/adapter.d.ts +146 -0
  678. package/dist/storage/adapter.js +2 -0
  679. package/dist/storage/index.d.ts +48 -0
  680. package/dist/storage/index.js +135 -0
  681. package/dist/storage/libsql.d.ts +99 -0
  682. package/dist/storage/libsql.js +1873 -0
  683. package/dist/storage/migrations.d.ts +65 -0
  684. package/dist/storage/migrations.js +289 -0
  685. package/dist/storage/schema.d.ts +10185 -0
  686. package/dist/storage/schema.js +1113 -0
  687. package/dist/summaries/extractor.d.ts +56 -0
  688. package/dist/summaries/extractor.js +377 -0
  689. package/dist/summaries/index.d.ts +13 -0
  690. package/dist/summaries/index.js +14 -0
  691. package/dist/summaries/storage.d.ts +51 -0
  692. package/dist/summaries/storage.js +101 -0
  693. package/dist/summaries/templates.d.ts +68 -0
  694. package/dist/summaries/templates.js +245 -0
  695. package/dist/sync/adapters/base.d.ts +42 -0
  696. package/dist/sync/adapters/base.js +142 -0
  697. package/dist/sync/adapters/github.d.ts +45 -0
  698. package/dist/sync/adapters/github.js +445 -0
  699. package/dist/sync/adapters/linear.d.ts +40 -0
  700. package/dist/sync/adapters/linear.js +434 -0
  701. package/dist/sync/config.d.ts +388 -0
  702. package/dist/sync/config.js +281 -0
  703. package/dist/sync/engine.d.ts +112 -0
  704. package/dist/sync/engine.js +623 -0
  705. package/dist/sync/index.d.ts +31 -0
  706. package/dist/sync/index.js +34 -0
  707. package/dist/sync/integration.d.ts +53 -0
  708. package/dist/sync/integration.js +231 -0
  709. package/dist/sync/types.d.ts +249 -0
  710. package/dist/sync/types.js +30 -0
  711. package/dist/tickets/index.d.ts +139 -0
  712. package/dist/tickets/index.js +1406 -0
  713. package/dist/tickets/types.d.ts +817 -0
  714. package/dist/tickets/types.js +310 -0
  715. package/dist/tools/adapters.d.ts +56 -0
  716. package/dist/tools/adapters.js +183 -0
  717. package/dist/tools/index.d.ts +66 -0
  718. package/dist/tools/index.js +105 -0
  719. package/dist/tools/types.d.ts +117 -0
  720. package/dist/tools/types.js +20 -0
  721. package/dist/types/agent.d.ts +101 -0
  722. package/dist/types/agent.js +2 -0
  723. package/dist/types/errors.d.ts +150 -0
  724. package/dist/types/errors.js +338 -0
  725. package/dist/types/index.d.ts +3 -0
  726. package/dist/types/index.js +3 -0
  727. package/dist/types/summary.d.ts +638 -0
  728. package/dist/types/summary.js +137 -0
  729. package/dist/types/task.d.ts +123 -0
  730. package/dist/types/task.js +46 -0
  731. package/dist/utils/ai-cache.d.ts +72 -0
  732. package/dist/utils/ai-cache.js +204 -0
  733. package/dist/utils/ai-inference.d.ts +57 -0
  734. package/dist/utils/ai-inference.js +190 -0
  735. package/dist/utils/ai-responder.d.ts +44 -0
  736. package/dist/utils/ai-responder.js +272 -0
  737. package/dist/utils/circuit-breaker.d.ts +139 -0
  738. package/dist/utils/circuit-breaker.js +281 -0
  739. package/dist/utils/config-loader.d.ts +12 -0
  740. package/dist/utils/config-loader.js +44 -0
  741. package/dist/utils/crypto.d.ts +10 -0
  742. package/dist/utils/crypto.js +59 -0
  743. package/dist/utils/env-validator.d.ts +44 -0
  744. package/dist/utils/env-validator.js +236 -0
  745. package/dist/utils/file-lock.d.ts +85 -0
  746. package/dist/utils/file-lock.js +204 -0
  747. package/dist/utils/logger.d.ts +153 -0
  748. package/dist/utils/logger.js +282 -0
  749. package/dist/utils/metrics.d.ts +183 -0
  750. package/dist/utils/metrics.js +345 -0
  751. package/dist/utils/security.d.ts +90 -0
  752. package/dist/utils/security.js +347 -0
  753. package/dist/voice/index.d.ts +79 -0
  754. package/dist/voice/index.js +144 -0
  755. package/dist/voice/stt/whisper.d.ts +13 -0
  756. package/dist/voice/stt/whisper.js +116 -0
  757. package/dist/voice/tts/elevenlabs.d.ts +18 -0
  758. package/dist/voice/tts/elevenlabs.js +178 -0
  759. package/dist/voice/tts/openai-tts.d.ts +19 -0
  760. package/dist/voice/tts/openai-tts.js +127 -0
  761. package/dist/voice/tts/system.d.ts +26 -0
  762. package/dist/voice/tts/system.js +146 -0
  763. package/dist/voice/wake-word.d.ts +44 -0
  764. package/dist/voice/wake-word.js +145 -0
  765. package/docker-compose.yml +222 -0
  766. package/package.json +154 -0
  767. package/profclaw.mjs +24 -0
  768. package/skills/1password/SKILL.md +155 -0
  769. package/skills/api-tester/SKILL.md +177 -0
  770. package/skills/apple-notes/SKILL.md +167 -0
  771. package/skills/apple-reminders/SKILL.md +178 -0
  772. package/skills/bear-notes/SKILL.md +166 -0
  773. package/skills/blogwatcher/SKILL.md +177 -0
  774. package/skills/camsnap/SKILL.md +130 -0
  775. package/skills/code-generation/SKILL.md +139 -0
  776. package/skills/code-review/SKILL.md +116 -0
  777. package/skills/coding-agent/SKILL.md +184 -0
  778. package/skills/cron-manager/SKILL.md +141 -0
  779. package/skills/debug-helper/SKILL.md +134 -0
  780. package/skills/docker-ops/SKILL.md +246 -0
  781. package/skills/file-manager/SKILL.md +160 -0
  782. package/skills/git-workflow/SKILL.md +171 -0
  783. package/skills/github-issues/SKILL.md +244 -0
  784. package/skills/gog/SKILL.md +191 -0
  785. package/skills/goplaces/SKILL.md +156 -0
  786. package/skills/healthcheck/SKILL.md +270 -0
  787. package/skills/himalaya/SKILL.md +165 -0
  788. package/skills/mcp-discovery/SKILL.md +109 -0
  789. package/skills/memory-manager/SKILL.md +151 -0
  790. package/skills/model-usage/SKILL.md +177 -0
  791. package/skills/nano-banana-pro/SKILL.md +214 -0
  792. package/skills/nano-pdf/SKILL.md +165 -0
  793. package/skills/notion/SKILL.md +147 -0
  794. package/skills/obsidian/SKILL.md +163 -0
  795. package/skills/openai-image-gen/SKILL.md +194 -0
  796. package/skills/openai-whisper/SKILL.md +98 -0
  797. package/skills/openai-whisper-api/SKILL.md +130 -0
  798. package/skills/openhue/SKILL.md +203 -0
  799. package/skills/oracle/SKILL.md +236 -0
  800. package/skills/phone-control/SKILL.md +201 -0
  801. package/skills/profclaw-assistant/SKILL.md +81 -0
  802. package/skills/profclaw-projects/SKILL.md +68 -0
  803. package/skills/profclaw-tickets/SKILL.md +91 -0
  804. package/skills/session-logs/SKILL.md +216 -0
  805. package/skills/sherpa-onnx-tts/SKILL.md +134 -0
  806. package/skills/skill-creator/SKILL.md +183 -0
  807. package/skills/songsee/SKILL.md +170 -0
  808. package/skills/spotify-player/SKILL.md +254 -0
  809. package/skills/summarize/SKILL.md +155 -0
  810. package/skills/system-admin/SKILL.md +179 -0
  811. package/skills/things-mac/SKILL.md +179 -0
  812. package/skills/tmux/SKILL.md +170 -0
  813. package/skills/trello/SKILL.md +154 -0
  814. package/skills/video-frames/SKILL.md +127 -0
  815. package/skills/weather/SKILL.md +186 -0
  816. package/skills/web-research/SKILL.md +128 -0
  817. package/skills/xurl/SKILL.md +198 -0
  818. package/ui/README.md +73 -0
  819. package/ui/dist/assets/ActivityView-CkPgKhwm.js +1 -0
  820. package/ui/dist/assets/AgentList-C3SVdeEz.js +1 -0
  821. package/ui/dist/assets/AnalyticsDashboard-DVU--vlP.js +1 -0
  822. package/ui/dist/assets/AreaChart-B5qMEGWj.js +1 -0
  823. package/ui/dist/assets/CartesianChart-B50bcUJi.js +36 -0
  824. package/ui/dist/assets/ChatView-BZFJs7w_.js +10 -0
  825. package/ui/dist/assets/CostsDashboard-ChfH8BlG.js +1 -0
  826. package/ui/dist/assets/EstimateSelect-CLpB4NQO.js +1 -0
  827. package/ui/dist/assets/FloatingChatbot-CBzBY9a0.js +2 -0
  828. package/ui/dist/assets/InviteCodeManagement-DsbdPa6W.js +2 -0
  829. package/ui/dist/assets/ProjectDetail-BEM3tFXg.js +2 -0
  830. package/ui/dist/assets/ProjectDetail-D1-0B2xV.css +1 -0
  831. package/ui/dist/assets/ProjectIcon-CN1FmFAk.js +1 -0
  832. package/ui/dist/assets/ProjectList-DSDaNhxQ.js +4 -0
  833. package/ui/dist/assets/Settings-dPVcqC_d.js +6 -0
  834. package/ui/dist/assets/StatusIndicator-DA3NAo_b.js +1 -0
  835. package/ui/dist/assets/SummaryDetail-Bjnf9lT8.js +27 -0
  836. package/ui/dist/assets/SummaryList-ENwKDBKW.js +1 -0
  837. package/ui/dist/assets/TaskDetail-DnwG6MzB.js +1 -0
  838. package/ui/dist/assets/TaskList-D9Ug_HiV.js +1 -0
  839. package/ui/dist/assets/TicketBoard-CviH1571.js +1 -0
  840. package/ui/dist/assets/TicketDetail-8Jk8O-33.js +1 -0
  841. package/ui/dist/assets/TicketList-B-iV4rRA.js +1 -0
  842. package/ui/dist/assets/UserManagement-CPZ8s7s2.js +2 -0
  843. package/ui/dist/assets/ViewSwitcher-BUyOOWDI.js +1 -0
  844. package/ui/dist/assets/alert-dialog-BOmnTkN-.js +7 -0
  845. package/ui/dist/assets/archive-D5my9zOG.js +1 -0
  846. package/ui/dist/assets/badge-B4ov81_m.js +1 -0
  847. package/ui/dist/assets/brain-C53ElFLD.js +1 -0
  848. package/ui/dist/assets/bug-D0TJoCYn.js +1 -0
  849. package/ui/dist/assets/calendar-BkWIhKa1.js +1 -0
  850. package/ui/dist/assets/chevron-up-BRTtndUZ.js +1 -0
  851. package/ui/dist/assets/circle-x-BN89YhbS.js +1 -0
  852. package/ui/dist/assets/constants-fc7TFI7u.js +1 -0
  853. package/ui/dist/assets/cpu-B41x1-vV.js +1 -0
  854. package/ui/dist/assets/database-D9Cnfmzj.js +1 -0
  855. package/ui/dist/assets/defineProperty-CoXUr7_6.js +2 -0
  856. package/ui/dist/assets/dialog-DrWB4EYD.js +1 -0
  857. package/ui/dist/assets/element-adapter-DL0DQilL.js +4 -0
  858. package/ui/dist/assets/ellipsis-NuUWekvu.js +1 -0
  859. package/ui/dist/assets/ellipsis-vertical-BueMfuCw.js +1 -0
  860. package/ui/dist/assets/file-code-HR9829Jc.js +1 -0
  861. package/ui/dist/assets/folder-open-C_7oYEqe.js +1 -0
  862. package/ui/dist/assets/funnel-B5gmNXGf.js +1 -0
  863. package/ui/dist/assets/git-branch-BRMiJmV3.js +1 -0
  864. package/ui/dist/assets/git-commit-horizontal-CXOUQeJI.js +1 -0
  865. package/ui/dist/assets/globe-CCspjvus.js +1 -0
  866. package/ui/dist/assets/hash-g3102kPC.js +1 -0
  867. package/ui/dist/assets/history-CNqcBBrV.js +1 -0
  868. package/ui/dist/assets/index-27mTPKuh.js +1 -0
  869. package/ui/dist/assets/index-BMx3fH-e.js +1 -0
  870. package/ui/dist/assets/index-C9jNQXzL.js +1 -0
  871. package/ui/dist/assets/index-CEZ6R2Uw.js +7 -0
  872. package/ui/dist/assets/index-DURTouJI.js +1 -0
  873. package/ui/dist/assets/index-WclMPci1.css +1 -0
  874. package/ui/dist/assets/index-kb4AJXUB.js +67 -0
  875. package/ui/dist/assets/layers-CLXiHN6o.js +1 -0
  876. package/ui/dist/assets/layout-dashboard-B07MFhBs.js +1 -0
  877. package/ui/dist/assets/lightbulb-B2dgG5ks.js +1 -0
  878. package/ui/dist/assets/link-2-BxNmr9hL.js +1 -0
  879. package/ui/dist/assets/markdown-renderer-CjU6hBcW.js +36 -0
  880. package/ui/dist/assets/message-square-Bf2-CVbt.js +1 -0
  881. package/ui/dist/assets/pencil-D096Ey62.js +1 -0
  882. package/ui/dist/assets/play-DfdcSI3x.js +1 -0
  883. package/ui/dist/assets/popover-BV0QJDQq.js +1 -0
  884. package/ui/dist/assets/progress-DjPEDJfI.js +1 -0
  885. package/ui/dist/assets/rocket-CPsTc-5G.js +1 -0
  886. package/ui/dist/assets/select-LsO16slr.js +1 -0
  887. package/ui/dist/assets/send-BDYBZDUZ.js +1 -0
  888. package/ui/dist/assets/server-B3k6noce.js +1 -0
  889. package/ui/dist/assets/settings-2-Cu4xTjhG.js +1 -0
  890. package/ui/dist/assets/sheet-BScLnPKX.js +1 -0
  891. package/ui/dist/assets/shield-check-CQqkwufI.js +1 -0
  892. package/ui/dist/assets/shield-off-ZFruH9KO.js +1 -0
  893. package/ui/dist/assets/skeleton-CtkIA_MU.js +1 -0
  894. package/ui/dist/assets/smartphone-DnoksVkc.js +1 -0
  895. package/ui/dist/assets/square-uD9ZHMfW.js +1 -0
  896. package/ui/dist/assets/switch-MQPnwGJK.js +1 -0
  897. package/ui/dist/assets/table-B8cqlywA.js +1 -0
  898. package/ui/dist/assets/tag-wEJQRWlV.js +1 -0
  899. package/ui/dist/assets/textarea-D5LJCOGl.js +1 -0
  900. package/ui/dist/assets/timer-mbGHegmr.js +1 -0
  901. package/ui/dist/assets/tooltip-Df1CunSp.js +1 -0
  902. package/ui/dist/assets/trash-2-B4oAXsX-.js +1 -0
  903. package/ui/dist/assets/trending-up-BGWxvlmZ.js +1 -0
  904. package/ui/dist/assets/wand-sparkles-CZy4xvL3.js +1 -0
  905. package/ui/dist/assets/wrench-ByZkjO6m.js +1 -0
  906. package/ui/dist/audio-worklets/vad-processor.js +132 -0
  907. package/ui/dist/brand/profclaw-appicon-192.png +0 -0
  908. package/ui/dist/brand/profclaw-appicon-512.png +0 -0
  909. package/ui/dist/brand/profclaw-appicon-shadow.svg +51 -0
  910. package/ui/dist/brand/profclaw-appicon.svg +50 -0
  911. package/ui/dist/brand/profclaw-favicon-coral-bg-128.png +0 -0
  912. package/ui/dist/brand/profclaw-favicon-coral-bg-64.png +0 -0
  913. package/ui/dist/brand/profclaw-favicon-coral-bg.svg +52 -0
  914. package/ui/dist/brand/profclaw-favicon-coral-body-128.png +0 -0
  915. package/ui/dist/brand/profclaw-favicon-coral-body.svg +41 -0
  916. package/ui/dist/brand/profclaw-favicon-shadow-128.png +0 -0
  917. package/ui/dist/brand/profclaw-favicon-shadow-64.png +0 -0
  918. package/ui/dist/brand/profclaw-favicon-shadow.svg +51 -0
  919. package/ui/dist/brand/profclaw-mark-coral-256.png +0 -0
  920. package/ui/dist/brand/profclaw-mark-coral-64.png +0 -0
  921. package/ui/dist/brand/profclaw-mark-coral.svg +31 -0
  922. package/ui/dist/brand/profclaw-mono-white.svg +18 -0
  923. package/ui/dist/brand/profclaw-text-dark.svg +18 -0
  924. package/ui/dist/brand/profclaw-text-light.svg +18 -0
  925. package/ui/dist/brand/profclaw-wordmark-dark.svg +48 -0
  926. package/ui/dist/brand/profclaw-wordmark-light.svg +48 -0
  927. package/ui/dist/brand/safari-pinned-tab.svg +15 -0
  928. package/ui/dist/favicon/android-chrome-192x192.png +0 -0
  929. package/ui/dist/favicon/android-chrome-384x384.png +0 -0
  930. package/ui/dist/favicon/android-chrome-512x512.png +0 -0
  931. package/ui/dist/favicon/apple-touch-icon.png +0 -0
  932. package/ui/dist/favicon/browserconfig.xml +9 -0
  933. package/ui/dist/favicon/favicon-16x16.png +0 -0
  934. package/ui/dist/favicon/favicon-32x32.png +0 -0
  935. package/ui/dist/favicon/favicon.ico +0 -0
  936. package/ui/dist/favicon/mstile-150x150.png +0 -0
  937. package/ui/dist/favicon/safari-pinned-tab.svg +46 -0
  938. package/ui/dist/favicon/site.webmanifest +22 -0
  939. package/ui/dist/index.html +32 -0
  940. package/ui/dist/manifest.json +49 -0
  941. package/ui/dist/sw.js +124 -0
  942. package/ui/dist/vite.svg +1 -0
@@ -0,0 +1,6 @@
1
+ import{c as Z,j as e,r as f,W as ut,i as w,Y as ht,Z as Fs,k as b,H as tt,t as u,n as H,u as R,o as L,m as le,S as pt,R as Q,_ as Ce,K as ke,$ as $e,J as ae,C as U,l as Ae,a0 as pe,a1 as ge,L as P,p as de,I as O,O as ue,v as re,w as be,P as Ye,Q as Pe,g as ss,X as ve,a2 as Ms,N as Ls,U as we,a3 as Ue,a4 as gt,B as Se,a5 as ft,a6 as hs,a7 as ps,a8 as gs,a9 as fs,aa as js,ab as Ns,ac as bs,ad as jt,ae as Nt,af as bt,E as vt,q as wt,s as yt,ag as Ct,ah as kt,M as St,ai as vs,aj as Ft,D as Et,x as Pt,y as Tt,z as cs}from"./index-kb4AJXUB.js";import{S as Ne}from"./switch-MQPnwGJK.js";import{D as ts,b as as,c as ns,d as rs,e as is,f as at}from"./dialog-DrWB4EYD.js";import{A as qs,a as Qe,v as At,b as A,P as ws,c as nt,T as Oe,S as rt,M as Dt,V as It,d as Mt,e as ds,C as zs}from"./constants-fc7TFI7u.js";import{I as Fe,C as Lt,S as Es,T as qt}from"./timer-mbGHegmr.js";import{T as it}from"./tag-wEJQRWlV.js";import{P as zt}from"./pencil-D096Ey62.js";import{T as fe}from"./trash-2-B4oAXsX-.js";import{B as ie}from"./badge-B4ov81_m.js";import{A as Ot,a as Bt,b as Rt,c as $t,d as Ut,e as Kt,f as _t,g as Qt}from"./alert-dialog-BOmnTkN-.js";import{S as xe,C as Wt}from"./smartphone-DnoksVkc.js";import{T as Vt,a as Gt,b as Os,c as Me,d as Jt,e as Le}from"./table-B8cqlywA.js";import{D as Ze}from"./database-D9Cnfmzj.js";import{B as ys}from"./brain-C53ElFLD.js";import{C as Ps}from"./cpu-B41x1-vV.js";import{F as Ts}from"./file-code-HR9829Jc.js";import{G as Ee}from"./globe-CCspjvus.js";import{W as Xe}from"./wrench-ByZkjO6m.js";import{B as Je,a as Ht}from"./bug-D0TJoCYn.js";import{G as Cs}from"./git-commit-horizontal-CXOUQeJI.js";import{C as ne}from"./circle-x-BN89YhbS.js";import{F as Yt}from"./funnel-B5gmNXGf.js";import{G as Zt}from"./git-branch-BRMiJmV3.js";import{S as me}from"./shield-check-CQqkwufI.js";import{T as Xt}from"./textarea-D5LJCOGl.js";import{L as De}from"./link-2-BxNmr9hL.js";import{S as As}from"./send-BDYBZDUZ.js";import{M as ea}from"./message-square-Bf2-CVbt.js";import{S as sa,a as ta,b as aa,c as na,d as Bs}from"./select-LsO16slr.js";import{P as He}from"./play-DfdcSI3x.js";import{S as Rs}from"./square-uD9ZHMfW.js";import{T as $s,a as Us,b as Ks}from"./tooltip-Df1CunSp.js";import{S as ra}from"./server-B3k6noce.js";import{S as ia}from"./shield-off-ZFruH9KO.js";import{S as la}from"./settings-2-Cu4xTjhG.js";import"./chevron-up-BRTtndUZ.js";const oa=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]],ca=Z("circle-arrow-up",oa);const da=[["path",{d:"M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z",key:"p7xjir"}]],ls=Z("cloud",da);const ma=[["path",{d:"M22 7.7c0-.6-.4-1.2-.8-1.5l-6.3-3.9a1.72 1.72 0 0 0-1.7 0l-10.3 6c-.5.2-.9.8-.9 1.4v6.6c0 .5.4 1.2.8 1.5l6.3 3.9a1.72 1.72 0 0 0 1.7 0l10.3-6c.5-.3.9-1 .9-1.5Z",key:"1t2lqe"}],["path",{d:"M10 21.9V14L2.1 9.1",key:"o7czzq"}],["path",{d:"m10 14 11.9-6.9",key:"zm5e20"}],["path",{d:"M14 19.8v-8.1",key:"159ecu"}],["path",{d:"M18 17.5V9.4",key:"11uown"}]],lt=Z("container",ma);const xa=[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]],ot=Z("file-braces",xa);const ua=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],ha=Z("gauge",ua);const pa=[["path",{d:"M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z",key:"1pdavp"}],["path",{d:"M20.054 15.987H3.946",key:"14rxg9"}]],ga=Z("laptop",pa);const fa=[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 9.9-1",key:"1mm8w8"}]],ct=Z("lock-open",fa);const ja=[["path",{d:"M15.033 9.44a.647.647 0 0 1 0 1.12l-4.065 2.352a.645.645 0 0 1-.968-.56V7.648a.645.645 0 0 1 .967-.56z",key:"vbtd3f"}],["path",{d:"M12 17v4",key:"1riwvh"}],["path",{d:"M8 21h8",key:"1ev6f3"}],["rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",key:"x3v2xh"}]],Na=Z("monitor-play",ja);const ba=[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 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.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]],dt=Z("package",ba);const va=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M3 9h18",key:"1pudct"}],["path",{d:"M9 21V9",key:"1oto5p"}]],ks=Z("panels-top-left",va);const wa=[["rect",{width:"5",height:"5",x:"3",y:"3",rx:"1",key:"1tu5fj"}],["rect",{width:"5",height:"5",x:"16",y:"3",rx:"1",key:"1v8r4q"}],["rect",{width:"5",height:"5",x:"3",y:"16",rx:"1",key:"1x03jg"}],["path",{d:"M21 16h-3a2 2 0 0 0-2 2v3",key:"177gqh"}],["path",{d:"M21 21v.01",key:"ents32"}],["path",{d:"M12 7v3a2 2 0 0 1-2 2H7",key:"8crl2c"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M12 3h.01",key:"n36tog"}],["path",{d:"M12 16v.01",key:"133mhm"}],["path",{d:"M16 12h1",key:"1slzba"}],["path",{d:"M21 12v.01",key:"1lwtk9"}],["path",{d:"M12 21v-1",key:"1880an"}]],ms=Z("qr-code",wa);const ya=[["circle",{cx:"6",cy:"19",r:"3",key:"1kj8tv"}],["path",{d:"M9 19h8.5a3.5 3.5 0 0 0 0-7h-11a3.5 3.5 0 0 1 0-7H15",key:"1d8sl"}],["circle",{cx:"18",cy:"5",r:"3",key:"gq8acd"}]],Ca=Z("route",ya);const ka=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M9.1 9a3 3 0 0 1 5.82 1c0 2-3 3-3 3",key:"mhlwft"}],["path",{d:"M12 17h.01",key:"p32p05"}]],Sa=Z("shield-question-mark",ka);const Fa=[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]],es=Z("star",Fa);const Ea=[["circle",{cx:"9",cy:"12",r:"3",key:"u3jwor"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],mt=Z("toggle-left",Ea);const Pa=[["circle",{cx:"15",cy:"12",r:"3",key:"1afu0r"}],["rect",{width:"20",height:"14",x:"2",y:"5",rx:"7",key:"g7kal2"}]],Ss=Z("toggle-right",Pa);const Ta=[["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],Aa=Z("trash",Ta);const Da=[["path",{d:"m18.84 12.25 1.72-1.71h-.02a5.004 5.004 0 0 0-.12-7.07 5.006 5.006 0 0 0-6.95 0l-1.72 1.71",key:"yqzxt4"}],["path",{d:"m5.17 11.75-1.71 1.71a5.004 5.004 0 0 0 .12 7.07 5.006 5.006 0 0 0 6.95 0l1.71-1.71",key:"4qinb0"}],["line",{x1:"8",x2:"8",y1:"2",y2:"5",key:"1041cp"}],["line",{x1:"2",x2:"5",y1:"8",y2:"8",key:"14m1p5"}],["line",{x1:"16",x2:"16",y1:"19",y2:"22",key:"rzdirn"}],["line",{x1:"19",x2:"22",y1:"16",y2:"16",key:"ox905f"}]],Ke=Z("unlink",Da);const Ia=[["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"}]],Ma=Z("upload",Ia);const La=[["path",{d:"M12 20h.01",key:"zekei9"}],["path",{d:"M2 8.82a15 15 0 0 1 20 0",key:"dnpr2z"}],["path",{d:"M5 12.859a10 10 0 0 1 14 0",key:"1x1e6c"}],["path",{d:"M8.5 16.429a5 5 0 0 1 7 0",key:"1bycff"}]],qa=Z("wifi",La);function B({title:s,description:r,children:t,icon:c}){return e.jsxs("div",{className:"glass rounded-2xl p-6 lg:p-8",children:[e.jsxs("div",{className:"mb-4 flex items-start gap-3",children:[c?e.jsx("div",{className:"mt-0.5 text-muted-foreground",children:c}):null,e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-bold",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]})]}),t]})}f.createContext(null);function qe({label:s,description:r,checked:t,onChange:c,disabled:x}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]}),e.jsx(Ne,{checked:t,onCheckedChange:c,disabled:x})]})}function _s({theme:s,setTheme:r,handleRestartTour:t}){return e.jsxs(e.Fragment,{children:[e.jsx(B,{title:"Theme",description:"Choose your preferred color scheme",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm",children:"Color Mode"}),e.jsxs("div",{className:"flex bg-muted rounded-lg p-1",children:[e.jsx("button",{onClick:()=>r("light"),className:w("p-2 rounded-md transition-all",s==="light"?"bg-white shadow-sm text-black":"text-muted-foreground hover:text-foreground"),children:e.jsx(ut,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>r("dark"),className:w("p-2 rounded-md transition-all",s==="dark"?"bg-primary text-white":"text-muted-foreground hover:text-foreground"),children:e.jsx(ht,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>r("midnight"),className:w("p-2 rounded-md transition-all",s==="midnight"?"bg-slate-700 text-white":"text-muted-foreground hover:text-foreground"),children:e.jsx(Fs,{className:"h-4 w-4"})})]})]})}),e.jsx(B,{title:"Onboarding",description:"Replay the product tour",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Product Tour"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Walk through all features"})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:t,className:"rounded-xl",children:[e.jsx(tt,{className:"h-4 w-4 mr-2"}),"Restart Tour"]})]})})]})}function za({settings:s,handleToggle:r,isPending:t}){const c=async()=>{if(s?.notifications?.browserNotifications??!1){r("notifications","browserNotifications",!0);return}if(!("Notification"in window)){u.error("Browser notifications are not supported in this browser");return}await Notification.requestPermission()==="granted"?r("notifications","browserNotifications",!1):u.error("Browser notification permission denied. Enable it in your browser settings.")};return e.jsx(B,{title:"Notification Preferences",description:"Control which notifications you receive",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(qe,{label:"Task Complete",description:"Notify when a task finishes successfully",checked:s?.notifications?.taskComplete??!0,onChange:()=>r("notifications","taskComplete",s?.notifications?.taskComplete??!0),disabled:t}),e.jsx(qe,{label:"Task Failed",description:"Notify when a task fails or errors",checked:s?.notifications?.taskFailed??!0,onChange:()=>r("notifications","taskFailed",s?.notifications?.taskFailed??!0),disabled:t}),e.jsx(qe,{label:"Budget Alerts",description:"Notify at 50%, 80%, and 100% budget usage",checked:s?.notifications?.budgetAlerts??!0,onChange:()=>r("notifications","budgetAlerts",s?.notifications?.budgetAlerts??!0),disabled:t}),e.jsx(qe,{label:"Daily Digest",description:"Receive a daily summary of activity",checked:s?.notifications?.dailyDigest??!1,onChange:()=>r("notifications","dailyDigest",s?.notifications?.dailyDigest??!1),disabled:t}),e.jsx(qe,{label:"Browser Notifications",description:"Show native browser notifications for task events",checked:s?.notifications?.browserNotifications??!1,onChange:c,disabled:t})]})})}function Oa(){const s=H(),[r,t]=f.useState({}),[c,x]=f.useState({}),[j,h]=f.useState({}),[N,y]=f.useState({}),[d,v]=f.useState(null),[m,g]=f.useState(null),[a,n]=f.useState(null),[k,i]=f.useState(""),[C,p]=f.useState(qs[0].value),[l,o]=f.useState({}),{data:q,refetch:T,isRefetching:_}=R({queryKey:["chat","providers"],queryFn:()=>le.chat.providers(),refetchInterval:3e4,staleTime:25e3}),X=L({mutationFn:({type:S,apiKey:J,baseUrl:Y,defaultModel:ee,apiVersion:D})=>le.chat.configure(S,{apiKey:J,baseUrl:Y,defaultModel:ee,apiVersion:D,enabled:!0}),onSuccess:(S,J)=>{u.success(`${J.type} configured`),T(),s.invalidateQueries({queryKey:["chat","providers"]})},onError:S=>u.error(S instanceof Error?S.message:"Failed")}),F=L({mutationFn:async S=>{const J=await fetch(`http://localhost:3000/api/chat/providers/${S}/health`,{method:"POST"});if(!J.ok)throw new Error("Health check failed");return J.json()},onSuccess:S=>{S.healthy?u.success(`Connection successful (${S.latencyMs}ms)`):u.error(S.message||"Connection failed"),T()},onError:S=>u.error(S instanceof Error?S.message:"Test failed")}),K=q?.providers||[],V=K.filter(S=>S.healthy).length,oe=async S=>{if(Qe.find(Y=>Y.type===S)){g(S);try{const Y=S==="azure"?k:j[S];let ee=c[S];S==="azure"&&ee&&(ee=ee.replace(/\/$/,""),ee.includes("cognitive.microsoft.com")&&!ee.endsWith("/openai")&&(ee=`${ee}/openai`)),await X.mutateAsync({type:S,apiKey:r[S],baseUrl:ee,defaultModel:Y,apiVersion:S==="azure"?C:void 0})}finally{g(null)}}},G=async S=>{n(S);try{await F.mutateAsync(S)}finally{n(null)}},he=S=>{const J=K.find(D=>D.type===S.type),Y=J?.healthy,ee=d===S.type;return e.jsxs("div",{className:w("rounded-xl border transition-all",Y?"border-green-500/30 bg-green-500/5":"border-border bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 cursor-pointer",onClick:()=>v(ee?null:S.type),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("h-10 w-10 rounded-xl flex items-center justify-center",Y?"bg-green-500/10":"bg-muted/50"),children:e.jsx(S.Logo,{className:w("h-5 w-5",Y&&"text-green-600")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium",children:S.name}),Y&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-green-500 bg-green-500/10 px-2 py-0.5 rounded-full",children:[e.jsx(U,{className:"h-3 w-3"}),"Connected"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:S.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("a",{href:S.setupUrl,target:"_blank",rel:"noopener noreferrer",onClick:D=>D.stopPropagation(),className:"text-xs text-primary hover:underline flex items-center gap-1",children:["Get Key",e.jsx(ae,{className:"h-3 w-3"})]}),e.jsx(Ae,{className:w("h-4 w-4 text-muted-foreground transition-transform",ee&&"rotate-90")})]})]}),ee&&e.jsxs("div",{className:"px-4 pb-4 space-y-4 border-t border-border/50 pt-4",children:[S.type!=="ollama"&&S.type!=="copilot"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"API Key"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:N[S.type]?"text":"password",placeholder:S.placeholder,value:r[S.type]||"",onChange:D=>t(M=>({...M,[S.type]:D.target.value})),onClick:D=>D.stopPropagation(),className:"w-full field pr-10"}),e.jsx("button",{type:"button",onClick:D=>{D.stopPropagation(),y(M=>({...M,[S.type]:!M[S.type]}))},className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:N[S.type]?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}),S.type==="azure"&&e.jsxs("div",{className:"space-y-4 p-3 rounded-xl bg-blue-500/5 border border-blue-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-blue-600 dark:text-blue-400",children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),"Azure OpenAI Configuration"]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Endpoint URL"}),e.jsx("input",{type:"text",placeholder:"https://your-resource.openai.azure.com",value:c.azure||"",onChange:D=>{const M=D.target.value;x($=>({...$,azure:M}));const E=At(M);o($=>({...$,endpoint:E.message}))},onClick:D=>D.stopPropagation(),className:w("w-full field font-mono text-xs",l.endpoint&&"ring-1 ring-destructive")}),l.endpoint&&e.jsx("p",{className:"text-[10px] text-destructive mt-1",children:l.endpoint}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:["Supported formats: ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"https://your-resource.openai.azure.com"})," or ",e.jsx("code",{className:"bg-muted px-1 rounded",children:"https://region.api.cognitive.microsoft.com"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Model (Deployment Name)"}),e.jsx("input",{type:"text",placeholder:"e.g., gpt-4o, gpt-4-turbo",value:k,onChange:D=>i(D.target.value),onClick:D=>D.stopPropagation(),className:"w-full field"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"The deployment name from Model deployments section"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"API Version"}),e.jsx("select",{value:C,onChange:D=>{D.stopPropagation(),p(D.target.value)},onClick:D=>D.stopPropagation(),className:"w-full field appearance-none cursor-pointer",children:qs.map(D=>e.jsx("option",{value:D.value,children:D.label},D.value))}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:["Use ",e.jsx("strong",{children:"2024-10-21"})," for most models. Use ",e.jsx("strong",{children:"2024-12-01-preview"})," for o1/o1-mini reasoning models."]})]}),e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-lg bg-muted/50 text-[10px] text-muted-foreground",children:[e.jsx(Lt,{className:"h-3.5 w-3.5 shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium mb-1",children:"Where to find these values:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-0.5",children:[e.jsxs("li",{children:["Go to"," ",e.jsx("a",{href:"https://portal.azure.com/#blade/HubsExtension/BrowseResource/resourceType/Microsoft.CognitiveServices%2Faccounts",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Azure Portal → Azure OpenAI"})]}),e.jsxs("li",{children:["Select your ",e.jsx("strong",{children:"Azure OpenAI"})," resource (not Cognitive Services)"]}),e.jsxs("li",{children:["Go to ",e.jsx("strong",{children:"Keys and Endpoint"})," under Resource Management"]}),e.jsxs("li",{children:["Copy the endpoint (format: ",e.jsx("code",{children:"https://your-resource.openai.azure.com"}),")"]}),e.jsxs("li",{children:["Deployment Name is in ",e.jsx("strong",{children:"Model deployments"})," section"]})]}),e.jsxs("p",{className:"mt-2 text-amber-600 dark:text-amber-400",children:["⚠️ Don't use regional endpoints like ",e.jsx("code",{children:"eastus.api.cognitive.microsoft.com"})]})]})]})]}),S.requiresBaseUrl&&S.type!=="azure"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Base URL"}),e.jsx("input",{type:"text",placeholder:S.placeholder,value:c[S.type]||"",onChange:D=>x(M=>({...M,[S.type]:D.target.value})),onClick:D=>D.stopPropagation(),className:"w-full field"})]}),S.type!=="azure"&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Default Model"}),S.models.length>0?e.jsxs(e.Fragment,{children:[e.jsx("select",{value:j[S.type]||S.models[0],onChange:D=>{D.stopPropagation(),h(M=>({...M,[S.type]:D.target.value}))},onClick:D=>D.stopPropagation(),className:"w-full field appearance-none cursor-pointer",children:S.models.map(D=>e.jsx("option",{value:D,children:D},D))}),e.jsxs("p",{className:"text-[10px] text-muted-foreground mt-1",children:[S.models.length," model",S.models.length!==1?"s":""," available"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",placeholder:"Enter model name",value:j[S.type]||"",onChange:D=>{h(M=>({...M,[S.type]:D.target.value}))},onClick:D=>D.stopPropagation(),className:"w-full field"}),e.jsx("p",{className:"text-[10px] text-muted-foreground mt-1",children:"Enter your model identifier"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:D=>{D.stopPropagation(),G(S.type)},disabled:a===S.type||!J&&!r[S.type],className:"rounded-lg",children:[a===S.type?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Test Connection"]}),e.jsxs(b,{size:"sm",onClick:D=>{D.stopPropagation(),oe(S.type)},disabled:m===S.type,className:"rounded-lg",children:[m===S.type?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Es,{className:"h-4 w-4 mr-2"}),"Save"]})]}),J?.message&&e.jsxs("p",{className:w("text-xs",Y?"text-green-500":"text-muted-foreground"),children:[J.message,J.latencyMs&&` (${J.latencyMs}ms)`]})]})]},S.type)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"glass rounded-2xl p-6 mb-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",V>0?"bg-green-500/10":"bg-amber-500/10"),children:e.jsx(pt,{className:w("h-6 w-6",V>0?"text-green-500":"text-amber-500")})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold",children:"AI Provider Status"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:V>0?e.jsxs("span",{className:"text-green-500",children:[V," provider",V!==1?"s":""," connected"]}):e.jsx("span",{className:"text-amber-500",children:"No providers configured"})})]})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>T(),disabled:_,className:"rounded-xl",children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",_&&"animate-spin")}),"Refresh"]})]}),e.jsxs("div",{className:"mt-4 flex items-start gap-3 p-3 rounded-xl bg-blue-500/5 border border-blue-500/20",children:[e.jsx(Ce,{className:"h-4 w-4 text-blue-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-blue-400 mb-1",children:"Secure Storage"}),e.jsx("p",{children:"API keys are encrypted and stored securely. Keys are transmitted over HTTPS and never logged."})]})]})]}),e.jsx(B,{title:"Cloud Providers",description:"Connect to hosted AI services",children:e.jsx("div",{className:"space-y-3",children:Qe.filter(S=>S.category==="cloud").map(he)})}),e.jsx(B,{title:"Enterprise",description:"Enterprise-grade AI",children:e.jsx("div",{className:"space-y-3",children:Qe.filter(S=>S.category==="enterprise").map(he)})}),e.jsxs(B,{title:"Local & Self-Hosted",description:"Run models locally",children:[e.jsx("div",{className:"space-y-3",children:Qe.filter(S=>S.category==="local").map(he)}),e.jsxs("div",{className:"mt-4 flex items-start gap-3 p-3 rounded-xl bg-muted/50 border border-border",children:[e.jsx(ke,{className:"h-4 w-4 text-muted-foreground mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium mb-1",children:"Quick Ollama Setup"}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded",children:"curl -fsSL https://ollama.com/install.sh | sh && ollama serve"})]})]}),e.jsxs("div",{className:"mt-3 flex items-start gap-3 p-3 rounded-xl bg-indigo-500/5 border border-indigo-500/20",children:[e.jsx($e,{className:"h-4 w-4 text-indigo-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium mb-1 text-indigo-600 dark:text-indigo-400",children:"GitHub Copilot Proxy Setup (Experimental)"}),e.jsx("p",{className:"mb-2",children:"Use your existing Copilot subscription for free inference:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-1 text-[11px]",children:[e.jsxs("li",{children:["Install:"," ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"npx copilot-api"})]}),e.jsx("li",{children:"Authenticate with GitHub when prompted"}),e.jsxs("li",{children:["Enter"," ",e.jsx("code",{className:"bg-muted px-1 py-0.5 rounded",children:"http://localhost:4141"})," ","above"]})]}),e.jsxs("a",{href:"https://github.com/ericc-ch/copilot-api",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 mt-2 text-indigo-500 hover:underline",children:["View full setup guide",e.jsx(ae,{className:"h-3 w-3"})]})]})]})]})]})}const We=["#EF4444","#F97316","#EAB308","#22C55E","#06B6D4","#3B82F6","#8B5CF6","#EC4899"];function Ba({open:s,onOpenChange:r,projectId:t,label:c,onSuccess:x}){const[j,h]=f.useState(""),[N,y]=f.useState(""),[d,v]=f.useState(We[0]),[m,g]=f.useState(""),a=H(),n=!!c;f.useEffect(()=>{c?(h(c.name),y(c.description||""),v(c.color),We.includes(c.color)?g(""):g(c.color)):(h(""),y(""),v(We[0]),g(""))},[c,s]);const k=L({mutationFn:p=>n&&c?le.labels.update(c.id,p):le.labels.create(t,p),onSuccess:p=>{a.invalidateQueries({queryKey:["labels",t]}),u.success(`Label ${n?"updated":"created"} successfully`),r(!1),x?.(p.label)},onError:p=>{u.error(`Failed to ${n?"update":"create"} label: ${p.message}`)}}),i=p=>{if(p.preventDefault(),!j.trim()){u.error("Label name is required");return}const l=m&&m.startsWith("#")?m:d;k.mutate({name:j.trim(),description:N.trim()||void 0,color:l})},C=p=>{const l=p.target.value;g(l),l.startsWith("#")&&(l.length===4||l.length===7)&&v(l)};return e.jsx(ts,{open:s,onOpenChange:r,children:e.jsx(as,{className:"glass-heavy rounded-[20px] border-white/10 sm:max-w-[450px]",children:e.jsxs("form",{onSubmit:i,children:[e.jsxs(ns,{children:[e.jsxs(rs,{className:"flex items-center gap-2",children:[e.jsx(it,{className:"h-5 w-5 text-primary"}),n?"Edit Label":"Create Label"]}),e.jsx(is,{children:n?"Update the label details and color.":"Create a new label to categorize your tickets."})]}),e.jsxs("div",{className:"grid gap-5 py-6",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(de,{htmlFor:"name",children:"Name *"}),e.jsx(O,{id:"name",placeholder:"Label name...",value:j,onChange:p=>h(p.target.value),className:"bg-white/5 border-white/10 rounded-xl focus:ring-2 focus:ring-primary/20",autoFocus:!0,required:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(de,{htmlFor:"description",children:"Description (optional)"}),e.jsx(O,{id:"description",placeholder:"What is this label for?",value:N,onChange:p=>y(p.target.value),className:"bg-white/5 border-white/10 rounded-xl focus:ring-2 focus:ring-primary/20"})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx(de,{children:"Color"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:We.map(p=>e.jsx("button",{type:"button",onClick:()=>{v(p),g("")},className:w("h-8 w-8 rounded-full transition-all hover:scale-110 flex items-center justify-center",d===p&&"ring-2 ring-primary ring-offset-2 ring-offset-background"),style:{backgroundColor:p},children:d===p&&e.jsx(ue,{className:"h-4 w-4 text-white drop-shadow-sm"})},p))}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(O,{placeholder:"#HEX color",value:m,onChange:C,className:"bg-white/5 border-white/10 rounded-xl pl-10"}),e.jsx("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 rounded-full border border-white/20",style:{backgroundColor:m||d}})]})})]})]}),e.jsxs(at,{children:[e.jsx(b,{type:"button",variant:"ghost",onClick:()=>r(!1),className:"rounded-xl",children:"Cancel"}),e.jsxs(b,{type:"submit",disabled:k.isPending||!j.trim(),className:"gap-2 rounded-xl",children:[k.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ue,{className:"h-4 w-4"}),n?"Save Changes":"Create Label"]})]})]})})})}function Ra(){const[s,r]=f.useState(!1),[t,c]=f.useState(null),[x,j]=f.useState(""),h=H(),{data:N,isLoading:y}=R({queryKey:["projects","default"],queryFn:()=>le.projects.getDefault()}),d=N?.id,{data:v,isLoading:m}=R({queryKey:["labels",d],queryFn:()=>le.labels.list(d),enabled:!!d}),g=L({mutationFn:p=>le.labels.delete(p),onSuccess:()=>{h.invalidateQueries({queryKey:["labels",d]}),u.success("Label deleted")},onError:p=>{u.error(`Failed to delete label: ${p.message}`)}}),n=(v?.labels||[]).filter(p=>p.name.toLowerCase().includes(x.toLowerCase())||p.description?.toLowerCase().includes(x.toLowerCase())),k=p=>{c(p),r(!0)},i=()=>{c(null),r(!0)},C=p=>{window.confirm("Are you sure you want to delete this label?")&&g.mutate(p)};return y||d&&m?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-4",children:[e.jsx(P,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground animate-pulse",children:"Loading labels..."})]}):d?e.jsxs(e.Fragment,{children:[e.jsx(B,{title:"Labels",description:"Categorize and organize your tickets with custom labels",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 justify-between items-start sm:items-center",children:[e.jsxs("div",{className:"relative w-full sm:w-64",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Search labels...",value:x,onChange:p=>j(p.target.value),className:"w-full pl-9 pr-4 py-2 bg-white/5 border border-white/10 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-primary/50"})]}),e.jsxs(b,{onClick:i,className:"gap-2 rounded-xl w-full sm:w-auto",children:[e.jsx(Ye,{className:"h-4 w-4"}),"Create Label"]})]}),e.jsx("div",{className:"grid gap-3",children:n.length===0?e.jsxs("div",{className:"text-center py-12 bg-muted/20 border border-dashed border-border rounded-2xl",children:[e.jsx(it,{className:"h-10 w-10 text-muted-foreground/30 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:x?"No labels match your search":"No labels created yet"})]}):n.map(p=>e.jsxs("div",{className:"group flex items-center justify-between p-4 bg-white/5 border border-white/10 rounded-2xl hover:bg-white/10 transition-all",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-4 w-4 rounded-full shadow-sm",style:{backgroundColor:p.color}}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold",children:p.name}),p.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-1",children:p.description})]})]}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>k(p),className:"h-8 w-8 rounded-lg text-muted-foreground hover:text-foreground",children:e.jsx(zt,{className:"h-4 w-4"})}),e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>C(p.id),disabled:g.isPending,className:"h-8 w-8 rounded-lg text-red-400 hover:text-red-300 hover:bg-red-500/10",children:g.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(fe,{className:"h-4 w-4"})})]})]},p.id))})]})}),e.jsx(Ba,{open:s,onOpenChange:r,projectId:d,label:t})]}):e.jsx(B,{title:"Labels",description:"Manage your project labels",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center bg-red-500/5 rounded-2xl border border-red-500/10",children:[e.jsx(re,{className:"h-8 w-8 text-red-400 mb-2"}),e.jsx("p",{className:"text-sm font-medium",children:"Project not found"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 px-4",children:"Could not find the default project. Please make sure you have a project created."})]})})}function Qs(s){switch(s?.toLowerCase()){case"macos":case"darwin":return ga;case"windows":return Ms;case"linux":return Ms;default:return xe}}function $a(s){const r=new Date(s),c=new Date().getTime()-r.getTime();return c<6e4?"just now":c<36e5?`${Math.floor(c/6e4)}m ago`:c<864e5?`${Math.floor(c/36e5)}h ago`:c<6048e5?`${Math.floor(c/864e5)}d ago`:r.toLocaleDateString()}function Ua(){const s=H(),[r,t]=f.useState(null),[c,x]=f.useState(null),{data:j,isLoading:h}=R({queryKey:["device-identity"],queryFn:async()=>(await(await fetch(`${A}/api/devices/identity`,{credentials:"include"})).json()).identity}),{data:N,isLoading:y}=R({queryKey:["paired-devices"],queryFn:async()=>(await(await fetch(`${A}/api/devices/paired`,{credentials:"include"})).json()).devices}),{data:d,isLoading:v}=R({queryKey:["pending-pairing-requests"],queryFn:async()=>(await(await fetch(`${A}/api/devices/pairing/pending`,{credentials:"include"})).json()).requests,refetchInterval:1e4}),m=L({mutationFn:async()=>(await fetch(`${A}/api/devices/pairing/request`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({})})).json(),onSuccess:i=>{s.invalidateQueries({queryKey:["pending-pairing-requests"]}),u.success("Pairing code generated",{description:`Code: ${i.formattedCode}`})},onError:i=>{u.error("Failed to generate pairing code",{description:i instanceof Error?i.message:"Unknown error"})}}),g=L({mutationFn:async i=>(await fetch(`${A}/api/devices/pairing/approve`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:i})})).json(),onSuccess:()=>{s.invalidateQueries({queryKey:["paired-devices"]}),s.invalidateQueries({queryKey:["pending-pairing-requests"]}),u.success("Device approved")},onError:i=>{u.error("Failed to approve device",{description:i instanceof Error?i.message:"Unknown error"})}}),a=L({mutationFn:async i=>(await fetch(`${A}/api/devices/pairing/reject`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:i})})).json(),onSuccess:()=>{s.invalidateQueries({queryKey:["pending-pairing-requests"]}),u.success("Device rejected")},onError:i=>{u.error("Failed to reject device",{description:i instanceof Error?i.message:"Unknown error"})}}),n=L({mutationFn:async i=>(await fetch(`${A}/api/devices/paired/${i}`,{method:"DELETE",credentials:"include"})).json(),onSuccess:()=>{s.invalidateQueries({queryKey:["paired-devices"]}),t(null),u.success("Device access revoked")},onError:i=>{u.error("Failed to revoke device",{description:i instanceof Error?i.message:"Unknown error"})}}),k=i=>{navigator.clipboard.writeText(i),x(i),setTimeout(()=>x(null),2e3),u.success("Code copied to clipboard")};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-2xl glass shadow-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-5 w-5 text-primary"}),e.jsx("h3",{className:"font-medium",children:"This Device"})]}),j&&e.jsxs(ie,{variant:"outline",className:"font-mono text-xs",children:[j.deviceId.slice(0,12),"..."]})]}),h?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Loading device identity..."})]}):j?e.jsx("div",{className:"space-y-2 text-sm",children:e.jsxs("div",{className:"flex items-center gap-2",children:[(()=>{const i=Qs(j.platform);return e.jsx(i,{className:"h-4 w-4 text-muted-foreground"})})(),e.jsx("span",{children:j.displayName||"Unnamed Device"}),j.platform&&e.jsx(ie,{variant:"secondary",className:"text-xs",children:j.platform})]})}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No device identity found. One will be created automatically."})]}),e.jsxs("div",{className:"rounded-2xl glass shadow-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ms,{className:"h-5 w-5 text-amber-500"}),e.jsx("h3",{className:"font-medium",children:"Pending Requests"}),d&&d.length>0&&e.jsx(ie,{variant:"secondary",children:d.length})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>m.mutate(),disabled:m.isPending,children:[m.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(ms,{className:"h-4 w-4 mr-2"}),"Generate Code"]})]}),v?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Loading requests..."})]}):d&&d.length>0?e.jsx("div",{className:"space-y-3",children:d.map(i=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-amber-500/10",children:e.jsx(xe,{className:"h-4 w-4 text-amber-500"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono font-medium",children:i.formattedCode}),e.jsx(b,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>k(i.code),children:c===i.code?e.jsx(ue,{className:"h-3 w-3 text-green-500"}):e.jsx(Pe,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ss,{className:"h-3 w-3"}),e.jsxs("span",{children:["Expires"," ",new Date(i.expiresAt).toLocaleTimeString()]}),i.meta?.displayName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:i.meta.displayName})]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",className:"text-green-600 hover:text-green-700 hover:bg-green-50",onClick:()=>g.mutate(i.code),disabled:g.isPending,children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),"Approve"]}),e.jsxs(b,{variant:"outline",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50",onClick:()=>a.mutate(i.code),disabled:a.isPending,children:[e.jsx(ve,{className:"h-4 w-4 mr-1"}),"Reject"]})]})]},i.id))}):e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(ms,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No pending pairing requests"}),e.jsx("p",{className:"text-xs mt-1",children:'Click "Generate Code" to create a new pairing code'})]})]}),e.jsxs("div",{className:"rounded-2xl glass shadow-lg p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5 text-green-500"}),e.jsx("h3",{className:"font-medium",children:"Paired Devices"}),N&&N.length>0&&e.jsx(ie,{variant:"secondary",children:N.length})]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>s.invalidateQueries({queryKey:["paired-devices"]}),children:e.jsx(Q,{className:"h-4 w-4"})})]}),y?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{children:"Loading devices..."})]}):N&&N.length>0?e.jsx("div",{className:"space-y-3",children:N.map(i=>{const C=Qs(i.platform),p=i.deviceId===j?.deviceId;return e.jsxs("div",{className:w("flex items-center justify-between p-3 rounded-lg border",p?"bg-primary/5 border-primary/20":"bg-muted/50 border-border"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("p-2 rounded-lg",p?"bg-primary/10":"bg-green-500/10"),children:e.jsx(C,{className:w("h-4 w-4",p?"text-primary":"text-green-500")})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium",children:i.displayName}),p&&e.jsx(ie,{variant:"default",className:"text-xs",children:"This Device"})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i.platform&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:i.platform}),e.jsx("span",{children:"•"})]}),e.jsxs("span",{children:["Paired ",$a(i.approvedAt||i.createdAt)]}),i.approvedBy&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsxs("span",{children:["by ",i.approvedBy]})]})]})]})]}),!p&&e.jsx(b,{variant:"ghost",size:"sm",className:"text-red-600 hover:text-red-700 hover:bg-red-50",onClick:()=>t(i),children:e.jsx(fe,{className:"h-4 w-4"})})]},i.id)})}):e.jsxs("div",{className:"text-center py-6 text-muted-foreground",children:[e.jsx(xe,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No paired devices"}),e.jsx("p",{className:"text-xs mt-1",children:"Pair a device to enable multi-device access"})]})]}),e.jsx("div",{className:"rounded-lg border border-amber-500/20 bg-amber-500/5 p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(re,{className:"h-5 w-5 text-amber-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-amber-600 dark:text-amber-400",children:"Security Notice"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Only approve pairing requests from devices you trust. Paired devices have full access to your profClaw account. Revoke access immediately for any device you no longer use."})]})]})}),e.jsx(Ot,{open:!!r,onOpenChange:()=>t(null),children:e.jsxs(Bt,{children:[e.jsxs(Rt,{children:[e.jsx($t,{children:"Revoke Device Access?"}),e.jsxs(Ut,{children:["This will immediately revoke access for"," ",e.jsx("strong",{children:r?.displayName}),". The device will need to be paired again to regain access."]})]}),e.jsxs(Kt,{children:[e.jsx(_t,{children:"Cancel"}),e.jsxs(Qt,{className:"bg-red-600 hover:bg-red-700",onClick:()=>r&&n.mutate(r.id),children:[n.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Revoke Access"]})]})]})})]})}const je="http://localhost:3000";function Ka(){const[s,r]=f.useState(null),[t,c]=f.useState([]),[x,j]=f.useState(null),[h,N]=f.useState(!0),[y,d]=f.useState(!1),[v,m]=f.useState(""),[g,a]=f.useState([]),[n,k]=f.useState(!1),[i,C]=f.useState(null),[p,l]=f.useState([]),[o,q]=f.useState(!1),[T,_]=f.useState(!1),[X,F]=f.useState(!1),[K,V]=f.useState(null),oe=async()=>{N(!0),V(null);try{const[E,$,se]=await Promise.all([fetch(`${je}/api/memory/stats`,{credentials:"include"}),fetch(`${je}/api/memory/files`,{credentials:"include"}),fetch(`${je}/api/memory/watcher/status`,{credentials:"include"})]);if(E.ok){const ce=await E.json();r(ce.stats)}if($.ok){const ce=await $.json();c(ce.files)}if(se.ok){const ce=await se.json();j(ce)}}catch(E){V("Failed to load memory data"),console.error(E)}finally{N(!1)}};f.useEffect(()=>{oe()},[]);const G=async()=>{d(!0);try{(await fetch(`${je}/api/memory/sync`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({})})).ok&&await oe()}catch(E){V("Sync failed"),console.error(E)}finally{d(!1)}},he=async()=>{d(!0);try{(await fetch(`${je}/api/memory/warm`,{method:"POST",credentials:"include"})).ok&&await oe()}catch(E){V("Warm session failed"),console.error(E)}finally{d(!1)}},S=async()=>{if(v.trim()){k(!0),a([]);try{const E=await fetch(`${je}/api/memory/search`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:v,maxResults:10})});if(E.ok){const $=await E.json();a($.chunks||[])}}catch(E){V("Search failed"),console.error(E)}finally{k(!1)}}},J=async E=>{C(E),q(!0);try{const $=await fetch(`${je}/api/memory/files/${encodeURIComponent(E.path)}/chunks`,{credentials:"include"});if($.ok){const se=await $.json();l(se.chunks||[])}}catch($){console.error($)}finally{q(!1)}},Y=async E=>{try{(await fetch(`${je}/api/memory/files/${encodeURIComponent(E)}`,{method:"DELETE",credentials:"include"})).ok&&(C(null),l([]),await oe())}catch($){V("Failed to delete file"),console.error($)}},ee=async()=>{F(!0);try{(await fetch(`${je}/api/memory/all`,{method:"DELETE",credentials:"include"})).ok&&(_(!1),await oe())}catch(E){V("Failed to clear memories"),console.error(E)}finally{F(!1)}},D=E=>{if(E===0)return"0 B";const $=1024,se=["B","KB","MB","GB"],ce=Math.floor(Math.log(E)/Math.log($));return parseFloat((E/Math.pow($,ce)).toFixed(1))+" "+se[ce]},M=E=>E?new Date(E).toLocaleString():"Never";return e.jsxs(e.Fragment,{children:[e.jsxs(B,{title:"Memory Statistics",description:"Semantic memory system status",children:[h?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(Q,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(Ls,{className:"h-3.5 w-3.5"}),"Files"]}),e.jsx("div",{className:"text-2xl font-semibold",children:s.totalFiles})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(Ze,{className:"h-3.5 w-3.5"}),"Chunks"]}),e.jsx("div",{className:"text-2xl font-semibold",children:s.totalChunks})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(ys,{className:"h-3.5 w-3.5"}),"Est. Tokens"]}),e.jsx("div",{className:"text-2xl font-semibold",children:s.totalTokensEstimate.toLocaleString()})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground text-xs mb-1",children:[e.jsx(Ps,{className:"h-3.5 w-3.5"}),"Embeddings"]}),e.jsx("div",{className:"text-2xl font-semibold",children:s.cachedEmbeddings})]})]}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(ss,{className:"h-4 w-4"}),"Last Sync: ",M(s.lastSyncAt)]}),e.jsx(ie,{variant:"outline",children:s.embeddingModel})]}),x&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:w("h-2 w-2 rounded-full",x.enabled?x.state?.watching?"bg-green-500":"bg-yellow-500":"bg-gray-400")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:x.enabled?x.state?.watching?`Watching ${x.state.watchedFiles?.length||0} files`:"Watcher enabled but not watching":"Watcher disabled"}),x.state?.dirty&&e.jsx(ie,{variant:"secondary",className:"text-xs",children:"Dirty"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:G,disabled:y,className:"rounded-xl",children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",y&&"animate-spin")}),y?"Syncing...":"Sync Files"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:he,disabled:y,className:"rounded-xl",children:[e.jsx(ys,{className:"h-4 w-4 mr-2"}),"Warm Session"]}),e.jsxs(b,{variant:"destructive",size:"sm",onClick:()=>_(!0),className:"rounded-xl ml-auto",children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Clear All"]})]})]}):e.jsx("div",{className:"text-center py-4 text-muted-foreground",children:"No memory data available"}),K&&e.jsxs("div",{className:"mt-4 p-3 bg-destructive/10 text-destructive text-sm rounded-lg flex items-center gap-2",children:[e.jsx(we,{className:"h-4 w-4"}),K]})]}),e.jsx(B,{title:"Search Memory",description:"Semantically search indexed memories",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{placeholder:"Search memories...",value:v,onChange:E=>m(E.target.value),onKeyDown:E=>E.key==="Enter"&&S(),className:"flex-1"}),e.jsx(b,{onClick:S,disabled:n||!v.trim(),className:"rounded-xl",children:e.jsx(be,{className:w("h-4 w-4",n&&"animate-pulse")})})]}),g.length>0&&e.jsx("div",{className:"space-y-2 max-h-64 overflow-y-auto",children:g.map(E=>e.jsxs("div",{className:"p-3 bg-muted/50 rounded-lg space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:E.path}),e.jsxs(ie,{variant:"outline",className:"text-xs",children:[(E.score*100).toFixed(0),"%"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Lines ",E.startLine,"-",E.endLine]}),e.jsx("p",{className:"text-xs line-clamp-2",children:E.text})]},E.id))})]})}),e.jsx(B,{title:"Memory Files",description:"Indexed memory files and their chunks",children:t.length>0?e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Vt,{children:[e.jsx(Gt,{children:e.jsxs(Os,{children:[e.jsx(Me,{children:"Path"}),e.jsx(Me,{children:"Source"}),e.jsx(Me,{children:"Size"}),e.jsx(Me,{children:"Modified"}),e.jsx(Me,{className:"w-10"})]})}),e.jsx(Jt,{children:t.map(E=>e.jsxs(Os,{className:w("cursor-pointer",i?.path===E.path&&"bg-muted"),onClick:()=>J(E),children:[e.jsx(Le,{className:"font-mono text-xs truncate max-w-[200px]",children:E.path}),e.jsx(Le,{children:e.jsx(ie,{variant:"secondary",className:"text-xs",children:E.source})}),e.jsx(Le,{className:"text-xs",children:D(E.size)}),e.jsx(Le,{className:"text-xs text-muted-foreground",children:new Date(E.mtime).toLocaleDateString()}),e.jsx(Le,{children:e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground"})})]},E.path))})]}),i&&e.jsxs("div",{className:"bg-muted/30 rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:i.path}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[p.length," chunks"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{variant:"destructive",size:"sm",onClick:()=>Y(i.path),className:"rounded-xl",children:[e.jsx(fe,{className:"h-4 w-4 mr-1"}),"Delete"]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>{C(null),l([])},children:e.jsx(ve,{className:"h-4 w-4"})})]})]}),o?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(Q,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-2 max-h-48 overflow-y-auto",children:p.map((E,$)=>e.jsxs("div",{className:"p-2 bg-muted/30 rounded text-xs space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsxs("span",{children:["Chunk ",$+1," (lines ",E.startLine,"-",E.endLine,")"]}),e.jsxs("span",{children:[E.text.length," chars"]})]}),e.jsx("p",{className:"line-clamp-2",children:E.text})]},E.id))})]})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Ls,{className:"h-12 w-12 mx-auto mb-3 opacity-50"}),e.jsx("p",{children:"No memory files indexed"}),e.jsx("p",{className:"text-xs mt-1",children:"Create a MEMORY.md file or memory/ directory to get started"})]})}),e.jsx(ts,{open:T,onOpenChange:_,children:e.jsxs(as,{children:[e.jsxs(ns,{children:[e.jsxs(rs,{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5 text-destructive"}),"Clear All Memories"]}),e.jsx(is,{children:"This will permanently delete all indexed memory files, chunks, and embedding caches. This action cannot be undone."})]}),e.jsxs(at,{children:[e.jsx(b,{variant:"outline",onClick:()=>_(!1),disabled:X,children:"Cancel"}),e.jsx(b,{variant:"destructive",onClick:ee,disabled:X,children:X?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"h-4 w-4 mr-2 animate-spin"}),"Clearing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4 mr-2"}),"Clear All"]})})]})]})})]})}const xs={bundled:"bg-blue-500/10 text-blue-400 border-blue-500/20",managed:"bg-purple-500/10 text-purple-400 border-purple-500/20",workspace:"bg-green-500/10 text-green-400 border-green-500/20",plugin:"bg-orange-500/10 text-orange-400 border-orange-500/20"},Ve={"git-commit":Cs,commit:Cs,debugging:Je,"systematic-debugging":Je,"mobile-app-debugging":Je,"code-review":be,"code-review-excellence":be,testing:Oe,"javascript-testing-patterns":Oe,"e2e-testing-patterns":Oe,"webapp-testing":Oe,"ui-patterns":ks,"building-native-ui":ks,"react-native":xe,"react-native-basics":xe,"react-native-architecture":xe,"react-native-best-practices":xe,"react-native-expo":xe,"vercel-react-native-skills":xe,"mobile-developer":xe,"find-skills":be,"skill-creator":Xe,"profclaw-agents":Se,"subagent-driven-development":Se,"graphql-operations":Ee,"api-conventions":Ts,"keybindings-help":gt,"task-router":Ca,"claude-router":Fs};function Ws(s){if(Ve[s])return Ve[s];const r=s.split(":")[0];if(Ve[r])return Ve[r];const t=s.toLowerCase();return t.includes("test")?Oe:t.includes("debug")||t.includes("bug")?Je:t.includes("commit")||t.includes("git")?Cs:t.includes("mobile")||t.includes("native")?xe:t.includes("ui")||t.includes("layout")?ks:t.includes("api")||t.includes("graphql")?Ee:t.includes("agent")||t.includes("bot")?Se:t.includes("security")||t.includes("auth")?Ce:t.includes("code")?Wt:t.includes("doc")||t.includes("learn")?Ht:ws}function _a(){const s=H(),[r,t]=f.useState(null),{data:c,isLoading:x,error:j}=R({queryKey:["skills"],queryFn:async()=>{const a=await fetch(`${A}/api/skills`,{credentials:"include"});if(!a.ok)throw new Error("Failed to fetch skills");return a.json()}}),{data:h,isLoading:N}=R({queryKey:["skills",r],queryFn:async()=>{const a=await fetch(`${A}/api/skills/${r}`,{credentials:"include"});if(!a.ok)throw new Error("Failed to fetch skill detail");return a.json()},enabled:!!r}),y=L({mutationFn:async()=>{const a=await fetch(`${A}/api/skills/reload`,{method:"POST",credentials:"include"});if(!a.ok)throw new Error("Failed to reload skills");return a.json()},onSuccess:a=>{s.invalidateQueries({queryKey:["skills"]}),u.success(`Skills reloaded: ${a.stats.totalSkills} loaded`)},onError:()=>u.error("Failed to reload skills")}),d=L({mutationFn:async a=>{const n=await fetch(`${A}/api/skills/${a}/toggle`,{method:"POST",credentials:"include"});if(!n.ok)throw new Error("Failed to toggle skill");return n.json()},onSuccess:a=>{s.invalidateQueries({queryKey:["skills"]}),u.success(`${a.name} ${a.enabled?"enabled":"disabled"}`)}}),v=L({mutationFn:async a=>{const n=await fetch(`${A}/api/skills/${a}/install`,{method:"POST",credentials:"include"});if(!n.ok)throw new Error("Failed to install dependencies");return n.json()},onSuccess:a=>{s.invalidateQueries({queryKey:["skills"]}),a.allSucceeded?u.success(`Dependencies installed for ${a.skill}`):u.error("Some dependencies failed to install")},onError:()=>u.error("Failed to install dependencies")});if(x)return e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(j)return e.jsxs("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-destructive",children:[e.jsx(we,{className:"mb-2 h-5 w-5"}),e.jsx("p",{className:"text-sm",children:"Failed to load skills. Make sure the backend is running."})]});const m=c?.stats,g=c?.skills??[];return e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:"Skills"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Modular capabilities that extend AI knowledge."})]}),e.jsxs(b,{variant:"ghost",size:"sm",className:"h-8 gap-1.5 text-xs text-muted-foreground hover:text-foreground",onClick:()=>y.mutate(),disabled:y.isPending,children:[e.jsx(Q,{className:w("h-3.5 w-3.5",y.isPending&&"animate-spin")}),"Reload"]})]}),m&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(Ge,{label:"Total",value:m.total,icon:ws}),e.jsx(Ge,{label:"Eligible",value:m.eligible,icon:ue}),e.jsx(Ge,{label:"Enabled",value:m.enabled,icon:Ss}),e.jsx(Ge,{label:"~Tokens",value:m.estimatedTokens.toLocaleString(),icon:Ps})]}),m&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[Object.entries(m.bySource).filter(([,a])=>a>0).map(([a,n])=>e.jsxs("span",{className:w("inline-flex items-center rounded-full px-2.5 py-0.5 text-[11px] font-medium",xs[a]),children:[a," ",n]},a)),m.mcpServers>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-cyan-500/10 text-cyan-400 px-2.5 py-0.5 text-[11px] font-medium",children:[e.jsx(nt,{className:"h-3 w-3"}),"MCP ",m.mcpServers]})]}),e.jsx("div",{className:"rounded-xl bg-card/50 backdrop-blur-sm shadow-sm ring-1 ring-white/[0.05] overflow-hidden divide-y divide-white/[0.04]",children:g.length===0?e.jsxs("div",{className:"p-12 text-center text-muted-foreground",children:[e.jsx("div",{className:"mx-auto mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-muted/50",children:e.jsx(ws,{className:"h-6 w-6 opacity-40"})}),e.jsx("p",{className:"text-sm font-medium",children:"No skills loaded"}),e.jsxs("p",{className:"mt-1 text-xs opacity-70",children:["Add SKILL.md files to the ",e.jsx("code",{className:"rounded bg-muted/50 px-1.5 py-0.5",children:"skills/"})," directory"]})]}):g.map(a=>{const n=Ws(a.name);return e.jsxs("div",{className:w("group flex items-center gap-3.5 px-4 py-3.5 transition-all duration-150 cursor-pointer","hover:bg-white/[0.03]",!a.eligible&&"opacity-50"),onClick:()=>t(a.name),children:[e.jsx("div",{className:w("flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-colors","bg-gradient-to-br from-white/[0.08] to-white/[0.02]","shadow-sm ring-1 ring-white/[0.06]"),children:e.jsx(n,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium text-[13px] tracking-tight",children:a.name}),e.jsx("span",{className:w("rounded-full px-2 py-px text-[10px] font-medium",xs[a.source]),children:a.source}),!a.eligible&&e.jsx("span",{className:"rounded-full bg-amber-500/10 text-amber-400 px-2 py-px text-[10px] font-medium",children:"ineligible"})]}),e.jsx("p",{className:"truncate text-xs text-muted-foreground/70 mt-0.5",children:a.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a.userInvocable&&e.jsxs("span",{className:"rounded-md bg-white/[0.04] px-2 py-0.5 text-[10px] font-mono text-muted-foreground",children:["/",a.name]}),e.jsx("button",{className:"p-1.5 rounded-lg transition-colors hover:bg-white/[0.06]",onClick:k=>{k.stopPropagation(),d.mutate(a.name)},title:a.enabled?"Disable":"Enable",children:a.enabled?e.jsx(Ss,{className:"h-4 w-4 text-green-400"}):e.jsx(mt,{className:"h-4 w-4 text-muted-foreground/50"})}),e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground/30 group-hover:text-muted-foreground/60 transition-all duration-150 group-hover:translate-x-0.5"})]})]},a.name)})}),e.jsx(ts,{open:!!r,onOpenChange:a=>!a&&t(null),children:e.jsxs(as,{className:"max-w-lg max-h-[80vh] overflow-y-auto",children:[e.jsxs(ns,{children:[e.jsxs(rs,{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-gradient-to-br from-white/[0.08] to-white/[0.02] shadow-sm ring-1 ring-white/[0.06]",children:(()=>{const a=Ws(h?.name||r||"");return e.jsx(a,{className:"h-4 w-4 text-muted-foreground"})})()}),h?.name||r]}),e.jsx(is,{children:h?.description})]}),N?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):h?e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("span",{className:w("rounded-full px-2.5 py-0.5 text-[11px] font-medium",xs[h.source]),children:h.source}),e.jsx("span",{className:w("rounded-full px-2.5 py-0.5 text-[11px] font-medium",h.eligible?"bg-green-500/10 text-green-400":"bg-red-500/10 text-red-400"),children:h.eligible?"Eligible":"Ineligible"}),e.jsx("span",{className:w("rounded-full px-2.5 py-0.5 text-[11px] font-medium",h.enabled?"bg-blue-500/10 text-blue-400":"bg-white/[0.06] text-muted-foreground"),children:h.enabled?"Enabled":"Disabled"})]}),h.eligibilityErrors.length>0&&e.jsxs("div",{className:"rounded-xl bg-amber-500/[0.06] p-4 ring-1 ring-amber-500/10",children:[e.jsx("p",{className:"text-xs font-semibold text-amber-400 mb-2",children:"Missing Requirements"}),e.jsx("ul",{className:"space-y-1.5 text-xs text-amber-300/80",children:h.eligibilityErrors.map((a,n)=>e.jsxs("li",{className:"flex items-center gap-1.5",children:[e.jsx(ve,{className:"h-3 w-3 shrink-0"}),a]},n))}),h.metadata?.install&&h.metadata.install.length>0&&e.jsxs(b,{size:"sm",variant:"outline",className:"mt-3 h-7 text-xs",onClick:()=>v.mutate(h.name),disabled:v.isPending,children:[e.jsx(Ue,{className:"mr-1.5 h-3 w-3"}),v.isPending?"Installing...":"Install Dependencies"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Invocation"}),e.jsxs("div",{className:"flex gap-4 text-xs",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[h.invocation.userInvocable?e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded-full bg-green-500/15",children:e.jsx(ue,{className:"h-2.5 w-2.5 text-green-400"})}):e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded-full bg-white/[0.06]",children:e.jsx(ve,{className:"h-2.5 w-2.5 text-muted-foreground/50"})}),"User (/",h.command?.name||h.name,")"]}),e.jsxs("span",{className:"flex items-center gap-1.5",children:[h.invocation.modelInvocable?e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded-full bg-green-500/15",children:e.jsx(ue,{className:"h-2.5 w-2.5 text-green-400"})}):e.jsx("div",{className:"flex h-4 w-4 items-center justify-center rounded-full bg-white/[0.06]",children:e.jsx(ve,{className:"h-2.5 w-2.5 text-muted-foreground/50"})}),"AI Auto-invoke"]})]})]}),h.metadata?.toolCategories&&h.metadata.toolCategories.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Tools"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:h.metadata.toolCategories.map(a=>e.jsx("span",{className:"rounded-md bg-white/[0.04] px-2 py-0.5 text-[10px] font-medium text-muted-foreground",children:a},a))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Location"}),e.jsx("code",{className:"block rounded-lg bg-white/[0.03] px-3 py-2 text-[11px] break-all text-muted-foreground ring-1 ring-white/[0.04]",children:h.dirPath})]}),h.metadata?.homepage&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Documentation"}),e.jsx("a",{href:h.metadata.homepage,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-blue-400 hover:text-blue-300 transition-colors",children:h.metadata.homepage})]}),h.instructions&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground/60",children:"Instructions Preview"}),e.jsx("div",{className:"max-h-48 overflow-y-auto rounded-lg bg-white/[0.02] p-3 ring-1 ring-white/[0.04]",children:e.jsxs("pre",{className:"whitespace-pre-wrap text-[11px] text-muted-foreground/70 leading-relaxed",children:[h.instructions.slice(0,2e3),h.instructions.length>2e3&&`
2
+
3
+ ... (truncated)`]})})]}),e.jsx("div",{className:"flex gap-2 pt-3 border-t border-white/[0.04]",children:e.jsx(b,{size:"sm",variant:h.enabled?"destructive":"default",className:"h-8 text-xs",onClick:()=>{d.mutate(h.name),t(null)},children:h.enabled?"Disable":"Enable"})})]}):null]})}),e.jsxs("div",{className:"flex items-start gap-2.5 rounded-xl bg-white/[0.02] p-4 text-xs text-muted-foreground/60",children:[e.jsx(Fe,{className:"h-4 w-4 shrink-0 mt-0.5 opacity-50"}),e.jsxs("p",{className:"leading-relaxed",children:["Skills are loaded from ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1 py-px",children:"skills/"})," (bundled),"," ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1 py-px",children:"~/.profclaw/skills/"})," (managed), and project"," ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1 py-px",children:"skills/"})," (workspace). Each skill is a folder with a"," ",e.jsx("code",{className:"rounded bg-white/[0.06] px-1 py-px",children:"SKILL.md"})," file."]})]})]})}function Ge({label:s,value:r,icon:t}){return e.jsxs("div",{className:"rounded-xl bg-card/50 backdrop-blur-sm p-4 shadow-sm ring-1 ring-white/[0.05]",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground/60",children:[e.jsx(t,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-[11px] font-medium uppercase tracking-wider",children:s})]}),e.jsx("p",{className:"mt-2 text-2xl font-semibold tracking-tight",children:r})]})}const Vs={execution:{icon:ke,label:"Execution",description:"Shell commands and scripts"},filesystem:{icon:Ze,label:"Filesystem",description:"File read/write operations"},web:{icon:Ee,label:"Web",description:"Web search and fetching"},git:{icon:Zt,label:"Git",description:"Version control operations"},browser:{icon:Na,label:"Browser",description:"Browser automation (Playwright)"},profclaw:{icon:Xe,label:"profClaw",description:"Ticket and project management"},memory:{icon:ys,label:"Memory",description:"Semantic memory storage"},data:{icon:Ze,label:"Data",description:"Database and API operations"},system:{icon:ke,label:"System",description:"System information"},custom:{icon:Xe,label:"Custom",description:"User-defined tools"}};function Qa({level:s}){const r={safe:{icon:me,label:"Safe",className:"text-green-600 dark:text-green-400 bg-green-100 dark:bg-green-900/30"},moderate:{icon:Ce,label:"Moderate",className:"text-amber-600 dark:text-amber-400 bg-amber-100 dark:bg-amber-900/30"},dangerous:{icon:rt,label:"Dangerous",className:"text-red-600 dark:text-red-400 bg-red-100 dark:bg-red-900/30"}},{icon:t,label:c,className:x}=r[s];return e.jsxs("span",{className:w("inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium",x),children:[e.jsx(t,{className:"h-3 w-3"}),c]})}function Wa({availability:s}){return s.available?e.jsxs("span",{className:"inline-flex items-center gap-1 text-green-600 dark:text-green-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:"Available"})]}):e.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-600 dark:text-amber-400",children:[e.jsx(re,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:s.reason||"Not configured"})]})}function Va({tool:s}){return e.jsxs("div",{className:w("rounded-lg p-3 transition-colors",s.availability.available?"bg-muted/30":"bg-amber-50/50 dark:bg-amber-900/10"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("code",{className:"text-sm font-mono font-medium text-foreground",children:s.name}),e.jsx(Qa,{level:s.securityLevel}),s.requiresApproval&&e.jsx("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium text-blue-600 dark:text-blue-400 bg-blue-100 dark:bg-blue-900/30",children:"Requires Approval"})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:s.description})]}),e.jsx("div",{className:"flex-shrink-0",children:e.jsx(Wa,{availability:s.availability})})]}),!s.availability.available&&e.jsx("div",{className:"mt-2 pt-2 border-t border-amber-200/20 dark:border-amber-800/30",children:e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:"Configure this tool in the Integrations section to enable it."})})]})}function Ga({category:s,tools:r,defaultExpanded:t=!1}){const[c,x]=f.useState(t),j=Vs[s]||Vs.custom,h=j.icon,N=r.filter(d=>d.availability.available).length,y=r.length-N;return e.jsxs("div",{className:"rounded-lg bg-muted/20 overflow-hidden",children:[e.jsxs("button",{onClick:()=>x(!c),className:"w-full flex items-center justify-between p-4 bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-lg bg-background",children:e.jsx(h,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("h3",{className:"font-medium text-sm",children:j.label}),e.jsx("p",{className:"text-xs text-muted-foreground",children:j.description})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[N>0&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400",children:[e.jsx(U,{className:"h-3.5 w-3.5"}),N]}),y>0&&e.jsxs("span",{className:"flex items-center gap-1 text-amber-600 dark:text-amber-400",children:[e.jsx(re,{className:"h-3.5 w-3.5"}),y]})]}),e.jsx(ft,{className:w("h-4 w-4 text-muted-foreground transition-transform",c&&"rotate-180")})]})]}),c&&e.jsx("div",{className:"p-3 space-y-2 bg-background",children:r.map(d=>e.jsx(Va,{tool:d},d.name))})]})}function Ja(){const[s,r]=f.useState(""),[t,c]=f.useState(!1),{data:x,isLoading:j,error:h,refetch:N,isFetching:y}=R({queryKey:["tools","availability"],queryFn:async()=>{const v=await fetch(`${A}/api/tools/list/availability`,{credentials:"include"});if(!v.ok)throw new Error("Failed to fetch tools");return v.json()},staleTime:3e4}),d=x?.byCategory?Object.entries(x.byCategory).reduce((v,[m,g])=>{let a=g;if(s){const n=s.toLowerCase();a=a.filter(k=>k.name.toLowerCase().includes(n)||k.description.toLowerCase().includes(n))}return t&&(a=a.filter(n=>!n.availability.available)),a.length>0&&(v[m]=a),v},{}):{};return j?e.jsx(B,{title:"AI Tools",description:"Tools available for AI agents",children:e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})})}):h?e.jsx(B,{title:"AI Tools",description:"Tools available for AI agents",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx(ne,{className:"h-8 w-8 text-destructive mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load tools"}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>N(),className:"mt-4",children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):e.jsx("div",{className:"space-y-6",children:e.jsxs(B,{title:"AI Tools",description:"Configure tools available to AI agents",children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs(b,{variant:"ghost",size:"sm",onClick:()=>N(),disabled:y,children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",y&&"animate-spin")}),"Refresh"]})}),e.jsxs("div",{className:"grid grid-cols-3 gap-4 mb-6",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-muted/30 text-center",children:[e.jsx("p",{className:"text-2xl font-bold",children:x?.summary.total??0}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Tools"})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-green-100 dark:bg-green-900/20 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-green-600 dark:text-green-400",children:x?.summary.available??0}),e.jsx("p",{className:"text-xs text-green-700 dark:text-green-300",children:"Available"})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-amber-100 dark:bg-amber-900/20 text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-amber-600 dark:text-amber-400",children:x?.summary.unavailable??0}),e.jsx("p",{className:"text-xs text-amber-700 dark:text-amber-300",children:"Need Config"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(O,{placeholder:"Search tools...",value:s,onChange:v=>r(v.target.value),className:"pl-9"})]}),e.jsxs(b,{variant:t?"default":"outline",size:"sm",onClick:()=>c(!t),children:[e.jsx(Yt,{className:"h-4 w-4 mr-2"}),t?"Show All":"Needs Setup"]})]}),x&&x.summary.unavailable>0&&!t&&e.jsx("div",{className:"p-3 rounded-lg bg-amber-50 dark:bg-amber-900/20 mb-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsxs("p",{className:"text-amber-800 dark:text-amber-200",children:[e.jsxs("strong",{children:[x.summary.unavailable," tools"]})," need configuration"]}),e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-0.5",children:"Configure API keys or install dependencies in Integrations to enable these tools."})]})]})}),e.jsx("div",{className:"space-y-3",children:Object.entries(d).length>0?Object.entries(d).map(([v,m])=>e.jsx(Ga,{category:v,tools:m,defaultExpanded:t||Object.keys(d).length<=3},v)):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Xe,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No tools match your search"})]})})]})})}const Ha=[{id:"telegram",name:"Telegram",description:"Bot API with commands & inline keyboards",Logo:hs,color:"text-[#0088CC]",bgColor:"bg-[#0088CC]/10",activeBorder:"border-[#0088CC]/40",activeBg:"bg-[#0088CC]/8",docsUrl:"https://core.telegram.org/bots/api",setupUrl:"https://t.me/BotFather",status:"available"},{id:"discord",name:"Discord",description:"Slash commands & interactions",Logo:ps,color:"text-[#5865F2]",bgColor:"bg-[#5865F2]/10",activeBorder:"border-[#5865F2]/40",activeBg:"bg-[#5865F2]/8",docsUrl:"https://discord.com/developers/docs",setupUrl:"https://discord.com/developers/applications",status:"available"},{id:"whatsapp",name:"WhatsApp",description:"Business Cloud API",Logo:gs,color:"text-[#25D366]",bgColor:"bg-[#25D366]/10",activeBorder:"border-[#25D366]/40",activeBg:"bg-[#25D366]/8",docsUrl:"https://developers.facebook.com/docs/whatsapp",setupUrl:"https://developers.facebook.com/apps/",status:"available"},{id:"slack",name:"Slack",description:"Bolt SDK with slash commands",Logo:fs,color:"text-[#4A154B]",bgColor:"bg-[#4A154B]/10",activeBorder:"border-[#4A154B]/40",activeBg:"bg-[#4A154B]/8",docsUrl:"https://api.slack.com/",setupUrl:"https://api.slack.com/apps",status:"available"},{id:"matrix",name:"Matrix",description:"Decentralized, E2EE optional",Logo:js,color:"text-[#0DBD8B]",bgColor:"bg-[#0DBD8B]/10",activeBorder:"border-[#0DBD8B]/40",activeBg:"bg-[#0DBD8B]/8",docsUrl:"https://spec.matrix.org/",setupUrl:"https://element.io/",status:"available"},{id:"googlechat",name:"Google Chat",description:"Workspace integration",Logo:Ns,color:"text-[#00AC47]",bgColor:"bg-[#00AC47]/10",activeBorder:"border-[#00AC47]/40",activeBg:"bg-[#00AC47]/8",docsUrl:"https://developers.google.com/chat",setupUrl:"https://console.cloud.google.com/",status:"available"},{id:"msteams",name:"MS Teams",description:"Bot Framework + Adaptive Cards",Logo:bs,color:"text-[#5059C9]",bgColor:"bg-[#5059C9]/10",activeBorder:"border-[#5059C9]/40",activeBg:"bg-[#5059C9]/8",docsUrl:"https://learn.microsoft.com/en-us/microsoftteams/platform/",setupUrl:"https://dev.teams.microsoft.com/",status:"available"}];function Ya(){const[s,r]=f.useState("telegram");return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:Ha.map(t=>{const c=t.Logo,x=s===t.id,j=t.status==="external",h=t.status==="coming-soon";return e.jsxs("button",{onClick:()=>r(t.id),className:w("flex items-center gap-2.5 px-4 py-2.5 rounded-xl border transition-all",x?`${t.activeBorder} ${t.activeBg} shadow-sm`:"border-border hover:border-primary/30 hover:bg-muted/50",h&&!x&&"opacity-80"),children:[e.jsx("div",{className:w("h-8 w-8 rounded-lg flex items-center justify-center transition-all",x?t.bgColor:"bg-muted"),children:e.jsx(c,{className:w("h-4 w-4",x?t.color:"text-muted-foreground")})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:w("font-medium text-sm",x&&t.color),children:t.name}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:h?"Coming soon":j?"See Integrations":x?"Active":"Configure"})]})]},t.id)})}),s==="telegram"&&e.jsx(Za,{}),s==="discord"&&e.jsx(Xa,{}),s==="whatsapp"&&e.jsx(en,{}),s==="slack"&&e.jsx(sn,{}),s==="matrix"&&e.jsx(tn,{}),s==="googlechat"&&e.jsx(an,{}),s==="msteams"&&e.jsx(nn,{}),e.jsx(rn,{})]})}function Za(){const s=H(),[r,t]=f.useState(!1),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(""),[d,v]=f.useState("Hello from profClaw!"),{data:m,isLoading:g,refetch:a}=R({queryKey:["telegram-status"],queryFn:async()=>{const T=await fetch(`${A}/api/telegram/status`,{credentials:"include"});if(!T.ok)throw new Error("Failed to fetch Telegram status");return T.json()},staleTime:3e4}),{data:n,refetch:k}=R({queryKey:["telegram-webhook"],queryFn:async()=>{const T=await fetch(`${A}/api/telegram/webhook`,{credentials:"include"});if(!T.ok)throw new Error("Failed to fetch webhook info");return T.json()},staleTime:3e4,enabled:!!m?.configured}),i=L({mutationFn:async T=>{const _=await fetch(`${A}/api/telegram/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({botToken:T})});if(!_.ok){const X=await _.json();throw new Error(X.error||"Failed to save config")}return _.json()},onSuccess:T=>{u.success("Telegram bot configured!",{description:`Connected as @${T.account.botUsername}`}),x(""),T.webhookSecret&&(navigator.clipboard.writeText(T.webhookSecret),u.info("Webhook secret copied to clipboard")),s.invalidateQueries({queryKey:["telegram-status"]})},onError:T=>{u.error("Failed to configure Telegram",{description:T instanceof Error?T.message:"Unknown error"})}}),C=L({mutationFn:async T=>{const _=await fetch(`${A}/api/telegram/set-webhook`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({url:T})});if(!_.ok){const X=await _.json();throw new Error(X.error||"Failed to set webhook")}return _.json()},onSuccess:T=>{u.success("Webhook configured!"),h(""),T.secretToken&&(navigator.clipboard.writeText(T.secretToken),u.info("Secret token copied to clipboard")),s.invalidateQueries({queryKey:["telegram-webhook"]})},onError:T=>{u.error("Failed to set webhook",{description:T instanceof Error?T.message:"Unknown error"})}}),p=L({mutationFn:async()=>{const T=await fetch(`${A}/api/telegram/webhook`,{method:"DELETE",credentials:"include"});if(!T.ok){const _=await T.json();throw new Error(_.error||"Failed to delete webhook")}return T.json()},onSuccess:()=>{u.success("Webhook removed"),s.invalidateQueries({queryKey:["telegram-webhook"]})},onError:T=>{u.error("Failed to remove webhook",{description:T instanceof Error?T.message:"Unknown error"})}}),l=L({mutationFn:async()=>{const T=await fetch(`${A}/api/telegram/test`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({chat_id:N,text:d})});if(!T.ok){const _=await T.json();throw new Error(_.error||"Failed to send message")}return T.json()},onSuccess:()=>{u.success("Test message sent!")},onError:T=>{u.error("Failed to send message",{description:T instanceof Error?T.message:"Unknown error"})}}),o=L({mutationFn:async()=>{const T=await fetch(`${A}/api/telegram/config`,{method:"DELETE",credentials:"include"});if(!T.ok){const _=await T.json();throw new Error(_.error||"Failed to disconnect")}return T.json()},onSuccess:()=>{u.success("Telegram bot disconnected"),x(""),h(""),s.invalidateQueries({queryKey:["telegram-status"]}),s.invalidateQueries({queryKey:["telegram-webhook"]})},onError:T=>{u.error("Failed to disconnect",{description:T instanceof Error?T.message:"Unknown error"})}}),q=()=>{a(),k()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#0088CC]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#0088CC]/8 via-[#0077B5]/5 to-[#005F8C]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#0088CC]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#0088CC] to-[#005F8C] flex items-center justify-center shadow-lg shadow-[#0088CC]/20 flex-shrink-0",children:e.jsx(hs,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Telegram Bot API"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#0088CC]/15 text-[#0088CC] border border-[#0088CC]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Official API"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Powered by the official"," ",e.jsx("a",{href:"https://core.telegram.org/bots/api",target:"_blank",rel:"noopener noreferrer",className:"text-[#0088CC] hover:underline",children:"Telegram Bot API"}),". Create your bot via @BotFather, paste the token, and you're live."]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#0088CC]"}),"Instant setup"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#0088CC]"}),"Webhook support"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#0088CC]"}),"Groups & channels"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#0088CC]"}),"Free & unlimited"]})]})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect your Telegram bot",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",m?.connected?"bg-gradient-to-br from-[#0088CC]/20 to-[#005F8C]/20 ring-1 ring-[#0088CC]/30":"bg-muted"),children:e.jsx(hs,{className:w("h-6 w-6",m?.connected?"text-[#0088CC]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:g?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):m?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#0088CC]"}),e.jsxs("span",{className:"font-medium",children:["@",m.bot?.username]}),m.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",m.latencyMs,"ms)"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:m.bot?.name}),m.allowlists&&(m.allowlists.users>0||m.allowlists.chats>0)&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-muted-foreground",children:[e.jsx(me,{className:"h-3.5 w-3.5 text-[#0088CC]"}),e.jsxs("span",{children:[m.allowlists.users>0&&`${m.allowlists.users} allowed users`,m.allowlists.users>0&&m.allowlists.chats>0&&", ",m.allowlists.chats>0&&`${m.allowlists.chats} allowed chats`]})]})]}):m?.configured?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Configured but not connected"})]}),m.error&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:m.error})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not configured"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Create a bot via"," ",e.jsx("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noopener noreferrer",className:"text-[#0088CC] hover:underline",children:"@BotFather"})," ","to get started"]})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:q,disabled:g,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",g&&"animate-spin")})})]}),!m?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Bot Token"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From @BotFather on Telegram"})]}),e.jsxs("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#0088CC] hover:underline flex items-center gap-1",children:["Open BotFather ",e.jsx(ae,{className:"h-3 w-3"})]})]}),e.jsx("div",{className:"space-y-1.5",children:e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:r?"text":"password",value:c,onChange:T=>x(T.target.value),placeholder:"123456789:ABCdefGHI...",className:"font-mono pr-10"}),e.jsx("button",{type:"button",onClick:()=>t(!r),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:r?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})}),e.jsxs(b,{onClick:()=>i.mutate(c.trim()),disabled:!c.trim()||i.isPending,className:"w-full sm:w-auto bg-[#0088CC] hover:bg-[#006DA3] text-white",children:[i.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):null,"Connect Telegram"]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-muted/50 text-xs text-muted-foreground",children:[e.jsx(Fe,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground/80",children:"Quick setup:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-0.5",children:[e.jsxs("li",{children:["Open ",e.jsx("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noopener noreferrer",className:"text-[#0088CC] hover:underline",children:"@BotFather"})," in Telegram"]}),e.jsxs("li",{children:["Send ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-muted",children:"/newbot"})," and follow the prompts"]}),e.jsx("li",{children:"Copy the bot token and paste it above"})]})]})]})]})]})}),m?.connected&&e.jsx(B,{title:"Webhook",description:"Configure how profClaw receives messages",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-lg bg-muted/50",children:[e.jsx(De,{className:"h-5 w-5 text-muted-foreground mt-0.5"}),e.jsx("div",{className:"flex-1 min-w-0",children:n?.url?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium text-green-600",children:"Webhook Active"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate font-mono",children:n.url}),n.pendingUpdateCount>0&&e.jsxs("p",{className:"text-xs text-yellow-600 mt-1",children:[n.pendingUpdateCount," pending updates"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium",children:"No Webhook Set"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Set a webhook URL so Telegram can deliver messages to profClaw"})]})}),n?.url&&e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>p.mutate(),disabled:p.isPending,className:"text-red-500 hover:text-red-600",children:p.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4"})})]}),!n?.url&&e.jsxs("div",{className:"space-y-3 p-3 rounded-lg border border-[#0088CC]/20 bg-[#0088CC]/5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4 text-[#0088CC]"}),e.jsx("p",{className:"text-sm font-medium",children:"Suggested Webhook URL"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{readOnly:!0,value:`${window.location.origin}/api/telegram/webhook`,className:"font-mono text-sm bg-background"}),e.jsx(b,{variant:"outline",size:"icon",className:"shrink-0",onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/api/telegram/webhook`),u.success("URL copied!")},children:e.jsx(Pe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{className:"bg-[#0088CC] hover:bg-[#0077B5] text-white",onClick:()=>C.mutate(`${window.location.origin}/api/telegram/webhook`),disabled:C.isPending,children:[C.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Use This URL"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"or enter a custom URL below"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:n?.url?"Change Webhook URL":"Custom Webhook URL"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(O,{type:"url",value:j,onChange:T=>h(T.target.value),placeholder:"https://your-domain.com/api/telegram/webhook"}),e.jsx(b,{onClick:()=>C.mutate(j.trim()),disabled:!j.trim()||C.isPending,variant:n?.url?"outline":"default",children:C.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Set"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Use a custom URL if profClaw is behind a reverse proxy or on a different domain"})]})]})}),m?.connected&&e.jsx(B,{title:"Test Message",description:"Verify the connection works",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Chat ID"}),e.jsx(O,{type:"text",value:N,onChange:T=>y(T.target.value),placeholder:"-100123456789"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Message"}),e.jsx(O,{type:"text",value:d,onChange:T=>v(T.target.value),placeholder:"Hello from profClaw!"})]})]}),e.jsxs(b,{onClick:()=>l.mutate(),disabled:!N.trim()||!d.trim()||l.isPending,children:[l.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(As,{className:"h-4 w-4 mr-2"}),"Send Test Message"]})]})}),m?.connected&&e.jsx(B,{title:"Bot Management",description:"Manage connected bots",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-[#0088CC]/20 bg-[#0088CC]/5",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-[#0088CC]/10 flex items-center justify-center",children:e.jsx(Se,{className:"h-4 w-4 text-[#0088CC]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:m.bot?.username?`@${m.bot.username}`:"Connected Bot"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Primary bot · Active"})]}),e.jsx(b,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>o.mutate(),disabled:o.isPending,children:o.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-lg border border-dashed border-muted-foreground/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 opacity-60",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(ls,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Multi-Bot Support"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect multiple Telegram bots for different teams or projects"})]})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60 backdrop-blur-[1px]",children:e.jsx("span",{className:"px-3 py-1 rounded-full text-xs font-medium bg-[#0088CC]/10 text-[#0088CC] border border-[#0088CC]/20",children:"Coming Soon — Cloud"})})]})]})})]})}function Xa(){const s=H(),[r,t]=f.useState(!1),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(""),[d,v]=f.useState(""),[m,g]=f.useState("Hello from profClaw!"),{data:a,isLoading:n,refetch:k}=R({queryKey:["discord-status"],queryFn:async()=>{const o=await fetch(`${A}/api/discord/status`,{credentials:"include"});if(!o.ok)throw new Error("Failed to fetch Discord status");return o.json()},staleTime:3e4}),i=L({mutationFn:async o=>{const q=await fetch(`${A}/api/discord/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(o)});if(!q.ok){const T=await q.json();throw new Error(T.error||"Failed to save config")}return q.json()},onSuccess:o=>{u.success("Discord bot configured!",{description:`Connected as ${o.account.botUsername}`}),x(""),h(""),y(""),s.invalidateQueries({queryKey:["discord-status"]})},onError:o=>{u.error("Failed to configure Discord",{description:o instanceof Error?o.message:"Unknown error"})}}),C=L({mutationFn:async({channelId:o,text:q})=>{const T=await fetch(`${A}/api/discord/test`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({channel_id:o,text:q})});if(!T.ok){const _=await T.json();throw new Error(_.error||"Failed to send message")}return T.json()},onSuccess:()=>{u.success("Test message sent!")},onError:o=>{u.error("Failed to send message",{description:o instanceof Error?o.message:"Unknown error"})}}),p=L({mutationFn:async()=>{const o=await fetch(`${A}/api/discord/config`,{method:"DELETE",credentials:"include"});if(!o.ok){const q=await o.json();throw new Error(q.error||"Failed to disconnect")}return o.json()},onSuccess:()=>{u.success("Discord bot disconnected"),x(""),h(""),y(""),s.invalidateQueries({queryKey:["discord-status"]})},onError:o=>{u.error("Failed to disconnect",{description:o instanceof Error?o.message:"Unknown error"})}}),l=async()=>{try{const o=await fetch(`${A}/api/discord/oauth/url`,{credentials:"include"});if(!o.ok)throw new Error("Failed to get OAuth URL");const q=await o.json();window.open(q.url,"_blank")}catch{u.error("Failed to get OAuth URL")}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#5865F2]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#5865F2]/8 via-[#4752C4]/5 to-[#3C45A5]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#5865F2]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#5865F2] to-[#4752C4] flex items-center justify-center shadow-lg shadow-[#5865F2]/20 flex-shrink-0",children:e.jsx(ps,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Discord Bot API"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#5865F2]/15 text-[#5865F2] border border-[#5865F2]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Official API"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Powered by the official"," ",e.jsx("a",{href:"https://discord.com/developers/docs",target:"_blank",rel:"noopener noreferrer",className:"text-[#5865F2] hover:underline",children:"Discord API"}),". Add your bot to any server with slash commands, interactions, and real-time messaging."]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#5865F2]"}),"Slash commands"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#5865F2]"}),"Interactions"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#5865F2]"}),"Multi-server"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#5865F2]"}),"Role-based access"]})]})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect your Discord bot",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",a?.connected?"bg-gradient-to-br from-[#5865F2]/20 to-[#4752C4]/20 ring-1 ring-[#5865F2]/30":"bg-muted"),children:e.jsx(ps,{className:w("h-6 w-6",a?.connected?"text-[#5865F2]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):a?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#5865F2]"}),e.jsx("span",{className:"font-medium",children:a.bot?.username}),a.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",a.latencyMs,"ms)"]})]}),a.allowlists&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-muted-foreground",children:[e.jsx(me,{className:"h-3.5 w-3.5 text-[#5865F2]"}),e.jsxs("span",{children:[a.allowlists.guilds," guilds, ",a.allowlists.channels," channels, ",a.allowlists.roles," roles"]})]})]}):a?.configured?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Configured but not connected"})]}),a?.error&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:a.error})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not configured"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Create an app at the"," ",e.jsx("a",{href:"https://discord.com/developers/applications",target:"_blank",rel:"noopener noreferrer",className:"text-[#5865F2] hover:underline",children:"Developer Portal"})," ","to get started"]})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>k(),disabled:n,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",n&&"animate-spin")})})]}),!a?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Bot Credentials"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From Discord Developer Portal"})]}),e.jsxs("a",{href:"https://discord.com/developers/applications",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#5865F2] hover:underline flex items-center gap-1",children:["Open Portal ",e.jsx(ae,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Application ID"}),e.jsx(O,{type:"text",placeholder:"e.g., 1234567890123456789",value:j,onChange:o=>h(o.target.value),className:"font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"General Information → Application ID"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Public Key"}),e.jsx(O,{type:"text",placeholder:"Hex string for Ed25519 verification",value:N,onChange:o=>y(o.target.value),className:"font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"General Information → Public Key"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Bot Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:r?"text":"password",placeholder:"Your bot token from Discord",value:c,onChange:o=>x(o.target.value),className:"font-mono pr-10"}),e.jsx("button",{type:"button",onClick:()=>t(!r),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:r?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Bot → Reset Token (only shown once)"})]}),e.jsxs(b,{onClick:()=>i.mutate({botToken:c,applicationId:j,publicKey:N}),disabled:!c||!j||!N||i.isPending,className:"w-full sm:w-auto bg-[#5865F2] hover:bg-[#4752C4] text-white",children:[i.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):null,"Connect Discord"]})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-muted/50 text-xs text-muted-foreground",children:[e.jsx(Fe,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground/80",children:"Quick setup:"}),e.jsxs("ol",{className:"list-decimal list-inside space-y-0.5",children:[e.jsxs("li",{children:["Go to ",e.jsx("a",{href:"https://discord.com/developers/applications",target:"_blank",rel:"noopener noreferrer",className:"text-[#5865F2] hover:underline",children:"Developer Portal"})," → New Application"]}),e.jsx("li",{children:"Copy Application ID and Public Key from General Information"}),e.jsx("li",{children:"Go to Bot → Reset Token and copy it"}),e.jsx("li",{children:"Enable Message Content Intent under Privileged Gateway Intents"})]})]})]})]})]})}),a?.configured&&e.jsx(B,{title:"Interactions Endpoint",description:"Configure this URL in your Discord application",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Interactions Endpoint URL"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{readOnly:!0,value:`${window.location.origin}/api/discord/interactions`,className:"font-mono text-sm"}),e.jsx(b,{variant:"outline",onClick:()=>{navigator.clipboard.writeText(`${window.location.origin}/api/discord/interactions`),u.success("URL copied!")},children:"Copy"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Paste this in General Information → Interactions Endpoint URL"})]}),e.jsxs(b,{variant:"outline",onClick:l,className:"border-[#5865F2]/30 text-[#5865F2] hover:bg-[#5865F2]/5",children:["Add Bot to Server ",e.jsx(ae,{className:"h-4 w-4 ml-2"})]})]})}),a?.connected&&e.jsx(B,{title:"Test Message",description:"Send a test message to a channel",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Channel ID"}),e.jsx(O,{type:"text",placeholder:"e.g., 1234567890123456789",value:d,onChange:o=>v(o.target.value),className:"font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Right-click channel → Copy Channel ID"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Message"}),e.jsx(O,{type:"text",placeholder:"Hello from profClaw!",value:m,onChange:o=>g(o.target.value)})]})]}),e.jsxs(b,{onClick:()=>C.mutate({channelId:d,text:m}),disabled:!d||!m||C.isPending,children:[C.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(As,{className:"h-4 w-4 mr-2"}),"Send Test Message"]})]})}),a?.connected&&e.jsx(B,{title:"Bot Management",description:"Manage connected bots",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-[#5865F2]/20 bg-[#5865F2]/5",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-[#5865F2]/10 flex items-center justify-center",children:e.jsx(Se,{className:"h-4 w-4 text-[#5865F2]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:a.bot?.username?`${a.bot.username}`:"Connected Bot"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Primary bot · Active"})]}),e.jsx(b,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>p.mutate(),disabled:p.isPending,children:p.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-lg border border-dashed border-muted-foreground/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 opacity-60",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(ls,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Multi-Bot Support"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect multiple Discord bots for different servers or purposes"})]})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60 backdrop-blur-[1px]",children:e.jsx("span",{className:"px-3 py-1 rounded-full text-xs font-medium bg-[#5865F2]/10 text-[#5865F2] border border-[#5865F2]/20",children:"Coming Soon — Cloud"})})]})]})})]})}function en(){const s=H(),[r,t]=f.useState(!1),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(""),[d,v]=f.useState(""),[m,g]=f.useState("Hello from profClaw!"),{data:a,isLoading:n,refetch:k}=R({queryKey:["whatsapp-status"],queryFn:async()=>{const o=await fetch(`${A}/api/whatsapp/status`,{credentials:"include"});if(!o.ok)throw new Error("Failed to fetch WhatsApp status");return o.json()},staleTime:3e4}),i=L({mutationFn:async o=>{const q=await fetch(`${A}/api/whatsapp/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(o)});if(!q.ok){const T=await q.json();throw new Error(T.error||"Failed to save config")}return q.json()},onSuccess:o=>{u.success("WhatsApp configured!",{description:o.account.phoneNumber?`Connected as ${o.account.phoneNumber}`:"Connected successfully"}),x(""),h(""),y(""),o.webhookVerifyToken&&(navigator.clipboard.writeText(o.webhookVerifyToken),u.info("Webhook verify token copied to clipboard")),s.invalidateQueries({queryKey:["whatsapp-status"]})},onError:o=>{u.error("Failed to configure WhatsApp",{description:o instanceof Error?o.message:"Unknown error"})}}),C=L({mutationFn:async()=>{const o=await fetch(`${A}/api/whatsapp/test`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({to:d,text:m})});if(!o.ok){const q=await o.json();throw new Error(q.error||"Failed to send message")}return o.json()},onSuccess:()=>{u.success("Test message sent!")},onError:o=>{u.error("Failed to send message",{description:o instanceof Error?o.message:"Unknown error"})}}),p=L({mutationFn:async()=>{const o=await fetch(`${A}/api/whatsapp/config`,{method:"DELETE",credentials:"include"});if(!o.ok){const q=await o.json();throw new Error(q.error||"Failed to disconnect")}return o.json()},onSuccess:()=>{u.success("WhatsApp disconnected"),x(""),h(""),y(""),s.invalidateQueries({queryKey:["whatsapp-status"]})},onError:o=>{u.error("Failed to disconnect",{description:o instanceof Error?o.message:"Unknown error"})}}),l=()=>{i.mutate({phoneNumberId:c.trim(),accessToken:j.trim(),appSecret:N.trim()||void 0})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#25D366]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#25D366]/8 via-[#128C7E]/5 to-[#075E54]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#25D366]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#25D366] to-[#128C7E] flex items-center justify-center shadow-lg shadow-[#25D366]/20 flex-shrink-0",children:e.jsx(gs,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"WhatsApp Business Cloud API"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#25D366]/15 text-[#25D366] border border-[#25D366]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Official API"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Powered by Meta's official"," ",e.jsx("a",{href:"https://developers.facebook.com/docs/whatsapp/cloud-api",target:"_blank",rel:"noopener noreferrer",className:"text-[#25D366] hover:underline",children:"WhatsApp Business Cloud API"})," ","— stable, enterprise-ready, and fully compliant with Meta's Terms of Service. No risk of account bans."]}),e.jsxs("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#25D366]"}),"ToS compliant"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#25D366]"}),"No ban risk"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#25D366]"}),"1,000 free msgs/month"]}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#25D366]"}),"Webhook verified"]})]})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect your WhatsApp Business account",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",a?.connected?"bg-gradient-to-br from-[#25D366]/20 to-[#128C7E]/20 ring-1 ring-[#25D366]/30":"bg-muted"),children:e.jsx(gs,{className:w("h-6 w-6",a?.connected?"text-[#25D366]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:n?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):a?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#25D366]"}),e.jsx("span",{className:"font-medium",children:a.phone?.displayPhoneNumber}),a.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",a.latencyMs,"ms)"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a.phone?.verifiedName}),a.phone?.qualityRating&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Quality: ",a.phone.qualityRating]}),a.allowlist&&a.allowlist.phones>0&&e.jsxs("div",{className:"flex items-center gap-2 mt-1.5 text-xs text-muted-foreground",children:[e.jsx(me,{className:"h-3.5 w-3.5 text-[#25D366]"}),e.jsxs("span",{children:[a.allowlist.phones," allowed phone numbers"]})]})]}):a?.configured?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"text-muted-foreground",children:"Configured but not connected"})]}),a.error&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:a.error})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Not configured"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Set up via"," ",e.jsx("a",{href:"https://developers.facebook.com/apps/",target:"_blank",rel:"noopener noreferrer",className:"text-[#25D366] hover:underline",children:"Meta Developer Dashboard"})," ","to get started"]})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>k(),disabled:n,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",n&&"animate-spin")})})]}),!a?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"API Credentials"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"From your Meta App Dashboard"})]}),e.jsxs("a",{href:"https://developers.facebook.com/docs/whatsapp/cloud-api/get-started",target:"_blank",rel:"noopener noreferrer",className:"text-xs text-[#25D366] hover:underline flex items-center gap-1",children:["Setup Guide ",e.jsx(ae,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Phone Number ID"}),e.jsx(O,{type:"text",value:c,onChange:o=>x(o.target.value),placeholder:"1234567890...",className:"font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:"Access Token"}),e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:r?"text":"password",value:j,onChange:o=>h(o.target.value),placeholder:"EAAxxxxxxxxx...",className:"font-mono pr-10"}),e.jsx("button",{type:"button",onClick:()=>t(!r),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:r?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("label",{className:"text-sm font-medium",children:["App Secret ",e.jsx("span",{className:"text-muted-foreground font-normal",children:"(for webhook verification)"})]}),e.jsx(O,{type:"password",value:N,onChange:o=>y(o.target.value),placeholder:"Optional but recommended",className:"font-mono"})]}),e.jsxs(b,{onClick:l,disabled:!c.trim()||!j.trim()||i.isPending,className:"w-full sm:w-auto bg-[#25D366] hover:bg-[#128C7E] text-white",children:[i.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):null,"Connect WhatsApp"]})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-muted/50 text-xs text-muted-foreground",children:[e.jsx(Fe,{className:"h-3.5 w-3.5 mt-0.5 flex-shrink-0"}),e.jsxs("p",{children:["profClaw uses the official WhatsApp Business Cloud API — not unofficial libraries like Baileys or whatsapp-web.js. This means no QR code scanning, no risk of your number being banned, and no breakage when WhatsApp updates their protocol."," ",e.jsx("a",{href:"https://developers.facebook.com/docs/whatsapp/cloud-api",target:"_blank",rel:"noopener noreferrer",className:"text-[#25D366] hover:underline",children:"Learn more"})]})]})]})]})}),a?.connected&&e.jsx(B,{title:"Webhook Configuration",description:"Configure Meta webhook for receiving messages",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-muted/50 space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Webhook URL"}),e.jsxs("code",{className:"text-xs font-mono text-muted-foreground block break-all",children:[window.location.origin,"/api/whatsapp/webhook"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Add this URL in your"," ",e.jsx("a",{href:"https://developers.facebook.com/apps",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Meta App Dashboard"})," ","under WhatsApp ",">"," Configuration ",">",' Webhook. Subscribe to the "messages" field.']})]})}),a?.connected&&e.jsx(B,{title:"Test Message",description:"Verify the connection works",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Phone Number"}),e.jsx(O,{type:"text",value:d,onChange:o=>v(o.target.value),placeholder:"+1234567890"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Message"}),e.jsx(O,{type:"text",value:m,onChange:o=>g(o.target.value),placeholder:"Hello from profClaw!"})]})]}),e.jsxs(b,{onClick:()=>C.mutate(),disabled:!d.trim()||!m.trim()||C.isPending,children:[C.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(As,{className:"h-4 w-4 mr-2"}),"Send Test Message"]})]})}),a?.connected&&e.jsx(B,{title:"Number Management",description:"Manage connected WhatsApp numbers",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-[#25D366]/20 bg-[#25D366]/5",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-[#25D366]/10 flex items-center justify-center",children:e.jsx(Se,{className:"h-4 w-4 text-[#25D366]"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:a.phone?.displayPhoneNumber||a.phone?.verifiedName||"Connected Number"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Primary number",a.phone?.qualityRating?` · Quality: ${a.phone.qualityRating}`:" · Active"]})]}),e.jsx(b,{variant:"ghost",size:"sm",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>p.mutate(),disabled:p.isPending,children:p.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(ne,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative overflow-hidden rounded-lg border border-dashed border-muted-foreground/20 p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 opacity-60",children:[e.jsx("div",{className:"h-8 w-8 rounded-full bg-muted flex items-center justify-center",children:e.jsx(ls,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:"Multi-Number Support"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connect multiple WhatsApp Business numbers for different teams"})]})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/60 backdrop-blur-[1px]",children:e.jsx("span",{className:"px-3 py-1 rounded-full text-xs font-medium bg-[#25D366]/10 text-[#25D366] border border-[#25D366]/20",children:"Coming Soon — Cloud"})})]})]})})]})}function sn(){const s=H(),[r,t]=f.useState(!1),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(""),{data:d,isLoading:v,refetch:m}=R({queryKey:["slack-status"],queryFn:async()=>{const n=await fetch(`${A}/api/slack/status`,{credentials:"include"});if(!n.ok)throw new Error("Failed to fetch Slack status");return n.json()},staleTime:3e4}),g=L({mutationFn:async n=>{const k=await fetch(`${A}/api/slack/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!k.ok){const i=await k.json();throw new Error(i.error||"Failed to save config")}return k.json()},onSuccess:()=>{u.success("Slack bot configured!"),x(""),h(""),y(""),s.invalidateQueries({queryKey:["slack-status"]})},onError:n=>{u.error("Failed to configure Slack",{description:n instanceof Error?n.message:"Unknown error"})}}),a=L({mutationFn:async()=>{const n=await fetch(`${A}/api/slack/config`,{method:"DELETE",credentials:"include"});if(!n.ok)throw new Error("Failed to disconnect");return n.json()},onSuccess:()=>{u.success("Slack bot disconnected"),s.invalidateQueries({queryKey:["slack-status"]})},onError:n=>{u.error("Failed to disconnect",{description:n instanceof Error?n.message:"Unknown error"})}});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#4A154B]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#4A154B]/8 via-[#4A154B]/5 to-[#611f69]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#4A154B]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#4A154B] to-[#611f69] flex items-center justify-center shadow-lg shadow-[#4A154B]/20 flex-shrink-0",children:e.jsx(fs,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Slack (Bolt SDK)"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#4A154B]/15 text-[#4A154B] border border-[#4A154B]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Official SDK"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Connect via the"," ",e.jsx("a",{href:"https://api.slack.com/",target:"_blank",rel:"noopener noreferrer",className:"text-[#4A154B] hover:underline",children:"Slack Bolt SDK"}),". Create a Slack App, add the Bot Token and Signing Secret."]}),e.jsx("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:["Slash commands","Thread replies","Channel notifications","App Home tab"].map(n=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#4A154B]"}),n]},n))})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect your Slack bot",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",d?.connected?"bg-gradient-to-br from-[#4A154B]/20 to-[#611f69]/20 ring-1 ring-[#4A154B]/30":"bg-muted"),children:e.jsx(fs,{className:w("h-6 w-6",d?.connected?"text-[#4A154B]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:v?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):d?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#4A154B]"}),e.jsx("span",{className:"font-medium",children:d.bot?.name}),d.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",d.latencyMs,"ms)"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.bot?.teamName})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:d?.configured?"Configured but not connected":"Not configured"})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>m(),disabled:v,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",v&&"animate-spin")})})]}),!d?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Bot Token"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"xoxb-... token from your Slack App"}),e.jsx("div",{className:"flex gap-2",children:e.jsxs("div",{className:"relative flex-1",children:[e.jsx(O,{type:r?"text":"password",value:c,onChange:n=>x(n.target.value),placeholder:"xoxb-..."}),e.jsx("button",{onClick:()=>t(!r),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:r?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Signing Secret"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"From App Credentials page"}),e.jsx(O,{type:"password",value:j,onChange:n=>h(n.target.value),placeholder:"Signing secret..."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"App-Level Token (optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"xapp-... for Socket Mode"}),e.jsx(O,{type:"password",value:N,onChange:n=>y(n.target.value),placeholder:"xapp-..."})]}),e.jsxs(b,{onClick:()=>g.mutate({botToken:c,signingSecret:j,appToken:N||void 0}),disabled:!c.trim()||!j.trim()||g.isPending,className:"bg-[#4A154B] hover:bg-[#611f69]",children:[g.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Connect Slack Bot"]})]}),d?.connected&&e.jsx("div",{className:"pt-4 border-t border-border",children:e.jsxs(b,{variant:"outline",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>a.mutate(),disabled:a.isPending,children:[a.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Disconnect"]})})]})})]})}function tn(){const s=H(),[r,t]=f.useState(""),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(!1),{data:d,isLoading:v,refetch:m}=R({queryKey:["matrix-status"],queryFn:async()=>{const n=await fetch(`${A}/api/matrix/status`,{credentials:"include"});if(!n.ok)throw new Error("Failed to fetch Matrix status");return n.json()},staleTime:3e4}),g=L({mutationFn:async n=>{const k=await fetch(`${A}/api/matrix/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!k.ok){const i=await k.json();throw new Error(i.error||"Failed to save config")}return k.json()},onSuccess:()=>{u.success("Matrix bot configured!"),t(""),x(""),h(""),s.invalidateQueries({queryKey:["matrix-status"]})},onError:n=>{u.error("Failed to configure Matrix",{description:n instanceof Error?n.message:"Unknown error"})}}),a=L({mutationFn:async()=>{const n=await fetch(`${A}/api/matrix/config`,{method:"DELETE",credentials:"include"});if(!n.ok)throw new Error("Failed to disconnect");return n.json()},onSuccess:()=>{u.success("Matrix bot disconnected"),s.invalidateQueries({queryKey:["matrix-status"]})},onError:n=>{u.error("Failed to disconnect",{description:n instanceof Error?n.message:"Unknown error"})}});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#0DBD8B]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#0DBD8B]/8 via-[#0DBD8B]/5 to-[#00886A]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#0DBD8B]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#0DBD8B] to-[#00886A] flex items-center justify-center shadow-lg shadow-[#0DBD8B]/20 flex-shrink-0",children:e.jsx(js,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Matrix Protocol"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#0DBD8B]/15 text-[#0DBD8B] border border-[#0DBD8B]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Decentralized"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Connect to any"," ",e.jsx("a",{href:"https://matrix.org/",target:"_blank",rel:"noopener noreferrer",className:"text-[#0DBD8B] hover:underline",children:"Matrix"})," ","homeserver. Works with Element, Synapse, Dendrite, and others."]}),e.jsx("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:["Room-based chat","E2EE optional","Federation","Self-hosted"].map(n=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#0DBD8B]"}),n]},n))})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect to a Matrix homeserver",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",d?.connected?"bg-gradient-to-br from-[#0DBD8B]/20 to-[#00886A]/20 ring-1 ring-[#0DBD8B]/30":"bg-muted"),children:e.jsx(js,{className:w("h-6 w-6",d?.connected?"text-[#0DBD8B]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:v?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):d?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#0DBD8B]"}),e.jsx("span",{className:"font-medium",children:d.user?.displayName||d.user?.userId}),d.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",d.latencyMs,"ms)"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:d.user?.homeserver})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:d?.configured?"Configured but not connected":"Not configured"})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>m(),disabled:v,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",v&&"animate-spin")})})]}),!d?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Homeserver URL"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"e.g. https://matrix.org or your self-hosted server"}),e.jsx(O,{value:r,onChange:n=>t(n.target.value),placeholder:"https://matrix.org"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"User ID"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Full Matrix user ID"}),e.jsx(O,{value:j,onChange:n=>h(n.target.value),placeholder:"@bot:matrix.org"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Access Token"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"From Element Settings or /_matrix/client/v3/login"}),e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:N?"text":"password",value:c,onChange:n=>x(n.target.value),placeholder:"syt_..."}),e.jsx("button",{onClick:()=>y(!N),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:N?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}),e.jsxs(b,{onClick:()=>g.mutate({homeserverUrl:r,accessToken:c,userId:j}),disabled:!r.trim()||!c.trim()||!j.trim()||g.isPending,className:"bg-[#0DBD8B] hover:bg-[#00886A] text-white",children:[g.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Connect to Matrix"]})]}),d?.connected&&e.jsx("div",{className:"pt-4 border-t border-border",children:e.jsxs(b,{variant:"outline",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>a.mutate(),disabled:a.isPending,children:[a.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Disconnect"]})})]})})]})}function an(){const s=H(),[r,t]=f.useState(""),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState("webhook"),{data:d,isLoading:v,refetch:m}=R({queryKey:["googlechat-status"],queryFn:async()=>{const n=await fetch(`${A}/api/googlechat/status`,{credentials:"include"});if(!n.ok)throw new Error("Failed to fetch Google Chat status");return n.json()},staleTime:3e4}),g=L({mutationFn:async n=>{const k=await fetch(`${A}/api/googlechat/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!k.ok){const i=await k.json();throw new Error(i.error||"Failed to save config")}return k.json()},onSuccess:()=>{u.success("Google Chat configured!"),t(""),x(""),h(""),s.invalidateQueries({queryKey:["googlechat-status"]})},onError:n=>{u.error("Failed to configure Google Chat",{description:n instanceof Error?n.message:"Unknown error"})}}),a=L({mutationFn:async()=>{const n=await fetch(`${A}/api/googlechat/config`,{method:"DELETE",credentials:"include"});if(!n.ok)throw new Error("Failed to disconnect");return n.json()},onSuccess:()=>{u.success("Google Chat disconnected"),s.invalidateQueries({queryKey:["googlechat-status"]})},onError:n=>{u.error("Failed to disconnect",{description:n instanceof Error?n.message:"Unknown error"})}});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#00AC47]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#00AC47]/8 via-[#00AC47]/5 to-[#00832D]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#00AC47]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#00AC47] to-[#00832D] flex items-center justify-center shadow-lg shadow-[#00AC47]/20 flex-shrink-0",children:e.jsx(Ns,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Google Chat"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#00AC47]/15 text-[#00AC47] border border-[#00AC47]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Workspace"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Integrate with"," ",e.jsx("a",{href:"https://developers.google.com/chat",target:"_blank",rel:"noopener noreferrer",className:"text-[#00AC47] hover:underline",children:"Google Chat"}),". Use webhook mode for simple notifications, or service account for full interactivity."]}),e.jsx("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:["Spaces","Threads","Cards v2","Webhook + API"].map(n=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#00AC47]"}),n]},n))})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect to Google Chat",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",d?.connected?"bg-gradient-to-br from-[#00AC47]/20 to-[#00832D]/20 ring-1 ring-[#00AC47]/30":"bg-muted"),children:e.jsx(Ns,{className:w("h-6 w-6",d?.connected?"text-[#00AC47]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:v?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):d?.connected?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#00AC47]"}),e.jsx("span",{className:"font-medium",children:d.space?.displayName||"Connected"}),d.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",d.latencyMs,"ms)"]})]})}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:d?.configured?"Configured but not connected":"Not configured"})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>m(),disabled:v,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",v&&"animate-spin")})})]}),!d?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>y("webhook"),className:w("flex-1 py-2 px-3 rounded-lg border text-sm font-medium transition-all",N==="webhook"?"border-[#00AC47]/40 bg-[#00AC47]/8 text-[#00AC47]":"border-border hover:bg-muted/50"),children:"Webhook (Simple)"}),e.jsx("button",{onClick:()=>y("service-account"),className:w("flex-1 py-2 px-3 rounded-lg border text-sm font-medium transition-all",N==="service-account"?"border-[#00AC47]/40 bg-[#00AC47]/8 text-[#00AC47]":"border-border hover:bg-muted/50"),children:"Service Account (Full)"})]}),N==="webhook"?e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Webhook URL"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"From Google Chat space settings"}),e.jsx(O,{value:r,onChange:n=>t(n.target.value),placeholder:"https://chat.googleapis.com/v1/spaces/..."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Project ID"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Google Cloud project ID"}),e.jsx(O,{value:j,onChange:n=>h(n.target.value),placeholder:"my-project-123"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Service Account Key (JSON)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Paste the full JSON key contents"}),e.jsx("textarea",{value:c,onChange:n=>x(n.target.value),placeholder:'{"type": "service_account", ...}',className:"w-full h-24 px-3 py-2 text-sm rounded-md border border-input bg-background font-mono resize-none"})]})]}),e.jsxs(b,{onClick:()=>g.mutate(N==="webhook"?{webhookUrl:r}:{serviceAccountKey:c,projectId:j}),disabled:(N==="webhook"?!r.trim():!c.trim()||!j.trim())||g.isPending,className:"bg-[#00AC47] hover:bg-[#00832D] text-white",children:[g.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Connect Google Chat"]})]}),d?.connected&&e.jsx("div",{className:"pt-4 border-t border-border",children:e.jsxs(b,{variant:"outline",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>a.mutate(),disabled:a.isPending,children:[a.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Disconnect"]})})]})})]})}function nn(){const s=H(),[r,t]=f.useState(""),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(!1),{data:d,isLoading:v,refetch:m}=R({queryKey:["msteams-status"],queryFn:async()=>{const n=await fetch(`${A}/api/msteams/status`,{credentials:"include"});if(!n.ok)throw new Error("Failed to fetch Teams status");return n.json()},staleTime:3e4}),g=L({mutationFn:async n=>{const k=await fetch(`${A}/api/msteams/config`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(n)});if(!k.ok){const i=await k.json();throw new Error(i.error||"Failed to save config")}return k.json()},onSuccess:()=>{u.success("Microsoft Teams bot configured!"),t(""),x(""),h(""),s.invalidateQueries({queryKey:["msteams-status"]})},onError:n=>{u.error("Failed to configure Teams",{description:n instanceof Error?n.message:"Unknown error"})}}),a=L({mutationFn:async()=>{const n=await fetch(`${A}/api/msteams/config`,{method:"DELETE",credentials:"include"});if(!n.ok)throw new Error("Failed to disconnect");return n.json()},onSuccess:()=>{u.success("Teams bot disconnected"),s.invalidateQueries({queryKey:["msteams-status"]})},onError:n=>{u.error("Failed to disconnect",{description:n instanceof Error?n.message:"Unknown error"})}});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative overflow-hidden rounded-xl border border-[#5059C9]/20",children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-[#5059C9]/8 via-[#5059C9]/5 to-[#7B83EB]/8"}),e.jsx("div",{className:"absolute top-0 right-0 w-32 h-32 bg-[#5059C9]/5 rounded-full -translate-y-1/2 translate-x-1/2 blur-2xl"}),e.jsx("div",{className:"relative p-4 sm:p-5",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-12 w-12 rounded-xl bg-gradient-to-br from-[#5059C9] to-[#7B83EB] flex items-center justify-center shadow-lg shadow-[#5059C9]/20 flex-shrink-0",children:e.jsx(bs,{className:"h-6 w-6 text-white"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("h3",{className:"text-base font-semibold",children:"Microsoft Teams"}),e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-semibold bg-[#5059C9]/15 text-[#5059C9] border border-[#5059C9]/25",children:[e.jsx(me,{className:"h-3 w-3"}),"Bot Framework"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Connect via"," ",e.jsx("a",{href:"https://dev.teams.microsoft.com/",target:"_blank",rel:"noopener noreferrer",className:"text-[#5059C9] hover:underline",children:"Microsoft Bot Framework"}),". Register your bot app in Azure AD, then add the credentials here."]}),e.jsx("div",{className:"flex flex-wrap gap-3 mt-3 text-[11px] text-muted-foreground",children:["Adaptive Cards","Channel messages","Mentions","SSO auth"].map(n=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3 text-[#5059C9]"}),n]},n))})]})]})})]}),e.jsx(B,{title:"Connection",description:"Connect your Teams bot",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",d?.connected?"bg-gradient-to-br from-[#5059C9]/20 to-[#7B83EB]/20 ring-1 ring-[#5059C9]/30":"bg-muted"),children:e.jsx(bs,{className:w("h-6 w-6",d?.connected?"text-[#5059C9]":"text-muted-foreground")})}),e.jsx("div",{className:"flex-1 min-w-0",children:v?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Checking connection..."})]}):d?.connected?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(U,{className:"h-4 w-4 text-[#5059C9]"}),e.jsx("span",{className:"font-medium",children:d.bot?.name||"Connected"}),d.latencyMs&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",d.latencyMs,"ms)"]})]}),d.bot?.tenantId&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Tenant: ",d.bot.tenantId]})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:d?.configured?"Configured but not connected":"Not configured"})]})}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>m(),disabled:v,className:"h-8 w-8 p-0",children:e.jsx(Q,{className:w("h-4 w-4",v&&"animate-spin")})})]}),!d?.connected&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"App (Client) ID"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"From Azure AD App Registration"}),e.jsx(O,{value:r,onChange:n=>t(n.target.value),placeholder:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"App Password (Client Secret)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"From Certificates & Secrets"}),e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:N?"text":"password",value:c,onChange:n=>x(n.target.value),placeholder:"Client secret value..."}),e.jsx("button",{onClick:()=>y(!N),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:N?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Tenant ID (optional)"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Leave blank for multi-tenant bots"}),e.jsx(O,{value:j,onChange:n=>h(n.target.value),placeholder:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"})]}),e.jsxs(b,{onClick:()=>g.mutate({appId:r,appPassword:c,tenantId:j||void 0}),disabled:!r.trim()||!c.trim()||g.isPending,className:"bg-[#5059C9] hover:bg-[#4B53BC] text-white",children:[g.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(De,{className:"h-4 w-4 mr-2"}),"Connect Teams Bot"]})]}),d?.connected&&e.jsx("div",{className:"pt-4 border-t border-border",children:e.jsxs(b,{variant:"outline",className:"text-red-500 hover:text-red-600 hover:bg-red-500/10",onClick:()=>a.mutate(),disabled:a.isPending,children:[a.isPending?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ke,{className:"h-4 w-4 mr-2"}),"Disconnect"]})})]})})]})}function rn(){const s=H(),[r,t]=f.useState(""),[c,x]=f.useState(""),[j,h]=f.useState(""),[N,y]=f.useState(""),{data:d,isLoading:v}=R({queryKey:["group-chat-config"],queryFn:async()=>{const i=await fetch(`${A}/api/chat/group/config`,{credentials:"include"});if(!i.ok)throw new Error("Failed to fetch group chat config");return i.json()},staleTime:3e4}),m=L({mutationFn:async i=>{if(!(await fetch(`${A}/api/chat/group/rate-limit`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(i)})).ok)throw new Error("Failed to save rate limit")},onSuccess:()=>{u.success("Rate limit saved"),t(""),x(""),s.invalidateQueries({queryKey:["group-chat-config"]})},onError:i=>{u.error(i.message??"Failed to save rate limit")}}),g=L({mutationFn:async i=>{if(!(await fetch(`${A}/api/chat/group/personality`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(i)})).ok)throw new Error("Failed to save personality")},onSuccess:()=>{u.success("Channel personality saved"),h(""),y(""),s.invalidateQueries({queryKey:["group-chat-config"]})},onError:i=>{u.error(i.message??"Failed to save personality")}}),a=parseInt(c,10),n=r.trim().length>0&&!isNaN(a)&&a>0,k=j.trim().length>0&&N.trim().length>0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsx("div",{className:"h-8 w-8 rounded-lg bg-primary/10 flex items-center justify-center",children:e.jsx(jt,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-base",children:"Group Chat"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Behaviour settings for group and multi-user channels"})]})]}),e.jsxs(B,{title:"Mention Gating",description:"Control when the bot responds in group conversations",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-muted flex items-center justify-center",children:e.jsx(ea,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Only respond when @mentioned"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"When enabled, the bot ignores messages that do not mention it directly"})]})]}),v?e.jsx(P,{className:"h-4 w-4 animate-spin text-muted-foreground"}):e.jsx(Ne,{checked:d?.mentionGating??!1,disabled:!0,"aria-label":"Mention gating status (read-only)"})]}),!v&&d&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-3 flex items-center gap-1.5",children:[e.jsx(Fe,{className:"h-3.5 w-3.5 shrink-0"}),"This setting is managed via the config file. Restart the server after changing it."]})]}),e.jsx(B,{title:"Rate Limits",description:"Throttle bot responses per channel to prevent spam",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-muted/40 border border-border",children:[e.jsx(ha,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Default rate limit"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Applied to all channels without a specific override"})]}),e.jsx("span",{className:"text-sm font-mono font-semibold tabular-nums",children:v?e.jsx(P,{className:"h-3.5 w-3.5 animate-spin"}):`${d?.rateLimits?.default??"-"} / min`})]}),!v&&d&&Object.keys(d.rateLimits?.perChannel??{}).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Channel overrides"}),Object.entries(d.rateLimits.perChannel).map(([i,C])=>e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded-lg border border-border bg-muted/20 text-sm",children:[e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:i}),e.jsxs("span",{className:"font-semibold tabular-nums",children:[C," / min"]})]},i))]}),e.jsxs("div",{className:"space-y-3 pt-1",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Add override"}),e.jsxs("div",{className:"grid grid-cols-[1fr_auto] gap-2 items-end",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{htmlFor:"rl-channel-id",className:"text-xs",children:"Channel ID"}),e.jsx(O,{id:"rl-channel-id",value:r,onChange:i=>t(i.target.value),placeholder:"e.g. C01234ABCDE or -1001234567890",className:"text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{htmlFor:"rl-max-per-min",className:"text-xs",children:"Max / min"}),e.jsx(O,{id:"rl-max-per-min",type:"number",min:1,value:c,onChange:i=>x(i.target.value),placeholder:"10",className:"text-sm w-24"})]})]}),e.jsxs(b,{size:"sm",disabled:!n||m.isPending,onClick:()=>m.mutate({channelId:r.trim(),maxPerMinute:a}),children:[m.isPending?e.jsx(P,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Ye,{className:"h-3.5 w-3.5 mr-1.5"}),"Save Override"]})]})]})}),e.jsx(B,{title:"Channel Personality",description:"Give the bot a custom system prompt for a specific channel",children:e.jsxs("div",{className:"space-y-4",children:[!v&&d&&Object.keys(d.personalities??{}).length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Active personalities"}),Object.entries(d.personalities).map(([i,C])=>e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-mono text-muted-foreground",children:i}),e.jsx("p",{className:"text-sm line-clamp-2",children:C})]},i))]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Set personality"}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{htmlFor:"persona-channel-id",className:"text-xs",children:"Channel ID"}),e.jsx(O,{id:"persona-channel-id",value:j,onChange:i=>h(i.target.value),placeholder:"e.g. C01234ABCDE or -1001234567890",className:"text-sm"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(de,{htmlFor:"persona-system-prompt",className:"text-xs",children:"System prompt"}),e.jsx(Xt,{id:"persona-system-prompt",value:N,onChange:i=>y(i.target.value),placeholder:"You are a helpful assistant specialized in customer support...",rows:4,className:"text-sm resize-y"})]}),e.jsxs(b,{size:"sm",disabled:!k||g.isPending,onClick:()=>g.mutate({channelId:j.trim(),systemPrompt:N.trim()}),children:[g.isPending?e.jsx(P,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Se,{className:"h-3.5 w-3.5 mr-1.5"}),"Save Personality"]})]})]})})]})}function ln(){const[s,r]=f.useState({isInstalled:!1,isInstallable:!1,isOnline:navigator.onLine,pushSupported:"PushManager"in window,pushSubscribed:!1,serviceWorkerReady:!1}),[t,c]=f.useState(null);f.useEffect(()=>{"serviceWorker"in navigator&&navigator.serviceWorker.register("/sw.js").then(v=>{r(m=>({...m,serviceWorkerReady:!0})),setInterval(()=>v.update(),3600*1e3)}).catch(v=>{console.error("[PWA] Service worker registration failed:",v)});const h=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0;r(v=>({...v,isInstalled:h}));const N=v=>{v.preventDefault(),c(v),r(m=>({...m,isInstallable:!0}))},y=()=>r(v=>({...v,isOnline:!0})),d=()=>r(v=>({...v,isOnline:!1}));return window.addEventListener("beforeinstallprompt",N),window.addEventListener("online",y),window.addEventListener("offline",d),()=>{window.removeEventListener("beforeinstallprompt",N),window.removeEventListener("online",y),window.removeEventListener("offline",d)}},[]);const x=f.useCallback(async()=>{if(!t)return!1;const N=(await t.prompt()).outcome==="accepted";return N&&(r(y=>({...y,isInstalled:!0,isInstallable:!1})),c(null)),N},[t]),j=f.useCallback(async()=>{if(!("PushManager"in window)||!("serviceWorker"in navigator))return!1;try{const h=await navigator.serviceWorker.ready,N=await fetch("/api/push/vapid-key"),{publicKey:y}=await N.json(),d=await h.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:y});return await fetch("/api/push/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoint:d.endpoint,keys:{p256dh:btoa(String.fromCharCode(...new Uint8Array(d.getKey("p256dh")))),auth:btoa(String.fromCharCode(...new Uint8Array(d.getKey("auth"))))}})}),r(v=>({...v,pushSubscribed:!0})),!0}catch(h){return console.error("[PWA] Push subscription failed:",h),!1}},[]);return{...s,promptInstall:x,subscribePush:j}}function on(){const{isInstalled:s,isInstallable:r,isOnline:t,pushSupported:c,pushSubscribed:x,serviceWorkerReady:j,promptInstall:h,subscribePush:N}=ln();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Progressive Web App"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Install profClaw as a native app and enable push notifications."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Service Worker"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enables offline support and caching"})]}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${j?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-yellow-100 text-yellow-700 dark:bg-yellow-900/30 dark:text-yellow-400"}`,children:j?"Active":"Registering..."})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Connection"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages queue when offline"})]}),e.jsx("span",{className:`inline-flex items-center rounded-full px-2 py-1 text-xs font-medium ${t?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"}`,children:t?"Online":"Offline"})]})]}),!s&&r&&e.jsx("div",{className:"rounded-lg border border-dashed p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Install profClaw"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add to your home screen for a native app experience"})]}),e.jsx("button",{onClick:()=>h(),className:"rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90",children:"Install"})]})}),s&&e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"profClaw is installed as a native app."})}),c&&e.jsx("div",{className:"rounded-lg border p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Push Notifications"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Get notified about task completions and agent activity"})]}),x?e.jsx("span",{className:"inline-flex items-center rounded-full bg-green-100 px-2 py-1 text-xs font-medium text-green-700 dark:bg-green-900/30 dark:text-green-400",children:"Enabled"}):e.jsx("button",{onClick:()=>N(),className:"rounded-md border px-4 py-2 text-sm font-medium hover:bg-accent",children:"Enable"})]})})]})}function Gs({value:s,onValueChange:r,min:t,max:c,step:x,className:j,disabled:h}){const[N]=s,y=d=>{r([parseFloat(d.target.value)])};return e.jsx("input",{type:"range",min:t,max:c,step:x,value:N,onChange:y,disabled:h,className:w("w-full h-2 rounded-lg appearance-none cursor-pointer","bg-secondary accent-primary","disabled:cursor-not-allowed disabled:opacity-50",j)})}const cn=[{name:"OpenAI Whisper",envVar:"OPENAI_API_KEY",description:"Most popular, supports 99 languages",icon:"W"},{name:"Deepgram",envVar:"DEEPGRAM_API_KEY",description:"Real-time streaming, lower latency",icon:"D"}],dn=[{name:"ElevenLabs",envVar:"ELEVENLABS_API_KEY",description:"Natural, expressive voices",icon:"E"},{name:"OpenAI TTS",envVar:"OPENAI_API_KEY",description:"6 voices, uses same key as chat",icon:"O"},{name:"System TTS",envVar:"none",description:"No key needed (macOS say / Linux espeak)",icon:"S"}];function mn({available:s}){return s?e.jsxs(ie,{className:"gap-1 bg-green-500/10 text-green-600 dark:text-green-400 border-green-500/20",children:[e.jsx(U,{className:"h-3 w-3"}),"Available"]}):e.jsxs(ie,{className:"gap-1 bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/20",children:[e.jsx(ne,{className:"h-3 w-3"}),"Unavailable"]})}function Js({provider:s}){return e.jsxs("div",{className:w("flex items-start gap-3 rounded-xl border border-border/50 p-3","bg-muted/30 transition-colors hover:bg-muted/50"),children:[e.jsx("div",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-sm font-bold text-primary",children:s.icon}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:s.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.description}),s.envVar!=="none"&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx(bt,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("code",{className:"font-mono text-[11px] text-muted-foreground",children:s.envVar})]})]})]})}const xn={enabled:!0,autoSend:!0,autoTts:!0,continuous:!0,speechThreshold:.01,silenceDuration:1500};function un(){if(typeof window<"u"){const s=localStorage.getItem("profclaw-talk-mode-config");if(s)try{return JSON.parse(s)}catch{}}return xn}function hn(){const[s,r]=f.useState(""),[t,c]=f.useState(!1),[x,j]=f.useState(un),h=p=>{j(l=>{const o={...l,...p};return localStorage.setItem("profclaw-talk-mode-config",JSON.stringify(o)),o})},{data:N,isLoading:y,isError:d,refetch:v}=R({queryKey:["voice-status"],queryFn:async()=>{const p=await fetch(`${A}/api/voice/status`);if(!p.ok)throw new Error("Failed to fetch voice status");return p.json()},retry:1}),{data:m,isLoading:g}=R({queryKey:["voice-voices"],queryFn:async()=>{const p=await fetch(`${A}/api/voice/voices`);if(!p.ok)throw new Error("Failed to fetch voices");return p.json()},enabled:N?.tts?.provider!=null,retry:1}),a=L({mutationFn:async()=>{const p=await fetch(`${A}/api/voice/synthesize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:"Hello! This is a test of the text-to-speech system.",voice:s||void 0})});if(!p.ok)throw new Error("Synthesis request failed");return p.arrayBuffer()},onSuccess:async p=>{try{const l=new AudioContext,o=await l.decodeAudioData(p),q=l.createBufferSource();q.buffer=o,q.connect(l.destination),q.onended=()=>{c(!1),l.close()},q.start(),c(!0)}catch{u.error("Could not play audio"),c(!1)}},onError:()=>{u.error("TTS test failed"),c(!1)}}),n=()=>{t||a.mutate()},k=m?.voices??[],i=N?.stt?.provider!=null,C=N?.tts?.provider!=null;return e.jsxs("div",{className:"space-y-6",children:[e.jsx(B,{title:"Speech Recognition",description:"Status of the speech-to-text transcription service",icon:e.jsx(Dt,{className:"h-5 w-5"}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[y&&e.jsx(P,{className:"h-4 w-4 animate-spin text-muted-foreground"}),d&&e.jsx(re,{className:"h-4 w-4 text-destructive"}),N&&e.jsx(mn,{available:i}),N?.stt?.provider&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Provider: ",e.jsx("span",{className:"font-medium text-foreground",children:N.stt.provider})]})]}),e.jsx(b,{variant:"ghost",size:"icon",onClick:()=>{v()},className:"h-8 w-8",title:"Refresh status",children:e.jsx(Q,{className:w("h-4 w-4",y&&"animate-spin")})})]}),N?.stt?.model&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Model: ",e.jsx("span",{className:"font-medium text-foreground",children:N.stt.model})]}),N?.stt?.languages&&N.stt.languages.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1",children:N.stt.languages.map(p=>e.jsx(ie,{variant:"secondary",className:"text-xs",children:p},p))}),!i&&!y&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Set up a transcription provider to enable voice input. If you already set ",e.jsx("code",{className:"text-xs font-mono",children:"OPENAI_API_KEY"})," for chat, STT is automatically available."]}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:cn.map(p=>e.jsx(Js,{provider:p},p.name))}),e.jsxs(b,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>{const p=document.querySelector('[data-settings-section="ai-providers"]');p&&p.scrollIntoView({behavior:"smooth"})},children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Go to AI Providers"]})]})]})}),e.jsx(B,{title:"Text-to-Speech",description:"Configure voice synthesis for audio responses",icon:e.jsx(It,{className:"h-5 w-5"}),children:e.jsxs("div",{className:"space-y-4",children:[N?.tts?.provider&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Provider: ",e.jsx("span",{className:"font-medium text-foreground",children:N.tts.provider})]}),!C&&!y&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Set up a TTS provider to enable spoken responses."}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2",children:dn.map(p=>e.jsx(Js,{provider:p},p.name))}),e.jsxs(b,{variant:"outline",size:"sm",className:"gap-2",onClick:()=>{const p=document.querySelector('[data-settings-section="ai-providers"]');p&&p.scrollIntoView({behavior:"smooth"})},children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Go to AI Providers"]})]}),C&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Voice"}),g?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(P,{className:"h-4 w-4 animate-spin"}),"Loading voices..."]}):k.length>0?e.jsxs(sa,{value:s,onValueChange:r,children:[e.jsx(ta,{className:"w-full max-w-xs",children:e.jsx(aa,{placeholder:"Default voice"})}),e.jsxs(na,{children:[e.jsx(Bs,{value:"",children:"Default voice"}),k.map(p=>e.jsxs(Bs,{value:p.id,children:[e.jsx("span",{children:p.name}),p.language&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:p.language})]},p.id))]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No voices available. Ensure a TTS provider is configured."})]}),C&&e.jsxs("div",{className:"flex items-center gap-3 pt-2",children:[e.jsxs(b,{variant:"outline",size:"sm",onClick:n,disabled:t||a.isPending,className:"gap-2",children:[t||a.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(He,{className:"h-4 w-4"}),t?"Playing...":"Test TTS"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Plays a sample phrase using the selected voice"})]})]})}),e.jsx(B,{title:"Talk Mode",description:"Hands-free continuous conversation with voice activity detection",icon:e.jsx(Nt,{className:"h-5 w-5"}),children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:"Enable Talk Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use Cmd+Shift+V to toggle in chat"})]}),e.jsx(Ne,{checked:x.enabled,onCheckedChange:p=>h({enabled:p})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:"Auto-send"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically send transcribed speech"})]}),e.jsx(Ne,{checked:x.autoSend,onCheckedChange:p=>h({autoSend:p})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:"Auto-speak responses"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Speak AI responses aloud"})]}),e.jsx(Ne,{checked:x.autoTts,onCheckedChange:p=>h({autoTts:p})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(de,{children:"Continuous mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Resume listening after AI speaks"})]}),e.jsx(Ne,{checked:x.continuous,onCheckedChange:p=>h({continuous:p})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(de,{children:"Sensitivity"}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:x.speechThreshold})]}),e.jsx(Gs,{value:[x.speechThreshold],onValueChange:([p])=>h({speechThreshold:p}),min:.005,max:.05,step:.005,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"More sensitive"}),e.jsx("span",{children:"Less sensitive"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(de,{children:"Silence duration"}),e.jsxs("span",{className:"font-mono text-xs text-muted-foreground",children:[x.silenceDuration,"ms"]})]}),e.jsx(Gs,{value:[x.silenceDuration],onValueChange:([p])=>h({silenceDuration:p}),min:500,max:3e3,step:100,className:"w-full"}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Quick (500ms)"}),e.jsx("span",{children:"Patient (3s)"})]})]})]})})]})}async function pn(){const s=await fetch(`${A}/api/tunnels/status`);if(!s.ok)throw new Error("Failed to fetch tunnel status");return s.json()}async function Te(s,r){const t=await fetch(`${A}/api/tunnels${s}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r)});if(!t.ok){const c=await t.text();throw new Error(c||"Request failed")}}function Hs({available:s,active:r}){return s?r?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-green-500/15 text-green-600 dark:text-green-400",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-green-500 animate-pulse"}),"Active"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-muted text-muted-foreground",children:[e.jsx("span",{className:"size-1.5 rounded-full bg-muted-foreground/50"}),"Idle"]}):e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-muted text-muted-foreground",children:[e.jsx(re,{className:"size-3"}),"Not installed"]})}function Ys({url:s}){const[r,t]=f.useState(!1),c=()=>{navigator.clipboard.writeText(s).then(()=>{t(!0),setTimeout(()=>t(!1),2e3)})};return e.jsxs("div",{className:"flex items-center gap-2 mt-3 p-2.5 rounded-lg bg-muted/60 border border-border/50",children:[e.jsx(Ee,{className:"size-3.5 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-xs text-foreground truncate flex-1 font-mono",children:s}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:c,children:r?e.jsx(ue,{className:"size-3"}):e.jsx(Pe,{className:"size-3"})}),e.jsx(b,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",asChild:!0,children:e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",children:e.jsx(ae,{className:"size-3"})})})]})]})}function gn(){const s=H(),[r,t]=f.useState("3000"),[c,x]=f.useState(""),[j,h]=f.useState(""),{data:N,isLoading:y}=R({queryKey:["tunnel-status"],queryFn:pn,refetchInterval:1e4}),d=()=>s.invalidateQueries({queryKey:["tunnel-status"]}),v=L({mutationFn:()=>Te("/tailscale/serve",{port:Number(r)}),onSuccess:()=>{u.success("Tailscale Serve started"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),m=L({mutationFn:()=>Te("/tailscale/funnel",{port:Number(r)}),onSuccess:()=>{u.success("Tailscale Funnel started"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),g=L({mutationFn:()=>Te("/tailscale/stop",{}),onSuccess:()=>{u.success("Tailscale tunnel stopped"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),a=L({mutationFn:()=>Te("/cloudflare/quick",{port:Number(r)}),onSuccess:()=>{u.success("Cloudflare quick tunnel started"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),n=L({mutationFn:()=>Te("/cloudflare/named",{port:Number(r),name:c,...j?{domain:j}:{}}),onSuccess:()=>{u.success("Cloudflare named tunnel started"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),k=L({mutationFn:()=>Te("/cloudflare/stop",{}),onSuccess:()=>{u.success("Cloudflare tunnel stopped"),d()},onError:o=>u.error(`Failed: ${o.message}`)}),i=N?.tailscale,C=N?.cloudflare,p=!!(i?.serving||i?.funneling),l=v.isPending||m.isPending||g.isPending||a.isPending||n.isPending||k.isPending;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold flex items-center gap-2",children:[e.jsx(Ee,{className:"size-5"}),"Tunnels"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Expose profClaw to the internet securely via Tailscale or Cloudflare."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-sm font-medium shrink-0",children:"Local Port"}),e.jsx(O,{type:"number",value:r,onChange:o=>t(o.target.value),className:"w-28 h-8 text-sm",min:1,max:65535,disabled:l}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Port to expose (default: 3000)"})]}),y&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(P,{className:"size-4 animate-spin"}),"Checking tunnel status..."]}),e.jsx(B,{title:"Tailscale",description:"Share on your Tailnet (Serve) or make publicly accessible (Funnel)",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(qa,{className:"size-4 text-muted-foreground"}),e.jsx(Hs,{available:i?.available??!1,active:p}),i?.tailnet&&e.jsx("span",{className:"text-xs text-muted-foreground",children:i.tailnet}),i?.funneling&&e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-blue-500/15 text-blue-600 dark:text-blue-400",children:"Public funnel"})]})}),i?.url&&p&&e.jsx(Ys,{url:i.url}),e.jsxs("div",{className:w("flex flex-wrap gap-2",!i?.available&&"opacity-50 pointer-events-none"),children:[e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>v.mutate(),disabled:l||p,children:[v.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(He,{className:"size-3.5 mr-1.5"}),"Start Serve"]}),e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>m.mutate(),disabled:l||p,children:[m.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(Ee,{className:"size-3.5 mr-1.5"}),"Start Funnel"]}),p&&e.jsxs(b,{size:"sm",variant:"outline",className:"text-destructive hover:text-destructive",onClick:()=>g.mutate(),disabled:l,children:[g.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(Rs,{className:"size-3.5 mr-1.5"}),"Stop"]})]}),!i?.available&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(re,{className:"size-3.5"}),"Tailscale not detected. Install it from"," ",e.jsx("a",{href:"https://tailscale.com/download",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-2",children:"tailscale.com"})]})]})}),e.jsx(B,{title:"Cloudflare Tunnel",description:"Quick anonymous tunnel or persistent named tunnel with custom domain",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(ls,{className:"size-4 text-muted-foreground"}),e.jsx(Hs,{available:C?.available??!1,active:C?.running??!1}),C?.name&&e.jsx("span",{className:"text-xs text-muted-foreground",children:C.name})]})}),C?.url&&C.running&&e.jsx(Ys,{url:C.url}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>a.mutate(),disabled:l||C?.running,className:w(!C?.available&&"opacity-50 pointer-events-none"),children:[a.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(He,{className:"size-3.5 mr-1.5"}),"Quick Tunnel"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"One-click via trycloudflare.com"})]}),e.jsxs("div",{className:"space-y-2 pt-1 border-t border-border/50",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Named Tunnel"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(O,{placeholder:"tunnel-name",value:c,onChange:o=>x(o.target.value),className:"h-8 text-sm w-40",disabled:l||C?.running}),e.jsx(O,{placeholder:"example.com (optional)",value:j,onChange:o=>h(o.target.value),className:"h-8 text-sm w-48",disabled:l||C?.running}),e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>n.mutate(),disabled:l||C?.running||!c,className:w(!C?.available&&"opacity-50 pointer-events-none"),children:[n.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(He,{className:"size-3.5 mr-1.5"}),"Start Named"]})]})]}),C?.running&&e.jsxs(b,{size:"sm",variant:"outline",className:"text-destructive hover:text-destructive",onClick:()=>k.mutate(),disabled:l,children:[k.isPending?e.jsx(P,{className:"size-3.5 animate-spin mr-1.5"}):e.jsx(Rs,{className:"size-3.5 mr-1.5"}),"Stop Cloudflare Tunnel"]}),!C?.available&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(re,{className:"size-3.5"}),"cloudflared not detected. Install from"," ",e.jsx("a",{href:"https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/downloads/",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-2",children:"Cloudflare Docs"})]})]})})]})}function Zs({active:s,onClick:r,children:t}){return e.jsx("button",{onClick:r,className:w("px-4 py-2 text-sm font-medium border-b-2 transition-colors",s?"border-primary text-primary":"border-transparent text-muted-foreground hover:text-foreground"),children:t})}function Xs({plugin:s,onInstall:r,onUninstall:t,onToggle:c,onUpdate:x,isPending:j,hasUpdate:h}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 p-4 rounded-lg border bg-card",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"mt-0.5 shrink-0 w-8 h-8 rounded-md bg-muted flex items-center justify-center",children:e.jsx(dt,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:s.name}),s.version&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["v",s.version]}),h&&e.jsx("span",{className:"text-xs text-amber-500 font-medium",children:"update available"})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:s.description}),s.author&&e.jsxs("p",{className:"text-xs text-muted-foreground/70 mt-0.5",children:["by ",s.author]})]})]}),e.jsx("div",{className:"flex items-center gap-2 shrink-0",children:s.installed?e.jsxs(e.Fragment,{children:[h&&e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>x(s.name),disabled:j,className:"h-7 text-xs gap-1",children:[e.jsx(ca,{className:"w-3 h-3"}),"Update"]}),e.jsx("button",{onClick:()=>c(s.name),disabled:j,className:"text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",title:s.enabled?"Disable plugin":"Enable plugin",children:s.enabled?e.jsx(Ss,{className:"w-5 h-5 text-primary"}):e.jsx(mt,{className:"w-5 h-5"})}),e.jsx(b,{size:"sm",variant:"ghost",onClick:()=>t(s.name),disabled:j,className:"h-7 text-xs text-destructive hover:text-destructive gap-1",children:e.jsx(fe,{className:"w-3 h-3"})})]}):e.jsxs(b,{size:"sm",onClick:()=>r(s.name),disabled:j,className:"h-7 text-xs gap-1",children:[j?e.jsx(P,{className:"w-3 h-3 animate-spin"}):e.jsx(Ue,{className:"w-3 h-3"}),"Install"]})})]})}function us({skill:s,onInstall:r,onUninstall:t,isPending:c}){return e.jsxs("div",{className:"flex items-start justify-between gap-4 p-4 rounded-lg border bg-card",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"mt-0.5 shrink-0 w-8 h-8 rounded-md bg-muted flex items-center justify-center",children:e.jsx(es,{className:"w-4 h-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm",children:s.name}),s.stars!==void 0&&e.jsxs("span",{className:"flex items-center gap-0.5 text-xs text-amber-500",children:[e.jsx(es,{className:"w-3 h-3 fill-current"}),s.stars]})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-2",children:s.description}),e.jsxs("a",{href:`https://github.com/${s.repo}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-muted-foreground/70 hover:text-foreground mt-0.5 transition-colors",children:[e.jsx(ae,{className:"w-2.5 h-2.5"}),s.repo]})]})]}),e.jsx("div",{className:"shrink-0",children:s.installed?e.jsxs(b,{size:"sm",variant:"ghost",onClick:()=>t(s.name),disabled:c,className:"h-7 text-xs text-destructive hover:text-destructive gap-1",children:[e.jsx(fe,{className:"w-3 h-3"}),"Remove"]}):e.jsxs(b,{size:"sm",onClick:()=>r(s),disabled:c,className:"h-7 text-xs gap-1",children:[c?e.jsx(P,{className:"w-3 h-3 animate-spin"}):e.jsx(Ue,{className:"w-3 h-3"}),"Install"]})})]})}function fn(){const[s,r]=f.useState(""),[t,c]=f.useState(""),x=H(),j=l=>{r(l);const o=setTimeout(()=>c(l),400);return()=>clearTimeout(o)},{data:h=[],isLoading:N}=R({queryKey:["plugins","installed"],queryFn:async()=>{const l=await fetch(`${A}/api/plugins`);if(!l.ok)throw new Error("Failed to load plugins");return l.json()}}),{data:y=[],isFetching:d}=R({queryKey:["plugins","search",t],queryFn:async()=>{if(!t.trim())return[];const l=await fetch(`${A}/api/plugins/search?q=${encodeURIComponent(t)}`);if(!l.ok)throw new Error("Search failed");return l.json()},enabled:t.trim().length>0}),{data:v=[]}=R({queryKey:["plugins","updates"],queryFn:async()=>{const l=await fetch(`${A}/api/plugins/updates`);return l.ok?l.json():[]},staleTime:300*1e3}),m=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/plugins/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l})})).ok)throw new Error("Install failed")},onSuccess:(l,o)=>{u.success(`Installed ${o}`),x.invalidateQueries({queryKey:["plugins"]})},onError:l=>u.error(l.message)}),g=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/plugins/uninstall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l})})).ok)throw new Error("Uninstall failed")},onSuccess:(l,o)=>{u.success(`Removed ${o}`),x.invalidateQueries({queryKey:["plugins"]})},onError:l=>u.error(l.message)}),a=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/plugins/${encodeURIComponent(l)}/toggle`,{method:"PATCH"})).ok)throw new Error("Toggle failed")},onSuccess:()=>x.invalidateQueries({queryKey:["plugins","installed"]}),onError:l=>u.error(l.message)}),n=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/plugins/${encodeURIComponent(l)}/update`,{method:"POST"})).ok)throw new Error("Update failed")},onSuccess:(l,o)=>{u.success(`Updated ${o}`),x.invalidateQueries({queryKey:["plugins"]})},onError:l=>u.error(l.message)}),k=L({mutationFn:async()=>{const l=await fetch(`${A}/api/plugins/updates`);if(!l.ok)throw new Error("Check failed");return l.json()},onSuccess:l=>{x.setQueryData(["plugins","updates"],l),u.success(l.length>0?`${l.length} update(s) available`:"All plugins up to date")},onError:l=>u.error(l.message)}),i=new Set(v.map(l=>l.name)),C=m.variables??g.variables??a.variables??n.variables,p=y.filter(l=>!h.some(o=>o.name===l.name));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(O,{placeholder:"Search npm plugins...",value:s,onChange:l=>j(l.target.value),className:"pl-9"}),d&&e.jsx(P,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 animate-spin text-muted-foreground"})]}),t.trim()&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Search Results"}),p.length===0&&!d?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No results found"}):e.jsx("div",{className:"space-y-2",children:p.map(l=>e.jsx(Xs,{plugin:l,onInstall:o=>m.mutate(o),onUninstall:o=>g.mutate(o),onToggle:o=>a.mutate(o),onUpdate:o=>n.mutate(o),isPending:C===l.name,hasUpdate:i.has(l.name)},l.name))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground",children:["Installed (",h.length,")"]}),e.jsxs(b,{size:"sm",variant:"outline",onClick:()=>k.mutate(),disabled:k.isPending,className:"h-7 text-xs gap-1",children:[k.isPending?e.jsx(P,{className:"w-3 h-3 animate-spin"}):e.jsx(Q,{className:"w-3 h-3"}),"Check Updates"]})]}),N?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):h.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(dt,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No plugins installed yet"})]}):e.jsx("div",{className:"space-y-2",children:h.map(l=>e.jsx(Xs,{plugin:l,onInstall:o=>m.mutate(o),onUninstall:o=>g.mutate(o),onToggle:o=>a.mutate(o),onUpdate:o=>n.mutate(o),isPending:C===l.name,hasUpdate:i.has(l.name)},l.name))})]})]})}function jn(){const[s,r]=f.useState(""),[t,c]=f.useState(""),x=H(),j=l=>{r(l);const o=setTimeout(()=>c(l),400);return()=>clearTimeout(o)},{data:h=[],isLoading:N}=R({queryKey:["clawhub","featured"],queryFn:async()=>{const l=await fetch(`${A}/api/clawhub/featured`);if(!l.ok)throw new Error("Failed to load featured skills");return l.json()}}),{data:y=[],isLoading:d}=R({queryKey:["clawhub","installed"],queryFn:async()=>{const l=await fetch(`${A}/api/clawhub/installed`);if(!l.ok)throw new Error("Failed to load installed skills");return l.json()}}),{data:v=[],isFetching:m}=R({queryKey:["clawhub","search",t],queryFn:async()=>{if(!t.trim())return[];const l=await fetch(`${A}/api/clawhub/search?q=${encodeURIComponent(t)}`);if(!l.ok)throw new Error("Search failed");return l.json()},enabled:t.trim().length>0}),g=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/clawhub/install`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l.name,repo:l.repo,path:l.path,author:l.author})})).ok)throw new Error("Install failed")},onSuccess:(l,o)=>{u.success(`Installed ${o.name}`),x.invalidateQueries({queryKey:["clawhub"]})},onError:l=>u.error(l.message)}),a=L({mutationFn:async l=>{if(!(await fetch(`${A}/api/clawhub/uninstall`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l})})).ok)throw new Error("Uninstall failed")},onSuccess:(l,o)=>{u.success(`Removed ${o}`),x.invalidateQueries({queryKey:["clawhub"]})},onError:l=>u.error(l.message)}),n=new Set(y.map(l=>l.name)),k=g.variables?.name,i=a.variables,C=v.filter(l=>!n.has(l.name)),p=h.filter(l=>!n.has(l.name));return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(O,{placeholder:"Search ClawHub skills...",value:s,onChange:l=>j(l.target.value),className:"pl-9"}),m&&e.jsx(P,{className:"absolute right-3 top-1/2 -translate-y-1/2 w-4 h-4 animate-spin text-muted-foreground"})]}),t.trim()&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Search Results"}),C.length===0&&!m?e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No results found"}):e.jsx("div",{className:"space-y-2",children:C.map(l=>e.jsx(us,{skill:l,onInstall:o=>g.mutate(o),onUninstall:o=>a.mutate(o),isPending:k===l.name||i===l.name},l.name))})]}),!t.trim()&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground flex items-center gap-1.5",children:[e.jsx(es,{className:"w-3.5 h-3.5 text-amber-500"}),"Featured Skills"]}),N?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"All featured skills are installed."}):e.jsx("div",{className:"space-y-2",children:p.map(l=>e.jsx(us,{skill:l,onInstall:o=>g.mutate(o),onUninstall:o=>a.mutate(o),isPending:k===l.name||i===l.name},l.name))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h3",{className:"text-sm font-medium text-muted-foreground",children:["Installed (",y.length,")"]}),d?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):y.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(es,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No ClawHub skills installed yet"})]}):e.jsx("div",{className:"space-y-2",children:y.map(l=>e.jsx(us,{skill:{...l,installed:!0},onInstall:o=>g.mutate(o),onUninstall:o=>a.mutate(o),isPending:k===l.name||i===l.name},l.name))})]})]})}function Nn(){const[s,r]=f.useState("npm");return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center",children:e.jsx(Mt,{className:"w-5 h-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Marketplace"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Browse and install plugins and skills"})]})]}),e.jsx("div",{className:"border-b",children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(Zs,{active:s==="npm",onClick:()=>r("npm"),children:"npm Plugins"}),e.jsx(Zs,{active:s==="clawhub",onClick:()=>r("clawhub"),children:"ClawHub Skills"})]})}),s==="npm"?e.jsx(fn,{}):e.jsx(jn,{})]})}const et={github:e.jsx($e,{className:"h-4 w-4"}),linear:e.jsx("span",{className:"font-bold text-xs",children:"L"}),jira:e.jsx("span",{className:"font-bold text-xs",children:"J"})},bn={github:"#24292e",linear:"#5E6AD2",jira:"#0052CC"};function vn({compact:s=!1,className:r}){const t=H(),[c,x]=f.useState(null),{data:j,isLoading:h}=R({queryKey:["sync-status"],queryFn:()=>le.sync.status(),refetchInterval:3e4}),N=L({mutationFn:m=>le.sync.trigger(m),onMutate:m=>{x(m??"all")},onSettled:()=>{x(null),t.invalidateQueries({queryKey:["sync-status"]})}});if(h)return e.jsxs("div",{className:w("flex items-center gap-2 text-muted-foreground",r),children:[e.jsx(Q,{className:"h-4 w-4 animate-spin"}),e.jsx("span",{className:"text-sm",children:"Loading sync status..."})]});if(!j?.enabled)return null;const y=Object.entries(j.adapters??{}),d=j.health??{},v=j.pendingConflicts??0;return s?e.jsxs("div",{className:w("flex items-center gap-1",r),children:[y.map(([m,g])=>{const n=d[m]?.healthy??g.connected,k=c===m||c==="all";return e.jsxs($s,{children:[e.jsx(Us,{asChild:!0,children:e.jsx("button",{type:"button",onClick:()=>N.mutate(m),disabled:k,className:w("flex h-6 w-6 items-center justify-center rounded","hover:bg-muted transition-colors",n?"text-green-500":"text-red-500"),children:k?e.jsx(Q,{className:"h-3.5 w-3.5 animate-spin"}):et[m]??e.jsx(ae,{className:"h-3.5 w-3.5"})})}),e.jsx(Ks,{children:e.jsxs("div",{className:"text-xs",children:[e.jsx("div",{className:"font-medium capitalize",children:m}),e.jsx("div",{className:"text-muted-foreground",children:n?"Connected":"Disconnected"}),g.lastSync&&e.jsxs("div",{className:"text-muted-foreground",children:["Last sync: ",st(g.lastSync)]})]})})]},m)}),v>0&&e.jsxs($s,{children:[e.jsx(Us,{children:e.jsxs(ie,{variant:"destructive",className:"h-5 px-1.5 text-xs",children:[e.jsx(we,{className:"mr-1 h-3 w-3"}),v]})}),e.jsxs(Ks,{children:[v," sync conflict",v>1?"s":""," need resolution"]})]})]}):e.jsxs("div",{className:w("space-y-3",r),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-medium",children:"External Sync"}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>N.mutate(void 0),disabled:!!c,children:c?e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Syncing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"mr-2 h-3.5 w-3.5"}),"Sync All"]})})]}),e.jsx("div",{className:"space-y-2",children:y.map(([m,g])=>{const a=d[m],n=a?.healthy??g.connected,k=a?.latencyMs,i=c===m||c==="all";return e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-8 w-8 items-center justify-center rounded-md text-white",style:{backgroundColor:bn[m]??"#6B7280"},children:et[m]??e.jsx(ae,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-medium capitalize",children:m}),n?e.jsxs(ie,{variant:"outline",className:"h-5 gap-1 border-green-500 text-green-500",children:[e.jsx(ue,{className:"h-3 w-3"}),"Connected"]}):e.jsxs(ie,{variant:"outline",className:"h-5 gap-1 border-red-500 text-red-500",children:[e.jsx(ve,{className:"h-3 w-3"}),"Disconnected"]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[g.lastSync&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ss,{className:"h-3 w-3"}),st(g.lastSync)]}),k!==void 0&&e.jsxs("span",{children:[k,"ms"]}),g.errorCount>0&&e.jsxs("span",{className:"text-orange-500",children:[g.errorCount," error",g.errorCount>1?"s":""]})]})]})]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>N.mutate(m),disabled:i,children:i?e.jsx(Q,{className:"h-4 w-4 animate-spin"}):e.jsx(Q,{className:"h-4 w-4"})})]},m)})}),v>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-orange-500/50 bg-orange-500/10 p-3 text-sm",children:[e.jsx(we,{className:"h-4 w-4 text-orange-500"}),e.jsxs("span",{children:[v," sync conflict",v>1?"s":""," need manual resolution"]}),e.jsx(b,{variant:"link",size:"sm",className:"ml-auto h-auto p-0 text-orange-500",children:"Resolve"})]})]})}function st(s){const r=new Date(s),c=new Date().getTime()-r.getTime(),x=Math.floor(c/6e4),j=Math.floor(c/36e5),h=Math.floor(c/864e5);return x<1?"Just now":x<60?`${x}m ago`:j<24?`${j}h ago`:h<7?`${h}d ago`:r.toLocaleDateString("en-US",{month:"short",day:"numeric"})}const xt=f.createContext(null);function wn(){const s=f.useContext(xt);if(!s)throw new Error("useUnsavedChanges must be used within UnsavedChangesProvider");return s}function pr(){const{section:s}=vt(),[r,t]=wt(),c=yt(),{theme:x,setTheme:j}=Ct(),{resetTour:h,startTour:N}=kt(),[y,d]=f.useState(!1),[v,m]=f.useState(!1),[g,a]=f.useState(r.get("q")||""),[n,k]=f.useState({}),i=f.useRef(null),C=H(),p=s||"general",l=Object.keys(n).length>0,o=f.useCallback((M,E,$)=>{k(se=>({...se,[M]:{...se[M]||{},[E]:$}}))},[]),q=f.useCallback(()=>{k({})},[]),{data:T}=R({queryKey:["settings"],queryFn:()=>le.settings.get(),staleTime:3e4}),_=T?.settings,X=L({mutationFn:M=>le.settings.update(M),onSuccess:()=>{C.invalidateQueries({queryKey:["settings"]}),u.success("Settings updated")},onError:M=>{u.error("Failed to update settings",{description:M instanceof Error?M.message:"Unknown error"})}}),F=L({mutationFn:()=>le.settings.reset(),onSuccess:()=>{C.invalidateQueries({queryKey:["settings"]}),u.success("Settings reset to defaults")},onError:M=>{u.error("Failed to reset settings",{description:M instanceof Error?M.message:"Unknown error"})}}),K=L({mutationFn:M=>le.settings.update(M),onSuccess:()=>{C.invalidateQueries({queryKey:["settings"]}),q(),u.success("All changes saved")},onError:M=>{u.error("Failed to save changes",{description:M instanceof Error?M.message:"Unknown error"})}}),V={pendingChanges:n,setPendingChange:o,clearPendingChanges:q,hasPendingChanges:l},oe=M=>{a(M),t(M?{q:M}:{})},G=f.useMemo(()=>{if(!g)return ds;const M=g.toLowerCase();return ds.filter(E=>E.label.toLowerCase().includes(M)||E.description.toLowerCase().includes(M))},[g]),he=(M,E,$)=>{X.mutate({[M]:{[E]:!$}})},S=async()=>{d(!0);try{const M=await fetch(`${A}/api/tasks/export`);if(!M.ok)throw new Error("Export failed");const E=await M.blob(),$=window.URL.createObjectURL(E),se=document.createElement("a");se.href=$,se.download=`profclaw-tasks-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(se),se.click(),window.URL.revokeObjectURL($),document.body.removeChild(se),u.success("Tasks exported successfully")}catch{u.error("Failed to export tasks")}finally{d(!1)}},J=async M=>{const E=M.target.files?.[0];if(E){m(!0);try{const $=await E.text(),se=JSON.parse($),ce=await fetch(`${A}/api/tasks/import`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(se)}),_e=await ce.json();if(!ce.ok)throw new Error(_e.error||"Import failed");u.success(_e.message)}catch($){u.error("Failed to import tasks",{description:$ instanceof Error?$.message:"Unknown error"})}finally{m(!1),i.current&&(i.current.value="")}}},Y=()=>{h(),setTimeout(()=>N(),100)},ee=()=>{switch(p){case"general":return e.jsx(_s,{theme:x,setTheme:j,handleRestartTour:Y});case"account":return e.jsx(yn,{});case"notifications":return e.jsx(za,{settings:_,handleToggle:he,isPending:X.isPending});case"ai-providers":return e.jsx(Oa,{});case"labels":return e.jsx(Ra,{});case"devices":return e.jsx(Ua,{});case"memory":return e.jsx(Ka,{});case"skills":return e.jsx(_a,{});case"tools":return e.jsx(Ja,{});case"integrations":return e.jsx(Cn,{settings:_});case"messaging":return e.jsx(Ya,{});case"security":return e.jsx(Sn,{});case"plugins":return e.jsx(En,{});case"marketplace":return e.jsx(Nn,{});case"storage":return e.jsx(Pn,{isExporting:y,isImporting:v,handleExport:S,handleImport:J,fileInputRef:i});case"voice":return e.jsx(hn,{});case"pwa":return e.jsx(on,{});case"tunnels":return e.jsx(gn,{});case"system":return e.jsx(Tn,{settings:_,handleToggle:he,updateSettings:X,resetSettings:F});default:return e.jsx(_s,{theme:x,setTheme:j,handleRestartTour:Y})}},D=ds.find(M=>M.id===p);return e.jsx(xt.Provider,{value:V,children:e.jsxs("div",{className:"flex flex-col lg:flex-row gap-8 xl:gap-12 w-full max-w-7xl mx-auto px-4 lg:px-6 pb-20",children:[e.jsx("aside",{className:"lg:w-72 shrink-0",children:e.jsxs("div",{className:"glass rounded-2xl p-5 sticky top-24",children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx("input",{type:"text",placeholder:"Search settings...","aria-label":"Search settings",value:g,onChange:M=>oe(M.target.value),className:"w-full pl-9 pr-8 py-2 bg-muted/40 rounded-xl text-sm focus:outline-none focus:ring-2 focus:ring-primary/50"}),g&&e.jsx("button",{onClick:()=>oe(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:e.jsx(ve,{className:"h-4 w-4"})})]}),e.jsx("nav",{className:"space-y-1.5",children:G.map(M=>{const E=M.id===p;return e.jsxs("button",{onClick:()=>c(`/settings/${M.id}`),className:w("w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-left transition-all",E?"bg-[#0a0a0b] text-white shadow-lg shadow-black/20 nav-item-active z-10":"hover:bg-muted text-muted-foreground hover:text-foreground"),children:[e.jsx(M.icon,{className:w("h-4 w-4 shrink-0",E&&"text-white")}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:w("text-sm font-medium truncate",E&&"text-white"),children:M.label}),!E&&e.jsx("div",{className:"text-[10px] text-muted-foreground truncate",children:M.description})]}),E&&e.jsx(Ae,{className:"h-4 w-4 shrink-0"})]},M.id)})}),e.jsxs("div",{className:"mt-6 pt-4 border-t border-border",children:[e.jsx("span",{className:"nav-group-label mb-2 px-3",children:"Quick Actions"}),e.jsxs("button",{onClick:()=>F.mutate(),disabled:F.isPending,className:"w-full flex items-center gap-2 px-3 py-2 rounded-xl text-sm text-red-400 hover:bg-red-500/10 transition-colors",children:[F.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(tt,{className:"h-4 w-4"}),"Reset All Settings"]})]})]})}),e.jsxs("main",{className:"flex-1 min-w-0 pb-12",children:[e.jsxs("header",{className:"mb-8",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground mb-3",children:[e.jsx("span",{children:"Settings"}),e.jsx(Ae,{className:"h-3 w-3"}),e.jsx("span",{className:"text-foreground font-medium",children:D?.label})]}),e.jsx("h2",{className:"text-3xl font-bold tracking-tight",children:D?.label}),e.jsx("p",{className:"text-muted-foreground mt-1",children:D?.description})]}),e.jsx("div",{className:"space-y-8",children:ee()})]}),e.jsx(Dn,{hasPendingChanges:l,pendingChanges:n,onSave:()=>K.mutate(n),onDiscard:q,isSaving:K.isPending})]})})}function yn(){const s=H(),[r,t]=f.useState(!1),[c,x]=f.useState({name:"",bio:""}),[j,h]=f.useState(!1),[N,y]=f.useState(!1),[d,v]=f.useState(!1),[m,g]=f.useState({current:"",new:"",confirm:""}),[a,n]=f.useState({newEmail:"",currentPassword:""}),[k,i]=f.useState(!1),[C,p]=f.useState(null),{data:l,isLoading:o,error:q}=R({queryKey:["user","profile"],queryFn:async()=>{const I=await fetch(`${A}/api/users/me/profile`,{credentials:"include"});if(!I.ok){const z=await I.json().catch(()=>({error:"Failed to fetch profile"}));throw new Error(z.error||"Failed to fetch profile")}return I.json()}}),{data:T}=R({queryKey:["user","connected-accounts"],queryFn:async()=>{const I=await fetch(`${A}/api/users/me/connected-accounts`,{credentials:"include"});return I.ok?I.json():{accounts:[],hasPassword:!1,canDisconnect:!1}}}),_=L({mutationFn:async I=>{const z=await fetch(`${A}/api/users/me/profile`,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(I)});if(!z.ok)throw new Error("Failed to update profile");return z.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["user","profile"]}),s.invalidateQueries({queryKey:["auth"]}),u.success("Profile updated"),t(!1)},onError:()=>u.error("Failed to update profile")}),X=L({mutationFn:async I=>{const z=await fetch(`${A}/api/users/me/password`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(I)});if(!z.ok){const Ie=await z.json().catch(()=>({error:"Failed to change password"}));throw new Error(Ie.error||"Failed to change password")}return z.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["user","connected-accounts"]}),u.success("Password updated successfully"),y(!1),g({current:"",new:"",confirm:""})},onError:I=>u.error(I.message)}),F=L({mutationFn:async I=>{const z=await fetch(`${A}/api/users/me/email`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(I)});if(!z.ok){const Ie=await z.json().catch(()=>({error:"Failed to change email"}));throw new Error(Ie.error||"Failed to change email")}return z.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["user","profile"]}),s.invalidateQueries({queryKey:["auth"]}),u.success("Email updated successfully"),v(!1),n({newEmail:"",currentPassword:""})},onError:I=>u.error(I.message)}),K=L({mutationFn:async I=>{const z=await fetch(`${A}/api/users/me/connected-accounts/${I}`,{method:"DELETE",credentials:"include"});if(!z.ok){const Ie=await z.json().catch(()=>({error:"Failed to disconnect"}));throw new Error(Ie.error||"Failed to disconnect account")}return z.json()},onSuccess:(I,z)=>{s.invalidateQueries({queryKey:["user","profile"]}),s.invalidateQueries({queryKey:["user","connected-accounts"]}),u.success(`${z} account disconnected`),p(null)},onError:I=>{u.error(I.message),p(null)}}),V=async()=>{c.name.trim()&&(h(!0),await _.mutateAsync({name:c.name.trim(),bio:c.bio.trim()}),h(!1))},oe=()=>{x({name:l?.user?.name||"",bio:l?.user?.bio||""}),t(!0)},G=T?.hasPassword??!1,he=T?.canDisconnect??!1,[S,J]=f.useState({}),Y=I=>{J(z=>({...z,[I]:!z[I]}))},D=(I=>{if(!I)return{label:"",color:"",width:"0%",score:0};let z=0;return I.length>=8&&z++,I.length>=12&&z++,/[A-Z]/.test(I)&&/[a-z]/.test(I)&&z++,/\d/.test(I)&&z++,/[^A-Za-z0-9]/.test(I)&&z++,z<=1?{label:"Weak",color:"bg-red-500",width:"20%",score:z}:z===2?{label:"Fair",color:"bg-orange-500",width:"40%",score:z}:z===3?{label:"Good",color:"bg-amber-500",width:"60%",score:z}:z===4?{label:"Strong",color:"bg-green-500",width:"80%",score:z}:{label:"Very Strong",color:"bg-emerald-500",width:"100%",score:z}})(m.new),M=m.confirm.length>0&&m.new===m.confirm,E=m.confirm.length>0&&m.new!==m.confirm,$=()=>{if(m.new!==m.confirm){u.error("New passwords do not match");return}if(m.new.length<8){u.error("Password must be at least 8 characters");return}if(!/[a-zA-Z]/.test(m.new)||!/\d/.test(m.new)){u.error("Password must contain at least 1 letter and 1 number");return}const I={newPassword:m.new};G&&(I.currentPassword=m.current),X.mutate(I)},se=()=>{if(!a.newEmail.trim()){u.error("Please enter a new email");return}const I={newEmail:a.newEmail.trim()};G&&(I.currentPassword=a.currentPassword),F.mutate(I)},ce=I=>{if(!he){u.error("Please set a password before disconnecting your only login method"),y(!0);return}p(I),K.mutate(I)},_e=()=>{l?.user?.id&&(navigator.clipboard.writeText(l.user.id),i(!0),setTimeout(()=>i(!1),2e3),u.success("User ID copied"))},te=l?.user,os=l?.connectedAccounts||[],Ds=te?.email?.endsWith("@github.local"),Is={admin:"bg-red-500/80 text-white border-red-400/50 backdrop-blur-xl backdrop-saturate-150 shadow-lg shadow-red-500/20",user:"bg-black/60 text-white border-white/30 backdrop-blur-xl backdrop-saturate-150 shadow-lg shadow-black/20"};return q?e.jsx(W,{title:"Profile",description:"Manage your account information",children:e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[e.jsx(re,{className:"h-8 w-8 text-destructive mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Failed to load profile data"}),e.jsxs(b,{variant:"outline",size:"sm",className:"mt-4 rounded-xl",onClick:()=>s.invalidateQueries({queryKey:["user","profile"]}),children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Retry"]})]})}):e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Profile",description:"Manage your account information",children:o?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"relative",children:[te?.avatarUrl?e.jsx("img",{src:te.avatarUrl,alt:te.name,className:"h-20 w-20 rounded-full ring-4 ring-primary/20 object-cover"}):e.jsx("div",{className:"h-20 w-20 rounded-full bg-gradient-to-br from-primary to-primary/60 ring-4 ring-primary/20 flex items-center justify-center text-2xl font-bold text-white",children:te?.name?.charAt(0).toUpperCase()||"U"}),e.jsx("span",{className:w("absolute -bottom-1 -right-1 px-2 py-0.5 text-[10px] font-bold uppercase rounded-full border",Is[te?.role||"user"]||Is.user),children:te?.role||"user"})]}),e.jsx("div",{className:"flex-1 min-w-0",children:r?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Display Name"}),e.jsx("input",{type:"text",value:c.name,onChange:I=>x(z=>({...z,name:I.target.value})),className:"w-full field",placeholder:"Your name",autoFocus:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Bio"}),e.jsx("textarea",{value:c.bio,onChange:I=>x(z=>({...z,bio:I.target.value})),className:"w-full field resize-none",placeholder:"A short bio about yourself",rows:2})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{size:"sm",onClick:V,disabled:j||!c.name.trim(),className:"rounded-xl",children:j?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(ue,{className:"h-4 w-4 mr-1"}),"Save"]})}),e.jsx(b,{size:"sm",variant:"ghost",onClick:()=>t(!1),className:"rounded-xl",children:"Cancel"})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h3",{className:"text-xl font-semibold",children:te?.name||"User"}),e.jsx(b,{size:"sm",variant:"ghost",onClick:oe,className:"h-7 px-2 rounded-lg",children:e.jsx(la,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:te?.email||"No email"}),Ds&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/10 text-amber-500 rounded-md border border-amber-500/20",children:"Temporary"})]}),te?.bio&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:te.bio}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Member since"," ",te?.createdAt?new Date(te.createdAt).toLocaleDateString("en-US",{month:"long",day:"numeric",year:"numeric"}):"Unknown"]})]})})]}),Ds&&e.jsxs("div",{className:"p-3 rounded-xl bg-amber-500/10 border border-amber-500/20 flex items-start gap-3",children:[e.jsx(we,{className:"h-5 w-5 text-amber-500 flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-700 dark:text-amber-400",children:"Update your email address"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Your email is a temporary placeholder. Log out and log back in with GitHub to fetch your real email, or set a custom email below."}),e.jsx(b,{size:"sm",variant:"outline",className:"mt-2 rounded-xl h-7 text-xs",onClick:()=>v(!0),children:"Set Email Address"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 pt-4 border-t border-border",children:[e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Email Address"}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-5 px-1.5 text-xs",onClick:()=>v(!0),children:"Change"})]}),e.jsx("p",{className:"text-sm font-medium truncate",children:te?.email||"Not set"})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Active Sessions"}),e.jsxs("p",{className:"text-sm font-medium",children:[l?.activeSessions||1," device",(l?.activeSessions||1)>1?"s":""]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"Account Status"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:w("h-2 w-2 rounded-full",te?.status==="active"?"bg-green-500":"bg-amber-500")}),e.jsx("p",{className:"text-sm font-medium capitalize",children:te?.status||"Active"})]})]}),e.jsxs("div",{className:"p-3 rounded-xl bg-muted/30",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:"User ID"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-mono text-muted-foreground truncate flex-1",children:te?.id||"Unknown"}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:_e,children:k?e.jsx(ue,{className:"h-3 w-3 text-green-500"}):e.jsx(Pe,{className:"h-3 w-3"})})]})]})]})]})}),d&&e.jsx(W,{title:"Change Email",description:"Update your email address",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"New Email Address"}),e.jsx("input",{type:"email",value:a.newEmail,onChange:I=>n(z=>({...z,newEmail:I.target.value})),className:"w-full field",placeholder:"your@email.com",autoFocus:!0})]}),G&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1 block",children:"Current Password"}),e.jsx("input",{type:"password",value:a.currentPassword,onChange:I=>n(z=>({...z,currentPassword:I.target.value})),className:"w-full field",placeholder:"Enter your password to confirm"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{size:"sm",onClick:se,disabled:F.isPending||!a.newEmail.trim(),className:"rounded-xl",children:F.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):"Update Email"}),e.jsx(b,{size:"sm",variant:"ghost",onClick:()=>v(!1),className:"rounded-xl",children:"Cancel"})]})]})}),e.jsx(W,{title:"Connected Accounts",description:"Linked external accounts for authentication",children:e.jsxs("div",{className:"space-y-3",children:[os.length>0?os.map(I=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-[#24292f] flex items-center justify-center",children:e.jsx($e,{className:"h-5 w-5 text-white"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:["@",I.username,e.jsx(U,{className:"h-4 w-4 text-green-500"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Connected"," ",new Date(I.connectedAt).toLocaleDateString()]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("a",{href:`https://github.com/${I.username}`,target:"_blank",rel:"noopener noreferrer",className:"text-muted-foreground hover:text-foreground transition-colors p-2",children:e.jsx(ae,{className:"h-4 w-4"})}),e.jsx(b,{size:"sm",variant:"ghost",className:"h-8 px-2 text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>ce(I.provider),disabled:C===I.provider,children:C===I.provider?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(fe,{className:"h-4 w-4"})})]})]},I.provider)):e.jsx("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"No connected accounts"}),!he&&os.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-2 flex items-center gap-1.5",children:[e.jsx(re,{className:"h-3 w-3"}),"Set a password before disconnecting your only login method"]})]})}),e.jsxs(W,{title:"Password",description:G?"Change your account password":"Set a password to enable email login",children:[N?e.jsxs("div",{className:"space-y-4",children:[G&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Current Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S.current?"text":"password",value:m.current,onChange:I=>g(z=>({...z,current:I.target.value})),className:"w-full bg-muted/40 rounded-xl px-3 py-2.5 pr-10 text-sm focus:outline-none focus:ring-2 focus:ring-primary/20",placeholder:"Enter current password"}),e.jsx("button",{type:"button",onClick:()=>Y("current"),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:S.current?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:G?"New Password":"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S.new?"text":"password",value:m.new,onChange:I=>g(z=>({...z,new:I.target.value})),className:"w-full bg-muted/40 rounded-xl px-3 py-2.5 pr-10 text-sm focus:outline-none focus:ring-2 focus:ring-primary/20",placeholder:G?"Enter new password":"Create a password (min 8 characters)"}),e.jsx("button",{type:"button",onClick:()=>Y("new"),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:S.new?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]}),m.new&&e.jsxs("div",{className:"mt-2 space-y-1.5",children:[e.jsx("div",{className:"h-1.5 w-full bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:w("h-full rounded-full transition-all duration-300",D.color),style:{width:D.width}})}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("p",{className:w("text-xs font-medium",D.score<=1&&"text-red-500",D.score===2&&"text-orange-500",D.score===3&&"text-amber-500",D.score>=4&&"text-green-500"),children:D.label}),e.jsxs("div",{className:"flex gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{className:w(m.new.length>=8?"text-green-500":""),children:[m.new.length>=8?e.jsx(U,{className:"h-3 w-3 inline mr-0.5"}):e.jsx(ne,{className:"h-3 w-3 inline mr-0.5"}),"8+ chars"]}),e.jsxs("span",{className:w(/[a-zA-Z]/.test(m.new)&&/\d/.test(m.new)?"text-green-500":""),children:[/[a-zA-Z]/.test(m.new)&&/\d/.test(m.new)?e.jsx(U,{className:"h-3 w-3 inline mr-0.5"}):e.jsx(ne,{className:"h-3 w-3 inline mr-0.5"}),"Letter + number"]})]})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Confirm Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:S.confirm?"text":"password",value:m.confirm,onChange:I=>g(z=>({...z,confirm:I.target.value})),className:w("w-full bg-muted/40 rounded-xl px-3 py-2.5 pr-10 text-sm focus:outline-none focus:ring-2 focus:ring-primary/20 transition-colors",M&&"border-green-500/50",E&&"border-red-500/50"),placeholder:"Confirm password"}),e.jsx("button",{type:"button",onClick:()=>Y("confirm"),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:S.confirm?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]}),E&&e.jsxs("p",{className:"text-xs text-red-500 mt-1 flex items-center gap-1",children:[e.jsx(ne,{className:"h-3 w-3"}),"Passwords do not match"]}),M&&e.jsxs("p",{className:"text-xs text-green-500 mt-1 flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3"}),"Passwords match"]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs(b,{size:"sm",onClick:$,disabled:X.isPending||!m.new||!m.confirm||E||m.new.length<8||G&&!m.current,className:"rounded-xl",children:[X.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Ce,{className:"h-4 w-4 mr-2"}),G?"Update Password":"Set Password"]}),e.jsx(b,{size:"sm",variant:"ghost",onClick:()=>{y(!1),g({current:"",new:"",confirm:""}),J({})},className:"rounded-xl",children:"Cancel"})]})]}):e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("h-10 w-10 rounded-full flex items-center justify-center",G?"bg-green-500/10":"bg-amber-500/10"),children:G?e.jsx(Ce,{className:"h-5 w-5 text-green-500"}):e.jsx(ct,{className:"h-5 w-5 text-amber-500"})}),e.jsx("div",{children:G?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium",children:"Password protected"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"You can log in with email + password"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-sm font-medium text-amber-500",children:"No password set"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Set one to enable email login alongside OAuth"})]})})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>y(!0),className:"rounded-xl",children:[e.jsx(vs,{className:"h-4 w-4 mr-2"}),G?"Change":"Set Password"]})]}),G&&!N&&e.jsx("div",{className:"mt-4 pt-4 border-t border-border/50",children:e.jsxs("div",{className:"flex items-start gap-2.5 p-3 rounded-xl bg-muted/20",children:[e.jsx(ke,{className:"h-4 w-4 text-muted-foreground flex-shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsx("p",{className:"font-medium text-foreground/80",children:"Forgot your password?"}),e.jsx("p",{children:"Ask an admin to reset it, or run this on the server:"}),e.jsxs("code",{className:"block mt-1 px-2 py-1.5 bg-muted/40 rounded-lg font-mono text-[11px] break-all",children:["profclaw auth reset-password ",l?.user?.email||"your@email.com"]})]})]})})]}),e.jsx(Fn,{}),e.jsx(W,{title:"Support",description:"Get help with your account",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/30",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Contact Support"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"For account issues and questions"})]}),e.jsxs("a",{href:"mailto:support@profclaw.dev",className:"text-sm text-primary hover:underline flex items-center gap-1",children:["support@profclaw.dev",e.jsx(ae,{className:"h-3 w-3"})]})]}),e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/30",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Documentation"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Guides and API reference"})]}),e.jsxs("a",{href:"https://docs.profclaw.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline flex items-center gap-1",children:["docs.profclaw.dev",e.jsx(ae,{className:"h-3 w-3"})]})]}),te?.role==="admin"&&e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-red-500/5 border border-red-500/20",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-red-600 dark:text-red-400",children:"Admin Contact"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"System administrator"})]}),e.jsxs("a",{href:"mailto:support@profclaw.dev",className:"text-sm text-red-600 dark:text-red-400 hover:underline flex items-center gap-1",children:["support@profclaw.dev",e.jsx(ae,{className:"h-3 w-3"})]})]})]})})]})}function Cn({settings:s}){return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"AI Services",description:"Configure connections to AI providers",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Be,{label:"OpenClaw API Key",placeholder:"sk-oc-••••••••••••••••",value:s?.integrations?.openclawApiKey,category:"integrations",fieldKey:"openclawApiKey"}),e.jsx(Be,{label:"Ollama Endpoint",placeholder:"http://localhost:11434",value:s?.integrations?.ollamaEndpoint,category:"integrations",fieldKey:"ollamaEndpoint",isSecret:!1})]})}),e.jsx(kn,{settings:s}),e.jsx(W,{title:"Sync Status",description:"Real-time sync status for connected platforms",children:e.jsx(vn,{})}),e.jsx(W,{title:"Project Management",description:"Connect to issue trackers",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Be,{label:"Jira Webhook Secret",placeholder:"••••••••",value:s?.integrations?.jiraWebhookSecret,category:"integrations",fieldKey:"jiraWebhookSecret"}),e.jsx(Be,{label:"Linear Webhook Secret",placeholder:"••••••••",value:s?.integrations?.linearWebhookSecret,category:"integrations",fieldKey:"linearWebhookSecret"})]})})]})}function kn({settings:s}){const[r,t]=f.useState(!1),{data:c,isLoading:x}=R({queryKey:["github","status"],queryFn:async()=>{const d=await fetch(`${A}/api/import/github/status`,{credentials:"include"});if(!d.ok)throw new Error("Failed to fetch GitHub status");return d.json()}}),{data:j,isLoading:h,refetch:N}=R({queryKey:["github","repos"],queryFn:async()=>{const d=await fetch(`${A}/api/import/github/repos`,{credentials:"include"});if(!d.ok)throw new Error("Failed to fetch repos");return d.json()},enabled:r&&c?.connected}),y=c?.connected;return e.jsx(W,{title:"GitHub Integration",description:"Connect your GitHub account for projects, issues, and sync",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("w-10 h-10 rounded-full flex items-center justify-center",y?"bg-green-500/10":"bg-muted"),children:e.jsx($e,{className:w("h-5 w-5",y?"text-green-500":"text-muted-foreground")})}),e.jsx("div",{children:x?e.jsx(P,{className:"h-4 w-4 animate-spin"}):y?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium flex items-center gap-2",children:["@",c?.username,e.jsx(U,{className:"h-4 w-4 text-green-500"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Connected via OAuth"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium text-muted-foreground",children:"Not connected"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sign in with GitHub to enable sync"})]})})]}),y&&e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>t(!r),className:"rounded-xl",children:[r?"Hide":"View"," Repos",e.jsx(Ae,{className:w("h-4 w-4 ml-1 transition-transform",r&&"rotate-90")})]})]}),r&&y&&e.jsxs("div",{className:"rounded-2xl glass shadow-lg overflow-hidden",children:[e.jsxs("div",{className:"p-2 bg-muted/30 border-b border-white/5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:[j?.count||0," repositories"]}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>N(),disabled:h,className:"h-7 px-2",children:e.jsx(Q,{className:w("h-3.5 w-3.5",h&&"animate-spin")})})]}),e.jsx("div",{className:"max-h-[300px] overflow-y-auto",children:h?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):j?.repos?.length?e.jsxs("div",{className:"divide-y",children:[j.repos.slice(0,20).map(d=>e.jsx("div",{className:"p-3 hover:bg-muted/30 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"font-medium text-sm hover:text-primary truncate flex items-center gap-1",children:[d.nameWithOwner,e.jsx(ae,{className:"h-3 w-3 flex-shrink-0"})]}),d.isPrivate&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-500 font-medium",children:"Private"})]}),d.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 line-clamp-1",children:d.description})]}),e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:["⭐ ",d.stargazerCount]})]})},d.id)),j.repos.length>20&&e.jsxs("div",{className:"p-3 text-center text-xs text-muted-foreground",children:["+",j.repos.length-20," more repositories"]})]}):e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"No repositories found"})})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:"Alternatively, add a personal access token for CLI access:"}),e.jsx(Be,{label:"GitHub Personal Token",placeholder:"ghp_••••••••••••••••",value:s?.integrations?.githubToken,category:"integrations",fieldKey:"githubToken"})]})]})})}const ze=[{mode:"deny",label:"Deny All",description:"Block all tool execution",icon:ia,color:"red"},{mode:"sandbox",label:"Sandbox",description:"Run in isolated Docker containers",icon:lt,color:"blue"},{mode:"allowlist",label:"Allowlist",description:"Only pre-approved commands",icon:me,color:"green"},{mode:"ask",label:"Ask Always",description:"Require approval for each tool",icon:Sa,color:"amber"},{mode:"full",label:"Full Access",description:"No restrictions (dangerous!)",icon:ct,color:"red"}];function Sn(){const s=H(),[r,t]=f.useState(""),[c,x]=f.useState("command"),[j,h]=f.useState(""),{data:N,refetch:y,isRefetching:d}=R({queryKey:["tools","security"],queryFn:async()=>{const F=await fetch("http://localhost:3000/api/tools/security");if(!F.ok)throw new Error("Failed to fetch security policy");return F.json()},refetchInterval:3e4}),{data:v,refetch:m,isRefetching:g}=R({queryKey:["tools","status"],queryFn:async()=>{const F=await fetch("http://localhost:3000/api/tools/status");if(!F.ok)throw new Error("Failed to fetch status");return F.json()},refetchInterval:1e4}),a=L({mutationFn:async F=>{const K=await fetch("http://localhost:3000/api/tools/security",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)});if(!K.ok)throw new Error("Failed to update policy");return K.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["tools","security"]}),u.success("Security policy updated")},onError:F=>u.error(F instanceof Error?F.message:"Failed")}),n=L({mutationFn:async F=>{const K=await fetch("http://localhost:3000/api/tools/security/allowlist",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)});if(!K.ok)throw new Error("Failed to add to allowlist");return K.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["tools","security"]}),t(""),h(""),u.success("Added to allowlist")},onError:F=>u.error(F instanceof Error?F.message:"Failed")}),k=L({mutationFn:async F=>{const K=await fetch(`http://localhost:3000/api/tools/security/allowlist/${encodeURIComponent(F)}`,{method:"DELETE"});if(!K.ok)throw new Error("Failed to remove from allowlist");return K.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["tools","security"]}),u.success("Removed from allowlist")},onError:F=>u.error(F instanceof Error?F.message:"Failed")}),i=L({mutationFn:async F=>{const K=await fetch("http://localhost:3000/api/tools/ratelimit/config",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(F)});if(!K.ok)throw new Error("Failed to update rate limits");return K.json()},onSuccess:()=>{s.invalidateQueries({queryKey:["tools","status"]}),u.success("Rate limits updated")},onError:F=>u.error(F instanceof Error?F.message:"Failed")}),C=N?.policy,p=N?.allowlist||[],l=v?.sandbox,o=v?.pool,q=v?.rateLimit,T=(F,K)=>{const oe=ze.find(G=>G.mode===F)?.color||"gray";if(!K)return"border-border bg-muted/30 hover:bg-muted/50";switch(oe){case"red":return"border-red-500/50 bg-red-500/10 ring-2 ring-red-500/30";case"blue":return"border-blue-500/50 bg-blue-500/10 ring-2 ring-blue-500/30";case"green":return"border-green-500/50 bg-green-500/10 ring-2 ring-green-500/30";case"amber":return"border-amber-500/50 bg-amber-500/10 ring-2 ring-amber-500/30";default:return"border-primary/50 bg-primary/10 ring-2 ring-primary/30"}},_=F=>{switch(ze.find(V=>V.mode===F)?.color){case"red":return"text-red-500";case"blue":return"text-blue-500";case"green":return"text-green-500";case"amber":return"text-amber-500";default:return"text-muted-foreground"}},X=()=>{if(!r.trim()){u.error("Pattern is required");return}n.mutate({pattern:r.trim(),type:c,description:j.trim()||void 0})};return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Security Mode",description:"Control how tool commands are validated and executed",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:w("flex items-center gap-4 p-4 rounded-xl border",C?.mode==="full"||C?.mode==="deny"?"bg-red-500/5 border-red-500/20":"bg-green-500/5 border-green-500/20"),children:[e.jsx("div",{className:w("h-12 w-12 rounded-xl flex items-center justify-center",C?.mode==="full"||C?.mode==="deny"?"bg-red-500/10":"bg-green-500/10"),children:e.jsx(Ce,{className:w("h-6 w-6",C?.mode==="full"||C?.mode==="deny"?"text-red-500":"text-green-500")})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("h4",{className:"font-semibold",children:["Current Mode:"," ",ze.find(F=>F.mode===C?.mode)?.label||"Unknown"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:ze.find(F=>F.mode===C?.mode)?.description})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>y(),disabled:d,className:"rounded-xl",children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",d&&"animate-spin")}),"Refresh"]})]}),e.jsx("div",{className:"grid gap-3",children:ze.map(F=>{const K=C?.mode===F.mode,V=F.icon;return e.jsxs("button",{onClick:()=>a.mutate({mode:F.mode}),disabled:a.isPending,className:w("flex items-center gap-4 p-4 rounded-xl border transition-all text-left",T(F.mode,K)),children:[e.jsx("div",{className:w("h-10 w-10 rounded-xl flex items-center justify-center",K?"bg-white/10":"bg-muted/50"),children:e.jsx(V,{className:w("h-5 w-5",K?_(F.mode):"text-muted-foreground")})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h4",{className:"font-medium",children:F.label}),K&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-primary/20 text-primary",children:"Active"}),F.mode==="full"&&e.jsx("span",{className:"text-xs px-2 py-0.5 rounded-full bg-red-500/20 text-red-400",children:"Dangerous"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:F.description})]}),K&&e.jsx(U,{className:w("h-5 w-5",_(F.mode))})]},F.mode)})}),C?.mode==="ask"&&e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-xl bg-muted/30 border border-border",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Approval Timeout"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"How long to wait for user approval"})]}),e.jsxs("select",{value:C?.askTimeout||3e4,onChange:F=>a.mutate({askTimeout:parseInt(F.target.value)}),className:"field py-1.5",children:[e.jsx("option",{value:15e3,children:"15 seconds"}),e.jsx("option",{value:3e4,children:"30 seconds"}),e.jsx("option",{value:6e4,children:"1 minute"}),e.jsx("option",{value:12e4,children:"2 minutes"}),e.jsx("option",{value:3e5,children:"5 minutes"})]})]})]})}),e.jsx(W,{title:"Allowlist",description:"Pre-approved patterns for commands, paths, and URLs",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-xl bg-muted/30 border border-border space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium",children:"Add New Pattern"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("select",{value:c,onChange:F=>x(F.target.value),className:"field",children:[e.jsx("option",{value:"command",children:"Command"}),e.jsx("option",{value:"path",children:"File Path"}),e.jsx("option",{value:"url",children:"URL"})]}),e.jsx("input",{type:"text",placeholder:c==="command"?"git *":c==="path"?"/workspace/**":"https://api.*",value:r,onChange:F=>t(F.target.value),className:"col-span-2 field"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{type:"text",placeholder:"Description (optional)",value:j,onChange:F=>h(F.target.value),className:"flex-1 field"}),e.jsx(b,{onClick:X,disabled:n.isPending||!r.trim(),className:"rounded-xl",children:n.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Ye,{className:"h-4 w-4"})})]})]}),p.length===0?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(me,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No patterns in allowlist"}),e.jsx("p",{className:"text-xs",children:"Add patterns to allow specific commands, paths, or URLs"})]}):e.jsx("div",{className:"space-y-2",children:p.map((F,K)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl bg-muted/30 border border-border group",children:[e.jsx("div",{className:w("h-8 w-8 rounded-lg flex items-center justify-center text-xs font-bold",F.type==="command"?"bg-indigo-500/10 text-indigo-500":F.type==="path"?"bg-blue-500/10 text-blue-500":"bg-green-500/10 text-green-500"),children:F.type==="command"?e.jsx(ke,{className:"h-4 w-4"}):F.type==="path"?e.jsx(Ts,{className:"h-4 w-4"}):e.jsx(Ee,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("code",{className:"text-sm font-mono",children:F.pattern}),F.description&&e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:F.description})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground uppercase",children:F.type}),e.jsx(b,{variant:"ghost",size:"sm",onClick:()=>k.mutate(F.pattern),disabled:k.isPending,className:"opacity-0 group-hover:opacity-100 h-8 w-8 p-0 text-red-400 hover:text-red-500 hover:bg-red-500/10",children:e.jsx(Aa,{className:"h-4 w-4"})})]},K))})]})}),e.jsxs(W,{title:"Execution Status",description:"Real-time tool execution monitoring",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:w("p-4 rounded-xl border",l?.available?"bg-green-500/5 border-green-500/20":"bg-muted/30 border-border"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(lt,{className:w("h-4 w-4",l?.available?"text-green-500":"text-muted-foreground")}),e.jsx("span",{className:"text-xs font-medium",children:"Sandbox"})]}),e.jsx("p",{className:w("text-2xl font-bold",l?.available?"text-green-500":"text-muted-foreground"),children:l?.available?"Ready":"Unavailable"}),l?.available?e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[l.activeContainers,"/",l.poolSize," containers"]}):e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"Docker required"})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-blue-500/5 border border-blue-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(St,{className:"h-4 w-4 text-blue-500"}),e.jsx("span",{className:"text-xs font-medium",children:"Running"})]}),e.jsx("p",{className:"text-2xl font-bold text-blue-500",children:o?.running||0}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["of ",o?.maxConcurrent||10," max"]})]}),e.jsxs("div",{className:"p-4 rounded-xl bg-amber-500/5 border border-amber-500/20",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(ss,{className:"h-4 w-4 text-amber-500"}),e.jsx("span",{className:"text-xs font-medium",children:"Queued"})]}),e.jsx("p",{className:"text-2xl font-bold text-amber-500",children:o?.queued||0}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["of ",o?.maxQueueSize||100," max"]})]}),e.jsxs("div",{className:w("p-4 rounded-xl border",q?.enabled?"bg-indigo-500/5 border-indigo-500/20":"bg-muted/30 border-border"),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(qt,{className:"h-4 w-4 text-indigo-500"}),e.jsx("span",{className:"text-xs font-medium",children:"Rate Limit"})]}),e.jsx("p",{className:w("text-2xl font-bold",q?.enabled?"text-indigo-500":"text-muted-foreground"),children:q?.enabled?"Active":"Disabled"}),q?.enabled&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[q.globalLimit,"/min global"]})]})]}),e.jsx("div",{className:"flex justify-end mt-4",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>m(),disabled:g,className:"rounded-xl",children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",g&&"animate-spin")}),"Refresh Status"]})})]}),e.jsx(W,{title:"Rate Limits",description:"Configure execution rate limits to prevent abuse",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{label:"Enable Rate Limiting",description:"Enforce limits on tool execution frequency",checked:q?.enabled??!0,onChange:()=>i.mutate({enabled:!q?.enabled}),disabled:i.isPending}),q?.enabled&&e.jsxs("div",{className:"grid grid-cols-3 gap-4 pt-4 border-t border-border",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Per User"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:q?.userLimit||100,onChange:F=>i.mutate({userLimit:parseInt(F.target.value)||100}),className:"w-full field",min:1,max:1e3}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"/min"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Per Conversation"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:q?.conversationLimit||50,onChange:F=>i.mutate({conversationLimit:parseInt(F.target.value)||50}),className:"w-full field",min:1,max:500}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"/min"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:"Global Limit"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:q?.globalLimit||500,onChange:F=>i.mutate({globalLimit:parseInt(F.target.value)||500}),className:"w-full field",min:1,max:5e3}),e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"/min"})]})]})]})]})}),e.jsx("div",{className:"glass rounded-2xl p-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-blue-500/10 flex items-center justify-center shrink-0",children:e.jsx(rt,{className:"h-5 w-5 text-blue-500"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-semibold mb-1",children:"Security Best Practices"}),e.jsxs("ul",{className:"text-sm text-muted-foreground space-y-1",children:[e.jsxs("li",{children:["• Use ",e.jsx("strong",{children:"Sandbox"})," mode for production environments to isolate tool execution"]}),e.jsxs("li",{children:["• Configure the ",e.jsx("strong",{children:"Allowlist"})," to restrict which commands can run without approval"]}),e.jsxs("li",{children:["• Enable ",e.jsx("strong",{children:"Rate Limiting"})," to prevent abuse and runaway processes"]}),e.jsxs("li",{children:["• Avoid ",e.jsx("strong",{children:"Full Access"})," mode unless absolutely necessary for development"]}),e.jsxs("li",{children:["• Regularly review the ",e.jsx("strong",{children:"Audit Log"})," for suspicious activity"]})]})]})]})})]})}function Fn(){const[s,r]=f.useState(!1),[t,c]=f.useState([]),[x,j]=f.useState(!1),{data:h,refetch:N}=R({queryKey:["user","recovery-codes-count"],queryFn:async()=>{const i=await fetch("/api/users/me/recovery-codes/count",{credentials:"include"});return i.ok?i.json():{remainingCodes:0,hasRecoveryCodes:!1}}}),y=L({mutationFn:async()=>{const i=await fetch("/api/users/me/recovery-codes/regenerate",{method:"POST",credentials:"include"});if(!i.ok)throw new Error("Failed to regenerate codes");return i.json()},onSuccess:i=>{c(i.recoveryCodes),N()},onError:i=>u.error(i instanceof Error?i.message:"Failed to regenerate codes")}),d=()=>{y.mutate()},v=()=>{navigator.clipboard.writeText(t.join(`
4
+ `)),u.success("Recovery codes copied to clipboard")},m=(i,C,p)=>{const l=new Blob([i],{type:p}),o=URL.createObjectURL(l),q=document.createElement("a");q.href=o,q.download=C,document.body.appendChild(q),q.click(),document.body.removeChild(q),URL.revokeObjectURL(o),u.success(`Downloaded ${C}`)},g=()=>{const i=["profClaw Recovery Codes",`Generated: ${new Date().toISOString()}`,"","Keep these codes in a safe place. Each code can only be used once.","",...t.map((C,p)=>`${p+1}. ${C}`)].join(`
5
+ `);m(i,"profclaw-recovery-codes.txt","text/plain")},a=()=>{const i=JSON.stringify({app:"profClaw",type:"recovery_codes",generatedAt:new Date().toISOString(),codes:t,warning:"Each code can only be used once. Keep these secure."},null,2);m(i,"profclaw-recovery-codes.json","application/json")},n=()=>{const i=["index,code,status",...t.map((C,p)=>`${p+1},${C},unused`)].join(`
6
+ `);m(i,"profclaw-recovery-codes.csv","text/csv")},k=(i=!1)=>{if(!i&&t.length>0&&!x){u.error("Please confirm you have saved your recovery codes");return}r(!1),c([]),j(!1)};return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Recovery Codes",description:"Backup codes for account recovery if you lose access",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-xl bg-muted/30 border border-border",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-amber-500/10 flex items-center justify-center",children:e.jsx(vs,{className:"h-5 w-5 text-amber-500"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Recovery Codes"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:h?.hasRecoveryCodes?`${h.remainingCodes} codes remaining`:"No recovery codes configured"})]})]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>r(!0),className:"rounded-xl",children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Regenerate"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Recovery codes can be used to regain access to your account if you forget your password. Each code can only be used once. Keep them in a safe place."})]})}),e.jsx(ts,{open:s,onOpenChange:i=>{i||k(t.length===0)},children:e.jsxs(as,{className:"max-w-md",children:[e.jsx(ns,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-amber-500/10 flex items-center justify-center",children:e.jsx(vs,{className:"h-5 w-5 text-amber-500"})}),e.jsxs("div",{children:[e.jsx(rs,{children:"Recovery Codes"}),e.jsx(is,{children:t.length>0?"Save these codes securely":"Generate new backup codes"})]})]})}),t.length===0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/20 rounded-xl p-4",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(re,{className:"h-5 w-5 text-amber-500 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium text-amber-500",children:"Warning"}),e.jsx("p",{className:"text-muted-foreground",children:"Regenerating codes will invalidate all existing recovery codes. Make sure you save the new codes in a secure location."})]})]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{variant:"outline",onClick:()=>r(!1),className:"flex-1 rounded-xl",children:"Cancel"}),e.jsxs(b,{onClick:d,disabled:y.isPending,className:"flex-1 rounded-xl bg-amber-500 hover:bg-amber-600 text-white",children:[y.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Generate New Codes"]})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"bg-muted/40 rounded-xl p-4",children:e.jsx("div",{className:"grid grid-cols-2 gap-2 font-mono text-sm",children:t.map((i,C)=>e.jsx("div",{className:"bg-background rounded-lg px-3 py-2 text-center",children:i},C))})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{variant:"outline",onClick:v,className:"flex-1 rounded-xl",children:[e.jsx(Pe,{className:"h-4 w-4 mr-2"}),"Copy All"]}),e.jsxs(Et,{children:[e.jsx(Pt,{asChild:!0,children:e.jsxs(b,{variant:"outline",className:"rounded-xl",children:[e.jsx(Ue,{className:"h-4 w-4 mr-2"}),"Download"]})}),e.jsxs(Tt,{align:"end",className:"w-40",children:[e.jsxs(cs,{onClick:g,children:[e.jsx(Ts,{className:"h-4 w-4 mr-2"}),"Text (.txt)"]}),e.jsxs(cs,{onClick:a,children:[e.jsx(ot,{className:"h-4 w-4 mr-2"}),"JSON (.json)"]}),e.jsxs(cs,{onClick:n,children:[e.jsx(Ze,{className:"h-4 w-4 mr-2"}),"CSV (.csv)"]})]})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:x,onChange:i=>j(i.target.checked),className:"mt-1 rounded"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"I have saved these recovery codes in a secure location. I understand they will not be shown again."})]}),e.jsx(b,{onClick:()=>k(),disabled:!x,className:"w-full rounded-xl",children:"Done"})]})]})})]})}function En(){const s=H(),{data:r,isLoading:t,refetch:c,isRefetching:x}=R({queryKey:["plugins","health"],queryFn:()=>le.plugins.health(),refetchInterval:3e4}),j=L({mutationFn:({pluginId:g,enabled:a})=>le.plugins.toggle(g,a),onSuccess:()=>{s.invalidateQueries({queryKey:["plugins"]}),s.invalidateQueries({queryKey:["settings"]}),u.success("Plugin updated")},onError:g=>{u.error("Failed to update plugin",{description:g instanceof Error?g.message:"Unknown error"})}}),h=r?.plugins||[],N=g=>{switch(g){case"online":return{bg:"bg-green-500/10",text:"text-green-500",border:"border-green-500/20"};case"offline":return{bg:"bg-yellow-500/10",text:"text-yellow-500",border:"border-yellow-500/20"};case"error":return{bg:"bg-red-500/10",text:"text-red-500",border:"border-red-500/20"};case"disabled":return{bg:"bg-muted/50",text:"text-muted-foreground",border:"border-border"}}},y=g=>{switch(g){case"online":return e.jsx(U,{className:"h-4 w-4"});case"offline":return e.jsx(re,{className:"h-4 w-4"});case"error":return e.jsx(ne,{className:"h-4 w-4"});case"disabled":return e.jsx(ne,{className:"h-4 w-4"})}},d=g=>g.includes("mcp")?e.jsx(ke,{className:"h-5 w-5"}):g.includes("cli")?e.jsx(Ps,{className:"h-5 w-5"}):g.includes("ollama")?e.jsx(Fs,{className:"h-5 w-5"}):g.includes("github")?e.jsx($e,{className:"h-5 w-5"}):g.includes("webhook")?e.jsx(Ft,{className:"h-5 w-5"}):e.jsx(nt,{className:"h-5 w-5"}),v=h.filter(g=>["mcp-server","cli-access","ollama"].includes(g.id)),m=h.filter(g=>g.id.startsWith("webhook-"));return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-end mb-4",children:e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>c(),disabled:x,className:"rounded-xl",children:[e.jsx(Q,{className:w("h-4 w-4 mr-2",x&&"animate-spin")}),"Refresh Status"]})}),e.jsx(W,{title:"Core Plugins",description:"Essential profClaw extensions",children:t?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"space-y-3",children:v.map(g=>{const a=N(g.status);return e.jsxs("div",{className:w("flex items-center justify-between p-4 rounded-xl border",a.border,a.bg),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:w("h-10 w-10 rounded-xl flex items-center justify-center",a.bg,a.text),children:d(g.id)}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:g.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsxs("span",{className:w("flex items-center gap-1 text-xs",a.text),children:[y(g.status),g.status.toUpperCase()]}),g.message&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["• ",g.message]})]})]})]}),e.jsx(Ne,{checked:g.enabled,onCheckedChange:n=>j.mutate({pluginId:g.id,enabled:n}),disabled:j.isPending})]},g.id)})})}),e.jsx(W,{title:"Webhook Receivers",description:"Receive events from external services",children:t?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(P,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsx("div",{className:"grid grid-cols-2 gap-3",children:m.map(g=>{const a=N(g.status);return e.jsxs("div",{className:w("flex items-center justify-between p-3 rounded-xl border",a.border,a.bg),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:w(a.text),children:d(g.id)}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:g.name.replace(" Webhook","")}),e.jsx("span",{className:w("text-xs",a.text),children:g.status.toUpperCase()})]})]}),e.jsx(Ne,{checked:g.enabled,onCheckedChange:n=>j.mutate({pluginId:g.id,enabled:n}),disabled:j.isPending})]},g.id)})})}),e.jsxs(W,{title:"CLI & MCP Commands",description:"Control profClaw from your terminal",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden border border-border",children:[e.jsxs("div",{className:"bg-muted/80 px-4 py-2 flex items-center gap-2 border-b border-border",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"w-3 h-3 rounded-full bg-red-500/80"}),e.jsx("div",{className:"w-3 h-3 rounded-full bg-yellow-500/80"}),e.jsx("div",{className:"w-3 h-3 rounded-full bg-green-500/80"})]}),e.jsx("span",{className:"text-xs text-muted-foreground ml-2 font-mono",children:"Terminal"})]}),e.jsxs("div",{className:"bg-zinc-950 dark:bg-zinc-900 p-4 space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-zinc-500 mb-2",children:"Task Management"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ye,{command:"profclaw task list",description:"List all tasks"}),e.jsx(ye,{command:"profclaw task create",description:"Create a new task"}),e.jsx(ye,{command:"profclaw task get <id>",description:"Get task details"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-zinc-500 mb-2",children:"Configuration"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ye,{command:"profclaw config get",description:"View settings"}),e.jsx(ye,{command:"profclaw config set --key value",description:"Update settings"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] uppercase tracking-wider text-zinc-500 mb-2",children:"Server & MCP"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ye,{command:"profclaw serve --port 3000",description:"Start API server"}),e.jsx(ye,{command:"npx profclaw-mcp",description:"Run MCP server for AI agents",highlight:!0})]})]})]})]}),e.jsxs("div",{className:"mt-4 flex items-center gap-3 p-3 rounded-xl bg-primary/5 border border-primary/20",children:[e.jsx(ke,{className:"h-5 w-5 text-primary shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium",children:"Install CLI Globally"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"npm install -g @profclaw/task-manager"})]}),e.jsxs(b,{variant:"outline",size:"sm",className:"rounded-lg text-xs",onClick:()=>window.open("https://github.com/profclaw/profclaw-task-manager","_blank"),children:[e.jsx(ae,{className:"h-3 w-3 mr-1"}),"Docs"]})]})]})]})}function Pn({isExporting:s,isImporting:r,handleExport:t,handleImport:c,fileInputRef:x}){return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Database",description:"Local storage configuration",children:e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-xl bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Local SQLite"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"/data/profclaw.db"})]}),e.jsx("span",{className:"text-xs font-bold px-2 py-1 rounded-full bg-green-500/10 text-green-500",children:"CONNECTED"})]})}),e.jsx(W,{title:"Backup & Restore",description:"Export or import your data",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsxs(b,{variant:"outline",onClick:t,disabled:s,className:"flex-1 rounded-xl",children:[s?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ue,{className:"h-4 w-4 mr-2"}),"Export Tasks"]}),e.jsxs(b,{variant:"outline",onClick:()=>x.current?.click(),disabled:r,className:"flex-1 rounded-xl",children:[r?e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(Ma,{className:"h-4 w-4 mr-2"}),"Import Tasks"]}),e.jsx("input",{ref:x,type:"file",accept:".json",onChange:c,className:"hidden"})]})}),e.jsx(W,{title:"Cloud Sync",description:"Sync data across devices",children:e.jsxs(b,{variant:"outline",className:"w-full rounded-xl",disabled:!0,children:[e.jsx(ra,{className:"h-4 w-4 mr-2"}),"Connect to Turso Cloud (Coming Soon)"]})})]})}function Tn({settings:s,handleToggle:r,updateSettings:t,resetSettings:c}){return e.jsxs(e.Fragment,{children:[e.jsx(W,{title:"Execution",description:"Control how agents run tasks",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{label:"Autonomous Execution",description:"Allow agents to run tasks without manual approval",checked:s?.system?.autonomousExecution??!1,onChange:()=>r("system","autonomousExecution",s?.system?.autonomousExecution??!1),disabled:t.isPending}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Max Concurrent Tasks"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit parallel task execution"})]}),e.jsx("select",{value:s?.system?.maxConcurrentTasks??3,onChange:x=>t.mutate({system:{maxConcurrentTasks:parseInt(x.target.value)}}),className:"field py-1.5",children:[1,2,3,5,10].map(x=>e.jsx("option",{value:x,children:x},x))})]})]})}),e.jsx(W,{title:"Privacy & Telemetry",description:"Control data collection",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(Re,{label:"Usage Telemetry",description:"Help improve profClaw with anonymous usage data",checked:s?.system?.telemetry??!0,onChange:()=>r("system","telemetry",s?.system?.telemetry??!0),disabled:t.isPending}),e.jsx(Re,{label:"Debug Mode",description:"Enable verbose logging for troubleshooting",checked:s?.system?.debugMode??!1,onChange:()=>r("system","debugMode",s?.system?.debugMode??!1),disabled:t.isPending})]})}),e.jsx(W,{title:"Authentication",description:"Login and registration security options",children:e.jsx("div",{className:"space-y-4",children:e.jsx(Re,{label:"Show Forgot Password",description:"Display the 'Forgot password?' link on the login page with CLI reset instructions",checked:s?.system?.showForgotPassword??!0,onChange:()=>r("system","showForgotPassword",s?.system?.showForgotPassword??!0),disabled:t.isPending})})}),e.jsx(W,{title:"Advanced Configuration",description:"Edit settings as raw JSON",children:e.jsx(An,{settings:s,onSave:x=>t.mutate(x),isSaving:t.isPending})}),e.jsxs("div",{className:"glass rounded-2xl p-6 border border-red-500/20",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[e.jsx("div",{className:"h-10 w-10 rounded-xl bg-red-500/10 flex items-center justify-center",children:e.jsx(fe,{className:"h-5 w-5 text-red-500"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-red-400",children:"Danger Zone"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Permanent actions that cannot be undone"})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(b,{variant:"outline",className:"rounded-xl border-red-500/20 text-red-400 hover:bg-red-500/10",children:"Clear Task History"}),e.jsxs(b,{variant:"outline",className:"rounded-xl border-red-500/20 text-red-400 hover:bg-red-500/10",onClick:()=>c.mutate(),disabled:c.isPending,children:[c.isPending&&e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}),"Reset All Settings"]})]})]})]})}function W({title:s,description:r,children:t}){return e.jsxs("div",{className:"glass rounded-2xl p-6 lg:p-8",children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("h3",{className:"text-base font-bold",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]}),t]})}function Be({label:s,placeholder:r,value:t,category:c,fieldKey:x,isSecret:j=!0}){const{setPendingChange:h,pendingChanges:N}=wn(),[y,d]=f.useState(!1),[v,m]=f.useState(t||""),g=N[c]?.[x],a=g!==void 0?g:v,n=a!==(t||"");f.useEffect(()=>{m(t||"")},[t]);const k=i=>{const C=i.target.value;m(C),C!==(t||"")&&h(c,x,C)};return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block",children:s}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx("input",{type:j&&!y?"password":"text",placeholder:r,value:a,onChange:k,className:w("w-full bg-muted/40 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-1 focus:ring-primary/30",n&&"ring-1 ring-amber-500/50")}),j&&e.jsx("button",{type:"button",onClick:()=>d(!y),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:y?e.jsx(pe,{className:"h-4 w-4"}):e.jsx(ge,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"flex items-center px-2",children:e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500"})})]})]})}function Re({label:s,description:r,checked:t,onChange:c,disabled:x}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r})]}),e.jsx(Ne,{checked:t,onCheckedChange:c,disabled:x})]})}function ye({command:s,description:r,highlight:t}){const[c,x]=f.useState(!1),j=async()=>{await navigator.clipboard.writeText(s),x(!0),setTimeout(()=>x(!1),2e3)};return e.jsxs("div",{className:w("group flex items-center justify-between gap-3 px-3 py-2 rounded-lg transition-colors",t?"bg-primary/10 border border-primary/20":"hover:bg-zinc-800"),children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:"text-emerald-400 font-mono text-xs",children:"$"}),e.jsx("code",{className:"text-zinc-200 font-mono text-xs truncate",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("span",{className:"text-zinc-500 text-[10px] hidden sm:block",children:r}),e.jsx("button",{onClick:j,className:w("p-1.5 rounded-md transition-colors",c?"bg-emerald-500/20 text-emerald-400":"text-zinc-500 hover:text-zinc-300 hover:bg-zinc-700"),children:c?e.jsx(ue,{className:"h-3 w-3"}):e.jsx(Pe,{className:"h-3 w-3"})})]})]})}function An({settings:s,onSave:r,isSaving:t}){const[c,x]=f.useState(!1),[j,h]=f.useState(""),[N,y]=f.useState(null),[d,v]=f.useState(!1);f.useEffect(()=>{if(s&&c){const k=JSON.stringify(s,null,2);h(k),v(!1),y(null)}},[s,c]);const m=k=>{h(k),v(!0);try{JSON.parse(k),y(null)}catch(i){y(i instanceof Error?i.message:"Invalid JSON")}},g=()=>{try{const k=JSON.parse(j);r(k),x(!1),v(!1)}catch(k){y(k instanceof Error?k.message:"Invalid JSON")}},a=()=>{x(!1),h(""),y(null),v(!1)},n=async()=>{const k=s?JSON.stringify(s,null,2):"{}";await navigator.clipboard.writeText(k),u.success("Settings copied to clipboard")};return c?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zs,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"text-sm font-medium",children:"Editing Raw JSON"}),d&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-amber-500",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-amber-500"}),"Unsaved"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"ghost",size:"sm",onClick:a,disabled:t,className:"h-8 rounded-lg text-muted-foreground",children:[e.jsx(ve,{className:"h-3.5 w-3.5 mr-1.5"}),"Cancel"]}),e.jsxs(b,{size:"sm",onClick:g,disabled:t||!!N||!d,className:"h-8 rounded-lg",children:[t?e.jsx(P,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Es,{className:"h-3.5 w-3.5 mr-1.5"}),"Apply JSON"]})]})]}),N&&e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-red-500/10 border border-red-500/20",children:[e.jsx(we,{className:"h-4 w-4 text-red-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs",children:[e.jsx("p",{className:"font-medium text-red-400 mb-0.5",children:"Invalid JSON"}),e.jsx("p",{className:"text-red-400/80 font-mono",children:N})]})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden border border-border",children:[e.jsxs("div",{className:w("px-4 py-2 flex items-center justify-between border-b",N?"bg-red-500/10 border-red-500/20":"bg-muted/80 border-border"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/60"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-500/60"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/60"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground ml-2 font-mono",children:"settings.json"})]}),!N&&e.jsxs("span",{className:"text-[10px] text-green-400 flex items-center gap-1",children:[e.jsx(U,{className:"h-3 w-3"}),"Valid JSON"]})]}),e.jsx("textarea",{value:j,onChange:k=>m(k.target.value),className:w("w-full bg-zinc-950 dark:bg-zinc-900 p-4 font-mono text-xs text-zinc-300","min-h-100 max-h-150 resize-y","focus:outline-none focus:ring-0 border-none",N&&"text-red-400"),spellCheck:!1,placeholder:"{}"})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-amber-500/5 border border-amber-500/20",children:[e.jsx(we,{className:"h-4 w-4 text-amber-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-amber-400 mb-1",children:"Caution"}),e.jsx("p",{children:"Changes made here will completely replace your current settings. Make sure you understand the JSON structure before saving. Invalid configurations may cause unexpected behavior."})]})]})]}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ot,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Current settings as JSON"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"ghost",size:"sm",onClick:n,className:"h-8 rounded-lg",children:[e.jsx(Pe,{className:"h-3.5 w-3.5 mr-1.5"}),"Copy"]}),e.jsxs(b,{variant:"outline",size:"sm",onClick:()=>x(!0),className:"h-8 rounded-lg",children:[e.jsx(zs,{className:"h-3.5 w-3.5 mr-1.5"}),"Edit JSON"]})]})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden border border-border",children:[e.jsxs("div",{className:"bg-muted/80 px-4 py-2 flex items-center gap-2 border-b border-border",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-red-500/60"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-yellow-500/60"}),e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-green-500/60"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground ml-2 font-mono",children:"settings.json"})]}),e.jsx("pre",{className:"bg-zinc-950 dark:bg-zinc-900 p-4 overflow-x-auto max-h-75 overflow-y-auto",children:e.jsx("code",{className:"text-xs font-mono text-zinc-300 whitespace-pre",children:s?JSON.stringify(s,null,2):"Loading..."})})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-xl bg-blue-500/5 border border-blue-500/20",children:[e.jsx(re,{className:"h-4 w-4 text-blue-400 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsx("p",{className:"font-medium text-blue-400 mb-1",children:"About JSON Override"}),e.jsx("p",{children:"Edit settings directly as JSON for advanced configuration. Changes made here will override UI settings. Invalid JSON will be rejected."})]})]})]})}function Dn({hasPendingChanges:s,pendingChanges:r,onSave:t,onDiscard:c,isSaving:x}){const j=Object.values(r).reduce((h,N)=>typeof N=="object"&&N!==null?h+Object.keys(N).length:h,0);return e.jsx("div",{className:w("fixed bottom-6 left-1/2 -translate-x-1/2 z-50","transition-all duration-300 ease-out",s?"translate-y-0 opacity-100":"translate-y-20 opacity-0 pointer-events-none"),children:e.jsxs("div",{className:"flex items-center gap-4 px-6 py-3 rounded-2xl glass-heavy shadow-float border border-primary/20",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-amber-500 animate-pulse"}),e.jsxs("span",{className:"text-sm font-medium",children:[j," unsaved ",j===1?"change":"changes"]})]}),e.jsx("div",{className:"w-px h-6 bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{variant:"ghost",size:"sm",onClick:c,disabled:x,className:"text-muted-foreground hover:text-foreground",children:[e.jsx(ve,{className:"h-4 w-4 mr-1"}),"Discard"]}),e.jsxs(b,{size:"sm",onClick:t,disabled:x,className:"bg-primary text-primary-foreground hover:bg-primary/90 rounded-xl",children:[x?e.jsx(P,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(Es,{className:"h-4 w-4 mr-1"}),"Save Changes"]})]})]})})}export{pr as Settings};