Go: refactor CLI (#15728)

### What problem does this PR solve?

```
RAGFlow(user)> add api server 'ccc' host '127.0.0.1:9980';
SUCCESS
RAGFlow(user)> list api server;
+------------+---------------+-----------------+---------+-------------+---------------+
| api_server | api_server_ip | api_server_port | auth    | user_name   | user_password |
+------------+---------------+-----------------+---------+-------------+---------------+
| ccc        | 127.0.0.1     | 9980            | no auth |             |               |
| default    | 127.0.0.1     | 9384            | login   | aaa@aaa.com | ***           |
+------------+---------------+-----------------+---------+-------------+---------------+
RAGFlow(user)> delete api server 'ccc';
SUCCESS
RAGFlow(user)> list api server;
+------------+---------------+-----------------+---------+
| api_server | api_server_ip | api_server_port | auth    |
+------------+---------------+-----------------+---------+
| default    | 127.0.0.1     | 9384            | no auth |
+------------+---------------+-----------------+---------+

RAGFlow(user)> show admin server;
+--------------+-------+
| field        | value |
+--------------+-------+
| admin_server | N/A   |
+--------------+-------+
RAGFlow(user)> add admin server host '127.0.0.1:9880';
SUCCESS
RAGFlow(user)> show admin server;
+-------------------+-----------+
| field             | value     |
+-------------------+-----------+
| admin_server_ip   | 127.0.0.1 |
| admin_server_port | 9880      |
| auth              | no auth   |
+-------------------+-----------+
RAGFlow(user)> delete admin server;
SUCCESS
RAGFlow(user)> show admin server;
+--------------+-------+
| field        | value |
+--------------+-------+
| admin_server | N/A   |
+--------------+-------+

RAGFlow(user)> show current
+-----------------+-------------+
| field           | value       |
+-----------------+-------------+
| api_server_port | 9384        |
| user_name       | aaa@aaa.com |
| user_password   | ***         |
| mode            | api         |
| verbose         | false       |
| api_server      | default     |
| api_server_ip   | 127.0.0.1   |
| auth            | login       |
| output          | table       |
| interactive     | true        |
+-----------------+-------------+
```
### Type of change

- [x] Refactoring

---------

Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
Jin Hai
2026-06-09 15:22:50 +08:00
committed by GitHub
parent 1ab51a27bf
commit d02eb6b596
16 changed files with 2325 additions and 1425 deletions

View File

@@ -24,7 +24,7 @@ import (
// PingServer pings the server to check if it's alive
// Returns benchmark result map if iterations > 1, otherwise prints status
func (c *RAGFlowClient) PingAdmin(cmd *Command) (ResponseIf, error) {
func (c *CLI) PingAdmin(cmd *Command) (ResponseIf, error) {
// Get iterations from command params (for benchmark)
iterations := 1
if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
@@ -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", "web", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/ping", "web", nil, nil, iterations)
}
// Single mode
resp, err := c.HTTPClient.Request("GET", "/admin/ping", "web", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/ping", "web", nil, nil)
if err != nil {
fmt.Printf("Error: %v\n", err)
fmt.Println("Server is down")
@@ -58,7 +58,7 @@ func (c *RAGFlowClient) PingAdmin(cmd *Command) (ResponseIf, error) {
// Show admin version to show RAGFlow admin version
// Returns benchmark result map if iterations > 1, otherwise prints status
func (c *RAGFlowClient) ShowAdminVersion(cmd *Command) (ResponseIf, error) {
func (c *CLI) ShowAdminVersion(cmd *Command) (ResponseIf, error) {
// Get iterations from command params (for benchmark)
iterations := 1
if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
@@ -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", "web", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/version", "web", nil, nil, iterations)
}
// Single mode
resp, err := c.HTTPClient.Request("GET", "/admin/version", "web", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/version", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show admin version: %w", err)
}
@@ -93,9 +93,9 @@ func (c *RAGFlowClient) ShowAdminVersion(cmd *Command) (ResponseIf, error) {
}
// ListRoles to list roles (admin mode only)
func (c *RAGFlowClient) ListRoles(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListRoles(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
// Check for benchmark iterations
@@ -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", "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/roles", "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", "/admin/roles", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/roles", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list roles: %w", err)
}
@@ -136,9 +136,9 @@ func (c *RAGFlowClient) ListRoles(cmd *Command) (ResponseIf, error) {
}
// ShowRole to show role (admin mode only)
func (c *RAGFlowClient) ShowRole(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ShowRole(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
roleName := cmd.Params["role_name"].(string)
@@ -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, "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", endPoint, "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", endPoint, "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show role: %w", err)
}
@@ -179,9 +179,9 @@ func (c *RAGFlowClient) ShowRole(cmd *Command) (ResponseIf, error) {
}
// CreateRole creates a new role (admin mode only)
func (c *RAGFlowClient) CreateRole(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) CreateRole(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
roleName, ok := cmd.Params["role_name"].(string)
@@ -197,7 +197,7 @@ func (c *RAGFlowClient) CreateRole(cmd *Command) (ResponseIf, error) {
payload["description"] = description
}
resp, err := c.HTTPClient.Request("POST", "/admin/roles", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("POST", "/admin/roles", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create role: %w", err)
}
@@ -220,9 +220,9 @@ func (c *RAGFlowClient) CreateRole(cmd *Command) (ResponseIf, error) {
}
// DropRole deletes the role (admin mode only)
func (c *RAGFlowClient) DropRole(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) DropRole(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
roleName, ok := cmd.Params["role_name"].(string)
@@ -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), "admin", nil, nil)
resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop role: %w", err)
}
@@ -253,9 +253,9 @@ func (c *RAGFlowClient) DropRole(cmd *Command) (ResponseIf, error) {
}
// AlterRole alters the role rights (admin mode only)
func (c *RAGFlowClient) AlterRole(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AlterRole(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
roleName, ok := cmd.Params["role_name"].(string)
@@ -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), "admin", nil, payload)
resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to alter role: %w", err)
}
@@ -294,9 +294,9 @@ func (c *RAGFlowClient) AlterRole(cmd *Command) (ResponseIf, error) {
}
// GrantAdmin grants admin privileges to a user (admin mode only)
func (c *RAGFlowClient) GrantAdmin(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) GrantAdmin(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -327,9 +327,9 @@ func (c *RAGFlowClient) GrantAdmin(cmd *Command) (ResponseIf, error) {
}
// RevokeAdmin revokes admin privileges from a user (admin mode only)
func (c *RAGFlowClient) RevokeAdmin(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) RevokeAdmin(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -360,9 +360,9 @@ func (c *RAGFlowClient) RevokeAdmin(cmd *Command) (ResponseIf, error) {
}
// CreateUser creates a new user (admin mode only)
func (c *RAGFlowClient) CreateUser(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) CreateUser(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -387,7 +387,7 @@ func (c *RAGFlowClient) CreateUser(cmd *Command) (ResponseIf, error) {
"role": "user",
}
resp, err := c.HTTPClient.Request("POST", "/admin/users", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("POST", "/admin/users", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create user: %w", err)
}
@@ -410,9 +410,9 @@ func (c *RAGFlowClient) CreateUser(cmd *Command) (ResponseIf, error) {
}
// ActivateUser activates or deactivates a user (admin mode only)
func (c *RAGFlowClient) ActivateUser(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ActivateUser(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -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), "admin", nil, payload)
resp, err := c.AdminServerClient.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)
}
@@ -457,9 +457,9 @@ func (c *RAGFlowClient) ActivateUser(cmd *Command) (ResponseIf, error) {
}
// AlterUserPassword changes a user's password (admin mode only)
func (c *RAGFlowClient) AlterUserPassword(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AlterUserPassword(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -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), "admin", nil, payload)
resp, err := c.AdminServerClient.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)
}
@@ -511,9 +511,9 @@ type listServicesResponse struct {
}
// ListServices lists all services (admin mode only)
func (c *RAGFlowClient) ListServices(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListServices(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
// Check for benchmark iterations
@@ -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", "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/services", "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", "/admin/services", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/services", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list services: %w", err)
}
@@ -554,9 +554,9 @@ func (c *RAGFlowClient) ListServices(cmd *Command) (ResponseIf, error) {
}
// Show service show service (admin mode only)
func (c *RAGFlowClient) ShowService(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ShowService(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
serviceIndex := cmd.Params["number"].(int)
@@ -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, "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", endPoint, "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", endPoint, "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show service: %w", err)
}
@@ -610,9 +610,9 @@ func normalizeVariableRows(rows []map[string]interface{}) {
}
// ListVariables lists all system variables (admin mode only).
func (c *RAGFlowClient) ListVariables(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListVariables(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
iterations := 1
@@ -621,10 +621,10 @@ func (c *RAGFlowClient) ListVariables(cmd *Command) (ResponseIf, error) {
}
if iterations > 1 {
return c.HTTPClient.RequestWithIterations("GET", "/admin/variables", "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/variables", "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", "/admin/variables", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/variables", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list variables: %w", err)
}
@@ -648,9 +648,9 @@ func (c *RAGFlowClient) ListVariables(cmd *Command) (ResponseIf, error) {
}
// ShowVariable shows system variables by exact name or name prefix (admin mode only).
func (c *RAGFlowClient) ShowVariable(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ShowVariable(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
varName, ok := cmd.Params["var_name"].(string)
@@ -665,10 +665,10 @@ func (c *RAGFlowClient) ShowVariable(cmd *Command) (ResponseIf, error) {
payload := map[string]interface{}{"var_name": varName}
if iterations > 1 {
return c.HTTPClient.RequestWithIterations("GET", "/admin/variables", "admin", nil, payload, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/variables", "admin", nil, payload, iterations)
}
resp, err := c.HTTPClient.Request("GET", "/admin/variables", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("GET", "/admin/variables", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to show variable: %w", err)
}
@@ -692,9 +692,9 @@ func (c *RAGFlowClient) ShowVariable(cmd *Command) (ResponseIf, error) {
}
// SetVariable updates a system variable (admin mode only).
func (c *RAGFlowClient) SetVariable(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) SetVariable(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
varName, ok := cmd.Params["var_name"].(string)
@@ -710,7 +710,7 @@ func (c *RAGFlowClient) SetVariable(cmd *Command) (ResponseIf, error) {
"var_name": varName,
"var_value": varValue,
}
resp, err := c.HTTPClient.Request("PUT", "/admin/variables", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("PUT", "/admin/variables", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set variable: %w", err)
}
@@ -734,9 +734,9 @@ func (c *RAGFlowClient) SetVariable(cmd *Command) (ResponseIf, error) {
// ListUsers lists all users (admin mode only)
// Returns (result_map, error) - result_map is non-nil for benchmark mode
func (c *RAGFlowClient) ListUsers(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListUsers(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
// Check for benchmark iterations
@@ -747,10 +747,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", "admin", nil, nil, iterations)
return c.AdminServerClient.RequestWithIterations("GET", "/admin/users", "admin", nil, nil, iterations)
}
resp, err := c.HTTPClient.Request("GET", "/admin/users", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/users", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list users: %w", err)
}
@@ -777,9 +777,9 @@ func (c *RAGFlowClient) ListUsers(cmd *Command) (ResponseIf, error) {
}
// DropUser deletes a user (admin mode only)
func (c *RAGFlowClient) DropUser(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) DropUser(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -787,7 +787,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), "admin", nil, nil)
resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/users/%s", userName), "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop user: %w", err)
}
@@ -810,9 +810,9 @@ func (c *RAGFlowClient) DropUser(cmd *Command) (ResponseIf, error) {
}
// Show user show user (admin mode only)
func (c *RAGFlowClient) ShowUser(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ShowUser(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -820,7 +820,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), "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", fmt.Sprintf("/admin/users/%s", userName), "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show user: %w", err)
}
@@ -844,9 +844,9 @@ func (c *RAGFlowClient) ShowUser(cmd *Command) (ResponseIf, error) {
// ListUserDatasets lists datasets for a specific user (admin mode)
// Returns (result_map, error) - result_map is non-nil for benchmark mode
func (c *RAGFlowClient) ListUserDatasets(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -862,10 +862,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), "admin", nil, nil, iterations)
return c.AdminServerClient.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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -899,9 +899,9 @@ func (c *RAGFlowClient) ListUserDatasets(cmd *Command) (ResponseIf, error) {
// ListAgents lists agents for a specific user (admin mode)
// Returns (result_map, error) - result_map is non-nil for benchmark mode
func (c *RAGFlowClient) ListAgents(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListAgents(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -917,10 +917,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), "admin", nil, nil, iterations)
return c.AdminServerClient.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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -953,9 +953,9 @@ func (c *RAGFlowClient) ListAgents(cmd *Command) (ResponseIf, error) {
}
// GrantPermission grants permission to a role (admin mode only)
func (c *RAGFlowClient) GrantPermission(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) GrantPermission(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -963,7 +963,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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -991,9 +991,9 @@ func (c *RAGFlowClient) GrantPermission(cmd *Command) (ResponseIf, error) {
}
// RevokePermission revokes permission from a role (admin mode only)
func (c *RAGFlowClient) RevokePermission(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) RevokePermission(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
roleName, ok := cmd.Params["role_name"].(string)
@@ -1023,7 +1023,7 @@ func (c *RAGFlowClient) RevokePermission(cmd *Command) (ResponseIf, error) {
"actions": actions,
}
resp, err := c.HTTPClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s/permission", roleName), "admin", nil, payload)
resp, err := c.AdminServerClient.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)
}
@@ -1051,9 +1051,9 @@ func (c *RAGFlowClient) RevokePermission(cmd *Command) (ResponseIf, error) {
}
// AlterUserRole alters user's role (admin mode only)
func (c *RAGFlowClient) AlterUserRole(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AlterUserRole(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -1070,7 +1070,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), "admin", nil, payload)
resp, err := c.AdminServerClient.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)
}
@@ -1098,9 +1098,9 @@ func (c *RAGFlowClient) AlterUserRole(cmd *Command) (ResponseIf, error) {
}
// ShowUserPermission shows user's permissions (admin mode only)
func (c *RAGFlowClient) ShowUserPermission(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -1108,7 +1108,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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -1136,9 +1136,9 @@ func (c *RAGFlowClient) ShowUserPermission(cmd *Command) (ResponseIf, error) {
}
// GenerateAdminToken generates an API token for a user (admin mode only)
func (c *RAGFlowClient) GenerateAdminToken(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) GenerateAdminToken(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -1146,7 +1146,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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -1173,9 +1173,9 @@ func (c *RAGFlowClient) GenerateAdminToken(cmd *Command) (ResponseIf, error) {
}
// ListAdminTokens lists all API tokens for a user (admin mode only)
func (c *RAGFlowClient) ListAdminTokens(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListAdminTokens(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -1183,7 +1183,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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -1215,9 +1215,9 @@ func (c *RAGFlowClient) ListAdminTokens(cmd *Command) (ResponseIf, error) {
}
// DropToken drops an API token for a user (admin mode only)
func (c *RAGFlowClient) DropAdminToken(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) DropAdminToken(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
userName, ok := cmd.Params["user_name"].(string)
@@ -1233,7 +1233,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), "admin", nil, nil)
resp, err := c.AdminServerClient.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)
}
@@ -1255,12 +1255,12 @@ func (c *RAGFlowClient) DropAdminToken(cmd *Command) (ResponseIf, error) {
return &result, nil
}
func (c *RAGFlowClient) ListAdminTasks(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListAdminTasks(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
resp, err := c.HTTPClient.Request("GET", "/admin/tasks", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/tasks", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop token: %w", err)
}
@@ -1282,11 +1282,11 @@ func (c *RAGFlowClient) ListAdminTasks(cmd *Command) (ResponseIf, error) {
return &result, nil
}
func (c *RAGFlowClient) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
resp, err := c.HTTPClient.Request("GET", "/admin/ingestors", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/ingestors", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list ingestors: %w", err)
}
@@ -1307,12 +1307,12 @@ func (c *RAGFlowClient) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
result.Duration = resp.Duration
return &result, nil
}
func (c *RAGFlowClient) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
resp, err := c.HTTPClient.Request("GET", "/admin/ingestion/tasks", "admin", nil, nil)
resp, err := c.AdminServerClient.Request("GET", "/admin/ingestion/tasks", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list admin tasks: %w", err)
}
@@ -1334,9 +1334,9 @@ func (c *RAGFlowClient) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error
return &result, nil
}
func (c *RAGFlowClient) AdminStartIngestionCommand(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AdminStartIngestionCommand(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
fileURI, ok := cmd.Params["uri"].(string)
@@ -1348,7 +1348,7 @@ func (c *RAGFlowClient) AdminStartIngestionCommand(cmd *Command) (ResponseIf, er
"from": "CLI",
}
resp, err := c.HTTPClient.Request("POST", "/admin/ingestion", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("POST", "/admin/ingestion", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to ingest file: %w", err)
}
@@ -1370,9 +1370,9 @@ func (c *RAGFlowClient) AdminStartIngestionCommand(cmd *Command) (ResponseIf, er
return &result, nil
}
func (c *RAGFlowClient) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
taskID, ok := cmd.Params["task_id"].(string)
@@ -1384,7 +1384,7 @@ func (c *RAGFlowClient) AdminStopIngestionCommand(cmd *Command) (ResponseIf, err
"from": "CLI",
}
resp, err := c.HTTPClient.Request("DELETE", "/admin/ingestion", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("DELETE", "/admin/ingestion", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to ingest file: %w", err)
}
@@ -1406,9 +1406,9 @@ func (c *RAGFlowClient) AdminStopIngestionCommand(cmd *Command) (ResponseIf, err
return &result, nil
}
func (c *RAGFlowClient) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
if c.ServerType != "admin" {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode")
func (c *CLI) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode || c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
ingestorName, ok := cmd.Params["ingestor_name"].(string)
@@ -1419,7 +1419,7 @@ func (c *RAGFlowClient) AdminShutdownIngestor(cmd *Command) (ResponseIf, error)
"ingestor_name": ingestorName,
}
resp, err := c.HTTPClient.Request("DELETE", "/admin/ingestors", "admin", nil, payload)
resp, err := c.AdminServerClient.Request("DELETE", "/admin/ingestors", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to shutdown ingestor: %w", err)
}