Documentation
¶
Index ¶
Constants ¶
const (
InternalMCPServerID = "coder"
)
Variables ¶
var ( ErrNoAuthKey = xerrors.New("no authentication key provided") ErrConnect = xerrors.New("could not connect to coderd") ErrAcquireRequestHandler = xerrors.New("failed to acquire request handler") )
var ( ErrEmptyConfig = xerrors.New("empty config given") ErrCompileRegex = xerrors.New("compile tool regex") )
var DefaultPoolOptions = PoolOptions{MaxItems: 100, TTL: time.Minute * 15}
Functions ¶
func ExtractAuthToken ¶
ExtractAuthToken extracts authorization token from HTTP request using multiple sources. These sources represent the different ways clients authenticate against AI providers. It checks the Authorization header (Bearer token) and X-Api-Key header. If neither are present, an empty string is returned.
Types ¶
type CachedBridgePool ¶
type CachedBridgePool struct {
// contains filtered or unexported fields
}
func NewCachedBridgePool ¶
func NewCachedBridgePool(options PoolOptions, providers []aibridge.Provider, logger slog.Logger) (*CachedBridgePool, error)
func (*CachedBridgePool) Acquire ¶
func (p *CachedBridgePool) Acquire(ctx context.Context, req Request, clientFn ClientFunc, mcpProxyFactory MCPProxyBuilder) (http.Handler, error)
Acquire retrieves or creates a *aibridge.RequestBridge instance per given key.
Each returned *aibridge.RequestBridge is safe for concurrent use. Each *aibridge.RequestBridge is stateful because it has MCP clients which maintain sessions to the configured MCP server.
func (*CachedBridgePool) Metrics ¶
func (p *CachedBridgePool) Metrics() PoolMetrics
type Client ¶
type Client struct {
proto.DRPCRecorderClient
proto.DRPCMCPConfiguratorClient
proto.DRPCAuthorizerClient
Conn drpc.Conn
}
type ClientFunc ¶
type ClientFunc func() (DRPCClient, error)
type DRPCClient ¶
type DRPCClient interface {
proto.DRPCRecorderClient
proto.DRPCMCPConfiguratorClient
proto.DRPCAuthorizerClient
}
DRPCClient is the union of various service interfaces the client must support.
type DRPCServer ¶
type DRPCServer interface {
proto.DRPCRecorderServer
proto.DRPCMCPConfiguratorServer
proto.DRPCAuthorizerServer
}
type MCPProxyBuilder ¶
type MCPProxyBuilder interface {
// Build creates a [mcp.ServerProxier] for the given request initiator.
// At minimum, the Coder MCP server will be proxied.
// The SessionKey from [Request] is used to authenticate against the Coder MCP server.
//
// NOTE: the [mcp.ServerProxier] instance may be proxying one or more MCP servers.
Build(ctx context.Context, req Request) (mcp.ServerProxier, error)
}
type MCPProxyFactory ¶
type MCPProxyFactory struct {
// contains filtered or unexported fields
}
func NewMCPProxyFactory ¶
func NewMCPProxyFactory(logger slog.Logger, clientFn ClientFunc) *MCPProxyFactory
func (*MCPProxyFactory) Build ¶
func (m *MCPProxyFactory) Build(ctx context.Context, req Request) (mcp.ServerProxier, error)
type PoolMetrics ¶
type PoolOptions ¶
type Pooler ¶
type Pooler interface {
Acquire(ctx context.Context, req Request, clientFn ClientFunc, mcpBootstrapper MCPProxyBuilder) (http.Handler, error)
Shutdown(ctx context.Context) error
}
Pooler describes a pool of *aibridge.RequestBridge instances from which instances can be retrieved. One *aibridge.RequestBridge instance is created per given key.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server provides the AI Bridge functionality. It is responsible for:
- receiving requests on /api/v2/aibridged/*
- manipulating the requests
- relaying requests to upstream AI services and relaying responses to caller
It requires a Dialer to provide a DRPCClient implementation to communicate with a DRPCServer implementation, to persist state and perform other functions.
func (*Server) Client ¶
func (s *Server) Client() (DRPCClient, error)
func (*Server) GetRequestHandler ¶
GetRequestHandler retrieves a (possibly reused) *aibridge.RequestBridge from the pool, for the given user.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(rw http.ResponseWriter, r *http.Request)
ServeHTTP is the entrypoint for requests which will be intercepted by AI Bridge. This function will validate that the given API key may be used to perform the request.
An aibridge.RequestBridge instance is acquired from a pool based on the API key's owner (referred to as the "initiator"); this instance is responsible for the AI Bridge-specific handling of the request.
A DRPCClient is provided to the aibridge.RequestBridge instance so that data can be passed up to a DRPCServer for persistence.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package aibridgedmock is a generated GoMock package.
|
Package aibridgedmock is a generated GoMock package. |