import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:cutdex_ui/theme.dart'; import '../../l10n/l10n.dart'; import 'chat_controller.dart'; import 'chat_state.dart'; /// Streaming output observes its conversation independently of history/composer. class AgentReplyRegion extends ConsumerWidget { const AgentReplyRegion({ super.key, required this.projectId, this.conversationId, this.draftKey, }); final String? projectId; final String? conversationId; final String? draftKey; @override Widget build(BuildContext context, WidgetRef ref) { if (projectId == null) return const SizedBox.shrink(); final provider = chatControllerProvider( projectId!, conversationId: conversationId, draftKey: draftKey, ).select( (state) => ( state.busy, state.partialResponse, state.stopping, state.activity, ), ); final state = TickerMode.valuesOf(context).enabled ? ref.watch(provider) : ref.read(provider); if (!state.$1) return const SizedBox.shrink(); return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ if (state.$2.isNotEmpty) SelectionArea( child: Text( state.$2, style: AppTheme.chatMessageTextStyle(context), ), ), Text( state.$3 ? context.l10n.stopping : switch (state.$4) { AgentChatActivity.compacting => context.l10n.agentCompacting, AgentChatActivity.editing => context.l10n.agentEditing, AgentChatActivity.verifying => context.l10n.agentVerifying, AgentChatActivity.replying => context.l10n.replying, }, style: Theme.of(context).textTheme.bodySmall, ), ], ); } } /// Stable chrome/history snapshot; each streamed token belongs to reply region. ChatState chatChrome(ChatState state) => state.copyWith(partialResponse: '', activity: AgentChatActivity.replying);