From e6b488a6ed9d1e94c9b45e5a8154af4a56af2a31 Mon Sep 17 00:00:00 2001 From: Aleksander Grygier Date: Tue, 11 Aug 2026 16:37:18 +0200 Subject: [PATCH] refactor: Clean up UI types --- .../app/chat/ChatForm/ChatForm.svelte | 4 +- ....svelte => ChatFormContentEditable.svelte} | 5 +- .../ContextGaugeDial.svelte | 2 +- .../ChatFormContextGauge/context-gauge.ts | 22 +++--- .../ChatFormMentionPicker.svelte | 4 +- .../ChatForm/ChatFormWorkingDirectory.svelte | 2 +- .../ChatMessageToolCallBlock.svelte | 8 +- .../ChatMessageToolCallBlockDefault.svelte | 2 +- .../ChatMessageToolCallBlockEditFile.svelte | 3 +- ...essageToolCallBlockExecShellCommand.svelte | 5 +- ...tMessageToolCallBlockFileGlobSearch.svelte | 3 +- ...ChatMessageToolCallBlockGetDatetime.svelte | 2 +- .../ChatMessageToolCallBlockGetInfo.svelte | 3 +- .../ChatMessageToolCallBlockGrepSearch.svelte | 3 +- .../ChatMessageToolCallBlockReadFile.svelte | 2 +- ...atMessageToolCallBlockRunJavascript.svelte | 3 +- ...atMessageToolCallBlockSearchResults.svelte | 5 +- .../ChatMessageToolCallBlockWriteFile.svelte | 3 +- .../ChatMessageToolCall/ToolCallBlock.svelte | 3 +- .../ChatMessageToolCall/parsers/_shared.ts | 2 +- .../ChatMessageToolCall/parsers/edit-file.ts | 3 +- .../parsers/exec-shell-command.ts | 2 +- .../parsers/file-glob-search.ts | 3 +- .../parsers/grep-search.ts | 3 +- .../ChatMessageToolCall/parsers/read-file.ts | 3 +- .../parsers/run-javascript.ts | 2 +- .../ChatMessageToolCall/parsers/write-file.ts | 3 +- .../ChatMessageAgenticContent.svelte | 3 +- .../ChatMessageReasoningBlock.svelte | 2 +- tools/ui/src/lib/components/app/chat/index.ts | 4 +- tools/ui/src/lib/enums/chat.enums.ts | 10 +++ tools/ui/src/lib/enums/index.ts | 12 ++- tools/ui/src/lib/enums/ui.enums.ts | 10 +++ .../src/lib/hooks/use-context-gauge.svelte.ts | 7 +- tools/ui/src/lib/types/agentic.d.ts | 60 ++++++++++++++- tools/ui/src/lib/types/contenteditable.d.ts | 11 +++ tools/ui/src/lib/types/glob.d.ts | 67 +++++++++++++++++ tools/ui/src/lib/types/index.ts | 21 +++++- tools/ui/src/lib/types/search.d.ts | 10 +++ tools/ui/src/lib/utils/agentic.ts | 53 +------------ .../lib/utils/contenteditable-tokenizer.ts | 71 ++++++++++-------- tools/ui/src/lib/utils/glob-search.ts | 46 +++--------- tools/ui/src/lib/utils/index.ts | 20 +---- tools/ui/src/lib/utils/search-results.ts | 10 +-- tools/ui/src/lib/utils/working-directory.ts | 17 +---- ...form-contenteditable-blocks.svelte.test.ts | 18 ++--- ...t-form-contenteditable-undo.svelte.test.ts | 20 ++--- .../chat-form-contenteditable.svelte.test.ts | 74 +++++++++---------- ... => ChatFormContentEditableHarness.svelte} | 6 +- .../tests/unit/assistant-raw-output.test.ts | 3 +- tools/ui/tests/unit/tool-calls.test.ts | 2 +- 51 files changed, 378 insertions(+), 284 deletions(-) rename tools/ui/src/lib/components/app/chat/ChatForm/{ChatFormContenteditable.svelte => ChatFormContentEditable.svelte} (99%) create mode 100644 tools/ui/src/lib/types/contenteditable.d.ts create mode 100644 tools/ui/src/lib/types/glob.d.ts create mode 100644 tools/ui/src/lib/types/search.d.ts rename tools/ui/tests/client/components/{ChatFormContenteditableHarness.svelte => ChatFormContentEditableHarness.svelte} (65%) diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte index bc1befd633..9921d8d88d 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatForm.svelte @@ -3,7 +3,7 @@ import { ChatAttachmentsList, ChatFormActions, - ChatFormContenteditable, + ChatFormContentEditable, ChatFormFileInputInvisible, ChatFormMcpResourcesList, ChatFormPickers, @@ -605,7 +605,7 @@ class="flex-column relative min-h-12 items-center rounded-4xl md:rounded-3xl py-2 pb-2.25 shadow-sm transition-all focus-within:shadow-md md:py-3!" > {#if useContenteditable} - - import type { ColorLevel } from './context-gauge'; import { colorLevelTextClass } from './context-gauge'; + import type { ColorLevel } from '$lib/enums'; interface Props { percent: number | null; diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/context-gauge.ts b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/context-gauge.ts index 42aab668e6..e0a7f74780 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/context-gauge.ts +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormContextGauge/context-gauge.ts @@ -1,25 +1,25 @@ -export type ColorLevel = 'ok' | 'warning' | 'critical' | 'neutral'; +import { ColorLevel } from '$lib/enums'; const WARNING_THRESHOLD = 80; const CRITICAL_THRESHOLD = 95; export function colorLevelFromPercent(percent: number | null): ColorLevel { - if (percent === null) return 'neutral'; + if (percent === null) return ColorLevel.NEUTRAL; - if (percent >= CRITICAL_THRESHOLD) return 'critical'; + if (percent >= CRITICAL_THRESHOLD) return ColorLevel.CRITICAL; - if (percent >= WARNING_THRESHOLD) return 'warning'; + if (percent >= WARNING_THRESHOLD) return ColorLevel.WARNING; - return 'ok'; + return ColorLevel.OK; } export function colorLevelTextClass(level: ColorLevel): string { switch (level) { - case 'critical': + case ColorLevel.CRITICAL: return 'text-red-400'; - case 'warning': + case ColorLevel.WARNING: return 'text-amber-400'; - case 'ok': + case ColorLevel.OK: return 'text-muted-foreground'; default: return 'text-muted-foreground'; @@ -28,11 +28,11 @@ export function colorLevelTextClass(level: ColorLevel): string { export function colorLevelBgClass(level: ColorLevel): string { switch (level) { - case 'critical': + case ColorLevel.CRITICAL: return 'bg-red-500'; - case 'warning': + case ColorLevel.WARNING: return 'bg-amber-500'; - case 'ok': + case ColorLevel.OK: return 'bg-green-500'; default: return 'bg-muted'; diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormMentionPicker.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormMentionPicker.svelte index 86a9fb81cd..6a2be8cffd 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormMentionPicker.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormPickers/ChatFormMentionPicker.svelte @@ -11,8 +11,8 @@ import { config } from '$lib/stores/settings.svelte'; import { toolsStore } from '$lib/stores/tools.svelte'; import { isMobile } from '$lib/stores/viewport.svelte'; - import type { FileMentionEntry } from '$lib/types'; - import { abbreviateHome, type GlobEntryResult, runGlobSearchWithChildren } from '$lib/utils'; + import type { FileMentionEntry, GlobEntryResult } from '$lib/types'; + import { abbreviateHome, runGlobSearchWithChildren } from '$lib/utils'; /** * Floating file/folder mention picker. The chat input is the search diff --git a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormWorkingDirectory.svelte b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormWorkingDirectory.svelte index 27bc40b24a..639ddb5247 100644 --- a/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormWorkingDirectory.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatForm/ChatFormWorkingDirectory.svelte @@ -11,10 +11,10 @@ import { useScrollActiveRow } from '$lib/hooks/use-scroll-active-row.svelte'; import { ToolsService } from '$lib/services/tools.service'; import { toolsStore } from '$lib/stores/tools.svelte'; + import type { GlobEntry } from '$lib/types'; import { abbreviateHome, buildCaseInsensitiveGlob, - type GlobEntry, joinPath, lastPathSegment, runGlobSearchWithChildren diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlock.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlock.svelte index 5bbaa4ea31..d0d8684e17 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlock.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlock.svelte @@ -11,13 +11,9 @@ import ChatMessageToolCallBlockSearchResults from './ChatMessageToolCallBlockSearchResults.svelte'; import ChatMessageToolCallBlockWriteFile from './ChatMessageToolCallBlockWriteFile.svelte'; import { BuiltInTool } from '$lib/enums'; + import type { AgenticSection } from '$lib/types'; import type { DatabaseMessageExtra } from '$lib/types'; - import { - type AgenticSection, - extractSearchQuery, - extractSearchResults, - isWebSearchToolName - } from '$lib/utils'; + import { extractSearchQuery, extractSearchResults, isWebSearchToolName } from '$lib/utils'; interface Props { section: AgenticSection; diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte index 4608232fa6..9009eae3d2 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockDefault.svelte @@ -8,9 +8,9 @@ import { MarkdownContent, SyntaxHighlightedCode } from '$lib/components/app'; import { MAX_HEIGHT_CODE_BLOCK } from '$lib/constants'; import { FileTypeText, ToolResultKind } from '$lib/enums'; + import type { AgenticSection } from '$lib/types'; import type { DatabaseMessageExtra } from '$lib/types'; import { - type AgenticSection, classifyToolResult, formatJsonPretty, getBuiltinToolUi, diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockEditFile.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockEditFile.svelte index 5ee9d4936e..6b95a92fb2 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockEditFile.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockEditFile.svelte @@ -4,7 +4,8 @@ import { XCircle } from '@lucide/svelte'; import { MAX_HEIGHT_CODE_BLOCK, RESULT_STAT_SEPARATOR } from '$lib/constants'; import { toolsStore } from '$lib/stores/tools.svelte'; - import { abbreviateHome, type AgenticSection, computeLineDiff, prefixFor } from '$lib/utils'; + import type { AgenticSection } from '$lib/types'; + import { abbreviateHome, computeLineDiff, prefixFor } from '$lib/utils'; interface Props { section: AgenticSection; diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte index 0ac559a73d..2c1d70315f 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockExecShellCommand.svelte @@ -13,17 +13,16 @@ import { SETTINGS_KEYS, TOOL_RUNTIME_SCROLL_AT_BOTTOM_THRESHOLD_PX } from '$lib/constants'; import { config } from '$lib/stores/settings.svelte'; import { toolsStore } from '$lib/stores/tools.svelte'; + import type { AgenticSection, ToolResultLine } from '$lib/types'; import type { DatabaseMessageExtra } from '$lib/types'; import { abbreviateHome, - type AgenticSection, type ExecShellExitStatus, highlightCode, isExitCodeSummaryLine, parseExecShellCommandError, parseExecShellCommandExitStatus, - parseToolResultWithImages, - type ToolResultLine + parseToolResultWithImages } from '$lib/utils'; interface Props { diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockFileGlobSearch.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockFileGlobSearch.svelte index 37f7350fb7..66eb3a2ad6 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockFileGlobSearch.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockFileGlobSearch.svelte @@ -3,7 +3,8 @@ import ToolCallBlock from './ToolCallBlock.svelte'; import { XCircle } from '@lucide/svelte'; import { toolsStore } from '$lib/stores/tools.svelte'; - import { abbreviateHome, type AgenticSection } from '$lib/utils'; + import type { AgenticSection } from '$lib/types'; + import { abbreviateHome } from '$lib/utils'; interface Props { section: AgenticSection; diff --git a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockGetDatetime.svelte b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockGetDatetime.svelte index 4c525daa7b..23de7cbd6c 100644 --- a/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockGetDatetime.svelte +++ b/tools/ui/src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/ChatMessageToolCallBlockGetDatetime.svelte @@ -1,7 +1,7 @@ - + diff --git a/tools/ui/tests/unit/assistant-raw-output.test.ts b/tools/ui/tests/unit/assistant-raw-output.test.ts index ec75a0e492..d13b796c43 100644 --- a/tools/ui/tests/unit/assistant-raw-output.test.ts +++ b/tools/ui/tests/unit/assistant-raw-output.test.ts @@ -1,6 +1,7 @@ import { REASONING_TAGS } from '$lib/constants'; import { AgenticSectionType } from '$lib/enums'; -import { type AgenticSection, buildAssistantRawOutput } from '$lib/utils/agentic'; +import type { AgenticSection } from '$lib/types/agentic'; +import { buildAssistantRawOutput } from '$lib/utils/agentic'; import { describe, expect, it } from 'vitest'; function makeSection( diff --git a/tools/ui/tests/unit/tool-calls.test.ts b/tools/ui/tests/unit/tool-calls.test.ts index 3349b7ab6e..b0ec76be41 100644 --- a/tools/ui/tests/unit/tool-calls.test.ts +++ b/tools/ui/tests/unit/tool-calls.test.ts @@ -10,7 +10,7 @@ import { type WriteFileMeta } from '$lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/parsers/write-file'; import { AgenticSectionType, BuiltInTool } from '$lib/enums'; -import type { AgenticSection } from '$lib/utils'; +import type { AgenticSection } from '$lib/types'; import { abbreviateHome, formatCwdMessage, lastPathSegment, parseCwdMessage } from '$lib/utils'; import { describe, expect, it } from 'vitest';