SdkResponseParser class

Parser for LiteRT-LM SDK Chat Completions JSON responses.

Used by InferenceChat when the active session backend exposes lastRawResponse (FFI/LiteRT-LM path with structured tool_calls). The SDK already converts native <|tool_call>...<tool_call|> Gemma 4 tokens into OpenAI-style JSON via chat_template.jinja + minja, so this helper just walks the JSON and surfaces FunctionCallResponses.

Parsing rules mirror upstream Python Conversation._handle_tool_calls (python/litert_lm/conversation.py).

Constructors

SdkResponseParser()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

buildToolResponseJson({required String toolName, required Object? response, String? toolCallId}) String
Build the JSON message that delivers a tool execution result back to the model on the next turn. Format mirrors upstream Python serve.py::gemini_to_litertlm_message and Gemma 4 data processor's FormatToolResponse.
cleanRawForHistory(String rawJson) String
Clean a raw SDK response JSON string by recursively stripping <|"|> escape tokens. Used by chat.dart before writing the assistant turn into chat history — without this the next request echoes the escape tokens back to the model and Gemma 4 starts reproducing them in subsequent tool_calls arguments (#248).
extractToolCalls(String jsonStr) List<FunctionCallResponse>
Extract all function calls from an SDK response JSON string.
serializeToolsForSdk(List<Tool> tools) String
Serialize tools into the OpenAI Chat Completions JSON format that LiteRT-LM SDK expects in litert_lm_conversation_config_set_tools. SDK then applies chat_template.jinja (via minja) to render native Gemma 4 <|tool>declaration:...<tool|> tokens.