🎨 优化扩展模块,完成ai接入和对话功能

This commit is contained in:
2026-02-12 23:12:28 +08:00
parent 4e611d3a5e
commit 572f3aa15b
779 changed files with 194400 additions and 3136 deletions

View File

@@ -45,6 +45,11 @@ func Routers() *gin.Engine {
Router.Use(gin.Logger())
}
// 跨域配置(前台应用需要)
// 必须在静态文件路由之前注册,否则静态文件跨域会失败
Router.Use(middleware.Cors())
global.GVA_LOG.Info("use middleware cors")
if !global.GVA_CONFIG.MCP.Separate {
sseServer := McpRun()
@@ -63,20 +68,23 @@ func Routers() *gin.Engine {
exampleRouter := router.RouterGroupApp.Example
appRouter := router.RouterGroupApp.App // 前台应用路由
// 前台用户端静态文件服务web-app
// 开发环境:直接使用 web-app/public 目录
// 生产环境:使用打包后的 web-app/dist 目录
webAppPath := "../web-app/public"
if _, err := os.Stat(webAppPath); err == nil {
Router.Static("/css", webAppPath+"/css")
Router.Static("/scripts", webAppPath+"/scripts")
Router.Static("/img", webAppPath+"/img")
Router.Static("/fonts", webAppPath+"/fonts")
Router.Static("/webfonts", webAppPath+"/webfonts")
Router.StaticFile("/auth.html", webAppPath+"/auth.html")
Router.StaticFile("/dashboard-example.html", webAppPath+"/dashboard-example.html")
Router.StaticFile("/favicon.ico", webAppPath+"/favicon.ico")
global.GVA_LOG.Info("前台静态文件服务已启动: " + webAppPath)
// SillyTavern 核心脚本静态文件服务
// 扩展通过 ES module 相对路径 import 引用这些核心模块(如 ../../../../../script.js → /script.js
// 所有核心文件存储在 data/st-core-scripts/ 下,完全独立于 web-app/ 目录
// 扩展文件存储在 data/st-core-scripts/scripts/extensions/third-party/{name}/ 下
stCorePath := "data/st-core-scripts"
if _, err := os.Stat(stCorePath); err == nil {
Router.Static("/scripts", stCorePath+"/scripts")
Router.Static("/css", stCorePath+"/css")
Router.Static("/img", stCorePath+"/img")
Router.Static("/webfonts", stCorePath+"/webfonts")
Router.Static("/lib", stCorePath+"/lib") // SillyTavern 扩展依赖的第三方库
Router.Static("/locales", stCorePath+"/locales") // 国际化文件
Router.StaticFile("/script.js", stCorePath+"/script.js") // SillyTavern 主入口
Router.StaticFile("/lib.js", stCorePath+"/lib.js") // Webpack 编译后的 lib.js
global.GVA_LOG.Info("SillyTavern 核心脚本服务已启动: " + stCorePath)
} else {
global.GVA_LOG.Warn("SillyTavern 核心脚本目录不存在: " + stCorePath + ",扩展功能将不可用")
}
// 管理后台前端静态文件web
@@ -90,9 +98,6 @@ func Routers() *gin.Engine {
Router.StaticFS(global.GVA_CONFIG.Local.StorePath, justFilesFilesystem{http.Dir(global.GVA_CONFIG.Local.StorePath)}) // Router.Use(middleware.LoadTls()) // 如果需要使用https 请打开此中间件 然后前往 core/server.go 将启动模式 更变为 Router.RunTLS("端口","你的cre/pem文件","你的key文件")
// 跨域配置(前台应用需要)
Router.Use(middleware.Cors()) // 直接放行全部跨域请求
global.GVA_LOG.Info("use middleware cors")
docs.SwaggerInfo.BasePath = global.GVA_CONFIG.System.RouterPrefix
Router.GET(global.GVA_CONFIG.System.RouterPrefix+"/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
global.GVA_LOG.Info("register swagger handler")
@@ -149,6 +154,8 @@ func Routers() *gin.Engine {
appRouter.InitWorldInfoRouter(appGroup) // 世界书路由:/app/worldbook/*
appRouter.InitExtensionRouter(appGroup) // 扩展路由:/app/extension/*
appRouter.InitRegexScriptRouter(appGroup) // 正则脚本路由:/app/regex/*
appRouter.InitProviderRouter(appGroup) // AI提供商路由/app/provider/*
appRouter.InitChatRouter(appGroup) // 对话路由:/app/chat/*
}
//插件路由安装