feat(conversation): improve OpenWebUI error handling and parsing
This commit is contained in:
@@ -878,6 +878,15 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
|
||||
),
|
||||
),
|
||||
|
||||
// Display error banner if message has an error
|
||||
if (widget.message is ChatMessage &&
|
||||
(widget.message as ChatMessage).error != null) ...[
|
||||
const SizedBox(height: Spacing.sm),
|
||||
_buildErrorBanner(
|
||||
(widget.message as ChatMessage).error!,
|
||||
),
|
||||
],
|
||||
|
||||
if (hasCodeExecutions) ...[
|
||||
const SizedBox(height: Spacing.md),
|
||||
CodeExecutionListView(
|
||||
@@ -924,6 +933,47 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
|
||||
);
|
||||
}
|
||||
|
||||
/// Build an error banner matching OpenWebUI's error display style.
|
||||
/// Shows error content in a red-tinted container with an info icon.
|
||||
Widget _buildErrorBanner(ChatMessageError error) {
|
||||
final theme = Theme.of(context);
|
||||
final errorColor = theme.colorScheme.error;
|
||||
final errorContent = error.content;
|
||||
|
||||
// If no content, show a generic error message
|
||||
final displayText = (errorContent != null && errorContent.isNotEmpty)
|
||||
? errorContent
|
||||
: 'An error occurred while generating this response.';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(Spacing.md),
|
||||
decoration: BoxDecoration(
|
||||
color: errorColor.withValues(alpha: 0.1),
|
||||
border: Border.all(color: errorColor.withValues(alpha: 0.2)),
|
||||
borderRadius: BorderRadius.circular(Spacing.sm),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 20,
|
||||
color: errorColor,
|
||||
),
|
||||
const SizedBox(width: Spacing.sm),
|
||||
Expanded(
|
||||
child: Text(
|
||||
displayText,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: errorColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEnhancedMarkdownContent(String content) {
|
||||
if (content.trim().isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
@@ -1252,7 +1302,10 @@ class _AssistantMessageWidgetState extends ConsumerState<AssistantMessageWidget>
|
||||
final ttsState = ref.watch(textToSpeechControllerProvider);
|
||||
final messageId = _messageId;
|
||||
final hasSpeechText = _ttsPlainText.trim().isNotEmpty;
|
||||
final isErrorMessage =
|
||||
// Check for error using the error field (preferred) or legacy content detection
|
||||
final hasErrorField = widget.message is ChatMessage &&
|
||||
(widget.message as ChatMessage).error != null;
|
||||
final isErrorMessage = hasErrorField ||
|
||||
widget.message.content.contains('⚠️') ||
|
||||
widget.message.content.contains('Error') ||
|
||||
widget.message.content.contains('timeout') ||
|
||||
|
||||
Reference in New Issue
Block a user