okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221apps/host: the owner's UI and the Node App Host0b3299a01

main
1012 B16 linesraw
1/** One conservative policy for operations affecting the shared loaded model. */
2export function lifecyclePolicy(input: {
3  connected: boolean;
4  streaming: boolean;
5  stats?: { running?: number; waiting?: number } | null;
6  busy: Record<string, boolean | undefined>;
7}) {
8  const { running, waiting } = input.stats ?? {};
9  if (!input.connected || !Number.isFinite(running) || !Number.isFinite(waiting))
10    return { allowed: false, reason: 'Request status unavailable. Reconnect before changing the loaded model.' };
11  if (input.streaming || running! > 0 || waiting! > 0)
12    return { allowed: false, reason: `${running! > 0 ? running : input.streaming ? 'A' : 0} active · ${waiting} queued. Finish or cancel requests first.` };
13  if (Object.entries(input.busy).some(([key, value]) => value && (key === 'restart' || key === 'unload' || key === 'modelDirectory' || key.startsWith('load:'))))
14    return { allowed: false, reason: 'A model operation is in progress.' };
15  return { allowed: true, reason: '' };
16}