Movatterモバイル変換


[0]ホーム

URL:


aibridged

package
v2.28.4Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License:AGPL-3.0Imports:25Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

View Source
const (InternalMCPServerID = "coder")

Variables

View Source
var (ErrNoAuthKey             =xerrors.New("no authentication key provided")ErrConnect               =xerrors.New("could not connect to coderd")ErrUnauthorized          =xerrors.New("unauthorized")ErrAcquireRequestHandler =xerrors.New("failed to acquire request handler"))
View Source
var (ErrEmptyConfig  =xerrors.New("empty config given")ErrCompileRegex =xerrors.New("compile tool regex"))
View Source
var DefaultPoolOptions =PoolOptions{MaxItems: 100, TTL:time.Minute * 15}

Functions

funcExtractAuthToken

func ExtractAuthToken(headerhttp.Header)string

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

typeCachedBridgePool

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

funcNewCachedBridgePool

func NewCachedBridgePool(optionsPoolOptions, providers []aibridge.Provider, loggerslog.Logger) (*CachedBridgePool,error)

func (*CachedBridgePool)Acquire

func (p *CachedBridgePool) Acquire(ctxcontext.Context, reqRequest, clientFnClientFunc, mcpProxyFactoryMCPProxyBuilder) (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

func (*CachedBridgePool)Shutdown

Shutdown will close the cache which will trigger eviction of all the Bridge entries.

typeClientFunc

type ClientFunc func() (DRPCClient,error)

typeDRPCClient

DRPCClient is the union of various service interfaces the client must support.

typeDialer

type Dialer func(ctxcontext.Context) (DRPCClient,error)

typeMCPProxyBuilder

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(ctxcontext.Context, reqRequest) (mcp.ServerProxier,error)}

typeMCPProxyFactory

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

funcNewMCPProxyFactory

func NewMCPProxyFactory(loggerslog.Logger, clientFnClientFunc) *MCPProxyFactory

func (*MCPProxyFactory)Build

typePoolMetrics

type PoolMetrics interface {Hits()uint64Misses()uint64KeysAdded()uint64KeysEvicted()uint64}

typePoolOptions

type PoolOptions struct {MaxItemsint64TTLtime.Duration}

typePooler

type Pooler interface {Acquire(ctxcontext.Context, reqRequest, clientFnClientFunc, mcpBootstrapperMCPProxyBuilder) (http.Handler,error)Shutdown(ctxcontext.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.

typeRequest

type Request struct {SessionKeystringInitiatorIDuuid.UUID}

typeServer

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 aDialer to provide aDRPCClient implementation tocommunicate with aDRPCServer implementation, to persist state and perform other functions.

funcNew

func New(ctxcontext.Context, poolPooler, rpcDialerDialer, loggerslog.Logger) (*Server,error)

func (*Server)Client

func (s *Server) Client() (DRPCClient,error)

func (*Server)Close

func (s *Server) Close()error

Close shuts down the server with a timeout of 5s.

func (*Server)GetRequestHandler

func (s *Server) GetRequestHandler(ctxcontext.Context, reqRequest) (http.Handler,error)

GetRequestHandler retrieves a (possibly reused)*aibridge.RequestBridge from the pool, for the given user.

func (*Server)ServeHTTP

func (s *Server) ServeHTTP(rwhttp.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.

Anaibridge.RequestBridge instance is acquired from a pool based on the API key'sowner (referred to as the "initiator"); this instance is responsible for theAI Bridge-specific handling of the request.

ADRPCClient is provided to theaibridge.RequestBridge instance so that data canbe passed up to aDRPCServer for persistence.

func (*Server)Shutdown

func (s *Server) Shutdown(ctxcontext.Context)error

Shutdown waits for all exiting in-flight requests to complete, or the context to expire, whichever comes first.

Source Files

View all Source files

Directories

PathSynopsis
Package aibridgedmock is a generated GoMock package.
Package aibridgedmock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp