|
32 | 32 | import io.a2a.grpc.mapper.OAuthFlowsMapper; |
33 | 33 | import io.a2a.grpc.mapper.OpenIdConnectSecuritySchemeMapper; |
34 | 34 | import io.a2a.grpc.mapper.PasswordOAuthFlowMapper; |
| 35 | +import io.a2a.grpc.mapper.PushNotificationConfigMapper; |
35 | 36 | import io.a2a.grpc.mapper.SecuritySchemeMapper; |
| 37 | +import io.a2a.grpc.mapper.TaskStateMapper; |
36 | 38 | import io.a2a.spec.APIKeySecurityScheme; |
37 | 39 | import io.a2a.spec.AgentCapabilities; |
38 | 40 | import io.a2a.spec.AgentCard; |
@@ -148,20 +150,7 @@ public static io.a2a.grpc.TaskPushNotificationConfig taskPushNotificationConfig( |
148 | 150 | } |
149 | 151 |
|
150 | 152 | private static io.a2a.grpc.PushNotificationConfig pushNotificationConfig(PushNotificationConfig config) { |
151 | | - io.a2a.grpc.PushNotificationConfig.Builder builder = io.a2a.grpc.PushNotificationConfig.newBuilder(); |
152 | | - if (config.url() != null) { |
153 | | - builder.setUrl(config.url()); |
154 | | - } |
155 | | - if (config.token() != null) { |
156 | | - builder.setToken(config.token()); |
157 | | - } |
158 | | - if (config.authentication() != null) { |
159 | | - builder.setAuthentication(authenticationInfo(config.authentication())); |
160 | | - } |
161 | | - if (config.id() != null) { |
162 | | - builder.setId(config.id()); |
163 | | - } |
164 | | - return builder.build(); |
| 153 | + return PushNotificationConfigMapper.INSTANCE.toProto(config); |
165 | 154 | } |
166 | 155 |
|
167 | 156 | public static io.a2a.grpc.TaskArtifactUpdateEvent taskArtifactUpdateEvent(TaskArtifactUpdateEvent event) { |
@@ -275,29 +264,7 @@ private static io.a2a.grpc.TaskStatus taskStatus(TaskStatus taskStatus) { |
275 | 264 | } |
276 | 265 |
|
277 | 266 | public static io.a2a.grpc.TaskState taskState(TaskState taskState) { |
278 | | - if (taskState == null) { |
279 | | - return io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED; |
280 | | - } |
281 | | - return switch (taskState) { |
282 | | - case SUBMITTED -> |
283 | | - io.a2a.grpc.TaskState.TASK_STATE_SUBMITTED; |
284 | | - case WORKING -> |
285 | | - io.a2a.grpc.TaskState.TASK_STATE_WORKING; |
286 | | - case INPUT_REQUIRED -> |
287 | | - io.a2a.grpc.TaskState.TASK_STATE_INPUT_REQUIRED; |
288 | | - case AUTH_REQUIRED -> |
289 | | - io.a2a.grpc.TaskState.TASK_STATE_AUTH_REQUIRED; |
290 | | - case COMPLETED -> |
291 | | - io.a2a.grpc.TaskState.TASK_STATE_COMPLETED; |
292 | | - case CANCELED -> |
293 | | - io.a2a.grpc.TaskState.TASK_STATE_CANCELLED; |
294 | | - case FAILED -> |
295 | | - io.a2a.grpc.TaskState.TASK_STATE_FAILED; |
296 | | - case REJECTED -> |
297 | | - io.a2a.grpc.TaskState.TASK_STATE_REJECTED; |
298 | | - default -> |
299 | | - io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED; |
300 | | - }; |
| 267 | + return TaskStateMapper.INSTANCE.toProto(taskState); |
301 | 268 | } |
302 | 269 |
|
303 | 270 | private static io.a2a.grpc.AuthenticationInfo authenticationInfo(AuthenticationInfo authenticationInfo) { |
@@ -658,12 +625,13 @@ private static MessageSendConfiguration messageSendConfiguration(io.a2a.grpc.Sen |
658 | 625 | if(pushNotification == null || pushNotification.getDefaultInstanceForType().equals(pushNotification)) { |
659 | 626 | return null; |
660 | 627 | } |
661 | | - return new PushNotificationConfig( |
662 | | - pushNotification.getUrl(), |
663 | | - pushNotification.getToken().isEmpty() ? null : pushNotification.getToken(), |
664 | | - pushNotification.hasAuthentication() ? authenticationInfo(pushNotification.getAuthentication()) : null, |
665 | | - pushNotification.getId().isEmpty() ? configId : pushNotification.getId() |
666 | | - ); |
| 628 | + io.a2a.grpc.PushNotificationConfig proto = (io.a2a.grpc.PushNotificationConfig) pushNotification; |
| 629 | + PushNotificationConfig result = PushNotificationConfigMapper.INSTANCE.fromProto(proto); |
| 630 | + // Override ID if different configId provided |
| 631 | + if (configId != null && !configId.isEmpty() && !configId.equals(result.id())) { |
| 632 | + return new PushNotificationConfig(result.url(), result.token(), result.authentication(), configId); |
| 633 | + } |
| 634 | + return result; |
667 | 635 | } |
668 | 636 |
|
669 | 637 | private static @Nullable PushNotificationConfig pushNotification(io.a2a.grpc.PushNotificationConfigOrBuilder pushNotification) { |
@@ -793,31 +761,11 @@ private static DataPart dataPart(io.a2a.grpc.DataPartOrBuilder dataPart) { |
793 | 761 | } |
794 | 762 |
|
795 | 763 | private static @Nullable TaskState taskState(io.a2a.grpc.TaskState taskState) { |
796 | | - if (taskState == null) { |
| 764 | + if (taskState == null || taskState == io.a2a.grpc.TaskState.TASK_STATE_UNSPECIFIED) { |
797 | 765 | return null; |
798 | 766 | } |
799 | | - return switch (taskState) { |
800 | | - case TASK_STATE_SUBMITTED -> |
801 | | - TaskState.SUBMITTED; |
802 | | - case TASK_STATE_WORKING -> |
803 | | - TaskState.WORKING; |
804 | | - case TASK_STATE_INPUT_REQUIRED -> |
805 | | - TaskState.INPUT_REQUIRED; |
806 | | - case TASK_STATE_AUTH_REQUIRED -> |
807 | | - TaskState.AUTH_REQUIRED; |
808 | | - case TASK_STATE_COMPLETED -> |
809 | | - TaskState.COMPLETED; |
810 | | - case TASK_STATE_CANCELLED -> |
811 | | - TaskState.CANCELED; |
812 | | - case TASK_STATE_FAILED -> |
813 | | - TaskState.FAILED; |
814 | | - case TASK_STATE_REJECTED -> |
815 | | - TaskState.REJECTED; |
816 | | - case TASK_STATE_UNSPECIFIED -> |
817 | | - null; |
818 | | - case UNRECOGNIZED -> |
819 | | - null; |
820 | | - }; |
| 767 | + TaskState result = TaskStateMapper.INSTANCE.fromProto(taskState); |
| 768 | + return result == TaskState.UNKNOWN ? null : result; |
821 | 769 | } |
822 | 770 |
|
823 | 771 | private static @Nullable Map<String, Object> struct(Struct struct) { |
|
0 commit comments