blib/lib/SignalWire/Skills/SkillBase.pm

filter: Statementstmt 87.5% 49 / 56 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 18 / 22 Podpod 0.0% 0 / 11 totaltotal 75.2% 73 / 97 CC 6 SCAR 4.7
CC
6
Cov
86%
validate_env_vars
3.7
BUILD
2.0
setup
2.0
CRAP 1.6
« blib/lib/SignalWire/Prefabs/InfoGatherer.pm ↑ Summary blib/lib/SignalWire/Skills/Builtin/NativeVectorSearch.pm »
1 package SignalWire::Skills::SkillBase;
2 # Copyright (c) 2025 SignalWire
3 # Licensed under the MIT License.
4  
5 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 20 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 20 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # Required class-level constants (subclasses override via 'has' or '+')
11 20 has skill_name => (is => 'ro', required => 1);
12 20 has skill_description => (is => 'ro', required => 1);
13 124 ▶has skill_version => (is => 'ro', default => sub { '1.0.0' });
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 0 ▶has supports_multiple_instances => (is => 'ro', default => sub { 0 });
Subroutine __ANON__: not called CC=1 SCAR=1.2
16 136 ▶has required_packages => (is => 'ro', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
17 136 ▶has required_env_vars => (is => 'ro', default => sub { [] });
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 # The agent this skill is attached to
20 20 has agent => (is => 'ro', required => 1, weak_ref => 1);
21 # Config params passed at registration
22 0 ▶has params => (is => 'rw', default => sub { {} });
Subroutine __ANON__: not called CC=1 SCAR=1.2
23  
24 # Extra SWAIG fields to merge into tool definitions
25 136 ▶has swaig_fields => (is => 'rw', default => sub { {} });
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27 136 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
28 136 my ($self) = @_;
29 # Extract swaig_fields from params if present
30 136 ▶ if (exists $self->params->{swaig_fields}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->params->{"swaig_fields"}) 1 135 136
31 1 $self->swaig_fields(delete $self->params->{swaig_fields});
32 }
33 }
34  
35 # --- Abstract interface (subclasses must override) ---
36  
37 0 ▶sub setup {
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
38 0 my ($self) = @_;
39 0 croak(ref($self) . " must implement setup()");
40 }
41  
42 0 ▶sub register_tools {
Subroutine register_tools: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ($self) = @_;
44 0 croak(ref($self) . " must implement register_tools()");
45 }
46  
47 # --- Default implementations ---
48  
49 61 ▶sub define_tool {
Subroutine define_tool: called CC=1 SCAR=0.0
Pod undocumented
50 61 my ($self, %opts) = @_;
51 # Merge swaig_fields into the tool definition
52 61 my %merged = (%{ $self->swaig_fields }, %opts);
53 61 return $self->agent->define_tool(%merged);
54 }
55  
56 9 ▶sub get_hints {
Subroutine get_hints: called CC=1 SCAR=0.0
Pod undocumented
57 9 return [];
58 }
59  
60 10 ▶sub get_global_data {
Subroutine get_global_data: called CC=1 SCAR=0.0
Pod undocumented
61 10 return {};
62 }
63  
64 23 ▶sub get_prompt_sections {
Subroutine get_prompt_sections: called CC=2 SCAR=6.9
Pod undocumented
65 23 my ($self) = @_;
66 23 ▶ return [] if $self->params->{skip_prompt};
Branch: 1 branch
BranchTrueFalseTotal
if $self->params->{"skip_prompt"} 2 21 23
67 21 return $self->_get_prompt_sections;
68 }
69  
70 2 ▶sub _get_prompt_sections {
Subroutine _get_prompt_sections: called CC=1 SCAR=0.0
71 2 return [];
72 }
73  
74 1 ▶sub cleanup {
Subroutine cleanup: called CC=1 SCAR=0.0
Pod undocumented
75 # no-op by default
76 }
77  
78 10 ▶sub validate_env_vars {
Subroutine validate_env_vars: called CC=3 SCAR=13.1
Pod undocumented
79 10 my ($self) = @_;
80 10 for my $var (@{ $self->required_env_vars }) {
81 0 ▶ return 0 unless $ENV{$var};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{$var} 0 0 0
82 }
83 10 return 1;
84 }
85  
86 15 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: called CC=1 SCAR=0.0
Pod undocumented
87 return {
88 15 swaig_fields => { type => 'object', description => 'Additional SWAIG fields' },
89 skip_prompt => { type => 'boolean', description => 'Skip injecting prompt sections', default => 0 },
90 tool_name => { type => 'string', description => 'Override the default tool name' },
91 };
92 }
93  
94 14 ▶sub get_instance_key {
Subroutine get_instance_key: called CC=2 SCAR=6.9
Pod undocumented
95 14 my ($self) = @_;
96 14 my $base = $self->skill_name;
97 14 ▶ if ($self->params->{tool_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->params->{"tool_name"}) 4 10 14
98 4 return $base . ':' . $self->params->{tool_name};
99 }
100 10 return $base;
101 }
102  
103 20 1;
« blib/lib/SignalWire/Prefabs/InfoGatherer.pm ↑ Summary blib/lib/SignalWire/Skills/Builtin/NativeVectorSearch.pm »