« blib/lib/SignalWire/Agents/Skills/Builtin/DatasphereServerless.pm
↑ Summary
blib/lib/SignalWire/Agents/REST/Namespaces/Calling.pm »
| 1 | package SignalWire::Agents::Skills::SkillRegistry; | ||||||||||
| 2 | # Copyright (c) 2025 SignalWire | ||||||||||
| 3 | # Licensed under the MIT License. | ||||||||||
| 4 | |||||||||||
| 5 | 19 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 19 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Global registry mapping skill name -> class name | ||||||||||
| 9 | 19 | my %REGISTRY; | |||||||||
| 10 | |||||||||||
| 11 | 54 | ▶ | sub register_skill { | ||||||||
|
Subroutine
register_skill: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | 54 | my ($class, $skill_name, $skill_class) = @_; | |||||||||
| 13 | 54 | $REGISTRY{$skill_name} = $skill_class; | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 185 | ▶ | sub get_factory { | ||||||||
|
Subroutine
get_factory: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 17 | 185 | my ($class, $skill_name) = @_; | |||||||||
| 18 | |||||||||||
| 19 | # Return if already registered | ||||||||||
| 20 | 185 | ▶ | return $REGISTRY{$skill_name} if exists $REGISTRY{$skill_name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | |||||||||||
| 22 | # Attempt to auto-load from Builtin namespace | ||||||||||
| 23 | 74 | my $module = 'SignalWire::Agents::Skills::Builtin::' . _camelize($skill_name); | |||||||||
| 24 | 74 | eval "require $module"; ## no critic | |||||||||
| 25 | 74 | ▶ | if (!$@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | # If the module registered itself, return it | ||||||||||
| 27 | 71 | ▶ | return $REGISTRY{$skill_name} if exists $REGISTRY{$skill_name}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | # Otherwise register it | ||||||||||
| 29 | 18 | $REGISTRY{$skill_name} = $module; | |||||||||
| 30 | 18 | return $module; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 3 | return undef; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 5 | ▶ | sub list_skills { | ||||||||
|
Subroutine
list_skills: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 37 | 5 | my ($class) = @_; | |||||||||
| 38 | # Make sure all builtins are loaded | ||||||||||
| 39 | 5 | $class->_load_all_builtins; | |||||||||
| 40 | 5 | return [ sort keys %REGISTRY ]; | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | 5 | ▶ | sub _load_all_builtins { | ||||||||
|
Subroutine
_load_all_builtins: called CC=2 SCAR=6.9
| |||||||||||
| 44 | 5 | my ($class) = @_; | |||||||||
| 45 | 5 | my @names = qw( | |||||||||
| 46 | api_ninjas_trivia claude_skills datasphere datasphere_serverless | ||||||||||
| 47 | datetime google_maps info_gatherer joke math mcp_gateway | ||||||||||
| 48 | native_vector_search play_background_file spider swml_transfer | ||||||||||
| 49 | weather_api web_search wikipedia_search custom_skills | ||||||||||
| 50 | ); | ||||||||||
| 51 | 5 | for my $name (@names) { | |||||||||
| 52 | 90 | $class->get_factory($name); # triggers auto-load | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 74 | ▶ | sub _camelize { | ||||||||
|
Subroutine
_camelize: called CC=1 SCAR=0.0
| |||||||||||
| 57 | 74 | my ($name) = @_; | |||||||||
| 58 | # Convert snake_case to CamelCase: api_ninjas_trivia -> ApiNinjasTrivia | ||||||||||
| 59 | 74 | $name =~ s/_(.)/uc($1)/ge; | |||||||||
| 60 | 74 | return ucfirst($name); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 3 | ▶ | sub clear_registry { | ||||||||
|
Subroutine
clear_registry: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 64 | 3 | %REGISTRY = (); | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 19 | 1; | |||||||||