feat(talk): add provider-agnostic config with legacy compatibility

This commit is contained in:
Nimrod Gutman
2026-02-21 21:47:39 +02:00
committed by Peter Steinberger
parent d1f28c954e
commit d58f71571a
19 changed files with 1003 additions and 109 deletions

View File

@@ -1,5 +1,6 @@
import { readConfigFileSnapshot } from "../../config/config.js";
import { redactConfigObject } from "../../config/redact-snapshot.js";
import { buildTalkConfigResponse } from "../../config/talk.js";
import {
ErrorCodes,
errorShape,
@@ -17,46 +18,6 @@ function canReadTalkSecrets(client: { connect?: { scopes?: string[] } } | null):
return scopes.includes(ADMIN_SCOPE) || scopes.includes(TALK_SECRETS_SCOPE);
}
function normalizeTalkConfigSection(value: unknown): Record<string, unknown> | undefined {
if (!value || typeof value !== "object" || Array.isArray(value)) {
return undefined;
}
const source = value as Record<string, unknown>;
const talk: Record<string, unknown> = {};
if (typeof source.voiceId === "string") {
talk.voiceId = source.voiceId;
}
if (
source.voiceAliases &&
typeof source.voiceAliases === "object" &&
!Array.isArray(source.voiceAliases)
) {
const aliases: Record<string, string> = {};
for (const [alias, id] of Object.entries(source.voiceAliases as Record<string, unknown>)) {
if (typeof id !== "string") {
continue;
}
aliases[alias] = id;
}
if (Object.keys(aliases).length > 0) {
talk.voiceAliases = aliases;
}
}
if (typeof source.modelId === "string") {
talk.modelId = source.modelId;
}
if (typeof source.outputFormat === "string") {
talk.outputFormat = source.outputFormat;
}
if (typeof source.apiKey === "string") {
talk.apiKey = source.apiKey;
}
if (typeof source.interruptOnSpeech === "boolean") {
talk.interruptOnSpeech = source.interruptOnSpeech;
}
return Object.keys(talk).length > 0 ? talk : undefined;
}
export const talkHandlers: GatewayRequestHandlers = {
"talk.config": async ({ params, respond, client }) => {
if (!validateTalkConfigParams(params)) {
@@ -87,7 +48,7 @@ export const talkHandlers: GatewayRequestHandlers = {
const talkSource = includeSecrets
? snapshot.config.talk
: redactConfigObject(snapshot.config.talk);
const talk = normalizeTalkConfigSection(talkSource);
const talk = buildTalkConfigResponse(talkSource);
if (talk) {
configPayload.talk = talk;
}