budget

package
v2.35.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

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 EffectiveBudget

type EffectiveBudget struct {
	// GroupID is the group the spend is attributed to.
	GroupID uuid.UUID
	// SpendLimitMicros is the effective spend limit in micro-units
	// (1 unit = 1,000,000).
	SpendLimitMicros int64
	Source           LimitSource
}

EffectiveBudget is the AI budget that applies to a user after override and policy resolution.

func ResolveUserAIBudget

func ResolveUserAIBudget(ctx context.Context, db Store, userID uuid.UUID, policy codersdk.AIBudgetPolicy) (EffectiveBudget, bool, error)

ResolveUserAIBudget returns the effective AI budget for userID. The second return value is false when no budget is configured for the user. A per-user override wins unconditionally; otherwise the budget is selected from the user's groups according to policy.

type LimitSource

type LimitSource string

LimitSource identifies which tier produced an EffectiveBudget.

const (
	// SourceUserOverride indicates the budget came from a per-user override.
	SourceUserOverride LimitSource = "user_override"
	// SourceGroup indicates the budget came from a group budget selected by the
	// deployment policy.
	SourceGroup LimitSource = "group"
)

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)
}

Store is the subset of database.Store needed to resolve a user's effective AI budget.

Jump to

Keyboard shortcuts

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