Class: SignalWire::Skills::SkillBase

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/skills/skill_base.rb

Overview

Base class for all skills. Subclasses override the metadata methods and register_tools to supply tool hashes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent = nil, params = nil) ⇒ SkillBase

Python parity: “SkillBase.__init__(self, agent, params=None)“. First positional arg is the owning AgentBase (or nil for standalone). The second is the params hash. We accept the legacy 1-arg form for backwards compatibility (“DateTimeSkill.new(…)“).



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/signalwire/skills/skill_base.rb', line 34

def initialize(agent = nil, params = nil)
  # Backwards compat: a single Hash means params-only (no agent).
  if agent.is_a?(Hash) && params.nil?
    params = agent
    agent  = nil
  end
  @agent  = agent
  @params = (params || {}).transform_keys(&:to_s)
  # Python: pop swaig_fields out of params for separate access.
  @swaig_fields = @params.delete('swaig_fields') || {}
  @logger = ::SignalWire::Logging.logger("signalwire.skills.#{begin
    name
  rescue NotImplementedError
    self.class.name
  end}")
end

Instance Attribute Details

#agentObject (readonly)

Python parity:

  • “params“ — params hash passed at construction

  • “agent“ — owning AgentBase instance (or nil for standalone)

  • “logger“ — namespaced logger “signalwire.skills.<name>“

  • “swaig_fields“ — extra SWAIG fields merged into tool defs; pulled out of “params“ if provided



22
23
24
# File 'lib/signalwire/skills/skill_base.rb', line 22

def agent
  @agent
end

#loggerObject (readonly)

Python parity:

  • “params“ — params hash passed at construction

  • “agent“ — owning AgentBase instance (or nil for standalone)

  • “logger“ — namespaced logger “signalwire.skills.<name>“

  • “swaig_fields“ — extra SWAIG fields merged into tool defs; pulled out of “params“ if provided



22
23
24
# File 'lib/signalwire/skills/skill_base.rb', line 22

def logger
  @logger
end

#paramsObject (readonly)

Python parity:

  • “params“ — params hash passed at construction

  • “agent“ — owning AgentBase instance (or nil for standalone)

  • “logger“ — namespaced logger “signalwire.skills.<name>“

  • “swaig_fields“ — extra SWAIG fields merged into tool defs; pulled out of “params“ if provided



22
23
24
# File 'lib/signalwire/skills/skill_base.rb', line 22

def params
  @params
end

#swaig_fieldsObject (readonly)

Python parity:

  • “params“ — params hash passed at construction

  • “agent“ — owning AgentBase instance (or nil for standalone)

  • “logger“ — namespaced logger “signalwire.skills.<name>“

  • “swaig_fields“ — extra SWAIG fields merged into tool defs; pulled out of “params“ if provided



22
23
24
# File 'lib/signalwire/skills/skill_base.rb', line 22

def swaig_fields
  @swaig_fields
end

Instance Method Details

#cleanupObject

Called when the skill is unloaded.



68
# File 'lib/signalwire/skills/skill_base.rb', line 68

def cleanup; end

#descriptionObject

Raises:

  • (NotImplementedError)


25
# File 'lib/signalwire/skills/skill_base.rb', line 25

def description;                raise NotImplementedError, "#{self.class}#description"; end

#get_global_dataObject

Global data to merge into the agent.



62
# File 'lib/signalwire/skills/skill_base.rb', line 62

def get_global_data; {}; end

#get_hintsObject

Speech recognition hints.



59
# File 'lib/signalwire/skills/skill_base.rb', line 59

def get_hints; []; end

#get_param(key, env_var: nil, default: nil) ⇒ Object

Helper to get a param with env-var fallback.



77
78
79
# File 'lib/signalwire/skills/skill_base.rb', line 77

def get_param(key, env_var: nil, default: nil)
  @params[key.to_s] || @params[key.to_sym.to_s] || (env_var && ENV[env_var]) || default
end

#get_parameter_schemaObject

Parameter schema for GUI / validation.



74
# File 'lib/signalwire/skills/skill_base.rb', line 74

def get_parameter_schema; {}; end

#get_prompt_sectionsObject

Prompt sections to add to the agent.



65
# File 'lib/signalwire/skills/skill_base.rb', line 65

def get_prompt_sections; []; end

#instance_keyObject

Unique key for tracking this skill instance.



71
# File 'lib/signalwire/skills/skill_base.rb', line 71

def instance_key; name; end

#nameObject

Raises:

  • (NotImplementedError)


24
# File 'lib/signalwire/skills/skill_base.rb', line 24

def name;                       raise NotImplementedError, "#{self.class}#name"; end

#register_toolsObject

Return an Array of tool definition hashes. Each hash should have:

:name, :description, :parameters, :handler (lambda/proc)


56
# File 'lib/signalwire/skills/skill_base.rb', line 56

def register_tools; []; end

#required_env_varsObject



27
# File 'lib/signalwire/skills/skill_base.rb', line 27

def required_env_vars;          []; end

#setupObject

Called once after construction. Return true if the skill is ready.



52
# File 'lib/signalwire/skills/skill_base.rb', line 52

def setup; true; end

#supports_multiple_instances?Boolean

Returns:

  • (Boolean)


28
# File 'lib/signalwire/skills/skill_base.rb', line 28

def supports_multiple_instances?; false; end

#versionObject



26
# File 'lib/signalwire/skills/skill_base.rb', line 26

def version;                    '1.0.0'; end