modelalias

package
v0.1.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ModeDisabled = "disabled"
	ModeRewrite  = "rewrite"

	EnvAliasesFile = "CCWRAP_MODEL_ALIASES_FILE"
	EnvAliasesJSON = "CCWRAP_MODEL_ALIASES_JSON"
)
View Source
const MaxRewriteBytes int64 = 32 * 1024 * 1024

Variables

This section is empty.

Functions

func ExtractFromFlagSettings

func ExtractFromFlagSettings(settings map[string]any) (map[string]string, error)

func Fingerprint

func Fingerprint(forward map[string]string) string

func LoadFile

func LoadFile(path string) (map[string]string, error)

func LooksProviderSpecific

func LooksProviderSpecific(modelID string) bool

LooksProviderSpecific reports whether modelID is shaped like a provider-routed id (Bedrock, Vertex, Azure-style deployments, ARNs) rather than a Claude logical id. It backs the strict-mode fail-closed gates (rewriteRequestObjectModel, validateHiddenModeModels), so it must err toward TRUE for provider shapes: a miss here lets an unaliased provider id sail to the gateway unrewritten. Marker scan runs BEFORE any canonical-shape exemption — Vertex ids ("claude-opus-4-8@20250115") start with "claude-" yet are provider-specific, and Bedrock ids carry an "anthropic." segment ("anthropic.claude-opus-4-8", "us.anthropic.claude-...-v1:0") with none of the path/ARN markers. Canonical ids ("claude-opus-4-8", bare aliases like "sonnet") contain no marker and fall through to false. Explicitly aliased ids are exempt upstream of this check (cfg.Forward is consulted first).

func NormalizeModelID

func NormalizeModelID(value string, cfg Config) (logical string, changed bool, unresolved bool)

func ParseJSON

func ParseJSON(data []byte, source string) (map[string]string, error)

func ParsePairs

func ParsePairs(pairs []string) (map[string]string, error)

func ProviderSpecificModelArgs

func ProviderSpecificModelArgs(args []string) []string

func RewriteJSONLResponseBody

func RewriteJSONLResponseBody(body []byte, ctx *Context) ([]byte, error)

func RewriteJSONResponseBody

func RewriteJSONResponseBody(body []byte, ctx *Context) ([]byte, error)

func RewriteResponse

func RewriteResponse(resp *http.Response, ctx *Context) error

func WrapSSEResponse

func WrapSSEResponse(body io.ReadCloser, ctx *Context) io.ReadCloser

Types

type Config

type Config struct {
	Forward                  map[string]string
	Strict                   bool
	Source                   string
	Fingerprint              string
	ProviderModelPassthrough bool
}

func New

func New(forward map[string]string, source string, strict bool) (Config, error)

func Resolve

func Resolve(opts ResolveOptions) (Config, []string, error)

func (Config) Count

func (c Config) Count() int

func (Config) Enabled

func (c Config) Enabled() bool

func (Config) LogicalForProvider

func (c Config) LogicalForProvider(provider string) (string, bool)

func (Config) Mode

func (c Config) Mode() string

type Context

type Context struct {
	Enabled           bool
	Rewritten         bool
	NormalizeResponse bool
	LogicalModel      string
	UpstreamModel     string
	Reverse           map[string]string
}

func RewriteJSONBatchCreateBody

func RewriteJSONBatchCreateBody(body []byte, cfg Config, ctx *Context) ([]byte, *Context, error)

func RewriteJSONRequestBody

func RewriteJSONRequestBody(path string, body []byte, cfg Config) ([]byte, *Context, error)

func RewriteRequest

func RewriteRequest(r *http.Request, cfg Config) (*Context, error)

type Normalization

type Normalization struct {
	Source        string
	LogicalModel  string
	ProviderModel string
}

func NormalizeClaudeModelArgs

func NormalizeClaudeModelArgs(args []string, cfg Config) (out []string, normalized []Normalization, unresolved []string)

func NormalizeModelEnv

func NormalizeModelEnv(env map[string]string, cfg Config, isModelKey func(string) bool) (out map[string]string, normalized []Normalization, unresolved map[string]string)

type ResolveOptions

type ResolveOptions struct {
	ExplicitFile             string
	ExplicitFileContent      []byte // if non-empty, used in place of LoadFile(ExplicitFile); takes normative precedence over reading from disk
	ExplicitPairs            []string
	ParentEnv                []string
	EnvFileContent           []byte // if non-empty, used in place of LoadFile(env-path); takes normative precedence over reading from disk
	FlagSettings             map[string]any
	Strict                   bool
	ProviderModelPassthrough bool
}

Jump to

Keyboard shortcuts

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