Documentation
¶
Index ¶
- Constants
- func AsActor(ctx context.Context, actorID string, metadata recorder.Metadata) context.Context
- func GuessSessionID(client Client, r *http.Request) *string
- func NewAnthropicProvider(cfg config.Anthropic, bedrockCfg *config.AWSBedrock) provider.Provider
- func NewCopilotProvider(cfg config.Copilot) provider.Provider
- func NewMetrics(reg prometheus.Registerer) *metrics.Metrics
- func NewOpenAIProvider(cfg config.OpenAI) provider.Provider
- type AWSBedrockConfig
- type AnthropicConfig
- type Client
- type CopilotConfig
- type InterceptionRecord
- type InterceptionRecordEnded
- type Metadata
- type Metrics
- type ModelThoughtRecord
- type OpenAIConfig
- type PromptUsageRecord
- type Provider
- type Recorder
- type RequestBridge
- type SSEEvent
- type SSEParser
- type TokenUsageRecord
- type ToolUsageRecord
Constants ¶
const ( ProviderAnthropic = config.ProviderAnthropic ProviderOpenAI = config.ProviderOpenAI ProviderCopilot = config.ProviderCopilot )
Const + Type + function aliases for backwards compatibility.
const ( SSEEventTypeMessage = "message" SSEEventTypeError = "error" SSEEventTypePing = "ping" )
Variables ¶
This section is empty.
Functions ¶
func GuessSessionID ¶ added in v1.1.2
GuessSessionID attempts to retrieve a session ID which may have been sent by the client. We only attempt to retrieve sessions using methods recognized for the given client.
func NewAnthropicProvider ¶
func NewCopilotProvider ¶ added in v1.0.0
func NewMetrics ¶ added in v0.2.0
func NewMetrics(reg prometheus.Registerer) *metrics.Metrics
Types ¶
type AWSBedrockConfig ¶ added in v0.1.6
type AWSBedrockConfig = config.AWSBedrock
type AnthropicConfig ¶ added in v0.1.6
type Client ¶ added in v1.1.0
type Client string
const ( // Possible values for the "client" field in interception records. // Must be kept in sync with documentation: https://github.com/coder/coder/blob/90c11f3386578da053ec5cd9f1475835b980e7c7/docs/ai-coder/ai-bridge/monitoring.md?plain=1#L36-L44 ClientClaudeCode Client = "Claude Code" ClientCodex Client = "Codex" ClientZed Client = "Zed" ClientCopilotVSC Client = "GitHub Copilot (VS Code)" ClientCopilotCLI Client = "GitHub Copilot (CLI)" ClientKilo Client = "Kilo Code" ClientCoderAgents Client = "Coder Agents" ClientCrush Client = "Charm Crush" ClientMux Client = "Mux" ClientRoo Client = "Roo Code" ClientCursor Client = "Cursor" ClientUnknown Client = "Unknown" )
func GuessClient ¶ added in v1.1.2
GuessClient attempts to guess the client application from the request headers. Not all clients set proper user agent headers, so this is a best-effort approach. Based on https://github.com/coder/aibridge/issues/20#issuecomment-3769444101.
type CopilotConfig ¶ added in v1.0.0
type InterceptionRecord ¶
type InterceptionRecord = recorder.InterceptionRecord
type InterceptionRecordEnded ¶ added in v0.1.5
type InterceptionRecordEnded = recorder.InterceptionRecordEnded
type ModelThoughtRecord ¶ added in v1.1.0
type ModelThoughtRecord = recorder.ModelThoughtRecord
type OpenAIConfig ¶ added in v0.1.6
type PromptUsageRecord ¶
type PromptUsageRecord = recorder.PromptUsageRecord
type RequestBridge ¶
type RequestBridge struct {
// contains filtered or unexported fields
}
RequestBridge is an http.Handler which is capable of masquerading as AI providers' APIs; specifically, OpenAI's & Anthropic's at present. RequestBridge intercepts requests to - and responses from - these upstream services to provide a centralized governance layer.
RequestBridge has no concept of authentication or authorization. It does have a concept of identity, in the narrow sense that it expects an [actor] to be defined in the context, to record the initiator of each interception.
RequestBridge is safe for concurrent use.
func NewRequestBridge ¶
func NewRequestBridge(ctx context.Context, providers []provider.Provider, rec recorder.Recorder, mcpProxy mcp.ServerProxier, logger slog.Logger, m *metrics.Metrics, tracer trace.Tracer) (*RequestBridge, error)
NewRequestBridge creates a new *RequestBridge and registers the HTTP routes defined by the given providers. Any routes which are requested but not registered will be reverse-proxied to the upstream service.
A [intercept.Recorder] is also required to record prompt, tool, and token use.
mcpProxy will be closed when the RequestBridge is closed.
Circuit breaker configuration is obtained from each provider's CircuitBreakerConfig() method. Providers returning nil will not have circuit breaker protection.
func (*RequestBridge) InflightRequests ¶
func (b *RequestBridge) InflightRequests() int32
func (*RequestBridge) ServeHTTP ¶
func (b *RequestBridge) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP exposes the internal http.Handler, which has all [Provider]s' routes registered. It also tracks inflight requests.
type SSEParser ¶
type SSEParser struct {
// contains filtered or unexported fields
}
func NewSSEParser ¶
func NewSSEParser() *SSEParser
func (*SSEParser) EventsByType ¶
func (*SSEParser) MessageEvents ¶
type TokenUsageRecord ¶
type TokenUsageRecord = recorder.TokenUsageRecord
type ToolUsageRecord ¶
type ToolUsageRecord = recorder.ToolUsageRecord
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
Package mcpmock is a generated GoMock package.
|
Package mcpmock is a generated GoMock package. |
|
Package gorules defines custom ruleguard checks used by golangci-lint.
|
Package gorules defines custom ruleguard checks used by golangci-lint. |
