From 2b2f4110da53a03742faff89cdec17c55e091a90 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 11 Jun 2026 00:21:50 +0300 Subject: llm: return concrete client types from provider constructors Follow the Go idiom "return concrete types, accept interfaces": the provider constructors newOpenAI, newAnthropic, newOpenRouter, newOllama and their *WithTimeout variants now return their concrete *Client value types instead of the Client interface. The provider factories registered in the registry still return Client, so NewFromConfig and the registry keep working unchanged. Updated comments to explain the reasoning, dropped the now-redundant type assertions in tests, and switched the anthropic Streamer-capability tests to assert via an explicit Client interface value. Co-Authored-By: Claude Opus 4.8 --- internal/llm/openrouter.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'internal/llm/openrouter.go') diff --git a/internal/llm/openrouter.go b/internal/llm/openrouter.go index aa8a4d4..d728275 100644 --- a/internal/llm/openrouter.go +++ b/internal/llm/openrouter.go @@ -40,11 +40,15 @@ func openRouterProviderFactory(cfg Config, keys ProviderKeys) (Client, error) { ), nil } -func newOpenRouter(baseURL, model, apiKey string, defaultTemp *float64) Client { +// newOpenRouter constructs an OpenRouter client using explicit configuration +// values. Following the Go idiom "return concrete types, accept interfaces", +// this returns openRouterClient directly; the provider registry wraps it back +// into a Client at registration time. +func newOpenRouter(baseURL, model, apiKey string, defaultTemp *float64) openRouterClient { return newOpenRouterWithTimeout(baseURL, model, apiKey, defaultTemp, 0) } -func newOpenRouterWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) Client { +func newOpenRouterWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) openRouterClient { if strings.TrimSpace(baseURL) == "" { baseURL = "https://openrouter.ai/api/v1" } -- cgit v1.2.3