« blib/lib/SignalWire/Agents/REST/Namespaces/Video.pm
↑ Summary
blib/lib/SignalWire/Agents/Skills/Builtin/CustomSkills.pm »
| 1 | package SignalWire::Agents::Skills::Builtin::InfoGatherer; | ||||||||||||
| 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 | ▶ | use JSON qw(encode_json); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | extends 'SignalWire::Agents::Skills::SkillBase'; | |||||||||||
| 7 | |||||||||||||
| 8 | 3 | ▶ | use SignalWire::Agents::Skills::SkillRegistry; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 3 | SignalWire::Agents::Skills::SkillRegistry->register_skill('info_gatherer', __PACKAGE__); | |||||||||||
| 10 | |||||||||||||
| 11 | 7 | ▶ | has '+skill_name' => (default => sub { 'info_gatherer' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 7 | ▶ | has '+skill_description' => (default => sub { 'Gather answers to a configurable list of questions' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 7 | ▶ | has '+supports_multiple_instances' => (default => sub { 1 }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | 4 | ▶ | sub setup { 1 } | ||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 16 | |||||||||||||
| 17 | 3 | ▶ | sub register_tools { | ||||||||||
|
Subroutine
register_tools: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||
| 18 | 3 | my ($self) = @_; | |||||||||||
| 19 | 3 | ▶ | my $prefix = $self->params->{prefix} // ''; | ||||||||||
|
Condition100%2/2
$self->params->{"prefix"} // ""
MC/DC100%1/1
$self->params->{"prefix"} // ""
$self->params->{"prefix"}
Truth table100%2/2
A
A= $self->params->{"prefix"}
| |||||||||||||
| 20 | 3 | ▶ | my $questions = $self->params->{questions} // []; | ||||||||||
|
Condition100%2/2
$self->params->{"questions"} // []
MC/DC100%1/1
$self->params->{"questions"} // []
$self->params->{"questions"}
Truth table100%2/2
A
A= $self->params->{"questions"}
| |||||||||||||
| 21 | |||||||||||||
| 22 | 3 | ▶ | my $start_name = $prefix ? "${prefix}_start_questions" : 'start_questions'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 3 | ▶ | my $submit_name = $prefix ? "${prefix}_submit_answer" : 'submit_answer'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | |||||||||||||
| 25 | $self->define_tool( | ||||||||||||
| 26 | name => $start_name, | ||||||||||||
| 27 | description => 'Start the question-gathering process and return the first question', | ||||||||||||
| 28 | parameters => { type => 'object', properties => {} }, | ||||||||||||
| 29 | 0 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 30 | 0 | my ($args, $raw) = @_; | |||||||||||
| 31 | 0 | require SignalWire::Agents::SWAIG::FunctionResult; | |||||||||||
| 32 | 0 | ▶ | my $first = $questions->[0]{question_text} // 'No questions configured'; | ||||||||||
|
Condition0%0/2
$questions->[0]{"question_text"} // "No questions configured"
MC/DC0%0/1
$questions->[0]{"question_text"} // "No questions configured"
$questions->[0]{"question_text"}
Truth table0%0/2
A
A= $questions->[0]{"question_text"}
| |||||||||||||
| 33 | 0 | return SignalWire::Agents::SWAIG::FunctionResult->new( | |||||||||||
| 34 | response => $first, | ||||||||||||
| 35 | ); | ||||||||||||
| 36 | }, | ||||||||||||
| 37 | 3 | ); | |||||||||||
| 38 | |||||||||||||
| 39 | $self->define_tool( | ||||||||||||
| 40 | name => $submit_name, | ||||||||||||
| 41 | description => 'Submit an answer to the current question', | ||||||||||||
| 42 | parameters => { | ||||||||||||
| 43 | type => 'object', | ||||||||||||
| 44 | properties => { | ||||||||||||
| 45 | answer => { type => 'string', description => 'The answer' }, | ||||||||||||
| 46 | confirmed_by_user => { type => 'boolean', description => 'Whether user confirmed' }, | ||||||||||||
| 47 | }, | ||||||||||||
| 48 | required => ['answer'], | ||||||||||||
| 49 | }, | ||||||||||||
| 50 | 0 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 51 | 0 | my ($args, $raw) = @_; | |||||||||||
| 52 | 0 | require SignalWire::Agents::SWAIG::FunctionResult; | |||||||||||
| 53 | 0 | return SignalWire::Agents::SWAIG::FunctionResult->new( | |||||||||||
| 54 | response => "Answer recorded: $args->{answer}", | ||||||||||||
| 55 | ); | ||||||||||||
| 56 | }, | ||||||||||||
| 57 | 3 | ); | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 1 | ▶ | sub get_global_data { | ||||||||||
|
Subroutine
get_global_data: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||
| 61 | 1 | my ($self) = @_; | |||||||||||
| 62 | 1 | ▶ | my $ns = $self->params->{prefix} // 'info_gatherer'; | ||||||||||
|
Condition50%1/2
$self->params->{"prefix"} // "info_gatherer"
MC/DC0%0/1
$self->params->{"prefix"} // "info_gatherer"
$self->params->{"prefix"}
Truth table50%1/2
A
A= $self->params->{"prefix"}
| |||||||||||||
| 63 | return { | ||||||||||||
| 64 | $ns => { | ||||||||||||
| 65 | 1 | ▶ | questions => $self->params->{questions} // [], | ||||||||||
|
Condition50%1/2
$self->params->{"questions"} // []
MC/DC0%0/1
$self->params->{"questions"} // []
$self->params->{"questions"}
Truth table50%1/2
A
A= $self->params->{"questions"}
| |||||||||||||
| 66 | question_index => 0, | ||||||||||||
| 67 | answers => [], | ||||||||||||
| 68 | }, | ||||||||||||
| 69 | }; | ||||||||||||
| 70 | } | ||||||||||||
| 71 | |||||||||||||
| 72 | 1 | ▶ | sub _get_prompt_sections { | ||||||||||
|
Subroutine
_get_prompt_sections: called CC=2 SCAR=7.1
| |||||||||||||
| 73 | 1 | my ($self) = @_; | |||||||||||
| 74 | 1 | ▶ | my $key = $self->params->{prefix} // 'info_gatherer'; | ||||||||||
|
Condition50%1/2
$self->params->{"prefix"} // "info_gatherer"
MC/DC0%0/1
$self->params->{"prefix"} // "info_gatherer"
$self->params->{"prefix"}
Truth table50%1/2
A
A= $self->params->{"prefix"}
| |||||||||||||
| 75 | return [{ | ||||||||||||
| 76 | 1 | title => "Info Gatherer ($key)", | |||||||||||
| 77 | body => 'Ask the user a series of questions and collect their answers.', | ||||||||||||
| 78 | bullets => [ | ||||||||||||
| 79 | 'Ask questions one at a time', | ||||||||||||
| 80 | 'Wait for the user to answer before proceeding', | ||||||||||||
| 81 | 'Confirm answers when required', | ||||||||||||
| 82 | ], | ||||||||||||
| 83 | }]; | ||||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 1 | ▶ | sub get_parameter_schema { | ||||||||||
|
Subroutine
get_parameter_schema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 87 | return { | ||||||||||||
| 88 | 1 | %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, | |||||||||||
| 89 | questions => { type => 'array', required => 1, description => 'List of question objects' }, | ||||||||||||
| 90 | prefix => { type => 'string', description => 'Prefix for tool names' }, | ||||||||||||
| 91 | completion_message => { type => 'string', description => 'Message after all questions answered' }, | ||||||||||||
| 92 | }; | ||||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | 3 | 1; | |||||||||||