Files
OmniRoute/src/lib/db/apiKeys/permissionsUpdate.ts
Xiangzhe def5334768 feat(api-manager): add provider-level model permissions (#9313)
* feat(api-manager): add provider-level model permissions

Persist canonical provider wildcards alongside exact model grants and
preserve explicit restricted-empty deny-all semantics across API, SQLite,
JSON import, sync, runtime policy, and the dashboard.

Invalidate filtered model catalogs on permission changes and guard against
stale in-flight catalog builders repopulating invalidated cache entries.

* fix(api-manager): show provider and model counts separately in summary

Provider wildcard selections (provider/*) are no longer counted as
individual models in the Selected Models Summary. The header now shows
"N providers · M models" when both are present, or just the non-empty
category when only one type is selected.

* fix(api-manager): separate provider and model permission displays

* fix(api-manager): separate provider wildcard permissions in UI
2026-08-11 10:29:28 -03:00

78 lines
2.7 KiB
TypeScript

import type { AccessSchedule, RateLimitRule } from "./types";
import { normalizeModelAccessUpdate, type ModelAccessMode } from "./modelAccessMode";
export interface ApiKeyPermissionsUpdate {
name?: string;
modelAccessMode?: ModelAccessMode;
allowedModels?: string[];
blockedModels?: string[];
allowedCombos?: string[];
allowedConnections?: string[];
allowedQuotas?: string[];
noLog?: boolean;
autoResolve?: boolean;
isActive?: boolean;
accessSchedule?: AccessSchedule | null;
maxRequestsPerDay?: number | null;
maxRequestsPerMinute?: number | null;
throttleDelayMs?: number | null;
rateLimits?: RateLimitRule[] | null;
isBanned?: boolean;
expiresAt?: string | null;
maxSessions?: number | null;
scopes?: string[] | null;
proxyId?: string | null;
allowedEndpoints?: string[] | null;
streamDefaultMode?: "legacy" | "json" | null;
cacheDefaultMode?: "legacy" | "bypass" | null;
disableNonPublicModels?: boolean;
allowUsageCommand?: boolean;
usageLimitEnabled?: boolean;
dailyUsageLimitUsd?: number | null;
weeklyUsageLimitUsd?: number | null;
chaosModeEnabled?: boolean;
compressionEnabled?: boolean;
}
export function normalizeApiKeyPermissionsUpdate(
update: string[] | ApiKeyPermissionsUpdate | undefined
): ApiKeyPermissionsUpdate {
if (update === undefined) {
return normalizeModelAccessUpdate(undefined, []);
}
if (Array.isArray(update)) {
return normalizeModelAccessUpdate(undefined, update);
}
return {
name: update.name,
...normalizeModelAccessUpdate(update.modelAccessMode, update.allowedModels),
blockedModels: update.blockedModels,
allowedCombos: update.allowedCombos,
allowedConnections: update.allowedConnections,
allowedQuotas: update.allowedQuotas,
noLog: update.noLog,
autoResolve: update.autoResolve,
isActive: update.isActive,
accessSchedule: update.accessSchedule,
maxRequestsPerDay: update.maxRequestsPerDay,
maxRequestsPerMinute: update.maxRequestsPerMinute,
throttleDelayMs: update.throttleDelayMs,
rateLimits: update.rateLimits,
isBanned: update.isBanned,
expiresAt: update.expiresAt,
maxSessions: update.maxSessions,
scopes: update.scopes,
proxyId: update.proxyId,
allowedEndpoints: update.allowedEndpoints,
streamDefaultMode: update.streamDefaultMode,
cacheDefaultMode: update.cacheDefaultMode,
disableNonPublicModels: update.disableNonPublicModels,
allowUsageCommand: update.allowUsageCommand,
usageLimitEnabled: update.usageLimitEnabled,
dailyUsageLimitUsd: update.dailyUsageLimitUsd,
weeklyUsageLimitUsd: update.weeklyUsageLimitUsd,
chaosModeEnabled: update.chaosModeEnabled,
compressionEnabled: update.compressionEnabled,
};
}