MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / sanitizeProviderConfig

Function sanitizeProviderConfig

src/core/config/importExport.ts:46–72  ·  view source on GitHub ↗

* Sanitizes a provider config by resetting invalid/removed apiProvider values. * Returns the sanitized config and a warning message if the provider was invalid.

(configName: string, apiConfig: unknown)

Source from the content-addressed store, hash-verified

44 * Returns the sanitized config and a warning message if the provider was invalid.
45 */
46function sanitizeProviderConfig(configName: string, apiConfig: unknown): { config: unknown; warning?: string } {
47 if (typeof apiConfig !== "object" || apiConfig === null) {
48 return { config: apiConfig }
49 }
50
51 const { config, migrated } = downgradeLegacyRooConfig(apiConfig as Record<string, unknown>)
52
53 if (migrated) {
54 return {
55 config,
56 warning: `Profile "${configName}": ${ROUTER_REMOVAL_IMPORT_WARNING}`,
57 }
58 }
59
60 // Check if apiProvider is set and if it's still valid
61 if (config.apiProvider !== undefined && !isProviderName(config.apiProvider)) {
62 const invalidProvider = config.apiProvider
63 // Return a new config object without the invalid apiProvider
64 const { apiProvider, ...restConfig } = config
65 return {
66 config: restConfig,
67 warning: `Profile "${configName}": Invalid provider "${invalidProvider}" was removed. Please reconfigure this profile.`,
68 }
69 }
70
71 return { config: apiConfig }
72}
73
74const globalSettingsShape = globalSettingsSchema.shape as Record<keyof GlobalSettings, z.ZodTypeAny>
75

Callers 1

importSettingsFromPathFunction · 0.85

Calls 2

downgradeLegacyRooConfigFunction · 0.90
isProviderNameFunction · 0.90

Tested by

no test coverage detected