blib/lib/Langertha/ServerTool.pm

filter: Statementstmt 83.5% 66 / 79 Branchbran 69.2% 36 / 52 Conditioncond 57.4% 31 / 54 MC/DCmcdc 48.4% 16 / 33 Subroutinesub 92.3% 12 / 13 Podpod 75.0% 6 / 8 totaltotal 69.8% 167 / 239 CC 68 SCAR 29.4
CC
68
Cov
72%
BUILD
44.0
BUILD
44.0
to
9.1
CRAP 18.9
« blib/lib/Langertha/HTTP/Redirect.pm ↑ Summary blib/lib/Langertha/Role/ResponsesCompatible.pm »
1 package Langertha::ServerTool;
2 # ABSTRACT: Provider-native server-side tool definition, pinned to one wire format
3 197 our $VERSION = '0.505';
4 197 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 197 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 197 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 197 ▶use Langertha::Tool;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 # Wires whose server tools this value object can carry (Phase 1a, k206).
11 197 my %SUPPORTED_WIRE = ( responses => 1 );
12  
13 # Typed client tools that are never server tools, even with unlisted => 1.
14 197 my %CLIENT_TYPE = map { $_ => 1 } qw( function custom namespace );
15  
16 197 has wire => (
17 is => 'ro',
18 isa => 'Str',
19 required => 1,
20 );
21  
22  
23 197 has spec => (
24 is => 'ro',
25 isa => 'HashRef',
26 required => 1,
27 );
28  
29  
30 197 has unlisted => (
31 is => 'ro',
32 isa => 'Bool',
33 default => 0,
34 );
35  
36  
37 149 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
38 149 my ( $orig, $class, @args ) = @_;
39 149 my $params = $class->$orig(@args);
40 149 ▶ $params->{spec} = { %{ $params->{spec} } } if ref $params->{spec} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $params->{"spec"} eq "HASH" 149 0 149
41 149 return $params;
42 197 };
43  
44 149 ▶sub BUILD {
Subroutine BUILD: called CC=14 SCAR=37.8
Pod undocumented
45 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=14 SCAR=37.8
Pod undocumented
46 0 my $wire = $self->wire;
47 0 my $spec = $self->spec;
48 0 ▶ my $label = $spec->{type} // '';
Condition50%2/4
$spec->{"type"} // ""
l!l
1481
$$spec{"type"} // ""
l!l
00
MC/DC100%1/1
$spec->{"type"} // ""
$spec->{"type"}
MC/DC0%0/1
$$spec{"type"} // ""
$$spec{"type"}
Truth table100%2/2
A
A= $spec->{"type"}
Aresult
11
00
Truth table0%0/2
A
A= $$spec{"type"}
Aresult
11
00
49 croak "Langertha::ServerTool: server tools on the '$wire' wire are not supported yet"
50 0 ▶ unless $SUPPORTED_WIRE{$wire};
Branch: 2 branches
BranchTrueFalseTotal
unless $SUPPORTED_WIRE{$wire} 1 148 149
unless $SUPPORTED_WIRE{$wire} 0 0 0
51 0 ▶ croak "Langertha::ServerTool: spec has no type (keys: "
Branch: 2 branches
BranchTrueFalseTotal
unless length $label 1 147 148
unless length $label 0 0 0
Condition25%1/4
join(',', sort(keys %$spec)) || '(empty)'
l!l
10
join(',', sort(keys %$spec)) || '(empty)'
l!l
00
MC/DC0%0/1
join(',', sort(keys %$spec)) || '(empty)'
join(',', sort(keys %$spec))
MC/DC0%0/1
join(',', sort(keys %$spec)) || '(empty)'
join(',', sort(keys %$spec))
Truth table50%1/2
A
A= join(',', sort(keys %$spec))
Aresult
11
00
Truth table0%0/2
A
A= join(',', sort(keys %$spec))
Aresult
11
00
52 . ( join( ',', sort keys %$spec ) || '(empty)' ) . ")"
53 unless length $label;
54 0 my ( $category, $own_wire ) = Langertha::Tool->classify($spec);
55 0 ▶ croak "Langertha::ServerTool: '$label' is a function tool; use Langertha::Tool"
Branch: 2 branches
BranchTrueFalseTotal
if $category eq "function" and $label eq "function" 1 146 147
if $category eq "function" and $label eq "function" 0 0 0
Condition33%2/6
$category eq "function" and $label eq "function"
!ll&&!rl&&r
14601
$category eq "function" and $label eq "function"
!ll&&!rl&&r
000
MC/DC50%1/2
$category eq "function" and $label eq "function"
$category eq "function" $label eq "function"
MC/DC0%0/2
$category eq "function" and $label eq "function"
$category eq "function" $label eq "function"
Truth table66%2/3
A and B
A= $category eq "function"B= $label eq "function"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $category eq "function"B= $label eq "function"
ABresult
0X0
100
111
56 if $category eq 'function' && $label eq 'function';
57 croak "Langertha::ServerTool: '$label' is a client tool, not a server tool"
58 0 ▶ if $CLIENT_TYPE{$label} || $category eq 'function';
Branch: 2 branches
BranchTrueFalseTotal
if $CLIENT_TYPE{$label} or $category eq "function" 3 143 146
if $CLIENT_TYPE{$label} or $category eq "function" 0 0 0
Condition33%2/6
$CLIENT_TYPE{$label} or $category eq "function"
l!l&&r!l&&!r
30143
$CLIENT_TYPE{$label} or $category eq "function"
l!l&&r!l&&!r
000
MC/DC50%1/2
$CLIENT_TYPE{$label} or $category eq "function"
$CLIENT_TYPE{$label} $category eq "function"
MC/DC0%0/2
$CLIENT_TYPE{$label} or $category eq "function"
$CLIENT_TYPE{$label} $category eq "function"
Truth table66%2/3
A or B
A= $CLIENT_TYPE{$label}B= $category eq "function"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $CLIENT_TYPE{$label}B= $category eq "function"
ABresult
1X1
011
000
59 0 ▶ croak "Langertha::ServerTool: '$label' is a client-executed built-in ($own_wire), not a server tool"
Branch: 2 branches
BranchTrueFalseTotal
if $category eq "client_builtin" 1 142 143
if $category eq "client_builtin" 0 0 0
60 if $category eq 'client_builtin';
61 0 ▶ croak "Langertha::ServerTool: '$label' belongs to the $own_wire wire, not '$wire'"
Branch: 2 branches
BranchTrueFalseTotal
if $category eq "server" and $own_wire ne $wire 1 141 142
if $category eq "server" and $own_wire ne $wire 0 0 0
Condition50%3/6
$category eq "server" and $own_wire ne $wire
!ll&&!rl&&r
31381
$category eq "server" and $own_wire ne $wire
!ll&&!rl&&r
000
MC/DC100%2/2
$category eq "server" and $own_wire ne $wire
$category eq "server" $own_wire ne $wire
MC/DC0%0/2
$category eq "server" and $own_wire ne $wire
$category eq "server" $own_wire ne $wire
Truth table100%3/3
A and B
A= $category eq "server"B= $own_wire ne $wire
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $category eq "server"B= $own_wire ne $wire
ABresult
0X0
100
111
62 if $category eq 'server' && $own_wire ne $wire;
63 0 ▶ return if $category eq 'server' || $self->unlisted;
Branch: 2 branches
BranchTrueFalseTotal
if $category eq "server" or $self->unlisted 140 1 141
if $category eq "server" or $self->unlisted 0 0 0
Condition50%3/6
$category eq "server" or $self->unlisted
l!l&&r!l&&!r
13821
$category eq "server" or $self->unlisted
l!l&&r!l&&!r
000
MC/DC100%2/2
$category eq "server" or $self->unlisted
$category eq "server" $self->unlisted
MC/DC0%0/2
$category eq "server" or $self->unlisted
$category eq "server" $self->unlisted
Truth table100%3/3
A or B
A= $category eq "server"B= $self->unlisted
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $category eq "server"B= $self->unlisted
ABresult
1X1
011
000
64 0 croak "Langertha::ServerTool: '$label' is not a known server tool on '$wire'; "
65 . "pass unlisted => 1 if the provider runs it";
66 }
67  
68 269 ▶sub type { $_[0]->spec->{type} }
Subroutine type: called CC=1 SCAR=0.0
Pod documented
69  
70  
71 1745 ▶sub from_hash {
Subroutine from_hash: called CC=7 SCAR=19.5
Pod documented
72 1745 my ( $class, $fmt, $hash ) = @_;
73 1745 ▶ return $hash if blessed($hash) && $hash->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($hash) and $hash->isa(__PACKAGE__) 26 1719 1745
Condition100%3/3
builtin::blessed($hash) and $hash->isa(__PACKAGE__)
!ll&&!rl&&r
16833626
MC/DC100%2/2
builtin::blessed($hash) and $hash->isa(__PACKAGE__)
builtin::blessed($hash) $hash->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= builtin::blessed($hash)B= $hash->isa(__PACKAGE__)
ABresult
0X0
100
111
74 1719 ▶ return undef unless ref $hash eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 37 1682 1719
75 1682 ▶ return undef unless defined $fmt && $SUPPORTED_WIRE{$fmt};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fmt and $SUPPORTED_WIRE{$fmt} 821 861 1682
Condition66%2/3
defined $fmt and $SUPPORTED_WIRE{$fmt}
!ll&&!rl&&r
0821861
MC/DC50%1/2
defined $fmt and $SUPPORTED_WIRE{$fmt}
defined $fmt $SUPPORTED_WIRE{$fmt}
Truth table66%2/3
A and B
A= defined $fmtB= $SUPPORTED_WIRE{$fmt}
ABresult
0X0
100
111
76 861 ▶ return undef unless Langertha::Tool->classify( $hash, $fmt ) eq 'server';
Branch: 1 branch
BranchTrueFalseTotal
unless "Langertha::Tool"->classify($hash, $fmt) eq "server" 732 129 861
77 129 return $class->new( wire => $fmt, spec => $hash );
78 }
79  
80  
81 157 ▶sub to {
Subroutine to: called CC=9 SCAR=22.1
Pod documented
82 157 my ( $self, $fmt ) = @_;
83 157 ▶ $fmt //= '';
Condition50%1/2
$fmt //= ""
l!l
1570
MC/DC0%0/1
$fmt //= ""
$fmt
Truth table50%1/2
A
A= $fmt
Aresult
11
00
84 157 ▶ croak "Langertha::ServerTool: '" . $self->type . "' belongs to the "
Branch: 1 branch
BranchTrueFalseTotal
unless $fmt eq $self->wire 9 148 157
85 . $self->wire . " wire, not '$fmt'; server tools are provider-native and cannot be translated"
86 unless $fmt eq $self->wire;
87 148 my $spec = $self->spec;
88 # Remote MCP on the Responses wire: OpenAI defaults require_approval to
89 # "always", which answers with an mcp_approval_request the client must
90 # confirm, and Langertha has no approval flow (orchestrator ruling Q2 on
91 # k206). Checked here, on the one door every emission path goes through --
92 # the Responses envelope and Tool->format_list, which sees no engine -- so it
93 # is enforced once (k206 review M3). An engine whose provider does not take
94 # the field (xAI) strips it in its _server_tool_wire_check hook afterwards.
95 148 ▶ if ( $self->type eq 'mcp' && $fmt eq 'responses' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq "mcp" and $fmt eq "responses") 26 122 148
Condition66%2/3
$self->type eq "mcp" and $fmt eq "responses"
!ll&&!rl&&r
122026
MC/DC50%1/2
$self->type eq "mcp" and $fmt eq "responses"
$self->type eq "mcp" $fmt eq "responses"
Truth table66%2/3
A and B
A= $self->type eq "mcp"B= $fmt eq "responses"
ABresult
0X0
100
111
96 26 my $approval = $spec->{require_approval};
97 26 ▶ croak "Langertha::ServerTool: remote MCP tool '" . ( $spec->{server_label} // '?' )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $approval and not ref $approval and $approval eq "never" 12 14 26
Condition87%7/8
defined $approval and not ref $approval and $approval eq "never"
!ll&&!rl&&r
8414
defined $approval and not ref $approval
!ll&&!rl&&r
4418
$spec->{"server_label"} // "?"
l!l
120
MC/DC100%3/3
defined $approval and not ref $approval and $approval eq "never"
defined $approval not ref $approval $approval eq "never"
MC/DC0%0/1
$spec->{"server_label"} // "?"
$spec->{"server_label"}
Truth table100%4/4
A and not(B) and C
A= defined $approvalB= not ref $approvalC= $approval eq "never"
ABCresult
0XX0
10X0
1100
1111
Truth table50%1/2
A
A= $spec->{"server_label"}
Aresult
11
00
98 . "' needs require_approval => 'never'; the approval flow is not supported"
99 unless defined $approval && !ref $approval && $approval eq 'never';
100 }
101 136 return { %$spec };
102 }
103  
104  
105 584 ▶sub check_engine {
Subroutine check_engine: called CC=6 SCAR=17.9
Pod documented
106 584 my ( $class, $engine, $tools ) = @_;
107 584 ▶ return unless ref $tools eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tools eq "ARRAY" 265 319 584
108 319 ▶ return if $engine->supports('server_tools');
Branch: 1 branch
BranchTrueFalseTotal
if $engine->supports("server_tools") 6 313 319
109 313 for my $item (@$tools) {
110 344 ▶ next unless blessed($item) && $item->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($item) and $item->isa(__PACKAGE__) 338 6 344
Condition100%3/3
builtin::blessed($item) and $item->isa(__PACKAGE__)
!ll&&!rl&&r
305336
MC/DC100%2/2
builtin::blessed($item) and $item->isa(__PACKAGE__)
builtin::blessed($item) $item->isa(__PACKAGE__)
Truth table100%3/3
A and B
A= builtin::blessed($item)B= $item->isa(__PACKAGE__)
ABresult
0X0
100
111
111 6 croak "" . ( ref $engine ) . ": '" . $item->type . "' is a Langertha::ServerTool, "
112 . "and this engine does not supports('server_tools')";
113 }
114 307 return;
115 }
116  
117  
118 3 ▶sub to_hash {
Subroutine to_hash: called CC=2 SCAR=7.1
Pod documented
119 3 my ($self) = @_;
120 return {
121 wire => $self->wire,
122 3 ▶ spec => { %{ $self->spec } },
Branch: 1 branch
BranchTrueFalseTotal
$self->unlisted ? : 0 3 3
123 ( $self->unlisted ? ( unlisted => 1 ) : () ),
124 };
125 }
126  
127  
128 1 ▶sub TO_JSON { shift->to_hash }
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod documented
129  
130  
131  
132 197 __PACKAGE__->meta->make_immutable;
133 197 1;
134  
135 __END__
« blib/lib/Langertha/HTTP/Redirect.pm ↑ Summary blib/lib/Langertha/Role/ResponsesCompatible.pm »