Refactor assistant script loading and improve error diagnostics

- Comment out assistant script loading in script package
- Enhance global variable error message with detailed type information
- Prepare for moving assistant script loading to a dedicated package
This commit is contained in:
Max 2025-02-24 14:33:04 +08:00
parent 9c9f137a8a
commit 3c51f16d95
2 changed files with 18 additions and 19 deletions

View file

@ -283,7 +283,7 @@ func global(info *v8go.FunctionCallbackInfo) (global *GlobalVariables, err error
global, ok := goGlobal.(*GlobalVariables)
if !ok {
return nil, fmt.Errorf("global is not a valid GlobalVariables")
return nil, fmt.Errorf("global is not a valid GlobalVariables. %#v", goGlobal)
}
return global, nil

View file

@ -2,7 +2,6 @@ package script
import (
"fmt"
"strings"
"github.com/yaoapp/gou/application"
v8 "github.com/yaoapp/gou/runtime/v8"
@ -26,26 +25,26 @@ func Load(cfg config.Config) error {
return err
}
// Load assistants
err = application.App.Walk("assistants", func(root, file string, isdir bool) error {
if isdir {
return nil
}
// Load assistants - Move to the neo assistant package
// err = application.App.Walk("assistants", func(root, file string, isdir bool) error {
// if isdir {
// return nil
// }
// Keep the src.index only
if !strings.HasSuffix(file, "src/index.ts") {
return nil
}
// // Keep the src.index only
// if !strings.HasSuffix(file, "src/index.ts") {
// return nil
// }
id := fmt.Sprintf("assistants.%s", share.ID(root, file))
id = strings.TrimSuffix(id, ".src.index")
_, err := v8.Load(file, id)
return err
}, exts...)
// id := fmt.Sprintf("assistants.%s", share.ID(root, file))
// id = strings.TrimSuffix(id, ".src.index")
// _, err := v8.Load(file, id)
// return err
// }, exts...)
if err != nil {
return err
}
// if err != nil {
// return err
// }
return application.App.Walk("services", func(root, file string, isdir bool) error {
if isdir {