limits

package
v1.261210.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MPL-2.0 Imports: 10 Imported by: 0 modules, 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 limits exposes the live state of account concurrency / usage limits (see .design/routing-limits.md) so the UI can show who is busy right now.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Policies  *db.LimitPolicyStore
	Directory Directory
	// OnPolicyChanged runs after a policy is saved (warm start of its window).
	OnPolicyChanged func(ai.LimitPolicy)
}

Deps are the optional collaborators of the person / team / model scopes. A nil Policies store switches those scopes (and their API) off.

type Directory

type Directory interface {
	// TeamName returns the team's name ("" when the team does not exist).
	TeamName(teamID string) string
	// KeysOfTeam lists the sharing keys bound to a team.
	KeysOfTeam(teamID string) []KeyInfo
	// KeyByUserID finds the sharing key behind a user_id.
	KeyByUserID(userID string) (KeyInfo, bool)
}

Directory resolves the people and teams policies refer to.

type Handler

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

Handler serves the limits status and policy APIs.

func NewHandler

func NewHandler(cfg *config.Config, guard *routing.LimitsGuard, deps Deps) *Handler

NewHandler creates the handler. guard may be nil (limits off: empty status).

func (*Handler) DeletePolicy

func (h *Handler) DeletePolicy(c *gin.Context)

DeletePolicy DELETE /limit-policies/:kind/:ref.

func (*Handler) ListPolicies

func (h *Handler) ListPolicies(c *gin.Context)

ListPolicies GET /limit-policies.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(rt *module.Routes)

RegisterRoutes mounts GET /limits/status.

func (*Handler) Status

func (h *Handler) Status(c *gin.Context)

Status lists every configured limit with its live counters.

func (*Handler) UpsertPolicy

func (h *Handler) UpsertPolicy(c *gin.Context)

UpsertPolicy PUT /limit-policies/:kind/:ref.

type KeyInfo

type KeyInfo struct {
	UserID      string
	TeamID      string
	DisplayName string
	Enabled     bool
}

KeyInfo describes one sharing key as far as limits care (never its secret).

type LimitPoliciesResponse

type LimitPoliciesResponse struct {
	Success bool             `json:"success" example:"true"`
	Data    []ai.LimitPolicy `json:"data"`
}

LimitPoliciesResponse is the response of GET /limit-policies.

type LimitPolicyQuery

type LimitPolicyQuery struct {
	Kind string `form:"kind" description:"user | team | team_member | model"`
	Ref  string `form:"ref" description:"user_id, team id or model name"`
}

LimitPolicyQuery filters GET /limit-policies.

type LimitPolicyResponse

type LimitPolicyResponse struct {
	Success bool            `json:"success" example:"true"`
	Exists  bool            `json:"exists" description:"false after a delete or when the saved policy held no limit"`
	Data    *ai.LimitPolicy `json:"data,omitempty"`
}

LimitPolicyResponse is the response of PUT/DELETE /limit-policies/{kind}/{ref}.

type LimitPolicyUpsertRequest

type LimitPolicyUpsertRequest struct {
	Limits              ai.Limits `json:"limits"`
	Overflow            string    `json:"overflow,omitempty" description:"user/team/team_member: queue (default) | reject"`
	QueueTimeoutSeconds int       `json:"queue_timeout_seconds,omitempty"`
}

LimitPolicyUpsertRequest is the body of PUT /limit-policies/{kind}/{ref}. An empty `limits` object deletes the policy.

type LimitStatusEntry

type LimitStatusEntry struct {
	Scope         string    `json:"scope" example:"account" description:"account | service | model | user | team"`
	Key           string    `json:"key"`
	Ref           string    `json:"ref,omitempty" description:"policy ref for user/team/model scopes (user_id, team id, model name)"`
	Label         string    `json:"label,omitempty" description:"human-readable name (key display name, team name, provider name)"`
	TeamID        string    `json:"team_id,omitempty"`
	InheritedFrom string    `json:"inherited_from,omitempty" description:"team_member when a per-member template governs this person"`
	Overflow      string    `json:"overflow,omitempty" description:"actor scopes: queue | reject"`
	QueueTimeout  int       `json:"queue_timeout_seconds,omitempty"`
	ProviderUUID  string    `json:"provider_uuid,omitempty"`
	ProviderName  string    `json:"provider_name,omitempty"`
	RuleUUID      string    `json:"rule_uuid,omitempty"`
	Scenario      string    `json:"scenario,omitempty"`
	RequestModel  string    `json:"request_model,omitempty"`
	Model         string    `json:"model,omitempty"`
	Limits        ai.Limits `json:"limits"`
	Inflight      int       `json:"inflight"`
	Requests      int64     `json:"requests" description:"requests admitted in the current usage window"`
	Tokens        int64     `json:"tokens" description:"tokens recorded in the current usage window"`
	Pressure      float64   `json:"pressure" description:"largest used/limit ratio; 1 = at the hard limit"`
	State         string    `json:"state" example:"ok" description:"ok | hot | blocked"`
}

LimitStatusEntry is the live state of one limit: an account, a rule's service share, a model, a person or a team.

type LimitsStatusResponse

type LimitsStatusResponse struct {
	Success bool               `json:"success" example:"true"`
	Data    []LimitStatusEntry `json:"data"`
}

LimitsStatusResponse is the response of GET /limits/status.

Jump to

Keyboard shortcuts

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