Skip to content

Commit 8317c08

Browse files
committed
fix: Apply Gemini fixes
1 parent ab36702 commit 8317c08

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

client/src/main/java/io/a2a/client/A2AGrpcClient.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ public EventKind sendMessage(MessageSendParams messageSendParams) throws A2AServ
7171
} else if (response.hasTask()) {
7272
return FromProto.task(response.getTask());
7373
} else {
74-
throw new A2AServerException("Failed to send message: ");
74+
throw new A2AServerException("Server response did not contain a message or task");
7575
}
7676
} catch (StatusRuntimeException e) {
77-
throw new A2AServerException("Failed to send message: " + e, e.getCause());
77+
throw new A2AServerException("Failed to send message: " + e, e);
7878
}
7979
}
8080

@@ -95,7 +95,7 @@ public Task getTask(TaskQueryParams taskQueryParams) throws A2AServerException {
9595
try {
9696
return FromProto.task(blockingStub.getTask(getTaskRequest));
9797
} catch (StatusRuntimeException e) {
98-
throw new A2AServerException("Failed to get task: " + e, e.getCause());
98+
throw new A2AServerException("Failed to get task: " + e, e);
9999
}
100100
}
101101

@@ -113,7 +113,7 @@ public Task cancelTask(TaskIdParams taskIdParams) throws A2AServerException {
113113
try {
114114
return FromProto.task(blockingStub.cancelTask(cancelTaskRequest));
115115
} catch (StatusRuntimeException e) {
116-
throw new A2AServerException("Failed to cancel task: " + e, e.getCause());
116+
throw new A2AServerException("Failed to cancel task: " + e, e);
117117
}
118118
}
119119

@@ -125,13 +125,16 @@ public Task cancelTask(TaskIdParams taskIdParams) throws A2AServerException {
125125
* @throws A2AServerException if setting the push notification configuration fails for any reason
126126
*/
127127
public TaskPushNotificationConfig setTaskPushNotificationConfig(TaskPushNotificationConfig taskPushNotificationConfig) throws A2AServerException {
128+
String configId = taskPushNotificationConfig.pushNotificationConfig().id();
128129
CreateTaskPushNotificationConfigRequest request = CreateTaskPushNotificationConfigRequest.newBuilder()
130+
.setParent("tasks/" + taskPushNotificationConfig.taskId())
129131
.setConfig(ToProto.taskPushNotificationConfig(taskPushNotificationConfig))
132+
.setConfigId(configId == null ? "" : configId)
130133
.build();
131134
try {
132135
return FromProto.taskPushNotificationConfig(blockingStub.createTaskPushNotificationConfig(request));
133136
} catch (StatusRuntimeException e) {
134-
throw new A2AServerException("Failed to set the task push notification config: " + e, e.getCause());
137+
throw new A2AServerException("Failed to set the task push notification config: " + e, e);
135138
}
136139
}
137140

@@ -149,7 +152,7 @@ public TaskPushNotificationConfig getTaskPushNotificationConfig(GetTaskPushNotif
149152
try {
150153
return FromProto.taskPushNotificationConfig(blockingStub.getTaskPushNotificationConfig(getTaskPushNotificationConfigRequest));
151154
} catch (StatusRuntimeException e) {
152-
throw new A2AServerException("Failed to get the task push notification config: " + e, e.getCause());
155+
throw new A2AServerException("Failed to get the task push notification config: " + e, e);
153156
}
154157
}
155158

@@ -168,7 +171,7 @@ public void sendMessageStreaming(MessageSendParams messageSendParams, Consumer<S
168171
try {
169172
asyncStub.sendStreamingMessage(request, streamObserver);
170173
} catch (StatusRuntimeException e) {
171-
throw new A2AServerException("Failed to send streaming message: " + e, e.getCause());
174+
throw new A2AServerException("Failed to send streaming message: " + e, e);
172175
}
173176
}
174177

@@ -189,7 +192,7 @@ private String getTaskPushNotificationConfigName(GetTaskPushNotificationConfigPa
189192
name.append("tasks/");
190193
name.append(getTaskPushNotificationConfigParams.id());
191194
if (getTaskPushNotificationConfigParams.pushNotificationConfigId() != null) {
192-
name.append("pushNotification/");
195+
name.append("/pushNotificationConfigs/");
193196
name.append(getTaskPushNotificationConfigParams.pushNotificationConfigId());
194197
}
195198
return name.toString();

client/src/main/java/io/a2a/client/sse/SSEStreamObserver.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@ public SSEStreamObserver(Consumer<StreamingEventKind> eventHandler, Consumer<Thr
2424
@Override
2525
public void onNext(StreamResponse response) {
2626
StreamingEventKind event;
27-
if (response.hasMsg()) {
28-
event = FromProto.message(response.getMsg());
29-
} else if (response.hasTask()) {
30-
event = FromProto.task(response.getTask());
31-
} else if (response.hasStatusUpdate()) {
32-
event = FromProto.taskStatusUpdateEvent(response.getStatusUpdate());
33-
} else if (response.hasArtifactUpdate()) {
34-
event = FromProto.taskArtifactUpdateEvent(response.getArtifactUpdate());
35-
} else {
36-
log.warning("Invalid stream response " + response);
37-
return;
27+
switch (response.getPayloadCase()) {
28+
case MSG:
29+
event = FromProto.message(response.getMsg());
30+
break;
31+
case TASK:
32+
event = FromProto.task(response.getTask());
33+
break;
34+
case STATUS_UPDATE:
35+
event = FromProto.taskStatusUpdateEvent(response.getStatusUpdate());
36+
break;
37+
case ARTIFACT_UPDATE:
38+
event = FromProto.taskArtifactUpdateEvent(response.getArtifactUpdate());
39+
break;
40+
default:
41+
log.warning("Invalid stream response " + response.getPayloadCase());
42+
errorHandler.accept(new IllegalStateException("Invalid stream response from server: " + response.getPayloadCase()));
43+
return;
3844
}
3945
eventHandler.accept(event);
4046
}

grpc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@
3636
</dependency>
3737
</dependencies>
3838

39-
</project>
39+
</project>

0 commit comments

Comments
 (0)