Module: Protege::AgentsHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/protege/agents_helper.rb

Overview

View helpers for agent pages — selectors, labels, status, and resolver display.

Instance Method Summary collapse

Instance Method Details

#agent_label(agent) ⇒ String

Format an agent's name together with its type for display.

agent_label(agent) # => "Bob <Executive Agent>"

Parameters:

Returns:

  • (String)

    the "name <Type>" label



33
34
35
# File 'app/helpers/protege/agents_helper.rb', line 33

def agent_label(agent)
  "#{agent.name} <#{agent.class.display_name}>"
end

#agent_status(agent) ⇒ ActiveSupport::SafeBuffer

Render a status dot reflecting whether an agent is available.

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer)

    a green dot when active, red otherwise



41
42
43
44
45
46
47
# File 'app/helpers/protege/agents_helper.rb', line 41

def agent_status(agent)
  if agent.active?
    status_dot('Available', :green)
  else
    status_dot('Unavailable', :red)
  end
end

#all_agentsActiveRecord::Relation<Protege::Agent>

Fetch every Agent ordered by name for sidebar listing.

Returns:

  • (ActiveRecord::Relation<Protege::Agent>)

    agents ordered alphabetically



23
24
25
# File 'app/helpers/protege/agents_helper.rb', line 23

def all_agents
  Agent.order(:name)
end

#available_agent_typesArray<Class>

List the loaded Agent subclasses for the new-agent type selector.

Returns:

  • (Array<Class>)

    the Agent descendant classes



9
10
11
# File 'app/helpers/protege/agents_helper.rb', line 9

def available_agent_types
  Agent.descendants
end

#available_email_domainsActiveRecord::Relation<Protege::EmailDomain>

List active email domains for the agent form's domain selector.

Returns:



16
17
18
# File 'app/helpers/protege/agents_helper.rb', line 16

def available_email_domains
  EmailDomain.all
end

#resolver_pairs(agent) ⇒ Hash{String => String}

Format an agent's resolver chain as a hash suitable for info_card (rendered full-width, since the resolver class names are long). Each entry maps the resolver's short class name to a summary of its positional args, keyword args, and whether it was given a block.

Parameters:

  • agent (Protege::Agent)

    the agent whose reply (+message_resolvers+) chain to format

Returns:

  • (Hash{String => String})

    resolver-name => configuration summary



55
56
57
58
59
60
61
# File 'app/helpers/protege/agents_helper.rb', line 55

def resolver_pairs(agent)
  pairs = agent.message_resolvers.entries.each_with_object({}) do |(klass, args, kwargs, block), accumulator|
    accumulator[klass.name.demodulize] = resolver_config(args, kwargs, block)
  end

  pairs.any? ? pairs : { 'Resolvers' => 'None configured' }
end