interceptor

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package interceptor implements utility interceptors for cross-cutting concerns.

Package interceptor implements utility interceptors for cross-cutting concerns.

Package interceptor implements utility interceptors for cross-cutting concerns.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MaxTokenConfig

type MaxTokenConfig struct {
	// DefaultLimit is the fallback max_tokens limit when no specific limit is found.
	DefaultLimit int
	// ProviderLimits maps provider names to their max token limits.
	ProviderLimits map[string]int
	// ModelLimits maps specific model names to their max token limits.
	// These override provider limits when matched.
	ModelLimits map[string]int
}

MaxTokenConfig holds configuration for max token limits by provider/model.

func DefaultMaxTokenConfig

func DefaultMaxTokenConfig() *MaxTokenConfig

DefaultMaxTokenConfig returns a default configuration with common provider limits.

type MaxTokenInterceptor

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

MaxTokenInterceptor adjusts max_tokens based on provider/model limits.

func NewMaxTokenInterceptor

func NewMaxTokenInterceptor() *MaxTokenInterceptor

NewMaxTokenInterceptor creates a new MaxTokenInterceptor with default configuration.

func NewMaxTokenInterceptorWithConfig

func NewMaxTokenInterceptorWithConfig(config *MaxTokenConfig) *MaxTokenInterceptor

NewMaxTokenInterceptorWithConfig creates a new MaxTokenInterceptor with custom configuration.

func (*MaxTokenInterceptor) InterceptRequest

func (i *MaxTokenInterceptor) InterceptRequest(ctx context.Context, req *anthropic.Request) error

InterceptRequest adjusts max_tokens based on provider/model limits.

type ReasoningConfig

type ReasoningConfig struct {
	// Enabled enables reasoning extraction.
	Enabled bool
	// ExtractThinking extracts thinking content from responses.
	ExtractThinking bool
	// FormatForClaudeCode formats reasoning for Claude Code display.
	FormatForClaudeCode bool
}

ReasoningConfig holds configuration for reasoning content extraction.

func DefaultReasoningConfig

func DefaultReasoningConfig() *ReasoningConfig

DefaultReasoningConfig returns a default configuration.

type ReasoningInterceptor

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

ReasoningInterceptor handles thinking/reasoning content extraction and formatting.

func NewReasoningInterceptor

func NewReasoningInterceptor() *ReasoningInterceptor

NewReasoningInterceptor creates a new ReasoningInterceptor with default configuration.

func NewReasoningInterceptorWithConfig

func NewReasoningInterceptorWithConfig(config *ReasoningConfig) *ReasoningInterceptor

NewReasoningInterceptorWithConfig creates a new ReasoningInterceptor with custom configuration.

func (*ReasoningInterceptor) ExtractReasoningFromDelta

func (i *ReasoningInterceptor) ExtractReasoningFromDelta(delta map[string]any) string

ExtractReasoningFromDelta extracts reasoning from a content_block_delta event.

func (*ReasoningInterceptor) ExtractThinkingFromResponse

func (i *ReasoningInterceptor) ExtractThinkingFromResponse(resp *anthropic.Response) string

ExtractThinkingFromResponse extracts thinking content from a response. This is a utility method that can be called by other components.

func (*ReasoningInterceptor) InterceptResponse

func (i *ReasoningInterceptor) InterceptResponse(ctx context.Context, req *anthropic.Request, resp *anthropic.Response) error

InterceptResponse extracts and formats reasoning content from non-streaming responses.

func (*ReasoningInterceptor) InterceptStreamingEvent

func (i *ReasoningInterceptor) InterceptStreamingEvent(ctx context.Context, req *anthropic.Request, eventType string, data []byte) ([]byte, error)

InterceptStreamingEvent extracts and formats reasoning content from streaming events. This implements StreamingResponseInterceptor for real-time reasoning extraction.

func (*ReasoningInterceptor) ParseReasoningEvent

func (i *ReasoningInterceptor) ParseReasoningEvent(eventType string, data []byte) (string, error)

ParseReasoningEvent parses a reasoning SSE event and returns the extracted content.

type ToolEnhanceConfig

type ToolEnhanceConfig struct {
	// Enabled enables tool enhancement.
	Enabled bool
	// EnsureDescriptions ensures all tools have descriptions.
	EnsureDescriptions bool
	// NormalizeParameters normalizes parameter schemas.
	NormalizeParameters bool
	// AddMissingType adds missing type fields to parameters.
	AddMissingType bool
}

ToolEnhanceConfig holds configuration for tool enhancement.

func DefaultToolEnhanceConfig

func DefaultToolEnhanceConfig() *ToolEnhanceConfig

DefaultToolEnhanceConfig returns a default configuration.

type ToolEnhanceInterceptor

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

ToolEnhanceInterceptor adds/modifies tool definitions for provider compatibility.

func NewToolEnhanceInterceptor

func NewToolEnhanceInterceptor() *ToolEnhanceInterceptor

NewToolEnhanceInterceptor creates a new ToolEnhanceInterceptor with default configuration.

func NewToolEnhanceInterceptorWithConfig

func NewToolEnhanceInterceptorWithConfig(config *ToolEnhanceConfig) *ToolEnhanceInterceptor

NewToolEnhanceInterceptorWithConfig creates a new ToolEnhanceInterceptor with custom configuration.

func (*ToolEnhanceInterceptor) FixToolSchema

func (i *ToolEnhanceInterceptor) FixToolSchema(schema any) (any, error)

FixToolSchema attempts to fix common issues in a tool schema.

func (*ToolEnhanceInterceptor) InterceptRequest

func (i *ToolEnhanceInterceptor) InterceptRequest(ctx context.Context, req *anthropic.Request) error

InterceptRequest enhances tool definitions for provider compatibility.

func (*ToolEnhanceInterceptor) MergeToolSchemas

func (i *ToolEnhanceInterceptor) MergeToolSchemas(schemas []any) (any, error)

MergeToolSchemas merges multiple tool schemas into one. Useful for combining tools from different providers.

func (*ToolEnhanceInterceptor) ToolSchemaFixer

func (i *ToolEnhanceInterceptor) ToolSchemaFixer() ToolSchemaFixer

ToolSchemaFixer is a helper to fix JSON marshaling issues in tool arguments.

func (*ToolEnhanceInterceptor) ValidateToolSchema

func (i *ToolEnhanceInterceptor) ValidateToolSchema(schema any) error

ValidateToolSchema validates a tool schema for common issues.

type ToolSchemaFixer

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

ToolSchemaFixer provides methods to fix JSON-related issues in tool schemas.

func (ToolSchemaFixer) FixToolCallJSON

func (f ToolSchemaFixer) FixToolCallJSON(rawArgs json.RawMessage) (map[string]any, error)

FixToolCallJSON fixes JSON marshaling issues in tool call arguments.

Jump to

Keyboard shortcuts

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