mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 13:22:11 +03:00
- Replace stale model IDs (gemini-3.1-pro-preview, gemini-3.1-flash-lite-preview) with correct High/Low tier variants from fetchAvailableModels API (gemini-3-pro-high, gemini-3-pro-low, gemini-3.1-pro-high, gemini-3.1-pro-low, etc.) - Remove ag/ alias prefix in favor of antigravity/ across registry, providers, model capabilities, combos, docs, and static model providers - Make provider alias optional in Zod schema and guard ALIAS_TO_ID/ID_TO_ALIAS maps - Show raw model IDs in quota display instead of unmapped display names - Update T28 model catalog test to assert new High/Low tier models
45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
/**
|
|
* Provider Schema Validation — Phase 7.2
|
|
*
|
|
* Zod schemas for provider constant validation.
|
|
* Validates FREE_PROVIDERS, OAUTH_PROVIDERS, and APIKEY_PROVIDERS
|
|
* at module load time to catch configuration drift early.
|
|
*
|
|
* @module shared/validation/providerSchema
|
|
*/
|
|
|
|
import { z } from "zod";
|
|
|
|
export const ProviderSchema = z.object({
|
|
id: z.string().min(1),
|
|
alias: z.string().min(1).optional(),
|
|
name: z.string().min(1),
|
|
icon: z.string().min(1),
|
|
color: z.string().regex(/^#[0-9A-Fa-f]{6}$/, "Must be a valid hex color (#RRGGBB)"),
|
|
textIcon: z.string().optional(),
|
|
website: z.string().url().optional(),
|
|
passthroughModels: z.boolean().optional(),
|
|
deprecated: z.boolean().optional(),
|
|
deprecationReason: z.string().optional(),
|
|
hasFree: z.boolean().optional(),
|
|
freeNote: z.string().optional(),
|
|
authHint: z.string().optional(),
|
|
apiHint: z.string().optional(),
|
|
});
|
|
|
|
export const ProvidersMapSchema = z.record(z.string(), ProviderSchema);
|
|
|
|
/**
|
|
* Validate a providers map, throwing a descriptive error on failure.
|
|
* @param {Record<string, object>} map - The providers map to validate
|
|
* @param {string} name - Name of the map for error messages
|
|
*/
|
|
export function validateProviders(map: Record<string, unknown>, name: string): void {
|
|
const result = ProvidersMapSchema.safeParse(map);
|
|
if (!result.success) {
|
|
const issues = result.error.issues.map((i) => ` ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
console.error(`[PROVIDER VALIDATION] ${name} has invalid entries:\n${issues}`);
|
|
throw new Error(`Provider validation failed for ${name}`);
|
|
}
|
|
}
|