mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-10-01 02:17:42 -05:00
* refactor: Stores barrel imports + SSR gates * refactor: Drop agenticStore wrapper exports * refactor: Drop chatStore wrapper exports * refactor: Drop modelsStore wrapper exports * refactor: Drop serverStore wrapper exports * refactor: Drop unused mcpStore wrapper exports * refactor: Drop mcpResourceStore wrapper exports * refactor: Drop conversationsStore wrapper exports + move buildConversationTree to utils * refactor: Drop settingsStore wrapper exports * refactor: Drop unused toolsStore wrapper exports * refactor: Fix lint errors from store wrapper removal * fix: Missing change * refactor: Cleanup * refactor: Context Stats store
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { error } from '@sveltejs/kit';
|
|
import { browser } from '$app/environment';
|
|
import { base } from '$app/paths';
|
|
import { HEADERS } from '$lib/constants';
|
|
import { MimeTypeApplication } from '$lib/enums';
|
|
import { settingsStore } from '$lib/stores/settings.svelte';
|
|
|
|
/**
|
|
* Validates API key by making a request to the server props endpoint
|
|
* Throws SvelteKit errors for authentication failures or server issues
|
|
*/
|
|
export async function validateApiKey(fetch: typeof globalThis.fetch): Promise<void> {
|
|
if (!browser) {
|
|
return;
|
|
}
|
|
|
|
const apiKey = settingsStore.config.apiKey;
|
|
|
|
try {
|
|
const headers: Record<string, string> = {
|
|
[HEADERS.CONTENT_TYPE]: MimeTypeApplication.JSON
|
|
};
|
|
|
|
// Probe /props even without a stored key: on a server started with
|
|
// --api-key the unauthenticated request returns 401 and surfaces the
|
|
// API key splash, which is the onboarding path for entering the key.
|
|
if (apiKey) {
|
|
headers[HEADERS.AUTHORIZATION] = `${HEADERS.BEARER}${apiKey}`;
|
|
}
|
|
|
|
const response = await fetch(`${base}/props`, { headers });
|
|
|
|
if (!response.ok) {
|
|
if (response.status === 401 || response.status === 403) {
|
|
throw error(401, 'Access denied');
|
|
}
|
|
|
|
console.warn(`Server responded with status ${response.status} during API key validation`);
|
|
|
|
return;
|
|
}
|
|
} catch (err) {
|
|
// If it's already a SvelteKit error, re-throw it
|
|
if (err && typeof err === 'object' && 'status' in err) {
|
|
throw err;
|
|
}
|
|
|
|
// Network or other errors
|
|
console.warn('Cannot connect to server for API key validation:', err);
|
|
}
|
|
}
|