Documentation
¶
Index ¶
- Constants
- type BedrockRuntime
- type BlockingInterception
- func (i *BlockingInterception) CorrelatingToolCallID() *string
- func (i *BlockingInterception) Credential() intercept.Credential
- func (i *BlockingInterception) ID() uuid.UUID
- func (i *BlockingInterception) Model() string
- func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Request) (outErr error)
- func (i *BlockingInterception) Setup(logger slog.Logger, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
- func (*BlockingInterception) Streaming() bool
- func (i *BlockingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue
- type RequestPayload
- type ResponseError
- type StreamingInterception
- func (i *StreamingInterception) CorrelatingToolCallID() *string
- func (i *StreamingInterception) Credential() intercept.Credential
- func (i *StreamingInterception) ID() uuid.UUID
- func (i *StreamingInterception) Model() string
- func (i *StreamingInterception) ProcessRequest(w http.ResponseWriter, r *http.Request) (outErr error)
- func (i *StreamingInterception) Setup(logger slog.Logger, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
- func (*StreamingInterception) Streaming() bool
- func (i *StreamingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue
Constants ¶
const BedrockPRMUserAgent = "sdk-ua-app-id/APN_1.1%2Fpc_cdfmjwn8i6u8l9fwz8h82e4w3%24"
BedrockPRMUserAgent is Coder's AWS Partner Revenue Measurement (PRM) attribution marker for outbound Bedrock requests.
It is appended to Bedrock User-Agent headers so AWS can recognize the traffic as Coder-associated Bedrock usage.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BedrockRuntime ¶ added in v2.35.0
type BedrockRuntime struct {
Cfg aibconfig.AWSBedrock
Creds aws.CredentialsProvider
}
BedrockRuntime carries everything a Bedrock-backed interception needs: the static Bedrock config plus the AWS credentials provider.
type BlockingInterception ¶
type BlockingInterception struct {
// contains filtered or unexported fields
}
func NewBlockingInterceptor ¶
func NewBlockingInterceptor( id uuid.UUID, reqPayload RequestPayload, cfg intercept.Config, cred intercept.Credential, bedrock *BedrockRuntime, clientHeaders http.Header, tracer trace.Tracer, ) *BlockingInterception
func (*BlockingInterception) CorrelatingToolCallID ¶
func (i *BlockingInterception) CorrelatingToolCallID() *string
func (*BlockingInterception) Credential ¶
func (i *BlockingInterception) Credential() intercept.Credential
Credential returns the credential resolved for this interception.
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, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
func (*BlockingInterception) Streaming ¶
func (*BlockingInterception) Streaming() bool
func (*BlockingInterception) TraceAttributes ¶
func (i *BlockingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue
type RequestPayload ¶
type RequestPayload []byte
RequestPayload 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 NewRequestPayload ¶
func NewRequestPayload(raw []byte) (RequestPayload, error)
func (RequestPayload) Stream ¶
func (p RequestPayload) Stream() bool
type ResponseError ¶ added in v2.34.0
type ResponseError struct {
*anthropic.ErrorResponse
StatusCode int `json:"-"`
RetryAfter time.Duration `json:"-"`
}
func ResponseErrorFromAPIError ¶ added in v2.36.0
func ResponseErrorFromAPIError(err error) *ResponseError
func ResponseErrorFromKeyPool ¶ added in v2.34.0
func ResponseErrorFromKeyPool(keyPoolErr *keypool.Error) *ResponseError
ResponseErrorFromKeyPool translates a *keypool.Error into a developer-facing ResponseError shaped for the Anthropic API.
func (*ResponseError) Error ¶ added in v2.34.0
func (e *ResponseError) Error() string
func (*ResponseError) ToResponse ¶ added in v2.34.0
func (e *ResponseError) ToResponse() *http.Response
ToResponse marshals e into an *http.Response shaped for the Anthropic API.
type StreamingInterception ¶
type StreamingInterception struct {
// contains filtered or unexported fields
}
func NewStreamingInterceptor ¶
func NewStreamingInterceptor( id uuid.UUID, reqPayload RequestPayload, cfg intercept.Config, cred intercept.Credential, bedrock *BedrockRuntime, clientHeaders http.Header, tracer trace.Tracer, ) *StreamingInterception
func (*StreamingInterception) CorrelatingToolCallID ¶
func (i *StreamingInterception) CorrelatingToolCallID() *string
func (*StreamingInterception) Credential ¶
func (i *StreamingInterception) Credential() intercept.Credential
Credential returns the credential resolved for this interception.
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 (i *StreamingInterception) Setup(logger slog.Logger, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
func (*StreamingInterception) Streaming ¶
func (*StreamingInterception) Streaming() bool
func (*StreamingInterception) TraceAttributes ¶
func (i *StreamingInterception) TraceAttributes(r *http.Request) []attribute.KeyValue