transform

package
v0.260321.800-hotfix Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseTransform

type BaseTransform struct {
	// contains filtered or unexported fields
}

BaseTransform handles protocol conversion from original format to target API style This is the first transform in the chain, converting the request format before consistency normalization and vendor-specific adjustments.

func NewBaseTransform

func NewBaseTransform(targetType TargetAPIStyle) *BaseTransform

NewBaseTransform creates a new BaseTransform with the specified target API style

func (*BaseTransform) Apply

func (t *BaseTransform) Apply(ctx *TransformContext) error

Apply converts the request to the target API style This transform detects the original request type and applies the appropriate conversion. For OpenAI Chat target, it converts Anthropic v1/beta requests to OpenAI Chat format. For OpenAI Responses target, it converts Anthropic v1/beta requests to Responses format. For Anthropic targets, it converts OpenAI requests to Anthropic format. If the input type already matches the target type, no conversion is performed.

func (*BaseTransform) Name

func (t *BaseTransform) Name() string

Name returns the name of this transform

type ConsistencyTransform

type ConsistencyTransform struct {
	// contains filtered or unexported fields
}

ConsistencyTransform applies cross-provider normalization rules to requests. These rules apply to ALL providers, regardless of vendor.

Consistency Transform handles:

  • Tool Schema Normalization - Ensure type: "object", normalize properties
  • Scenario Flags - Disable stream usage, thinking mode if needed
  • Messages Normalization - Truncate tool_call_id to 40 chars
  • Validation - Check max_tokens, temperature ranges

func NewConsistencyTransform

func NewConsistencyTransform(targetAPIStyle TargetAPIStyle) *ConsistencyTransform

NewConsistencyTransform creates a new ConsistencyTransform for the given target API style.

func (*ConsistencyTransform) Apply

Apply executes the consistency normalization based on the target API style. Modifies ctx.Request in place and returns an error if transformation fails.

func (*ConsistencyTransform) Name

func (t *ConsistencyTransform) Name() string

Name returns the transform name for logging and tracking.

type GoogleRequest added in v0.260324.0

type GoogleRequest struct {
	Model    string
	Contents []*genai.Content
	Config   *genai.GenerateContentConfig
}

GoogleRequest wraps Google API request parameters Google's SDK uses separate parameters rather than a single request struct

type TargetAPIStyle added in v0.260324.0

type TargetAPIStyle string

TargetAPIStyle represents the target API style for protocol conversion

const (
	// TargetAPIStyleOpenAIChat converts requests to OpenAI Chat Completions format
	TargetAPIStyleOpenAIChat TargetAPIStyle = "openai_chat"

	// TargetAPIStyleOpenAIResponses converts requests to OpenAI Responses API format
	TargetAPIStyleOpenAIResponses TargetAPIStyle = "openai_responses"

	// TargetAPIStyleAnthropicV1 converts requests to Anthropic v1 Messages API format
	TargetAPIStyleAnthropicV1 TargetAPIStyle = "anthropic_v1"

	// TargetAPIStyleAnthropicBeta converts requests to Anthropic v1beta Messages API format
	TargetAPIStyleAnthropicBeta TargetAPIStyle = "anthropic_beta"

	// TargetAPIStyleGoogle converts requests to Google Gemini API format
	TargetAPIStyleGoogle TargetAPIStyle = "google"
)

type Transform

type Transform interface {
	// Name returns the unique identifier for this transform
	Name() string

	// Apply applies the transformation to the context
	// Returns an error if the transformation fails
	Apply(ctx *TransformContext) error
}

Transform defines the interface for a single transformation step

type TransformChain

type TransformChain struct {
	// contains filtered or unexported fields
}

TransformChain manages an ordered sequence of transforms

func NewTransformChain

func NewTransformChain(transforms []Transform) *TransformChain

NewTransformChain creates a new TransformChain with the given transforms

func (*TransformChain) Add

func (c *TransformChain) Add(transform Transform)

Add appends a transform to the end of the chain

func (*TransformChain) Execute

Execute runs the transform chain on the provided context Transforms are executed in order, and each transform's name is recorded in TransformSteps. Returns the final TransformContext or an error if any transform fails with a descriptive error message.

func (*TransformChain) GetTransforms

func (c *TransformChain) GetTransforms() []Transform

GetTransforms returns a copy of the transforms in the chain

func (*TransformChain) Length

func (c *TransformChain) Length() int

Length returns the number of transforms in the chain

type TransformContext

type TransformContext struct {
	// Request is the request being transformed
	Request interface{}

	// ProviderURL identifies the provider (e.g., "api.deepseek.com")
	ProviderURL string

	// ProviderType identifies the OAuth provider type (e.g., "claude_code", "codex")
	// This is used for provider-specific model filtering
	ProviderType string

	// ScenarioFlags contains configuration flags for the scenario
	ScenarioFlags *typ.ScenarioFlags

	// IsStreaming indicates if this is a streaming request
	IsStreaming bool

	// OriginalRequest stores the original request before any transformations
	OriginalRequest interface{}

	// TransformSteps records the names of transforms that have been applied
	TransformSteps []string

	// Extra allows transforms to pass arbitrary data through the chain
	Extra map[string]interface{}
}

TransformContext carries state through the transform chain

type ValidationError

type ValidationError struct {
	Field   string      `json:"field"`
	Message string      `json:"message"`
	Value   interface{} `json:"value,omitempty"`
}

ValidationError represents a validation error for request parameters.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error implements the error interface.

type VendorTransform

type VendorTransform struct {
	ProviderURL string // e.g., "api.deepseek.com", "api.moonshot.cn"
}

VendorTransform applies provider-specific adjustments to requests This wraps the existing transformer package functionality

func NewVendorTransform

func NewVendorTransform(providerURL string) *VendorTransform

NewVendorTransform creates a new vendor transform for the given provider URL

func (*VendorTransform) Apply

func (t *VendorTransform) Apply(ctx *TransformContext) error

Apply applies vendor-specific transformations to the request

func (*VendorTransform) Name

func (t *VendorTransform) Name() string

Name returns the transform name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL