| 1 | package Langertha::Engine::LMStudioAnthropic; | ||||||||||||
| 2 | # ABSTRACT: LM Studio via Anthropic-compatible API | ||||||||||||
| 3 | 14 | our $VERSION = '0.505'; | |||||||||||
| 4 | 14 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 14 | extends 'Langertha::Engine::AnthropicBase'; | |||||||||||
| 7 | |||||||||||||
| 8 | |||||||||||||
| 9 | has '+url' => ( | ||||||||||||
| 10 | lazy => 1, | ||||||||||||
| 11 | 1 | ▶ | default => sub { 'http://localhost:1234' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 14 | ); | |||||||||||
| 13 | |||||||||||||
| 14 | 8 | ▶ | sub _build_api_key { | ||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=6.9
| |||||||||||||
| 15 | 8 | ▶ | return $ENV{LANGERTHA_LMSTUDIO_API_KEY} || 'lmstudio'; | ||||||||||
|
Condition100%2/2
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'} || 'lmstudio'
MC/DC100%1/1
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'} || 'lmstudio'
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'}
Truth table100%2/2
A
A= $ENV{'LANGERTHA_LMSTUDIO_API_KEY'}
| |||||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | |||||||||||||
| 19 | 15 | ▶ | sub default_model { 'default' } | ||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 20 | |||||||||||||
| 21 | # Shares the LM Studio key with the native engine (derivation would name the | ||||||||||||
| 22 | # protocol variant); optional, the local server accepts the 'lmstudio' dummy. | ||||||||||||
| 23 | 1 | ▶ | sub api_key_env { 'LANGERTHA_LMSTUDIO_API_KEY' } | ||||||||||
|
Subroutine
api_key_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 24 | 1 | ▶ | sub api_key_required { 0 } | ||||||||||
|
Subroutine
api_key_required: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 25 | |||||||||||||
| 26 | # image_input (k266, ADR 0019): self-hosted: the served model is launch state | ||||||||||||
| 27 | # the client cannot see, so no static claim. A layer-3 catch-all rather than a | ||||||||||||
| 28 | # layer-2 delete, so a fact probed from the server's native /api/v1/models | ||||||||||||
| 29 | # (capabilities.vision) can answer per model (ADR 0032), as on the other two | ||||||||||||
| 30 | # LM Studio faces. | ||||||||||||
| 31 | 156 | ▶ | sub model_capability_corrections { | ||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 32 | 156 | return ( qr/\A/ => { image_input => 0 } ); | |||||||||||
| 33 | } | ||||||||||||
| 34 | |||||||||||||
| 35 | # Source blocks in a tool_result (karr k372, ADR 0001 k372 Update): off, | ||||||||||||
| 36 | # conservatively, like MoonshotAnthropic. NOT live-verified (no LM Studio | ||||||||||||
| 37 | # server available); the evidence is indirect: the anthropic-compat docs | ||||||||||||
| 38 | # (lmstudio.ai/docs/developer/anthropic-compat) only point to Anthropic's own, | ||||||||||||
| 39 | # the changelog names only "Images in tool call results" for /v1/messages, and | ||||||||||||
| 40 | # lmstudio-bug-tracker#1792 (LM Studio 0.4.11, Apr 2026) reports the API | ||||||||||||
| 41 | # rejecting PDFs with a 400 even for vision models and offering no document | ||||||||||||
| 42 | # type. A text resource (the common MCP case) goes out as a text block, a PDF | ||||||||||||
| 43 | # as the k336 placeholder, a native document / search_result as its text. | ||||||||||||
| 44 | # Wire truth, not image_input: a vision model gets the same treatment. | ||||||||||||
| 45 | 166 | ▶ | sub _tool_result_source_blocks_on_wire { 0 } | ||||||||||
|
Subroutine
_tool_result_source_blocks_on_wire: called CC=1 SCAR=0.0
| |||||||||||||
| 46 | |||||||||||||
| 47 | # url is the server root (the envelope appends /v1/messages); the native | ||||||||||||
| 48 | # models list sits beside it. | ||||||||||||
| 49 | 21 | ▶ | sub model_metadata_format { 'lmstudio' } | ||||||||||
|
Subroutine
model_metadata_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 50 | 71 | ▶ | sub model_metadata_url { | ||||||||||
|
Subroutine
model_metadata_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 51 | 71 | return Langertha::ModelProbe->server_root_url( $_[0]->url ) . '/api/v1/models'; | |||||||||||
| 52 | } | ||||||||||||
| 53 | |||||||||||||
| 54 | # LM Studio documents only "Authorization: Bearer" for its native REST API | ||||||||||||
| 55 | # (lmstudio.ai/docs/developer/core/authentication); x-api-key is documented for | ||||||||||||
| 56 | # /v1/messages. So the probe request also carries the token as Bearer, the chat | ||||||||||||
| 57 | # wire is unchanged. | ||||||||||||
| 58 | 62 | ▶ | around update_request => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||
| 59 | 62 | my ( $orig, $self, $request ) = @_; | |||||||||||
| 60 | 62 | $self->$orig($request); | |||||||||||
| 61 | 62 | ▶ | $request->header( 'Authorization', 'Bearer ' . $self->api_key ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | if $request->uri->as_string eq $self->model_metadata_url; | ||||||||||||
| 63 | 62 | return; | |||||||||||
| 64 | 14 | }; | |||||||||||
| 65 | |||||||||||||
| 66 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 67 | |||||||||||||
| 68 | |||||||||||||
| 69 | 14 | 1; | |||||||||||
| 70 | |||||||||||||
| 71 | __END__ | ||||||||||||