yao/service/service.go
Max c54ef71d6a ⚠️ BREAKING: Removed the Studio package and renamed Neo to Agent. Configuration file path changed from neo/neo.yml to agent/agent.yml.
Remove deprecated studio package and refactor agent integration

- Deleted the studio package, which is no longer in use, to streamline the codebase.
- Updated references in the agent and chat modules to utilize the new agent package instead of the deprecated neo package.
- Ensured that all related middleware and routing functionalities are now aligned with the agent architecture, enhancing overall system coherence.
2025-11-06 18:13:54 +08:00

90 lines
1.5 KiB
Go

package service
import (
"time"
"github.com/gin-gonic/gin"
"github.com/yaoapp/gou/api"
"github.com/yaoapp/gou/server/http"
"github.com/yaoapp/yao/agent"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/openapi"
"github.com/yaoapp/yao/share"
)
// Start the yao service
func Start(cfg config.Config) (*http.Server, error) {
if cfg.AllowFrom == nil {
cfg.AllowFrom = []string{}
}
err := prepare()
if err != nil {
return nil, err
}
router := gin.New()
router.Use(Middlewares...)
api.SetGuards(Guards)
api.SetRoutes(router, "/api", cfg.AllowFrom...)
srv := http.New(router, http.Option{
Host: cfg.Host,
Port: cfg.Port,
Root: "/api",
Allows: cfg.AllowFrom,
Timeout: 5 * time.Second,
})
// Agent API
if agent.Agent != nil {
agent.Agent.API(router, "/api/__yao/agent")
}
// OpenAPI Server
if openapi.Server != nil {
openapi.Server.Attach(router)
}
go func() {
err = srv.Start()
}()
return srv, nil
}
// Restart the yao service
func Restart(srv *http.Server, cfg config.Config) error {
router := gin.New()
router.Use(Middlewares...)
api.SetGuards(Guards)
api.SetRoutes(router, "/api", cfg.AllowFrom...)
srv.Reset(router)
return srv.Restart()
}
// Stop the yao service
func Stop(srv *http.Server) error {
err := srv.Stop()
if err != nil {
return err
}
<-srv.Event()
return nil
}
func prepare() error {
// Session server
err := share.SessionStart()
if err != nil {
return err
}
err = SetupStatic()
if err != nil {
return err
}
return nil
}