sendMessage method
Send a text message and get the full response (sync C API, non-blocking Dart).
Implementation
Future<String> sendMessage(String messageJson, {String? extraContext}) async {
_assertInitialized();
_assertConversation();
final b = _bindings!;
final messagePtr = messageJson.toNativeUtf8();
final extraPtr =
extraContext != null ? extraContext.toNativeUtf8() : nullptr;
try {
final response = b.litert_lm_conversation_send_message(
_conversation!,
messagePtr.cast(),
extraPtr == nullptr ? nullptr : extraPtr.cast(),
);
if (response == nullptr) {
throw Exception('send_message returned null');
}
final strPtr = b.litert_lm_json_response_get_string(response);
final result =
strPtr == nullptr ? '' : strPtr.cast<Utf8>().toDartString();
b.litert_lm_json_response_delete(response);
return result;
} finally {
calloc.free(messagePtr);
if (extraPtr != nullptr) calloc.free(extraPtr);
}
}