feat(chat): files upload over HTTP before the prompt, up to 100 MiB each
This commit is contained in:
@@ -50,7 +50,11 @@ ChatPickedFile _file(
|
||||
String name,
|
||||
List<int> bytes, {
|
||||
String mime = 'text/plain',
|
||||
}) => ChatPickedFile(name: name, mime: mime, bytes: Uint8List.fromList(bytes));
|
||||
}) => ChatPickedFile(
|
||||
name: name,
|
||||
mime: mime,
|
||||
bytes: bytes is Uint8List ? bytes : Uint8List.fromList(bytes),
|
||||
);
|
||||
|
||||
Finder get _field => find.byKey(const Key('chat-composer-field'));
|
||||
|
||||
@@ -159,7 +163,7 @@ void main() {
|
||||
fake.paste([
|
||||
_file(
|
||||
'huge.bin',
|
||||
List<int>.filled(ChatAttachmentDraft.maxTotalBytes + 1, 0),
|
||||
Uint8List(ChatAttachmentDraft.maxTotalBytes + 1),
|
||||
mime: 'application/octet-stream',
|
||||
),
|
||||
]);
|
||||
@@ -184,7 +188,7 @@ void main() {
|
||||
_file('kept.txt', [1]),
|
||||
_file(
|
||||
'huge.bin',
|
||||
List<int>.filled(ChatAttachmentDraft.maxTotalBytes, 0),
|
||||
Uint8List(ChatAttachmentDraft.maxTotalBytes),
|
||||
mime: 'application/octet-stream',
|
||||
),
|
||||
]);
|
||||
|
||||
@@ -42,10 +42,15 @@ void main() {
|
||||
expect(draft.attachments, [second]);
|
||||
});
|
||||
|
||||
test('accepts exactly 1 MiB in total', () {
|
||||
test('accepts exactly 100 MiB in total', () {
|
||||
final draft = ChatAttachmentDraft();
|
||||
|
||||
expect(draft.add(attachment('large.bin', 700000)), isNull);
|
||||
expect(
|
||||
draft.add(
|
||||
attachment('large.bin', ChatAttachmentDraft.maxTotalBytes - 348576),
|
||||
),
|
||||
isNull,
|
||||
);
|
||||
expect(draft.add(attachment('rest.bin', 348576)), isNull);
|
||||
expect(draft.totalBytes, ChatAttachmentDraft.maxTotalBytes);
|
||||
expect(draft.attachments, hasLength(2));
|
||||
@@ -59,10 +64,7 @@ void main() {
|
||||
final refusal = draft.add(attachment('extra.bin', 1));
|
||||
|
||||
expect(refusal, ChatAttachmentRefusal.totalTooLarge);
|
||||
expect(
|
||||
refusal!.message,
|
||||
'Attachments are too large for web chat (1 MiB total).',
|
||||
);
|
||||
expect(refusal!.message, 'Attachments are too large (100 MiB total).');
|
||||
expect(draft.attachments, [kept]);
|
||||
expect(draft.totalBytes, ChatAttachmentDraft.maxTotalBytes);
|
||||
});
|
||||
|
||||
@@ -121,14 +121,14 @@ void main() {
|
||||
draft,
|
||||
read: (_) {
|
||||
reads += 1;
|
||||
return Uint8List(ChatAttachmentDraft.maxTotalBytes + 1);
|
||||
return Uint8List(maxInlineAttachmentBytes + 1);
|
||||
},
|
||||
),
|
||||
throwsA(
|
||||
isA<ChatAttachmentWireException>().having(
|
||||
(error) => error.message,
|
||||
'message',
|
||||
'Attachments are too large for web chat (1 MiB total).',
|
||||
'Attachments are too large to send without a server (1 MiB total).',
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -190,4 +190,35 @@ void main() {
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'uploaded files are named in their parts, not carried as bytes',
|
||||
() async {
|
||||
final draft = ChatAttachmentDraft();
|
||||
final big = ChatAttachment(
|
||||
name: 'photo.png',
|
||||
mime: 'image/png',
|
||||
sizeBytes: maxInlineAttachmentBytes + 1,
|
||||
);
|
||||
draft.add(big);
|
||||
final uploaded = <String>[];
|
||||
final parts = await chatAttachmentUploadParts(
|
||||
draft,
|
||||
read: (_) => Uint8List(maxInlineAttachmentBytes + 1),
|
||||
upload: (attachment, bytes) async {
|
||||
uploaded.add(attachment.name);
|
||||
return 'up-0123-${attachment.name}';
|
||||
},
|
||||
);
|
||||
|
||||
expect(uploaded, ['photo.png']);
|
||||
expect(parts, [
|
||||
{
|
||||
'name': 'photo.png',
|
||||
'mime': 'image/png',
|
||||
'upload': 'up-0123-photo.png',
|
||||
},
|
||||
]);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user