blib/lib/Langertha/Manifest/Endpoint.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 100% 8 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 87.5% 7 / 8 Podpod 66.6% 4 / 6 totaltotal 92.3% 48 / 52 CC 5 SCAR 5.6
CC
5
Cov
97%
BUILD
2.0
is_known_dialect
2.0
from_hash
2.0
CRAP 1.8
« blib/lib/Langertha/Engine/Mistral.pm ↑ Summary blib/lib/Langertha/Role/StaticModels.pm »
1 package Langertha::Manifest::Endpoint;
2 # ABSTRACT: One endpoint of a provider manifest: wire dialect, base URL, auth reference
3 8 our $VERSION = '0.503';
4 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 with 'Langertha::Manifest::Validation';
6  
7  
8 # The v1 dialect vocabulary, derived from the engine hierarchy (ADR 0006:
9 # inheritance encodes the wire dialect) and named after the tool_wire_format
10 # tag where the two coincide. openai-chat carries a suffix because OpenAI
11 # ships two envelopes (/chat/completions and /responses).
12 # anthropic-compat is the /anthropic shim variant of the Messages envelope:
13 # same envelope, but structured output is emulated with a synthetic tool plus
14 # a forced tool_choice instead of first-party output_config.format.
15 8 my @KNOWN_DIALECTS = qw(
16 openai-chat responses perplexity-agent anthropic anthropic-compat gemini ollama aki lmstudio
17 );
18 8 my %KNOWN_DIALECT = map { $_ => 1 } @KNOWN_DIALECTS;
19  
20 8 has id => ( is => 'ro', isa => 'Str', required => 1 );
21 8 has dialect => ( is => 'ro', isa => 'Str', required => 1 );
22 8 has base_url => ( is => 'ro', isa => 'Str', required => 1 );
23 25 ▶has auth_ref => ( is => 'ro', isa => 'Maybe[Str]', default => sub { undef } );
Subroutine __ANON__: called CC=1 SCAR=0.0
24  
25  
26 120 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
27 120 my ($self) = @_;
28 120 $self->_check_id( 'id', $self->id );
29 119 $self->_check_token( 'dialect', $self->dialect );
30 118 $self->_check_url( 'base_url', $self->base_url );
31 114 ▶ $self->_check_id( 'auth_ref', $self->auth_ref ) if defined $self->auth_ref;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->auth_ref 89 25 114
32 114 return;
33 }
34  
35 1 ▶sub known_dialects { return @KNOWN_DIALECTS }
Subroutine known_dialects: called CC=1 SCAR=0.0
Pod documented
36  
37  
38 3 ▶sub is_known_dialect { return $KNOWN_DIALECT{ $_[0]->dialect } ? 1 : 0 }
Subroutine is_known_dialect: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$KNOWN_DIALECT{$_[0]->dialect} ? : 2 1 3
39  
40  
41 87 ▶sub from_hash {
Subroutine from_hash: called CC=2 SCAR=6.9
Pod documented
42 87 my ( $class, $data ) = @_;
43 87 $class->_check_fields( $data,
44 required => [qw( id dialect base_url )],
45 optional => [qw( auth_ref )],
46 );
47 return $class->new(
48 82 ▶ map { exists $data->{$_} ? ( $_ => $class->_string( $_, $data->{$_} ) ) : () }
Branch: 1 branch
BranchTrueFalseTotal
exists $$data{$_} ? : 311 14 325
49 qw( id dialect base_url auth_ref )
50 );
51 }
52  
53  
54 47 ▶sub to_hash {
Subroutine to_hash: called CC=2 SCAR=6.9
Pod documented
55 47 my ($self) = @_;
56 return {
57 47 ▶ id => $self->id,
Branch: 1 branch
BranchTrueFalseTotal
defined $self->auth_ref ? : 22 25 47
58 dialect => $self->dialect,
59 base_url => $self->base_url,
60 ( defined $self->auth_ref ? ( auth_ref => $self->auth_ref ) : () ),
61 };
62 }
63  
64  
65 0 ▶sub TO_JSON { shift->to_hash }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 8 __PACKAGE__->meta->make_immutable;
68  
69  
70 8 1;
71  
72 __END__
73  
74 =pod
75  
76 =encoding UTF-8
77  
78 =head1 NAME
79  
80 Langertha::Manifest::Endpoint - One endpoint of a provider manifest: wire dialect, base URL, auth reference
81  
82 =head1 VERSION
83  
84 version 0.503
85  
86 =head1 SYNOPSIS
87  
88 my $endpoint = Langertha::Manifest::Endpoint->new(
89 id => 'chat',
90 dialect => 'openai-chat',
91 base_url => 'https://provider.example/v1',
92 auth_ref => 'api',
93 );
94  
95 if ( $endpoint->is_known_dialect ) { ... }
96  
97 =head1 DESCRIPTION
98  
99 An endpoint of a L<Langertha::Manifest>: where to talk (C<base_url>), which
100 wire envelope to speak (C<dialect>) and which auth mechanism it needs
101 (C<auth_ref>, absent when it needs none). Immutable; validated on
102 construction.
103  
104 =head2 id
105  
106 Local id of the endpoint, unique within the manifest; models point at it
107 with C<endpoint_ref>.
108  
109 =head2 dialect
110  
111 The wire dialect token (see L</known_dialects>). A pattern-valid but unknown
112 dialect is accepted — whether a client has an adapter for it is
113 L</is_known_dialect>, a separate question from validity.
114  
115 =head2 base_url
116  
117 C<http>/C<https> URL; exactly what a Langertha engine of this dialect takes
118 as C<url> (the dialect decides which path it appends). Printable ASCII,
119 never carries userinfo, a query string or a fragment. This keeps the usual
120 credential carriers out of a published URL; it is best effort — a secret
121 embedded in the path itself cannot be told apart from a real path.
122  
123 =head2 auth_ref
124  
125 Id of the L<Langertha::Manifest::Auth> entry this endpoint needs, or
126 C<undef> when it needs no credentials.
127  
128 =head2 known_dialects
129  
130 my @dialects = Langertha::Manifest::Endpoint->known_dialects;
131  
132 The v1 dialect vocabulary: C<openai-chat>, C<responses>,
133 C<perplexity-agent>, C<anthropic> (first-party Messages API),
134 C<anthropic-compat> (the C</anthropic> shims: structured output via a
135 synthetic tool and forced choice), C<gemini>, C<ollama>, C<aki>,
136 C<lmstudio>.
137  
138 =head2 is_known_dialect
139  
140 True when L</dialect> is in the v1 vocabulary.
141  
142 =head2 from_hash
143  
144 my $endpoint = Langertha::Manifest::Endpoint->from_hash(\%data);
145  
146 Builds an endpoint from its JSON object form, rejecting unknown and
147 forbidden fields.
148  
149 =head2 to_hash
150  
151 Returns the JSON object form; C<auth_ref> is omitted when undefined.
152  
153 =head1 SEE ALSO
154  
155 =over
156  
157 =item * L<Langertha::Manifest> - The provider manifest
158  
159 =back
160  
161 =head1 SUPPORT
162  
163 =head2 Issues
164  
165 Please report bugs and feature requests on GitHub at
166 L<https://github.com/Getty/langertha/issues>.
167  
168 =head2 IRC
169  
170 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
171  
172 =head1 CONTRIBUTING
173  
174 Contributions are welcome! Please fork the repository and submit a pull request.
175  
176 =head1 AUTHOR
177  
178 Torsten Raudssus <getty@cpan.org>
179  
180 =head1 COPYRIGHT AND LICENSE
181  
182 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
183  
184 This is free software; you can redistribute it and/or modify it under
185 the same terms as the Perl 5 programming language system itself.
186  
187 =cut
« blib/lib/Langertha/Engine/Mistral.pm ↑ Summary blib/lib/Langertha/Role/StaticModels.pm »