File Coverage

blib/lib/SignalWire/Agents/Skills/Builtin/Joke.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition 4 4 100.0
subroutine 10 10 100.0
pod 0 4 0.0
total 37 41 90.2


line stmt bran cond sub pod time code
1             package SignalWire::Agents::Skills::Builtin::Joke;
2 3     3   24 use strict;
  3         6  
  3         140  
3 3     3   16 use warnings;
  3         6  
  3         198  
4 3     3   20 use Moo;
  3         5  
  3         24  
5 3     3   1166 use JSON ();
  3         8  
  3         113  
6             extends 'SignalWire::Agents::Skills::SkillBase';
7              
8 3     3   15 use SignalWire::Agents::Skills::SkillRegistry;
  3         6  
  3         1417  
9             SignalWire::Agents::Skills::SkillRegistry->register_skill('joke', __PACKAGE__);
10              
11             has '+skill_name' => (default => sub { 'joke' });
12             has '+skill_description' => (default => sub { 'Tell jokes using the API Ninjas joke API' });
13             has '+supports_multiple_instances' => (default => sub { 0 });
14              
15 4     4 0 2340 sub setup { 1 }
16              
17             sub register_tools {
18 3     3 0 538 my ($self) = @_;
19 3   100     110 my $tool_name = $self->params->{tool_name} // 'get_joke';
20              
21             # DataMap-style registration
22             $self->agent->register_swaig_function({
23             function => $tool_name,
24             description => 'Get a random joke from API Ninjas',
25             parameters => {
26             type => 'object',
27             properties => {
28             type => {
29             type => 'string',
30             description => 'Type of joke',
31             enum => ['jokes', 'dadjokes'],
32             },
33             },
34             required => ['type'],
35             },
36             data_map => {
37             webhooks => [{
38             method => 'GET',
39             url => 'https://api.api-ninjas.com/v1/${args.type}',
40 3   100     75 headers => { 'X-Api-Key' => $self->params->{api_key} // '' },
41             output => {
42             response => 'Here\'s a joke: ${array[0].joke}',
43             },
44             }],
45             },
46             });
47             }
48              
49             sub get_global_data {
50 1     1 0 8 return { joke_skill_enabled => JSON::true };
51             }
52              
53             sub _get_prompt_sections {
54             return [{
55 1     1   5 title => 'Joke Telling',
56             body => 'You can tell jokes to lighten the mood.',
57             bullets => [
58             'Use the joke tool when the user asks for a joke',
59             'Choose between regular jokes and dad jokes',
60             ],
61             }];
62             }
63              
64             sub get_parameter_schema {
65             return {
66 1     1 0 2569 %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema },
  1         5  
67             api_key => { type => 'string', required => 1, hidden => 1 },
68             tool_name => { type => 'string', default => 'get_joke' },
69             };
70             }
71              
72             1;