module RailsAiAdmin::Assistant
Opt-in admin Chat on RubyLLM (ADR 0022). Loaded only when ‘config.assistant` is enabled, so conventional hosts never load RubyLLM.
Constants
- Session
-
Tool state for one claimed turn: the freshly resolved
Context, the chat and a fence that stops a worker whose lease was reassigned. conversation is the server-owned reference of a session without a chat (an MCP client); its proposals become reviews opened by URL.
Public Class Methods
Source
# File lib/rails_ai_admin/assistant.rb, line 11 def available?(context) context.is_a?(Context) && RailsAiAdmin.registry.resources.any? do |resource| Authorization::Access.new(context, resource).authorize_assistant! rescue AccessDenied false end end
True when at least one registered resource is exposed to this actor.
Source
# File lib/rails_ai_admin/assistant.rb, line 30 def create_chat!(context) Chat.create!(ref: SecureRandom.uuid, actor_ref: context.actor_ref, tenant_ref: context.tenant_ref, security_version: context.security_version, model: RailsAiAdmin.configuration.assistant_model, provider: RailsAiAdmin.configuration.assistant_provider) end
Source
# File lib/rails_ai_admin/assistant.rb, line 8 def enabled? = RailsAiAdmin.configuration.assistant == true # True when at least one registered resource is exposed to this actor. def available?(context) context.is_a?(Context) && RailsAiAdmin.registry.resources.any? do |resource| Authorization::Access.new(context, resource).authorize_assistant! rescue AccessDenied false end end # The host's per-request provider configuration. nil means the assistant # is unavailable for this actor, which is a normal, recoverable state. def llm_context(context) adapter = RailsAiAdmin.configuration.assistant_adapter.constantize.new raise ConfigurationError, "assistant_adapter must define llm_context(context:)" unless adapter.respond_to?(:llm_context) value = adapter.llm_context(context: context) return nil if value.nil? raise ConfigurationError, "llm_context must return a RubyLLM::Context" unless value.is_a?(::RubyLLM::Context) value end def create_chat!(context) Chat.create!(ref: SecureRandom.uuid, actor_ref: context.actor_ref, tenant_ref: context.tenant_ref, security_version: context.security_version, model: RailsAiAdmin.configuration.assistant_model, provider: RailsAiAdmin.configuration.assistant_provider) end def tool_views require "rails_ai_admin/integrations/tool_views" Integrations::ToolViews end end
Source
# File lib/rails_ai_admin/assistant.rb, line 21 def llm_context(context) adapter = RailsAiAdmin.configuration.assistant_adapter.constantize.new raise ConfigurationError, "assistant_adapter must define llm_context(context:)" unless adapter.respond_to?(:llm_context) value = adapter.llm_context(context: context) return nil if value.nil? raise ConfigurationError, "llm_context must return a RubyLLM::Context" unless value.is_a?(::RubyLLM::Context) value end
The host’s per-request provider configuration. nil means the assistant is unavailable for this actor, which is a normal, recoverable state.
Source
# File lib/rails_ai_admin/assistant.rb, line 36 def tool_views require "rails_ai_admin/integrations/tool_views" Integrations::ToolViews end