@aigentic/ruflo 3.7.0-alpha.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +410 -0
- package/bin/ruflo.js +57 -0
- package/package.json +98 -0
- 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 +17 -0
- package/src/ruvocal/.eslintignore +13 -0
- package/src/ruvocal/.eslintrc.cjs +45 -0
- package/src/ruvocal/.gcloudignore +18 -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/CLAUDE.md +126 -0
- package/src/ruvocal/Dockerfile +96 -0
- package/src/ruvocal/LICENSE +203 -0
- package/src/ruvocal/PRIVACY.md +41 -0
- package/src/ruvocal/README.md +164 -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/cloudbuild.yaml +68 -0
- package/src/ruvocal/config/branding.env.example +19 -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/Dockerfile +45 -0
- package/src/ruvocal/mcp-bridge/cloudbuild.yaml +49 -0
- package/src/ruvocal/mcp-bridge/index.js +1878 -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/FoundationBackground.svelte +242 -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 +313 -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/RufloHelpModal.svelte +411 -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 +1057 -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/components/wasm/GalleryPanel.svelte +357 -0
- package/src/ruvocal/src/lib/constants/mcpExamples.ts +114 -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 +133 -0
- package/src/ruvocal/src/lib/constants/rvagentPresets.ts +206 -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.spec.ts +175 -0
- package/src/ruvocal/src/lib/server/mcp/clientPool.ts +0 -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 +96 -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 +831 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/toolInvocation.ts +349 -0
- package/src/ruvocal/src/lib/server/textGeneration/mcp/wasmTools.test.ts +633 -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 +28 -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 +77 -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 +534 -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/stores/wasmMcp.ts +472 -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 +93 -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 +77 -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/wasm/idb.ts +438 -0
- package/src/ruvocal/src/lib/wasm/index.ts +1213 -0
- package/src/ruvocal/src/lib/wasm/tests/wasm-capabilities.test.ts +565 -0
- package/src/ruvocal/src/lib/wasm/wasm.worker.ts +332 -0
- package/src/ruvocal/src/lib/wasm/workerClient.ts +166 -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 +110 -0
- package/src/ruvocal/src/routes/conversation/+server.ts +115 -0
- package/src/ruvocal/src/routes/conversation/[id]/+page.svelte +586 -0
- package/src/ruvocal/src/routes/conversation/[id]/+page.ts +60 -0
- package/src/ruvocal/src/routes/conversation/[id]/+server.ts +740 -0
- package/src/ruvocal/src/routes/conversation/[id]/message/[messageId]/prompt/+server.ts +66 -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 +59 -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/static/wasm/rvagent_wasm.js +1539 -0
- package/src/ruvocal/static/wasm/rvagent_wasm_bg.wasm +0 -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,23 @@
|
|
|
1
|
+
import { config } from "$lib/server/config";
|
|
2
|
+
import { logger } from "$lib/server/logger";
|
|
3
|
+
|
|
4
|
+
export async function sendSlack(text: string) {
|
|
5
|
+
if (!config.WEBHOOK_URL_REPORT_ASSISTANT) {
|
|
6
|
+
logger.warn("WEBHOOK_URL_REPORT_ASSISTANT is not set, tried to send a slack message.");
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const res = await fetch(config.WEBHOOK_URL_REPORT_ASSISTANT, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-type": "application/json",
|
|
14
|
+
},
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
text,
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
logger.error(`Webhook message failed. ${res.statusText} ${res.text}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { config } from "$lib/server/config";
|
|
2
|
+
import {
|
|
3
|
+
MessageReasoningUpdateType,
|
|
4
|
+
MessageUpdateType,
|
|
5
|
+
type MessageUpdate,
|
|
6
|
+
} from "$lib/types/MessageUpdate";
|
|
7
|
+
import { AbortedGenerations } from "../abortedGenerations";
|
|
8
|
+
import type { TextGenerationContext } from "./types";
|
|
9
|
+
import type { EndpointMessage } from "../endpoints/endpoints";
|
|
10
|
+
import { generateFromDefaultEndpoint } from "../generateFromDefaultEndpoint";
|
|
11
|
+
import { generateSummaryOfReasoning } from "./reasoning";
|
|
12
|
+
import { logger } from "../logger";
|
|
13
|
+
|
|
14
|
+
type GenerateContext = Omit<TextGenerationContext, "messages"> & { messages: EndpointMessage[] };
|
|
15
|
+
|
|
16
|
+
export async function* generate(
|
|
17
|
+
{
|
|
18
|
+
model,
|
|
19
|
+
endpoint,
|
|
20
|
+
conv,
|
|
21
|
+
messages,
|
|
22
|
+
assistant,
|
|
23
|
+
promptedAt,
|
|
24
|
+
forceMultimodal,
|
|
25
|
+
provider,
|
|
26
|
+
locals,
|
|
27
|
+
abortController,
|
|
28
|
+
}: GenerateContext,
|
|
29
|
+
preprompt?: string
|
|
30
|
+
): AsyncIterable<MessageUpdate> {
|
|
31
|
+
// Reasoning mode support
|
|
32
|
+
let reasoning = false;
|
|
33
|
+
let reasoningBuffer = "";
|
|
34
|
+
let lastReasoningUpdate = new Date();
|
|
35
|
+
let status = "";
|
|
36
|
+
const startTime = new Date();
|
|
37
|
+
const modelReasoning = Reflect.get(model, "reasoning") as
|
|
38
|
+
| { type: string; beginToken?: string; endToken?: string; regex?: string }
|
|
39
|
+
| undefined;
|
|
40
|
+
if (
|
|
41
|
+
modelReasoning &&
|
|
42
|
+
(modelReasoning.type === "regex" ||
|
|
43
|
+
modelReasoning.type === "summarize" ||
|
|
44
|
+
(modelReasoning.type === "tokens" && modelReasoning.beginToken === ""))
|
|
45
|
+
) {
|
|
46
|
+
// Starts in reasoning mode and we extract the answer from the reasoning
|
|
47
|
+
reasoning = true;
|
|
48
|
+
yield {
|
|
49
|
+
type: MessageUpdateType.Reasoning,
|
|
50
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
51
|
+
status: "Started reasoning...",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const stream = await endpoint({
|
|
56
|
+
messages,
|
|
57
|
+
preprompt,
|
|
58
|
+
generateSettings: assistant?.generateSettings,
|
|
59
|
+
// Allow user-level override to force multimodal
|
|
60
|
+
isMultimodal: (forceMultimodal ?? false) || model.multimodal,
|
|
61
|
+
conversationId: conv._id,
|
|
62
|
+
locals,
|
|
63
|
+
abortSignal: abortController.signal,
|
|
64
|
+
provider,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
for await (const output of stream) {
|
|
68
|
+
// Check if this output contains router metadata. Emit if either:
|
|
69
|
+
// 1) route+model are present (router models), or
|
|
70
|
+
// 2) provider-only is present (non-router models exposing x-inference-provider)
|
|
71
|
+
if ("routerMetadata" in output && output.routerMetadata) {
|
|
72
|
+
const hasRouteModel = Boolean(output.routerMetadata.route && output.routerMetadata.model);
|
|
73
|
+
const hasProviderOnly = Boolean(output.routerMetadata.provider);
|
|
74
|
+
if (hasRouteModel || hasProviderOnly) {
|
|
75
|
+
yield {
|
|
76
|
+
type: MessageUpdateType.RouterMetadata,
|
|
77
|
+
route: output.routerMetadata.route || "",
|
|
78
|
+
model: output.routerMetadata.model || "",
|
|
79
|
+
provider:
|
|
80
|
+
(output.routerMetadata
|
|
81
|
+
.provider as unknown as import("@huggingface/inference").InferenceProvider) ||
|
|
82
|
+
undefined,
|
|
83
|
+
};
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// text generation completed
|
|
88
|
+
if (output.generated_text) {
|
|
89
|
+
// If an abort happened just before final output, stop here and let
|
|
90
|
+
// the caller emit an interrupted final answer with partial text.
|
|
91
|
+
const abortTime = AbortedGenerations.getInstance().getAbortTime(conv._id.toString());
|
|
92
|
+
if (abortController.signal.aborted || (abortTime && abortTime > promptedAt)) {
|
|
93
|
+
if (!abortController.signal.aborted) {
|
|
94
|
+
abortController.abort();
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
let interrupted =
|
|
100
|
+
!output.token.special && !model.parameters.stop?.includes(output.token.text);
|
|
101
|
+
|
|
102
|
+
let text = output.generated_text.trimEnd();
|
|
103
|
+
for (const stopToken of model.parameters.stop ?? []) {
|
|
104
|
+
if (!text.endsWith(stopToken)) continue;
|
|
105
|
+
|
|
106
|
+
interrupted = false;
|
|
107
|
+
text = text.slice(0, text.length - stopToken.length);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let finalAnswer = text;
|
|
111
|
+
if (modelReasoning && modelReasoning.type === "regex" && modelReasoning.regex) {
|
|
112
|
+
const regex = new RegExp(modelReasoning.regex);
|
|
113
|
+
finalAnswer = regex.exec(reasoningBuffer)?.[1] ?? text;
|
|
114
|
+
} else if (modelReasoning && modelReasoning.type === "summarize") {
|
|
115
|
+
yield {
|
|
116
|
+
type: MessageUpdateType.Reasoning,
|
|
117
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
118
|
+
status: "Summarizing reasoning...",
|
|
119
|
+
};
|
|
120
|
+
try {
|
|
121
|
+
const summary = yield* generateFromDefaultEndpoint({
|
|
122
|
+
messages: [
|
|
123
|
+
{
|
|
124
|
+
from: "user",
|
|
125
|
+
content: `Question: ${messages[messages.length - 1].content}\n\nReasoning: ${reasoningBuffer}`,
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
preprompt: `Your task is to summarize concisely all your reasoning steps and then give the final answer. Keep it short, one short paragraph at most. If the reasoning steps explicitly include a code solution, make sure to include it in your answer.`,
|
|
129
|
+
modelId: Reflect.get(model, "id") as string | undefined,
|
|
130
|
+
locals,
|
|
131
|
+
});
|
|
132
|
+
finalAnswer = summary;
|
|
133
|
+
yield {
|
|
134
|
+
type: MessageUpdateType.Reasoning,
|
|
135
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
136
|
+
status: `Done in ${Math.round((new Date().getTime() - startTime.getTime()) / 1000)}s.`,
|
|
137
|
+
};
|
|
138
|
+
} catch (e) {
|
|
139
|
+
finalAnswer = text;
|
|
140
|
+
logger.error(e, "Error generating summary of reasoning");
|
|
141
|
+
}
|
|
142
|
+
} else if (modelReasoning && modelReasoning.type === "tokens") {
|
|
143
|
+
// Remove the reasoning segment from final answer to avoid duplication
|
|
144
|
+
const beginIndex = modelReasoning.beginToken
|
|
145
|
+
? reasoningBuffer.indexOf(modelReasoning.beginToken)
|
|
146
|
+
: 0;
|
|
147
|
+
const endIndex = modelReasoning.endToken
|
|
148
|
+
? reasoningBuffer.lastIndexOf(modelReasoning.endToken)
|
|
149
|
+
: -1;
|
|
150
|
+
|
|
151
|
+
if (beginIndex !== -1 && endIndex !== -1 && modelReasoning.endToken) {
|
|
152
|
+
finalAnswer =
|
|
153
|
+
text.slice(0, beginIndex) + text.slice(endIndex + modelReasoning.endToken.length);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
yield { type: MessageUpdateType.FinalAnswer, text: finalAnswer, interrupted };
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (modelReasoning && modelReasoning.type === "tokens") {
|
|
162
|
+
if (output.token.text === modelReasoning.beginToken) {
|
|
163
|
+
reasoning = true;
|
|
164
|
+
reasoningBuffer += output.token.text;
|
|
165
|
+
continue;
|
|
166
|
+
} else if (modelReasoning.endToken && output.token.text === modelReasoning.endToken) {
|
|
167
|
+
reasoning = false;
|
|
168
|
+
reasoningBuffer += output.token.text;
|
|
169
|
+
yield {
|
|
170
|
+
type: MessageUpdateType.Reasoning,
|
|
171
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
172
|
+
status: `Done in ${Math.round((new Date().getTime() - startTime.getTime()) / 1000)}s.`,
|
|
173
|
+
};
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// ignore special tokens
|
|
179
|
+
if (output.token.special) continue;
|
|
180
|
+
|
|
181
|
+
// pass down normal token
|
|
182
|
+
if (reasoning) {
|
|
183
|
+
reasoningBuffer += output.token.text;
|
|
184
|
+
|
|
185
|
+
if (modelReasoning && modelReasoning.type === "tokens" && modelReasoning.endToken) {
|
|
186
|
+
if (reasoningBuffer.lastIndexOf(modelReasoning.endToken) !== -1) {
|
|
187
|
+
const endTokenIndex = reasoningBuffer.lastIndexOf(modelReasoning.endToken);
|
|
188
|
+
const textBuffer = reasoningBuffer.slice(endTokenIndex + modelReasoning.endToken.length);
|
|
189
|
+
reasoningBuffer = reasoningBuffer.slice(
|
|
190
|
+
0,
|
|
191
|
+
endTokenIndex + modelReasoning.endToken.length + 1
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
yield {
|
|
195
|
+
type: MessageUpdateType.Reasoning,
|
|
196
|
+
subtype: MessageReasoningUpdateType.Stream,
|
|
197
|
+
token: output.token.text,
|
|
198
|
+
};
|
|
199
|
+
yield { type: MessageUpdateType.Stream, token: textBuffer };
|
|
200
|
+
yield {
|
|
201
|
+
type: MessageUpdateType.Reasoning,
|
|
202
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
203
|
+
status: `Done in ${Math.round((new Date().getTime() - startTime.getTime()) / 1000)}s.`,
|
|
204
|
+
};
|
|
205
|
+
reasoning = false;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// yield status update if it has changed
|
|
211
|
+
if (status !== "") {
|
|
212
|
+
yield {
|
|
213
|
+
type: MessageUpdateType.Reasoning,
|
|
214
|
+
subtype: MessageReasoningUpdateType.Status,
|
|
215
|
+
status,
|
|
216
|
+
};
|
|
217
|
+
status = "";
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// create a new status every ~4s (optional)
|
|
221
|
+
if (
|
|
222
|
+
Reflect.get(config, "REASONING_SUMMARY") === "true" &&
|
|
223
|
+
new Date().getTime() - lastReasoningUpdate.getTime() > 4000
|
|
224
|
+
) {
|
|
225
|
+
lastReasoningUpdate = new Date();
|
|
226
|
+
try {
|
|
227
|
+
generateSummaryOfReasoning(reasoningBuffer, model.id, locals).then((summary) => {
|
|
228
|
+
status = summary;
|
|
229
|
+
});
|
|
230
|
+
} catch (e) {
|
|
231
|
+
logger.error(e, "Error generating summary of reasoning");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
yield {
|
|
236
|
+
type: MessageUpdateType.Reasoning,
|
|
237
|
+
subtype: MessageReasoningUpdateType.Stream,
|
|
238
|
+
token: output.token.text,
|
|
239
|
+
};
|
|
240
|
+
} else {
|
|
241
|
+
yield { type: MessageUpdateType.Stream, token: output.token.text };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// abort check
|
|
245
|
+
const date = AbortedGenerations.getInstance().getAbortTime(conv._id.toString());
|
|
246
|
+
|
|
247
|
+
if (date && date > promptedAt) {
|
|
248
|
+
logger.info(`Aborting generation for conversation ${conv._id}`);
|
|
249
|
+
if (!abortController.signal.aborted) {
|
|
250
|
+
abortController.abort();
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// no output check
|
|
256
|
+
if (!output) break;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { preprocessMessages } from "../endpoints/preprocessMessages";
|
|
2
|
+
|
|
3
|
+
import { generateTitleForConversation } from "./title";
|
|
4
|
+
import {
|
|
5
|
+
type MessageUpdate,
|
|
6
|
+
MessageUpdateType,
|
|
7
|
+
MessageUpdateStatus,
|
|
8
|
+
} from "$lib/types/MessageUpdate";
|
|
9
|
+
import { generate } from "./generate";
|
|
10
|
+
import { runMcpFlow } from "./mcp/runMcpFlow";
|
|
11
|
+
import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
|
|
12
|
+
import type { TextGenerationContext } from "./types";
|
|
13
|
+
|
|
14
|
+
async function* keepAlive(done: AbortSignal): AsyncGenerator<MessageUpdate, undefined, undefined> {
|
|
15
|
+
while (!done.aborted) {
|
|
16
|
+
yield {
|
|
17
|
+
type: MessageUpdateType.Status,
|
|
18
|
+
status: MessageUpdateStatus.KeepAlive,
|
|
19
|
+
};
|
|
20
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function* textGeneration(ctx: TextGenerationContext) {
|
|
25
|
+
const done = new AbortController();
|
|
26
|
+
|
|
27
|
+
const titleGen = generateTitleForConversation(ctx.conv, ctx.locals);
|
|
28
|
+
const textGen = textGenerationWithoutTitle(ctx, done);
|
|
29
|
+
const keepAliveGen = keepAlive(done.signal);
|
|
30
|
+
|
|
31
|
+
// keep alive until textGen is done
|
|
32
|
+
|
|
33
|
+
yield* mergeAsyncGenerators([titleGen, textGen, keepAliveGen]);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function* textGenerationWithoutTitle(
|
|
37
|
+
ctx: TextGenerationContext,
|
|
38
|
+
done: AbortController
|
|
39
|
+
): AsyncGenerator<MessageUpdate, undefined, undefined> {
|
|
40
|
+
yield {
|
|
41
|
+
type: MessageUpdateType.Status,
|
|
42
|
+
status: MessageUpdateStatus.Started,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const { conv, messages } = ctx;
|
|
46
|
+
const convId = conv._id;
|
|
47
|
+
|
|
48
|
+
const preprompt = conv.preprompt;
|
|
49
|
+
|
|
50
|
+
const processedMessages = await preprocessMessages(messages, convId);
|
|
51
|
+
|
|
52
|
+
// Try MCP tool flow first; fall back to default generation if not selected/available
|
|
53
|
+
try {
|
|
54
|
+
const mcpGen = runMcpFlow({
|
|
55
|
+
model: ctx.model,
|
|
56
|
+
conv,
|
|
57
|
+
messages: processedMessages,
|
|
58
|
+
assistant: ctx.assistant,
|
|
59
|
+
forceMultimodal: ctx.forceMultimodal,
|
|
60
|
+
forceTools: ctx.forceTools,
|
|
61
|
+
provider: ctx.provider,
|
|
62
|
+
locals: ctx.locals,
|
|
63
|
+
preprompt,
|
|
64
|
+
abortSignal: ctx.abortController.signal,
|
|
65
|
+
abortController: ctx.abortController,
|
|
66
|
+
promptedAt: ctx.promptedAt,
|
|
67
|
+
autopilot: ctx.autopilot,
|
|
68
|
+
autopilotMaxSteps: ctx.autopilotMaxSteps,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let step = await mcpGen.next();
|
|
72
|
+
while (!step.done) {
|
|
73
|
+
yield step.value;
|
|
74
|
+
step = await mcpGen.next();
|
|
75
|
+
}
|
|
76
|
+
const mcpResult = step.value;
|
|
77
|
+
if (mcpResult === "not_applicable") {
|
|
78
|
+
// fallback to normal text generation
|
|
79
|
+
yield* generate({ ...ctx, messages: processedMessages }, preprompt);
|
|
80
|
+
}
|
|
81
|
+
// If mcpResult is "completed" or "aborted", don't fall back
|
|
82
|
+
} catch (err) {
|
|
83
|
+
// Don't fall back on abort errors - user intentionally stopped
|
|
84
|
+
const isAbort =
|
|
85
|
+
ctx.abortController.signal.aborted ||
|
|
86
|
+
(err instanceof Error &&
|
|
87
|
+
(err.name === "AbortError" ||
|
|
88
|
+
err.name === "APIUserAbortError" ||
|
|
89
|
+
err.message.includes("Request was aborted")));
|
|
90
|
+
if (!isAbort) {
|
|
91
|
+
// On non-abort MCP error, fall back to normal generation
|
|
92
|
+
yield* generate({ ...ctx, messages: processedMessages }, preprompt);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
done.abort();
|
|
96
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { EndpointMessage } from "../../endpoints/endpoints";
|
|
2
|
+
|
|
3
|
+
export type FileRefPayload = {
|
|
4
|
+
name: string;
|
|
5
|
+
mime: string;
|
|
6
|
+
base64: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type RefKind = {
|
|
10
|
+
prefix: string;
|
|
11
|
+
matches: (mime: string) => boolean;
|
|
12
|
+
toDataUrl?: (payload: FileRefPayload) => string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ResolvedFileRef = FileRefPayload & { refKind: RefKind };
|
|
16
|
+
export type FileRefResolver = (ref: string) => ResolvedFileRef | undefined;
|
|
17
|
+
|
|
18
|
+
const IMAGE_REF_KIND: RefKind = {
|
|
19
|
+
prefix: "image",
|
|
20
|
+
matches: (mime) => typeof mime === "string" && mime.startsWith("image/"),
|
|
21
|
+
toDataUrl: (payload) => `data:${payload.mime};base64,${payload.base64}`,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const DEFAULT_REF_KINDS: RefKind[] = [IMAGE_REF_KIND];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Build a resolver that maps short ref strings (e.g. "image_1", "image_2") to the
|
|
28
|
+
* corresponding file payload across the whole conversation in chronological
|
|
29
|
+
* order of user uploads. (image_1 = first user-uploaded image, image_2 = second, etc.)
|
|
30
|
+
* Currently only images are exposed to end users, but the plumbing supports
|
|
31
|
+
* additional kinds later.
|
|
32
|
+
*/
|
|
33
|
+
export function buildFileRefResolver(
|
|
34
|
+
messages: EndpointMessage[],
|
|
35
|
+
refKinds: RefKind[] = DEFAULT_REF_KINDS
|
|
36
|
+
): FileRefResolver | undefined {
|
|
37
|
+
if (!Array.isArray(refKinds) || refKinds.length === 0) return undefined;
|
|
38
|
+
|
|
39
|
+
// Bucket matched files by ref kind preserving conversation order (oldest -> newest)
|
|
40
|
+
const buckets = new Map<RefKind, FileRefPayload[]>();
|
|
41
|
+
for (const msg of messages) {
|
|
42
|
+
if (msg.from !== "user") continue;
|
|
43
|
+
for (const file of msg.files ?? []) {
|
|
44
|
+
const mime = file?.mime ?? "";
|
|
45
|
+
const kind = refKinds.find((k) => k.matches(mime));
|
|
46
|
+
if (!kind) continue;
|
|
47
|
+
const payload: FileRefPayload = { name: file.name, mime, base64: file.value };
|
|
48
|
+
const arr = buckets.get(kind) ?? [];
|
|
49
|
+
arr.push(payload);
|
|
50
|
+
buckets.set(kind, arr);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (buckets.size === 0) return undefined;
|
|
55
|
+
|
|
56
|
+
const resolver: FileRefResolver = (ref) => {
|
|
57
|
+
if (!ref || typeof ref !== "string") return undefined;
|
|
58
|
+
const trimmed = ref.trim().toLowerCase();
|
|
59
|
+
for (const kind of refKinds) {
|
|
60
|
+
const match = new RegExp(`^${kind.prefix}_(\\d+)$`).exec(trimmed);
|
|
61
|
+
if (!match) continue;
|
|
62
|
+
const idx = Number(match[1]) - 1;
|
|
63
|
+
const files = buckets.get(kind) ?? [];
|
|
64
|
+
if (Number.isFinite(idx) && idx >= 0 && idx < files.length) {
|
|
65
|
+
const payload = files[idx];
|
|
66
|
+
return payload ? { ...payload, refKind: kind } : undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return resolver;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function buildImageRefResolver(messages: EndpointMessage[]): FileRefResolver | undefined {
|
|
76
|
+
return buildFileRefResolver(messages, [IMAGE_REF_KIND]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type FieldRule = {
|
|
80
|
+
keys: string[];
|
|
81
|
+
action: "attachPayload" | "replaceWithDataUrl";
|
|
82
|
+
attachKey?: string;
|
|
83
|
+
allowedPrefixes?: string[]; // limit to specific ref kinds (e.g. ["image"])
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const DEFAULT_FIELD_RULES: FieldRule[] = [
|
|
87
|
+
{
|
|
88
|
+
keys: ["image_ref"],
|
|
89
|
+
action: "attachPayload",
|
|
90
|
+
attachKey: "image",
|
|
91
|
+
allowedPrefixes: ["image"],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
keys: ["input_image", "image", "image_url"],
|
|
95
|
+
action: "replaceWithDataUrl",
|
|
96
|
+
allowedPrefixes: ["image"],
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Walk tool args and hydrate known ref fields while keeping logging lightweight.
|
|
102
|
+
* Only image refs are recognized for now to preserve current behavior.
|
|
103
|
+
*/
|
|
104
|
+
export function attachFileRefsToArgs(
|
|
105
|
+
argsObj: Record<string, unknown>,
|
|
106
|
+
resolveRef?: FileRefResolver,
|
|
107
|
+
fieldRules: FieldRule[] = DEFAULT_FIELD_RULES
|
|
108
|
+
): void {
|
|
109
|
+
if (!resolveRef) return;
|
|
110
|
+
|
|
111
|
+
const visit = (node: unknown): void => {
|
|
112
|
+
if (!node || typeof node !== "object") return;
|
|
113
|
+
if (Array.isArray(node)) {
|
|
114
|
+
for (const v of node) visit(v);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const obj = node as Record<string, unknown>;
|
|
119
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
120
|
+
if (typeof value !== "string") {
|
|
121
|
+
if (value && typeof value === "object") visit(value);
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const resolved = resolveRef(value);
|
|
126
|
+
if (!resolved) continue;
|
|
127
|
+
|
|
128
|
+
const rule = fieldRules.find((r) => r.keys.includes(key));
|
|
129
|
+
if (!rule) continue;
|
|
130
|
+
if (rule.allowedPrefixes && !rule.allowedPrefixes.includes(resolved.refKind.prefix)) continue;
|
|
131
|
+
|
|
132
|
+
if (rule.action === "attachPayload") {
|
|
133
|
+
const targetKey = rule.attachKey ?? "file";
|
|
134
|
+
if (
|
|
135
|
+
typeof obj[targetKey] !== "object" ||
|
|
136
|
+
obj[targetKey] === null ||
|
|
137
|
+
Array.isArray(obj[targetKey])
|
|
138
|
+
) {
|
|
139
|
+
obj[targetKey] = {
|
|
140
|
+
name: resolved.name,
|
|
141
|
+
mime: resolved.mime,
|
|
142
|
+
base64: resolved.base64,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
} else if (rule.action === "replaceWithDataUrl") {
|
|
146
|
+
const toUrl =
|
|
147
|
+
resolved.refKind.toDataUrl ??
|
|
148
|
+
((p: FileRefPayload) => `data:${p.mime};base64,${p.base64}`);
|
|
149
|
+
obj[key] = toUrl(resolved);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
visit(argsObj);
|
|
155
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { config } from "$lib/server/config";
|
|
2
|
+
import { archSelectRoute } from "$lib/server/router/arch";
|
|
3
|
+
import { getRoutes, resolveRouteModels } from "$lib/server/router/policy";
|
|
4
|
+
import {
|
|
5
|
+
hasActiveToolsSelection,
|
|
6
|
+
isRouterToolsBypassEnabled,
|
|
7
|
+
pickToolsCapableModel,
|
|
8
|
+
ROUTER_TOOLS_ROUTE,
|
|
9
|
+
} from "$lib/server/router/toolsRoute";
|
|
10
|
+
import { findConfiguredMultimodalModel } from "$lib/server/router/multimodal";
|
|
11
|
+
import type { EndpointMessage } from "../../endpoints/endpoints";
|
|
12
|
+
import { stripReasoningFromMessageForRouting } from "../utils/routing";
|
|
13
|
+
import type { ProcessedModel } from "../../models";
|
|
14
|
+
import { logger } from "../../logger";
|
|
15
|
+
|
|
16
|
+
export interface RouterResolutionInput {
|
|
17
|
+
model: ProcessedModel;
|
|
18
|
+
messages: EndpointMessage[];
|
|
19
|
+
conversationId: string;
|
|
20
|
+
hasImageInput: boolean;
|
|
21
|
+
locals: App.Locals | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface RouterResolutionResult {
|
|
25
|
+
runMcp: boolean;
|
|
26
|
+
targetModel: ProcessedModel;
|
|
27
|
+
candidateModelId?: string;
|
|
28
|
+
resolvedRoute?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function resolveRouterTarget({
|
|
32
|
+
model,
|
|
33
|
+
messages,
|
|
34
|
+
conversationId,
|
|
35
|
+
hasImageInput,
|
|
36
|
+
locals,
|
|
37
|
+
}: RouterResolutionInput): Promise<RouterResolutionResult> {
|
|
38
|
+
let targetModel = model;
|
|
39
|
+
let candidateModelId: string | undefined;
|
|
40
|
+
let resolvedRoute: string | undefined;
|
|
41
|
+
let runMcp = true;
|
|
42
|
+
|
|
43
|
+
if (!model.isRouter) {
|
|
44
|
+
return { runMcp, targetModel };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const mod = await import("../../models");
|
|
49
|
+
const allModels = mod.models as ProcessedModel[];
|
|
50
|
+
|
|
51
|
+
if (hasImageInput) {
|
|
52
|
+
const multimodalCandidate = findConfiguredMultimodalModel(allModels);
|
|
53
|
+
if (!multimodalCandidate) {
|
|
54
|
+
runMcp = false;
|
|
55
|
+
logger.warn(
|
|
56
|
+
{ configuredModel: config.LLM_ROUTER_MULTIMODAL_MODEL },
|
|
57
|
+
"[mcp] multimodal input but configured model missing or invalid; skipping MCP route"
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
targetModel = multimodalCandidate;
|
|
61
|
+
candidateModelId = multimodalCandidate.id ?? multimodalCandidate.name;
|
|
62
|
+
resolvedRoute = "multimodal";
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// If tools are enabled and at least one MCP server is active, prefer a tools-capable model
|
|
66
|
+
const toolsEnabled = isRouterToolsBypassEnabled();
|
|
67
|
+
const hasToolsActive = hasActiveToolsSelection(locals);
|
|
68
|
+
|
|
69
|
+
if (toolsEnabled && hasToolsActive) {
|
|
70
|
+
const found = pickToolsCapableModel(allModels);
|
|
71
|
+
if (found) {
|
|
72
|
+
targetModel = found;
|
|
73
|
+
candidateModelId = found.id ?? found.name;
|
|
74
|
+
resolvedRoute = ROUTER_TOOLS_ROUTE;
|
|
75
|
+
// Continue; runMcp remains true
|
|
76
|
+
return { runMcp, targetModel, candidateModelId, resolvedRoute };
|
|
77
|
+
}
|
|
78
|
+
// No tools-capable model found; fall back to normal Arch routing below
|
|
79
|
+
}
|
|
80
|
+
const routes = await getRoutes();
|
|
81
|
+
const sanitized = messages.map(stripReasoningFromMessageForRouting);
|
|
82
|
+
const { routeName } = await archSelectRoute(sanitized, conversationId, locals);
|
|
83
|
+
resolvedRoute = routeName;
|
|
84
|
+
const fallbackModel = config.LLM_ROUTER_FALLBACK_MODEL || model.id;
|
|
85
|
+
const { candidates } = resolveRouteModels(routeName, routes, fallbackModel);
|
|
86
|
+
const primaryCandidateId = candidates[0];
|
|
87
|
+
if (!primaryCandidateId || primaryCandidateId === fallbackModel) {
|
|
88
|
+
runMcp = false;
|
|
89
|
+
} else {
|
|
90
|
+
const found = allModels?.find(
|
|
91
|
+
(candidate) =>
|
|
92
|
+
candidate.id === primaryCandidateId || candidate.name === primaryCandidateId
|
|
93
|
+
);
|
|
94
|
+
if (found) {
|
|
95
|
+
targetModel = found;
|
|
96
|
+
candidateModelId = primaryCandidateId;
|
|
97
|
+
} else {
|
|
98
|
+
runMcp = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} catch (error) {
|
|
103
|
+
logger.warn({ err: String(error) }, "[mcp] routing preflight failed");
|
|
104
|
+
runMcp = false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return { runMcp, targetModel, candidateModelId, resolvedRoute };
|
|
108
|
+
}
|