Documentation
¶
Overview ¶
Package convmeta defines the conversion-context contract between format converters (future relaykit) and the hosting application. Converters read protocol state and per-request options exclusively through the Meta interface; the host's RelayInfo implements it.
Index ¶
- Constants
- func ChannelTypeOf(m Meta) int
- func GuessRelayFormatFromRequest(req any) (types.RelayFormat, bool)
- func UpstreamModelName(m Meta) string
- type ClaudeConvertInfo
- type ClaudeOptions
- type GeminiOptions
- type Meta
- type Options
- type Values
- func (v *Values) AppendRequestConversion(format types.RelayFormat)
- func (v *Values) ConvOptions() *Options
- func (v *Values) EnsureClaudeConvertInfo() *ClaudeConvertInfo
- func (v *Values) GetChannelID() int
- func (v *Values) GetChannelType() int
- func (v *Values) GetEstimatePromptTokens() int
- func (v *Values) GetIsStream() bool
- func (v *Values) GetOriginModelName() string
- func (v *Values) GetReasoningEffort() string
- func (v *Values) GetSendResponseCount() int
- func (v *Values) GetUpstreamModelName() string
- func (v *Values) HasChannelMeta() bool
- func (v *Values) IncrSendResponseCount()
- func (v *Values) SetReasoningEffort(effort string)
Constants ¶
const ( LastMessageTypeNone = "none" LastMessageTypeText = "text" LastMessageTypeTools = "tools" LastMessageTypeThinking = "thinking" )
Variables ¶
This section is empty.
Functions ¶
func ChannelTypeOf ¶
func GuessRelayFormatFromRequest ¶
func GuessRelayFormatFromRequest(req any) (types.RelayFormat, bool)
GuessRelayFormatFromRequest infers the relay format from a request DTO's concrete type. Moved from relay/common (which keeps a delegating alias).
func UpstreamModelName ¶
UpstreamModelName / ChannelTypeOf are nil-safe accessors for optional Meta values (converters are often called with a nil Meta in tests and compat shims).
Types ¶
type ClaudeConvertInfo ¶
type ClaudeConvertInfo struct {
LastMessagesType string
Index int
Usage *dto.Usage
FinishReason string
Done bool
ToolCallBaseIndex int
ToolCallMaxIndexOffset int
}
ClaudeConvertInfo carries mutable state for OpenAI chat → Claude Messages stream conversion. Moved here from relay/common (which keeps an alias).
type ClaudeOptions ¶
type ClaudeOptions struct {
// ThinkingAdapterEnabled turns "-thinking"-suffixed OpenAI model names
// into Claude extended-thinking requests.
ThinkingAdapterEnabled bool
// ThinkingAdapterBudgetTokensPercentage sizes thinking budget_tokens as a
// fraction of max_tokens when the adapter fires.
ThinkingAdapterBudgetTokensPercentage float64
// DefaultMaxTokens returns the max_tokens to inject when the source
// request carries none. The Claude Messages API requires max_tokens
// (omitting it is a 400), so when this hook is nil and no other path
// supplies a value, OpenAI→Claude request conversion fails with an
// explicit error instead of emitting a request the upstream is
// guaranteed to reject. The MyAPI host always provides this hook;
// standalone relaykit users must supply one or guarantee max_tokens on
// every request.
DefaultMaxTokens func(modelName string) int
}
func (*ClaudeOptions) DefaultMaxTokensFor ¶
func (o *ClaudeOptions) DefaultMaxTokensFor(modelName string) (int, bool)
type GeminiOptions ¶
type GeminiOptions struct {
// ThinkingAdapterEnabled maps -thinking/-nothinking/effort suffixes to
// Gemini thinkingConfig.
ThinkingAdapterEnabled bool
// ThinkingAdapterBudgetTokensPercentage sizes thinkingBudget as a fraction
// of maxOutputTokens when the adapter fires.
ThinkingAdapterBudgetTokensPercentage float64
// FunctionCallThoughtSignatureEnabled attaches thoughtSignature bypass
// values to function-call parts.
FunctionCallThoughtSignatureEnabled bool
// SupportsImagine reports whether the model supports image generation
// (switches response modalities). Nil means "never".
SupportsImagine func(modelName string) bool
// SafetySetting returns the harm threshold for a category. Nil or empty
// return means no safetySettings are attached.
SafetySetting func(category string) string
}
func (*GeminiOptions) SafetySettingFor ¶
func (o *GeminiOptions) SafetySettingFor(category string) string
func (*GeminiOptions) SupportsImagineModel ¶
func (o *GeminiOptions) SupportsImagineModel(modelName string) bool
type Meta ¶
type Meta interface {
GetOriginModelName() string
GetUpstreamModelName() string
// HasChannelMeta reports whether upstream channel information is attached;
// converters use it to decide if GetUpstreamModelName is meaningful.
HasChannelMeta() bool
GetChannelID() int
GetChannelType() int
GetIsStream() bool
GetReasoningEffort() string
// SetReasoningEffort records the effort level a converter derived from a
// model-name suffix so downstream billing/logging can see it.
SetReasoningEffort(effort string)
GetEstimatePromptTokens() int
// EnsureClaudeConvertInfo lazily creates and returns the mutable
// OpenAI→Claude stream conversion state. For non-nil receivers, the same
// instance must be returned for the lifetime of one streaming session; a
// nil receiver may return a temporary initialized state.
EnsureClaudeConvertInfo() *ClaudeConvertInfo
// GetSendResponseCount / IncrSendResponseCount expose the shared
// downstream-chunk counter (the host may also increment it).
GetSendResponseCount() int
IncrSendResponseCount()
// AppendRequestConversion records a hop in the request format chain.
AppendRequestConversion(format types.RelayFormat)
// ConvOptions returns the request-scoped conversion options snapshot.
// Must never return nil.
ConvOptions() *Options
}
Meta is the only view of the relay session that format converters may use. It is satisfied by *relaycommon.RelayInfo on the host side; other embedders (tests, external relaykit users) can use *Values. Implementations backed by pointer types must make every method safe on a nil receiver: a typed-nil pointer stored in Meta is still a non-nil interface, and relaykit deliberately does not use reflection to detect that case.
type Options ¶
type Options struct {
Claude ClaudeOptions
Gemini GeminiOptions
// OpenRouterDialect marks the upstream as OpenRouter's OpenAI-compatible
// surface, which accepts extra fields (reasoning config, cache_control on
// system parts) that converters emit only for that dialect. The host sets
// it from the channel type.
OpenRouterDialect bool
// PreserveThinkingSuffix reports models whose -thinking/-nothinking/effort
// suffix must be kept on the outgoing model name (host blacklist lookup).
// Nil means "never preserve".
PreserveThinkingSuffix func(modelName string) bool
}
Options is the per-request snapshot of host configuration that converters consult. The host fills it from its settings system when constructing the Meta (see relaycommon.RelayInfo.ConvOptions); relaykit users fill it directly. Zero value = every adaptation disabled, no defaults applied.
func (*Options) ShouldPreserveThinkingSuffix ¶
type Values ¶
type Values struct {
OriginModelName string
UpstreamModelName string
ChannelMetaAttached bool
ChannelID int
ChannelType int
IsStream bool
ReasoningEffort string
EstimatePromptTokens int
ClaudeConvertInfo *ClaudeConvertInfo
SendResponseCount int
ConversionChain []types.RelayFormat
Options *Options
}
Values is a plain-struct Meta implementation for tests and non-RelayInfo hosts (the relaykit-native entry point).
func (*Values) AppendRequestConversion ¶
func (v *Values) AppendRequestConversion(format types.RelayFormat)
func (*Values) ConvOptions ¶
func (*Values) EnsureClaudeConvertInfo ¶
func (v *Values) EnsureClaudeConvertInfo() *ClaudeConvertInfo
func (*Values) GetChannelID ¶
func (*Values) GetChannelType ¶
func (*Values) GetEstimatePromptTokens ¶
func (*Values) GetIsStream ¶
func (*Values) GetOriginModelName ¶
func (*Values) GetReasoningEffort ¶
func (*Values) GetSendResponseCount ¶
func (*Values) GetUpstreamModelName ¶
func (*Values) HasChannelMeta ¶
func (*Values) IncrSendResponseCount ¶
func (v *Values) IncrSendResponseCount()