From 3cd35fabd643e2ae4ded12270b49ebc479da1e4e Mon Sep 17 00:00:00 2001 From: cheliu Date: Thu, 14 Aug 2025 14:35:37 -0700 Subject: [PATCH 1/3] fix: Add missing mime_type and name in proto conversion utils --- src/a2a/utils/proto_utils.py | 24 ++++++++++++++++++++---- tests/utils/test_proto_utils.py | 8 +++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index 3f3db5783..19d781590 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -80,8 +80,16 @@ def file( cls, file: types.FileWithUri | types.FileWithBytes ) -> a2a_pb2.FilePart: if isinstance(file, types.FileWithUri): - return a2a_pb2.FilePart(file_with_uri=file.uri) - return a2a_pb2.FilePart(file_with_bytes=file.bytes.encode('utf-8')) + return a2a_pb2.FilePart( + file_with_uri=file.uri, + mime_type=file.mime_type, + name=file.name + ) + return a2a_pb2.FilePart( + file_with_bytes=file.bytes.encode('utf-8'), + mime_type=file.mime_type, + name=file.name, + ) @classmethod def task(cls, task: types.Task) -> a2a_pb2.Task: @@ -501,8 +509,16 @@ def file( cls, file: a2a_pb2.FilePart ) -> types.FileWithUri | types.FileWithBytes: if file.HasField('file_with_uri'): - return types.FileWithUri(uri=file.file_with_uri) - return types.FileWithBytes(bytes=file.file_with_bytes.decode('utf-8')) + return types.FileWithUri( + uri=file.file_with_uri, + mime_type=file.mime_type, + name=file.name, + ) + return types.FileWithBytes( + bytes=file.file_with_bytes.decode('utf-8'), + mime_type=file.mime_type, + name=file.name, + ) @classmethod def task_or_message( diff --git a/tests/utils/test_proto_utils.py b/tests/utils/test_proto_utils.py index 83848c248..74483f4a5 100644 --- a/tests/utils/test_proto_utils.py +++ b/tests/utils/test_proto_utils.py @@ -22,7 +22,11 @@ def sample_message() -> types.Message: types.Part(root=types.TextPart(text='Hello')), types.Part( root=types.FilePart( - file=types.FileWithUri(uri='file:///test.txt') + file=types.FileWithUri( + uri='file:///test.txt', + name='test.txt', + mime_type="text/plain", + ), ) ), types.Part(root=types.DataPart(data={'key': 'value'})), @@ -148,6 +152,8 @@ def test_roundtrip_message(self, sample_message: types.Message): # Test file part handling assert proto_msg.content[1].file.file_with_uri == 'file:///test.txt' + assert proto_msg.content[1].file.mime_type == 'text/plain' + assert proto_msg.content[1].file.name == 'test.txt' roundtrip_msg = proto_utils.FromProto.message(proto_msg) assert roundtrip_msg == sample_message From da14fc5cc6011f595d88100db92fae468157b0be Mon Sep 17 00:00:00 2001 From: cheliu Date: Fri, 15 Aug 2025 09:14:30 -0700 Subject: [PATCH 2/3] Apply Gemini suggestions --- src/a2a/utils/proto_utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index 19d781590..34309aefb 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -508,16 +508,18 @@ def data(cls, data: a2a_pb2.DataPart) -> dict[str, Any]: def file( cls, file: a2a_pb2.FilePart ) -> types.FileWithUri | types.FileWithBytes: + common_args = { + 'mime_type': file.mime_type or None, + 'name': file.name or None, + } if file.HasField('file_with_uri'): return types.FileWithUri( uri=file.file_with_uri, - mime_type=file.mime_type, - name=file.name, + **common_args, ) return types.FileWithBytes( bytes=file.file_with_bytes.decode('utf-8'), - mime_type=file.mime_type, - name=file.name, + **common_args, ) @classmethod From 57b8aad88c6fee0c08f6fdebb2ee9ad3dff8591f Mon Sep 17 00:00:00 2001 From: cheliu Date: Fri, 15 Aug 2025 09:20:28 -0700 Subject: [PATCH 3/3] Reformat files `ruff format` --- src/a2a/utils/proto_utils.py | 4 +--- tests/utils/test_proto_utils.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index 34309aefb..408c47bf2 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -81,9 +81,7 @@ def file( ) -> a2a_pb2.FilePart: if isinstance(file, types.FileWithUri): return a2a_pb2.FilePart( - file_with_uri=file.uri, - mime_type=file.mime_type, - name=file.name + file_with_uri=file.uri, mime_type=file.mime_type, name=file.name ) return a2a_pb2.FilePart( file_with_bytes=file.bytes.encode('utf-8'), diff --git a/tests/utils/test_proto_utils.py b/tests/utils/test_proto_utils.py index 74483f4a5..c3f1b6a42 100644 --- a/tests/utils/test_proto_utils.py +++ b/tests/utils/test_proto_utils.py @@ -25,7 +25,7 @@ def sample_message() -> types.Message: file=types.FileWithUri( uri='file:///test.txt', name='test.txt', - mime_type="text/plain", + mime_type='text/plain', ), ) ),