Files
prowler/ui/lib/lighthouse/validation.ts
Chandrapal Badshah 031548ca7e feat: Update Lighthouse UI to support multi LLM (#8925)
Co-authored-by: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com>
Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com>
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
2025-11-14 11:46:38 +01:00

69 lines
1.7 KiB
TypeScript

import type { LighthouseProvider } from "@/types/lighthouse";
import {
baseUrlSchema,
bedrockCredentialsSchema,
openAICompatibleCredentialsSchema,
openAICredentialsSchema,
} from "@/types/lighthouse/credentials";
/**
* Validate credentials based on provider type
*/
export function validateCredentials(
providerType: LighthouseProvider,
credentials: Record<string, string>,
): { success: boolean; error?: string } {
try {
switch (providerType) {
case "openai":
openAICredentialsSchema.parse(credentials);
break;
case "bedrock":
bedrockCredentialsSchema.parse(credentials);
break;
case "openai_compatible":
openAICompatibleCredentialsSchema.parse(credentials);
break;
default:
return {
success: false,
error: `Unknown provider type: ${providerType}`,
};
}
return { success: true };
} catch (error: unknown) {
const errorMessage =
(error as { issues?: Array<{ message: string }>; message?: string })
?.issues?.[0]?.message ||
(error as { message?: string })?.message ||
"Validation failed";
return {
success: false,
error: errorMessage,
};
}
}
/**
* Validate base URL
*/
export function validateBaseUrl(baseUrl: string): {
success: boolean;
error?: string;
} {
try {
baseUrlSchema.parse(baseUrl);
return { success: true };
} catch (error: unknown) {
const errorMessage =
(error as { issues?: Array<{ message: string }>; message?: string })
?.issues?.[0]?.message ||
(error as { message?: string })?.message ||
"Invalid base URL";
return {
success: false,
error: errorMessage,
};
}
}