Class: RubyLLM::Agents::TenantsController Private

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/ruby_llm/agents/tenants_controller.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Controller for managing tenant budgets

Provides CRUD operations for viewing and editing tenant budget configurations, including cost limits and token limits.

Constant Summary collapse

TENANT_SORTABLE_COLUMNS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[name enforcement daily_limit monthly_limit].freeze
DEFAULT_TENANT_SORT_COLUMN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"name"
DEFAULT_TENANT_SORT_DIRECTION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"asc"

Instance Method Summary collapse

Instance Method Details

#editvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Renders the edit form for a tenant budget



52
53
54
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 52

def edit
  @tenant = TenantBudget.find(params[:id])
end

#indexvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Lists all tenant budgets with optional search and sorting



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 20

def index
  @sort_params = parse_tenant_sort_params
  scope = TenantBudget.all

  if params[:q].present?
    @search_query = params[:q].to_s.strip
    escaped = TenantBudget.sanitize_sql_like(@search_query)
    scope = scope.where(
      "tenant_id LIKE :q OR name LIKE :q OR tenant_record_type LIKE :q OR tenant_record_id LIKE :q",
      q: "%#{escaped}%"
    )
  end

  @tenants = scope.order(@sort_params[:column] => @sort_params[:direction].to_sym)
  preload_tenant_index_data
end

#refresh_countersvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Recalculates budget counters from the executions table



59
60
61
62
63
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 59

def refresh_counters
  @tenant = TenantBudget.find(params[:id])
  @tenant.refresh_counters!
  redirect_to tenant_path(@tenant), notice: "Counters refreshed"
end

#showvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Shows a single tenant’s budget details



40
41
42
43
44
45
46
47
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 40

def show
  @tenant = TenantBudget.find(params[:id])
  @executions = tenant_executions(@tenant.tenant_id).recent.limit(10)
  @usage_stats = calculate_usage_stats(@tenant)
  @usage_by_agent = @tenant.usage_by_agent(period: nil)
  @usage_by_model = @tenant.usage_by_model(period: nil)
  load_tenant_analytics
end

#updatevoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Updates a tenant budget



68
69
70
71
72
73
74
75
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 68

def update
  @tenant = TenantBudget.find(params[:id])
  if @tenant.update(tenant_params)
    redirect_to tenant_path(@tenant), notice: "Tenant updated successfully"
  else
    render :edit, status: :unprocessable_entity
  end
end