|
21 | 21 |
|
22 | 22 | import com.google.gson.JsonParser; |
23 | 23 | import com.google.gson.JsonSyntaxException; |
| 24 | +import com.google.gson.reflect.TypeToken; |
24 | 25 | import com.google.protobuf.InvalidProtocolBufferException; |
25 | 26 | import com.google.protobuf.util.JsonFormat; |
26 | 27 | import io.a2a.grpc.utils.ProtoUtils; |
|
62 | 63 | import io.a2a.spec.UnsupportedOperationError; |
63 | 64 | import io.a2a.spec.ExtensionSupportRequiredError; |
64 | 65 | import io.a2a.spec.VersionNotSupportedError; |
| 66 | +import java.lang.reflect.Type; |
| 67 | +import java.util.Collections; |
65 | 68 | import mutiny.zero.ZeroPublisher; |
66 | 69 | import org.jspecify.annotations.Nullable; |
67 | 70 |
|
@@ -144,12 +147,21 @@ public HTTPRestResponse sendStreamingMessage(ServerCallContext context, String t |
144 | 147 | } |
145 | 148 | } |
146 | 149 |
|
147 | | - public HTTPRestResponse cancelTask(ServerCallContext context, String tenant, String taskId) { |
| 150 | + @SuppressWarnings("unchecked") |
| 151 | + public HTTPRestResponse cancelTask(ServerCallContext context, String tenant, String body, String taskId) { |
148 | 152 | try { |
149 | 153 | if (taskId == null || taskId.isEmpty()) { |
150 | 154 | throw new InvalidParamsError(); |
151 | 155 | } |
152 | | - TaskIdParams params = TaskIdParams.builder().id(taskId).tenant(tenant).build(); |
| 156 | + Map<String, Object> metadata = Collections.emptyMap(); |
| 157 | + if (body != null && !body.isEmpty()) { |
| 158 | + Type type = new TypeToken<Map<String, Object>>(){}.getType(); |
| 159 | + Map<String, Object> payload = JsonUtil.fromJson(body, type); |
| 160 | + if(payload.containsKey("metadata") && payload.get("metadata") instanceof Map metadataMap) { |
| 161 | + metadata = (Map<String, Object>) metadataMap; |
| 162 | + } |
| 163 | + } |
| 164 | + TaskIdParams params = TaskIdParams.builder().id(taskId).tenant(tenant).metadata(metadata).build(); |
153 | 165 | Task task = requestHandler.onCancelTask(params, context); |
154 | 166 | if (task != null) { |
155 | 167 | return createSuccessResponse(200, io.a2a.grpc.Task.newBuilder(ProtoUtils.ToProto.task(task))); |
|
0 commit comments