11// Gateway RPC handlers for Talk voice, transcription, and speech synthesis surfaces.
2+ import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce" ;
23import {
34 normalizeLowercaseStringOrEmpty ,
45 normalizeOptionalLowercaseString ,
@@ -45,7 +46,6 @@ import {
4546} from "../../tts/tts.js" ;
4647import { ADMIN_SCOPE , TALK_SECRETS_SCOPE } from "../operator-scopes.js" ;
4748import { formatForLog } from "../ws-log.js" ;
48- import { asRecord } from "./record-shared.js" ;
4949import { talkClientHandlers } from "./talk-client.js" ;
5050import { talkSessionHandlers } from "./talk-session.js" ;
5151import {
@@ -72,7 +72,7 @@ function canReadTalkSecrets(client: { connect?: { scopes?: string[] } } | null):
7272}
7373
7474function asStringRecord ( value : unknown ) : Record < string , string > | undefined {
75- const record = asRecord ( value ) ;
75+ const record = asOptionalRecord ( value ) ;
7676 if ( ! record ) {
7777 return undefined ;
7878 }
@@ -113,20 +113,20 @@ function withTalkBaseTtsSpeakerSelectionCompat(
113113 baseTts : Record < string , unknown > ,
114114) : Record < string , unknown > {
115115 const next = withSpeakerSelectionCompat ( baseTts ) ;
116- const providers = asRecord ( baseTts . providers ) ;
116+ const providers = asOptionalRecord ( baseTts . providers ) ;
117117 if ( providers ) {
118118 next . providers = Object . fromEntries (
119119 Object . entries ( providers ) . map ( ( [ providerId , providerConfig ] ) => [
120120 providerId ,
121- withSpeakerSelectionCompat ( asRecord ( providerConfig ) ?? { } ) ,
121+ withSpeakerSelectionCompat ( asOptionalRecord ( providerConfig ) ?? { } ) ,
122122 ] ) ,
123123 ) ;
124124 }
125125 for ( const [ key , value ] of Object . entries ( baseTts ) ) {
126126 if ( key === "providers" ) {
127127 continue ;
128128 }
129- const record = asRecord ( value ) ;
129+ const record = asOptionalRecord ( value ) ;
130130 if ( record ) {
131131 next [ key ] = withSpeakerSelectionCompat ( record ) ;
132132 }
@@ -157,7 +157,7 @@ function buildTalkTtsConfig(
157157 }
158158
159159 const baseTts = withTalkBaseTtsSpeakerSelectionCompat (
160- asRecord ( config . messages ?. tts ) ?? { } ,
160+ asOptionalRecord ( config . messages ?. tts ) ?? { } ,
161161 ) as TtsConfig ;
162162 const providerConfig = withSpeakerSelectionFallbackCompat ( resolved . config ) ;
163163 const resolvedProviderConfig =
@@ -172,7 +172,7 @@ function buildTalkTtsConfig(
172172 auto : "always" ,
173173 provider,
174174 providers : {
175- ...( ( asRecord ( baseTts . providers ) ?? { } ) as TtsProviderConfigMap ) ,
175+ ...( ( asOptionalRecord ( baseTts . providers ) ?? { } ) as TtsProviderConfigMap ) ,
176176 [ provider ] : resolvedProviderConfig ,
177177 } ,
178178 } ;
@@ -425,10 +425,10 @@ function resolveTalkResponseFromConfig(params: {
425425
426426 const speechProvider = getSpeechProvider ( provider , params . runtimeConfig ) ;
427427 const sourceBaseTts = withTalkBaseTtsSpeakerSelectionCompat (
428- asRecord ( params . sourceConfig . messages ?. tts ) ?? { } ,
428+ asOptionalRecord ( params . sourceConfig . messages ?. tts ) ?? { } ,
429429 ) ;
430430 const runtimeBaseTts = withTalkBaseTtsSpeakerSelectionCompat (
431- asRecord ( params . runtimeConfig . messages ?. tts ) ?? { } ,
431+ asOptionalRecord ( params . runtimeConfig . messages ?. tts ) ?? { } ,
432432 ) ;
433433 const sourceProviderConfig = withSpeakerSelectionFallbackCompat ( sourceResolved ?. config ) ;
434434 const runtimeProviderConfig = withSpeakerSelectionFallbackCompat ( runtimeResolved ?. config ) ;
@@ -474,7 +474,7 @@ function stripUnresolvedSecretApiKey(config: TalkProviderConfig): TalkProviderCo
474474function stripUnresolvedSecretApiKeysFromBaseTtsProviders (
475475 base : Record < string , unknown > ,
476476) : Record < string , unknown > {
477- const providers = asRecord ( base . providers ) ;
477+ const providers = asOptionalRecord ( base . providers ) ;
478478 if ( ! providers ) {
479479 return base ;
480480 }
@@ -486,7 +486,7 @@ function stripUnresolvedSecretApiKeysFromBaseTtsProviders(
486486 // they're already validated upstream.
487487 const cleaned : Record < string , unknown > = Object . create ( null ) ;
488488 for ( const [ providerId , providerConfig ] of Object . entries ( providers ) ) {
489- const cfg = asRecord ( providerConfig ) ;
489+ const cfg = asOptionalRecord ( providerConfig ) ;
490490 if ( ! cfg ) {
491491 cleaned [ providerId ] = providerConfig ;
492492 continue ;
0 commit comments