@@ -13,7 +13,7 @@ import { Label } from "@/components/ui/label";
1313import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
1414import { toast } from "@/stores/use-toast-store" ;
1515import { getProviderDefinition } from "@/data/tts-providers" ;
16- import type { TtsConfig , TtsProviderConfig , SynthesizeParams } from "../hooks/use-tts-config" ;
16+ import type { TtsConfig , TtsProviderConfig , TestConnectionParams , TestConnectionResult } from "../hooks/use-tts-config" ;
1717
1818interface Props {
1919 provider : string ;
@@ -22,10 +22,10 @@ interface Props {
2222 providerKey : keyof Pick < TtsConfig , "openai" | "elevenlabs" | "edge" | "minimax" > ,
2323 patch : Partial < TtsProviderConfig > ,
2424 ) => void ;
25- synthesize : ( params : SynthesizeParams ) => Promise < Blob > ;
25+ testConnection : ( params : TestConnectionParams ) => Promise < TestConnectionResult > ;
2626}
2727
28- export function CredentialsSection ( { provider, draft, onUpdate, synthesize } : Props ) {
28+ export function CredentialsSection ( { provider, draft, onUpdate, testConnection } : Props ) {
2929 const { t } = useTranslation ( "tts" ) ;
3030 const [ testing , setTesting ] = useState ( false ) ;
3131
@@ -36,8 +36,18 @@ export function CredentialsSection({ provider, draft, onUpdate, synthesize }: Pr
3636 const handleTestConnection = async ( ) => {
3737 setTesting ( true ) ;
3838 try {
39- await synthesize ( { text : "Hello, this is a connection test." , provider } ) ;
40- toast . success ( t ( "testConnection.success" , "Connection successful" ) ) ;
39+ // Build params from draft credentials — test with unsaved config
40+ const cfg = draft [ provider as keyof Pick < typeof draft , "openai" | "elevenlabs" | "minimax" > ] ;
41+ const params : TestConnectionParams = {
42+ provider,
43+ api_key : cfg ?. api_key ,
44+ api_base : cfg ?. api_base || cfg ?. base_url ,
45+ voice_id : cfg ?. voice_id || cfg ?. voice ,
46+ model_id : cfg ?. model_id || cfg ?. model ,
47+ group_id : ( cfg as { group_id ?: string } ) ?. group_id ,
48+ } ;
49+ const result = await testConnection ( params ) ;
50+ toast . success ( t ( "testConnection.success" , "Connection successful" ) , `${ result . latency_ms } ms` ) ;
4151 } catch ( err ) {
4252 const msg = err instanceof Error ? err . message : String ( err ) ;
4353 toast . error ( t ( "testConnection.failed" , "Connection failed" ) , msg ) ;
0 commit comments