mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix: fail closed talk provider selection
This commit is contained in:
@@ -31,10 +31,19 @@ public enum TalkConfigParsing {
|
||||
let hasNormalizedPayload = rawProvider != nil || rawProviders != nil
|
||||
if hasNormalizedPayload {
|
||||
let normalizedProviders = self.normalizedTalkProviders(rawProviders)
|
||||
let providerID =
|
||||
self.normalizedTalkProviderID(rawProvider) ??
|
||||
normalizedProviders.keys.min() ??
|
||||
defaultProvider
|
||||
let explicitProviderID = self.normalizedTalkProviderID(rawProvider)
|
||||
if let explicitProviderID {
|
||||
if !normalizedProviders.isEmpty, normalizedProviders[explicitProviderID] == nil {
|
||||
return nil
|
||||
}
|
||||
return TalkProviderConfigSelection(
|
||||
provider: explicitProviderID,
|
||||
config: normalizedProviders[explicitProviderID] ?? [:],
|
||||
normalizedPayload: true)
|
||||
}
|
||||
guard normalizedProviders.count == 1, let providerID = normalizedProviders.keys.first else {
|
||||
return nil
|
||||
}
|
||||
return TalkProviderConfigSelection(
|
||||
provider: providerID,
|
||||
config: normalizedProviders[providerID] ?? [:],
|
||||
|
||||
@@ -66,6 +66,36 @@ struct TalkConfigParsingTests {
|
||||
#expect(selection == nil)
|
||||
}
|
||||
|
||||
@Test func rejectsNormalizedPayloadWhenProviderMissingFromProviders() {
|
||||
let talk: [String: AnyCodable] = [
|
||||
"provider": AnyCodable("acme"),
|
||||
"providers": AnyCodable([
|
||||
"elevenlabs": [
|
||||
"voiceId": "voice-normalized",
|
||||
],
|
||||
]),
|
||||
]
|
||||
|
||||
let selection = TalkConfigParsing.selectProviderConfig(talk, defaultProvider: "elevenlabs")
|
||||
#expect(selection == nil)
|
||||
}
|
||||
|
||||
@Test func rejectsNormalizedPayloadWhenMultipleProvidersAndNoProvider() {
|
||||
let talk: [String: AnyCodable] = [
|
||||
"providers": AnyCodable([
|
||||
"acme": [
|
||||
"voiceId": "voice-acme",
|
||||
],
|
||||
"elevenlabs": [
|
||||
"voiceId": "voice-eleven",
|
||||
],
|
||||
]),
|
||||
]
|
||||
|
||||
let selection = TalkConfigParsing.selectProviderConfig(talk, defaultProvider: "elevenlabs")
|
||||
#expect(selection == nil)
|
||||
}
|
||||
|
||||
@Test func bridgesFoundationDictionary() {
|
||||
let raw: [String: Any] = [
|
||||
"provider": "elevenlabs",
|
||||
|
||||
Reference in New Issue
Block a user