Documentation
¶
Overview ¶
Package transformer provides the base transformer implementation.
Package transformer defines the transformer interface for request/response transformation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseTransformer ¶
type BaseTransformer struct {
// contains filtered or unexported fields
}
BaseTransformer provides common utilities for transformers.
func NewBaseTransformer ¶
func NewBaseTransformer(name string) *BaseTransformer
NewBaseTransformer creates a new base transformer.
func (*BaseTransformer) MarshalSSEEvent ¶
func (b *BaseTransformer) MarshalSSEEvent(eventType string, data any) (SSEEvent, error)
MarshalSSEEvent creates an SSEEvent from the provided data.
func (*BaseTransformer) Name ¶
func (b *BaseTransformer) Name() string
Name returns the transformer name.
type Provider ¶
Provider represents a provider configuration (deprecated, for backward compatibility).
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages transformer instances. Uses sync.Map for optimal read-heavy concurrency (write-once at startup, read on every request).
func (*Registry) Get ¶
func (r *Registry) Get(name string) (Transformer, error)
Get retrieves a transformer by name.
func (*Registry) Register ¶
func (r *Registry) Register(t Transformer)
Register adds a transformer to the registry.
type SSEEvent ¶
type SSEEvent struct {
// EventType is the SSE event type (e.g., "message_start", "content_block_delta").
EventType string
// Data is the raw JSON data payload.
Data []byte
}
SSEEvent represents a complete server-sent event with type and data.
type Transformer ¶
type Transformer interface {
// Name returns the transformer name.
Name() string
// Endpoint returns the API endpoint path.
Endpoint() string
// PrepareRequest converts Anthropic request to provider HTTP request.
PrepareRequest(req *anthropic.Request, baseURL, apiKey, model string) (*http.Request, error)
// ParseResponse converts provider HTTP response to Anthropic response.
ParseResponse(resp *http.Response) (*anthropic.Response, error)
// SupportsStreaming returns true if transformer supports streaming.
SupportsStreaming() bool
// TransformStreamEvent converts provider SSE event to Anthropic SSE events.
TransformStreamEvent(event *SSEEvent) ([]SSEEvent, error)
}
Transformer transforms between Anthropic and provider formats.