//#region src/voice/stt/config-slice.ts
/** Built-in env fallbacks when config slice has no apiKey. */
const STT_LEGACY_ENV_KEYS = {
	openai: "OPENAI_API_KEY",
	alibaba: "DASHSCOPE_API_KEY"
};
function asRecord(value) {
	return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
}
/** Collect provider-id → raw config entries from the `providers` map. */
function collectSttProviderConfigEntries(config) {
	const providers = asRecord((config ?? {}).providers);
	if (!providers) return {};
	const entries = {};
	for (const [providerId, value] of Object.entries(providers)) entries[providerId] = { ...asRecord(value) ?? {} };
	return entries;
}
/** Resolve the raw config slice for one provider id. */
function resolveSttProviderConfigSlice(providerId, config) {
	return collectSttProviderConfigEntries(config)[providerId] ?? {};
}
function trimToUndefined(value) {
	if (typeof value !== "string") return;
	const trimmed = value.trim();
	return trimmed.length > 0 ? trimmed : void 0;
}
function readStringRecord(value) {
	const record = asRecord(value);
	if (!record) return;
	const out = {};
	for (const [key, entry] of Object.entries(record)) {
		const text = trimToUndefined(entry);
		if (text) out[key] = text;
	}
	return Object.keys(out).length > 0 ? out : void 0;
}
/** Read normalized provider fields from a config slice or model entry override. */
function readSttProviderFields(slice, entryOverride) {
	const merged = {
		...slice,
		...entryOverride ?? {}
	};
	return {
		apiKey: trimToUndefined(merged.apiKey),
		model: trimToUndefined(merged.model),
		baseUrl: trimToUndefined(merged.baseUrl),
		headers: readStringRecord(merged.headers),
		language: trimToUndefined(merged.language),
		prompt: trimToUndefined(merged.prompt)
	};
}
//#endregion
export { STT_LEGACY_ENV_KEYS, collectSttProviderConfigEntries, readSttProviderFields, resolveSttProviderConfigSlice };

//# sourceMappingURL=config-slice.js.map