@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,260 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Client,
|
|
3
|
-
GatewayIntentBits,
|
|
4
|
-
Events,
|
|
5
|
-
type Message,
|
|
6
|
-
type TextChannel,
|
|
7
|
-
type DMChannel,
|
|
8
|
-
type NewsChannel,
|
|
9
|
-
} from "discord.js";
|
|
10
|
-
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage } from "./base.ts";
|
|
11
|
-
import { logger } from "../utils/logger.ts";
|
|
12
|
-
|
|
13
|
-
export interface DiscordConfig extends ChannelConfig {
|
|
14
|
-
botToken: string;
|
|
15
|
-
applicationId?: string;
|
|
16
|
-
guilds?: Record<string, unknown>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type DiscordTextChannel = TextChannel | DMChannel | NewsChannel;
|
|
20
|
-
|
|
21
|
-
export class DiscordChannel extends BaseChannel {
|
|
22
|
-
name = "discord";
|
|
23
|
-
accountId: string;
|
|
24
|
-
config: DiscordConfig;
|
|
25
|
-
|
|
26
|
-
private client?: Client;
|
|
27
|
-
private log = logger.child("discord");
|
|
28
|
-
private channelCache: Map<string, DiscordTextChannel> = new Map();
|
|
29
|
-
|
|
30
|
-
constructor(accountId: string, config: DiscordConfig) {
|
|
31
|
-
super();
|
|
32
|
-
this.accountId = accountId;
|
|
33
|
-
this.config = config;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async start(): Promise<void> {
|
|
37
|
-
if (!this.config.botToken) {
|
|
38
|
-
throw new Error("Discord bot token not configured");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this.client = new Client({
|
|
42
|
-
intents: [
|
|
43
|
-
GatewayIntentBits.Guilds,
|
|
44
|
-
GatewayIntentBits.GuildMessages,
|
|
45
|
-
GatewayIntentBits.DirectMessages,
|
|
46
|
-
GatewayIntentBits.MessageContent,
|
|
47
|
-
],
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
this.client.on(Events.MessageCreate, async (message) => {
|
|
51
|
-
await this.handleDiscordMessage(message);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.client.on(Events.Error, (error) => {
|
|
55
|
-
this.log.error(`Discord client error: ${error.message}`);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this.client.once(Events.ClientReady, () => {
|
|
59
|
-
this.log.info(`Discord bot started: ${this.client?.user?.tag ?? "unknown"}`);
|
|
60
|
-
this.running = true;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
try {
|
|
64
|
-
await this.client.login(this.config.botToken);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
this.log.error(`Failed to login to Discord: ${(error as Error).message}`);
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
private async handleDiscordMessage(message: Message): Promise<void> {
|
|
72
|
-
if (message.author.bot) return;
|
|
73
|
-
|
|
74
|
-
const isGuild = message.guild !== null;
|
|
75
|
-
const kind = isGuild ? "group" : "direct";
|
|
76
|
-
const peerId = isGuild
|
|
77
|
-
? `${message.guildId}:${message.channelId}:${message.author.id}`
|
|
78
|
-
: message.author.id;
|
|
79
|
-
|
|
80
|
-
if (!isGuild && !this.isUserAllowed(message.author.id)) {
|
|
81
|
-
this.log.debug(`Message from unauthorized user: ${message.author.id}`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const sessionId = this.formatSessionId(peerId, kind);
|
|
86
|
-
if (message.channel.isTextBased()) {
|
|
87
|
-
this.channelCache.set(sessionId, message.channel as DiscordTextChannel);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const audioAttachment = message.attachments.find(a =>
|
|
91
|
-
a.contentType?.startsWith("audio/") ||
|
|
92
|
-
a.url.endsWith(".mp3") ||
|
|
93
|
-
a.url.endsWith(".ogg") ||
|
|
94
|
-
a.url.endsWith(".webm") ||
|
|
95
|
-
a.url.endsWith(".wav")
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
const incomingMessage: IncomingMessage = {
|
|
99
|
-
sessionId,
|
|
100
|
-
channel: "discord",
|
|
101
|
-
accountId: this.accountId,
|
|
102
|
-
peerId,
|
|
103
|
-
peerKind: kind,
|
|
104
|
-
content: message.content || "",
|
|
105
|
-
audio: audioAttachment ? { url: audioAttachment.url, mimeType: audioAttachment.contentType || "audio/webm" } : undefined,
|
|
106
|
-
metadata: {
|
|
107
|
-
discord: {
|
|
108
|
-
guildId: message.guildId,
|
|
109
|
-
channelId: message.channelId,
|
|
110
|
-
userId: message.author.id,
|
|
111
|
-
username: message.author.username,
|
|
112
|
-
messageId: message.id,
|
|
113
|
-
roles: message.member?.roles.cache.map(r => r.id),
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
replyToId: message.reference?.messageId
|
|
117
|
-
? `discord:${message.reference.messageId}`
|
|
118
|
-
: undefined,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
await this.handleMessage(incomingMessage);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
async stop(): Promise<void> {
|
|
125
|
-
if (this.client) {
|
|
126
|
-
this.client.destroy();
|
|
127
|
-
this.running = false;
|
|
128
|
-
this.log.info("Discord bot stopped");
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private async getChannel(sessionId: string): Promise<DiscordTextChannel | null> {
|
|
133
|
-
const cached = this.channelCache.get(sessionId);
|
|
134
|
-
if (cached) return cached;
|
|
135
|
-
|
|
136
|
-
if (!this.client) return null;
|
|
137
|
-
|
|
138
|
-
const parts = sessionId.split(":");
|
|
139
|
-
const peerPart = parts.slice(3).join(":");
|
|
140
|
-
|
|
141
|
-
let channelId: string;
|
|
142
|
-
if (peerPart.includes(":")) {
|
|
143
|
-
const channelPart = peerPart.split(":");
|
|
144
|
-
channelId = channelPart[1] ?? peerPart;
|
|
145
|
-
} else {
|
|
146
|
-
channelId = peerPart;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
const channel = await this.client.channels.fetch(channelId);
|
|
151
|
-
if (channel && channel.isTextBased()) {
|
|
152
|
-
this.channelCache.set(sessionId, channel as DiscordTextChannel);
|
|
153
|
-
return channel as DiscordTextChannel;
|
|
154
|
-
}
|
|
155
|
-
} catch {
|
|
156
|
-
// Channel not found
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return null;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async startTyping(sessionId: string): Promise<void> {
|
|
163
|
-
const channel = await this.getChannel(sessionId);
|
|
164
|
-
if (!channel) return;
|
|
165
|
-
|
|
166
|
-
await channel.sendTyping();
|
|
167
|
-
|
|
168
|
-
const interval = setInterval(async () => {
|
|
169
|
-
try {
|
|
170
|
-
await channel.sendTyping();
|
|
171
|
-
} catch {
|
|
172
|
-
this.stopTyping(sessionId);
|
|
173
|
-
}
|
|
174
|
-
}, 8000);
|
|
175
|
-
|
|
176
|
-
this.typingIntervals.set(sessionId, interval);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async stopTyping(sessionId: string): Promise<void> {
|
|
180
|
-
const interval = this.typingIntervals.get(sessionId);
|
|
181
|
-
if (interval) {
|
|
182
|
-
clearInterval(interval);
|
|
183
|
-
this.typingIntervals.delete(sessionId);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
async send(sessionId: string, message: OutboundMessage): Promise<void> {
|
|
188
|
-
await this.stopTyping(sessionId);
|
|
189
|
-
|
|
190
|
-
const channel = await this.getChannel(sessionId);
|
|
191
|
-
|
|
192
|
-
if (!channel) {
|
|
193
|
-
throw new Error(`Channel not found for session: ${sessionId}`);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
const content = message.content ?? "";
|
|
197
|
-
const maxLength = 2000;
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
if (content.length <= maxLength) {
|
|
201
|
-
await channel.send(content);
|
|
202
|
-
} else {
|
|
203
|
-
const chunks = this.chunkMessage(content, maxLength);
|
|
204
|
-
for (const chunk of chunks) {
|
|
205
|
-
await channel.send(chunk);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
this.log.error(`Failed to send Discord message: ${(error as Error).message}`);
|
|
210
|
-
throw error;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private chunkMessage(content: string, maxLength: number): string[] {
|
|
215
|
-
const chunks: string[] = [];
|
|
216
|
-
let remaining = content;
|
|
217
|
-
|
|
218
|
-
while (remaining.length > 0) {
|
|
219
|
-
if (remaining.length <= maxLength) {
|
|
220
|
-
chunks.push(remaining);
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
let splitPoint = remaining.lastIndexOf("\n", maxLength);
|
|
225
|
-
if (splitPoint === -1 || splitPoint < maxLength * 0.5) {
|
|
226
|
-
splitPoint = remaining.lastIndexOf(" ", maxLength);
|
|
227
|
-
}
|
|
228
|
-
if (splitPoint === -1 || splitPoint < maxLength * 0.5) {
|
|
229
|
-
splitPoint = maxLength;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
chunks.push(remaining.slice(0, splitPoint));
|
|
233
|
-
remaining = remaining.slice(splitPoint).trim();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return chunks;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async sendAudio(sessionId: string, audio: Buffer, mimeType: string): Promise<void> {
|
|
240
|
-
const channel = await this.getChannel(sessionId);
|
|
241
|
-
|
|
242
|
-
if (!channel) {
|
|
243
|
-
throw new Error(`Channel not found for session: ${sessionId}`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
const attachmentName = `response.${mimeType === "audio/mpeg" ? "mp3" : "ogg"}`;
|
|
248
|
-
await channel.send({
|
|
249
|
-
files: [{ attachment: audio, name: attachmentName }]
|
|
250
|
-
});
|
|
251
|
-
} catch (error) {
|
|
252
|
-
this.log.error(`Failed to send Discord audio: ${(error as Error).message}`);
|
|
253
|
-
throw error;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export function createDiscordChannel(accountId: string, config: DiscordConfig): DiscordChannel {
|
|
259
|
-
return new DiscordChannel(accountId, config);
|
|
260
|
-
}
|
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../config/loader.ts";
|
|
2
|
-
import { logger } from "../utils/logger.ts";
|
|
3
|
-
import type { IChannel, IncomingMessage, MessageHandler } from "./base.ts";
|
|
4
|
-
import { createTelegramChannel, type TelegramConfig } from "./telegram.ts";
|
|
5
|
-
import { createDiscordChannel, type DiscordConfig } from "./discord.ts";
|
|
6
|
-
import { createWebChatChannel, type WebChatConfig } from "./webchat.ts";
|
|
7
|
-
import { createWhatsAppChannel, type WhatsAppConfig } from "./whatsapp.ts";
|
|
8
|
-
import { createSlackChannel, type SlackConfig } from "./slack.ts";
|
|
9
|
-
import { getDb } from "../storage/sqlite.ts";
|
|
10
|
-
import { decryptConfig } from "../storage/crypto.ts";
|
|
11
|
-
|
|
12
|
-
export class ChannelManager {
|
|
13
|
-
private config: Config;
|
|
14
|
-
private channels: Map<string, IChannel> = new Map();
|
|
15
|
-
private messageHandler?: MessageHandler;
|
|
16
|
-
private log = logger.child("channels");
|
|
17
|
-
|
|
18
|
-
constructor(config: Config) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
onMessage(handler: MessageHandler): void {
|
|
23
|
-
this.messageHandler = handler;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
async initialize(): Promise<void> {
|
|
27
|
-
// Primero, intentar cargar canales desde la BD
|
|
28
|
-
await this.initializeFromDB();
|
|
29
|
-
|
|
30
|
-
// Si no hay canales en la BD, usar config
|
|
31
|
-
if (this.channels.size === 0) {
|
|
32
|
-
await this.initializeFromConfig();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.log.info(`Initialized ${this.channels.size} channel(s)`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private async initializeFromDB(): Promise<void> {
|
|
39
|
-
try {
|
|
40
|
-
const db = getDb();
|
|
41
|
-
// Load all active channels - config may be empty for webchat
|
|
42
|
-
const rows = db.query(`
|
|
43
|
-
SELECT id, type, config_encrypted, config_iv, enabled, active
|
|
44
|
-
FROM channels
|
|
45
|
-
WHERE enabled = 1 AND active = 1
|
|
46
|
-
`).all() as Array<{
|
|
47
|
-
id: string;
|
|
48
|
-
type: string;
|
|
49
|
-
config_encrypted: string | null;
|
|
50
|
-
config_iv: string | null;
|
|
51
|
-
enabled: number;
|
|
52
|
-
active: number;
|
|
53
|
-
}>;
|
|
54
|
-
|
|
55
|
-
for (const row of rows) {
|
|
56
|
-
let config: Record<string, unknown> = {};
|
|
57
|
-
|
|
58
|
-
if (row.config_encrypted && row.config_iv) {
|
|
59
|
-
try {
|
|
60
|
-
config = await decryptConfig(row.config_encrypted, row.config_iv);
|
|
61
|
-
this.log.debug(`Decrypted config for ${row.type}:${row.id}:`, Object.keys(config));
|
|
62
|
-
} catch (error) {
|
|
63
|
-
this.log.warn(`Failed to decrypt config for channel ${row.id}:`, (error as Error).message);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Use channel id as accountId
|
|
68
|
-
const accountId = row.id;
|
|
69
|
-
this.log.info(`Creating channel ${row.type}:${accountId} with config keys:`, Object.keys(config));
|
|
70
|
-
await this.createChannel(row.type, accountId, config);
|
|
71
|
-
}
|
|
72
|
-
} catch (error) {
|
|
73
|
-
this.log.debug("No channels found in DB or DB not initialized:", (error as Error).message);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
private async initializeFromConfig(): Promise<void> {
|
|
78
|
-
const channelConfigs = this.config.channels ?? {};
|
|
79
|
-
|
|
80
|
-
for (const [channelName, channelConfig] of Object.entries(channelConfigs)) {
|
|
81
|
-
// If enabled is explicitly false, skip
|
|
82
|
-
if (channelConfig.enabled === false) {
|
|
83
|
-
this.log.debug(`Channel ${channelName} is disabled`);
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const accounts = channelConfig.accounts;
|
|
88
|
-
if (!accounts || Object.keys(accounts).length === 0) {
|
|
89
|
-
this.log.warn(`Channel ${channelName} has no accounts configured`);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const [accountId, accountConfig] of Object.entries(accounts)) {
|
|
94
|
-
const fullConfig = { ...channelConfig, ...accountConfig };
|
|
95
|
-
await this.createChannel(channelName, accountId, fullConfig);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
private async createChannel(
|
|
101
|
-
channelName: string,
|
|
102
|
-
accountId: string,
|
|
103
|
-
config: Record<string, unknown>
|
|
104
|
-
): Promise<void> {
|
|
105
|
-
let channel: IChannel;
|
|
106
|
-
|
|
107
|
-
try {
|
|
108
|
-
switch (channelName) {
|
|
109
|
-
case "telegram":
|
|
110
|
-
channel = createTelegramChannel(accountId, {
|
|
111
|
-
enabled: true,
|
|
112
|
-
botToken: config.botToken as string,
|
|
113
|
-
dmPolicy: (config.dmPolicy as "open" | "pairing" | "allowlist") ?? "open",
|
|
114
|
-
allowFrom: (config.allowFrom as string[]) ?? [],
|
|
115
|
-
groups: (config.groups as boolean) ?? false,
|
|
116
|
-
} as TelegramConfig);
|
|
117
|
-
break;
|
|
118
|
-
|
|
119
|
-
case "discord":
|
|
120
|
-
channel = createDiscordChannel(accountId, {
|
|
121
|
-
enabled: true,
|
|
122
|
-
botToken: config.botToken as string,
|
|
123
|
-
applicationId: config.applicationId as string,
|
|
124
|
-
dmPolicy: (config.dmPolicy as "open" | "pairing" | "allowlist") ?? "allowlist",
|
|
125
|
-
allowFrom: (config.allowFrom as string[]) ?? [],
|
|
126
|
-
} as DiscordConfig);
|
|
127
|
-
break;
|
|
128
|
-
|
|
129
|
-
case "webchat":
|
|
130
|
-
channel = createWebChatChannel({
|
|
131
|
-
enabled: true,
|
|
132
|
-
dmPolicy: "open",
|
|
133
|
-
allowFrom: [],
|
|
134
|
-
} as WebChatConfig);
|
|
135
|
-
break;
|
|
136
|
-
|
|
137
|
-
case "whatsapp":
|
|
138
|
-
channel = createWhatsAppChannel({
|
|
139
|
-
enabled: true,
|
|
140
|
-
accountId,
|
|
141
|
-
agentId: (config.agentId as string) ?? "main",
|
|
142
|
-
dmPolicy: (config.dmPolicy as "open" | "pairing" | "allowlist") ?? "allowlist",
|
|
143
|
-
allowFrom: (config.allowFrom as string[]) ?? [],
|
|
144
|
-
reconnectMaxAttempts: (config.reconnectMaxAttempts as number) ?? 10,
|
|
145
|
-
reconnectBaseDelayMs: (config.reconnectBaseDelayMs as number) ?? 5000,
|
|
146
|
-
} as WhatsAppConfig);
|
|
147
|
-
break;
|
|
148
|
-
|
|
149
|
-
case "slack":
|
|
150
|
-
channel = createSlackChannel({
|
|
151
|
-
enabled: true,
|
|
152
|
-
botToken: config.botToken as string,
|
|
153
|
-
appToken: config.appToken as string,
|
|
154
|
-
signingSecret: config.signingSecret as string,
|
|
155
|
-
port: (config.port as number) ?? 3000,
|
|
156
|
-
dmPolicy: (config.dmPolicy as "open" | "pairing" | "allowlist") ?? "allowlist",
|
|
157
|
-
allowFrom: (config.allowFrom as string[]) ?? [],
|
|
158
|
-
} as SlackConfig);
|
|
159
|
-
break;
|
|
160
|
-
|
|
161
|
-
default:
|
|
162
|
-
this.log.warn(`Unknown channel type: ${channelName}`);
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
channel.onMessage(async (message: IncomingMessage) => {
|
|
167
|
-
if (this.messageHandler) {
|
|
168
|
-
await this.messageHandler(message);
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const key = `${channelName}:${accountId}`;
|
|
173
|
-
this.channels.set(key, channel);
|
|
174
|
-
|
|
175
|
-
this.log.info(`Created channel: ${key}`);
|
|
176
|
-
} catch (error) {
|
|
177
|
-
this.log.error(`Failed to create channel ${channelName}:${accountId}: ${(error as Error).message}`);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
async startAll(): Promise<void> {
|
|
182
|
-
const promises: Promise<void>[] = [];
|
|
183
|
-
|
|
184
|
-
for (const [key, channel] of this.channels) {
|
|
185
|
-
if (channel.isRunning()) {
|
|
186
|
-
this.log.info(`Channel ${key} is already running, skipping`);
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
promises.push(
|
|
190
|
-
channel.start().catch((error) => {
|
|
191
|
-
this.log.error(`Failed to start channel ${key}: ${error.message}`);
|
|
192
|
-
})
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
await Promise.allSettled(promises);
|
|
197
|
-
this.log.info("All channels started");
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async stopAll(): Promise<void> {
|
|
201
|
-
const promises: Promise<void>[] = [];
|
|
202
|
-
|
|
203
|
-
for (const [key, channel] of this.channels) {
|
|
204
|
-
promises.push(
|
|
205
|
-
channel.stop().catch((error) => {
|
|
206
|
-
this.log.error(`Failed to stop channel ${key}: ${error.message}`);
|
|
207
|
-
})
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
await Promise.allSettled(promises);
|
|
212
|
-
this.log.info("All channels stopped");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
getChannel(channelName: string, accountId?: string): IChannel | undefined {
|
|
216
|
-
if (accountId) {
|
|
217
|
-
return this.channels.get(`${channelName}:${accountId}`);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
for (const [key, channel] of this.channels) {
|
|
221
|
-
if (key.startsWith(channelName)) {
|
|
222
|
-
return channel;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return undefined;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async removeChannel(channelName: string, accountId: string): Promise<void> {
|
|
230
|
-
const key = `${channelName}:${accountId}`;
|
|
231
|
-
await this.stopChannel(channelName, accountId);
|
|
232
|
-
this.channels.delete(key);
|
|
233
|
-
this.log.info(`Removed channel: ${key}`);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
getAccountConfig(channelName: string, accountId: string): any {
|
|
237
|
-
const channelConfigs = (this.config.channels ?? {}) as Record<string, any>;
|
|
238
|
-
const channelConfig = channelConfigs[channelName];
|
|
239
|
-
if (!channelConfig) return null;
|
|
240
|
-
|
|
241
|
-
const accounts = channelConfig.accounts;
|
|
242
|
-
if (!accounts) return null;
|
|
243
|
-
return accounts[accountId] || null;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async startChannel(channelName: string, accountId: string): Promise<void> {
|
|
247
|
-
const key = `${channelName}:${accountId}`;
|
|
248
|
-
let channel = this.channels.get(key);
|
|
249
|
-
|
|
250
|
-
if (!channel) {
|
|
251
|
-
const channelConfigs = (this.config.channels ?? {}) as Record<string, any>;
|
|
252
|
-
const channelConfig = channelConfigs[channelName];
|
|
253
|
-
if (!channelConfig) {
|
|
254
|
-
throw new Error(`Channel configuration not found: ${channelName}`);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const accounts = channelConfig.accounts;
|
|
258
|
-
if (!accounts) {
|
|
259
|
-
throw new Error(`Accounts configuration not found for channel ${channelName}`);
|
|
260
|
-
}
|
|
261
|
-
const accountConfig = accounts[accountId];
|
|
262
|
-
if (!accountConfig) {
|
|
263
|
-
throw new Error(`Account configuration not found: ${accountId} for channel ${channelName}`);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const fullConfig = { ...channelConfig, ...(accountConfig ?? {}) };
|
|
267
|
-
await this.createChannel(channelName, accountId, fullConfig as any);
|
|
268
|
-
channel = this.channels.get(key);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (!channel) {
|
|
272
|
-
throw new Error(`Failed to instantiate channel: ${key}`);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (channel.isRunning()) {
|
|
276
|
-
this.log.info(`Channel ${key} is already running`);
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
await channel.start();
|
|
281
|
-
this.log.info(`Started channel: ${key}`);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
async stopChannel(channelName: string, accountId: string): Promise<void> {
|
|
285
|
-
const key = `${channelName}:${accountId}`;
|
|
286
|
-
const channel = this.channels.get(key);
|
|
287
|
-
|
|
288
|
-
if (!channel) {
|
|
289
|
-
this.log.warn(`Channel ${key} not found or not instantiated`);
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
if (!channel.isRunning()) {
|
|
294
|
-
this.log.info(`Channel ${key} is not running`);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
await channel.stop();
|
|
299
|
-
this.log.info(`Stopped channel: ${key}`);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
listAllAvailableChannels(): Array<{ name: string; accountId: string; running: boolean; enabled: boolean }> {
|
|
303
|
-
const available: Array<{ name: string; accountId: string; running: boolean; enabled: boolean }> = [];
|
|
304
|
-
const channelConfigs = (this.config.channels ?? {}) as Record<string, any>;
|
|
305
|
-
|
|
306
|
-
for (const [channelName, channelConfig] of Object.entries(channelConfigs)) {
|
|
307
|
-
const accounts = channelConfig.accounts;
|
|
308
|
-
if (!accounts) continue;
|
|
309
|
-
for (const accountId of Object.keys(accounts)) {
|
|
310
|
-
const key = `${channelName}:${accountId}`;
|
|
311
|
-
const channel = this.channels.get(key);
|
|
312
|
-
available.push({
|
|
313
|
-
name: channelName,
|
|
314
|
-
accountId: accountId,
|
|
315
|
-
running: channel ? channel.isRunning() : false,
|
|
316
|
-
enabled: channelConfig.enabled !== false,
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
return available;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
listChannels(): Array<{ name: string; accountId: string; running: boolean }> {
|
|
324
|
-
return Array.from(this.channels.entries()).map(([key, channel]) => {
|
|
325
|
-
const [name, accountId] = key.split(":");
|
|
326
|
-
return {
|
|
327
|
-
name: name ?? "unknown",
|
|
328
|
-
accountId: accountId ?? "unknown",
|
|
329
|
-
running: channel.isRunning(),
|
|
330
|
-
};
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
async send(
|
|
335
|
-
channelName: string,
|
|
336
|
-
sessionId: string,
|
|
337
|
-
message: unknown
|
|
338
|
-
): Promise<void> {
|
|
339
|
-
const channel = this.getChannel(channelName);
|
|
340
|
-
|
|
341
|
-
if (!channel) {
|
|
342
|
-
throw new Error(`Channel not found: ${channelName}`);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
await channel.send(sessionId, message as any);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
async startTyping(channelName: string, sessionId: string): Promise<void> {
|
|
349
|
-
const channel = this.getChannel(channelName);
|
|
350
|
-
if (channel?.startTyping) {
|
|
351
|
-
await channel.startTyping(sessionId);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
async stopTyping(channelName: string, sessionId: string): Promise<void> {
|
|
356
|
-
const channel = this.getChannel(channelName);
|
|
357
|
-
if (channel?.stopTyping) {
|
|
358
|
-
await channel.stopTyping(sessionId);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
async markAsRead(channelName: string, sessionId: string, messageId?: string): Promise<void> {
|
|
363
|
-
const channel = this.getChannel(channelName);
|
|
364
|
-
if (channel?.markAsRead) {
|
|
365
|
-
await channel.markAsRead(sessionId, messageId);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
async sendAudio(channelName: string, sessionId: string, audio: Buffer, mimeType: string): Promise<void> {
|
|
370
|
-
const channel = this.getChannel(channelName);
|
|
371
|
-
if (!channel) {
|
|
372
|
-
throw new Error(`Channel not found: ${channelName}`);
|
|
373
|
-
}
|
|
374
|
-
if (!channel.sendAudio) {
|
|
375
|
-
throw new Error(`Channel ${channelName} does not support audio`);
|
|
376
|
-
}
|
|
377
|
-
await channel.sendAudio(sessionId, audio, mimeType);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export function createChannelManager(config: Config): ChannelManager {
|
|
382
|
-
return new ChannelManager(config);
|
|
383
|
-
}
|