13
13
import com .google .protobuf .ByteString ;
14
14
import com .google .protobuf .Struct ;
15
15
import com .google .protobuf .Value ;
16
+ import io .a2a .grpc .ListTaskPushNotificationConfigResponse ;
16
17
17
18
import io .a2a .grpc .StreamResponse ;
18
19
import io .a2a .spec .APIKeySecurityScheme ;
@@ -530,6 +531,15 @@ private static io.a2a.grpc.AuthorizationCodeOAuthFlow authorizationCodeOAuthFlow
530
531
return builder .build ();
531
532
}
532
533
534
+ public static io .a2a .grpc .ListTaskPushNotificationConfigResponse listTaskPushNotificationConfigResponse (List <TaskPushNotificationConfig > configs ) {
535
+ List <io .a2a .grpc .TaskPushNotificationConfig > confs = new ArrayList <>(configs .size ());
536
+ ListTaskPushNotificationConfigResponse .Builder response = ListTaskPushNotificationConfigResponse .newBuilder ();
537
+ for (TaskPushNotificationConfig config : configs ) {
538
+ confs .add (taskPushNotificationConfig (config ));
539
+ }
540
+ return io .a2a .grpc .ListTaskPushNotificationConfigResponse .newBuilder ().addAllConfigs (confs ).build ();
541
+ }
542
+
533
543
private static io .a2a .grpc .ClientCredentialsOAuthFlow clientCredentialsOAuthFlow (ClientCredentialsOAuthFlow clientCredentialsOAuthFlow ) {
534
544
io .a2a .grpc .ClientCredentialsOAuthFlow .Builder builder = io .a2a .grpc .ClientCredentialsOAuthFlow .newBuilder ();
535
545
if (clientCredentialsOAuthFlow .refreshUrl () != null ) {
@@ -699,17 +709,31 @@ public static MessageSendParams messageSendParams(io.a2a.grpc.SendMessageRequest
699
709
}
700
710
701
711
public static TaskPushNotificationConfig taskPushNotificationConfig (io .a2a .grpc .CreateTaskPushNotificationConfigRequestOrBuilder request ) {
702
- return taskPushNotificationConfig (request .getConfig ());
712
+ return taskPushNotificationConfig (request .getConfig (), true );
703
713
}
704
714
705
715
public static TaskPushNotificationConfig taskPushNotificationConfig (io .a2a .grpc .TaskPushNotificationConfigOrBuilder config ) {
716
+ return taskPushNotificationConfig (config , false );
717
+ }
718
+
719
+ private static TaskPushNotificationConfig taskPushNotificationConfig (io .a2a .grpc .TaskPushNotificationConfigOrBuilder config , boolean create ) {
706
720
String name = config .getName (); // "tasks/{id}/pushNotificationConfigs/{push_id}"
707
721
String [] parts = name .split ("/" );
708
- if (parts .length < 4 ) {
709
- throw new IllegalArgumentException ("Invalid name format for TaskPushNotificationConfig: " + name );
722
+ String configId = "" ;
723
+ if (create ) {
724
+ if (parts .length < 3 ) {
725
+ throw new IllegalArgumentException ("Invalid name format for TaskPushNotificationConfig: " + name );
726
+ }
727
+ if (parts .length == 4 ) {
728
+ configId = parts [3 ];
729
+ }
730
+ } else {
731
+ if (parts .length < 4 ) {
732
+ throw new IllegalArgumentException ("Invalid name format for TaskPushNotificationConfig: " + name );
733
+ }
734
+ configId = parts [3 ];
710
735
}
711
736
String taskId = parts [1 ];
712
- String configId = parts [3 ];
713
737
PushNotificationConfig pnc = pushNotification (config .getPushNotificationConfig (), configId );
714
738
return new TaskPushNotificationConfig (taskId , pnc );
715
739
}
@@ -730,13 +754,12 @@ public static TaskIdParams taskIdParams(io.a2a.grpc.TaskSubscriptionRequestOrBui
730
754
String id = name .substring (name .lastIndexOf ('/' ) + 1 );
731
755
return new TaskIdParams (id );
732
756
}
733
-
734
-
757
+
735
758
public static List <TaskPushNotificationConfig > listTaskPushNotificationConfigParams (io .a2a .grpc .ListTaskPushNotificationConfigResponseOrBuilder response ) {
736
759
List <io .a2a .grpc .TaskPushNotificationConfig > configs = response .getConfigsList ();
737
760
List <TaskPushNotificationConfig > result = new ArrayList <>(configs .size ());
738
761
for (io .a2a .grpc .TaskPushNotificationConfig config : configs ) {
739
- result .add (taskPushNotificationConfig (config ));
762
+ result .add (taskPushNotificationConfig (config , false ));
740
763
}
741
764
return result ;
742
765
}
0 commit comments