getResponseAsync method

  1. @override
Stream<String> getResponseAsync()
override

Implementation

@override
Stream<String> getResponseAsync() async* {
  _assertNotClosed();

  final text = _queryBuffer.toString();
  _queryBuffer.clear();

  // Capture and clear pending media BEFORE making the call
  // This prevents stale media from being reused if the call fails
  final audio = _pendingAudio;
  final image = _pendingImage;
  _pendingAudio = null;
  _pendingImage = null;

  debugPrint('[DesktopSession] getResponseAsync: audio=${audio?.length}, image=${image?.length}');

  if (audio != null) {
    debugPrint('[DesktopSession] Calling chatWithAudio: audio=${audio.length} bytes');
    yield* grpcClient.chatWithAudio(text, audio);
  } else if (image != null) {
    debugPrint('[DesktopSession] Calling chatWithImage: image=${image.length} bytes');
    yield* grpcClient.chatWithImage(text, image);
  } else {
    debugPrint('[DesktopSession] Calling chat (no image/audio)');
    yield* grpcClient.chat(text);
  }
}