diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-06 11:06:19 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-06 11:06:19 +0300 |
| commit | 05f54cc0cb8cf3535698ab5027d200842bdb28e3 (patch) | |
| tree | 30b7e778be29db63301119b7cfa8be5a5edc041e /internal/image | |
| parent | 23160bce9a18a70080a85dda6e9c654499aba7f7 (diff) | |
refactor: consolidate provider factory test seams into shared named types
Define audio.ProviderFactory, image.PromptAwareClient,
image.OpenAIClientFactory, image.NanoBananaClientFactory, and
image.ClientFactories as the single source of truth for the three injectable
factory signatures that were previously duplicated across processor.Processor,
gui.Application, and gui.GenerationOrchestrator. Replace all three separate
function-type fields with imageFactories image.ClientFactories +
newAudioProvider audio.ProviderFactory, eliminating the parallel field
declarations and the local promptAwareImageClient interface in gui/generator.go.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/image')
| -rw-r--r-- | internal/image/search.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/internal/image/search.go b/internal/image/search.go index 7e405da..61176cd 100644 --- a/internal/image/search.go +++ b/internal/image/search.go @@ -77,6 +77,61 @@ type ImageClient interface { AttributionProvider } +// PromptAwareClient extends ImageClient with a callback for receiving the +// generated image prompt before the actual image download begins. Both +// OpenAIClient and NanoBananaClient implement this interface. It is the +// preferred return type for factory functions so callers (processor, gui) can +// register a prompt callback without a type-assertion. +type PromptAwareClient interface { + ImageClient + // SetPromptCallback registers a function that is called with the generated + // prompt text before the image download begins. + SetPromptCallback(func(prompt string)) +} + +// OpenAIClientFactory is the canonical type for functions that construct an +// OpenAI image client from config. Using a named type avoids duplicating the +// raw function signature in every package that needs to inject or replace the +// factory (processor, gui). +type OpenAIClientFactory func(*OpenAIConfig) PromptAwareClient + +// NanoBananaClientFactory is the canonical type for functions that construct a +// NanoBanana (Gemini) image client from config. Using a named type avoids +// duplicating the raw function signature in every package that needs to inject +// or replace the factory (processor, gui). +type NanoBananaClientFactory func(*NanoBananaConfig) PromptAwareClient + +// ClientFactories groups the two image-provider construction functions. +// Embedding or holding a ClientFactories value is the single source of truth +// for the image-factory test seams; packages no longer redeclare the same +// fields independently. Audio factory injection is kept separate (audio.ProviderFactory) +// to avoid an import cycle between the image and audio packages. +type ClientFactories struct { + // NewOpenAIClient constructs a PromptAwareClient from an OpenAI config. + // Production code uses the real constructor; tests replace it with a fake. + NewOpenAIClient OpenAIClientFactory + + // NewNanoBananaClient constructs a PromptAwareClient from a NanoBanana config. + // Production code uses the real constructor; tests replace it with a fake. + NewNanoBananaClient NanoBananaClientFactory +} + +// DefaultClientFactories returns a ClientFactories wired to the real production +// constructors. Callers that need test doubles replace individual fields before +// passing the value to a constructor. +func DefaultClientFactories() ClientFactories { + return ClientFactories{ + NewOpenAIClient: func(c *OpenAIConfig) PromptAwareClient { + // NewOpenAIClient returns *OpenAIClient which implements PromptAwareClient. + return NewOpenAIClient(c) + }, + NewNanoBananaClient: func(c *NanoBananaConfig) PromptAwareClient { + // NewNanoBananaClient returns *NanoBananaClient which implements PromptAwareClient. + return NewNanoBananaClient(c) + }, + } +} + // SearchError represents an error from an image search provider type SearchError struct { Provider string |
