Add assistant script loading mechanism
- Implement loading of assistant TypeScript index files - Filter and load only src/index.ts files from assistants directory - Generate unique IDs for assistant scripts using file path - Extend application walk method to support assistant script loading
This commit is contained in:
parent
9a9d1e38a8
commit
9c419c3209
1 changed files with 22 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package script
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yaoapp/gou/application"
|
||||
v8 "github.com/yaoapp/gou/runtime/v8"
|
||||
|
|
@ -25,6 +26,27 @@ 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
|
||||
}
|
||||
|
||||
// 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...)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return application.App.Walk("services", func(root, file string, isdir bool) error {
|
||||
if isdir {
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue