Skip to content

Commit a2499fb

Browse files
authored
feat!: Replace public Builder constructors with static factory methods (#540)
Fixes #498 🦕
1 parent ec0ef92 commit a2499fb

File tree

94 files changed

+1038
-585
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1038
-585
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ public class WeatherAgentCardProducer {
113113
@Produces
114114
@PublicAgentCard
115115
public AgentCard agentCard() {
116-
return new AgentCard.Builder()
116+
return AgentCard.builder()
117117
.name("Weather Agent")
118118
.description("Helps with weather")
119119
.url("http://localhost:10001")
120120
.version("1.0.0")
121-
.capabilities(new AgentCapabilities.Builder()
121+
.capabilities(AgentCapabilities.builder()
122122
.streaming(true)
123123
.pushNotifications(false)
124124
.stateTransitionHistory(false)
125125
.build())
126126
.defaultInputModes(Collections.singletonList("text"))
127127
.defaultOutputModes(Collections.singletonList("text"))
128-
.skills(Collections.singletonList(new AgentSkill.Builder()
128+
.skills(Collections.singletonList(AgentSkill.builder()
129129
.id("weather_search")
130130
.name("Search weather")
131131
.description("Helps with weather in cities or states")
@@ -565,12 +565,12 @@ TaskPushNotificationConfig config = client.getTaskPushNotificationConfiguration(
565565

566566
```java
567567
// Set task push notification configuration
568-
PushNotificationConfig pushNotificationConfig = new PushNotificationConfig.Builder()
568+
PushNotificationConfig pushNotificationConfig = PushNotificationConfig.builder()
569569
.url("https://example.com/callback")
570570
.authenticationInfo(new AuthenticationInfo(Collections.singletonList("jwt"), null))
571571
.build();
572572

573-
TaskPushNotificationConfig taskConfig = new TaskPushNotificationConfig.Builder()
573+
TaskPushNotificationConfig taskConfig = TaskPushNotificationConfig.builder()
574574
.taskId("task-1234")
575575
.pushNotificationConfig(pushNotificationConfig)
576576
.build();

client/base/src/main/java/io/a2a/A2A.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private static Message toMessage(String text, Message.Role role, String messageI
106106
}
107107

108108
private static Message toMessage(String text, Message.Role role, String messageId, String contextId, String taskId) {
109-
Message.Builder messageBuilder = new Message.Builder()
109+
Message.Builder messageBuilder = Message.builder()
110110
.role(role)
111111
.parts(Collections.singletonList(new TextPart(text)))
112112
.contextId(contextId)
@@ -118,7 +118,7 @@ private static Message toMessage(String text, Message.Role role, String messageI
118118
}
119119

120120
private static Message toMessage(List<Part<?>> parts, Message.Role role, String messageId, String contextId, String taskId) {
121-
Message.Builder messageBuilder = new Message.Builder()
121+
Message.Builder messageBuilder = Message.builder()
122122
.role(role)
123123
.parts(parts)
124124
.contextId(contextId)

client/base/src/main/java/io/a2a/client/Client.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void sendMessage(@NonNull Message request,
7171
@Nullable ClientCallContext context) throws A2AClientException {
7272
MessageSendConfiguration messageSendConfiguration = createMessageSendConfiguration(pushNotificationConfiguration);
7373

74-
MessageSendParams messageSendParams = new MessageSendParams.Builder()
74+
MessageSendParams messageSendParams = MessageSendParams.builder()
7575
.message(request)
7676
.configuration(messageSendConfiguration)
7777
.metadata(metadata)
@@ -169,7 +169,7 @@ private ClientEvent getClientEvent(StreamingEventKind event, ClientTaskManager t
169169
}
170170

171171
private MessageSendConfiguration createMessageSendConfiguration(@Nullable PushNotificationConfig pushNotificationConfig) {
172-
return new MessageSendConfiguration.Builder()
172+
return MessageSendConfiguration.builder()
173173
.acceptedOutputModes(clientConfig.getAcceptedOutputModes())
174174
.blocking(!clientConfig.isPolling())
175175
.historyLength(clientConfig.getHistoryLength())
@@ -225,7 +225,7 @@ private void consume(ClientEvent clientEvent, AgentCard agentCard, @NonNull List
225225
private MessageSendParams getMessageSendParams(Message request, ClientConfig clientConfig) {
226226
MessageSendConfiguration messageSendConfiguration = createMessageSendConfiguration(clientConfig.getPushNotificationConfig());
227227

228-
return new MessageSendParams.Builder()
228+
return MessageSendParams.builder()
229229
.message(request)
230230
.configuration(messageSendConfiguration)
231231
.metadata(clientConfig.getMetadata())

client/base/src/main/java/io/a2a/client/ClientTaskManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ public Task saveTaskEvent(TaskStatusUpdateEvent taskStatusUpdateEvent) throws A2
5959
}
6060
Task task = currentTask;
6161
if (task == null) {
62-
task = new Task.Builder()
62+
task = Task.builder()
6363
.status(new TaskStatus(TaskState.UNKNOWN))
6464
.id(taskId)
6565
.contextId(contextId == null ? "" : contextId)
6666
.build();
6767
}
6868

69-
Task.Builder taskBuilder = new Task.Builder(task);
69+
Task.Builder taskBuilder = Task.builder(task);
7070
if (taskStatusUpdateEvent.getStatus().message() != null) {
7171
if (task.getHistory() == null) {
7272
taskBuilder.history(taskStatusUpdateEvent.getStatus().message());
@@ -95,7 +95,7 @@ public Task saveTaskEvent(TaskArtifactUpdateEvent taskArtifactUpdateEvent) {
9595
}
9696
Task task = currentTask;
9797
if (task == null) {
98-
task = new Task.Builder()
98+
task = Task.builder()
9999
.status(new TaskStatus(TaskState.UNKNOWN))
100100
.id(taskId)
101101
.contextId(contextId == null ? "" : contextId)
@@ -114,7 +114,7 @@ public Task saveTaskEvent(TaskArtifactUpdateEvent taskArtifactUpdateEvent) {
114114
* @return the updated task
115115
*/
116116
public Task updateWithMessage(Message message, Task task) {
117-
Task.Builder taskBuilder = new Task.Builder(task);
117+
Task.Builder taskBuilder = Task.builder(task);
118118
List<Message> history = task.getHistory();
119119
if (history == null) {
120120
history = new ArrayList<>();

client/base/src/test/java/io/a2a/client/AuthenticationAuthorizationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class AuthenticationAuthorizationTest {
6565
@BeforeEach
6666
public void setUp() {
6767
server = new ClientAndServer(4001);
68-
MESSAGE = new Message.Builder()
68+
MESSAGE = Message.builder()
6969
.role(Message.Role.USER)
7070
.parts(Collections.singletonList(new TextPart("test message")))
7171
.contextId("context-1234")
@@ -74,16 +74,16 @@ public void setUp() {
7474

7575
grpcServerName = InProcessServerBuilder.generateName();
7676

77-
agentCard = new AgentCard.Builder()
77+
agentCard = AgentCard.builder()
7878
.name("Test Agent")
7979
.description("Test agent for auth tests")
8080
.version("1.0.0")
81-
.capabilities(new AgentCapabilities.Builder()
81+
.capabilities(AgentCapabilities.builder()
8282
.streaming(true) // Support streaming for all tests
8383
.build())
8484
.defaultInputModes(Collections.singletonList("text"))
8585
.defaultOutputModes(Collections.singletonList("text"))
86-
.skills(Collections.singletonList(new AgentSkill.Builder()
86+
.skills(Collections.singletonList(AgentSkill.builder()
8787
.id("test_skill")
8888
.name("Test skill")
8989
.description("Test skill")

client/base/src/test/java/io/a2a/client/ClientBuilderTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,28 @@
2121

2222
public class ClientBuilderTest {
2323

24-
private AgentCard card = new AgentCard.Builder()
24+
private AgentCard card = AgentCard.builder()
2525
.name("Hello World Agent")
2626
.description("Just a hello world agent")
27-
.supportedInterfaces(Collections.singletonList(new AgentInterface("jsonrpc", "http://localhost:9999")))
2827
.version("1.0.0")
2928
.documentationUrl("http://example.com/docs")
30-
.capabilities(new AgentCapabilities.Builder()
29+
.capabilities(AgentCapabilities.builder()
3130
.streaming(true)
3231
.pushNotifications(true)
3332
.stateTransitionHistory(true)
3433
.build())
3534
.defaultInputModes(Collections.singletonList("text"))
3635
.defaultOutputModes(Collections.singletonList("text"))
37-
.skills(Collections.singletonList(new AgentSkill.Builder()
36+
.skills(Collections.singletonList(AgentSkill.builder()
3837
.id("hello_world")
3938
.name("Returns hello world")
4039
.description("just returns hello world")
4140
.tags(Collections.singletonList("hello world"))
4241
.examples(List.of("hi", "hello world"))
4342
.build()))
4443
.protocolVersion("0.3.0")
45-
.additionalInterfaces(List.of(
46-
new AgentInterface(TransportProtocol.JSONRPC.asString(), "http://localhost:9999")))
44+
.supportedInterfaces(List.of(
45+
new AgentInterface(TransportProtocol.JSONRPC.asString(), "http://localhost:9999")))
4746
.build();
4847

4948
@Test

client/transport/jsonrpc/src/main/java/io/a2a/client/transport/jsonrpc/JSONRPCTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public AgentCard getAgentCard(@Nullable ClientCallContext context) throws A2ACli
301301
return agentCard;
302302
}
303303

304-
GetAuthenticatedExtendedCardRequest getExtendedAgentCardRequest = new GetAuthenticatedExtendedCardRequest.Builder()
304+
GetAuthenticatedExtendedCardRequest getExtendedAgentCardRequest = GetAuthenticatedExtendedCardRequest.builder()
305305
.jsonrpc(JSONRPCMessage.JSONRPC_VERSION)
306306
.build(); // id will be randomly generated
307307

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JSONRPCTransportStreamingTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,19 @@ public void tearDown() {
5454
public void testSendStreamingMessageParams() {
5555
// The goal here is just to verify the correct parameters are being used
5656
// This is a unit test of the parameter construction, not the streaming itself
57-
Message message = new Message.Builder()
57+
Message message = Message.builder()
5858
.role(Message.Role.USER)
5959
.parts(Collections.singletonList(new TextPart("test message")))
6060
.contextId("context-test")
6161
.messageId("message-test")
6262
.build();
6363

64-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
64+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
6565
.acceptedOutputModes(List.of("text"))
6666
.blocking(false)
6767
.build();
6868

69-
MessageSendParams params = new MessageSendParams.Builder()
69+
MessageSendParams params = MessageSendParams.builder()
7070
.message(message)
7171
.configuration(configuration)
7272
.build();
@@ -95,17 +95,17 @@ public void testA2AClientSendStreamingMessage() throws Exception {
9595
);
9696

9797
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
98-
Message message = new Message.Builder()
98+
Message message = Message.builder()
9999
.role(Message.Role.USER)
100100
.parts(Collections.singletonList(new TextPart("tell me some jokes")))
101101
.contextId("context-1234")
102102
.messageId("message-1234")
103103
.build();
104-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
104+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
105105
.acceptedOutputModes(List.of("text"))
106106
.blocking(false)
107107
.build();
108-
MessageSendParams params = new MessageSendParams.Builder()
108+
MessageSendParams params = MessageSendParams.builder()
109109
.message(message)
110110
.configuration(configuration)
111111
.build();

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/JSONRPCTransportTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,17 @@ public void testA2AClientSendMessage() throws Exception {
104104
);
105105

106106
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
107-
Message message = new Message.Builder()
107+
Message message = Message.builder()
108108
.role(Message.Role.USER)
109109
.parts(Collections.singletonList(new TextPart("tell me a joke")))
110110
.contextId("context-1234")
111111
.messageId("message-1234")
112112
.build();
113-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
113+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
114114
.acceptedOutputModes(List.of("text"))
115115
.blocking(true)
116116
.build();
117-
MessageSendParams params = new MessageSendParams.Builder()
117+
MessageSendParams params = MessageSendParams.builder()
118118
.message(message)
119119
.configuration(configuration)
120120
.build();
@@ -152,17 +152,17 @@ public void testA2AClientSendMessageWithMessageResponse() throws Exception {
152152
);
153153

154154
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
155-
Message message = new Message.Builder()
155+
Message message = Message.builder()
156156
.role(Message.Role.USER)
157157
.parts(Collections.singletonList(new TextPart("tell me a joke")))
158158
.contextId("context-1234")
159159
.messageId("message-1234")
160160
.build();
161-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
161+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
162162
.acceptedOutputModes(List.of("text"))
163163
.blocking(true)
164164
.build();
165-
MessageSendParams params = new MessageSendParams.Builder()
165+
MessageSendParams params = MessageSendParams.builder()
166166
.message(message)
167167
.configuration(configuration)
168168
.build();
@@ -194,17 +194,17 @@ public void testA2AClientSendMessageWithError() throws Exception {
194194
);
195195

196196
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
197-
Message message = new Message.Builder()
197+
Message message = Message.builder()
198198
.role(Message.Role.USER)
199199
.parts(Collections.singletonList(new TextPart("tell me a joke")))
200200
.contextId("context-1234")
201201
.messageId("message-1234")
202202
.build();
203-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
203+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
204204
.acceptedOutputModes(List.of("text"))
205205
.blocking(true)
206206
.build();
207-
MessageSendParams params = new MessageSendParams.Builder()
207+
MessageSendParams params = MessageSendParams.builder()
208208
.message(message)
209209
.configuration(configuration)
210210
.build();
@@ -339,10 +339,10 @@ public void testA2AClientSetTaskPushNotificationConfig() throws Exception {
339339
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
340340
TaskPushNotificationConfig taskPushNotificationConfig = client.setTaskPushNotificationConfiguration(
341341
new TaskPushNotificationConfig("de38c76d-d54c-436c-8b9f-4c2703648d64",
342-
new PushNotificationConfig.Builder()
342+
PushNotificationConfig.builder()
343343
.id("c295ea44-7543-4f78-b524-7a38915ad6e4")
344344
.url("https://example.com/callback")
345-
.authenticationInfo(new AuthenticationInfo(Collections.singletonList("jwt"),
345+
.authentication(new AuthenticationInfo(Collections.singletonList("jwt"),
346346
null))
347347
.build()), null);
348348
PushNotificationConfig pushNotificationConfig = taskPushNotificationConfig.pushNotificationConfig();
@@ -532,7 +532,7 @@ public void testA2AClientSendMessageWithFilePart() throws Exception {
532532
);
533533

534534
JSONRPCTransport client = new JSONRPCTransport("http://localhost:4001");
535-
Message message = new Message.Builder()
535+
Message message = Message.builder()
536536
.role(Message.Role.USER)
537537
.parts(List.of(
538538
new TextPart("analyze this image"),
@@ -541,11 +541,11 @@ public void testA2AClientSendMessageWithFilePart() throws Exception {
541541
.contextId("context-1234")
542542
.messageId("message-1234-with-file")
543543
.build();
544-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
544+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
545545
.acceptedOutputModes(List.of("text"))
546546
.blocking(true)
547547
.build();
548-
MessageSendParams params = new MessageSendParams.Builder()
548+
MessageSendParams params = MessageSendParams.builder()
549549
.message(message)
550550
.configuration(configuration)
551551
.build();
@@ -592,7 +592,7 @@ public void testA2AClientSendMessageWithDataPart() throws Exception {
592592
data.put("location", "San Francisco");
593593
data.put("timestamp", "2024-01-15T10:30:00Z");
594594

595-
Message message = new Message.Builder()
595+
Message message = Message.builder()
596596
.role(Message.Role.USER)
597597
.parts(List.of(
598598
new TextPart("process this data"),
@@ -601,11 +601,11 @@ public void testA2AClientSendMessageWithDataPart() throws Exception {
601601
.contextId("context-1234")
602602
.messageId("message-1234-with-data")
603603
.build();
604-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
604+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
605605
.acceptedOutputModes(List.of("text"))
606606
.blocking(true)
607607
.build();
608-
MessageSendParams params = new MessageSendParams.Builder()
608+
MessageSendParams params = MessageSendParams.builder()
609609
.message(message)
610610
.configuration(configuration)
611611
.build();
@@ -649,7 +649,7 @@ public void testA2AClientSendMessageWithMixedParts() throws Exception {
649649
data.put("dataPoints", List.of(10, 20, 30, 40));
650650
data.put("labels", List.of("Q1", "Q2", "Q3", "Q4"));
651651

652-
Message message = new Message.Builder()
652+
Message message = Message.builder()
653653
.role(Message.Role.USER)
654654
.parts(List.of(
655655
new TextPart("analyze this data and image"),
@@ -659,11 +659,11 @@ public void testA2AClientSendMessageWithMixedParts() throws Exception {
659659
.contextId("context-1234")
660660
.messageId("message-1234-with-mixed")
661661
.build();
662-
MessageSendConfiguration configuration = new MessageSendConfiguration.Builder()
662+
MessageSendConfiguration configuration = MessageSendConfiguration.builder()
663663
.acceptedOutputModes(List.of("text"))
664664
.blocking(true)
665665
.build();
666-
MessageSendParams params = new MessageSendParams.Builder()
666+
MessageSendParams params = MessageSendParams.builder()
667667
.message(message)
668668
.configuration(configuration)
669669
.build();

client/transport/jsonrpc/src/test/java/io/a2a/client/transport/jsonrpc/sse/SSEEventListenerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void testOnFailure() {
185185

186186
@Test
187187
public void testFinalTaskStatusUpdateEventCancels() {
188-
TaskStatusUpdateEvent tsue = new TaskStatusUpdateEvent.Builder()
188+
TaskStatusUpdateEvent tsue = TaskStatusUpdateEvent.builder()
189189
.taskId("1234")
190190
.contextId("xyz")
191191
.status(new TaskStatus(TaskState.COMPLETED))

0 commit comments

Comments
 (0)