Skip to content

Commit 815e551

Browse files
authored
Merge pull request #869 from trheyi/main
Update run method to support SendMessage in nested script contexts
2 parents adc3d01 + 9a9d1e3 commit 815e551

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

neo/assistant/hooks.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (ast *Assistant) call(ctx context.Context, method string, c *gin.Context, c
312312

313313
// Add sendMessage function to the script context
314314
scriptCtx.WithFunction("SendMessage", sendMessage(c, contents))
315-
scriptCtx.WithFunction("Run", ast.run(c, context))
315+
scriptCtx.WithFunction("Run", ast.run(c, context, contents))
316316

317317
// Check if the method exists
318318
if !scriptCtx.Global().Has(method) {
@@ -328,7 +328,7 @@ func (ast *Assistant) call(ctx context.Context, method string, c *gin.Context, c
328328
}
329329

330330
// Execute the assistant
331-
func (ast *Assistant) run(c *gin.Context, context chatctx.Context) func(info *v8go.FunctionCallbackInfo) *v8go.Value {
331+
func (ast *Assistant) run(c *gin.Context, context chatctx.Context, contents *chatMessage.Contents) func(info *v8go.FunctionCallbackInfo) *v8go.Value {
332332
return func(info *v8go.FunctionCallbackInfo) *v8go.Value {
333333

334334
// Get the args
@@ -401,6 +401,7 @@ func (ast *Assistant) run(c *gin.Context, context chatctx.Context) func(info *v8
401401
return
402402
}
403403
defer ctx.Close()
404+
ctx.WithFunction("SendMessage", sendMessage(c, contents))
404405
_, err = ctx.CallWith(context, name, cbArgs...)
405406
if err != nil {
406407
log.Error("Failed to call the method: %s", err.Error())

0 commit comments

Comments
 (0)