| 1 | package Langertha::Knarr::CLI::Cmd::Check; | ||||||||||||||||||||||||||||
| 2 | 39 | our $VERSION = '1.103'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Validate Knarr configuration file | ||||||||||||||||||||||||||||
| 4 | 39 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 39 | with 'Langertha::Knarr::CLI::Role::GlobalOptions'; | |||||||||||||||||||||||||||
| 6 | 39 | ▶ | use MooX::Cmd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 39 | ▶ | use MooX::Options protect_argv => 0, usage_string => 'USAGE: knarr check [options]'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: called CC=24 SCAR=49.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 2 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||
| 12 | 2 | my $config_file = $self->config_file($chain); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | unless (-f $config_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 0 | print STDERR "Config file not found: $config_file\n"; | |||||||||||||||||||||||||||
| 16 | 0 | exit 1; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | require Langertha::Knarr::Config; | |||||||||||||||||||||||||||
| 20 | 2 | my $config = eval { Langertha::Knarr::Config->new(file => $config_file) }; | |||||||||||||||||||||||||||
| 21 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | print STDERR "Failed to parse config: $@\n"; | |||||||||||||||||||||||||||
| 23 | 0 | exit 1; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2 | my @errors = $config->validate; | |||||||||||||||||||||||||||
| 27 | 2 | ▶ | if (@errors) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 1 | print "Configuration INVALID:\n"; | |||||||||||||||||||||||||||
| 29 | 1 | print " - $_\n" for @errors; | |||||||||||||||||||||||||||
| 30 | 1 | exit 1; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if ( $config->token_auth ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | # The stack builds the token store, which needs DBD::Pg; nothing connects. | ||||||||||||||||||||||||||||
| 35 | 0 | require Langertha::Knarr::Stack; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | unless ( eval { Langertha::Knarr::Stack->new( config => $config )->build; 1 } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ( my $err = $@ ) =~ s/ at \S+ line \d+\.?\n?\z//; | |||||||||||||||||||||||||||
| 38 | 0 | print "Configuration INVALID:\n - $err\n"; | |||||||||||||||||||||||||||
| 39 | 0 | exit 1; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | print "Configuration OK\n"; | |||||||||||||||||||||||||||
| 42 | 0 | print " File: $config_file\n"; | |||||||||||||||||||||||||||
| 43 | 0 | print " Listen: ", join(', ', @{$config->listen}), "\n"; | |||||||||||||||||||||||||||
| 44 | print " Token auth: ", $config->token_auth->{backend}, | ||||||||||||||||||||||||||||
| 45 | 0 | " (routes: ", join(', ', sort keys %{ $config->routes }), ")\n"; | |||||||||||||||||||||||||||
| 46 | 0 | print " Models: from the tokens (no static list)\n"; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | print " Admin routes: ", ($config->has_admin_key ? 'enabled' : 'disabled'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | my $lf = $config->langfuse; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $lf_pub = $lf->{public_key} // $ENV{LANGFUSE_PUBLIC_KEY}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$lf->{"public_key"} // $ENV{"LANGFUSE_PUBLIC_KEY"}
MC/DC0%0/2
$lf->{"public_key"} // $ENV{"LANGFUSE_PUBLIC_KEY"}
$lf->{"public_key"}
$ENV{"LANGFUSE_PUBLIC_KEY"}
Truth table0%0/3
A // B
A= $lf->{"public_key"}B= $ENV{"LANGFUSE_PUBLIC_KEY"}
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $lf_sec = $lf->{secret_key} // $ENV{LANGFUSE_SECRET_KEY}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$lf->{"secret_key"} // $ENV{"LANGFUSE_SECRET_KEY"}
MC/DC0%0/2
$lf->{"secret_key"} // $ENV{"LANGFUSE_SECRET_KEY"}
$lf->{"secret_key"}
$ENV{"LANGFUSE_SECRET_KEY"}
Truth table0%0/3
A // B
A= $lf->{"secret_key"}B= $ENV{"LANGFUSE_SECRET_KEY"}
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | print " Langfuse: ", ( $lf_pub && $lf_sec ? 'enabled' : 'disabled' ), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$lf_pub and $lf_sec
MC/DC0%0/2
$lf_pub and $lf_sec
$lf_pub
$lf_sec
Truth table0%0/3
A and B
A= $lf_pubB= $lf_sec
| |||||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | my $models = $config->models; | |||||||||||||||||||||||||||
| 56 | 1 | my $model_count = scalar keys %$models; | |||||||||||||||||||||||||||
| 57 | 1 | print "Configuration OK\n"; | |||||||||||||||||||||||||||
| 58 | 1 | print " File: $config_file\n"; | |||||||||||||||||||||||||||
| 59 | 1 | print " Listen: ", join(', ', @{$config->listen}), "\n"; | |||||||||||||||||||||||||||
| 60 | 1 | print " Models: $model_count configured\n"; | |||||||||||||||||||||||||||
| 61 | 1 | ▶ | print " Default engine: ", ($config->default_engine ? $config->default_engine->{engine} : 'none'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | print " Auto-discover: ", ($config->auto_discover ? 'enabled' : 'disabled'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | print " Proxy auth: ", ($config->has_proxy_api_key && $config->proxy_api_key ? 'enabled' : 'disabled'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$config->has_proxy_api_key and $config->proxy_api_key
MC/DC0%0/2
$config->has_proxy_api_key and $config->proxy_api_key
$config->has_proxy_api_key
$config->proxy_api_key
Truth table33%1/3
A and B
A= $config->has_proxy_api_keyB= $config->proxy_api_key
| |||||||||||||||||||||||||||||
| 64 | # Whether, never which key (k75) | ||||||||||||||||||||||||||||
| 65 | 1 | ▶ | print " Admin routes: ", ($config->has_admin_key ? 'enabled' : 'disabled'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 1 | ▶ | print " Remote config: ", ($config->remote_config ? 'yes (a setup may arrive by PUT /knarr/admin/config)' : 'no'), "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Check Langfuse | ||||||||||||||||||||||||||||
| 69 | 1 | my $lf = $config->langfuse; | |||||||||||||||||||||||||||
| 70 | 1 | ▶ | my $lf_pub = $lf->{public_key} // $ENV{LANGFUSE_PUBLIC_KEY}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$lf->{"public_key"} // $ENV{"LANGFUSE_PUBLIC_KEY"}
MC/DC0%0/2
$lf->{"public_key"} // $ENV{"LANGFUSE_PUBLIC_KEY"}
$lf->{"public_key"}
$ENV{"LANGFUSE_PUBLIC_KEY"}
Truth table33%1/3
A // B
A= $lf->{"public_key"}B= $ENV{"LANGFUSE_PUBLIC_KEY"}
| |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | my $lf_sec = $lf->{secret_key} // $ENV{LANGFUSE_SECRET_KEY}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$lf->{"secret_key"} // $ENV{"LANGFUSE_SECRET_KEY"}
MC/DC0%0/2
$lf->{"secret_key"} // $ENV{"LANGFUSE_SECRET_KEY"}
$lf->{"secret_key"}
$ENV{"LANGFUSE_SECRET_KEY"}
Truth table33%1/3
A // B
A= $lf->{"secret_key"}B= $ENV{"LANGFUSE_SECRET_KEY"}
| |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | if ($lf_pub && $lf_sec) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$lf_pub and $lf_sec
MC/DC0%0/2
$lf_pub and $lf_sec
$lf_pub
$lf_sec
Truth table33%1/3
A and B
A= $lf_pubB= $lf_sec
| |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | print " Langfuse: enabled (", ($lf->{url} // $ENV{LANGFUSE_URL} // 'cloud.langfuse.com'), | ||||||||||||||||||||||||||
|
Condition0%0/5
($lf->{"url"} // $ENV{"LANGFUSE_URL"}) // "cloud.langfuse.com"
$lf->{"url"} // $ENV{"LANGFUSE_URL"}
MC/DC0%0/2
($lf->{"url"} // $ENV{"LANGFUSE_URL"}) // "cloud.langfuse.com"
$lf->{"url"}
$ENV{"LANGFUSE_URL"}
Truth table0%0/3
A // B
A= $lf->{"url"}B= $ENV{"LANGFUSE_URL"}
| |||||||||||||||||||||||||||||
| 74 | ", ", $config->langfuse_transport, ")\n"; | ||||||||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||||||||
| 76 | 1 | print " Langfuse: disabled (set LANGFUSE_PUBLIC_KEY + LANGFUSE_SECRET_KEY to enable)\n"; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 39 | 1; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | __END__ | ||||||||||||||||||||||||||||