- Refactored the Makefile to include new benchmark and memory leak detection tests, improving test coverage. - Introduced context adjustments in the Create method, allowing hooks to modify context fields such as AssistantID, Connector, Locale, Theme, Route, and Metadata. - Added a new test scenario to validate context field adjustments, ensuring proper updates during assistant operations. - Updated test preparation to support optional V8 mode configuration for improved performance during benchmarks.
22 lines
508 B
Go
22 lines
508 B
Go
package hook
|
|
|
|
import (
|
|
"github.com/yaoapp/yao/agent/context"
|
|
)
|
|
|
|
// Execute execute the script
|
|
func (s *Script) Execute(ctx *context.Context, method string, args ...interface{}) (interface{}, error) {
|
|
if s == nil || s.Script == nil {
|
|
return nil, nil
|
|
}
|
|
|
|
scriptCtx, err := s.NewContext(ctx.Sid, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer scriptCtx.Close()
|
|
|
|
// The first argument is the context
|
|
args = append([]interface{}{ctx}, args...)
|
|
return scriptCtx.CallWith(ctx.Context, method, args...)
|
|
}
|