11"""Unified helper functions for creating and handling A2A types."""
22
33import uuid
4- from collections .abc import Sequence
5- from typing import Any
64
7- from google . protobuf . json_format import MessageToDict
5+ from collections . abc import Sequence
86
97from a2a .types .a2a_pb2 import (
108 Artifact ,
@@ -121,7 +119,6 @@ def new_task(
121119 history : list [Message ] | None = None ,
122120) -> Task :
123121 """Creates a Task object with a specified status."""
124-
125122 if history is None :
126123 history = []
127124 if artifacts is None :
@@ -169,7 +166,7 @@ def new_text_status_update_event(
169166 )
170167
171168
172- def new_text_artifact_update_event (
169+ def new_text_artifact_update_event ( # noqa: PLR0913
173170 task_id : str ,
174171 context_id : str ,
175172 name : str ,
@@ -189,17 +186,23 @@ def new_text_artifact_update_event(
189186 )
190187
191188
192- def get_stream_response_text (response : StreamResponse , delimiter : str = '\n ' ) -> str :
189+ def get_stream_response_text (
190+ response : StreamResponse , delimiter : str = '\n '
191+ ) -> str :
193192 """Extracts text content from a StreamResponse."""
194193 if response .HasField ('message' ):
195194 return get_message_text (response .message , delimiter )
196- elif response .HasField ('task' ):
197- texts = [get_artifact_text (a , delimiter ) for a in response .task .artifacts ]
195+ if response .HasField ('task' ):
196+ texts = [
197+ get_artifact_text (a , delimiter ) for a in response .task .artifacts
198+ ]
198199 return delimiter .join (t for t in texts if t )
199- elif response .HasField ('status_update' ):
200+ if response .HasField ('status_update' ):
200201 if response .status_update .status .HasField ('message' ):
201- return get_message_text (response .status_update .status .message , delimiter )
202+ return get_message_text (
203+ response .status_update .status .message , delimiter
204+ )
202205 return ''
203- elif response .HasField ('artifact_update' ):
206+ if response .HasField ('artifact_update' ):
204207 return get_artifact_text (response .artifact_update .artifact , delimiter )
205208 return ''
0 commit comments