From 9a9d1e38a885cb39e724fb141caae17b6c4dbc48 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 19 Feb 2025 09:39:16 +0800 Subject: [PATCH] Update run method to support SendMessage in nested script contexts - Modify run method signature to include contents parameter - Add SendMessage function to nested script context during execution - Ensure consistent message sending capabilities across script levels --- neo/assistant/hooks.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/neo/assistant/hooks.go b/neo/assistant/hooks.go index f4ed1d14..36001824 100644 --- a/neo/assistant/hooks.go +++ b/neo/assistant/hooks.go @@ -312,7 +312,7 @@ func (ast *Assistant) call(ctx context.Context, method string, c *gin.Context, c // Add sendMessage function to the script context scriptCtx.WithFunction("SendMessage", sendMessage(c, contents)) - scriptCtx.WithFunction("Run", ast.run(c, context)) + scriptCtx.WithFunction("Run", ast.run(c, context, contents)) // Check if the method exists if !scriptCtx.Global().Has(method) { @@ -328,7 +328,7 @@ func (ast *Assistant) call(ctx context.Context, method string, c *gin.Context, c } // Execute the assistant -func (ast *Assistant) run(c *gin.Context, context chatctx.Context) func(info *v8go.FunctionCallbackInfo) *v8go.Value { +func (ast *Assistant) run(c *gin.Context, context chatctx.Context, contents *chatMessage.Contents) func(info *v8go.FunctionCallbackInfo) *v8go.Value { return func(info *v8go.FunctionCallbackInfo) *v8go.Value { // Get the args @@ -401,6 +401,7 @@ func (ast *Assistant) run(c *gin.Context, context chatctx.Context) func(info *v8 return } defer ctx.Close() + ctx.WithFunction("SendMessage", sendMessage(c, contents)) _, err = ctx.CallWith(context, name, cbArgs...) if err != nil { log.Error("Failed to call the method: %s", err.Error())