proxy

package
v1.100.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Environment variable names for Claude credentials
	EnvClaudeAccessToken  = "CLAUDE_ACCESS_TOKEN"
	EnvClaudeRefreshToken = "CLAUDE_REFRESH_TOKEN"
	EnvClaudeExpiresAt    = "CLAUDE_EXPIRES_AT"
)

Variables

This section is empty.

Functions

func ExtractTeamEnvFile added in v1.48.0

func ExtractTeamEnvFile(tags map[string]string) string

ExtractTeamEnvFile extracts the env_file value from tags

func MergeEnvironmentVariables added in v1.48.0

func MergeEnvironmentVariables(cfg EnvMergeConfig) (map[string]string, error)

MergeEnvironmentVariables merges environment variables from multiple sources with the following priority (highest to lowest): 1. Request environment variables 2. Team/organization specific environment file (from tags["env_file"]) 3. Auth team environment file (from team_role_mapping) 4. Role-based environment variables

Types

type AuthInfoHandlers added in v1.9.1

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

func NewAuthInfoHandlers added in v1.9.1

func NewAuthInfoHandlers(cfg *config.Config) *AuthInfoHandlers

func (*AuthInfoHandlers) GetAuthStatus added in v1.9.1

func (h *AuthInfoHandlers) GetAuthStatus(c echo.Context) error

func (*AuthInfoHandlers) GetAuthTypes added in v1.9.1

func (h *AuthInfoHandlers) GetAuthTypes(c echo.Context) error

type AuthStatusResponse added in v1.9.1

type AuthStatusResponse struct {
	Authenticated bool                 `json:"authenticated"`
	AuthType      string               `json:"auth_type,omitempty"`
	UserID        string               `json:"user_id,omitempty"`
	Role          string               `json:"role,omitempty"`
	Permissions   []string             `json:"permissions,omitempty"`
	GitHubUser    *auth.GitHubUserInfo `json:"github_user,omitempty"`
}

type AuthType added in v1.9.1

type AuthType struct {
	Type      string `json:"type"`
	Name      string `json:"name"`
	Available bool   `json:"available"`
}

type AuthTypesResponse added in v1.9.1

type AuthTypesResponse struct {
	Enabled bool       `json:"enabled"`
	Types   []AuthType `json:"types"`
}

type ChainCredentialProvider added in v1.86.0

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

ChainCredentialProvider tries multiple providers in order until one succeeds

func NewChainCredentialProvider added in v1.86.0

func NewChainCredentialProvider(providers ...CredentialProvider) *ChainCredentialProvider

NewChainCredentialProvider creates a new ChainCredentialProvider

func (*ChainCredentialProvider) Load added in v1.86.0

Load attempts to load credentials from each provider in order Returns the first successful result Returns nil, nil if all providers return nil

func (*ChainCredentialProvider) Name added in v1.86.0

func (p *ChainCredentialProvider) Name() string

Name returns the provider name

type ClaudeCredentials added in v1.86.0

type ClaudeCredentials struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    string // epoch milliseconds as string

	// RawJSON contains the original credentials.json file content
	// When set, this should be used directly instead of reconstructing from fields
	RawJSON []byte
}

ClaudeCredentials represents Claude authentication credentials

type CredentialProvider added in v1.86.0

type CredentialProvider interface {
	// Name returns the provider name for logging purposes
	Name() string

	// Load attempts to load credentials from this provider for the specified user
	// userID is used to locate user-specific credential files
	// Returns nil, nil if credentials are not available (not an error)
	// Returns nil, error if there was an error loading credentials
	Load(userID string) (*ClaudeCredentials, error)
}

CredentialProvider is an interface for loading Claude credentials from various sources

func DefaultCredentialProvider added in v1.86.0

func DefaultCredentialProvider() CredentialProvider

DefaultCredentialProvider returns the default credential provider chain Order: Environment variables (highest priority) -> File

type CustomHandler added in v1.76.0

type CustomHandler interface {
	RegisterRoutes(e *echo.Echo, proxy *Proxy) error
	GetName() string
}

CustomHandler interface for adding custom routes

type EnvCredentialProvider added in v1.86.0

type EnvCredentialProvider struct{}

EnvCredentialProvider loads credentials from environment variables

func NewEnvCredentialProvider added in v1.86.0

func NewEnvCredentialProvider() *EnvCredentialProvider

NewEnvCredentialProvider creates a new EnvCredentialProvider

func (*EnvCredentialProvider) Load added in v1.86.0

Load attempts to load credentials from environment variables userID is ignored for environment variable provider Returns nil, nil if CLAUDE_ACCESS_TOKEN is not set

func (*EnvCredentialProvider) Name added in v1.86.0

func (p *EnvCredentialProvider) Name() string

Name returns the provider name

type EnvMergeConfig added in v1.48.0

type EnvMergeConfig struct {
	RoleEnvFiles    *config.RoleEnvFilesConfig
	UserRole        string
	TeamEnvFile     string // From tags["env_file"]
	AuthTeamEnvFile string // From team_role_mapping
	RequestEnv      map[string]string
}

EnvMergeConfig contains configuration for environment variable merging

type FileCredentialProvider added in v1.86.0

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

FileCredentialProvider loads credentials from user-specific credential files When userID is provided, it looks for credentials at: $HOME/.agentapi-proxy/myclaudes/[userID]/.claude/.credentials.json When userID is empty, it falls back to ~/.claude/.credentials.json

func NewFileCredentialProvider added in v1.86.0

func NewFileCredentialProvider() *FileCredentialProvider

NewFileCredentialProvider creates a new FileCredentialProvider with default path

func NewFileCredentialProviderWithPath added in v1.86.0

func NewFileCredentialProviderWithPath(path string) *FileCredentialProvider

NewFileCredentialProviderWithPath creates a new FileCredentialProvider with custom path This is primarily used for testing

func (*FileCredentialProvider) Load added in v1.86.0

Load attempts to load credentials from the file If userID is provided, looks in the user-specific directory Returns nil, nil if the file doesn't exist Returns nil, error if there was an error reading the file

func (*FileCredentialProvider) Name added in v1.86.0

func (p *FileCredentialProvider) Name() string

Name returns the provider name

type HandlerRegistry added in v1.76.0

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

HandlerRegistry contains all handlers

type HealthHandlers added in v1.76.0

type HealthHandlers struct{}

HealthHandlers handles health check endpoints

func NewHealthHandlers added in v1.76.0

func NewHealthHandlers() *HealthHandlers

NewHealthHandlers creates a new HealthHandlers instance

func (*HealthHandlers) HealthCheck added in v1.76.0

func (h *HealthHandlers) HealthCheck(c echo.Context) error

HealthCheck handles GET /health requests to check server health

type KubernetesSessionManager added in v1.84.0

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

KubernetesSessionManager manages sessions using Kubernetes Deployments

func NewKubernetesSessionManager added in v1.84.0

func NewKubernetesSessionManager(
	cfg *config.Config,
	verbose bool,
	lgr *logger.Logger,
) (*KubernetesSessionManager, error)

NewKubernetesSessionManager creates a new KubernetesSessionManager

func NewKubernetesSessionManagerWithClient added in v1.84.0

func NewKubernetesSessionManagerWithClient(
	cfg *config.Config,
	verbose bool,
	lgr *logger.Logger,
	client kubernetes.Interface,
) (*KubernetesSessionManager, error)

NewKubernetesSessionManagerWithClient creates a new KubernetesSessionManager with a custom client This is useful for testing with a fake client

func (*KubernetesSessionManager) CreateSession added in v1.84.0

func (m *KubernetesSessionManager) CreateSession(ctx context.Context, id string, req *RunServerRequest) (Session, error)

CreateSession creates a new session with a Kubernetes Deployment

func (*KubernetesSessionManager) DeleteSession added in v1.84.0

func (m *KubernetesSessionManager) DeleteSession(id string) error

DeleteSession stops and removes a session If the session is not in memory, it attempts to restore from Kubernetes Service first

func (*KubernetesSessionManager) GetClient added in v1.90.0

GetClient returns the Kubernetes client (used by subscription secret syncer)

func (*KubernetesSessionManager) GetNamespace added in v1.90.0

func (m *KubernetesSessionManager) GetNamespace() string

GetNamespace returns the Kubernetes namespace (used by subscription secret syncer)

func (*KubernetesSessionManager) GetSession added in v1.84.0

func (m *KubernetesSessionManager) GetSession(id string) Session

GetSession returns a session by ID If the session is not in memory, it attempts to restore from Kubernetes Service

func (*KubernetesSessionManager) ListSessions added in v1.84.0

func (m *KubernetesSessionManager) ListSessions(filter SessionFilter) []Session

ListSessions returns all sessions matching the filter Sessions are retrieved from Kubernetes Services to survive proxy restarts

func (*KubernetesSessionManager) Shutdown added in v1.84.0

func (m *KubernetesSessionManager) Shutdown(timeout time.Duration) error

Shutdown gracefully stops all sessions Note: This does NOT delete Kubernetes resources (Deployment, Service, PVC, Secret). Resources are preserved so sessions can be restored when the proxy restarts. Use DeleteSession to explicitly delete a session and its resources.

type KubernetesSubscriptionSecretSyncer added in v1.90.0

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

KubernetesSubscriptionSecretSyncer syncs subscription data to Kubernetes Secrets

func NewKubernetesSubscriptionSecretSyncer added in v1.90.0

func NewKubernetesSubscriptionSecretSyncer(
	clientset kubernetes.Interface,
	namespace string,
	storage notification.Storage,
	secretPrefix string,
) *KubernetesSubscriptionSecretSyncer

NewKubernetesSubscriptionSecretSyncer creates a new KubernetesSubscriptionSecretSyncer

func (*KubernetesSubscriptionSecretSyncer) GetSecretName added in v1.90.0

func (s *KubernetesSubscriptionSecretSyncer) GetSecretName(userID string) string

GetSecretName returns the secret name for a given user ID

func (*KubernetesSubscriptionSecretSyncer) Sync added in v1.90.0

Sync creates or updates the subscription Secret for a user

type LocalSessionManager added in v1.83.0

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

LocalSessionManager manages sessions using local processes

func NewLocalSessionManager added in v1.83.0

func NewLocalSessionManager(cfg *config.Config, verbose bool, lgr *logger.Logger, startPort int) *LocalSessionManager

NewLocalSessionManager creates a new LocalSessionManager

func (*LocalSessionManager) CreateSession added in v1.83.0

func (m *LocalSessionManager) CreateSession(ctx context.Context, id string, req *RunServerRequest) (Session, error)

CreateSession creates a new session and starts it

func (*LocalSessionManager) DeleteSession added in v1.83.0

func (m *LocalSessionManager) DeleteSession(id string) error

DeleteSession stops and removes a session

func (*LocalSessionManager) GetLocalSession added in v1.83.0

func (m *LocalSessionManager) GetLocalSession(id string) *localSession

GetLocalSession returns the internal localSession for handlers that need it

func (*LocalSessionManager) GetSession added in v1.83.0

func (m *LocalSessionManager) GetSession(id string) Session

GetSession returns a session by ID, nil if not found

func (*LocalSessionManager) ListSessions added in v1.83.0

func (m *LocalSessionManager) ListSessions(filter SessionFilter) []Session

ListSessions returns all sessions matching the filter

func (*LocalSessionManager) Shutdown added in v1.83.0

func (m *LocalSessionManager) Shutdown(timeout time.Duration) error

Shutdown gracefully stops all sessions

type NotificationHandlers added in v1.59.0

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

NotificationHandlers handles notification-related HTTP requests

func NewNotificationHandlers added in v1.59.0

func NewNotificationHandlers(service *notification.Service) *NotificationHandlers

NewNotificationHandlers creates new notification handlers

func (*NotificationHandlers) DeleteSubscription added in v1.59.0

func (h *NotificationHandlers) DeleteSubscription(c echo.Context) error

DeleteSubscription handles DELETE /notification/subscribe

func (*NotificationHandlers) GetHistory added in v1.59.0

func (h *NotificationHandlers) GetHistory(c echo.Context) error

GetHistory handles GET /notifications/history

func (*NotificationHandlers) GetSubscriptions added in v1.59.0

func (h *NotificationHandlers) GetSubscriptions(c echo.Context) error

GetSubscriptions handles GET /notification/subscribe

func (*NotificationHandlers) Subscribe added in v1.59.0

func (h *NotificationHandlers) Subscribe(c echo.Context) error

Subscribe handles POST /notification/subscribe

func (*NotificationHandlers) Webhook added in v1.59.0

func (h *NotificationHandlers) Webhook(c echo.Context) error

Webhook handles POST /notifications/webhook

type OAuthCallbackRequest added in v1.9.1

type OAuthCallbackRequest struct {
	Code  string `query:"code"`
	State string `query:"state"`
}

OAuthCallbackRequest represents the OAuth callback parameters

type OAuthLoginRequest added in v1.9.1

type OAuthLoginRequest struct {
	RedirectURI string `json:"redirect_uri"`
}

OAuthLoginRequest represents the request body for OAuth login

type OAuthLoginResponse added in v1.9.1

type OAuthLoginResponse struct {
	AuthURL string `json:"auth_url"`
	State   string `json:"state"`
}

OAuthLoginResponse represents the response for OAuth login

type OAuthSession added in v1.9.1

type OAuthSession struct {
	ID          string
	UserContext *auth.UserContext
	CreatedAt   time.Time
	ExpiresAt   time.Time
}

OAuthSession represents an authenticated OAuth session

type OAuthSessionResponse added in v1.9.1

type OAuthSessionResponse struct {
	SessionID   string            `json:"session_id"`
	AccessToken string            `json:"access_token"`
	TokenType   string            `json:"token_type"`
	ExpiresAt   time.Time         `json:"expires_at"`
	User        *auth.UserContext `json:"user"`
}

OAuthSessionResponse represents the response with session information

type OAuthTokenResponse added in v1.9.1

type OAuthTokenResponse struct {
	AccessToken string            `json:"access_token"`
	TokenType   string            `json:"token_type"`
	ExpiresAt   time.Time         `json:"expires_at"`
	User        *auth.UserContext `json:"user"`
}

OAuthTokenResponse represents the response after successful OAuth

type Proxy

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

Proxy represents the HTTP proxy server

func NewProxy

func NewProxy(cfg *config.Config, verbose bool) *Proxy

NewProxy creates a new proxy instance

func (*Proxy) CreateSession added in v1.76.0

func (p *Proxy) CreateSession(sessionID string, startReq StartRequest, userID, userRole string, teams []string) (Session, error)

CreateSession creates a new agent session

func (*Proxy) DeleteSessionByID added in v1.76.0

func (p *Proxy) DeleteSessionByID(sessionID string) error

DeleteSessionByID deletes a session by ID

func (*Proxy) GetContainer added in v1.76.0

func (p *Proxy) GetContainer() *di.Container

GetContainer returns the DI container

func (*Proxy) GetEcho

func (p *Proxy) GetEcho() *echo.Echo

GetEcho returns the Echo instance for external access

func (*Proxy) GetSessionManager added in v1.83.0

func (p *Proxy) GetSessionManager() SessionManager

GetSessionManager returns the session manager

func (*Proxy) SetSessionManager added in v1.83.0

func (p *Proxy) SetSessionManager(manager SessionManager)

SetSessionManager allows configuration of a custom session manager (for testing)

func (*Proxy) Shutdown

func (p *Proxy) Shutdown(timeout time.Duration) error

Shutdown gracefully stops all running sessions and waits for them to terminate

func (*Proxy) StartMonitoring added in v1.62.0

func (p *Proxy) StartMonitoring()

StartMonitoring starts the session monitoring (called after proxy is fully initialized)

type RepositoryInfo added in v0.10.0

type RepositoryInfo struct {
	FullName string
	CloneDir string
}

RepositoryInfo contains repository information extracted from tags

type Router added in v1.76.0

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

Router handles route registration and management

func NewRouter added in v1.76.0

func NewRouter(e *echo.Echo, proxy *Proxy) *Router

NewRouter creates a new Router instance

func (*Router) AddCustomHandler added in v1.76.0

func (r *Router) AddCustomHandler(handler CustomHandler)

AddCustomHandler adds a custom handler to the registry

func (*Router) RegisterRoutes added in v1.76.0

func (r *Router) RegisterRoutes() error

RegisterRoutes registers all routes

type RunServerRequest added in v1.82.0

type RunServerRequest struct {
	Port           int
	UserID         string
	Environment    map[string]string
	Tags           map[string]string
	RepoInfo       *RepositoryInfo
	InitialMessage string
	Teams          []string // GitHub team slugs (e.g., ["org/team-a", "org/team-b"])
}

RunServerRequest contains parameters needed to run an agentapi server

type Session added in v1.83.0

type Session interface {
	// ID returns the unique session identifier
	ID() string

	// Addr returns the address (host:port) the session is running on
	// For local sessions, this returns "localhost:{port}"
	// For Kubernetes sessions, this returns "{service-dns}:{port}"
	Addr() string

	// UserID returns the user ID that owns this session
	UserID() string

	// Tags returns the session tags
	Tags() map[string]string

	// Status returns the current status of the session
	Status() string

	// StartedAt returns when the session was started
	StartedAt() time.Time

	// Cancel cancels the session context to trigger shutdown
	Cancel()
}

Session represents a running agentapi session

type SessionFilter added in v1.83.0

type SessionFilter struct {
	UserID string
	Status string
	Tags   map[string]string
}

SessionFilter defines filter criteria for listing sessions

type SessionHandlers added in v1.77.0

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

SessionHandlers handles session management endpoints without persistence

func NewSessionHandlers added in v1.77.0

func NewSessionHandlers(proxy *Proxy) *SessionHandlers

NewSessionHandlers creates a new SessionHandlers instance

func (*SessionHandlers) DeleteSession added in v1.77.0

func (h *SessionHandlers) DeleteSession(c echo.Context) error

DeleteSession handles DELETE /sessions/:sessionId requests to terminate a session

func (*SessionHandlers) GetName added in v1.77.0

func (h *SessionHandlers) GetName() string

GetName returns the name of this handler for logging

func (*SessionHandlers) RegisterRoutes added in v1.77.0

func (h *SessionHandlers) RegisterRoutes(e *echo.Echo, proxy *Proxy) error

RegisterRoutes registers session management routes

func (*SessionHandlers) RouteToSession added in v1.77.0

func (h *SessionHandlers) RouteToSession(c echo.Context) error

RouteToSession routes requests to the appropriate agentapi server instance

func (*SessionHandlers) SearchSessions added in v1.77.0

func (h *SessionHandlers) SearchSessions(c echo.Context) error

SearchSessions handles GET /search requests to list and filter active sessions (memory only)

func (*SessionHandlers) StartSession added in v1.77.0

func (h *SessionHandlers) StartSession(c echo.Context) error

StartSession handles POST /start requests to start a new agentapi server

type SessionManager added in v1.83.0

type SessionManager interface {
	// CreateSession creates a new session and starts it
	CreateSession(ctx context.Context, id string, req *RunServerRequest) (Session, error)

	// GetSession returns a session by ID, nil if not found
	GetSession(id string) Session

	// ListSessions returns all sessions matching the filter
	ListSessions(filter SessionFilter) []Session

	// DeleteSession stops and removes a session
	DeleteSession(id string) error

	// Shutdown gracefully stops all sessions
	Shutdown(timeout time.Duration) error
}

SessionManager manages the lifecycle of sessions

type SessionParams added in v1.98.0

type SessionParams struct {
	// Message is the initial message to send to the agent after session starts
	Message string `json:"message,omitempty"`
}

SessionParams represents session parameters for agentapi server

type StartRequest

type StartRequest struct {
	Environment map[string]string `json:"environment,omitempty"`
	Tags        map[string]string `json:"tags,omitempty"`
	// Params contains session parameters
	Params *SessionParams `json:"params,omitempty"`
	// Message is the initial message (deprecated: use Params.Message instead)
	// Kept for backward compatibility
	Message string `json:"message,omitempty"`
}

StartRequest represents the request body for starting a new agentapi server

type StartupConfig added in v1.41.3

type StartupConfig struct {
	Port                      int
	UserID                    string
	RepoFullName              string
	CloneDir                  string
	GitHubToken               string
	GitHubAppID               string
	GitHubInstallationID      string
	GitHubAppPEMPath          string
	GitHubAPI                 string
	GitHubPersonalAccessToken string
	MCPConfigs                string
	AgentAPIArgs              string
	ClaudeArgs                string
	Environment               map[string]string
	Config                    *config.Config
	Verbose                   bool
	IsRestore                 bool // Whether this is a restored session
}

StartupConfig holds configuration for session startup

type StartupManager added in v1.41.3

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

StartupManager manages the startup process

func NewStartupManager added in v1.41.3

func NewStartupManager(config *config.Config, verbose bool) *StartupManager

NewStartupManager creates a new startup manager

func (*StartupManager) StartAgentAPISession added in v1.41.3

func (sm *StartupManager) StartAgentAPISession(ctx context.Context, cfg *StartupConfig) (*exec.Cmd, error)

StartAgentAPISession starts an AgentAPI session with the given configuration

Jump to

Keyboard shortcuts

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