@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,503 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLM client — direct official SDKs, no abstraction layers.
|
|
3
|
-
*
|
|
4
|
-
* gemini / google → native Gemini REST API (v1beta, ?key=)
|
|
5
|
-
* anthropic → @anthropic-ai/sdk
|
|
6
|
-
* everything else → openai npm package (OpenAI-compatible endpoint)
|
|
7
|
-
*
|
|
8
|
-
* Public interface (LLMMessage, callLLM, resolveProviderConfig) is stable.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { logger } from "../utils/logger"
|
|
12
|
-
|
|
13
|
-
const log = logger.child("llm-client")
|
|
14
|
-
|
|
15
|
-
// ─── Canonical types ───────────────────────────────────────────────────────────
|
|
16
|
-
|
|
17
|
-
export interface LLMToolCall {
|
|
18
|
-
id: string
|
|
19
|
-
type: "function"
|
|
20
|
-
function: { name: string; arguments: string }
|
|
21
|
-
/** Gemini 3.x thought signature — must be round-tripped for tool-calling. */
|
|
22
|
-
thought_signature?: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface LLMMessage {
|
|
26
|
-
role: "system" | "user" | "assistant" | "tool"
|
|
27
|
-
content: string
|
|
28
|
-
tool_calls?: LLMToolCall[]
|
|
29
|
-
tool_call_id?: string
|
|
30
|
-
name?: string
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface LLMToolDef {
|
|
34
|
-
type: "function"
|
|
35
|
-
function: {
|
|
36
|
-
name: string
|
|
37
|
-
description: string
|
|
38
|
-
parameters: Record<string, unknown>
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export interface LLMCallOptions {
|
|
43
|
-
provider: string
|
|
44
|
-
model: string
|
|
45
|
-
apiKey: string
|
|
46
|
-
baseUrl?: string
|
|
47
|
-
numCtx?: number
|
|
48
|
-
messages: LLMMessage[]
|
|
49
|
-
tools?: LLMToolDef[]
|
|
50
|
-
temperature?: number
|
|
51
|
-
maxTokens?: number
|
|
52
|
-
numGpu?: number
|
|
53
|
-
onToken?: (token: string) => void
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface LLMResponse {
|
|
57
|
-
content: string
|
|
58
|
-
tool_calls?: LLMToolCall[]
|
|
59
|
-
stop_reason: "stop" | "tool_calls" | "max_tokens" | "error"
|
|
60
|
-
usage?: { input_tokens: number; output_tokens: number }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// ─── Provider routing ──────────────────────────────────────────────────────────
|
|
64
|
-
|
|
65
|
-
const GEMINI_PROVIDERS = new Set(["gemini", "google"])
|
|
66
|
-
|
|
67
|
-
const OPENAI_COMPAT_BASE_URLS: Record<string, string> = {
|
|
68
|
-
groq: "https://api.groq.com/openai/v1",
|
|
69
|
-
mistral: "https://api.mistral.ai/v1",
|
|
70
|
-
openrouter: "https://openrouter.ai/api/v1",
|
|
71
|
-
deepseek: "https://api.deepseek.com/v1",
|
|
72
|
-
kimi: "https://api.moonshot.ai/v1",
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ─── Gemini (@google/genai) ───────────────────────────────────────────────────
|
|
76
|
-
|
|
77
|
-
async function callGemini(options: LLMCallOptions): Promise<LLMResponse> {
|
|
78
|
-
const { GoogleGenAI } = await import("@google/genai")
|
|
79
|
-
|
|
80
|
-
const clientOpts: any = { apiKey: options.apiKey }
|
|
81
|
-
if (options.baseUrl?.trim()) clientOpts.httpOptions = { baseUrl: options.baseUrl.trim() }
|
|
82
|
-
|
|
83
|
-
const ai = new GoogleGenAI(clientOpts)
|
|
84
|
-
|
|
85
|
-
// Build toolCallId → name map for converting tool results
|
|
86
|
-
const toolNameMap = new Map<string, string>()
|
|
87
|
-
for (const msg of options.messages) {
|
|
88
|
-
if (msg.role === "assistant" && msg.tool_calls) {
|
|
89
|
-
for (const tc of msg.tool_calls) toolNameMap.set(tc.id, tc.function.name)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Convert canonical messages → Gemini Content[]
|
|
94
|
-
let systemText = ""
|
|
95
|
-
const contents: any[] = []
|
|
96
|
-
|
|
97
|
-
for (const msg of options.messages) {
|
|
98
|
-
if (msg.role === "system") {
|
|
99
|
-
systemText += (systemText ? "\n\n" : "") + msg.content
|
|
100
|
-
continue
|
|
101
|
-
}
|
|
102
|
-
if (msg.role === "user") {
|
|
103
|
-
contents.push({ role: "user", parts: [{ text: msg.content }] })
|
|
104
|
-
continue
|
|
105
|
-
}
|
|
106
|
-
if (msg.role === "assistant") {
|
|
107
|
-
const parts: any[] = []
|
|
108
|
-
if (msg.content) parts.push({ text: msg.content })
|
|
109
|
-
for (const tc of msg.tool_calls ?? []) {
|
|
110
|
-
const fcPart: any = { functionCall: { name: tc.function.name, args: JSON.parse(tc.function.arguments || "{}") } }
|
|
111
|
-
if (tc.thought_signature) fcPart.thoughtSignature = tc.thought_signature
|
|
112
|
-
parts.push(fcPart)
|
|
113
|
-
}
|
|
114
|
-
if (parts.length) contents.push({ role: "model", parts })
|
|
115
|
-
continue
|
|
116
|
-
}
|
|
117
|
-
if (msg.role === "tool") {
|
|
118
|
-
const fnName = toolNameMap.get(msg.tool_call_id || "") || msg.name || "tool"
|
|
119
|
-
const frPart = { functionResponse: { name: fnName, response: { output: msg.content } } }
|
|
120
|
-
const last = contents[contents.length - 1]
|
|
121
|
-
if (last?.role === "user" && Array.isArray(last.parts)) {
|
|
122
|
-
last.parts.push(frPart)
|
|
123
|
-
} else {
|
|
124
|
-
contents.push({ role: "user", parts: [frPart] })
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const config: any = {}
|
|
130
|
-
if (systemText) config.systemInstruction = systemText
|
|
131
|
-
if (options.maxTokens) config.maxOutputTokens = options.maxTokens
|
|
132
|
-
if (options.temperature !== undefined) config.temperature = options.temperature
|
|
133
|
-
if (options.tools?.length) {
|
|
134
|
-
config.tools = [{
|
|
135
|
-
functionDeclarations: options.tools.map((t) => ({
|
|
136
|
-
name: t.function.name,
|
|
137
|
-
description: t.function.description,
|
|
138
|
-
parameters: t.function.parameters,
|
|
139
|
-
})),
|
|
140
|
-
}]
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
log.info(`[llm-client] gemini/${options.model} — ${contents.length} turns, ${options.tools?.length ?? 0} tools`)
|
|
144
|
-
|
|
145
|
-
const response = await ai.models.generateContent({ model: options.model, contents, config })
|
|
146
|
-
|
|
147
|
-
const candidate = response.candidates?.[0]
|
|
148
|
-
const parts: any[] = candidate?.content?.parts ?? []
|
|
149
|
-
|
|
150
|
-
let content = ""
|
|
151
|
-
const tool_calls: LLMToolCall[] = []
|
|
152
|
-
|
|
153
|
-
for (const part of parts) {
|
|
154
|
-
if (part.text) content += part.text
|
|
155
|
-
if (part.functionCall) {
|
|
156
|
-
tool_calls.push({
|
|
157
|
-
id: crypto.randomUUID(),
|
|
158
|
-
type: "function",
|
|
159
|
-
function: { name: part.functionCall.name, arguments: JSON.stringify(part.functionCall.args ?? {}) },
|
|
160
|
-
thought_signature: part.thoughtSignature ?? undefined,
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const stop_reason: LLMResponse["stop_reason"] =
|
|
166
|
-
tool_calls.length > 0 ? "tool_calls"
|
|
167
|
-
: candidate?.finishReason === "MAX_TOKENS" ? "max_tokens"
|
|
168
|
-
: "stop"
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
content,
|
|
172
|
-
tool_calls: tool_calls.length ? tool_calls : undefined,
|
|
173
|
-
stop_reason,
|
|
174
|
-
usage: response.usageMetadata ? {
|
|
175
|
-
input_tokens: response.usageMetadata.promptTokenCount ?? 0,
|
|
176
|
-
output_tokens: response.usageMetadata.candidatesTokenCount ?? 0,
|
|
177
|
-
} : undefined,
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// ─── Anthropic (@anthropic-ai/sdk) ────────────────────────────────────────────
|
|
182
|
-
|
|
183
|
-
async function callAnthropic(options: LLMCallOptions): Promise<LLMResponse> {
|
|
184
|
-
const Anthropic = await import("@anthropic-ai/sdk")
|
|
185
|
-
const client = new Anthropic.default({ apiKey: options.apiKey })
|
|
186
|
-
|
|
187
|
-
const systemText = options.messages
|
|
188
|
-
.filter((m) => m.role === "system")
|
|
189
|
-
.map((m) => m.content)
|
|
190
|
-
.join("\n\n")
|
|
191
|
-
|
|
192
|
-
const anthropicMessages: any[] = []
|
|
193
|
-
|
|
194
|
-
for (const msg of options.messages) {
|
|
195
|
-
if (msg.role === "system") continue
|
|
196
|
-
|
|
197
|
-
if (msg.role === "tool") {
|
|
198
|
-
const block = { type: "tool_result", tool_use_id: msg.tool_call_id, content: msg.content }
|
|
199
|
-
const last = anthropicMessages[anthropicMessages.length - 1]
|
|
200
|
-
if (last?.role === "user" && Array.isArray(last.content)) {
|
|
201
|
-
last.content.push(block)
|
|
202
|
-
} else {
|
|
203
|
-
anthropicMessages.push({ role: "user", content: [block] })
|
|
204
|
-
}
|
|
205
|
-
continue
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
if (msg.role === "assistant" && msg.tool_calls?.length) {
|
|
209
|
-
const content: any[] = []
|
|
210
|
-
if (msg.content) content.push({ type: "text", text: msg.content })
|
|
211
|
-
for (const tc of msg.tool_calls) {
|
|
212
|
-
content.push({ type: "tool_use", id: tc.id, name: tc.function.name, input: JSON.parse(tc.function.arguments || "{}") })
|
|
213
|
-
}
|
|
214
|
-
anthropicMessages.push({ role: "assistant", content })
|
|
215
|
-
continue
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
anthropicMessages.push({ role: msg.role, content: msg.content })
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const tools: any[] = (options.tools ?? []).map((t) => ({
|
|
222
|
-
name: t.function.name,
|
|
223
|
-
description: t.function.description,
|
|
224
|
-
input_schema: t.function.parameters,
|
|
225
|
-
}))
|
|
226
|
-
|
|
227
|
-
const body: any = {
|
|
228
|
-
model: options.model,
|
|
229
|
-
max_tokens: options.maxTokens ?? 8192,
|
|
230
|
-
messages: anthropicMessages,
|
|
231
|
-
}
|
|
232
|
-
if (systemText) body.system = systemText
|
|
233
|
-
if (tools.length) body.tools = tools
|
|
234
|
-
|
|
235
|
-
log.info(`[llm-client] anthropic/${options.model} — ${anthropicMessages.length} msgs, ${tools.length} tools`)
|
|
236
|
-
|
|
237
|
-
const response = await client.messages.create(body)
|
|
238
|
-
|
|
239
|
-
let content = ""
|
|
240
|
-
const tool_calls: LLMToolCall[] = []
|
|
241
|
-
|
|
242
|
-
for (const block of response.content) {
|
|
243
|
-
if (block.type === "text") content = block.text
|
|
244
|
-
if (block.type === "tool_use") {
|
|
245
|
-
tool_calls.push({
|
|
246
|
-
id: block.id,
|
|
247
|
-
type: "function",
|
|
248
|
-
function: { name: block.name, arguments: JSON.stringify(block.input) },
|
|
249
|
-
})
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
return {
|
|
254
|
-
content,
|
|
255
|
-
tool_calls: tool_calls.length ? tool_calls : undefined,
|
|
256
|
-
stop_reason:
|
|
257
|
-
response.stop_reason === "tool_use" ? "tool_calls"
|
|
258
|
-
: response.stop_reason === "max_tokens" ? "max_tokens"
|
|
259
|
-
: "stop",
|
|
260
|
-
usage: {
|
|
261
|
-
input_tokens: response.usage.input_tokens,
|
|
262
|
-
output_tokens: response.usage.output_tokens,
|
|
263
|
-
},
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// ─── Ollama (sdk nativo) ──────────────────────────────────────────────────────
|
|
268
|
-
|
|
269
|
-
async function callOllama(options: LLMCallOptions): Promise<LLMResponse> {
|
|
270
|
-
const { Ollama } = await import("ollama")
|
|
271
|
-
|
|
272
|
-
// Limpiar el prefijo "ollama/" del modelo si viene del DB
|
|
273
|
-
const modelName = options.model.replace(/^ollama\//, "")
|
|
274
|
-
const host = options.baseUrl?.trim() || "http://localhost:11434"
|
|
275
|
-
|
|
276
|
-
try {
|
|
277
|
-
// Detectar Cloud API de Ollama (ollama.com) → usar Authorization header
|
|
278
|
-
const isCloud = host.includes("ollama.com")
|
|
279
|
-
const headers: Record<string, string> = {}
|
|
280
|
-
if (isCloud && options.apiKey) {
|
|
281
|
-
headers["Authorization"] = `Bearer ${options.apiKey}`
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const client = new Ollama({
|
|
285
|
-
host,
|
|
286
|
-
...(Object.keys(headers).length ? { headers } : {}),
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
// Convertir mensajes al formato que espera Ollama:
|
|
290
|
-
// - assistant con tool_calls → incluir tool_calls con arguments como objeto (no string)
|
|
291
|
-
// - tool result → role:"tool", content (sin tool_call_id, Ollama no lo usa)
|
|
292
|
-
const messages = options.messages.map((m): any => {
|
|
293
|
-
if (m.role === "assistant" && m.tool_calls?.length) {
|
|
294
|
-
return {
|
|
295
|
-
role: "assistant",
|
|
296
|
-
content: m.content || "",
|
|
297
|
-
tool_calls: m.tool_calls.map((tc) => ({
|
|
298
|
-
function: {
|
|
299
|
-
name: tc.function.name,
|
|
300
|
-
arguments: (() => {
|
|
301
|
-
try { return JSON.parse(tc.function.arguments) } catch { return {} }
|
|
302
|
-
})(),
|
|
303
|
-
},
|
|
304
|
-
})),
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
if (m.role === "tool") {
|
|
308
|
-
return { role: "tool", content: m.content }
|
|
309
|
-
}
|
|
310
|
-
return { role: m.role, content: m.content }
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
// Convertir tools al formato Ollama (igual que OpenAI function-calling)
|
|
314
|
-
const tools = options.tools?.map((t) => ({
|
|
315
|
-
type: "function" as const,
|
|
316
|
-
function: {
|
|
317
|
-
name: t.function.name,
|
|
318
|
-
description: t.function.description,
|
|
319
|
-
parameters: t.function.parameters,
|
|
320
|
-
},
|
|
321
|
-
}))
|
|
322
|
-
|
|
323
|
-
// Opciones de runtime (num_ctx para contextos grandes)
|
|
324
|
-
const runtimeOptions: Record<string, unknown> = {}
|
|
325
|
-
if (options.numCtx) runtimeOptions.num_ctx = options.numCtx
|
|
326
|
-
if (options.numGpu !== undefined) runtimeOptions.num_gpu = options.numGpu
|
|
327
|
-
if (options.temperature !== undefined) runtimeOptions.temperature = options.temperature
|
|
328
|
-
|
|
329
|
-
log.info(
|
|
330
|
-
`[llm-client] ollama/${modelName} @ ${isCloud ? "ollama.com" : host} stream=true` +
|
|
331
|
-
` — ${messages.length} msgs, ${tools?.length ?? 0} tools` +
|
|
332
|
-
(options.numCtx ? ` num_ctx=${options.numCtx}` : "")
|
|
333
|
-
)
|
|
334
|
-
|
|
335
|
-
// ── Streaming ───────────────────────────────────────────────────────────────
|
|
336
|
-
const stream = await client.chat({
|
|
337
|
-
model: modelName,
|
|
338
|
-
messages,
|
|
339
|
-
tools: tools?.length ? tools : undefined,
|
|
340
|
-
options: Object.keys(runtimeOptions).length ? runtimeOptions : undefined,
|
|
341
|
-
stream: true,
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
let content = ""
|
|
345
|
-
let promptEvalCount = 0
|
|
346
|
-
let evalCount = 0
|
|
347
|
-
const tool_calls: LLMToolCall[] = []
|
|
348
|
-
|
|
349
|
-
for await (const part of stream) {
|
|
350
|
-
// Acumular texto parcial
|
|
351
|
-
const delta = part.message?.content ?? ""
|
|
352
|
-
if (delta) {
|
|
353
|
-
content += delta
|
|
354
|
-
if (options.onToken) options.onToken(delta)
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// tool_calls solo llegan en el último chunk
|
|
358
|
-
if (part.message?.tool_calls?.length) {
|
|
359
|
-
for (const tc of part.message.tool_calls) {
|
|
360
|
-
tool_calls.push({
|
|
361
|
-
id: crypto.randomUUID(),
|
|
362
|
-
type: "function" as const,
|
|
363
|
-
function: {
|
|
364
|
-
name: (tc as any).function.name,
|
|
365
|
-
arguments: JSON.stringify((tc as any).function.arguments ?? {}),
|
|
366
|
-
},
|
|
367
|
-
})
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Tokens de uso en el chunk final
|
|
372
|
-
if (part.prompt_eval_count !== undefined) promptEvalCount = part.prompt_eval_count
|
|
373
|
-
if (part.eval_count !== undefined) evalCount = part.eval_count
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return {
|
|
377
|
-
content,
|
|
378
|
-
tool_calls: tool_calls.length ? tool_calls : undefined,
|
|
379
|
-
stop_reason: tool_calls.length > 0 ? "tool_calls" : "stop",
|
|
380
|
-
usage:
|
|
381
|
-
evalCount > 0
|
|
382
|
-
? { input_tokens: promptEvalCount, output_tokens: evalCount }
|
|
383
|
-
: undefined,
|
|
384
|
-
}
|
|
385
|
-
} catch (error: any) {
|
|
386
|
-
// Logger mucho más explícito para errores críticos (especialmente resource issues)
|
|
387
|
-
log.error(`[llm-client] FAILED call to ollama/${modelName} at ${host}`)
|
|
388
|
-
log.error(`[llm-client] Error details: ${error.message || error}`)
|
|
389
|
-
if (options.numCtx) log.error(`[llm-client] Context requested: num_ctx=${options.numCtx}`)
|
|
390
|
-
if (options.tools?.length) log.error(`[llm-client] Tools defined: ${options.tools.length}`)
|
|
391
|
-
|
|
392
|
-
// Sugerencia proactiva si es el error típico de Ollama server crash
|
|
393
|
-
if (error.message?.includes("model runner has unexpectedly stopped")) {
|
|
394
|
-
log.warn(`[llm-client] TIP: This usually means Ollama ran out of VRAM/RAM. Try reducing 'num_ctx' or the number of tools.`)
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
throw error // Re-throw to be caught by the main callLLM for consistent response
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
// ─── OpenAI-compatible (openai npm package) ────────────────────────────────────
|
|
403
|
-
|
|
404
|
-
async function callOpenAICompat(options: LLMCallOptions): Promise<LLMResponse> {
|
|
405
|
-
const { default: OpenAI } = await import("openai")
|
|
406
|
-
|
|
407
|
-
const baseURL = options.baseUrl?.trim() || OPENAI_COMPAT_BASE_URLS[options.provider] || undefined
|
|
408
|
-
const isLocal = baseURL?.includes("localhost") || baseURL?.includes("127.0.0.1")
|
|
409
|
-
const apiKey = options.apiKey || (isLocal ? "ollama" : "missing-api-key")
|
|
410
|
-
|
|
411
|
-
const client = new OpenAI({ apiKey, baseURL })
|
|
412
|
-
|
|
413
|
-
const body: any = {
|
|
414
|
-
model: options.provider === "ollama" ? options.model.replace(/^ollama\//, "") : options.model,
|
|
415
|
-
messages: options.messages,
|
|
416
|
-
temperature: options.temperature ?? 0.7,
|
|
417
|
-
}
|
|
418
|
-
if (options.maxTokens) body.max_tokens = options.maxTokens
|
|
419
|
-
if (options.numCtx && isLocal) body.num_ctx = options.numCtx
|
|
420
|
-
if (options.tools?.length) {
|
|
421
|
-
body.tools = options.tools
|
|
422
|
-
body.tool_choice = "auto"
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
log.info(`[llm-client] ${options.provider}/${body.model} — ${options.messages.length} msgs, ${options.tools?.length ?? 0} tools`)
|
|
426
|
-
|
|
427
|
-
const response = await client.chat.completions.create(body)
|
|
428
|
-
const choice = response.choices[0]
|
|
429
|
-
const msg = choice.message
|
|
430
|
-
|
|
431
|
-
const tool_calls: LLMToolCall[] | undefined = (msg.tool_calls as any[])?.map((tc: any) => ({
|
|
432
|
-
id: tc.id,
|
|
433
|
-
type: "function" as const,
|
|
434
|
-
function: { name: tc.function.name, arguments: tc.function.arguments },
|
|
435
|
-
}))
|
|
436
|
-
|
|
437
|
-
return {
|
|
438
|
-
content: msg.content ?? "",
|
|
439
|
-
tool_calls: tool_calls?.length ? tool_calls : undefined,
|
|
440
|
-
stop_reason:
|
|
441
|
-
choice.finish_reason === "tool_calls" ? "tool_calls"
|
|
442
|
-
: choice.finish_reason === "length" ? "max_tokens"
|
|
443
|
-
: "stop",
|
|
444
|
-
usage: response.usage ? {
|
|
445
|
-
input_tokens: response.usage.prompt_tokens,
|
|
446
|
-
output_tokens: response.usage.completion_tokens,
|
|
447
|
-
} : undefined,
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// ─── Public API ────────────────────────────────────────────────────────────────
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* Call any LLM provider. Returns a canonical LLMResponse regardless of provider.
|
|
455
|
-
*/
|
|
456
|
-
export async function callLLM(options: LLMCallOptions): Promise<LLMResponse> {
|
|
457
|
-
try {
|
|
458
|
-
if (GEMINI_PROVIDERS.has(options.provider)) return await callGemini(options)
|
|
459
|
-
if (options.provider === "anthropic") return await callAnthropic(options)
|
|
460
|
-
if (options.provider === "ollama") return await callOllama(options)
|
|
461
|
-
return await callOpenAICompat(options)
|
|
462
|
-
} catch (err) {
|
|
463
|
-
const msg = (err as Error).message
|
|
464
|
-
const cleanModel = options.model.replace(new RegExp(`^${options.provider}\\/`), "")
|
|
465
|
-
log.error(`[llm-client] Error calling ${options.provider}/${cleanModel}: ${msg}`)
|
|
466
|
-
return { content: `[LLM Error] ${msg}`, stop_reason: "error" }
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
/**
|
|
471
|
-
* Resolve provider config from DB (decrypts API key).
|
|
472
|
-
*/
|
|
473
|
-
export async function resolveProviderConfig(
|
|
474
|
-
providerId: string,
|
|
475
|
-
modelId: string
|
|
476
|
-
): Promise<Pick<LLMCallOptions, "provider" | "model" | "apiKey" | "baseUrl" | "numCtx" | "numGpu">> {
|
|
477
|
-
const { getDb } = await import("../storage/sqlite")
|
|
478
|
-
const { decryptApiKey } = await import("../storage/crypto")
|
|
479
|
-
|
|
480
|
-
const db = getDb()
|
|
481
|
-
const providerRow = db
|
|
482
|
-
.query<any, [string]>("SELECT * FROM providers WHERE id = ? AND enabled = 1")
|
|
483
|
-
.get(providerId)
|
|
484
|
-
|
|
485
|
-
let apiKey = ""
|
|
486
|
-
if (providerRow?.api_key_encrypted && providerRow?.api_key_iv) {
|
|
487
|
-
try {
|
|
488
|
-
apiKey = await decryptApiKey(providerRow.api_key_encrypted, providerRow.api_key_iv)
|
|
489
|
-
} catch { /* fall through to env var */ }
|
|
490
|
-
}
|
|
491
|
-
if (!apiKey) {
|
|
492
|
-
apiKey = process.env[`${providerId.toUpperCase()}_API_KEY`] || ""
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return {
|
|
496
|
-
provider: providerId,
|
|
497
|
-
model: modelId,
|
|
498
|
-
apiKey,
|
|
499
|
-
baseUrl: providerRow?.base_url || undefined,
|
|
500
|
-
numCtx: providerRow?.num_ctx ?? undefined,
|
|
501
|
-
numGpu: providerRow?.num_gpu ?? undefined,
|
|
502
|
-
}
|
|
503
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native Tools Type Definitions
|
|
3
|
-
*
|
|
4
|
-
* Tool interface for native Hive tools (no LangChain)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export interface Tool {
|
|
8
|
-
name: string
|
|
9
|
-
description: string
|
|
10
|
-
parameters: {
|
|
11
|
-
type: "object"
|
|
12
|
-
properties: Record<string, ToolParameter>
|
|
13
|
-
required?: string[]
|
|
14
|
-
}
|
|
15
|
-
execute: (params: Record<string, unknown>, config?: any) => Promise<string | object>
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface ToolParameter {
|
|
19
|
-
type: string
|
|
20
|
-
description?: string
|
|
21
|
-
enum?: string[]
|
|
22
|
-
items?: ToolParameter
|
|
23
|
-
properties?: Record<string, ToolParameter>
|
|
24
|
-
required?: string[]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface ToolResult {
|
|
28
|
-
success: boolean
|
|
29
|
-
result?: any
|
|
30
|
-
error?: string
|
|
31
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FTS5-based Playbook Rules Selector (ACE Curator)
|
|
3
|
-
*
|
|
4
|
-
* This module allows the Context Compiler to inject relevant evolved rules
|
|
5
|
-
* into the agent prompt based on semantic relevance to the current message.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { getDb } from "../storage/sqlite"
|
|
9
|
-
import { logger } from "../utils/logger"
|
|
10
|
-
|
|
11
|
-
const log = logger.child("playbook-selector")
|
|
12
|
-
|
|
13
|
-
// ─── Types ───────────────────────────────────────────────────────────────────────
|
|
14
|
-
|
|
15
|
-
export interface PlaybookRule {
|
|
16
|
-
id: number
|
|
17
|
-
rule: string
|
|
18
|
-
category: string
|
|
19
|
-
applicable_to?: string
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// ─── Configuration ─────────────────────────────────────────────────────────────
|
|
23
|
-
|
|
24
|
-
/** Maximum rules to inject per context window */
|
|
25
|
-
const MAX_RULES_PER_TURN = 5
|
|
26
|
-
|
|
27
|
-
/** Minimum bm25 score threshold for rules */
|
|
28
|
-
const MIN_RELEVANCE_THRESHOLD = -10 // Relaxed for better matching
|
|
29
|
-
|
|
30
|
-
// ─── Selection Logic ───────────────────────────────────────────────────────────
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Select relevant rules from the Playbook based on semantic matching
|
|
34
|
-
*/
|
|
35
|
-
export function selectPlaybookRules(message: string): PlaybookRule[] {
|
|
36
|
-
const db = getDb()
|
|
37
|
-
const startTime = performance.now()
|
|
38
|
-
|
|
39
|
-
// Clean query
|
|
40
|
-
const keywords = message
|
|
41
|
-
.toLowerCase()
|
|
42
|
-
// Keep only letters, numbers, spaces (strips ALL FTS5 special syntax)
|
|
43
|
-
.replace(/[^\p{L}\p{N}\s]/gu, " ")
|
|
44
|
-
.split(/\s+/)
|
|
45
|
-
.filter(w => w.length > 3)
|
|
46
|
-
.slice(0, 5)
|
|
47
|
-
|
|
48
|
-
if (keywords.length === 0) return []
|
|
49
|
-
|
|
50
|
-
const ftsQuery = keywords.join(" OR ")
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
// Query FTS table
|
|
54
|
-
const ftsResults = db.query(`
|
|
55
|
-
SELECT rowid, bm25(playbook_fts) as score
|
|
56
|
-
FROM playbook_fts
|
|
57
|
-
WHERE playbook_fts MATCH ?
|
|
58
|
-
ORDER BY score ASC
|
|
59
|
-
LIMIT ?
|
|
60
|
-
`).all(ftsQuery, MAX_RULES_PER_TURN) as Array<{ rowid: number; score: number }>
|
|
61
|
-
|
|
62
|
-
const relevantIds = ftsResults
|
|
63
|
-
.filter(r => r.score >= MIN_RELEVANCE_THRESHOLD)
|
|
64
|
-
.map(r => r.rowid)
|
|
65
|
-
|
|
66
|
-
if (relevantIds.length === 0) return []
|
|
67
|
-
|
|
68
|
-
// Fetch full rules
|
|
69
|
-
const rules = db.query(`
|
|
70
|
-
SELECT id, rule, category, applicable_to
|
|
71
|
-
FROM playbook
|
|
72
|
-
WHERE id IN (${relevantIds.map(() => '?').join(',')})
|
|
73
|
-
AND active = 1
|
|
74
|
-
`).all(...relevantIds) as PlaybookRule[]
|
|
75
|
-
|
|
76
|
-
const timing = performance.now() - startTime
|
|
77
|
-
log.info(`[playbook-selector] Selected ${rules.length} rules in ${timing.toFixed(2)}ms`)
|
|
78
|
-
|
|
79
|
-
return rules
|
|
80
|
-
} catch (err) {
|
|
81
|
-
log.error(`[playbook-selector] Failed to select rules:`, err)
|
|
82
|
-
return []
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ─── Sync Logic ───────────────────────────────────────────────────────────────
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Sync active playbook rules to FTS5 virtual table
|
|
90
|
-
*/
|
|
91
|
-
export async function syncPlaybookToFTS(): Promise<void> {
|
|
92
|
-
const db = getDb()
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
// Step 1: Get active rules
|
|
96
|
-
const rules = db.query(`
|
|
97
|
-
SELECT id, rule, category, applicable_to
|
|
98
|
-
FROM playbook
|
|
99
|
-
WHERE active = 1
|
|
100
|
-
`).all() as Array<{
|
|
101
|
-
id: number
|
|
102
|
-
rule: string
|
|
103
|
-
category: string
|
|
104
|
-
applicable_to: string
|
|
105
|
-
}>
|
|
106
|
-
|
|
107
|
-
if (rules.length === 0) {
|
|
108
|
-
log.debug(`[playbook-selector] No rules in playbook to sync`)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Step 2: Atomic transaction for FTS5 sync
|
|
112
|
-
const syncTransaction = db.transaction(() => {
|
|
113
|
-
// Verify table exists
|
|
114
|
-
const tableCheck = db.query("SELECT name FROM sqlite_master WHERE type='table' AND name='playbook_fts'").get()
|
|
115
|
-
if (!tableCheck) {
|
|
116
|
-
throw new Error("playbook_fts table does not exist!")
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// A: Clear existing data
|
|
120
|
-
db.run("DELETE FROM playbook_fts")
|
|
121
|
-
|
|
122
|
-
// B: Prepare insertion
|
|
123
|
-
const insert = db.prepare(`
|
|
124
|
-
INSERT INTO playbook_fts(rowid, rule, category, applicable_to)
|
|
125
|
-
VALUES (?, ?, ?, ?)
|
|
126
|
-
`)
|
|
127
|
-
|
|
128
|
-
// C: Re-populate
|
|
129
|
-
for (const item of rules) {
|
|
130
|
-
insert.run(item.id, item.rule, item.category, item.applicable_to)
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
// Execute transaction
|
|
135
|
-
syncTransaction()
|
|
136
|
-
|
|
137
|
-
log.info(`[playbook-selector] Atomic sync complete: ${rules.length} rules indexed in FTS5`)
|
|
138
|
-
|
|
139
|
-
} catch (err) {
|
|
140
|
-
log.error(`[playbook-selector] Transactional sync failed:`, err)
|
|
141
|
-
throw err
|
|
142
|
-
}
|
|
143
|
-
}
|