Skip to content

Commit 5a44143

Browse files
committed
refactor: use TransportProtocol enum in examples AgentCardProducer
Replace the raw string switch statement with an exhaustive switch expression based on the TransportProtocol enum. Using fromString() provides fail-fast validation on invalid config values, and removing the default clause enforces compile-time updates when new protocols are added to the enum.
1 parent 05597d2 commit 5a44143

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
package io.a2a.examples.helloworld;
22

3-
4-
import java.util.Collections;
5-
import java.util.List;
6-
3+
import io.a2a.server.PublicAgentCard;
4+
import io.a2a.spec.*;
75
import jakarta.enterprise.context.ApplicationScoped;
86
import jakarta.enterprise.inject.Produces;
9-
10-
import io.a2a.server.PublicAgentCard;
11-
import io.a2a.spec.AgentCapabilities;
12-
import io.a2a.spec.AgentCard;
13-
import io.a2a.spec.AgentInterface;
14-
import io.a2a.spec.AgentSkill;
157
import org.eclipse.microprofile.config.inject.ConfigProperty;
168

9+
import java.util.Collections;
10+
import java.util.List;
11+
1712
@ApplicationScoped
1813
public class AgentCardProducer {
1914

20-
@ConfigProperty(name = "quarkus.agentcard.protocol", defaultValue="JSONRPC")
21-
String protocol;
15+
@ConfigProperty(name = "quarkus.agentcard.protocol", defaultValue = "JSONRPC")
16+
TransportProtocol protocol;
2217

2318
@Produces
2419
@PublicAgentCard
@@ -39,24 +34,20 @@ public AgentCard agentCard() {
3934
.defaultInputModes(Collections.singletonList("text"))
4035
.defaultOutputModes(Collections.singletonList("text"))
4136
.skills(Collections.singletonList(AgentSkill.builder()
42-
.id("hello_world")
43-
.name("Returns hello world")
44-
.description("just returns hello world")
45-
.tags(Collections.singletonList("hello world"))
46-
.examples(List.of("hi", "hello world"))
47-
.build()))
37+
.id("hello_world")
38+
.name("Returns hello world")
39+
.description("just returns hello world")
40+
.tags(Collections.singletonList("hello world"))
41+
.examples(List.of("hi", "hello world"))
42+
.build()))
4843
.build();
4944
}
5045

5146
private AgentInterface getAgentInterface() {
52-
switch(protocol) {
53-
case "GRPC":
54-
return new AgentInterface("GRPC", "localhost:9000");
55-
case "HTTP+JSON":
56-
return new AgentInterface("HTTP+JSON", "http://localhost:9999");
57-
case "JSONRPC":
58-
default:
59-
return new AgentInterface("JSONRPC", "http://localhost:9999");
60-
}
47+
String url = switch (protocol) {
48+
case GRPC -> "localhost:9000";
49+
case JSONRPC, HTTP_JSON -> "http://localhost:9999";
50+
};
51+
return new AgentInterface(protocol.asString(), url);
6152
}
6253
}

0 commit comments

Comments
 (0)