aibridgedserver

package
v2.34.8 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InterceptionLogMarker = "interception log"
	MetadataUserAgentKey  = "request_user_agent"
)

Variables

View Source
var (
	ErrExpiredOrInvalidOAuthToken = xerrors.New("expired or invalid OAuth2 token")
	ErrNoMCPConfigFound           = xerrors.New("no MCP config found")

	// These errors are returned by IsAuthorized. Since they're just returned as
	// a generic dRPC error, it's difficult to tell them apart without string
	// matching.
	// TODO: return these errors to the client in a more structured/comparable
	//       way.
	ErrInvalidKey    = xerrors.New("invalid key")
	ErrUnknownKey    = xerrors.New("unknown key")
	ErrExpired       = xerrors.New("expired")
	ErrUnknownUser   = xerrors.New("unknown user")
	ErrDeletedUser   = xerrors.New("deleted user")
	ErrInactiveUser  = xerrors.New("inactive user")
	ErrSystemUser    = xerrors.New("system user")
	ErrAmbiguousAuth = xerrors.New("both key and key_id set; exactly one required")

	ErrNoExternalAuthLinkFound = xerrors.New("no external auth link found")
)

Functions

This section is empty.

Types

type Server

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

func NewServer

func NewServer(lifecycleCtx context.Context, store store, logger slog.Logger, accessURL string,
	bridgeCfg codersdk.AIBridgeConfig, externalAuthConfigs []*externalauth.Config, experiments codersdk.Experiments,
	aiSeatTracker aiseats.SeatTracker,
) (*Server, error)

func (*Server) IsAuthorized

IsAuthorized validates a given Coder API key and returns the user ID to which it belongs (if valid).

SECURITY: when in.KeyId is set (the "delegated" path), this method trusts the caller's claim of identity and skips the key-secret check. This is safe only because the DRPCServer is reachable solely via the in-process aibridged.MemTransportPipe; the handler itself cannot tell whether it was invoked over the in-memory pipe or a network socket. If this RPC is ever exposed over a network boundary, any caller who knows a valid 10-char key ID (which is not secret) could authenticate as the key's owner without the secret. Do not bind this DRPCServer to a network listener.

NOTE: this should really be using the code from httpmw.ExtractAPIKey. That function not only validates the key but handles many other cases like updating last used, expiry, etc. This code does not currently use it for a few reasons:

  1. httpmw.ExtractAPIKey relies on keys being given in specific headers httpmw.APITokenFromRequest which AI bridge requests will not conform to.
  2. The code mixes many different concerns, and handles HTTP responses too, which is undesirable here.
  3. The core logic would need to be extracted, but that will surely be a complex & time-consuming distraction right now.
  4. Once we have an Early Access release of AI Bridge, we need to return to this.

TODO: replace with logic from httpmw.ExtractAPIKey.

func (*Server) RecordTokenUsage

func (*Server) RecordToolUsage

Jump to

Keyboard shortcuts

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