@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,623 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FTS5-based Dynamic Tool Selector Module
|
|
3
|
-
*
|
|
4
|
-
* Context Compiler Level 3 - Intelligent Tool Selection
|
|
5
|
-
*
|
|
6
|
-
* This module intercepts each message BEFORE calling the LLM and uses
|
|
7
|
-
* SQLite FTS5 bm25() scoring to select the most relevant tools (0-4).
|
|
8
|
-
*
|
|
9
|
-
* DESIGN DECISIONS:
|
|
10
|
-
*
|
|
11
|
-
* 1. Stateless: No memory between turns - each message is evaluated independently.
|
|
12
|
-
* Rationale: Prevents cascade effects where a bad selection in one turn affects
|
|
13
|
-
* future turns. Forces fresh evaluation each time.
|
|
14
|
-
*
|
|
15
|
-
* 2. Maximum 4 tools per turn: Keeps token count low and prevents overwhelming
|
|
16
|
-
* the LLM with irrelevant tools. Forces prioritization.
|
|
17
|
-
*
|
|
18
|
-
* 3. Relevance threshold: If highest bm25 score < MIN_RELEVANCE_THRESHOLD,
|
|
19
|
-
* the message is considered conversational and returns empty array.
|
|
20
|
-
* Rationale: Prevents false positives on generic messages like "hola" or
|
|
21
|
-
* "cómo estás?" which should not trigger any tools.
|
|
22
|
-
*
|
|
23
|
-
* 4. Atomic over orchestration: When ambiguous, prefer individual tools over
|
|
24
|
-
* compound/manager tools. Rationale: Atomic tools are more predictable and
|
|
25
|
-
* the LLM can combine them as needed.
|
|
26
|
-
*
|
|
27
|
-
* 5. Performance: Must complete in under 50ms. FTS5 queries are typically
|
|
28
|
-
* <5ms for small tool catalogs (<100 tools).
|
|
29
|
-
*
|
|
30
|
-
* 6. Tool categorization: Tools are categorized by semantic domain:
|
|
31
|
-
* - scheduling (cron tools)
|
|
32
|
-
* - projects (project/task management)
|
|
33
|
-
* - filesystem (file operations)
|
|
34
|
-
* - web (search/fetch)
|
|
35
|
-
* - browser (browser automation)
|
|
36
|
-
* - memory (notes, memory operations)
|
|
37
|
-
* - code (exec, terminal)
|
|
38
|
-
* - canvas (UI rendering)
|
|
39
|
-
* - agents (agent creation/management)
|
|
40
|
-
* - core (notify, report_progress, save_note)
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
import { getDb } from "../storage/sqlite"
|
|
44
|
-
import { logger } from "../utils/logger"
|
|
45
|
-
|
|
46
|
-
const log = logger.child("tool-selector")
|
|
47
|
-
|
|
48
|
-
// ─── Types ───────────────────────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
export interface ToolDescriptor {
|
|
51
|
-
name: string
|
|
52
|
-
description: string
|
|
53
|
-
category: string
|
|
54
|
-
/** Abstraction level: atomic (single operation) vs orchestration (manages multiple) */
|
|
55
|
-
abstractionLevel?: "atomic" | "orchestration"
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface SelectedTool {
|
|
59
|
-
name: string
|
|
60
|
-
score: number
|
|
61
|
-
category: string
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface ToolSelectorResult {
|
|
65
|
-
tools: ToolDescriptor[]
|
|
66
|
-
selected: SelectedTool[]
|
|
67
|
-
reasoning: string
|
|
68
|
-
timingMs: number
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ─── Configuration ───────────────────────────────────────────────────────────
|
|
72
|
-
|
|
73
|
-
/** Maximum tools to return per message */
|
|
74
|
-
const MAX_TOOLS_PER_TURN = 6
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Minimum bm25 score threshold. Below this = conversational, no tools needed.
|
|
78
|
-
*
|
|
79
|
-
* CRITICAL: bm25() returns NEGATIVE scores where closer to 0 = more relevant.
|
|
80
|
-
* - Score of -5 is MORE relevant than -20
|
|
81
|
-
* - We use -25 as threshold to allow reasonable matching while filtering noise
|
|
82
|
-
*
|
|
83
|
-
* Previous value: -15 (too strict, filtered out valid matches like -15.85)
|
|
84
|
-
* New value: -25 (allows more relevant tools while still filtering garbage)
|
|
85
|
-
*/
|
|
86
|
-
const MIN_RELEVANCE_THRESHOLD = -25
|
|
87
|
-
|
|
88
|
-
/** Stopwords to filter out before FTS5 query construction */
|
|
89
|
-
const STOPWORDS = new Set([
|
|
90
|
-
"que", "con", "para", "por", "una", "uno", "los", "las", "del",
|
|
91
|
-
"como", "esta", "esto", "ese", "eso", "the", "and", "for",
|
|
92
|
-
"with", "this", "that", "have", "will", "also", "de", "en",
|
|
93
|
-
"el", "la", "se", "su", "sus", "al", "es", "son", "pero",
|
|
94
|
-
"más", "mas", "ya", "yo", "tu", "te", "ti", "mi", "me",
|
|
95
|
-
"hola", "hi", "hello", "hey", "gracias", "thank", "please",
|
|
96
|
-
"ok", "okay", "yes", "si", "no", "bien", "good", "great",
|
|
97
|
-
])
|
|
98
|
-
|
|
99
|
-
/** Conversational patterns that should return empty tool list */
|
|
100
|
-
const CONVERSATIONAL_PATTERNS = [
|
|
101
|
-
/^(hola|hi|hello|hey|buenos? días?|buenas? noches?|qué tal|howdy)/i,
|
|
102
|
-
/^(gracias|thank you|thanks|muchas gracias|muchas thanks)/i,
|
|
103
|
-
/^(cómo estás?|how are you?|qué流水|you doing|qué cuentas)/i,
|
|
104
|
-
/^(sí|yes|ok|okay|de acuerdo|perfecto|claro|por supuesto)/i,
|
|
105
|
-
/^(adiós|bye|nos vemos|see you|later|chau)/i,
|
|
106
|
-
/^(entiendo|understand|i see|ya veo|got it)/i,
|
|
107
|
-
/^(bien|good|great|excelente|awesome|perfect)/i,
|
|
108
|
-
/^(?:\?|¿)$/, // Just a question mark
|
|
109
|
-
]
|
|
110
|
-
|
|
111
|
-
// ─── Tool Catalog ───────────────────────────────────────────────────────────
|
|
112
|
-
//
|
|
113
|
-
// These 47 tools are the core toolset. Each has:
|
|
114
|
-
// - name: unique identifier
|
|
115
|
-
// - description: what the tool does (used for FTS5 matching)
|
|
116
|
-
// - category: semantic domain for grouping
|
|
117
|
-
// - abstractionLevel: atomic (single operation) vs orchestration (manages multiple)
|
|
118
|
-
//
|
|
119
|
-
// The descriptions are enriched with Spanish/English keywords for better FTS5 matching.
|
|
120
|
-
|
|
121
|
-
export const CORE_TOOL_CATALOG: ToolDescriptor[] = [
|
|
122
|
-
// Scheduling tools (cron)
|
|
123
|
-
{ name: "cron_add", description: "Add scheduled tasks with cron expressions, create recurring reminders and alarms for future actions. IMPORTANT: Ask user if one-time or recurring. For ONE-TIME use '0 0 * * *' with maxRuns=1. For DAILY use 'MM HH * * *'. For WEEKLY use 'MM HH * * 1' (Monday). For MONTHLY use 'MM HH 1 * *' (day 1). Spanish keywords: tareas programadas, programar recordatorios, agenda, automatizar, cronograma, tarea repetitiva", category: "scheduling", abstractionLevel: "atomic" },
|
|
124
|
-
{ name: "cron_list", description: "List all scheduled tasks, show upcoming cron jobs and their next execution times. Spanish keywords: ver tareas, listar recordatorios, mostrar cronograma, tareas pendientes, lista de tareas", category: "scheduling", abstractionLevel: "atomic" },
|
|
125
|
-
{ name: "cron_remove", description: "Remove scheduled tasks, delete cron jobs and cancel scheduled reminders. Spanish keywords: eliminar tarea programada, borrar recordatorio, cancelar, eliminar, quitar tarea", category: "scheduling", abstractionLevel: "atomic" },
|
|
126
|
-
{ name: "cron_edit", description: "Edit scheduled tasks, modify cron expressions and update scheduled job configurations. Spanish keywords: modificar tarea, cambiar horario, actualizar programación, editar tarea", category: "scheduling", abstractionLevel: "atomic" },
|
|
127
|
-
|
|
128
|
-
// Project management tools (high-level orchestration)
|
|
129
|
-
{ name: "project_create", description: "Create project with tasks, start new project for complex multi-step work. Spanish keywords: crear proyecto, nuevo proyecto, iniciar trabajo, proyecto nuevo, comenzar proyecto", category: "projects", abstractionLevel: "orchestration" },
|
|
130
|
-
{ name: "project_start", description: "Create new project for complex tasks, initialize project structure and planning. Spanish keywords: empezar proyecto, comenzar tarea, iniciar planificación, iniciar proyecto", category: "projects", abstractionLevel: "orchestration" },
|
|
131
|
-
{ name: "project_update", description: "Update project progress, mark progress percentage and status changes. Spanish keywords: actualizar progreso, marcar avance, estado del proyecto, porcentaje completado", category: "projects", abstractionLevel: "atomic" },
|
|
132
|
-
{ name: "project_done", description: "Mark project complete, close finished projects and archive results. Spanish keywords: proyecto terminado, cerrar proyecto, finalizar, proyecto completado, marcar como hecho", category: "projects", abstractionLevel: "atomic" },
|
|
133
|
-
{ name: "project_fail", description: "Mark project failed, record failure reason and lessons learned. Spanish keywords: proyecto fallido, error, marcar como fallido, proyecto fracasado, fracaso", category: "projects", abstractionLevel: "atomic" },
|
|
134
|
-
|
|
135
|
-
// Task management (atomic)
|
|
136
|
-
{ name: "task_create", description: "Add task to project, create subtasks and action items within projects. Spanish keywords: crear tarea, nueva tarea, agregar pendiente, agregar tarea, crear subtarea", category: "projects", abstractionLevel: "atomic" },
|
|
137
|
-
{ name: "task_update", description: "Update task status, mark tasks as complete or in progress. Spanish keywords: actualizar tarea, cambiar estado, marcar completa, tarea completada, tarea en progreso", category: "projects", abstractionLevel: "atomic" },
|
|
138
|
-
|
|
139
|
-
// Code execution
|
|
140
|
-
{ name: "cli_exec", description: "Execute shell commands, run bash scripts and system commands. Spanish keywords: ejecutar comando, terminal, línea de comandos, bash, script, comando del sistema", category: "cli", abstractionLevel: "atomic" },
|
|
141
|
-
|
|
142
|
-
// Web tools
|
|
143
|
-
{ name: "web_search", description: "Search web for current information, find up-to-date news facts and research. Spanish keywords: buscar en internet, buscar web, información, noticias, investigación, buscar", category: "web", abstractionLevel: "atomic" },
|
|
144
|
-
{ name: "web_fetch", description: "Fetch content from URL, download and extract content from web pages. Spanish keywords: obtener página, descargar web, extraer contenido, obtener contenido, página web", category: "web", abstractionLevel: "atomic" },
|
|
145
|
-
|
|
146
|
-
// Memory tools
|
|
147
|
-
{ name: "memory_write", description: "Store in long-term memory, save information to persistent memory for later retrieval. Spanish keywords: guardar memoria, guardar información, recordar, guardar dato, memoria", category: "memory", abstractionLevel: "atomic" },
|
|
148
|
-
{ name: "memory_read", description: "Retrieve from memory by title, fetch saved information using memory identifier. Spanish keywords: leer memoria, recuperar información, recordar, obtener dato, buscar memoria", category: "memory", abstractionLevel: "atomic" },
|
|
149
|
-
{ name: "memory_list", description: "List all memory entries, show all saved memories and stored knowledge. Spanish keywords: listar memorias, ver memorias guardadas, todas las memorias, lista de memorias", category: "memory", abstractionLevel: "atomic" },
|
|
150
|
-
{ name: "memory_search", description: "Search memory by content, find memories containing specific keywords. Spanish keywords: buscar en memoria, buscar información guardada, buscar en recuerdos", category: "memory", abstractionLevel: "atomic" },
|
|
151
|
-
{ name: "memory_delete", description: "Delete memory entry, remove saved memory from long-term storage. Spanish keywords: borrar memoria, eliminar información guardada, borrar dato, eliminar memoria", category: "memory", abstractionLevel: "atomic" },
|
|
152
|
-
|
|
153
|
-
// Agent/worker management
|
|
154
|
-
{ name: "create_agent", description: "Create specialized worker agent, spawn new agent for specific task execution. Spanish keywords: crear agente, nuevo agente, trabajador, crear worker, nuevo trabajador", category: "agents", abstractionLevel: "orchestration" },
|
|
155
|
-
{ name: "find_agent", description: "Find existing worker agents, locate running or idle worker agents. Spanish keywords: buscar agente, encontrar trabajador, localizar, buscar worker, encontrar agente", category: "agents", abstractionLevel: "atomic" },
|
|
156
|
-
{ name: "archive_agent", description: "Archive unnecessary worker, terminate and archive idle or completed agents. Spanish keywords: archivar agente, terminar agente, borrar trabajador, desactivar agente", category: "agents", abstractionLevel: "atomic" },
|
|
157
|
-
|
|
158
|
-
// Notes/persistence
|
|
159
|
-
{ name: "save_note", description: "Save persistent note to scratchpad, write quick notes and reminders. Spanish keywords: guardar nota, escribir nota, recordatorio rápido, nota rápida, apuntar", category: "core", abstractionLevel: "atomic" },
|
|
160
|
-
|
|
161
|
-
// Notifications/reporting
|
|
162
|
-
{ name: "notify", description: "Send system notification, alert user with message or alert. Spanish keywords: notificar, enviar notificación, alertar, aviso, alarma", category: "core", abstractionLevel: "atomic" },
|
|
163
|
-
{ name: "report_progress", description: "Report progress to user, inform user of current status and completion. Spanish keywords: reportar progreso, informar estado, actualizar,报告进度, progreso", category: "core", abstractionLevel: "atomic" },
|
|
164
|
-
|
|
165
|
-
// Browser automation
|
|
166
|
-
{ name: "browser_navigate", description: "Navigate to URL and get content, open web pages and extract information. Spanish keywords: navegar web, abrir página, ir a sitio, navegar, ir a página", category: "browser", abstractionLevel: "atomic" },
|
|
167
|
-
{ name: "browser_fetch", description: "Fetch with custom HTTP method/headers, make custom HTTP requests. Spanish keywords: obtener página web, descargar contenido, peticion http, obtener datos", category: "browser", abstractionLevel: "atomic" },
|
|
168
|
-
{ name: "browser_screenshot", description: "Take webpage screenshot, capture visual snapshot of web page. Spanish keywords: captura de pantalla, screenshot, fotografiar página, imagen de página", category: "browser", abstractionLevel: "atomic" },
|
|
169
|
-
{ name: "browser_click", description: "Click element on page, interact with buttons and links in browser. Spanish keywords: hacer clic, presionar botón, clickear, pulsar, botón", category: "browser", abstractionLevel: "atomic" },
|
|
170
|
-
{ name: "browser_type", description: "Type into input field, fill forms and text inputs in browser. Spanish keywords: escribir en página, llenar formulario, introducir texto, completar formulario", category: "browser", abstractionLevel: "atomic" },
|
|
171
|
-
|
|
172
|
-
// Canvas/UI rendering tools
|
|
173
|
-
{ name: "canvas_render", description: "Render component on canvas, display UI components and data visualizations. Spanish keywords: renderizar, mostrar en canvas, visualizar, mostrar componente, dibujar", category: "canvas", abstractionLevel: "atomic" },
|
|
174
|
-
{ name: "canvas_ask", description: "Display form and wait for response, show interactive form and collect user input. Spanish keywords: mostrar formulario, pedir datos, solicitar información, formulario interactivo", category: "canvas", abstractionLevel: "atomic" },
|
|
175
|
-
{ name: "canvas_clear", description: "Clear canvas for session, reset canvas display and start fresh. Spanish keywords: limpiar canvas, borrar pantalla, reiniciar, limpiar, borrar", category: "canvas", abstractionLevel: "atomic" },
|
|
176
|
-
{ name: "canvas_show_card", description: "Display card with labeled items, show structured data in card format. Spanish keywords: mostrar tarjeta, visualizar datos, tarjeta de información, mostrar datos", category: "canvas", abstractionLevel: "atomic" },
|
|
177
|
-
{ name: "canvas_show_progress", description: "Display progress bars, show progress indicators and completion status. Spanish keywords: mostrar progreso, barra de progreso, indicador de progreso, avance", category: "canvas", abstractionLevel: "atomic" },
|
|
178
|
-
{ name: "canvas_show_list", description: "Display key-value list, show information in structured list format. Spanish keywords: mostrar lista, listar elementos, lista de valores, mostrar elementos", category: "canvas", abstractionLevel: "atomic" },
|
|
179
|
-
{ name: "canvas_confirm", description: "Show confirmation dialog, request user confirmation for actions. Spanish keywords: confirmar, diálogo de confirmación, confirmar acción, validación", category: "canvas", abstractionLevel: "atomic" },
|
|
180
|
-
|
|
181
|
-
// CodeBridge (subagent process management)
|
|
182
|
-
{ name: "codebridge_launch", description: "Launch subagent process, spawn new code bridge agent process. Spanish keywords: lanzar proceso, iniciar subagente, ejecutar código, nuevo proceso", category: "code", abstractionLevel: "orchestration" },
|
|
183
|
-
{ name: "codebridge_status", description: "Get status of running subagents, check code bridge agent status. Spanish keywords: estado del proceso, verificar subagente, estado del worker, estado", category: "code", abstractionLevel: "atomic" },
|
|
184
|
-
{ name: "codebridge_cancel", description: "Cancel running subagent, terminate code bridge agent process. Spanish keywords: cancelar proceso, terminar subagente, detener proceso, parar", category: "code", abstractionLevel: "atomic" },
|
|
185
|
-
|
|
186
|
-
// Voice tools
|
|
187
|
-
{ name: "voice_transcribe", description: "Transcribe audio to text, convert speech to written text from audio files. Spanish keywords: transcribir audio, voz a texto, convertir audio, transcripción", category: "voice", abstractionLevel: "atomic" },
|
|
188
|
-
{ name: "voice_speak", description: "Convert text to audio and play, synthesize speech from text. Spanish keywords: hablar, sintetizar voz, texto a voz, reproducir audio, voz", category: "voice", abstractionLevel: "atomic" },
|
|
189
|
-
]
|
|
190
|
-
|
|
191
|
-
// ─── Helper Functions ───────────────────────────────────────────────────────-
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Check if message is purely conversational (no tools needed)
|
|
195
|
-
*
|
|
196
|
-
* Uses pattern matching for common conversational phrases.
|
|
197
|
-
* Also checks for very short messages that are likely greetings.
|
|
198
|
-
*/
|
|
199
|
-
function isConversational(message: string): boolean {
|
|
200
|
-
log.info(`[tool-selector] Checking if message is conversational: "${message}"`)
|
|
201
|
-
const trimmed = message.trim()
|
|
202
|
-
|
|
203
|
-
// Empty or very short messages
|
|
204
|
-
if (trimmed.length < 2) return true
|
|
205
|
-
|
|
206
|
-
// Check conversational patterns
|
|
207
|
-
for (const pattern of CONVERSATIONAL_PATTERNS) {
|
|
208
|
-
if (pattern.test(trimmed)) {
|
|
209
|
-
log.debug(`[tool-selector] Message matched conversational pattern: ${pattern}`)
|
|
210
|
-
return true
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Check if all words are stopwords (likely conversational)
|
|
215
|
-
const words = trimmed.toLowerCase().split(/\s+/)
|
|
216
|
-
const meaningfulWords = words.filter(w => w.length > 2 && !STOPWORDS.has(w))
|
|
217
|
-
if (meaningfulWords.length === 0) {
|
|
218
|
-
log.debug(`[tool-selector] All words are stopwords - conversational`)
|
|
219
|
-
return true
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return false
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Build FTS5 query from user message
|
|
227
|
-
*
|
|
228
|
-
* Strips stopwords, special characters, and limits to 8 keywords.
|
|
229
|
-
* Uses OR operator for flexible matching.
|
|
230
|
-
*/
|
|
231
|
-
function buildFTSQuery(message: string): string {
|
|
232
|
-
log.info(`[tool-selector] Building FTS query from message: "${message}"`)
|
|
233
|
-
const words = message
|
|
234
|
-
.toLowerCase()
|
|
235
|
-
.replace(/[^\p{L}\p{N}\s]/gu, " ")
|
|
236
|
-
.split(/\s+/)
|
|
237
|
-
.filter((w) => w.length > 2 && !STOPWORDS.has(w))
|
|
238
|
-
.slice(0, 8)
|
|
239
|
-
|
|
240
|
-
if (words.length === 0) return ""
|
|
241
|
-
|
|
242
|
-
return words.join(" OR ")
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Determine abstraction level preference
|
|
247
|
-
*
|
|
248
|
-
* Returns 'atomic' to prefer individual tools, 'orchestration' to prefer
|
|
249
|
-
* manager tools. Currently always prefers atomic for better control.
|
|
250
|
-
*/
|
|
251
|
-
function getAbstractionPreference(): "atomic" | "orchestration" {
|
|
252
|
-
// Prefer atomic tools for more predictable behavior
|
|
253
|
-
return "atomic"
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// ─── Main Selection Function ─────────────────────────────────────────────────
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Select tools for a given user message using FTS5 bm25() scoring
|
|
260
|
-
*
|
|
261
|
-
* @param userMessage - The raw user message
|
|
262
|
-
* @param fullToolList - Full list of available tools (for validation/filtering)
|
|
263
|
-
* @returns Array of 0-4 selected tools with scores
|
|
264
|
-
*
|
|
265
|
-
* ALGORITHM:
|
|
266
|
-
* 1. If conversational → return []
|
|
267
|
-
* 2. Build FTS5 query from message keywords
|
|
268
|
-
* 3. Query tools_fts with bm25() scoring
|
|
269
|
-
* 4. Filter results below MIN_RELEVANCE_THRESHOLD
|
|
270
|
-
* 5. If ambiguous → prefer atomic over orchestration
|
|
271
|
-
* 6. Return top maxTools results (default: MAX_TOOLS_PER_TURN)
|
|
272
|
-
*/
|
|
273
|
-
export function selectTools(
|
|
274
|
-
userMessage: string,
|
|
275
|
-
fullToolList: ToolDescriptor[] = CORE_TOOL_CATALOG,
|
|
276
|
-
maxTools: number = MAX_TOOLS_PER_TURN
|
|
277
|
-
): ToolDescriptor[] {
|
|
278
|
-
const startTime = performance.now()
|
|
279
|
-
|
|
280
|
-
// Log incoming user message for debugging/validation
|
|
281
|
-
log.debug(`[tool-selector] Processing user message: "${userMessage.substring(0, 100)}"`)
|
|
282
|
-
|
|
283
|
-
// Step 1: Check if conversational
|
|
284
|
-
if (isConversational(userMessage)) {
|
|
285
|
-
log.debug(`[tool-selector] Conversational message, returning empty array`)
|
|
286
|
-
return []
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// Step 2: Build FTS5 query
|
|
290
|
-
const ftsQuery = buildFTSQuery(userMessage)
|
|
291
|
-
if (!ftsQuery) {
|
|
292
|
-
log.debug(`[tool-selector] No valid FTS query terms, returning empty array`)
|
|
293
|
-
return []
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
log.debug(`[tool-selector] FTS query: "${ftsQuery}"`)
|
|
297
|
-
|
|
298
|
-
// Step 3: Execute FTS5 query with bm25 scoring
|
|
299
|
-
const db = getDb()
|
|
300
|
-
|
|
301
|
-
// Use bm25() for relevance scoring - more accurate than simple MATCH
|
|
302
|
-
// bm25() returns negative scores (more negative = less relevant)
|
|
303
|
-
// We sort by rank ascending (best matches first in FTS5)
|
|
304
|
-
// Get more initially (maxTools * 2) for filtering, then limit to maxTools
|
|
305
|
-
const ftsResults = db.query(`
|
|
306
|
-
SELECT tool_name, bm25(tools_fts) as bm25_score
|
|
307
|
-
FROM tools_fts
|
|
308
|
-
WHERE tools_fts MATCH ?
|
|
309
|
-
ORDER BY bm25_score ASC
|
|
310
|
-
LIMIT ?
|
|
311
|
-
`).all(ftsQuery, maxTools * 2) as { tool_name: string; bm25_score: number }[]
|
|
312
|
-
|
|
313
|
-
if (ftsResults.length === 0) {
|
|
314
|
-
log.debug(`[tool-selector] No FTS matches, returning empty array`)
|
|
315
|
-
return []
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
log.debug(`[tool-selector] Raw FTS results:`, ftsResults.slice(0, 5))
|
|
319
|
-
|
|
320
|
-
// Log relevance scores for debugging
|
|
321
|
-
log.debug(`[tool-selector] Relevance scores:`, ftsResults.map(r => ({ tool: r.tool_name, score: r.bm25_score })))
|
|
322
|
-
|
|
323
|
-
// Step 4: Apply relevance threshold filter
|
|
324
|
-
// bm25() returns negative scores; threshold is -0.5 (loosened from typical -5)
|
|
325
|
-
const relevantResults = ftsResults.filter(r => r.bm25_score >= MIN_RELEVANCE_THRESHOLD)
|
|
326
|
-
|
|
327
|
-
if (relevantResults.length === 0) {
|
|
328
|
-
log.debug(`[tool-selector] All results below threshold ${MIN_RELEVANCE_THRESHOLD}, returning empty`)
|
|
329
|
-
return []
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Step 5: Map to tool descriptors with additional metadata
|
|
333
|
-
const toolMap = new Map(fullToolList.map(t => [t.name, t]))
|
|
334
|
-
|
|
335
|
-
const scoredTools: SelectedTool[] = []
|
|
336
|
-
|
|
337
|
-
for (const result of relevantResults) {
|
|
338
|
-
const tool = toolMap.get(result.tool_name)
|
|
339
|
-
if (tool) {
|
|
340
|
-
scoredTools.push({
|
|
341
|
-
name: tool.name,
|
|
342
|
-
score: result.bm25_score,
|
|
343
|
-
category: tool.category,
|
|
344
|
-
})
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// Step 6: Prefer atomic over orchestration when ambiguous
|
|
349
|
-
// If we have more than MAX_TOOLS_PER_TURN, prioritize by abstraction level
|
|
350
|
-
const abstractionPref = getAbstractionPreference()
|
|
351
|
-
|
|
352
|
-
if (scoredTools.length > MAX_TOOLS_PER_TURN) {
|
|
353
|
-
// Sort by score first, then by abstraction level preference
|
|
354
|
-
// CRITICAL FIX: bm25() returns NEGATIVE scores where closer to 0 = more relevant
|
|
355
|
-
// So we sort ASCENDING (a.score - b.score) to put -8.02 before -5.11
|
|
356
|
-
scoredTools.sort((a, b) => {
|
|
357
|
-
// First by score (ascending for bm25 - closer to 0 is better)
|
|
358
|
-
if (Math.abs(a.score - b.score) > 0.1) {
|
|
359
|
-
return a.score - b.score // ✅ Fixed: ascending for negative bm25 scores
|
|
360
|
-
}
|
|
361
|
-
// Then by abstraction preference (preferred type first)
|
|
362
|
-
const aTool = toolMap.get(a.name)
|
|
363
|
-
const bTool = toolMap.get(b.name)
|
|
364
|
-
const aLevel = aTool?.abstractionLevel ?? "atomic"
|
|
365
|
-
const bLevel = bTool?.abstractionLevel ?? "atomic"
|
|
366
|
-
|
|
367
|
-
if (abstractionPref === "atomic") {
|
|
368
|
-
return (aLevel === "atomic" ? -1 : 1)
|
|
369
|
-
} else {
|
|
370
|
-
return (aLevel === "orchestration" ? -1 : 1)
|
|
371
|
-
}
|
|
372
|
-
})
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// Step 7: Take top N tools
|
|
376
|
-
const topTools = scoredTools.slice(0, maxTools)
|
|
377
|
-
|
|
378
|
-
// Step 8: Return as ToolDescriptor array
|
|
379
|
-
const result = topTools.map(t => toolMap.get(t.name)!).filter(Boolean)
|
|
380
|
-
|
|
381
|
-
const timing = performance.now() - startTime
|
|
382
|
-
|
|
383
|
-
// Log final selected tools with info level (important for tracking tool selection process)
|
|
384
|
-
if (result.length > 0) {
|
|
385
|
-
log.info(`[tool-selector] Selected ${result.length} tools in ${timing.toFixed(2)}ms:`,
|
|
386
|
-
result.map(t => ({ name: t.name, category: t.category })))
|
|
387
|
-
} else {
|
|
388
|
-
log.debug(`[tool-selector] No tools selected, returning empty array in ${timing.toFixed(2)}ms`)
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
return result
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
// ─── Sync Tools to FTS5 ─────────────────────────────────────────────────────
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Sync tool catalog to FTS5 virtual table
|
|
398
|
-
*
|
|
399
|
-
* Called on initialization from gateway/initializer.ts to populate the FTS5 index.
|
|
400
|
-
* Assumes the tools_fts table already exists (created by CONTEXT_ENGINE_SCHEMA).
|
|
401
|
-
* Descriptions are enriched with bilingual keywords for better matching.
|
|
402
|
-
*
|
|
403
|
-
* @param tools - Optional array of tools to sync. If not provided, fetches from DB.
|
|
404
|
-
*/
|
|
405
|
-
export async function syncToolCatalogToFTS(tools?: ToolDescriptor[]): Promise<void> {
|
|
406
|
-
const db = getDb()
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
// Step 1: Build full catalog = CORE_TOOL_CATALOG + any tools in DB not already covered
|
|
410
|
-
// CORE_TOOL_CATALOG has bilingual keywords; DB tools may be dynamically registered
|
|
411
|
-
const catalogByName = new Map<string, ToolDescriptor>(
|
|
412
|
-
CORE_TOOL_CATALOG.map(t => [t.name, t])
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
// Merge in any tools from the DB that are missing from the static catalog
|
|
416
|
-
const dbTools = db.query("SELECT name, description, category FROM tools").all() as Array<{ name: string; description: string | null; category: string | null }>
|
|
417
|
-
for (const row of dbTools) {
|
|
418
|
-
if (!catalogByName.has(row.name)) {
|
|
419
|
-
catalogByName.set(row.name, {
|
|
420
|
-
name: row.name,
|
|
421
|
-
description: row.description ?? row.name,
|
|
422
|
-
category: (row.category ?? "core") as any,
|
|
423
|
-
abstractionLevel: "atomic",
|
|
424
|
-
})
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
// Also merge any explicitly passed tools (e.g. from initializer)
|
|
429
|
-
for (const t of (tools || [])) {
|
|
430
|
-
if (!catalogByName.has(t.name)) {
|
|
431
|
-
catalogByName.set(t.name, t)
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
const toolCatalog = Array.from(catalogByName.values())
|
|
436
|
-
|
|
437
|
-
// Step 2: Atomic transaction for FTS5 sync
|
|
438
|
-
// We use a transaction to ensure that if sync fails, we don't end up with an empty FTS table
|
|
439
|
-
const syncTransaction = db.transaction(() => {
|
|
440
|
-
// Verify table exists inside transaction (optional but safer)
|
|
441
|
-
const tableCheck = db.query("SELECT name FROM sqlite_master WHERE type='table' AND name='tools_fts'").get()
|
|
442
|
-
if (!tableCheck) {
|
|
443
|
-
throw new Error("tools_fts table does not exist!")
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// A: Clear existing data
|
|
447
|
-
db.run("DELETE FROM tools_fts")
|
|
448
|
-
|
|
449
|
-
// B: Prepare insertion
|
|
450
|
-
const insert = db.prepare(`
|
|
451
|
-
INSERT INTO tools_fts(tool_name, name, description, category)
|
|
452
|
-
VALUES (?, ?, ?, ?)
|
|
453
|
-
`)
|
|
454
|
-
|
|
455
|
-
// C: Re-populate
|
|
456
|
-
for (const tool of toolCatalog) {
|
|
457
|
-
const enriched = enrichToolDescription(tool)
|
|
458
|
-
insert.run(tool.name, tool.name, enriched, tool.category)
|
|
459
|
-
}
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
// Execute transaction
|
|
463
|
-
syncTransaction()
|
|
464
|
-
|
|
465
|
-
log.info(`[tool-selector] Atomic sync complete: ${toolCatalog.length} tools indexed in FTS5`)
|
|
466
|
-
|
|
467
|
-
} catch (err) {
|
|
468
|
-
log.error(`[tool-selector] Transactional sync failed:`, err)
|
|
469
|
-
throw err // Re-throw to inform initializer
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Enrich tool description with category-specific keywords
|
|
475
|
-
*
|
|
476
|
-
* This improves FTS5 matching for both English and Spanish queries.
|
|
477
|
-
*/
|
|
478
|
-
function enrichToolDescription(tool: ToolDescriptor): string {
|
|
479
|
-
const keywordsByCategory: Record<string, string> = {
|
|
480
|
-
scheduling: "programar recordatorio alarma cron schedule reminder task future tiempo",
|
|
481
|
-
projects: "proyecto tarea plan organizer milestone backlog sprint work",
|
|
482
|
-
filesystem: "archivo file leer escribir editar documento content source code",
|
|
483
|
-
web: "buscar internet google web search find information news research",
|
|
484
|
-
browser: "navegador browser click screenshot form automation web page UI",
|
|
485
|
-
memory: "recordar nota guardar memory store remember persist knowledge",
|
|
486
|
-
code: "code ejecutar run script bash shell terminal command devops",
|
|
487
|
-
canvas: "canvas diagram visualization graph node edge flow chart",
|
|
488
|
-
agents: "agente worker specialist create delegate hire team manager",
|
|
489
|
-
core: "notificar message alert notify communicate progress status",
|
|
490
|
-
voice: "voz audio transcribir speech speak sintetizar audio voice transcription",
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
const extra = keywordsByCategory[tool.category] ?? ""
|
|
494
|
-
return `${tool.description} ${extra}`
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// ─── Initialization ─────────────────────────────────────────────────────────
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Sanitize an MCP tool name to comply with LLM function-name rules.
|
|
501
|
-
*
|
|
502
|
-
* Gemini (and OpenAI) require: start with letter/underscore, only [a-zA-Z0-9_.-:], max 64 chars.
|
|
503
|
-
* Server names from the UI can contain spaces and special chars (e.g. "X antes twiter").
|
|
504
|
-
*
|
|
505
|
-
* Canonical format: `{safeServer}__{safeTool}` (double underscore as separator)
|
|
506
|
-
*/
|
|
507
|
-
export function mcpToolFullName(serverName: string, toolName: string): string {
|
|
508
|
-
const safe = (s: string) => s.replace(/\s+/g, '_').replace(/[^a-zA-Z0-9_.\-:]/g, '_')
|
|
509
|
-
const full = `${safe(serverName)}__${safe(toolName)}`
|
|
510
|
-
// Ensure starts with letter/underscore and fits within 64 chars
|
|
511
|
-
const trimmed = full.length > 64 ? full.substring(0, 64) : full
|
|
512
|
-
return /^[a-zA-Z_]/.test(trimmed) ? trimmed : `_${trimmed}`.substring(0, 64)
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Sync MCP tools to FTS5
|
|
517
|
-
* Called when MCP servers are connected/updated
|
|
518
|
-
*/
|
|
519
|
-
export async function syncMCPToolsToFTS(
|
|
520
|
-
serverId: string,
|
|
521
|
-
serverName: string,
|
|
522
|
-
mcpTools: Array<{ name: string; description: string; inputSchema?: any }>
|
|
523
|
-
): Promise<void> {
|
|
524
|
-
const db = getDb()
|
|
525
|
-
|
|
526
|
-
try {
|
|
527
|
-
const syncTransaction = db.transaction(() => {
|
|
528
|
-
// Remove existing tools from this server
|
|
529
|
-
db.query("DELETE FROM tools_fts WHERE category = ?").run(`mcp:${serverId}`)
|
|
530
|
-
|
|
531
|
-
// Also remove from tools table
|
|
532
|
-
db.query("DELETE FROM tools WHERE category = ?").run(`mcp:${serverId}`)
|
|
533
|
-
|
|
534
|
-
// Insert new tools to FTS5 and tools table
|
|
535
|
-
const insertFts = db.prepare(`
|
|
536
|
-
INSERT INTO tools_fts(tool_name, name, description, category)
|
|
537
|
-
VALUES (?, ?, ?, ?)
|
|
538
|
-
`)
|
|
539
|
-
|
|
540
|
-
const insertTool = db.prepare(`
|
|
541
|
-
INSERT INTO tools(id, name, description, category, enabled, active)
|
|
542
|
-
VALUES (?, ?, ?, ?, 1, 0)
|
|
543
|
-
`)
|
|
544
|
-
|
|
545
|
-
for (const tool of mcpTools) {
|
|
546
|
-
// Sanitized canonical name — same as what mcpToolExecutors will use
|
|
547
|
-
const fullName = mcpToolFullName(serverName, tool.name)
|
|
548
|
-
|
|
549
|
-
// Enrich description for better FTS matching (bilingual)
|
|
550
|
-
const keywords = `mcp ${serverName.toLowerCase()} automation api external tool action function`
|
|
551
|
-
const enrichedDesc = `${tool.description} ${keywords} ${tool.name.replace(/_/g, ' ')}`
|
|
552
|
-
|
|
553
|
-
// Register in tools table (so search_knowledge can JOIN with the right name)
|
|
554
|
-
const toolId = `mcp_${serverId}_${tool.name.toLowerCase().replace(/[^a-z0-9]/g, '_')}`
|
|
555
|
-
insertTool.run(toolId, fullName, enrichedDesc, `mcp:${serverId}`)
|
|
556
|
-
|
|
557
|
-
// Single FTS entry using sanitized fullName — must match mcpToolExecutors exactly
|
|
558
|
-
insertFts.run(fullName, fullName, enrichedDesc, `mcp:${serverId}`)
|
|
559
|
-
}
|
|
560
|
-
})
|
|
561
|
-
|
|
562
|
-
syncTransaction()
|
|
563
|
-
log.info(`[tool-selector] Synced ${mcpTools.length} MCP tools from ${serverName} to FTS5`)
|
|
564
|
-
} catch (err) {
|
|
565
|
-
log.error(`[tool-selector] Failed to sync MCP tools: ${(err as Error).message}`)
|
|
566
|
-
throw err
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
/**
|
|
571
|
-
* Remove MCP tools from FTS5
|
|
572
|
-
* Called when MCP servers are disconnected/removed
|
|
573
|
-
*/
|
|
574
|
-
export async function removeMCPToolsFromFTS(serverId: string): Promise<void> {
|
|
575
|
-
const db = getDb()
|
|
576
|
-
|
|
577
|
-
try {
|
|
578
|
-
// Remove from tools table first
|
|
579
|
-
db.query("DELETE FROM tools WHERE category = ?").run(`mcp:${serverId}`)
|
|
580
|
-
|
|
581
|
-
// Then remove from FTS5
|
|
582
|
-
db.query("DELETE FROM tools_fts WHERE category = ?").run(`mcp:${serverId}`)
|
|
583
|
-
|
|
584
|
-
log.info(`[tool-selector] Removed MCP tools for server ${serverId} from FTS5`)
|
|
585
|
-
} catch (err) {
|
|
586
|
-
log.error(`[tool-selector] Failed to remove MCP tools: ${(err as Error).message}`)
|
|
587
|
-
throw err
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
/**
|
|
592
|
-
* Initialize the tool selector
|
|
593
|
-
*
|
|
594
|
-
* DEPRECATED: syncToolCatalogToFTS() is now called from gateway/initializer.ts
|
|
595
|
-
* This function is kept for backward compatibility but is no longer needed
|
|
596
|
-
*/
|
|
597
|
-
export function initializeToolSelector(): void {
|
|
598
|
-
log.info(`[tool-selector] Initializing (deprecated - sync is done in gateway/initializer.ts)`)
|
|
599
|
-
// syncToolCatalogToFTS() - No longer needed here, done in gateway/initializer.ts
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// ─── Debug/Test Helpers ─────────────────────────────────────────────────────
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* Get all tools (for debugging/testing)
|
|
606
|
-
*/
|
|
607
|
-
export function getAllTools(): ToolDescriptor[] {
|
|
608
|
-
return [...CORE_TOOL_CATALOG]
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
/**
|
|
612
|
-
* Get tool by name
|
|
613
|
-
*/
|
|
614
|
-
export function getToolByName(name: string): ToolDescriptor | undefined {
|
|
615
|
-
return CORE_TOOL_CATALOG.find(t => t.name === name)
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
/**
|
|
619
|
-
* Get tools by category
|
|
620
|
-
*/
|
|
621
|
-
export function getToolsByCategory(category: string): ToolDescriptor[] {
|
|
622
|
-
return CORE_TOOL_CATALOG.filter(t => t.category === category)
|
|
623
|
-
}
|