Documentation
¶
Index ¶
Constants ¶
const ( EventLLMReport = "llm_report" EventAppReport = "app_report" EventUserReport = "user_report" EventChatReport = "chat_report" EventHTTPInteraction = "http_interaction" )
Common event types
const ( FeaturePortal = "feature_portal" FeatureChat = "feature_chat" FeatureGateway = "feature_gateway" FeatureTrack = "track" // Telemetry enabled FeatureHubSpokeMultiTenant = "hub_spoke_multi_tenant" // Multi-tenant namespace support (ENT) FeatureGroups = "feature_groups" // Group-based access control (ENT) FeatureAdvancedLLMCache = "feature_advanced_llm_cache" // Enterprise LLM Cache with distributed backends (ENT) FeatureAssetCatalog = "feature_asset_catalog" // Asset Catalog plugin: portal asset types with governance (ENT) FeatureRBAC = "feature_rbac" // Fine-grained roles and permissions (ENT) )
Common feature names
Variables ¶
var ( // ErrInvalidLicense indicates the license is invalid or malformed ErrInvalidLicense = errors.New("invalid license") // ErrExpiredLicense indicates the license has expired ErrExpiredLicense = errors.New("license expired") // ErrNoLicense indicates no license was provided ErrNoLicense = errors.New("no license provided") // ErrInvalidSignature indicates the JWT signature is invalid ErrInvalidSignature = errors.New("invalid license signature") // ErrFeatureNotAvailable indicates a feature is not included in the license ErrFeatureNotAvailable = errors.New("feature not available in license") // ErrTelemetryFailed indicates telemetry transmission failed ErrTelemetryFailed = errors.New("telemetry transmission failed") )
Functions ¶
func IsEnterpriseAvailable ¶
func IsEnterpriseAvailable() bool
IsEnterpriseAvailable returns true if enterprise licensing is available
func RegisterEnterpriseFactory ¶
func RegisterEnterpriseFactory(f FactoryFunc)
RegisterEnterpriseFactory registers the enterprise licensing factory This is called by the enterprise submodule's init() function
Types ¶
type Config ¶
type Config struct {
// License key (JWT token)
LicenseKey string
// LicenseSource, when set, supplies the licence instead of LicenseKey,
// and is read at start and at every validity check: a host embedding
// Studio keeps the licence in its own settings, and a renewed licence
// takes effect without a restart. It is the same AI Studio Enterprise
// licence, validated the same way.
LicenseSource func() string
// Telemetry configuration
TelemetryURL string
TelemetryPeriod time.Duration
TelemetryDisabled bool
ValidityCheckPeriod time.Duration
TelemetryConcurrency int
// OnInvalid is called when a periodic re-check finds the licence no
// longer valid. Nil exits the process, which is what the standalone
// binaries rely on; an embedding host supplies its own handling.
OnInvalid func(error)
}
Config holds licensing configuration
type FactoryFunc ¶
FactoryFunc is a function that creates a licensing service
type Feature ¶
type Feature struct {
Name string
Value interface{}
}
Feature represents a license feature entitlement
type LicenseInfo ¶
type LicenseInfo struct {
// JWT claims
ExpiresAt time.Time
IssuedAt time.Time
NotBefore time.Time
Version string
// Feature entitlements from scope claim
Features map[string]Feature
// Raw token
Token string
}
LicenseInfo contains parsed license information
type Revalidator ¶
type Revalidator interface {
Revalidate() error
}
Revalidator is implemented by licensing services that can re-read and re-check the licence on demand (Enterprise). A host calls it through studio.ReloadLicense after storing a renewed licence.
type Service ¶
type Service interface {
// Start initializes and starts the licensing service
// - Validates license at boot (ENT: returns an error if invalid)
// - Starts periodic validation checks (ENT: every 24h)
// - Starts telemetry collection (ENT: every 1h)
Start() error
// Stop gracefully stops all background processes
Stop()
// IsValid returns whether the license is currently valid
// CE: Always returns true
// ENT: Returns true if JWT is valid and not expired
IsValid() bool
// Entitlement checks if a specific feature is available
// Returns the feature value and whether it exists
// CE: All features return true
// ENT: Checks JWT scope claim
Entitlement(name string) (Feature, bool)
// DaysLeft returns the number of days until license expiry
// CE: Returns -1 (never expires)
// ENT: Returns days until JWT exp claim
DaysLeft() int
// TelemetryMiddleware returns a Gin middleware for tracking HTTP requests
// CE: No-op middleware
// ENT: Tracks actions, status codes, access types
TelemetryMiddleware() gin.HandlerFunc
// SendTelemetry manually triggers a telemetry collection and send
// CE: No-op
// ENT: Collects stats and sends to telemetry endpoint
SendTelemetry() error
// GetLicenseInfo returns the current license information
// CE: Returns nil
// ENT: Returns parsed JWT claims and features
GetLicenseInfo() *LicenseInfo
}
Service defines the licensing service interface Community Edition: Always valid, no checks, no telemetry Enterprise Edition: JWT validation, periodic checks, telemetry
type TelemetryCollector ¶
type TelemetryCollector interface {
// CollectLLMStats collects LLM usage statistics
CollectLLMStats(db *gorm.DB) (map[string]interface{}, error)
// CollectAppStats collects application statistics
CollectAppStats(db *gorm.DB) (map[string]interface{}, error)
// CollectUserStats collects user statistics
CollectUserStats(db *gorm.DB) (map[string]interface{}, error)
// CollectChatStats collects chat statistics
CollectChatStats(db *gorm.DB) (map[string]interface{}, error)
}
TelemetryCollector defines the interface for collecting usage statistics
type TelemetryEvent ¶
type TelemetryEvent struct {
Identity string `json:"identity"` // Hashed license key
Event string `json:"event"` // Event type
Timestamp int64 `json:"timestamp"` // Unix timestamp
Properties map[string]interface{} `json:"properties"` // Event data
}
TelemetryEvent represents a telemetry event to be sent