diff --git a/tools/server/webui/src/lib/constants/attachment-labels.ts b/tools/server/webui/src/lib/constants/attachment-labels.ts new file mode 100644 index 0000000000..2a32e4e18b --- /dev/null +++ b/tools/server/webui/src/lib/constants/attachment-labels.ts @@ -0,0 +1,3 @@ +export const ATTACHMENT_LABEL_FILE = 'File'; +export const ATTACHMENT_LABEL_PDF_FILE = 'PDF File'; +export const ATTACHMENT_LABEL_MCP_PROMPT = 'MCP Prompt'; diff --git a/tools/server/webui/src/lib/constants/code-blocks.ts b/tools/server/webui/src/lib/constants/code-blocks.ts new file mode 100644 index 0000000000..0f7265104d --- /dev/null +++ b/tools/server/webui/src/lib/constants/code-blocks.ts @@ -0,0 +1,8 @@ +export const CODE_BLOCK_SCROLL_CONTAINER_CLASS = 'code-block-scroll-container'; +export const CODE_BLOCK_WRAPPER_CLASS = 'code-block-wrapper'; +export const CODE_BLOCK_HEADER_CLASS = 'code-block-header'; +export const CODE_BLOCK_ACTIONS_CLASS = 'code-block-actions'; +export const CODE_LANGUAGE_CLASS = 'code-language'; +export const COPY_CODE_BTN_CLASS = 'copy-code-btn'; +export const PREVIEW_CODE_BTN_CLASS = 'preview-code-btn'; +export const RELATIVE_CLASS = 'relative'; diff --git a/tools/server/webui/src/lib/markdown/enhance-code-blocks.ts b/tools/server/webui/src/lib/markdown/enhance-code-blocks.ts index 02cdff3974..168de97403 100644 --- a/tools/server/webui/src/lib/markdown/enhance-code-blocks.ts +++ b/tools/server/webui/src/lib/markdown/enhance-code-blocks.ts @@ -13,6 +13,16 @@ import type { Plugin } from 'unified'; import type { Root, Element, ElementContent } from 'hast'; import { visit } from 'unist-util-visit'; +import { + CODE_BLOCK_SCROLL_CONTAINER_CLASS, + CODE_BLOCK_WRAPPER_CLASS, + CODE_BLOCK_HEADER_CLASS, + CODE_BLOCK_ACTIONS_CLASS, + CODE_LANGUAGE_CLASS, + COPY_CODE_BTN_CLASS, + PREVIEW_CODE_BTN_CLASS, + RELATIVE_CLASS +} from '$lib/constants/code-blocks'; declare global { interface Window { @@ -42,7 +52,7 @@ function createCopyButton(codeId: string): Element { type: 'element', tagName: 'button', properties: { - className: ['copy-code-btn'], + className: [COPY_CODE_BTN_CLASS], 'data-code-id': codeId, title: 'Copy code', type: 'button' @@ -56,7 +66,7 @@ function createPreviewButton(codeId: string): Element { type: 'element', tagName: 'button', properties: { - className: ['preview-code-btn'], + className: [PREVIEW_CODE_BTN_CLASS], 'data-code-id': codeId, title: 'Preview code', type: 'button' @@ -75,18 +85,18 @@ function createHeader(language: string, codeId: string): Element { return { type: 'element', tagName: 'div', - properties: { className: ['code-block-header'] }, + properties: { className: [CODE_BLOCK_HEADER_CLASS] }, children: [ { type: 'element', tagName: 'span', - properties: { className: ['code-language'] }, + properties: { className: [CODE_LANGUAGE_CLASS] }, children: [{ type: 'text', value: language }] }, { type: 'element', tagName: 'div', - properties: { className: ['code-block-actions'] }, + properties: { className: [CODE_BLOCK_ACTIONS_CLASS] }, children: actions } ] @@ -97,7 +107,7 @@ function createScrollContainer(preElement: Element): Element { return { type: 'element', tagName: 'div', - properties: { className: ['code-block-scroll-container'] }, + properties: { className: [CODE_BLOCK_SCROLL_CONTAINER_CLASS] }, children: [preElement] }; } @@ -106,7 +116,7 @@ function createWrapper(header: Element, preElement: Element): Element { return { type: 'element', tagName: 'div', - properties: { className: ['code-block-wrapper', 'relative'] }, + properties: { className: [CODE_BLOCK_WRAPPER_CLASS, RELATIVE_CLASS] }, children: [header, createScrollContainer(preElement)] }; } diff --git a/tools/server/webui/src/lib/services/chat.service.ts b/tools/server/webui/src/lib/services/chat.service.ts index ebdd4374f8..9abe0515ff 100644 --- a/tools/server/webui/src/lib/services/chat.service.ts +++ b/tools/server/webui/src/lib/services/chat.service.ts @@ -1,5 +1,9 @@ import { getJsonHeaders, formatAttachmentText, isAbortError } from '$lib/utils'; import { AGENTIC_REGEX } from '$lib/constants/agentic'; +import { + ATTACHMENT_LABEL_PDF_FILE, + ATTACHMENT_LABEL_MCP_PROMPT +} from '$lib/constants/attachment-labels'; import { AttachmentType, ContentPartType, MessageRole, ReasoningFormat } from '$lib/enums'; import type { ApiChatMessageContentPart, ApiChatCompletionToolCall } from '$lib/types/api'; import type { DatabaseMessageExtraMcpPrompt } from '$lib/types'; @@ -764,7 +768,7 @@ export class ChatService { } else { contentParts.push({ type: ContentPartType.TEXT, - text: formatAttachmentText('PDF File', pdfFile.name, pdfFile.content) + text: formatAttachmentText(ATTACHMENT_LABEL_PDF_FILE, pdfFile.name, pdfFile.content) }); } } @@ -778,7 +782,7 @@ export class ChatService { contentParts.push({ type: ContentPartType.TEXT, text: formatAttachmentText( - 'MCP Prompt', + ATTACHMENT_LABEL_MCP_PROMPT, mcpPrompt.name, mcpPrompt.content, mcpPrompt.serverName diff --git a/tools/server/webui/src/lib/stores/chat.svelte.ts b/tools/server/webui/src/lib/stores/chat.svelte.ts index 869206aa70..7bb5e3b5f4 100644 --- a/tools/server/webui/src/lib/stores/chat.svelte.ts +++ b/tools/server/webui/src/lib/stores/chat.svelte.ts @@ -432,7 +432,7 @@ class ChatStore { return await DatabaseService.createMessageBranch( { convId: activeConv.id, - type: 'text', + type: MessageType.TEXT, role: MessageRole.ASSISTANT, content: '', timestamp: Date.now(), @@ -1234,7 +1234,7 @@ class ChatStore { const assistantMessage = await DatabaseService.createMessageBranch( { convId: activeConv.id, - type: 'text', + type: MessageType.TEXT, timestamp: Date.now(), role: MessageRole.ASSISTANT, content: '',