openreader/src/lib/server/admin/tts-instructions.ts
Richard R b4f4d43d6a feat(tts,config,types): migrate to providerRef/providerType model and add centralized TTS provider policy
Transition all TTS-related logic, types, and UI to use the new providerRef/providerType model in place of legacy ttsProvider fields. Introduce a centralized tts-provider-policy module to encapsulate provider/model capability checks, default value resolution, and compatibility logic. Update all API routes, contexts, hooks, components, and tests to use providerRef and providerType, ensuring consistent handling of built-in and shared TTS providers. Remove legacy defaultTtsModel config in favor of per-provider defaults and shared provider admin control. Add the showAllProviderModels runtime flag to restrict users to provider default models when desired.

BREAKING CHANGE: ttsProvider fields are replaced by providerRef/providerType throughout the codebase; defaultTtsModel config is removed in favor of per-provider defaults.
2026-05-13 10:11:05 -06:00

34 lines
1.1 KiB
TypeScript

import { resolveTtsProviderModelPolicy } from '@/lib/shared/tts-provider-policy';
function normalizeInstructionCandidate(value: string | null | undefined): string | undefined {
if (value === null || value === undefined) return undefined;
const trimmed = String(value).trim();
return trimmed.length > 0 ? trimmed : undefined;
}
/**
* Resolve effective TTS instructions for a request.
*
* Priority:
* 1) explicit per-request instructions
* 2) shared-provider default instructions
*
* Returns `undefined` when the model does not support instructions or when
* neither source provides a non-empty value.
*/
export function resolveEffectiveTtsInstructions(opts: {
model: string | null | undefined;
requestInstructions?: string | null;
sharedDefaultInstructions?: string | null;
}): string | undefined {
if (!resolveTtsProviderModelPolicy({
providerRef: '',
providerType: 'custom-openai',
model: opts.model,
}).supportsInstructions) {
return undefined;
}
return normalizeInstructionCandidate(opts.requestInstructions)
?? normalizeInstructionCandidate(opts.sharedDefaultInstructions);
}