11// Service for handling AI communications with AGiXT API
22import 'dart:async' ;
3- import 'dart:typed_data' ;
43import 'package:agixt/models/agixt/widgets/agixt_chat.dart' ;
54import 'package:agixt/services/bluetooth_manager.dart' ;
65import 'package:agixt/services/whisper.dart' ;
@@ -44,8 +43,8 @@ class AIService {
4443 StreamSubscription <WakeWordEvent >? _wakeWordSubscription;
4544 StreamSubscription <VoiceInputState >? _voiceInputSubscription;
4645 StreamSubscription <WatchVoiceInput >? _watchVoiceInputSubscription;
47- StringBuffer _streamingResponse = StringBuffer ();
48- bool _isStreaming = false ;
46+ final StringBuffer _streamingResponse = StringBuffer ();
47+ bool _isStreaming = false ; // ignore: prefer_final_fields
4948
5049 factory AIService () {
5150 return singleton;
@@ -284,10 +283,8 @@ class AIService {
284283 }
285284
286285 /// Process text input and return the response
287- Future <String ?> _processTextInput (
288- String text, {
289- bool isFromWatch = false ,
290- }) async {
286+ // ignore: unused_element
287+ Future <String ?> _processTextInput (String text) async {
291288 try {
292289 // Use streaming for better responsiveness
293290 final responseBuffer = StringBuffer ();
@@ -384,7 +381,6 @@ class AIService {
384381 // This uses tts_mode=interleaved to stream both text and audio
385382 final responseBuffer = StringBuffer ();
386383 bool audioHeaderSent = false ;
387- bool hasReceivedAudio = false ;
388384 bool usePhoneAudio =
389385 ! _watchService.isConnected; // Track if we're using phone audio
390386 DateTime ? lastGlassesUpdate;
@@ -401,7 +397,7 @@ class AIService {
401397 if (_bluetoothManager.isConnected) {
402398 final now = DateTime .now ();
403399 if (lastGlassesUpdate == null ||
404- now.difference (lastGlassesUpdate! ) >
400+ now.difference (lastGlassesUpdate) >
405401 glassesUpdateInterval) {
406402 lastGlassesUpdate = now;
407403 // Send full accumulated text so far
@@ -451,7 +447,6 @@ class AIService {
451447 case ChatStreamEventType .audioChunk:
452448 // Stream audio to watch speaker or phone speaker
453449 if (event.audioData != null && audioHeaderSent) {
454- hasReceivedAudio = true ;
455450 if (! usePhoneAudio && _watchService.isConnected) {
456451 final success =
457452 await _watchService.sendAudioChunk (event.audioData! );
@@ -580,6 +575,7 @@ class AIService {
580575 }
581576
582577 /// Output response to the appropriate device(s)
578+ // ignore: unused_element
583579 Future <void > _outputResponse (String response) async {
584580 // Always display on glasses if connected
585581 if (_bluetoothManager.isConnected) {
@@ -759,6 +755,7 @@ class AIService {
759755 }
760756
761757 /// Fallback to original glasses-only recording method
758+ // ignore: unused_element
762759 Future <void > _fallbackToOriginalRecording () async {
763760 try {
764761 // First open the microphone before showing "Listening..."
@@ -818,7 +815,6 @@ class AIService {
818815 // Use streaming TTS to send audio to watch (like ESP32 does)
819816 final responseBuffer = StringBuffer ();
820817 bool audioHeaderSent = false ;
821- bool hasReceivedAudio = false ;
822818 bool usePhoneAudio =
823819 ! _watchService.isConnected; // Track if we're using phone audio
824820 DateTime ? lastGlassesUpdate;
@@ -835,7 +831,7 @@ class AIService {
835831 if (_bluetoothManager.isConnected) {
836832 final now = DateTime .now ();
837833 if (lastGlassesUpdate == null ||
838- now.difference (lastGlassesUpdate! ) >
834+ now.difference (lastGlassesUpdate) >
839835 glassesUpdateInterval) {
840836 lastGlassesUpdate = now;
841837 await _bluetoothManager.sendAIResponse (
@@ -882,7 +878,6 @@ class AIService {
882878 case ChatStreamEventType .audioChunk:
883879 // Stream audio to watch speaker or phone speaker
884880 if (event.audioData != null && audioHeaderSent) {
885- hasReceivedAudio = true ;
886881 if (! usePhoneAudio && _watchService.isConnected) {
887882 final success =
888883 await _watchService.sendAudioChunk (event.audioData! );
@@ -997,7 +992,6 @@ class AIService {
997992 // Use streaming TTS to send audio to watch (like foreground mode)
998993 final responseBuffer = StringBuffer ();
999994 bool audioHeaderSent = false ;
1000- bool hasReceivedAudio = false ;
1001995 bool usePhoneAudio =
1002996 ! _watchService.isConnected; // Track if we're using phone audio
1003997 DateTime ? lastGlassesUpdate;
@@ -1014,7 +1008,7 @@ class AIService {
10141008 if (_bluetoothManager.isConnected) {
10151009 final now = DateTime .now ();
10161010 if (lastGlassesUpdate == null ||
1017- now.difference (lastGlassesUpdate! ) >
1011+ now.difference (lastGlassesUpdate) >
10181012 glassesUpdateInterval) {
10191013 lastGlassesUpdate = now;
10201014 await _bluetoothManager.sendAIResponse (
@@ -1057,7 +1051,6 @@ class AIService {
10571051
10581052 case ChatStreamEventType .audioChunk:
10591053 if (event.audioData != null && audioHeaderSent) {
1060- hasReceivedAudio = true ;
10611054 if (! usePhoneAudio && _watchService.isConnected) {
10621055 final success =
10631056 await _watchService.sendAudioChunk (event.audioData! );
0 commit comments