Langertha/Role/Capabilities.pm

filter: Statementstmt 100% 15 / 15 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 100% 22 / 22 CC 4 SCAR 11.0
CC
4
Cov
100%
engine_capabilities
4.0
BEGIN
1.0
supports
1.0
CRAP 3.0
« Langertha/ImageGen.pm ↑ Summary Langertha/Embedder.pm »
1 package Langertha::Role::Capabilities;
2 # ABSTRACT: Engine-capability registry derived from composed roles
3 34 our $VERSION = '0.502';
4 34 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 # Role-name => list of capability flag names that role contributes.
8 # Plus implicit:
9 # chat -> simple_chat works (Role::Chat is composed)
10 # streaming -> chat_stream_request is wired up (Role::Streaming)
11 # tools_native -> Role::Tools (the named flags below come too)
12 # tools_hermes -> Role::HermesTools
13 # ... see %ROLE_TO_CAPS below.
14 34 my %ROLE_TO_CAPS = (
15 'Langertha::Role::Chat' => [qw( chat )],
16 'Langertha::Role::Streaming' => [qw( streaming )],
17 'Langertha::Role::Tools' => [qw(
18 tools_native tool_choice_auto tool_choice_any tool_choice_none tool_choice_named
19 )],
20 'Langertha::Role::HermesTools' => [qw( tools_hermes )],
21 'Langertha::Role::ResponseFormat' => [qw(
22 response_format_json_object response_format_json_schema
23 )],
24 'Langertha::Role::Embedding' => [qw( embedding )],
25 'Langertha::Role::Transcription' => [qw( transcription )],
26 'Langertha::Role::ImageGeneration' => [qw( image_generation )],
27 'Langertha::Role::Temperature' => [qw( temperature )],
28 'Langertha::Role::Seed' => [qw( seed )],
29 'Langertha::Role::ContextSize' => [qw( context_size )],
30 'Langertha::Role::ResponseSize' => [qw( response_size )],
31 'Langertha::Role::SystemPrompt' => [qw( system_prompt )],
32 'Langertha::Role::ParallelToolUse' => [qw( parallel_tool_use )],
33 );
34  
35 sub engine_capabilities {
36 9 ▶ my ($self) = @_;
Subroutine engine_capabilities: called CC=4 SCAR=13.9
Pod documented
37 9 my %caps;
38 9 for my $role ( keys %ROLE_TO_CAPS ) {
39 126 ▶ next unless $self->does($role);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->does($role) 50 76 126
40 76 $caps{$_} = 1 for @{ $ROLE_TO_CAPS{$role} };
41 }
42 9 return \%caps;
43 }
44  
45  
46 sub supports {
47 2 ▶ my ( $self, $cap ) = @_;
Subroutine supports: called CC=1 SCAR=0.0
Pod documented
48 2 return !!$self->engine_capabilities->{$cap};
49 }
50  
51  
52 34 1;
53  
54 __END__
55  
56 =pod
57  
58 =encoding UTF-8
59  
60 =head1 NAME
61  
62 Langertha::Role::Capabilities - Engine-capability registry derived from composed roles
63  
64 =head1 VERSION
65  
66 version 0.502
67  
68 =head1 SYNOPSIS
69  
70 if ( $engine->supports('tool_choice_named') ) { ... }
71  
72 my $caps = $engine->engine_capabilities;
73 for my $cap ( sort keys %$caps ) {
74 say "$cap" if $caps->{$cap};
75 }
76  
77 # Engine-level override for a wire reality the role inventory
78 # cannot express (e.g. provider only accepts string tool_choice):
79 around engine_capabilities => sub {
80 my ( $orig, $self, @rest ) = @_;
81 my $caps = $self->$orig(@rest);
82 delete $caps->{tool_choice_named};
83 return $caps;
84 };
85  
86 =head1 DESCRIPTION
87  
88 Composed by L<Langertha::Role::Chat> (and therefore present on every
89 engine), this role provides the C<engine_capabilities> method plus the
90 C<supports> helper. The default implementation derives the flag set
91 from which capability-bearing roles the engine composes — no per-role
92 plumbing required, the registry below is the single source of truth.
93  
94 Engines override (via C<around>) when the wire reality differs from
95 the role inventory — for example to clear C<tool_choice_named> on a
96 provider that only accepts string forms of C<tool_choice>.
97  
98 The mapping from role to flag is intentionally kept inside this one
99 module so adding a new capability is a single-file change. The role
100 itself does not need to know about C<engine_capabilities>.
101  
102 =head2 engine_capabilities
103  
104 my $caps = $engine->engine_capabilities;
105  
106 Returns a HashRef of capability flags. The default scans the composed
107 role inventory and sets flags from a static role-to-flags map. Override
108 via C<around> on an engine to remove flags for capabilities the wire
109 reality cannot deliver, or to add ad-hoc flags an engine wants to
110 advertise.
111  
112 =head2 supports
113  
114 if ( $engine->supports('tool_choice_named') ) { ... }
115  
116 Convenience wrapper that returns a true value when the named capability
117 is present and truthy in C<engine_capabilities>.
118  
119 =head1 SUPPORT
120  
121 =head2 Issues
122  
123 Please report bugs and feature requests on GitHub at
124 L<https://github.com/Getty/langertha/issues>.
125  
126 =head2 IRC
127  
128 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
129  
130 =head1 CONTRIBUTING
131  
132 Contributions are welcome! Please fork the repository and submit a pull request.
133  
134 =head1 AUTHOR
135  
136 Torsten Raudssus <getty@cpan.org>
137  
138 =head1 COPYRIGHT AND LICENSE
139  
140 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
141  
142 This is free software; you can redistribute it and/or modify it under
143 the same terms as the Perl 5 programming language system itself.
144  
145 =cut
« Langertha/ImageGen.pm ↑ Summary Langertha/Embedder.pm »