mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-05-10 12:11:08 +00:00
* server/webui: add server-side WebUI config support Add CLI arguments --webui-config (inline JSON) and --webui-config-file (file path) to configure WebUI default settings from server side. Backend changes: - Parse JSON once in server_context::load_model() for performance - Cache parsed config in webui_settings member (zero overhead on /props) - Add proper error handling in router mode with try/catch - Expose webui_settings in /props endpoint for both router and child modes Frontend changes: - Add 14 configurable WebUI settings via parameter sync - Add tests for webui settings extraction - Fix subpath support with base path in API calls Addresses feedback from @ngxson and @ggerganov * server: address review feedback from ngxson * server: regenerate README with llama-gen-docs
45 lines
1.2 KiB
TypeScript
45 lines
1.2 KiB
TypeScript
import { base } from '$app/paths';
|
|
import { error } from '@sveltejs/kit';
|
|
import { browser } from '$app/environment';
|
|
import { config } 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;
|
|
}
|
|
|
|
try {
|
|
const apiKey = config().apiKey;
|
|
|
|
const headers: Record<string, string> = {
|
|
'Content-Type': 'application/json'
|
|
};
|
|
|
|
if (apiKey) {
|
|
headers.Authorization = `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);
|
|
}
|
|
}
|