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,531 @@
|
|
|
1
|
+
import katex from "katex";
|
|
2
|
+
import "katex/dist/contrib/mhchem.mjs";
|
|
3
|
+
import { Marked } from "marked";
|
|
4
|
+
import type { Tokens, TokenizerExtension, RendererExtension } from "marked";
|
|
5
|
+
import { parseDocument } from "htmlparser2";
|
|
6
|
+
// Simple type to replace removed WebSearchSource
|
|
7
|
+
type SimpleSource = {
|
|
8
|
+
title?: string;
|
|
9
|
+
link: string;
|
|
10
|
+
};
|
|
11
|
+
import hljs from "highlight.js/lib/core";
|
|
12
|
+
import type { LanguageFn } from "highlight.js";
|
|
13
|
+
import javascript from "highlight.js/lib/languages/javascript";
|
|
14
|
+
import typescript from "highlight.js/lib/languages/typescript";
|
|
15
|
+
import json from "highlight.js/lib/languages/json";
|
|
16
|
+
import bash from "highlight.js/lib/languages/bash";
|
|
17
|
+
import shell from "highlight.js/lib/languages/shell";
|
|
18
|
+
import python from "highlight.js/lib/languages/python";
|
|
19
|
+
import go from "highlight.js/lib/languages/go";
|
|
20
|
+
import rust from "highlight.js/lib/languages/rust";
|
|
21
|
+
import java from "highlight.js/lib/languages/java";
|
|
22
|
+
import csharp from "highlight.js/lib/languages/csharp";
|
|
23
|
+
import cpp from "highlight.js/lib/languages/cpp";
|
|
24
|
+
import cLang from "highlight.js/lib/languages/c";
|
|
25
|
+
import xml from "highlight.js/lib/languages/xml";
|
|
26
|
+
import css from "highlight.js/lib/languages/css";
|
|
27
|
+
import scss from "highlight.js/lib/languages/scss";
|
|
28
|
+
import markdownLang from "highlight.js/lib/languages/markdown";
|
|
29
|
+
import yaml from "highlight.js/lib/languages/yaml";
|
|
30
|
+
import sql from "highlight.js/lib/languages/sql";
|
|
31
|
+
import plaintext from "highlight.js/lib/languages/plaintext";
|
|
32
|
+
import { parseIncompleteMarkdown } from "./parseIncompleteMarkdown";
|
|
33
|
+
import { parseMarkdownIntoBlocks } from "./parseBlocks";
|
|
34
|
+
|
|
35
|
+
const bundledLanguages: [string, LanguageFn][] = [
|
|
36
|
+
["javascript", javascript],
|
|
37
|
+
["typescript", typescript],
|
|
38
|
+
["json", json],
|
|
39
|
+
["bash", bash],
|
|
40
|
+
["shell", shell],
|
|
41
|
+
["python", python],
|
|
42
|
+
["go", go],
|
|
43
|
+
["rust", rust],
|
|
44
|
+
["java", java],
|
|
45
|
+
["csharp", csharp],
|
|
46
|
+
["cpp", cpp],
|
|
47
|
+
["c", cLang],
|
|
48
|
+
["xml", xml],
|
|
49
|
+
["html", xml],
|
|
50
|
+
["css", css],
|
|
51
|
+
["scss", scss],
|
|
52
|
+
["markdown", markdownLang],
|
|
53
|
+
["yaml", yaml],
|
|
54
|
+
["sql", sql],
|
|
55
|
+
["plaintext", plaintext],
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
bundledLanguages.forEach(([name, language]) => hljs.registerLanguage(name, language));
|
|
59
|
+
|
|
60
|
+
// Media URL detection
|
|
61
|
+
const VIDEO_EXTENSIONS = /\.(mp4|webm|ogg|mov|m4v)([?#]|$)/i;
|
|
62
|
+
const AUDIO_EXTENSIONS = /\.(mp3|wav|m4a|aac|flac)([?#]|$)/i;
|
|
63
|
+
|
|
64
|
+
function isVideoUrl(url: string): boolean {
|
|
65
|
+
return VIDEO_EXTENSIONS.test(url);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function isAudioUrl(url: string): boolean {
|
|
69
|
+
return AUDIO_EXTENSIONS.test(url);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Multimedia HTML sanitization (works in Web Workers - no DOM needed)
|
|
73
|
+
const MULTIMEDIA_TAGS = new Set(["video", "source", "audio"]);
|
|
74
|
+
const MULTIMEDIA_ALLOWED_ATTRS = new Set([
|
|
75
|
+
"src",
|
|
76
|
+
"type",
|
|
77
|
+
"controls",
|
|
78
|
+
"autoplay",
|
|
79
|
+
"loop",
|
|
80
|
+
"muted",
|
|
81
|
+
"playsinline",
|
|
82
|
+
"poster",
|
|
83
|
+
"width",
|
|
84
|
+
"height",
|
|
85
|
+
"preload",
|
|
86
|
+
]);
|
|
87
|
+
const MULTIMEDIA_BOOLEAN_ATTRS = new Set(["controls", "autoplay", "loop", "muted", "playsinline"]);
|
|
88
|
+
const MULTIMEDIA_URI_ATTRS = new Set(["src", "poster"]);
|
|
89
|
+
const MULTIMEDIA_ALLOWED_URI_PATTERN = /^(?!javascript:|data:text\/html)/i;
|
|
90
|
+
const MULTIMEDIA_HTML_REGEX = /<\/?(video|source|audio)\b/i;
|
|
91
|
+
|
|
92
|
+
type HtmlNode = {
|
|
93
|
+
type: string;
|
|
94
|
+
name?: string;
|
|
95
|
+
attribs?: Record<string, string>;
|
|
96
|
+
children?: HtmlNode[];
|
|
97
|
+
data?: string;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
interface katexBlockToken extends Tokens.Generic {
|
|
101
|
+
type: "katexBlock";
|
|
102
|
+
raw: string;
|
|
103
|
+
text: string;
|
|
104
|
+
displayMode: true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
interface katexInlineToken extends Tokens.Generic {
|
|
108
|
+
type: "katexInline";
|
|
109
|
+
raw: string;
|
|
110
|
+
text: string;
|
|
111
|
+
displayMode: false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const katexBlockExtension: TokenizerExtension & RendererExtension = {
|
|
115
|
+
name: "katexBlock",
|
|
116
|
+
level: "block",
|
|
117
|
+
|
|
118
|
+
start(src: string): number | undefined {
|
|
119
|
+
const match = src.match(/(\${2}|\\\[)/);
|
|
120
|
+
return match ? match.index : -1;
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
tokenizer(src: string): katexBlockToken | undefined {
|
|
124
|
+
// 1) $$ ... $$
|
|
125
|
+
const rule1 = /^\${2}([\s\S]+?)\${2}/;
|
|
126
|
+
const match1 = rule1.exec(src);
|
|
127
|
+
if (match1) {
|
|
128
|
+
const token: katexBlockToken = {
|
|
129
|
+
type: "katexBlock",
|
|
130
|
+
raw: match1[0],
|
|
131
|
+
text: match1[1].trim(),
|
|
132
|
+
displayMode: true,
|
|
133
|
+
};
|
|
134
|
+
return token;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 2) \[ ... \]
|
|
138
|
+
const rule2 = /^\\\[([\s\S]+?)\\\]/;
|
|
139
|
+
const match2 = rule2.exec(src);
|
|
140
|
+
if (match2) {
|
|
141
|
+
const token: katexBlockToken = {
|
|
142
|
+
type: "katexBlock",
|
|
143
|
+
raw: match2[0],
|
|
144
|
+
text: match2[1].trim(),
|
|
145
|
+
displayMode: true,
|
|
146
|
+
};
|
|
147
|
+
return token;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return undefined;
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
renderer(token) {
|
|
154
|
+
if (token.type === "katexBlock") {
|
|
155
|
+
return katex.renderToString(token.text, {
|
|
156
|
+
throwOnError: false,
|
|
157
|
+
displayMode: token.displayMode,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const katexInlineExtension: TokenizerExtension & RendererExtension = {
|
|
165
|
+
name: "katexInline",
|
|
166
|
+
level: "inline",
|
|
167
|
+
|
|
168
|
+
start(src: string): number | undefined {
|
|
169
|
+
const match = src.match(/(\$|\\\()/);
|
|
170
|
+
return match ? match.index : -1;
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
tokenizer(src: string): katexInlineToken | undefined {
|
|
174
|
+
// 1) $...$
|
|
175
|
+
const rule1 = /^\$([^$]+?)\$/;
|
|
176
|
+
const match1 = rule1.exec(src);
|
|
177
|
+
if (match1) {
|
|
178
|
+
const token: katexInlineToken = {
|
|
179
|
+
type: "katexInline",
|
|
180
|
+
raw: match1[0],
|
|
181
|
+
text: match1[1].trim(),
|
|
182
|
+
displayMode: false,
|
|
183
|
+
};
|
|
184
|
+
return token;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 2) \(...\)
|
|
188
|
+
const rule2 = /^\\\(([\s\S]+?)\\\)/;
|
|
189
|
+
const match2 = rule2.exec(src);
|
|
190
|
+
if (match2) {
|
|
191
|
+
const token: katexInlineToken = {
|
|
192
|
+
type: "katexInline",
|
|
193
|
+
raw: match2[0],
|
|
194
|
+
text: match2[1].trim(),
|
|
195
|
+
displayMode: false,
|
|
196
|
+
};
|
|
197
|
+
return token;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return undefined;
|
|
201
|
+
},
|
|
202
|
+
|
|
203
|
+
renderer(token) {
|
|
204
|
+
if (token.type === "katexInline") {
|
|
205
|
+
return katex.renderToString(token.text, {
|
|
206
|
+
throwOnError: false,
|
|
207
|
+
displayMode: token.displayMode,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
function escapeHTML(content: string) {
|
|
215
|
+
return content.replace(
|
|
216
|
+
/[<>&"']/g,
|
|
217
|
+
(x) =>
|
|
218
|
+
({
|
|
219
|
+
"<": "<",
|
|
220
|
+
">": ">",
|
|
221
|
+
"&": "&",
|
|
222
|
+
"'": "'",
|
|
223
|
+
'"': """,
|
|
224
|
+
})[x] || x
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function addInlineCitations(md: string, webSearchSources: SimpleSource[] = []): string {
|
|
229
|
+
const linkStyle =
|
|
230
|
+
"color: rgb(59, 130, 246); text-decoration: none; hover:text-decoration: underline;";
|
|
231
|
+
return md.replace(/\[(\d+)\]/g, (match: string) => {
|
|
232
|
+
const indices: number[] = (match.match(/\d+/g) || []).map(Number);
|
|
233
|
+
const links: string = indices
|
|
234
|
+
.map((index: number) => {
|
|
235
|
+
if (index === 0) return false;
|
|
236
|
+
const source = webSearchSources[index - 1];
|
|
237
|
+
if (source) {
|
|
238
|
+
return `<a href="${escapeHTML(source.link)}" target="_blank" rel="noreferrer" style="${linkStyle}">${index}</a>`;
|
|
239
|
+
}
|
|
240
|
+
return "";
|
|
241
|
+
})
|
|
242
|
+
.filter(Boolean)
|
|
243
|
+
.join(", ");
|
|
244
|
+
return links ? ` <sup>${links}</sup>` : match;
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function sanitizeHref(href?: string | null): string | undefined {
|
|
249
|
+
if (!href) return undefined;
|
|
250
|
+
const trimmed = href.trim();
|
|
251
|
+
const lower = trimmed.toLowerCase();
|
|
252
|
+
if (lower.startsWith("javascript:") || lower.startsWith("data:text/html")) {
|
|
253
|
+
return undefined;
|
|
254
|
+
}
|
|
255
|
+
return trimmed.replace(/>$/, "");
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function highlightCode(text: string, lang?: string): string {
|
|
259
|
+
if (lang && hljs.getLanguage(lang)) {
|
|
260
|
+
try {
|
|
261
|
+
return hljs.highlight(text, { language: lang, ignoreIllegals: true }).value;
|
|
262
|
+
} catch {
|
|
263
|
+
// fall through to auto-detect
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return hljs.highlightAuto(text).value;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function sanitizeMediaUrl(value: string): string | undefined {
|
|
270
|
+
const trimmed = value.trim().replace(/>$/, "");
|
|
271
|
+
if (!MULTIMEDIA_ALLOWED_URI_PATTERN.test(trimmed)) return undefined;
|
|
272
|
+
return trimmed;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function serializeMediaAttributes(attribs?: Record<string, string>): string {
|
|
276
|
+
if (!attribs) return "";
|
|
277
|
+
const parts: string[] = [];
|
|
278
|
+
for (const [rawName, rawValue] of Object.entries(attribs)) {
|
|
279
|
+
const name = rawName.toLowerCase();
|
|
280
|
+
if (!MULTIMEDIA_ALLOWED_ATTRS.has(name)) continue;
|
|
281
|
+
if (MULTIMEDIA_BOOLEAN_ATTRS.has(name)) {
|
|
282
|
+
parts.push(name);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
let value = rawValue ?? "";
|
|
286
|
+
if (MULTIMEDIA_URI_ATTRS.has(name)) {
|
|
287
|
+
const safeUrl = sanitizeMediaUrl(value);
|
|
288
|
+
if (!safeUrl) continue;
|
|
289
|
+
value = safeUrl;
|
|
290
|
+
}
|
|
291
|
+
parts.push(`${name}="${escapeHTML(value)}"`);
|
|
292
|
+
}
|
|
293
|
+
return parts.length ? ` ${parts.join(" ")}` : "";
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function serializeMediaNode(node: HtmlNode, state: { hasDisallowedTag: boolean }): string {
|
|
297
|
+
if (node.type === "text") {
|
|
298
|
+
return escapeHTML(node.data ?? "");
|
|
299
|
+
}
|
|
300
|
+
if (node.type === "tag" || node.type === "script" || node.type === "style") {
|
|
301
|
+
const tagName = node.name?.toLowerCase() ?? "";
|
|
302
|
+
if (!MULTIMEDIA_TAGS.has(tagName)) {
|
|
303
|
+
state.hasDisallowedTag = true;
|
|
304
|
+
return "";
|
|
305
|
+
}
|
|
306
|
+
const attrs = serializeMediaAttributes(node.attribs);
|
|
307
|
+
if (tagName === "source") {
|
|
308
|
+
return `<source${attrs}>`;
|
|
309
|
+
}
|
|
310
|
+
const children = (node.children ?? [])
|
|
311
|
+
.map((child) => serializeMediaNode(child, state))
|
|
312
|
+
.join("");
|
|
313
|
+
return `<${tagName}${attrs}>${children}</${tagName}>`;
|
|
314
|
+
}
|
|
315
|
+
if (node.type === "comment") {
|
|
316
|
+
return "";
|
|
317
|
+
}
|
|
318
|
+
return "";
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Sanitizes HTML to allow only video/audio/source tags with safe attributes.
|
|
323
|
+
* Uses htmlparser2 which works in Web Workers (no DOM needed).
|
|
324
|
+
* If any disallowed tags are found, escapes the entire input.
|
|
325
|
+
*/
|
|
326
|
+
function sanitizeHtmlForMultimedia(html: string): string {
|
|
327
|
+
if (!MULTIMEDIA_HTML_REGEX.test(html)) {
|
|
328
|
+
return escapeHTML(html);
|
|
329
|
+
}
|
|
330
|
+
const document = parseDocument(html, {
|
|
331
|
+
lowerCaseAttributeNames: true,
|
|
332
|
+
lowerCaseTags: true,
|
|
333
|
+
recognizeSelfClosing: true,
|
|
334
|
+
}) as unknown as { children: HtmlNode[] };
|
|
335
|
+
const state = { hasDisallowedTag: false };
|
|
336
|
+
const sanitized = (document.children ?? [])
|
|
337
|
+
.map((child) => serializeMediaNode(child, state))
|
|
338
|
+
.join("");
|
|
339
|
+
if (state.hasDisallowedTag) {
|
|
340
|
+
return escapeHTML(html);
|
|
341
|
+
}
|
|
342
|
+
return sanitized;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function createMarkedInstance(sources: SimpleSource[]): Marked {
|
|
346
|
+
return new Marked({
|
|
347
|
+
hooks: {
|
|
348
|
+
postprocess: (html) => addInlineCitations(html, sources),
|
|
349
|
+
},
|
|
350
|
+
extensions: [katexBlockExtension, katexInlineExtension],
|
|
351
|
+
renderer: {
|
|
352
|
+
link: (href, title, text) => {
|
|
353
|
+
const safeHref = sanitizeHref(href);
|
|
354
|
+
return safeHref
|
|
355
|
+
? `<a href="${escapeHTML(safeHref)}" target="_blank" rel="noreferrer">${text}</a>`
|
|
356
|
+
: `<span>${escapeHTML(text ?? "")}</span>`;
|
|
357
|
+
},
|
|
358
|
+
image: (href, title, text) => {
|
|
359
|
+
const safeHref = sanitizeHref(href);
|
|
360
|
+
if (!safeHref) return `<span>${escapeHTML(text ?? "")}</span>`;
|
|
361
|
+
|
|
362
|
+
const safeSrc = escapeHTML(safeHref);
|
|
363
|
+
const safeTitle = title ? ` title="${escapeHTML(title)}"` : "";
|
|
364
|
+
const safeAlt = escapeHTML(text ?? "");
|
|
365
|
+
|
|
366
|
+
if (isVideoUrl(safeHref)) {
|
|
367
|
+
return `<video controls${safeTitle}><source src="${safeSrc}">${safeAlt}</video>`;
|
|
368
|
+
}
|
|
369
|
+
if (isAudioUrl(safeHref)) {
|
|
370
|
+
return `<audio controls${safeTitle}><source src="${safeSrc}">${safeAlt}</audio>`;
|
|
371
|
+
}
|
|
372
|
+
return `<img src="${safeSrc}" alt="${safeAlt}"${safeTitle} />`;
|
|
373
|
+
},
|
|
374
|
+
html: (html) => sanitizeHtmlForMultimedia(html),
|
|
375
|
+
},
|
|
376
|
+
gfm: true,
|
|
377
|
+
breaks: true,
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function isFencedBlockClosed(raw?: string): boolean {
|
|
381
|
+
if (!raw) return true;
|
|
382
|
+
/* eslint-disable-next-line no-control-regex */
|
|
383
|
+
const trimmed = raw.replace(/[\s\u0000]+$/, "");
|
|
384
|
+
const openingFenceMatch = trimmed.match(/^([`~]{3,})/);
|
|
385
|
+
if (!openingFenceMatch) {
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
const fence = openingFenceMatch[1];
|
|
389
|
+
const closingFencePattern = new RegExp(`(?:\n|\r\n)${fence}(?:[\t ]+)?$`);
|
|
390
|
+
return closingFencePattern.test(trimmed);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
type CodeToken = {
|
|
394
|
+
type: "code";
|
|
395
|
+
lang: string;
|
|
396
|
+
code: string;
|
|
397
|
+
rawCode: string;
|
|
398
|
+
isClosed: boolean;
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
type TextToken = {
|
|
402
|
+
type: "text";
|
|
403
|
+
html: string | Promise<string>;
|
|
404
|
+
};
|
|
405
|
+
|
|
406
|
+
const blockCache = new Map<string, BlockToken>();
|
|
407
|
+
|
|
408
|
+
function cacheKey(index: number, blockContent: string, sources: SimpleSource[]) {
|
|
409
|
+
const sourceKey = sources.map((s) => s.link).join("|");
|
|
410
|
+
return `${index}-${hashString(blockContent)}|${sourceKey}`;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export async function processTokens(content: string, sources: SimpleSource[]): Promise<Token[]> {
|
|
414
|
+
// Apply incomplete markdown preprocessing for smooth streaming
|
|
415
|
+
const processedContent = parseIncompleteMarkdown(content);
|
|
416
|
+
|
|
417
|
+
const marked = createMarkedInstance(sources);
|
|
418
|
+
const tokens = marked.lexer(processedContent);
|
|
419
|
+
|
|
420
|
+
const processedTokens = await Promise.all(
|
|
421
|
+
tokens.map(async (token) => {
|
|
422
|
+
if (token.type === "code") {
|
|
423
|
+
return {
|
|
424
|
+
type: "code" as const,
|
|
425
|
+
lang: token.lang,
|
|
426
|
+
code: highlightCode(token.text, token.lang),
|
|
427
|
+
rawCode: token.text,
|
|
428
|
+
isClosed: isFencedBlockClosed(token.raw ?? ""),
|
|
429
|
+
};
|
|
430
|
+
} else {
|
|
431
|
+
return {
|
|
432
|
+
type: "text" as const,
|
|
433
|
+
html: marked.parse(token.raw),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
return processedTokens;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function processTokensSync(content: string, sources: SimpleSource[]): Token[] {
|
|
443
|
+
// Apply incomplete markdown preprocessing for smooth streaming
|
|
444
|
+
const processedContent = parseIncompleteMarkdown(content);
|
|
445
|
+
|
|
446
|
+
const marked = createMarkedInstance(sources);
|
|
447
|
+
const tokens = marked.lexer(processedContent);
|
|
448
|
+
return tokens.map((token) => {
|
|
449
|
+
if (token.type === "code") {
|
|
450
|
+
return {
|
|
451
|
+
type: "code" as const,
|
|
452
|
+
lang: token.lang,
|
|
453
|
+
code: highlightCode(token.text, token.lang),
|
|
454
|
+
rawCode: token.text,
|
|
455
|
+
isClosed: isFencedBlockClosed(token.raw ?? ""),
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
return { type: "text" as const, html: marked.parse(token.raw) };
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export type Token = CodeToken | TextToken;
|
|
463
|
+
|
|
464
|
+
export type BlockToken = {
|
|
465
|
+
id: string;
|
|
466
|
+
content: string;
|
|
467
|
+
tokens: Token[];
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Simple hash function for generating stable block IDs
|
|
472
|
+
*/
|
|
473
|
+
function hashString(str: string): string {
|
|
474
|
+
let hash = 0;
|
|
475
|
+
for (let i = 0; i < str.length; i++) {
|
|
476
|
+
const char = str.charCodeAt(i);
|
|
477
|
+
hash = (hash << 5) - hash + char;
|
|
478
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
479
|
+
}
|
|
480
|
+
return Math.abs(hash).toString(36);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Process markdown content into blocks with stable IDs for efficient memoization.
|
|
485
|
+
* Each block is processed independently and assigned a content-based hash ID.
|
|
486
|
+
*/
|
|
487
|
+
export async function processBlocks(
|
|
488
|
+
content: string,
|
|
489
|
+
sources: SimpleSource[] = []
|
|
490
|
+
): Promise<BlockToken[]> {
|
|
491
|
+
const blocks = parseMarkdownIntoBlocks(content);
|
|
492
|
+
|
|
493
|
+
return await Promise.all(
|
|
494
|
+
blocks.map(async (blockContent, index) => {
|
|
495
|
+
const key = cacheKey(index, blockContent, sources);
|
|
496
|
+
const cached = blockCache.get(key);
|
|
497
|
+
if (cached) return cached;
|
|
498
|
+
|
|
499
|
+
const tokens = await processTokens(blockContent, sources);
|
|
500
|
+
const block: BlockToken = {
|
|
501
|
+
id: `${index}-${hashString(blockContent)}`,
|
|
502
|
+
content: blockContent,
|
|
503
|
+
tokens,
|
|
504
|
+
};
|
|
505
|
+
blockCache.set(key, block);
|
|
506
|
+
return block;
|
|
507
|
+
})
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Synchronous version of processBlocks for SSR
|
|
513
|
+
*/
|
|
514
|
+
export function processBlocksSync(content: string, sources: SimpleSource[] = []): BlockToken[] {
|
|
515
|
+
const blocks = parseMarkdownIntoBlocks(content);
|
|
516
|
+
|
|
517
|
+
return blocks.map((blockContent, index) => {
|
|
518
|
+
const key = cacheKey(index, blockContent, sources);
|
|
519
|
+
const cached = blockCache.get(key);
|
|
520
|
+
if (cached) return cached;
|
|
521
|
+
|
|
522
|
+
const tokens = processTokensSync(blockContent, sources);
|
|
523
|
+
const block: BlockToken = {
|
|
524
|
+
id: `${index}-${hashString(blockContent)}`,
|
|
525
|
+
content: blockContent,
|
|
526
|
+
tokens,
|
|
527
|
+
};
|
|
528
|
+
blockCache.set(key, block);
|
|
529
|
+
return block;
|
|
530
|
+
});
|
|
531
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL validation and sanitization utilities for MCP integration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { browser } from "$app/environment";
|
|
6
|
+
import { dev } from "$app/environment";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sanitize and validate a URL for MCP server connections
|
|
10
|
+
* @param urlString - The URL string to validate
|
|
11
|
+
* @returns Sanitized URL string or null if invalid
|
|
12
|
+
*/
|
|
13
|
+
export function validateMcpServerUrl(urlString: string): string | null {
|
|
14
|
+
if (!urlString || typeof urlString !== "string") {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const url = new URL(urlString.trim());
|
|
20
|
+
|
|
21
|
+
// Allow http/https only
|
|
22
|
+
if (!["http:", "https:"].includes(url.protocol)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Warn about non-HTTPS in production
|
|
27
|
+
if (!dev && url.protocol === "http:" && browser) {
|
|
28
|
+
console.warn(
|
|
29
|
+
"Warning: Connecting to non-HTTPS MCP server in production. This may expose sensitive data."
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Block certain localhost/private IPs in production
|
|
34
|
+
if (!dev && isPrivateOrLocalhost(url.hostname)) {
|
|
35
|
+
console.warn("Warning: Localhost/private IP addresses are not recommended in production.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return url.toString();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
// Invalid URL
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Check if hostname is localhost or a private IP
|
|
47
|
+
*/
|
|
48
|
+
function isPrivateOrLocalhost(hostname: string): boolean {
|
|
49
|
+
// Localhost checks
|
|
50
|
+
if (
|
|
51
|
+
hostname === "localhost" ||
|
|
52
|
+
hostname === "127.0.0.1" ||
|
|
53
|
+
hostname === "::1" ||
|
|
54
|
+
hostname.endsWith(".localhost")
|
|
55
|
+
) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Private IP ranges (IPv4)
|
|
60
|
+
const ipv4Regex = /^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.|127\.|0\.0\.0\.0|169\.254\.)/;
|
|
61
|
+
if (ipv4Regex.test(hostname)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sanitize URL by removing sensitive parts
|
|
70
|
+
* Used for logging and display purposes
|
|
71
|
+
*/
|
|
72
|
+
export function sanitizeUrlForDisplay(urlString: string): string {
|
|
73
|
+
try {
|
|
74
|
+
const url = new URL(urlString);
|
|
75
|
+
// Remove username/password if present
|
|
76
|
+
url.username = "";
|
|
77
|
+
url.password = "";
|
|
78
|
+
return url.toString();
|
|
79
|
+
} catch {
|
|
80
|
+
return urlString;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if URL is safe to connect to
|
|
86
|
+
* Returns an error message if unsafe, null if safe
|
|
87
|
+
*/
|
|
88
|
+
export function checkUrlSafety(urlString: string): string | null {
|
|
89
|
+
const validated = validateMcpServerUrl(urlString);
|
|
90
|
+
if (!validated) {
|
|
91
|
+
return "Invalid URL. Please use http:// or https:// URLs only.";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const url = new URL(validated);
|
|
96
|
+
|
|
97
|
+
// Additional safety checks
|
|
98
|
+
if (!dev && url.protocol === "http:") {
|
|
99
|
+
return "Non-HTTPS URLs are not recommended in production. Please use https:// for security.";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return null; // Safe
|
|
103
|
+
} catch {
|
|
104
|
+
return "Invalid URL format.";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check if a header key is likely to contain sensitive data
|
|
110
|
+
*/
|
|
111
|
+
export function isSensitiveHeader(key: string): boolean {
|
|
112
|
+
const sensitiveKeys = [
|
|
113
|
+
"authorization",
|
|
114
|
+
"api-key",
|
|
115
|
+
"api_key",
|
|
116
|
+
"apikey",
|
|
117
|
+
"token",
|
|
118
|
+
"secret",
|
|
119
|
+
"password",
|
|
120
|
+
"bearer",
|
|
121
|
+
"x-api-key",
|
|
122
|
+
"x-auth-token",
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const lowerKey = key.toLowerCase();
|
|
126
|
+
return sensitiveKeys.some((sensitive) => lowerKey.includes(sensitive));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Validate header key-value pair
|
|
131
|
+
* Returns error message if invalid, null if valid
|
|
132
|
+
*/
|
|
133
|
+
export function validateHeader(key: string, value: string): string | null {
|
|
134
|
+
if (!key || !key.trim()) {
|
|
135
|
+
return "Header name is required";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!/^[a-zA-Z0-9_-]+$/.test(key)) {
|
|
139
|
+
return "Header name can only contain letters, numbers, hyphens, and underscores";
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!value) {
|
|
143
|
+
return "Header value is required";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
type Gen<T, TReturn> = AsyncGenerator<T, TReturn, undefined>;
|
|
2
|
+
|
|
3
|
+
type GenPromiseMap<T, TReturn> = Map<
|
|
4
|
+
Gen<T, TReturn>,
|
|
5
|
+
Promise<{ gen: Gen<T, TReturn> } & IteratorResult<T, TReturn>>
|
|
6
|
+
>;
|
|
7
|
+
|
|
8
|
+
/** Merges multiple async generators into a single async generator that yields values from all of them in parallel. */
|
|
9
|
+
export async function* mergeAsyncGenerators<T, TReturn>(
|
|
10
|
+
generators: Gen<T, TReturn>[]
|
|
11
|
+
): Gen<T, TReturn[]> {
|
|
12
|
+
const promises: GenPromiseMap<T, TReturn> = new Map();
|
|
13
|
+
const results: Map<Gen<T, TReturn>, TReturn> = new Map();
|
|
14
|
+
|
|
15
|
+
for (const gen of generators) {
|
|
16
|
+
promises.set(
|
|
17
|
+
gen,
|
|
18
|
+
gen.next().then((result) => ({ gen, ...result }))
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
while (promises.size) {
|
|
23
|
+
const { gen, value, done } = await Promise.race(promises.values());
|
|
24
|
+
if (done) {
|
|
25
|
+
results.set(gen, value as TReturn);
|
|
26
|
+
promises.delete(gen);
|
|
27
|
+
} else {
|
|
28
|
+
promises.set(
|
|
29
|
+
gen,
|
|
30
|
+
gen.next().then((result) => ({ gen, ...result }))
|
|
31
|
+
);
|
|
32
|
+
yield value as T;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const orderedResults = generators.map((gen) => results.get(gen) as TReturn);
|
|
37
|
+
return orderedResults;
|
|
38
|
+
}
|