|
@@ -38,6 +38,25 @@ func (g *Gateway) injectStandardLibs(vm *otto.Otto, scriptFile string, scriptSco
|
|
|
// Available in every AGI script — use it for log correlation, deduplication, etc.
|
|
// Available in every AGI script — use it for log correlation, deduplication, etc.
|
|
|
vm.Set("EXECUTION_ID", execID)
|
|
vm.Set("EXECUTION_ID", execID)
|
|
|
|
|
|
|
|
|
|
+ // Override otto's built-in console.log (which maps to fmt.Println) so that
|
|
|
|
|
+ // script output goes through the structured logger and carries the execID.
|
|
|
|
|
+ // Use the system-wide logger (with file output) when available; fall back to
|
|
|
|
|
+ // agiLogger (stdout only) if the Gateway was created without one.
|
|
|
|
|
+ scriptLogger := agiLogger
|
|
|
|
|
+ if g.Option.Logger != nil {
|
|
|
|
|
+ scriptLogger = g.Option.Logger
|
|
|
|
|
+ }
|
|
|
|
|
+ vm.Set("_agi_console_log", func(call otto.FunctionCall) otto.Value {
|
|
|
|
|
+ parts := make([]string, 0, len(call.ArgumentList))
|
|
|
|
|
+ for _, arg := range call.ArgumentList {
|
|
|
|
|
+ str, _ := arg.ToString()
|
|
|
|
|
+ parts = append(parts, str)
|
|
|
|
|
+ }
|
|
|
|
|
+ scriptLogger.PrintAndLog("AGI", "["+execID+"] "+strings.Join(parts, " "), nil)
|
|
|
|
|
+ return otto.UndefinedValue()
|
|
|
|
|
+ })
|
|
|
|
|
+ vm.Run(`var console = { log: _agi_console_log, warn: _agi_console_log, error: _agi_console_log, info: _agi_console_log };`) //nolint:errcheck
|
|
|
|
|
+
|
|
|
//Response related
|
|
//Response related
|
|
|
vm.Set("sendResp", func(call otto.FunctionCall) otto.Value {
|
|
vm.Set("sendResp", func(call otto.FunctionCall) otto.Value {
|
|
|
argString, _ := call.Argument(0).ToString()
|
|
argString, _ := call.Argument(0).ToString()
|