import { api } from './api.js';
let _health = $state(null);
let _indexes = $state([]); let _loading = $state(false);
let _error = $state(null);
export function getHealth() {
return _health;
}
export function getIndexes() {
return _indexes;
}
export function getLoading() {
return _loading;
}
export function getError() {
return _error;
}
export async function refreshHealth() {
try {
_health = await api.health();
} catch (e) {
_health = { status: 'unreachable', version: '', indexes: 0, uptime_secs: 0 };
_error = e.message || String(e);
}
return _health;
}
export async function refreshIndexes() {
_loading = true;
_error = null;
try {
const body = await api.listIndexes();
const names = body?.indexes || [];
const pairs = await Promise.all(
names.map(async (id) => {
try {
const s = await api.indexStatus(id);
return {
id,
chunk_count: s.chunk_count ?? 0,
root_path: s.root_path ?? '',
error: false
};
} catch (_e) {
return { id, chunk_count: 0, root_path: '', error: true };
}
})
);
_indexes = pairs;
} catch (e) {
_error = e.message || String(e);
_indexes = [];
} finally {
_loading = false;
}
return _indexes;
}