@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,520 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent Loop — native implementation, no LangGraph.
|
|
3
|
-
*
|
|
4
|
-
* Replaces supervisor.ts + graph.ts.
|
|
5
|
-
*
|
|
6
|
-
* Pattern:
|
|
7
|
-
* user message → context compiler → model call → [tool call → model call]* → response
|
|
8
|
-
*
|
|
9
|
-
* Exposes an async generator compatible with the existing providers/index.ts stream API:
|
|
10
|
-
* yield { agent: { messages: [AIMessage] } }
|
|
11
|
-
* yield { tools: { messages: [ToolMessage] } }
|
|
12
|
-
*
|
|
13
|
-
* Also used directly by runAgentIsolated() for worker tasks.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { logger } from "../utils/logger"
|
|
17
|
-
import { getDb } from "../storage/sqlite"
|
|
18
|
-
import { callLLM, resolveProviderConfig, type LLMMessage } from "./llm-client"
|
|
19
|
-
import { addMessage } from "./conversation-store"
|
|
20
|
-
import { saveTrace, recordLLMUsage } from "./tracer"
|
|
21
|
-
import { maybeCompact, clearOldToolResults } from "./compaction"
|
|
22
|
-
import { emitCanvas } from "../canvas/emitter"
|
|
23
|
-
import type { MCPClientManager } from "@johpaz/hive-mcp"
|
|
24
|
-
import { compileContext } from "./context-compiler"
|
|
25
|
-
import { formatToolResult, parse as parseToon } from "../utils/toon"
|
|
26
|
-
import { resolveUserId, resolveAgentId } from "../storage/onboarding"
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Execute a tool by name from the available tools list
|
|
30
|
-
* This is a local helper function since executeTool is not exported elsewhere
|
|
31
|
-
*
|
|
32
|
-
* Tool results are formatted in TOON to save tokens on input to the model.
|
|
33
|
-
*/
|
|
34
|
-
async function executeTool(
|
|
35
|
-
allTools: Array<{ name: string; execute?: (params: Record<string, unknown>, config?: any) => Promise<unknown> }>,
|
|
36
|
-
toolName: string,
|
|
37
|
-
args: unknown,
|
|
38
|
-
config: { user_id?: string; thread_id?: string; channel?: string; workspace?: string | null }
|
|
39
|
-
): Promise<string> {
|
|
40
|
-
const tool = allTools.find(t => t.name === toolName)
|
|
41
|
-
if (!tool?.execute) {
|
|
42
|
-
return `[Tool Error] Tool '${toolName}' not found or not executable`
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const parsedArgs = typeof args === 'string' ? JSON.parse(args) : args
|
|
46
|
-
const result = await tool.execute(parsedArgs as Record<string, unknown>, { configurable: config })
|
|
47
|
-
// TOON format for token savings on model input
|
|
48
|
-
return formatToolResult(result)
|
|
49
|
-
} catch (err) {
|
|
50
|
-
// Also format errors as TOON
|
|
51
|
-
return formatToolResult({
|
|
52
|
-
error: true,
|
|
53
|
-
tool: toolName,
|
|
54
|
-
message: (err as Error).message,
|
|
55
|
-
timestamp: new Date().toISOString(),
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const log = logger.child("agent-loop")
|
|
61
|
-
|
|
62
|
-
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
63
|
-
|
|
64
|
-
export interface AgentLoopOptions {
|
|
65
|
-
agentId: string
|
|
66
|
-
userMessage: string
|
|
67
|
-
threadId: string
|
|
68
|
-
channel?: string
|
|
69
|
-
mcpManager?: MCPClientManager | null
|
|
70
|
-
/** System prompt override (from server.ts config) */
|
|
71
|
-
systemPromptOverride?: string
|
|
72
|
-
/** Worker mode: isolated context + single-task execution */
|
|
73
|
-
isolated?: boolean
|
|
74
|
-
taskContext?: string
|
|
75
|
-
onStep?: (step: StepEvent) => Promise<void>
|
|
76
|
-
/** User ID for context propagation */
|
|
77
|
-
userId?: string
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface StepEvent {
|
|
81
|
-
type: "text" | "tool_call" | "tool_result"
|
|
82
|
-
message: string
|
|
83
|
-
toolName?: string
|
|
84
|
-
isError?: boolean
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ─── Stream chunk types (compatible with providers/index.ts) ─────────────────
|
|
88
|
-
|
|
89
|
-
export interface StreamChunk {
|
|
90
|
-
agent?: { messages: any[] }
|
|
91
|
-
tools?: { messages: any[] }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// ─── Main agent loop ──────────────────────────────────────────────────────────
|
|
95
|
-
|
|
96
|
-
export async function* runAgent(
|
|
97
|
-
opts: AgentLoopOptions
|
|
98
|
-
): AsyncGenerator<StreamChunk> {
|
|
99
|
-
const t0 = performance.now()
|
|
100
|
-
const db = getDb()
|
|
101
|
-
|
|
102
|
-
// Load agent config from DB
|
|
103
|
-
const agent = db.query<any, [string]>("SELECT * FROM agents WHERE id = ?").get(opts.agentId)
|
|
104
|
-
if (!agent) throw new Error(`Agent not found: ${opts.agentId}`)
|
|
105
|
-
|
|
106
|
-
const agentName = agent.name || opts.agentId
|
|
107
|
-
const maxIterations = agent.max_iterations || 10
|
|
108
|
-
|
|
109
|
-
// Resolve LLM provider config
|
|
110
|
-
const providerCfg = await resolveProviderConfig(
|
|
111
|
-
agent.provider_id || "openai",
|
|
112
|
-
agent.model_id || "gpt-4o-mini"
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
const cleanModel = providerCfg.model.replace(new RegExp(`^${providerCfg.provider}\\/`), "")
|
|
116
|
-
log.info(`[agent-loop] Starting: agent=${agentName} thread=${opts.threadId} provider=${providerCfg.provider}/${cleanModel}`)
|
|
117
|
-
|
|
118
|
-
emitCanvas("canvas:node_update", {
|
|
119
|
-
nodeId: agentName,
|
|
120
|
-
changes: { status: "thinking" },
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
// Store the user message in conversation history
|
|
124
|
-
if (!opts.isolated) {
|
|
125
|
-
addMessage(opts.threadId, "user", opts.userMessage, { channel: opts.channel })
|
|
126
|
-
// Run compaction if conversation history is getting large
|
|
127
|
-
await maybeCompact(opts.threadId)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Compile context (system prompt + history + tools)
|
|
131
|
-
const ctx = await compileContext({
|
|
132
|
-
agentId: opts.agentId,
|
|
133
|
-
threadId: opts.threadId,
|
|
134
|
-
userMessage: opts.userMessage,
|
|
135
|
-
channel: opts.channel,
|
|
136
|
-
mcpManager: opts.mcpManager,
|
|
137
|
-
isolated: opts.isolated,
|
|
138
|
-
taskContext: opts.taskContext,
|
|
139
|
-
userId: opts.userId,
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
const systemPrompt = opts.systemPromptOverride || ctx.systemPrompt
|
|
143
|
-
|
|
144
|
-
// Build initial messages array for the model
|
|
145
|
-
let messages: LLMMessage[] = [
|
|
146
|
-
{ role: "system", content: systemPrompt },
|
|
147
|
-
...ctx.messages,
|
|
148
|
-
]
|
|
149
|
-
|
|
150
|
-
// For isolated workers the user message is the task context, not from history
|
|
151
|
-
if (opts.isolated) {
|
|
152
|
-
messages.push({ role: "user", content: opts.userMessage })
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
let iterations = 0
|
|
156
|
-
let totalInputTokens = 0
|
|
157
|
-
let totalOutputTokens = 0
|
|
158
|
-
let finalContent = ""
|
|
159
|
-
// Loop detection: track last tool call signature to break identical consecutive calls
|
|
160
|
-
let lastToolSignature = ""
|
|
161
|
-
let consecutiveRepeat = 0
|
|
162
|
-
|
|
163
|
-
// ── The loop ────────────────────────────────────────────────────────────
|
|
164
|
-
while (iterations < maxIterations) {
|
|
165
|
-
iterations++
|
|
166
|
-
|
|
167
|
-
const response = await callLLM({
|
|
168
|
-
...providerCfg,
|
|
169
|
-
messages: clearOldToolResults(messages) as LLMMessage[],
|
|
170
|
-
tools: ctx.tools.length > 0 ? ctx.tools : undefined,
|
|
171
|
-
})
|
|
172
|
-
|
|
173
|
-
// Accumulate usage
|
|
174
|
-
if (response.usage) {
|
|
175
|
-
totalInputTokens += response.usage.input_tokens
|
|
176
|
-
totalOutputTokens += response.usage.output_tokens
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Emit agent chunk (compatible with providers/index.ts)
|
|
180
|
-
const agentMsg: any = { content: response.content }
|
|
181
|
-
if (response.tool_calls?.length) agentMsg.tool_calls = response.tool_calls
|
|
182
|
-
yield { agent: { messages: [agentMsg] } }
|
|
183
|
-
|
|
184
|
-
// Notify onStep for narration text
|
|
185
|
-
if (opts.onStep && response.content) {
|
|
186
|
-
await opts.onStep({ type: "text", message: response.content })
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ── No tool calls → final response ──────────────────────────────────
|
|
190
|
-
if (!response.tool_calls?.length || response.stop_reason !== "tool_calls") {
|
|
191
|
-
// Use response.content if available, otherwise use fallback message for successful tool execution
|
|
192
|
-
finalContent = response.content && response.content.trim().length > 0
|
|
193
|
-
? response.content
|
|
194
|
-
: "Tarea completada exitosamente."
|
|
195
|
-
// Save assistant message to history
|
|
196
|
-
if (!opts.isolated) {
|
|
197
|
-
addMessage(opts.threadId, "assistant", finalContent)
|
|
198
|
-
}
|
|
199
|
-
break
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// ── Tool calls → execute each tool ──────────────────────────────────
|
|
203
|
-
// Add assistant message with tool_calls to local messages array
|
|
204
|
-
messages.push({
|
|
205
|
-
role: "assistant",
|
|
206
|
-
content: response.content,
|
|
207
|
-
tool_calls: response.tool_calls,
|
|
208
|
-
})
|
|
209
|
-
|
|
210
|
-
for (const tc of response.tool_calls) {
|
|
211
|
-
const toolName = tc.function.name
|
|
212
|
-
|
|
213
|
-
emitCanvas("canvas:node_update", {
|
|
214
|
-
nodeId: agentName,
|
|
215
|
-
changes: { status: "tool_call", currentTool: toolName },
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
if (opts.onStep) {
|
|
219
|
-
if (response.content) {
|
|
220
|
-
await opts.onStep({ type: "text", message: response.content })
|
|
221
|
-
}
|
|
222
|
-
await opts.onStep({
|
|
223
|
-
type: "tool_call",
|
|
224
|
-
toolName,
|
|
225
|
-
message: `Calling tool: \`${toolName}\``,
|
|
226
|
-
})
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const tTool = performance.now()
|
|
230
|
-
const toolResult = await executeTool(
|
|
231
|
-
ctx.allTools,
|
|
232
|
-
toolName,
|
|
233
|
-
tc.function.arguments,
|
|
234
|
-
{
|
|
235
|
-
user_id: opts.userId,
|
|
236
|
-
thread_id: opts.threadId,
|
|
237
|
-
channel: opts.channel,
|
|
238
|
-
workspace: agent.workspace ?? null,
|
|
239
|
-
}
|
|
240
|
-
)
|
|
241
|
-
const toolMs = Math.round(performance.now() - tTool)
|
|
242
|
-
|
|
243
|
-
log.info(`[agent-loop] Tool ${toolName} completed in ${toolMs}ms`)
|
|
244
|
-
|
|
245
|
-
// Log tool result before returning to agent (truncated to avoid flooding logs)
|
|
246
|
-
const resultPreview = toolResult.length > 500
|
|
247
|
-
? toolResult.substring(0, 500) + `… (+${toolResult.length - 500} chars)`
|
|
248
|
-
: toolResult
|
|
249
|
-
log.info(`[agent-loop] Tool result [${toolName}]: ${resultPreview}`)
|
|
250
|
-
|
|
251
|
-
// Clean timestamp from message for trace
|
|
252
|
-
const cleanMessage = opts.userMessage.replace(/^\[Timestamp:.*?\]\n/, "")
|
|
253
|
-
|
|
254
|
-
// Save tool call trace
|
|
255
|
-
saveTrace({
|
|
256
|
-
threadId: opts.threadId,
|
|
257
|
-
agentId: opts.agentId,
|
|
258
|
-
agentName,
|
|
259
|
-
toolUsed: toolName,
|
|
260
|
-
inputSummary: `${cleanMessage.substring(0, 200)} → ${toolName}`,
|
|
261
|
-
outputSummary: toolResult.substring(0, 300),
|
|
262
|
-
success: !toolResult.startsWith("[Tool Error]"),
|
|
263
|
-
errorMessage: toolResult.startsWith("[Tool Error]") ? toolResult : null,
|
|
264
|
-
durationMs: toolMs,
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
// Emit tool chunk
|
|
268
|
-
yield { tools: { messages: [{ content: toolResult, tool_call_id: tc.id }] } }
|
|
269
|
-
|
|
270
|
-
if (opts.onStep) {
|
|
271
|
-
await opts.onStep({ type: "tool_result", message: toolResult })
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Add tool result to messages for next model call
|
|
275
|
-
messages.push({
|
|
276
|
-
role: "tool",
|
|
277
|
-
content: toolResult,
|
|
278
|
-
tool_call_id: tc.id,
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
// Dynamic tool injection: when search_knowledge finds tools, add them to ctx.tools
|
|
282
|
-
// so the LLM can call them in subsequent iterations without re-searching
|
|
283
|
-
if (toolName === "search_knowledge") {
|
|
284
|
-
try {
|
|
285
|
-
const parsed = parseToon(toolResult).data
|
|
286
|
-
const foundTools: Array<{ name: string }> = parsed?.tools ?? []
|
|
287
|
-
const currentToolNames = new Set(ctx.tools.map((t: any) => t.function?.name))
|
|
288
|
-
for (const found of foundTools) {
|
|
289
|
-
if (!currentToolNames.has(found.name)) {
|
|
290
|
-
const nativeTool = ctx.allTools.find(t => t.name === found.name)
|
|
291
|
-
if (nativeTool) {
|
|
292
|
-
ctx.tools.push({
|
|
293
|
-
type: "function",
|
|
294
|
-
function: {
|
|
295
|
-
name: nativeTool.name,
|
|
296
|
-
description: (nativeTool as any).description ?? "",
|
|
297
|
-
parameters: (nativeTool as any).parameters ?? { type: "object", properties: {} },
|
|
298
|
-
},
|
|
299
|
-
})
|
|
300
|
-
log.info(`[agent-loop] Injected discovered tool into loadout: ${nativeTool.name}`)
|
|
301
|
-
currentToolNames.add(found.name)
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
} catch {
|
|
306
|
-
// Non-critical — tool injection is best-effort
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// Loop detection: same tool + same args called consecutively → break
|
|
311
|
-
const sig = `${toolName}:${JSON.stringify(tc.function.arguments)}`
|
|
312
|
-
if (sig === lastToolSignature) {
|
|
313
|
-
consecutiveRepeat++
|
|
314
|
-
if (consecutiveRepeat >= 2) {
|
|
315
|
-
log.warn(`[agent-loop] Loop detected: "${toolName}" called ${consecutiveRepeat + 1} times with same args. Breaking.`)
|
|
316
|
-
finalContent = "No pude completar la tarea porque no encontré las herramientas necesarias para ello."
|
|
317
|
-
break
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
lastToolSignature = sig
|
|
321
|
-
consecutiveRepeat = 0
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
emitCanvas("canvas:node_update", {
|
|
326
|
-
nodeId: agentName,
|
|
327
|
-
changes: { status: "thinking", currentTool: null },
|
|
328
|
-
})
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ── Synthesis call when max iterations hit without a text response ────────
|
|
332
|
-
// The agent spent all iterations on tool calls and never produced a final message.
|
|
333
|
-
// Make one extra call without tools so it summarizes what it did.
|
|
334
|
-
if (!finalContent && !opts.isolated) {
|
|
335
|
-
log.info(`[agent-loop] Max iterations hit with no text response — requesting synthesis`)
|
|
336
|
-
try {
|
|
337
|
-
messages.push({
|
|
338
|
-
role: "user",
|
|
339
|
-
content: "Basándote en lo que hiciste hasta ahora, responde al usuario con un resumen claro de lo que completaste o del estado actual. Sé conciso.",
|
|
340
|
-
})
|
|
341
|
-
const synthesis = await callLLM({
|
|
342
|
-
...providerCfg,
|
|
343
|
-
messages: clearOldToolResults(messages) as LLMMessage[],
|
|
344
|
-
tools: undefined, // no tools — force text response
|
|
345
|
-
})
|
|
346
|
-
if (synthesis.usage) {
|
|
347
|
-
totalInputTokens += synthesis.usage.input_tokens
|
|
348
|
-
totalOutputTokens += synthesis.usage.output_tokens
|
|
349
|
-
}
|
|
350
|
-
finalContent = synthesis.content?.trim() || "He completado las tareas solicitadas."
|
|
351
|
-
addMessage(opts.threadId, "assistant", finalContent)
|
|
352
|
-
yield { agent: { messages: [{ content: finalContent }] } }
|
|
353
|
-
} catch (err) {
|
|
354
|
-
log.warn(`[agent-loop] Synthesis call failed: ${(err as Error).message}`)
|
|
355
|
-
finalContent = "He completado las tareas solicitadas."
|
|
356
|
-
addMessage(opts.threadId, "assistant", finalContent)
|
|
357
|
-
yield { agent: { messages: [{ content: finalContent }] } }
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
// ── Post-loop ────────────────────────────────────────────────────────────
|
|
362
|
-
const durationMs = Math.round(performance.now() - t0)
|
|
363
|
-
|
|
364
|
-
emitCanvas("canvas:node_update", {
|
|
365
|
-
nodeId: agentName,
|
|
366
|
-
changes: { status: "idle", currentTool: null },
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
// Record usage
|
|
370
|
-
recordLLMUsage({
|
|
371
|
-
provider: providerCfg.provider,
|
|
372
|
-
model: providerCfg.model,
|
|
373
|
-
inputTokens: totalInputTokens,
|
|
374
|
-
outputTokens: totalOutputTokens,
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
// Save overall trace
|
|
378
|
-
const cleanMessageFinal = opts.userMessage.replace(/^\[Timestamp:.*?\]\n/, "")
|
|
379
|
-
saveTrace({
|
|
380
|
-
threadId: opts.threadId,
|
|
381
|
-
agentId: opts.agentId,
|
|
382
|
-
agentName,
|
|
383
|
-
inputSummary: cleanMessageFinal.substring(0, 300),
|
|
384
|
-
outputSummary: finalContent.substring(0, 300),
|
|
385
|
-
success: true,
|
|
386
|
-
durationMs,
|
|
387
|
-
tokensUsed: totalInputTokens + totalOutputTokens,
|
|
388
|
-
})
|
|
389
|
-
|
|
390
|
-
log.info(
|
|
391
|
-
`[agent-loop] Done: agent=${agentName} iterations=${iterations} ` +
|
|
392
|
-
`tokens=${totalInputTokens + totalOutputTokens} elapsed=${durationMs}ms`
|
|
393
|
-
)
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// ─── Isolated worker execution (Fase 4.4) ───────────────────────────────────
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Run a worker agent in an isolated context.
|
|
400
|
-
* Returns the final response string.
|
|
401
|
-
*/
|
|
402
|
-
export async function runAgentIsolated(opts: {
|
|
403
|
-
agentId: string
|
|
404
|
-
taskDescription: string
|
|
405
|
-
threadId: string
|
|
406
|
-
mcpManager?: MCPClientManager | null
|
|
407
|
-
}): Promise<string> {
|
|
408
|
-
let lastContent = ""
|
|
409
|
-
for await (const chunk of runAgent({
|
|
410
|
-
agentId: opts.agentId,
|
|
411
|
-
userMessage: opts.taskDescription,
|
|
412
|
-
threadId: opts.threadId,
|
|
413
|
-
isolated: true,
|
|
414
|
-
taskContext: opts.taskDescription,
|
|
415
|
-
mcpManager: opts.mcpManager,
|
|
416
|
-
})) {
|
|
417
|
-
if (chunk.agent?.messages?.[0]?.content) {
|
|
418
|
-
lastContent = chunk.agent.messages[0].content
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
return lastContent
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// ─── Shim: AgentLoop class with stream() compatible with providers/index.ts ──
|
|
425
|
-
|
|
426
|
-
export class AgentLoop {
|
|
427
|
-
private mcpManager: MCPClientManager | null = null
|
|
428
|
-
|
|
429
|
-
setMCPManager(m: MCPClientManager) {
|
|
430
|
-
this.mcpManager = m
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* Returns an async iterable that emits chunks compatible with
|
|
435
|
-
* the existing providers/index.ts stream consumer.
|
|
436
|
-
*/
|
|
437
|
-
stream(
|
|
438
|
-
input: { messages: Array<{ role: string; content: string }> },
|
|
439
|
-
config: {
|
|
440
|
-
configurable?: {
|
|
441
|
-
thread_id?: string
|
|
442
|
-
agent_id?: string
|
|
443
|
-
user_id?: string
|
|
444
|
-
system_prompt?: string
|
|
445
|
-
channel?: string
|
|
446
|
-
raw_user_message?: string
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
): AsyncIterable<StreamChunk> {
|
|
450
|
-
// Resolve from database with priority: explicit param → DB lookup → single user/agent
|
|
451
|
-
const threadId = config.configurable?.thread_id || resolveUserId({}) || "default"
|
|
452
|
-
const agentId = config.configurable?.agent_id || resolveAgentId(config.configurable?.agent_id) || this._resolveCoordinatorId() || "main"
|
|
453
|
-
const systemPromptOverride = config.configurable?.system_prompt
|
|
454
|
-
const channel = config.configurable?.channel
|
|
455
|
-
const userId = config.configurable?.user_id || resolveUserId({
|
|
456
|
-
channel: config.configurable?.channel ? (config.configurable?.channel as string).split(':')[0] : null,
|
|
457
|
-
channelUserId: config.configurable?.thread_id
|
|
458
|
-
})
|
|
459
|
-
|
|
460
|
-
// Log MCP Manager status
|
|
461
|
-
console.log(`[AgentLoop.stream] MCP Manager available: ${this.mcpManager !== null}`)
|
|
462
|
-
if (this.mcpManager) {
|
|
463
|
-
try {
|
|
464
|
-
const servers = this.mcpManager.listServers?.() || []
|
|
465
|
-
console.log(`[AgentLoop.stream] MCP servers: ${servers.length} registered`)
|
|
466
|
-
for (const s of servers) {
|
|
467
|
-
console.log(` - ${s.name}: ${s.status} (${s.tools?.length || 0} tools)`)
|
|
468
|
-
}
|
|
469
|
-
} catch (e) {
|
|
470
|
-
console.log(`[AgentLoop.stream] Failed to list MCP servers: ${(e as Error).message}`)
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
// Extract the last user message from the input
|
|
475
|
-
const lastUserMsg = [...input.messages].reverse().find((m) => m.role === "user")
|
|
476
|
-
const userMessage = lastUserMsg?.content || ""
|
|
477
|
-
|
|
478
|
-
// Use clean message (without timestamp) for FTS5 selectors
|
|
479
|
-
const rawUserMessage = config.configurable?.raw_user_message || userMessage
|
|
480
|
-
|
|
481
|
-
return runAgent({
|
|
482
|
-
agentId,
|
|
483
|
-
userMessage: rawUserMessage, // Clean message for FTS5 selectors
|
|
484
|
-
threadId,
|
|
485
|
-
channel,
|
|
486
|
-
systemPromptOverride,
|
|
487
|
-
mcpManager: this.mcpManager,
|
|
488
|
-
userId,
|
|
489
|
-
})
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
private _resolveCoordinatorId(): string {
|
|
493
|
-
// Use the storage helper to get coordinator agent ID from database
|
|
494
|
-
const coordinatorId = resolveAgentId(null);
|
|
495
|
-
return coordinatorId || "main";
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
// Singleton
|
|
500
|
-
let _agentLoop: AgentLoop | null = null
|
|
501
|
-
|
|
502
|
-
export function getAgentLoop(): AgentLoop | null {
|
|
503
|
-
return _agentLoop
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
export function buildAgentLoop(opts: { mcpManager?: MCPClientManager | null } = {}): AgentLoop {
|
|
507
|
-
_agentLoop = new AgentLoop()
|
|
508
|
-
if (opts.mcpManager) {
|
|
509
|
-
_agentLoop.setMCPManager(opts.mcpManager)
|
|
510
|
-
console.log("[buildAgentLoop] MCP Manager set successfully")
|
|
511
|
-
} else {
|
|
512
|
-
console.log("[buildAgentLoop] WARNING: No MCP Manager provided, agent will not have MCP tools")
|
|
513
|
-
}
|
|
514
|
-
return _agentLoop
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
export async function rebuildAgentLoop(opts: { mcpManager?: MCPClientManager | null } = {}): Promise<AgentLoop> {
|
|
518
|
-
_agentLoop = null
|
|
519
|
-
return buildAgentLoop(opts)
|
|
520
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compaction — Fase 6.
|
|
3
|
-
*
|
|
4
|
-
* Compresses conversation history when token count exceeds threshold.
|
|
5
|
-
* Uses the active LLM to summarize old messages, preserving:
|
|
6
|
-
* - User data and preferences
|
|
7
|
-
* - Decisions made
|
|
8
|
-
* - Tool results
|
|
9
|
-
* - Context needed to continue
|
|
10
|
-
*
|
|
11
|
-
* Saves summary to `summaries` table. Original messages are kept (audit trail)
|
|
12
|
-
* but the Context Compiler uses the summary instead of old messages.
|
|
13
|
-
*
|
|
14
|
-
* Also implements "tool result clearing": replaces old tool results with
|
|
15
|
-
* short summaries in the in-memory message array before model calls.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { logger } from "../utils/logger"
|
|
19
|
-
import {
|
|
20
|
-
getTotalTokens,
|
|
21
|
-
getHistory,
|
|
22
|
-
getSummary,
|
|
23
|
-
saveSummary,
|
|
24
|
-
toAPIMessages,
|
|
25
|
-
getMessageCount,
|
|
26
|
-
} from "./conversation-store"
|
|
27
|
-
import { estimateTokens } from "../utils/toon"
|
|
28
|
-
import { callLLM, resolveProviderConfig } from "./llm-client"
|
|
29
|
-
import { getDb } from "../storage/sqlite"
|
|
30
|
-
|
|
31
|
-
const log = logger.child("compaction")
|
|
32
|
-
|
|
33
|
-
// Token budget: compress when stored tokens exceed this threshold
|
|
34
|
-
const COMPACT_TOKEN_THRESHOLD = 6000 // ~60% of 10K context window
|
|
35
|
-
const KEEP_LAST_N_MESSAGES = 5 // always keep most recent N messages
|
|
36
|
-
const TOOL_RESULT_MAX_CHARS = 200 // max chars for old tool results after clearing
|
|
37
|
-
const MAX_TRANSCRIPT_MSGS = 30 // cap messages sent to summarizer (avoids OOM on small models)
|
|
38
|
-
const MAX_MSG_CHARS = 300 // chars per message in transcript
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Check if compaction is needed and run it if so.
|
|
42
|
-
* Called at the start of each agent loop iteration.
|
|
43
|
-
*/
|
|
44
|
-
export async function maybeCompact(threadId: string): Promise<void> {
|
|
45
|
-
try {
|
|
46
|
-
const totalTokens = getTotalTokens(threadId)
|
|
47
|
-
if (totalTokens < COMPACT_TOKEN_THRESHOLD) return
|
|
48
|
-
|
|
49
|
-
const summary = getSummary(threadId)
|
|
50
|
-
const totalMessages = getMessageCount(threadId)
|
|
51
|
-
|
|
52
|
-
// Already summarized up to near the current state
|
|
53
|
-
if (summary && summary.last_message_id > totalMessages - KEEP_LAST_N_MESSAGES) return
|
|
54
|
-
|
|
55
|
-
log.info(`[compaction] Compacting thread=${threadId} tokens=${totalTokens}`)
|
|
56
|
-
await compactThread(threadId)
|
|
57
|
-
} catch (err) {
|
|
58
|
-
log.warn("[compaction] Error during compaction check:", err)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Compress a thread's history into a summary.
|
|
64
|
-
*/
|
|
65
|
-
export async function compactThread(threadId: string): Promise<void> {
|
|
66
|
-
const allMessages = getHistory(threadId)
|
|
67
|
-
if (allMessages.length <= KEEP_LAST_N_MESSAGES) return
|
|
68
|
-
|
|
69
|
-
const toSummarize = allMessages.slice(0, allMessages.length - KEEP_LAST_N_MESSAGES)
|
|
70
|
-
if (toSummarize.length === 0) return
|
|
71
|
-
|
|
72
|
-
const lastSummarizedId = toSummarize[toSummarize.length - 1].id
|
|
73
|
-
|
|
74
|
-
const existingSummary = getSummary(threadId)
|
|
75
|
-
if (existingSummary && existingSummary.last_message_id >= lastSummarizedId) return
|
|
76
|
-
|
|
77
|
-
// Cap transcript to avoid overflowing small model contexts
|
|
78
|
-
const capped = toSummarize.slice(-MAX_TRANSCRIPT_MSGS)
|
|
79
|
-
const apiMessages = toAPIMessages(capped)
|
|
80
|
-
const transcript = apiMessages
|
|
81
|
-
.map((m) => `[${m.role.toUpperCase()}]: ${m.content.substring(0, MAX_MSG_CHARS)}`)
|
|
82
|
-
.join("\n\n")
|
|
83
|
-
|
|
84
|
-
const db = getDb()
|
|
85
|
-
const coordinator = db.query<any, []>(
|
|
86
|
-
"SELECT provider_id, model_id FROM agents WHERE role = 'coordinator' LIMIT 1"
|
|
87
|
-
).get()
|
|
88
|
-
|
|
89
|
-
const providerCfg = await resolveProviderConfig(
|
|
90
|
-
coordinator?.provider_id || "openai",
|
|
91
|
-
coordinator?.model_id || "gpt-4o-mini"
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
const summaryResponse = await callLLM({
|
|
95
|
-
...providerCfg,
|
|
96
|
-
messages: [
|
|
97
|
-
{
|
|
98
|
-
role: "system",
|
|
99
|
-
content:
|
|
100
|
-
"You are a conversation summarizer. Create a concise summary preserving: " +
|
|
101
|
-
"user preferences, decisions made, important facts, tool results, and context needed to continue.",
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
role: "user",
|
|
105
|
-
content: `Summarize this conversation (${toSummarize.length} messages) in 3-5 sentences:\n\n${transcript}`,
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const summary = summaryResponse.content.trim()
|
|
111
|
-
if (!summary) return
|
|
112
|
-
|
|
113
|
-
saveSummary(threadId, summary, toSummarize.length, lastSummarizedId)
|
|
114
|
-
log.info(
|
|
115
|
-
`[compaction] Thread ${threadId} compacted: ${toSummarize.length} msgs → ${estimateTokens(summary)} tokens`
|
|
116
|
-
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Clear old tool results in-memory to reduce tokens before a model call.
|
|
121
|
-
* Does NOT modify the database — only the in-memory messages array.
|
|
122
|
-
*
|
|
123
|
-
* Strategy: COMPRESS (Context Engineering)
|
|
124
|
-
* - Replaces old tool results with short summaries
|
|
125
|
-
* - Keeps recent tool results intact (keepLastN)
|
|
126
|
-
* - Uses TOON format for compact representation
|
|
127
|
-
*/
|
|
128
|
-
export function clearOldToolResults<T extends { role: string; content: string }>(
|
|
129
|
-
messages: T[],
|
|
130
|
-
keepLastN = 6
|
|
131
|
-
): T[] {
|
|
132
|
-
if (messages.length <= keepLastN) return messages
|
|
133
|
-
const cutoffIndex = messages.length - keepLastN
|
|
134
|
-
|
|
135
|
-
return messages.map((msg, i) => {
|
|
136
|
-
if (i >= cutoffIndex) return msg
|
|
137
|
-
|
|
138
|
-
if (msg.role === "tool") {
|
|
139
|
-
// For tool results older than keepLastN, summarize
|
|
140
|
-
if (msg.content.length > TOOL_RESULT_MAX_CHARS) {
|
|
141
|
-
// Try to extract key info from TOON/JSON format
|
|
142
|
-
let summary = msg.content.substring(0, TOOL_RESULT_MAX_CHARS)
|
|
143
|
-
|
|
144
|
-
// If it looks like JSON/TOON, add a marker
|
|
145
|
-
if (msg.content.trim().startsWith('{') || msg.content.trim().includes(':')) {
|
|
146
|
-
summary = `[Tool result summarized: ${summary}...]`
|
|
147
|
-
} else {
|
|
148
|
-
summary = `[Result truncated: ${summary}...]`
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return {
|
|
152
|
-
...msg,
|
|
153
|
-
content: summary,
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return msg
|
|
159
|
-
})
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Summarize a tool result to a single line
|
|
164
|
-
* Used for very old tool results (> 10 turns)
|
|
165
|
-
*/
|
|
166
|
-
export function summarizeToolResult(content: string, toolName?: string): string {
|
|
167
|
-
// Try to extract success/failure status
|
|
168
|
-
const isError = content.includes('error') || content.includes('failed') || content.startsWith('[Tool Error]')
|
|
169
|
-
const isSuccess = content.includes('ok') || content.includes('success') || content.includes('true')
|
|
170
|
-
|
|
171
|
-
// Try to extract key result field from JSON/TOON
|
|
172
|
-
let keyInfo = ""
|
|
173
|
-
try {
|
|
174
|
-
// Simple extraction of first key value
|
|
175
|
-
const firstLine = content.split('\n')[0].substring(0, 80)
|
|
176
|
-
keyInfo = firstLine
|
|
177
|
-
} catch {
|
|
178
|
-
keyInfo = content.substring(0, 80)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const status = isError ? "failed" : isSuccess ? "success" : "completed"
|
|
182
|
-
return `[${toolName || 'Tool'} ${status}: ${keyInfo}...]`
|
|
183
|
-
}
|