persist model access policy to database

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-26 20:22:42 +00:00
co-authored by Claude Opus 4.6
parent b8b71e78d9
commit e0f470137b
3 changed files with 31 additions and 1 deletions
@@ -3,6 +3,7 @@ import { createRouter } from '../../create-router';
import { PI_CONFIG_DIR } from '../../data-path';
import { invalidateModelCache } from '../pi/list-models';
import { logger } from '../pi/logger';
import { readConfigValue, writeConfigValue } from 'officerdb';
export const piMonoRouter = createRouter();
@@ -387,6 +388,20 @@ piMonoRouter.put('/api-keys', async (ctx) => {
return ctx.json({ ok: true });
});
type AccessPolicy = { allowedModels: string[] };
const ACCESS_POLICY_KEY = 'pi-access-policy';
piMonoRouter.get('/access-policy', async (ctx) => {
const policy = await readConfigValue<AccessPolicy>(ACCESS_POLICY_KEY, { allowedModels: [] });
return ctx.json(policy);
});
piMonoRouter.put('/access-policy', async (ctx) => {
const body = await ctx.req.json<AccessPolicy>();
await writeConfigValue(ACCESS_POLICY_KEY, body);
return ctx.json(body);
});
const REMOTE_HEALTH_CONFIG: Record<string, {
url: string | ((key: string) => string);
headers: (key: string) => Record<string, string>;