feat: introduce WeKnora Lite edition with lightweight configuration and deployment

- Added a new `.env.lite.example` file for the Lite version, providing a minimal configuration template.
- Updated `.env.example` to remove deprecated variables and include new Docreader settings.
- Enhanced Docker configurations to support the Lite version, including a new Dockerfile for the Docreader service.
- Introduced a Makefile target for building and running the Lite version, along with packaging capabilities.
- Created GitHub workflows for building and releasing Lite binaries, including Homebrew formula support.
- Implemented a new service file for managing the Lite version as a system service.

This update enables a streamlined, single-binary deployment of WeKnora, reducing external dependencies and simplifying setup.
This commit is contained in:
wizardchen
2026-02-28 13:22:07 +08:00
committed by lyingbug
parent 5241dbc39e
commit 397689d2f3
140 changed files with 13365 additions and 5413 deletions
+97 -1
View File
@@ -1,6 +1,11 @@
package router
import (
"context"
"net/http"
"os"
"path/filepath"
"strings"
"time"
"github.com/gin-contrib/cors"
@@ -12,6 +17,7 @@ import (
"github.com/Tencent/WeKnora/internal/config"
"github.com/Tencent/WeKnora/internal/handler"
"github.com/Tencent/WeKnora/internal/handler/session"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/middleware"
"github.com/Tencent/WeKnora/internal/types/interfaces"
@@ -88,11 +94,19 @@ func NewRouter(params RouterParams) *gin.Engine {
))
}
// 本地存储文件服务(无需认证,用于 <img> 等标签访问图片)
serveLocalFiles(r)
// 前端静态文件(仅 Lite 版本内嵌前端)
if handler.Edition == "lite" {
serveFrontendStatic(r)
}
// 认证中间件
r.Use(middleware.Auth(params.TenantService, params.UserService, params.Config))
// 添加OpenTelemetry追踪中间件
r.Use(middleware.TracingMiddleware())
// r.Use(middleware.TracingMiddleware())
// 需要认证的API路由
v1 := r.Group("/api/v1")
@@ -173,6 +187,8 @@ func RegisterKnowledgeRoutes(r *gin.RouterGroup, handler *handler.KnowledgeHandl
k.POST("/:id/reparse", handler.ReparseKnowledge)
// 获取知识文件
k.GET("/:id/download", handler.DownloadKnowledgeFile)
// 预览知识文件(内联显示,返回正确 Content-Type)
k.GET("/:id/preview", handler.PreviewKnowledgeFile)
// 更新图像分块信息
k.PUT("/image/:id/:chunk_id", handler.UpdateImageInfo)
// 批量更新知识标签
@@ -389,6 +405,11 @@ func RegisterSystemRoutes(r *gin.RouterGroup, handler *handler.SystemHandler) {
systemRoutes := r.Group("/system")
{
systemRoutes.GET("/info", handler.GetSystemInfo)
systemRoutes.GET("/parser-engines", handler.ListParserEngines)
systemRoutes.POST("/parser-engines/check", handler.CheckParserEngines)
systemRoutes.POST("/docreader/reconnect", handler.ReconnectDocReader)
systemRoutes.GET("/storage-engine-status", handler.GetStorageEngineStatus)
systemRoutes.POST("/storage-engine-check", handler.CheckStorageEngine)
systemRoutes.GET("/minio/buckets", handler.ListMinioBuckets)
}
}
@@ -538,3 +559,78 @@ func RegisterOrganizationRoutes(r *gin.RouterGroup, orgHandler *handler.Organiza
r.GET("/shared-agents", orgHandler.ListSharedAgents)
r.POST("/shared-agents/disabled", orgHandler.SetSharedAgentDisabledByMe)
}
// serveFrontendStatic registers a middleware that serves the frontend SPA
// from the ./web directory if it exists. Must be called BEFORE auth middleware
// so static files are served without authentication.
func serveFrontendStatic(r *gin.Engine) {
webDir := os.Getenv("WEKNORA_WEB_DIR")
if webDir == "" {
webDir = "./web"
}
absDir, _ := filepath.Abs(webDir)
indexPath := filepath.Join(absDir, "index.html")
if _, err := os.Stat(indexPath); err != nil {
return
}
logger.Infof(context.Background(), "[Router] Serving frontend static files from %s", absDir)
fs := http.Dir(absDir)
fileServer := http.FileServer(fs)
r.Use(func(c *gin.Context) {
if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {
c.Next()
return
}
path := c.Request.URL.Path
if strings.HasPrefix(path, "/api/") || strings.HasPrefix(path, "/health") || strings.HasPrefix(path, "/swagger/") {
c.Next()
return
}
fullPath := filepath.Join(absDir, path)
if info, err := os.Stat(fullPath); err == nil && !info.IsDir() {
fileServer.ServeHTTP(c.Writer, c.Request)
c.Abort()
return
}
c.File(indexPath)
c.Abort()
})
}
// serveLocalFiles serves files from the local storage directory (e.g. /data/files)
// at the /files/ URL path. Registered before auth middleware so that <img> tags
// in rendered markdown can load images without authentication tokens.
func serveLocalFiles(r *gin.Engine) {
baseDir := os.Getenv("LOCAL_STORAGE_BASE_DIR")
if baseDir == "" {
baseDir = "/data/files"
}
absDir, _ := filepath.Abs(baseDir)
if info, err := os.Stat(absDir); err != nil || !info.IsDir() {
if err := os.MkdirAll(absDir, 0o755); err != nil {
logger.Warnf(context.Background(), "[Router] Cannot create local storage dir %s: %v", absDir, err)
return
}
}
logger.Infof(context.Background(), "[Router] Serving local storage files from %s at /files/", absDir)
r.GET("/files/*filepath", func(c *gin.Context) {
reqPath := c.Param("filepath")
fullPath := filepath.Join(absDir, filepath.Clean(reqPath))
if !strings.HasPrefix(fullPath, absDir) {
c.Status(http.StatusForbidden)
return
}
info, err := os.Stat(fullPath)
if err != nil || info.IsDir() {
c.Status(http.StatusNotFound)
return
}
c.File(fullPath)
})
}
+98
View File
@@ -0,0 +1,98 @@
package router
import (
"context"
"fmt"
"sync"
"time"
"github.com/Tencent/WeKnora/internal/logger"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"github.com/google/uuid"
"github.com/hibiken/asynq"
"go.uber.org/dig"
)
// SyncTaskExecutor executes tasks synchronously (in a goroutine) without Redis.
// Used in Lite mode as a drop-in replacement for *asynq.Client.
type SyncTaskExecutor struct {
mu sync.RWMutex
handlers map[string]func(context.Context, *asynq.Task) error
}
func NewSyncTaskExecutor() *SyncTaskExecutor {
return &SyncTaskExecutor{
handlers: make(map[string]func(context.Context, *asynq.Task) error),
}
}
// RegisterHandler registers a handler for a given task type pattern.
func (e *SyncTaskExecutor) RegisterHandler(pattern string, handler func(context.Context, *asynq.Task) error) {
e.mu.Lock()
defer e.mu.Unlock()
e.handlers[pattern] = handler
}
// Enqueue satisfies interfaces.TaskEnqueuer.
// Instead of queuing to Redis, it dispatches the task to a goroutine.
func (e *SyncTaskExecutor) Enqueue(task *asynq.Task, _ ...asynq.Option) (*asynq.TaskInfo, error) {
e.mu.RLock()
handler, ok := e.handlers[task.Type()]
e.mu.RUnlock()
if !ok {
return nil, fmt.Errorf("sync task executor: no handler registered for type %q", task.Type())
}
taskID := uuid.New().String()
info := &asynq.TaskInfo{
ID: taskID,
Queue: "sync",
Type: task.Type(),
}
go func() {
ctx := context.Background()
start := time.Now()
logger.Infof(ctx, "[SyncTask] Executing task type=%s id=%s", task.Type(), taskID)
if err := handler(ctx, task); err != nil {
logger.Errorf(ctx, "[SyncTask] Task failed type=%s id=%s elapsed=%v err=%v",
task.Type(), taskID, time.Since(start), err)
} else {
logger.Infof(ctx, "[SyncTask] Task completed type=%s id=%s elapsed=%v",
task.Type(), taskID, time.Since(start))
}
}()
return info, nil
}
type SyncTaskParams struct {
dig.In
Executor *SyncTaskExecutor
KnowledgeService interfaces.KnowledgeService
KnowledgeBaseService interfaces.KnowledgeBaseService
TagService interfaces.KnowledgeTagService
ChunkExtractor interfaces.TaskHandler `name:"chunkExtractor"`
DataTableSummary interfaces.TaskHandler `name:"dataTableSummary"`
ImageMultimodal interfaces.TaskHandler `name:"imageMultimodal"`
}
// RegisterSyncHandlers registers all task handlers on the SyncTaskExecutor.
// Used in Lite mode instead of RunAsynqServer.
func RegisterSyncHandlers(params SyncTaskParams) {
params.Executor.RegisterHandler(types.TypeChunkExtract, params.ChunkExtractor.Handle)
params.Executor.RegisterHandler(types.TypeDataTableSummary, params.DataTableSummary.Handle)
params.Executor.RegisterHandler(types.TypeDocumentProcess, params.KnowledgeService.ProcessDocument)
params.Executor.RegisterHandler(types.TypeFAQImport, params.KnowledgeService.ProcessFAQImport)
params.Executor.RegisterHandler(types.TypeQuestionGeneration, params.KnowledgeService.ProcessQuestionGeneration)
params.Executor.RegisterHandler(types.TypeSummaryGeneration, params.KnowledgeService.ProcessSummaryGeneration)
params.Executor.RegisterHandler(types.TypeKBClone, params.KnowledgeService.ProcessKBClone)
params.Executor.RegisterHandler(types.TypeKnowledgeListDelete, params.KnowledgeService.ProcessKnowledgeListDelete)
params.Executor.RegisterHandler(types.TypeIndexDelete, params.TagService.ProcessIndexDelete)
params.Executor.RegisterHandler(types.TypeKBDelete, params.KnowledgeBaseService.ProcessKBDelete)
params.Executor.RegisterHandler(types.TypeImageMultimodal, params.ImageMultimodal.Handle)
logger.Infof(context.Background(), "[SyncTask] All task handlers registered (Lite mode, no Redis)")
}
+4
View File
@@ -21,6 +21,7 @@ type AsynqTaskParams struct {
TagService interfaces.KnowledgeTagService
ChunkExtractor interfaces.TaskHandler `name:"chunkExtractor"`
DataTableSummary interfaces.TaskHandler `name:"dataTableSummary"`
ImageMultimodal interfaces.TaskHandler `name:"imageMultimodal"`
}
func getAsynqRedisClientOpt() *asynq.RedisClientOpt {
@@ -98,6 +99,9 @@ func RunAsynqServer(params AsynqTaskParams) *asynq.ServeMux {
// Register KB delete handler
mux.HandleFunc(types.TypeKBDelete, params.KnowledgeBaseService.ProcessKBDelete)
// Register image multimodal handler
mux.HandleFunc(types.TypeImageMultimodal, params.ImageMultimodal.Handle)
go func() {
// Start the server
if err := params.Server.Run(mux); err != nil {