Documentation
¶
Overview ¶
Package imagegen provides provider-neutral image generation primitives.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsContextError ¶
IsContextError lets the tool distinguish cancellation/deadline failures from provider errors without parsing strings.
func XAIImageAspectRatios ¶
func XAIImageAspectRatios() []string
XAIImageAspectRatios returns the supported xAI image geometry values without exposing mutable package state to capability consumers.
func XAIImageResolutions ¶
func XAIImageResolutions() []string
XAIImageResolutions returns the supported xAI resolution values.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the shared synchronous Images transport with a protocol-specific request encoder.
func NewClient ¶
func NewClient(cfg ClientConfig) (*Client, error)
NewClient validates config eagerly so a misconfigured image provider can be omitted from the agent tool list instead of failing only after a tool call.
func NewXAIImagesClient ¶
func NewXAIImagesClient(cfg ClientConfig) (*Client, error)
NewXAIImagesClient constructs the xAI-native image adapter. Keeping this protocol separate prevents OpenAI-only fields from crossing the managed xAI boundary and makes the approved request match the dispatched payload.
type ClientConfig ¶
type ClientConfig struct {
Protocol Protocol
BaseURL string
APIKey string
Headers map[string]string
// Credential resolves a managed bearer token immediately before dispatch.
// When set, an empty token fails closed and protected headers are applied
// after configured headers.
Credential CredentialFunc
Model string
// AssetHosts explicitly allows temporary image URL hosts in addition to the
// provider API host. Values are exact hosts or "*.example.com" wildcards.
AssetHosts []string
HTTPClient *http.Client
MaxImageSize int64
// AllowInsecureHTTP exists for local tests and development endpoints. Real
// provider configuration must leave it false.
AllowInsecureHTTP bool
}
ClientConfig describes one concrete image-generation endpoint. Secrets are deliberately kept out of result and error types so callers can safely serialize those values into session records.
type CredentialFunc ¶
CredentialFunc resolves request-scoped managed authorization without exposing bearer tokens to image runtime configuration or session records.
type Generator ¶
Generator is the seam used by the generate_image tool and provider adapters.
func NewGenerator ¶
func NewGenerator(cfg ClientConfig) (Generator, error)
NewGenerator constructs the exact protocol adapter selected by provider capability resolution. Callers must not infer a protocol from a provider or model name.
type Image ¶
type Image struct {
Data []byte
MIMEType string
Width int
Height int
SourceURL string
RevisedPrompt string
}
Image is validated binary output. SourceURL is retained only as provenance; callers should persist Data in managed local storage instead of depending on the provider's temporary URL.
type Protocol ¶
type Protocol string
Protocol identifies the upstream image-generation wire protocol.
const ( // ProtocolOpenAIImages is the POST /images/generations JSON protocol used // by OpenAI and compatible providers such as BigModel. ProtocolOpenAIImages Protocol = "openai_images" // ProtocolXAIImages is xAI's image-generation protocol. Although it shares // the OpenAI Images endpoint shape, its native output controls are // aspect_ratio and resolution rather than size. ProtocolXAIImages Protocol = "xai_images" // ProtocolTokenPlanMultimodal is the synchronous multimodal-generation // protocol exposed by Alibaba Token Plan. It is deliberately distinct from // both OpenAI Images and the general DashScope asynchronous task API. ProtocolTokenPlanMultimodal Protocol = "token_plan_multimodal" )
type Request ¶
type Request struct {
Prompt string
Size string
AspectRatio string
Resolution string
Quality string
Background string
OutputFormat string
ResponseFormat string
Count int
}
Request is the provider-neutral subset supported by the POC protocol. Empty optional values are omitted so older OpenAI-compatible gateways do not reject newer fields they do not understand.
type Result ¶
type Result struct {
Images []Image
}
Result contains all images returned by one billable upstream invocation.
type TokenPlanMultimodalClient ¶
type TokenPlanMultimodalClient struct {
// contains filtered or unexported fields
}
TokenPlanMultimodalClient implements Alibaba Token Plan's synchronous image endpoint. Token Plan uses the DashScope-style messages schema on a plan-specific host; it is not an OpenAI Images endpoint and must not send the X-DashScope-Async header used by the general asynchronous task API.
func NewTokenPlanMultimodalClient ¶
func NewTokenPlanMultimodalClient(cfg ClientConfig) (*TokenPlanMultimodalClient, error)
NewTokenPlanMultimodalClient validates the endpoint eagerly so an invalid route never enters the agent's tool catalog.