diff --git a/tools/server/webui/src/lib/utils/base64.ts b/tools/server/webui/src/lib/utils/base64.ts deleted file mode 100644 index e825e16086..0000000000 --- a/tools/server/webui/src/lib/utils/base64.ts +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Decode base64 to UTF-8 string using modern APIs. - * Falls back to legacy method if TextDecoder is unavailable. - * - * @param base64 - Base64 encoded string (padding is optional) - * @returns Decoded UTF-8 string, or empty string if decoding fails - */ -export function decodeBase64(base64: string): string { - if (!base64) return ''; - - const padded = base64 + '=='.slice(0, (4 - (base64.length % 4)) % 4); - - try { - const binaryString = atob(padded); - const bytes = new Uint8Array(binaryString.length); - for (let i = 0; i < binaryString.length; i++) { - bytes[i] = binaryString.charCodeAt(i); - } - return new TextDecoder('utf-8').decode(bytes); - } catch { - // Fallback to legacy method - try { - return decodeURIComponent(escape(atob(padded))); - } catch { - // Return empty string if all decoding fails - return ''; - } - } -} diff --git a/tools/server/webui/src/lib/utils/chat-stream.ts b/tools/server/webui/src/lib/utils/chat-stream.ts deleted file mode 100644 index 44145348b2..0000000000 --- a/tools/server/webui/src/lib/utils/chat-stream.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { - ApiChatCompletionResponse, - ApiChatCompletionStreamChunk, - ApiChatCompletionToolCall, - ApiChatCompletionToolCallDelta -} from '$lib/types/api'; - -export function mergeToolCallDeltas( - existing: ApiChatCompletionToolCall[], - deltas: ApiChatCompletionToolCallDelta[], - indexOffset = 0 -): ApiChatCompletionToolCall[] { - const result = existing.map((call) => ({ - ...call, - function: call.function ? { ...call.function } : undefined - })); - - for (const delta of deltas) { - const index = - typeof delta.index === 'number' && delta.index >= 0 - ? delta.index + indexOffset - : result.length; - - while (result.length <= index) { - result.push({ function: undefined }); - } - - const target = result[index]!; - - if (delta.id) { - target.id = delta.id; - } - - if (delta.type) { - target.type = delta.type; - } - - if (delta.function) { - const fn = target.function ? { ...target.function } : {}; - - if (delta.function.name) { - fn.name = delta.function.name; - } - - if (delta.function.arguments) { - fn.arguments = (fn.arguments ?? '') + delta.function.arguments; - } - - target.function = fn; - } - } - - return result; -} - -export function extractModelName( - data: ApiChatCompletionStreamChunk | ApiChatCompletionResponse | unknown -): string | undefined { - const asRecord = (value: unknown): Record | undefined => { - return typeof value === 'object' && value !== null - ? (value as Record) - : undefined; - }; - - const getTrimmedString = (value: unknown): string | undefined => { - return typeof value === 'string' && value.trim() ? value.trim() : undefined; - }; - - const root = asRecord(data); - if (!root) return undefined; - - const rootModel = getTrimmedString(root.model); - if (rootModel) return rootModel; - - const firstChoice = Array.isArray(root.choices) ? asRecord(root.choices[0]) : undefined; - if (!firstChoice) return undefined; - - const deltaModel = getTrimmedString(asRecord(firstChoice.delta)?.model); - if (deltaModel) return deltaModel; - - const messageModel = getTrimmedString(asRecord(firstChoice.message)?.model); - if (messageModel) return messageModel; - - return undefined; -} diff --git a/tools/server/webui/src/lib/utils/index.ts b/tools/server/webui/src/lib/utils/index.ts index 3b2488b840..47040f8723 100644 --- a/tools/server/webui/src/lib/utils/index.ts +++ b/tools/server/webui/src/lib/utils/index.ts @@ -104,12 +104,6 @@ export { isTextFileByName, readFileAsText, isLikelyTextFile } from './text-files // Agentic utilities export { toAgenticMessages, getAgenticConfig } from './agentic'; -// Base64 utilities -export { decodeBase64 } from './base64'; - -// Chat stream utilities -export { mergeToolCallDeltas, extractModelName } from './chat-stream'; - // Debounce utilities export { debounce } from './debounce';