Merge pull request #870 from trheyi/main

Add assistant script loading mechanism
This commit is contained in:
Max 2025-02-21 15:36:12 +08:00 committed by GitHub
commit 27524f7fb0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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