blib/lib/Langertha/ServerToolCall.pm

filter: Statementstmt 67.3% 31 / 46 Branchbran 43.7% 14 / 32 Conditioncond 27.5% 11 / 40 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 66.6% 6 / 9 Podpod 100% 7 / 7 totaltotal 45.5% 71 / 156 CC 33 SCAR 32.9
CC
33
Cov
47%
from_responses
42.4
from_responses
42.4
extract
13.1
CRAP 26.9
« blib/lib/Langertha/ToolResult.pm ↑ Summary blib/lib/Langertha/Role/OpenAICompatible.pm »
1 package Langertha::ServerToolCall;
2 # ABSTRACT: Record of one tool call the provider executed itself
3 198 our $VERSION = '0.505';
4 198 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 198 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7  
8 198 has type => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12 );
13  
14  
15 198 has id => (
16 is => 'ro',
17 isa => 'Str',
18 default => '',
19 );
20  
21  
22 198 has status => (
23 is => 'ro',
24 isa => 'Str',
25 predicate => 'has_status',
26 );
27  
28  
29 198 has data => (
30 is => 'ro',
31 isa => 'HashRef',
32 required => 1,
33 );
34  
35  
36 # Output items of the Responses wire that record a call the provider ran
37 # (OpenAI create-response reference, spec k206 section 2.1). A client
38 # tool_search_call (execution => 'client') is client-actionable instead, and
39 # the walkers croak on it (Langertha::Tool->_croak_on_client_item). Anything
40 # else unknown is skipped -- values open; it stays on Response.raw.
41 # x_search_call is xAI's X Search item (docs.x.ai tool-usage-details, k355;
42 # documentation-derived, not capture-verified).
43 198 my %RESPONSES_SERVER_ITEM = map { $_ => 1 } qw(
44 web_search_call file_search_call code_interpreter_call image_generation_call
45 mcp_call mcp_list_tools shell_call tool_search_call x_search_call
46 );
47  
48 153 ▶sub from_responses {
Subroutine from_responses: called CC=11 SCAR=37.5
Pod documented
49 0 ▶ my ( $class, $item ) = @_;
Subroutine from_responses: not called CC=11 SCAR=37.5
Pod documented
50 0 ▶ return undef unless ref $item eq 'HASH';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $item eq "HASH" 1 152 153
unless ref $item eq "HASH" 0 0 0
51 0 ▶ my $type = $item->{type} // '';
Condition25%1/4
$item->{"type"} // ""
l!l
1520
$item->{"type"} // ""
l!l
00
MC/DC0%0/1
$item->{"type"} // ""
$item->{"type"}
MC/DC0%0/1
$item->{"type"} // ""
$item->{"type"}
Truth table50%1/2
A
A= $item->{"type"}
Aresult
11
00
Truth table0%0/2
A
A= $item->{"type"}
Aresult
11
00
52 0 ▶ return undef unless $RESPONSES_SERVER_ITEM{$type};
Branch: 2 branches
BranchTrueFalseTotal
unless $RESPONSES_SERVER_ITEM{$type} 131 21 152
unless $RESPONSES_SERVER_ITEM{$type} 0 0 0
53 0 ▶ return undef if $type eq 'tool_search_call' && ( $item->{execution} // '' ) eq 'client';
Branch: 2 branches
BranchTrueFalseTotal
if $type eq "tool_search_call" and ($item->{"execution"} // "") eq "client" 0 21 21
if $type eq "tool_search_call" and ($item->{"execution"} // "") eq "client" 0 0 0
Condition30%3/10
$type eq "tool_search_call" and ($item->{"execution"} // "") eq "client"
!ll&&!rl&&r
2010
$item->{"execution"} // ""
l!l
01
$type eq "tool_search_call" and ($item->{"execution"} // "") eq "client"
!ll&&!rl&&r
000
$item->{"execution"} // ""
l!l
00
MC/DC0%0/2
$type eq "tool_search_call" and ($item->{"execution"} // "") eq "client"
$type eq "tool_search_call" $item->{"execution"}
MC/DC0%0/2
$type eq "tool_search_call" and ($item->{"execution"} // "") eq "client"
$type eq "tool_search_call" $item->{"execution"}
Truth table66%2/3
A and B
A= $type eq "tool_search_call"B= $item->{"execution"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $type eq "tool_search_call"B= $item->{"execution"}
ABresult
0X0
100
111
54 return $class->new(
55 type => $type,
56 data => $item,
57 ( defined $item->{id} && !ref $item->{id} ? ( id => $item->{id} ) : () ),
58 0 ▶ ( defined $item->{status} && !ref $item->{status} ? ( status => $item->{status} ) : () ),
Branch: 4 branches
BranchTrueFalseTotal
defined $item->{'id'} && !ref($item->{'id'}) ? : 21 0 21
defined $item->{'status'} && !ref($item->{'status'}) ? : 15 6 21
defined $item->{'id'} && !ref($item->{'id'}) ? : 0 0 0
defined $item->{'status'} && !ref($item->{'status'}) ? : 0 0 0
Condition25%3/12
defined $item->{"id"} and not ref $item->{"id"}
!ll&&!rl&&r
0021
defined $item->{"status"} and not ref $item->{"status"}
!ll&&!rl&&r
6015
defined $item->{"id"} and not ref $item->{"id"}
!ll&&!rl&&r
000
defined $item->{"status"} and not ref $item->{"status"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $item->{"id"} and not ref $item->{"id"}
defined $item->{"id"} not ref $item->{"id"}
MC/DC50%1/2
defined $item->{"status"} and not ref $item->{"status"}
defined $item->{"status"} not ref $item->{"status"}
MC/DC0%0/2
defined $item->{"id"} and not ref $item->{"id"}
defined $item->{"id"} not ref $item->{"id"}
MC/DC0%0/2
defined $item->{"status"} and not ref $item->{"status"}
defined $item->{"status"} not ref $item->{"status"}
Truth table33%1/3
A and not(B)
A= defined $item->{"id"}B= not ref $item->{"id"}
ABresult
0X0
100
111
Truth table66%2/3
A and not(B)
A= defined $item->{"status"}B= not ref $item->{"status"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $item->{"id"}B= not ref $item->{"id"}
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $item->{"status"}B= not ref $item->{"status"}
ABresult
0X0
100
111
59 );
60 }
61  
62  
63 102 ▶sub extract {
Subroutine extract: called CC=6 SCAR=25.8
Pod documented
64 0 ▶ my ( $class, $fmt, $data ) = @_;
Subroutine extract: not called CC=6 SCAR=25.8
Pod documented
65 0 ▶ croak "Langertha::ServerToolCall: server tool calls on the '" . ( $fmt // '' )
Branch: 2 branches
BranchTrueFalseTotal
unless ($fmt // "") eq "responses" 1 101 102
unless ($fmt // "") eq "responses" 0 0 0
Condition25%2/8
$fmt // ""
l!l
1020
$fmt // ""
l!l
10
$fmt // ""
l!l
00
$fmt // ""
l!l
00
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
MC/DC0%0/1
$fmt // ""
$fmt
Truth table50%1/2
A
A= $fmt
Aresult
11
00
Truth table50%1/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
Truth table0%0/2
A
A= $fmt
Aresult
11
00
66 . "' wire are not supported yet"
67 unless ( $fmt // '' ) eq 'responses';
68 0 ▶ return () unless ref $data eq 'HASH' && ref $data->{output} eq 'ARRAY';
Branch: 2 branches
BranchTrueFalseTotal
unless ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY" 4 97 101
unless ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY" 0 0 0
Condition33%2/6
ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY"
!ll&&!rl&&r
0497
ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC50%1/2
ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY"
ref $data eq "HASH" ref $data->{"output"} eq "ARRAY"
MC/DC0%0/2
ref $data eq "HASH" and ref $data->{"output"} eq "ARRAY"
ref $data eq "HASH" ref $data->{"output"} eq "ARRAY"
Truth table66%2/3
A and B
A= ref $data eq "HASH"B= ref $data->{"output"} eq "ARRAY"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $data eq "HASH"B= ref $data->{"output"} eq "ARRAY"
ABresult
0X0
100
111
69 0 return grep { defined } map { $class->from_responses($_) } @{ $data->{output} };
70 }
71  
72  
73 4 ▶sub to_hash {
Subroutine to_hash: called CC=2 SCAR=9.2
Pod documented
74 0 ▶ my ($self) = @_;
Subroutine to_hash: not called CC=2 SCAR=9.2
Pod documented
75 return {
76 0 ▶ type => $self->type,
Branch: 2 branches
BranchTrueFalseTotal
$self->has_status ? : 3 1 4
$self->has_status ? : 0 0 0
77 id => $self->id,
78 ( $self->has_status ? ( status => $self->status ) : () ),
79 data => $self->data,
80 };
81 }
82  
83  
84 1 ▶sub TO_JSON { shift->to_hash }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
85  
86  
87  
88 198 __PACKAGE__->meta->make_immutable;
89 198 1;
90  
91 __END__
« blib/lib/Langertha/ToolResult.pm ↑ Summary blib/lib/Langertha/Role/OpenAICompatible.pm »