|
24 | 24 | import uuid |
25 | 25 |
|
26 | 26 | from a2a.server.events import Event as A2AEvent |
27 | | -from a2a.types import Artifact |
28 | 27 | from a2a.types import DataPart |
29 | 28 | from a2a.types import Message |
30 | 29 | from a2a.types import Part as A2APart |
31 | 30 | from a2a.types import Role |
32 | 31 | from a2a.types import Task |
33 | | -from a2a.types import TaskArtifactUpdateEvent |
34 | 32 | from a2a.types import TaskState |
35 | 33 | from a2a.types import TaskStatus |
36 | 34 | from a2a.types import TaskStatusUpdateEvent |
@@ -145,81 +143,6 @@ def _create_artifact_id( |
145 | 143 | return ARTIFACT_ID_SEPARATOR.join(components) |
146 | 144 |
|
147 | 145 |
|
148 | | -def _convert_artifact_to_a2a_events( |
149 | | - event: Event, |
150 | | - invocation_context: InvocationContext, |
151 | | - filename: str, |
152 | | - version: int, |
153 | | - task_id: Optional[str] = None, |
154 | | - context_id: Optional[str] = None, |
155 | | -) -> TaskArtifactUpdateEvent: |
156 | | - """Converts a new artifact version to an A2A TaskArtifactUpdateEvent. |
157 | | -
|
158 | | - Args: |
159 | | - event: The ADK event containing the artifact information. |
160 | | - invocation_context: The invocation context. |
161 | | - filename: The name of the artifact file. |
162 | | - version: The version number of the artifact. |
163 | | - task_id: Optional task ID to use for generated events. If not provided, new UUIDs will be generated. |
164 | | -
|
165 | | - Returns: |
166 | | - A TaskArtifactUpdateEvent representing the artifact update. |
167 | | -
|
168 | | - Raises: |
169 | | - ValueError: If required parameters are invalid. |
170 | | - RuntimeError: If artifact loading fails. |
171 | | - """ |
172 | | - if not filename: |
173 | | - raise ValueError("Filename cannot be empty") |
174 | | - if version < 0: |
175 | | - raise ValueError("Version must be non-negative") |
176 | | - |
177 | | - try: |
178 | | - artifact_part = invocation_context.artifact_service.load_artifact( |
179 | | - app_name=invocation_context.app_name, |
180 | | - user_id=invocation_context.user_id, |
181 | | - session_id=invocation_context.session.id, |
182 | | - filename=filename, |
183 | | - version=version, |
184 | | - ) |
185 | | - |
186 | | - converted_part = convert_genai_part_to_a2a_part(part=artifact_part) |
187 | | - if not converted_part: |
188 | | - raise RuntimeError(f"Failed to convert artifact part for {filename}") |
189 | | - |
190 | | - artifact_id = _create_artifact_id( |
191 | | - invocation_context.app_name, |
192 | | - invocation_context.user_id, |
193 | | - invocation_context.session.id, |
194 | | - filename, |
195 | | - version, |
196 | | - ) |
197 | | - |
198 | | - return TaskArtifactUpdateEvent( |
199 | | - taskId=task_id, |
200 | | - append=False, |
201 | | - contextId=context_id, |
202 | | - lastChunk=True, |
203 | | - artifact=Artifact( |
204 | | - artifactId=artifact_id, |
205 | | - name=filename, |
206 | | - metadata={ |
207 | | - "filename": filename, |
208 | | - "version": version, |
209 | | - }, |
210 | | - parts=[converted_part], |
211 | | - ), |
212 | | - ) |
213 | | - except Exception as e: |
214 | | - logger.error( |
215 | | - "Failed to convert artifact for %s, version %s: %s", |
216 | | - filename, |
217 | | - version, |
218 | | - e, |
219 | | - ) |
220 | | - raise RuntimeError(f"Artifact conversion failed: {e}") from e |
221 | | - |
222 | | - |
223 | 146 | def _process_long_running_tool(a2a_part: A2APart, event: Event) -> None: |
224 | 147 | """Processes long-running tool metadata for an A2A part. |
225 | 148 |
|
@@ -268,7 +191,11 @@ def convert_a2a_task_to_event( |
268 | 191 | try: |
269 | 192 | # Extract message from task status or history |
270 | 193 | message = None |
271 | | - if a2a_task.status and a2a_task.status.message: |
| 194 | + if a2a_task.artifacts: |
| 195 | + message = Message( |
| 196 | + messageId="", role=Role.agent, parts=a2a_task.artifacts[-1].parts |
| 197 | + ) |
| 198 | + elif a2a_task.status and a2a_task.status.message: |
272 | 199 | message = a2a_task.status.message |
273 | 200 | elif a2a_task.history: |
274 | 201 | message = a2a_task.history[-1] |
@@ -573,13 +500,6 @@ def convert_event_to_a2a_events( |
573 | 500 | a2a_events = [] |
574 | 501 |
|
575 | 502 | try: |
576 | | - # Handle artifact deltas |
577 | | - if event.actions.artifact_delta: |
578 | | - for filename, version in event.actions.artifact_delta.items(): |
579 | | - artifact_event = _convert_artifact_to_a2a_events( |
580 | | - event, invocation_context, filename, version, task_id, context_id |
581 | | - ) |
582 | | - a2a_events.append(artifact_event) |
583 | 503 |
|
584 | 504 | # Handle error scenarios |
585 | 505 | if event.error_code: |
|
0 commit comments