Expand description
LLM transports for trusty-code.
Why: trusty-code agents invoke LLMs via OpenAI-compatible endpoints
(OpenRouter / Fireworks) and AWS Bedrock. Since #2406 (epic #2400) the
OpenAI-compatible HTTP mechanics live in the shared trusty_common::inference
adapter layer rather than a bespoke tcode client; since #4425 (epic #4429)
so does the ABSTRACTION — trusty-code defines no chat/provider trait of its
own, it implements and consumes trusty_common::inference::InferenceAdapter.
That is what gave trusty-code streaming: the shared trait’s chat_stream
already carried native SSE, which the deleted local trait had no method for.
What: Exports OpenAiCompatClient (shared OpenRouter/Fireworks/Together/
AtlasCloud transport), DispatchingLlmClient (slug-routed transport),
BedrockChatClient, the trusty-code-local response views (token_usage,
finish_reason, resolved_model), and RE-EXPORTS of the shared trait,
error, and wire types (InferenceAdapter, InferenceError, ChatRequest,
ChatResponse, ChatMessage, ToolDefinition, …) so crate::llm::… paths
keep resolving. Credentials resolve via the shared 3-tier chain (env >
.env.local > secure store) at first use.
Test: cargo test -p trusty-code covers transport routing, the streaming
decorators, and the local response views, plus the offline black-box e2e
(tests/inference_shared_adapter_e2e.rs). --include-ignored adds the
live provider tests.
trusty-code’s inference layer — a CONSUMER of the shared multi-provider
adapter, not a provider abstraction of its own (#4425, epic #4429).
Why: the owner directive (2026-07-30) is that all inference/chat in this
workspace goes through ONE adapter pattern that supports multiple providers
and streams when needed. Until #4425 trusty-code owned a parallel one:
InferenceAdapter (its own object-safe chat seam) plus duplicate
ChatRequest/ChatResponse/ChatMessage/UsageBlock/InferenceError types and
a convert module bridging them to the shared ones. That duplication had a
concrete cost, not just an aesthetic one: the shared adapter gained real SSE
streaming (InferenceAdapter::chat_stream, epic #3696 Gap B) and trusty-code
could not use it, because its own trait had no streaming method — so a tcode tui turn could only ever arrive as one paste. #4425 deletes the parallel
abstraction outright: the seam every trusty-code call site depends on IS
trusty_common::inference::InferenceAdapter, and the wire types ARE the
shared ones (they were copied from trusty-code’s in #2406, so this is a
de-duplication, not a re-modelling).
What: this module now contributes only trusty-code-SPECIFIC transports and
decorators — OpenAiCompatClient (OpenRouter / Fireworks / Together /
AtlasCloud, delegating to the shared adapters), BedrockChatClient
(Bedrock Converse; its re-pointing at the shared Bedrock adapter is #4426),
DispatchingLlmClient (per-request routing by model slug), the opt-in
debug_capture wire-dump decorator (#2264), and the tool_call_extractor
argument-repair machinery — plus flat re-exports of the shared trait, error,
and wire types so existing crate::llm::… import paths keep resolving.
Every one of those is an IMPLEMENTATION of the shared trait; none of them is
an abstraction over providers.
OpenRouter/Fireworks credentials resolve via the shared 3-tier chain
(process env > .env.local > secure store); Bedrock uses the standard AWS
credential chain (no key). Library helpers never read std::env for secrets
directly.
Test: cargo test -p trusty-code covers transport routing, the streaming
decorator pass-through (dispatch::tests, debug_capture), the
trusty-code-local response views (response_ext), and the offline black-box
HTTP round-trip in tests/inference_shared_adapter_e2e.rs. cargo test -p trusty-code -- --include-ignored additionally runs the live
live_openrouter_call/live_fireworks_call/live_bedrock_call tests.
Structs§
- Assistant
Message - The assistant message within a choice.
- Bedrock
Chat Client - AWS Bedrock Converse transport, backed by the shared inference adapter.
- Cache
Control - An Anthropic-style ephemeral prompt-cache breakpoint.
- Chat
Choice - One choice in the model response.
- Chat
Message - A single message in the chat conversation.
- Chat
Request - The full request body for a chat/completions call.
- Chat
Response - The top-level response from a chat/completions call.
- Debug
Capture Sink - Shared, thread-safe sink for one run’s debug-capture output.
- Dispatching
LlmClient - Routes each chat request to the Bedrock Converse transport or the shared OpenAI-compatible transport (OpenRouter / Fireworks), by model slug.
- Extracted
Tool Call - A tool call recovered by
ToolCallExtractor::extract, normalised across every extraction strategy and already schema-validated. - Function
Call - The function name and arguments within a
ToolCall. - Function
Definition - JSON-Schema description of a callable function.
- Open
AiCompat Client - OpenAI-compatible transport over the shared inference adapter, routing OpenRouter and Fireworks by model slug.
- Prompt
Tokens Details - OpenRouter-shaped nested cache-accounting object.
- Request
Usage Config - OpenRouter’s request-side “return detailed usage” directive.
- Schema
Violation - One schema-validation failure, with a JSON-pointer-like
pathfor context. - Stream
Assembly - Accumulates streamed chat events into a finished
ChatResponse. - Stream
Completion - The terminal summary of a streamed completion.
- Tool
Call - A tool call emitted by the model.
- Tool
Call Delta - A single streamed tool-call fragment.
- Tool
Call Extractor - Recovers and validates tool calls across every supported provider convention.
- Tool
Definition - A tool definition submitted with a request.
- Usage
Block - Wire-shape token-usage block from a chat-completions response.
Enums§
- Chat
Stream Event - One event in a streamed chat completion.
- Extraction
Strategy - Which extraction convention recovered a tool call.
- Inference
Error - Errors raised by an
super::adapter::InferenceAdapteror the configurator. - Stop
Reason - Why the model stopped generating, as a typed view over the wire string.
- Tool
Call Extract Error - Failure modes of tool-call extraction and validation.
Constants§
- DEFAULT_
MAX_ REPAIR_ ATTEMPTS - Default cap on corrective round-trips before giving up.
Traits§
- Inference
Adapter - The async inference surface every provider implements.
Functions§
- buffered_
stream - Replay a completed
ChatResponseas a one-shotChatStream. - extract_
with_ repair - Drive the bounded extract → (on failure) corrective-retry loop.
- finish_
reason - The first choice’s raw wire stop condition.
- resolved_
model - The model slug this turn should be attributed to (#1475 bug 2).
- strategy_
order_ for - Per-model fallback strategy order, tried when no native tool call is present.
- token_
usage - Convert a response’s wire usage block into trusty-code’s
TokenUsage. - wrap_
with_ debug_ capture - Wrap
innerin debug capture whensinkis configured; otherwise returninnerUNCHANGED.
Type Aliases§
- Chat
Stream - The boxed,
Sendstream of streaming events an adapter yields.