Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ public static com.google.genai.types.Part toGenaiPart(io.a2a.spec.Part<?> a2aPar
com.google.genai.types.Part.Builder partBuilder =
com.google.genai.types.Part.builder().text(textPart.getText());
if (textPart.getMetadata() != null) {
partBuilder.partMetadata(textPart.getMetadata());
if (Objects.equals(textPart.getMetadata().get("thought"), true)) {
partBuilder.thought(true);
}
if (!textPart.getMetadata().isEmpty()) {
partBuilder.partMetadata(textPart.getMetadata());
}
}
return partBuilder.build();
}
Expand Down Expand Up @@ -122,7 +124,7 @@ private static com.google.genai.types.Part convertFilePartToGenAiPart(FilePart f
.fileUri(fileWithUri.uri())
.mimeType(fileWithUri.mimeType())
.build());
if (metadata != null) {
if (metadata != null && !metadata.isEmpty()) {
builder.partMetadata(metadata);
}
return builder.build();
Expand All @@ -137,7 +139,7 @@ private static com.google.genai.types.Part convertFilePartToGenAiPart(FilePart f
com.google.genai.types.Part.Builder builder =
com.google.genai.types.Part.builder()
.inlineData(Blob.builder().data(decoded).mimeType(fileWithBytes.mimeType()).build());
if (metadata != null) {
if (metadata != null && !metadata.isEmpty()) {
builder.partMetadata(metadata);
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,27 @@ public void toGenaiPart_dataPartWithNonMapCoercedToMap() {
assertThat(result.functionCall().get().args()).hasValue(ImmutableMap.of("value", 123));
}

@Test
public void toGenaiPart_withTextPartEmptyMetadata_doesNotSetPartMetadata() {
TextPart textPart = new TextPart("Hello", ImmutableMap.of());

Part result = PartConverter.toGenaiPart(textPart);

assertThat(result.text()).hasValue("Hello");
assertThat(result.partMetadata()).isEmpty();
}

@Test
public void toGenaiPart_withFilePartEmptyMetadata_doesNotSetPartMetadata() {
FilePart filePart =
new FilePart(
new FileWithUri("text/plain", "file.txt", "http://file.txt"), ImmutableMap.of());

Part result = PartConverter.toGenaiPart(filePart);

assertThat(result.partMetadata()).isEmpty();
}

@Test
public void toGenaiPart_withTextPartMetadata_propagatesMetadata() {
TextPart textPart = new TextPart("Hello", ImmutableMap.of("key", "value"));
Expand Down
Loading