2929import io .reactivex .rxjava3 .core .Completable ;
3030import io .reactivex .rxjava3 .core .Maybe ;
3131import java .util .Map ;
32- import java . util . Optional ;
32+ import org . jspecify . annotations . Nullable ;
3333import org .slf4j .Logger ;
3434import org .slf4j .LoggerFactory ;
3535
@@ -57,7 +57,7 @@ private void log(String message) {
5757
5858 @ Override
5959 public Maybe <Content > onUserMessageCallback (
60- InvocationContext invocationContext , Content userMessage ) {
60+ InvocationContext invocationContext , @ Nullable Content userMessage ) {
6161 return Maybe .fromAction (
6262 () -> {
6363 log ("🚀 USER MESSAGE RECEIVED" );
@@ -66,7 +66,7 @@ public Maybe<Content> onUserMessageCallback(
6666 log (" User ID: " + invocationContext .userId ());
6767 log (" App Name: " + invocationContext .appName ());
6868 log (" Root Agent: " + invocationContext .agent ().name ());
69- log (" User Content: " + formatContent (Optional . ofNullable ( userMessage ) ));
69+ log (" User Content: " + formatContent (userMessage ));
7070 invocationContext .branch ().ifPresent (branch -> log (" Branch: " + branch ));
7171 });
7272 }
@@ -88,7 +88,7 @@ public Maybe<Event> onEventCallback(InvocationContext invocationContext, Event e
8888 log ("📢 EVENT YIELDED" );
8989 log (" Event ID: " + event .id ());
9090 log (" Author: " + event .author ());
91- log (" Content: " + formatContent (event .content ()));
91+ log (" Content: " + formatContent (event .content (). orElse ( null ) ));
9292 log (" Final Response: " + event .finalResponse ());
9393
9494 if (!event .functionCalls ().isEmpty ()) {
@@ -190,7 +190,7 @@ public Maybe<LlmResponse> afterModelCallback(
190190 log (" ❌ ERROR - Code: " + llmResponse .errorCode ().get ());
191191 log (" Error Message: " + llmResponse .errorMessage ().orElse ("None" ));
192192 } else {
193- log (" Content: " + formatContent (llmResponse .content ()));
193+ log (" Content: " + formatContent (llmResponse .content (). orElse ( null ) ));
194194 llmResponse .partial ().ifPresent (partial -> log (" Partial: " + partial ));
195195 llmResponse
196196 .turnComplete ()
@@ -265,12 +265,8 @@ public Maybe<Map<String, Object>> onToolErrorCallback(
265265 });
266266 }
267267
268- private String formatContent (Optional <Content > contentOptional ) {
269- if (contentOptional .isEmpty ()) {
270- return "None" ;
271- }
272- Content content = contentOptional .get ();
273- if (content .parts ().isEmpty () || content .parts ().get ().isEmpty ()) {
268+ private String formatContent (@ Nullable Content content ) {
269+ if (content == null || content .parts ().isEmpty () || content .parts ().get ().isEmpty ()) {
274270 return "None" ;
275271 }
276272 return content .parts ().get ().stream ()
0 commit comments