feat(chat): add support for custom HTTP headers in image attachments

This commit is contained in:
cogwheel0
2025-11-29 10:57:06 +05:30
parent 4c5f12919f
commit aefd4dfa2c
4 changed files with 90 additions and 5 deletions

View File

@@ -150,6 +150,7 @@ class _UserMessageBubbleState extends ConsumerState<UserMessageBubble> {
maxHeight: 350,
),
disableAnimation: widget.isStreaming,
httpHeaders: _headersForFile(imageFiles[0]),
),
),
),
@@ -191,6 +192,7 @@ class _UserMessageBubbleState extends ConsumerState<UserMessageBubble> {
maxHeight: 180,
),
disableAnimation: widget.isStreaming,
httpHeaders: _headersForFile(entry.value),
),
),
),
@@ -232,6 +234,7 @@ class _UserMessageBubbleState extends ConsumerState<UserMessageBubble> {
maxHeight: imageCount == 3 ? 135 : 90,
),
disableAnimation: widget.isStreaming,
httpHeaders: _headersForFile(file),
),
),
);
@@ -401,6 +404,24 @@ class _UserMessageBubbleState extends ConsumerState<UserMessageBubble> {
);
}
Map<String, String>? _headersForFile(dynamic file) {
if (file is! Map) return null;
final rawHeaders = file['headers'];
if (rawHeaders is! Map) return null;
final result = <String, String>{};
rawHeaders.forEach((key, value) {
final keyString = key?.toString();
final valueString = value?.toString();
if (keyString != null &&
keyString.isNotEmpty &&
valueString != null &&
valueString.isNotEmpty) {
result[keyString] = valueString;
}
});
return result.isEmpty ? null : result;
}
// Assistant-only helpers removed; this widget renders only user bubbles.
@override