Skip to content

Commit ade67af

Browse files
committed
Merge remote-tracking branch 'upstream/main' into chore/improve-coverage-grpc-client
Signed-off-by: Shingo OKAWA <[email protected]>
2 parents f5b2340 + 72b2ee7 commit ade67af

File tree

4 files changed

+132
-108
lines changed

4 files changed

+132
-108
lines changed

src/a2a/grpc/a2a_pb2.py

Lines changed: 101 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/a2a/grpc/a2a_pb2.pyi

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ class Part(_message.Message):
9494
def __init__(self, text: _Optional[str] = ..., file: _Optional[_Union[FilePart, _Mapping]] = ..., data: _Optional[_Union[DataPart, _Mapping]] = ...) -> None: ...
9595

9696
class FilePart(_message.Message):
97-
__slots__ = ("file_with_uri", "file_with_bytes", "mime_type")
97+
__slots__ = ("file_with_uri", "file_with_bytes", "mime_type", "name")
9898
FILE_WITH_URI_FIELD_NUMBER: _ClassVar[int]
9999
FILE_WITH_BYTES_FIELD_NUMBER: _ClassVar[int]
100100
MIME_TYPE_FIELD_NUMBER: _ClassVar[int]
101+
NAME_FIELD_NUMBER: _ClassVar[int]
101102
file_with_uri: str
102103
file_with_bytes: bytes
103104
mime_type: str
104-
def __init__(self, file_with_uri: _Optional[str] = ..., file_with_bytes: _Optional[bytes] = ..., mime_type: _Optional[str] = ...) -> None: ...
105+
name: str
106+
def __init__(self, file_with_uri: _Optional[str] = ..., file_with_bytes: _Optional[bytes] = ..., mime_type: _Optional[str] = ..., name: _Optional[str] = ...) -> None: ...
105107

106108
class DataPart(_message.Message):
107109
__slots__ = ("data",)

src/a2a/utils/proto_utils.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ def file(
7878
cls, file: types.FileWithUri | types.FileWithBytes
7979
) -> a2a_pb2.FilePart:
8080
if isinstance(file, types.FileWithUri):
81-
return a2a_pb2.FilePart(file_with_uri=file.uri)
82-
return a2a_pb2.FilePart(file_with_bytes=file.bytes.encode('utf-8'))
81+
return a2a_pb2.FilePart(
82+
file_with_uri=file.uri, mime_type=file.mime_type, name=file.name
83+
)
84+
return a2a_pb2.FilePart(
85+
file_with_bytes=file.bytes.encode('utf-8'),
86+
mime_type=file.mime_type,
87+
name=file.name,
88+
)
8389

8490
@classmethod
8591
def task(cls, task: types.Task) -> a2a_pb2.Task:
@@ -498,9 +504,19 @@ def data(cls, data: a2a_pb2.DataPart) -> dict[str, Any]:
498504
def file(
499505
cls, file: a2a_pb2.FilePart
500506
) -> types.FileWithUri | types.FileWithBytes:
507+
common_args = {
508+
'mime_type': file.mime_type or None,
509+
'name': file.name or None,
510+
}
501511
if file.HasField('file_with_uri'):
502-
return types.FileWithUri(uri=file.file_with_uri)
503-
return types.FileWithBytes(bytes=file.file_with_bytes.decode('utf-8'))
512+
return types.FileWithUri(
513+
uri=file.file_with_uri,
514+
**common_args,
515+
)
516+
return types.FileWithBytes(
517+
bytes=file.file_with_bytes.decode('utf-8'),
518+
**common_args,
519+
)
504520

505521
@classmethod
506522
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)