File Coverage

blib/lib/SignalWire/Agents/Skills/Builtin/PlayBackgroundFile.pm
Criterion Covered Total %
statement 22 22 100.0
branch 1 2 50.0
condition 4 4 100.0
subroutine 7 7 100.0
pod 0 3 0.0
total 34 38 89.4


line stmt bran cond sub pod time code
1             package SignalWire::Agents::Skills::Builtin::PlayBackgroundFile;
2 3     3   44 use strict;
  3         8  
  3         133  
3 3     3   19 use warnings;
  3         6  
  3         207  
4 3     3   21 use Moo;
  3         8  
  3         22  
5             extends 'SignalWire::Agents::Skills::SkillBase';
6              
7 3     3   1515 use SignalWire::Agents::Skills::SkillRegistry;
  3         7  
  3         1578  
8             SignalWire::Agents::Skills::SkillRegistry->register_skill('play_background_file', __PACKAGE__);
9              
10             has '+skill_name' => (default => sub { 'play_background_file' });
11             has '+skill_description' => (default => sub { 'Control background file playback' });
12             has '+supports_multiple_instances' => (default => sub { 1 });
13              
14 4     4 0 2341 sub setup { 1 }
15              
16             sub register_tools {
17 3     3 0 571 my ($self) = @_;
18 3   100     28 my $tool_name = $self->params->{tool_name} // 'play_background_file';
19 3   100     18 my $files = $self->params->{files} // [];
20              
21             # Build action enum from file keys
22 3         29 my @actions = ('stop');
23 3         11 for my $f (@$files) {
24 2 50       12 push @actions, "start_$f->{key}" if $f->{key};
25             }
26              
27             # DataMap-style registration with expressions
28             $self->agent->register_swaig_function({
29 3         169 function => $tool_name,
30             description => "Control background file playback for $tool_name",
31             parameters => {
32             type => 'object',
33             properties => {
34             action => {
35             type => 'string',
36             description => 'Playback action',
37             enum => \@actions,
38             },
39             },
40             required => ['action'],
41             },
42             data_map => {
43             expressions => [
44             {
45             string => '${args.action}',
46             pattern => 'stop',
47             output => {
48             response => 'Stopping background playback.',
49             action => [{ stop_background_file => {} }],
50             },
51             },
52             ],
53             },
54             });
55             }
56              
57             sub get_parameter_schema {
58             return {
59 1     1 0 4614 %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema },
  1         7  
60             files => { type => 'array', required => 1, description => 'Array of file objects with key, description, url' },
61             tool_name => { type => 'string', default => 'play_background_file' },
62             };
63             }
64              
65             1;