Merge pull request #869 from trheyi/main

Update run method to support SendMessage in nested script contexts
This commit is contained in:
Max 2025-02-19 10:10:28 +08:00 committed by GitHub
commit 815e551bfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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())