Skip to content

Commit c59e280

Browse files
committed
added a2ui support and display part added more support for other components
1 parent 6d835a3 commit c59e280

File tree

2 files changed

+135
-2
lines changed

2 files changed

+135
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.vishalmysore</groupId>
88
<artifactId>a2ajava</artifactId>
9-
<version>1.0.4</version>
9+
<version>1.0.5</version>
1010
<name>A2A Protocol Implementation for Java</name>
1111
<description>
1212
Java implementation of the A2A protocol v1.0, which allows for the exchange of data between different AI systems.

src/main/java/io/github/vishalmysore/a2ui/A2UIAware.java

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ default boolean isUICallback(ActionCallback callback) {
319319
return callback != null && callback.getType().equals(CallBackType.A2UI.name());
320320
}
321321

322-
322+
default boolean isUICallback() {
323+
return isUICallback(getCallback());
324+
}
323325
/**
324326
* Creates an Image component
325327
*/
@@ -602,4 +604,135 @@ default Map<String, Object> createChoicePickerComponent(String id, String label,
602604

603605
return component;
604606
}
607+
608+
/**
609+
* Creates a Video component
610+
*/
611+
default Map<String, Object> createVideoComponent(String id, String url, String usageHint) {
612+
Map<String, Object> component = new HashMap<>();
613+
component.put("id", id);
614+
615+
Map<String, Object> videoComponent = new HashMap<>();
616+
Map<String, Object> videoProps = new HashMap<>();
617+
618+
videoProps.put("url", new HashMap<String, Object>() {{
619+
put("literalString", url);
620+
}});
621+
622+
if (usageHint != null) {
623+
videoProps.put("usageHint", usageHint);
624+
}
625+
626+
videoComponent.put("Video", videoProps);
627+
component.put("component", videoComponent);
628+
629+
return component;
630+
}
631+
632+
/**
633+
* Creates an AudioPlayer component
634+
*/
635+
default Map<String, Object> createAudioPlayerComponent(String id, String url, String description) {
636+
Map<String, Object> component = new HashMap<>();
637+
component.put("id", id);
638+
639+
Map<String, Object> audioComponent = new HashMap<>();
640+
Map<String, Object> audioProps = new HashMap<>();
641+
642+
audioProps.put("url", new HashMap<String, Object>() {{
643+
put("literalString", url);
644+
}});
645+
646+
if (description != null) {
647+
audioProps.put("description", new HashMap<String, Object>() {{
648+
put("literalString", description);
649+
}});
650+
}
651+
652+
audioComponent.put("AudioPlayer", audioProps);
653+
component.put("component", audioComponent);
654+
655+
return component;
656+
}
657+
658+
/**
659+
* Creates a Tabs component
660+
*/
661+
default Map<String, Object> createTabsComponent(String id, List<Map<String, Object>> tabItems) {
662+
Map<String, Object> component = new HashMap<>();
663+
component.put("id", id);
664+
665+
Map<String, Object> tabsComponent = new HashMap<>();
666+
Map<String, Object> tabsProps = new HashMap<>();
667+
668+
List<Map<String, Object>> items = new ArrayList<>();
669+
for (Map<String, Object> tab : tabItems) {
670+
items.add(new HashMap<String, Object>() {{
671+
put("title", new HashMap<String, Object>() {{
672+
put("literalString", tab.get("title"));
673+
}});
674+
put("child", tab.get("child"));
675+
}});
676+
}
677+
tabsProps.put("tabItems", items);
678+
679+
tabsComponent.put("Tabs", tabsProps);
680+
component.put("component", tabsComponent);
681+
682+
return component;
683+
}
684+
685+
/**
686+
* Creates a Modal component
687+
*/
688+
default Map<String, Object> createModalComponent(String id, String entryPointChild, String contentChild) {
689+
Map<String, Object> component = new HashMap<>();
690+
component.put("id", id);
691+
692+
Map<String, Object> modalComponent = new HashMap<>();
693+
Map<String, Object> modalProps = new HashMap<>();
694+
695+
modalProps.put("entryPointChild", entryPointChild);
696+
modalProps.put("contentChild", contentChild);
697+
698+
modalComponent.put("Modal", modalProps);
699+
component.put("component", modalComponent);
700+
701+
return component;
702+
}
703+
704+
/**
705+
* Creates a DateTimeInput component
706+
*/
707+
default Map<String, Object> createDateTimeInputComponent(String id, String label, String dataPath,
708+
Boolean enableDate, Boolean enableTime) {
709+
Map<String, Object> component = new HashMap<>();
710+
component.put("id", id);
711+
712+
Map<String, Object> dateTimeComponent = new HashMap<>();
713+
Map<String, Object> dateTimeProps = new HashMap<>();
714+
715+
dateTimeProps.put("label", new HashMap<String, Object>() {{
716+
put("literalString", label);
717+
}});
718+
719+
if (dataPath != null) {
720+
dateTimeProps.put("value", new HashMap<String, Object>() {{
721+
put("path", dataPath);
722+
}});
723+
}
724+
725+
if (enableDate != null) {
726+
dateTimeProps.put("enableDate", enableDate);
727+
}
728+
729+
if (enableTime != null) {
730+
dateTimeProps.put("enableTime", enableTime);
731+
}
732+
733+
dateTimeComponent.put("DateTimeInput", dateTimeProps);
734+
component.put("component", dateTimeComponent);
735+
736+
return component;
737+
}
605738
}

0 commit comments

Comments
 (0)