Skip to content

Commit 29d2022

Browse files
committed
Refactor code structure for improved readability and maintainability.
1 parent c0b6747 commit 29d2022

5 files changed

Lines changed: 1283 additions & 131 deletions

File tree

src/main/java/com/github/copilot/sdk/CopilotSession.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ public CompletableFuture<List<AbstractSessionEvent>> getMessages() {
750750
if (response.getEvents() != null) {
751751
for (JsonNode eventNode : response.getEvents()) {
752752
try {
753-
AbstractSessionEvent event = SessionEventParser.parse(eventNode.toString());
753+
AbstractSessionEvent event = SessionEventParser.parse(eventNode);
754754
if (event != null) {
755755
events.add(event);
756756
}

src/main/java/com/github/copilot/sdk/RpcHandlerDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void handleSessionEvent(JsonNode params) {
8282

8383
CopilotSession session = sessions.get(sessionId);
8484
if (session != null && eventNode != null) {
85-
AbstractSessionEvent event = SessionEventParser.parse(eventNode.toString());
85+
AbstractSessionEvent event = SessionEventParser.parse(eventNode);
8686
if (event != null) {
8787
session.dispatchEvent(event);
8888
}

src/main/java/com/github/copilot/sdk/events/SessionEventParser.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -88,36 +88,6 @@ public class SessionEventParser {
8888
TYPE_MAP.put("skill.invoked", SkillInvokedEvent.class);
8989
}
9090

91-
/**
92-
* Parses a JSON string into the appropriate SessionEvent subclass.
93-
*
94-
* @param json
95-
* the JSON string representing an event
96-
* @return the parsed event, or {@code null} if parsing fails or type is unknown
97-
*/
98-
public static AbstractSessionEvent parse(String json) {
99-
try {
100-
JsonNode node = MAPPER.readTree(json);
101-
String type = node.has("type") ? node.get("type").asText() : null;
102-
103-
if (type == null) {
104-
LOG.warning("Missing 'type' field in event: " + json);
105-
return null;
106-
}
107-
108-
Class<? extends AbstractSessionEvent> eventClass = TYPE_MAP.get(type);
109-
if (eventClass == null) {
110-
LOG.fine("Unknown event type: " + type);
111-
return null;
112-
}
113-
114-
return MAPPER.treeToValue(node, eventClass);
115-
} catch (Exception e) {
116-
LOG.log(Level.SEVERE, "Failed to parse session event", e);
117-
return null;
118-
}
119-
}
120-
12191
/**
12292
* Parses a JsonNode into the appropriate SessionEvent subclass.
12393
*

src/test/java/com/github/copilot/sdk/MetadataApiTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private static String findCopilotInPath() {
8181
// ===== ToolExecutionProgressEvent Tests =====
8282

8383
@Test
84-
void testToolExecutionProgressEventParsing() {
84+
void testToolExecutionProgressEventParsing() throws Exception {
8585
String json = """
8686
{
8787
"type": "tool.execution_progress",
@@ -94,7 +94,7 @@ void testToolExecutionProgressEventParsing() {
9494
}
9595
""";
9696

97-
var event = SessionEventParser.parse(json);
97+
var event = SessionEventParser.parse(MAPPER.readTree(json));
9898

9999
assertNotNull(event);
100100
assertInstanceOf(ToolExecutionProgressEvent.class, event);

0 commit comments

Comments
 (0)