Documentation
¶
Overview ¶
Package budget resolves the effective AI spend budget for a user. A per-user override always wins; otherwise the deployment budget policy selects a budget from the groups the user belongs to.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EffectiveGroup ¶ added in v2.36.0
type EffectiveGroup struct {
// GroupID is the group the spend is attributed to.
GroupID uuid.UUID
// Limit is the resolved spend limit, or nil for the unlimited Everyone
// fallback.
Limit *Limit
}
EffectiveGroup is a user's resolved effective group and, when a budget applies, its limit. Limit is nil for the Everyone fallback (unlimited).
func ResolveUserAIBudget ¶
func ResolveUserAIBudget(ctx context.Context, db Store, userID uuid.UUID, policy codersdk.AIBudgetPolicy) (EffectiveGroup, bool, error)
ResolveUserAIBudget returns the effective AI budget group for userID, resolved in order:
- A per-user override, if configured.
- Otherwise, a group budget selected by the deployment policy.
The second return value is false when no budget is configured for the user. TODO(AIGOV-527): unify effective group resolution in a single place.
func ResolveUserEffectiveGroup ¶ added in v2.36.0
func ResolveUserEffectiveGroup(ctx context.Context, db Store, userID uuid.UUID, policy codersdk.AIBudgetPolicy) (EffectiveGroup, bool, error)
ResolveUserEffectiveGroup resolves the user's effective group, falling back to the organization's Everyone group when no override or group budget applies. The second return value is false when no effective group was found for the user.
type Limit ¶ added in v2.36.0
type Limit struct {
// SpendLimitMicros is the spend limit in micro-units (1 unit = 1,000,000).
SpendLimitMicros int64
Source codersdk.AIBudgetLimitSource
}
Limit is an AI spend limit and the source that produced it.
type PeriodWindow ¶ added in v2.36.0
type PeriodWindow struct {
// Start is the inclusive first instant of the window.
Start time.Time
// End is the exclusive first instant of the next window.
End time.Time
}
PeriodWindow is the [Start, End) time window covered by an AI budget period. Bounds are in UTC.
func CurrentPeriod ¶ added in v2.36.0
func CurrentPeriod(now time.Time, period codersdk.AIBudgetPeriod) (PeriodWindow, error)
CurrentPeriod returns the PeriodWindow containing now (normalized to UTC) for the given AI budget period. An unknown budget period returns an error.
type Store ¶
type Store interface {
GetUserAIBudgetOverride(ctx context.Context, userID uuid.UUID) (database.UserAIBudgetOverride, error)
GetHighestGroupAIBudgetByUser(ctx context.Context, userID uuid.UUID) (database.GetHighestGroupAIBudgetByUserRow, error)
GetUserEveryoneFallbackGroup(ctx context.Context, userID uuid.UUID) (uuid.UUID, error)
}
Store is the subset of database.Store needed to resolve a user's effective AI budget.