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/anthropic.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'internal/llm/anthropic.go') diff --git a/internal/llm/anthropic.go b/internal/llm/anthropic.go index 17c40ad..3f7a616 100644 --- a/internal/llm/anthropic.go +++ b/internal/llm/anthropic.go @@ -81,8 +81,8 @@ type anthropicStreamError struct { // Ensure anthropicClient implements Client and Streamer. var ( - _ Client = (*anthropicClient)(nil) - _ Streamer = (*anthropicClient)(nil) + _ Client = anthropicClient{} + _ Streamer = anthropicClient{} ) func anthropicProviderFactory(cfg Config, keys ProviderKeys) (Client, error) { @@ -101,11 +101,14 @@ func anthropicProviderFactory(cfg Config, keys ProviderKeys) (Client, error) { // Constructor // newAnthropic constructs an Anthropic client using explicit configuration values. // The apiKey may be empty; calls will fail until a valid key is supplied. -func newAnthropic(baseURL, model, apiKey string, defaultTemp *float64) Client { +// Following the Go idiom "return concrete types, accept interfaces", this +// returns anthropicClient directly; the provider registry wraps it back into a +// Client at registration time. +func newAnthropic(baseURL, model, apiKey string, defaultTemp *float64) anthropicClient { return newAnthropicWithTimeout(baseURL, model, apiKey, defaultTemp, 0) } -func newAnthropicWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) Client { +func newAnthropicWithTimeout(baseURL, model, apiKey string, defaultTemp *float64, timeoutSec int) anthropicClient { if strings.TrimSpace(baseURL) == "" { baseURL = "https://api.anthropic.com/v1" } -- cgit v1.2.3