File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,6 +47,29 @@ describe("gradium speech provider", () => {
4747 }
4848 } ) ;
4949
50+ it ( "reports not configured for an invalid baseUrl instead of throwing" , ( ) => {
51+ const original = process . env . GRADIUM_API_KEY ;
52+ try {
53+ delete process . env . GRADIUM_API_KEY ;
54+ expect (
55+ provider . isConfigured ( {
56+ providerConfig : { apiKey : String ( true ) , baseUrl : "https://example.com" } ,
57+ timeoutMs : 5_000 ,
58+ } ) ,
59+ ) . toBe ( false ) ;
60+ expect (
61+ provider . isConfigured ( {
62+ providerConfig : { apiKey : String ( true ) , baseUrl : "not-a-url" } ,
63+ timeoutMs : 5_000 ,
64+ } ) ,
65+ ) . toBe ( false ) ;
66+ } finally {
67+ if ( original !== undefined ) {
68+ process . env . GRADIUM_API_KEY = original ;
69+ }
70+ }
71+ } ) ;
72+
5073 it ( "synthesizes audio via the Gradium TTS endpoint" , async ( ) => {
5174 const audioData = Buffer . from ( "wav-audio-data" ) ;
5275 const fetchMock = vi . fn ( ) . mockResolvedValue ( new Response ( audioData , { status : 200 } ) ) ;
Original file line number Diff line number Diff line change @@ -39,6 +39,20 @@ function readGradiumProviderConfig(config: SpeechProviderConfig): GradiumProvide
3939 } ;
4040}
4141
42+ function isGradiumProviderConfigured ( config : SpeechProviderConfig ) : boolean {
43+ const apiKey = trimToUndefined ( config . apiKey ) ?? trimToUndefined ( process . env . GRADIUM_API_KEY ) ;
44+ if ( ! apiKey ) {
45+ return false ;
46+ }
47+ try {
48+ normalizeGradiumBaseUrl ( trimToUndefined ( config . baseUrl ) ) ;
49+ return true ;
50+ } catch {
51+ // Provider selection is a predicate; synthesis reports the precise URL error.
52+ return false ;
53+ }
54+ }
55+
4256function resolveGeneratedAudioMaxBytes ( req : {
4357 cfg : { agents ?: { defaults ?: { mediaMaxMb ?: number } } } ;
4458} ) : number {
@@ -81,8 +95,7 @@ export function buildGradiumSpeechProvider(): SpeechProviderPlugin {
8195 resolveConfig : ( { rawConfig } ) => normalizeGradiumProviderConfig ( rawConfig ) ,
8296 parseDirectiveToken,
8397 listVoices : async ( ) => GRADIUM_VOICES . map ( ( v ) => ( { id : v . id , name : v . name } ) ) ,
84- isConfigured : ( { providerConfig } ) =>
85- Boolean ( readGradiumProviderConfig ( providerConfig ) . apiKey || process . env . GRADIUM_API_KEY ) ,
98+ isConfigured : ( { providerConfig } ) => isGradiumProviderConfigured ( providerConfig ) ,
8699 synthesize : async ( req ) => {
87100 const config = readGradiumProviderConfig ( req . providerConfig ) ;
88101 const overrides = req . providerOverrides ?? { } ;
You can’t perform that action at this time.
0 commit comments