char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Improve Chat Messages rendering performance (#28460)0afb805b1

char/aliceai-t5-moe
9.4 KiB353 linesraw
1/**
2 * Unified exports for all utility functions
3 * Import utilities from '$lib/utils' for cleaner imports
4 *
5 * For browser-only utilities (pdf-processing, audio-recording, svg-to-png,
6 * webp-to-png, process-uploaded-files, convert-files-to-extra), use:
7 * import { ... } from '$lib/utils/browser-only'
8 */
9
10// API utilities
11export { getAuthHeaders, getJsonHeaders, sanitizeHeaders } from './api-headers';
12export { ApiError, apiFetch, apiFetchWithParams, apiPost } from './api-fetch';
13export { validateApiKey } from './api-key-validation';
14
15// Attachment utilities
16export { getAttachmentDisplayItems, isMcpPrompt, isMcpResource } from './attachment-display';
17export { isTextFile, isImageFile, isPdfFile, isAudioFile, isVideoFile } from './attachment-type';
18
19// Textarea utilities
20export { default as autoResizeTextarea } from './autoresize-textarea';
21
22// Branching utilities
23export {
24	filterByLeafNodeId,
25	findMessageById,
26	findLeafNode,
27	findDescendantMessages,
28	getMessageSiblings,
29	buildSiblingInfoMap
30} from './branching';
31
32// Code
33export {
34	highlightCode,
35	detectIncompleteCodeBlock,
36	splitGluedClosingCodeFences,
37	trimCodePadding,
38	type IncompleteCodeBlock
39} from './code';
40
41// Config helpers
42export { setConfigValue, getConfigValue, configToParameterRecord } from './config-helpers';
43
44// CORS Proxy
45export { buildProxiedUrl, buildProxiedHeaders } from './cors-proxy';
46
47// URL utilities
48export { extractRootDomain, sanitizeExternalUrl, canonicalizeServerUrl } from './url';
49
50// Progress helpers
51export { modelLoadFraction, modelLoadProgressText } from './progress';
52
53// Conversation utilities
54export {
55	createMessageCountMap,
56	getMessageCount,
57	getConversationModel,
58	buildConversationTree,
59	type ConversationTreeItem
60} from './conversation-utils';
61
62// Clipboard utilities
63export {
64	copyToClipboard,
65	copyCodeToClipboard,
66	formatMessageForClipboard,
67	parseClipboardContent,
68	hasClipboardAttachments
69} from './clipboard';
70
71// File preview utilities
72export { getFileTypeLabel } from './file-preview';
73export { getPreviewText, generateConversationTitle } from './text';
74
75// File type utilities
76export {
77	getFileTypeCategory,
78	getFileTypeCategoryByExtension,
79	getFileTypeByExtension,
80	isFileTypeSupported
81} from './file-type';
82
83// Formatting utilities
84export {
85	formatFileSize,
86	formatParameters,
87	formatNumber,
88	formatJsonPretty,
89	formatTime,
90	formatPerformanceTime,
91	formatAttachmentText
92} from './formatters';
93
94// IME utilities
95export { isIMEComposing } from './is-ime-composing';
96
97// LaTeX utilities
98export { maskInlineLaTeX, preprocessLaTeX } from './latex-protection';
99
100// Modality file validation utilities
101export {
102	isFileTypeSupportedByModel,
103	filterFilesByModalities,
104	generateModalityErrorMessage
105} from './modality-file-validation';
106
107// Model name utilities
108export { normalizeModelName, isValidModelName } from './model-names';
109
110// Portal utilities
111export { portalToBody } from './portal-to-body';
112
113// Precision utilities
114export { normalizeFloatingPoint, normalizeNumber } from './precision';
115
116// Syntax highlighting utilities
117export { getLanguageFromFilename } from './syntax-highlight-language';
118
119// Text file utilities
120export { isTextFileByName, readFileAsText, isLikelyTextFile } from './text-files';
121
122// Debounce utilities
123export { debounce } from './debounce';
124
125// Sanitization utilities
126export { sanitizeKeyValuePairKey, sanitizeKeyValuePairValue } from './sanitize';
127
128// Image error fallback utilities
129export { getImageErrorFallbackHtml } from './image-error-fallback';
130
131// SSE-with-JSON stream iterator (used by server tool streaming, decoupled
132// from chat.service.ts which embeds its own SSE parser for resume support)
133export { extractSseDataPayload, parseSseJsonStream, splitSseRecords } from './sse';
134
135// Stream session identity (conversation-id based)
136export { streamIdentity } from './stream-identity';
137
138// MCP utilities
139export {
140	detectMcpTransportFromUrl,
141	parseMcpServerSettings,
142	getMcpLogLevelIcon,
143	getMcpLogLevelClass,
144	isImageMimeType,
145	parseResourcePath,
146	getDisplayName,
147	getResourceDisplayName,
148	isCodeResource,
149	isImageResource,
150	getResourceIcon,
151	getResourceTextContent,
152	getResourceBlobContent,
153	downloadResourceContent,
154	getMcpIconUrl,
155	getMcpServerFaviconFallback,
156	getMcpServerLabel
157} from './mcp';
158
159// URI Template utilities
160export {
161	extractTemplateVariables,
162	expandTemplate,
163	isTemplateComplete,
164	normalizeResourceUri,
165	type UriTemplateVariable
166} from './uri-template';
167
168// Data URL utilities
169export { createBase64DataUrl } from './data-url';
170
171// Header utilities
172export { parseHeadersToArray, serializeHeaders } from './headers';
173
174// Working-directory display helpers (HOME-style tilde abbreviation)
175export {
176	abbreviateWorkingDir,
177	abbreviateHome,
178	lastPathSegment,
179	formatCwdMessage,
180	parseCwdMessage,
181	CWD_CHANGED_PREFIX,
182	CWD_CLEARED_TEXT,
183	type CwdMessageInfo
184} from './path-display';
185
186// Working-directory picker search helpers
187export {
188	splitPathQuery,
189	buildCaseInsensitiveGlob,
190	buildGlobSearchArgs,
191	rankEntries,
192	joinPath,
193	highlightMatch,
194	type PathQuery
195} from './working-directory';
196
197// Shared `file_glob_search` runner with a short-lived result cache
198export { runGlobSearch, runGlobSearchWithChildren } from './glob-search';
199
200// Mention-token detection (for the `@`-triggered file/folder mention picker)
201export {
202	findMentionToken,
203	takeMentionDismissSnapshot,
204	type MentionDismissSnapshot
205} from './mention-token';
206
207// Slash-command token detection (for the `/`-triggered command picker)
208export {
209	findCommandToken,
210	takeCommandDismissSnapshot,
211	type CommandDismissSnapshot
212} from './command-token';
213
214// Tokenization for the ChatFormInputRich (mention links + code spans <-> chip DOM)
215export {
216	tokenizeContent,
217	containsCodeSpan,
218	isOffsetInCodeBlock,
219	domMatchesTokens,
220	syncCodeBlockHatches,
221	stripBlockBoundaryLineBreaks,
222	serializeContent,
223	buildFragment,
224	rangeToTextOffset,
225	textOffsetToRange,
226	badgeAwareWordJump,
227	leadingBadgeEdgeOffset
228} from './chat-form-input-rich-tokenizer';
229
230// Source-space undo/redo history for the ChatFormInputRich
231export { SourceHistory, type SourceHistoryEntry } from './source-history';
232
233// Mention-badge visual contract (used by the ChatFormInputRich / rehype
234// DOM paths that build the same chip without a Svelte mount)
235export {
236	containsFileMentionLink,
237	fileMentionLinkRe,
238	encodeFileLinkPath,
239	decodeFileLinkPath,
240	MENTION_BADGE_CLASSNAME,
241	MENTION_BADGE_ICON_CLASSNAME,
242	MENTION_BADGE_SVG_ATTRIBUTES,
243	MENTION_BADGE_FILE_ICON_PATHS,
244	MENTION_BADGE_FOLDER_ICON_PATHS,
245	getMentionBadgeIconPaths,
246	getMentionBadgeLabel,
247	splitMentionSegments,
248	buildMentionInsertion
249} from './mention-badge';
250
251// Chat template utilities
252export {
253	detectThinkingSupport,
254	detectThinkingSupportWithReason
255} from './chat-template-thinking-detector';
256
257// Agentic content utilities (structured section derivation)
258export {
259	deriveAgenticSections,
260	buildAssistantRawOutput,
261	parseToolResultWithMedia,
262	splitSearchSummaryList,
263	hasAgenticContent,
264	classifyToolResult,
265	classifyContinueIntent
266} from './agentic';
267
268// Line-level unified diff for tool result rendering (`edit_file` block)
269export { computeLineDiff, prefixFor, renderUnifiedDiff, type DiffLine } from './compute-line-diff';
270
271// Partial-incremental JSON parser for streaming tool arguments
272export { parsePartialJsonArgs } from './parse-partial-json-args';
273
274// `exec_shell_command` result parsing
275export { parseExecShellCommandError } from './parse-exec-shell-error';
276export {
277	parseExecShellCommandExitStatus,
278	isExitCodeSummaryLine,
279	type ExecShellExitStatus
280} from './parse-exec-shell-status';
281
282// Search-result parsing (web-search / fetch MCP tools)
283export {
284	SUPPORTED_WEB_SEARCH_TOOL_NAMES,
285	extractSearchResults,
286	extractSearchQuery,
287	faviconForUrl,
288	isWebSearchToolName,
289	looksLikeSearchResult
290} from './search-results';
291
292// Cache utilities
293export { TTLCache, ReactiveTTLMap } from './cache-ttl';
294
295// Redaction utilities
296export { redactValue } from './redact';
297
298// Request inspection utilities
299export {
300	getRequestUrl,
301	getRequestMethod,
302	getRequestBody,
303	summarizeRequestBody,
304	formatDiagnosticErrorMessage,
305	extractJsonRpcMethods,
306	type RequestBodySummary
307} from './request-helpers';
308
309// Abort signal utilities
310export {
311	throwIfAborted,
312	isAbortError,
313	createLinkedController,
314	createTimeoutSignal,
315	withAbortSignal
316} from './abort';
317
318// Tool-call meta utilities. Parsers for each server tool live next to
319// their renderer family under
320// `src/lib/components/app/chat/ChatMessages/ChatMessage/ChatMessageToolCall/parsers/`.
321// This module only carries the helpers that genuinely cross tool
322// boundaries (currently: parsing the tool-result blob into a JSON
323// object).
324export { tryParseToolResultObject } from './tool-call-meta';
325
326// Per-tool UI metadata (label + icon) used by the tool-call chrome.
327// Re-exported through $lib/utils so renderer components can read the
328// label without depending on $lib/constants directly.
329export { getToolUi } from './tool-ui';
330
331// Chat command picker
332
333export { getChatCommands } from './chat-commands';
334
335// Sandbox tool definition
336// SANDBOX_TOOL_DEFINITION is deprecated; kept for backward compatibility.
337export { buildSandboxToolDefinition, SANDBOX_TOOL_DEFINITION } from './sandbox-tool';
338
339// Browser `get_datetime` executor (the browser clock, not the server's)
340export { executeGetDatetimeTool } from './get-datetime';
341
342// Browser fallback for the server's get_info tool
343export { executeBrowserInfoTool } from './browser-info';
344
345// Cryptography utilities
346
347export { uuid } from './uuid';
348
349// CSS utilities
350export { remToPx } from './css';
351
352// Audio format helper (used by agentic store and chat service)
353export { getAudioInputFormat } from './audio-format';