Skip to content

Commit 01572c5

Browse files
ehsavoieclaude
andcommitted
refactor: Update ProtoUtils to use StreamResponseMapper
Updated ProtoUtils.ToProto and ProtoUtils.FromProto to delegate to the new StreamResponseMapper instead of using manual instanceof checks. Changes: - ToProto.streamResponse(): Now delegates to StreamResponseMapper.toProto() instead of manual instanceof pattern matching (removed 20 lines of code) - FromProto.streamingEventKind(): New method that delegates to StreamResponseMapper.fromProto() for converting proto StreamResponse back to domain StreamingEventKind - Added import for StreamResponseMapper This centralizes the conversion logic in the mapper, making the code more maintainable and consistent with the existing mapper pattern used throughout the codebase. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3342383 commit 01572c5

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

spec-grpc/src/main/java/io/a2a/grpc/utils/ProtoUtils.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.a2a.grpc.mapper.MessageSendConfigurationMapper;
1717
import io.a2a.grpc.mapper.MessageSendParamsMapper;
1818
import io.a2a.grpc.mapper.SetTaskPushNotificationConfigMapper;
19+
import io.a2a.grpc.mapper.StreamResponseMapper;
1920
import io.a2a.grpc.mapper.TaskArtifactUpdateEventMapper;
2021
import io.a2a.grpc.mapper.TaskIdParamsMapper;
2122
import io.a2a.grpc.mapper.TaskMapper;
@@ -122,26 +123,7 @@ public static io.a2a.grpc.ListTaskPushNotificationConfigResponse listTaskPushNot
122123
}
123124

124125
public static StreamResponse streamResponse(StreamingEventKind streamingEventKind) {
125-
// This makes a decision and wraps the MapStruct Mappers
126-
if (streamingEventKind instanceof TaskStatusUpdateEvent) {
127-
return StreamResponse.newBuilder()
128-
.setStatusUpdate(taskStatusUpdateEvent((TaskStatusUpdateEvent) streamingEventKind))
129-
.build();
130-
} else if (streamingEventKind instanceof TaskArtifactUpdateEvent) {
131-
return StreamResponse.newBuilder()
132-
.setArtifactUpdate(taskArtifactUpdateEvent((TaskArtifactUpdateEvent) streamingEventKind))
133-
.build();
134-
} else if (streamingEventKind instanceof Message) {
135-
return StreamResponse.newBuilder()
136-
.setMsg(message((Message) streamingEventKind))
137-
.build();
138-
} else if (streamingEventKind instanceof Task) {
139-
return StreamResponse.newBuilder()
140-
.setTask(task((Task) streamingEventKind))
141-
.build();
142-
} else {
143-
throw new IllegalArgumentException("Unsupported event type: " + streamingEventKind);
144-
}
126+
return StreamResponseMapper.INSTANCE.toProto(streamingEventKind);
145127
}
146128

147129
public static io.a2a.grpc.SendMessageResponse taskOrMessage(EventKind eventKind) {
@@ -307,6 +289,13 @@ public static io.a2a.spec.ListTasksResult listTasksResult(io.a2a.grpc.ListTasksR
307289
: ((io.a2a.grpc.ListTasksResponse.Builder) listTasksResponse).build();
308290
return ListTasksResultMapper.INSTANCE.fromProto(eventProto);
309291
}
292+
293+
public static StreamingEventKind streamingEventKind(io.a2a.grpc.StreamResponseOrBuilder streamResponse) {
294+
io.a2a.grpc.StreamResponse streamResponseProto = streamResponse instanceof io.a2a.grpc.StreamResponse
295+
? (io.a2a.grpc.StreamResponse) streamResponse
296+
: ((io.a2a.grpc.StreamResponse.Builder) streamResponse).build();
297+
return StreamResponseMapper.INSTANCE.fromProto(streamResponseProto);
298+
}
310299
}
311300

312301
}

0 commit comments

Comments
 (0)