admin

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 48 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package admin implements the REST API handlers for the admin dashboard.

Index

Constants

View Source
const (
	TokenValueStatusReady         = "ready"
	TokenValueStatusMaskedPending = "masked_pending"
)

TokenValueStatusReady and MaskedPending

Variables

This section is empty.

Functions

func AuditMiddleware

func AuditMiddleware(db *sqlx.DB) func(http.Handler) http.Handler

AuditMiddleware wraps admin handlers and records write operations. It must be mounted after AdminAuth so only authenticated requests pass. Panics inside the handler are recorded as status 500 before re-panicking, so chi's outer Recoverer still renders the standard error page.

func IsMaskedTokenValue

func IsMaskedTokenValue(token string) bool

IsMaskedTokenValue checks if a token value contains masking characters.

func RegisterAccountTokensRoutes

func RegisterAccountTokensRoutes(r chi.Router, db *sqlx.DB)

RegisterAccountTokensRoutes registers all /api/account-tokens routes.

func RegisterAccountTokensRoutesWithConfig

func RegisterAccountTokensRoutesWithConfig(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterAccountTokensRoutesWithConfig is like RegisterAccountTokensRoutes but accepts optional runtime config for proxy-aware upstream calls.

func RegisterAccountsRoutes

func RegisterAccountsRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterAccountsRoutes registers all /api/accounts routes.

func RegisterAnnouncementsRoutes

func RegisterAnnouncementsRoutes(r chi.Router, db *sqlx.DB)

RegisterAnnouncementsRoutes mounts the announcement endpoints.

func RegisterAuditLogsRoutes

func RegisterAuditLogsRoutes(r chi.Router, db *sqlx.DB)

GET /api/admin/audit-logs?limit=&offset=&method=&path= Lists recent admin write operations newest-first. method filters exact methods (POST/PUT/PATCH/DELETE); path filters by substring.

func RegisterAuthSettingsRoutes

func RegisterAuthSettingsRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterAuthSettingsRoutes registers all /api/settings/auth routes.

func RegisterBackupRoutes

func RegisterBackupRoutes(r chi.Router, db *sqlx.DB)

RegisterBackupRoutes registers all /api/settings/backup routes.

func RegisterChannelTestRoutes

func RegisterChannelTestRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterChannelTestRoutes registers admin-only forced-channel probe endpoints.

POST /api/admin/test-channel
POST /api/debug/channel-probe (alias)

func RegisterCheckinRoutes

func RegisterCheckinRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterCheckinRoutes registers all /api/checkin routes.

func RegisterDatabaseRoutes

func RegisterDatabaseRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterDatabaseRoutes registers all /api/settings/database routes.

func RegisterDownstreamKeysRoutes

func RegisterDownstreamKeysRoutes(r chi.Router, db *sqlx.DB)

RegisterDownstreamKeysRoutes registers all /api/downstream-keys routes.

func RegisterDownstreamPricingRoutes

func RegisterDownstreamPricingRoutes(r chi.Router, db *sqlx.DB)

Mounted under /v1/* so it inherits ProxyAuth + CORS from the /v1 route group.

func RegisterEventsRoutes

func RegisterEventsRoutes(r chi.Router, db *sqlx.DB)

RegisterEventsRoutes registers all /api/events routes.

func RegisterMaintenanceRoutes

func RegisterMaintenanceRoutes(r chi.Router, db *sqlx.DB)

RegisterMaintenanceRoutes registers all /api/settings/maintenance routes.

func RegisterModelRatesRoutes

func RegisterModelRatesRoutes(r chi.Router, db *sqlx.DB)

RegisterModelRatesRoutes mounts the rate overview endpoint.

func RegisterModelRedirectRoutes

func RegisterModelRedirectRoutes(r chi.Router, db *sqlx.DB)

RegisterModelRedirectRoutes mounts the redirect endpoints.

func RegisterMonitorRoutes

func RegisterMonitorRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterMonitorRoutes registers all /api/monitor and /monitor-proxy routes.

func RegisterNotifyRoutes

func RegisterNotifyRoutes(r chi.Router)

RegisterNotifyRoutes registers the /api/settings/notify/test route.

func RegisterOauthRoutes

func RegisterOauthRoutes(r chi.Router, db *sqlx.DB)

RegisterOauthRoutes registers all /api/oauth routes. Start/rebind issue cryptographically random server-stored state tokens (TTL 10m); session lookup and manual callback validate that state.

func RegisterOpsWSRoutes

func RegisterOpsWSRoutes(r chi.Router, cfg *config.Config)

RegisterOpsWSRoutes mounts the live ops WebSocket endpoint.

func RegisterSchedulerStatusRoutes

func RegisterSchedulerStatusRoutes(r chi.Router, db *sqlx.DB)

Data sources are existing signals only — no scheduler code changes: - checkin: checkin_logs aggregate (status counts + latest timestamp) - balance-refresh: accounts.last_balance_refresh / last_checkin_at - oauth-refresh / sub2api-refresh: extra_config is JSON — we do not parse it here (cross-dialect); the events table carries token/balance alerts - model-probe: in-memory ProbeRunSummary (single-instance honest) - announcements: site_announcements.last_seen_at - daily-summary / log-cleanup / usage-aggregation: recent events rows

func RegisterSearchRoutes

func RegisterSearchRoutes(r chi.Router, db *sqlx.DB)

RegisterSearchRoutes registers all /api/search routes.

func RegisterSettingsRoutes

func RegisterSettingsRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterSettingsRoutes registers all /api/settings routes (runtime, brand-list, system-proxy/test).

func RegisterSiteAnnouncementsRoutes

func RegisterSiteAnnouncementsRoutes(r chi.Router, db *sqlx.DB)

RegisterSiteAnnouncementsRoutes registers all /api/site-announcements routes. Also wires the background SiteAnnouncementScheduler to real SyncSiteAnnouncements . Routes register before StartBackgroundServices, so the package-level default is installed for NewSiteAnnouncementScheduler to pick up.

func RegisterSitesRoutes

func RegisterSitesRoutes(r chi.Router, db *sqlx.DB)

RegisterSitesRoutes registers all /api/sites routes.

func RegisterStatsRoutes

func RegisterStatsRoutes(r chi.Router, db *sqlx.DB)

RegisterStatsRoutes registers all /api/stats and /api/models routes.

func RegisterTagsRoutes

func RegisterTagsRoutes(r chi.Router, db *sqlx.DB)

RegisterTagsRoutes mounts the tag endpoints behind admin auth.

func RegisterTasksRoutes

func RegisterTasksRoutes(r chi.Router, db *sqlx.DB)

RegisterTasksRoutes registers /api/tasks routes. list/get observe memory-visible tasks AND durable tasks from admin_background_tasks when the handler DB is set. Cold DB fallback enables cross-instance visibility.

func RegisterTestRoutes

func RegisterTestRoutes(r chi.Router, db *sqlx.DB, cfg *config.Config)

RegisterTestRoutes registers all /api/test routes.

Known limitation : - sync proxy/chat probes alias the forced-channel harness when a channel/site is forced - stream + async job create surfaces return honest 501 known limitations (no fake SSE/job success) - job status/cancel return 404 (no in-process /api/test job registry; never invent stub-job ids)

func RegisterTokenRoutes

func RegisterTokenRoutes(r chi.Router, db *sqlx.DB)

RegisterTokenRoutes registers all /api/routes and /api/channels routes.

func RegisterTokenRoutesWithDeps

func RegisterTokenRoutesWithDeps(r chi.Router, db *sqlx.DB, deps TokenRoutesDeps)

RegisterTokenRoutesWithDeps registers routes with optional decision engine deps.

func RegisterUpdateCenterRoutes

func RegisterUpdateCenterRoutes(r chi.Router)

RegisterUpdateCenterRoutes registers all /api/update-center routes.

Known limitation : - status/check are local stubs (never invent updateAvailable=true) - config is echo-only (no durable helper registry config product) - deploy/rollback/task stream are honest 501 known limitations (no stub task ids / fake SSE) See limitation-update-center.md.

func SetBackgroundTaskDB

func SetBackgroundTaskDB(db *sqlx.DB)

SetBackgroundTaskDB stores the DB handle used by free-function start/update. Called from server boot or test wiring.

Types

type BackgroundTask

type BackgroundTask struct {
	ID         string                   `json:"id"`
	Type       string                   `json:"type"`
	Title      string                   `json:"title"`
	Status     BackgroundTaskStatus     `json:"status"`
	Message    string                   `json:"message"`
	Error      *string                  `json:"error"`
	Result     any                      `json:"result"`
	DedupeKey  *string                  `json:"dedupeKey"`
	CreatedAt  string                   `json:"createdAt"`
	UpdatedAt  string                   `json:"updatedAt"`
	StartedAt  *string                  `json:"startedAt"`
	FinishedAt *string                  `json:"finishedAt"`
	Logs       []BackgroundTaskLogEntry `json:"logs"`
	// contains filtered or unexported fields
}

StartBackgroundTask dual-writes to `admin_background_tasks` when a runtime DB is available so multi-instance deployments can list/get tasks across processes. Memory cache is the primary fast path; DB is the cold cross-process fallback. Cleanup removes expired rows from both memory and DB.

func StartBackgroundTask

func StartBackgroundTask(opts BackgroundTaskStartOptions, runner func() (any, error)) (task *BackgroundTask, reused bool)

When dedupeKey matches a pending/running task across memory+DB, that task is reused.

type BackgroundTaskLogEntry

type BackgroundTaskLogEntry struct {
	Seq       int    `json:"seq"`
	Message   string `json:"message"`
	CreatedAt string `json:"createdAt"`
}

BackgroundTaskLogEntry is a single task log line.

type BackgroundTaskStartOptions

type BackgroundTaskStartOptions struct {
	Type      string
	Title     string
	DedupeKey string
	KeepMs    int64
}

BackgroundTaskStartOptions configures StartBackgroundTask.

type BackgroundTaskStatus

type BackgroundTaskStatus string

BackgroundTaskStatus mirrors the TS background task lifecycle.

const (
	BackgroundTaskPending   BackgroundTaskStatus = "pending"
	BackgroundTaskRunning   BackgroundTaskStatus = "running"
	BackgroundTaskSucceeded BackgroundTaskStatus = "succeeded"
	BackgroundTaskFailed    BackgroundTaskStatus = "failed"
)

type RouteDecisionExplainer

type RouteDecisionExplainer interface {
	ExplainSelection(ctx context.Context, requestedModel string, excludeChannelIDs []int64, policy routing.DownstreamRoutingPolicy) (routing.RouteDecisionExplanation, error)
	ExplainSelectionForRoute(ctx context.Context, routeID int64, requestedModel string, excludeChannelIDs []int64, policy routing.DownstreamRoutingPolicy) (routing.RouteDecisionExplanation, error)
	ExplainSelectionRouteWide(ctx context.Context, routeID int64, policy routing.DownstreamRoutingPolicy) (routing.RouteDecisionExplanation, error)
}

RouteDecisionExplainer is the router surface used by decision admin APIs. Tests inject fakes; production wires routing.TokenRouter.

type RouteDecisionRefresher

type RouteDecisionRefresher interface {
	RefreshAllRouteDecisionSnapshots(ctx context.Context, refreshPricingCatalog bool) (exactModelCount int, wildcardRouteCount int, err error)
}

RouteDecisionRefresher refreshes persisted route decision snapshots.

type SiteAnnouncementFailedSite

type SiteAnnouncementFailedSite struct {
	SiteID   int64  `json:"siteId"`
	SiteName string `json:"siteName"`
	Message  string `json:"message"`
}

SiteAnnouncementFailedSite is one site that failed during announcement sync.

type SiteAnnouncementSyncResult

type SiteAnnouncementSyncResult struct {
	ScannedSites  int                          `json:"scannedSites"`
	Inserted      int                          `json:"inserted"`
	Updated       int                          `json:"updated"`
	Unsupported   int                          `json:"unsupported"`
	Notifications int                          `json:"notifications"`
	Events        int                          `json:"events"`
	Failed        int                          `json:"failed"`
	FailedSites   []SiteAnnouncementFailedSite `json:"failedSites"`
}

SiteAnnouncementSyncResult mirrors the TS syncSiteAnnouncements result shape. Used by the admin HTTP task path and by SiteAnnouncementScheduler via SyncSiteAnnouncements.

func SyncSiteAnnouncements

func SyncSiteAnnouncements(db *sqlx.DB, siteID *int64) SiteAnnouncementSyncResult

SyncSiteAnnouncements fetches announcements for active sites (or one site) via platform adapters and upserts site_announcements. Exported so the background SiteAnnouncementScheduler can reuse this path without HTTP.

type TokenRoutesDeps

type TokenRoutesDeps struct {
	Router    RouteDecisionExplainer
	Decisions RouteDecisionRefresher
}

TokenRoutesDeps are optional dependencies for route decision endpoints.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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