@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.
- package/README.md +178 -36
- package/dist/hive.js +315124 -0
- package/package.json +11 -3
- package/packages/core/src/index.ts +0 -1
- package/.dockerignore +0 -9
- package/CONTRIBUTING.md +0 -44
- package/Dockerfile +0 -67
- package/docker-compose.yml +0 -19
- package/packages/cli/package.json +0 -28
- package/packages/cli/src/commands/agent-run.ts +0 -168
- package/packages/cli/src/commands/agents.ts +0 -398
- package/packages/cli/src/commands/chat.ts +0 -142
- package/packages/cli/src/commands/config.ts +0 -50
- package/packages/cli/src/commands/cron.ts +0 -161
- package/packages/cli/src/commands/dev.ts +0 -95
- package/packages/cli/src/commands/doctor.ts +0 -133
- package/packages/cli/src/commands/gateway.ts +0 -422
- package/packages/cli/src/commands/logs.ts +0 -57
- package/packages/cli/src/commands/mcp.ts +0 -175
- package/packages/cli/src/commands/message.ts +0 -77
- package/packages/cli/src/commands/onboard.ts +0 -1696
- package/packages/cli/src/commands/security.ts +0 -144
- package/packages/cli/src/commands/service.ts +0 -50
- package/packages/cli/src/commands/sessions.ts +0 -116
- package/packages/cli/src/commands/skills.ts +0 -187
- package/packages/cli/src/commands/update.ts +0 -25
- package/packages/cli/src/index.ts +0 -190
- package/packages/cli/src/utils/token.ts +0 -6
- package/packages/code-bridge/README.md +0 -78
- package/packages/code-bridge/package.json +0 -18
- package/packages/code-bridge/src/index.ts +0 -95
- package/packages/code-bridge/src/process-manager.ts +0 -212
- package/packages/code-bridge/src/schemas.ts +0 -133
- package/packages/core/package.json +0 -55
- package/packages/core/src/agent/agent-loop.ts +0 -520
- package/packages/core/src/agent/compaction.ts +0 -183
- package/packages/core/src/agent/context-compiler.ts +0 -544
- package/packages/core/src/agent/context-guard.ts +0 -91
- package/packages/core/src/agent/conversation-store.ts +0 -193
- package/packages/core/src/agent/curator.ts +0 -158
- package/packages/core/src/agent/hooks.ts +0 -166
- package/packages/core/src/agent/llm-client.ts +0 -503
- package/packages/core/src/agent/native-tools.ts +0 -31
- package/packages/core/src/agent/playbook-selector.ts +0 -143
- package/packages/core/src/agent/prompt-builder.ts +0 -167
- package/packages/core/src/agent/providers/index.ts +0 -186
- package/packages/core/src/agent/providers.ts +0 -1
- package/packages/core/src/agent/reflector.ts +0 -200
- package/packages/core/src/agent/service.ts +0 -266
- package/packages/core/src/agent/skill-selector.ts +0 -413
- package/packages/core/src/agent/stuck-loop.ts +0 -133
- package/packages/core/src/agent/tool-selector.ts +0 -623
- package/packages/core/src/agent/tracer.ts +0 -102
- package/packages/core/src/canvas/canvas-manager.ts +0 -319
- package/packages/core/src/canvas/canvas-tools.ts +0 -420
- package/packages/core/src/canvas/emitter.ts +0 -119
- package/packages/core/src/canvas/index.ts +0 -2
- package/packages/core/src/channels/base.ts +0 -140
- package/packages/core/src/channels/discord.ts +0 -260
- package/packages/core/src/channels/index.ts +0 -7
- package/packages/core/src/channels/manager.ts +0 -383
- package/packages/core/src/channels/slack.ts +0 -287
- package/packages/core/src/channels/telegram.ts +0 -552
- package/packages/core/src/channels/webchat.ts +0 -139
- package/packages/core/src/channels/whatsapp.ts +0 -375
- package/packages/core/src/config/index.ts +0 -12
- package/packages/core/src/config/loader.ts +0 -529
- package/packages/core/src/events/agent-bus.ts +0 -460
- package/packages/core/src/events/event-bus.ts +0 -169
- package/packages/core/src/gateway/helpers/cors.ts +0 -32
- package/packages/core/src/gateway/helpers/index.ts +0 -4
- package/packages/core/src/gateway/helpers/narration.ts +0 -60
- package/packages/core/src/gateway/helpers/path.ts +0 -13
- package/packages/core/src/gateway/helpers/redact.ts +0 -61
- package/packages/core/src/gateway/index.ts +0 -5
- package/packages/core/src/gateway/initializer.ts +0 -332
- package/packages/core/src/gateway/lane-queue.ts +0 -169
- package/packages/core/src/gateway/resolver.ts +0 -108
- package/packages/core/src/gateway/router.ts +0 -124
- package/packages/core/src/gateway/routes/agents.ts +0 -187
- package/packages/core/src/gateway/routes/channels.ts +0 -203
- package/packages/core/src/gateway/routes/chat.ts +0 -241
- package/packages/core/src/gateway/routes/config.ts +0 -12
- package/packages/core/src/gateway/routes/cron.ts +0 -42
- package/packages/core/src/gateway/routes/ethics.ts +0 -46
- package/packages/core/src/gateway/routes/mcp.ts +0 -346
- package/packages/core/src/gateway/routes/models.ts +0 -93
- package/packages/core/src/gateway/routes/projects.ts +0 -179
- package/packages/core/src/gateway/routes/providers.ts +0 -192
- package/packages/core/src/gateway/routes/setup.ts +0 -267
- package/packages/core/src/gateway/routes/skills.ts +0 -70
- package/packages/core/src/gateway/routes/system.ts +0 -165
- package/packages/core/src/gateway/routes/tasks.ts +0 -44
- package/packages/core/src/gateway/routes/tools.ts +0 -35
- package/packages/core/src/gateway/routes/users.ts +0 -118
- package/packages/core/src/gateway/routes/voice.ts +0 -73
- package/packages/core/src/gateway/routes/workspace.ts +0 -281
- package/packages/core/src/gateway/server.ts +0 -1978
- package/packages/core/src/gateway/session.ts +0 -95
- package/packages/core/src/gateway/slash-commands.ts +0 -193
- package/packages/core/src/heartbeat/index.ts +0 -157
- package/packages/core/src/mcp/hot-reload.ts +0 -213
- package/packages/core/src/mcp/singleton.ts +0 -21
- package/packages/core/src/memory/index.ts +0 -1
- package/packages/core/src/memory/notes.ts +0 -68
- package/packages/core/src/plugins/api.ts +0 -128
- package/packages/core/src/plugins/index.ts +0 -2
- package/packages/core/src/plugins/loader.ts +0 -365
- package/packages/core/src/resilience/circuit-breaker.ts +0 -225
- package/packages/core/src/security/google-chat.ts +0 -269
- package/packages/core/src/security/index.ts +0 -192
- package/packages/core/src/security/pairing.ts +0 -250
- package/packages/core/src/security/rate-limit.ts +0 -270
- package/packages/core/src/security/signal.ts +0 -321
- package/packages/core/src/state/store.ts +0 -312
- package/packages/core/src/storage/crypto.ts +0 -101
- package/packages/core/src/storage/onboarding.ts +0 -1609
- package/packages/core/src/storage/schema.ts +0 -567
- package/packages/core/src/storage/seed.ts +0 -608
- package/packages/core/src/storage/sqlite.ts +0 -363
- package/packages/core/src/storage/usage.ts +0 -270
- package/packages/core/src/tools/agents/index.ts +0 -607
- package/packages/core/src/tools/bridge-events.ts +0 -26
- package/packages/core/src/tools/canvas/index.ts +0 -281
- package/packages/core/src/tools/cli/index.ts +0 -142
- package/packages/core/src/tools/codebridge/index.ts +0 -179
- package/packages/core/src/tools/core/index.ts +0 -257
- package/packages/core/src/tools/cron/index.ts +0 -373
- package/packages/core/src/tools/filesystem/fs-delete.ts +0 -78
- package/packages/core/src/tools/filesystem/fs-edit.ts +0 -106
- package/packages/core/src/tools/filesystem/fs-exists.ts +0 -63
- package/packages/core/src/tools/filesystem/fs-glob.ts +0 -108
- package/packages/core/src/tools/filesystem/fs-list.ts +0 -129
- package/packages/core/src/tools/filesystem/fs-read.ts +0 -72
- package/packages/core/src/tools/filesystem/fs-write.ts +0 -67
- package/packages/core/src/tools/filesystem/index.ts +0 -34
- package/packages/core/src/tools/filesystem/workspace-guard.ts +0 -62
- package/packages/core/src/tools/index.ts +0 -197
- package/packages/core/src/tools/projects/index.ts +0 -37
- package/packages/core/src/tools/projects/project-create.ts +0 -94
- package/packages/core/src/tools/projects/project-done.ts +0 -66
- package/packages/core/src/tools/projects/project-fail.ts +0 -66
- package/packages/core/src/tools/projects/project-list.ts +0 -96
- package/packages/core/src/tools/projects/project-update.ts +0 -72
- package/packages/core/src/tools/projects/task-create.ts +0 -68
- package/packages/core/src/tools/projects/task-evaluate.ts +0 -93
- package/packages/core/src/tools/projects/task-update.ts +0 -93
- package/packages/core/src/tools/search-knowledge/search-knowledge.ts +0 -155
- package/packages/core/src/tools/types.ts +0 -39
- package/packages/core/src/tools/voice/index.ts +0 -104
- package/packages/core/src/tools/web/browser-click.ts +0 -54
- package/packages/core/src/tools/web/browser-navigate.ts +0 -84
- package/packages/core/src/tools/web/browser-screenshot.ts +0 -54
- package/packages/core/src/tools/web/browser-type.ts +0 -60
- package/packages/core/src/tools/web/index.ts +0 -31
- package/packages/core/src/tools/web/web-fetch.ts +0 -78
- package/packages/core/src/tools/web/web-search.ts +0 -123
- package/packages/core/src/utils/benchmark.ts +0 -80
- package/packages/core/src/utils/crypto.ts +0 -73
- package/packages/core/src/utils/date.ts +0 -42
- package/packages/core/src/utils/index.ts +0 -5
- package/packages/core/src/utils/logger.ts +0 -389
- package/packages/core/src/utils/retry.ts +0 -70
- package/packages/core/src/utils/toon.ts +0 -356
- package/packages/core/src/voice/index.ts +0 -583
- package/packages/hive-ui/README.md +0 -52
- package/packages/hive-ui/components.json +0 -20
- package/packages/hive-ui/index.html +0 -30
- package/packages/hive-ui/package.json +0 -90
- package/packages/hive-ui/public/favicon.ico +0 -0
- package/packages/hive-ui/public/placeholder.svg +0 -1
- package/packages/hive-ui/src/App.tsx +0 -115
- package/packages/hive-ui/src/components/CronJobsPanel.tsx +0 -200
- package/packages/hive-ui/src/components/NavLink.tsx +0 -34
- package/packages/hive-ui/src/components/NotesPanel.tsx +0 -79
- package/packages/hive-ui/src/components/SystemMonitor.tsx +0 -270
- package/packages/hive-ui/src/components/UsageStatsPanel.tsx +0 -334
- package/packages/hive-ui/src/components/WelcomeDialog.tsx +0 -279
- package/packages/hive-ui/src/components/ui/accordion.tsx +0 -52
- package/packages/hive-ui/src/components/ui/alert-dialog.tsx +0 -104
- package/packages/hive-ui/src/components/ui/alert.tsx +0 -45
- package/packages/hive-ui/src/components/ui/aspect-ratio.tsx +0 -5
- package/packages/hive-ui/src/components/ui/avatar.tsx +0 -38
- package/packages/hive-ui/src/components/ui/badge.tsx +0 -29
- package/packages/hive-ui/src/components/ui/bee-loader.tsx +0 -68
- package/packages/hive-ui/src/components/ui/breadcrumb.tsx +0 -90
- package/packages/hive-ui/src/components/ui/button.tsx +0 -47
- package/packages/hive-ui/src/components/ui/calendar.tsx +0 -54
- package/packages/hive-ui/src/components/ui/card.tsx +0 -45
- package/packages/hive-ui/src/components/ui/carousel.tsx +0 -224
- package/packages/hive-ui/src/components/ui/chart.tsx +0 -303
- package/packages/hive-ui/src/components/ui/checkbox.tsx +0 -26
- package/packages/hive-ui/src/components/ui/collapsible.tsx +0 -9
- package/packages/hive-ui/src/components/ui/command.tsx +0 -133
- package/packages/hive-ui/src/components/ui/context-menu.tsx +0 -178
- package/packages/hive-ui/src/components/ui/dialog.tsx +0 -95
- package/packages/hive-ui/src/components/ui/drawer.tsx +0 -87
- package/packages/hive-ui/src/components/ui/dropdown-menu.tsx +0 -179
- package/packages/hive-ui/src/components/ui/form.tsx +0 -129
- package/packages/hive-ui/src/components/ui/hover-card.tsx +0 -27
- package/packages/hive-ui/src/components/ui/input-otp.tsx +0 -61
- package/packages/hive-ui/src/components/ui/input.tsx +0 -22
- package/packages/hive-ui/src/components/ui/label.tsx +0 -17
- package/packages/hive-ui/src/components/ui/menubar.tsx +0 -207
- package/packages/hive-ui/src/components/ui/navigation-menu.tsx +0 -120
- package/packages/hive-ui/src/components/ui/pagination.tsx +0 -80
- package/packages/hive-ui/src/components/ui/popover.tsx +0 -29
- package/packages/hive-ui/src/components/ui/progress.tsx +0 -23
- package/packages/hive-ui/src/components/ui/radio-group.tsx +0 -36
- package/packages/hive-ui/src/components/ui/resizable.tsx +0 -37
- package/packages/hive-ui/src/components/ui/scroll-area.tsx +0 -38
- package/packages/hive-ui/src/components/ui/select.tsx +0 -143
- package/packages/hive-ui/src/components/ui/separator.tsx +0 -20
- package/packages/hive-ui/src/components/ui/sheet.tsx +0 -107
- package/packages/hive-ui/src/components/ui/sidebar.tsx +0 -636
- package/packages/hive-ui/src/components/ui/skeleton.tsx +0 -7
- package/packages/hive-ui/src/components/ui/slider.tsx +0 -23
- package/packages/hive-ui/src/components/ui/sonner.tsx +0 -27
- package/packages/hive-ui/src/components/ui/switch.tsx +0 -27
- package/packages/hive-ui/src/components/ui/table.tsx +0 -72
- package/packages/hive-ui/src/components/ui/tabs.tsx +0 -53
- package/packages/hive-ui/src/components/ui/textarea.tsx +0 -21
- package/packages/hive-ui/src/components/ui/toast.tsx +0 -111
- package/packages/hive-ui/src/components/ui/toaster.tsx +0 -24
- package/packages/hive-ui/src/components/ui/toggle-group.tsx +0 -49
- package/packages/hive-ui/src/components/ui/toggle.tsx +0 -37
- package/packages/hive-ui/src/components/ui/tooltip.tsx +0 -28
- package/packages/hive-ui/src/components/ui/use-toast.ts +0 -3
- package/packages/hive-ui/src/hooks/use-mobile.tsx +0 -19
- package/packages/hive-ui/src/hooks/use-toast.ts +0 -186
- package/packages/hive-ui/src/hooks/useAgentConfig.ts +0 -25
- package/packages/hive-ui/src/hooks/useAgents.ts +0 -38
- package/packages/hive-ui/src/hooks/useBridge.ts +0 -38
- package/packages/hive-ui/src/hooks/useCanvas.ts +0 -24
- package/packages/hive-ui/src/hooks/useChannels.ts +0 -2
- package/packages/hive-ui/src/hooks/useEthics.ts +0 -51
- package/packages/hive-ui/src/hooks/useProviders.ts +0 -14
- package/packages/hive-ui/src/hooks/useTheme.ts +0 -29
- package/packages/hive-ui/src/hooks/useUserConfig.ts +0 -17
- package/packages/hive-ui/src/hooks/useWebSocket.ts +0 -12
- package/packages/hive-ui/src/index.css +0 -620
- package/packages/hive-ui/src/lib/api.ts +0 -100
- package/packages/hive-ui/src/lib/constants.ts +0 -6
- package/packages/hive-ui/src/lib/models.ts +0 -64
- package/packages/hive-ui/src/lib/swal.ts +0 -30
- package/packages/hive-ui/src/lib/utils.ts +0 -6
- package/packages/hive-ui/src/lib/websocket.ts +0 -7
- package/packages/hive-ui/src/main.tsx +0 -5
- package/packages/hive-ui/src/modules/agent-config/details/AgentDetailsEditor.tsx +0 -524
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsConflictDetector.tsx +0 -18
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsEditor.tsx +0 -19
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsRulesList.tsx +0 -36
- package/packages/hive-ui/src/modules/agent-config/ethics/EthicsTemplateGallery.tsx +0 -361
- package/packages/hive-ui/src/modules/agent-config/ethics/index.ts +0 -4
- package/packages/hive-ui/src/modules/agent-config/index.ts +0 -6
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerAdd.tsx +0 -322
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerCard.tsx +0 -93
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerConfig.tsx +0 -427
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPServerList.tsx +0 -85
- package/packages/hive-ui/src/modules/agent-config/mcp/MCPToolExplorer.tsx +0 -79
- package/packages/hive-ui/src/modules/agent-config/mcp/index.ts +0 -5
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigEditorLayout.tsx +0 -30
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigExporter.tsx +0 -26
- package/packages/hive-ui/src/modules/agent-config/shared/ConfigImporter.tsx +0 -25
- package/packages/hive-ui/src/modules/agent-config/shared/DiffViewer.tsx +0 -31
- package/packages/hive-ui/src/modules/agent-config/shared/MarkdownEditor.tsx +0 -32
- package/packages/hive-ui/src/modules/agent-config/shared/SaveStatusIndicator.tsx +0 -23
- package/packages/hive-ui/src/modules/agent-config/shared/ValidationPanel.tsx +0 -36
- package/packages/hive-ui/src/modules/agent-config/shared/index.ts +0 -7
- package/packages/hive-ui/src/modules/agent-config/skills/SkillCard.tsx +0 -81
- package/packages/hive-ui/src/modules/agent-config/skills/SkillConfigEditor.tsx +0 -22
- package/packages/hive-ui/src/modules/agent-config/skills/SkillCreator.tsx +0 -60
- package/packages/hive-ui/src/modules/agent-config/skills/SkillInstaller.tsx +0 -23
- package/packages/hive-ui/src/modules/agent-config/skills/SkillList.tsx +0 -72
- package/packages/hive-ui/src/modules/agent-config/skills/SkillsTab.tsx +0 -202
- package/packages/hive-ui/src/modules/agent-config/skills/index.ts +0 -5
- package/packages/hive-ui/src/modules/agent-config/tools/ToolCard.tsx +0 -27
- package/packages/hive-ui/src/modules/agent-config/tools/ToolConfigPanel.tsx +0 -22
- package/packages/hive-ui/src/modules/agent-config/tools/ToolManager.tsx +0 -266
- package/packages/hive-ui/src/modules/agent-config/tools/ToolPermissions.tsx +0 -287
- package/packages/hive-ui/src/modules/agent-config/tools/ToolRegistry.tsx +0 -84
- package/packages/hive-ui/src/modules/agent-config/tools/ToolUsageStats.tsx +0 -52
- package/packages/hive-ui/src/modules/agent-config/tools/index.ts +0 -4
- package/packages/hive-ui/src/modules/agent-config/user/ActiveAgentsList.tsx +0 -109
- package/packages/hive-ui/src/modules/agent-config/user/GlobalConfigOverview.tsx +0 -119
- package/packages/hive-ui/src/modules/agent-config/user/UserMemoryManager.tsx +0 -54
- package/packages/hive-ui/src/modules/agent-config/user/UserPreferencesForm.tsx +0 -163
- package/packages/hive-ui/src/modules/agent-config/user/UserProfileEditor.tsx +0 -261
- package/packages/hive-ui/src/modules/agent-config/user/index.ts +0 -3
- package/packages/hive-ui/src/modules/agents/AgentActivityLog.tsx +0 -25
- package/packages/hive-ui/src/modules/agents/AgentCard.tsx +0 -305
- package/packages/hive-ui/src/modules/agents/AgentCreateForm.tsx +0 -446
- package/packages/hive-ui/src/modules/agents/AgentDetail.tsx +0 -28
- package/packages/hive-ui/src/modules/agents/AgentInternalCard.tsx +0 -162
- package/packages/hive-ui/src/modules/agents/AgentList.tsx +0 -29
- package/packages/hive-ui/src/modules/agents/AgentStatusBadge.tsx +0 -34
- package/packages/hive-ui/src/modules/agents/ModelSelector.tsx +0 -151
- package/packages/hive-ui/src/modules/bridge/BridgeLogViewer.tsx +0 -61
- package/packages/hive-ui/src/modules/bridge/BridgeProcessList.tsx +0 -77
- package/packages/hive-ui/src/modules/bridge/BridgeStatus.tsx +0 -23
- package/packages/hive-ui/src/modules/bridge/BridgeTerminal.tsx +0 -7
- package/packages/hive-ui/src/modules/canvas/CanvasButton.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasChart.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasComponentMap.tsx +0 -605
- package/packages/hive-ui/src/modules/canvas/CanvasContainer.tsx +0 -360
- package/packages/hive-ui/src/modules/canvas/CanvasForm.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasMarkdown.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/CanvasTable.tsx +0 -3
- package/packages/hive-ui/src/modules/canvas/ComponentRenderer.tsx +0 -30
- package/packages/hive-ui/src/modules/canvas/DynamicRenderer.tsx +0 -3
- package/packages/hive-ui/src/modules/channels/available/AvailableChannelsGrid.tsx +0 -89
- package/packages/hive-ui/src/modules/channels/available/ChannelAuthForm.tsx +0 -33
- package/packages/hive-ui/src/modules/channels/available/ChannelSetupWizard.tsx +0 -48
- package/packages/hive-ui/src/modules/channels/available/ChannelTestConnection.tsx +0 -37
- package/packages/hive-ui/src/modules/channels/available/ChannelTypeCard.tsx +0 -30
- package/packages/hive-ui/src/modules/channels/available/ChannelWebhookConfig.tsx +0 -30
- package/packages/hive-ui/src/modules/channels/available/index.ts +0 -6
- package/packages/hive-ui/src/modules/channels/connected/ChannelCard.tsx +0 -95
- package/packages/hive-ui/src/modules/channels/connected/ChannelConfigPanel.tsx +0 -260
- package/packages/hive-ui/src/modules/channels/connected/ChannelDisconnectButton.tsx +0 -21
- package/packages/hive-ui/src/modules/channels/connected/ChannelLogsViewer.tsx +0 -42
- package/packages/hive-ui/src/modules/channels/connected/ChannelQRCode.tsx +0 -32
- package/packages/hive-ui/src/modules/channels/connected/ChannelReconnectButton.tsx +0 -16
- package/packages/hive-ui/src/modules/channels/connected/ChannelStatusBadge.tsx +0 -26
- package/packages/hive-ui/src/modules/channels/connected/ConnectedChannelsList.tsx +0 -40
- package/packages/hive-ui/src/modules/channels/connected/index.ts +0 -8
- package/packages/hive-ui/src/modules/channels/shared/ChannelCard.tsx +0 -84
- package/packages/hive-ui/src/modules/channels/shared/ChannelConfigDialog.tsx +0 -279
- package/packages/hive-ui/src/modules/channels/shared/ChannelIcon.tsx +0 -40
- package/packages/hive-ui/src/modules/channels/shared/ChannelStats.tsx +0 -37
- package/packages/hive-ui/src/modules/channels/shared/ChannelTypeBadge.tsx +0 -23
- package/packages/hive-ui/src/modules/channels/shared/ConnectionHealthIndicator.tsx +0 -20
- package/packages/hive-ui/src/modules/channels/shared/MessagePreview.tsx +0 -19
- package/packages/hive-ui/src/modules/channels/shared/index.ts +0 -5
- package/packages/hive-ui/src/modules/chat/ChatContainer.tsx +0 -268
- package/packages/hive-ui/src/modules/chat/ChatHistory.tsx +0 -101
- package/packages/hive-ui/src/modules/chat/ChatInput.tsx +0 -108
- package/packages/hive-ui/src/modules/chat/ChatMessage.tsx +0 -137
- package/packages/hive-ui/src/modules/chat/ThinkingIndicator.tsx +0 -10
- package/packages/hive-ui/src/modules/layout/AppLayout.tsx +0 -45
- package/packages/hive-ui/src/modules/layout/ConnectionStatus.tsx +0 -19
- package/packages/hive-ui/src/modules/layout/Header.tsx +0 -20
- package/packages/hive-ui/src/modules/layout/HiveSidebar.tsx +0 -173
- package/packages/hive-ui/src/modules/layout/ThemeToggle.tsx +0 -18
- package/packages/hive-ui/src/modules/providers/ProviderCard.tsx +0 -319
- package/packages/hive-ui/src/modules/providers/ProviderConfigForm.tsx +0 -146
- package/packages/hive-ui/src/modules/providers/ProviderFailoverConfig.tsx +0 -110
- package/packages/hive-ui/src/modules/providers/ProviderList.tsx +0 -33
- package/packages/hive-ui/src/modules/providers/ProviderStatusIndicator.tsx +0 -23
- package/packages/hive-ui/src/modules/providers/configs/ProviderAPIKeyManager.tsx +0 -39
- package/packages/hive-ui/src/modules/providers/configs/ProviderEndpointConfig.tsx +0 -27
- package/packages/hive-ui/src/modules/providers/configs/ProviderRateLimits.tsx +0 -37
- package/packages/hive-ui/src/modules/providers/configs/ProviderRetryPolicy.tsx +0 -46
- package/packages/hive-ui/src/modules/providers/configs/index.ts +0 -4
- package/packages/hive-ui/src/modules/providers/index.ts +0 -5
- package/packages/hive-ui/src/modules/providers/models/ModelBenchmarkBadge.tsx +0 -21
- package/packages/hive-ui/src/modules/providers/models/ModelCapabilities.tsx +0 -44
- package/packages/hive-ui/src/modules/providers/models/ModelCard.tsx +0 -36
- package/packages/hive-ui/src/modules/providers/models/ModelComparisonTable.tsx +0 -47
- package/packages/hive-ui/src/modules/providers/models/ModelList.tsx +0 -51
- package/packages/hive-ui/src/modules/providers/models/ModelPricingInfo.tsx +0 -17
- package/packages/hive-ui/src/modules/providers/models/ModelSelector.tsx +0 -32
- package/packages/hive-ui/src/modules/providers/models/index.ts +0 -7
- package/packages/hive-ui/src/pages/AgentDetailPage.tsx +0 -74
- package/packages/hive-ui/src/pages/AgentNewPage.tsx +0 -5
- package/packages/hive-ui/src/pages/AgentsPage.tsx +0 -147
- package/packages/hive-ui/src/pages/BridgePage.tsx +0 -83
- package/packages/hive-ui/src/pages/CanvasPage.tsx +0 -32
- package/packages/hive-ui/src/pages/ChannelsPage.tsx +0 -176
- package/packages/hive-ui/src/pages/DashboardPage.tsx +0 -321
- package/packages/hive-ui/src/pages/Index.tsx +0 -14
- package/packages/hive-ui/src/pages/LogsPage.tsx +0 -252
- package/packages/hive-ui/src/pages/NotFound.tsx +0 -24
- package/packages/hive-ui/src/pages/ProjectsPage.tsx +0 -241
- package/packages/hive-ui/src/pages/ProvidersPage.tsx +0 -111
- package/packages/hive-ui/src/pages/SettingsPage.tsx +0 -147
- package/packages/hive-ui/src/pages/SetupPage.tsx +0 -1177
- package/packages/hive-ui/src/pages/WebChatPage.tsx +0 -15
- package/packages/hive-ui/src/stores/agentConfigStore.ts +0 -32
- package/packages/hive-ui/src/stores/agentStore.ts +0 -5
- package/packages/hive-ui/src/stores/bridgeStore.ts +0 -237
- package/packages/hive-ui/src/stores/canvasStore.ts +0 -250
- package/packages/hive-ui/src/stores/channelStore.ts +0 -5
- package/packages/hive-ui/src/stores/chatStore.ts +0 -42
- package/packages/hive-ui/src/stores/ethicsStore.ts +0 -141
- package/packages/hive-ui/src/stores/mcpStore.ts +0 -5
- package/packages/hive-ui/src/stores/modelStore.ts +0 -2
- package/packages/hive-ui/src/stores/projectsStore.ts +0 -141
- package/packages/hive-ui/src/stores/providerStore.ts +0 -2
- package/packages/hive-ui/src/stores/skillStore.ts +0 -5
- package/packages/hive-ui/src/stores/toolStore.ts +0 -5
- package/packages/hive-ui/src/stores/useGlobalConfigStore.ts +0 -937
- package/packages/hive-ui/src/stores/useLoaderStore.ts +0 -21
- package/packages/hive-ui/src/stores/useNotesAndCronsStore.ts +0 -144
- package/packages/hive-ui/src/stores/useWebSocketStore.ts +0 -152
- package/packages/hive-ui/src/stores/useWelcomeStore.ts +0 -37
- package/packages/hive-ui/src/stores/userConfigStore.ts +0 -23
- package/packages/hive-ui/src/stores/userStore.ts +0 -82
- package/packages/hive-ui/src/test/setup.ts +0 -15
- package/packages/hive-ui/src/types/agent-config.ts +0 -33
- package/packages/hive-ui/src/types/agent.ts +0 -65
- package/packages/hive-ui/src/types/bridge.ts +0 -27
- package/packages/hive-ui/src/types/canvas.ts +0 -76
- package/packages/hive-ui/src/types/channels.ts +0 -109
- package/packages/hive-ui/src/types/chat.ts +0 -25
- package/packages/hive-ui/src/types/connections.ts +0 -17
- package/packages/hive-ui/src/types/ethics.ts +0 -41
- package/packages/hive-ui/src/types/index.ts +0 -15
- package/packages/hive-ui/src/types/mcp.ts +0 -36
- package/packages/hive-ui/src/types/notes-crons.ts +0 -31
- package/packages/hive-ui/src/types/providers.ts +0 -145
- package/packages/hive-ui/src/types/skill.ts +0 -12
- package/packages/hive-ui/src/types/tool.ts +0 -44
- package/packages/hive-ui/src/types/user.ts +0 -26
- package/packages/hive-ui/src/types/websocket.ts +0 -14
- package/packages/hive-ui/src/vite-env.d.ts +0 -1
- package/packages/mcp/package.json +0 -26
- package/packages/mcp/src/config.ts +0 -13
- package/packages/mcp/src/index.ts +0 -1
- package/packages/mcp/src/logger.ts +0 -42
- package/packages/mcp/src/manager.ts +0 -439
- package/packages/mcp/src/transports/index.ts +0 -67
- package/packages/mcp/src/transports/sse.ts +0 -241
- package/packages/mcp/src/transports/websocket.ts +0 -159
- package/packages/skills/package.json +0 -21
- package/packages/skills/src/index.ts +0 -1
- package/packages/skills/src/loader.ts +0 -346
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// ─── Tool narration map ───────────────────────────────────────────────────────
|
|
2
|
-
// Maps tool name prefixes/exact names to human-readable Spanish narrations.
|
|
3
|
-
// Shown to the user while the agent executes a tool.
|
|
4
|
-
export const TOOL_NARRATIONS: Record<string, string> = {
|
|
5
|
-
// Web
|
|
6
|
-
web_search: "Buscando en la web...",
|
|
7
|
-
web_fetch: "Leyendo página web...",
|
|
8
|
-
// Files
|
|
9
|
-
read: "Leyendo archivo...",
|
|
10
|
-
write: "Escribiendo archivo...",
|
|
11
|
-
edit: "Editando archivo...",
|
|
12
|
-
exec: "Ejecutando comando...",
|
|
13
|
-
// Cron
|
|
14
|
-
cron_add: "Programando tarea...",
|
|
15
|
-
cron_list: "Consultando tareas programadas...",
|
|
16
|
-
cron_remove: "Eliminando tarea programada...",
|
|
17
|
-
cron_edit: "Actualizando tarea programada...",
|
|
18
|
-
// Projects
|
|
19
|
-
project_create: "Creando proyecto...",
|
|
20
|
-
project_update: "Actualizando proyecto...",
|
|
21
|
-
project_done: "Marcando proyecto como completado...",
|
|
22
|
-
project_fail: "Registrando falla en el proyecto...",
|
|
23
|
-
task_create: "Creando tarea...",
|
|
24
|
-
task_update: "Actualizando tarea...",
|
|
25
|
-
// Agents
|
|
26
|
-
create_agent: "Creando agente worker...",
|
|
27
|
-
find_agent: "Buscando agente disponible...",
|
|
28
|
-
archive_agent: "Archivando agente...",
|
|
29
|
-
// Memory
|
|
30
|
-
save_note: "Guardando nota...",
|
|
31
|
-
memory_write: "Guardando en memoria...",
|
|
32
|
-
memory_read: "Leyendo memoria...",
|
|
33
|
-
memory_search: "Buscando en memoria...",
|
|
34
|
-
memory_delete: "Eliminando de memoria...",
|
|
35
|
-
memory_list: "Listando notas...",
|
|
36
|
-
// Browser
|
|
37
|
-
browser_navigate: "Navegando a la página...",
|
|
38
|
-
browser_click: "Haciendo clic...",
|
|
39
|
-
browser_type: "Escribiendo en la página...",
|
|
40
|
-
browser_screenshot: "Tomando captura de pantalla...",
|
|
41
|
-
browser_extract: "Extrayendo información de la página...",
|
|
42
|
-
// Canvas
|
|
43
|
-
canvas_add_node: "Actualizando canvas...",
|
|
44
|
-
canvas_update: "Actualizando canvas...",
|
|
45
|
-
// Code Bridge
|
|
46
|
-
bridge_send: "Enviando tarea al CLI...",
|
|
47
|
-
bridge_exec: "Ejecutando en el Code Bridge...",
|
|
48
|
-
// Notify
|
|
49
|
-
notify: "Enviando notificación...",
|
|
50
|
-
report_progress: "Reportando progreso...",
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function getNarration(toolName: string): string {
|
|
54
|
-
if (TOOL_NARRATIONS[toolName]) return TOOL_NARRATIONS[toolName]
|
|
55
|
-
// Prefix matching for MCP tools like "github__create_pr" → "Ejecutando github..."
|
|
56
|
-
const prefix = toolName.split("__")[0]
|
|
57
|
-
if (prefix && prefix !== toolName) return `Ejecutando ${prefix}...`
|
|
58
|
-
// Fallback
|
|
59
|
-
return `Ejecutando ${toolName.replace(/_/g, " ")}...`
|
|
60
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as path from "node:path";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Expands a path that starts with ~ to the user's home directory.
|
|
5
|
-
* @param p - The path to expand
|
|
6
|
-
* @returns The expanded path
|
|
7
|
-
*/
|
|
8
|
-
export function expandPath(p: string): string {
|
|
9
|
-
if (p.startsWith("~")) {
|
|
10
|
-
return path.join(process.env.HOME ?? "", p.slice(1));
|
|
11
|
-
}
|
|
12
|
-
return p;
|
|
13
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../../config/loader.ts";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Redacts a sensitive value by showing only the first 4 characters.
|
|
5
|
-
* @param value - The value to redact
|
|
6
|
-
* @returns The redacted value or a string of bullets if too short
|
|
7
|
-
*/
|
|
8
|
-
export function redactValue(value: string): string {
|
|
9
|
-
if (!value || value.length < 8) return "••••••••";
|
|
10
|
-
return `${value.slice(0, 4)}••••••••`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Redacts sensitive information from a config object for safe exposure.
|
|
15
|
-
* @param cfg - The config object to redact
|
|
16
|
-
* @returns A new config object with sensitive values redacted
|
|
17
|
-
*/
|
|
18
|
-
export function redactConfig(cfg: Config): Record<string, unknown> {
|
|
19
|
-
const redacted = JSON.parse(JSON.stringify(cfg)) as any;
|
|
20
|
-
|
|
21
|
-
// Redact gateway authToken
|
|
22
|
-
if (redacted.gateway?.authToken) {
|
|
23
|
-
redacted.gateway.authToken = redactValue(redacted.gateway.authToken);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Redact provider API keys
|
|
27
|
-
if (redacted.models?.providers) {
|
|
28
|
-
for (const provider of Object.values(redacted.models.providers) as any[]) {
|
|
29
|
-
if (provider?.apiKey) provider.apiKey = redactValue(provider.apiKey);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Redact channel tokens
|
|
34
|
-
if (redacted.channels) {
|
|
35
|
-
for (const channel of Object.values(redacted.channels) as any[]) {
|
|
36
|
-
if (channel?.accounts) {
|
|
37
|
-
for (const acc of Object.values(channel.accounts) as any[]) {
|
|
38
|
-
if (acc?.botToken) acc.botToken = redactValue(acc.botToken);
|
|
39
|
-
if (acc?.appToken) acc.appToken = redactValue(acc.appToken);
|
|
40
|
-
if (acc?.signingSecret) acc.signingSecret = redactValue(acc.signingSecret);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Redact MCP server headers
|
|
47
|
-
if (redacted.mcp?.servers) {
|
|
48
|
-
for (const server of Object.values(redacted.mcp.servers) as any[]) {
|
|
49
|
-
if (server?.headers) {
|
|
50
|
-
for (const [k, v] of Object.entries(server.headers)) {
|
|
51
|
-
const lk = k.toLowerCase();
|
|
52
|
-
if (lk.includes("auth") || lk.includes("token") || lk.includes("key")) {
|
|
53
|
-
server.headers[k] = redactValue(v as string);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return redacted;
|
|
61
|
-
}
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../config/loader";
|
|
2
|
-
import { logger } from "../utils/logger";
|
|
3
|
-
import { getDb, initializeDatabase, getDbPathLazy } from "../storage/sqlite";
|
|
4
|
-
import { buildAgentLoop } from "../agent/agent-loop";
|
|
5
|
-
import { AgentRunner } from "../agent/providers/index";
|
|
6
|
-
import { ChannelManager } from "../channels/manager";
|
|
7
|
-
import { syncToolsToFTS, syncSkillsToFTS, syncPlaybookToFTS } from "../agent/context-compiler";
|
|
8
|
-
import { AgentService, createAgentService } from "../agent/service";
|
|
9
|
-
import { mkdirSync, existsSync } from "node:fs";
|
|
10
|
-
import * as path from "node:path";
|
|
11
|
-
import { resolveAgentId } from "../storage/onboarding";
|
|
12
|
-
import { createMCPManager, type MCPClientManager } from "@johpaz/hive-mcp";
|
|
13
|
-
import { setMCPManager } from "../mcp/singleton";
|
|
14
|
-
import { startMCPHotReload } from "../mcp/hot-reload";
|
|
15
|
-
|
|
16
|
-
const log = logger.child("gateway:init");
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Verifica que exista al menos un usuario en la base de datos
|
|
20
|
-
*/
|
|
21
|
-
export async function verifyDatabaseUsers(): Promise<void> {
|
|
22
|
-
// Setup mode: no DB yet — skip verification, gateway starts to serve the web setup
|
|
23
|
-
if (!existsSync(getDbPathLazy())) {
|
|
24
|
-
log.info("Setup mode: no database found — gateway will serve web setup at /setup");
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
initializeDatabase();
|
|
30
|
-
|
|
31
|
-
const db = getDb();
|
|
32
|
-
const userCount = db.query("SELECT COUNT(*) as count FROM users").get() as { count: number };
|
|
33
|
-
|
|
34
|
-
if (userCount.count === 0) {
|
|
35
|
-
const error = new Error("No users found in the database. A valid user is required to start the Hive Gateway.");
|
|
36
|
-
log.error(error.message);
|
|
37
|
-
log.error("Please run the onboarding process or manually insert a user.");
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
log.info(`Database verified: ${userCount.count} user(s) found`);
|
|
42
|
-
} catch (error) {
|
|
43
|
-
log.error(`Database verification failed: ${(error as Error).message}`);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Escribe el archivo PID del proceso
|
|
50
|
-
*/
|
|
51
|
-
export async function writePidFile(pidFile: string): Promise<void> {
|
|
52
|
-
try {
|
|
53
|
-
const dir = path.dirname(pidFile);
|
|
54
|
-
mkdirSync(dir, { recursive: true });
|
|
55
|
-
await Bun.write(pidFile, process.pid.toString());
|
|
56
|
-
log.info(`PID file written: ${pidFile}`);
|
|
57
|
-
} catch (error) {
|
|
58
|
-
log.warn(`Could not write PID file: ${(error as Error).message}`);
|
|
59
|
-
// No throw - PID file is not critical
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Carga la configuración del agente desde la base de datos
|
|
65
|
-
* @returns Provider y modelo configurados
|
|
66
|
-
*/
|
|
67
|
-
export async function loadAgentConfigFromDB(
|
|
68
|
-
config: Config
|
|
69
|
-
): Promise<{ provider: string; model: string }> {
|
|
70
|
-
const defaultProvider = "gemini";
|
|
71
|
-
const defaultModel = "gemini-2.5-flash";
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
const db = getDb();
|
|
75
|
-
|
|
76
|
-
// Get coordinator agent ID from database
|
|
77
|
-
const coordinatorAgentId = resolveAgentId(null);
|
|
78
|
-
|
|
79
|
-
// Obtener configuración del agente coordinador
|
|
80
|
-
const agentConfig = db.query(`
|
|
81
|
-
SELECT provider_id, model_id FROM agents
|
|
82
|
-
WHERE id = ? OR role = 'coordinator'
|
|
83
|
-
ORDER BY (CASE WHEN id = ? THEN 1 ELSE 0 END) DESC
|
|
84
|
-
LIMIT 1
|
|
85
|
-
`).get(coordinatorAgentId || "", coordinatorAgentId || "") as
|
|
86
|
-
{ provider_id: string | null; model_id: string | null } | undefined;
|
|
87
|
-
|
|
88
|
-
let provider = agentConfig?.provider_id || defaultProvider;
|
|
89
|
-
let model = agentConfig?.model_id || defaultModel;
|
|
90
|
-
|
|
91
|
-
// Cargar API keys de los providers desde la DB
|
|
92
|
-
const providers = db.query(`
|
|
93
|
-
SELECT id, name, api_key_encrypted, api_key_iv, base_url
|
|
94
|
-
FROM providers
|
|
95
|
-
WHERE active = 1 AND api_key_encrypted IS NOT NULL
|
|
96
|
-
`).all() as Array<{
|
|
97
|
-
id: string;
|
|
98
|
-
name: string;
|
|
99
|
-
api_key_encrypted: string;
|
|
100
|
-
api_key_iv: string;
|
|
101
|
-
base_url: string | null
|
|
102
|
-
}>;
|
|
103
|
-
|
|
104
|
-
if (providers.length > 0) {
|
|
105
|
-
config.models = config.models || {};
|
|
106
|
-
config.models.providers = config.models.providers || {};
|
|
107
|
-
|
|
108
|
-
const { decryptApiKey } = await import("../storage/crypto");
|
|
109
|
-
|
|
110
|
-
for (const p of providers) {
|
|
111
|
-
const apiKey = await decryptApiKey(p.api_key_encrypted, p.api_key_iv);
|
|
112
|
-
|
|
113
|
-
config.models.providers[p.name] = {
|
|
114
|
-
apiKey,
|
|
115
|
-
baseUrl: p.base_url || undefined,
|
|
116
|
-
defaultModel: model,
|
|
117
|
-
availableModels: [],
|
|
118
|
-
maxRetries: 3,
|
|
119
|
-
timeoutMs: 30000,
|
|
120
|
-
} as any;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
log.info(`Loaded ${providers.length} provider(s) from DB with API keys`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
log.info(`Agent config loaded from DB: ${provider}/${model}`);
|
|
127
|
-
return { provider, model };
|
|
128
|
-
|
|
129
|
-
} catch (error) {
|
|
130
|
-
log.debug(`Could not read agent config from DB, using defaults: ${defaultProvider}/${defaultModel}`);
|
|
131
|
-
return { provider: defaultProvider, model: defaultModel };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Inicializa el agent loop
|
|
137
|
-
*/
|
|
138
|
-
export async function initializeAgentLoop(mcpManager?: any): Promise<void> {
|
|
139
|
-
try {
|
|
140
|
-
await buildAgentLoop({ mcpManager });
|
|
141
|
-
log.info("Agent loop initialized");
|
|
142
|
-
} catch (error) {
|
|
143
|
-
log.warn(`Agent loop initialization failed: ${(error as Error).message}`);
|
|
144
|
-
// No throw - agent loop can be rebuilt later
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Inicializa el runner de LLM
|
|
150
|
-
*/
|
|
151
|
-
export async function initializeLLMRunner(
|
|
152
|
-
config: Config,
|
|
153
|
-
provider: string,
|
|
154
|
-
model: string
|
|
155
|
-
): Promise<AgentRunner> {
|
|
156
|
-
try {
|
|
157
|
-
const runner = new AgentRunner(config);
|
|
158
|
-
log.info(`LLM runner initialized: ${provider}/${model}`);
|
|
159
|
-
return runner;
|
|
160
|
-
} catch (error) {
|
|
161
|
-
log.error(`Failed to initialize LLM runner: ${(error as Error).message}`);
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Inicializa el manager de canales
|
|
168
|
-
*/
|
|
169
|
-
export async function initializeChannelManager(
|
|
170
|
-
config: Config
|
|
171
|
-
): Promise<ChannelManager> {
|
|
172
|
-
try {
|
|
173
|
-
const channelManager = new ChannelManager(config);
|
|
174
|
-
await channelManager.initialize();
|
|
175
|
-
await channelManager.startAll();
|
|
176
|
-
log.info("Channel manager initialized and started");
|
|
177
|
-
return channelManager;
|
|
178
|
-
} catch (error) {
|
|
179
|
-
log.error(`Failed to initialize channel manager: ${(error as Error).message}`);
|
|
180
|
-
throw error;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Función principal de inicialización que orquesta todos los módulos
|
|
186
|
-
*/
|
|
187
|
-
export interface GatewayInitializationResult {
|
|
188
|
-
agent: AgentService;
|
|
189
|
-
runner: AgentRunner;
|
|
190
|
-
channelManager: ChannelManager;
|
|
191
|
-
provider: string;
|
|
192
|
-
model: string;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
export async function initializeGateway(
|
|
196
|
-
config: Config,
|
|
197
|
-
pidFile: string
|
|
198
|
-
): Promise<GatewayInitializationResult> {
|
|
199
|
-
// Setup mode: no DB file, OR DB exists but has no users (e.g. interrupted first run)
|
|
200
|
-
const isSetupMode = (): boolean => {
|
|
201
|
-
if (!existsSync(getDbPathLazy())) return true;
|
|
202
|
-
try {
|
|
203
|
-
initializeDatabase();
|
|
204
|
-
const count = (getDb().query("SELECT COUNT(*) as count FROM users").get() as { count: number }).count;
|
|
205
|
-
return count === 0;
|
|
206
|
-
} catch {
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
if (isSetupMode()) {
|
|
212
|
-
log.info("Setup mode: skipping full initialization — only setup routes will be available");
|
|
213
|
-
await writePidFile(pidFile);
|
|
214
|
-
// Return stubs; server.ts checks isSetupMode() before using these
|
|
215
|
-
return {
|
|
216
|
-
agent: null as any,
|
|
217
|
-
runner: null as any,
|
|
218
|
-
channelManager: null as any,
|
|
219
|
-
provider: "",
|
|
220
|
-
model: "",
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
try {
|
|
225
|
-
// 1. Verificar base de datos (crítico)
|
|
226
|
-
await verifyDatabaseUsers();
|
|
227
|
-
|
|
228
|
-
// 2. Escribir archivo PID (no crítico)
|
|
229
|
-
await writePidFile(pidFile);
|
|
230
|
-
|
|
231
|
-
// 3. Cargar configuración del agente desde DB
|
|
232
|
-
const { provider, model } = await loadAgentConfigFromDB(config);
|
|
233
|
-
|
|
234
|
-
// 4. Sync FTS5 indexes (tools + skills + playbook)
|
|
235
|
-
log.info("[initialize] Syncing FTS5 indexes (asynchronous & transactional)...")
|
|
236
|
-
try {
|
|
237
|
-
await Promise.all([
|
|
238
|
-
syncToolsToFTS(),
|
|
239
|
-
syncSkillsToFTS(),
|
|
240
|
-
syncPlaybookToFTS()
|
|
241
|
-
]);
|
|
242
|
-
log.info("[initialize] ✅ FTS5 indexes synced (tools, skills, playbook)")
|
|
243
|
-
} catch (err) {
|
|
244
|
-
log.error(`[initialize] FTS5 sync failed during startup: ${(err as Error).message}`);
|
|
245
|
-
// Consider if we should throw or continue. For now, continue but log error.
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// 5. Crear AgentService (reemplaza la clase Agent legacy)
|
|
249
|
-
const agent = createAgentService();
|
|
250
|
-
await agent.initialize();
|
|
251
|
-
|
|
252
|
-
// 6. Inicializar MCP Manager y agent loop
|
|
253
|
-
// MCP se inicializa con los servidores de la config + DB
|
|
254
|
-
let mcpManager: MCPClientManager | null = null;
|
|
255
|
-
|
|
256
|
-
// Load MCP servers from DB and merge with config
|
|
257
|
-
const db = getDb();
|
|
258
|
-
const dbServers = db.query(`SELECT * FROM mcp_servers WHERE enabled = 1`).all() as Record<string, any>[];
|
|
259
|
-
|
|
260
|
-
const mcpServersFromDB: Record<string, any> = {};
|
|
261
|
-
for (const server of dbServers) {
|
|
262
|
-
try {
|
|
263
|
-
const mcpServerConfig: any = {
|
|
264
|
-
transport: server.transport,
|
|
265
|
-
command: server.command,
|
|
266
|
-
args: server.args ? JSON.parse(server.args) : [],
|
|
267
|
-
url: server.url,
|
|
268
|
-
enabled: true,
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
// Decrypt headers if present
|
|
272
|
-
if (server.headers_encrypted && server.headers_iv) {
|
|
273
|
-
const { decryptConfig } = await import("../storage/crypto");
|
|
274
|
-
mcpServerConfig.headers = decryptConfig(server.headers_encrypted, server.headers_iv);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
mcpServersFromDB[server.id || server.name] = mcpServerConfig;
|
|
278
|
-
} catch (error) {
|
|
279
|
-
log.warn(`Failed to load MCP server ${server.name} from DB: ${(error as Error).message}`);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Merge config MCP servers with DB servers
|
|
284
|
-
const configMcpServers = config.mcp?.servers || {};
|
|
285
|
-
const mergedMcpServers = { ...configMcpServers, ...mcpServersFromDB };
|
|
286
|
-
|
|
287
|
-
if (Object.keys(mergedMcpServers).length > 0) {
|
|
288
|
-
try {
|
|
289
|
-
mcpManager = createMCPManager({
|
|
290
|
-
...config.mcp,
|
|
291
|
-
servers: mergedMcpServers,
|
|
292
|
-
});
|
|
293
|
-
await mcpManager.initialize();
|
|
294
|
-
setMCPManager(mcpManager); // Save to singleton for global access
|
|
295
|
-
log.info(`MCP Manager initialized with ${Object.keys(mergedMcpServers).length} server(s) from config + DB`);
|
|
296
|
-
|
|
297
|
-
// Start hot reload watcher for dynamic server changes
|
|
298
|
-
startMCPHotReload(mcpManager);
|
|
299
|
-
log.info("MCP Hot Reload started - new servers will auto-connect");
|
|
300
|
-
} catch (error) {
|
|
301
|
-
log.warn(`MCP Manager initialization failed: ${(error as Error).message}`);
|
|
302
|
-
}
|
|
303
|
-
} else {
|
|
304
|
-
log.info("No MCP servers found in config or DB");
|
|
305
|
-
// Initialize empty MCP Manager for hot reload to work
|
|
306
|
-
try {
|
|
307
|
-
mcpManager = createMCPManager({ servers: {} });
|
|
308
|
-
await mcpManager.initialize();
|
|
309
|
-
setMCPManager(mcpManager);
|
|
310
|
-
startMCPHotReload(mcpManager);
|
|
311
|
-
log.info("MCP Hot Reload started - waiting for first server");
|
|
312
|
-
} catch (error) {
|
|
313
|
-
log.warn(`Empty MCP Manager initialization failed: ${(error as Error).message}`);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Inicializar agent loop con MCP Manager
|
|
318
|
-
await initializeAgentLoop(mcpManager || undefined);
|
|
319
|
-
|
|
320
|
-
// 7. Inicializar LLM runner (crítico)
|
|
321
|
-
const runner = await initializeLLMRunner(config, provider, model);
|
|
322
|
-
|
|
323
|
-
// 8. Inicializar channel manager (crítico)
|
|
324
|
-
const channelManager = await initializeChannelManager(config);
|
|
325
|
-
|
|
326
|
-
return { agent, runner, channelManager, provider, model };
|
|
327
|
-
|
|
328
|
-
} catch (error) {
|
|
329
|
-
log.error(`Gateway initialization failed: ${(error as Error).message}`);
|
|
330
|
-
throw error;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
export type TaskStatus = "pending" | "running" | "completed" | "failed" | "cancelled";
|
|
2
|
-
|
|
3
|
-
export interface Task {
|
|
4
|
-
id: string;
|
|
5
|
-
sessionId: string;
|
|
6
|
-
status: TaskStatus;
|
|
7
|
-
priority: number;
|
|
8
|
-
createdAt: Date;
|
|
9
|
-
startedAt?: Date;
|
|
10
|
-
completedAt?: Date;
|
|
11
|
-
error?: string;
|
|
12
|
-
abortController: AbortController;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface LaneQueueOptions {
|
|
16
|
-
maxConcurrency?: number;
|
|
17
|
-
taskTimeoutMs?: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
type TaskHandler<T> = (task: Task, signal: AbortSignal) => Promise<T>;
|
|
21
|
-
|
|
22
|
-
export class LaneQueue {
|
|
23
|
-
private queues: Map<string, Task[]> = new Map();
|
|
24
|
-
private running: Map<string, Task> = new Map();
|
|
25
|
-
private handlers: Map<string, TaskHandler<unknown>> = new Map();
|
|
26
|
-
private taskIdCounter = 0;
|
|
27
|
-
private options: Required<LaneQueueOptions>;
|
|
28
|
-
|
|
29
|
-
constructor(options: LaneQueueOptions = {}) {
|
|
30
|
-
this.options = {
|
|
31
|
-
maxConcurrency: options.maxConcurrency ?? 1,
|
|
32
|
-
taskTimeoutMs: options.taskTimeoutMs ?? 300000,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private generateTaskId(): string {
|
|
37
|
-
return `task-${Date.now()}-${++this.taskIdCounter}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private getQueue(sessionId: string): Task[] {
|
|
41
|
-
let queue = this.queues.get(sessionId);
|
|
42
|
-
if (!queue) {
|
|
43
|
-
queue = [];
|
|
44
|
-
this.queues.set(sessionId, queue);
|
|
45
|
-
}
|
|
46
|
-
return queue;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
enqueue<T>(
|
|
50
|
-
sessionId: string,
|
|
51
|
-
handler: TaskHandler<T>,
|
|
52
|
-
priority = 0
|
|
53
|
-
): Task {
|
|
54
|
-
const task: Task = {
|
|
55
|
-
id: this.generateTaskId(),
|
|
56
|
-
sessionId,
|
|
57
|
-
status: "pending",
|
|
58
|
-
priority,
|
|
59
|
-
createdAt: new Date(),
|
|
60
|
-
abortController: new AbortController(),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
this.handlers.set(task.id, handler as TaskHandler<unknown>);
|
|
64
|
-
|
|
65
|
-
const queue = this.getQueue(sessionId);
|
|
66
|
-
queue.push(task);
|
|
67
|
-
queue.sort((a, b) => b.priority - a.priority);
|
|
68
|
-
|
|
69
|
-
this.processQueue(sessionId);
|
|
70
|
-
|
|
71
|
-
return task;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private async processQueue(sessionId: string): Promise<void> {
|
|
75
|
-
const running = this.running.get(sessionId);
|
|
76
|
-
if (running) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const queue = this.getQueue(sessionId);
|
|
81
|
-
if (queue.length === 0) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const task = queue.shift();
|
|
86
|
-
if (!task) return;
|
|
87
|
-
|
|
88
|
-
task.status = "running";
|
|
89
|
-
task.startedAt = new Date();
|
|
90
|
-
this.running.set(sessionId, task);
|
|
91
|
-
|
|
92
|
-
const handler = this.handlers.get(task.id);
|
|
93
|
-
|
|
94
|
-
const timeoutId = setTimeout(() => {
|
|
95
|
-
task.abortController.abort();
|
|
96
|
-
}, this.options.taskTimeoutMs);
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
if (handler) {
|
|
100
|
-
await handler(task, task.abortController.signal);
|
|
101
|
-
}
|
|
102
|
-
task.status = "completed";
|
|
103
|
-
task.completedAt = new Date();
|
|
104
|
-
} catch (error) {
|
|
105
|
-
if ((error as Error).name === "AbortError") {
|
|
106
|
-
task.status = "cancelled";
|
|
107
|
-
} else {
|
|
108
|
-
task.status = "failed";
|
|
109
|
-
task.error = (error as Error).message;
|
|
110
|
-
}
|
|
111
|
-
task.completedAt = new Date();
|
|
112
|
-
} finally {
|
|
113
|
-
clearTimeout(timeoutId);
|
|
114
|
-
this.running.delete(sessionId);
|
|
115
|
-
this.handlers.delete(task.id);
|
|
116
|
-
|
|
117
|
-
if (queue.length > 0) {
|
|
118
|
-
this.processQueue(sessionId);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
cancel(sessionId: string): boolean {
|
|
124
|
-
const task = this.running.get(sessionId);
|
|
125
|
-
if (task) {
|
|
126
|
-
task.abortController.abort();
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const queue = this.getQueue(sessionId);
|
|
131
|
-
const index = queue.findIndex((t) => t.status === "pending");
|
|
132
|
-
if (index >= 0) {
|
|
133
|
-
const cancelled = queue.splice(index, 1)[0];
|
|
134
|
-
if (cancelled) {
|
|
135
|
-
cancelled.status = "cancelled";
|
|
136
|
-
cancelled.completedAt = new Date();
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
getStatus(sessionId: string): {
|
|
145
|
-
queueLength: number;
|
|
146
|
-
running?: Task;
|
|
147
|
-
} {
|
|
148
|
-
const queue = this.getQueue(sessionId);
|
|
149
|
-
const running = this.running.get(sessionId);
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
queueLength: queue.length,
|
|
153
|
-
running,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
isProcessing(sessionId: string): boolean {
|
|
158
|
-
return this.running.has(sessionId);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
prune(sessionId: string): void {
|
|
162
|
-
const queue = this.getQueue(sessionId);
|
|
163
|
-
if (queue.length === 0 && !this.running.has(sessionId)) {
|
|
164
|
-
this.queues.delete(sessionId);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export const laneQueue = new LaneQueue();
|