-
Notifications
You must be signed in to change notification settings - Fork 303
refactor(utils): move part helpers & add artifact text extractor #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
holtskinner
merged 6 commits into
a2aproject:main
from
martimfasantos:task-add-artifact-utils
Oct 21, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8421df
refactored artifact and message; added parts utils
martimfasantos 4f0d2b8
fix linting
martimfasantos 8cd7bac
fixed circular imports
martimfasantos 91a59ae
added tests
martimfasantos 24ec339
Formatting
holtskinner 2939f60
Merge branch 'main' into task-add-artifact-utils
holtskinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| """Utility functions for creating and handling A2A Parts objects.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from a2a.types import ( | ||
| DataPart, | ||
| FilePart, | ||
| FileWithBytes, | ||
| FileWithUri, | ||
| Part, | ||
| TextPart, | ||
| ) | ||
|
|
||
|
|
||
| def get_text_parts(parts: list[Part]) -> list[str]: | ||
| """Extracts text content from all TextPart objects in a list of Parts. | ||
|
|
||
| Args: | ||
| parts: A list of `Part` objects. | ||
|
|
||
| Returns: | ||
| A list of strings containing the text content from any `TextPart` objects found. | ||
| """ | ||
| return [part.root.text for part in parts if isinstance(part.root, TextPart)] | ||
|
|
||
|
|
||
| def get_data_parts(parts: list[Part]) -> list[dict[str, Any]]: | ||
| """Extracts dictionary data from all DataPart objects in a list of Parts. | ||
|
|
||
| Args: | ||
| parts: A list of `Part` objects. | ||
|
|
||
| Returns: | ||
| A list of dictionaries containing the data from any `DataPart` objects found. | ||
| """ | ||
| return [part.root.data for part in parts if isinstance(part.root, DataPart)] | ||
|
|
||
|
|
||
| def get_file_parts(parts: list[Part]) -> list[FileWithBytes | FileWithUri]: | ||
| """Extracts file data from all FilePart objects in a list of Parts. | ||
|
|
||
| Args: | ||
| parts: A list of `Part` objects. | ||
|
|
||
| Returns: | ||
| A list of `FileWithBytes` or `FileWithUri` objects containing the file data from any `FilePart` objects found. | ||
| """ | ||
| return [part.root.file for part in parts if isinstance(part.root, FilePart)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.