ruflo 3.5.2 → 3.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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,115 @@
|
|
|
1
|
+
import type { RequestHandler } from "./$types";
|
|
2
|
+
import { collections } from "$lib/server/database";
|
|
3
|
+
import { ObjectId } from "mongodb";
|
|
4
|
+
import { error, redirect } from "@sveltejs/kit";
|
|
5
|
+
import { base } from "$app/paths";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import type { Message } from "$lib/types/Message";
|
|
8
|
+
import { models, validateModel } from "$lib/server/models";
|
|
9
|
+
import { v4 } from "uuid";
|
|
10
|
+
import { authCondition } from "$lib/server/auth";
|
|
11
|
+
import { usageLimits } from "$lib/server/usageLimits";
|
|
12
|
+
import { MetricsServer } from "$lib/server/metrics";
|
|
13
|
+
|
|
14
|
+
export const POST: RequestHandler = async ({ locals, request }) => {
|
|
15
|
+
const body = await request.text();
|
|
16
|
+
|
|
17
|
+
let title = "";
|
|
18
|
+
|
|
19
|
+
const parsedBody = z
|
|
20
|
+
.object({
|
|
21
|
+
fromShare: z.string().optional(),
|
|
22
|
+
model: validateModel(models),
|
|
23
|
+
preprompt: z.string().optional(),
|
|
24
|
+
})
|
|
25
|
+
.safeParse(JSON.parse(body));
|
|
26
|
+
|
|
27
|
+
if (!parsedBody.success) {
|
|
28
|
+
error(400, "Invalid request");
|
|
29
|
+
}
|
|
30
|
+
const values = parsedBody.data;
|
|
31
|
+
|
|
32
|
+
const convCount = await collections.conversations.countDocuments(authCondition(locals));
|
|
33
|
+
|
|
34
|
+
if (usageLimits?.conversations && convCount > usageLimits?.conversations) {
|
|
35
|
+
error(429, "You have reached the maximum number of conversations. Delete some to continue.");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const model = models.find((m) => (m.id || m.name) === values.model);
|
|
39
|
+
|
|
40
|
+
if (!model) {
|
|
41
|
+
error(400, "Invalid model");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let messages: Message[] = [
|
|
45
|
+
{
|
|
46
|
+
id: v4(),
|
|
47
|
+
from: "system",
|
|
48
|
+
content: values.preprompt ?? "",
|
|
49
|
+
createdAt: new Date(),
|
|
50
|
+
updatedAt: new Date(),
|
|
51
|
+
children: [],
|
|
52
|
+
ancestors: [],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
let rootMessageId: Message["id"] = messages[0].id;
|
|
57
|
+
|
|
58
|
+
if (values.fromShare) {
|
|
59
|
+
const conversation = await collections.sharedConversations.findOne({
|
|
60
|
+
_id: values.fromShare,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (!conversation) {
|
|
64
|
+
error(404, "Conversation not found");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Strip <think> markers from imported titles
|
|
68
|
+
title = conversation.title.replace(/<\/?think>/gi, "").trim();
|
|
69
|
+
messages = conversation.messages;
|
|
70
|
+
rootMessageId = conversation.rootMessageId ?? rootMessageId;
|
|
71
|
+
values.model = conversation.model;
|
|
72
|
+
values.preprompt = conversation.preprompt;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (model.unlisted) {
|
|
76
|
+
error(400, "Can't start a conversation with an unlisted model");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// use provided preprompt or model preprompt
|
|
80
|
+
values.preprompt ??= model?.preprompt ?? "";
|
|
81
|
+
|
|
82
|
+
if (messages && messages.length > 0 && messages[0].from === "system") {
|
|
83
|
+
messages[0].content = values.preprompt;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const res = await collections.conversations.insertOne({
|
|
87
|
+
_id: new ObjectId(),
|
|
88
|
+
// Always store sanitized titles
|
|
89
|
+
title: (title || "New Chat").replace(/<\/?think>/gi, "").trim(),
|
|
90
|
+
rootMessageId,
|
|
91
|
+
messages,
|
|
92
|
+
model: values.model,
|
|
93
|
+
preprompt: values.preprompt,
|
|
94
|
+
createdAt: new Date(),
|
|
95
|
+
updatedAt: new Date(),
|
|
96
|
+
userAgent: request.headers.get("User-Agent") ?? undefined,
|
|
97
|
+
...(locals.user ? { userId: locals.user._id } : { sessionId: locals.sessionId }),
|
|
98
|
+
...(values.fromShare ? { meta: { fromShareId: values.fromShare } } : {}),
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (MetricsServer.isEnabled()) {
|
|
102
|
+
MetricsServer.getMetrics().model.conversationsTotal.inc({ model: values.model });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return new Response(
|
|
106
|
+
JSON.stringify({
|
|
107
|
+
conversationId: res.insertedId.toString(),
|
|
108
|
+
}),
|
|
109
|
+
{ headers: { "Content-Type": "application/json" } }
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const GET: RequestHandler = async () => {
|
|
114
|
+
redirect(302, `${base}/`);
|
|
115
|
+
};
|
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
|
|
3
|
+
import { pendingMessage } from "$lib/stores/pendingMessage";
|
|
4
|
+
import { isAborted } from "$lib/stores/isAborted";
|
|
5
|
+
import { onMount } from "svelte";
|
|
6
|
+
import { page } from "$app/state";
|
|
7
|
+
import { beforeNavigate, invalidateAll } from "$app/navigation";
|
|
8
|
+
import { base } from "$app/paths";
|
|
9
|
+
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
|
10
|
+
import { findCurrentModel } from "$lib/utils/models";
|
|
11
|
+
import type { Message } from "$lib/types/Message";
|
|
12
|
+
import { MessageUpdateStatus, MessageUpdateType } from "$lib/types/MessageUpdate";
|
|
13
|
+
import titleUpdate from "$lib/stores/titleUpdate";
|
|
14
|
+
import file2base64 from "$lib/utils/file2base64";
|
|
15
|
+
import { addChildren } from "$lib/utils/tree/addChildren";
|
|
16
|
+
import { addSibling } from "$lib/utils/tree/addSibling";
|
|
17
|
+
import { fetchMessageUpdates, resolveStreamingMode } from "$lib/utils/messageUpdates";
|
|
18
|
+
import type { v4 } from "uuid";
|
|
19
|
+
import { useSettingsStore } from "$lib/stores/settings.js";
|
|
20
|
+
import { enabledServers } from "$lib/stores/mcpServers";
|
|
21
|
+
import { browser } from "$app/environment";
|
|
22
|
+
import {
|
|
23
|
+
addBackgroundGeneration,
|
|
24
|
+
removeBackgroundGeneration,
|
|
25
|
+
} from "$lib/stores/backgroundGenerations";
|
|
26
|
+
import type { TreeNode, TreeId } from "$lib/utils/tree/tree";
|
|
27
|
+
import "katex/dist/katex.min.css";
|
|
28
|
+
import { updateDebouncer } from "$lib/utils/updates.js";
|
|
29
|
+
import SubscribeModal from "$lib/components/SubscribeModal.svelte";
|
|
30
|
+
import { loading } from "$lib/stores/loading.js";
|
|
31
|
+
import { requireAuthUser } from "$lib/utils/auth.js";
|
|
32
|
+
import { isConversationGenerationActive } from "$lib/utils/generationState";
|
|
33
|
+
|
|
34
|
+
let { data = $bindable() } = $props();
|
|
35
|
+
|
|
36
|
+
let convId = $derived(page.params.id ?? "");
|
|
37
|
+
let pending = $state(false);
|
|
38
|
+
let initialRun = true;
|
|
39
|
+
let showSubscribeModal = $state(false);
|
|
40
|
+
let stopRequested = $state(false);
|
|
41
|
+
|
|
42
|
+
let files: File[] = $state([]);
|
|
43
|
+
|
|
44
|
+
let conversations = $state(data.conversations);
|
|
45
|
+
$effect(() => {
|
|
46
|
+
conversations = data.conversations;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
function createMessagesPath<T>(messages: TreeNode<T>[], msgId?: TreeId): TreeNode<T>[] {
|
|
50
|
+
if (initialRun) {
|
|
51
|
+
if (!msgId && page.url.searchParams.get("leafId")) {
|
|
52
|
+
msgId = page.url.searchParams.get("leafId") as string;
|
|
53
|
+
page.url.searchParams.delete("leafId");
|
|
54
|
+
}
|
|
55
|
+
if (!msgId && browser && localStorage.getItem("leafId")) {
|
|
56
|
+
msgId = localStorage.getItem("leafId") as string;
|
|
57
|
+
}
|
|
58
|
+
initialRun = false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const msg = messages.find((msg) => msg.id === msgId) ?? messages.at(-1);
|
|
62
|
+
if (!msg) return [];
|
|
63
|
+
// ancestor path
|
|
64
|
+
const { ancestors } = msg;
|
|
65
|
+
const path = [];
|
|
66
|
+
if (ancestors?.length) {
|
|
67
|
+
for (const ancestorId of ancestors) {
|
|
68
|
+
const ancestor = messages.find((msg) => msg.id === ancestorId);
|
|
69
|
+
if (ancestor) {
|
|
70
|
+
path.push(ancestor);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// push the node itself in the middle
|
|
76
|
+
path.push(msg);
|
|
77
|
+
|
|
78
|
+
// children path
|
|
79
|
+
let childrenIds = msg.children;
|
|
80
|
+
while (childrenIds?.length) {
|
|
81
|
+
let lastChildId = childrenIds.at(-1);
|
|
82
|
+
const lastChild = messages.find((msg) => msg.id === lastChildId);
|
|
83
|
+
if (lastChild) {
|
|
84
|
+
path.push(lastChild);
|
|
85
|
+
}
|
|
86
|
+
childrenIds = lastChild?.children;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return path;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function createMessagesAlternatives<T>(messages: TreeNode<T>[]): TreeId[][] {
|
|
93
|
+
const alternatives = [];
|
|
94
|
+
for (const message of messages) {
|
|
95
|
+
if (message.children?.length) {
|
|
96
|
+
alternatives.push(message.children);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return alternatives;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// this function is used to send new message to the backends
|
|
103
|
+
async function writeMessage({
|
|
104
|
+
prompt,
|
|
105
|
+
messageId = messagesPath.at(-1)?.id ?? undefined,
|
|
106
|
+
isRetry = false,
|
|
107
|
+
}: {
|
|
108
|
+
prompt?: string;
|
|
109
|
+
messageId?: ReturnType<typeof v4>;
|
|
110
|
+
isRetry?: boolean;
|
|
111
|
+
}): Promise<void> {
|
|
112
|
+
try {
|
|
113
|
+
stopRequested = false;
|
|
114
|
+
$isAborted = false;
|
|
115
|
+
$loading = true;
|
|
116
|
+
pending = true;
|
|
117
|
+
const base64Files = await Promise.all(
|
|
118
|
+
(files ?? []).map((file) =>
|
|
119
|
+
file2base64(file).then((value) => ({
|
|
120
|
+
type: "base64" as const,
|
|
121
|
+
value,
|
|
122
|
+
mime: file.type,
|
|
123
|
+
name: file.name,
|
|
124
|
+
}))
|
|
125
|
+
)
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
let messageToWriteToId: Message["id"] | undefined = undefined;
|
|
129
|
+
// used for building the prompt, subtree of the conversation that goes from the latest message to the root
|
|
130
|
+
|
|
131
|
+
if (isRetry && messageId) {
|
|
132
|
+
// two cases, if we're retrying a user message with a newPrompt set,
|
|
133
|
+
// it means we're editing a user message
|
|
134
|
+
// if we're retrying on an assistant message, newPrompt cannot be set
|
|
135
|
+
// it means we're retrying the last assistant message for a new answer
|
|
136
|
+
|
|
137
|
+
const messageToRetry = messages.find((message) => message.id === messageId);
|
|
138
|
+
|
|
139
|
+
if (!messageToRetry) {
|
|
140
|
+
$error = "Message not found";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (messageToRetry?.from === "user" && prompt) {
|
|
144
|
+
// add a sibling to this message from the user, with the alternative prompt
|
|
145
|
+
// add a children to that sibling, where we can write to
|
|
146
|
+
const newUserMessageId = addSibling(
|
|
147
|
+
{
|
|
148
|
+
messages,
|
|
149
|
+
rootMessageId: data.rootMessageId,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
from: "user",
|
|
153
|
+
content: prompt,
|
|
154
|
+
files: messageToRetry.files,
|
|
155
|
+
},
|
|
156
|
+
messageId
|
|
157
|
+
);
|
|
158
|
+
messageToWriteToId = addChildren(
|
|
159
|
+
{
|
|
160
|
+
messages,
|
|
161
|
+
rootMessageId: data.rootMessageId,
|
|
162
|
+
},
|
|
163
|
+
{ from: "assistant", content: "" },
|
|
164
|
+
newUserMessageId
|
|
165
|
+
);
|
|
166
|
+
} else if (messageToRetry?.from === "assistant") {
|
|
167
|
+
// we're retrying an assistant message, to generate a new answer
|
|
168
|
+
// just add a sibling to the assistant answer where we can write to
|
|
169
|
+
messageToWriteToId = addSibling(
|
|
170
|
+
{
|
|
171
|
+
messages,
|
|
172
|
+
rootMessageId: data.rootMessageId,
|
|
173
|
+
},
|
|
174
|
+
{ from: "assistant", content: "" },
|
|
175
|
+
messageId
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
// just a normal linear conversation, so we add the user message
|
|
180
|
+
// and the blank assistant message back to back
|
|
181
|
+
const newUserMessageId = addChildren(
|
|
182
|
+
{
|
|
183
|
+
messages,
|
|
184
|
+
rootMessageId: data.rootMessageId,
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
from: "user",
|
|
188
|
+
content: prompt ?? "",
|
|
189
|
+
files: base64Files,
|
|
190
|
+
},
|
|
191
|
+
messageId
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (!data.rootMessageId) {
|
|
195
|
+
data.rootMessageId = newUserMessageId;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
messageToWriteToId = addChildren(
|
|
199
|
+
{
|
|
200
|
+
messages,
|
|
201
|
+
rootMessageId: data.rootMessageId,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
from: "assistant",
|
|
205
|
+
content: "",
|
|
206
|
+
},
|
|
207
|
+
newUserMessageId
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const userMessage = messages.find((message) => message.id === messageId);
|
|
212
|
+
const messageToWriteTo = messages.find((message) => message.id === messageToWriteToId);
|
|
213
|
+
if (!messageToWriteTo) {
|
|
214
|
+
throw new Error("Message to write to not found");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const messageUpdatesAbortController = new AbortController();
|
|
218
|
+
const streamingMode = resolveStreamingMode($settings);
|
|
219
|
+
|
|
220
|
+
const messageUpdatesIterator = await fetchMessageUpdates(
|
|
221
|
+
convId,
|
|
222
|
+
{
|
|
223
|
+
base,
|
|
224
|
+
inputs: prompt,
|
|
225
|
+
messageId,
|
|
226
|
+
isRetry,
|
|
227
|
+
files: isRetry ? userMessage?.files : base64Files,
|
|
228
|
+
selectedMcpServerNames: $enabledServers.map((s) => s.name),
|
|
229
|
+
selectedMcpServers: $enabledServers.map((s) => ({
|
|
230
|
+
name: s.name,
|
|
231
|
+
url: s.url,
|
|
232
|
+
headers: s.headers,
|
|
233
|
+
})),
|
|
234
|
+
streamingMode,
|
|
235
|
+
autopilot: $settings.autopilotEnabled === true,
|
|
236
|
+
},
|
|
237
|
+
messageUpdatesAbortController.signal
|
|
238
|
+
).catch((err) => {
|
|
239
|
+
error.set(err.message);
|
|
240
|
+
});
|
|
241
|
+
if (messageUpdatesIterator === undefined) return;
|
|
242
|
+
|
|
243
|
+
files = [];
|
|
244
|
+
let buffer = "";
|
|
245
|
+
// Initialize lastUpdateTime outside the loop to persist between updates
|
|
246
|
+
let lastUpdateTime = new Date();
|
|
247
|
+
let frameFlushScheduled = false;
|
|
248
|
+
|
|
249
|
+
const flushBuffer = (currentTime: Date) => {
|
|
250
|
+
if (buffer.length === 0) return;
|
|
251
|
+
messageToWriteTo.content += buffer;
|
|
252
|
+
buffer = "";
|
|
253
|
+
lastUpdateTime = currentTime;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const scheduleFrameFlush = () => {
|
|
257
|
+
if (frameFlushScheduled) return;
|
|
258
|
+
frameFlushScheduled = true;
|
|
259
|
+
const flush = () => {
|
|
260
|
+
frameFlushScheduled = false;
|
|
261
|
+
flushBuffer(new Date());
|
|
262
|
+
};
|
|
263
|
+
if (typeof requestAnimationFrame === "function") {
|
|
264
|
+
requestAnimationFrame(flush);
|
|
265
|
+
} else {
|
|
266
|
+
setTimeout(flush, 0);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
for await (const update of messageUpdatesIterator) {
|
|
271
|
+
if ($isAborted) {
|
|
272
|
+
messageUpdatesAbortController.abort();
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Remove null characters added due to remote keylogging prevention
|
|
277
|
+
// See server code for more details
|
|
278
|
+
if (update.type === MessageUpdateType.Stream) {
|
|
279
|
+
update.token = update.token.replaceAll("\0", "");
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const isKeepAlive =
|
|
283
|
+
update.type === MessageUpdateType.Status &&
|
|
284
|
+
update.status === MessageUpdateStatus.KeepAlive;
|
|
285
|
+
|
|
286
|
+
if (!isKeepAlive) {
|
|
287
|
+
if (update.type === MessageUpdateType.Stream) {
|
|
288
|
+
const existingUpdates = messageToWriteTo.updates ?? [];
|
|
289
|
+
const lastUpdate = existingUpdates.at(-1);
|
|
290
|
+
if (lastUpdate?.type === MessageUpdateType.Stream) {
|
|
291
|
+
// Create fresh objects/arrays so the UI reacts to merged tokens
|
|
292
|
+
const merged = {
|
|
293
|
+
...lastUpdate,
|
|
294
|
+
token: (lastUpdate.token ?? "") + (update.token ?? ""),
|
|
295
|
+
};
|
|
296
|
+
messageToWriteTo.updates = [...existingUpdates.slice(0, -1), merged];
|
|
297
|
+
} else {
|
|
298
|
+
messageToWriteTo.updates = [...existingUpdates, update];
|
|
299
|
+
}
|
|
300
|
+
} else {
|
|
301
|
+
messageToWriteTo.updates = [...(messageToWriteTo.updates ?? []), update];
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const currentTime = new Date();
|
|
305
|
+
|
|
306
|
+
// If we receive a non-stream update (e.g. tool/status/final answer),
|
|
307
|
+
// flush any buffered stream tokens so the UI doesn't appear to cut
|
|
308
|
+
// mid-sentence while tools are running or the final answer arrives.
|
|
309
|
+
if (update.type !== MessageUpdateType.Stream && buffer.length > 0) {
|
|
310
|
+
flushBuffer(currentTime);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (update.type === MessageUpdateType.Stream) {
|
|
314
|
+
buffer += update.token;
|
|
315
|
+
if (streamingMode === "smooth") {
|
|
316
|
+
// Coalesce UI updates to animation frames for smooth mode.
|
|
317
|
+
scheduleFrameFlush();
|
|
318
|
+
} else if (
|
|
319
|
+
currentTime.getTime() - lastUpdateTime.getTime() >
|
|
320
|
+
updateDebouncer.maxUpdateTime
|
|
321
|
+
) {
|
|
322
|
+
flushBuffer(currentTime);
|
|
323
|
+
}
|
|
324
|
+
pending = false;
|
|
325
|
+
} else if (update.type === MessageUpdateType.FinalAnswer) {
|
|
326
|
+
// Mirror server-side merge behavior so the UI reflects the
|
|
327
|
+
// final text once tools complete, while preserving any
|
|
328
|
+
// pre‑tool streamed content when appropriate.
|
|
329
|
+
const finalText = update.text ?? "";
|
|
330
|
+
const isInterrupted = update.interrupted === true;
|
|
331
|
+
const hadTools =
|
|
332
|
+
messageToWriteTo.updates?.some((u) => u.type === MessageUpdateType.Tool) ?? false;
|
|
333
|
+
|
|
334
|
+
if (isInterrupted) {
|
|
335
|
+
// Preserve streamed content on abort. If we never streamed, fall back to finalText.
|
|
336
|
+
if (!messageToWriteTo.content) {
|
|
337
|
+
messageToWriteTo.content = finalText;
|
|
338
|
+
}
|
|
339
|
+
} else if (hadTools) {
|
|
340
|
+
const existing = messageToWriteTo.content;
|
|
341
|
+
const trimmedExistingSuffix = existing.replace(/\s+$/, "");
|
|
342
|
+
const trimmedFinalPrefix = finalText.replace(/^\s+/, "");
|
|
343
|
+
const alreadyStreamed =
|
|
344
|
+
finalText &&
|
|
345
|
+
(existing.endsWith(finalText) ||
|
|
346
|
+
(trimmedFinalPrefix.length > 0 &&
|
|
347
|
+
trimmedExistingSuffix.endsWith(trimmedFinalPrefix)));
|
|
348
|
+
|
|
349
|
+
if (existing && existing.length > 0) {
|
|
350
|
+
if (alreadyStreamed) {
|
|
351
|
+
// A. Already streamed the same final text; keep as-is.
|
|
352
|
+
messageToWriteTo.content = existing;
|
|
353
|
+
} else if (
|
|
354
|
+
finalText &&
|
|
355
|
+
(finalText.startsWith(existing) ||
|
|
356
|
+
(trimmedExistingSuffix.length > 0 &&
|
|
357
|
+
trimmedFinalPrefix.startsWith(trimmedExistingSuffix)))
|
|
358
|
+
) {
|
|
359
|
+
// B. Final text already includes streamed prefix; use it verbatim.
|
|
360
|
+
messageToWriteTo.content = finalText;
|
|
361
|
+
} else {
|
|
362
|
+
// C. Merge with a paragraph break for readability.
|
|
363
|
+
const needsGap = !/\n\n$/.test(existing) && !/^\n/.test(finalText ?? "");
|
|
364
|
+
messageToWriteTo.content = existing + (needsGap ? "\n\n" : "") + finalText;
|
|
365
|
+
}
|
|
366
|
+
} else {
|
|
367
|
+
messageToWriteTo.content = finalText;
|
|
368
|
+
}
|
|
369
|
+
} else {
|
|
370
|
+
// No tools: final answer replaces streamed content so
|
|
371
|
+
// the provider's final text is authoritative.
|
|
372
|
+
messageToWriteTo.content = finalText;
|
|
373
|
+
}
|
|
374
|
+
} else if (
|
|
375
|
+
update.type === MessageUpdateType.Status &&
|
|
376
|
+
update.status === MessageUpdateStatus.Error
|
|
377
|
+
) {
|
|
378
|
+
// Check if this is a 402 payment required error
|
|
379
|
+
if (update.statusCode === 402) {
|
|
380
|
+
showSubscribeModal = true;
|
|
381
|
+
} else {
|
|
382
|
+
$error = update.message ?? "An error has occurred";
|
|
383
|
+
}
|
|
384
|
+
} else if (update.type === MessageUpdateType.Title) {
|
|
385
|
+
const convInData = conversations.find(({ id }) => id === page.params.id);
|
|
386
|
+
if (convInData) {
|
|
387
|
+
convInData.title = update.title;
|
|
388
|
+
|
|
389
|
+
$titleUpdate = {
|
|
390
|
+
title: update.title,
|
|
391
|
+
convId,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
} else if (update.type === MessageUpdateType.File) {
|
|
395
|
+
messageToWriteTo.files = [
|
|
396
|
+
...(messageToWriteTo.files ?? []),
|
|
397
|
+
{ type: "hash", value: update.sha, mime: update.mime, name: update.name },
|
|
398
|
+
];
|
|
399
|
+
} else if (update.type === MessageUpdateType.RouterMetadata) {
|
|
400
|
+
// Update router metadata immediately when received
|
|
401
|
+
messageToWriteTo.routerMetadata = {
|
|
402
|
+
route: update.route,
|
|
403
|
+
model: update.model,
|
|
404
|
+
};
|
|
405
|
+
} else if (update.type === MessageUpdateType.AutopilotStep) {
|
|
406
|
+
// Track autopilot step progress — stored on updates array for UI rendering
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (buffer.length > 0) {
|
|
411
|
+
flushBuffer(new Date());
|
|
412
|
+
}
|
|
413
|
+
} catch (err) {
|
|
414
|
+
if (err instanceof Error && err.message.includes("overloaded")) {
|
|
415
|
+
$error = "Too much traffic, please try again.";
|
|
416
|
+
} else if (err instanceof Error && err.message.includes("429")) {
|
|
417
|
+
$error = ERROR_MESSAGES.rateLimited;
|
|
418
|
+
} else if (err instanceof Error) {
|
|
419
|
+
$error = err.message;
|
|
420
|
+
} else {
|
|
421
|
+
$error = ERROR_MESSAGES.default;
|
|
422
|
+
}
|
|
423
|
+
console.error(err);
|
|
424
|
+
} finally {
|
|
425
|
+
$loading = false;
|
|
426
|
+
pending = false;
|
|
427
|
+
await invalidateAll();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async function stopGeneration() {
|
|
432
|
+
stopRequested = true;
|
|
433
|
+
$isAborted = true;
|
|
434
|
+
$loading = false;
|
|
435
|
+
|
|
436
|
+
const sendStopRequest = async () => {
|
|
437
|
+
const response = await fetch(`${base}/conversation/${page.params.id}/stop-generating`, {
|
|
438
|
+
method: "POST",
|
|
439
|
+
});
|
|
440
|
+
if (!response.ok) {
|
|
441
|
+
throw new Error(`Stop request failed: ${response.status}`);
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
try {
|
|
446
|
+
await sendStopRequest();
|
|
447
|
+
} catch (firstErr) {
|
|
448
|
+
try {
|
|
449
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
450
|
+
await sendStopRequest();
|
|
451
|
+
} catch (retryErr) {
|
|
452
|
+
console.error("Failed to stop generation", firstErr, retryErr);
|
|
453
|
+
$error = "Failed to stop generation. Please try again.";
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
459
|
+
// Stop generation on ESC key when loading
|
|
460
|
+
if (event.key === "Escape" && $loading) {
|
|
461
|
+
event.preventDefault();
|
|
462
|
+
stopGeneration();
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
onMount(async () => {
|
|
467
|
+
if ($pendingMessage) {
|
|
468
|
+
files = $pendingMessage.files;
|
|
469
|
+
await writeMessage({ prompt: $pendingMessage.content });
|
|
470
|
+
$pendingMessage = undefined;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const streaming = isConversationGenerationActive(messages);
|
|
474
|
+
if (streaming) {
|
|
475
|
+
addBackgroundGeneration({ id: convId, startedAt: Date.now() });
|
|
476
|
+
$loading = true;
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
async function onMessage(content: string) {
|
|
481
|
+
await writeMessage({ prompt: content });
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
async function onRetry(payload: { id: Message["id"]; content?: string }) {
|
|
485
|
+
if (requireAuthUser()) return;
|
|
486
|
+
|
|
487
|
+
const lastMsgId = payload.id;
|
|
488
|
+
messagesPath = createMessagesPath(messages, lastMsgId);
|
|
489
|
+
|
|
490
|
+
await writeMessage({
|
|
491
|
+
prompt: payload.content,
|
|
492
|
+
messageId: payload.id,
|
|
493
|
+
isRetry: true,
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
async function onShowAlternateMsg(payload: { id: Message["id"] }) {
|
|
498
|
+
const msgId = payload.id;
|
|
499
|
+
messagesPath = createMessagesPath(messages, msgId);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const settings = useSettingsStore();
|
|
503
|
+
let messages = $state(data.messages);
|
|
504
|
+
$effect(() => {
|
|
505
|
+
messages = data.messages;
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
$effect(() => {
|
|
509
|
+
page.params.id;
|
|
510
|
+
stopRequested = false;
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
$effect(() => {
|
|
514
|
+
const streaming = isConversationGenerationActive(messages);
|
|
515
|
+
if (stopRequested) {
|
|
516
|
+
$loading = false;
|
|
517
|
+
} else if (streaming) {
|
|
518
|
+
$loading = true;
|
|
519
|
+
} else if (!pending) {
|
|
520
|
+
$loading = false;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
if (!streaming && browser) {
|
|
524
|
+
removeBackgroundGeneration(convId);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
// create a linear list of `messagesPath` from `messages` that is a tree of threaded messages
|
|
529
|
+
let messagesPath = $derived(createMessagesPath(messages));
|
|
530
|
+
let messagesAlternatives = $derived(createMessagesAlternatives(messages));
|
|
531
|
+
|
|
532
|
+
$effect(() => {
|
|
533
|
+
if (browser && messagesPath.at(-1)?.id) {
|
|
534
|
+
localStorage.setItem("leafId", messagesPath.at(-1)?.id as string);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
beforeNavigate((navigation) => {
|
|
539
|
+
if (!page.params.id) return;
|
|
540
|
+
|
|
541
|
+
const navigatingAway =
|
|
542
|
+
navigation.to?.route.id !== page.route.id || navigation.to?.params?.id !== page.params.id;
|
|
543
|
+
|
|
544
|
+
if ($loading && navigatingAway) {
|
|
545
|
+
addBackgroundGeneration({ id: page.params.id, startedAt: Date.now() });
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
$isAborted = true;
|
|
549
|
+
$loading = false;
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
let title = $derived.by(() => {
|
|
553
|
+
const rawTitle = conversations.find((conv) => conv.id === page.params.id)?.title ?? data.title;
|
|
554
|
+
return rawTitle ? rawTitle.charAt(0).toUpperCase() + rawTitle.slice(1) : rawTitle;
|
|
555
|
+
});
|
|
556
|
+
</script>
|
|
557
|
+
|
|
558
|
+
<svelte:window onkeydown={handleKeydown} />
|
|
559
|
+
|
|
560
|
+
<svelte:head>
|
|
561
|
+
<title>{title}</title>
|
|
562
|
+
</svelte:head>
|
|
563
|
+
|
|
564
|
+
<ChatWindow
|
|
565
|
+
loading={$loading}
|
|
566
|
+
{pending}
|
|
567
|
+
messages={messagesPath as Message[]}
|
|
568
|
+
{messagesAlternatives}
|
|
569
|
+
shared={data.shared}
|
|
570
|
+
preprompt={data.preprompt}
|
|
571
|
+
bind:files
|
|
572
|
+
onmessage={onMessage}
|
|
573
|
+
onretry={onRetry}
|
|
574
|
+
onshowAlternateMsg={onShowAlternateMsg}
|
|
575
|
+
onstop={stopGeneration}
|
|
576
|
+
models={data.models}
|
|
577
|
+
currentModel={findCurrentModel(data.models, data.oldModels, data.model)}
|
|
578
|
+
/>
|
|
579
|
+
|
|
580
|
+
{#if showSubscribeModal}
|
|
581
|
+
<SubscribeModal close={() => (showSubscribeModal = false)} />
|
|
582
|
+
{/if}
|