From eedd55e15449251b29d217aa93fd72f42f3fb6c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 08:13:36 +0000 Subject: [PATCH 1/4] Initial plan From 57b6b896071d7919e682b932f2ea85d59f53f6b3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 08:15:27 +0000 Subject: [PATCH 2/4] Implement saveConversation method in AIService Co-authored-by: hassan689 <117458014+hassan689@users.noreply.github.com> --- lib/ai_agent/ai_service.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/ai_agent/ai_service.dart b/lib/ai_agent/ai_service.dart index 978530d..bcb54c4 100644 --- a/lib/ai_agent/ai_service.dart +++ b/lib/ai_agent/ai_service.dart @@ -1,5 +1,7 @@ import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/foundation.dart'; import 'package:connect/config/app_config.dart'; import 'package:connect/services/points_service.dart'; @@ -164,8 +166,18 @@ Always be encouraging and help users get the most out of Connect! /// Example implementation would save to a 'conversations' collection /// in Firestore with timestamp and user context. static Future saveConversation(String userId, String userMessage, String aiResponse) async { - // You can implement this to save conversations for analytics - // This helps improve the AI responses over time + try { + await FirebaseFirestore.instance + .collection('ai_conversations') + .add({ + 'userId': userId, + 'userMessage': userMessage, + 'aiResponse': aiResponse, + 'timestamp': FieldValue.serverTimestamp(), + }); + } catch (e) { + debugPrint('Error saving conversation: $e'); + } } /// Gets a list of suggested questions users can ask Dino. From 2a2f32a9de8ac063c762f37b7266ec7fcc79e26a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 08:16:07 +0000 Subject: [PATCH 3/4] Update documentation to match actual collection name Co-authored-by: hassan689 <117458014+hassan689@users.noreply.github.com> --- lib/ai_agent/ai_service.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ai_agent/ai_service.dart b/lib/ai_agent/ai_service.dart index bcb54c4..c462d30 100644 --- a/lib/ai_agent/ai_service.dart +++ b/lib/ai_agent/ai_service.dart @@ -156,15 +156,14 @@ Always be encouraging and help users get the most out of Connect! /// Saves conversation history to Firestore for analytics and improvement. /// - /// This method can be implemented to store user interactions with Dino, + /// Stores user interactions with Dino to the 'ai_conversations' collection, /// which helps analyze user needs and improve AI responses over time. /// /// [userId] The ID of the user having the conversation /// [userMessage] The message sent by the user /// [aiResponse] The response generated by the AI /// - /// Example implementation would save to a 'conversations' collection - /// in Firestore with timestamp and user context. + /// Saves to the 'ai_conversations' collection in Firestore with timestamp. static Future saveConversation(String userId, String userMessage, String aiResponse) async { try { await FirebaseFirestore.instance From 04a46aadd030bb7512f642cc082067e09a479384 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 24 Jan 2026 08:16:36 +0000 Subject: [PATCH 4/4] Add input validation and improve error message Co-authored-by: hassan689 <117458014+hassan689@users.noreply.github.com> --- lib/ai_agent/ai_service.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ai_agent/ai_service.dart b/lib/ai_agent/ai_service.dart index c462d30..7467145 100644 --- a/lib/ai_agent/ai_service.dart +++ b/lib/ai_agent/ai_service.dart @@ -165,6 +165,12 @@ Always be encouraging and help users get the most out of Connect! /// /// Saves to the 'ai_conversations' collection in Firestore with timestamp. static Future saveConversation(String userId, String userMessage, String aiResponse) async { + // Validate input parameters + if (userId.isEmpty || userMessage.trim().isEmpty || aiResponse.trim().isEmpty) { + debugPrint('Cannot save conversation: Invalid parameters provided'); + return; + } + try { await FirebaseFirestore.instance .collection('ai_conversations') @@ -175,7 +181,7 @@ Always be encouraging and help users get the most out of Connect! 'timestamp': FieldValue.serverTimestamp(), }); } catch (e) { - debugPrint('Error saving conversation: $e'); + debugPrint('Failed to save conversation to Firestore: $e'); } }