FUCKASS IA

This commit is contained in:
2026-05-16 17:31:06 +01:00
parent f8e3a7686f
commit 321df8bb1d
5 changed files with 651 additions and 212 deletions

View File

@@ -4,6 +4,8 @@ import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/services/auth_service.dart';
import '../../../../core/services/chat_memory_service.dart';
import '../../../../core/services/materials_rag_service.dart';
import '../../../../core/services/rag_ai_service.dart';
import '../../../../core/utils/logger.dart';
@@ -23,10 +25,21 @@ class _TutorChatPageSimpleState extends State<TutorChatPageSimple>
bool _isLoading = false;
List<Map<String, dynamic>> _messages = [];
List<Map<String, String>> _availableMaterials = [];
Set<String> _selectedMaterialIds = {};
@override
void initState() {
super.initState();
_addWelcomeMessage();
_loadAvailableMaterials();
}
Future<void> _loadAvailableMaterials() async {
final materials = await MaterialsRAGService.getAvailableMaterialsForStudent();
if (mounted) {
setState(() => _availableMaterials = materials);
}
}
@override
@@ -337,20 +350,116 @@ class _TutorChatPageSimpleState extends State<TutorChatPageSimple>
),
],
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Theme.of(context).colorScheme.surface,
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.5),
width: 1,
),
),
child: Row(
children: [
// Text field
Expanded(
child: TextField(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Chips dos materiais selecionados
if (_availableMaterials.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
children: [
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
InkWell(
onTap: _showMaterialsPicker,
borderRadius: BorderRadius.circular(20),
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 6,
),
decoration: BoxDecoration(
color: _selectedMaterialIds.isEmpty
? Theme.of(context).colorScheme.outline.withOpacity(0.15)
: Theme.of(context).colorScheme.primary.withOpacity(0.12),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: _selectedMaterialIds.isEmpty
? Theme.of(context).colorScheme.outline.withOpacity(0.4)
: Theme.of(context).colorScheme.primary.withOpacity(0.5),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.attach_file,
size: 14,
color: _selectedMaterialIds.isEmpty
? Theme.of(context).colorScheme.onSurfaceVariant
: Theme.of(context).colorScheme.primary,
),
const SizedBox(width: 4),
Text(
_selectedMaterialIds.isEmpty
? 'Materiais'
: '${_selectedMaterialIds.length} selecionado(s)',
style: TextStyle(
fontSize: 12,
color: _selectedMaterialIds.isEmpty
? Theme.of(context).colorScheme.onSurfaceVariant
: Theme.of(context).colorScheme.primary,
fontWeight: FontWeight.w500,
),
),
],
),
),
),
if (_selectedMaterialIds.isNotEmpty) ...
_selectedMaterialIds.map((id) {
final name = _availableMaterials
.firstWhere(
(m) => m['id'] == id,
orElse: () => {'id': id, 'name': id},
)['name'] ??
id;
final short = name.length > 18
? '${name.substring(0, 16)}'
: name;
return Padding(
padding: const EdgeInsets.only(left: 6),
child: Chip(
label: Text(
short,
style: const TextStyle(fontSize: 11),
),
deleteIcon: const Icon(Icons.close, size: 14),
onDeleted: () => setState(
() => _selectedMaterialIds.remove(id),
),
materialTapTargetSize:
MaterialTapTargetSize.shrinkWrap,
padding: EdgeInsets.zero,
visualDensity: VisualDensity.compact,
),
);
}).toList(),
],
),
),
),
],
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Theme.of(context).colorScheme.surface,
border: Border.all(
color: Theme.of(context).colorScheme.outline.withOpacity(0.5),
width: 1,
),
),
child: Row(
children: [
// Text field
Expanded(
child: TextField(
controller: _messageController,
style: TextStyle(
fontSize: 16,
@@ -379,62 +488,163 @@ class _TutorChatPageSimpleState extends State<TutorChatPageSimple>
),
// Send button
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Container(
width: 44,
height: 44,
decoration: BoxDecoration(
gradient: _messageController.text.isNotEmpty
? LinearGradient(
colors: [
Theme.of(context).colorScheme.primary,
Theme.of(
context,
).colorScheme.primary.withOpacity(0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
color: _messageController.text.isNotEmpty
? null
: Theme.of(context).colorScheme.outline.withOpacity(0.3),
borderRadius: BorderRadius.circular(22),
boxShadow: _messageController.text.isNotEmpty
? [
BoxShadow(
color: Theme.of(
context,
).colorScheme.primary.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
]
: null,
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Container(
width: 44,
height: 44,
decoration: BoxDecoration(
gradient: _messageController.text.isNotEmpty
? LinearGradient(
colors: [
Theme.of(context).colorScheme.primary,
Theme.of(
context,
).colorScheme.primary.withOpacity(0.8),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
)
: null,
color: _messageController.text.isNotEmpty
? null
: Theme.of(context).colorScheme.outline.withOpacity(0.3),
borderRadius: BorderRadius.circular(22),
boxShadow: _messageController.text.isNotEmpty
? [
BoxShadow(
color: Theme.of(
context,
).colorScheme.primary.withOpacity(0.3),
blurRadius: 8,
offset: const Offset(0, 2),
),
]
: null,
),
child: IconButton(
onPressed: _messageController.text.isNotEmpty && !_isLoading
? _handleSendMessage
: null,
icon: _isLoading
? SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
)
: Icon(Icons.send, color: Colors.white, size: 18),
),
),
),
child: IconButton(
onPressed: _messageController.text.isNotEmpty && !_isLoading
? _handleSendMessage
: null,
icon: _isLoading
? SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
],
),
),
],
),
);
}
void _showMaterialsPicker() {
showDialog(
context: context,
builder: (dialogContext) {
final tempSelected = Set<String>.from(_selectedMaterialIds);
return StatefulBuilder(
builder: (context, setDialogState) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
title: const Text(
'Escolher Materiais',
style: TextStyle(fontWeight: FontWeight.bold),
),
content: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Seleciona os materiais que o tutor deve analisar:',
style: TextStyle(
fontSize: 13,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 12),
ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 300),
child: ListView(
shrinkWrap: true,
children: _availableMaterials.map((material) {
final id = material['id']!;
final name = material['name']!;
final isChecked = tempSelected.contains(id);
return CheckboxListTile(
value: isChecked,
onChanged: (val) {
setDialogState(() {
if (val == true) {
tempSelected.add(id);
} else {
tempSelected.remove(id);
}
});
},
title: Text(
name,
style: const TextStyle(fontSize: 14),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
)
: Icon(Icons.send, color: Colors.white, size: 18),
),
controlAffinity: ListTileControlAffinity.leading,
dense: true,
contentPadding: EdgeInsets.zero,
);
}).toList(),
),
),
],
),
),
],
),
),
actions: [
TextButton(
onPressed: () {
setDialogState(() => tempSelected.clear());
setState(() {
_selectedMaterialIds.clear();
_messages.clear();
});
ChatMemoryService.clearHistory();
Navigator.of(dialogContext).pop();
},
child: const Text('Limpar'),
),
ElevatedButton(
onPressed: () {
setState(() {
_selectedMaterialIds = tempSelected;
_messages.clear();
});
ChatMemoryService.clearHistory();
Navigator.of(dialogContext).pop();
},
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: const Text('Confirmar'),
),
],
),
);
},
);
}
@@ -490,7 +700,12 @@ Envia-me a tua pergunta sobre qualquer assunto educacional e vou usar o material
// Use RAGAIService with memory, PDFs, and O GOAT identity
Logger.info('USING RAG AI SERVICE');
final replyText = await RAGAIService.ask(userMessage);
final replyText = await RAGAIService.ask(
userMessage,
selectedMaterialIds: _selectedMaterialIds.isEmpty
? null
: _selectedMaterialIds.toList(),
);
final preview = replyText.length > 50
? replyText.substring(0, 50)