blib/lib/SignalWire/Agents/Skills/Builtin/WeatherApi.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 95.0% 57 / 60 CC 7 SCAR 12.9
CC
7
Cov
100%
register_tools
7.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.6
« blib/lib/SignalWire/Agents/Skills/Builtin/McpGateway.pm ↑ Summary blib/lib/SignalWire/Agents/Prefabs/FAQBot.pm »
1 package SignalWire::Agents::Skills::Builtin::WeatherApi;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 extends 'SignalWire::Agents::Skills::SkillBase';
6  
7 3 ▶use SignalWire::Agents::Skills::SkillRegistry;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 SignalWire::Agents::Skills::SkillRegistry->register_skill('weather_api', __PACKAGE__);
9  
10 7 ▶has '+skill_name' => (default => sub { 'weather_api' });
Subroutine __ANON__: called CC=1 SCAR=0.0
11 7 ▶has '+skill_description' => (default => sub { 'Get current weather information from WeatherAPI.com' });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 7 ▶has '+supports_multiple_instances' => (default => sub { 0 });
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 6 ▶sub setup { 1 }
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
15  
16 5 ▶sub register_tools {
Subroutine register_tools: called CC=7 SCAR=19.5
Pod undocumented
17 5 my ($self) = @_;
18 5 ▶ my $tool_name = $self->params->{tool_name} // 'get_weather';
Condition100%2/2
$self->params->{"tool_name"} // "get_weather"
l!l
23
MC/DC100%1/1
$self->params->{"tool_name"} // "get_weather"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
Aresult
11
00
19 5 ▶ my $api_key = $self->params->{api_key} // '';
Condition100%2/2
$self->params->{"api_key"} // ""
l!l
41
MC/DC100%1/1
$self->params->{"api_key"} // ""
$self->params->{"api_key"}
Truth table100%2/2
A
A= $self->params->{"api_key"}
Aresult
11
00
20 5 ▶ my $unit = $self->params->{temperature_unit} // 'fahrenheit';
Condition100%2/2
$self->params->{"temperature_unit"} // "fahrenheit"
l!l
14
MC/DC100%1/1
$self->params->{"temperature_unit"} // "fahrenheit"
$self->params->{"temperature_unit"}
Truth table100%2/2
A
A= $self->params->{"temperature_unit"}
Aresult
11
00
21  
22 5 ▶ my $temp_field = $unit eq 'celsius' ? 'temp_c' : 'temp_f';
Branch: 1 branch
BranchTrueFalseTotal
$unit eq 'celsius' ? : 1 4 5
23 5 ▶ my $feels_field = $unit eq 'celsius' ? 'feelslike_c' : 'feelslike_f';
Branch: 1 branch
BranchTrueFalseTotal
$unit eq 'celsius' ? : 1 4 5
24 5 ▶ my $unit_label = $unit eq 'celsius' ? 'C' : 'F';
Branch: 1 branch
BranchTrueFalseTotal
$unit eq 'celsius' ? : 1 4 5
25  
26 5 $self->agent->register_swaig_function({
27 function => $tool_name,
28 description => 'Get current weather information for any location',
29 parameters => {
30 type => 'object',
31 properties => {
32 location => { type => 'string', description => 'Location to get weather for' },
33 },
34 required => ['location'],
35 },
36 data_map => {
37 webhooks => [{
38 method => 'GET',
39 url => "https://api.weatherapi.com/v1/current.json?key=${api_key}&q=\${lc:enc:args.location}&aqi=no",
40 output => {
41 response => "Temperature: \${current.${temp_field}}${unit_label}, "
42 . "Feels like: \${current.${feels_field}}${unit_label}, "
43 . "Condition: \${current.condition.text}, "
44 . "Humidity: \${current.humidity}%, "
45 . "Wind: \${current.wind_mph} mph",
46 },
47 }],
48 },
49 });
50 }
51  
52 1 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: called CC=1 SCAR=0.0
Pod undocumented
53 return {
54 1 %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema },
55 api_key => { type => 'string', required => 1, hidden => 1 },
56 tool_name => { type => 'string', default => 'get_weather' },
57 temperature_unit => { type => 'string', enum => ['fahrenheit', 'celsius'], default => 'fahrenheit' },
58 };
59 }
60  
61 3 1;
« blib/lib/SignalWire/Agents/Skills/Builtin/McpGateway.pm ↑ Summary blib/lib/SignalWire/Agents/Prefabs/FAQBot.pm »