@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,225 +0,0 @@
|
|
|
1
|
-
import { logger } from "../utils/logger.ts";
|
|
2
|
-
|
|
3
|
-
type CircuitState = "closed" | "open" | "half-open";
|
|
4
|
-
|
|
5
|
-
export interface CircuitBreakerOptions {
|
|
6
|
-
failureThreshold: number;
|
|
7
|
-
successThreshold: number;
|
|
8
|
-
resetTimeout: number;
|
|
9
|
-
halfOpenMaxCalls: number;
|
|
10
|
-
onStateChange?: (from: CircuitState, to: CircuitState) => void;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const defaultOptions: CircuitBreakerOptions = {
|
|
14
|
-
failureThreshold: 5,
|
|
15
|
-
successThreshold: 3,
|
|
16
|
-
resetTimeout: 30000,
|
|
17
|
-
halfOpenMaxCalls: 1,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export interface CircuitBreakerStats {
|
|
21
|
-
state: CircuitState;
|
|
22
|
-
failures: number;
|
|
23
|
-
successes: number;
|
|
24
|
-
lastFailureTime?: number;
|
|
25
|
-
lastSuccessTime?: number;
|
|
26
|
-
totalCalls: number;
|
|
27
|
-
totalFailures: number;
|
|
28
|
-
totalSuccesses: number;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class CircuitBreaker {
|
|
32
|
-
private state: CircuitState = "closed";
|
|
33
|
-
private failures = 0;
|
|
34
|
-
private successes = 0;
|
|
35
|
-
private lastFailureTime?: number;
|
|
36
|
-
private lastSuccessTime?: number;
|
|
37
|
-
private halfOpenCalls = 0;
|
|
38
|
-
private totalCalls = 0;
|
|
39
|
-
private totalFailures = 0;
|
|
40
|
-
private totalSuccesses = 0;
|
|
41
|
-
|
|
42
|
-
constructor(
|
|
43
|
-
private readonly name: string,
|
|
44
|
-
private readonly options: CircuitBreakerOptions = defaultOptions
|
|
45
|
-
) { }
|
|
46
|
-
|
|
47
|
-
async execute<T>(fn: () => Promise<T>): Promise<T> {
|
|
48
|
-
if (this.state === "open") {
|
|
49
|
-
const timeSinceLastFailure = Date.now() - (this.lastFailureTime ?? 0);
|
|
50
|
-
|
|
51
|
-
if (timeSinceLastFailure > this.options.resetTimeout) {
|
|
52
|
-
this.transitionTo("half-open");
|
|
53
|
-
} else {
|
|
54
|
-
const waitTime = this.options.resetTimeout - timeSinceLastFailure;
|
|
55
|
-
throw new CircuitBreakerOpenError(
|
|
56
|
-
`Circuit breaker '${this.name}' is OPEN. Retry in ${Math.ceil(waitTime / 1000)}s`,
|
|
57
|
-
this.name,
|
|
58
|
-
waitTime
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this.state === "half-open") {
|
|
64
|
-
if (this.halfOpenCalls >= this.options.halfOpenMaxCalls) {
|
|
65
|
-
throw new CircuitBreakerOpenError(
|
|
66
|
-
`Circuit breaker '${this.name}' is HALF-OPEN with pending calls`,
|
|
67
|
-
this.name,
|
|
68
|
-
0
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
this.halfOpenCalls++;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
this.totalCalls++;
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const result = await fn();
|
|
78
|
-
this.onSuccess();
|
|
79
|
-
return result;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
this.onFailure();
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private onSuccess(): void {
|
|
87
|
-
this.lastSuccessTime = Date.now();
|
|
88
|
-
this.totalSuccesses++;
|
|
89
|
-
this.failures = 0;
|
|
90
|
-
|
|
91
|
-
if (this.state === "half-open") {
|
|
92
|
-
this.successes++;
|
|
93
|
-
this.halfOpenCalls--;
|
|
94
|
-
|
|
95
|
-
if (this.successes >= this.options.successThreshold) {
|
|
96
|
-
this.transitionTo("closed");
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private onFailure(): void {
|
|
102
|
-
this.lastFailureTime = Date.now();
|
|
103
|
-
this.totalFailures++;
|
|
104
|
-
this.failures++;
|
|
105
|
-
|
|
106
|
-
if (this.state === "half-open") {
|
|
107
|
-
this.halfOpenCalls--;
|
|
108
|
-
this.transitionTo("open");
|
|
109
|
-
} else if (this.state === "closed") {
|
|
110
|
-
if (this.failures >= this.options.failureThreshold) {
|
|
111
|
-
this.transitionTo("open");
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private transitionTo(newState: CircuitState): void {
|
|
117
|
-
const oldState = this.state;
|
|
118
|
-
this.state = newState;
|
|
119
|
-
|
|
120
|
-
if (newState === "closed") {
|
|
121
|
-
this.failures = 0;
|
|
122
|
-
this.successes = 0;
|
|
123
|
-
this.halfOpenCalls = 0;
|
|
124
|
-
} else if (newState === "open") {
|
|
125
|
-
this.successes = 0;
|
|
126
|
-
this.halfOpenCalls = 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
this.options.onStateChange?.(oldState, newState);
|
|
130
|
-
logger.info(`[CircuitBreaker] ${this.name}: ${oldState} → ${newState}`);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
getState(): CircuitState {
|
|
134
|
-
return this.state;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
isOpen(): boolean {
|
|
138
|
-
return this.state === "open";
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
isClosed(): boolean {
|
|
142
|
-
return this.state === "closed";
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
isHalfOpen(): boolean {
|
|
146
|
-
return this.state === "half-open";
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
getStats(): CircuitBreakerStats {
|
|
150
|
-
return {
|
|
151
|
-
state: this.state,
|
|
152
|
-
failures: this.failures,
|
|
153
|
-
successes: this.successes,
|
|
154
|
-
lastFailureTime: this.lastFailureTime,
|
|
155
|
-
lastSuccessTime: this.lastSuccessTime,
|
|
156
|
-
totalCalls: this.totalCalls,
|
|
157
|
-
totalFailures: this.totalFailures,
|
|
158
|
-
totalSuccesses: this.totalSuccesses,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
reset(): void {
|
|
163
|
-
this.transitionTo("closed");
|
|
164
|
-
this.failures = 0;
|
|
165
|
-
this.successes = 0;
|
|
166
|
-
this.lastFailureTime = undefined;
|
|
167
|
-
this.lastSuccessTime = undefined;
|
|
168
|
-
this.halfOpenCalls = 0;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
forceOpen(): void {
|
|
172
|
-
this.transitionTo("open");
|
|
173
|
-
this.lastFailureTime = Date.now();
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export class CircuitBreakerOpenError extends Error {
|
|
178
|
-
constructor(
|
|
179
|
-
message: string,
|
|
180
|
-
public readonly circuitName: string,
|
|
181
|
-
public readonly retryAfterMs: number
|
|
182
|
-
) {
|
|
183
|
-
super(message);
|
|
184
|
-
this.name = "CircuitBreakerOpenError";
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export class CircuitBreakerRegistry {
|
|
189
|
-
private breakers: Map<string, CircuitBreaker> = new Map();
|
|
190
|
-
|
|
191
|
-
getOrCreate(name: string, options?: Partial<CircuitBreakerOptions>): CircuitBreaker {
|
|
192
|
-
let breaker = this.breakers.get(name);
|
|
193
|
-
|
|
194
|
-
if (!breaker) {
|
|
195
|
-
breaker = new CircuitBreaker(name, { ...defaultOptions, ...options });
|
|
196
|
-
this.breakers.set(name, breaker);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
return breaker;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
get(name: string): CircuitBreaker | undefined {
|
|
203
|
-
return this.breakers.get(name);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
getAll(): Map<string, CircuitBreaker> {
|
|
207
|
-
return new Map(this.breakers);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
getAllStats(): Record<string, CircuitBreakerStats> {
|
|
211
|
-
const stats: Record<string, CircuitBreakerStats> = {};
|
|
212
|
-
for (const [name, breaker] of this.breakers) {
|
|
213
|
-
stats[name] = breaker.getStats();
|
|
214
|
-
}
|
|
215
|
-
return stats;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
resetAll(): void {
|
|
219
|
-
for (const breaker of this.breakers.values()) {
|
|
220
|
-
breaker.reset();
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export const circuitBreakerRegistry = new CircuitBreakerRegistry();
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import http, { type IncomingMessage, type ServerResponse, type Server } from "http";
|
|
2
|
-
import { BaseChannel, type ChannelConfig, type IncomingMessage as HiveIncomingMessage, type OutboundMessage } from "../channels/base.ts";
|
|
3
|
-
import { logger } from "../utils/logger.ts";
|
|
4
|
-
import { pairingService } from "./pairing.ts";
|
|
5
|
-
|
|
6
|
-
export interface GoogleChatConfig extends ChannelConfig {
|
|
7
|
-
projectId?: string;
|
|
8
|
-
serviceAccountKey?: string;
|
|
9
|
-
webhookPort?: number;
|
|
10
|
-
webhookPath?: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface GoogleChatEvent {
|
|
14
|
-
type: string;
|
|
15
|
-
eventTime: string;
|
|
16
|
-
space: {
|
|
17
|
-
name: string;
|
|
18
|
-
displayName: string;
|
|
19
|
-
type: "ROOM" | "DM";
|
|
20
|
-
};
|
|
21
|
-
message?: {
|
|
22
|
-
name: string;
|
|
23
|
-
sender: {
|
|
24
|
-
name: string;
|
|
25
|
-
displayName: string;
|
|
26
|
-
};
|
|
27
|
-
createTime: string;
|
|
28
|
-
text: string;
|
|
29
|
-
thread?: {
|
|
30
|
-
name: string;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
user?: {
|
|
34
|
-
name: string;
|
|
35
|
-
displayName: string;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class GoogleChatChannel extends BaseChannel {
|
|
40
|
-
name = "google-chat";
|
|
41
|
-
accountId: string;
|
|
42
|
-
config: GoogleChatConfig;
|
|
43
|
-
|
|
44
|
-
private server?: Server;
|
|
45
|
-
private log = logger.child("google-chat");
|
|
46
|
-
private spaceCache: Map<string, { space: string; thread?: string }> = new Map();
|
|
47
|
-
|
|
48
|
-
constructor(accountId: string, config: GoogleChatConfig) {
|
|
49
|
-
super();
|
|
50
|
-
this.accountId = accountId;
|
|
51
|
-
this.config = {
|
|
52
|
-
...config,
|
|
53
|
-
dmPolicy: config.dmPolicy ?? "pairing",
|
|
54
|
-
allowFrom: config.allowFrom ?? [],
|
|
55
|
-
enabled: config.enabled ?? true,
|
|
56
|
-
webhookPort: config.webhookPort ?? 8080,
|
|
57
|
-
webhookPath: config.webhookPath ?? "/webhook/google-chat",
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async start(): Promise<void> {
|
|
62
|
-
this.server = http.createServer((req, res) => {
|
|
63
|
-
if (req.url === this.config.webhookPath && req.method === "POST") {
|
|
64
|
-
this.handleWebhook(req, res);
|
|
65
|
-
} else {
|
|
66
|
-
res.writeHead(404).end();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
this.server!.listen(this.config.webhookPort, () => {
|
|
72
|
-
this.running = true;
|
|
73
|
-
this.log.info(
|
|
74
|
-
`Google Chat webhook listening on port ${this.config.webhookPort}${this.config.webhookPath}`
|
|
75
|
-
);
|
|
76
|
-
resolve();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this.server!.on("error", (error: Error) => {
|
|
80
|
-
this.log.error(`Server error: ${error.message}`);
|
|
81
|
-
reject(error);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private async handleWebhook(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
87
|
-
let body = "";
|
|
88
|
-
req.on("data", (chunk) => (body += chunk));
|
|
89
|
-
req.on("end", async () => {
|
|
90
|
-
try {
|
|
91
|
-
const event: GoogleChatEvent = JSON.parse(body);
|
|
92
|
-
|
|
93
|
-
if (event.type === "ADDED_TO_SPACE") {
|
|
94
|
-
await this.handleAddedToSpace(event, res);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (event.type === "REMOVED_FROM_SPACE") {
|
|
99
|
-
this.log.info(`Removed from space: ${event.space.name}`);
|
|
100
|
-
res.writeHead(200).end();
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (event.type === "MESSAGE" && event.message) {
|
|
105
|
-
await this.handleChatMessage(event, res);
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
res.writeHead(200).end();
|
|
110
|
-
} catch (error) {
|
|
111
|
-
this.log.error(`Webhook error: ${(error as Error).message}`);
|
|
112
|
-
res.writeHead(500).end();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
private async handleAddedToSpace(
|
|
118
|
-
event: GoogleChatEvent,
|
|
119
|
-
res: ServerResponse
|
|
120
|
-
): Promise<void> {
|
|
121
|
-
const message =
|
|
122
|
-
event.space.type === "DM"
|
|
123
|
-
? {
|
|
124
|
-
text: "¡Hola! Soy tu asistente AI. Envía un mensaje para comenzar.",
|
|
125
|
-
}
|
|
126
|
-
: {
|
|
127
|
-
text: "¡Gracias por añadirme al espacio! Mencióname con @bot para interactuar.",
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
131
|
-
res.end(JSON.stringify(message));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
private async handleChatMessage(event: GoogleChatEvent, res: ServerResponse): Promise<void> {
|
|
135
|
-
if (!event.message) {
|
|
136
|
-
res.writeHead(200).end();
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const userId = event.message.sender.name.split("/").pop() ?? "unknown";
|
|
141
|
-
const spaceName = event.space.name;
|
|
142
|
-
const isDM = event.space.type === "DM";
|
|
143
|
-
const kind = isDM ? "direct" : "group";
|
|
144
|
-
const peerId = isDM ? userId : `${spaceName}:${userId}`;
|
|
145
|
-
|
|
146
|
-
if (event.message.text === "/myid") {
|
|
147
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
148
|
-
res.end(
|
|
149
|
-
JSON.stringify({
|
|
150
|
-
text: `🆔 Tu Google Chat ID es: ${userId}\n\nPara emparejar, solicita un código al administrador.`,
|
|
151
|
-
})
|
|
152
|
-
);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (event.message.text.startsWith("/pair ")) {
|
|
157
|
-
const code = event.message.text.split(" ")[1]?.trim();
|
|
158
|
-
const result = pairingService.approve(code ?? "");
|
|
159
|
-
|
|
160
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
161
|
-
res.end(
|
|
162
|
-
JSON.stringify({
|
|
163
|
-
text: result.success
|
|
164
|
-
? "✅ ¡Emparejamiento exitoso!"
|
|
165
|
-
: `❌ ${result.error}`,
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (this.config.dmPolicy === "pairing" && !pairingService.isAllowed("google-chat", userId)) {
|
|
172
|
-
this.log.debug(`Message from unpaired user: ${userId}`);
|
|
173
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
174
|
-
res.end(
|
|
175
|
-
JSON.stringify({
|
|
176
|
-
text:
|
|
177
|
-
"⛔ No estás emparejado.\n\n" +
|
|
178
|
-
"Tu ID: " +
|
|
179
|
-
userId +
|
|
180
|
-
"\n\n" +
|
|
181
|
-
"Solicita un código de emparejamiento al administrador.",
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (!isDM && !this.isUserAllowed(peerId)) {
|
|
188
|
-
this.log.debug(`Message from unauthorized user: ${peerId}`);
|
|
189
|
-
res.writeHead(200).end();
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const sessionId = this.formatSessionId(peerId, kind);
|
|
194
|
-
this.spaceCache.set(sessionId, {
|
|
195
|
-
space: spaceName,
|
|
196
|
-
thread: event.message.thread?.name,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
const incomingMessage: HiveIncomingMessage = {
|
|
200
|
-
sessionId,
|
|
201
|
-
channel: "google-chat",
|
|
202
|
-
accountId: this.accountId,
|
|
203
|
-
peerId,
|
|
204
|
-
peerKind: kind,
|
|
205
|
-
content: event.message.text,
|
|
206
|
-
metadata: {
|
|
207
|
-
googleChat: {
|
|
208
|
-
spaceName,
|
|
209
|
-
userId,
|
|
210
|
-
displayName: event.message.sender.displayName,
|
|
211
|
-
threadName: event.message.thread?.name,
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
res.writeHead(200).end();
|
|
217
|
-
|
|
218
|
-
await this.handleMessage(incomingMessage);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async stop(): Promise<void> {
|
|
222
|
-
if (this.server) {
|
|
223
|
-
return new Promise((resolve) => {
|
|
224
|
-
this.server!.close(() => {
|
|
225
|
-
this.running = false;
|
|
226
|
-
this.log.info("Google Chat channel stopped");
|
|
227
|
-
resolve();
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
async send(sessionId: string, message: OutboundMessage): Promise<void> {
|
|
234
|
-
const content = message.content ?? "";
|
|
235
|
-
|
|
236
|
-
if (!content || content.trim().length === 0) {
|
|
237
|
-
this.log.warn("Empty response, skipping send");
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const cached = this.spaceCache.get(sessionId);
|
|
242
|
-
|
|
243
|
-
if (!cached) {
|
|
244
|
-
this.log.warn(`No cached space for session: ${sessionId}`);
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (message.type === "stream" && message.chunk) {
|
|
249
|
-
this.log.info(`[Google Chat] Stream chunk to ${cached.space}: ${message.chunk.slice(0, 50)}...`);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
this.log.info(`[Google Chat] Would send to ${cached.space}: ${content.slice(0, 100)}...`);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async sendMessage(space: string, content: string, thread?: string): Promise<void> {
|
|
257
|
-
this.log.info(`[Google Chat] Sending to ${space}: ${content.slice(0, 100)}...`);
|
|
258
|
-
if (thread) {
|
|
259
|
-
this.log.info(` Thread: ${thread}`);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
export function createGoogleChatChannel(
|
|
265
|
-
accountId: string,
|
|
266
|
-
config: GoogleChatConfig
|
|
267
|
-
): GoogleChatChannel {
|
|
268
|
-
return new GoogleChatChannel(accountId, config);
|
|
269
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import type { Config } from "../config/loader.ts";
|
|
2
|
-
import { logger } from "../utils/logger.ts";
|
|
3
|
-
|
|
4
|
-
export * from "./pairing.ts";
|
|
5
|
-
export * from "./rate-limit.ts";
|
|
6
|
-
export * from "./signal.ts";
|
|
7
|
-
export * from "./google-chat.ts";
|
|
8
|
-
|
|
9
|
-
export interface RateLimitConfig {
|
|
10
|
-
windowMs: number;
|
|
11
|
-
maxRequests: number;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface RateLimitEntry {
|
|
15
|
-
count: number;
|
|
16
|
-
resetAt: number;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class RateLimiter {
|
|
20
|
-
private limits: Map<string, RateLimitEntry> = new Map();
|
|
21
|
-
private config: RateLimitConfig;
|
|
22
|
-
private log = logger.child("rate-limiter");
|
|
23
|
-
|
|
24
|
-
constructor(config: RateLimitConfig) {
|
|
25
|
-
this.config = config;
|
|
26
|
-
this.startCleanup();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
check(key: string): { allowed: boolean; remaining: number; resetAt: number } {
|
|
30
|
-
const now = Date.now();
|
|
31
|
-
const entry = this.limits.get(key);
|
|
32
|
-
|
|
33
|
-
if (!entry || now > entry.resetAt) {
|
|
34
|
-
const resetAt = now + this.config.windowMs;
|
|
35
|
-
this.limits.set(key, { count: 1, resetAt });
|
|
36
|
-
return { allowed: true, remaining: this.config.maxRequests - 1, resetAt };
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (entry.count >= this.config.maxRequests) {
|
|
40
|
-
this.log.warn(`Rate limit exceeded for ${key}`);
|
|
41
|
-
return { allowed: false, remaining: 0, resetAt: entry.resetAt };
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
entry.count++;
|
|
45
|
-
return {
|
|
46
|
-
allowed: true,
|
|
47
|
-
remaining: this.config.maxRequests - entry.count,
|
|
48
|
-
resetAt: entry.resetAt
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
reset(key: string): void {
|
|
53
|
-
this.limits.delete(key);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
private startCleanup(): void {
|
|
57
|
-
setInterval(() => {
|
|
58
|
-
const now = Date.now();
|
|
59
|
-
for (const [key, entry] of this.limits) {
|
|
60
|
-
if (now > entry.resetAt) {
|
|
61
|
-
this.limits.delete(key);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}, this.config.windowMs);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class InputValidator {
|
|
69
|
-
private maxMessageLength: number;
|
|
70
|
-
private maxCommandArgs: number;
|
|
71
|
-
private log = logger.child("validator");
|
|
72
|
-
|
|
73
|
-
constructor(options: { maxMessageLength?: number; maxCommandArgs?: number } = {}) {
|
|
74
|
-
this.maxMessageLength = options.maxMessageLength ?? 100000;
|
|
75
|
-
this.maxCommandArgs = options.maxCommandArgs ?? 50;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
validateMessage(content: string): { valid: boolean; error?: string } {
|
|
79
|
-
if (typeof content !== "string") {
|
|
80
|
-
return { valid: false, error: "Message must be a string" };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (content.length === 0) {
|
|
84
|
-
return { valid: false, error: "Message cannot be empty" };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
if (content.length > this.maxMessageLength) {
|
|
88
|
-
this.log.warn(`Message too long: ${content.length} > ${this.maxMessageLength}`);
|
|
89
|
-
return {
|
|
90
|
-
valid: false,
|
|
91
|
-
error: `Message too long (max ${this.maxMessageLength} characters)`
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return { valid: true };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
validateCommand(name: string, args: string[]): { valid: boolean; error?: string } {
|
|
99
|
-
if (!name || typeof name !== "string") {
|
|
100
|
-
return { valid: false, error: "Command name is required" };
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!/^[a-z0-9_-]+$/.test(name)) {
|
|
104
|
-
return { valid: false, error: "Invalid command name format" };
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (args.length > this.maxCommandArgs) {
|
|
108
|
-
return { valid: false, error: `Too many arguments (max ${this.maxCommandArgs})` };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return { valid: true };
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
validateSessionId(sessionId: string): { valid: boolean; error?: string } {
|
|
115
|
-
if (!sessionId || typeof sessionId !== "string") {
|
|
116
|
-
return { valid: false, error: "Session ID is required" };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const pattern = /^agent:[a-z0-9_-]+:[a-z0-9_-]+:(main|dm|group)(?::[a-z0-9_-]+)?$/;
|
|
120
|
-
if (!pattern.test(sessionId)) {
|
|
121
|
-
return { valid: false, error: "Invalid session ID format" };
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return { valid: true };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
sanitizeInput(input: string): string {
|
|
128
|
-
return input
|
|
129
|
-
.replace(/\x00/g, "")
|
|
130
|
-
.replace(/[\x1F\x7F]/g, "")
|
|
131
|
-
.trim();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export class AuthManager {
|
|
136
|
-
private config: Config;
|
|
137
|
-
private allowedUsers: Set<string>;
|
|
138
|
-
private log = logger.child("auth");
|
|
139
|
-
|
|
140
|
-
constructor(config: Config) {
|
|
141
|
-
this.config = config;
|
|
142
|
-
this.allowedUsers = new Set(config.security?.allowedUsers ?? []);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
isAllowed(peerId: string, channel: string): boolean {
|
|
146
|
-
if (this.allowedUsers.size === 0) {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const channelConfig = this.config.channels?.[channel as keyof typeof this.config.channels];
|
|
151
|
-
if (channelConfig && typeof channelConfig === "object" && "allowFrom" in channelConfig) {
|
|
152
|
-
const allowFrom = (channelConfig as { allowFrom?: string[] }).allowFrom;
|
|
153
|
-
if (allowFrom && allowFrom.length > 0) {
|
|
154
|
-
return allowFrom.includes(peerId);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return this.allowedUsers.has(peerId);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
addAllowedUser(peerId: string): void {
|
|
162
|
-
this.allowedUsers.add(peerId);
|
|
163
|
-
this.log.info(`Added allowed user: ${peerId}`);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
removeAllowedUser(peerId: string): boolean {
|
|
167
|
-
const removed = this.allowedUsers.delete(peerId);
|
|
168
|
-
if (removed) {
|
|
169
|
-
this.log.info(`Removed allowed user: ${peerId}`);
|
|
170
|
-
}
|
|
171
|
-
return removed;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
listAllowedUsers(): string[] {
|
|
175
|
-
return Array.from(this.allowedUsers);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function createRateLimiter(config: RateLimitConfig): RateLimiter {
|
|
180
|
-
return new RateLimiter(config);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function createInputValidator(options?: {
|
|
184
|
-
maxMessageLength?: number;
|
|
185
|
-
maxCommandArgs?: number;
|
|
186
|
-
}): InputValidator {
|
|
187
|
-
return new InputValidator(options);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export function createAuthManager(config: Config): AuthManager {
|
|
191
|
-
return new AuthManager(config);
|
|
192
|
-
}
|