| 1 | package Langertha::Manifest::Model; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: One model entry of a provider manifest: id, endpoint, declared capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use JSON::MaybeXS (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | with 'Langertha::Manifest::Validation'; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 8 | has id => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 8 | has endpoint_ref => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | has capabilities => ( is => 'ro', isa => 'HashRef', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 119 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 119 | my ( $orig, $class, @args ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 119 | my $args = $class->$orig(@args); | |||||||||||||||||||||||||||||||||||||||||
| 17 | 119 | ▶ | if ( exists $args->{capabilities} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 115 | my $caps = $args->{capabilities}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 115 | ▶ | $class->_error('capabilities: must be a JSON object') unless ref $caps eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 114 | my %norm; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 114 | for my $name ( sort keys %$caps ) { | |||||||||||||||||||||||||||||||||||||||||
| 22 | 702 | ▶ | $class->_error( "capabilities: invalid capability name '" . $class->_display($name) . q{'} ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | unless $name =~ /\A[a-z][a-z0-9_]{0,63}\z/; | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 701 | $norm{$name} = $class->_bool( "capabilities: '$name'", $caps->{$name} ); | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 107 | $args->{capabilities} = \%norm; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 111 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 111 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 111 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 111 | my $id = $self->id; | |||||||||||||||||||||||||||||||||||||||||
| 34 | # Control, format (bidi overrides such as U+202E), surrogate, private-use, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # unassigned and line/paragraph-separator characters are rejected: a client | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # prints model ids. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 111 | ▶ | $self->_error('id must be a non-empty model id without control or format characters (max 256)') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
length $id and length $id <= 256 and not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
length $id and length $id <= 256
MC/DC33%1/3
length $id and length $id <= 256 and not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
length $id
length $id <= 256
not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
Truth table50%2/4
A and B and not(C)
A= length $idB= length $id <= 256C= not $id =~ /[\p{C}\p{Zl}\p{Zp}]/
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | unless length $id && length $id <= 256 && $id !~ /[\p{C}\p{Zl}\p{Zp}]/; | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 108 | $self->_check_id( 'endpoint_ref', $self->endpoint_ref ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 108 | return; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 42 | ▶ | sub supports { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supports: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 42 | my ( $self, $cap ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 42 | ▶ | return $self->capabilities->{$cap} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 77 | ▶ | sub from_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_hash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 77 | my ( $class, $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 77 | $class->_check_fields( $data, | |||||||||||||||||||||||||||||||||||||||||
| 52 | required => [qw( id endpoint_ref )], | ||||||||||||||||||||||||||||||||||||||||||
| 53 | optional => [qw( capabilities )], | ||||||||||||||||||||||||||||||||||||||||||
| 54 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | return $class->new( | ||||||||||||||||||||||||||||||||||||||||||
| 56 | id => $class->_string( 'id', $data->{id} ), | ||||||||||||||||||||||||||||||||||||||||||
| 57 | endpoint_ref => $class->_string( 'endpoint_ref', $data->{endpoint_ref} ), | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 73 | ▶ | ( exists $data->{capabilities} ? ( capabilities => $data->{capabilities} ) : () ), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 58 | ▶ | sub to_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 58 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 58 | my $caps = $self->capabilities; | |||||||||||||||||||||||||||||||||||||||||
| 66 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | id => $self->id, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | endpoint_ref => $self->endpoint_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | capabilities => { | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 58 | ▶ | map { $_ => ( $caps->{$_} ? JSON::MaybeXS::true() : JSON::MaybeXS::false() ) } keys %$caps | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub TO_JSON { shift->to_hash } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | Langertha::Manifest::Model - One model entry of a provider manifest: id, endpoint, declared capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | version 0.503 | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | my $model = Langertha::Manifest::Model->new( | ||||||||||||||||||||||||||||||||||||||||||
| 100 | id => 'gpt-5.6', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | endpoint_ref => 'chat', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | capabilities => { chat => 1, streaming => 1, tools_native => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 103 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | $model->supports('tools_native'); # 1 | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | A model entry of a L<Langertha::Manifest>. The same model id may appear | ||||||||||||||||||||||||||||||||||||||||||
| 110 | once per endpoint (a proxy serves one model on several protocol endpoints), | ||||||||||||||||||||||||||||||||||||||||||
| 111 | so C<(id, endpoint_ref)> is the uniqueness key. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | C<capabilities> are what the B<provider claims>, in the | ||||||||||||||||||||||||||||||||||||||||||
| 114 | L<Langertha::Role::Capabilities> vocabulary (C<engine_capabilities> names). | ||||||||||||||||||||||||||||||||||||||||||
| 115 | A claim is not a probe result and not a local permission. | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | =head2 id | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | The model id as the endpoint expects it (free-form, e.g. C<org/model:tag>); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | non-empty, no control characters, at most 256 characters. | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | =head2 endpoint_ref | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | Id of the L<Langertha::Manifest::Endpoint> serving this model. | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | =head2 capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | HashRef of capability name to C<1>/C<0>. Names match C<[a-z][a-z0-9_]*>; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | input values may be JSON booleans, C<\1>/C<\0> or the numbers C<1>/C<0> | ||||||||||||||||||||||||||||||||||||||||||
| 130 | and are normalized to C<1>/C<0>; strings (C<"1">, C<"true">) are rejected. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | Names are open: a client treats a capability it does not know as absent. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | =head2 supports | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | $model->supports('streaming'); | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | True when the manifest claims the capability for this model. Accepts any | ||||||||||||||||||||||||||||||||||||||||||
| 138 | name; an unknown or absent capability is simply not supported. | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =head2 from_hash | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | Builds a model entry from its JSON object form, rejecting unknown and | ||||||||||||||||||||||||||||||||||||||||||
| 143 | forbidden fields. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head2 to_hash | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Returns the JSON object form; capability values are JSON booleans. | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =item * L<Langertha::Manifest> - The provider manifest | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | =item * L<Langertha::Role::Capabilities> - The capability vocabulary | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | =head2 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||||||||||
| 164 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head2 IRC | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 183 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | =cut | ||||||||||||||||||||||||||||||||||||||||||