From 731c887ba070ce47385255e03fe895e427702453 Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Fri, 8 May 2026 13:56:19 +0800 Subject: [PATCH] Fix cli login (#14658) ### What problem does this PR solve? Since API is updated, CLI login failed. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Signed-off-by: Jin Hai --- internal/cli/admin_command.go | 70 +++++++++++------------ internal/cli/benchmark.go | 8 +-- internal/cli/client.go | 4 +- internal/cli/common_command.go | 32 +++++------ internal/cli/filesystem/dataset.go | 18 +++--- internal/cli/filesystem/file.go | 10 ++-- internal/cli/filesystem/skill.go | 42 +++++++------- internal/cli/http_client.go | 87 ++++------------------------- internal/cli/user_command.go | 90 +++++++++++++++--------------- internal/cli/user_parser.go | 12 ++-- internal/router/router.go | 24 +++++--- 11 files changed, 167 insertions(+), 230 deletions(-) diff --git a/internal/cli/admin_command.go b/internal/cli/admin_command.go index d092fe35b2..4b7afe52a8 100644 --- a/internal/cli/admin_command.go +++ b/internal/cli/admin_command.go @@ -33,11 +33,11 @@ func (c *RAGFlowClient) PingAdmin(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode: multiple iterations - return c.HTTPClient.RequestWithIterations("GET", "/admin/ping", false, "web", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/admin/ping", "web", nil, nil, iterations) } // Single mode - resp, err := c.HTTPClient.Request("GET", "/admin/ping", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/admin/ping", "web", nil, nil) if err != nil { fmt.Printf("Error: %v\n", err) fmt.Println("Server is down") @@ -67,11 +67,11 @@ func (c *RAGFlowClient) ShowAdminVersion(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode: multiple iterations - return c.HTTPClient.RequestWithIterations("GET", "/admin/version", false, "web", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/admin/version", "web", nil, nil, iterations) } // Single mode - resp, err := c.HTTPClient.Request("GET", "/admin/version", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/admin/version", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show admin version: %w", err) } @@ -106,10 +106,10 @@ func (c *RAGFlowClient) ListRoles(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", "/admin/roles", true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/admin/roles", "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", "/admin/roles", true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/admin/roles", "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list roles: %w", err) } @@ -153,10 +153,10 @@ func (c *RAGFlowClient) ShowRole(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", endPoint, true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", endPoint, "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show role: %w", err) } @@ -197,7 +197,7 @@ func (c *RAGFlowClient) CreateRole(cmd *Command) (ResponseIf, error) { payload["description"] = description } - resp, err := c.HTTPClient.Request("POST", "/admin/roles", true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/admin/roles", "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to create role: %w", err) } @@ -230,7 +230,7 @@ func (c *RAGFlowClient) DropRole(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("role_name not provided") } - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s", roleName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to drop role: %w", err) } @@ -271,7 +271,7 @@ func (c *RAGFlowClient) AlterRole(cmd *Command) (ResponseIf, error) { payload["description"] = description } - resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/roles/%s", roleName), true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to alter role: %w", err) } @@ -304,7 +304,7 @@ func (c *RAGFlowClient) GrantAdmin(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/admin", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/admin", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to grant admin: %w", err) } @@ -337,7 +337,7 @@ func (c *RAGFlowClient) RevokeAdmin(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/admin", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/admin", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to revoke admin: %w", err) } @@ -387,7 +387,7 @@ func (c *RAGFlowClient) CreateUser(cmd *Command) (ResponseIf, error) { "role": "user", } - resp, err := c.HTTPClient.Request("POST", "/admin/users", true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/admin/users", "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to create user: %w", err) } @@ -434,7 +434,7 @@ func (c *RAGFlowClient) ActivateUser(cmd *Command) (ResponseIf, error) { "activate_status": activateStatus, } - resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/activate", userName), true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/activate", userName), "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to update user status: %w", err) } @@ -482,7 +482,7 @@ func (c *RAGFlowClient) AlterUserPassword(cmd *Command) (ResponseIf, error) { "new_password": encryptedPassword, } - resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/password", userName), true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/password", userName), "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to change user password: %w", err) } @@ -524,10 +524,10 @@ func (c *RAGFlowClient) ListServices(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", "/admin/services", true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/admin/services", "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", "/admin/services", true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/admin/services", "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list services: %w", err) } @@ -571,10 +571,10 @@ func (c *RAGFlowClient) ShowService(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", endPoint, true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", endPoint, "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show service: %w", err) } @@ -611,10 +611,10 @@ func (c *RAGFlowClient) ListUsers(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", "/admin/users", true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/admin/users", "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", "/admin/users", true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/admin/users", "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list users: %w", err) } @@ -651,7 +651,7 @@ func (c *RAGFlowClient) DropUser(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to drop user: %w", err) } @@ -684,7 +684,7 @@ func (c *RAGFlowClient) ShowUser(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show user: %w", err) } @@ -726,10 +726,10 @@ func (c *RAGFlowClient) ListUserDatasets(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list datasets: %w", err) } @@ -781,10 +781,10 @@ func (c *RAGFlowClient) ListAgents(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/agents", userName), true, "admin", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", fmt.Sprintf("/admin/users/%s/agents", userName), "admin", nil, nil, iterations) } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/agents", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/agents", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list agents: %w", err) } @@ -827,7 +827,7 @@ func (c *RAGFlowClient) GrantPermission(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list tokens: %w", err) } @@ -887,7 +887,7 @@ func (c *RAGFlowClient) RevokePermission(cmd *Command) (ResponseIf, error) { "actions": actions, } - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s/permission", roleName), true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s/permission", roleName), "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to revoke permission: %w", err) } @@ -934,7 +934,7 @@ func (c *RAGFlowClient) AlterUserRole(cmd *Command) (ResponseIf, error) { "role_name": roleName, } - resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/role", userName), true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("PUT", fmt.Sprintf("/admin/users/%s/role", userName), "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to alter user role: %w", err) } @@ -972,7 +972,7 @@ func (c *RAGFlowClient) ShowUserPermission(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/permission", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/permission", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show user permission: %w", err) } @@ -1010,7 +1010,7 @@ func (c *RAGFlowClient) GenerateAdminToken(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("POST", fmt.Sprintf("/admin/users/%s/keys", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("POST", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to generate token: %w", err) } @@ -1047,7 +1047,7 @@ func (c *RAGFlowClient) ListAdminTokens(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("user_name not provided") } - resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/keys", userName), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list tokens: %w", err) } @@ -1097,7 +1097,7 @@ func (c *RAGFlowClient) DropAdminToken(cmd *Command) (ResponseIf, error) { // URL encode the token to handle special characters encodedToken := url.QueryEscape(token) - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/keys/%s", userName, encodedToken), true, "admin", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/users/%s/keys/%s", userName, encodedToken), "admin", nil, nil) if err != nil { return nil, fmt.Errorf("failed to drop token: %w", err) } diff --git a/internal/cli/benchmark.go b/internal/cli/benchmark.go index ab4d025c3b..1315ce1715 100644 --- a/internal/cli/benchmark.go +++ b/internal/cli/benchmark.go @@ -227,12 +227,12 @@ func (c *RAGFlowClient) executeBenchmarkSilent(cmd *Command, iterations int) []* switch cmd.Type { case "ping": - resp, err = c.HTTPClient.Request("GET", "/system/ping", false, "web", nil, nil) + resp, err = c.HTTPClient.Request("GET", "/system/ping", "web", nil, nil) case "list_user_datasets": - resp, err = c.HTTPClient.Request("POST", "/kb/list", false, "web", nil, nil) + resp, err = c.HTTPClient.Request("POST", "/kb/list", "web", nil, nil) case "list_datasets": userName, _ := cmd.Params["user_name"].(string) - resp, err = c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), true, "admin", nil, nil) + resp, err = c.HTTPClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil) case "search_on_datasets": question, _ := cmd.Params["question"].(string) datasetIDs, _ := cmd.Params["dataset_ids"].([]string) @@ -242,7 +242,7 @@ func (c *RAGFlowClient) executeBenchmarkSilent(cmd *Command, iterations int) []* "similarity_threshold": 0.2, "vector_similarity_weight": 0.3, } - resp, err = c.HTTPClient.Request("POST", "/chunk/retrieval_test", false, "web", nil, payload) + resp, err = c.HTTPClient.Request("POST", "/chunk/retrieval_test", "web", nil, payload) default: // For other commands, we would need to add specific handling // For now, mark as failed diff --git a/internal/cli/client.go b/internal/cli/client.go index 861a265c1e..e71e2fd6a0 100644 --- a/internal/cli/client.go +++ b/internal/cli/client.go @@ -80,7 +80,7 @@ type httpClientAdapter struct { client *HTTPClient } -func (a *httpClientAdapter) Request(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*ce.HTTPResponse, error) { +func (a *httpClientAdapter) Request(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*ce.HTTPResponse, error) { // Auto-detect auth kind based on available tokens // If authKind is "auto" or empty, determine based on token availability if authKind == "auto" || authKind == "" { @@ -92,7 +92,7 @@ func (a *httpClientAdapter) Request(method, path string, useAPIBase bool, authKi authKind = "web" // default } } - resp, err := a.client.Request(method, path, useAPIBase, authKind, headers, jsonBody) + resp, err := a.client.Request(method, path, authKind, headers, jsonBody) if err != nil { return nil, err } diff --git a/internal/cli/common_command.go b/internal/cli/common_command.go index 045d53206d..b794cc61bb 100644 --- a/internal/cli/common_command.go +++ b/internal/cli/common_command.go @@ -32,16 +32,13 @@ func (c *RAGFlowClient) LoginUserInteractive(username, password string) error { // For admin mode, use /admin/ping with useAPIBase=true // For user mode, use /system/ping with useAPIBase=false var pingPath string - var useAPIBase bool if c.ServerType == "admin" { pingPath = "/admin/ping" - useAPIBase = true } else { pingPath = "/system/ping" - useAPIBase = false } - resp, err := c.HTTPClient.Request("GET", pingPath, useAPIBase, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", pingPath, "web", nil, nil) if err != nil { fmt.Printf("Error: %v\n", err) fmt.Println("Can't access server for login (connection failed)") @@ -99,16 +96,13 @@ func (c *RAGFlowClient) LoginUser(cmd *Command) error { // For admin mode, use /admin/ping with useAPIBase=true // For user mode, use /system/ping with useAPIBase=false var pingPath string - var useAPIBase bool if c.ServerType == "admin" { pingPath = "/admin/ping" - useAPIBase = true } else { pingPath = "/system/ping" - useAPIBase = false } - resp, err := c.HTTPClient.Request("GET", pingPath, useAPIBase, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", pingPath, "web", nil, nil) if err != nil { fmt.Printf("Error: %v\n", err) fmt.Println("Can't access server for login (connection failed)") @@ -182,10 +176,10 @@ func (c *RAGFlowClient) loginUser(email, password string) (string, error) { if c.ServerType == "admin" { path = "/admin/login" } else { - path = "/user/login" + path = "/auth/login" } - resp, err := c.HTTPClient.Request("POST", path, c.ServerType == "admin", "", nil, payload) + resp, err := c.HTTPClient.Request("POST", path, "", nil, payload) if err != nil { return "", err } @@ -219,7 +213,7 @@ func (c *RAGFlowClient) Logout() (ResponseIf, error) { path = "/user/logout" } - resp, err := c.HTTPClient.Request("GET", path, c.ServerType == "admin", "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", path, "web", nil, nil) if err != nil { return nil, err } @@ -245,7 +239,7 @@ func (c *RAGFlowClient) ListAvailableProviders(cmd *Command) (ResponseIf, error) endPoint = fmt.Sprintf("/providers?available=true") } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list providers: %w", err) } @@ -279,7 +273,7 @@ func (c *RAGFlowClient) ShowProvider(cmd *Command) (ResponseIf, error) { endPoint = fmt.Sprintf("/providers/%s", providerName) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show provider: %w", err) } @@ -314,7 +308,7 @@ func (c *RAGFlowClient) ListModels(cmd *Command) (ResponseIf, error) { endPoint = fmt.Sprintf("/providers/%s/models", providerName) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list models: %w", err) } @@ -353,7 +347,7 @@ func (c *RAGFlowClient) ListSupportedModels(cmd *Command) (ResponseIf, error) { endPoint = fmt.Sprintf("/providers/%s/instances/%s/models?supported=true", providerName, instanceName) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list models: %w", err) } @@ -391,7 +385,7 @@ func (c *RAGFlowClient) ShowModel(cmd *Command) (ResponseIf, error) { endPoint = fmt.Sprintf("/providers/%s/models/%s", providerName, modelName) } - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show model: %w", err) } @@ -440,7 +434,7 @@ func (c *RAGFlowClient) SetDefaultModel(cmd *Command) (ResponseIf, error) { "model_name": modelName, } - resp, err := c.HTTPClient.Request("PATCH", "/models", true, "web", nil, payload) + resp, err := c.HTTPClient.Request("PATCH", "/models", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to set default model: %w", err) } @@ -472,7 +466,7 @@ func (c *RAGFlowClient) ResetDefaultModel(cmd *Command) (ResponseIf, error) { "model_type": modelType, } - resp, err := c.HTTPClient.Request("PATCH", "/models", true, "web", nil, payload) + resp, err := c.HTTPClient.Request("PATCH", "/models", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to reset default model: %w", err) } @@ -494,7 +488,7 @@ func (c *RAGFlowClient) ResetDefaultModel(cmd *Command) (ResponseIf, error) { } func (c *RAGFlowClient) ListDefaultModels(cmd *Command) (ResponseIf, error) { - resp, err := c.HTTPClient.Request("GET", "/models", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/models", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list default models: %w", err) } diff --git a/internal/cli/filesystem/dataset.go b/internal/cli/filesystem/dataset.go index 27ba475c35..06fa6b0735 100644 --- a/internal/cli/filesystem/dataset.go +++ b/internal/cli/filesystem/dataset.go @@ -17,10 +17,10 @@ package filesystem import ( - "io" stdctx "context" "encoding/json" "fmt" + "io" "strconv" "strings" "time" @@ -36,7 +36,7 @@ type HTTPResponse struct { // HTTPClientInterface defines the interface needed from HTTPClient type HTTPClientInterface interface { - Request(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*HTTPResponse, error) + Request(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*HTTPResponse, error) UploadMultipart(path string, contentType string, body io.Reader) error } @@ -145,7 +145,7 @@ func (p *DatasetProvider) Cat(ctx stdctx.Context, subPath string) ([]byte, error // ==================== Dataset Operations ==================== func (p *DatasetProvider) listDatasets(ctx stdctx.Context, opts *ListOptions) (*Result, error) { - resp, err := p.httpClient.Request("GET", "/datasets", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/datasets", "auto", nil, nil) if err != nil { return nil, err } @@ -194,7 +194,7 @@ func (p *DatasetProvider) getDataset(ctx stdctx.Context, name string) (*Node, er } // First list all datasets to find the one with matching name - resp, err := p.httpClient.Request("GET", "/datasets", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/datasets", "auto", nil, nil) if err != nil { return nil, err } @@ -324,7 +324,7 @@ func (p *DatasetProvider) searchWithRetrieval(ctx stdctx.Context, opts *SearchOp payload["similarity_threshold"] = threshold // Call retrieval API (useAPIBase=false because the route is /v1/chunk/retrieval_test, not /api/v1/...) - resp, err := p.httpClient.Request("POST", "/chunk/retrieval_test", false, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/chunk/retrieval_test", "auto", nil, payload) if err != nil { return nil, fmt.Errorf("retrieval request failed: %w", err) } @@ -504,14 +504,14 @@ func (p *DatasetProvider) listDocuments(ctx stdctx.Context, datasetName string, } path := fmt.Sprintf("/datasets/%s/documents", datasetID) - resp, err := p.httpClient.Request("GET", path, true, "auto", params, nil) + resp, err := p.httpClient.Request("GET", path, "auto", params, nil) if err != nil { return nil, err } var apiResp struct { - Code int `json:"code"` - Data struct { + Code int `json:"code"` + Data struct { Docs []map[string]interface{} `json:"docs"` } `json:"data"` Message string `json:"message"` @@ -608,7 +608,7 @@ func (p *DatasetProvider) searchDocuments(ctx stdctx.Context, datasetName string payload["similarity_threshold"] = threshold // Call retrieval API (useAPIBase=false because the route is /v1/chunk/retrieval_test, not /api/v1/...) - resp, err := p.httpClient.Request("POST", "/chunk/retrieval_test", false, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/chunk/retrieval_test", "auto", nil, payload) if err != nil { return nil, fmt.Errorf("retrieval request failed: %w", err) } diff --git a/internal/cli/filesystem/file.go b/internal/cli/filesystem/file.go index 6863637920..6c64453f40 100644 --- a/internal/cli/filesystem/file.go +++ b/internal/cli/filesystem/file.go @@ -279,7 +279,7 @@ func (p *FileProvider) getRootID(ctx stdctx.Context) (string, error) { } // List files without parent_id to get root folder - resp, err := p.httpClient.Request("GET", "/files", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/files", "auto", nil, nil) if err != nil { return "", err } @@ -340,7 +340,7 @@ func (p *FileProvider) listFilesByParentID(ctx stdctx.Context, parentID string, path = path + "?" + strings.Join(queryParams, "&") } - resp, err := p.httpClient.Request("GET", path, true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", path, "auto", nil, nil) if err != nil { return nil, err } @@ -429,7 +429,7 @@ func (p *FileProvider) getFolderIDByName(ctx stdctx.Context, folderName string) path = path + "?" + strings.Join(queryParams, "&") } - resp, err := p.httpClient.Request("GET", path, true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", path, "auto", nil, nil) if err != nil { return "", err } @@ -521,7 +521,7 @@ func (p *FileProvider) getFileNode(ctx stdctx.Context, folderName, fileName stri // downloadFile downloads file content func (p *FileProvider) downloadFile(ctx stdctx.Context, fileID string) ([]byte, error) { path := fmt.Sprintf("/files/%s", fileID) - resp, err := p.httpClient.Request("GET", path, true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", path, "auto", nil, nil) if err != nil { return nil, err } @@ -548,7 +548,7 @@ func (p *FileProvider) DeleteFile(ctx stdctx.Context, fileID string) error { payload := map[string]interface{}{ "ids": []string{fileID}, } - resp, err := p.httpClient.Request("DELETE", "/files", true, "api", nil, payload) + resp, err := p.httpClient.Request("DELETE", "/files", "api", nil, payload) if err != nil { return fmt.Errorf("delete request failed: %w", err) } diff --git a/internal/cli/filesystem/skill.go b/internal/cli/filesystem/skill.go index 1664eed60b..9710075e98 100644 --- a/internal/cli/filesystem/skill.go +++ b/internal/cli/filesystem/skill.go @@ -220,7 +220,7 @@ func (p *SkillProvider) Search(ctx stdctx.Context, subPath string, opts *SearchO } // Call skill search API - resp, err := p.httpClient.Request("POST", "/skills/search", true, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/skills/search", "auto", nil, payload) if err != nil { return nil, fmt.Errorf("search request failed: %w", err) } @@ -327,7 +327,7 @@ func (p *SkillProvider) Cat(ctx stdctx.Context, path string) ([]byte, error) { } // Find the version folder - filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), true, "auto", nil, nil) + filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list versions: %w", err) } @@ -371,7 +371,7 @@ func (p *SkillProvider) Cat(ctx stdctx.Context, path string) ([]byte, error) { // If there's a directory path before the file, navigate through it for i := 0; i < len(pathParts)-1; i++ { - subResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), true, "auto", nil, nil) + subResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to navigate path: %w", err) } @@ -415,7 +415,7 @@ func (p *SkillProvider) Cat(ctx stdctx.Context, path string) ([]byte, error) { // Step 5: Find the file in the current directory fileName := pathParts[len(pathParts)-1] - finalResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), true, "auto", nil, nil) + finalResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list directory: %w", err) } @@ -456,7 +456,7 @@ func (p *SkillProvider) Cat(ctx stdctx.Context, path string) ([]byte, error) { // Step 6: Download the file content // First get file info to get the download URL - contentResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files/%s", fileID), true, "auto", nil, nil) + contentResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files/%s", fileID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to get file info: %w", err) } @@ -468,7 +468,7 @@ func (p *SkillProvider) Cat(ctx stdctx.Context, path string) ([]byte, error) { // listHubs lists all skills spaces func (p *SkillProvider) listSpaces(ctx stdctx.Context, opts *ListOptions) (*Result, error) { - resp, err := p.httpClient.Request("GET", "/skills/spaces", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/skills/spaces", "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list hubs: %w", err) } @@ -539,7 +539,7 @@ func (p *SkillProvider) listSkillsInSpace(ctx stdctx.Context, spaceName string, common.Debug("Listing skills via search API", zap.String("space", spaceName), zap.String("spaceUUID", spaceUUID), zap.Int("limit", limit)) - resp, err := p.httpClient.Request("POST", "/skills/search", true, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/skills/search", "auto", nil, payload) if err == nil { var result struct { Code int `json:"code"` @@ -620,7 +620,7 @@ func (p *SkillProvider) listSkillsInSpaceFromFileSystem(ctx stdctx.Context, spac common.Debug("Got space folder ID", zap.String("spaceName", spaceName), zap.String("spaceFolderID", spaceFolderID)) // List all subfolders in the space folder (each subfolder is a skill) - skillsResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", spaceFolderID), true, "auto", nil, nil) + skillsResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", spaceFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list skills: %w", err) } @@ -686,7 +686,7 @@ func (p *SkillProvider) listSkillsInSpaceFromFileSystem(ctx stdctx.Context, spac // getSkillsFolderID gets the ID of the 'skills' folder func (p *SkillProvider) getSkillsFolderID(ctx stdctx.Context) (string, error) { - resp, err := p.httpClient.Request("GET", "/files", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/files", "auto", nil, nil) if err != nil { return "", fmt.Errorf("failed to list root folders: %w", err) } @@ -722,7 +722,7 @@ func (p *SkillProvider) getSkillsFolderID(ctx stdctx.Context) (string, error) { // findFolderID finds a folder by name under a parent folder func (p *SkillProvider) findFolderID(ctx stdctx.Context, parentID, folderName string) (string, error) { - resp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", parentID), true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", parentID), "auto", nil, nil) if err != nil { return "", fmt.Errorf("failed to list folders: %w", err) } @@ -769,7 +769,7 @@ func (p *SkillProvider) getSkillFolderID(ctx stdctx.Context, spaceID, skillName "page": 1, "page_size": 10, } - resp, err := p.httpClient.Request("POST", "/skills/search", true, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/skills/search", "auto", nil, payload) if err == nil { var searchResult struct { Code int `json:"code"` @@ -812,7 +812,7 @@ func (p *SkillProvider) listSkillVersions(ctx stdctx.Context, spaceID, skillName } // List the skill folder to get versions (subdirectories) - filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), true, "auto", nil, nil) + filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list versions: %w", err) } @@ -873,7 +873,7 @@ func (p *SkillProvider) listSkillContent(ctx stdctx.Context, spaceID, skillName, } // List the version folder under the skill folder - filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), true, "auto", nil, nil) + filesResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", skillFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list skill versions: %w", err) } @@ -930,7 +930,7 @@ func (p *SkillProvider) listSkillContent(ctx stdctx.Context, spaceID, skillName, isLastPart := (i == len(extraParts)-1) // List current folder to find the next part - subResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), true, "auto", nil, nil) + subResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to navigate path: %w", err) } @@ -1001,7 +1001,7 @@ func (p *SkillProvider) listSkillContent(ctx stdctx.Context, spaceID, skillName, } // Step 5: List the final folder contents - finalResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), true, "auto", nil, nil) + finalResp, err := p.httpClient.Request("GET", fmt.Sprintf("/files?parent_id=%s", currentFolderID), "auto", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list folder contents: %w", err) } @@ -1057,7 +1057,7 @@ func (p *SkillProvider) listSkillContent(ctx stdctx.Context, spaceID, skillName, // getSpaceUUIDByName gets space UUID by its name func (p *SkillProvider) getSpaceUUIDByName(ctx stdctx.Context, spaceName string) (string, error) { - resp, err := p.httpClient.Request("GET", "/skills/spaces", true, "auto", nil, nil) + resp, err := p.httpClient.Request("GET", "/skills/spaces", "auto", nil, nil) if err != nil { return "", fmt.Errorf("failed to list hubs: %w", err) } @@ -1104,7 +1104,7 @@ func (p *SkillProvider) DeleteSkill(ctx stdctx.Context, spaceID, skillName strin fmt.Sprintf("/skills/index?skill_id=%s&space_id=%s", url.QueryEscape(skillName), url.QueryEscape(spaceUUID)), - true, "auto", nil, nil) + "auto", nil, nil) if err != nil { return fmt.Errorf("delete index request failed: %w", err) } @@ -1147,7 +1147,7 @@ func (p *SkillProvider) IndexSkill(ctx stdctx.Context, spaceID string, skillInfo } // Call index API - resp, err := p.httpClient.Request("POST", "/skills/index", true, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/skills/index", "auto", nil, payload) if err != nil { return fmt.Errorf("index request failed: %w", err) } @@ -1175,7 +1175,7 @@ func (p *SkillProvider) IndexSkill(ctx stdctx.Context, spaceID string, skillInfo func (p *SkillProvider) getDefaultEmbdID(ctx stdctx.Context, spaceID string) (string, error) { resp, err := p.httpClient.Request("GET", fmt.Sprintf("/skills/config?embd_id=&space_id=%s", url.QueryEscape(spaceID)), - true, "web", nil, nil) + "web", nil, nil) if err != nil { return "", nil } @@ -1357,7 +1357,7 @@ func (p *SkillProvider) createFolder(ctx stdctx.Context, parentID, name string) payload["parent_id"] = parentID } - resp, err := p.httpClient.Request("POST", "/files", true, "auto", nil, payload) + resp, err := p.httpClient.Request("POST", "/files", "auto", nil, payload) if err != nil { return "", err } @@ -2063,7 +2063,7 @@ func (u *SkillUploader) createFolder(ctx stdctx.Context, parentID, name string) payload["parent_id"] = parentID } - resp, err := u.client.Request("POST", "/files", true, "auto", nil, payload) + resp, err := u.client.Request("POST", "/files", "auto", nil, payload) if err != nil { return "", err } diff --git a/internal/cli/http_client.go b/internal/cli/http_client.go index 111604927c..f8950fd56d 100644 --- a/internal/cli/http_client.go +++ b/internal/cli/http_client.go @@ -70,11 +70,8 @@ func (c *HTTPClient) NonAPIBase() string { } // BuildURL builds the full URL for a given path -func (c *HTTPClient) BuildURL(path string, useAPIBase bool) string { +func (c *HTTPClient) BuildURL(path string) string { base := c.APIBase() - if !useAPIBase { - base = c.NonAPIBase() - } if c.VerifySSL { return fmt.Sprintf("https://%s%s", base, path) } @@ -123,70 +120,8 @@ func (r *Response) JSON() (map[string]interface{}, error) { } // Request makes an HTTP request -func (c *HTTPClient) Request(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*Response, error) { - url := c.BuildURL(path, useAPIBase) - mergedHeaders := c.Headers(authKind, headers) - - var body io.Reader - if jsonBody != nil { - jsonData, err := json.Marshal(jsonBody) - if err != nil { - return nil, err - } - body = bytes.NewReader(jsonData) - if mergedHeaders == nil { - mergedHeaders = make(map[string]string) - } - mergedHeaders["Content-Type"] = "application/json" - } - - req, err := http.NewRequest(method, url, body) - if err != nil { - return nil, err - } - - for k, v := range mergedHeaders { - req.Header.Set(k, v) - } - - var resp *http.Response - startTime := time.Now() - resp, err = c.client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - duration := time.Since(startTime).Seconds() - - respBody, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - return &Response{ - StatusCode: resp.StatusCode, - Body: respBody, - Headers: resp.Header.Clone(), - Duration: duration, - }, nil -} - -// Request makes an HTTP request -func (c *HTTPClient) RequestWith2URL(method, webPath string, apiPath string, headers map[string]string, jsonBody map[string]interface{}) (*Response, error) { - var path string - var useAPIBase bool - var authKind string - if c.useAPIToken { - path = apiPath - useAPIBase = true - authKind = "api" - } else { - path = webPath - useAPIBase = false - authKind = "web" - } - - url := c.BuildURL(path, useAPIBase) +func (c *HTTPClient) Request(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*Response, error) { + url := c.BuildURL(path) mergedHeaders := c.Headers(authKind, headers) var body io.Reader @@ -235,12 +170,12 @@ func (c *HTTPClient) RequestWith2URL(method, webPath string, apiPath string, hea // RequestWithIterations makes multiple HTTP requests for benchmarking // Returns a map with "duration" (total time in seconds) and "response_list" -func (c *HTTPClient) RequestWithIterations(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}, iterations int) (*BenchmarkResponse, error) { +func (c *HTTPClient) RequestWithIterations(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}, iterations int) (*BenchmarkResponse, error) { response := new(BenchmarkResponse) if iterations <= 1 { start := time.Now() - resp, err := c.Request(method, path, useAPIBase, authKind, headers, jsonBody) + resp, err := c.Request(method, path, authKind, headers, jsonBody) totalDuration := time.Since(start).Seconds() if err != nil { return nil, err @@ -256,7 +191,7 @@ func (c *HTTPClient) RequestWithIterations(method, path string, useAPIBase bool, return response, nil } - url := c.BuildURL(path, useAPIBase) + url := c.BuildURL(path) mergedHeaders := c.Headers(authKind, headers) var body io.Reader @@ -328,8 +263,8 @@ func (c *HTTPClient) RequestWithIterations(method, path string, useAPIBase bool, } // RequestJSON makes an HTTP request and returns JSON response -func (c *HTTPClient) RequestJSON(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}) (map[string]interface{}, error) { - resp, err := c.Request(method, path, useAPIBase, authKind, headers, jsonBody) +func (c *HTTPClient) RequestJSON(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (map[string]interface{}, error) { + resp, err := c.Request(method, path, authKind, headers, jsonBody) if err != nil { return nil, err } @@ -338,7 +273,7 @@ func (c *HTTPClient) RequestJSON(method, path string, useAPIBase bool, authKind // UploadMultipart uploads data using multipart/form-data func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Reader) error { - url := c.BuildURL(path, true) + url := c.BuildURL(path) req, err := http.NewRequest("POST", url, body) if err != nil { @@ -381,8 +316,8 @@ func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Re } // RequestStream makes an HTTP request for SSE streaming and returns the response body reader -func (c *HTTPClient) RequestStream(method, path string, useAPIBase bool, authKind string, headers map[string]string, jsonBody map[string]interface{}) (io.ReadCloser, error) { - url := c.BuildURL(path, useAPIBase) +func (c *HTTPClient) RequestStream(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (io.ReadCloser, error) { + url := c.BuildURL(path) mergedHeaders := c.Headers(authKind, headers) var body io.Reader diff --git a/internal/cli/user_command.go b/internal/cli/user_command.go index fac17dbf4a..91121560ef 100644 --- a/internal/cli/user_command.go +++ b/internal/cli/user_command.go @@ -43,11 +43,11 @@ func (c *RAGFlowClient) PingServer(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode: multiple iterations - return c.HTTPClient.RequestWithIterations("GET", "/system/ping", false, "web", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/system/ping", "web", nil, nil, iterations) } // Single mode - resp, err := c.HTTPClient.Request("GET", "/system/ping", false, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/system/ping", "web", nil, nil) if err != nil { fmt.Printf("Error: %v\n", err) fmt.Println("Server is down") @@ -75,11 +75,11 @@ func (c *RAGFlowClient) ShowServerVersion(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode: multiple iterations - return c.HTTPClient.RequestWithIterations("GET", "/system/version", true, "web", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/system/version", "web", nil, nil, iterations) } // Single mode - resp, err := c.HTTPClient.Request("GET", "/system/version", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/system/version", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show version: %w", err) } @@ -110,11 +110,11 @@ func (c *RAGFlowClient) ListConfigs(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode: multiple iterations - return c.HTTPClient.RequestWithIterations("GET", "/system/configs", true, "web", nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/system/configs", "web", nil, nil, iterations) } // Single mode - resp, err := c.HTTPClient.Request("GET", "/system/configs", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/system/configs", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list configs: %w", err) } @@ -260,7 +260,7 @@ func (c *RAGFlowClient) SetLogLevel(cmd *Command) (ResponseIf, error) { "level": logLevel, } - resp, err := c.HTTPClient.Request("PUT", "/system/log", true, "admin", nil, payload) + resp, err := c.HTTPClient.Request("PUT", "/system/log", "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to change log level: %w", err) } @@ -317,7 +317,7 @@ func (c *RAGFlowClient) RegisterUser(cmd *Command) (ResponseIf, error) { "nickname": nickname, } - resp, err := c.HTTPClient.Request("POST", "/user/register", false, "admin", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/user/register", "admin", nil, payload) if err != nil { return nil, fmt.Errorf("failed to register user: %w", err) } @@ -368,11 +368,11 @@ func (c *RAGFlowClient) ListDatasets(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("GET", "/datasets", true, authKind, nil, nil, iterations) + return c.HTTPClient.RequestWithIterations("GET", "/datasets", authKind, nil, nil, iterations) } // Normal mode - resp, err := c.HTTPClient.Request("GET", "/datasets", true, authKind, nil, nil) + resp, err := c.HTTPClient.Request("GET", "/datasets", authKind, nil, nil) if err != nil { return nil, fmt.Errorf("failed to list datasets: %w", err) } @@ -396,7 +396,7 @@ func (c *RAGFlowClient) ListDatasets(cmd *Command) (ResponseIf, error) { // getDatasetID gets dataset ID by name func (c *RAGFlowClient) getDatasetID(datasetName string) (string, error) { - resp, err := c.HTTPClient.Request("GET", "/datasets", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/datasets", "web", nil, nil) if err != nil { return "", fmt.Errorf("failed to list datasets: %w", err) } @@ -500,11 +500,11 @@ func (c *RAGFlowClient) SearchOnDatasets(cmd *Command) (ResponseIf, error) { if iterations > 1 { // Benchmark mode - return raw result for benchmark stats - return c.HTTPClient.RequestWithIterations("POST", "/chunk/retrieval_test", false, "web", nil, payload, iterations) + return c.HTTPClient.RequestWithIterations("POST", "/chunk/retrieval_test", "web", nil, payload, iterations) } // Normal mode - resp, err := c.HTTPClient.Request("POST", "/chunk/retrieval_test", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/chunk/retrieval_test", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to search on datasets: %w", err) } @@ -579,7 +579,7 @@ func (c *RAGFlowClient) CreateToken(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("this command is only allowed in USER mode") } - resp, err := c.HTTPClient.Request("POST", "/system/tokens", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("POST", "/system/tokens", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to create token: %w", err) } @@ -610,7 +610,7 @@ func (c *RAGFlowClient) ListTokens(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("this command is only allowed in USER mode") } - resp, err := c.HTTPClient.Request("GET", "/system/tokens", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/system/tokens", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list tokens: %w", err) } @@ -642,7 +642,7 @@ func (c *RAGFlowClient) DropToken(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("token not provided") } - resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/system/tokens/%s", token), true, "web", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/system/tokens/%s", token), "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to drop token: %w", err) } @@ -683,7 +683,7 @@ func (c *RAGFlowClient) SetToken(cmd *Command) (ResponseIf, error) { c.HTTPClient.useAPIToken = true // Validate token by calling list tokens API - resp, err := c.HTTPClient.Request("GET", "/tokens", true, "api", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/tokens", "api", nil, nil) if err != nil { // Restore original token on error c.HTTPClient.APIToken = savedToken @@ -792,7 +792,7 @@ func (c *RAGFlowClient) CreateDataset(cmd *Command) (ResponseIf, error) { "vector_size": vectorSize, } - resp, err := c.HTTPClient.Request("POST", "/kb/doc_engine_table", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/kb/doc_engine_table", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to create table: %w", err) } @@ -849,7 +849,7 @@ func (c *RAGFlowClient) CreateDatasetInDocEngine(cmd *Command) (ResponseIf, erro "vector_size": vectorSize, } - resp, err := c.HTTPClient.Request("POST", "/kb/doc_engine_table", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/kb/doc_engine_table", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to create table: %w", err) } @@ -900,7 +900,7 @@ func (c *RAGFlowClient) DropDatasetInDocEngine(cmd *Command) (ResponseIf, error) "kb_id": datasetID, } - resp, err := c.HTTPClient.Request("DELETE", "/kb/doc_engine_table", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("DELETE", "/kb/doc_engine_table", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to drop dataset: %w", err) } @@ -936,7 +936,7 @@ func (c *RAGFlowClient) CreateMetadataInDocEngine(cmd *Command) (ResponseIf, err return nil, fmt.Errorf("this command is only allowed in USER mode") } - resp, err := c.HTTPClient.Request("POST", "/tenant/doc_engine_metadata_table", false, "web", nil, nil) + resp, err := c.HTTPClient.Request("POST", "/tenant/doc_engine_metadata_table", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to create metadata table: %w", err) } @@ -972,7 +972,7 @@ func (c *RAGFlowClient) DropMetadataInDocEngine(cmd *Command) (ResponseIf, error return nil, fmt.Errorf("this command is only allowed in USER mode") } - resp, err := c.HTTPClient.Request("DELETE", "/tenant/doc_engine_metadata_table", false, "web", nil, nil) + resp, err := c.HTTPClient.Request("DELETE", "/tenant/doc_engine_metadata_table", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to drop metadata table: %w", err) } @@ -1020,7 +1020,7 @@ func (c *RAGFlowClient) AddProvider(cmd *Command) (ResponseIf, error) { "provider_name": providerName, } - resp, err := c.HTTPClient.Request("PUT", "/providers", true, "web", nil, payload) + resp, err := c.HTTPClient.Request("PUT", "/providers", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to add provider: %w", err) } @@ -1049,7 +1049,7 @@ func (c *RAGFlowClient) ListProviders(cmd *Command) (ResponseIf, error) { return nil, fmt.Errorf("this command is only allowed in USER mode") } - resp, err := c.HTTPClient.Request("GET", "/providers", true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", "/providers", "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list providers: %w", err) } @@ -1090,7 +1090,7 @@ func (c *RAGFlowClient) DeleteProvider(cmd *Command) (ResponseIf, error) { "llm_factory": providerName, } - resp, err := c.HTTPClient.Request("DELETE", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("DELETE", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to delete provider: %w", err) } @@ -1153,7 +1153,7 @@ func (c *RAGFlowClient) CreateProviderInstance(cmd *Command) (ResponseIf, error) "region": region, } - resp, err := c.HTTPClient.Request("POST", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to create provider instance: %w", err) } @@ -1189,7 +1189,7 @@ func (c *RAGFlowClient) ListProviderInstances(cmd *Command) (ResponseIf, error) url := fmt.Sprintf("/providers/%s/instances", providerName) - resp, err := c.HTTPClient.Request("GET", url, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", url, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list instances: %w", err) } @@ -1230,7 +1230,7 @@ func (c *RAGFlowClient) ShowProviderInstance(cmd *Command) (ResponseIf, error) { url := fmt.Sprintf("/providers/%s/instances/%s", providerName, instanceName) - resp, err := c.HTTPClient.Request("GET", url, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", url, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show instance: %w", err) } @@ -1271,7 +1271,7 @@ func (c *RAGFlowClient) ShowInstanceBalance(cmd *Command) (ResponseIf, error) { url := fmt.Sprintf("/providers/%s/instances/%s/balance", providerName, instanceName) - resp, err := c.HTTPClient.Request("GET", url, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", url, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to show instance: %w", err) } @@ -1321,7 +1321,7 @@ func (c *RAGFlowClient) AlterProviderInstance(cmd *Command) (ResponseIf, error) "llm_name": newName, } - resp, err := c.HTTPClient.Request("PUT", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("PUT", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to alter instance: %w", err) } @@ -1366,7 +1366,7 @@ func (c *RAGFlowClient) DropProviderInstance(cmd *Command) (ResponseIf, error) { url := fmt.Sprintf("/providers/%s/instances", providerName) - resp, err := c.HTTPClient.Request("DELETE", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("DELETE", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to drop instance: %w", err) } @@ -1416,7 +1416,7 @@ func (c *RAGFlowClient) DropInstanceModel(cmd *Command) (ResponseIf, error) { url := fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName) - resp, err := c.HTTPClient.Request("DELETE", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("DELETE", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to drop instance: %w", err) } @@ -1454,7 +1454,7 @@ func (c *RAGFlowClient) ListInstanceModels(cmd *Command) (ResponseIf, error) { var endPoint string endPoint = fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName) - resp, err := c.HTTPClient.Request("GET", endPoint, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", endPoint, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to list instance models: %w", err) } @@ -1501,7 +1501,7 @@ func (c *RAGFlowClient) EnableOrDisableModel(cmd *Command, status string) (Respo "status": status, } - resp, err := c.HTTPClient.Request("PATCH", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("PATCH", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to enable/disable model: %w", err) } @@ -1687,7 +1687,7 @@ func (c *RAGFlowClient) ChatToModel(cmd *Command) (ResponseIf, error) { if stream { // Call stream http api startTime := time.Now() - reader, err := c.HTTPClient.RequestStream("POST", url, true, "web", nil, payload) + reader, err := c.HTTPClient.RequestStream("POST", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to chat model: %w", err) } @@ -1756,7 +1756,7 @@ func (c *RAGFlowClient) ChatToModel(cmd *Command) (ResponseIf, error) { return result, nil } - resp, err := c.HTTPClient.Request("POST", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", url, "web", nil, payload) if err != nil { if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) { return nil, fmt.Errorf("connection closed (EOF): upstream overloaded or proxy timeout: %w", err) @@ -1807,7 +1807,7 @@ func (c *RAGFlowClient) CheckProviderConnection(cmd *Command) (ResponseIf, error url := fmt.Sprintf("/providers/%s/instances/%s/connection", providerName, instanceName) - resp, err := c.HTTPClient.Request("GET", url, true, "web", nil, nil) + resp, err := c.HTTPClient.Request("GET", url, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to check provider connection: %w", err) } @@ -1929,7 +1929,7 @@ func (c *RAGFlowClient) AddCustomModel(cmd *Command) (ResponseIf, error) { payload["thinking"] = supportThink } - resp, err := c.HTTPClient.Request("POST", url, true, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", url, "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to check provider connection: %w", err) } @@ -2070,7 +2070,7 @@ func (c *RAGFlowClient) InsertDatasetFromFile(cmd *Command) (ResponseIf, error) "file_path": filePath, } - resp, err := c.HTTPClient.Request("POST", "/kb/insert_from_file", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/kb/insert_from_file", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to insert dataset from file: %w", err) } @@ -2115,7 +2115,7 @@ func (c *RAGFlowClient) InsertMetadataFromFile(cmd *Command) (ResponseIf, error) "file_path": filePath, } - resp, err := c.HTTPClient.Request("POST", "/tenant/insert_metadata_from_file", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/tenant/insert_metadata_from_file", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to insert metadata from file: %w", err) } @@ -2173,7 +2173,7 @@ func (c *RAGFlowClient) UpdateChunk(cmd *Command) (ResponseIf, error) { } // Try to get doc_id from the chunk retrieval endpoint - getResp, err := c.HTTPClient.Request("GET", "/chunk/get?chunk_id="+chunkID, false, "web", nil, nil) + getResp, err := c.HTTPClient.Request("GET", "/chunk/get?chunk_id="+chunkID, "web", nil, nil) if err != nil { return nil, fmt.Errorf("failed to get chunk info: %w", err) } @@ -2205,7 +2205,7 @@ func (c *RAGFlowClient) UpdateChunk(cmd *Command) (ResponseIf, error) { payload["document_id"] = docID payload["chunk_id"] = chunkID - resp, err := c.HTTPClient.Request("POST", "/chunk/update", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/chunk/update", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to update chunk: %w", err) } @@ -2256,7 +2256,7 @@ func (c *RAGFlowClient) SetMeta(cmd *Command) (ResponseIf, error) { "meta": metaJSON, } - resp, err := c.HTTPClient.Request("POST", "/document/set_meta", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/document/set_meta", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to set metadata: %w", err) } @@ -2311,7 +2311,7 @@ func (c *RAGFlowClient) RmTags(cmd *Command) (ResponseIf, error) { "tags": tags, } - resp, err := c.HTTPClient.Request("POST", "/kb/"+kbID+"/rm_tags", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/kb/"+kbID+"/rm_tags", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to remove tags: %w", err) } @@ -2363,7 +2363,7 @@ func (c *RAGFlowClient) RemoveChunks(cmd *Command) (ResponseIf, error) { payload["chunk_ids"] = chunkIDs } - resp, err := c.HTTPClient.Request("POST", "/chunk/rm", false, "web", nil, payload) + resp, err := c.HTTPClient.Request("POST", "/chunk/rm", "web", nil, payload) if err != nil { return nil, fmt.Errorf("failed to remove chunks: %w", err) } diff --git a/internal/cli/user_parser.go b/internal/cli/user_parser.go index 9efc8cf0ee..60d8eb7d91 100644 --- a/internal/cli/user_parser.go +++ b/internal/cli/user_parser.go @@ -68,39 +68,39 @@ func (p *Parser) parseRegisterCommand() (*Command, error) { if err := p.expectPeek(TokenUser); err != nil { return nil, err } - p.nextToken() + p.nextToken() // consume USER userName, err := p.parseQuotedString() if err != nil { return nil, err } cmd.Params["user_name"] = userName + p.nextToken() // consume Email - p.nextToken() if p.curToken.Type != TokenAs { return nil, fmt.Errorf("expected AS") } + p.nextToken() // consume AS - p.nextToken() nickname, err := p.parseQuotedString() if err != nil { return nil, err } cmd.Params["nickname"] = nickname + p.nextToken() // consume nickname - p.nextToken() if p.curToken.Type != TokenPassword { return nil, fmt.Errorf("expected PASSWORD") } + p.nextToken() // consume PASSWORD - p.nextToken() password, err := p.parseQuotedString() if err != nil { return nil, err } cmd.Params["password"] = password + p.nextToken() // consume 'password' - p.nextToken() // Semicolon is optional for UNSET TOKEN if p.curToken.Type == TokenSemicolon { p.nextToken() diff --git a/internal/router/router.go b/internal/router/router.go index 2316345360..3c9a3dd16e 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -89,20 +89,28 @@ func (r *Router) Setup(engine *gin.Engine) { engine.GET("/health", r.systemHandler.Health) // System endpoints - engine.GET("/v1/system/ping", r.systemHandler.Ping) - engine.GET("/api/v1/system/config", r.systemHandler.GetConfig) engine.GET("/v1/system/configs", r.systemHandler.GetConfigs) - engine.GET("/api/v1/system/version", r.systemHandler.GetVersion) engine.POST("/v1/user/register", r.userHandler.Register) - // User login channels endpoint - engine.GET("/api/v1/auth/login/channels", r.userHandler.GetLoginChannels) - - // User login by email endpoint - engine.POST("/api/v1/auth/login", r.userHandler.LoginByEmail) // User logout endpoint engine.GET("/v1/user/logout", r.userHandler.Logout) + apiNoAuth := engine.Group("/api/v1") + { + apiNoAuth.GET("/system/ping", r.systemHandler.Ping) + apiNoAuth.GET("/system/config", r.systemHandler.GetConfig) + apiNoAuth.GET("/system/version", r.systemHandler.GetVersion) + + // User login channels endpoint + apiNoAuth.GET("/auth/login/channels", r.userHandler.GetLoginChannels) + + // User login by email endpoint + apiNoAuth.POST("/auth/login", r.userHandler.LoginByEmail) + + // Register + apiNoAuth.POST("/users", r.userHandler.Register) + } + // Protected routes authorized := engine.Group("") authorized.Use(r.authHandler.AuthMiddleware())