(rawGlobalSettings: unknown)
| 78 | } |
| 79 | |
| 80 | function sanitizeGlobalSettings(rawGlobalSettings: unknown): { |
| 81 | sanitizedGlobalSettings: GlobalSettings |
| 82 | warnings: string[] |
| 83 | } { |
| 84 | const warnings: string[] = [] |
| 85 | const sanitizedGlobalSettings: Record<string, unknown> = {} |
| 86 | |
| 87 | if (typeof rawGlobalSettings === "undefined") { |
| 88 | return { sanitizedGlobalSettings: sanitizedGlobalSettings as GlobalSettings, warnings } |
| 89 | } |
| 90 | |
| 91 | if (typeof rawGlobalSettings !== "object" || rawGlobalSettings === null || Array.isArray(rawGlobalSettings)) { |
| 92 | warnings.push( |
| 93 | `Setting "globalSettings" was skipped: Expected object, received ${Array.isArray(rawGlobalSettings) ? "array" : typeof rawGlobalSettings}.`, |
| 94 | ) |
| 95 | return { sanitizedGlobalSettings: sanitizedGlobalSettings as GlobalSettings, warnings } |
| 96 | } |
| 97 | |
| 98 | for (const [key, rawValue] of Object.entries(rawGlobalSettings)) { |
| 99 | const path = `globalSettings.${key}` |
| 100 | const schema = globalSettingsShape[key as keyof GlobalSettings] |
| 101 | |
| 102 | if (!schema) { |
| 103 | warnings.push(`Setting "${path}" was skipped: Unknown setting.`) |
| 104 | continue |
| 105 | } |
| 106 | |
| 107 | let valueToValidate = rawValue |
| 108 | |
| 109 | if (key === "imageGenerationProvider" && rawValue === "roo") { |
| 110 | warnings.push(`Setting "${path}" used unsupported value "roo" and was cleared during import.`) |
| 111 | valueToValidate = undefined |
| 112 | } |
| 113 | |
| 114 | const result = schema.safeParse(valueToValidate) |
| 115 | if (result.success) { |
| 116 | sanitizedGlobalSettings[key] = result.data |
| 117 | } else { |
| 118 | warnings.push(`Setting "${path}" was skipped: ${formatZodIssues(result.error)}`) |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return { sanitizedGlobalSettings: sanitizedGlobalSettings as GlobalSettings, warnings } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Imports configuration from a specific file path |
no test coverage detected