diff --git a/Makefile b/Makefile index 4287aff..81174ae 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ UNAME_S := $(shell uname -s) UNAME_M := $(shell uname -m) .PHONY: all build agent vet test clean release \ - macos-x64 macos-arm64 windows-x64 linux-x64 linux-arm64 + macos-x64 macos-arm64 windows-x64 linux-x64 linux-arm64 macos linux all: vet test build @@ -49,3 +49,25 @@ linux-arm64: GOOS=linux GOARCH=arm64 $(GO) build -o build/linux-arm64/$(APP_NAME) ./cmd/api release: macos-x64 macos-arm64 windows-x64 linux-x64 linux-arm64 + +macos: +@if [ "$(UNAME_S)" = "Darwin" ]; then \ +if [ "$(UNAME_M)" = "arm64" ]; then \ +GOOS=darwin GOARCH=arm64 $(GO) build -o build/macos-arm64/$(APP_NAME) ./cmd/api; \ +else \ +GOOS=darwin GOARCH=amd64 $(GO) build -o build/macos-x64/$(APP_NAME) ./cmd/api; \ +fi; \ +else \ +echo "macos build requires macOS host"; \ +fi + +linux: +@if [ "$(UNAME_S)" = "Linux" ]; then \ +if [ "$(UNAME_M)" = "aarch64" ] || [ "$(UNAME_M)" = "arm64" ]; then \ +GOOS=linux GOARCH=arm64 $(GO) build -o build/linux-arm64/$(APP_NAME) ./cmd/api; \ +else \ +GOOS=linux GOARCH=amd64 $(GO) build -o build/linux-x64/$(APP_NAME) ./cmd/api; \ +fi; \ +else \ +echo "linux build requires Linux host"; \ +fi diff --git a/cmd/api/main.go b/cmd/api/main.go index 1d6a9ac..d9a6e45 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -10,8 +10,8 @@ import ( "github.com/jackc/pgx/v5" "xcontrol/internal/api" - kbserver "xcontrol/modules/markmind/server" "xcontrol/server" + markmind "xcontrol/server/markmind" "xcontrol/ui" ) @@ -27,7 +27,7 @@ func main() { r := server.New( api.RegisterRoutes, - func(r *gin.Engine) { kbserver.RegisterRoutes(r, conn) }, + func(r *gin.Engine) { markmind.RegisterRoutes(r, conn) }, func(r *gin.Engine) { r.StaticFS("/", http.FS(ui.Assets)) }, ) diff --git a/docs/architecture/ai-kb-design.md b/docs/architecture/ai-kb-design.md index 48714b2..2ddde88 100644 --- a/docs/architecture/ai-kb-design.md +++ b/docs/architecture/ai-kb-design.md @@ -78,7 +78,7 @@ func Embed(text string) ([]float32, error) { /* 调用 Embedding 模型 */ } ## 5. 项目代码规划 ``` -modules/markmind/ +server/markmind/ ├── ingest/ │ ├── fetch_repo.go # Git 克隆/更新 │ ├── convert.go # 文档转换 diff --git a/docs/deployments/docker-compose.md b/docs/deployments/docker-compose.md index 104bd2a..15c483c 100644 --- a/docs/deployments/docker-compose.md +++ b/docs/deployments/docker-compose.md @@ -33,17 +33,24 @@ server { try_files $uri $uri/ /index.html; } - # 5. 静态资源缓存优化 - location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?)$ { - expires 30d; - access_log off; - add_header Cache-Control "public"; - } + # 5. 静态资源缓存优化 + location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?)$ { + expires 30d; + access_log off; + add_header Cache-Control "public"; + } - # 6. 隐藏 . 文件(如 .DS_Store) - location ~ /\. { - deny all; - } + # 6. 转发后端 API + location /api/ { + proxy_pass http://127.0.0.1:8080/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + # 7. 隐藏 . 文件(如 .DS_Store) + location ~ /\. { + deny all; + } } # 7. HTTPS 独立下载服务 artifact.svc.plus diff --git a/docs/deployments/helm-chart.md b/docs/deployments/helm-chart.md index 3a1680b..86a2d1c 100644 --- a/docs/deployments/helm-chart.md +++ b/docs/deployments/helm-chart.md @@ -33,17 +33,24 @@ server { try_files $uri $uri/ /index.html; } - # 5. 静态资源缓存优化 - location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?)$ { - expires 30d; - access_log off; - add_header Cache-Control "public"; - } + # 5. 静态资源缓存优化 + location ~* \.(?:ico|css|js|gif|jpe?g|png|woff2?)$ { + expires 30d; + access_log off; + add_header Cache-Control "public"; + } - # 6. 隐藏 . 文件(如 .DS_Store) - location ~ /\. { - deny all; - } + # 6. 转发后端 API + location /api/ { + proxy_pass http://127.0.0.1:8080/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + # 7. 隐藏 . 文件(如 .DS_Store) + location ~ /\. { + deny all; + } } # 7. HTTPS 独立下载服务 artifact.svc.plus diff --git a/docs/deployments/systemd-agent.md b/docs/deployments/systemd-agent.md index da09b9a..dc04a70 100644 --- a/docs/deployments/systemd-agent.md +++ b/docs/deployments/systemd-agent.md @@ -49,7 +49,14 @@ server { add_header Cache-Control "public"; } - # 6. 隐藏 . 文件(如 .DS_Store) + # 6. 转发后端 API + location /api/ { + proxy_pass http://127.0.0.1:8080/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } + + # 7. 隐藏 . 文件(如 .DS_Store) location ~ /\. { deny all; } diff --git a/modules/markmind/Dockerfile b/server/markmind/Dockerfile similarity index 100% rename from modules/markmind/Dockerfile rename to server/markmind/Dockerfile diff --git a/modules/markmind/server/api.go b/server/markmind/api.go similarity index 83% rename from modules/markmind/server/api.go rename to server/markmind/api.go index 99e92c8..04bd031 100644 --- a/modules/markmind/server/api.go +++ b/server/markmind/api.go @@ -1,4 +1,4 @@ -package server +package markmind import ( "net/http" @@ -6,15 +6,15 @@ import ( "github.com/gin-gonic/gin" "github.com/jackc/pgx/v5" - "xcontrol/modules/markmind/db" - "xcontrol/modules/markmind/ingest" - "xcontrol/modules/markmind/llm" + "xcontrol/server/markmind/db" + "xcontrol/server/markmind/ingest" + "xcontrol/server/markmind/llm" ) // RegisterRoutes registers knowledge base endpoints. func RegisterRoutes(r *gin.Engine, conn *pgx.Conn) { store := &db.Store{Conn: conn} - r.POST("/sync", func(c *gin.Context) { + r.POST("/api/sync", func(c *gin.Context) { var req struct { RepoURL string `json:"repo_url"` LocalPath string `json:"local_path"` @@ -30,7 +30,7 @@ func RegisterRoutes(r *gin.Engine, conn *pgx.Conn) { c.JSON(http.StatusOK, gin.H{"status": "synced"}) }) - r.POST("/ask", func(c *gin.Context) { + r.POST("/api/askai", func(c *gin.Context) { var req struct { Question string `json:"question"` } diff --git a/modules/markmind/config/repos.yaml b/server/markmind/config/repos.yaml similarity index 100% rename from modules/markmind/config/repos.yaml rename to server/markmind/config/repos.yaml diff --git a/modules/markmind/db/pgvector.go b/server/markmind/db/pgvector.go similarity index 97% rename from modules/markmind/db/pgvector.go rename to server/markmind/db/pgvector.go index 24b7162..0398f52 100644 --- a/modules/markmind/db/pgvector.go +++ b/server/markmind/db/pgvector.go @@ -5,7 +5,7 @@ import ( "encoding/json" "github.com/jackc/pgx/v5" - "xcontrol/modules/markmind/ingest" + "xcontrol/server/markmind/ingest" ) // Store wraps a pgx connection for vector operations. diff --git a/modules/markmind/ingest/chunk.go b/server/markmind/ingest/chunk.go similarity index 100% rename from modules/markmind/ingest/chunk.go rename to server/markmind/ingest/chunk.go diff --git a/modules/markmind/ingest/convert.go b/server/markmind/ingest/convert.go similarity index 100% rename from modules/markmind/ingest/convert.go rename to server/markmind/ingest/convert.go diff --git a/modules/markmind/ingest/embed.go b/server/markmind/ingest/embed.go similarity index 100% rename from modules/markmind/ingest/embed.go rename to server/markmind/ingest/embed.go diff --git a/modules/markmind/ingest/fetch_repo.go b/server/markmind/ingest/fetch_repo.go similarity index 100% rename from modules/markmind/ingest/fetch_repo.go rename to server/markmind/ingest/fetch_repo.go diff --git a/modules/markmind/llm/chutes.go b/server/markmind/llm/chutes.go similarity index 100% rename from modules/markmind/llm/chutes.go rename to server/markmind/llm/chutes.go diff --git a/modules/markmind/llm/prompt.go b/server/markmind/llm/prompt.go similarity index 91% rename from modules/markmind/llm/prompt.go rename to server/markmind/llm/prompt.go index 668c9f2..0e21030 100644 --- a/modules/markmind/llm/prompt.go +++ b/server/markmind/llm/prompt.go @@ -3,7 +3,7 @@ package llm import ( "strings" - "xcontrol/modules/markmind/ingest" + "xcontrol/server/markmind/ingest" ) // BuildPrompt constructs a simple prompt from retrieved chunks and a question. diff --git a/modules/markmind/llm/rag.go b/server/markmind/llm/rag.go similarity index 87% rename from modules/markmind/llm/rag.go rename to server/markmind/llm/rag.go index 685417c..d8757af 100644 --- a/modules/markmind/llm/rag.go +++ b/server/markmind/llm/rag.go @@ -3,8 +3,8 @@ package llm import ( "context" - "xcontrol/modules/markmind/db" - "xcontrol/modules/markmind/ingest" + "xcontrol/server/markmind/db" + "xcontrol/server/markmind/ingest" ) // Answer performs a minimal RAG workflow.