From 493ef087231efd2acca05e02b0460ca1bff25397 Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Sat, 29 Nov 2025 02:33:37 +0100 Subject: [PATCH] refactor: Utils imports + move types to `app.d.ts` --- tools/server/webui/src/app.d.ts | 58 +++++++++---- .../ChatAttachmentPreview.svelte | 12 ++- .../ChatAttachmentThumbnailFile.svelte | 5 +- .../ChatAttachmentsList.svelte | 4 +- .../ChatAttachmentsViewAll.svelte | 4 +- .../app/chat/ChatForm/ChatForm.svelte | 4 +- .../ChatFormActions/ChatFormActions.svelte | 3 +- .../ChatFormFileInputInvisible.svelte | 2 +- .../app/chat/ChatForm/ChatFormTextarea.svelte | 2 +- .../app/chat/ChatMessages/ChatMessage.svelte | 4 +- .../ChatMessages/ChatMessageAssistant.svelte | 4 +- .../chat/ChatMessages/ChatMessageUser.svelte | 2 +- .../app/chat/ChatMessages/ChatMessages.svelte | 2 +- .../app/chat/ChatScreen/ChatScreen.svelte | 6 +- .../ChatSettingsImportExportTab.svelte | 3 +- .../DialogChatAttachmentPreview.svelte | 3 +- .../app/dialogs/DialogModelInformation.svelte | 3 +- .../app/misc/BadgeChatStatistic.svelte | 2 +- .../app/misc/CopyToClipboardIcon.svelte | 2 +- .../app/misc/MarkdownContent.svelte | 3 +- .../app/models/ModelsSelector.svelte | 3 +- .../use-model-change-validation.svelte.ts | 1 - tools/server/webui/src/lib/services/chat.ts | 22 +---- .../server/webui/src/lib/services/database.ts | 2 +- tools/server/webui/src/lib/services/models.ts | 10 +-- .../src/lib/services/parameter-sync.spec.ts | 1 - .../webui/src/lib/services/parameter-sync.ts | 3 +- tools/server/webui/src/lib/services/props.ts | 2 +- .../webui/src/lib/stores/chat.svelte.ts | 19 ++-- .../src/lib/stores/conversations.svelte.ts | 9 +- .../webui/src/lib/stores/models.svelte.ts | 6 +- .../webui/src/lib/stores/settings.svelte.ts | 8 +- tools/server/webui/src/lib/types/index.ts | 70 +++++++++++++++ .../webui/src/lib/utils/attachment-display.ts | 5 +- .../webui/src/lib/utils/attachment-type.ts | 3 +- .../webui/src/lib/utils/browser-only.ts | 35 ++++++++ .../webui/src/lib/utils/config-helpers.ts | 2 - .../src/lib/utils/convert-files-to-extra.ts | 2 +- tools/server/webui/src/lib/utils/index.ts | 87 +++++++++++++++++++ .../src/lib/utils/modality-file-validation.ts | 2 +- .../src/lib/utils/process-uploaded-files.ts | 4 +- tools/server/webui/src/routes/+page.ts | 2 +- .../webui/src/routes/chat/[id]/+page.ts | 2 +- .../src/stories/ChatSidebar.stories.svelte | 2 +- 44 files changed, 292 insertions(+), 138 deletions(-) create mode 100644 tools/server/webui/src/lib/types/index.ts create mode 100644 tools/server/webui/src/lib/utils/browser-only.ts create mode 100644 tools/server/webui/src/lib/utils/index.ts diff --git a/tools/server/webui/src/app.d.ts b/tools/server/webui/src/app.d.ts index a15d1f0d02..71976936ed 100644 --- a/tools/server/webui/src/app.d.ts +++ b/tools/server/webui/src/app.d.ts @@ -4,14 +4,19 @@ // Import chat types from dedicated module import type { + // API types ApiChatCompletionRequest, ApiChatCompletionResponse, ApiChatCompletionStreamChunk, + ApiChatCompletionToolCall, + ApiChatCompletionToolCallDelta, ApiChatMessageData, ApiChatMessageContentPart, ApiContextSizeError, ApiErrorResponse, ApiLlamaCppServerProps, + ApiModelDataEntry, + ApiModelListResponse, ApiProcessingState, ApiRouterModelMeta, ApiRouterModelsLoadRequest, @@ -20,21 +25,17 @@ import type { ApiRouterModelsStatusResponse, ApiRouterModelsListResponse, ApiRouterModelsUnloadRequest, - ApiRouterModelsUnloadResponse -} from '$lib/types/api'; - -import { ServerRole, ServerModelStatus, ModelModality } from '$lib/enums'; - -import type { + ApiRouterModelsUnloadResponse, + // Chat types + ChatAttachmentDisplayItem, + ChatAttachmentPreviewItem, ChatMessageType, ChatRole, ChatUploadedFile, ChatMessageSiblingInfo, ChatMessagePromptProgress, - ChatMessageTimings -} from '$lib/types/chat'; - -import type { + ChatMessageTimings, + // Database types DatabaseConversation, DatabaseMessage, DatabaseMessageExtra, @@ -42,14 +43,20 @@ import type { DatabaseMessageExtraImageFile, DatabaseMessageExtraTextFile, DatabaseMessageExtraPdfFile, - DatabaseMessageExtraLegacyContext -} from '$lib/types/database'; - -import type { + DatabaseMessageExtraLegacyContext, + ExportedConversation, + ExportedConversations, + // Model types + ModelModalities, + ModelOption, + // Settings types + SettingsChatServiceOptions, SettingsConfigValue, SettingsFieldConfig, SettingsConfigType -} from '$lib/types/settings'; +} from '$lib/types'; + +import { ServerRole, ServerModelStatus, ModelModality } from '$lib/enums'; declare global { // namespace App { @@ -61,14 +68,19 @@ declare global { // } export { + // API types ApiChatCompletionRequest, ApiChatCompletionResponse, ApiChatCompletionStreamChunk, + ApiChatCompletionToolCall, + ApiChatCompletionToolCallDelta, ApiChatMessageData, ApiChatMessageContentPart, ApiContextSizeError, ApiErrorResponse, ApiLlamaCppServerProps, + ApiModelDataEntry, + ApiModelListResponse, ApiProcessingState, ApiRouterModelMeta, ApiRouterModelsLoadRequest, @@ -78,13 +90,16 @@ declare global { ApiRouterModelsListResponse, ApiRouterModelsUnloadRequest, ApiRouterModelsUnloadResponse, - ChatMessageData, + // Chat types + ChatAttachmentDisplayItem, + ChatAttachmentPreviewItem, ChatMessagePromptProgress, ChatMessageSiblingInfo, ChatMessageTimings, ChatMessageType, ChatRole, ChatUploadedFile, + // Database types DatabaseConversation, DatabaseMessage, DatabaseMessageExtra, @@ -93,12 +108,19 @@ declare global { DatabaseMessageExtraTextFile, DatabaseMessageExtraPdfFile, DatabaseMessageExtraLegacyContext, + ExportedConversation, + ExportedConversations, + // Enum types ModelModality, ServerRole, ServerModelStatus, + // Model types + ModelModalities, + ModelOption, + // Settings types + SettingsChatServiceOptions, SettingsConfigValue, SettingsFieldConfig, - SettingsConfigType, - SettingsChatServiceOptions + SettingsConfigType }; } diff --git a/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentPreview.svelte b/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentPreview.svelte index ea8b330d68..b5fe3fa9c4 100644 --- a/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentPreview.svelte +++ b/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentPreview.svelte @@ -3,10 +3,14 @@ import * as Alert from '$lib/components/ui/alert'; import { SyntaxHighlightedCode } from '$lib/components/app'; import { FileText, Image, Music, FileIcon, Eye, Info } from '@lucide/svelte'; - import type { DatabaseMessageExtra } from '$lib/types/database'; - import { convertPDFToImage } from '$lib/utils/pdf-processing'; - import { isTextFile, isImageFile, isPdfFile, isAudioFile } from '$lib/utils/attachment-type'; - import { getLanguageFromFilename } from '$lib/utils/syntax-highlight-language'; + import { + isTextFile, + isImageFile, + isPdfFile, + isAudioFile, + getLanguageFromFilename + } from '$lib/utils'; + import { convertPDFToImage } from '$lib/utils/browser-only'; import { modelsStore } from '$lib/stores/models.svelte'; interface Props { diff --git a/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentThumbnailFile.svelte b/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentThumbnailFile.svelte index 73ef7852e1..6fdd857214 100644 --- a/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentThumbnailFile.svelte +++ b/tools/server/webui/src/lib/components/app/chat/ChatAttachments/ChatAttachmentThumbnailFile.svelte @@ -1,9 +1,6 @@