Skip to content
Merged
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 @@ -43,6 +43,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -80,7 +81,13 @@ public static com.google.genai.types.Part toGenaiPart(io.a2a.spec.Part<?> a2aPar
}

if (a2aPart instanceof TextPart textPart) {
return com.google.genai.types.Part.builder().text(textPart.getText()).build();
com.google.genai.types.Part.Builder partBuilder =
com.google.genai.types.Part.builder().text(textPart.getText());
if (textPart.getMetadata() != null
&& Objects.equals(textPart.getMetadata().get("thought"), Boolean.TRUE)) {
partBuilder.thought(true);
}
return partBuilder.build();
}

if (a2aPart instanceof FilePart filePart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,46 @@ public void toGenaiPart_withTextPart_returnsGenaiTextPart() {
assertThat(result.text()).hasValue("Hello");
}

@Test
public void toGenaiPart_withTextPartThought_returnsGenaiTextPartWithThought() {
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", true));

Part result = PartConverter.toGenaiPart(textPart);

assertThat(result.text()).hasValue("Thinking process");
assertThat(result.thought()).hasValue(true);
}

@Test
public void toGenaiPart_withTextPartMetadataWithoutThought_returnsGenaiTextPartWithoutThought() {
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("otherKey", "value"));

Part result = PartConverter.toGenaiPart(textPart);

assertThat(result.text()).hasValue("Thinking process");
assertThat(result.thought()).isEmpty();
}

@Test
public void toGenaiPart_withTextPartThoughtFalse_returnsGenaiTextPartWithoutThought() {
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", false));

Part result = PartConverter.toGenaiPart(textPart);

assertThat(result.text()).hasValue("Thinking process");
assertThat(result.thought()).isEmpty();
}

@Test
public void toGenaiPart_withTextPartNonBooleanThought_returnsGenaiTextPartWithoutThought() {
TextPart textPart = new TextPart("Thinking process", ImmutableMap.of("thought", "true"));

Part result = PartConverter.toGenaiPart(textPart);

assertThat(result.text()).hasValue("Thinking process");
assertThat(result.thought()).isEmpty();
}

@Test
public void toGenaiPart_withFilePartUri_returnsGenaiFilePart() {
FilePart filePart = new FilePart(new FileWithUri("text/plain", "file.txt", "http://file.txt"));
Expand Down
Loading