Skip to content

Commit 3cd35fa

Browse files
committed
fix: Add missing mime_type and name in proto conversion utils
1 parent 1dbe33d commit 3cd35fa

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

src/a2a/utils/proto_utils.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,16 @@ def file(
8080
cls, file: types.FileWithUri | types.FileWithBytes
8181
) -> a2a_pb2.FilePart:
8282
if isinstance(file, types.FileWithUri):
83-
return a2a_pb2.FilePart(file_with_uri=file.uri)
84-
return a2a_pb2.FilePart(file_with_bytes=file.bytes.encode('utf-8'))
83+
return a2a_pb2.FilePart(
84+
file_with_uri=file.uri,
85+
mime_type=file.mime_type,
86+
name=file.name
87+
)
88+
return a2a_pb2.FilePart(
89+
file_with_bytes=file.bytes.encode('utf-8'),
90+
mime_type=file.mime_type,
91+
name=file.name,
92+
)
8593

8694
@classmethod
8795
def task(cls, task: types.Task) -> a2a_pb2.Task:
@@ -501,8 +509,16 @@ def file(
501509
cls, file: a2a_pb2.FilePart
502510
) -> types.FileWithUri | types.FileWithBytes:
503511
if file.HasField('file_with_uri'):
504-
return types.FileWithUri(uri=file.file_with_uri)
505-
return types.FileWithBytes(bytes=file.file_with_bytes.decode('utf-8'))
512+
return types.FileWithUri(
513+
uri=file.file_with_uri,
514+
mime_type=file.mime_type,
515+
name=file.name,
516+
)
517+
return types.FileWithBytes(
518+
bytes=file.file_with_bytes.decode('utf-8'),
519+
mime_type=file.mime_type,
520+
name=file.name,
521+
)
506522

507523
@classmethod
508524
def task_or_message(

tests/utils/test_proto_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def sample_message() -> types.Message:
2222
types.Part(root=types.TextPart(text='Hello')),
2323
types.Part(
2424
root=types.FilePart(
25-
file=types.FileWithUri(uri='file:///test.txt')
25+
file=types.FileWithUri(
26+
uri='file:///test.txt',
27+
name='test.txt',
28+
mime_type="text/plain",
29+
),
2630
)
2731
),
2832
types.Part(root=types.DataPart(data={'key': 'value'})),
@@ -148,6 +152,8 @@ def test_roundtrip_message(self, sample_message: types.Message):
148152

149153
# Test file part handling
150154
assert proto_msg.content[1].file.file_with_uri == 'file:///test.txt'
155+
assert proto_msg.content[1].file.mime_type == 'text/plain'
156+
assert proto_msg.content[1].file.name == 'test.txt'
151157

152158
roundtrip_msg = proto_utils.FromProto.message(proto_msg)
153159
assert roundtrip_msg == sample_message

0 commit comments

Comments
 (0)