messages

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockingInterception

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

func NewBlockingInterceptor

func NewBlockingInterceptor(
	id uuid.UUID,
	reqPayload MessagesRequestPayload,
	providerName string,
	cfg config.Anthropic,
	bedrockCfg *config.AWSBedrock,
	clientHeaders http.Header,
	authHeaderName string,
	tracer trace.Tracer,
) *BlockingInterception

func (*BlockingInterception) CorrelatingToolCallID added in v1.1.0

func (i *BlockingInterception) CorrelatingToolCallID() *string

func (*BlockingInterception) ID

func (i *BlockingInterception) ID() uuid.UUID

func (*BlockingInterception) Model

func (i *BlockingInterception) Model() string

func (*BlockingInterception) ProcessRequest

func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Request) (outErr error)

func (*BlockingInterception) Setup

func (i *BlockingInterception) Setup(logger slog.Logger, recorder recorder.Recorder, mcpProxy mcp.ServerProxier)

func (*BlockingInterception) Streaming

func (s *BlockingInterception) Streaming() bool

func (*BlockingInterception) TraceAttributes

func (i *BlockingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue

type ErrorResponse

type ErrorResponse struct {
	*anthropic.ErrorResponse

	StatusCode int `json:"-"`
}

func (*ErrorResponse) Error

func (a *ErrorResponse) Error() string

type MessagesRequestPayload added in v1.0.10

type MessagesRequestPayload []byte

MessagesRequestPayload is raw JSON bytes of an Anthropic Messages API request. Methods provide package-specific reads and rewrites while preserving the original body for upstream pass-through.

func NewMessagesRequestPayload added in v1.0.10

func NewMessagesRequestPayload(raw []byte) (MessagesRequestPayload, error)

func (MessagesRequestPayload) Stream added in v1.0.10

func (p MessagesRequestPayload) Stream() bool

type StreamingInterception

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

func NewStreamingInterceptor

func NewStreamingInterceptor(
	id uuid.UUID,
	reqPayload MessagesRequestPayload,
	providerName string,
	cfg config.Anthropic,
	bedrockCfg *config.AWSBedrock,
	clientHeaders http.Header,
	authHeaderName string,
	tracer trace.Tracer,
) *StreamingInterception

func (*StreamingInterception) CorrelatingToolCallID added in v1.1.0

func (i *StreamingInterception) CorrelatingToolCallID() *string

func (*StreamingInterception) ID

func (i *StreamingInterception) ID() uuid.UUID

func (*StreamingInterception) Model

func (i *StreamingInterception) Model() string

func (*StreamingInterception) ProcessRequest

func (i *StreamingInterception) ProcessRequest(w http.ResponseWriter, r *http.Request) (outErr error)

ProcessRequest handles a request to /v1/messages. This API has a state-machine behind it, which is described in https://docs.claude.com/en/docs/build-with-claude/streaming#event-types.

Each stream uses the following event flow: - `message_start`: contains a Message object with empty content. - A series of content blocks, each of which have a `content_block_start`, one or more `content_block_delta` events, and a `content_block_stop` event. - Each content block will have an index that corresponds to its index in the final Message content array. - One or more `message_delta` events, indicating top-level changes to the final Message object. - A final `message_stop` event.

It will inject any tools which have been provided by the mcp.ServerProxier.

When a response from the server includes an event indicating that a tool must be invoked, a conditional flow takes place:

a) if the tool is not injected (i.e. defined by the client), relay the event unmodified b) if the tool is injected, it will be invoked by the mcp.ServerProxier in the remote MCP server, and its results relayed to the SERVER. The response from the server will be handled synchronously, and this loop can continue until all injected tool invocations are completed and the response is relayed to the client.

func (*StreamingInterception) Setup

func (s *StreamingInterception) Setup(logger slog.Logger, recorder recorder.Recorder, mcpProxy mcp.ServerProxier)

func (*StreamingInterception) Streaming

func (s *StreamingInterception) Streaming() bool

func (*StreamingInterception) TraceAttributes

func (s *StreamingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue

Jump to

Keyboard shortcuts

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