Merge pull request #869 from trheyi/main
Update run method to support SendMessage in nested script contexts
This commit is contained in:
commit
815e551bfe
1 changed files with 3 additions and 2 deletions
|
|
@ -312,7 +312,7 @@ func (ast *Assistant) call(ctx context.Context, method string, c *gin.Context, c
|
||||||
|
|
||||||
// Add sendMessage function to the script context
|
// Add sendMessage function to the script context
|
||||||
scriptCtx.WithFunction("SendMessage", sendMessage(c, contents))
|
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
|
// Check if the method exists
|
||||||
if !scriptCtx.Global().Has(method) {
|
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
|
// 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 {
|
return func(info *v8go.FunctionCallbackInfo) *v8go.Value {
|
||||||
|
|
||||||
// Get the args
|
// Get the args
|
||||||
|
|
@ -401,6 +401,7 @@ func (ast *Assistant) run(c *gin.Context, context chatctx.Context) func(info *v8
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer ctx.Close()
|
defer ctx.Close()
|
||||||
|
ctx.WithFunction("SendMessage", sendMessage(c, contents))
|
||||||
_, err = ctx.CallWith(context, name, cbArgs...)
|
_, err = ctx.CallWith(context, name, cbArgs...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to call the method: %s", err.Error())
|
log.Error("Failed to call the method: %s", err.Error())
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue