SdkTextExtractor class
Pure-Dart extractor for LiteRT-LM SDK JSON response chunks.
Lives in core, not in flutter_edge_ai_litertlm's native lib/src/ffi/, so
the web @litert-lm/core path can reuse the exact same text-extraction
logic that the native FFI path uses — both inputs are the same OpenAI Chat
Completions chunk JSON shape produced by liblitert_lm and
@litert-lm/core respectively.
Handles these response formats:
- Text:
{"role":"assistant","content":[{"type":"text","text":"hello"}]}→ returns"hello" - Thinking:
{"role":"assistant","channels":{"thought":"reasoning..."}}→ returns<|channel>thought\nreasoning...<channel|>(compatible withThinkingFilterincore/extensions.dart) - An object without content, a tool call
(
{"role":"assistant","tool_calls":[...]}) included → returns the chunk's JSON unchanged. - A content list keeps only its text parts, so
[]gives"".
Text that is not JSON passes through. JSON that is not an object, or a content of another type, throws: that is a contract change with LiteRT-LM.
Constructors
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
-
extractTextFromResponse(
String jsonStr) → String - Extract text from a LiteRT-LM JSON response chunk.