Files
PaperClipAI/server/src/services/onboarding-models.ts
T
Devin FoleyandPaperclip 6e340a3f96 Verify onboarding models and explain provider failures (#23563)
Verify deployment-configured model preferences with the selected account.
Preserve structured provider failures and show descriptive messages for known
causes through the existing onboarding error display. Keep the existing failure
buttons, account binding, and retry/sign-in behavior.

Validation: UI typecheck, 38 focused tests, four browser journeys, all applicable
CI checks, and Greptile 5/5 with no unresolved review comments.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-12-02 16:47:58 -08:00

15 lines
820 B
TypeScript

export function onboardingModels(env: Record<string, string | undefined>): Record<string, string[]> {
const raw = env.PAPERCLIP_ONBOARDING_MODELS;
if (!raw || raw.length > 8_192) return {};
try {
const value: unknown = JSON.parse(raw);
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
const entries = Object.entries(value);
if (entries.length > 16 || entries.some(([harness, models]) =>
!/^[a-z][a-z0-9_]{0,63}$/.test(harness) || !Array.isArray(models) || !models.length || models.length > 3
|| models.some(model => typeof model !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._/\[\]-]{0,159}$/.test(model)),
)) return {};
return Object.fromEntries(entries.map(([harness, models]) => [harness, [...new Set(models as string[])]]));
} catch { return {}; }
}