Skip to content

Commit

Permalink
Merge pull request #869 from trheyi/main
Browse files Browse the repository at this point in the history
Update run method to support SendMessage in nested script contexts
  • Loading branch information
trheyi authored Feb 19, 2025
2 parents adc3d01 + 9a9d1e3 commit 815e551
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions neo/assistant/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 815e551

Please sign in to comment.