Skip to content

Commit 5968397

Browse files
committed
refactor: share voice-call config extraction
1 parent c8f8907 commit 5968397

1 file changed

Lines changed: 18 additions & 26 deletions

File tree

src/gateway/server-methods/talk-shared.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -72,54 +72,46 @@ function singleRecordKey(record: Record<string, unknown> | undefined): string |
7272
return keys.length === 1 ? keys[0] : undefined;
7373
}
7474

75-
function getVoiceCallRealtimeConfig(config: OpenClawConfig): {
75+
function getVoiceCallProviderConfig<TConfig extends Record<string, unknown>>(
76+
config: OpenClawConfig,
77+
sectionName: "realtime" | "streaming",
78+
): {
7679
provider?: string;
77-
providers?: Record<string, RealtimeVoiceProviderConfig>;
80+
providers?: Record<string, TConfig>;
7881
} {
7982
const plugins = getRecord(config.plugins);
8083
const entries = getRecord(plugins?.entries);
8184
const voiceCall = getRecord(entries?.["voice-call"]);
8285
const pluginConfig = getRecord(voiceCall?.config);
83-
const realtime = getRecord(pluginConfig?.realtime);
84-
const providersRaw = getRecord(realtime?.providers);
85-
const providers: Record<string, RealtimeVoiceProviderConfig> = {};
86+
const section = getRecord(pluginConfig?.[sectionName]);
87+
const providersRaw = getRecord(section?.providers);
88+
const providers: Record<string, TConfig> = {};
8689
if (providersRaw) {
8790
for (const [providerId, providerConfig] of Object.entries(providersRaw)) {
8891
const record = getRecord(providerConfig);
8992
if (record) {
90-
providers[providerId] = record;
93+
providers[providerId] = record as TConfig;
9194
}
9295
}
9396
}
9497
return {
95-
provider: normalizeOptionalString(realtime?.provider),
98+
provider: normalizeOptionalString(section?.provider),
9699
providers: Object.keys(providers).length > 0 ? providers : undefined,
97100
};
98101
}
99102

103+
function getVoiceCallRealtimeConfig(config: OpenClawConfig): {
104+
provider?: string;
105+
providers?: Record<string, RealtimeVoiceProviderConfig>;
106+
} {
107+
return getVoiceCallProviderConfig(config, "realtime");
108+
}
109+
100110
export function getVoiceCallStreamingConfig(config: OpenClawConfig): {
101111
provider?: string;
102112
providers?: Record<string, RealtimeTranscriptionProviderConfig>;
103113
} {
104-
const plugins = getRecord(config.plugins);
105-
const entries = getRecord(plugins?.entries);
106-
const voiceCall = getRecord(entries?.["voice-call"]);
107-
const pluginConfig = getRecord(voiceCall?.config);
108-
const streaming = getRecord(pluginConfig?.streaming);
109-
const providersRaw = getRecord(streaming?.providers);
110-
const providers: Record<string, RealtimeTranscriptionProviderConfig> = {};
111-
if (providersRaw) {
112-
for (const [providerId, providerConfig] of Object.entries(providersRaw)) {
113-
const record = getRecord(providerConfig);
114-
if (record) {
115-
providers[providerId] = record;
116-
}
117-
}
118-
}
119-
return {
120-
provider: normalizeOptionalString(streaming?.provider),
121-
providers: Object.keys(providers).length > 0 ? providers : undefined,
122-
};
114+
return getVoiceCallProviderConfig(config, "streaming");
123115
}
124116

125117
type RealtimeProviderWithConfig<TConfig extends Record<string, unknown>> = VoiceModelProvider & {

0 commit comments

Comments
 (0)