@johpaz/hive 1.7.2 → 1.7.3

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 (427) hide show
  1. package/README.md +178 -36
  2. package/dist/hive.js +315124 -0
  3. package/package.json +11 -3
  4. package/packages/core/src/index.ts +0 -1
  5. package/.dockerignore +0 -9
  6. package/CONTRIBUTING.md +0 -44
  7. package/Dockerfile +0 -67
  8. package/docker-compose.yml +0 -19
  9. package/packages/cli/package.json +0 -28
  10. package/packages/cli/src/commands/agent-run.ts +0 -168
  11. package/packages/cli/src/commands/agents.ts +0 -398
  12. package/packages/cli/src/commands/chat.ts +0 -142
  13. package/packages/cli/src/commands/config.ts +0 -50
  14. package/packages/cli/src/commands/cron.ts +0 -161
  15. package/packages/cli/src/commands/dev.ts +0 -95
  16. package/packages/cli/src/commands/doctor.ts +0 -133
  17. package/packages/cli/src/commands/gateway.ts +0 -422
  18. package/packages/cli/src/commands/logs.ts +0 -57
  19. package/packages/cli/src/commands/mcp.ts +0 -175
  20. package/packages/cli/src/commands/message.ts +0 -77
  21. package/packages/cli/src/commands/onboard.ts +0 -1696
  22. package/packages/cli/src/commands/security.ts +0 -144
  23. package/packages/cli/src/commands/service.ts +0 -50
  24. package/packages/cli/src/commands/sessions.ts +0 -116
  25. package/packages/cli/src/commands/skills.ts +0 -187
  26. package/packages/cli/src/commands/update.ts +0 -25
  27. package/packages/cli/src/index.ts +0 -190
  28. package/packages/cli/src/utils/token.ts +0 -6
  29. package/packages/code-bridge/README.md +0 -78
  30. package/packages/code-bridge/package.json +0 -18
  31. package/packages/code-bridge/src/index.ts +0 -95
  32. package/packages/code-bridge/src/process-manager.ts +0 -212
  33. package/packages/code-bridge/src/schemas.ts +0 -133
  34. package/packages/core/package.json +0 -55
  35. package/packages/core/src/agent/agent-loop.ts +0 -520
  36. package/packages/core/src/agent/compaction.ts +0 -183
  37. package/packages/core/src/agent/context-compiler.ts +0 -544
  38. package/packages/core/src/agent/context-guard.ts +0 -91
  39. package/packages/core/src/agent/conversation-store.ts +0 -193
  40. package/packages/core/src/agent/curator.ts +0 -158
  41. package/packages/core/src/agent/hooks.ts +0 -166
  42. package/packages/core/src/agent/llm-client.ts +0 -503
  43. package/packages/core/src/agent/native-tools.ts +0 -31
  44. package/packages/core/src/agent/playbook-selector.ts +0 -143
  45. package/packages/core/src/agent/prompt-builder.ts +0 -167
  46. package/packages/core/src/agent/providers/index.ts +0 -186
  47. package/packages/core/src/agent/providers.ts +0 -1
  48. package/packages/core/src/agent/reflector.ts +0 -200
  49. package/packages/core/src/agent/service.ts +0 -266
  50. package/packages/core/src/agent/skill-selector.ts +0 -413
  51. package/packages/core/src/agent/stuck-loop.ts +0 -133
  52. package/packages/core/src/agent/tool-selector.ts +0 -623
  53. package/packages/core/src/agent/tracer.ts +0 -102
  54. package/packages/core/src/canvas/canvas-manager.ts +0 -319
  55. package/packages/core/src/canvas/canvas-tools.ts +0 -420
  56. package/packages/core/src/canvas/emitter.ts +0 -119
  57. package/packages/core/src/canvas/index.ts +0 -2
  58. package/packages/core/src/channels/base.ts +0 -140
  59. package/packages/core/src/channels/discord.ts +0 -260
  60. package/packages/core/src/channels/index.ts +0 -7
  61. package/packages/core/src/channels/manager.ts +0 -383
  62. package/packages/core/src/channels/slack.ts +0 -287
  63. package/packages/core/src/channels/telegram.ts +0 -552
  64. package/packages/core/src/channels/webchat.ts +0 -139
  65. package/packages/core/src/channels/whatsapp.ts +0 -375
  66. package/packages/core/src/config/index.ts +0 -12
  67. package/packages/core/src/config/loader.ts +0 -529
  68. package/packages/core/src/events/agent-bus.ts +0 -460
  69. package/packages/core/src/events/event-bus.ts +0 -169
  70. package/packages/core/src/gateway/helpers/cors.ts +0 -32
  71. package/packages/core/src/gateway/helpers/index.ts +0 -4
  72. package/packages/core/src/gateway/helpers/narration.ts +0 -60
  73. package/packages/core/src/gateway/helpers/path.ts +0 -13
  74. package/packages/core/src/gateway/helpers/redact.ts +0 -61
  75. package/packages/core/src/gateway/index.ts +0 -5
  76. package/packages/core/src/gateway/initializer.ts +0 -332
  77. package/packages/core/src/gateway/lane-queue.ts +0 -169
  78. package/packages/core/src/gateway/resolver.ts +0 -108
  79. package/packages/core/src/gateway/router.ts +0 -124
  80. package/packages/core/src/gateway/routes/agents.ts +0 -187
  81. package/packages/core/src/gateway/routes/channels.ts +0 -203
  82. package/packages/core/src/gateway/routes/chat.ts +0 -241
  83. package/packages/core/src/gateway/routes/config.ts +0 -12
  84. package/packages/core/src/gateway/routes/cron.ts +0 -42
  85. package/packages/core/src/gateway/routes/ethics.ts +0 -46
  86. package/packages/core/src/gateway/routes/mcp.ts +0 -346
  87. package/packages/core/src/gateway/routes/models.ts +0 -93
  88. package/packages/core/src/gateway/routes/projects.ts +0 -179
  89. package/packages/core/src/gateway/routes/providers.ts +0 -192
  90. package/packages/core/src/gateway/routes/setup.ts +0 -267
  91. package/packages/core/src/gateway/routes/skills.ts +0 -70
  92. package/packages/core/src/gateway/routes/system.ts +0 -165
  93. package/packages/core/src/gateway/routes/tasks.ts +0 -44
  94. package/packages/core/src/gateway/routes/tools.ts +0 -35
  95. package/packages/core/src/gateway/routes/users.ts +0 -118
  96. package/packages/core/src/gateway/routes/voice.ts +0 -73
  97. package/packages/core/src/gateway/routes/workspace.ts +0 -281
  98. package/packages/core/src/gateway/server.ts +0 -1978
  99. package/packages/core/src/gateway/session.ts +0 -95
  100. package/packages/core/src/gateway/slash-commands.ts +0 -193
  101. package/packages/core/src/heartbeat/index.ts +0 -157
  102. package/packages/core/src/mcp/hot-reload.ts +0 -213
  103. package/packages/core/src/mcp/singleton.ts +0 -21
  104. package/packages/core/src/memory/index.ts +0 -1
  105. package/packages/core/src/memory/notes.ts +0 -68
  106. package/packages/core/src/plugins/api.ts +0 -128
  107. package/packages/core/src/plugins/index.ts +0 -2
  108. package/packages/core/src/plugins/loader.ts +0 -365
  109. package/packages/core/src/resilience/circuit-breaker.ts +0 -225
  110. package/packages/core/src/security/google-chat.ts +0 -269
  111. package/packages/core/src/security/index.ts +0 -192
  112. package/packages/core/src/security/pairing.ts +0 -250
  113. package/packages/core/src/security/rate-limit.ts +0 -270
  114. package/packages/core/src/security/signal.ts +0 -321
  115. package/packages/core/src/state/store.ts +0 -312
  116. package/packages/core/src/storage/crypto.ts +0 -101
  117. package/packages/core/src/storage/onboarding.ts +0 -1609
  118. package/packages/core/src/storage/schema.ts +0 -567
  119. package/packages/core/src/storage/seed.ts +0 -608
  120. package/packages/core/src/storage/sqlite.ts +0 -363
  121. package/packages/core/src/storage/usage.ts +0 -270
  122. package/packages/core/src/tools/agents/index.ts +0 -607
  123. package/packages/core/src/tools/bridge-events.ts +0 -26
  124. package/packages/core/src/tools/canvas/index.ts +0 -281
  125. package/packages/core/src/tools/cli/index.ts +0 -142
  126. package/packages/core/src/tools/codebridge/index.ts +0 -179
  127. package/packages/core/src/tools/core/index.ts +0 -257
  128. package/packages/core/src/tools/cron/index.ts +0 -373
  129. package/packages/core/src/tools/filesystem/fs-delete.ts +0 -78
  130. package/packages/core/src/tools/filesystem/fs-edit.ts +0 -106
  131. package/packages/core/src/tools/filesystem/fs-exists.ts +0 -63
  132. package/packages/core/src/tools/filesystem/fs-glob.ts +0 -108
  133. package/packages/core/src/tools/filesystem/fs-list.ts +0 -129
  134. package/packages/core/src/tools/filesystem/fs-read.ts +0 -72
  135. package/packages/core/src/tools/filesystem/fs-write.ts +0 -67
  136. package/packages/core/src/tools/filesystem/index.ts +0 -34
  137. package/packages/core/src/tools/filesystem/workspace-guard.ts +0 -62
  138. package/packages/core/src/tools/index.ts +0 -197
  139. package/packages/core/src/tools/projects/index.ts +0 -37
  140. package/packages/core/src/tools/projects/project-create.ts +0 -94
  141. package/packages/core/src/tools/projects/project-done.ts +0 -66
  142. package/packages/core/src/tools/projects/project-fail.ts +0 -66
  143. package/packages/core/src/tools/projects/project-list.ts +0 -96
  144. package/packages/core/src/tools/projects/project-update.ts +0 -72
  145. package/packages/core/src/tools/projects/task-create.ts +0 -68
  146. package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
  147. package/packages/core/src/tools/projects/task-update.ts +0 -93
  148. package/packages/core/src/tools/search-knowledge/search-knowledge.ts +0 -155
  149. package/packages/core/src/tools/types.ts +0 -39
  150. package/packages/core/src/tools/voice/index.ts +0 -104
  151. package/packages/core/src/tools/web/browser-click.ts +0 -54
  152. package/packages/core/src/tools/web/browser-navigate.ts +0 -84
  153. package/packages/core/src/tools/web/browser-screenshot.ts +0 -54
  154. package/packages/core/src/tools/web/browser-type.ts +0 -60
  155. package/packages/core/src/tools/web/index.ts +0 -31
  156. package/packages/core/src/tools/web/web-fetch.ts +0 -78
  157. package/packages/core/src/tools/web/web-search.ts +0 -123
  158. package/packages/core/src/utils/benchmark.ts +0 -80
  159. package/packages/core/src/utils/crypto.ts +0 -73
  160. package/packages/core/src/utils/date.ts +0 -42
  161. package/packages/core/src/utils/index.ts +0 -5
  162. package/packages/core/src/utils/logger.ts +0 -389
  163. package/packages/core/src/utils/retry.ts +0 -70
  164. package/packages/core/src/utils/toon.ts +0 -356
  165. package/packages/core/src/voice/index.ts +0 -583
  166. package/packages/hive-ui/README.md +0 -52
  167. package/packages/hive-ui/components.json +0 -20
  168. package/packages/hive-ui/index.html +0 -30
  169. package/packages/hive-ui/package.json +0 -90
  170. package/packages/hive-ui/public/favicon.ico +0 -0
  171. package/packages/hive-ui/public/placeholder.svg +0 -1
  172. package/packages/hive-ui/src/App.tsx +0 -115
  173. package/packages/hive-ui/src/components/CronJobsPanel.tsx +0 -200
  174. package/packages/hive-ui/src/components/NavLink.tsx +0 -34
  175. package/packages/hive-ui/src/components/NotesPanel.tsx +0 -79
  176. package/packages/hive-ui/src/components/SystemMonitor.tsx +0 -270
  177. package/packages/hive-ui/src/components/UsageStatsPanel.tsx +0 -334
  178. package/packages/hive-ui/src/components/WelcomeDialog.tsx +0 -279
  179. package/packages/hive-ui/src/components/ui/accordion.tsx +0 -52
  180. package/packages/hive-ui/src/components/ui/alert-dialog.tsx +0 -104
  181. package/packages/hive-ui/src/components/ui/alert.tsx +0 -45
  182. package/packages/hive-ui/src/components/ui/aspect-ratio.tsx +0 -5
  183. package/packages/hive-ui/src/components/ui/avatar.tsx +0 -38
  184. package/packages/hive-ui/src/components/ui/badge.tsx +0 -29
  185. package/packages/hive-ui/src/components/ui/bee-loader.tsx +0 -68
  186. package/packages/hive-ui/src/components/ui/breadcrumb.tsx +0 -90
  187. package/packages/hive-ui/src/components/ui/button.tsx +0 -47
  188. package/packages/hive-ui/src/components/ui/calendar.tsx +0 -54
  189. package/packages/hive-ui/src/components/ui/card.tsx +0 -45
  190. package/packages/hive-ui/src/components/ui/carousel.tsx +0 -224
  191. package/packages/hive-ui/src/components/ui/chart.tsx +0 -303
  192. package/packages/hive-ui/src/components/ui/checkbox.tsx +0 -26
  193. package/packages/hive-ui/src/components/ui/collapsible.tsx +0 -9
  194. package/packages/hive-ui/src/components/ui/command.tsx +0 -133
  195. package/packages/hive-ui/src/components/ui/context-menu.tsx +0 -178
  196. package/packages/hive-ui/src/components/ui/dialog.tsx +0 -95
  197. package/packages/hive-ui/src/components/ui/drawer.tsx +0 -87
  198. package/packages/hive-ui/src/components/ui/dropdown-menu.tsx +0 -179
  199. package/packages/hive-ui/src/components/ui/form.tsx +0 -129
  200. package/packages/hive-ui/src/components/ui/hover-card.tsx +0 -27
  201. package/packages/hive-ui/src/components/ui/input-otp.tsx +0 -61
  202. package/packages/hive-ui/src/components/ui/input.tsx +0 -22
  203. package/packages/hive-ui/src/components/ui/label.tsx +0 -17
  204. package/packages/hive-ui/src/components/ui/menubar.tsx +0 -207
  205. package/packages/hive-ui/src/components/ui/navigation-menu.tsx +0 -120
  206. package/packages/hive-ui/src/components/ui/pagination.tsx +0 -80
  207. package/packages/hive-ui/src/components/ui/popover.tsx +0 -29
  208. package/packages/hive-ui/src/components/ui/progress.tsx +0 -23
  209. package/packages/hive-ui/src/components/ui/radio-group.tsx +0 -36
  210. package/packages/hive-ui/src/components/ui/resizable.tsx +0 -37
  211. package/packages/hive-ui/src/components/ui/scroll-area.tsx +0 -38
  212. package/packages/hive-ui/src/components/ui/select.tsx +0 -143
  213. package/packages/hive-ui/src/components/ui/separator.tsx +0 -20
  214. package/packages/hive-ui/src/components/ui/sheet.tsx +0 -107
  215. package/packages/hive-ui/src/components/ui/sidebar.tsx +0 -636
  216. package/packages/hive-ui/src/components/ui/skeleton.tsx +0 -7
  217. package/packages/hive-ui/src/components/ui/slider.tsx +0 -23
  218. package/packages/hive-ui/src/components/ui/sonner.tsx +0 -27
  219. package/packages/hive-ui/src/components/ui/switch.tsx +0 -27
  220. package/packages/hive-ui/src/components/ui/table.tsx +0 -72
  221. package/packages/hive-ui/src/components/ui/tabs.tsx +0 -53
  222. package/packages/hive-ui/src/components/ui/textarea.tsx +0 -21
  223. package/packages/hive-ui/src/components/ui/toast.tsx +0 -111
  224. package/packages/hive-ui/src/components/ui/toaster.tsx +0 -24
  225. package/packages/hive-ui/src/components/ui/toggle-group.tsx +0 -49
  226. package/packages/hive-ui/src/components/ui/toggle.tsx +0 -37
  227. package/packages/hive-ui/src/components/ui/tooltip.tsx +0 -28
  228. package/packages/hive-ui/src/components/ui/use-toast.ts +0 -3
  229. package/packages/hive-ui/src/hooks/use-mobile.tsx +0 -19
  230. package/packages/hive-ui/src/hooks/use-toast.ts +0 -186
  231. package/packages/hive-ui/src/hooks/useAgentConfig.ts +0 -25
  232. package/packages/hive-ui/src/hooks/useAgents.ts +0 -38
  233. package/packages/hive-ui/src/hooks/useBridge.ts +0 -38
  234. package/packages/hive-ui/src/hooks/useCanvas.ts +0 -24
  235. package/packages/hive-ui/src/hooks/useChannels.ts +0 -2
  236. package/packages/hive-ui/src/hooks/useEthics.ts +0 -51
  237. package/packages/hive-ui/src/hooks/useProviders.ts +0 -14
  238. package/packages/hive-ui/src/hooks/useTheme.ts +0 -29
  239. package/packages/hive-ui/src/hooks/useUserConfig.ts +0 -17
  240. package/packages/hive-ui/src/hooks/useWebSocket.ts +0 -12
  241. package/packages/hive-ui/src/index.css +0 -620
  242. package/packages/hive-ui/src/lib/api.ts +0 -100
  243. package/packages/hive-ui/src/lib/constants.ts +0 -6
  244. package/packages/hive-ui/src/lib/models.ts +0 -64
  245. package/packages/hive-ui/src/lib/swal.ts +0 -30
  246. package/packages/hive-ui/src/lib/utils.ts +0 -6
  247. package/packages/hive-ui/src/lib/websocket.ts +0 -7
  248. package/packages/hive-ui/src/main.tsx +0 -5
  249. package/packages/hive-ui/src/modules/agent-config/details/AgentDetailsEditor.tsx +0 -524
  250. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsConflictDetector.tsx +0 -18
  251. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsEditor.tsx +0 -19
  252. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsRulesList.tsx +0 -36
  253. package/packages/hive-ui/src/modules/agent-config/ethics/EthicsTemplateGallery.tsx +0 -361
  254. package/packages/hive-ui/src/modules/agent-config/ethics/index.ts +0 -4
  255. package/packages/hive-ui/src/modules/agent-config/index.ts +0 -6
  256. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerAdd.tsx +0 -322
  257. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerCard.tsx +0 -93
  258. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerConfig.tsx +0 -427
  259. package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerList.tsx +0 -85
  260. package/packages/hive-ui/src/modules/agent-config/mcp/MCPToolExplorer.tsx +0 -79
  261. package/packages/hive-ui/src/modules/agent-config/mcp/index.ts +0 -5
  262. package/packages/hive-ui/src/modules/agent-config/shared/ConfigEditorLayout.tsx +0 -30
  263. package/packages/hive-ui/src/modules/agent-config/shared/ConfigExporter.tsx +0 -26
  264. package/packages/hive-ui/src/modules/agent-config/shared/ConfigImporter.tsx +0 -25
  265. package/packages/hive-ui/src/modules/agent-config/shared/DiffViewer.tsx +0 -31
  266. package/packages/hive-ui/src/modules/agent-config/shared/MarkdownEditor.tsx +0 -32
  267. package/packages/hive-ui/src/modules/agent-config/shared/SaveStatusIndicator.tsx +0 -23
  268. package/packages/hive-ui/src/modules/agent-config/shared/ValidationPanel.tsx +0 -36
  269. package/packages/hive-ui/src/modules/agent-config/shared/index.ts +0 -7
  270. package/packages/hive-ui/src/modules/agent-config/skills/SkillCard.tsx +0 -81
  271. package/packages/hive-ui/src/modules/agent-config/skills/SkillConfigEditor.tsx +0 -22
  272. package/packages/hive-ui/src/modules/agent-config/skills/SkillCreator.tsx +0 -60
  273. package/packages/hive-ui/src/modules/agent-config/skills/SkillInstaller.tsx +0 -23
  274. package/packages/hive-ui/src/modules/agent-config/skills/SkillList.tsx +0 -72
  275. package/packages/hive-ui/src/modules/agent-config/skills/SkillsTab.tsx +0 -202
  276. package/packages/hive-ui/src/modules/agent-config/skills/index.ts +0 -5
  277. package/packages/hive-ui/src/modules/agent-config/tools/ToolCard.tsx +0 -27
  278. package/packages/hive-ui/src/modules/agent-config/tools/ToolConfigPanel.tsx +0 -22
  279. package/packages/hive-ui/src/modules/agent-config/tools/ToolManager.tsx +0 -266
  280. package/packages/hive-ui/src/modules/agent-config/tools/ToolPermissions.tsx +0 -287
  281. package/packages/hive-ui/src/modules/agent-config/tools/ToolRegistry.tsx +0 -84
  282. package/packages/hive-ui/src/modules/agent-config/tools/ToolUsageStats.tsx +0 -52
  283. package/packages/hive-ui/src/modules/agent-config/tools/index.ts +0 -4
  284. package/packages/hive-ui/src/modules/agent-config/user/ActiveAgentsList.tsx +0 -109
  285. package/packages/hive-ui/src/modules/agent-config/user/GlobalConfigOverview.tsx +0 -119
  286. package/packages/hive-ui/src/modules/agent-config/user/UserMemoryManager.tsx +0 -54
  287. package/packages/hive-ui/src/modules/agent-config/user/UserPreferencesForm.tsx +0 -163
  288. package/packages/hive-ui/src/modules/agent-config/user/UserProfileEditor.tsx +0 -261
  289. package/packages/hive-ui/src/modules/agent-config/user/index.ts +0 -3
  290. package/packages/hive-ui/src/modules/agents/AgentActivityLog.tsx +0 -25
  291. package/packages/hive-ui/src/modules/agents/AgentCard.tsx +0 -305
  292. package/packages/hive-ui/src/modules/agents/AgentCreateForm.tsx +0 -446
  293. package/packages/hive-ui/src/modules/agents/AgentDetail.tsx +0 -28
  294. package/packages/hive-ui/src/modules/agents/AgentInternalCard.tsx +0 -162
  295. package/packages/hive-ui/src/modules/agents/AgentList.tsx +0 -29
  296. package/packages/hive-ui/src/modules/agents/AgentStatusBadge.tsx +0 -34
  297. package/packages/hive-ui/src/modules/agents/ModelSelector.tsx +0 -151
  298. package/packages/hive-ui/src/modules/bridge/BridgeLogViewer.tsx +0 -61
  299. package/packages/hive-ui/src/modules/bridge/BridgeProcessList.tsx +0 -77
  300. package/packages/hive-ui/src/modules/bridge/BridgeStatus.tsx +0 -23
  301. package/packages/hive-ui/src/modules/bridge/BridgeTerminal.tsx +0 -7
  302. package/packages/hive-ui/src/modules/canvas/CanvasButton.tsx +0 -3
  303. package/packages/hive-ui/src/modules/canvas/CanvasChart.tsx +0 -3
  304. package/packages/hive-ui/src/modules/canvas/CanvasComponentMap.tsx +0 -605
  305. package/packages/hive-ui/src/modules/canvas/CanvasContainer.tsx +0 -360
  306. package/packages/hive-ui/src/modules/canvas/CanvasForm.tsx +0 -3
  307. package/packages/hive-ui/src/modules/canvas/CanvasMarkdown.tsx +0 -3
  308. package/packages/hive-ui/src/modules/canvas/CanvasTable.tsx +0 -3
  309. package/packages/hive-ui/src/modules/canvas/ComponentRenderer.tsx +0 -30
  310. package/packages/hive-ui/src/modules/canvas/DynamicRenderer.tsx +0 -3
  311. package/packages/hive-ui/src/modules/channels/available/AvailableChannelsGrid.tsx +0 -89
  312. package/packages/hive-ui/src/modules/channels/available/ChannelAuthForm.tsx +0 -33
  313. package/packages/hive-ui/src/modules/channels/available/ChannelSetupWizard.tsx +0 -48
  314. package/packages/hive-ui/src/modules/channels/available/ChannelTestConnection.tsx +0 -37
  315. package/packages/hive-ui/src/modules/channels/available/ChannelTypeCard.tsx +0 -30
  316. package/packages/hive-ui/src/modules/channels/available/ChannelWebhookConfig.tsx +0 -30
  317. package/packages/hive-ui/src/modules/channels/available/index.ts +0 -6
  318. package/packages/hive-ui/src/modules/channels/connected/ChannelCard.tsx +0 -95
  319. package/packages/hive-ui/src/modules/channels/connected/ChannelConfigPanel.tsx +0 -260
  320. package/packages/hive-ui/src/modules/channels/connected/ChannelDisconnectButton.tsx +0 -21
  321. package/packages/hive-ui/src/modules/channels/connected/ChannelLogsViewer.tsx +0 -42
  322. package/packages/hive-ui/src/modules/channels/connected/ChannelQRCode.tsx +0 -32
  323. package/packages/hive-ui/src/modules/channels/connected/ChannelReconnectButton.tsx +0 -16
  324. package/packages/hive-ui/src/modules/channels/connected/ChannelStatusBadge.tsx +0 -26
  325. package/packages/hive-ui/src/modules/channels/connected/ConnectedChannelsList.tsx +0 -40
  326. package/packages/hive-ui/src/modules/channels/connected/index.ts +0 -8
  327. package/packages/hive-ui/src/modules/channels/shared/ChannelCard.tsx +0 -84
  328. package/packages/hive-ui/src/modules/channels/shared/ChannelConfigDialog.tsx +0 -279
  329. package/packages/hive-ui/src/modules/channels/shared/ChannelIcon.tsx +0 -40
  330. package/packages/hive-ui/src/modules/channels/shared/ChannelStats.tsx +0 -37
  331. package/packages/hive-ui/src/modules/channels/shared/ChannelTypeBadge.tsx +0 -23
  332. package/packages/hive-ui/src/modules/channels/shared/ConnectionHealthIndicator.tsx +0 -20
  333. package/packages/hive-ui/src/modules/channels/shared/MessagePreview.tsx +0 -19
  334. package/packages/hive-ui/src/modules/channels/shared/index.ts +0 -5
  335. package/packages/hive-ui/src/modules/chat/ChatContainer.tsx +0 -268
  336. package/packages/hive-ui/src/modules/chat/ChatHistory.tsx +0 -101
  337. package/packages/hive-ui/src/modules/chat/ChatInput.tsx +0 -108
  338. package/packages/hive-ui/src/modules/chat/ChatMessage.tsx +0 -137
  339. package/packages/hive-ui/src/modules/chat/ThinkingIndicator.tsx +0 -10
  340. package/packages/hive-ui/src/modules/layout/AppLayout.tsx +0 -45
  341. package/packages/hive-ui/src/modules/layout/ConnectionStatus.tsx +0 -19
  342. package/packages/hive-ui/src/modules/layout/Header.tsx +0 -20
  343. package/packages/hive-ui/src/modules/layout/HiveSidebar.tsx +0 -173
  344. package/packages/hive-ui/src/modules/layout/ThemeToggle.tsx +0 -18
  345. package/packages/hive-ui/src/modules/providers/ProviderCard.tsx +0 -319
  346. package/packages/hive-ui/src/modules/providers/ProviderConfigForm.tsx +0 -146
  347. package/packages/hive-ui/src/modules/providers/ProviderFailoverConfig.tsx +0 -110
  348. package/packages/hive-ui/src/modules/providers/ProviderList.tsx +0 -33
  349. package/packages/hive-ui/src/modules/providers/ProviderStatusIndicator.tsx +0 -23
  350. package/packages/hive-ui/src/modules/providers/configs/ProviderAPIKeyManager.tsx +0 -39
  351. package/packages/hive-ui/src/modules/providers/configs/ProviderEndpointConfig.tsx +0 -27
  352. package/packages/hive-ui/src/modules/providers/configs/ProviderRateLimits.tsx +0 -37
  353. package/packages/hive-ui/src/modules/providers/configs/ProviderRetryPolicy.tsx +0 -46
  354. package/packages/hive-ui/src/modules/providers/configs/index.ts +0 -4
  355. package/packages/hive-ui/src/modules/providers/index.ts +0 -5
  356. package/packages/hive-ui/src/modules/providers/models/ModelBenchmarkBadge.tsx +0 -21
  357. package/packages/hive-ui/src/modules/providers/models/ModelCapabilities.tsx +0 -44
  358. package/packages/hive-ui/src/modules/providers/models/ModelCard.tsx +0 -36
  359. package/packages/hive-ui/src/modules/providers/models/ModelComparisonTable.tsx +0 -47
  360. package/packages/hive-ui/src/modules/providers/models/ModelList.tsx +0 -51
  361. package/packages/hive-ui/src/modules/providers/models/ModelPricingInfo.tsx +0 -17
  362. package/packages/hive-ui/src/modules/providers/models/ModelSelector.tsx +0 -32
  363. package/packages/hive-ui/src/modules/providers/models/index.ts +0 -7
  364. package/packages/hive-ui/src/pages/AgentDetailPage.tsx +0 -74
  365. package/packages/hive-ui/src/pages/AgentNewPage.tsx +0 -5
  366. package/packages/hive-ui/src/pages/AgentsPage.tsx +0 -147
  367. package/packages/hive-ui/src/pages/BridgePage.tsx +0 -83
  368. package/packages/hive-ui/src/pages/CanvasPage.tsx +0 -32
  369. package/packages/hive-ui/src/pages/ChannelsPage.tsx +0 -176
  370. package/packages/hive-ui/src/pages/DashboardPage.tsx +0 -321
  371. package/packages/hive-ui/src/pages/Index.tsx +0 -14
  372. package/packages/hive-ui/src/pages/LogsPage.tsx +0 -252
  373. package/packages/hive-ui/src/pages/NotFound.tsx +0 -24
  374. package/packages/hive-ui/src/pages/ProjectsPage.tsx +0 -241
  375. package/packages/hive-ui/src/pages/ProvidersPage.tsx +0 -111
  376. package/packages/hive-ui/src/pages/SettingsPage.tsx +0 -147
  377. package/packages/hive-ui/src/pages/SetupPage.tsx +0 -1177
  378. package/packages/hive-ui/src/pages/WebChatPage.tsx +0 -15
  379. package/packages/hive-ui/src/stores/agentConfigStore.ts +0 -32
  380. package/packages/hive-ui/src/stores/agentStore.ts +0 -5
  381. package/packages/hive-ui/src/stores/bridgeStore.ts +0 -237
  382. package/packages/hive-ui/src/stores/canvasStore.ts +0 -250
  383. package/packages/hive-ui/src/stores/channelStore.ts +0 -5
  384. package/packages/hive-ui/src/stores/chatStore.ts +0 -42
  385. package/packages/hive-ui/src/stores/ethicsStore.ts +0 -141
  386. package/packages/hive-ui/src/stores/mcpStore.ts +0 -5
  387. package/packages/hive-ui/src/stores/modelStore.ts +0 -2
  388. package/packages/hive-ui/src/stores/projectsStore.ts +0 -141
  389. package/packages/hive-ui/src/stores/providerStore.ts +0 -2
  390. package/packages/hive-ui/src/stores/skillStore.ts +0 -5
  391. package/packages/hive-ui/src/stores/toolStore.ts +0 -5
  392. package/packages/hive-ui/src/stores/useGlobalConfigStore.ts +0 -937
  393. package/packages/hive-ui/src/stores/useLoaderStore.ts +0 -21
  394. package/packages/hive-ui/src/stores/useNotesAndCronsStore.ts +0 -144
  395. package/packages/hive-ui/src/stores/useWebSocketStore.ts +0 -152
  396. package/packages/hive-ui/src/stores/useWelcomeStore.ts +0 -37
  397. package/packages/hive-ui/src/stores/userConfigStore.ts +0 -23
  398. package/packages/hive-ui/src/stores/userStore.ts +0 -82
  399. package/packages/hive-ui/src/test/setup.ts +0 -15
  400. package/packages/hive-ui/src/types/agent-config.ts +0 -33
  401. package/packages/hive-ui/src/types/agent.ts +0 -65
  402. package/packages/hive-ui/src/types/bridge.ts +0 -27
  403. package/packages/hive-ui/src/types/canvas.ts +0 -76
  404. package/packages/hive-ui/src/types/channels.ts +0 -109
  405. package/packages/hive-ui/src/types/chat.ts +0 -25
  406. package/packages/hive-ui/src/types/connections.ts +0 -17
  407. package/packages/hive-ui/src/types/ethics.ts +0 -41
  408. package/packages/hive-ui/src/types/index.ts +0 -15
  409. package/packages/hive-ui/src/types/mcp.ts +0 -36
  410. package/packages/hive-ui/src/types/notes-crons.ts +0 -31
  411. package/packages/hive-ui/src/types/providers.ts +0 -145
  412. package/packages/hive-ui/src/types/skill.ts +0 -12
  413. package/packages/hive-ui/src/types/tool.ts +0 -44
  414. package/packages/hive-ui/src/types/user.ts +0 -26
  415. package/packages/hive-ui/src/types/websocket.ts +0 -14
  416. package/packages/hive-ui/src/vite-env.d.ts +0 -1
  417. package/packages/mcp/package.json +0 -26
  418. package/packages/mcp/src/config.ts +0 -13
  419. package/packages/mcp/src/index.ts +0 -1
  420. package/packages/mcp/src/logger.ts +0 -42
  421. package/packages/mcp/src/manager.ts +0 -439
  422. package/packages/mcp/src/transports/index.ts +0 -67
  423. package/packages/mcp/src/transports/sse.ts +0 -241
  424. package/packages/mcp/src/transports/websocket.ts +0 -159
  425. package/packages/skills/package.json +0 -21
  426. package/packages/skills/src/index.ts +0 -1
  427. package/packages/skills/src/loader.ts +0 -346
@@ -1,363 +0,0 @@
1
- import { Database } from "bun:sqlite";
2
- import { logger } from "../utils/logger.ts";
3
- import * as path from "node:path";
4
- import { existsSync, mkdirSync } from "node:fs";
5
- import { getHiveDir } from "../config/loader.ts";
6
- import { SCHEMA, PROJECTS_SCHEMA, CONTEXT_ENGINE_SCHEMA } from "./schema.ts";
7
-
8
- function getDbPath(): string {
9
- return path.join(getHiveDir(), "data", "hive.db");
10
- }
11
-
12
- export function getDbPathLazy(): string {
13
- return getDbPath();
14
- }
15
-
16
- let _db: Database | null = null;
17
-
18
- export interface NoteRow {
19
- id: string;
20
- title: string;
21
- content: string;
22
- createdAt: string;
23
- updatedAt: string;
24
- }
25
-
26
- export function getDb(): Database {
27
- if (!_db) throw new Error("DB no inicializada. Llama initializeDatabase() primero.");
28
- return _db;
29
- }
30
-
31
-
32
- export function initializeDatabase(): Database {
33
- const hiveDir = getHiveDir();
34
- const dir = path.join(hiveDir, "data");
35
- if (!existsSync(dir)) {
36
- mkdirSync(dir, { recursive: true });
37
- }
38
-
39
- const dbPath = getDbPath();
40
- const dbFileExists = existsSync(dbPath);
41
-
42
- _db = new Database(dbPath, { create: true });
43
-
44
- // Use type assertion to avoid deprecated signature with bindings
45
- (_db as any).exec(SCHEMA);
46
- (_db as any).exec(PROJECTS_SCHEMA);
47
- (_db as any).exec(CONTEXT_ENGINE_SCHEMA);
48
-
49
- ensureSchemaSync();
50
-
51
- return _db;
52
- }
53
-
54
- function ensureColumnExists(tableName: string, columnName: string, columnDefinition: string): void {
55
- if (!_db) return;
56
- try {
57
- const info = _db.query(`PRAGMA table_info(${tableName})`).all() as any[];
58
- const exists = info.some((col: any) => col.name === columnName);
59
-
60
- if (!exists) {
61
- logger.info(`🛠️ Añadiendo columna faltante '${columnName}' a la tabla '${tableName}'`);
62
- _db.exec(`ALTER TABLE ${tableName} ADD COLUMN ${columnName} ${columnDefinition}`);
63
- }
64
- } catch (err) {
65
- logger.warn(`⚠️ No se pudo verificar/añadir la columna '${columnName}' en '${tableName}':`, { error: (err as Error).message });
66
- }
67
- }
68
-
69
- function ensureSchemaSync(): void {
70
- if (!_db) return;
71
-
72
- // Sync mcp_servers
73
- ensureColumnExists("mcp_servers", "tools_count", "INTEGER DEFAULT 0");
74
- ensureColumnExists("mcp_servers", "status", "TEXT NOT NULL DEFAULT 'disconnected'");
75
- ensureColumnExists("mcp_servers", "env_encrypted", "TEXT");
76
- ensureColumnExists("mcp_servers", "env_iv", "TEXT");
77
- ensureColumnExists("mcp_servers", "headers_encrypted", "TEXT");
78
- ensureColumnExists("mcp_servers", "headers_iv", "TEXT");
79
-
80
- // Sync providers
81
- ensureColumnExists("providers", "api_key_encrypted", "TEXT");
82
- ensureColumnExists("providers", "api_key_iv", "TEXT");
83
- ensureColumnExists("providers", "headers_encrypted", "TEXT");
84
- ensureColumnExists("providers", "headers_iv", "TEXT");
85
- ensureColumnExists("providers", "num_ctx", "INTEGER");
86
- ensureColumnExists("providers", "num_gpu", "INTEGER DEFAULT -1");
87
-
88
- // Sync agents (new Context Engine columns — safe no-ops if already present)
89
- ensureColumnExists("agents", "headers_encrypted", "TEXT");
90
- ensureColumnExists("agents", "headers_iv", "TEXT");
91
- ensureColumnExists("agents", "system_prompt", "TEXT");
92
- ensureColumnExists("agents", "role", "TEXT NOT NULL DEFAULT 'coordinator'");
93
- ensureColumnExists("agents", "tools_json", "TEXT");
94
- ensureColumnExists("agents", "skills_json", "TEXT");
95
- ensureColumnExists("agents", "parent_id", "TEXT");
96
- ensureColumnExists("agents", "max_iterations", "INTEGER NOT NULL DEFAULT 10");
97
- ensureColumnExists("agents", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
98
- ensureColumnExists("agents", "workspace", "TEXT");
99
-
100
- // Sync tasks (new Context Engine columns)
101
- ensureColumnExists("tasks", "priority", "INTEGER NOT NULL DEFAULT 0");
102
- ensureColumnExists("tasks", "depends_on", "TEXT");
103
- ensureColumnExists("tasks", "error", "TEXT");
104
- ensureColumnExists("tasks", "completed_at", "INTEGER");
105
-
106
- // Sync tools (new columns)
107
- ensureColumnExists("tools", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
108
- ensureColumnExists("tools", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
109
-
110
- // Sync skills (new columns)
111
- ensureColumnExists("skills", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
112
- ensureColumnExists("skills", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
113
-
114
- // Sync cron_jobs
115
- ensureColumnExists("cron_jobs", "max_runs", "INTEGER");
116
- ensureColumnExists("cron_jobs", "run_count", "INTEGER NOT NULL DEFAULT 0");
117
- ensureColumnExists("cron_jobs", "expires_at", "INTEGER");
118
-
119
- // Context Engine tables — ensure created_at/updated_at columns exist
120
- ensureColumnExists("conversations", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
121
- ensureColumnExists("conversations", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
122
- ensureColumnExists("summaries", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
123
- ensureColumnExists("summaries", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
124
- ensureColumnExists("scratchpad", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
125
- ensureColumnExists("scratchpad", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
126
- ensureColumnExists("traces", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
127
- ensureColumnExists("reflections", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
128
- ensureColumnExists("playbook", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
129
- ensureColumnExists("playbook", "updated_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
130
- ensureColumnExists("tool_cache", "created_at", "INTEGER NOT NULL DEFAULT (unixepoch())");
131
-
132
- // hive_capabilities: create if not exists (applied via CONTEXT_ENGINE_SCHEMA IF NOT EXISTS)
133
- // No column migrations needed — table is seeded fresh each startup via INSERT OR REPLACE
134
-
135
- // Data migrations: fix known bad base_url values from old seeds
136
- if (_db) {
137
- _db.query(`UPDATE providers SET base_url = 'https://api.groq.com/openai/v1' WHERE id = 'groq' AND base_url = 'https://api.groq.com/v1'`).run();
138
- _db.query(`UPDATE providers SET base_url = 'https://api.openai.com/v1' WHERE id = 'openai' AND base_url = 'https://api.openai.com'`).run();
139
- }
140
- }
141
-
142
-
143
- export class DatabaseService {
144
- private log = logger.child("sqlite");
145
-
146
- private get db(): Database {
147
- if (!_db) {
148
- initializeDatabase();
149
- }
150
- return _db!;
151
- }
152
-
153
- public close(): void {
154
- if (_db) {
155
- _db.close();
156
- _db = null;
157
- }
158
- }
159
-
160
- public writeNote(title: string, content: string): NoteRow {
161
- const stmt = this.db.query(`
162
- INSERT INTO notes (id, title, content)
163
- VALUES ($id, $title, $content)
164
- ON CONFLICT(title) DO UPDATE SET
165
- content = excluded.content,
166
- updatedAt = CURRENT_TIMESTAMP
167
- RETURNING *
168
- `);
169
- return stmt.get({
170
- $id: crypto.randomUUID(),
171
- $title: title,
172
- $content: content
173
- }) as NoteRow;
174
- }
175
-
176
- public readNote(title: string): NoteRow | null {
177
- const stmt = this.db.query(`SELECT * FROM notes WHERE title = $title`);
178
- return stmt.get({ $title: title }) as NoteRow | null;
179
- }
180
-
181
- public listNotes(): NoteRow[] {
182
- const stmt = this.db.query(`SELECT * FROM notes ORDER BY updatedAt DESC`);
183
- return stmt.all() as NoteRow[];
184
- }
185
-
186
- public searchNotes(queryText: string): NoteRow[] {
187
- const stmt = this.db.query(`
188
- SELECT * FROM notes
189
- WHERE title LIKE $query OR content LIKE $query
190
- ORDER BY updatedAt DESC
191
- `);
192
- return stmt.all({ $query: `%${queryText}%` }) as NoteRow[];
193
- }
194
-
195
- public deleteNote(title: string): boolean {
196
- const stmt = this.db.query(`DELETE FROM notes WHERE title = $title`);
197
- const result = stmt.run({ $title: title });
198
- return result.changes > 0;
199
- }
200
-
201
- public updateMCPServer(id: string, updates: any): void {
202
- const fields = [];
203
- const values: any = { $id: id };
204
-
205
- if (updates.enabled !== undefined) {
206
- fields.push("enabled = $enabled");
207
- values.$enabled = updates.enabled ? 1 : 0;
208
- }
209
- if (updates.active !== undefined) {
210
- fields.push("active = $active");
211
- values.$active = updates.active ? 1 : 0;
212
- }
213
- if (updates.status !== undefined) {
214
- fields.push("status = $status");
215
- values.$status = updates.status;
216
- }
217
- if (updates.tools_count !== undefined) {
218
- fields.push("tools_count = $tools_count");
219
- values.$tools_count = updates.tools_count;
220
- }
221
- if (updates.transport !== undefined) {
222
- fields.push("transport = $transport");
223
- values.$transport = updates.transport;
224
- }
225
- if (updates.command !== undefined) {
226
- fields.push("command = $command");
227
- values.$command = updates.command;
228
- }
229
- if (updates.args !== undefined) {
230
- fields.push("args = $args");
231
- values.$args = JSON.stringify(updates.args);
232
- }
233
- if (updates.url !== undefined) {
234
- fields.push("url = $url");
235
- values.$url = updates.url;
236
- }
237
- if (updates.env_encrypted !== undefined) {
238
- fields.push("env_encrypted = $env_encrypted");
239
- values.$env_encrypted = updates.env_encrypted;
240
- }
241
- if (updates.env_iv !== undefined) {
242
- fields.push("env_iv = $env_iv");
243
- values.$env_iv = updates.env_iv;
244
- }
245
- if (updates.headers_encrypted !== undefined) {
246
- fields.push("headers_encrypted = $headers_encrypted");
247
- values.$headers_encrypted = updates.headers_encrypted;
248
- }
249
- if (updates.headers_iv !== undefined) {
250
- fields.push("headers_iv = $headers_iv");
251
- values.$headers_iv = updates.headers_iv;
252
- }
253
-
254
- if (fields.length === 0) return;
255
-
256
- const query = `UPDATE mcp_servers SET ${fields.join(", ")} WHERE id = $id`;
257
- try {
258
- this.db.query(query).run(values);
259
- this.log.debug(`MCP server ${id} updated in DB`);
260
- } catch (error: any) {
261
- this.log.error(`Failed to update MCP server ${id}: ${error.message}`);
262
- }
263
- }
264
-
265
- public listMCPServers(): any[] {
266
- try {
267
- return this.db.query("SELECT * FROM mcp_servers").all();
268
- } catch (error: any) {
269
- this.log.error(`Failed to list MCP servers: ${error.message}`);
270
- return [];
271
- }
272
- }
273
-
274
- public createTask(task: {
275
- project_id: string;
276
- agent_id?: string | null;
277
- parent_task_id?: number | null;
278
- name: string;
279
- description?: string | null;
280
- }): number {
281
- const result = this.db.query(`
282
- INSERT INTO tasks (project_id, agent_id, parent_task_id, name, description)
283
- VALUES (?, ?, ?, ?, ?)
284
- `).run(
285
- task.project_id,
286
- task.agent_id ?? null,
287
- task.parent_task_id ?? null,
288
- task.name,
289
- task.description ?? null
290
- );
291
- return Number(result.lastInsertRowid);
292
- }
293
-
294
- public updateTask(taskId: number, updates: {
295
- status?: string;
296
- progress?: number;
297
- result?: string;
298
- agent_id?: string | null;
299
- }): boolean {
300
- const fields: string[] = ["updated_at = unixepoch()"];
301
- const values: any[] = [];
302
-
303
- if (updates.status !== undefined) { fields.push("status = ?"); values.push(updates.status); }
304
- if (updates.progress !== undefined) { fields.push("progress = ?"); values.push(updates.progress); }
305
- if (updates.result !== undefined) { fields.push("result = ?"); values.push(updates.result); }
306
- if (updates.agent_id !== undefined) { fields.push("agent_id = ?"); values.push(updates.agent_id); }
307
-
308
- values.push(taskId);
309
- const res = this.db.query(`UPDATE tasks SET ${fields.join(", ")} WHERE id = ?`).run(...values);
310
- return res.changes > 0;
311
- }
312
-
313
- public getTasksByProject(projectId: string): any[] {
314
- return this.db.query(
315
- "SELECT * FROM tasks WHERE project_id = ? ORDER BY id ASC"
316
- ).all(projectId) as any[];
317
- }
318
-
319
- public getProjectWithTasks(projectId: string): any | null {
320
- const project = this.db.query("SELECT * FROM projects WHERE id = ?").get(projectId) as any;
321
- if (!project) return null;
322
- project.tasks = this.getTasksByProject(projectId);
323
- return project;
324
- }
325
-
326
- public recalcProjectProgress(projectId: string): number {
327
- const row = this.db.query(
328
- "SELECT AVG(progress) as avg_progress FROM tasks WHERE project_id = ?"
329
- ).get(projectId) as any;
330
- const avg = Math.round(row?.avg_progress ?? 0);
331
- this.db.query("UPDATE projects SET progress = ?, updated_at = unixepoch() WHERE id = ?").run(avg, projectId);
332
- return avg;
333
- }
334
-
335
- public saveMCPServer(server: any): void {
336
- try {
337
- this.db.query(`
338
- INSERT OR REPLACE INTO mcp_servers (id, name, transport, command, args, url, env_encrypted, env_iv, headers_encrypted, headers_iv, enabled, active, builtin, tools_count, status)
339
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
340
- `).run(
341
- server.id || server.name,
342
- server.name,
343
- server.transport,
344
- server.command || null,
345
- JSON.stringify(server.args || []),
346
- server.url || null,
347
- server.env_encrypted || null,
348
- server.env_iv || null,
349
- server.headers_encrypted || null,
350
- server.headers_iv || null,
351
- server.enabled ? 1 : 0,
352
- server.active ? 1 : 0,
353
- server.builtin ? 1 : 0,
354
- server.tools_count || 0,
355
- server.status || "disconnected"
356
- );
357
- } catch (error: any) {
358
- this.log.error(`Failed to save MCP server ${server.name}: ${error.message}`);
359
- }
360
- }
361
- }
362
-
363
- export const dbService = new DatabaseService();
@@ -1,270 +0,0 @@
1
- import { getDb } from "./sqlite";
2
- import { randomUUID } from "crypto";
3
- import { logger } from "../utils/logger";
4
-
5
- const log = logger.child("usage");
6
-
7
- // Precios en USD por millón de tokens (input / output)
8
- // Fuentes: docs.anthropic.com, openrouter.ai/api/v1/models, api-docs.deepseek.com, console.groq.com
9
- const MODEL_PRICING: Record<string, { inputPer1M: number; outputPer1M: number }> = {
10
- // ── Anthropic (fuente: docs.anthropic.com) ──
11
- "claude-opus-4-6": { inputPer1M: 5, outputPer1M: 25 },
12
- "claude-sonnet-4-6": { inputPer1M: 3, outputPer1M: 15 },
13
- "claude-haiku-4-5-20251001": { inputPer1M: 1, outputPer1M: 5 },
14
- "anthropic/claude-opus-4-6": { inputPer1M: 5, outputPer1M: 25 },
15
- "anthropic/claude-sonnet-4-6": { inputPer1M: 3, outputPer1M: 15 },
16
-
17
- // ── OpenAI (fuente: openrouter.ai/api/v1/models) ──
18
- "gpt-4o": { inputPer1M: 2.5, outputPer1M: 10 },
19
- "gpt-4o-mini": { inputPer1M: 0.15, outputPer1M: 0.6 },
20
- "gpt-5.4": { inputPer1M: 2.5, outputPer1M: 15 }, // $0.0000025 / $0.000015
21
- "gpt-5.4-pro": { inputPer1M: 30, outputPer1M: 180 }, // $0.00003 / $0.00018
22
- "gpt-5.3": { inputPer1M: 1.75, outputPer1M: 14 }, // $0.00000175 / $0.000014
23
- "gpt-5.2": { inputPer1M: 1.75, outputPer1M: 14 },
24
- "o4-mini": { inputPer1M: 1.1, outputPer1M: 4.4 },
25
- "openai/gpt-5.4": { inputPer1M: 2.5, outputPer1M: 15 },
26
- "openai/gpt-5.4-pro": { inputPer1M: 30, outputPer1M: 180 },
27
- "openai/gpt-5.2": { inputPer1M: 1.75, outputPer1M: 14 },
28
- // Groq OSS (fuente: console.groq.com)
29
- "openai/gpt-oss-120b": { inputPer1M: 0.15, outputPer1M: 0.6 },
30
- "openai/gpt-oss-20b": { inputPer1M: 0.075, outputPer1M: 0.3 },
31
-
32
- // ── Google Gemini (fuente: openrouter.ai/api/v1/models) ──
33
- "gemini-3.1-pro-preview": { inputPer1M: 2, outputPer1M: 12 }, // $0.000002 / $0.000012
34
- "gemini-3.1-flash-lite-preview": { inputPer1M: 0.25, outputPer1M: 1.5 }, // $0.00000025 / $0.0000015
35
- "gemini-3-flash-preview": { inputPer1M: 0.5, outputPer1M: 3 }, // $0.0000005 / $0.000003
36
- "gemini-2.5-pro": { inputPer1M: 1.25, outputPer1M: 10 },
37
- "gemini-2.5-flash": { inputPer1M: 0.15, outputPer1M: 0.6 },
38
- "gemini-2.0-flash": { inputPer1M: 0.1, outputPer1M: 0.4 },
39
- "gemini-2.0-flash-lite": { inputPer1M: 0.075, outputPer1M: 0.3 },
40
- "google/gemini-3.1-pro-preview": { inputPer1M: 2, outputPer1M: 12 },
41
- "google/gemini-3.1-flash-lite-preview": { inputPer1M: 0.25, outputPer1M: 1.5 },
42
- "google/gemini-3-flash-preview": { inputPer1M: 0.5, outputPer1M: 3 },
43
- "google/gemini-2.5-flash": { inputPer1M: 0.15, outputPer1M: 0.6 },
44
-
45
- // ── Mistral (fuente: openrouter.ai/api/v1/models) ──
46
- "mistral-large-2512": { inputPer1M: 0.5, outputPer1M: 1.5 }, // $0.0000005 / $0.0000015
47
- "devstral-2512": { inputPer1M: 0.4, outputPer1M: 2 },
48
- "ministral-14b-2512": { inputPer1M: 0.2, outputPer1M: 0.2 },
49
- "ministral-8b-2512": { inputPer1M: 0.15, outputPer1M: 0.15 },
50
- "codestral-2508": { inputPer1M: 0.2, outputPer1M: 0.6 },
51
- "mistral-small-3.2-24b-instruct": { inputPer1M: 0.1, outputPer1M: 0.3 },
52
- "mistral-large-latest": { inputPer1M: 0.5, outputPer1M: 1.5 },
53
- "codestral-latest": { inputPer1M: 0.2, outputPer1M: 0.6 },
54
-
55
- // ── DeepSeek (fuente: api-docs.deepseek.com/quick_start/pricing) ──
56
- "deepseek-chat": { inputPer1M: 0.28, outputPer1M: 0.42 },
57
- "deepseek-reasoner": { inputPer1M: 0.28, outputPer1M: 0.42 },
58
- "deepseek/deepseek-v3.2": { inputPer1M: 0.25, outputPer1M: 0.4 }, // $0.00000025 / $0.0000004
59
- "deepseek/deepseek-r1:free": { inputPer1M: 0, outputPer1M: 0 },
60
-
61
- // ── Kimi / Moonshot (fuente: openrouter.ai/moonshotai) ──
62
- "kimi-k2.5": { inputPer1M: 0.45, outputPer1M: 2.2 },
63
- "kimi-k2": { inputPer1M: 0.45, outputPer1M: 2.2 },
64
- "moonshot-v1-8k": { inputPer1M: 1.67, outputPer1M: 1.67 },
65
- "moonshot-v1-32k": { inputPer1M: 3.33, outputPer1M: 3.33 },
66
- "moonshot-v1-128k": { inputPer1M: 8.33, outputPer1M: 8.33 },
67
- "moonshotai/kimi-k2.5": { inputPer1M: 0.45, outputPer1M: 2.2 },
68
- "moonshotai/kimi-k2-instruct-0905": { inputPer1M: 0.45, outputPer1M: 2.2 },
69
-
70
- // ── Meta Llama (vía OpenRouter) ──
71
- "meta-llama/llama-3.3-70b-instruct": { inputPer1M: 0.88, outputPer1M: 0.88 },
72
- "meta-llama/llama-4-maverick": { inputPer1M: 0.2, outputPer1M: 0.8 },
73
-
74
- // ── Qwen (vía OpenRouter) ──
75
- "qwen/qwen3.5-plus-02-15": { inputPer1M: 0.26, outputPer1M: 1.56 },
76
- "qwen/qwen3.5-flash-02-23": { inputPer1M: 0.1, outputPer1M: 0.4 },
77
- "qwen/qwen3-32b": { inputPer1M: 0, outputPer1M: 0 }, // Groq free
78
-
79
- // ── Groq (fuente: console.groq.com/docs/models) ──
80
- "llama-3.3-70b-versatile": { inputPer1M: 0.59, outputPer1M: 0.79 },
81
- "llama-3.1-8b-instant": { inputPer1M: 0.05, outputPer1M: 0.08 },
82
- "groq/compound": { inputPer1M: 0, outputPer1M: 0 },
83
- "groq/compound-mini": { inputPer1M: 0, outputPer1M: 0 },
84
-
85
- // ── Ollama local = siempre free ──
86
- "qwen3:4b": { inputPer1M: 0, outputPer1M: 0 },
87
- "qwen3:8b": { inputPer1M: 0, outputPer1M: 0 },
88
- "qwen3:14b": { inputPer1M: 0, outputPer1M: 0 },
89
- "llama3.2:3b": { inputPer1M: 0, outputPer1M: 0 },
90
- "gemma3:9b": { inputPer1M: 0, outputPer1M: 0 },
91
- };
92
-
93
- function calculateCost(model: string, inputTokens: number, outputTokens: number): number {
94
- const pricing = MODEL_PRICING[model] || { inputPer1M: 0, outputPer1M: 0 };
95
- const inputCost = (inputTokens / 1_000_000) * pricing.inputPer1M;
96
- const outputCost = (outputTokens / 1_000_000) * pricing.outputPer1M;
97
- return inputCost + outputCost;
98
- }
99
-
100
- export interface UsageRecord {
101
- id: string;
102
- provider: string;
103
- model: string;
104
- input_tokens: number;
105
- output_tokens: number;
106
- cost_usd: number;
107
- latency_ms: number | null;
108
- toon_saved_tokens: number;
109
- toon_saved_cost: number;
110
- created_at: number;
111
- }
112
-
113
- export interface UsageSummary {
114
- totalTokens: number;
115
- totalInputTokens: number;
116
- totalOutputTokens: number;
117
- totalCostUsd: number;
118
- toonSavedTokens: number;
119
- toonSavedCost: number;
120
- toonSavingsPercent: number;
121
- byProvider: Record<string, { tokens: number; costUsd: number; inputTokens: number; outputTokens: number }>;
122
- byModel: Record<string, { tokens: number; costUsd: number; provider: string; inputTokens: number; outputTokens: number }>;
123
- recentRecords: UsageRecord[];
124
- }
125
-
126
- export function recordUsage(options: {
127
- provider: string;
128
- model: string;
129
- inputTokens: number;
130
- outputTokens: number;
131
- latencyMs?: number;
132
- toonSavedTokens?: number;
133
- toonSavedCost?: number;
134
- }): void {
135
- try {
136
- const db = getDb();
137
- const costUsd = calculateCost(options.model, options.inputTokens, options.outputTokens);
138
-
139
- db.prepare(`
140
- INSERT INTO usage_records (id, provider, model, input_tokens, output_tokens, cost_usd, latency_ms, toon_saved_tokens, toon_saved_cost, created_at)
141
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
142
- `).run(
143
- randomUUID(),
144
- options.provider,
145
- options.model,
146
- options.inputTokens,
147
- options.outputTokens,
148
- costUsd,
149
- options.latencyMs || null,
150
- options.toonSavedTokens || 0,
151
- options.toonSavedCost || 0,
152
- Math.floor(Date.now() / 1000)
153
- );
154
- log.info(`[USAGE RECORDED] provider=${options.provider} model=${options.model} input=${options.inputTokens} output=${options.outputTokens} cost=$${costUsd.toFixed(4)} toonSaved=${options.toonSavedTokens || 0}`);
155
- } catch (error) {
156
- console.error("Failed to record usage:", error);
157
- }
158
- }
159
-
160
- export function getUsageStats(hours: number = 24): UsageSummary {
161
- log.info(`[USAGE STATS] Fetching stats for last ${hours} hours`);
162
- const db = getDb();
163
- const since = Math.floor(Date.now() / 1000) - (hours * 3600);
164
-
165
- const totals = db.prepare(`
166
- SELECT
167
- COALESCE(SUM(input_tokens), 0) as total_input,
168
- COALESCE(SUM(output_tokens), 0) as total_output,
169
- COALESCE(SUM(cost_usd), 0) as total_cost,
170
- COALESCE(SUM(toon_saved_tokens), 0) as toon_saved_tokens,
171
- COALESCE(SUM(toon_saved_cost), 0) as toon_saved_cost
172
- FROM usage_records
173
- WHERE created_at >= ?
174
- `).get(since) as { total_input: number; total_output: number; total_cost: number; toon_saved_tokens: number; toon_saved_cost: number };
175
-
176
- const byProvider = db.prepare(`
177
- SELECT
178
- provider,
179
- COALESCE(SUM(input_tokens), 0) as input_tokens,
180
- COALESCE(SUM(output_tokens), 0) as output_tokens,
181
- COALESCE(SUM(cost_usd), 0) as cost_usd
182
- FROM usage_records
183
- WHERE created_at >= ?
184
- GROUP BY provider
185
- `).all(since) as Array<{ provider: string; input_tokens: number; output_tokens: number; cost_usd: number }>;
186
-
187
- const byModel = db.prepare(`
188
- SELECT
189
- model,
190
- provider,
191
- COALESCE(SUM(input_tokens), 0) as input_tokens,
192
- COALESCE(SUM(output_tokens), 0) as output_tokens,
193
- COALESCE(SUM(cost_usd), 0) as cost_usd
194
- FROM usage_records
195
- WHERE created_at >= ?
196
- GROUP BY model
197
- ORDER BY cost_usd DESC
198
- `).all(since) as Array<{ model: string; provider: string; input_tokens: number; output_tokens: number; cost_usd: number }>;
199
-
200
- const recentRecords = db.prepare(`
201
- SELECT * FROM usage_records
202
- WHERE created_at >= ?
203
- ORDER BY created_at DESC
204
- LIMIT 20
205
- `).all(since) as UsageRecord[];
206
-
207
- const providerMap: UsageSummary["byProvider"] = {};
208
- for (const p of byProvider) {
209
- providerMap[p.provider] = {
210
- inputTokens: p.input_tokens,
211
- outputTokens: p.output_tokens,
212
- tokens: p.input_tokens + p.output_tokens,
213
- costUsd: p.cost_usd
214
- };
215
- }
216
-
217
- const modelMap: UsageSummary["byModel"] = {};
218
- for (const m of byModel) {
219
- modelMap[m.model] = {
220
- provider: m.provider,
221
- inputTokens: m.input_tokens,
222
- outputTokens: m.output_tokens,
223
- tokens: m.input_tokens + m.output_tokens,
224
- costUsd: m.cost_usd
225
- };
226
- }
227
-
228
- const totalTokens = totals.total_input + totals.total_output;
229
- const toonSavingsPercent = totalTokens > 0
230
- ? (totals.toon_saved_tokens / totalTokens) * 100
231
- : 0;
232
-
233
- return {
234
- totalTokens,
235
- totalInputTokens: totals.total_input,
236
- totalOutputTokens: totals.total_output,
237
- totalCostUsd: totals.total_cost,
238
- toonSavedTokens: totals.toon_saved_tokens,
239
- toonSavedCost: totals.toon_saved_cost,
240
- toonSavingsPercent,
241
- byProvider: providerMap,
242
- byModel: modelMap,
243
- recentRecords
244
- };
245
- }
246
-
247
- export function getProviderPricing(provider: string, model: string): { inputPer1M: number; outputPer1M: number } {
248
- return MODEL_PRICING[model] || { inputPer1M: 0, outputPer1M: 0 };
249
- }
250
-
251
- export function estimateCostForTokens(model: string, tokens: number): number {
252
- const pricing = MODEL_PRICING[model] || { inputPer1M: 0, outputPer1M: 0 };
253
- return (tokens / 1_000_000) * pricing.inputPer1M;
254
- }
255
-
256
- // Pending TOON savings — set before LLM invoke, consumed in handleLLMEnd callback
257
- let pendingToonTokens = 0;
258
- let pendingToonCost = 0;
259
-
260
- export function setPendingToonSavings(tokens: number, cost: number): void {
261
- pendingToonTokens = tokens;
262
- pendingToonCost = cost;
263
- }
264
-
265
- export function consumePendingToonSavings(): { tokens: number; cost: number } {
266
- const result = { tokens: pendingToonTokens, cost: pendingToonCost };
267
- pendingToonTokens = 0;
268
- pendingToonCost = 0;
269
- return result;
270
- }