| 1 | package Langertha::Role::Capabilities; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Engine-capability registry derived from composed roles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 195 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 195 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 195 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 195 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 195 | ▶ | use Future::AsyncAwait; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 195 | ▶ | use Langertha::ModelProbe; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 195 | ▶ | use Langertha::ToolResult; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Role-name => list of capability flag names that role contributes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # Plus implicit: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # chat -> simple_chat works (Role::Chat is composed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # streaming -> chat_stream_request is wired up (Role::Streaming) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # tools_native -> Role::Tools (the named flags below come too) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # tools_hermes -> Role::HermesTools | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # ... see %ROLE_TO_CAPS below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Every Langertha::Role::* is on one of two axes (ADR 0016 decision 2): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # a capability (an entry here) or envelope/infrastructure (the allowlist | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # in t/78_capability_registry.t). That guard fails on a role in neither, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # so a new role cannot quietly skip the decision. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 195 | my %ROLE_TO_CAPS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'Langertha::Role::Chat' => [qw( chat )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 'Langertha::Role::Streaming' => [qw( streaming )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 'Langertha::Role::Tools' => [qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | tools_native tool_choice_auto tool_choice_any tool_choice_none tool_choice_named | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'Langertha::Role::HermesTools' => [qw( tools_hermes )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 'Langertha::Role::ResponseFormat' => [qw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | response_format_json_object response_format_json_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'Langertha::Role::Embedding' => [qw( embedding )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 'Langertha::Role::Transcription' => [qw( transcription )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 'Langertha::Role::ImageGeneration' => [qw( image_generation )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'Langertha::Role::Temperature' => [qw( temperature )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 'Langertha::Role::ReasoningEffort' => [qw( reasoning_effort )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 'Langertha::Role::PromptCache' => [qw( prompt_cache prompt_cache_key )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'Langertha::Role::CachedContent' => [qw( cached_content )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'Langertha::Role::Seed' => [qw( seed )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 'Langertha::Role::ContextSize' => [qw( context_size )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 'Langertha::Role::ResponseSize' => [qw( response_size )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'Langertha::Role::SystemPrompt' => [qw( system_prompt )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'Langertha::Role::KeepAlive' => [qw( keep_alive )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'Langertha::Role::ParallelToolUse' => [qw( parallel_tool_use )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 'Langertha::Role::Runtime::MetricsPoll' => [qw( runtime_metrics )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'Langertha::Role::RuntimeKnobs' => [qw( prefix_caching )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'Langertha::Role::ServerTools' => [qw( server_tools )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'Langertha::Role::ImageInput' => [qw( image_input )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'Langertha::Role::StreamUsage' => [qw( stream_usage )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 'Langertha::Role::ToolResultImages' => [qw( tool_result_images )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 'Langertha::Role::ToolResultPDF' => [qw( tool_result_pdf )], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 10061 | ▶ | sub engine_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine_capabilities: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine_capabilities: not called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my %caps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | for my $role ( keys %ROLE_TO_CAPS ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | next unless $self->does($role); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $caps{$_} = 1 for @{ $ROLE_TO_CAPS{$role} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Layer 3 (ADR 0002 amendment, ADR 0019): per-model refinement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # The tool / structured-output wire reality is often per-MODEL, not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # per-engine (kimi-k3 forbids a forced named tool while its K2.x siblings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # allow it; deepseek-reasoner clamps differ from deepseek-chat). Engines | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # declare a model-id/pattern -> {cap => 0|1} table in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # model_capability_corrections; it refines the role-derived base for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # currently selected chat_model. Engine-WIDE corrections stay in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # `around engine_capabilities` (the outer endpoint-reality gate, layer 2). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # The wire set (layer 1) before any model-scoped refinement: a learned fact | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # can re-assert only a flag the composed roles grant (ADR 0032). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my %wire = %caps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $self->_apply_model_capability_corrections(\%caps); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # Learned layer (ADR 0032): facts the engine read from the provider's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # model metadata (probe_model_capabilities_f), for this chat_model. They | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # run after the static per-model table, so for a model the probe reported, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # the provider's statement beats the static default in both directions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Empty until the caller probes: supports() never does network I/O. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->_apply_learned_model_capabilities( \%caps, \%wire ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # Last, so a probed image_input flows through (ADR 0039). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->_apply_tool_result_media_dependencies( \%caps ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | return \%caps; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Tool-result media (ADR 0039, karr k380): tool_result_images and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # tool_result_pdf describe what format_tool_results sends, so they hold only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # where the serializer can, on the engine's CURRENT tool_wire_format (a forced | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # wire included): the wire must have a native tool-result form for the kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # (ToolResult->carries_native), and where that form reaches only a model that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # sees images -- an image everywhere, a PDF on responses / gemini, not on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # anthropic (k371) -- the model must claim image_input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # (ToolResult->native_needs_vision). Engine-specific gates (Gemini 3 and later, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # the anthropic source blocks, AKIAnthropic) stay with the engines. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 195 | my %TOOL_RESULT_MEDIA_CAP = ( image => 'tool_result_images', pdf => 'tool_result_pdf' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 10061 | ▶ | sub _apply_tool_result_media_dependencies { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_tool_result_media_dependencies: called CC=6 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ( $self, $caps ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_tool_result_media_dependencies: not called CC=6 SCAR=23.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my @kinds = grep { $caps->{ $TOOL_RESULT_MEDIA_CAP{$_} } } sort keys %TOOL_RESULT_MEDIA_CAP; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | return unless @kinds; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $fmt = $self->_capability_tool_wire_format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | for my $kind (@kinds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | my $keep = Langertha::ToolResult->carries_native( $fmt, $kind ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | && ( $caps->{image_input} || !Langertha::ToolResult->native_needs_vision( $fmt, $kind ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%6/12
'Langertha::ToolResult'->carries_native($fmt, $kind) && ($caps->{'image_input'} || !'Langertha::ToolResult'->native_needs_vision($fmt, $kind))
$caps->{"image_input"} or not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
'Langertha::ToolResult'->carries_native($fmt, $kind) && ($$caps{'image_input'} || !'Langertha::ToolResult'->native_needs_vision($fmt, $kind))
$$caps{"image_input"} or not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
MC/DC100%3/3
'Langertha::ToolResult'->carries_native($fmt, $kind) && ($caps->{'image_input'} || !'Langertha::ToolResult'->native_needs_vision($fmt, $kind))
'Langertha::ToolResult'->carries_native($fmt, $kind)
$caps->{"image_input"}
not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
MC/DC0%0/3
'Langertha::ToolResult'->carries_native($fmt, $kind) && ($$caps{'image_input'} || !'Langertha::ToolResult'->native_needs_vision($fmt, $kind))
'Langertha::ToolResult'->carries_native($fmt, $kind)
$$caps{"image_input"}
not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
Truth table100%4/4
A && B or not(C)
A= 'Langertha::ToolResult'->carries_native($fmt, $kind)B= $caps->{"image_input"}C= not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
Truth table0%0/4
A && B or not(C)
A= 'Langertha::ToolResult'->carries_native($fmt, $kind)B= $$caps{"image_input"}C= not "Langertha::ToolResult"->native_needs_vision($fmt, $kind)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | delete $caps->{ $TOOL_RESULT_MEDIA_CAP{$kind} } unless $keep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # The engine's tool_wire_format, or undef when it has none or its builder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # croaks; like _capability_model, supports() leaves no croak in $@. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3049 | ▶ | sub _capability_tool_wire_format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capability_tool_wire_format: called CC=3 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ( $self ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capability_tool_wire_format: not called CC=3 SCAR=14.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | return undef unless $self->can('tool_wire_format'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $fmt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $ok = eval { $fmt = $self->tool_wire_format; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | return $ok ? $fmt : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # Default: no per-model corrections. Engines override with a declarative, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # ordered list of ( $matcher => \%overrides ) pairs — see the =method below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 2357 | ▶ | sub model_capability_corrections { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 10061 | ▶ | sub _apply_model_capability_corrections { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_model_capability_corrections: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 10061 | my ( $self, $caps ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 10061 | my @corrections = $self->model_capability_corrections; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 10061 | ▶ | return unless @corrections; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # chat_model is the model that actually carries tools / tool_choice / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # response_format on the wire (Role::Chat); guard for the rare consumer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # of engine_capabilities that has no model surface at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # An empty or undef chat_model is matched as '' rather than skipped, so a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # default-deny catch-all row (qr/\A/, Engine::MiniMax, ADR 0019 k209 Update) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # holds even for model => ''; every family row needs a real id to match. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 7700 | ▶ | return unless $self->can('chat_model'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 7700 | ▶ | my $model = $self->_capability_model // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_capability_model // ""
MC/DC100%1/1
$self->_capability_model // ""
$self->_capability_model
Truth table100%2/2
A
A= $self->_capability_model
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 7700 | ▶ | while ( @corrections >= 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 42639 | my ( $matcher, $overrides ) = splice @corrections, 0, 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 42639 | ▶ | my $hit = ref $matcher eq 'Regexp' ? ( $model =~ $matcher ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | : ( $model eq $matcher ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 42639 | ▶ | next unless $hit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Later matching entries win on a shared flag. A true value asserts the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # capability, a false value clears it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 9013 | for my $cap ( keys %$overrides ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 11684 | ▶ | if ( $overrides->{$cap} ) { $caps->{$cap} = 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 8929 | else { delete $caps->{$cap} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 7700 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | # The model the capability picture is evaluated for. An engine without a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # default model (OpenRouter, OllamaOpenAI, Groq) croaks when chat_model is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # built with no model configured. For the capability picture that means "no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # model", which the table walk matches as '' (ADR 0019 k209 rule), not an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # error of supports() (ADR 0032). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 7856 | ▶ | sub _capability_model { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capability_model: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 7856 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 7856 | ▶ | return undef unless $self->can('chat_model'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7856 | my $model; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # supports() must not leave the chat_model croak behind in the caller's $@. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 7856 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 7856 | my $ok = eval { $model = $self->chat_model; 1 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 7856 | ▶ | return $ok ? $model : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | has _learned_model_capabilities => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | isa => 'HashRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 4456 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 195 | writer => '_set_learned_model_capabilities', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 10061 | ▶ | sub _apply_learned_model_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_apply_learned_model_capabilities: called CC=11 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 10061 | my ( $self, $caps, $wire ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 10061 | my $learned = $self->_learned_model_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 10061 | ▶ | return unless %$learned; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 65 | my $model = $self->_capability_model; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 65 | ▶ | return unless defined $model && !ref $model && length $model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $model and not ref $model and length $model
defined $model and not ref $model
MC/DC0%0/3
defined $model and not ref $model and length $model
defined $model
not ref $model
length $model
Truth table25%1/4
A and not(B) and C
A= defined $modelB= not ref $modelC= length $model
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Exact id first, then the format's equivalent spellings (Ollama's implicit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # :latest tag, OpenRouter's :variant suffixes), see ModelProbe->lookup_ids. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 65 | my $format = $self->model_metadata_format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 65 | ▶ | my @ids = defined $format && Langertha::ModelProbe->is_known_format($format) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $format and "Langertha::ModelProbe"->is_known_format($format)
MC/DC0%0/2
defined $format and "Langertha::ModelProbe"->is_known_format($format)
defined $format
"Langertha::ModelProbe"->is_known_format($format)
Truth table33%1/3
A and B
A= defined $formatB= "Langertha::ModelProbe"->is_known_format($format)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ? Langertha::ModelProbe->lookup_ids( $format, $model ) : ( $model ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 65 | my ($facts) = grep { ref $_ eq 'HASH' } map { $learned->{$_} } @ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 65 | ▶ | return unless $facts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 60 | for my $cap ( keys %$facts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 60 | ▶ | if ( $facts->{$cap} ) { $caps->{$cap} = 1 if $wire->{$cap} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 15 | else { delete $caps->{$cap} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 60 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 88 | ▶ | sub learned_model_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
learned_model_capabilities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 88 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 88 | my $learned = $self->_learned_model_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 88 | return { map { $_ => { %{ $learned->{$_} } } } keys %$learned }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | ▶ | sub clear_learned_model_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_learned_model_capabilities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $self->_set_learned_model_capabilities( {} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # Engine hooks (ADR 0032). An engine that can read its provider's model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # metadata names the document format (a Langertha::ModelProbe tag) and its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # URL. The default is no probe: probe_model_capabilities_f resolves to {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # without a request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 5 | ▶ | sub model_metadata_format { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_metadata_format: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | sub model_metadata_url { return undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_metadata_url: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 65 | ▶ | async sub probe_model_capabilities_f { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_model_capabilities_f: called CC=28 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 65 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 65 | my $format = $self->model_metadata_format; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 65 | ▶ | return {} unless defined $format; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 62 | my $url = $self->model_metadata_url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 62 | ▶ | croak ref($self) . ": model_metadata_format '$format' without a model_metadata_url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $url and length $url
MC/DC0%0/2
defined $url and length $url
defined $url
length $url
Truth table33%1/3
A and B
A= defined $urlB= length $url
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | unless defined $url && length $url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 62 | my @models; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 62 | ▶ | if ( exists $args{models} && !ref $args{models} && ( $args{models} // '' ) eq 'all' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition87%7/8
exists $args{"models"} and not ref $args{"models"} and ($args{"models"} // "") eq "all"
exists $args{"models"} and not ref $args{"models"}
$args{"models"} // ""
MC/DC66%2/3
exists $args{"models"} and not ref $args{"models"} and ($args{"models"} // "") eq "all"
exists $args{"models"}
not ref $args{"models"}
$args{"models"}
Truth table75%3/4
A and not(B) and C
A= exists $args{"models"}B= not ref $args{"models"}C= $args{"models"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # The whole catalogue (k282): only a document that names its models can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # answer "every model"; the others need ids to key their fact by. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 7 | ▶ | croak ref($self) . ": probe_model_capabilities_f models => 'all' needs a catalogue" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | . " document; model_metadata_format '$format' does not name its models" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | unless Langertha::ModelProbe->is_catalogue($format); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | elsif ( exists $args{models} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | croak ref($self) . q{: probe_model_capabilities_f models must be an ArrayRef or 'all'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 16 | ▶ | unless ref $args{models} eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 15 | ▶ | @models = grep { defined && !ref && length } @{ $args{models} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
defined $_ && !ref($_) && length $_
defined $_ and not ref $_
MC/DC100%3/3
defined $_ && !ref($_) && length $_
defined $_
not ref $_
length $_
Truth table100%4/4
A and not(B) && C
A= defined $_B= not ref $_C= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 39 | my $model = $self->_capability_model; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 39 | ▶ | @models = ( $model ) if defined $model && !ref $model && length $model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $model and not ref $model and length $model
defined $model and not ref $model
MC/DC33%1/3
defined $model and not ref $model and length $model
defined $model
not ref $model
length $model
Truth table50%2/4
A and not(B) and C
A= defined $modelB= not ref $modelC= length $model
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 59 | my $probe = 'Langertha::ModelProbe'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 59 | my $method = $probe->http_method($format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 59 | my $per_model = $probe->per_model($format); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # A per-model document (Ollama /api/show) takes one request per model and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # needs a model; a server-wide document is one request whatever was asked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 59 | ▶ | my @batches = $per_model ? ( map { [ $_ ] } @models ) : ( [ @models ] ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 59 | my %allowed = map { $_ => 1 } $probe->probed_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 59 | my %learned; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 59 | for my $batch (@batches) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | my $request = $self->generate_http_request( $method, $url, sub { $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 65 | ▶ | $per_model ? ( model => $batch->[0] ) : () ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 65 | my $response = await $self->_async_do_request_f( request => $request ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | # A per-model document that does not know the model (Ollama /api/show | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # answers 404 "model not found") gives no fact for that model; the other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # models of the call are still learned. Every other failure fails loud. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 65 | ▶ | next if $per_model && $response->code == 404; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$per_model and $response->code == 404
MC/DC100%2/2
$per_model and $response->code == 404
$per_model
$response->code == 404
Truth table100%3/3
A and B
A= $per_modelB= $response->code == 404
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 64 | ▶ | unless ( $response->is_success ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | my $body = $self->can('_error_response_body') ? $self->_error_response_body($response) : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | ▶ | croak ref($self) . ' model metadata probe failed: ' . $response->status_line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | . ( length $body ? " - $body" : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 60 | my $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 60 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | croak ref($self) . ' model metadata probe: response from ' . $request->uri->path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | . ' is not JSON' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 60 | ▶ | unless eval { $data = $self->json->decode( $response->content ); 1 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 59 | my $facts = $probe->extract( $format, $data, $batch ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 59 | for my $model ( grep { length } keys %$facts ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 102 | for my $cap ( grep { $allowed{$_} } keys %{ $facts->{$model} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 102 | ▶ | $learned{$model}{$cap} = $facts->{$model}{$cap} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 54 | $self->_merge_learned_model_capabilities( \%learned ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 54 | return \%learned; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 195 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | # Merge facts into the store; a later fact for the same model and capability | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # wins. A new HashRef, never a mutation in place: clone_object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # (Manifest::Builder) shares the slot, and a clone that probes or imports must | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # not write into its source. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 71 | ▶ | sub _merge_learned_model_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_learned_model_capabilities: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 71 | my ( $self, $learned ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 71 | my $current = $self->learned_model_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 71 | for my $model ( keys %$learned ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 132 | ▶ | $current->{$model} = { %{ $current->{$model} // {} }, %{ $learned->{$model} } }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$current->{$model} // {}
MC/DC100%1/1
$current->{$model} // {}
$current->{$model}
Truth table100%2/2
A
A= $current->{$model}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 71 | $self->_set_learned_model_capabilities($current); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 71 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 33 | ▶ | sub _is_fact_value { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_fact_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 33 | my ( $value ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 33 | ▶ | return 0 unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 32 | ▶ | return 1 unless ref $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | return blessed($value) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 20 | ▶ | sub import_learned_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import_learned_capabilities: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 20 | my ( $self, $map ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 20 | ▶ | croak ref($self) . ': import_learned_capabilities needs a HashRef of { $model_id => { $capability => 0|1 } }' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | unless ref $map eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 17 | my %allowed = map { $_ => 1 } Langertha::ModelProbe->probed_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 17 | my %import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 17 | for my $model ( keys %$map ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # Hash keys are always strings; an empty key is never a model id. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 35 | ▶ | next unless length $model && ref $map->{$model} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $model and ref $map->{$model} eq "HASH"
MC/DC100%2/2
length $model and ref $map->{$model} eq "HASH"
length $model
ref $map->{$model} eq "HASH"
Truth table100%3/3
A and B
A= length $modelB= ref $map->{$model} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 33 | my $facts = $map->{$model}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # A fact is a defined plain scalar or a JSON boolean (a map that went | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # through a JSON store); undef or an unblessed reference is no fact. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 33 | ▶ | for my $cap ( grep { $allowed{$_} && _is_fact_value( $facts->{$_} ) } keys %$facts ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$allowed{$_} && _is_fact_value($facts->{$_})
MC/DC100%2/2
$allowed{$_} && _is_fact_value($facts->{$_})
$allowed{$_}
_is_fact_value($facts->{$_})
Truth table100%3/3
A && B
A= $allowed{$_}B= _is_fact_value($facts->{$_})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 31 | ▶ | $import{$model}{$cap} = $facts->{$cap} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 17 | $self->_merge_learned_model_capabilities( \%import ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 17 | return \%import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 59 | ▶ | sub probe_model_capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probe_model_capabilities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 59 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # ->get drives the loop the pending future belongs to, or returns at once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # on the synchronous fallback (ADR 0027), as poll_metrics does. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 59 | return $self->probe_model_capabilities_f(%args)->get; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 9578 | ▶ | sub supports { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supports: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 9578 | my ( $self, $cap ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 9578 | return !!$self->engine_capabilities->{$cap}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 195 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||