@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,321 +0,0 @@
|
|
|
1
|
-
import { spawn, type ChildProcess } from "child_process";
|
|
2
|
-
import { BaseChannel, type ChannelConfig, type IncomingMessage, type OutboundMessage } from "../channels/base.ts";
|
|
3
|
-
import { logger } from "../utils/logger.ts";
|
|
4
|
-
import { pairingService } from "./pairing.ts";
|
|
5
|
-
|
|
6
|
-
export interface SignalConfig extends ChannelConfig {
|
|
7
|
-
phoneNumber: string;
|
|
8
|
-
dataDir?: string;
|
|
9
|
-
signalCliPath?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface SignalMessage {
|
|
13
|
-
envelope: {
|
|
14
|
-
source: string;
|
|
15
|
-
sourceNumber?: string;
|
|
16
|
-
sourceName?: string;
|
|
17
|
-
timestamp: number;
|
|
18
|
-
dataMessage?: {
|
|
19
|
-
message?: string;
|
|
20
|
-
expiresInSeconds?: number;
|
|
21
|
-
};
|
|
22
|
-
syncMessage?: {
|
|
23
|
-
sentMessage?: {
|
|
24
|
-
destination?: string;
|
|
25
|
-
message?: string;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class SignalChannel extends BaseChannel {
|
|
32
|
-
name = "signal";
|
|
33
|
-
accountId: string;
|
|
34
|
-
config: SignalConfig;
|
|
35
|
-
|
|
36
|
-
private signalCli?: ChildProcess;
|
|
37
|
-
private log = logger.child("signal");
|
|
38
|
-
private messageBuffer = "";
|
|
39
|
-
private chatIdCache: Map<string, string> = new Map();
|
|
40
|
-
|
|
41
|
-
constructor(accountId: string, config: SignalConfig) {
|
|
42
|
-
super();
|
|
43
|
-
this.accountId = accountId;
|
|
44
|
-
this.config = {
|
|
45
|
-
...config,
|
|
46
|
-
dmPolicy: config.dmPolicy ?? "pairing",
|
|
47
|
-
allowFrom: config.allowFrom ?? [],
|
|
48
|
-
enabled: config.enabled ?? true,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async start(): Promise<void> {
|
|
53
|
-
if (!this.config.phoneNumber) {
|
|
54
|
-
throw new Error("Signal phone number not configured");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const signalCliPath = this.config.signalCliPath ?? "signal-cli";
|
|
58
|
-
const dataDir = this.config.dataDir;
|
|
59
|
-
|
|
60
|
-
const args = ["daemon", "--system"];
|
|
61
|
-
if (dataDir) {
|
|
62
|
-
args.push("--config", dataDir);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
this.log.info(`Starting signal-cli: ${signalCliPath} ${args.join(" ")}`);
|
|
66
|
-
|
|
67
|
-
this.signalCli = spawn(signalCliPath, args, {
|
|
68
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
this.signalCli.stdout?.on("data", (data: Buffer) => {
|
|
72
|
-
this.handleSignalOutput(data.toString());
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
this.signalCli.stderr?.on("data", (data: Buffer) => {
|
|
76
|
-
this.log.error(`signal-cli stderr: ${data.toString()}`);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this.signalCli.on("error", (error: Error) => {
|
|
80
|
-
this.log.error(`signal-cli error: ${error.message}`);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
this.signalCli.on("exit", (code, signal) => {
|
|
84
|
-
this.log.warn(`signal-cli exited with code ${code}, signal ${signal}`);
|
|
85
|
-
this.running = false;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
89
|
-
|
|
90
|
-
this.running = true;
|
|
91
|
-
this.log.info(`Signal channel started for ${this.config.phoneNumber}`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private handleSignalOutput(output: string): void {
|
|
95
|
-
this.messageBuffer += output;
|
|
96
|
-
|
|
97
|
-
const lines = this.messageBuffer.split("\n");
|
|
98
|
-
this.messageBuffer = lines.pop() ?? "";
|
|
99
|
-
|
|
100
|
-
for (const line of lines) {
|
|
101
|
-
if (line.trim()) {
|
|
102
|
-
this.parseSignalMessage(line);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private parseSignalMessage(line: string): void {
|
|
108
|
-
try {
|
|
109
|
-
const data: SignalMessage = JSON.parse(line);
|
|
110
|
-
|
|
111
|
-
if (data.envelope?.dataMessage?.message) {
|
|
112
|
-
const from = data.envelope.source;
|
|
113
|
-
const content = data.envelope.dataMessage.message;
|
|
114
|
-
const timestamp = data.envelope.timestamp;
|
|
115
|
-
|
|
116
|
-
this.handleIncomingMessage({
|
|
117
|
-
from,
|
|
118
|
-
content,
|
|
119
|
-
timestamp,
|
|
120
|
-
name: data.envelope.sourceName,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
} catch {
|
|
124
|
-
this.log.debug(`Non-JSON output: ${line.slice(0, 100)}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
private async handleIncomingMessage(msg: {
|
|
129
|
-
from: string;
|
|
130
|
-
content: string;
|
|
131
|
-
timestamp: number;
|
|
132
|
-
name?: string;
|
|
133
|
-
}): Promise<void> {
|
|
134
|
-
const peerId = msg.from;
|
|
135
|
-
const kind = "direct";
|
|
136
|
-
|
|
137
|
-
if (msg.content === "/myid") {
|
|
138
|
-
await this.sendDirectMessage(
|
|
139
|
-
peerId,
|
|
140
|
-
`🆔 Tu Signal ID es: ${peerId}\n\n` +
|
|
141
|
-
`Para emparejar, usa el comando:\n` +
|
|
142
|
-
`\`hive pairing generate signal ${peerId}\``
|
|
143
|
-
);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if (msg.content === "/pair" || msg.content.startsWith("/pair ")) {
|
|
148
|
-
const code = msg.content.split(" ")[1]?.trim();
|
|
149
|
-
|
|
150
|
-
if (!code) {
|
|
151
|
-
await this.sendDirectMessage(
|
|
152
|
-
peerId,
|
|
153
|
-
"🔐 Envía /pair CODIGO para emparejar.\n" +
|
|
154
|
-
"Solicita un código de emparejamiento al administrador."
|
|
155
|
-
);
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const result = pairingService.approve(code);
|
|
160
|
-
if (result.success) {
|
|
161
|
-
await this.sendDirectMessage(peerId, "✅ ¡Emparejamiento exitoso! Ya puedes usar el bot.");
|
|
162
|
-
} else {
|
|
163
|
-
await this.sendDirectMessage(peerId, `❌ ${result.error}`);
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (this.config.dmPolicy === "pairing" && !pairingService.isAllowed("signal", peerId)) {
|
|
169
|
-
this.log.debug(`Message from unpaired user: ${peerId}`);
|
|
170
|
-
await this.sendDirectMessage(
|
|
171
|
-
peerId,
|
|
172
|
-
"⛔ No estás emparejado.\n\n" +
|
|
173
|
-
"Tu Signal ID: " + peerId + "\n\n" +
|
|
174
|
-
"Solicita un código de emparejamiento al administrador y envíalo con:\n" +
|
|
175
|
-
"/pair CODIGO"
|
|
176
|
-
);
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (!this.isUserAllowed(peerId)) {
|
|
181
|
-
this.log.debug(`Message from unauthorized user: ${peerId}`);
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const sessionId = this.formatSessionId(peerId, kind);
|
|
186
|
-
this.chatIdCache.set(sessionId, peerId);
|
|
187
|
-
|
|
188
|
-
const incomingMessage: IncomingMessage = {
|
|
189
|
-
sessionId,
|
|
190
|
-
channel: "signal",
|
|
191
|
-
accountId: this.accountId,
|
|
192
|
-
peerId,
|
|
193
|
-
peerKind: kind,
|
|
194
|
-
content: msg.content,
|
|
195
|
-
metadata: {
|
|
196
|
-
signal: {
|
|
197
|
-
phoneNumber: peerId,
|
|
198
|
-
name: msg.name,
|
|
199
|
-
timestamp: msg.timestamp,
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
await this.handleMessage(incomingMessage);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
async stop(): Promise<void> {
|
|
208
|
-
if (this.signalCli) {
|
|
209
|
-
this.signalCli.kill("SIGTERM");
|
|
210
|
-
this.running = false;
|
|
211
|
-
this.log.info("Signal channel stopped");
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
async send(sessionId: string, message: OutboundMessage): Promise<void> {
|
|
216
|
-
const content = message.content ?? "";
|
|
217
|
-
|
|
218
|
-
if (!content || content.trim().length === 0) {
|
|
219
|
-
this.log.warn("Empty response, skipping send");
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const phoneNumber = this.chatIdCache.get(sessionId) ?? this.extractPhoneFromSession(sessionId);
|
|
224
|
-
|
|
225
|
-
if (!phoneNumber) {
|
|
226
|
-
throw new Error(`Cannot determine phone number for session: ${sessionId}`);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
await this.sendDirectMessage(phoneNumber, content);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private async sendDirectMessage(phoneNumber: string, content: string): Promise<void> {
|
|
233
|
-
const chunks = this.chunkMessage(content, 2000);
|
|
234
|
-
|
|
235
|
-
for (const chunk of chunks) {
|
|
236
|
-
await this.executeCli([
|
|
237
|
-
"send",
|
|
238
|
-
"-a", this.config.phoneNumber,
|
|
239
|
-
"-m", chunk,
|
|
240
|
-
phoneNumber,
|
|
241
|
-
]);
|
|
242
|
-
|
|
243
|
-
if (chunks.length > 1) {
|
|
244
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private async executeCli(args: string[]): Promise<string> {
|
|
250
|
-
return new Promise((resolve, reject) => {
|
|
251
|
-
const signalCliPath = this.config.signalCliPath ?? "signal-cli";
|
|
252
|
-
const fullArgs = this.config.dataDir
|
|
253
|
-
? ["--config", this.config.dataDir, ...args]
|
|
254
|
-
: args;
|
|
255
|
-
|
|
256
|
-
const proc = spawn(signalCliPath, fullArgs, {
|
|
257
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
let stdout = "";
|
|
261
|
-
let stderr = "";
|
|
262
|
-
|
|
263
|
-
proc.stdout?.on("data", (data: Buffer) => {
|
|
264
|
-
stdout += data.toString();
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
proc.stderr?.on("data", (data: Buffer) => {
|
|
268
|
-
stderr += data.toString();
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
proc.on("close", (code) => {
|
|
272
|
-
if (code === 0) {
|
|
273
|
-
resolve(stdout);
|
|
274
|
-
} else {
|
|
275
|
-
reject(new Error(`signal-cli failed: ${stderr || stdout}`));
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
proc.on("error", (error) => {
|
|
280
|
-
reject(error);
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private extractPhoneFromSession(sessionId: string): string | undefined {
|
|
286
|
-
const parts = sessionId.split(":");
|
|
287
|
-
return parts[4];
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
private chunkMessage(content: string, maxLength: number): string[] {
|
|
291
|
-
const chunks: string[] = [];
|
|
292
|
-
let remaining = content;
|
|
293
|
-
|
|
294
|
-
while (remaining.length > 0) {
|
|
295
|
-
if (remaining.length <= maxLength) {
|
|
296
|
-
chunks.push(remaining);
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
let splitPoint = remaining.lastIndexOf("\n\n", maxLength);
|
|
301
|
-
if (splitPoint === -1 || splitPoint < maxLength * 0.5) {
|
|
302
|
-
splitPoint = remaining.lastIndexOf("\n", maxLength);
|
|
303
|
-
}
|
|
304
|
-
if (splitPoint === -1 || splitPoint < maxLength * 0.5) {
|
|
305
|
-
splitPoint = remaining.lastIndexOf(" ", maxLength);
|
|
306
|
-
}
|
|
307
|
-
if (splitPoint === -1 || splitPoint < maxLength * 0.5) {
|
|
308
|
-
splitPoint = maxLength;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
chunks.push(remaining.slice(0, splitPoint));
|
|
312
|
-
remaining = remaining.slice(splitPoint).trim();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
return chunks;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export function createSignalChannel(accountId: string, config: SignalConfig): SignalChannel {
|
|
320
|
-
return new SignalChannel(accountId, config);
|
|
321
|
-
}
|
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { logger } from "../utils/logger.ts";
|
|
2
|
-
|
|
3
|
-
export interface SessionState {
|
|
4
|
-
id: string;
|
|
5
|
-
agentId: string;
|
|
6
|
-
channel: string;
|
|
7
|
-
userId: string;
|
|
8
|
-
createdAt: number;
|
|
9
|
-
lastActivityAt: number;
|
|
10
|
-
messageCount: number;
|
|
11
|
-
status: "active" | "idle" | "closed";
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AgentState {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
status: "ready" | "busy" | "error";
|
|
18
|
-
currentSessionId?: string;
|
|
19
|
-
lastError?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ChannelState {
|
|
23
|
-
name: string;
|
|
24
|
-
accountId: string;
|
|
25
|
-
status: "connected" | "disconnected" | "error";
|
|
26
|
-
lastActivity?: number;
|
|
27
|
-
error?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface MetricsState {
|
|
31
|
-
totalMessages: number;
|
|
32
|
-
totalSessions: number;
|
|
33
|
-
totalToolCalls: number;
|
|
34
|
-
averageResponseTime: number;
|
|
35
|
-
errors: number;
|
|
36
|
-
startedAt: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export interface HiveState {
|
|
40
|
-
sessions: Map<string, SessionState>;
|
|
41
|
-
agents: Map<string, AgentState>;
|
|
42
|
-
channels: Map<string, ChannelState>;
|
|
43
|
-
metrics: MetricsState;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface StateSnapshot {
|
|
47
|
-
id: string;
|
|
48
|
-
timestamp: number;
|
|
49
|
-
state: HiveState;
|
|
50
|
-
reason?: string;
|
|
51
|
-
action?: string;
|
|
52
|
-
correlationId?: string;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
interface StateStoreOptions {
|
|
56
|
-
maxSnapshots?: number;
|
|
57
|
-
enableSnapshots?: boolean;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const defaultMetrics: MetricsState = {
|
|
61
|
-
totalMessages: 0,
|
|
62
|
-
totalSessions: 0,
|
|
63
|
-
totalToolCalls: 0,
|
|
64
|
-
averageResponseTime: 0,
|
|
65
|
-
errors: 0,
|
|
66
|
-
startedAt: Date.now(),
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export class StateStore {
|
|
70
|
-
private state: HiveState;
|
|
71
|
-
private snapshots: StateSnapshot[] = [];
|
|
72
|
-
private readonly maxSnapshots: number;
|
|
73
|
-
private readonly enableSnapshots: boolean;
|
|
74
|
-
private listeners: Set<(state: Readonly<HiveState>) => void> = new Set();
|
|
75
|
-
private correlationId?: string;
|
|
76
|
-
|
|
77
|
-
constructor(options: StateStoreOptions = {}) {
|
|
78
|
-
this.maxSnapshots = options.maxSnapshots ?? 100;
|
|
79
|
-
this.enableSnapshots = options.enableSnapshots ?? true;
|
|
80
|
-
this.state = this.createInitialState();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
setCorrelationId(id: string): void {
|
|
84
|
-
this.correlationId = id;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getCorrelationId(): string | undefined {
|
|
88
|
-
return this.correlationId;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
clearCorrelationId(): void {
|
|
92
|
-
this.correlationId = undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
private createInitialState(): HiveState {
|
|
96
|
-
return {
|
|
97
|
-
sessions: new Map(),
|
|
98
|
-
agents: new Map(),
|
|
99
|
-
channels: new Map(),
|
|
100
|
-
metrics: { ...defaultMetrics },
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getState(): Readonly<HiveState> {
|
|
105
|
-
return this.state;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
update(updater: (draft: HiveState) => void, reason?: string): void {
|
|
109
|
-
const newState = this.cloneState(this.state);
|
|
110
|
-
updater(newState);
|
|
111
|
-
|
|
112
|
-
if (this.enableSnapshots) {
|
|
113
|
-
this.saveSnapshot(newState, reason);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
this.state = newState;
|
|
117
|
-
this.notifyListeners();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private cloneState(state: HiveState): HiveState {
|
|
121
|
-
return {
|
|
122
|
-
sessions: new Map(state.sessions),
|
|
123
|
-
agents: new Map(state.agents),
|
|
124
|
-
channels: new Map(state.channels),
|
|
125
|
-
metrics: { ...state.metrics },
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
private saveSnapshot(state: HiveState, reason?: string): void {
|
|
130
|
-
const snapshot: StateSnapshot = {
|
|
131
|
-
id: crypto.randomUUID(),
|
|
132
|
-
timestamp: Date.now(),
|
|
133
|
-
state: this.cloneState(state),
|
|
134
|
-
reason,
|
|
135
|
-
action: reason,
|
|
136
|
-
correlationId: this.correlationId,
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
this.snapshots.push(snapshot);
|
|
140
|
-
|
|
141
|
-
if (this.snapshots.length > this.maxSnapshots) {
|
|
142
|
-
this.snapshots.shift();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
getSnapshotAt(timestamp: number): StateSnapshot | undefined {
|
|
147
|
-
return this.snapshots.find((s) => s.timestamp >= timestamp);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
getSnapshotById(id: string): StateSnapshot | undefined {
|
|
151
|
-
return this.snapshots.find((s) => s.id === id);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getAllSnapshots(): StateSnapshot[] {
|
|
155
|
-
return [...this.snapshots];
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getRecentSnapshots(count: number = 10): StateSnapshot[] {
|
|
159
|
-
return this.snapshots.slice(-count);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
subscribe(listener: (state: Readonly<HiveState>) => void): () => void {
|
|
163
|
-
this.listeners.add(listener);
|
|
164
|
-
return () => this.listeners.delete(listener);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private notifyListeners(): void {
|
|
168
|
-
const state = this.getState();
|
|
169
|
-
for (const listener of this.listeners) {
|
|
170
|
-
try {
|
|
171
|
-
listener(state);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
logger.error("[StateStore] Listener error:", { error: (error as Error).message });
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
createSession(session: Omit<SessionState, "createdAt" | "lastActivityAt" | "messageCount" | "status">): SessionState {
|
|
179
|
-
const newSession: SessionState = {
|
|
180
|
-
...session,
|
|
181
|
-
createdAt: Date.now(),
|
|
182
|
-
lastActivityAt: Date.now(),
|
|
183
|
-
messageCount: 0,
|
|
184
|
-
status: "active",
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
this.update((state) => {
|
|
188
|
-
state.sessions.set(session.id, newSession);
|
|
189
|
-
state.metrics.totalSessions++;
|
|
190
|
-
}, `Session created: ${session.id}`);
|
|
191
|
-
|
|
192
|
-
return newSession;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
updateSession(sessionId: string, updates: Partial<SessionState>): void {
|
|
196
|
-
this.update((state) => {
|
|
197
|
-
const session = state.sessions.get(sessionId);
|
|
198
|
-
if (session) {
|
|
199
|
-
state.sessions.set(sessionId, { ...session, ...updates });
|
|
200
|
-
}
|
|
201
|
-
}, `Session updated: ${sessionId}`);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
closeSession(sessionId: string): void {
|
|
205
|
-
this.update((state) => {
|
|
206
|
-
const session = state.sessions.get(sessionId);
|
|
207
|
-
if (session) {
|
|
208
|
-
state.sessions.set(sessionId, { ...session, status: "closed" });
|
|
209
|
-
}
|
|
210
|
-
}, `Session closed: ${sessionId}`);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
incrementMessageCount(sessionId: string): void {
|
|
214
|
-
this.update((state) => {
|
|
215
|
-
const session = state.sessions.get(sessionId);
|
|
216
|
-
if (session) {
|
|
217
|
-
session.messageCount++;
|
|
218
|
-
session.lastActivityAt = Date.now();
|
|
219
|
-
state.sessions.set(sessionId, session);
|
|
220
|
-
state.metrics.totalMessages++;
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
registerAgent(agent: Omit<AgentState, "status">): void {
|
|
226
|
-
this.update((state) => {
|
|
227
|
-
state.agents.set(agent.id, { ...agent, status: "ready" });
|
|
228
|
-
}, `Agent registered: ${agent.id}`);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
updateAgent(agentId: string, updates: Partial<AgentState>): void {
|
|
232
|
-
this.update((state) => {
|
|
233
|
-
const agent = state.agents.get(agentId);
|
|
234
|
-
if (agent) {
|
|
235
|
-
state.agents.set(agentId, { ...agent, ...updates });
|
|
236
|
-
}
|
|
237
|
-
}, `Agent updated: ${agentId}`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
updateChannel(channelName: string, accountId: string, updates: Partial<ChannelState>): void {
|
|
241
|
-
this.update((state) => {
|
|
242
|
-
const key = `${channelName}:${accountId}`;
|
|
243
|
-
const channel = state.channels.get(key);
|
|
244
|
-
if (channel) {
|
|
245
|
-
state.channels.set(key, { ...channel, ...updates });
|
|
246
|
-
} else {
|
|
247
|
-
state.channels.set(key, {
|
|
248
|
-
name: channelName,
|
|
249
|
-
accountId,
|
|
250
|
-
status: "disconnected",
|
|
251
|
-
...updates,
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}, `Channel updated: ${channelName}:${accountId}`);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
recordToolCall(duration: number, success: boolean): void {
|
|
258
|
-
this.update((state) => {
|
|
259
|
-
state.metrics.totalToolCalls++;
|
|
260
|
-
if (!success) {
|
|
261
|
-
state.metrics.errors++;
|
|
262
|
-
}
|
|
263
|
-
const total = state.metrics.totalToolCalls;
|
|
264
|
-
const prevAvg = state.metrics.averageResponseTime;
|
|
265
|
-
state.metrics.averageResponseTime = prevAvg + (duration - prevAvg) / total;
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
reset(): void {
|
|
270
|
-
this.state = this.createInitialState();
|
|
271
|
-
this.snapshots = [];
|
|
272
|
-
this.saveSnapshot(this.state, "Store reset");
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
exportState(): string {
|
|
276
|
-
const exportable = {
|
|
277
|
-
sessions: Object.fromEntries(this.state.sessions),
|
|
278
|
-
agents: Object.fromEntries(this.state.agents),
|
|
279
|
-
channels: Object.fromEntries(this.state.channels),
|
|
280
|
-
metrics: this.state.metrics,
|
|
281
|
-
};
|
|
282
|
-
return JSON.stringify(exportable, null, 2);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export(): string {
|
|
286
|
-
return this.exportState();
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
getStats(): {
|
|
290
|
-
sessionsCount: number;
|
|
291
|
-
activeSessions: number;
|
|
292
|
-
agentsCount: number;
|
|
293
|
-
channelsCount: number;
|
|
294
|
-
snapshotsCount: number;
|
|
295
|
-
uptime: number;
|
|
296
|
-
} {
|
|
297
|
-
const activeSessions = Array.from(this.state.sessions.values()).filter(
|
|
298
|
-
(s) => s.status === "active"
|
|
299
|
-
).length;
|
|
300
|
-
|
|
301
|
-
return {
|
|
302
|
-
sessionsCount: this.state.sessions.size,
|
|
303
|
-
activeSessions,
|
|
304
|
-
agentsCount: this.state.agents.size,
|
|
305
|
-
channelsCount: this.state.channels.size,
|
|
306
|
-
snapshotsCount: this.snapshots.length,
|
|
307
|
-
uptime: Date.now() - this.state.metrics.startedAt,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export const stateStore = new StateStore();
|