admin

package
v0.35.3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeAuthFailed     = ErrorCode(adminapi.ErrCodeAuthFailed)
	ErrCodeForbidden      = ErrorCode(adminapi.ErrCodeForbidden)
	ErrCodeNotFound       = ErrorCode(adminapi.ErrCodeNotFound)
	ErrCodeInvalidRequest = ErrorCode(adminapi.ErrCodeInvalidRequest)
	ErrCodeServerError    = ErrorCode(adminapi.ErrCodeServerError)
)

Re-export shared domain constants under the local package name so callers can use admin.ErrCodeAuthFailed etc.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigValidateRequest

type ConfigValidateRequest struct {
	ConfigPath string `json:"config_path"`
}

ConfigValidateRequest is the request for POST /admin/v1/config/validate.

type ConfigValidateResponse

type ConfigValidateResponse struct {
	Valid  bool     `json:"valid"`
	Errors []string `json:"errors"`
}

ConfigValidateResponse is the response for POST /admin/v1/config/validate.

type CronJobCreateRequest added in v0.35.0

type CronJobCreateRequest struct {
	CronExpr     string        `json:"cron_expr"`
	Prompt       string        `json:"prompt"`
	SessionKey   string        `json:"session_key,omitempty"`
	WorkDir      string        `json:"work_dir,omitempty"`
	Type         string        `json:"type"`
	TimeoutMins  int           `json:"timeout_mins"`
	Retries      int           `json:"retries"`
	RetryDelay   time.Duration `json:"retry_delay"`
	OutputFormat string        `json:"output_format"`
	OutputSchema string        `json:"output_schema,omitempty"`
	Enabled      bool          `json:"enabled"`
	Silent       bool          `json:"silent"`
	NotifyOn     []cron.Event  `json:"notify_on"`
	CreatedBy    string        `json:"created_by"`
}

CronJobCreateRequest is the request body for POST /admin/cron/jobs.

type CronJobDeleteResponse added in v0.35.0

type CronJobDeleteResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

CronJobDeleteResponse is the response for DELETE /admin/cron/jobs/:id.

type CronJobListResponse added in v0.35.0

type CronJobListResponse struct {
	Jobs  []*cron.CronJob `json:"jobs"`
	Total int             `json:"total"`
}

CronJobListResponse is the response for GET /admin/cron/jobs.

type CronJobResponse added in v0.35.0

type CronJobResponse struct {
	Job *cron.CronJob `json:"job"`
}

CronJobResponse is the response for a single cron job.

type CronRunListResponse added in v0.35.0

type CronRunListResponse struct {
	Runs  []*cron.CronRun `json:"runs"`
	Total int             `json:"total"`
}

CronRunListResponse is the response for GET /admin/cron/jobs/:id/runs.

type ErrorCode

type ErrorCode = adminapi.ErrorCode

ErrorCode is an alias to the shared domain error code.

type ErrorDetail

type ErrorDetail = adminapi.ErrorDetail

ErrorDetail is an alias to the shared domain error detail.

type ErrorResponse

type ErrorResponse = adminapi.ErrorResponse

ErrorResponse is an alias to the shared domain error response.

type Handler

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

Handler handles admin API requests.

func NewHandler

func NewHandler(eng *engine.Engine, cronScheduler *cron.CronScheduler, agentRegistry *intagent.AgentRegistry, startTime time.Time, logger Logger) *Handler

NewHandler creates a new admin handler.

type HealthChecks

type HealthChecks struct {
	Database             bool `json:"database"`
	Config               bool `json:"config"`
	CliAvailable         bool `json:"cli_available"`
	WebsocketConnections int  `json:"websocket_connections"`
}

HealthChecks contains health check results.

type HealthDetailedResponse

type HealthDetailedResponse struct {
	Status  string        `json:"status"`
	Checks  HealthChecks  `json:"checks"`
	Details HealthDetails `json:"details"`
}

HealthDetailedResponse is the response for GET /admin/v1/health/detailed.

type HealthDetails

type HealthDetails struct {
	DatabaseLatencyMs int    `json:"database_latency_ms"`
	CliVersion        string `json:"cli_version"`
	ConfigFile        string `json:"config_file"`
}

HealthDetails contains detailed health information.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger interface for logging.

type Middleware

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

Middleware provides HTTP middleware functions for the admin API.

func NewMiddleware

func NewMiddleware(adminToken string, logger *slog.Logger) *Middleware

NewMiddleware creates a new admin middleware. If logger is nil, slog.Default() is used.

func (*Middleware) AuthMiddleware

func (m *Middleware) AuthMiddleware(next http.Handler) http.Handler

AuthMiddleware returns an HTTP handler that validates the admin token. If adminToken is empty, authentication is disabled (dev mode). Uses Bearer token authentication (OAuth2 standard).

type RelayBindingCreateRequest added in v0.35.0

type RelayBindingCreateRequest struct {
	Platform string            `json:"platform"`
	ChatID   string            `json:"chat_id"`
	Bots     map[string]string `json:"bots"`
}

RelayBindingCreateRequest is the request body for POST /admin/relay/bindings.

type RelayBindingResponse added in v0.35.0

type RelayBindingResponse struct {
	Platform string            `json:"platform"`
	ChatID   string            `json:"chat_id"`
	Bots     map[string]string `json:"bots"`
}

RelayBindingResponse mirrors relay.RelayBinding for the admin API.

type RelayBindingsResponse added in v0.35.0

type RelayBindingsResponse struct {
	Bindings []*RelayBindingResponse `json:"bindings"`
	Total    int                     `json:"total"`
}

RelayBindingsResponse is the response for GET /admin/relay/bindings.

type Server

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

Server is the admin HTTP server.

func NewServer

func NewServer(eng *engine.Engine, cronScheduler *cron.CronScheduler, agentRegistry *intagent.AgentRegistry, port, token string, startTime time.Time, logger *slog.Logger) *Server

NewServer creates a new admin server.

func (*Server) ErrChan

func (s *Server) ErrChan() <-chan error

ErrChan returns the channel that receives server errors.

func (*Server) Start

func (s *Server) Start()

Start starts the admin server in a goroutine. Server errors (e.g., port already in use) are sent to ErrCh. Callers should monitor ErrCh after Start() to detect startup failures.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the admin server.

type SessionConfig

type SessionConfig struct {
	Provider string `json:"provider"`
	WorkDir  string `json:"work_dir"`
}

SessionConfig contains session configuration details.

type SessionDeleteResponse

type SessionDeleteResponse struct {
	Success bool   `json:"success"`
	Message string `json:"message"`
}

SessionDeleteResponse is the response for DELETE /admin/v1/sessions/:id.

type SessionDetailResponse

type SessionDetailResponse struct {
	ID         string        `json:"id"`
	Status     string        `json:"status"`
	CreatedAt  time.Time     `json:"created_at"`
	LastActive time.Time     `json:"last_active"`
	Provider   string        `json:"provider"`
	Config     SessionConfig `json:"config,omitempty"`
	Stats      SessionStats  `json:"stats,omitempty"`
}

SessionDetailResponse is the response for GET /admin/v1/sessions/:id.

type SessionInfo

type SessionInfo struct {
	ID           string    `json:"id"`
	Status       string    `json:"status"`
	CreatedAt    time.Time `json:"created_at"`
	LastActive   time.Time `json:"last_active"`
	Provider     string    `json:"provider"`
	CliVersion   string    `json:"cli_version,omitempty"`
	WorkDir      string    `json:"work_dir,omitempty"`
	InputTokens  int64     `json:"input_tokens,omitempty"`
	OutputTokens int64     `json:"output_tokens,omitempty"`
	DurationSecs int64     `json:"duration_seconds,omitempty"`
}

SessionInfo represents a session in admin CLI responses.

type SessionListResponse

type SessionListResponse struct {
	Sessions []*SessionInfo `json:"sessions"`
	Total    int            `json:"total"`
}

SessionListResponse is the response for GET /admin/v1/sessions.

type SessionLogsResponse

type SessionLogsResponse struct {
	SessionID    string    `json:"session_id"`
	LogPath      string    `json:"log_path"`
	SizeBytes    int64     `json:"size_bytes"`
	LastModified time.Time `json:"last_modified"`
}

SessionLogsResponse is the response for GET /admin/v1/sessions/:id/logs.

type SessionStats

type SessionStats struct {
	InputTokens  int64 `json:"input_tokens"`
	OutputTokens int64 `json:"output_tokens"`
	DurationSecs int64 `json:"duration_seconds"`
}

SessionStats contains session statistics.

type StatsResponse

type StatsResponse struct {
	TotalSessions   int     `json:"total_sessions"`
	ActiveSessions  int     `json:"active_sessions"`
	StoppedSessions int     `json:"stopped_sessions"`
	Uptime          string  `json:"uptime"`
	MemoryUsageMB   float64 `json:"memory_usage_mb"`
	CpuUsagePercent float64 `json:"cpu_usage_percent"`
}

StatsResponse is the response for GET /admin/v1/stats.

Jump to

Keyboard shortcuts

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