Class: RubyLLM::Agents::TenantsController Private
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RubyLLM::Agents::TenantsController
- 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
-
#edit ⇒ void
private
Renders the edit form for a tenant budget.
-
#index ⇒ void
private
Lists all tenant budgets with optional search and sorting.
-
#refresh_counters ⇒ void
private
Recalculates budget counters from the executions table.
-
#show ⇒ void
private
Shows a single tenant’s budget details.
-
#update ⇒ void
private
Updates a tenant budget.
Instance Method Details
#edit ⇒ void
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
54 55 56 |
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 54 def edit @tenant = TenantBudget.find(params[:id]) end |
#index ⇒ void
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 36 37 |
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 20 def index @sort_params = parse_tenant_sort_params # Eager-load tenant_record so display_name's live name resolution does # not issue a query per row. scope = TenantBudget.all.includes(:tenant_record) 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_counters ⇒ void
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
61 62 63 64 65 |
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 61 def refresh_counters @tenant = TenantBudget.find(params[:id]) @tenant.refresh_counters! redirect_to tenant_path(@tenant), notice: "Counters refreshed" end |
#show ⇒ void
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
42 43 44 45 46 47 48 49 |
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 42 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 |
#update ⇒ void
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
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/ruby_llm/agents/tenants_controller.rb', line 70 def update @tenant = TenantBudget.find(params[:id]) attrs = tenant_params # Linked tenants derive their name live from the host record, so ignore # any submitted name — it would be overwritten on the next record sync. attrs = attrs.except(:name) if @tenant.linked? if @tenant.update(attrs) redirect_to tenant_path(@tenant), notice: "Tenant updated successfully" else render :edit, status: :unprocessable_entity end end |