ops

package
v0.260412.1600-preview Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const ClaudeCodeVersion = "2.1.86"
View Source
const FingerprintSalt = "59cf53e54c78"

FingerprintSalt is the salt used in computeFingerprint. IMPORTANT: Must stay in sync with Claude Code's FINGERPRINT_SALT constant.

Variables

View Source
var ProviderConfigs = []providerConfig{

	{
		APIBasePattern: "api.deepseek.com",
		ModelPattern:   "*",
		Transform:      applyDeepSeekTransform,
	},

	{
		APIBasePattern: "api.moonshot.cn",
		ModelPattern:   "*",
		Transform:      applyDeepSeekTransform,
	},

	{
		APIBasePattern: "api.moonshot.ai",
		ModelPattern:   "*",
		Transform:      applyDeepSeekTransform,
	},

	{
		APIBasePattern: "generativelanguage.googleapis.com",
		ModelPattern:   "gemini",
		Transform:      applyGeminiTransform,
	},

	{
		APIBasePattern: "poe.com",
		ModelPattern:   "gemini",
		Transform:      applyGeminiPoeTransform,
	},
}

ProviderConfigs holds all registered provider configurations Add new providers here with their APIBase domain patterns

View Source
var ResponseConfigs = []responseConfig{

	{"api.deepseek.com", applyDeepSeekResponseTransform},
}

ResponseConfigs holds all registered provider response configurations

Functions

func ApplyAnthropicBetaMetadataTransform

func ApplyAnthropicBetaMetadataTransform(req *anthropic.BetaMessageNewParams, extra map[string]any) *anthropic.BetaMessageNewParams

ApplyAnthropicBetaMetadataTransform injects OAuth user_id into Anthropic beta request metadata. This adds metadata.user_id in JSON format for Anthropic API tracking.

Note: Only injects metadata when provider is OAuth and has valid UserID.

func ApplyAnthropicBetaModelTransform

func ApplyAnthropicBetaModelTransform(req *anthropic.BetaMessageNewParams, model string) *anthropic.BetaMessageNewParams

ApplyAnthropicBetaModelTransform applies Anthropic API beta model-specific filtering. Same rules as V1 but for BetaMessageNewParams.

func ApplyAnthropicV1MetadataTransform

func ApplyAnthropicV1MetadataTransform(req *anthropic.MessageNewParams, extra map[string]any) *anthropic.MessageNewParams

ApplyAnthropicV1MetadataTransform injects OAuth user_id into Anthropic v1 request metadata. This adds metadata.user_id in JSON format for Anthropic API tracking.

Note: Only injects metadata when provider is OAuth and has valid UserID.

func ApplyAnthropicV1ModelTransform

func ApplyAnthropicV1ModelTransform(req *anthropic.MessageNewParams, model string) *anthropic.MessageNewParams

ApplyAnthropicV1ModelTransform applies Anthropic API v1 model-specific filtering. This handles model-specific limitations such as adaptive thinking only being supported by Claude Opus 4.6 (claude-opus-4-6) and Claude Sonnet 4.6 (claude-sonnet-4-6).

Parameters:

  • req: The Anthropic v1 request to transform
  • model: The target model name

Returns the transformed request (same type as input).

Note: This applies to ALL Anthropic API requests, regardless of authentication method (API key or OAuth token). The limitation is in the Anthropic API itself, not the auth method.

func ApplyCodexResponsesTransform

func ApplyCodexResponsesTransform(req *responses.ResponseNewParams, originalRequest interface{}) *responses.ResponseNewParams

ApplyCodexResponsesTransform applies Codex-specific transformations to a Responses API request. This is called from VendorTransform for Codex backend providers.

It handles:

  • Stream configuration (always enabled for Codex)
  • Reasoning config (converts Anthropic "thinking" to Codex "reasoning")
  • Tool name shortening (64 char limit)
  • Tool parameter normalization
  • Special tool mappings (web_search_20250305 -> web_search)

Reference: ref/anthropic2codex.go.ref

func ApplyCodexTransform

func ApplyCodexTransform(anthropicReq *anthropic.BetaMessageNewParams, responsesReq *responses.ResponseNewParams) *responses.ResponseNewParams

ApplyCodexTransform applies Codex-specific transformations to a Responses API request. This is a backward-compatible wrapper for the server-level call. Deprecated: Use ApplyCodexResponsesTransform with TransformContext instead.

func ApplyCursorCompatContentNormalization

func ApplyCursorCompatContentNormalization(req *openai.ChatCompletionNewParams)

ApplyCursorCompatContentNormalization is the exported version of normalizeCursorContent. It flattens rich content in messages for Cursor compatibility. This should be called for ALL providers when cursor_compat is enabled.

func ApplyProviderTransforms

func ApplyProviderTransforms(req *openai.ChatCompletionNewParams, providerURL, model string, config *protocol.OpenAIConfig) *openai.ChatCompletionNewParams

ApplyProviderTransforms applies provider-specific transformations Falls back to default handling if no specific transform found

func ApplyResponseTransforms

func ApplyResponseTransforms(resp map[string]interface{}, providerURL, model string) map[string]interface{}

ApplyResponseTransforms applies provider-specific transformations to responses

func FormatMetadataUserID

func FormatMetadataUserID(m *MetadataUserID) string

FormatMetadataUserID formats a MetadataUserID to JSON string. Returns empty string for nil input.

func GenHex5

func GenHex5() string

func MessageToMap

func MessageToMap(msg openai.ChatCompletionMessageParamUnion) (map[string]interface{}, error)

MessageToMap converts a ChatCompletionMessageParamUnion to a map for modification

Types

type MetadataUserID

type MetadataUserID struct {
	DeviceID    string `json:"device_id"`
	AccountUUID string `json:"account_uuid"`
	SessionID   string `json:"session_id"`
}

MetadataUserID represents the JSON structure for metadata.user_id This matches Claude Code's format (>= 2.1.78)

func BuildMetadataUserID

func BuildMetadataUserID(extra map[string]any) *MetadataUserID

BuildMetadataUserID builds a MetadataUserID from extra map. Returns nil if all fields are empty after fixing.

func FixMetadataUserID

func FixMetadataUserID(raw string) *MetadataUserID

FixMetadataUserID parses and fixes a metadata user ID string. Returns a new MetadataUserID with generated fields for missing values.

func ParseMetadataUserID

func ParseMetadataUserID(raw string) *MetadataUserID

ParseMetadataUserID parses a metadata.user_id string in either JSON or legacy format. Returns nil if the input cannot be parsed.

func (*MetadataUserID) Fix

func (m *MetadataUserID) Fix(extras map[string]any)

func (*MetadataUserID) Format

func (m *MetadataUserID) Format() string

Format converts MetadataUserID to string for metadata.

func (*MetadataUserID) IsEmpty

func (m *MetadataUserID) IsEmpty() bool

IsEmpty checks if the MetadataUserID is effectively empty.

func (*MetadataUserID) IsValid

func (m *MetadataUserID) IsValid() bool

IsValid checks if the MetadataUserID has required fields.

type ProviderTransform

ProviderTransform applies provider-specific transformations to OpenAI requests

func GetProviderTransform

func GetProviderTransform(providerURL, model string) ProviderTransform

GetProviderTransform identifies provider by APIBase URL string and returns its transform Returns nil if no specific transform is needed (fallback to default)

type ResponseTransform

type ResponseTransform func(map[string]interface{}, string, string) map[string]interface{}

ResponseTransform applies provider-specific transformations to OpenAI responses

func GetResponseTransform

func GetResponseTransform(providerURL string) ResponseTransform

GetResponseTransform identifies provider by APIBase URL and returns its response transform

Jump to

Keyboard shortcuts

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