Private/Translation/Invoke-TranslationProviderAdapter.ps1

function Invoke-TranslationProviderAdapter {
    <#
    .SYNOPSIS
        Dispatches a translation API call to the adapter for the given provider.
    .DESCRIPTION
        Single source of truth for provider dispatch, replacing what used to be a
        `switch ($prov.Name)` duplicated in Invoke-SubtitleTranslation.ps1 and
        Invoke-TranslationPriming.ps1. Adding a new provider means adding one case
        here rather than touching every call site.
    .PARAMETER SystemPrompt
        The system prompt to send.
    .PARAMETER UserContent
        The user content to send.
    .PARAMETER Provider
        A TranslationProvider instance describing which provider/model/endpoint to
        call. Note: callers may pass a provider object distinct from the session's
        configured provider (e.g. Invoke-TranslationPriming builds its own copy
        with a different temperature for content analysis) - this function only
        cares about its .Name.
    .PARAMETER ApiKey
        The decrypted API key as a SecureString.
    .PARAMETER MaxRetries
        Forwarded to the underlying adapter's retry loop.
    .PARAMETER StreamCallback
        Optional. Forwarded to the adapter, which then attempts the streaming path so
        the caller can report progress mid-response.
    .OUTPUTS
        PSCustomObject: Content, InputTokens, OutputTokens, FinishReason, Model, RetryCount
    #>

    [OutputType([PSCustomObject])]
    param(
        [Parameter(Mandatory)]
        [string] $SystemPrompt,

        [Parameter(Mandatory)]
        [string] $UserContent,

        [Parameter(Mandatory)]
        [TranslationProvider] $Provider,

        [Parameter(Mandatory)]
        [SecureString] $ApiKey,

        [int] $MaxRetries = 3,

        # Forwarded to the adapter; see the adapters' own -StreamCallback notes.
        [scriptblock] $StreamCallback
    )

    switch ($Provider.Name) {
        'Anthropic' {
            return Invoke-AnthropicTranslation -SystemPrompt $SystemPrompt -UserContent $UserContent `
                -Provider $Provider -ApiKey $ApiKey -MaxRetries $MaxRetries -StreamCallback $StreamCallback
        }
        'OpenAI' {
            return Invoke-OpenAITranslation -SystemPrompt $SystemPrompt -UserContent $UserContent `
                -Provider $Provider -ApiKey $ApiKey -MaxRetries $MaxRetries -StreamCallback $StreamCallback
        }
        'Google' {
            return Invoke-GoogleTranslation -SystemPrompt $SystemPrompt -UserContent $UserContent `
                -Provider $Provider -ApiKey $ApiKey -MaxRetries $MaxRetries -StreamCallback $StreamCallback
        }
        'OpenRouter' {
            return Invoke-OpenRouterTranslation -SystemPrompt $SystemPrompt -UserContent $UserContent `
                -Provider $Provider -ApiKey $ApiKey -MaxRetries $MaxRetries -StreamCallback $StreamCallback
        }
        default {
            throw "Invoke-TranslationProviderAdapter: unknown translation provider '$($Provider.Name)'. Supported providers: Anthropic, OpenAI, Google, OpenRouter."
        }
    }
}