Skip to content

Commit 733b68e

Browse files
committed
refactor: Enhance provider configuration and cleanup
Improves provider data parsing with stricter validation and type safety. Makes error handling more precise for failed remote preset fetches. Removes unused code and imports for cleaner codebase.
1 parent ad13f1b commit 733b68e

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/lib/docker-compose/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function getProviderDisplayName(providerId: string, providerConfig?: ProviderPre
7171
* @param providerConfig Optional provider configuration
7272
* @returns The provider description
7373
*/
74-
function getProviderDescription(providerId: string, providerConfig?: ProviderPreset): string | null {
74+
function getProviderDescription(_providerId: string, providerConfig?: ProviderPreset): string | null {
7575
if (providerConfig && providerConfig.description) {
7676
return providerConfig.description;
7777
}

src/lib/docker-compose/providerConfigLoader.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ export class ProviderConfigLoader {
245245
results.forEach((result, index) => {
246246
if (result.status === 'fulfilled' && result.value) {
247247
validPresets.push(result.value);
248-
} else {
248+
} else if (result.status === 'rejected') {
249249
console.warn(`[ProviderConfigLoader] Failed to fetch provider ${knownProviders[index]}:`, result.reason);
250250
}
251251
});
@@ -294,25 +294,33 @@ export class ProviderConfigLoader {
294294
throw new Error(`Invalid provider data ${data.providerId}: missing or invalid name`);
295295
}
296296

297-
if (!data.apiUrl || typeof data.apiUrl !== 'object' || !data.apiUrl.codingPlanForAnthropic) {
297+
if (!data.apiUrl || typeof data.apiUrl !== 'object') {
298298
throw new Error(`Invalid provider data ${data.providerId}: missing or invalid apiUrl`);
299299
}
300300

301+
const apiUrl = data.apiUrl as Record<string, unknown>;
302+
if (!apiUrl.codingPlanForAnthropic) {
303+
throw new Error(`Invalid provider data ${data.providerId}: missing or invalid apiUrl.codingPlanForAnthropic`);
304+
}
305+
306+
// Extract defaultModels with proper typing
307+
const defaultModels = (data.defaultModels || {}) as Record<string, unknown>;
308+
301309
// Construct provider preset with defaults for optional fields
302310
return {
303311
providerId: data.providerId as string,
304312
name: data.name as string,
305-
description: data.description as string || '',
306-
category: data.category as string || 'other',
313+
description: (data.description as string) || '',
314+
category: (data.category as string) || 'other',
307315
apiUrl: {
308-
codingPlanForAnthropic: (data.apiUrl as Record<string, string>).codingPlanForAnthropic
316+
codingPlanForAnthropic: (apiUrl.codingPlanForAnthropic as string)
309317
},
310318
recommended: data.recommended === true,
311319
region: data.region as string | undefined,
312320
defaultModels: {
313-
sonnet: data.defaultModels?.sonnet as string | null ?? null,
314-
opus: data.defaultModels?.opus as string | null ?? null,
315-
haiku: data.defaultModels?.haiku as string | null ?? null
321+
sonnet: (defaultModels.sonnet as string | null) ?? null,
322+
opus: (defaultModels.opus as string | null) ?? null,
323+
haiku: (defaultModels.haiku as string | null) ?? null
316324
},
317325
supportedModels: Array.isArray(data.supportedModels) ? data.supportedModels as string[] : undefined,
318326
features: Array.isArray(data.features) ? data.features as string[] : undefined,

src/pages/DockerComposeGenerator.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ConfigForm } from '@/components/docker-compose/ConfigForm';
22
import { ConfigPreview } from '@/components/docker-compose/ConfigPreview';
33
import { NavigationLinks } from '@/components/Header/NavigationLinks';
4-
import PromoBanner from '@/components/PromoBanner';
54
import { useTranslation } from 'react-i18next';
65
import { Dock } from 'lucide-react';
76

0 commit comments

Comments
 (0)