45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import type { PageServerLoad } from './$types';
|
|
import { getClient } from '$lib/server/db/client.js';
|
|
import { LocalEmbeddingProvider } from '$lib/server/embeddings/local.provider.js';
|
|
import { EmbeddingSettingsDtoMapper } from '$lib/server/mappers/embedding-settings.dto.mapper.js';
|
|
import { EmbeddingSettingsService } from '$lib/server/services/embedding-settings.service.js';
|
|
|
|
export const load: PageServerLoad = async () => {
|
|
const db = getClient();
|
|
|
|
const service = new EmbeddingSettingsService(db);
|
|
const settings = EmbeddingSettingsDtoMapper.toDto(service.getSettings());
|
|
|
|
let localProviderAvailable = false;
|
|
try {
|
|
localProviderAvailable = await new LocalEmbeddingProvider().isAvailable();
|
|
} catch {
|
|
localProviderAvailable = false;
|
|
}
|
|
|
|
// Read indexing concurrency setting
|
|
let indexingConcurrency = 2;
|
|
const concurrencyRow = db
|
|
.prepare<[], { value: string }>("SELECT value FROM settings WHERE key = 'indexing.concurrency'")
|
|
.get();
|
|
|
|
if (concurrencyRow && concurrencyRow.value) {
|
|
try {
|
|
const parsed = JSON.parse(concurrencyRow.value);
|
|
if (typeof parsed === 'object' && parsed !== null && typeof parsed.value === 'number') {
|
|
indexingConcurrency = parsed.value;
|
|
} else if (typeof parsed === 'number') {
|
|
indexingConcurrency = parsed;
|
|
}
|
|
} catch {
|
|
indexingConcurrency = 2;
|
|
}
|
|
}
|
|
|
|
return {
|
|
settings,
|
|
localProviderAvailable,
|
|
indexingConcurrency
|
|
};
|
|
};
|