| 1 | package Langertha::Input::Tools; | ||||||||||||||||||||||
| 2 | 3 | our $VERSION = '0.502'; | |||||||||||||||||||||
| 3 | # ABSTRACT: Backwards-compat facade over Langertha::Tool / Langertha::ToolChoice | ||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp (); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 3 | ▶ | use Langertha::Tool; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 3 | ▶ | use Langertha::ToolChoice; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 3 | Carp::carp( | |||||||||||||||||||||
| 11 | "Langertha::Input::Tools is a backwards-compatibility facade. New code should use " | ||||||||||||||||||||||
| 12 | . "Langertha::Tool / Langertha::ToolChoice directly." | ||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | # All methods here are kept for backwards compatibility with Skeid/Knarr | ||||||||||||||||||||||
| 16 | # and other existing consumers. New code should use Langertha::Tool and | ||||||||||||||||||||||
| 17 | # Langertha::ToolChoice directly. | ||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | sub normalize_tools { | ||||||||||||||||||||||
| 20 | 2 | ▶ | my ($class, $tools) = @_; | ||||||||||||||||||||
|
Subroutine
normalize_tools: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 21 | 2 | return [ map { $_->to_hash } @{ Langertha::Tool->from_list($tools) } ]; | |||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | sub to_openai_tools { | ||||||||||||||||||||||
| 25 | 2 | ▶ | my ($class, $canonical_tools) = @_; | ||||||||||||||||||||
|
Subroutine
to_openai_tools: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||
| 26 | 2 | my @out; | |||||||||||||||||||||
| 27 | 2 | ▶ | for my $hash ( @{ $canonical_tools || [] } ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 28 | 4 | ▶ | next unless ref($hash) eq 'HASH'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 29 | 4 | ▶ | my $name = $hash->{name} // 'tool'; | ||||||||||||||||||||
|
Condition50%1/2
$$hash{"name"} // "tool"
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
| |||||||||||||||||||||||
| 30 | push @out, Langertha::Tool->new( | ||||||||||||||||||||||
| 31 | name => $name, | ||||||||||||||||||||||
| 32 | description => ( $hash->{description} // '' ), | ||||||||||||||||||||||
| 33 | 4 | ▶ | input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ), | ||||||||||||||||||||
|
Condition50%2/4
$$hash{"description"} // ""
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Truth table50%1/2
A
A= $$hash{'input_schema'}
| |||||||||||||||||||||||
| 34 | )->to_openai; | ||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||
| 36 | 2 | return \@out; | |||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | sub to_anthropic_tools { | ||||||||||||||||||||||
| 40 | 2 | ▶ | my ($class, $canonical_tools) = @_; | ||||||||||||||||||||
|
Subroutine
to_anthropic_tools: called CC=7 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||
| 41 | 2 | my @out; | |||||||||||||||||||||
| 42 | 2 | ▶ | for my $hash ( @{ $canonical_tools || [] } ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 43 | 4 | ▶ | next unless ref($hash) eq 'HASH'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 44 | 4 | ▶ | my $name = $hash->{name} // 'tool'; | ||||||||||||||||||||
|
Condition50%1/2
$$hash{"name"} // "tool"
MC/DC0%0/1
$$hash{"name"} // "tool"
$$hash{"name"}
Truth table50%1/2
A
A= $$hash{"name"}
| |||||||||||||||||||||||
| 45 | push @out, Langertha::Tool->new( | ||||||||||||||||||||||
| 46 | name => $name, | ||||||||||||||||||||||
| 47 | description => ( $hash->{description} // '' ), | ||||||||||||||||||||||
| 48 | 4 | ▶ | input_schema => ( $hash->{input_schema} || { type => 'object', properties => {} } ), | ||||||||||||||||||||
|
Condition50%2/4
$$hash{"description"} // ""
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
MC/DC0%0/1
$$hash{"description"} // ""
$$hash{"description"}
MC/DC0%0/1
$$hash{'input_schema'} || {'type', 'object', 'properties', {}}
$$hash{'input_schema'}
Truth table50%1/2
A
A= $$hash{"description"}
Truth table50%1/2
A
A= $$hash{'input_schema'}
| |||||||||||||||||||||||
| 49 | )->to_anthropic; | ||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||
| 51 | 2 | return \@out; | |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | sub normalize_tool_choice { | ||||||||||||||||||||||
| 55 | 2 | ▶ | my ($class, $tool_choice) = @_; | ||||||||||||||||||||
|
Subroutine
normalize_tool_choice: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||
| 56 | 2 | my $tc = Langertha::ToolChoice->from_hash($tool_choice); | |||||||||||||||||||||
| 57 | 2 | ▶ | return $tc ? $tc->to_hash : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | sub to_openai_tool_choice { | ||||||||||||||||||||||
| 61 | 1 | ▶ | my ($class, $canonical_tool_choice) = @_; | ||||||||||||||||||||
|
Subroutine
to_openai_tool_choice: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||
| 62 | 1 | ▶ | return undef unless ref($canonical_tool_choice) eq 'HASH'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | 1 | my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice); | |||||||||||||||||||||
| 64 | 1 | ▶ | return $tc ? $tc->to_openai : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | sub to_anthropic_tool_choice { | ||||||||||||||||||||||
| 68 | 1 | ▶ | my ($class, $canonical_tool_choice) = @_; | ||||||||||||||||||||
|
Subroutine
to_anthropic_tool_choice: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||
| 69 | 1 | ▶ | return undef unless ref($canonical_tool_choice) eq 'HASH'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 70 | 1 | my $tc = Langertha::ToolChoice->from_hash($canonical_tool_choice); | |||||||||||||||||||||
| 71 | 1 | ▶ | return $tc ? $tc->to_anthropic : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 3 | 1; | |||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | =pod | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | =encoding UTF-8 | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | =head1 NAME | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | Langertha::Input::Tools - Backwards-compat facade over Langertha::Tool / Langertha::ToolChoice | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | =head1 VERSION | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | version 0.502 | ||||||||||||||||||||||
| 89 | |||||||||||||||||||||||
| 90 | =head1 SUPPORT | ||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | =head2 Issues | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||
| 95 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | =head2 IRC | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | =head1 CONTRIBUTING | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||
| 104 | |||||||||||||||||||||||
| 105 | =head1 AUTHOR | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||
| 114 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||
| 115 | |||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||