intercept

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActorHeadersAsAnthropicOpts

func ActorHeadersAsAnthropicOpts(actor *context.Actor) []ant_option.RequestOption

ActorHeadersAsAnthropicOpts produces a slice of headers using Anthropic's RequestOption type.

func ActorHeadersAsOpenAIOpts

func ActorHeadersAsOpenAIOpts(actor *context.Actor) []oai_option.RequestOption

ActorHeadersAsOpenAIOpts produces a slice of headers using OpenAI's RequestOption type.

func ActorIDHeader

func ActorIDHeader() string

func ActorMetadataHeader

func ActorMetadataHeader(name string) string

func BuildUpstreamHeaders added in v1.1.0

func BuildUpstreamHeaders(sdkHeader http.Header, clientHeaders http.Header, authHeaderName string) http.Header

BuildUpstreamHeaders produces the header set for an upstream SDK request. It starts from the prepared client headers, then preserves specific headers from the SDK-built request that must not be overwritten.

func IsActorHeader

func IsActorHeader(name string) bool

func PrepareClientHeaders added in v1.1.0

func PrepareClientHeaders(clientHeaders http.Header) http.Header

PrepareClientHeaders returns a copy of the client headers with hop-by-hop, transport, and auth headers removed.

Types

type CredentialInfo added in v1.1.2

type CredentialInfo struct {
	Kind   CredentialKind
	Hint   string
	Length int
}

CredentialInfo holds credential metadata for an interception.

func NewCredentialInfo added in v1.1.2

func NewCredentialInfo(kind CredentialKind, credential string) CredentialInfo

NewCredentialInfo creates a CredentialInfo from a raw credential. The credential is automatically masked before storage so that the original secret is never retained.

type CredentialKind added in v1.1.2

type CredentialKind string

CredentialKind identifies how a request was authenticated. Keep in sync with the credential_kind enum in coderd's database.

const (
	CredentialKindCentralized CredentialKind = "centralized"
	CredentialKindBYOK        CredentialKind = "byok"
)

Credential kind constants for interception recording.

type Interceptor

type Interceptor interface {
	// ID returns the unique identifier for this interception.
	ID() uuid.UUID
	// Setup injects some required dependencies. This MUST be called before using the interceptor
	// to process requests.
	Setup(logger slog.Logger, rec recorder.Recorder, mcpProxy mcp.ServerProxier)
	// Model returns the model in use for this [Interceptor].
	Model() string
	// ProcessRequest handles the HTTP request.
	ProcessRequest(w http.ResponseWriter, r *http.Request) error
	// Specifies whether an interceptor handles streaming or not.
	Streaming() bool
	// TraceAttributes returns tracing attributes for this [Interceptor]
	TraceAttributes(*http.Request) []attribute.KeyValue
	// Credential returns the credential metadata for this interception.
	Credential() CredentialInfo
	// CorrelatingToolCallID returns the ID of a tool call result submitted
	// in the request, if present. This is used to correlate the current
	// interception back to the previous interception that issued those tool
	// calls. If multiple tool use results are present, we use the last one
	// (most recent). Both Anthropic's /v1/messages and OpenAI's /v1/responses
	// require that ALL tool results are submitted for tool choices returned
	// by the model, so any single tool call ID is sufficient to identify the
	// parent interception.
	CorrelatingToolCallID() *string
}

Interceptor describes a (potentially) stateful interaction with an AI provider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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