ruflo 3.5.2 → 3.5.4
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/dist/rvf.manifest.json +295 -0
- package/package.json +16 -2
- package/src/chat-ui/Dockerfile +25 -0
- package/src/chat-ui/patch-mcp-url-safety.sh +28 -0
- package/src/chat-ui/static/chatui/icon-144x144.png +0 -0
- package/src/chat-ui/static/chatui/omni-welcome.gif +0 -0
- package/src/config/config.example.json +76 -0
- package/src/mcp-bridge/Dockerfile +45 -0
- package/src/mcp-bridge/index.js +1668 -0
- package/src/mcp-bridge/mcp-stdio-kernel.js +159 -0
- package/src/mcp-bridge/package.json +17 -0
- package/src/mcp-bridge/test-harness.js +470 -0
- package/src/nginx/Dockerfile +10 -0
- package/src/nginx/nginx.conf +67 -0
- package/src/nginx/static/favicon-dark.svg +4 -0
- package/src/nginx/static/favicon.svg +4 -0
- package/src/nginx/static/icon.svg +5 -0
- package/src/nginx/static/logo.svg +9 -0
- package/src/nginx/static/manifest.json +22 -0
- package/src/nginx/static/welcome.js +184 -0
- package/src/ruvocal/.claude/skills/add-model-descriptions/SKILL.md +73 -0
- package/src/ruvocal/.devcontainer/Dockerfile +9 -0
- package/src/ruvocal/.devcontainer/devcontainer.json +36 -0
- package/src/ruvocal/.dockerignore +13 -0
- package/src/ruvocal/.env +194 -0
- package/src/ruvocal/.env.ci +1 -0
- package/src/ruvocal/.eslintignore +13 -0
- package/src/ruvocal/.eslintrc.cjs +45 -0
- package/src/ruvocal/.github/ISSUE_TEMPLATE/bug-report--chat-ui-.md +43 -0
- package/src/ruvocal/.github/ISSUE_TEMPLATE/config-support.md +9 -0
- package/src/ruvocal/.github/ISSUE_TEMPLATE/feature-request--chat-ui-.md +17 -0
- package/src/ruvocal/.github/ISSUE_TEMPLATE/huggingchat.md +11 -0
- package/src/ruvocal/.github/release.yml +16 -0
- package/src/ruvocal/.github/workflows/build-docs.yml +18 -0
- package/src/ruvocal/.github/workflows/build-image.yml +142 -0
- package/src/ruvocal/.github/workflows/build-pr-docs.yml +20 -0
- package/src/ruvocal/.github/workflows/deploy-dev.yml +63 -0
- package/src/ruvocal/.github/workflows/deploy-prod.yml +78 -0
- package/src/ruvocal/.github/workflows/lint-and-test.yml +84 -0
- package/src/ruvocal/.github/workflows/slugify.yaml +72 -0
- package/src/ruvocal/.github/workflows/trufflehog.yml +17 -0
- package/src/ruvocal/.github/workflows/upload-pr-documentation.yml +16 -0
- package/src/ruvocal/.husky/lint-stage-config.js +4 -0
- package/src/ruvocal/.husky/pre-commit +2 -0
- package/src/ruvocal/.prettierignore +14 -0
- package/src/ruvocal/.prettierrc +7 -0
- package/src/ruvocal/.vscode/launch.json +11 -0
- package/src/ruvocal/.vscode/settings.json +14 -0
- package/src/ruvocal/CLAUDE.md +126 -0
- package/src/ruvocal/Dockerfile +93 -0
- package/src/ruvocal/LICENSE +203 -0
- package/src/ruvocal/PRIVACY.md +41 -0
- package/src/ruvocal/README.md +190 -0
- package/src/ruvocal/chart/Chart.yaml +5 -0
- package/src/ruvocal/chart/env/dev.yaml +260 -0
- package/src/ruvocal/chart/env/prod.yaml +273 -0
- package/src/ruvocal/chart/templates/_helpers.tpl +22 -0
- package/src/ruvocal/chart/templates/config.yaml +10 -0
- package/src/ruvocal/chart/templates/deployment.yaml +81 -0
- package/src/ruvocal/chart/templates/hpa.yaml +45 -0
- package/src/ruvocal/chart/templates/infisical.yaml +24 -0
- package/src/ruvocal/chart/templates/ingress-internal.yaml +32 -0
- package/src/ruvocal/chart/templates/ingress.yaml +32 -0
- package/src/ruvocal/chart/templates/network-policy.yaml +36 -0
- package/src/ruvocal/chart/templates/service-account.yaml +13 -0
- package/src/ruvocal/chart/templates/service-monitor.yaml +17 -0
- package/src/ruvocal/chart/templates/service.yaml +21 -0
- package/src/ruvocal/chart/values.yaml +73 -0
- package/src/ruvocal/docker-compose.yml +21 -0
- package/src/ruvocal/docs/adr/ADR-029-HUGGINGFACE-CHAT-UI-CLOUD-RUN.md +1236 -0
- package/src/ruvocal/docs/adr/ADR-033-RUVECTOR-RUFLO-MCP-INTEGRATION.md +111 -0
- package/src/ruvocal/docs/adr/ADR-034-OPTIONAL-MCP-BACKENDS.md +117 -0
- package/src/ruvocal/docs/adr/ADR-035-MCP-TOOL-GROUPS.md +186 -0
- package/src/ruvocal/docs/adr/ADR-037-AUTOPILOT-CHAT-MODE.md +1500 -0
- package/src/ruvocal/docs/adr/ADR-038-RUVOCAL-FORK.md +286 -0
- package/src/ruvocal/docs/source/_toctree.yml +30 -0
- package/src/ruvocal/docs/source/configuration/common-issues.md +38 -0
- package/src/ruvocal/docs/source/configuration/llm-router.md +105 -0
- package/src/ruvocal/docs/source/configuration/mcp-tools.md +84 -0
- package/src/ruvocal/docs/source/configuration/metrics.md +9 -0
- package/src/ruvocal/docs/source/configuration/open-id.md +57 -0
- package/src/ruvocal/docs/source/configuration/overview.md +89 -0
- package/src/ruvocal/docs/source/configuration/theming.md +20 -0
- package/src/ruvocal/docs/source/developing/architecture.md +48 -0
- package/src/ruvocal/docs/source/index.md +53 -0
- package/src/ruvocal/docs/source/installation/docker.md +43 -0
- package/src/ruvocal/docs/source/installation/helm.md +43 -0
- package/src/ruvocal/docs/source/installation/local.md +62 -0
- package/src/ruvocal/entrypoint.sh +19 -0
- package/src/ruvocal/mcp-bridge/.claude-flow/agents/store.json +27 -0
- package/src/ruvocal/mcp-bridge/.claude-flow/daemon-state.json +130 -0
- package/src/ruvocal/mcp-bridge/.claude-flow/daemon.log +0 -0
- package/src/ruvocal/mcp-bridge/.claude-flow/daemon.pid +1 -0
- package/src/ruvocal/mcp-bridge/.claude-flow/tasks/store.json +21 -0
- package/src/ruvocal/mcp-bridge/.swarm/hnsw.index +0 -0
- package/src/ruvocal/mcp-bridge/.swarm/hnsw.metadata.json +1 -0
- package/src/ruvocal/mcp-bridge/.swarm/memory.db +0 -0
- package/src/ruvocal/mcp-bridge/.swarm/model-router-state.json +14 -0
- package/src/ruvocal/mcp-bridge/.swarm/schema.sql +305 -0
- package/src/ruvocal/mcp-bridge/Dockerfile +45 -0
- package/src/ruvocal/mcp-bridge/cloudbuild.yaml +49 -0
- package/src/ruvocal/mcp-bridge/index.js +1864 -0
- package/src/ruvocal/mcp-bridge/mcp-stdio-kernel.js +159 -0
- package/src/ruvocal/mcp-bridge/package-lock.json +762 -0
- package/src/ruvocal/mcp-bridge/package.json +17 -0
- package/src/ruvocal/mcp-bridge/test-harness.js +470 -0
- package/src/ruvocal/models/add-your-models-here.txt +1 -0
- package/src/ruvocal/package-lock.json +11741 -0
- package/src/ruvocal/package.json +121 -0
- package/src/ruvocal/postcss.config.js +6 -0
- package/src/ruvocal/rvf.manifest.json +204 -0
- package/src/ruvocal/scripts/config.ts +64 -0
- package/src/ruvocal/scripts/generate-welcome.mjs +181 -0
- package/src/ruvocal/scripts/populate.ts +288 -0
- package/src/ruvocal/scripts/samples.txt +194 -0
- package/src/ruvocal/scripts/setups/vitest-setup-client.ts +0 -0
- package/src/ruvocal/scripts/setups/vitest-setup-server.ts +44 -0
- package/src/ruvocal/scripts/updateLocalEnv.ts +48 -0
- package/src/ruvocal/src/ambient.d.ts +7 -0
- package/src/ruvocal/src/app.d.ts +29 -0
- package/src/ruvocal/src/app.html +53 -0
- package/src/ruvocal/src/hooks.server.ts +32 -0
- package/src/ruvocal/src/hooks.ts +6 -0
- package/src/ruvocal/src/lib/APIClient.ts +148 -0
- package/src/ruvocal/src/lib/actions/clickOutside.ts +18 -0
- package/src/ruvocal/src/lib/actions/snapScrollToBottom.ts +346 -0
- package/src/ruvocal/src/lib/buildPrompt.ts +33 -0
- package/src/ruvocal/src/lib/components/AnnouncementBanner.svelte +20 -0
- package/src/ruvocal/src/lib/components/BackgroundGenerationPoller.svelte +168 -0
- package/src/ruvocal/src/lib/components/CodeBlock.svelte +73 -0
- package/src/ruvocal/src/lib/components/CopyToClipBoardBtn.svelte +92 -0
- package/src/ruvocal/src/lib/components/DeleteConversationModal.svelte +75 -0
- package/src/ruvocal/src/lib/components/EditConversationModal.svelte +100 -0
- package/src/ruvocal/src/lib/components/ExpandNavigation.svelte +22 -0
- package/src/ruvocal/src/lib/components/HoverTooltip.svelte +44 -0
- package/src/ruvocal/src/lib/components/HtmlPreviewModal.svelte +143 -0
- package/src/ruvocal/src/lib/components/InfiniteScroll.svelte +50 -0
- package/src/ruvocal/src/lib/components/MobileNav.svelte +300 -0
- package/src/ruvocal/src/lib/components/Modal.svelte +115 -0
- package/src/ruvocal/src/lib/components/ModelCardMetadata.svelte +71 -0
- package/src/ruvocal/src/lib/components/NavConversationItem.svelte +151 -0
- package/src/ruvocal/src/lib/components/NavMenu.svelte +295 -0
- package/src/ruvocal/src/lib/components/Pagination.svelte +97 -0
- package/src/ruvocal/src/lib/components/PaginationArrow.svelte +27 -0
- package/src/ruvocal/src/lib/components/Portal.svelte +24 -0
- package/src/ruvocal/src/lib/components/RetryBtn.svelte +18 -0
- package/src/ruvocal/src/lib/components/RuFloUniverse.svelte +185 -0
- package/src/ruvocal/src/lib/components/ScrollToBottomBtn.svelte +47 -0
- package/src/ruvocal/src/lib/components/ScrollToPreviousBtn.svelte +77 -0
- package/src/ruvocal/src/lib/components/ShareConversationModal.svelte +182 -0
- package/src/ruvocal/src/lib/components/StopGeneratingBtn.svelte +69 -0
- package/src/ruvocal/src/lib/components/SubscribeModal.svelte +87 -0
- package/src/ruvocal/src/lib/components/Switch.svelte +36 -0
- package/src/ruvocal/src/lib/components/SystemPromptModal.svelte +44 -0
- package/src/ruvocal/src/lib/components/Toast.svelte +27 -0
- package/src/ruvocal/src/lib/components/Tooltip.svelte +30 -0
- package/src/ruvocal/src/lib/components/WelcomeModal.svelte +46 -0
- package/src/ruvocal/src/lib/components/chat/Alternatives.svelte +77 -0
- package/src/ruvocal/src/lib/components/chat/BlockWrapper.svelte +72 -0
- package/src/ruvocal/src/lib/components/chat/ChatInput.svelte +490 -0
- package/src/ruvocal/src/lib/components/chat/ChatIntroduction.svelte +123 -0
- package/src/ruvocal/src/lib/components/chat/ChatMessage.svelte +548 -0
- package/src/ruvocal/src/lib/components/chat/ChatWindow.svelte +939 -0
- package/src/ruvocal/src/lib/components/chat/FileDropzone.svelte +92 -0
- package/src/ruvocal/src/lib/components/chat/ImageLightbox.svelte +66 -0
- package/src/ruvocal/src/lib/components/chat/MarkdownBlock.svelte +23 -0
- package/src/ruvocal/src/lib/components/chat/MarkdownRenderer.svelte +69 -0
- package/src/ruvocal/src/lib/components/chat/MarkdownRenderer.svelte.test.ts +58 -0
- package/src/ruvocal/src/lib/components/chat/MessageAvatar.svelte +103 -0
- package/src/ruvocal/src/lib/components/chat/ModelSwitch.svelte +64 -0
- package/src/ruvocal/src/lib/components/chat/OpenReasoningResults.svelte +81 -0
- package/src/ruvocal/src/lib/components/chat/TaskGroup.svelte +88 -0
- package/src/ruvocal/src/lib/components/chat/ToolUpdate.svelte +273 -0
- package/src/ruvocal/src/lib/components/chat/UploadedFile.svelte +253 -0
- package/src/ruvocal/src/lib/components/chat/UrlFetchModal.svelte +203 -0
- package/src/ruvocal/src/lib/components/chat/VoiceRecorder.svelte +214 -0
- package/src/ruvocal/src/lib/components/icons/IconBurger.svelte +20 -0
- package/src/ruvocal/src/lib/components/icons/IconCheap.svelte +20 -0
- package/src/ruvocal/src/lib/components/icons/IconChevron.svelte +24 -0
- package/src/ruvocal/src/lib/components/icons/IconDazzled.svelte +40 -0
- package/src/ruvocal/src/lib/components/icons/IconFast.svelte +20 -0
- package/src/ruvocal/src/lib/components/icons/IconLoading.svelte +22 -0
- package/src/ruvocal/src/lib/components/icons/IconMCP.svelte +28 -0
- package/src/ruvocal/src/lib/components/icons/IconMoon.svelte +21 -0
- package/src/ruvocal/src/lib/components/icons/IconNew.svelte +20 -0
- package/src/ruvocal/src/lib/components/icons/IconOmni.svelte +90 -0
- package/src/ruvocal/src/lib/components/icons/IconPaperclip.svelte +24 -0
- package/src/ruvocal/src/lib/components/icons/IconPro.svelte +37 -0
- package/src/ruvocal/src/lib/components/icons/IconShare.svelte +21 -0
- package/src/ruvocal/src/lib/components/icons/IconSun.svelte +93 -0
- package/src/ruvocal/src/lib/components/icons/Logo.svelte +68 -0
- package/src/ruvocal/src/lib/components/icons/LogoHuggingFaceBorderless.svelte +54 -0
- package/src/ruvocal/src/lib/components/mcp/AddServerForm.svelte +250 -0
- package/src/ruvocal/src/lib/components/mcp/MCPServerManager.svelte +185 -0
- package/src/ruvocal/src/lib/components/mcp/ServerCard.svelte +203 -0
- package/src/ruvocal/src/lib/components/players/AudioPlayer.svelte +82 -0
- package/src/ruvocal/src/lib/components/voice/AudioWaveform.svelte +96 -0
- package/src/ruvocal/src/lib/constants/mcpExamples.ts +135 -0
- package/src/ruvocal/src/lib/constants/mime.ts +11 -0
- package/src/ruvocal/src/lib/constants/pagination.ts +1 -0
- package/src/ruvocal/src/lib/constants/publicSepToken.ts +1 -0
- package/src/ruvocal/src/lib/constants/routerExamples.ts +209 -0
- package/src/ruvocal/src/lib/createShareLink.ts +27 -0
- package/src/ruvocal/src/lib/jobs/refresh-conversation-stats.ts +297 -0
- package/src/ruvocal/src/lib/migrations/lock.ts +56 -0
- package/src/ruvocal/src/lib/migrations/migrations.spec.ts +74 -0
- package/src/ruvocal/src/lib/migrations/migrations.ts +109 -0
- package/src/ruvocal/src/lib/migrations/routines/01-update-search-assistants.ts +50 -0
- package/src/ruvocal/src/lib/migrations/routines/02-update-assistants-models.ts +48 -0
- package/src/ruvocal/src/lib/migrations/routines/04-update-message-updates.ts +151 -0
- package/src/ruvocal/src/lib/migrations/routines/05-update-message-files.ts +56 -0
- package/src/ruvocal/src/lib/migrations/routines/06-trim-message-updates.ts +56 -0
- package/src/ruvocal/src/lib/migrations/routines/08-update-featured-to-review.ts +32 -0
- package/src/ruvocal/src/lib/migrations/routines/09-delete-empty-conversations.spec.ts +214 -0
- package/src/ruvocal/src/lib/migrations/routines/09-delete-empty-conversations.ts +88 -0
- package/src/ruvocal/src/lib/migrations/routines/10-update-reports-assistantid.ts +29 -0
- package/src/ruvocal/src/lib/migrations/routines/index.ts +15 -0
- package/src/ruvocal/src/lib/server/__tests__/conversation-stop-generating.spec.ts +103 -0
- package/src/ruvocal/src/lib/server/abortRegistry.ts +57 -0
- package/src/ruvocal/src/lib/server/abortedGenerations.ts +43 -0
- package/src/ruvocal/src/lib/server/adminToken.ts +62 -0
- package/src/ruvocal/src/lib/server/api/__tests__/conversations-id.spec.ts +296 -0
- package/src/ruvocal/src/lib/server/api/__tests__/conversations-message.spec.ts +216 -0
- package/src/ruvocal/src/lib/server/api/__tests__/conversations.spec.ts +235 -0
- package/src/ruvocal/src/lib/server/api/__tests__/misc.spec.ts +72 -0
- package/src/ruvocal/src/lib/server/api/__tests__/testHelpers.ts +86 -0
- package/src/ruvocal/src/lib/server/api/__tests__/user-reports.spec.ts +78 -0
- package/src/ruvocal/src/lib/server/api/__tests__/user.spec.ts +239 -0
- package/src/ruvocal/src/lib/server/api/types.ts +37 -0
- package/src/ruvocal/src/lib/server/api/utils/requireAuth.ts +22 -0
- package/src/ruvocal/src/lib/server/api/utils/resolveConversation.ts +69 -0
- package/src/ruvocal/src/lib/server/api/utils/resolveModel.ts +27 -0
- package/src/ruvocal/src/lib/server/api/utils/superjsonResponse.ts +15 -0
- package/src/ruvocal/src/lib/server/apiToken.ts +11 -0
- package/src/ruvocal/src/lib/server/auth.ts +554 -0
- package/src/ruvocal/src/lib/server/config.ts +187 -0
- package/src/ruvocal/src/lib/server/conversation.ts +83 -0
- package/src/ruvocal/src/lib/server/database/__tests__/rvf.spec.ts +709 -0
- package/src/ruvocal/src/lib/server/database/postgres.ts +700 -0
- package/src/ruvocal/src/lib/server/database/rvf.ts +1078 -0
- package/src/ruvocal/src/lib/server/database.ts +145 -0
- package/src/ruvocal/src/lib/server/endpoints/document.ts +68 -0
- package/src/ruvocal/src/lib/server/endpoints/endpoints.ts +43 -0
- package/src/ruvocal/src/lib/server/endpoints/images.ts +211 -0
- package/src/ruvocal/src/lib/server/endpoints/openai/endpointOai.ts +266 -0
- package/src/ruvocal/src/lib/server/endpoints/openai/openAIChatToTextGenerationStream.ts +212 -0
- package/src/ruvocal/src/lib/server/endpoints/openai/openAICompletionToTextGenerationStream.ts +32 -0
- package/src/ruvocal/src/lib/server/endpoints/preprocessMessages.ts +61 -0
- package/src/ruvocal/src/lib/server/exitHandler.ts +59 -0
- package/src/ruvocal/src/lib/server/files/downloadFile.ts +34 -0
- package/src/ruvocal/src/lib/server/files/uploadFile.ts +29 -0
- package/src/ruvocal/src/lib/server/findRepoRoot.ts +13 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Black.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Bold.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-ExtraBold.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-ExtraLight.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Light.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Medium.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Regular.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-SemiBold.ttf +0 -0
- package/src/ruvocal/src/lib/server/fonts/Inter-Thin.ttf +0 -0
- package/src/ruvocal/src/lib/server/generateFromDefaultEndpoint.ts +46 -0
- package/src/ruvocal/src/lib/server/hooks/error.ts +37 -0
- package/src/ruvocal/src/lib/server/hooks/fetch.ts +22 -0
- package/src/ruvocal/src/lib/server/hooks/handle.ts +250 -0
- package/src/ruvocal/src/lib/server/hooks/init.ts +51 -0
- package/src/ruvocal/src/lib/server/isURLLocal.spec.ts +31 -0
- package/src/ruvocal/src/lib/server/isURLLocal.ts +74 -0
- package/src/ruvocal/src/lib/server/logger.ts +42 -0
- package/src/ruvocal/src/lib/server/mcp/clientPool.ts +70 -0
- package/src/ruvocal/src/lib/server/mcp/hf.ts +32 -0
- package/src/ruvocal/src/lib/server/mcp/httpClient.ts +122 -0
- package/src/ruvocal/src/lib/server/mcp/registry.ts +76 -0
- package/src/ruvocal/src/lib/server/mcp/tools.ts +196 -0
- package/src/ruvocal/src/lib/server/metrics.ts +255 -0
- package/src/ruvocal/src/lib/server/models.ts +518 -0
- package/src/ruvocal/src/lib/server/requestContext.ts +55 -0
- package/src/ruvocal/src/lib/server/router/arch.ts +230 -0
- package/src/ruvocal/src/lib/server/router/endpoint.ts +316 -0
- package/src/ruvocal/src/lib/server/router/multimodal.ts +28 -0
- package/src/ruvocal/src/lib/server/router/policy.ts +49 -0
- package/src/ruvocal/src/lib/server/router/toolsRoute.ts +51 -0
- package/src/ruvocal/src/lib/server/router/types.ts +21 -0
- package/src/ruvocal/src/lib/server/sendSlack.ts +23 -0
- package/src/ruvocal/src/lib/server/textGeneration/generate.ts +258 -0
- package/src/ruvocal/src/lib/server/textGeneration/index.ts +95 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/fileRefs.ts +155 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/routerResolution.ts +108 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/runMcpFlow.ts +822 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/toolInvocation.ts +349 -0
- package/src/ruvocal/src/lib/server/textGeneration/reasoning.ts +23 -0
- package/src/ruvocal/src/lib/server/textGeneration/title.ts +83 -0
- package/src/ruvocal/src/lib/server/textGeneration/types.ts +26 -0
- package/src/ruvocal/src/lib/server/textGeneration/utils/prepareFiles.ts +88 -0
- package/src/ruvocal/src/lib/server/textGeneration/utils/routing.ts +21 -0
- package/src/ruvocal/src/lib/server/textGeneration/utils/toolPrompt.ts +49 -0
- package/src/ruvocal/src/lib/server/urlSafety.ts +72 -0
- package/src/ruvocal/src/lib/server/usageLimits.ts +30 -0
- package/src/ruvocal/src/lib/stores/autopilotStore.svelte.ts +175 -0
- package/src/ruvocal/src/lib/stores/backgroundGenerations.svelte.ts +32 -0
- package/src/ruvocal/src/lib/stores/backgroundGenerations.ts +1 -0
- package/src/ruvocal/src/lib/stores/errors.ts +9 -0
- package/src/ruvocal/src/lib/stores/isAborted.ts +3 -0
- package/src/ruvocal/src/lib/stores/isPro.ts +4 -0
- package/src/ruvocal/src/lib/stores/loading.ts +3 -0
- package/src/ruvocal/src/lib/stores/mcpServers.ts +345 -0
- package/src/ruvocal/src/lib/stores/pendingChatInput.ts +3 -0
- package/src/ruvocal/src/lib/stores/pendingMessage.ts +9 -0
- package/src/ruvocal/src/lib/stores/settings.ts +182 -0
- package/src/ruvocal/src/lib/stores/shareModal.ts +13 -0
- package/src/ruvocal/src/lib/stores/titleUpdate.ts +8 -0
- package/src/ruvocal/src/lib/switchTheme.ts +124 -0
- package/src/ruvocal/src/lib/types/AbortedGeneration.ts +8 -0
- package/src/ruvocal/src/lib/types/Assistant.ts +31 -0
- package/src/ruvocal/src/lib/types/AssistantStats.ts +11 -0
- package/src/ruvocal/src/lib/types/ConfigKey.ts +4 -0
- package/src/ruvocal/src/lib/types/ConvSidebar.ts +9 -0
- package/src/ruvocal/src/lib/types/Conversation.ts +27 -0
- package/src/ruvocal/src/lib/types/ConversationStats.ts +13 -0
- package/src/ruvocal/src/lib/types/Message.ts +41 -0
- package/src/ruvocal/src/lib/types/MessageEvent.ts +10 -0
- package/src/ruvocal/src/lib/types/MessageUpdate.ts +139 -0
- package/src/ruvocal/src/lib/types/MigrationResult.ts +7 -0
- package/src/ruvocal/src/lib/types/Model.ts +23 -0
- package/src/ruvocal/src/lib/types/Report.ts +12 -0
- package/src/ruvocal/src/lib/types/Review.ts +6 -0
- package/src/ruvocal/src/lib/types/Semaphore.ts +19 -0
- package/src/ruvocal/src/lib/types/Session.ts +22 -0
- package/src/ruvocal/src/lib/types/Settings.ts +86 -0
- package/src/ruvocal/src/lib/types/SharedConversation.ts +9 -0
- package/src/ruvocal/src/lib/types/Template.ts +6 -0
- package/src/ruvocal/src/lib/types/Timestamps.ts +4 -0
- package/src/ruvocal/src/lib/types/TokenCache.ts +6 -0
- package/src/ruvocal/src/lib/types/Tool.ts +74 -0
- package/src/ruvocal/src/lib/types/UrlDependency.ts +5 -0
- package/src/ruvocal/src/lib/types/User.ts +14 -0
- package/src/ruvocal/src/lib/utils/PublicConfig.svelte.ts +75 -0
- package/src/ruvocal/src/lib/utils/auth.ts +17 -0
- package/src/ruvocal/src/lib/utils/chunk.ts +33 -0
- package/src/ruvocal/src/lib/utils/cookiesAreEnabled.ts +13 -0
- package/src/ruvocal/src/lib/utils/debounce.ts +17 -0
- package/src/ruvocal/src/lib/utils/deepestChild.ts +6 -0
- package/src/ruvocal/src/lib/utils/favicon.ts +21 -0
- package/src/ruvocal/src/lib/utils/fetchJSON.ts +23 -0
- package/src/ruvocal/src/lib/utils/file2base64.ts +14 -0
- package/src/ruvocal/src/lib/utils/formatUserCount.ts +37 -0
- package/src/ruvocal/src/lib/utils/generationState.spec.ts +75 -0
- package/src/ruvocal/src/lib/utils/generationState.ts +26 -0
- package/src/ruvocal/src/lib/utils/getHref.ts +41 -0
- package/src/ruvocal/src/lib/utils/getReturnFromGenerator.ts +7 -0
- package/src/ruvocal/src/lib/utils/haptics.ts +64 -0
- package/src/ruvocal/src/lib/utils/hashConv.ts +12 -0
- package/src/ruvocal/src/lib/utils/hf.ts +17 -0
- package/src/ruvocal/src/lib/utils/isDesktop.ts +7 -0
- package/src/ruvocal/src/lib/utils/isUrl.ts +8 -0
- package/src/ruvocal/src/lib/utils/isVirtualKeyboard.ts +16 -0
- package/src/ruvocal/src/lib/utils/loadAttachmentsFromUrls.ts +115 -0
- package/src/ruvocal/src/lib/utils/marked.spec.ts +96 -0
- package/src/ruvocal/src/lib/utils/marked.ts +531 -0
- package/src/ruvocal/src/lib/utils/mcpValidation.ts +147 -0
- package/src/ruvocal/src/lib/utils/mergeAsyncGenerators.ts +38 -0
- package/src/ruvocal/src/lib/utils/messageUpdates.spec.ts +262 -0
- package/src/ruvocal/src/lib/utils/messageUpdates.ts +324 -0
- package/src/ruvocal/src/lib/utils/mime.ts +56 -0
- package/src/ruvocal/src/lib/utils/models.ts +14 -0
- package/src/ruvocal/src/lib/utils/parseBlocks.ts +120 -0
- package/src/ruvocal/src/lib/utils/parseIncompleteMarkdown.ts +644 -0
- package/src/ruvocal/src/lib/utils/parseStringToList.ts +10 -0
- package/src/ruvocal/src/lib/utils/randomUuid.ts +14 -0
- package/src/ruvocal/src/lib/utils/searchTokens.ts +33 -0
- package/src/ruvocal/src/lib/utils/sha256.ts +7 -0
- package/src/ruvocal/src/lib/utils/stringifyError.ts +12 -0
- package/src/ruvocal/src/lib/utils/sum.ts +3 -0
- package/src/ruvocal/src/lib/utils/template.spec.ts +59 -0
- package/src/ruvocal/src/lib/utils/template.ts +53 -0
- package/src/ruvocal/src/lib/utils/timeout.ts +9 -0
- package/src/ruvocal/src/lib/utils/toolProgress.spec.ts +46 -0
- package/src/ruvocal/src/lib/utils/toolProgress.ts +11 -0
- package/src/ruvocal/src/lib/utils/tree/addChildren.spec.ts +102 -0
- package/src/ruvocal/src/lib/utils/tree/addChildren.ts +48 -0
- package/src/ruvocal/src/lib/utils/tree/addSibling.spec.ts +81 -0
- package/src/ruvocal/src/lib/utils/tree/addSibling.ts +41 -0
- package/src/ruvocal/src/lib/utils/tree/buildSubtree.spec.ts +110 -0
- package/src/ruvocal/src/lib/utils/tree/buildSubtree.ts +24 -0
- package/src/ruvocal/src/lib/utils/tree/convertLegacyConversation.spec.ts +31 -0
- package/src/ruvocal/src/lib/utils/tree/convertLegacyConversation.ts +36 -0
- package/src/ruvocal/src/lib/utils/tree/isMessageId.spec.ts +15 -0
- package/src/ruvocal/src/lib/utils/tree/isMessageId.ts +5 -0
- package/src/ruvocal/src/lib/utils/tree/tree.d.ts +14 -0
- package/src/ruvocal/src/lib/utils/tree/treeHelpers.spec.ts +167 -0
- package/src/ruvocal/src/lib/utils/updates.ts +39 -0
- package/src/ruvocal/src/lib/utils/urlParams.ts +13 -0
- package/src/ruvocal/src/lib/workers/autopilotWorker.ts +221 -0
- package/src/ruvocal/src/lib/workers/detailFetchWorker.ts +100 -0
- package/src/ruvocal/src/lib/workers/markdownWorker.ts +61 -0
- package/src/ruvocal/src/routes/+error.svelte +20 -0
- package/src/ruvocal/src/routes/+layout.svelte +324 -0
- package/src/ruvocal/src/routes/+layout.ts +91 -0
- package/src/ruvocal/src/routes/+page.svelte +168 -0
- package/src/ruvocal/src/routes/.well-known/oauth-cimd/+server.ts +37 -0
- package/src/ruvocal/src/routes/__debug/openai/+server.ts +21 -0
- package/src/ruvocal/src/routes/admin/export/+server.ts +159 -0
- package/src/ruvocal/src/routes/admin/stats/compute/+server.ts +16 -0
- package/src/ruvocal/src/routes/api/conversation/[id]/+server.ts +40 -0
- package/src/ruvocal/src/routes/api/conversation/[id]/message/[messageId]/+server.ts +42 -0
- package/src/ruvocal/src/routes/api/conversations/+server.ts +48 -0
- package/src/ruvocal/src/routes/api/fetch-url/+server.ts +147 -0
- package/src/ruvocal/src/routes/api/mcp/health/+server.ts +292 -0
- package/src/ruvocal/src/routes/api/mcp/servers/+server.ts +32 -0
- package/src/ruvocal/src/routes/api/models/+server.ts +25 -0
- package/src/ruvocal/src/routes/api/transcribe/+server.ts +104 -0
- package/src/ruvocal/src/routes/api/user/+server.ts +15 -0
- package/src/ruvocal/src/routes/api/user/validate-token/+server.ts +20 -0
- package/src/ruvocal/src/routes/api/v2/conversations/+server.ts +48 -0
- package/src/ruvocal/src/routes/api/v2/conversations/[id]/+server.ts +94 -0
- package/src/ruvocal/src/routes/api/v2/conversations/[id]/message/[messageId]/+server.ts +43 -0
- package/src/ruvocal/src/routes/api/v2/conversations/import-share/+server.ts +23 -0
- package/src/ruvocal/src/routes/api/v2/debug/config/+server.ts +16 -0
- package/src/ruvocal/src/routes/api/v2/debug/refresh/+server.ts +30 -0
- package/src/ruvocal/src/routes/api/v2/export/+server.ts +196 -0
- package/src/ruvocal/src/routes/api/v2/feature-flags/+server.ts +14 -0
- package/src/ruvocal/src/routes/api/v2/models/+server.ts +38 -0
- package/src/ruvocal/src/routes/api/v2/models/[namespace]/+server.ts +8 -0
- package/src/ruvocal/src/routes/api/v2/models/[namespace]/[model]/+server.ts +8 -0
- package/src/ruvocal/src/routes/api/v2/models/[namespace]/[model]/subscribe/+server.ts +28 -0
- package/src/ruvocal/src/routes/api/v2/models/[namespace]/subscribe/+server.ts +28 -0
- package/src/ruvocal/src/routes/api/v2/models/old/+server.ts +7 -0
- package/src/ruvocal/src/routes/api/v2/models/refresh/+server.ts +33 -0
- package/src/ruvocal/src/routes/api/v2/public-config/+server.ts +7 -0
- package/src/ruvocal/src/routes/api/v2/user/+server.ts +17 -0
- package/src/ruvocal/src/routes/api/v2/user/billing-orgs/+server.ts +73 -0
- package/src/ruvocal/src/routes/api/v2/user/reports/+server.ts +17 -0
- package/src/ruvocal/src/routes/api/v2/user/settings/+server.ts +103 -0
- package/src/ruvocal/src/routes/conversation/+server.ts +115 -0
- package/src/ruvocal/src/routes/conversation/[id]/+page.svelte +582 -0
- package/src/ruvocal/src/routes/conversation/[id]/+page.ts +60 -0
- package/src/ruvocal/src/routes/conversation/[id]/+server.ts +736 -0
- package/src/ruvocal/src/routes/conversation/[id]/message/[messageId]/prompt/+server.ts +66 -0
- package/src/ruvocal/src/routes/conversation/[id]/output/[sha256]/+server.ts +58 -0
- package/src/ruvocal/src/routes/conversation/[id]/share/+server.ts +69 -0
- package/src/ruvocal/src/routes/conversation/[id]/stop-generating/+server.ts +35 -0
- package/src/ruvocal/src/routes/healthcheck/+server.ts +3 -0
- package/src/ruvocal/src/routes/login/+server.ts +5 -0
- package/src/ruvocal/src/routes/login/callback/+server.ts +103 -0
- package/src/ruvocal/src/routes/login/callback/updateUser.spec.ts +157 -0
- package/src/ruvocal/src/routes/login/callback/updateUser.ts +215 -0
- package/src/ruvocal/src/routes/logout/+server.ts +18 -0
- package/src/ruvocal/src/routes/metrics/+server.ts +18 -0
- package/src/ruvocal/src/routes/models/+page.svelte +233 -0
- package/src/ruvocal/src/routes/models/[...model]/+page.svelte +161 -0
- package/src/ruvocal/src/routes/models/[...model]/+page.ts +14 -0
- package/src/ruvocal/src/routes/models/[...model]/thumbnail.png/+server.ts +64 -0
- package/src/ruvocal/src/routes/models/[...model]/thumbnail.png/ModelThumbnail.svelte +28 -0
- package/src/ruvocal/src/routes/privacy/+page.svelte +11 -0
- package/src/ruvocal/src/routes/r/[id]/+page.ts +34 -0
- package/src/ruvocal/src/routes/settings/(nav)/+layout.svelte +282 -0
- package/src/ruvocal/src/routes/settings/(nav)/+layout.ts +1 -0
- package/src/ruvocal/src/routes/settings/(nav)/+page.svelte +0 -0
- package/src/ruvocal/src/routes/settings/(nav)/+server.ts +53 -0
- package/src/ruvocal/src/routes/settings/(nav)/[...model]/+page.svelte +464 -0
- package/src/ruvocal/src/routes/settings/(nav)/[...model]/+page.ts +14 -0
- package/src/ruvocal/src/routes/settings/(nav)/application/+page.svelte +362 -0
- package/src/ruvocal/src/routes/settings/+layout.svelte +40 -0
- package/src/ruvocal/src/styles/highlight-js.css +195 -0
- package/src/ruvocal/src/styles/main.css +144 -0
- package/src/ruvocal/static/chatui/apple-touch-icon.png +0 -0
- package/src/ruvocal/static/chatui/favicon-dark.svg +3 -0
- package/src/ruvocal/static/chatui/favicon-dev.svg +3 -0
- package/src/ruvocal/static/chatui/favicon.ico +0 -0
- package/src/ruvocal/static/chatui/favicon.svg +3 -0
- package/src/ruvocal/static/chatui/icon-128x128.png +0 -0
- package/src/ruvocal/static/chatui/icon-144x144.png +0 -0
- package/src/ruvocal/static/chatui/icon-192x192.png +0 -0
- package/src/ruvocal/static/chatui/icon-256x256.png +0 -0
- package/src/ruvocal/static/chatui/icon-36x36.png +0 -0
- package/src/ruvocal/static/chatui/icon-48x48.png +0 -0
- package/src/ruvocal/static/chatui/icon-512x512.png +0 -0
- package/src/ruvocal/static/chatui/icon-72x72.png +0 -0
- package/src/ruvocal/static/chatui/icon-96x96.png +0 -0
- package/src/ruvocal/static/chatui/icon.svg +3 -0
- package/src/ruvocal/static/chatui/logo.svg +7 -0
- package/src/ruvocal/static/chatui/manifest.json +54 -0
- package/src/ruvocal/static/chatui/omni-welcome.gif +0 -0
- package/src/ruvocal/static/chatui/omni-welcome.png +0 -0
- package/src/ruvocal/static/chatui/welcome.js +184 -0
- package/src/ruvocal/static/chatui/welcome.svg +1 -0
- package/src/ruvocal/static/huggingchat/apple-touch-icon.png +0 -0
- package/src/ruvocal/static/huggingchat/assistants-thumbnail.png +0 -0
- package/src/ruvocal/static/huggingchat/castle-example.jpg +0 -0
- package/src/ruvocal/static/huggingchat/favicon-dark.svg +4 -0
- package/src/ruvocal/static/huggingchat/favicon-dev.svg +4 -0
- package/src/ruvocal/static/huggingchat/favicon.ico +0 -0
- package/src/ruvocal/static/huggingchat/favicon.svg +4 -0
- package/src/ruvocal/static/huggingchat/fulltext-logo.svg +2 -0
- package/src/ruvocal/static/huggingchat/icon-128x128.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-144x144.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-192x192.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-256x256.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-36x36.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-48x48.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-512x512.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-72x72.png +0 -0
- package/src/ruvocal/static/huggingchat/icon-96x96.png +0 -0
- package/src/ruvocal/static/huggingchat/icon.svg +4 -0
- package/src/ruvocal/static/huggingchat/logo.svg +4 -0
- package/src/ruvocal/static/huggingchat/manifest.json +54 -0
- package/src/ruvocal/static/huggingchat/omni-welcome.gif +0 -0
- package/src/ruvocal/static/huggingchat/routes.chat.json +226 -0
- package/src/ruvocal/static/huggingchat/thumbnail.png +0 -0
- package/src/ruvocal/static/huggingchat/tools-thumbnail.png +0 -0
- package/src/ruvocal/static/robots.txt +10 -0
- package/src/ruvocal/stub/@reflink/reflink/index.js +0 -0
- package/src/ruvocal/stub/@reflink/reflink/package.json +5 -0
- package/src/ruvocal/svelte.config.js +53 -0
- package/src/ruvocal/tailwind.config.cjs +30 -0
- package/src/ruvocal/tsconfig.json +19 -0
- package/src/ruvocal/vite.config.ts +87 -0
- package/src/scripts/deploy.sh +116 -0
- package/src/scripts/generate-config.js +245 -0
- package/src/scripts/generate-welcome.js +187 -0
- package/src/scripts/package-rvf.sh +116 -0
|
@@ -0,0 +1,1668 @@
|
|
|
1
|
+
import express from "express";
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
4
|
+
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// CONFIGURATION
|
|
7
|
+
// =============================================================================
|
|
8
|
+
|
|
9
|
+
const CLOUD_FUNCTIONS = {
|
|
10
|
+
// search: process.env.SEARCH_API_URL || "https://my-search-api.run.app",
|
|
11
|
+
// research: process.env.RESEARCH_API_URL || "https://my-research-api.run.app",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const PORT = parseInt(process.env.PORT || "3001", 10);
|
|
15
|
+
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// TOOL GROUPS — Enable/disable categories of tools independently
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// Groups map tool name prefixes from backends to logical categories.
|
|
20
|
+
// Each group can be toggled via env var. The AI sees only enabled tools.
|
|
21
|
+
|
|
22
|
+
const TOOL_GROUPS = {
|
|
23
|
+
// --- Core (always on, built-in) ---
|
|
24
|
+
core: {
|
|
25
|
+
enabled: true, // cannot be disabled
|
|
26
|
+
description: "Search, research, and guidance tools",
|
|
27
|
+
source: "builtin",
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// --- Intelligence (ruvector) ---
|
|
31
|
+
intelligence: {
|
|
32
|
+
enabled: process.env.MCP_GROUP_INTELLIGENCE !== "false",
|
|
33
|
+
description: "Self-learning intelligence — routing, memory, pattern training (ruvector)",
|
|
34
|
+
source: "ruvector",
|
|
35
|
+
prefixes: ["hooks_"],
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
// --- Agents & Orchestration (ruflo) ---
|
|
39
|
+
agents: {
|
|
40
|
+
enabled: process.env.MCP_GROUP_AGENTS !== "false",
|
|
41
|
+
description: "Agent lifecycle, swarm coordination, task management, workflows (ruflo)",
|
|
42
|
+
source: "ruflo",
|
|
43
|
+
prefixes: ["agent_", "swarm_", "task_", "session_", "hive-mind_", "workflow_", "coordination_"],
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// --- Memory & Knowledge (ruflo) ---
|
|
47
|
+
memory: {
|
|
48
|
+
enabled: process.env.MCP_GROUP_MEMORY !== "false",
|
|
49
|
+
description: "Vector memory, AgentDB, embeddings, semantic search (ruflo)",
|
|
50
|
+
source: "ruflo",
|
|
51
|
+
prefixes: ["memory_", "agentdb_", "embeddings_"],
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// --- Dev Tools (ruflo) ---
|
|
55
|
+
devtools: {
|
|
56
|
+
enabled: process.env.MCP_GROUP_DEVTOOLS !== "false",
|
|
57
|
+
description: "Hooks, code analysis, performance profiling, GitHub integration (ruflo)",
|
|
58
|
+
source: "ruflo",
|
|
59
|
+
prefixes: ["hooks_", "analyze_", "performance_", "github_", "terminal_", "config_", "system_", "progress_"],
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
// --- Security & Safety (ruflo) ---
|
|
63
|
+
security: {
|
|
64
|
+
enabled: process.env.MCP_GROUP_SECURITY === "true",
|
|
65
|
+
description: "AI defence, PII detection, claims management, pattern transfer (ruflo)",
|
|
66
|
+
source: "ruflo",
|
|
67
|
+
prefixes: ["aidefence_", "claims_", "transfer_"],
|
|
68
|
+
},
|
|
69
|
+
|
|
70
|
+
// --- Browser Automation (ruflo) ---
|
|
71
|
+
browser: {
|
|
72
|
+
enabled: process.env.MCP_GROUP_BROWSER === "true",
|
|
73
|
+
description: "Headless browser control — navigate, click, fill, screenshot (ruflo)",
|
|
74
|
+
source: "ruflo",
|
|
75
|
+
prefixes: ["browser_"],
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// --- Neural & DAA (ruflo) ---
|
|
79
|
+
neural: {
|
|
80
|
+
enabled: process.env.MCP_GROUP_NEURAL === "true",
|
|
81
|
+
description: "Neural network training, DAA autonomous agents, cognitive patterns (ruflo)",
|
|
82
|
+
source: "ruflo",
|
|
83
|
+
prefixes: ["neural_", "daa_"],
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
// --- Agentic Flow (agentic-flow@alpha) ---
|
|
87
|
+
"agentic-flow": {
|
|
88
|
+
enabled: process.env.MCP_GROUP_AGENTIC_FLOW === "true",
|
|
89
|
+
description: "Execute 66+ specialized agents, batch code editing, AgentDB patterns (agentic-flow)",
|
|
90
|
+
source: "agentic-flow",
|
|
91
|
+
prefixes: ["agentic_flow_", "agent_booster_", "agentdb_"],
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// --- Claude Code ---
|
|
95
|
+
"claude-code": {
|
|
96
|
+
enabled: process.env.MCP_GROUP_CLAUDE_CODE === "true",
|
|
97
|
+
description: "Anthropic Claude Code — file editing, bash execution, code analysis (requires ANTHROPIC_API_KEY)",
|
|
98
|
+
source: "claude",
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
// --- Gemini MCP ---
|
|
102
|
+
gemini: {
|
|
103
|
+
enabled: process.env.MCP_GROUP_GEMINI === "true",
|
|
104
|
+
description: "Google Gemini conversation context, multimodal capabilities (requires GOOGLE_API_KEY)",
|
|
105
|
+
source: "gemini-mcp",
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// --- OpenAI Codex ---
|
|
109
|
+
codex: {
|
|
110
|
+
enabled: process.env.MCP_GROUP_CODEX === "true",
|
|
111
|
+
description: "OpenAI Codex coding agent — code generation and execution (requires OPENAI_API_KEY)",
|
|
112
|
+
source: "codex",
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// =============================================================================
|
|
117
|
+
// STDIO MCP CLIENT — Connects to external MCP servers via child process
|
|
118
|
+
// =============================================================================
|
|
119
|
+
|
|
120
|
+
class StdioMcpClient {
|
|
121
|
+
constructor(name, command, args = []) {
|
|
122
|
+
this.name = name;
|
|
123
|
+
this.command = command;
|
|
124
|
+
this.args = args;
|
|
125
|
+
this.process = null;
|
|
126
|
+
this.tools = [];
|
|
127
|
+
this.ready = false;
|
|
128
|
+
this.pending = new Map();
|
|
129
|
+
this.buffer = "";
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async start() {
|
|
133
|
+
return new Promise((resolve) => {
|
|
134
|
+
try {
|
|
135
|
+
this.process = spawn(this.command, this.args, {
|
|
136
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
137
|
+
env: { ...process.env },
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
this.process.stdout.on("data", (data) => this._onData(data.toString()));
|
|
141
|
+
this.process.stderr.on("data", (data) => {
|
|
142
|
+
const msg = data.toString().trim();
|
|
143
|
+
if (msg && !msg.startsWith("npm WARN")) console.error(`[${this.name}] ${msg}`);
|
|
144
|
+
});
|
|
145
|
+
this.process.on("error", (err) => {
|
|
146
|
+
console.error(`[${this.name}] spawn error:`, err.message);
|
|
147
|
+
this.ready = false;
|
|
148
|
+
resolve(false);
|
|
149
|
+
});
|
|
150
|
+
this.process.on("exit", (code) => {
|
|
151
|
+
console.log(`[${this.name}] exited with code ${code}`);
|
|
152
|
+
this.ready = false;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
this._send("initialize", {
|
|
156
|
+
protocolVersion: "2024-11-05",
|
|
157
|
+
capabilities: {},
|
|
158
|
+
clientInfo: { name: "mcp-bridge", version: "2.0.0" },
|
|
159
|
+
}).then((result) => {
|
|
160
|
+
if (result && !result.error) {
|
|
161
|
+
this._notify("notifications/initialized", {});
|
|
162
|
+
return this._send("tools/list", {});
|
|
163
|
+
}
|
|
164
|
+
return null;
|
|
165
|
+
}).then((result) => {
|
|
166
|
+
if (result && result.tools) {
|
|
167
|
+
this.tools = result.tools.map(t => ({
|
|
168
|
+
...t,
|
|
169
|
+
_originalName: t.name,
|
|
170
|
+
_backend: this.name,
|
|
171
|
+
}));
|
|
172
|
+
this.ready = true;
|
|
173
|
+
console.log(`[${this.name}] ${this.tools.length} tools loaded`);
|
|
174
|
+
}
|
|
175
|
+
resolve(this.ready);
|
|
176
|
+
}).catch((err) => {
|
|
177
|
+
console.error(`[${this.name}] init failed:`, err.message);
|
|
178
|
+
resolve(false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
setTimeout(() => { if (!this.ready) resolve(false); }, 60000);
|
|
182
|
+
} catch (err) {
|
|
183
|
+
console.error(`[${this.name}] failed to start:`, err.message);
|
|
184
|
+
resolve(false);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
_onData(chunk) {
|
|
190
|
+
this.buffer += chunk;
|
|
191
|
+
const lines = this.buffer.split("\n");
|
|
192
|
+
this.buffer = lines.pop() || "";
|
|
193
|
+
for (const line of lines) {
|
|
194
|
+
const trimmed = line.trim();
|
|
195
|
+
if (!trimmed) continue;
|
|
196
|
+
try {
|
|
197
|
+
const msg = JSON.parse(trimmed);
|
|
198
|
+
if (msg.id && this.pending.has(msg.id)) {
|
|
199
|
+
const { resolve } = this.pending.get(msg.id);
|
|
200
|
+
this.pending.delete(msg.id);
|
|
201
|
+
resolve(msg.result || msg.error || {});
|
|
202
|
+
}
|
|
203
|
+
} catch { /* skip non-JSON */ }
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
_send(method, params) {
|
|
208
|
+
return new Promise((resolve, reject) => {
|
|
209
|
+
if (!this.process || this.process.killed) {
|
|
210
|
+
return reject(new Error(`${this.name} process not running`));
|
|
211
|
+
}
|
|
212
|
+
const id = randomUUID();
|
|
213
|
+
const msg = JSON.stringify({ jsonrpc: "2.0", id, method, params }) + "\n";
|
|
214
|
+
this.pending.set(id, { resolve, reject });
|
|
215
|
+
this.process.stdin.write(msg);
|
|
216
|
+
setTimeout(() => {
|
|
217
|
+
if (this.pending.has(id)) {
|
|
218
|
+
this.pending.delete(id);
|
|
219
|
+
reject(new Error(`${this.name} timeout for ${method}`));
|
|
220
|
+
}
|
|
221
|
+
}, 30000);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
_notify(method, params) {
|
|
226
|
+
if (!this.process || this.process.killed) return;
|
|
227
|
+
this.process.stdin.write(JSON.stringify({ jsonrpc: "2.0", method, params }) + "\n");
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
async callTool(originalName, args) {
|
|
231
|
+
if (!this.ready) return { error: `${this.name} backend not available` };
|
|
232
|
+
try {
|
|
233
|
+
return await this._send("tools/call", { name: originalName, arguments: args });
|
|
234
|
+
} catch (err) {
|
|
235
|
+
return { error: err.message };
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
stop() {
|
|
240
|
+
if (this.process && !this.process.killed) {
|
|
241
|
+
this.process.kill("SIGTERM");
|
|
242
|
+
this.process = null;
|
|
243
|
+
}
|
|
244
|
+
this.ready = false;
|
|
245
|
+
this.tools = [];
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// =============================================================================
|
|
250
|
+
// BACKEND REGISTRY
|
|
251
|
+
// =============================================================================
|
|
252
|
+
|
|
253
|
+
const BACKEND_DEFS = [
|
|
254
|
+
{ name: "ruvector", command: "npx", args: ["-y", "ruvector", "mcp", "start"], groups: ["intelligence"] },
|
|
255
|
+
{ name: "ruflo", command: "npx", args: ["-y", "ruflo", "mcp", "start"], groups: ["agents", "memory", "devtools", "security", "browser", "neural"] },
|
|
256
|
+
{ name: "agentic-flow", command: "npx", args: ["-y", "agentic-flow@alpha", "mcp", "start"], groups: ["agentic-flow"] },
|
|
257
|
+
{ name: "claude", command: "claude", args: ["mcp", "serve"], groups: ["claude-code"] },
|
|
258
|
+
{ name: "gemini-mcp", command: "npx", args: ["-y", "gemini-mcp-server"], groups: ["gemini"] },
|
|
259
|
+
{ name: "codex", command: "npx", args: ["-y", "@openai/codex", "mcp", "serve"], groups: ["codex"] },
|
|
260
|
+
];
|
|
261
|
+
|
|
262
|
+
const mcpBackends = new Map();
|
|
263
|
+
let allBackendTools = []; // all tools from all backends (pre-filter)
|
|
264
|
+
|
|
265
|
+
function isBackendNeeded(backendDef) {
|
|
266
|
+
return backendDef.groups.some(g => TOOL_GROUPS[g]?.enabled);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Filter tools from a backend based on which groups are enabled
|
|
270
|
+
function filterToolsByGroups(tools, backendName) {
|
|
271
|
+
const enabledGroups = Object.entries(TOOL_GROUPS)
|
|
272
|
+
.filter(([, g]) => g.enabled && g.source === backendName);
|
|
273
|
+
|
|
274
|
+
if (enabledGroups.length === 0) return [];
|
|
275
|
+
|
|
276
|
+
// If any enabled group has no prefixes defined, include all tools from that backend
|
|
277
|
+
const hasWildcard = enabledGroups.some(([, g]) => !g.prefixes);
|
|
278
|
+
if (hasWildcard) return tools;
|
|
279
|
+
|
|
280
|
+
const enabledPrefixes = enabledGroups.flatMap(([, g]) => g.prefixes || []);
|
|
281
|
+
return tools.filter(t => enabledPrefixes.some(p => t._originalName.startsWith(p)));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Get the final filtered tool list with namespaced names
|
|
285
|
+
function getActiveTools() {
|
|
286
|
+
const filtered = [];
|
|
287
|
+
for (const [backendName, client] of mcpBackends) {
|
|
288
|
+
const accepted = filterToolsByGroups(client.tools, backendName);
|
|
289
|
+
for (const t of accepted) {
|
|
290
|
+
filtered.push({ ...t, name: `${backendName}__${t._originalName}` });
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return filtered;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function initBackends() {
|
|
297
|
+
const needed = BACKEND_DEFS.filter(isBackendNeeded);
|
|
298
|
+
if (needed.length === 0) return;
|
|
299
|
+
|
|
300
|
+
console.log(`Starting ${needed.length} MCP backends: ${needed.map(b => b.name).join(", ")}`);
|
|
301
|
+
|
|
302
|
+
await Promise.allSettled(
|
|
303
|
+
needed.map(async (b) => {
|
|
304
|
+
const client = new StdioMcpClient(b.name, b.command, b.args);
|
|
305
|
+
const ok = await client.start();
|
|
306
|
+
if (ok) {
|
|
307
|
+
mcpBackends.set(b.name, client);
|
|
308
|
+
} else {
|
|
309
|
+
console.warn(`[${b.name}] failed to start`);
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
allBackendTools = getActiveTools();
|
|
315
|
+
console.log(`MCP backends: ${mcpBackends.size} active, ${allBackendTools.length} tools (filtered by groups)`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
process.on("SIGTERM", () => { for (const [, c] of mcpBackends) c.stop(); process.exit(0); });
|
|
319
|
+
process.on("SIGINT", () => { for (const [, c] of mcpBackends) c.stop(); process.exit(0); });
|
|
320
|
+
|
|
321
|
+
// =============================================================================
|
|
322
|
+
// BUILT-IN TOOLS (core group — always on)
|
|
323
|
+
// =============================================================================
|
|
324
|
+
|
|
325
|
+
const BUILTIN_TOOLS = [
|
|
326
|
+
{
|
|
327
|
+
name: "search",
|
|
328
|
+
description: "Search your knowledge base for relevant information.",
|
|
329
|
+
inputSchema: {
|
|
330
|
+
type: "object",
|
|
331
|
+
properties: {
|
|
332
|
+
query: { type: "string", description: "Natural language search query" },
|
|
333
|
+
limit: { type: "number", description: "Max results (default 5)", default: 5 },
|
|
334
|
+
},
|
|
335
|
+
required: ["query"],
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
name: "web_research",
|
|
340
|
+
description: "Search the web, fact-check claims, compare items, or conduct deep research. Actions: 'search' (quick), 'research' (deep report), 'compare' (side-by-side), 'fact_check' (verify claims), 'goap' (comprehensive multi-step research with verification).",
|
|
341
|
+
inputSchema: {
|
|
342
|
+
type: "object",
|
|
343
|
+
properties: {
|
|
344
|
+
action: { type: "string", enum: ["search", "research", "compare", "fact_check", "goap"], description: "Research action type", default: "search" },
|
|
345
|
+
query: { type: "string", description: "Search query or topic" },
|
|
346
|
+
items: { type: "array", items: { type: "string" }, description: "Items to compare (for 'compare')" },
|
|
347
|
+
claim: { type: "string", description: "Claim to verify (for 'fact_check')" },
|
|
348
|
+
verify: { type: "boolean", description: "Verify results in goap mode", default: true },
|
|
349
|
+
},
|
|
350
|
+
required: ["query"],
|
|
351
|
+
},
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "guidance",
|
|
355
|
+
description: "Get instructions on how to use the available tool groups and services. Call this FIRST when unsure which tool to use, when a user asks 'what can you do?', or when you need to understand a specific tool group. Returns structured guidance for the AI on tool selection and usage patterns.",
|
|
356
|
+
inputSchema: {
|
|
357
|
+
type: "object",
|
|
358
|
+
properties: {
|
|
359
|
+
topic: {
|
|
360
|
+
type: "string",
|
|
361
|
+
enum: ["overview", "groups", "intelligence", "agents", "memory", "devtools", "security", "browser", "neural", "agentic-flow", "claude-code", "gemini", "codex", "tool"],
|
|
362
|
+
description: "What to get guidance on. Use 'overview' for capabilities summary, 'groups' to see all tool groups and their status, or a specific group name for detailed usage instructions.",
|
|
363
|
+
default: "overview",
|
|
364
|
+
},
|
|
365
|
+
tool_name: { type: "string", description: "Specific tool name to get detailed usage info (when topic='tool')" },
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
];
|
|
370
|
+
|
|
371
|
+
// =============================================================================
|
|
372
|
+
// GUIDANCE ENGINE — AI-facing instruction system
|
|
373
|
+
// =============================================================================
|
|
374
|
+
|
|
375
|
+
function getGuidance(topic, toolName) {
|
|
376
|
+
const activeGroups = Object.entries(TOOL_GROUPS).filter(([, g]) => g.enabled);
|
|
377
|
+
const inactiveGroups = Object.entries(TOOL_GROUPS).filter(([, g]) => !g.enabled);
|
|
378
|
+
const externalTools = getActiveTools();
|
|
379
|
+
|
|
380
|
+
if (topic === "overview") {
|
|
381
|
+
return {
|
|
382
|
+
guidance: `# Tool Capabilities Overview
|
|
383
|
+
|
|
384
|
+
You have access to ${BUILTIN_TOOLS.length + externalTools.length} tools organized into ${activeGroups.length} active groups.
|
|
385
|
+
|
|
386
|
+
## Active Groups
|
|
387
|
+
${activeGroups.map(([name, g]) => {
|
|
388
|
+
const count = name === "core" ? BUILTIN_TOOLS.length : externalTools.filter(t => t.name.startsWith(g.source + "__")).length;
|
|
389
|
+
return `- **${name}** (${count} tools) — ${g.description}`;
|
|
390
|
+
}).join("\n")}
|
|
391
|
+
|
|
392
|
+
## Inactive Groups (can be enabled)
|
|
393
|
+
${inactiveGroups.map(([name, g]) => `- **${name}** — ${g.description}`).join("\n") || "None"}
|
|
394
|
+
|
|
395
|
+
## Quick Decision Guide
|
|
396
|
+
- **Knowledge questions** → use \`search\` first, then \`web_research\` if needed
|
|
397
|
+
- **Current events / facts** → use \`web_research\` with action 'search' or 'goap'
|
|
398
|
+
- **Complex research** → use \`web_research\` with action 'goap' (multi-step pipeline)
|
|
399
|
+
- **"What can you do?"** → call \`guidance\` with topic 'groups'
|
|
400
|
+
- **Memory / recall** → use tools from the \`memory\` group
|
|
401
|
+
- **Agent orchestration** → use tools from the \`agents\` group
|
|
402
|
+
- **Code analysis / performance** → use tools from the \`devtools\` group
|
|
403
|
+
|
|
404
|
+
## Rules
|
|
405
|
+
1. Call tools FIRST, then present results conversationally
|
|
406
|
+
2. Never show raw JSON — synthesize results naturally
|
|
407
|
+
3. For complex questions, prefer GOAP pipeline (web_research action='goap')
|
|
408
|
+
4. Call \`guidance\` with a specific group name to learn how to use that group's tools`,
|
|
409
|
+
topic: "overview",
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (topic === "groups") {
|
|
414
|
+
const groupList = Object.entries(TOOL_GROUPS).map(([name, g]) => {
|
|
415
|
+
const status = g.enabled ? "ACTIVE" : "INACTIVE";
|
|
416
|
+
const toolCount = name === "core" ? BUILTIN_TOOLS.length :
|
|
417
|
+
externalTools.filter(t => {
|
|
418
|
+
const backend = t._backend;
|
|
419
|
+
return g.source === backend && (!g.prefixes || g.prefixes.some(p => t._originalName.startsWith(p)));
|
|
420
|
+
}).length;
|
|
421
|
+
return `| ${name} | ${status} | ${toolCount} | ${g.description} |`;
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
guidance: `# Tool Groups\n\n| Group | Status | Tools | Description |\n|-------|--------|-------|-------------|\n${groupList.join("\n")}`,
|
|
426
|
+
topic: "groups",
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Specific group guidance
|
|
431
|
+
const groupGuides = {
|
|
432
|
+
intelligence: `# Intelligence Group (ruvector)
|
|
433
|
+
|
|
434
|
+
Self-learning intelligence tools for routing and vector memory.
|
|
435
|
+
|
|
436
|
+
## Key Tools
|
|
437
|
+
- **ruvector__hooks_route** — Route a task to the best agent type. Call with a task description.
|
|
438
|
+
- **ruvector__hooks_remember** — Store context/knowledge in vector memory for later recall.
|
|
439
|
+
- **ruvector__hooks_recall** — Search vector memory semantically. Good for finding past context.
|
|
440
|
+
- **ruvector__hooks_pretrain** — Bootstrap intelligence from a code repository.
|
|
441
|
+
- **ruvector__hooks_build_agents** — Generate optimized agent configurations.
|
|
442
|
+
- **ruvector__hooks_stats** — Get intelligence statistics and learning metrics.
|
|
443
|
+
|
|
444
|
+
## When to Use
|
|
445
|
+
- Before starting complex tasks: route to find the best agent approach
|
|
446
|
+
- To store important findings for cross-session memory
|
|
447
|
+
- To recall previously stored patterns or solutions`,
|
|
448
|
+
|
|
449
|
+
agents: `# Agents & Orchestration Group (ruflo)
|
|
450
|
+
|
|
451
|
+
Multi-agent lifecycle management, swarm coordination, and task workflows.
|
|
452
|
+
|
|
453
|
+
## Key Tools
|
|
454
|
+
- **ruflo__agent_spawn** — Create a new agent with specific capabilities
|
|
455
|
+
- **ruflo__agent_list** — List all active agents
|
|
456
|
+
- **ruflo__swarm_init** — Initialize a swarm with a topology (mesh, hierarchical, ring, star)
|
|
457
|
+
- **ruflo__task_create** — Create and assign tasks
|
|
458
|
+
- **ruflo__workflow_create** — Define multi-step workflows
|
|
459
|
+
- **ruflo__workflow_execute** — Execute a workflow
|
|
460
|
+
- **ruflo__hive-mind_init** — Start collective intelligence coordination
|
|
461
|
+
- **ruflo__coordination_orchestrate** — Multi-agent coordination
|
|
462
|
+
|
|
463
|
+
## When to Use
|
|
464
|
+
- Complex tasks requiring multiple agents working together
|
|
465
|
+
- Pipeline workflows with sequential or parallel steps
|
|
466
|
+
- Distributed task management`,
|
|
467
|
+
|
|
468
|
+
memory: `# Memory & Knowledge Group (ruflo)
|
|
469
|
+
|
|
470
|
+
Vector storage, semantic search, AgentDB pattern learning, and embeddings.
|
|
471
|
+
|
|
472
|
+
## Key Tools
|
|
473
|
+
- **ruflo__memory_store** — Store a value with vector embedding for semantic search
|
|
474
|
+
- **ruflo__memory_search** — Semantic search across stored memories (HNSW-indexed)
|
|
475
|
+
- **ruflo__memory_list** — List stored memory entries
|
|
476
|
+
- **ruflo__agentdb_pattern-store** — Store a reasoning pattern for learning
|
|
477
|
+
- **ruflo__agentdb_pattern-search** — Search for similar reasoning patterns
|
|
478
|
+
- **ruflo__agentdb_context-synthesize** — Synthesize context from stored memories
|
|
479
|
+
- **ruflo__embeddings_generate** — Generate vector embeddings for text
|
|
480
|
+
- **ruflo__embeddings_search** — Semantic similarity search
|
|
481
|
+
|
|
482
|
+
## When to Use
|
|
483
|
+
- Persistent knowledge storage across sessions
|
|
484
|
+
- Finding similar past solutions or patterns
|
|
485
|
+
- Building semantic search over custom data`,
|
|
486
|
+
|
|
487
|
+
devtools: `# Dev Tools Group (ruflo)
|
|
488
|
+
|
|
489
|
+
Code analysis, performance profiling, GitHub integration, and terminal access.
|
|
490
|
+
|
|
491
|
+
## Key Tools
|
|
492
|
+
- **ruflo__analyze_diff** — Analyze git diff for risk and change classification
|
|
493
|
+
- **ruflo__performance_benchmark** — Run performance benchmarks
|
|
494
|
+
- **ruflo__performance_bottleneck** — Detect performance bottlenecks
|
|
495
|
+
- **ruflo__github_repo_analyze** — Analyze a GitHub repository
|
|
496
|
+
- **ruflo__github_pr_manage** — Manage pull requests
|
|
497
|
+
- **ruflo__terminal_execute** — Execute commands in a terminal session
|
|
498
|
+
|
|
499
|
+
## When to Use
|
|
500
|
+
- Code review and change risk assessment
|
|
501
|
+
- Performance analysis and optimization
|
|
502
|
+
- GitHub repository management`,
|
|
503
|
+
|
|
504
|
+
security: `# Security & Safety Group (ruflo)
|
|
505
|
+
|
|
506
|
+
AI defence, PII detection, and claims-based authorization.
|
|
507
|
+
|
|
508
|
+
## Key Tools
|
|
509
|
+
- **ruflo__aidefence_scan** — Scan text for AI manipulation attempts
|
|
510
|
+
- **ruflo__aidefence_has_pii** — Check for PII (emails, phones, SSNs)
|
|
511
|
+
- **ruflo__aidefence_is_safe** — Quick safety check on input
|
|
512
|
+
- **ruflo__claims_claim** — Claim an issue for work
|
|
513
|
+
- **ruflo__claims_board** — Visual board of all claims
|
|
514
|
+
|
|
515
|
+
## When to Use
|
|
516
|
+
- Input validation and safety checking
|
|
517
|
+
- PII detection before processing sensitive data
|
|
518
|
+
- Work item management across agents`,
|
|
519
|
+
|
|
520
|
+
browser: `# Browser Automation Group (ruflo)
|
|
521
|
+
|
|
522
|
+
Headless browser control for web interaction and testing.
|
|
523
|
+
|
|
524
|
+
## Key Tools
|
|
525
|
+
- **ruflo__browser_open** — Navigate to a URL
|
|
526
|
+
- **ruflo__browser_click** — Click elements by reference
|
|
527
|
+
- **ruflo__browser_fill** — Fill form inputs
|
|
528
|
+
- **ruflo__browser_screenshot** — Capture page screenshots
|
|
529
|
+
- **ruflo__browser_snapshot** — Get accessibility tree for AI parsing
|
|
530
|
+
- **ruflo__browser_eval** — Execute JavaScript in page context
|
|
531
|
+
|
|
532
|
+
## When to Use
|
|
533
|
+
- Web scraping and data extraction
|
|
534
|
+
- Automated testing (E2E)
|
|
535
|
+
- Form filling and web interaction`,
|
|
536
|
+
|
|
537
|
+
neural: `# Neural & DAA Group (ruflo)
|
|
538
|
+
|
|
539
|
+
Neural network operations and Decentralized Autonomous Agents.
|
|
540
|
+
|
|
541
|
+
## Key Tools
|
|
542
|
+
- **ruflo__neural_train** — Train a neural model
|
|
543
|
+
- **ruflo__neural_predict** — Make predictions
|
|
544
|
+
- **ruflo__daa_agent_create** — Create an autonomous agent
|
|
545
|
+
- **ruflo__daa_workflow_create** — Create autonomous workflows
|
|
546
|
+
- **ruflo__daa_knowledge_share** — Share knowledge between agents
|
|
547
|
+
|
|
548
|
+
## When to Use
|
|
549
|
+
- Pattern learning and prediction
|
|
550
|
+
- Autonomous agent workflows
|
|
551
|
+
- Knowledge transfer between agents`,
|
|
552
|
+
|
|
553
|
+
"agentic-flow": `# Agentic Flow Group (agentic-flow@alpha)
|
|
554
|
+
|
|
555
|
+
Execute 66+ specialized agents with boosted code editing and AgentDB.
|
|
556
|
+
|
|
557
|
+
## Key Tools
|
|
558
|
+
- **agentic-flow__agentic_flow_agent** — Execute any of 66+ specialized agents
|
|
559
|
+
- **agentic-flow__agentic_flow_list_agents** — List available agent types
|
|
560
|
+
- **agentic-flow__agent_booster_edit_file** — 352x faster code editing
|
|
561
|
+
- **agentic-flow__agent_booster_batch_edit** — Multi-file refactoring
|
|
562
|
+
- **agentic-flow__agentdb_pattern_store** — Store reasoning patterns
|
|
563
|
+
- **agentic-flow__agentdb_pattern_search** — Search similar patterns
|
|
564
|
+
|
|
565
|
+
## When to Use
|
|
566
|
+
- Complex code generation with specialized agents
|
|
567
|
+
- Batch code refactoring across files
|
|
568
|
+
- Agent selection when you need the right specialist`,
|
|
569
|
+
|
|
570
|
+
"claude-code": `# Claude Code Group
|
|
571
|
+
|
|
572
|
+
Anthropic Claude Code MCP server — full coding agent capabilities.
|
|
573
|
+
|
|
574
|
+
Requires: ANTHROPIC_API_KEY environment variable.
|
|
575
|
+
|
|
576
|
+
## Capabilities
|
|
577
|
+
- File reading and editing
|
|
578
|
+
- Bash command execution
|
|
579
|
+
- Code analysis and generation
|
|
580
|
+
- Project exploration
|
|
581
|
+
|
|
582
|
+
## When to Use
|
|
583
|
+
- When you need a second AI perspective on code
|
|
584
|
+
- Complex refactoring tasks
|
|
585
|
+
- Code review and analysis`,
|
|
586
|
+
|
|
587
|
+
gemini: `# Gemini MCP Group
|
|
588
|
+
|
|
589
|
+
Google Gemini with conversation context management.
|
|
590
|
+
|
|
591
|
+
Requires: GOOGLE_API_KEY environment variable (already set for Gemini models).
|
|
592
|
+
|
|
593
|
+
## Capabilities
|
|
594
|
+
- Conversation context management
|
|
595
|
+
- Multimodal processing
|
|
596
|
+
- Google Search grounding
|
|
597
|
+
|
|
598
|
+
## When to Use
|
|
599
|
+
- Extended context conversations
|
|
600
|
+
- Multimodal content processing`,
|
|
601
|
+
|
|
602
|
+
codex: `# Codex Group
|
|
603
|
+
|
|
604
|
+
OpenAI Codex coding agent.
|
|
605
|
+
|
|
606
|
+
Requires: OPENAI_API_KEY environment variable (already set for OpenAI models).
|
|
607
|
+
|
|
608
|
+
## Capabilities
|
|
609
|
+
- Code generation and execution
|
|
610
|
+
- Code completion
|
|
611
|
+
- Code explanation
|
|
612
|
+
|
|
613
|
+
## When to Use
|
|
614
|
+
- Code generation tasks
|
|
615
|
+
- Quick code completions
|
|
616
|
+
- Code explanation and documentation`,
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
if (topic === "tool" && toolName) {
|
|
620
|
+
const allTools = [...BUILTIN_TOOLS, ...externalTools];
|
|
621
|
+
const tool = allTools.find(t => t.name === toolName);
|
|
622
|
+
if (tool) {
|
|
623
|
+
const props = Object.entries(tool.inputSchema?.properties || {})
|
|
624
|
+
.map(([k, v]) => `- **${k}** (${v.type}) — ${v.description || ""}`)
|
|
625
|
+
.join("\n");
|
|
626
|
+
return { guidance: `# ${tool.name}\n\n${tool.description}\n\n## Parameters\n${props}`, topic: "tool" };
|
|
627
|
+
}
|
|
628
|
+
return { guidance: `Tool '${toolName}' not found. Call guidance with topic='groups' to see available tools.`, topic: "tool" };
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (groupGuides[topic]) {
|
|
632
|
+
const group = TOOL_GROUPS[topic];
|
|
633
|
+
if (!group?.enabled) {
|
|
634
|
+
return { guidance: `# ${topic} — INACTIVE\n\n${group?.description || ""}\n\nThis group is not enabled. Set the appropriate MCP_GROUP_* env var to "true" to activate it.`, topic };
|
|
635
|
+
}
|
|
636
|
+
return { guidance: groupGuides[topic], topic };
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return { guidance: `Unknown topic '${topic}'. Use 'overview', 'groups', or a specific group name.`, topic };
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// =============================================================================
|
|
643
|
+
// HELPER — Call a backend Cloud Function / API
|
|
644
|
+
// =============================================================================
|
|
645
|
+
|
|
646
|
+
async function callCloudFunction(url, payload, timeoutMs = 25000) {
|
|
647
|
+
const controller = new AbortController();
|
|
648
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
649
|
+
try {
|
|
650
|
+
const resp = await fetch(url, {
|
|
651
|
+
method: "POST",
|
|
652
|
+
headers: { "Content-Type": "application/json" },
|
|
653
|
+
body: JSON.stringify(payload),
|
|
654
|
+
signal: controller.signal,
|
|
655
|
+
});
|
|
656
|
+
return await resp.json();
|
|
657
|
+
} catch (err) {
|
|
658
|
+
if (err.name === "AbortError") return { error: "Request timed out", timeout: timeoutMs };
|
|
659
|
+
return { error: err.message };
|
|
660
|
+
} finally {
|
|
661
|
+
clearTimeout(timer);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// =============================================================================
|
|
666
|
+
// GOAP SEARCH PIPELINE
|
|
667
|
+
// =============================================================================
|
|
668
|
+
|
|
669
|
+
async function executeGoapSearch(query, args) {
|
|
670
|
+
const researchUrl = CLOUD_FUNCTIONS.research;
|
|
671
|
+
if (!researchUrl) return { error: "GOAP requires a 'research' URL in CLOUD_FUNCTIONS" };
|
|
672
|
+
|
|
673
|
+
const startTime = Date.now();
|
|
674
|
+
|
|
675
|
+
const composeResult = await callCloudFunction(researchUrl, {
|
|
676
|
+
action: "search",
|
|
677
|
+
query: `Break this question into 3-4 distinct search queries that would help answer it comprehensively. Return ONLY the queries, one per line:\n\n${query}`,
|
|
678
|
+
}, 30000);
|
|
679
|
+
|
|
680
|
+
let searchQueries = [query];
|
|
681
|
+
if (composeResult && !composeResult.error) {
|
|
682
|
+
const answer = composeResult.result?.answer || composeResult.answer || "";
|
|
683
|
+
const lines = answer.split("\n").map(l => l.replace(/^[\d\-\*\.\)]+\s*/, "").trim()).filter(l => l.length > 5 && l.length < 200);
|
|
684
|
+
if (lines.length >= 2) searchQueries = lines.slice(0, 4);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
const searchResults = await Promise.all(
|
|
688
|
+
searchQueries.map(q => callCloudFunction(researchUrl, { action: "search", query: q }, 30000))
|
|
689
|
+
);
|
|
690
|
+
|
|
691
|
+
const allSources = [], allAnswers = [];
|
|
692
|
+
for (let i = 0; i < searchResults.length; i++) {
|
|
693
|
+
const r = searchResults[i];
|
|
694
|
+
if (r && !r.error && r.success !== false) {
|
|
695
|
+
const answer = r.result?.answer || r.answer || "";
|
|
696
|
+
if (answer) allAnswers.push({ query: searchQueries[i], answer });
|
|
697
|
+
const gm = r.result?.groundingMetadata || r.groundingMetadata || {};
|
|
698
|
+
if (gm.sources) allSources.push(...gm.sources);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
const uniqueSources = [];
|
|
703
|
+
const seenUrls = new Set();
|
|
704
|
+
for (const src of allSources) {
|
|
705
|
+
const url = src.url || src.uri || "";
|
|
706
|
+
if (url && !seenUrls.has(url)) { seenUrls.add(url); uniqueSources.push(src); }
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const synthesisInput = allAnswers.map(a => `## ${a.query}\n${a.answer}`).join("\n\n");
|
|
710
|
+
const synthesisResult = await callCloudFunction(researchUrl, {
|
|
711
|
+
action: "research",
|
|
712
|
+
topic: `Synthesize these findings into a comprehensive answer to: "${query}"\n\nFindings:\n${synthesisInput}`,
|
|
713
|
+
}, 60000);
|
|
714
|
+
|
|
715
|
+
const synthesizedAnswer = synthesisResult?.result?.answer || synthesisResult?.answer || synthesisInput;
|
|
716
|
+
const synthGm = synthesisResult?.result?.groundingMetadata || {};
|
|
717
|
+
if (synthGm.sources) {
|
|
718
|
+
for (const src of synthGm.sources) {
|
|
719
|
+
const url = src.url || src.uri || "";
|
|
720
|
+
if (url && !seenUrls.has(url)) { seenUrls.add(url); uniqueSources.push(src); }
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
let verification = { verified: true, confidence: "high" };
|
|
725
|
+
if (args.verify !== false && synthesizedAnswer.length > 100) {
|
|
726
|
+
const vr = await callCloudFunction(researchUrl, {
|
|
727
|
+
action: "fact_check", claim: synthesizedAnswer.substring(0, 500),
|
|
728
|
+
}, 30000);
|
|
729
|
+
if (vr && !vr.error && vr.result) {
|
|
730
|
+
verification = {
|
|
731
|
+
verified: vr.result.verdict !== "FALSE",
|
|
732
|
+
verdict: vr.result.verdict,
|
|
733
|
+
confidence: vr.result.confidence || "medium",
|
|
734
|
+
details: vr.result.analysis,
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return {
|
|
740
|
+
answer: synthesizedAnswer, pipeline: "goap",
|
|
741
|
+
steps: { queries_composed: searchQueries.length, searches_executed: searchResults.filter(r => !r?.error).length, sources_found: uniqueSources.length, verification },
|
|
742
|
+
sources: uniqueSources.slice(0, 10), searchQueries, duration_ms: Date.now() - startTime,
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// =============================================================================
|
|
747
|
+
// TOOL EXECUTOR
|
|
748
|
+
// =============================================================================
|
|
749
|
+
|
|
750
|
+
async function executeTool(name, args) {
|
|
751
|
+
// Validate that search-like tools have a non-empty query to prevent 400 errors
|
|
752
|
+
if (!args || typeof args !== "object") args = {};
|
|
753
|
+
const rawQuery = args.query ?? args.q ?? args.input ?? "";
|
|
754
|
+
const queryStr = typeof rawQuery === "string" ? rawQuery.trim() : String(rawQuery || "").trim();
|
|
755
|
+
const isSearchTool = name === "search" || name === "web_research" || /^(web_)?search/i.test(name);
|
|
756
|
+
if (isSearchTool && !queryStr) {
|
|
757
|
+
return { content: [{ type: "text", text: `No search query provided. Please specify a search query for '${name}'.` }] };
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
switch (name) {
|
|
761
|
+
case "search":
|
|
762
|
+
if (!CLOUD_FUNCTIONS.search) return { error: "search endpoint not configured" };
|
|
763
|
+
return callCloudFunction(CLOUD_FUNCTIONS.search, { query: args.query, limit: args.limit || 5 });
|
|
764
|
+
|
|
765
|
+
case "web_research": {
|
|
766
|
+
const action = args.action || "search";
|
|
767
|
+
if (action === "goap") return executeGoapSearch(args.query, args);
|
|
768
|
+
if (!CLOUD_FUNCTIONS.research) return { error: "research endpoint not configured" };
|
|
769
|
+
const payload = { action };
|
|
770
|
+
if (action === "search") payload.query = args.query;
|
|
771
|
+
else if (action === "research") payload.topic = args.query;
|
|
772
|
+
else if (action === "compare") payload.items = args.items;
|
|
773
|
+
else if (action === "fact_check") payload.claim = args.claim || args.query;
|
|
774
|
+
return callCloudFunction(CLOUD_FUNCTIONS.research, payload, 60000);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
case "guidance":
|
|
778
|
+
return getGuidance(args.topic || "overview", args.tool_name);
|
|
779
|
+
|
|
780
|
+
default: {
|
|
781
|
+
// Route to external MCP backend
|
|
782
|
+
const activeTools = getActiveTools();
|
|
783
|
+
const extTool = activeTools.find(t => t.name === name);
|
|
784
|
+
if (extTool) {
|
|
785
|
+
const backend = mcpBackends.get(extTool._backend);
|
|
786
|
+
if (backend) return backend.callTool(extTool._originalName, args);
|
|
787
|
+
return { error: `Backend ${extTool._backend} not available` };
|
|
788
|
+
}
|
|
789
|
+
return { error: `Unknown tool: ${name}. Call 'guidance' with topic='groups' to see available tools.` };
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// =============================================================================
|
|
795
|
+
// PER-GROUP TOOL HELPERS
|
|
796
|
+
// =============================================================================
|
|
797
|
+
|
|
798
|
+
// Get tools for a specific group only
|
|
799
|
+
function getToolsForGroup(groupName) {
|
|
800
|
+
const group = TOOL_GROUPS[groupName];
|
|
801
|
+
if (!group || !group.enabled) return [];
|
|
802
|
+
if (groupName === "core") return BUILTIN_TOOLS;
|
|
803
|
+
|
|
804
|
+
const allActive = getActiveTools();
|
|
805
|
+
if (!group.prefixes) {
|
|
806
|
+
// No prefix filter — return all tools from this backend
|
|
807
|
+
return allActive.filter(t => t._backend === group.source);
|
|
808
|
+
}
|
|
809
|
+
return allActive.filter(t =>
|
|
810
|
+
t._backend === group.source && group.prefixes.some(p => t._originalName.startsWith(p))
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// Group display names for the Chat UI
|
|
815
|
+
const GROUP_DISPLAY_NAMES = {
|
|
816
|
+
core: "Core Tools",
|
|
817
|
+
intelligence: "Intelligence & Learning",
|
|
818
|
+
agents: "Agents & Orchestration",
|
|
819
|
+
memory: "Memory & Knowledge",
|
|
820
|
+
devtools: "Dev Tools & Analysis",
|
|
821
|
+
security: "Security & Safety",
|
|
822
|
+
browser: "Browser Automation",
|
|
823
|
+
neural: "Neural & DAA",
|
|
824
|
+
"agentic-flow": "Agentic Flow",
|
|
825
|
+
"claude-code": "Claude Code",
|
|
826
|
+
gemini: "Gemini",
|
|
827
|
+
codex: "Codex",
|
|
828
|
+
};
|
|
829
|
+
|
|
830
|
+
// =============================================================================
|
|
831
|
+
// MCP SERVER — Multiple endpoints per group
|
|
832
|
+
// =============================================================================
|
|
833
|
+
|
|
834
|
+
const app = express();
|
|
835
|
+
app.use(express.json({ limit: "10mb" }));
|
|
836
|
+
|
|
837
|
+
// ---------- CORS middleware ----------
|
|
838
|
+
app.use((req, res, next) => {
|
|
839
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
840
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
841
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
842
|
+
if (req.method === "OPTIONS") return res.sendStatus(204);
|
|
843
|
+
next();
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
// ---------- Shared MCP handler ----------
|
|
847
|
+
function createMcpHandler(groupName) {
|
|
848
|
+
return async (req, res) => {
|
|
849
|
+
const { method, id, params } = req.body;
|
|
850
|
+
try {
|
|
851
|
+
switch (method) {
|
|
852
|
+
case "initialize":
|
|
853
|
+
return res.json({
|
|
854
|
+
jsonrpc: "2.0", id,
|
|
855
|
+
result: {
|
|
856
|
+
protocolVersion: "2024-11-05",
|
|
857
|
+
capabilities: { tools: {} },
|
|
858
|
+
serverInfo: { name: `mcp-bridge/${groupName}`, version: "2.0.0" },
|
|
859
|
+
},
|
|
860
|
+
});
|
|
861
|
+
case "tools/list": {
|
|
862
|
+
const tools = getToolsForGroup(groupName);
|
|
863
|
+
return res.json({ jsonrpc: "2.0", id, result: { tools } });
|
|
864
|
+
}
|
|
865
|
+
case "tools/call": {
|
|
866
|
+
const { name, arguments: toolArgs } = params;
|
|
867
|
+
const result = await executeTool(name, toolArgs || {});
|
|
868
|
+
// If executeTool already returned MCP-formatted content, pass through directly
|
|
869
|
+
const mcpResult = result && Array.isArray(result.content)
|
|
870
|
+
? { content: result.content }
|
|
871
|
+
: { content: [{ type: "text", text: typeof result === "string" ? result : JSON.stringify(result, null, 2) }] };
|
|
872
|
+
return res.json({ jsonrpc: "2.0", id, result: mcpResult });
|
|
873
|
+
}
|
|
874
|
+
case "notifications/initialized":
|
|
875
|
+
return res.json({ jsonrpc: "2.0", id, result: {} });
|
|
876
|
+
default:
|
|
877
|
+
return res.json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } });
|
|
878
|
+
}
|
|
879
|
+
} catch (err) {
|
|
880
|
+
console.error(`MCP error [${groupName}/${method}]:`, err);
|
|
881
|
+
return res.json({ jsonrpc: "2.0", id, error: { code: -32603, message: err.message } });
|
|
882
|
+
}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
function createMcpSseHandler(groupName) {
|
|
887
|
+
return (req, res) => {
|
|
888
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
889
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
890
|
+
res.setHeader("Connection", "keep-alive");
|
|
891
|
+
res.write(`data: ${JSON.stringify({ type: "endpoint", url: `/mcp/${groupName}` })}\n\n`);
|
|
892
|
+
};
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// ---------- Register per-group endpoints ----------
|
|
896
|
+
for (const groupName of Object.keys(TOOL_GROUPS)) {
|
|
897
|
+
app.post(`/mcp/${groupName}`, createMcpHandler(groupName));
|
|
898
|
+
app.get(`/mcp/${groupName}`, createMcpSseHandler(groupName));
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// ---------- Catch-all /mcp — serves ALL enabled tools (backwards-compatible) ----------
|
|
902
|
+
app.post("/mcp", async (req, res) => {
|
|
903
|
+
const { method, id, params } = req.body;
|
|
904
|
+
try {
|
|
905
|
+
switch (method) {
|
|
906
|
+
case "initialize":
|
|
907
|
+
return res.json({
|
|
908
|
+
jsonrpc: "2.0", id,
|
|
909
|
+
result: {
|
|
910
|
+
protocolVersion: "2024-11-05",
|
|
911
|
+
capabilities: { tools: {} },
|
|
912
|
+
serverInfo: { name: "mcp-bridge", version: "2.0.0" },
|
|
913
|
+
},
|
|
914
|
+
});
|
|
915
|
+
case "tools/list": {
|
|
916
|
+
const activeTools = getActiveTools();
|
|
917
|
+
return res.json({ jsonrpc: "2.0", id, result: { tools: [...BUILTIN_TOOLS, ...activeTools] } });
|
|
918
|
+
}
|
|
919
|
+
case "tools/call": {
|
|
920
|
+
const { name, arguments: toolArgs } = params;
|
|
921
|
+
const result = await executeTool(name, toolArgs || {});
|
|
922
|
+
// If executeTool already returned MCP-formatted content, pass through directly
|
|
923
|
+
const mcpResult = result && Array.isArray(result.content)
|
|
924
|
+
? { content: result.content }
|
|
925
|
+
: { content: [{ type: "text", text: typeof result === "string" ? result : JSON.stringify(result, null, 2) }] };
|
|
926
|
+
return res.json({ jsonrpc: "2.0", id, result: mcpResult });
|
|
927
|
+
}
|
|
928
|
+
case "notifications/initialized":
|
|
929
|
+
return res.json({ jsonrpc: "2.0", id, result: {} });
|
|
930
|
+
default:
|
|
931
|
+
return res.json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } });
|
|
932
|
+
}
|
|
933
|
+
} catch (err) {
|
|
934
|
+
console.error(`MCP error [${method}]:`, err);
|
|
935
|
+
return res.json({ jsonrpc: "2.0", id, error: { code: -32603, message: err.message } });
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
app.get("/mcp", (req, res) => {
|
|
940
|
+
res.setHeader("Content-Type", "text/event-stream");
|
|
941
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
942
|
+
res.setHeader("Connection", "keep-alive");
|
|
943
|
+
res.write(`data: ${JSON.stringify({ type: "endpoint", url: "/mcp" })}\n\n`);
|
|
944
|
+
});
|
|
945
|
+
|
|
946
|
+
// ---------- GET /mcp-servers — returns MCP_SERVERS JSON for Chat UI config ----------
|
|
947
|
+
app.get("/mcp-servers", (_, res) => {
|
|
948
|
+
const servers = [];
|
|
949
|
+
for (const [name, group] of Object.entries(TOOL_GROUPS)) {
|
|
950
|
+
if (!group.enabled) continue;
|
|
951
|
+
const tools = getToolsForGroup(name);
|
|
952
|
+
if (tools.length === 0) continue;
|
|
953
|
+
servers.push({
|
|
954
|
+
name: GROUP_DISPLAY_NAMES[name] || name,
|
|
955
|
+
url: `/mcp/${name}`,
|
|
956
|
+
tools: tools.length,
|
|
957
|
+
group: name,
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
res.json(servers);
|
|
961
|
+
});
|
|
962
|
+
|
|
963
|
+
// =============================================================================
|
|
964
|
+
// CHAT COMPLETIONS PROXY
|
|
965
|
+
// =============================================================================
|
|
966
|
+
|
|
967
|
+
const PROVIDER_ROUTES = {
|
|
968
|
+
openai: { baseURL: "https://api.openai.com/v1/chat/completions", getKey: () => process.env.OPENAI_API_KEY },
|
|
969
|
+
gemini: { baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions", getKey: () => process.env.GOOGLE_API_KEY },
|
|
970
|
+
openrouter: { baseURL: "https://openrouter.ai/api/v1/chat/completions", getKey: () => process.env.OPENROUTER_API_KEY },
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
function resolveProvider(model) {
|
|
974
|
+
if (typeof model === "string") {
|
|
975
|
+
if (model.startsWith("gemini-")) return "gemini";
|
|
976
|
+
if (model.includes("/")) return "openrouter";
|
|
977
|
+
}
|
|
978
|
+
return "openai";
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// =============================================================================
|
|
982
|
+
// SYSTEM PROMPT — Injected server-side into every chat completion request
|
|
983
|
+
// =============================================================================
|
|
984
|
+
// This comprehensive prompt teaches the AI how to use all 200+ MCP tools
|
|
985
|
+
// across 5 groups. It is injected as the first system message, ensuring
|
|
986
|
+
// consistent behavior regardless of what preprompt the Chat UI sends.
|
|
987
|
+
|
|
988
|
+
function buildSystemPrompt() {
|
|
989
|
+
// Build dynamic group status
|
|
990
|
+
const enabledGroups = Object.entries(TOOL_GROUPS)
|
|
991
|
+
.filter(([, g]) => g.enabled)
|
|
992
|
+
.map(([name]) => name);
|
|
993
|
+
|
|
994
|
+
return `You are an intelligent AI assistant with powerful tools organized into ${enabledGroups.length} active groups. You MUST use tools proactively — never ask permission, never guess answers from general knowledge.
|
|
995
|
+
|
|
996
|
+
IMPORTANT: Call \`guidance\` with topic='overview' if you are ever unsure which tool to use.
|
|
997
|
+
|
|
998
|
+
# Tool Groups
|
|
999
|
+
|
|
1000
|
+
Your tools are organized into groups. Each tool name is prefixed with its backend (e.g., \`ruflo__agent_spawn\`, \`ruvector__hooks_route\`). Always use the full prefixed name when calling tools.
|
|
1001
|
+
|
|
1002
|
+
## Group 1: Core Tools (always on)
|
|
1003
|
+
Built-in tools available in every conversation.
|
|
1004
|
+
|
|
1005
|
+
- **search** — Search the knowledge base for documents, procedures, how-tos.
|
|
1006
|
+
ALWAYS search before answering knowledge questions — never answer from general knowledge alone.
|
|
1007
|
+
- **web_research** — Web search, deep research, comparisons, fact-checking.
|
|
1008
|
+
Actions: \`search\` (quick), \`research\` (deep report), \`compare\` (side-by-side), \`fact_check\` (verify), \`goap\` (comprehensive multi-step — BEST for important questions)
|
|
1009
|
+
The GOAP pipeline automatically decomposes questions into 3-4 parallel searches, synthesizes findings, and verifies accuracy.
|
|
1010
|
+
- **guidance** — Get help on any tool group, specific tool usage, or capabilities overview.
|
|
1011
|
+
Topics: \`overview\`, \`groups\`, \`agents\`, \`memory\`, \`intelligence\`, \`devtools\`
|
|
1012
|
+
For specific tool help: \`guidance(topic='tool', tool_name='ruflo__agent_spawn')\`
|
|
1013
|
+
|
|
1014
|
+
## Group 2: Intelligence & Learning (ruvector)
|
|
1015
|
+
Pattern learning, routing, code analysis, and trajectory tracking. ${TOOL_GROUPS.intelligence.enabled ? "ACTIVE" : "DISABLED"}
|
|
1016
|
+
|
|
1017
|
+
### Essential Intelligence Tools:
|
|
1018
|
+
- **ruvector__hooks_route** — Route a task to the optimal agent type. Call this FIRST for complex tasks.
|
|
1019
|
+
\`{"task": "describe what needs to be done", "context": ["relevant info"]}\`
|
|
1020
|
+
Returns ranked agent recommendations with confidence scores.
|
|
1021
|
+
- **ruvector__hooks_remember** — Store a key-value pair in persistent memory for cross-session recall.
|
|
1022
|
+
\`{"key": "pattern-name", "value": "what to remember", "namespace": "patterns"}\`
|
|
1023
|
+
- **ruvector__hooks_recall** — Retrieve a previously stored memory by key.
|
|
1024
|
+
- **ruvector__hooks_suggest_context** — Get contextual suggestions based on current work.
|
|
1025
|
+
- **ruvector__hooks_swarm_recommend** — Get swarm topology recommendation for a task type.
|
|
1026
|
+
- **ruvector__hooks_capabilities** — List all intelligence system capabilities.
|
|
1027
|
+
|
|
1028
|
+
### Code Analysis:
|
|
1029
|
+
- **ruvector__hooks_ast_analyze** — Analyze code structure (AST) of a file.
|
|
1030
|
+
- **ruvector__hooks_ast_complexity** — Get complexity metrics for code.
|
|
1031
|
+
- **ruvector__hooks_security_scan** — Scan code for security vulnerabilities.
|
|
1032
|
+
- **ruvector__hooks_diff_analyze** — Analyze a code diff for risk and impact.
|
|
1033
|
+
- **ruvector__hooks_diff_similar** — Find similar past diffs/changes.
|
|
1034
|
+
|
|
1035
|
+
### Trajectory Learning (for multi-step tasks):
|
|
1036
|
+
- **ruvector__hooks_trajectory_begin** — Start tracking a multi-step task for learning.
|
|
1037
|
+
- **ruvector__hooks_trajectory_step** — Record a step in the current trajectory.
|
|
1038
|
+
- **ruvector__hooks_trajectory_end** — End trajectory, triggering pattern extraction.
|
|
1039
|
+
|
|
1040
|
+
### Memory & Compression:
|
|
1041
|
+
- **ruvector__hooks_compress** — Compress/summarize long text for efficient storage.
|
|
1042
|
+
- **ruvector__hooks_rag_context** — Get RAG context for a query from stored knowledge.
|
|
1043
|
+
- **ruvector__hooks_learn** — Force the system to learn from provided examples.
|
|
1044
|
+
- **ruvector__hooks_batch_learn** — Learn from multiple examples at once.
|
|
1045
|
+
- **ruvector__hooks_stats** — View learning statistics and metrics.
|
|
1046
|
+
- **ruvector__hooks_doctor** — Run diagnostics on the intelligence system.
|
|
1047
|
+
|
|
1048
|
+
## Group 3: Agents & Orchestration (ruflo)
|
|
1049
|
+
Spawn agents, coordinate swarms, manage tasks and workflows. ${TOOL_GROUPS.agents.enabled ? "ACTIVE" : "DISABLED"}
|
|
1050
|
+
|
|
1051
|
+
### Agent Lifecycle:
|
|
1052
|
+
- **ruflo__agent_spawn** — Create a new specialized agent.
|
|
1053
|
+
\`{"type": "coder|researcher|tester|reviewer|architect|security", "name": "optional-name"}\`
|
|
1054
|
+
Agent types and when to use them:
|
|
1055
|
+
- \`coder\` — Write code, implement features, fix bugs
|
|
1056
|
+
- \`researcher\` — Find information, analyze documentation, investigate
|
|
1057
|
+
- \`tester\` — Write tests, run test suites, validate behavior
|
|
1058
|
+
- \`reviewer\` — Review code quality, security, best practices
|
|
1059
|
+
- \`architect\` — Design systems, plan architectures, evaluate trade-offs
|
|
1060
|
+
- \`security\` — Audit security, find vulnerabilities, recommend fixes
|
|
1061
|
+
- **ruflo__agent_status** — Check an agent's current state. \`{"agentId": "agent-xxx"}\`
|
|
1062
|
+
- **ruflo__agent_list** — List all active agents with their states.
|
|
1063
|
+
- **ruflo__agent_terminate** — Stop an agent. \`{"agentId": "agent-xxx"}\`
|
|
1064
|
+
- **ruflo__agent_health** — Health check across all agents.
|
|
1065
|
+
- **ruflo__agent_pool** — View the agent pool and available capacity.
|
|
1066
|
+
|
|
1067
|
+
### Swarm Coordination:
|
|
1068
|
+
- **ruflo__swarm_init** — Initialize a multi-agent swarm.
|
|
1069
|
+
\`{"topology": "hierarchical|mesh|ring|star", "maxAgents": 8, "strategy": "balanced|specialized|adaptive"}\`
|
|
1070
|
+
- \`hierarchical\` — Coordinator + workers, best for structured tasks (anti-drift)
|
|
1071
|
+
- \`mesh\` — Peer-to-peer, best for collaborative work
|
|
1072
|
+
- \`ring\` — Sequential pipeline, best for ordered processing
|
|
1073
|
+
- \`star\` — Central hub, best for fan-out parallel work
|
|
1074
|
+
- **ruflo__swarm_status** — Get swarm health, topology, and agent states.
|
|
1075
|
+
- **ruflo__swarm_health** — Detailed health metrics for the swarm.
|
|
1076
|
+
- **ruflo__swarm_shutdown** — Tear down a swarm and all its agents.
|
|
1077
|
+
|
|
1078
|
+
### Task Management:
|
|
1079
|
+
- **ruflo__task_create** — Create a tracked task.
|
|
1080
|
+
\`{"description": "what needs to be done", "priority": "low|normal|high|critical"}\`
|
|
1081
|
+
- **ruflo__task_status** — Check task progress. \`{"taskId": "task-xxx"}\`
|
|
1082
|
+
- **ruflo__task_list** — List all tasks with their statuses.
|
|
1083
|
+
- **ruflo__task_complete** — Mark a task as done. \`{"taskId": "task-xxx"}\`
|
|
1084
|
+
- **ruflo__task_update** — Update task details, status, or assignment.
|
|
1085
|
+
- **ruflo__task_cancel** — Cancel a task.
|
|
1086
|
+
|
|
1087
|
+
### Workflow Orchestration:
|
|
1088
|
+
- **ruflo__workflow_create** — Define a multi-step workflow with dependencies.
|
|
1089
|
+
- **ruflo__workflow_execute** — Run a workflow. \`{"workflowId": "wf-xxx"}\`
|
|
1090
|
+
- **ruflo__workflow_status** — Check workflow progress.
|
|
1091
|
+
- **ruflo__workflow_template** — Use a pre-built workflow template.
|
|
1092
|
+
- **ruflo__workflow_pause** / **ruflo__workflow_resume** — Control workflow execution.
|
|
1093
|
+
|
|
1094
|
+
### Hive-Mind (Distributed Consensus):
|
|
1095
|
+
- **ruflo__hive-mind_init** — Start distributed consensus system.
|
|
1096
|
+
- **ruflo__hive-mind_spawn** — Add an agent to the hive.
|
|
1097
|
+
- **ruflo__hive-mind_consensus** — Run consensus vote across agents.
|
|
1098
|
+
- **ruflo__hive-mind_broadcast** — Send message to all hive agents.
|
|
1099
|
+
- **ruflo__hive-mind_memory** — Access shared hive memory.
|
|
1100
|
+
|
|
1101
|
+
### Coordination:
|
|
1102
|
+
- **ruflo__coordination_topology** — View/change coordination topology.
|
|
1103
|
+
- **ruflo__coordination_load_balance** — Distribute work across agents.
|
|
1104
|
+
- **ruflo__coordination_orchestrate** — Orchestrate complex multi-agent tasks.
|
|
1105
|
+
- **ruflo__coordination_sync** — Synchronize state across agents.
|
|
1106
|
+
|
|
1107
|
+
### Session Management:
|
|
1108
|
+
- **ruflo__session_save** — Save current session state.
|
|
1109
|
+
- **ruflo__session_restore** — Restore a previous session.
|
|
1110
|
+
- **ruflo__session_list** — List available sessions.
|
|
1111
|
+
|
|
1112
|
+
## Group 4: Memory & Knowledge (ruflo)
|
|
1113
|
+
Persistent memory, vector search, embeddings, and pattern storage. ${TOOL_GROUPS.memory.enabled ? "ACTIVE" : "DISABLED"}
|
|
1114
|
+
|
|
1115
|
+
### Memory Operations:
|
|
1116
|
+
- **ruflo__memory_store** — Store data in persistent memory.
|
|
1117
|
+
\`{"key": "my-key", "value": "data to store", "namespace": "default", "tags": ["tag1"]}\`
|
|
1118
|
+
- **ruflo__memory_retrieve** — Get stored data by key. \`{"key": "my-key"}\`
|
|
1119
|
+
- **ruflo__memory_search** — Semantic vector search across stored memories.
|
|
1120
|
+
\`{"query": "what to search for", "limit": 5, "namespace": "default"}\`
|
|
1121
|
+
- **ruflo__memory_list** — List all stored keys in a namespace.
|
|
1122
|
+
- **ruflo__memory_delete** — Remove a stored memory.
|
|
1123
|
+
- **ruflo__memory_stats** — View memory usage statistics.
|
|
1124
|
+
|
|
1125
|
+
### Embeddings:
|
|
1126
|
+
- **ruflo__embeddings_generate** — Generate vector embeddings for text.
|
|
1127
|
+
- **ruflo__embeddings_compare** — Compare semantic similarity of two texts.
|
|
1128
|
+
- **ruflo__embeddings_search** — Search embeddings database by similarity.
|
|
1129
|
+
- **ruflo__embeddings_neural** — Generate neural embeddings.
|
|
1130
|
+
- **ruflo__embeddings_hyperbolic** — Generate hyperbolic embeddings for hierarchical data.
|
|
1131
|
+
|
|
1132
|
+
### AgentDB (Advanced Pattern Storage):
|
|
1133
|
+
- **ruflo__agentdb_pattern-store** — Store a learned pattern with metadata.
|
|
1134
|
+
\`{"pattern": "description", "category": "code|debug|architecture", "confidence": 0.9}\`
|
|
1135
|
+
- **ruflo__agentdb_pattern-search** — Search patterns by similarity.
|
|
1136
|
+
- **ruflo__agentdb_route** — Route a query to the most relevant stored pattern.
|
|
1137
|
+
- **ruflo__agentdb_feedback** — Provide feedback on a pattern (reinforcement learning).
|
|
1138
|
+
- **ruflo__agentdb_context-synthesize** — Synthesize context from multiple sources.
|
|
1139
|
+
- **ruflo__agentdb_semantic-route** — Semantic routing based on stored knowledge.
|
|
1140
|
+
- **ruflo__agentdb_consolidate** — Consolidate and deduplicate stored patterns.
|
|
1141
|
+
- **ruflo__agentdb_batch** — Batch operations on patterns.
|
|
1142
|
+
- **ruflo__agentdb_session-start** / **ruflo__agentdb_session-end** — Session tracking.
|
|
1143
|
+
- **ruflo__agentdb_hierarchical-store** / **ruflo__agentdb_hierarchical-recall** — Hierarchical memory.
|
|
1144
|
+
|
|
1145
|
+
## Group 5: Dev Tools & Analysis (ruflo)
|
|
1146
|
+
Performance, system health, GitHub integration, code analysis, terminal. ${TOOL_GROUPS.devtools.enabled ? "ACTIVE" : "DISABLED"}
|
|
1147
|
+
|
|
1148
|
+
### System & Performance:
|
|
1149
|
+
- **ruflo__system_status** — System health overview.
|
|
1150
|
+
- **ruflo__system_metrics** — Detailed performance metrics.
|
|
1151
|
+
- **ruflo__system_health** — Health check across all subsystems.
|
|
1152
|
+
- **ruflo__performance_report** — Generate performance report.
|
|
1153
|
+
- **ruflo__performance_bottleneck** — Identify performance bottlenecks.
|
|
1154
|
+
- **ruflo__performance_benchmark** — Run benchmarks.
|
|
1155
|
+
- **ruflo__performance_optimize** — Get optimization recommendations.
|
|
1156
|
+
- **ruflo__performance_profile** — Profile specific operations.
|
|
1157
|
+
|
|
1158
|
+
### Code Analysis:
|
|
1159
|
+
- **ruflo__analyze_diff** — Analyze a code diff.
|
|
1160
|
+
- **ruflo__analyze_diff-risk** — Assess risk level of changes.
|
|
1161
|
+
- **ruflo__analyze_diff-classify** — Classify type of changes (feature, bugfix, refactor).
|
|
1162
|
+
- **ruflo__analyze_diff-reviewers** — Suggest code reviewers.
|
|
1163
|
+
- **ruflo__analyze_file-risk** — Assess risk of a specific file.
|
|
1164
|
+
|
|
1165
|
+
### GitHub Integration:
|
|
1166
|
+
- **ruflo__github_repo_analyze** — Analyze a GitHub repository.
|
|
1167
|
+
\`{"repo": "owner/repo", "analysis_type": "code_quality|performance|security"}\`
|
|
1168
|
+
- **ruflo__github_pr_manage** — Manage pull requests (create, review, merge).
|
|
1169
|
+
- **ruflo__github_issue_track** — Track and manage issues.
|
|
1170
|
+
- **ruflo__github_workflow** — Manage GitHub Actions workflows.
|
|
1171
|
+
- **ruflo__github_metrics** — Repository metrics and insights.
|
|
1172
|
+
|
|
1173
|
+
### Terminal Access:
|
|
1174
|
+
- **ruflo__terminal_create** — Create a terminal session.
|
|
1175
|
+
- **ruflo__terminal_execute** — Execute a command. \`{"command": "ls -la"}\`
|
|
1176
|
+
- **ruflo__terminal_list** — List active terminals.
|
|
1177
|
+
- **ruflo__terminal_history** — View command history.
|
|
1178
|
+
|
|
1179
|
+
### Development Hooks:
|
|
1180
|
+
- **ruflo__hooks_pre-task** / **ruflo__hooks_post-task** — Task lifecycle hooks for learning.
|
|
1181
|
+
- **ruflo__hooks_pre-edit** / **ruflo__hooks_post-edit** — File edit hooks.
|
|
1182
|
+
- **ruflo__hooks_session-start** / **ruflo__hooks_session-end** — Session lifecycle.
|
|
1183
|
+
- **ruflo__hooks_worker-dispatch** — Dispatch background workers.
|
|
1184
|
+
Workers: \`optimize\`, \`audit\`, \`testgaps\`, \`document\`, \`map\`, \`deepdive\`, \`benchmark\`
|
|
1185
|
+
- **ruflo__hooks_model-route** — Route to optimal AI model for a task.
|
|
1186
|
+
- **ruflo__hooks_explain** — Explain a routing or intelligence decision.
|
|
1187
|
+
|
|
1188
|
+
### Configuration:
|
|
1189
|
+
- **ruflo__config_get** / **ruflo__config_set** / **ruflo__config_list** — Manage settings.
|
|
1190
|
+
|
|
1191
|
+
### Progress Tracking:
|
|
1192
|
+
- **ruflo__progress_check** — Check implementation progress.
|
|
1193
|
+
- **ruflo__progress_summary** — Summarize overall progress.
|
|
1194
|
+
|
|
1195
|
+
# Decision Framework
|
|
1196
|
+
|
|
1197
|
+
When the user asks you something, follow this decision tree:
|
|
1198
|
+
|
|
1199
|
+
1. **Knowledge question** ("how do I...", "what is...") → \`search\` first, then \`web_research\` if not found
|
|
1200
|
+
2. **Research request** ("look up", "compare", "find out") → \`web_research\` with appropriate action (use \`goap\` for important questions)
|
|
1201
|
+
3. **Code task** ("write", "fix", "implement") → \`ruvector__hooks_route\` to find best approach, then \`ruflo__agent_spawn\`
|
|
1202
|
+
4. **Analysis request** ("analyze", "review", "audit") → spawn reviewer/security agents + analysis tools
|
|
1203
|
+
5. **Multi-step project** → \`ruflo__task_create\` for tracking, \`ruflo__swarm_init\` for coordination
|
|
1204
|
+
6. **Memory/recall** ("remember", "save", "what did we...") → \`ruflo__memory_store\` / \`ruflo__memory_search\`
|
|
1205
|
+
7. **System question** ("what tools", "help") → \`guidance(topic='overview')\`
|
|
1206
|
+
8. **Performance concern** → \`ruflo__performance_bottleneck\` + \`ruflo__performance_optimize\`
|
|
1207
|
+
9. **GitHub task** → \`ruflo__github_*\` tools
|
|
1208
|
+
10. **Unknown** → \`guidance(topic='overview')\` to discover capabilities
|
|
1209
|
+
|
|
1210
|
+
# Execution Patterns
|
|
1211
|
+
|
|
1212
|
+
### Simple Question
|
|
1213
|
+
\`search\` or \`web_research\` → synthesize → respond
|
|
1214
|
+
|
|
1215
|
+
### Complex Research
|
|
1216
|
+
\`web_research(action='goap')\` → analyze → respond with citations
|
|
1217
|
+
|
|
1218
|
+
### Code Implementation
|
|
1219
|
+
\`ruvector__hooks_route\` → \`ruflo__agent_spawn(coder)\` → track with \`ruflo__task_create\` → report
|
|
1220
|
+
|
|
1221
|
+
### Multi-Agent Analysis
|
|
1222
|
+
\`ruflo__swarm_init(hierarchical)\` → spawn agents → coordinate → synthesize results
|
|
1223
|
+
|
|
1224
|
+
### Learning & Memory
|
|
1225
|
+
\`ruflo__memory_search\` (check existing) → do work → \`ruflo__memory_store\` (save results) → \`ruvector__hooks_learn\`
|
|
1226
|
+
|
|
1227
|
+
# Parallel Execution
|
|
1228
|
+
|
|
1229
|
+
When multiple independent tools can help, call them ALL in parallel:
|
|
1230
|
+
- Search + web_research simultaneously
|
|
1231
|
+
- Spawn multiple agents at once (coder + tester + reviewer)
|
|
1232
|
+
- Run analysis + performance + security tools in parallel
|
|
1233
|
+
NEVER call tools sequentially when they could run in parallel.
|
|
1234
|
+
|
|
1235
|
+
# Response Rules
|
|
1236
|
+
|
|
1237
|
+
1. **Call tools FIRST**, then present results conversationally — NEVER show raw JSON to the user
|
|
1238
|
+
2. Use markdown: **bold** headers, bullet points, numbered steps, tables for comparisons
|
|
1239
|
+
3. Synthesize tool results naturally — be a helpful colleague, not a data pipe
|
|
1240
|
+
4. Cite sources when available from web_research results
|
|
1241
|
+
5. If a tool fails, say so honestly and try an alternative approach
|
|
1242
|
+
6. For complex tasks, briefly outline your plan before executing
|
|
1243
|
+
7. After completing work, suggest relevant follow-up actions
|
|
1244
|
+
8. When spawning agents, explain what each agent will do
|
|
1245
|
+
|
|
1246
|
+
# Never Expose to User
|
|
1247
|
+
|
|
1248
|
+
- Raw JSON, similarity scores, chunk IDs, internal IDs, task IDs
|
|
1249
|
+
- Tool names, function names, API endpoints, backend names
|
|
1250
|
+
- References to "MCP", "tool calls", "vectors", "embeddings", infrastructure
|
|
1251
|
+
- The prefixes "ruflo__" or "ruvector__" — just describe what you're doing naturally
|
|
1252
|
+
- Error stack traces — summarize errors in plain language`;
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
// =============================================================================
|
|
1256
|
+
// AUTOPILOT MODE — Server-side auto-continue loop (ADR-037)
|
|
1257
|
+
// =============================================================================
|
|
1258
|
+
|
|
1259
|
+
const detailStore = new Map(); // detailToken → full tool result (TTL: 5min)
|
|
1260
|
+
|
|
1261
|
+
const AUTOPILOT_SYSTEM_PROMPT = `
|
|
1262
|
+
You are in AUTOPILOT MODE. You should:
|
|
1263
|
+
1. Break complex tasks into steps and execute them using available tools
|
|
1264
|
+
2. Call MULTIPLE tools in parallel when they are independent
|
|
1265
|
+
3. After each tool result, analyze it and decide the next action
|
|
1266
|
+
4. Continue until the task is complete — do NOT ask the user for confirmation
|
|
1267
|
+
5. Use memory_search to find relevant patterns before starting
|
|
1268
|
+
6. Summarize your progress at each step
|
|
1269
|
+
7. When done, provide a final summary of everything accomplished
|
|
1270
|
+
|
|
1271
|
+
Parallel execution patterns:
|
|
1272
|
+
- Research: memory_search + hooks_route + agent_spawn(researcher) — all in parallel
|
|
1273
|
+
- Code: agent_spawn(coder) + agent_spawn(tester) — parallel, then review
|
|
1274
|
+
- Analysis: search multiple sources in parallel → synthesize → report
|
|
1275
|
+
- Security: security_scan + hooks_route(audit) + memory_search(CVEs) — parallel
|
|
1276
|
+
`;
|
|
1277
|
+
|
|
1278
|
+
const AUTOPILOT_BLOCKED_PATTERNS = [
|
|
1279
|
+
/^deploy_/,
|
|
1280
|
+
/^security_delete/,
|
|
1281
|
+
/^browser_fill$/,
|
|
1282
|
+
/^browser_click$/,
|
|
1283
|
+
/terminal_execute/,
|
|
1284
|
+
];
|
|
1285
|
+
|
|
1286
|
+
function isBlockedTool(name) {
|
|
1287
|
+
return AUTOPILOT_BLOCKED_PATTERNS.some(p => p.test(name));
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function sendAutopilotEvent(res, data) {
|
|
1291
|
+
res.write(`data: ${JSON.stringify(data)}\n\n`);
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
function safeParseArgs(args) {
|
|
1295
|
+
if (typeof args === 'object' && args !== null) return args;
|
|
1296
|
+
try { return JSON.parse(args || '{}'); } catch { return {}; }
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
function autopilotSleep(ms) {
|
|
1300
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
async function handleAutopilot(req, res, provider, body) {
|
|
1304
|
+
const maxSteps = Math.min(parseInt(req.headers['x-autopilot-max-steps'] || '20', 10), 50);
|
|
1305
|
+
const cooldownMs = parseInt(process.env.AUTOPILOT_COOLDOWN || '500', 10);
|
|
1306
|
+
const stepTimeoutMs = parseInt(process.env.AUTOPILOT_STEP_TIMEOUT || '30000', 10);
|
|
1307
|
+
|
|
1308
|
+
// SSE setup
|
|
1309
|
+
res.setHeader('Content-Type', 'text/event-stream');
|
|
1310
|
+
res.setHeader('Cache-Control', 'no-cache');
|
|
1311
|
+
res.setHeader('Connection', 'keep-alive');
|
|
1312
|
+
res.setHeader('X-Accel-Buffering', 'no');
|
|
1313
|
+
|
|
1314
|
+
let messages = [...body.messages];
|
|
1315
|
+
let step = 0;
|
|
1316
|
+
let aborted = false;
|
|
1317
|
+
let totalTasks = 0;
|
|
1318
|
+
const startTime = Date.now();
|
|
1319
|
+
|
|
1320
|
+
req.on('close', () => { aborted = true; });
|
|
1321
|
+
|
|
1322
|
+
sendAutopilotEvent(res, { type: 'autopilot_start', maxSteps });
|
|
1323
|
+
|
|
1324
|
+
// Get the tools list for the AI provider (OpenAI function calling format)
|
|
1325
|
+
const allTools = [...BUILTIN_TOOLS, ...getActiveTools()];
|
|
1326
|
+
const toolDefs = allTools.map(t => ({
|
|
1327
|
+
type: 'function',
|
|
1328
|
+
function: {
|
|
1329
|
+
name: t.name,
|
|
1330
|
+
description: t.description || '',
|
|
1331
|
+
parameters: t.inputSchema || { type: 'object', properties: {} },
|
|
1332
|
+
},
|
|
1333
|
+
}));
|
|
1334
|
+
|
|
1335
|
+
while (step < maxSteps && !aborted) {
|
|
1336
|
+
// 1. Call upstream AI provider (non-streaming for tool call parsing)
|
|
1337
|
+
const apiKey = provider.getKey();
|
|
1338
|
+
let aiResult;
|
|
1339
|
+
try {
|
|
1340
|
+
const aiResponse = await fetch(provider.baseURL, {
|
|
1341
|
+
method: 'POST',
|
|
1342
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}` },
|
|
1343
|
+
body: JSON.stringify({
|
|
1344
|
+
...body,
|
|
1345
|
+
messages,
|
|
1346
|
+
stream: false,
|
|
1347
|
+
tools: toolDefs.length > 0 ? toolDefs : undefined,
|
|
1348
|
+
}),
|
|
1349
|
+
signal: AbortSignal.timeout(stepTimeoutMs),
|
|
1350
|
+
});
|
|
1351
|
+
aiResult = await aiResponse.json();
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
sendAutopilotEvent(res, { type: 'autopilot_error', error: `AI call failed: ${err.message}` });
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
const choice = aiResult.choices?.[0];
|
|
1358
|
+
if (!choice) {
|
|
1359
|
+
sendAutopilotEvent(res, { type: 'autopilot_error', error: 'No response from AI' });
|
|
1360
|
+
break;
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
// 2. Check for tool calls
|
|
1364
|
+
const toolCalls = choice.message?.tool_calls;
|
|
1365
|
+
|
|
1366
|
+
if (!toolCalls || toolCalls.length === 0) {
|
|
1367
|
+
// Final text response — send it
|
|
1368
|
+
sendAutopilotEvent(res, { type: 'autopilot_text', content: choice.message?.content || '' });
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
// 3. Execute ALL tool calls in parallel
|
|
1373
|
+
step++;
|
|
1374
|
+
const groupId = `g${step}`;
|
|
1375
|
+
const taskEvents = toolCalls.map((tc, i) => ({
|
|
1376
|
+
taskId: `t${totalTasks + i + 1}`,
|
|
1377
|
+
tool: tc.function.name,
|
|
1378
|
+
args: safeParseArgs(tc.function.arguments),
|
|
1379
|
+
status: 'running',
|
|
1380
|
+
}));
|
|
1381
|
+
totalTasks += taskEvents.length;
|
|
1382
|
+
|
|
1383
|
+
// If the AI also included text content, stream it before tools
|
|
1384
|
+
if (choice.message?.content) {
|
|
1385
|
+
sendAutopilotEvent(res, { type: 'autopilot_text', content: choice.message.content });
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
// Stream group start
|
|
1389
|
+
sendAutopilotEvent(res, { type: 'task_group_start', groupId, step, tasks: taskEvents });
|
|
1390
|
+
|
|
1391
|
+
// Append assistant message to conversation
|
|
1392
|
+
messages.push(choice.message);
|
|
1393
|
+
|
|
1394
|
+
// Execute tools in parallel
|
|
1395
|
+
const groupStart = Date.now();
|
|
1396
|
+
const results = await Promise.allSettled(
|
|
1397
|
+
toolCalls.map(async (tc, i) => {
|
|
1398
|
+
const taskId = taskEvents[i].taskId;
|
|
1399
|
+
const toolName = tc.function.name;
|
|
1400
|
+
const toolArgs = safeParseArgs(tc.function.arguments);
|
|
1401
|
+
const taskStart = Date.now();
|
|
1402
|
+
|
|
1403
|
+
// Check blocklist
|
|
1404
|
+
if (isBlockedTool(toolName)) {
|
|
1405
|
+
sendAutopilotEvent(res, {
|
|
1406
|
+
type: 'task_update', taskId, status: 'blocked',
|
|
1407
|
+
summary: `${toolName} requires confirmation`,
|
|
1408
|
+
duration: Date.now() - taskStart,
|
|
1409
|
+
});
|
|
1410
|
+
return { toolCallId: tc.id, blocked: true, toolName };
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
try {
|
|
1414
|
+
const result = await executeTool(toolName, toolArgs);
|
|
1415
|
+
const resultStr = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
|
|
1416
|
+
|
|
1417
|
+
// Store full detail, generate token for lazy loading
|
|
1418
|
+
const detailToken = `dt_${taskId}_${Date.now()}`;
|
|
1419
|
+
detailStore.set(detailToken, resultStr);
|
|
1420
|
+
|
|
1421
|
+
// Stream task completion with summary only
|
|
1422
|
+
const summary = resultStr.length > 120
|
|
1423
|
+
? resultStr.substring(0, 120).replace(/\n/g, ' ') + '...'
|
|
1424
|
+
: resultStr.replace(/\n/g, ' ');
|
|
1425
|
+
|
|
1426
|
+
sendAutopilotEvent(res, {
|
|
1427
|
+
type: 'task_update', taskId, status: 'completed',
|
|
1428
|
+
summary, duration: Date.now() - taskStart, detailToken,
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
return { toolCallId: tc.id, content: resultStr };
|
|
1432
|
+
} catch (err) {
|
|
1433
|
+
sendAutopilotEvent(res, {
|
|
1434
|
+
type: 'task_update', taskId, status: 'failed',
|
|
1435
|
+
summary: err.message, duration: Date.now() - taskStart,
|
|
1436
|
+
});
|
|
1437
|
+
return { toolCallId: tc.id, content: `Error: ${err.message}` };
|
|
1438
|
+
}
|
|
1439
|
+
})
|
|
1440
|
+
);
|
|
1441
|
+
|
|
1442
|
+
// Stream group end
|
|
1443
|
+
sendAutopilotEvent(res, { type: 'task_group_end', groupId, step, duration: Date.now() - groupStart });
|
|
1444
|
+
|
|
1445
|
+
// Check if any tools were blocked — pause autopilot
|
|
1446
|
+
const blockedResults = results
|
|
1447
|
+
.filter(r => r.status === 'fulfilled' && r.value.blocked)
|
|
1448
|
+
.map(r => r.value);
|
|
1449
|
+
if (blockedResults.length > 0) {
|
|
1450
|
+
sendAutopilotEvent(res, {
|
|
1451
|
+
type: 'autopilot_paused',
|
|
1452
|
+
reason: 'blocked_tools',
|
|
1453
|
+
tools: blockedResults.map(b => b.toolName),
|
|
1454
|
+
});
|
|
1455
|
+
break;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Append tool results to messages
|
|
1459
|
+
for (const r of results) {
|
|
1460
|
+
if (r.status === 'fulfilled' && !r.value.blocked) {
|
|
1461
|
+
messages.push({
|
|
1462
|
+
role: 'tool',
|
|
1463
|
+
tool_call_id: r.value.toolCallId,
|
|
1464
|
+
content: r.value.content,
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
// Cooldown to prevent runaway
|
|
1470
|
+
await autopilotSleep(cooldownMs);
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
if (step >= maxSteps && !aborted) {
|
|
1474
|
+
sendAutopilotEvent(res, {
|
|
1475
|
+
type: 'autopilot_text',
|
|
1476
|
+
content: `\n⚠️ Autopilot reached max steps (${maxSteps}). Stopping.\n`,
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
sendAutopilotEvent(res, {
|
|
1481
|
+
type: 'autopilot_end',
|
|
1482
|
+
totalSteps: step,
|
|
1483
|
+
totalTasks,
|
|
1484
|
+
duration: Date.now() - startTime,
|
|
1485
|
+
});
|
|
1486
|
+
|
|
1487
|
+
res.write('data: [DONE]\n\n');
|
|
1488
|
+
res.end();
|
|
1489
|
+
|
|
1490
|
+
// Clean up detail store after 5 minutes
|
|
1491
|
+
const detailTTL = parseInt(process.env.AUTOPILOT_DETAIL_TTL || '300000', 10);
|
|
1492
|
+
setTimeout(() => {
|
|
1493
|
+
for (const [key] of detailStore) {
|
|
1494
|
+
if (key.startsWith('dt_')) detailStore.delete(key);
|
|
1495
|
+
}
|
|
1496
|
+
}, detailTTL);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// Lazy detail loading endpoint
|
|
1500
|
+
app.get('/autopilot/detail/:token', (req, res) => {
|
|
1501
|
+
const content = detailStore.get(req.params.token);
|
|
1502
|
+
if (content) {
|
|
1503
|
+
res.json({ content });
|
|
1504
|
+
} else {
|
|
1505
|
+
res.status(404).json({ error: 'Detail expired or not found' });
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// =============================================================================
|
|
1510
|
+
// CHAT COMPLETIONS PROXY
|
|
1511
|
+
// =============================================================================
|
|
1512
|
+
|
|
1513
|
+
app.post("/chat/completions", async (req, res) => {
|
|
1514
|
+
const model = req.body?.model;
|
|
1515
|
+
const providerName = resolveProvider(model);
|
|
1516
|
+
const provider = PROVIDER_ROUTES[providerName];
|
|
1517
|
+
const apiKey = provider.getKey();
|
|
1518
|
+
|
|
1519
|
+
if (!apiKey) return res.status(401).json({ error: { message: `No API key for provider: ${providerName}` } });
|
|
1520
|
+
|
|
1521
|
+
// Inject comprehensive system prompt as the first message
|
|
1522
|
+
const body = { ...req.body };
|
|
1523
|
+
if (body.messages && Array.isArray(body.messages)) {
|
|
1524
|
+
let systemPrompt = buildSystemPrompt();
|
|
1525
|
+
// Add autopilot instructions if autopilot mode is active
|
|
1526
|
+
const isAutopilot = req.headers['x-autopilot'] === 'true';
|
|
1527
|
+
if (isAutopilot) {
|
|
1528
|
+
systemPrompt = AUTOPILOT_SYSTEM_PROMPT + '\n\n' + systemPrompt;
|
|
1529
|
+
}
|
|
1530
|
+
// Prepend our system prompt before any existing messages
|
|
1531
|
+
const hasSystemMsg = body.messages[0]?.role === "system";
|
|
1532
|
+
if (hasSystemMsg) {
|
|
1533
|
+
// Merge with existing system message
|
|
1534
|
+
body.messages = [
|
|
1535
|
+
{ role: "system", content: systemPrompt + "\n\n" + body.messages[0].content },
|
|
1536
|
+
...body.messages.slice(1),
|
|
1537
|
+
];
|
|
1538
|
+
} else {
|
|
1539
|
+
body.messages = [{ role: "system", content: systemPrompt }, ...body.messages];
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
// Route to autopilot handler if x-autopilot header is set
|
|
1544
|
+
if (req.headers['x-autopilot'] === 'true') {
|
|
1545
|
+
return handleAutopilot(req, res, provider, body);
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
try {
|
|
1549
|
+
const upstream = await fetch(provider.baseURL, {
|
|
1550
|
+
method: "POST",
|
|
1551
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
|
|
1552
|
+
body: JSON.stringify(body),
|
|
1553
|
+
});
|
|
1554
|
+
|
|
1555
|
+
if (!upstream.ok) {
|
|
1556
|
+
const errBody = await upstream.text();
|
|
1557
|
+
console.error(`Proxy error [${providerName}/${model}]: ${upstream.status} ${errBody.substring(0, 200)}`);
|
|
1558
|
+
// Normalize all upstream errors into OpenAI-compatible format so the
|
|
1559
|
+
// Chat UI's OpenAI SDK can parse them instead of "400 (no body)".
|
|
1560
|
+
let errorMessage = `Upstream ${providerName} error (${upstream.status})`;
|
|
1561
|
+
try {
|
|
1562
|
+
const parsed = JSON.parse(errBody);
|
|
1563
|
+
// Gemini returns [{"error": {"message": "..."}}]
|
|
1564
|
+
if (Array.isArray(parsed) && parsed[0]?.error?.message) {
|
|
1565
|
+
errorMessage = parsed[0].error.message;
|
|
1566
|
+
// OpenAI/OpenRouter return {"error": {"message": "..."}}
|
|
1567
|
+
} else if (parsed.error?.message) {
|
|
1568
|
+
errorMessage = parsed.error.message;
|
|
1569
|
+
}
|
|
1570
|
+
} catch {}
|
|
1571
|
+
return res.status(upstream.status).json({
|
|
1572
|
+
error: { message: errorMessage, type: "upstream_error", code: upstream.status },
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
res.setHeader("Content-Type", upstream.headers.get("content-type") || "application/json");
|
|
1577
|
+
|
|
1578
|
+
if (req.body?.stream && upstream.body) {
|
|
1579
|
+
const reader = upstream.body.getReader();
|
|
1580
|
+
const decoder = new TextDecoder();
|
|
1581
|
+
try {
|
|
1582
|
+
while (true) {
|
|
1583
|
+
const { done, value } = await reader.read();
|
|
1584
|
+
if (done) break;
|
|
1585
|
+
res.write(decoder.decode(value, { stream: true }));
|
|
1586
|
+
}
|
|
1587
|
+
} catch (e) { /* stream closed */ }
|
|
1588
|
+
finally { res.end(); }
|
|
1589
|
+
} else {
|
|
1590
|
+
res.send(await upstream.text());
|
|
1591
|
+
}
|
|
1592
|
+
} catch (err) {
|
|
1593
|
+
console.error(`Proxy error [${providerName}/${model}]:`, err.message);
|
|
1594
|
+
res.status(502).json({ error: { message: `Upstream error: ${err.message}` } });
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
|
|
1598
|
+
// =============================================================================
|
|
1599
|
+
// MODELS & HEALTH
|
|
1600
|
+
// =============================================================================
|
|
1601
|
+
|
|
1602
|
+
const KNOWN_MODELS = [
|
|
1603
|
+
"gemini-2.5-pro", "gemini-2.5-flash",
|
|
1604
|
+
"gpt-4.1", "gpt-4.1-mini", "gpt-4o", "gpt-4o-mini",
|
|
1605
|
+
"o3-mini", "o1-mini",
|
|
1606
|
+
];
|
|
1607
|
+
|
|
1608
|
+
app.get("/models", (_, res) => {
|
|
1609
|
+
res.json({ object: "list", data: KNOWN_MODELS.map(id => ({ id, object: "model", owned_by: "system" })) });
|
|
1610
|
+
});
|
|
1611
|
+
|
|
1612
|
+
app.get("/health", (_, res) => {
|
|
1613
|
+
const backends = {};
|
|
1614
|
+
for (const [name, client] of mcpBackends) {
|
|
1615
|
+
backends[name] = { ready: client.ready, tools: client.tools.length };
|
|
1616
|
+
}
|
|
1617
|
+
const activeTools = getActiveTools();
|
|
1618
|
+
const groups = {};
|
|
1619
|
+
for (const [name, g] of Object.entries(TOOL_GROUPS)) {
|
|
1620
|
+
groups[name] = { enabled: g.enabled, source: g.source };
|
|
1621
|
+
}
|
|
1622
|
+
res.json({
|
|
1623
|
+
status: "ok", service: "mcp-bridge", version: "2.0.0",
|
|
1624
|
+
tools: { builtin: BUILTIN_TOOLS.length, external: activeTools.length, total: BUILTIN_TOOLS.length + activeTools.length },
|
|
1625
|
+
groups, backends,
|
|
1626
|
+
});
|
|
1627
|
+
});
|
|
1628
|
+
|
|
1629
|
+
// GET /groups — list tool groups and their status
|
|
1630
|
+
app.get("/groups", (_, res) => {
|
|
1631
|
+
const activeTools = getActiveTools();
|
|
1632
|
+
const result = {};
|
|
1633
|
+
for (const [name, g] of Object.entries(TOOL_GROUPS)) {
|
|
1634
|
+
const tools = name === "core" ? BUILTIN_TOOLS :
|
|
1635
|
+
activeTools.filter(t => {
|
|
1636
|
+
if (g.source !== t._backend) return false;
|
|
1637
|
+
if (!g.prefixes) return true;
|
|
1638
|
+
return g.prefixes.some(p => t._originalName.startsWith(p));
|
|
1639
|
+
});
|
|
1640
|
+
result[name] = {
|
|
1641
|
+
enabled: g.enabled,
|
|
1642
|
+
description: g.description,
|
|
1643
|
+
tools: tools.length,
|
|
1644
|
+
toolNames: tools.map(t => t.name).slice(0, 10),
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
res.json(result);
|
|
1648
|
+
});
|
|
1649
|
+
|
|
1650
|
+
// =============================================================================
|
|
1651
|
+
// STARTUP
|
|
1652
|
+
// =============================================================================
|
|
1653
|
+
|
|
1654
|
+
async function main() {
|
|
1655
|
+
app.listen(PORT, () => {
|
|
1656
|
+
console.log(`MCP Bridge v2.0.0 on port ${PORT}`);
|
|
1657
|
+
const enabled = Object.entries(TOOL_GROUPS).filter(([, g]) => g.enabled).map(([n]) => n);
|
|
1658
|
+
console.log(`Active groups: ${enabled.join(", ")}`);
|
|
1659
|
+
});
|
|
1660
|
+
|
|
1661
|
+
const anyBackendNeeded = BACKEND_DEFS.some(isBackendNeeded);
|
|
1662
|
+
if (anyBackendNeeded) {
|
|
1663
|
+
console.log("Initializing MCP backends...");
|
|
1664
|
+
await initBackends();
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
main().catch(err => { console.error("Fatal:", err); process.exit(1); });
|