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

filter: Statementstmt 95.7% 45 / 47 Branchbran n/a Conditioncond 66.6% 14 / 21 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 4 totaltotal 78.7% 74 / 94 CC 13 SCAR 16.8
CC
13
Cov
87%
register_tools
10.5
get_hints
3.0
_get_prompt_sections
2.0
CRAP 5.3
« blib/lib/SignalWire/Agents/SWML/Schema.pm ↑ Summary blib/lib/SignalWire/Agents/Relay/Action.pm »
1 package SignalWire::Agents::Skills::Builtin::SwmlTransfer;
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('swml_transfer', __PACKAGE__);
9  
10 7 ▶has '+skill_name' => (default => sub { 'swml_transfer' });
Subroutine __ANON__: called CC=1 SCAR=0.0
11 7 ▶has '+skill_description' => (default => sub { 'Transfer calls between agents based on pattern matching' });
Subroutine __ANON__: called CC=1 SCAR=0.0
12 7 ▶has '+supports_multiple_instances' => (default => sub { 1 });
Subroutine __ANON__: called CC=1 SCAR=0.0
13  
14 4 ▶sub setup { 1 }
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
15  
16 3 ▶sub register_tools {
Subroutine register_tools: called CC=10 SCAR=23.5
Pod undocumented
17 3 my ($self) = @_;
18 3 ▶ my $tool_name = $self->params->{tool_name} // 'transfer_call';
Condition100%2/2
$self->params->{"tool_name"} // "transfer_call"
l!l
12
MC/DC100%1/1
$self->params->{"tool_name"} // "transfer_call"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
Aresult
11
00
19 3 ▶ my $description = $self->params->{description} // 'Transfer call based on pattern matching';
Condition50%1/2
$self->params->{"description"} // "Transfer call based on pattern matching"
l!l
03
MC/DC0%0/1
$self->params->{"description"} // "Transfer call based on pattern matching"
$self->params->{"description"}
Truth table50%1/2
A
A= $self->params->{"description"}
Aresult
11
00
20 3 ▶ my $param_name = $self->params->{parameter_name} // 'transfer_type';
Condition100%2/2
$self->params->{"parameter_name"} // "transfer_type"
l!l
12
MC/DC100%1/1
$self->params->{"parameter_name"} // "transfer_type"
$self->params->{"parameter_name"}
Truth table100%2/2
A
A= $self->params->{"parameter_name"}
Aresult
11
00
21 3 ▶ my $transfers = $self->params->{transfers} // {};
Condition100%2/2
$self->params->{"transfers"} // {}
l!l
21
MC/DC100%1/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table100%2/2
A
A= $self->params->{"transfers"}
Aresult
11
00
22  
23 3 my @patterns = keys %$transfers;
24  
25 # Build DataMap expressions from transfer patterns
26 3 my @expressions;
27 3 for my $pattern (@patterns) {
28 3 my $cfg = $transfers->{$pattern};
29 3 ▶ my $url = $cfg->{url} // $cfg->{address} // '';
Condition40%2/5
($cfg->{"url"} // $cfg->{"address"}) // ""
l!l
30
$cfg->{"url"} // $cfg->{"address"}
l!l&&r!l&&!r
300
MC/DC0%0/2
($cfg->{"url"} // $cfg->{"address"}) // ""
$cfg->{"url"} $cfg->{"address"}
Truth table33%1/3
A // B
A= $cfg->{"url"}B= $cfg->{"address"}
ABresult
1X1
011
000
30 push @expressions, {
31 string => "\${args.$param_name}",
32 pattern => $pattern,
33 output => {
34 3 ▶ response => $cfg->{message} // "Transferring to $pattern",
Condition100%2/2
$cfg->{"message"} // "Transferring to $pattern"
l!l
12
MC/DC100%1/1
$cfg->{"message"} // "Transferring to $pattern"
$cfg->{"message"}
Truth table100%2/2
A
A= $cfg->{"message"}
Aresult
11
00
35 action => [{ swml_transfer => $url }],
36 },
37 };
38 }
39  
40 $self->agent->register_swaig_function({
41 function => $tool_name,
42 description => $description,
43 parameters => {
44 type => 'object',
45 properties => {
46 $param_name => {
47 type => 'string',
48 3 ▶ description => $self->params->{parameter_description} // 'The transfer destination',
Condition50%1/2
$self->params->{"parameter_description"} // "The transfer destination"
l!l
03
MC/DC0%0/1
$self->params->{"parameter_description"} // "The transfer destination"
$self->params->{"parameter_description"}
Truth table50%1/2
A
A= $self->params->{"parameter_description"}
Aresult
11
00
49 },
50 },
51 required => [$param_name],
52 },
53 data_map => { expressions => \@expressions },
54 });
55 }
56  
57 1 ▶sub get_hints {
Subroutine get_hints: called CC=3 SCAR=11.0
Pod undocumented
58 1 my ($self) = @_;
59 1 my @hints = ('transfer', 'connect', 'speak to', 'talk to');
60 1 ▶ for my $pattern (keys %{ $self->params->{transfers} // {} }) {
Condition50%1/2
$self->params->{"transfers"} // {}
l!l
10
MC/DC0%0/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table50%1/2
A
A= $self->params->{"transfers"}
Aresult
11
00
61 1 push @hints, split(/[\s_-]+/, $pattern);
62 }
63 1 return \@hints;
64 }
65  
66 1 ▶sub _get_prompt_sections {
Subroutine _get_prompt_sections: called CC=2 SCAR=7.0
67 1 my ($self) = @_;
68 1 ▶ my $transfers = $self->params->{transfers} // {};
Condition50%1/2
$self->params->{"transfers"} // {}
l!l
10
MC/DC0%0/1
$self->params->{"transfers"} // {}
$self->params->{"transfers"}
Truth table50%1/2
A
A= $self->params->{"transfers"}
Aresult
11
00
69 1 my @destinations = map { "- $_" } keys %$transfers;
70 return [
71 {
72 1 title => 'Transferring',
73 body => "Available transfer destinations:\n" . join("\n", @destinations),
74 },
75 {
76 title => 'Transfer Instructions',
77 body => 'When the user wants to be transferred, use the transfer tool.',
78 },
79 ];
80 }
81  
82 0 ▶sub get_parameter_schema {
Subroutine get_parameter_schema: not called CC=1 SCAR=6.9
Pod undocumented
83 return {
84 0 %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema },
85 transfers => { type => 'object', required => 1 },
86 description => { type => 'string' },
87 parameter_name => { type => 'string', default => 'transfer_type' },
88 parameter_description => { type => 'string' },
89 default_message => { type => 'string' },
90 };
91 }
92  
93 3 1;
« blib/lib/SignalWire/Agents/SWML/Schema.pm ↑ Summary blib/lib/SignalWire/Agents/Relay/Action.pm »