refactor: Remove unused code

This commit is contained in:
Aleksander Grygier 2026-01-24 23:42:59 +01:00
parent a05b0e3ec1
commit 3527446892
3 changed files with 0 additions and 120 deletions

View File

@ -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 '';
}
}
}

View File

@ -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<string, unknown> | undefined => {
return typeof value === 'object' && value !== null
? (value as Record<string, unknown>)
: 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;
}

View File

@ -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';