Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Go CLI: fix benchmark (#19946)

Jin Hai84b7608668db
diff --git a/cmd/ragflow-cli.go b/cmd/ragflow-cli.go
index 3a78ea11b7..7302486f3b 100644
--- a/cmd/ragflow-cli.go
+++ b/cmd/ragflow-cli.go
@@ -30,24 +30,25 @@ import (
func main() {
- arguments, err := cli.ParseArgs(os.Args[1:])
+ var err error
+ cli.Arguments, err = cli.ParseArgs(os.Args[1:])
if err != nil {
return
}
- if arguments.ShowHelp {
+ if cli.Arguments.ShowHelp {
cli.PrintUsage()
return
}
- if arguments.ShowVersion {
+ if cli.Arguments.ShowVersion {
fmt.Println("RAGFlow CLI version 1.0.0") // Replace with actual version if needed
return
}
- //arguments.Print()
+ // cli.Arguments.Print()
logLevel := "warn" // Default to warn (quiet mode)
- if arguments.Verbose {
+ if cli.Arguments.Verbose {
logLevel = "info"
}
@@ -55,7 +56,7 @@ func main() {
fmt.Printf("Warning: Failed to initialize logger: %v\n", err)
}
- client, err := cli.NewCLIWithConfig(arguments)
+ client, err := cli.NewCLIWithConfig(cli.Arguments)
if err != nil {
fmt.Printf("Failed to create CLI: %v\n", err)
os.Exit(1)
@@ -69,8 +70,8 @@ func main() {
os.Exit(0)
}()
- if arguments.Command != nil {
- if err = client.RunSingleCommand(arguments.Command); err != nil {
+ if cli.Arguments.Command != nil {
+ if err = client.RunSingleCommand(cli.Arguments.Command); err != nil {
fmt.Printf("Command execution failed: %v\n", err)
os.Exit(1)
}
diff --git a/internal/cli/admin_command.go b/internal/cli/admin_command.go
index b59dbc8487..e85fa1241e 100644
--- a/internal/cli/admin_command.go
+++ b/internal/cli/admin_command.go
@@ -26,20 +26,9 @@ import (
// PingServer pings the server to check if it's alive
// Returns benchmark result map if iterations > 1, otherwise prints status
-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 {
- iterations = val
- }
-
- if iterations > 1 {
- // Benchmark mode: multiple iterations
- return c.AdminServerClient.RequestWithIterations("GET", "/admin/ping", "web", nil, nil, iterations)
- }
-
+func (c *CLI) PingAdmin(commandCount int, cmd *Command) (ResponseIf, error) {
// Single mode
- resp, err := c.AdminServerClient.Request("GET", "/admin/ping", "web", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/ping", "web", nil, nil)
if err != nil {
fmt.Printf("Error: %v\n", err)
fmt.Println("Server is down")
@@ -50,8 +39,8 @@ func (c *CLI) PingAdmin(cmd *Command) (ResponseIf, error) {
}
// AdminPingStoreCommand ping object store
-func (c *CLI) AdminPingStoreCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/admin/store", "admin", nil, nil)
+func (c *CLI) AdminPingStoreCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/store", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to ping object store: %w", err)
}
@@ -60,8 +49,8 @@ func (c *CLI) AdminPingStoreCommand(cmd *Command) (ResponseIf, error) {
}
// AdminPingEngineCommand ping document engine
-func (c *CLI) AdminPingEngineCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/admin/engine", "admin", nil, nil)
+func (c *CLI) AdminPingEngineCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/engine", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to ping document engine: %w", err)
}
@@ -70,8 +59,8 @@ func (c *CLI) AdminPingEngineCommand(cmd *Command) (ResponseIf, error) {
}
// AdminPingMQCommand ping message queue
-func (c *CLI) AdminPingMQCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/admin/queue", "admin", nil, nil)
+func (c *CLI) AdminPingMQCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/queue", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to ping message queue: %w", err)
}
@@ -80,8 +69,8 @@ func (c *CLI) AdminPingMQCommand(cmd *Command) (ResponseIf, error) {
}
// AdminPingCacheCommand ping cache
-func (c *CLI) AdminPingCacheCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/admin/cache", "web", nil, nil)
+func (c *CLI) AdminPingCacheCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/cache", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to ping cache: %w", err)
}
@@ -90,8 +79,8 @@ func (c *CLI) AdminPingCacheCommand(cmd *Command) (ResponseIf, error) {
}
// AdminLiveServerCommand GET /live
-func (c *CLI) AdminLiveServerCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/live", "none", nil, nil)
+func (c *CLI) AdminLiveServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/live", "none", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show live server: %w", err)
}
@@ -99,8 +88,8 @@ func (c *CLI) AdminLiveServerCommand(cmd *Command) (ResponseIf, error) {
}
// AdminHealthServerCommand GET /healthz
-func (c *CLI) AdminHealthServerCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/healthz", "none", nil, nil)
+func (c *CLI) AdminHealthServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/healthz", "none", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show health server: %w", err)
}
@@ -108,8 +97,8 @@ func (c *CLI) AdminHealthServerCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowVersionCommand show RAGFlow admin version
-func (c *CLI) AdminShowVersionCommand(cmd *Command) (ResponseIf, error) {
- resp, err := c.AdminServerClient.Request("GET", "/admin/version", "web", nil, nil)
+func (c *CLI) AdminShowVersionCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/version", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show admin version: %w", err)
}
@@ -118,12 +107,12 @@ func (c *CLI) AdminShowVersionCommand(cmd *Command) (ResponseIf, error) {
}
// AdminListResourcesCommand to list resources command (admin mode only)
-func (c *CLI) AdminListResourcesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListResourcesCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/roles/resource", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/roles/resource", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list resources: %w", err)
}
@@ -132,23 +121,12 @@ func (c *CLI) AdminListResourcesCommand(cmd *Command) (ResponseIf, error) {
}
// AdminListRolesCommand to list roles command (admin mode only)
-func (c *CLI) AdminListRolesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListRolesCommand(commandCount int, 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
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
- if iterations > 1 {
- // Benchmark mode - return raw result for benchmark stats
- return c.AdminServerClient.RequestWithIterations("GET", "/admin/roles", "admin", nil, nil, iterations)
- }
-
- resp, err := c.AdminServerClient.Request("GET", "/admin/roles", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/roles", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list roles: %w", err)
}
@@ -175,14 +153,14 @@ func (c *CLI) AdminListRolesCommand(cmd *Command) (ResponseIf, error) {
}
// AdminListProvidersCommand to list providers command (admin mode only)
-func (c *CLI) AdminListProvidersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListProvidersCommand(commandCount int, 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")
}
apiURL := fmt.Sprintf("/admin/providers")
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list providers: %w", err)
}
@@ -191,7 +169,7 @@ func (c *CLI) AdminListProvidersCommand(cmd *Command) (ResponseIf, error) {
}
// AdminCreateRoleCommand creates a new role (admin mode only)
-func (c *CLI) AdminCreateRoleCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminCreateRoleCommand(commandCount int, 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")
}
@@ -209,7 +187,7 @@ func (c *CLI) AdminCreateRoleCommand(cmd *Command) (ResponseIf, error) {
payload["description"] = description
}
- resp, err := c.AdminServerClient.Request("POST", "/admin/roles", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", "/admin/roles", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create role: %w", err)
}
@@ -218,7 +196,7 @@ func (c *CLI) AdminCreateRoleCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDropRoleCommand deletes the role (admin mode only)
-func (c *CLI) AdminDropRoleCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDropRoleCommand(commandCount int, 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")
}
@@ -228,7 +206,7 @@ func (c *CLI) AdminDropRoleCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("role_name not provided")
}
- resp, err := c.AdminServerClient.Request("DELETE", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop role: %w", err)
}
@@ -237,7 +215,7 @@ func (c *CLI) AdminDropRoleCommand(cmd *Command) (ResponseIf, error) {
}
// AdminAlterRole alters the role rights (admin mode only)
-func (c *CLI) AdminAlterRole(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminAlterRole(commandCount int, 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")
}
@@ -255,7 +233,7 @@ func (c *CLI) AdminAlterRole(cmd *Command) (ResponseIf, error) {
payload["description"] = description
}
- resp, err := c.AdminServerClient.Request("PUT", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", fmt.Sprintf("/admin/roles/%s", roleName), "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to alter role: %w", err)
}
@@ -264,7 +242,7 @@ func (c *CLI) AdminAlterRole(cmd *Command) (ResponseIf, error) {
}
// AdminGrantUserAdminCommand grants admin privileges to a user (admin mode only)
-func (c *CLI) AdminGrantUserAdminCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminGrantUserAdminCommand(commandCount int, 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")
}
@@ -277,7 +255,7 @@ func (c *CLI) AdminGrantUserAdminCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
- resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to grant admin: %w", err)
}
@@ -286,7 +264,7 @@ func (c *CLI) AdminGrantUserAdminCommand(cmd *Command) (ResponseIf, error) {
}
// AdminRevokeUserAdminCommand revokes admin privileges from a user (admin mode only)
-func (c *CLI) AdminRevokeUserAdminCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminRevokeUserAdminCommand(commandCount int, 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")
}
@@ -299,7 +277,7 @@ func (c *CLI) AdminRevokeUserAdminCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/admin", encodedUserName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to revoke admin: %w", err)
}
@@ -308,7 +286,7 @@ func (c *CLI) AdminRevokeUserAdminCommand(cmd *Command) (ResponseIf, error) {
}
// AdminGrantRolePermissionCommand grants permission to role (admin mode only)
-func (c *CLI) AdminGrantRolePermissionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminGrantRolePermissionCommand(commandCount int, 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")
}
@@ -335,7 +313,7 @@ func (c *CLI) AdminGrantRolePermissionCommand(cmd *Command) (ResponseIf, error)
apiURL := fmt.Sprintf("/admin/roles/%s/permission", roleName)
- resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to grant permission to role: %w", err)
}
@@ -344,7 +322,7 @@ func (c *CLI) AdminGrantRolePermissionCommand(cmd *Command) (ResponseIf, error)
}
// AdminRevokeRolePermissionCommand revokes permission from role (admin mode only)
-func (c *CLI) AdminRevokeRolePermissionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminRevokeRolePermissionCommand(commandCount int, 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")
}
@@ -371,7 +349,7 @@ func (c *CLI) AdminRevokeRolePermissionCommand(cmd *Command) (ResponseIf, error)
apiURL := fmt.Sprintf("/admin/roles/%s/permission", roleName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to revoke permission from role: %w", err)
}
@@ -380,7 +358,7 @@ func (c *CLI) AdminRevokeRolePermissionCommand(cmd *Command) (ResponseIf, error)
}
// AdminShowRolePermissionCommand shows admin privileges from a user (admin mode only)
-func (c *CLI) AdminShowRolePermissionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowRolePermissionCommand(commandCount int, 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")
}
@@ -392,7 +370,7 @@ func (c *CLI) AdminShowRolePermissionCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/roles/%s/permission", roleName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show role permission: %w", err)
}
@@ -401,7 +379,7 @@ func (c *CLI) AdminShowRolePermissionCommand(cmd *Command) (ResponseIf, error) {
}
// AdminCreateUserCommand creates a new user (admin mode only)
-func (c *CLI) AdminCreateUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminCreateUserCommand(commandCount int, 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")
}
@@ -433,7 +411,7 @@ func (c *CLI) AdminCreateUserCommand(cmd *Command) (ResponseIf, error) {
"role": "user",
}
- resp, err := c.AdminServerClient.Request("POST", "/admin/users", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", "/admin/users", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create user: %w", err)
}
@@ -442,7 +420,7 @@ func (c *CLI) AdminCreateUserCommand(cmd *Command) (ResponseIf, error) {
}
// AdminCreateUserAPIKeyCommand creates a new user API key (admin mode only)
-func (c *CLI) AdminCreateUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminCreateUserAPIKeyCommand(commandCount int, 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")
}
@@ -456,7 +434,7 @@ func (c *CLI) AdminCreateUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
- resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create API key: %w", err)
}
@@ -483,7 +461,7 @@ func (c *CLI) AdminCreateUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
}
// AdminActivateUser activates or deactivates a user (admin mode only)
-func (c *CLI) AdminActivateUser(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminActivateUser(commandCount int, 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")
}
@@ -510,7 +488,7 @@ func (c *CLI) AdminActivateUser(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/activate", encodedUserName)
- resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to update user status: %w", err)
}
@@ -519,7 +497,7 @@ func (c *CLI) AdminActivateUser(cmd *Command) (ResponseIf, error) {
}
// AdminAlterUserPassword changes a user's password (admin mode only)
-func (c *CLI) AdminAlterUserPassword(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminAlterUserPassword(commandCount int, 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")
}
@@ -552,7 +530,7 @@ func (c *CLI) AdminAlterUserPassword(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/password", encodedUserName)
- resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to change user password: %w", err)
}
@@ -567,12 +545,12 @@ type listServicesResponse struct {
}
// AdminListServicesCommand lists all services (admin mode only)
-func (c *CLI) AdminListServicesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListServicesCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/services", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/services", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list services: %w", err)
}
@@ -581,7 +559,7 @@ func (c *CLI) AdminListServicesCommand(cmd *Command) (ResponseIf, error) {
}
// AdminStartServiceCommand starts a service (admin mode only)
-func (c *CLI) AdminStartServiceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStartServiceCommand(commandCount int, 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")
}
@@ -593,7 +571,7 @@ func (c *CLI) AdminStartServiceCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/services/%s", serviceName)
- resp, err := c.AdminServerClient.Request("POST", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to start service: %w", err)
}
@@ -602,7 +580,7 @@ func (c *CLI) AdminStartServiceCommand(cmd *Command) (ResponseIf, error) {
}
// AdminRestartServiceCommand restarts a service (admin mode only)
-func (c *CLI) AdminRestartServiceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminRestartServiceCommand(commandCount int, 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")
}
@@ -614,7 +592,7 @@ func (c *CLI) AdminRestartServiceCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/services/%s", serviceName)
- resp, err := c.AdminServerClient.Request("PUT", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to restart service: %w", err)
}
@@ -623,7 +601,7 @@ func (c *CLI) AdminRestartServiceCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShutdownServiceCommand shuts down a service (admin mode only)
-func (c *CLI) AdminShutdownServiceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShutdownServiceCommand(commandCount int, 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")
}
@@ -635,7 +613,7 @@ func (c *CLI) AdminShutdownServiceCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/services/%s", serviceName)
- resp, err := c.AdminServerClient.Request("DELETE", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to shutdown service: %w", err)
}
@@ -644,7 +622,7 @@ func (c *CLI) AdminShutdownServiceCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowService show service (admin mode only)
-func (c *CLI) AdminShowService(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowService(commandCount int, 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")
}
@@ -656,7 +634,7 @@ func (c *CLI) AdminShowService(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/services/%s", serviceName)
- resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show service: %w", err)
}
@@ -678,12 +656,12 @@ func normalizeVariableRows(rows []map[string]interface{}) {
}
// AdminListVariablesCommand lists all system variables (admin mode only).
-func (c *CLI) AdminListVariablesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListVariablesCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/variables", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/variables", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list variables: %w", err)
}
@@ -707,12 +685,12 @@ func (c *CLI) AdminListVariablesCommand(cmd *Command) (ResponseIf, error) {
}
// AdminListConfigsCommand lists all system configs (admin mode only).
-func (c *CLI) AdminListConfigsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListConfigsCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/configs", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/configs", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list configs: %w", err)
}
@@ -736,12 +714,12 @@ func (c *CLI) AdminListConfigsCommand(cmd *Command) (ResponseIf, error) {
}
// AdminListEnvironmentsCommand lists all system environments (admin mode only).
-func (c *CLI) AdminListEnvironmentsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListEnvironmentsCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/environments", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/environments", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list environments: %w", err)
}
@@ -750,7 +728,7 @@ func (c *CLI) AdminListEnvironmentsCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowVariable shows system variables by exact name or name prefix (admin mode only).
-func (c *CLI) AdminShowVariable(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowVariable(commandCount int, 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")
}
@@ -764,7 +742,7 @@ func (c *CLI) AdminShowVariable(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/variables/%s", encodedVarName)
- resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show variable: %w", err)
}
@@ -787,7 +765,7 @@ func (c *CLI) AdminShowVariable(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminSetLicenseCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetLicenseCommand(commandCount int, 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")
}
@@ -800,7 +778,7 @@ func (c *CLI) AdminSetLicenseCommand(cmd *Command) (ResponseIf, error) {
payload := map[string]interface{}{
"license": license,
}
- resp, err := c.AdminServerClient.Request("POST", "/admin/system/license", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", "/admin/system/license", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set license: %w", err)
}
@@ -808,7 +786,7 @@ func (c *CLI) AdminSetLicenseCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "set license")
}
-func (c *CLI) AdminSetSoftFingerprintCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetSoftFingerprintCommand(commandCount int, 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")
}
@@ -821,7 +799,7 @@ func (c *CLI) AdminSetSoftFingerprintCommand(cmd *Command) (ResponseIf, error) {
payload := map[string]interface{}{
"fingerprint": softFingerprint,
}
- resp, err := c.AdminServerClient.Request("POST", "/admin/system/soft-fingerprint", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", "/admin/system/soft-fingerprint", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set soft fingerprint: %w", err)
}
@@ -829,7 +807,7 @@ func (c *CLI) AdminSetSoftFingerprintCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "set soft fingerprint")
}
-func (c *CLI) AdminSetLicenseConfigCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetLicenseConfigCommand(commandCount int, 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")
}
@@ -847,7 +825,7 @@ func (c *CLI) AdminSetLicenseConfigCommand(cmd *Command) (ResponseIf, error) {
"value1": value1,
"value2": value2,
}
- resp, err := c.AdminServerClient.Request("PUT", "/admin/system/license/config", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", "/admin/system/license/config", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set license config: %w", err)
}
@@ -856,7 +834,7 @@ func (c *CLI) AdminSetLicenseConfigCommand(cmd *Command) (ResponseIf, error) {
}
// AdminSetVariableCommand updates a system variable (admin mode only).
-func (c *CLI) AdminSetVariableCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetVariableCommand(commandCount int, 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")
}
@@ -874,7 +852,7 @@ func (c *CLI) AdminSetVariableCommand(cmd *Command) (ResponseIf, error) {
"var_name": varName,
"var_value": varValue,
}
- resp, err := c.AdminServerClient.Request("PUT", "/admin/variables", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", "/admin/variables", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set variable: %w", err)
}
@@ -897,7 +875,7 @@ func (c *CLI) AdminSetVariableCommand(cmd *Command) (ResponseIf, error) {
}
// AdminSetRoleDefaultModelsCommand set role default models (admin mode only).
-func (c *CLI) AdminSetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetRoleDefaultModelsCommand(commandCount int, 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")
}
@@ -931,7 +909,7 @@ func (c *CLI) AdminSetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error)
endPoint := fmt.Sprintf("/admin/roles/%s/default-models", roleName)
- resp, err := c.AdminServerClient.Request("PATCH", endPoint, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PATCH", endPoint, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set role default models: %w", err)
}
@@ -940,7 +918,7 @@ func (c *CLI) AdminSetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error)
}
// AdminSetLogLevelCommand set log level (admin mode only).
-func (c *CLI) AdminSetLogLevelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminSetLogLevelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
@@ -954,7 +932,7 @@ func (c *CLI) AdminSetLogLevelCommand(cmd *Command) (ResponseIf, error) {
"level": logLevel,
}
- resp, err := c.AdminServerClient.Request("PUT", "/admin/config/log", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", "/admin/config/log", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to change log level: %w", err)
}
@@ -963,7 +941,7 @@ func (c *CLI) AdminSetLogLevelCommand(cmd *Command) (ResponseIf, error) {
}
// AdminResetRoleDefaultModelsCommand reset role default models (admin mode only).
-func (c *CLI) AdminResetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminResetRoleDefaultModelsCommand(commandCount int, 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")
}
@@ -984,7 +962,7 @@ func (c *CLI) AdminResetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, erro
endPoint := fmt.Sprintf("/admin/roles/%s/default-models", roleName)
- resp, err := c.AdminServerClient.Request("DELETE", endPoint, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", endPoint, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to reset role default models: %w", err)
}
@@ -993,7 +971,7 @@ func (c *CLI) AdminResetRoleDefaultModelsCommand(cmd *Command) (ResponseIf, erro
}
// AdminDropUserCommand deletes a user (admin mode only)
-func (c *CLI) AdminDropUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDropUserCommand(commandCount int, 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")
}
@@ -1006,7 +984,7 @@ func (c *CLI) AdminDropUserCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop user: %w", err)
}
@@ -1015,7 +993,7 @@ func (c *CLI) AdminDropUserCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDropUserAPIKeyCommand drops an API key for a user (admin mode only)
-func (c *CLI) AdminDropUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDropUserAPIKeyCommand(commandCount int, 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")
}
@@ -1033,7 +1011,7 @@ func (c *CLI) AdminDropUserAPIKeyCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/keys/%s", encodedUserName, apiKey)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop API key: %w", err)
}
@@ -1043,7 +1021,7 @@ func (c *CLI) AdminDropUserAPIKeyCommand(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 *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ListUserDatasets(commandCount int, 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")
}
@@ -1053,21 +1031,10 @@ func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("user_name not provided")
}
- // Check for benchmark iterations
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
- if iterations > 1 {
- // Benchmark mode - return raw result for benchmark stats
- return c.AdminServerClient.RequestWithIterations("GET", apiURL, "admin", nil, nil, iterations)
- }
-
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list datasets: %w", err)
}
@@ -1100,7 +1067,7 @@ func (c *CLI) ListUserDatasets(cmd *Command) (ResponseIf, error) {
}
// ShowUserPermission shows user's permissions (admin mode only)
-func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ShowUserPermission(commandCount int, 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")
}
@@ -1113,7 +1080,7 @@ func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show user permission: %w", err)
}
@@ -1140,12 +1107,12 @@ func (c *CLI) ShowUserPermission(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) ListAdminTasks(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ListAdminTasks(commandCount int, 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.AdminServerClient.Request("GET", "/admin/tasks", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/tasks", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list tasks: %w", err)
}
@@ -1153,11 +1120,11 @@ func (c *CLI) ListAdminTasks(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list tasks")
}
-func (c *CLI) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ListAdminIngestors(commandCount int, 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.AdminServerClient.Request("GET", "/admin/ingestors", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/ingestors", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list ingestors: %w", err)
}
@@ -1165,12 +1132,12 @@ func (c *CLI) ListAdminIngestors(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list ingestors")
}
-func (c *CLI) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ListAdminIngestionTasks(commandCount int, 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.AdminServerClient.Request("GET", "/admin/ingestion/tasks", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/ingestion/tasks", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list admin tasks: %w", err)
}
@@ -1178,7 +1145,7 @@ func (c *CLI) ListAdminIngestionTasks(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list admin tasks")
}
-func (c *CLI) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStopIngestionCommand(commandCount int, 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")
}
@@ -1191,7 +1158,7 @@ func (c *CLI) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
"tasks": tasks,
}
- resp, err := c.AdminServerClient.Request("PUT", "/admin/ingestion/tasks", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", "/admin/ingestion/tasks", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to stop ingestion: %w", err)
}
@@ -1199,7 +1166,7 @@ func (c *CLI) AdminStopIngestionCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "stop ingestion")
}
-func (c *CLI) AdminRemoveIngestionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminRemoveIngestionCommand(commandCount int, 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")
}
@@ -1212,7 +1179,7 @@ func (c *CLI) AdminRemoveIngestionCommand(cmd *Command) (ResponseIf, error) {
"tasks": tasks,
}
- resp, err := c.AdminServerClient.Request("DELETE", "/admin/ingestion/tasks", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", "/admin/ingestion/tasks", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove ingestion: %w", err)
}
@@ -1220,7 +1187,7 @@ func (c *CLI) AdminRemoveIngestionCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "remove ingestion")
}
-func (c *CLI) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShutdownIngestor(commandCount int, 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")
}
@@ -1233,7 +1200,7 @@ func (c *CLI) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
"ingestor_name": ingestorName,
}
- resp, err := c.AdminServerClient.Request("DELETE", "/admin/ingestors", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", "/admin/ingestors", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to shutdown ingestor: %w", err)
}
@@ -1241,7 +1208,7 @@ func (c *CLI) AdminShutdownIngestor(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "shutdown ingestor")
}
-func (c *CLI) UserListMessageQueueCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) UserListMessageQueueCommand(commandCount int, 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")
}
@@ -1254,7 +1221,7 @@ func (c *CLI) UserListMessageQueueCommand(cmd *Command) (ResponseIf, error) {
"pending": pending,
}
- resp, err := c.AdminServerClient.Request("GET", "/admin/queue/messages", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/queue/messages", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to list message queue: %w", err)
}
@@ -1262,7 +1229,7 @@ func (c *CLI) UserListMessageQueueCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list message queue")
}
-func (c *CLI) UserPublishMessageCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) UserPublishMessageCommand(commandCount int, 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")
}
@@ -1275,7 +1242,7 @@ func (c *CLI) UserPublishMessageCommand(cmd *Command) (ResponseIf, error) {
"message": message,
}
- resp, err := c.AdminServerClient.Request("POST", "/admin/queue/messages", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", "/admin/queue/messages", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to publish message: %w", err)
}
@@ -1297,7 +1264,7 @@ func (c *CLI) UserPublishMessageCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) UserPullMessageCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) UserPullMessageCommand(commandCount int, 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")
}
@@ -1316,7 +1283,7 @@ func (c *CLI) UserPullMessageCommand(cmd *Command) (ResponseIf, error) {
"ack_policy": ackPolicy,
}
- resp, err := c.AdminServerClient.Request("PUT", "/admin/queue/messages", "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", "/admin/queue/messages", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to pull message: %w", err)
}
@@ -1324,12 +1291,12 @@ func (c *CLI) UserPullMessageCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "pull message")
}
-func (c *CLI) UserShowMessageQueueCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) UserShowMessageQueueCommand(commandCount int, 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.AdminServerClient.Request("GET", "/admin/queue", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/queue", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show message queue: %w", err)
}
@@ -1338,14 +1305,14 @@ func (c *CLI) UserShowMessageQueueCommand(cmd *Command) (ResponseIf, error) {
}
// AdminCheckLicenseCommand check license command (admin mode only)
-func (c *CLI) AdminCheckLicenseCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminCheckLicenseCommand(commandCount int, 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")
}
apiURL := fmt.Sprintf("/admin/system/license?check=true")
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to check license: %w", err)
}
@@ -1354,14 +1321,14 @@ func (c *CLI) AdminCheckLicenseCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowFingerprintCommand show fingerprint command (admin mode only)
-func (c *CLI) AdminShowFingerprintCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowFingerprintCommand(commandCount int, 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")
}
apiURL := fmt.Sprintf("/admin/system/fingerprint")
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show fingerprint: %w", err)
}
@@ -1370,14 +1337,14 @@ func (c *CLI) AdminShowFingerprintCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowSoftFingerprintCommand show soft fingerprint command (admin mode only)
-func (c *CLI) AdminShowSoftFingerprintCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowSoftFingerprintCommand(commandCount int, 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")
}
apiURL := fmt.Sprintf("/admin/system/soft-fingerprint")
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show soft fingerprint: %w", err)
}
@@ -1386,14 +1353,14 @@ func (c *CLI) AdminShowSoftFingerprintCommand(cmd *Command) (ResponseIf, error)
}
// AdminShowLicenseCommand show license command (admin mode only)
-func (c *CLI) AdminShowLicenseCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowLicenseCommand(commandCount int, 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")
}
apiURL := fmt.Sprintf("/admin/system/license")
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show license: %w", err)
}
@@ -1402,7 +1369,7 @@ func (c *CLI) AdminShowLicenseCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowUserCommand show user command (admin mode only)
-func (c *CLI) AdminShowUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserCommand(commandCount int, 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")
}
@@ -1415,7 +1382,7 @@ func (c *CLI) AdminShowUserCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show user: %w", err)
}
@@ -1424,7 +1391,7 @@ func (c *CLI) AdminShowUserCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowRoleCommand show role command (admin mode only)
-func (c *CLI) AdminShowRoleCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowRoleCommand(commandCount int, 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")
}
@@ -1433,7 +1400,7 @@ func (c *CLI) AdminShowRoleCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/roles/%s/", roleName)
- resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show role: %w", err)
}
@@ -1442,7 +1409,7 @@ func (c *CLI) AdminShowRoleCommand(cmd *Command) (ResponseIf, error) {
}
// AdminShowRoleDefaultModelsCommand show role default models command (admin mode only)
-func (c *CLI) AdminShowRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowRoleDefaultModelsCommand(commandCount int, 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")
}
@@ -1451,7 +1418,7 @@ func (c *CLI) AdminShowRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error
endPoint := fmt.Sprintf("/admin/roles/%s/default-models", roleName)
- resp, err := c.AdminServerClient.Request("GET", endPoint, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", endPoint, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show role default models: %w", err)
}
@@ -1459,7 +1426,7 @@ func (c *CLI) AdminShowRoleDefaultModelsCommand(cmd *Command) (ResponseIf, error
return HandleCommonResponse(resp, "show role default models")
}
-func (c *CLI) AdminShowUserActivityCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserActivityCommand(commandCount int, 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")
@@ -1483,7 +1450,7 @@ func (c *CLI) AdminShowUserActivityCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/activity", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to get user activity: %w", err)
}
@@ -1491,7 +1458,7 @@ func (c *CLI) AdminShowUserActivityCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "get user activity")
}
-func (c *CLI) AdminShowUserSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserSummaryCommand(commandCount int, 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")
}
@@ -1504,7 +1471,7 @@ func (c *CLI) AdminShowUserSummaryCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/summary", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get statistics: %w", err)
}
@@ -1526,7 +1493,7 @@ func (c *CLI) AdminShowUserSummaryCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowUserDatasetCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserDatasetCommand(commandCount int, 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")
@@ -1549,7 +1516,7 @@ func (c *CLI) AdminShowUserDatasetCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/dataset", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to get user dataset: %w", err)
}
@@ -1557,7 +1524,7 @@ func (c *CLI) AdminShowUserDatasetCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "get user dataset")
}
-func (c *CLI) AdminShowUserStorageCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserStorageCommand(commandCount int, 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")
@@ -1571,7 +1538,7 @@ func (c *CLI) AdminShowUserStorageCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/storage", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get user storage: %w", err)
}
@@ -1593,7 +1560,7 @@ func (c *CLI) AdminShowUserStorageCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserQuotaCommand(commandCount int, 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")
@@ -1607,7 +1574,7 @@ func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/quota", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get user storage: %w", err)
}
@@ -1629,7 +1596,7 @@ func (c *CLI) AdminShowUserQuotaCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserIndexCommand(commandCount int, 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")
@@ -1643,7 +1610,7 @@ func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/index", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get user storage: %w", err)
}
@@ -1665,7 +1632,7 @@ func (c *CLI) AdminShowUserIndexCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowUserPermissionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUserPermissionCommand(commandCount int, 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")
@@ -1679,7 +1646,7 @@ func (c *CLI) AdminShowUserPermissionCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(email)
apiURL := fmt.Sprintf("/admin/users/%s/permission", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get user permission: %w", err)
}
@@ -1687,7 +1654,7 @@ func (c *CLI) AdminShowUserPermissionCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "get user permission")
}
-func (c *CLI) AdminShowUsersSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUsersSummaryCommand(commandCount int, 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")
@@ -1695,7 +1662,7 @@ func (c *CLI) AdminShowUsersSummaryCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/users/summary"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get users summary: %w", err)
}
@@ -1717,7 +1684,7 @@ func (c *CLI) AdminShowUsersSummaryCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowUsersActivityCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUsersActivityCommand(commandCount int, 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")
@@ -1739,7 +1706,7 @@ func (c *CLI) AdminShowUsersActivityCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/users/activity"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to get users activity: %w", err)
}
@@ -1747,7 +1714,7 @@ func (c *CLI) AdminShowUsersActivityCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "get users activity")
}
-func (c *CLI) AdminShowUsersPlanSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUsersPlanSummaryCommand(commandCount int, 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")
@@ -1755,7 +1722,7 @@ func (c *CLI) AdminShowUsersPlanSummaryCommand(cmd *Command) (ResponseIf, error)
apiURL := "/admin/users/plan/summary"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get users activity: %w", err)
}
@@ -1763,7 +1730,7 @@ func (c *CLI) AdminShowUsersPlanSummaryCommand(cmd *Command) (ResponseIf, error)
return HandleCommonDataResponse(resp, "get users plan")
}
-func (c *CLI) AdminShowUsersPlanQuotaCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowUsersPlanQuotaCommand(commandCount int, 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")
@@ -1776,7 +1743,7 @@ func (c *CLI) AdminShowUsersPlanQuotaCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/users/plan?quota=%d", quota)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get users plan quota: %w", err)
}
@@ -1785,7 +1752,7 @@ func (c *CLI) AdminShowUsersPlanQuotaCommand(cmd *Command) (ResponseIf, error) {
}
// AdminStatsUserCommand stats user token usage
-func (c *CLI) AdminStatsUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStatsUserCommand(commandCount int, 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")
}
@@ -1813,7 +1780,7 @@ func (c *CLI) AdminStatsUserCommand(cmd *Command) (ResponseIf, error) {
baseUrl := fmt.Sprintf("/admin/stats/token?%s", q.Encode())
- resp, err := c.AdminServerClient.Request("GET", baseUrl, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", baseUrl, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get stats user: %w", err)
}
@@ -1822,7 +1789,7 @@ func (c *CLI) AdminStatsUserCommand(cmd *Command) (ResponseIf, error) {
}
// AdminStatsUsersCommand stats users token usage
-func (c *CLI) AdminStatsUsersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStatsUsersCommand(commandCount int, 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")
}
@@ -1845,7 +1812,7 @@ func (c *CLI) AdminStatsUsersCommand(cmd *Command) (ResponseIf, error) {
baseURL := fmt.Sprintf("/admin/stats/token/users?%s", q.Encode())
- resp, err := c.AdminServerClient.Request("GET", baseURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", baseURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get stats: %w", err)
}
@@ -1854,7 +1821,7 @@ func (c *CLI) AdminStatsUsersCommand(cmd *Command) (ResponseIf, error) {
}
// AdminStatsSummaryCommand stats summary token usage
-func (c *CLI) AdminStatsSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStatsSummaryCommand(commandCount int, 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")
}
@@ -1872,7 +1839,7 @@ func (c *CLI) AdminStatsSummaryCommand(cmd *Command) (ResponseIf, error) {
baseUrl := fmt.Sprintf("/admin/stats/token/summary?%s", q.Encode())
- resp, err := c.AdminServerClient.Request("GET", baseUrl, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", baseUrl, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get stats summary: %w", err)
}
@@ -1882,23 +1849,12 @@ func (c *CLI) AdminStatsSummaryCommand(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 *CLI) AdminListUsersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUsersCommand(commandCount int, 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
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
- if iterations > 1 {
- // Benchmark mode - return raw result for benchmark stats
- return c.AdminServerClient.RequestWithIterations("GET", "/admin/users", "admin", nil, nil, iterations)
- }
-
- resp, err := c.AdminServerClient.Request("GET", "/admin/users", "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/users", "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list users: %w", err)
}
@@ -1924,7 +1880,7 @@ func (c *CLI) AdminListUsersCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminListUsersConditionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUsersConditionCommand(commandCount int, 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")
@@ -1958,7 +1914,7 @@ func (c *CLI) AdminListUsersConditionCommand(cmd *Command) (ResponseIf, error) {
apiURL = fmt.Sprintf("%s?%s", apiURL, encoded)
}
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list users: %w", err)
}
@@ -1980,7 +1936,7 @@ func (c *CLI) AdminListUsersConditionCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowDataSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowDataSummaryCommand(commandCount int, 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")
@@ -1988,7 +1944,7 @@ func (c *CLI) AdminShowDataSummaryCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/data/summary"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get data summary: %w", err)
}
@@ -2010,7 +1966,7 @@ func (c *CLI) AdminShowDataSummaryCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowDataOrphanCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowDataOrphanCommand(commandCount int, 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")
@@ -2018,7 +1974,7 @@ func (c *CLI) AdminShowDataOrphanCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/data/orphan"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get orphan data: %w", err)
}
@@ -2040,7 +1996,7 @@ func (c *CLI) AdminShowDataOrphanCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowDataStorageCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowDataStorageCommand(commandCount int, 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")
@@ -2048,7 +2004,7 @@ func (c *CLI) AdminShowDataStorageCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/data/storage"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get data storage: %w", err)
}
@@ -2070,7 +2026,7 @@ func (c *CLI) AdminShowDataStorageCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowDataIndexCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowDataIndexCommand(commandCount int, 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")
@@ -2078,7 +2034,7 @@ func (c *CLI) AdminShowDataIndexCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/data/index"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get data index: %w", err)
}
@@ -2100,7 +2056,7 @@ func (c *CLI) AdminShowDataIndexCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowQuotaSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowQuotaSummaryCommand(commandCount int, 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")
@@ -2108,7 +2064,7 @@ func (c *CLI) AdminShowQuotaSummaryCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/users/quota/summary"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get users quota summary: %w", err)
}
@@ -2130,7 +2086,7 @@ func (c *CLI) AdminShowQuotaSummaryCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminShowTasksSummaryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowTasksSummaryCommand(commandCount int, 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")
@@ -2138,7 +2094,7 @@ func (c *CLI) AdminShowTasksSummaryCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/ingestion/tasks/summary"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get tasks summary: %w", err)
}
@@ -2160,7 +2116,7 @@ func (c *CLI) AdminShowTasksSummaryCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminPurgeOrphanCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminPurgeOrphanCommand(commandCount int, 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")
@@ -2177,7 +2133,7 @@ func (c *CLI) AdminPurgeOrphanCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/data/orphan"
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to purge orphan data: %w", err)
}
@@ -2185,7 +2141,7 @@ func (c *CLI) AdminPurgeOrphanCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "purge orphan data")
}
-func (c *CLI) AdminPurgeUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminPurgeUserCommand(commandCount int, 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")
@@ -2207,7 +2163,7 @@ func (c *CLI) AdminPurgeUserCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/data", encodedUserName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to purge user %s: %w", userName, err)
}
@@ -2215,7 +2171,7 @@ func (c *CLI) AdminPurgeUserCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, fmt.Sprintf("purge user %s", userName))
}
-func (c *CLI) AdminPurgeUsersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminPurgeUsersCommand(commandCount int, 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")
@@ -2258,7 +2214,7 @@ func (c *CLI) AdminPurgeUsersCommand(cmd *Command) (ResponseIf, error) {
apiURL := "/admin/users/data"
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to purge users data: %w", err)
}
@@ -2266,7 +2222,7 @@ func (c *CLI) AdminPurgeUsersCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "purge users data")
}
-func (c *CLI) AdminListUserIngestionTasksCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserIngestionTasksCommand(commandCount int, 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")
@@ -2288,7 +2244,7 @@ func (c *CLI) AdminListUserIngestionTasksCommand(cmd *Command) (ResponseIf, erro
apiURL := "/admin/ingestion/tasks"
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to list user %s ingestion tasks: %w", userName, err)
}
@@ -2310,7 +2266,7 @@ func (c *CLI) AdminListUserIngestionTasksCommand(cmd *Command) (ResponseIf, erro
return &result, nil
}
-func (c *CLI) AdminListUserDatasetsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserDatasetsCommand(commandCount int, 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")
@@ -2324,14 +2280,14 @@ func (c *CLI) AdminListUserDatasetsCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/datasets", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s datasets: %w", userName, err)
}
return HandleCommonResponse(resp, fmt.Sprintf("list user %s datasets", userName))
}
-func (c *CLI) AdminListUserAgentsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserAgentsCommand(commandCount int, 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")
@@ -2345,14 +2301,14 @@ func (c *CLI) AdminListUserAgentsCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/agents", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s agents: %w", userName, err)
}
return HandleCommonResponse(resp, fmt.Sprintf("list user %s agents", userName))
}
-func (c *CLI) AdminListUserChatsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserChatsCommand(commandCount int, 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")
@@ -2366,7 +2322,7 @@ func (c *CLI) AdminListUserChatsCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/chats", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s chats: %w", userName, err)
}
@@ -2374,7 +2330,7 @@ func (c *CLI) AdminListUserChatsCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s chats", userName))
}
-func (c *CLI) AdminListUserSearchesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserSearchesCommand(commandCount int, 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")
@@ -2388,7 +2344,7 @@ func (c *CLI) AdminListUserSearchesCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/searches", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s searches: %w", userName, err)
}
@@ -2396,7 +2352,7 @@ func (c *CLI) AdminListUserSearchesCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s searches", userName))
}
-func (c *CLI) AdminListUserModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserModelsCommand(commandCount int, 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")
@@ -2410,7 +2366,7 @@ func (c *CLI) AdminListUserModelsCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/models", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s models: %w", userName, err)
}
@@ -2418,7 +2374,7 @@ func (c *CLI) AdminListUserModelsCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s models", userName))
}
-func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserFilesCommand(commandCount int, 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")
@@ -2432,7 +2388,7 @@ func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/files", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s files: %w", userName, err)
}
@@ -2440,7 +2396,7 @@ func (c *CLI) AdminListUserFilesCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s files", userName))
}
-func (c *CLI) AdminListUserKeysCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserKeysCommand(commandCount int, 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")
@@ -2454,7 +2410,7 @@ func (c *CLI) AdminListUserKeysCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/keys", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s keys: %w", userName, err)
}
@@ -2485,7 +2441,7 @@ func (c *CLI) AdminListUserKeysCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AdminListUserProvidersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserProvidersCommand(commandCount int, 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")
@@ -2499,7 +2455,7 @@ func (c *CLI) AdminListUserProvidersCommand(cmd *Command) (ResponseIf, error) {
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/providers", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s providers: %w", userName, err)
}
@@ -2507,7 +2463,7 @@ func (c *CLI) AdminListUserProvidersCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s providers", userName))
}
-func (c *CLI) AdminListUserProviderInstancesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserProviderInstancesCommand(commandCount int, 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")
@@ -2526,7 +2482,7 @@ func (c *CLI) AdminListUserProviderInstancesCommand(cmd *Command) (ResponseIf, e
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/providers/%s/instances", encodedUserName, providerName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s providers: %w", userName, err)
}
@@ -2534,7 +2490,7 @@ func (c *CLI) AdminListUserProviderInstancesCommand(cmd *Command) (ResponseIf, e
return HandleCommonResponse(resp, fmt.Sprintf("list user %s provider instances", userName))
}
-func (c *CLI) AdminListUserProviderInstanceModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserProviderInstanceModelsCommand(commandCount int, 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")
@@ -2556,7 +2512,7 @@ func (c *CLI) AdminListUserProviderInstanceModelsCommand(cmd *Command) (Response
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/providers/%s/instances/%s/models", encodedUserName, providerName, instanceName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s provider instance models: %w", userName, err)
}
@@ -2564,7 +2520,7 @@ func (c *CLI) AdminListUserProviderInstanceModelsCommand(cmd *Command) (Response
return HandleCommonResponse(resp, fmt.Sprintf("list user %s provider instance models", userName))
}
-func (c *CLI) AdminListUserDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserDefaultModelsCommand(commandCount int, 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")
@@ -2578,7 +2534,7 @@ func (c *CLI) AdminListUserDefaultModelsCommand(cmd *Command) (ResponseIf, error
encodedUserName := url.PathEscape(userName)
apiURL := fmt.Sprintf("/admin/users/%s/default-models", encodedUserName)
- resp, err := c.AdminServerClient.Request("GET", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s default models: %w", userName, err)
}
@@ -2587,7 +2543,7 @@ func (c *CLI) AdminListUserDefaultModelsCommand(cmd *Command) (ResponseIf, error
}
// AdminListUserLogsCommand list user operation logs
-func (c *CLI) AdminListUserLogsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListUserLogsCommand(commandCount int, 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")
@@ -2609,7 +2565,7 @@ func (c *CLI) AdminListUserLogsCommand(cmd *Command) (ResponseIf, error) {
baseUrl := fmt.Sprintf("/admin/logs?%s", q.Encode())
- resp, err := c.AdminServerClient.Request("GET", baseUrl, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", baseUrl, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list user %s logs: %w", userName, err)
}
@@ -2617,7 +2573,7 @@ func (c *CLI) AdminListUserLogsCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, fmt.Sprintf("list user %s logs", userName))
}
-func (c *CLI) AdminStopUserIngestionTasksCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminStopUserIngestionTasksCommand(commandCount int, 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")
@@ -2639,7 +2595,7 @@ func (c *CLI) AdminStopUserIngestionTasksCommand(cmd *Command) (ResponseIf, erro
apiURL := "/admin/ingestion/tasks"
- resp, err := c.AdminServerClient.Request("PUT", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "PUT", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to stop user %s ingestion tasks: %w", userName, err)
}
@@ -2647,7 +2603,7 @@ func (c *CLI) AdminStopUserIngestionTasksCommand(cmd *Command) (ResponseIf, erro
return HandleCommonResponse(resp, fmt.Sprintf("stop user %s ingestion tasks", userName))
}
-func (c *CLI) AdminRemoveUserIngestionTasksCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminRemoveUserIngestionTasksCommand(commandCount int, 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")
@@ -2669,7 +2625,7 @@ func (c *CLI) AdminRemoveUserIngestionTasksCommand(cmd *Command) (ResponseIf, er
apiURL := "/admin/ingestion/tasks"
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove user %s ingestion tasks: %w", userName, err)
}
@@ -2678,7 +2634,7 @@ func (c *CLI) AdminRemoveUserIngestionTasksCommand(cmd *Command) (ResponseIf, er
}
// AdminAddProviderCommand add provider
-func (c *CLI) AdminAddProviderCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminAddProviderCommand(commandCount int, 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")
@@ -2695,7 +2651,7 @@ func (c *CLI) AdminAddProviderCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers")
- resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add provider %s: %w", providerName, err)
}
@@ -2704,7 +2660,7 @@ func (c *CLI) AdminAddProviderCommand(cmd *Command) (ResponseIf, error) {
}
// AdminAddModelInstanceCommand add model instance
-func (c *CLI) AdminAddModelInstanceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminAddModelInstanceCommand(commandCount int, 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")
@@ -2726,7 +2682,7 @@ func (c *CLI) AdminAddModelInstanceCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers/%s/instances", providerName)
- resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add model instance %s: %w", instanceName, err)
}
@@ -2735,7 +2691,7 @@ func (c *CLI) AdminAddModelInstanceCommand(cmd *Command) (ResponseIf, error) {
}
// AdminAddModelsCommand add models
-func (c *CLI) AdminAddModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminAddModelsCommand(commandCount int, 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")
@@ -2762,7 +2718,7 @@ func (c *CLI) AdminAddModelsCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers/%s/instances/%s/models", providerName, instanceName)
- resp, err := c.AdminServerClient.Request("POST", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "POST", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add models %s: %w", modelNames, err)
}
@@ -2771,7 +2727,7 @@ func (c *CLI) AdminAddModelsCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDeleteProvidersCommand delete providers
-func (c *CLI) AdminDeleteProvidersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDeleteProvidersCommand(commandCount int, 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")
@@ -2788,7 +2744,7 @@ func (c *CLI) AdminDeleteProvidersCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers/")
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove providers %s: %w", providerNames, err)
}
@@ -2797,7 +2753,7 @@ func (c *CLI) AdminDeleteProvidersCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDeleteInstancesCommand delete instances
-func (c *CLI) AdminDeleteInstancesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDeleteInstancesCommand(commandCount int, 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")
@@ -2819,7 +2775,7 @@ func (c *CLI) AdminDeleteInstancesCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers/%s/instances", providerName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove instance %s: %w", instanceNames, err)
}
@@ -2828,7 +2784,7 @@ func (c *CLI) AdminDeleteInstancesCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDeleteModelsCommand delete models
-func (c *CLI) AdminDeleteModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDeleteModelsCommand(commandCount int, 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")
@@ -2855,7 +2811,7 @@ func (c *CLI) AdminDeleteModelsCommand(cmd *Command) (ResponseIf, error) {
apiURL := fmt.Sprintf("/admin/providers/%s/instances/%s/models", providerName, instanceName)
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, payload)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove model %s: %w", modelNames, err)
}
@@ -2864,7 +2820,7 @@ func (c *CLI) AdminDeleteModelsCommand(cmd *Command) (ResponseIf, error) {
}
// AdminDeleteSoftFingerprintCommand delete soft fingerprint
-func (c *CLI) AdminDeleteSoftFingerprintCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminDeleteSoftFingerprintCommand(commandCount int, 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")
@@ -2872,7 +2828,7 @@ func (c *CLI) AdminDeleteSoftFingerprintCommand(cmd *Command) (ResponseIf, error
apiURL := fmt.Sprintf("/admin/system/soft-fingerprint")
- resp, err := c.AdminServerClient.Request("DELETE", apiURL, "admin", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "DELETE", apiURL, "admin", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to remove soft fingerprint: %w", err)
}
@@ -2880,13 +2836,13 @@ func (c *CLI) AdminDeleteSoftFingerprintCommand(cmd *Command) (ResponseIf, error
return HandleSimpleResponse(resp, fmt.Sprintf("remove soft fingerprint"))
}
-func (c *CLI) AdminShowLogLevelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminShowLogLevelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
}
- resp, err := c.AdminServerClient.Request("GET", "/admin/config/log", "web", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", "/admin/config/log", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get log level config: %w", err)
}
@@ -2894,7 +2850,7 @@ func (c *CLI) AdminShowLogLevelCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, fmt.Sprintf("get log level config"))
}
-func (c *CLI) AdminListBucketObjects(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AdminListBucketObjects(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != AdminMode {
return nil, fmt.Errorf("this command is only allowed in ADMIN mode or already login")
@@ -2907,7 +2863,7 @@ func (c *CLI) AdminListBucketObjects(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/admin/bucket/%s/objects", bucketID)
- resp, err := c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err := c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get bucket objects: %w", err)
}
diff --git a/internal/cli/benchmark.go b/internal/cli/benchmark.go
index f73b7af80d..15d3b48822 100644
--- a/internal/cli/benchmark.go
+++ b/internal/cli/benchmark.go
@@ -34,7 +34,7 @@ type BenchmarkResult struct {
}
// RunBenchmark runs a benchmark with the given concurrency and iterations
-func (c *CLI) RunBenchmark(cmd *Command) (ResponseIf, error) {
+func (c *CLI) RunBenchmark(commandCount int, cmd *Command) (ResponseIf, error) {
concurrency, ok := cmd.Params["concurrency"].(int)
if !ok {
concurrency = 1
@@ -84,15 +84,7 @@ func (c *CLI) runBenchmarkSingle(iterations int, nestedCmd *Command) (*Benchmark
}
// Check if command supports native benchmark (iterations > 1)
- if iterations > 1 {
- result, err := c.ExecuteCommand(nestedCmd)
- // convert result to BenchmarkResponse
- benchmarkResponse := result.(*BenchmarkResponse)
- benchmarkResponse.Concurrency = 1
- return benchmarkResponse, err
- }
-
- result, err := c.ExecuteCommand(nestedCmd)
+ result, err := c.ExecuteCommand(iterations, nestedCmd)
if err != nil {
fmt.Printf("fail to execute: %s", commandType)
return nil, err
@@ -172,21 +164,22 @@ func (c *CLI) runBenchmarkConcurrent(concurrency, iterations int, nestedCmd *Com
go func(idx int) {
defer wg.Done()
- // Create a new client for each goroutine to avoid race conditions
- workerClient, err := NewCLIWithConfig(nil)
- if err != nil {
- fmt.Printf("fail to create worker client: %s", err)
- return
- }
- workerClient.AdminServerClient = c.AdminServerClient
- workerClient.APIServerClientMap = c.APIServerClientMap
+ //// Create a new client for each goroutine to avoid race conditions
+ //workerClient, err := NewCLIWithConfig(Arguments)
+ //if err != nil {
+ // fmt.Printf("fail to create worker client: %s", err)
+ // return
+ //}
+ //workerClient.AdminServerClient = c.AdminServerClient
+ //workerClient.APIServerClientMap = c.APIServerClientMap
// Execute benchmark silently (no output)
- responseList := workerClient.executeBenchmarkSilent(nestedCmd, iterations)
+ //responseList := workerClient.executeBenchmarkSilent(nestedCmd, iterations)
+ benchmarkResponse, _ := c.runBenchmarkSingle(iterations, nestedCmd)
results[idx] = map[string]interface{}{
"duration": 0.0,
- "response_list": responseList,
+ "response_list": benchmarkResponse,
}
}(i)
}
@@ -196,27 +189,24 @@ func (c *CLI) runBenchmarkConcurrent(concurrency, iterations int, nestedCmd *Com
totalDuration := endTime.Sub(startTime).Seconds()
successCount := 0
- commandType := nestedCmd.Type
+ failureCount := 0
for _, result := range results {
if result == nil {
continue
}
- responseList, _ := result["response_list"].([]*Response)
- for _, resp := range responseList {
- if isSuccess(resp, commandType) {
- successCount++
- }
- }
+ res, _ := result["response_list"].(*BenchmarkResponse)
+ successCount += res.SuccessCount
+ failureCount += res.FailureCount
}
- totalCommands := iterations * concurrency
+ //totalCommands := iterations * concurrency
var benchmarkResponse BenchmarkResponse
benchmarkResponse.Duration = totalDuration
benchmarkResponse.Code = 0
benchmarkResponse.SuccessCount = successCount
- benchmarkResponse.FailureCount = totalCommands - successCount
+ benchmarkResponse.FailureCount = failureCount
benchmarkResponse.Concurrency = concurrency
return &benchmarkResponse, nil
@@ -234,12 +224,12 @@ func (c *CLI) executeBenchmarkSilent(cmd *Command, iterations int) []*Response {
switch cmd.Type {
case "ping":
- resp, err = httpClient.Request("GET", "/system/ping", "web", nil, nil)
+ resp, err = httpClient.Request(1, "GET", "/system/ping", "web", nil, nil)
case "list_user_datasets":
- resp, err = httpClient.Request("POST", "/kb/list", "web", nil, nil)
+ resp, err = httpClient.Request(1, "POST", "/kb/list", "web", nil, nil)
case "api_list_datasets":
userName, _ := cmd.Params["user_name"].(string)
- resp, err = httpClient.Request("GET", fmt.Sprintf("/admin/users/%s/datasets", userName), "admin", nil, nil)
+ resp, err = httpClient.Request(1, "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)
@@ -249,7 +239,7 @@ func (c *CLI) executeBenchmarkSilent(cmd *Command, iterations int) []*Response {
"similarity_threshold": 0.2,
"vector_similarity_weight": 0.3,
}
- resp, err = httpClient.Request("POST", "/datasets/search", "web", nil, payload)
+ resp, err = httpClient.Request(1, "POST", "/datasets/search", "web", nil, payload)
default:
// For other commands, we would need to add specific handling
// For now, mark as failed
diff --git a/internal/cli/cli.go b/internal/cli/cli.go
index eba92921fb..1000e4b72f 100644
--- a/internal/cli/cli.go
+++ b/internal/cli/cli.go
@@ -106,6 +106,8 @@ func (c *CommandLineConfig) Print() {
}
}
+var Arguments *CommandLineConfig
+
func ParseArgs(args []string) (*CommandLineConfig, error) {
commandLineConfig := &CommandLineConfig{
CLIMode: APIMode,
@@ -763,19 +765,19 @@ func (c *CLI) execute(input string) error {
// Handle meta commands
if cmd.Type == "meta" {
- return c.handleMetaCommand(cmd)
+ return c.handleMetaCommand(1, cmd)
}
// Execute the command using the client
var result ResponseIf
- result, err = c.ExecuteCommand(cmd)
+ result, err = c.ExecuteCommand(1, cmd)
if result != nil {
result.PrintOut()
}
return err
}
-func (c *CLI) handleMetaCommand(cmd *Command) error {
+func (c *CLI) handleMetaCommand(commandCount int, cmd *Command) error {
command := cmd.Params["command"].(string)
//args, _ := cmd.Params["args"].([]string)
@@ -905,7 +907,7 @@ func (c *CLI) VerifyAuth(username, password string) error {
cmd.Params["email"] = username
cmd.Params["password"] = password
- _, err := c.LoginUserByCommand(cmd)
+ _, err := c.LoginUserByCommand(1, cmd)
return err
}
diff --git a/internal/cli/cli_http.go b/internal/cli/cli_http.go
index bd273788a0..d8687f7c76 100644
--- a/internal/cli/cli_http.go
+++ b/internal/cli/cli_http.go
@@ -22,526 +22,526 @@ import (
// ExecuteCommand executes a parsed command
// Returns benchmark result map for commands that support it (e.g., ping_server with iterations > 1)
-func (c *CLI) ExecuteCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ExecuteCommand(commandCount int, cmd *Command) (ResponseIf, error) {
switch c.Config.CLIMode {
case APIMode:
// Interactive mode: execute command with user privileges
- return c.ExecuteUserCommand(cmd)
+ return c.ExecuteUserCommand(commandCount, cmd)
case AdminMode:
// Admin mode: execute command with admin privileges
- return c.ExecuteAdminCommand(cmd)
+ return c.ExecuteAdminCommand(commandCount, cmd)
default:
return nil, fmt.Errorf("invalid server type: %s", c.Config.CLIMode)
}
}
-func (c *CLI) ExecuteAdminCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ExecuteAdminCommand(commandCount int, cmd *Command) (ResponseIf, error) {
switch cmd.Type {
case "admin_login_user":
- return c.LoginUserByCommand(cmd)
+ return c.LoginUserByCommand(commandCount, cmd)
case "admin_logout":
return c.Logout()
case "admin_ping_store":
- return c.AdminPingStoreCommand(cmd)
+ return c.AdminPingStoreCommand(commandCount, cmd)
case "admin_ping_engine":
- return c.AdminPingEngineCommand(cmd)
+ return c.AdminPingEngineCommand(commandCount, cmd)
case "admin_ping_mq":
- return c.AdminPingMQCommand(cmd)
+ return c.AdminPingMQCommand(commandCount, cmd)
case "admin_ping_cache":
- return c.AdminPingCacheCommand(cmd)
+ return c.AdminPingCacheCommand(commandCount, cmd)
case "admin_ping_server":
- return c.PingServerByCommand(cmd)
+ return c.PingServerByCommand(commandCount, cmd)
case "admin_live_server":
- return c.AdminLiveServerCommand(cmd)
+ return c.AdminLiveServerCommand(commandCount, cmd)
case "admin_health_server":
- return c.AdminHealthServerCommand(cmd)
+ return c.AdminHealthServerCommand(commandCount, cmd)
case "benchmark":
- return c.RunBenchmark(cmd)
+ return c.RunBenchmark(commandCount, cmd)
case "admin_list_services":
- return c.AdminListServicesCommand(cmd)
+ return c.AdminListServicesCommand(commandCount, cmd)
case "admin_start_service":
- return c.AdminStartServiceCommand(cmd)
+ return c.AdminStartServiceCommand(commandCount, cmd)
case "admin_restart_service":
- return c.AdminRestartServiceCommand(cmd)
+ return c.AdminRestartServiceCommand(commandCount, cmd)
case "admin_shutdown_service":
- return c.AdminShutdownServiceCommand(cmd)
+ return c.AdminShutdownServiceCommand(commandCount, cmd)
case "admin_grant_user_admin":
- return c.AdminGrantUserAdminCommand(cmd)
+ return c.AdminGrantUserAdminCommand(commandCount, cmd)
case "admin_revoke_user_admin":
- return c.AdminRevokeUserAdminCommand(cmd)
+ return c.AdminRevokeUserAdminCommand(commandCount, cmd)
case "admin_grant_role_permission":
- return c.AdminGrantRolePermissionCommand(cmd)
+ return c.AdminGrantRolePermissionCommand(commandCount, cmd)
case "admin_revoke_role_permission":
- return c.AdminRevokeRolePermissionCommand(cmd)
+ return c.AdminRevokeRolePermissionCommand(commandCount, cmd)
case "admin_show_role_permission":
- return c.AdminShowRolePermissionCommand(cmd)
+ return c.AdminShowRolePermissionCommand(commandCount, cmd)
case "admin_create_user":
- return c.AdminCreateUserCommand(cmd)
+ return c.AdminCreateUserCommand(commandCount, cmd)
case "admin_create_user_api_key":
- return c.AdminCreateUserAPIKeyCommand(cmd)
+ return c.AdminCreateUserAPIKeyCommand(commandCount, cmd)
case "admin_create_role":
- return c.AdminCreateRoleCommand(cmd)
+ return c.AdminCreateRoleCommand(commandCount, cmd)
case "admin_activate_user":
- return c.AdminActivateUser(cmd)
+ return c.AdminActivateUser(commandCount, cmd)
case "admin_alter_user":
- return c.AdminAlterUserPassword(cmd)
+ return c.AdminAlterUserPassword(commandCount, cmd)
case "admin_alter_role":
- return c.AdminAlterRole(cmd)
+ return c.AdminAlterRole(commandCount, cmd)
case "admin_alter_provider_instance":
- return c.CommonAlterProviderInstanceCommand(cmd)
+ return c.CommonAlterProviderInstanceCommand(commandCount, cmd)
case "admin_drop_user":
- return c.AdminDropUserCommand(cmd)
+ return c.AdminDropUserCommand(commandCount, cmd)
case "admin_drop_user_api_key":
- return c.AdminDropUserAPIKeyCommand(cmd)
+ return c.AdminDropUserAPIKeyCommand(commandCount, cmd)
case "admin_drop_role":
- return c.AdminDropRoleCommand(cmd)
+ return c.AdminDropRoleCommand(commandCount, cmd)
case "admin_show_service":
- return c.AdminShowService(cmd)
+ return c.AdminShowService(commandCount, cmd)
case "admin_show_version_command":
- return c.AdminShowVersionCommand(cmd)
+ return c.AdminShowVersionCommand(commandCount, cmd)
case "admin_show_current":
- return c.CommonShowCurrentCommand(cmd)
+ return c.CommonShowCurrentCommand(commandCount, cmd)
case "admin_list_variables":
- return c.AdminListVariablesCommand(cmd)
+ return c.AdminListVariablesCommand(commandCount, cmd)
case "admin_list_configs":
- return c.AdminListConfigsCommand(cmd)
+ return c.AdminListConfigsCommand(commandCount, cmd)
case "admin_list_environments":
- return c.AdminListEnvironmentsCommand(cmd)
+ return c.AdminListEnvironmentsCommand(commandCount, cmd)
case "admin_show_variable":
- return c.AdminShowVariable(cmd)
+ return c.AdminShowVariable(commandCount, cmd)
case "admin_set_license":
- return c.AdminSetLicenseCommand(cmd)
+ return c.AdminSetLicenseCommand(commandCount, cmd)
case "admin_set_soft_fingerprint":
- return c.AdminSetSoftFingerprintCommand(cmd)
+ return c.AdminSetSoftFingerprintCommand(commandCount, cmd)
case "admin_set_license_config":
- return c.AdminSetLicenseConfigCommand(cmd)
+ return c.AdminSetLicenseConfigCommand(commandCount, cmd)
case "admin_set_variable":
- return c.AdminSetVariableCommand(cmd)
+ return c.AdminSetVariableCommand(commandCount, cmd)
case "admin_set_role_default_model":
- return c.AdminSetRoleDefaultModelsCommand(cmd)
+ return c.AdminSetRoleDefaultModelsCommand(commandCount, cmd)
case "admin_set_log_level":
- return c.AdminSetLogLevelCommand(cmd)
+ return c.AdminSetLogLevelCommand(commandCount, cmd)
case "admin_reset_role_default_model":
- return c.AdminResetRoleDefaultModelsCommand(cmd)
+ return c.AdminResetRoleDefaultModelsCommand(commandCount, cmd)
case "list_user_datasets":
- return c.ListUserDatasets(cmd)
+ return c.ListUserDatasets(commandCount, cmd)
case "admin_list_resources_command":
- return c.AdminListResourcesCommand(cmd)
+ return c.AdminListResourcesCommand(commandCount, cmd)
case "admin_list_roles_command":
- return c.AdminListRolesCommand(cmd)
+ return c.AdminListRolesCommand(commandCount, cmd)
case "admin_list_available_providers":
- return c.CommonAvailableProvidersCommand(cmd)
+ return c.CommonAvailableProvidersCommand(commandCount, cmd)
case "admin_show_provider":
- return c.CommonShowProviderCommand(cmd)
+ return c.CommonShowProviderCommand(commandCount, cmd)
case "admin_show_provider_instance":
- return c.CommonShowProviderInstanceCommand(cmd)
+ return c.CommonShowProviderInstanceCommand(commandCount, cmd)
case "admin_show_provider_instance_balance":
- return c.CommonShowProviderInstanceBalanceCommand(cmd)
+ return c.CommonShowProviderInstanceBalanceCommand(commandCount, cmd)
case "admin_show_provider_model":
- return c.CommonShowProviderModelCommand(cmd)
+ return c.CommonShowProviderModelCommand(commandCount, cmd)
case "admin_list_provider_models":
- return c.CommonListModelsCommand(cmd)
+ return c.CommonListModelsCommand(commandCount, cmd)
case "admin_list_provider_instance_models":
- return c.CommonListInstanceModelsCommand(cmd)
+ return c.CommonListInstanceModelsCommand(commandCount, cmd)
case "admin_list_provider_instances":
- return c.CommonListProviderInstancesCommand(cmd)
+ return c.CommonListProviderInstancesCommand(commandCount, cmd)
case "admin_show_model":
- return c.CommonShowModelCommand(cmd)
+ return c.CommonShowModelCommand(commandCount, cmd)
case "admin_list_providers":
- return c.AdminListProvidersCommand(cmd)
+ return c.AdminListProvidersCommand(commandCount, cmd)
case "admin_list_all_models":
- return c.CommonListAllModels(cmd)
+ return c.CommonListAllModels(commandCount, cmd)
case "list_admin_tasks":
- return c.ListAdminTasks(cmd)
+ return c.ListAdminTasks(commandCount, cmd)
case "admin_list_ingestors":
- return c.ListAdminIngestors(cmd)
+ return c.ListAdminIngestors(commandCount, cmd)
case "admin_stop_ingestion_tasks":
- return c.AdminStopIngestionCommand(cmd)
+ return c.AdminStopIngestionCommand(commandCount, cmd)
case "admin_remove_ingestion_tasks":
- return c.AdminRemoveIngestionCommand(cmd)
+ return c.AdminRemoveIngestionCommand(commandCount, cmd)
case "admin_shutdown_ingestor_command":
- return c.AdminShutdownIngestor(cmd)
+ return c.AdminShutdownIngestor(commandCount, cmd)
case "list_admin_ingestion_tasks":
- return c.ListAdminIngestionTasks(cmd)
+ return c.ListAdminIngestionTasks(commandCount, cmd)
case "user_list_message_queue_command":
- return c.UserListMessageQueueCommand(cmd)
+ return c.UserListMessageQueueCommand(commandCount, cmd)
case "user_publish_message_command":
- return c.UserPublishMessageCommand(cmd)
+ return c.UserPublishMessageCommand(commandCount, cmd)
case "user_pull_message_command":
- return c.UserPullMessageCommand(cmd)
+ return c.UserPullMessageCommand(commandCount, cmd)
case "user_show_message_queue_command":
- return c.UserShowMessageQueueCommand(cmd)
+ return c.UserShowMessageQueueCommand(commandCount, cmd)
case "admin_check_license":
- return c.AdminCheckLicenseCommand(cmd)
+ return c.AdminCheckLicenseCommand(commandCount, cmd)
case "admin_check_provider_with_key":
- return c.CommonCheckProviderWithKeyCommand(cmd)
+ return c.CommonCheckProviderWithKeyCommand(commandCount, cmd)
case "admin_check_provider_instance":
- return c.CommonCheckProviderConnectionCommand(cmd)
+ return c.CommonCheckProviderConnectionCommand(commandCount, cmd)
case "admin_show_fingerprint":
- return c.AdminShowFingerprintCommand(cmd)
+ return c.AdminShowFingerprintCommand(commandCount, cmd)
case "admin_show_soft_fingerprint":
- return c.AdminShowSoftFingerprintCommand(cmd)
+ return c.AdminShowSoftFingerprintCommand(commandCount, cmd)
case "admin_show_license":
- return c.AdminShowLicenseCommand(cmd)
+ return c.AdminShowLicenseCommand(commandCount, cmd)
case "admin_show_user":
- return c.AdminShowUserCommand(cmd)
+ return c.AdminShowUserCommand(commandCount, cmd)
case "admin_show_role":
- return c.AdminShowRoleCommand(cmd)
+ return c.AdminShowRoleCommand(commandCount, cmd)
case "admin_show_role_default_models":
- return c.AdminShowRoleDefaultModelsCommand(cmd)
+ return c.AdminShowRoleDefaultModelsCommand(commandCount, cmd)
case "admin_show_user_activity_command":
- return c.AdminShowUserActivityCommand(cmd)
+ return c.AdminShowUserActivityCommand(commandCount, cmd)
case "admin_show_user_summary_command":
- return c.AdminShowUserSummaryCommand(cmd)
+ return c.AdminShowUserSummaryCommand(commandCount, cmd)
case "admin_show_user_dataset_command":
- return c.AdminShowUserDatasetCommand(cmd)
+ return c.AdminShowUserDatasetCommand(commandCount, cmd)
case "admin_show_user_storage_command":
- return c.AdminShowUserStorageCommand(cmd)
+ return c.AdminShowUserStorageCommand(commandCount, cmd)
case "admin_show_user_quota_command":
- return c.AdminShowUserQuotaCommand(cmd)
+ return c.AdminShowUserQuotaCommand(commandCount, cmd)
case "admin_show_user_index_command":
- return c.AdminShowUserIndexCommand(cmd)
+ return c.AdminShowUserIndexCommand(commandCount, cmd)
case "admin_show_user_permission_command":
- return c.AdminShowUserPermissionCommand(cmd)
+ return c.AdminShowUserPermissionCommand(commandCount, cmd)
case "admin_show_users_summary_command":
- return c.AdminShowUsersSummaryCommand(cmd)
+ return c.AdminShowUsersSummaryCommand(commandCount, cmd)
case "admin_show_users_activity_command":
- return c.AdminShowUsersActivityCommand(cmd)
+ return c.AdminShowUsersActivityCommand(commandCount, cmd)
case "admin_show_users_plan_summary":
- return c.AdminShowUsersPlanSummaryCommand(cmd)
+ return c.AdminShowUsersPlanSummaryCommand(commandCount, cmd)
case "admin_show_users_plan_quota":
- return c.AdminShowUsersPlanQuotaCommand(cmd)
+ return c.AdminShowUsersPlanQuotaCommand(commandCount, cmd)
case "admin_stats_user":
- return c.AdminStatsUserCommand(cmd)
+ return c.AdminStatsUserCommand(commandCount, cmd)
case "admin_stats_users":
- return c.AdminStatsUsersCommand(cmd)
+ return c.AdminStatsUsersCommand(commandCount, cmd)
case "admin_stats_summary":
- return c.AdminStatsSummaryCommand(cmd)
+ return c.AdminStatsSummaryCommand(commandCount, cmd)
case "admin_list_users_command":
- return c.AdminListUsersCommand(cmd)
+ return c.AdminListUsersCommand(commandCount, cmd)
case "admin_list_users_condition_command":
- return c.AdminListUsersConditionCommand(cmd)
+ return c.AdminListUsersConditionCommand(commandCount, cmd)
case "admin_show_quota_summary":
- return c.AdminShowQuotaSummaryCommand(cmd)
+ return c.AdminShowQuotaSummaryCommand(commandCount, cmd)
case "admin_show_tasks_summary":
- return c.AdminShowTasksSummaryCommand(cmd)
+ return c.AdminShowTasksSummaryCommand(commandCount, cmd)
case "admin_show_data_summary":
- return c.AdminShowDataSummaryCommand(cmd)
+ return c.AdminShowDataSummaryCommand(commandCount, cmd)
case "admin_show_data_orphan":
- return c.AdminShowDataOrphanCommand(cmd)
+ return c.AdminShowDataOrphanCommand(commandCount, cmd)
case "admin_show_data_storage":
- return c.AdminShowDataStorageCommand(cmd)
+ return c.AdminShowDataStorageCommand(commandCount, cmd)
case "admin_show_data_index":
- return c.AdminShowDataIndexCommand(cmd)
+ return c.AdminShowDataIndexCommand(commandCount, cmd)
case "admin_purge_orphan_command":
- return c.AdminPurgeOrphanCommand(cmd)
+ return c.AdminPurgeOrphanCommand(commandCount, cmd)
case "admin_purge_user_command":
- return c.AdminPurgeUserCommand(cmd)
+ return c.AdminPurgeUserCommand(commandCount, cmd)
case "admin_purge_users_command":
- return c.AdminPurgeUsersCommand(cmd)
+ return c.AdminPurgeUsersCommand(commandCount, cmd)
case "admin_list_user_ingestion_tasks":
- return c.AdminListUserIngestionTasksCommand(cmd)
+ return c.AdminListUserIngestionTasksCommand(commandCount, cmd)
case "admin_list_user_datasets":
- return c.AdminListUserDatasetsCommand(cmd)
+ return c.AdminListUserDatasetsCommand(commandCount, cmd)
case "admin_list_user_agents":
- return c.AdminListUserAgentsCommand(cmd)
+ return c.AdminListUserAgentsCommand(commandCount, cmd)
case "admin_list_user_chats":
- return c.AdminListUserChatsCommand(cmd)
+ return c.AdminListUserChatsCommand(commandCount, cmd)
case "admin_list_user_searches":
- return c.AdminListUserSearchesCommand(cmd)
+ return c.AdminListUserSearchesCommand(commandCount, cmd)
case "admin_list_user_models":
- return c.AdminListUserModelsCommand(cmd)
+ return c.AdminListUserModelsCommand(commandCount, cmd)
case "admin_list_user_files":
- return c.AdminListUserFilesCommand(cmd)
+ return c.AdminListUserFilesCommand(commandCount, cmd)
case "admin_list_user_keys":
- return c.AdminListUserKeysCommand(cmd)
+ return c.AdminListUserKeysCommand(commandCount, cmd)
case "admin_list_user_providers":
- return c.AdminListUserProvidersCommand(cmd)
+ return c.AdminListUserProvidersCommand(commandCount, cmd)
case "admin_list_user_provider_instances":
- return c.AdminListUserProviderInstancesCommand(cmd)
+ return c.AdminListUserProviderInstancesCommand(commandCount, cmd)
case "admin_list_user_provider_instance_models":
- return c.AdminListUserProviderInstanceModelsCommand(cmd)
+ return c.AdminListUserProviderInstanceModelsCommand(commandCount, cmd)
case "admin_list_user_default_models":
- return c.AdminListUserDefaultModelsCommand(cmd)
+ return c.AdminListUserDefaultModelsCommand(commandCount, cmd)
case "admin_list_user_operation_logs":
- return c.AdminListUserLogsCommand(cmd)
+ return c.AdminListUserLogsCommand(commandCount, cmd)
case "admin_stop_user_ingestion_tasks_command":
- return c.AdminStopUserIngestionTasksCommand(cmd)
+ return c.AdminStopUserIngestionTasksCommand(commandCount, cmd)
case "admin_remove_user_ingestion_tasks_command":
- return c.AdminRemoveUserIngestionTasksCommand(cmd)
+ return c.AdminRemoveUserIngestionTasksCommand(commandCount, cmd)
case "admin_add_provider":
- return c.AdminAddProviderCommand(cmd)
+ return c.AdminAddProviderCommand(commandCount, cmd)
case "admin_add_model_instance":
- return c.AdminAddModelInstanceCommand(cmd)
+ return c.AdminAddModelInstanceCommand(commandCount, cmd)
case "admin_add_models":
- return c.AdminAddModelsCommand(cmd)
+ return c.AdminAddModelsCommand(commandCount, cmd)
case "admin_delete_model_providers":
- return c.AdminDeleteProvidersCommand(cmd)
+ return c.AdminDeleteProvidersCommand(commandCount, cmd)
case "admin_delete_model_instance":
- return c.AdminDeleteInstancesCommand(cmd)
+ return c.AdminDeleteInstancesCommand(commandCount, cmd)
case "admin_delete_model":
- return c.AdminDeleteModelsCommand(cmd)
+ return c.AdminDeleteModelsCommand(commandCount, cmd)
case "admin_delete_soft_fingerprint":
- return c.AdminDeleteSoftFingerprintCommand(cmd)
+ return c.AdminDeleteSoftFingerprintCommand(commandCount, cmd)
case "admin_enable_model":
return c.CommonEnableOrDisableModelCommand(cmd, "enable")
case "admin_disable_model":
return c.CommonEnableOrDisableModelCommand(cmd, "disable")
case "admin_show_admin_server":
- return c.CommonShowAdminServerCommand(cmd)
+ return c.CommonShowAdminServerCommand(commandCount, cmd)
case "admin_show_api_server":
- return c.CommonShowAPIServerCommand(cmd)
+ return c.CommonShowAPIServerCommand(commandCount, cmd)
case "admin_show_log_level":
- return c.AdminShowLogLevelCommand(cmd)
+ return c.AdminShowLogLevelCommand(commandCount, cmd)
case "admin_list_api_servers":
- return c.CommonListAPIServersCommand(cmd)
+ return c.CommonListAPIServersCommand(commandCount, cmd)
case "api_add_api_server":
- return c.AddAPIServerCommand(cmd)
+ return c.AddAPIServerCommand(commandCount, cmd)
case "api_delete_api_server":
- return c.DeleteAPIServerCommand(cmd)
+ return c.DeleteAPIServerCommand(commandCount, cmd)
case "api_add_admin_server":
return nil, fmt.Errorf("cannot add admin server in admin mode")
case "api_delete_admin_server":
return nil, fmt.Errorf("cannot delete admin server in admin mode")
case "admin_save_config_command":
- return c.CommonSaveServerConfigCommand(cmd)
+ return c.CommonSaveServerConfigCommand(commandCount, cmd)
case "admin_use_api_server":
- return c.CommonUseAPIServerCommand(cmd)
+ return c.CommonUseAPIServerCommand(commandCount, cmd)
case "admin_use_admin_server":
- return c.CommonUseAdminServerCommand(cmd)
+ return c.CommonUseAdminServerCommand(commandCount, cmd)
case "admin_list_bucket_objects":
- return c.AdminListBucketObjects(cmd)
+ return c.AdminListBucketObjects(commandCount, cmd)
default:
return nil, fmt.Errorf("command '%s' would be executed with API", cmd.Type)
}
}
-func (c *CLI) ExecuteUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ExecuteUserCommand(commandCount int, cmd *Command) (ResponseIf, error) {
switch cmd.Type {
case "api_register_user":
- return c.RegisterUser(cmd)
+ return c.RegisterUser(commandCount, cmd)
case "api_login_user":
- return c.LoginUserByCommand(cmd)
+ return c.LoginUserByCommand(commandCount, cmd)
case "api_logout":
return c.Logout()
case "api_ping_server":
- return c.PingServerByCommand(cmd)
+ return c.PingServerByCommand(commandCount, cmd)
case "api_set_log_level":
- return c.APISetLogLevelCommand(cmd)
+ return c.APISetLogLevelCommand(commandCount, cmd)
case "benchmark":
- return c.RunBenchmark(cmd)
+ return c.RunBenchmark(commandCount, cmd)
case "api_list_datasets":
- return c.APIListDatasetsCommand(cmd)
+ return c.APIListDatasetsCommand(commandCount, cmd)
case "api_list_dataset_documents":
- return c.APIListDatasetDocumentsCommand(cmd)
+ return c.APIListDatasetDocumentsCommand(commandCount, cmd)
case "api_list_dataset_files":
- return c.APIListDatasetFilesCommand(cmd)
+ return c.APIListDatasetFilesCommand(commandCount, cmd)
case "api_list_agents":
- return c.APIListAgentsCommand(cmd)
+ return c.APIListAgentsCommand(commandCount, cmd)
case "api_list_chats":
- return c.APIListChatsCommand(cmd)
+ return c.APIListChatsCommand(commandCount, cmd)
case "api_list_searches":
- return c.APIListSearchesCommand(cmd)
+ return c.APIListSearchesCommand(commandCount, cmd)
case "api_list_memories":
- return c.APIListMemoriesCommand(cmd)
+ return c.APIListMemoriesCommand(commandCount, cmd)
case "search_on_datasets":
- return c.SearchOnDatasets(cmd)
+ return c.SearchOnDatasets(commandCount, cmd)
case "search_help":
printSearchHelp()
return nil, nil
case "api_create_api_key":
- return c.APICreateAPIKeyCommand(cmd)
+ return c.APICreateAPIKeyCommand(commandCount, cmd)
case "api_create_dataset":
- return c.APICreateDatasetCommand(cmd)
+ return c.APICreateDatasetCommand(commandCount, cmd)
case "api_create_agent":
- return c.APICreateAgentCommand(cmd)
+ return c.APICreateAgentCommand(commandCount, cmd)
case "api_create_chat":
- return c.APICreateChatCommand(cmd)
+ return c.APICreateChatCommand(commandCount, cmd)
case "api_create_search":
- return c.APICreateSearchCommand(cmd)
+ return c.APICreateSearchCommand(commandCount, cmd)
case "api_create_memory":
- return c.APICreateMemoryCommand(cmd)
+ return c.APICreateMemoryCommand(commandCount, cmd)
case "api_list_api_keys":
- return c.APIListAPIKeysCommand(cmd)
+ return c.APIListAPIKeysCommand(commandCount, cmd)
case "api_delete_api_key":
- return c.APIDeleteAPIKeyCommand(cmd)
+ return c.APIDeleteAPIKeyCommand(commandCount, cmd)
case "api_set_api_key":
- return c.APISetAPIKeyCommand(cmd)
+ return c.APISetAPIKeyCommand(commandCount, cmd)
case "api_set_variable":
- return c.APISetVariableCommand(cmd)
+ return c.APISetVariableCommand(commandCount, cmd)
case "api_show_variable":
- return c.APIShowVariableCommand(cmd)
+ return c.APIShowVariableCommand(commandCount, cmd)
case "api_unset_api_key":
- return c.APIUnsetAPIKeyCommand(cmd)
+ return c.APIUnsetAPIKeyCommand(commandCount, cmd)
case "api_show_version":
- return c.APIShowVersionCommand(cmd)
+ return c.APIShowVersionCommand(commandCount, cmd)
case "api_show_api_key":
- return c.APIShowAPIKeyCommand(cmd)
+ return c.APIShowAPIKeyCommand(commandCount, cmd)
case "api_show_current":
- return c.CommonShowCurrentCommand(cmd)
+ return c.CommonShowCurrentCommand(commandCount, cmd)
case "api_list_available_providers":
- return c.CommonAvailableProvidersCommand(cmd)
+ return c.CommonAvailableProvidersCommand(commandCount, cmd)
case "api_show_provider":
- return c.CommonShowProviderCommand(cmd)
+ return c.CommonShowProviderCommand(commandCount, cmd)
case "api_show_provider_instance":
- return c.CommonShowProviderInstanceCommand(cmd)
+ return c.CommonShowProviderInstanceCommand(commandCount, cmd)
case "api_show_provider_instance_balance":
- return c.CommonShowProviderInstanceBalanceCommand(cmd)
+ return c.CommonShowProviderInstanceBalanceCommand(commandCount, cmd)
case "api_show_provider_instance_task":
- return c.APIShowProviderInstanceTaskCommand(cmd)
+ return c.APIShowProviderInstanceTaskCommand(commandCount, cmd)
case "api_show_provider_model":
- return c.CommonShowProviderModelCommand(cmd)
+ return c.CommonShowProviderModelCommand(commandCount, cmd)
case "api_list_provider_models":
- return c.CommonListModelsCommand(cmd)
+ return c.CommonListModelsCommand(commandCount, cmd)
case "api_list_provider_instance_models":
- return c.CommonListInstanceModelsCommand(cmd)
+ return c.CommonListInstanceModelsCommand(commandCount, cmd)
case "api_list_provider_instance_models_sync":
- return c.CommonListInstanceModelsSyncCommand(cmd)
+ return c.CommonListInstanceModelsSyncCommand(commandCount, cmd)
case "api_list_provider_instance_tasks":
- return c.APIListModelInstanceTasksCommand(cmd)
+ return c.APIListModelInstanceTasksCommand(commandCount, cmd)
// Provider commands
case "api_show_model":
- return c.CommonShowModelCommand(cmd)
+ return c.CommonShowModelCommand(commandCount, cmd)
case "api_list_all_models":
- return c.CommonListAllModels(cmd)
+ return c.CommonListAllModels(commandCount, cmd)
case "api_add_provider":
- return c.APIAddProviderCommand(cmd)
+ return c.APIAddProviderCommand(commandCount, cmd)
case "api_list_providers":
- return c.APIListProvidersCommand(cmd)
+ return c.APIListProvidersCommand(commandCount, cmd)
case "api_delete_provider":
- return c.APIDeleteProviderCommand(cmd)
+ return c.APIDeleteProviderCommand(commandCount, cmd)
case "api_delete_provider_instance":
- return c.APIDeleteProviderInstanceCommand(cmd)
+ return c.APIDeleteProviderInstanceCommand(commandCount, cmd)
case "api_drop_dataset":
- return c.APIDropDatasetCommand(cmd)
+ return c.APIDropDatasetCommand(commandCount, cmd)
case "api_drop_chat":
- return c.APIDropChatCommand(cmd)
+ return c.APIDropChatCommand(commandCount, cmd)
case "api_drop_search":
- return c.APIDropSearchCommand(cmd)
+ return c.APIDropSearchCommand(commandCount, cmd)
case "api_drop_memory":
- return c.APIDropMemoryCommand(cmd)
+ return c.APIDropMemoryCommand(commandCount, cmd)
case "api_drop_agent":
- return c.APIDropAgentCommand(cmd)
+ return c.APIDropAgentCommand(commandCount, cmd)
case "api_add_provider_instance":
- return c.APIAddProviderInstanceCommand(cmd)
+ return c.APIAddProviderInstanceCommand(commandCount, cmd)
case "api_list_provider_instances":
- return c.CommonListProviderInstancesCommand(cmd)
+ return c.CommonListProviderInstancesCommand(commandCount, cmd)
case "api_alter_provider_instance":
- return c.CommonAlterProviderInstanceCommand(cmd)
+ return c.CommonAlterProviderInstanceCommand(commandCount, cmd)
case "api_delete_provider_instance_model":
- return c.APIDeleteProviderInstanceModelCommand(cmd)
+ return c.APIDeleteProviderInstanceModelCommand(commandCount, cmd)
case "enable_model":
return c.CommonEnableOrDisableModelCommand(cmd, "enable")
case "disable_model":
return c.CommonEnableOrDisableModelCommand(cmd, "disable")
case "api_add_custom_model":
- return c.APIAddCustomModelCommand(cmd)
+ return c.APIAddCustomModelCommand(commandCount, cmd)
case "api_chat_to_model":
- return c.APIChatToModelCommand(cmd)
+ return c.APIChatToModelCommand(commandCount, cmd)
case "api_openai_chat":
- return c.APIOpenaiChatCommand(cmd)
+ return c.APIOpenaiChatCommand(commandCount, cmd)
case "openai_chat_help":
printOpenaiChatHelp()
return nil, nil
case "api_embed_user_text":
- return c.EmbedUserTextCommand(cmd)
+ return c.EmbedUserTextCommand(commandCount, cmd)
case "api_rarank_user_document":
- return c.APIRerankUserDocumentCommand(cmd)
+ return c.APIRerankUserDocumentCommand(commandCount, cmd)
case "chat completions":
- return c.ChatCompletions(cmd)
+ return c.ChatCompletions(commandCount, cmd)
case "chat completions help":
printChatCompletionsHelp()
return nil, nil
case "tts_user_command":
- return c.APITTSUserCommand(cmd)
+ return c.APITTSUserCommand(commandCount, cmd)
case "asr_user_command":
- return c.APIASRUserCommand(cmd)
+ return c.APIASRUserCommand(commandCount, cmd)
case "ocr_user_command":
- return c.APIOCRUserCommand(cmd)
+ return c.APIOCRUserCommand(commandCount, cmd)
case "api_model_parse_file":
- return c.APIModelParseFileCommand(cmd)
+ return c.APIModelParseFileCommand(commandCount, cmd)
case "check_provider_connection":
- return c.CommonCheckProviderConnectionCommand(cmd)
+ return c.CommonCheckProviderConnectionCommand(commandCount, cmd)
case "check_provider_with_key":
- return c.CommonCheckProviderWithKeyCommand(cmd)
+ return c.CommonCheckProviderWithKeyCommand(commandCount, cmd)
case "api_use_model":
- return c.APIUseModelCommand(cmd)
+ return c.APIUseModelCommand(commandCount, cmd)
case "api_use_api_server":
- return c.CommonUseAPIServerCommand(cmd)
+ return c.CommonUseAPIServerCommand(commandCount, cmd)
case "api_use_admin_server":
- return c.CommonUseAdminServerCommand(cmd)
+ return c.CommonUseAdminServerCommand(commandCount, cmd)
case "api_set_default_model":
- return c.APISetDefaultModelCommand(cmd)
+ return c.APISetDefaultModelCommand(commandCount, cmd)
case "api_reset_default_model":
- return c.APIResetDefaultModelCommand(cmd)
+ return c.APIResetDefaultModelCommand(commandCount, cmd)
case "api_list_default_models":
- return c.APIListDefaultModelsCommand(cmd)
+ return c.APIListDefaultModelsCommand(commandCount, cmd)
case "api_parse_documents":
- return c.APIParseDocumentsCommand(cmd)
+ return c.APIParseDocumentsCommand(commandCount, cmd)
case "api_start_ingestion":
- return c.APIStartIngestionCommand(cmd)
+ return c.APIStartIngestionCommand(commandCount, cmd)
case "api_stop_ingestion":
- return c.APIStopIngestionCommand(cmd)
+ return c.APIStopIngestionCommand(commandCount, cmd)
case "api_list_ingestion_tasks":
- return c.APIListIngestionTasks(cmd)
+ return c.APIListIngestionTasks(commandCount, cmd)
case "api_list_sync_logs":
- return c.APIListSyncLogsCommand(cmd)
+ return c.APIListSyncLogsCommand(commandCount, cmd)
case "api_remove_task":
- return c.APIRemoveTaskCommand(cmd)
+ return c.APIRemoveTaskCommand(commandCount, cmd)
case "user_parse_local_file_command":
- return c.APIParseLocalFileCommand(cmd)
+ return c.APIParseLocalFileCommand(commandCount, cmd)
case "api_show_admin_server":
- return c.CommonShowAdminServerCommand(cmd)
+ return c.CommonShowAdminServerCommand(commandCount, cmd)
case "api_show_api_server":
- return c.CommonShowAPIServerCommand(cmd)
+ return c.CommonShowAPIServerCommand(commandCount, cmd)
case "api_show_log_level":
- return c.APIShowLogLevelCommand(cmd)
+ return c.APIShowLogLevelCommand(commandCount, cmd)
case "api_list_api_servers":
- return c.CommonListAPIServersCommand(cmd)
+ return c.CommonListAPIServersCommand(commandCount, cmd)
case "api_list_environments":
- return c.APIListEnvironmentsCommand(cmd)
+ return c.APIListEnvironmentsCommand(commandCount, cmd)
case "api_list_variables":
- return c.APIListVariablesCommand(cmd)
+ return c.APIListVariablesCommand(commandCount, cmd)
case "api_add_api_server":
- return c.AddAPIServerCommand(cmd)
+ return c.AddAPIServerCommand(commandCount, cmd)
case "api_delete_api_server":
- return c.DeleteAPIServerCommand(cmd)
+ return c.DeleteAPIServerCommand(commandCount, cmd)
case "api_add_admin_server":
- return c.AddAdminServerCommand(cmd)
+ return c.AddAdminServerCommand(commandCount, cmd)
case "api_delete_admin_server":
- return c.DeleteAdminServerCommand(cmd)
+ return c.DeleteAdminServerCommand(commandCount, cmd)
case "api_save_config_command":
- return c.CommonSaveServerConfigCommand(cmd)
+ return c.CommonSaveServerConfigCommand(commandCount, cmd)
// File system commands
case "file_system_command":
- return c.ExecuteFilesystemCommand(cmd)
+ return c.ExecuteFilesystemCommand(commandCount, cmd)
// For debug
case "dev_chunk":
- return c.DevChunkCommand(cmd)
+ return c.DevChunkCommand(commandCount, cmd)
case "dev_create_chunk_store":
- return c.DevCreateChunkStoreCommand(cmd)
+ return c.DevCreateChunkStoreCommand(commandCount, cmd)
case "dev_drop_chunk_store":
- return c.DevDropChunkStoreCommand(cmd)
+ return c.DevDropChunkStoreCommand(commandCount, cmd)
case "dev_create_metadata_store":
- return c.DevCreateMetadataStoreCommand(cmd)
+ return c.DevCreateMetadataStoreCommand(commandCount, cmd)
case "dev_drop_metadata_store":
- return c.DevDropMetadataStoreCommand(cmd)
+ return c.DevDropMetadataStoreCommand(commandCount, cmd)
case "dev_update_chunk":
- return c.DevUpdateChunkCommand(cmd)
+ return c.DevUpdateChunkCommand(commandCount, cmd)
case "dev_get_chunk":
- return c.DevGetChunkCommand(cmd)
+ return c.DevGetChunkCommand(commandCount, cmd)
case "dev_set_meta":
- return c.DevSetMetaCommand(cmd)
+ return c.DevSetMetaCommand(commandCount, cmd)
case "dev_delete_meta":
- return c.DevDeleteMetaCommand(cmd)
+ return c.DevDeleteMetaCommand(commandCount, cmd)
case "dev_rm_tags":
- return c.DevRmTagsCommand(cmd)
+ return c.DevRmTagsCommand(commandCount, cmd)
case "dev_remove_chunks":
- return c.DevRemoveChunksCommand(cmd)
+ return c.DevRemoveChunksCommand(commandCount, cmd)
case "dev_get_metadata":
- return c.DevGetMetadataCommand(cmd)
+ return c.DevGetMetadataCommand(commandCount, cmd)
default:
return nil, fmt.Errorf("command '%s' would be executed with API", cmd.Type)
}
diff --git a/internal/cli/common_command.go b/internal/cli/common_command.go
index 6fcf0a0abf..243eb32feb 100644
--- a/internal/cli/common_command.go
+++ b/internal/cli/common_command.go
@@ -30,7 +30,7 @@ import (
"golang.org/x/term"
)
-func (c *CLI) LoginUserByCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) LoginUserByCommand(commandCount int, cmd *Command) (ResponseIf, error) {
email, ok := cmd.Params["email"].(string)
if !ok {
return nil, fmt.Errorf("email not provided")
@@ -109,31 +109,21 @@ func (c *CLI) LoginUserInteractive(email, password string) error {
return nil
}
-func (c *CLI) PingServerByCommand(cmd *Command) (ResponseIf, error) {
- iterations := 1
- if iterationsParam, ok := cmd.Params["iterations"]; ok {
- iterations = int(iterationsParam.(float64))
- }
- return c.PingServer(iterations)
+func (c *CLI) PingServerByCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ return c.PingServer(commandCount)
}
-func (c *CLI) PingServer(iterations int) (ResponseIf, error) {
+func (c *CLI) PingServer(commandCount int) (ResponseIf, error) {
var pingPath string
var resp *Response
var err error
switch c.Config.CLIMode {
case AdminMode:
pingPath = "/admin/ping"
- if iterations > 1 {
- return c.AdminServerClient.RequestWithIterations("GET", pingPath, "web", nil, nil, iterations)
- }
- resp, err = c.AdminServerClient.Request("GET", pingPath, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", pingPath, "web", nil, nil)
case APIMode:
pingPath = "/system/ping"
- if iterations > 1 {
- return c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].RequestWithIterations("GET", pingPath, "web", nil, nil, iterations)
- }
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", pingPath, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", pingPath, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -191,7 +181,7 @@ func (c *CLI) loginUser(httpClient *HTTPClient, baseURL, email, password string)
}
var resp *Response
- resp, err = httpClient.Request("POST", baseURL, "", nil, payload)
+ resp, err = httpClient.Request(1, "POST", baseURL, "", nil, payload)
if err != nil {
return "", err
}
@@ -205,7 +195,7 @@ func (c *CLI) loginUser(httpClient *HTTPClient, baseURL, email, password string)
return "", fmt.Errorf("login failed: %s", result.Message)
}
- token := resp.Headers.Get("Authorization")
+ token := resp.Header.Get("Authorization")
if token == "" {
return "", fmt.Errorf("login failed: missing Authorization header")
}
@@ -222,12 +212,12 @@ func (c *CLI) Logout() (ResponseIf, error) {
if c.AdminServerClient.LoginToken == nil {
return nil, fmt.Errorf("not logged in")
}
- resp, err = c.AdminServerClient.Request("POST", "/admin/logout", "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(1, "POST", "/admin/logout", "web", nil, nil)
case APIMode:
if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
return nil, fmt.Errorf("not logged in")
}
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/auth/logout", "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(1, "POST", "/auth/logout", "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -261,15 +251,15 @@ func (c *CLI) Logout() (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonAvailableProvidersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonAvailableProvidersCommand(commandCount int, cmd *Command) (ResponseIf, error) {
var resp *Response
var err error
switch c.Config.CLIMode {
case AdminMode:
- resp, err = c.AdminServerClient.Request("GET", "/admin/providers?available=true", "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", "/admin/providers?available=true", "web", nil, nil)
case APIMode:
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/providers?available=true", "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", "/providers?available=true", "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -294,7 +284,7 @@ func (c *CLI) CommonAvailableProvidersCommand(cmd *Command) (ResponseIf, error)
return &result, nil
}
-func (c *CLI) CommonShowProviderCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowProviderCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
return nil, fmt.Errorf("provider_name not provided")
@@ -306,10 +296,10 @@ func (c *CLI) CommonShowProviderCommand(cmd *Command) (ResponseIf, error) {
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s", providerName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s", providerName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -322,7 +312,7 @@ func (c *CLI) CommonShowProviderCommand(cmd *Command) (ResponseIf, error) {
}
// CommonShowProviderInstanceCommand shows details of a specific instance
-func (c *CLI) CommonShowProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowProviderInstanceCommand(commandCount int, cmd *Command) (ResponseIf, error) {
instanceName, ok := cmd.Params["instance_name"].(string)
if !ok {
return nil, fmt.Errorf("instance name not provided")
@@ -339,10 +329,10 @@ func (c *CLI) CommonShowProviderInstanceCommand(cmd *Command) (ResponseIf, error
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -355,7 +345,7 @@ func (c *CLI) CommonShowProviderInstanceCommand(cmd *Command) (ResponseIf, error
}
// CommonShowProviderInstanceBalanceCommand shows balance of a specific instance
-func (c *CLI) CommonShowProviderInstanceBalanceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowProviderInstanceBalanceCommand(commandCount int, cmd *Command) (ResponseIf, error) {
instanceName, ok := cmd.Params["instance_name"].(string)
if !ok {
@@ -373,10 +363,10 @@ func (c *CLI) CommonShowProviderInstanceBalanceCommand(cmd *Command) (ResponseIf
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s/balance", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s/balance", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -390,7 +380,7 @@ func (c *CLI) CommonShowProviderInstanceBalanceCommand(cmd *Command) (ResponseIf
// CommonListProviderInstancesCommand lists all instances of a provider
// LIST INSTANCES FROM PROVIDER <name>
-func (c *CLI) CommonListProviderInstancesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListProviderInstancesCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
@@ -403,10 +393,10 @@ func (c *CLI) CommonListProviderInstancesCommand(cmd *Command) (ResponseIf, erro
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances", providerName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances", providerName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -432,7 +422,7 @@ func (c *CLI) CommonListProviderInstancesCommand(cmd *Command) (ResponseIf, erro
return &result, nil
}
-func (c *CLI) CommonListInstanceModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListInstanceModelsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
@@ -449,10 +439,10 @@ func (c *CLI) CommonListInstanceModelsCommand(cmd *Command) (ResponseIf, error)
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s/models", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -477,7 +467,7 @@ func (c *CLI) CommonListInstanceModelsCommand(cmd *Command) (ResponseIf, error)
return &result, nil
}
-func (c *CLI) CommonListModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListModelsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
@@ -490,10 +480,10 @@ func (c *CLI) CommonListModelsCommand(cmd *Command) (ResponseIf, error) {
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/models", providerName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/models", providerName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -518,7 +508,7 @@ func (c *CLI) CommonListModelsCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonListInstanceModelsSyncCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListInstanceModelsSyncCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
@@ -535,10 +525,10 @@ func (c *CLI) CommonListInstanceModelsSyncCommand(cmd *Command) (ResponseIf, err
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s/models?supported=true", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s/models?supported=true", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -563,7 +553,7 @@ func (c *CLI) CommonListInstanceModelsSyncCommand(cmd *Command) (ResponseIf, err
return &result, nil
}
-func (c *CLI) CommonShowProviderModelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowProviderModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
return nil, fmt.Errorf("provider_name not provided")
@@ -579,10 +569,10 @@ func (c *CLI) CommonShowProviderModelCommand(cmd *Command) (ResponseIf, error) {
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/models/%s", providerName, modelName)
- resp, err = c.AdminServerClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/models/%s", providerName, modelName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -593,7 +583,7 @@ func (c *CLI) CommonShowProviderModelCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "show model")
}
-func (c *CLI) CommonCheckProviderWithKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonCheckProviderWithKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok || providerName == "" {
@@ -630,10 +620,10 @@ func (c *CLI) CommonCheckProviderWithKeyCommand(cmd *Command) (ResponseIf, error
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/connection", providerName)
- resp, err = c.AdminServerClient.Request("POST", endPoint, "web", nil, payload)
+ resp, err = c.AdminServerClient.Request(commandCount, "POST", endPoint, "web", nil, payload)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/connection", providerName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", endPoint, "web", nil, payload)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "POST", endPoint, "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -652,7 +642,7 @@ func (c *CLI) CommonCheckProviderWithKeyCommand(cmd *Command) (ResponseIf, error
}
}
-func (c *CLI) CommonCheckProviderConnectionCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonCheckProviderConnectionCommand(commandCount int, cmd *Command) (ResponseIf, error) {
instanceName, ok := cmd.Params["instance_name"].(string)
if !ok {
@@ -670,10 +660,10 @@ func (c *CLI) CommonCheckProviderConnectionCommand(cmd *Command) (ResponseIf, er
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s/connection", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("POST", endPoint, "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "POST", endPoint, "web", nil, nil)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s/connection", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", endPoint, "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "POST", endPoint, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -693,7 +683,7 @@ func (c *CLI) CommonCheckProviderConnectionCommand(cmd *Command) (ResponseIf, er
}
// AlterProviderInstanceCommand alters a provider instance
-func (c *CLI) CommonAlterProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonAlterProviderInstanceCommand(commandCount int, cmd *Command) (ResponseIf, error) {
providerName, ok := cmd.Params["provider_name"].(string)
if !ok {
@@ -723,10 +713,10 @@ func (c *CLI) CommonAlterProviderInstanceCommand(cmd *Command) (ResponseIf, erro
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s", providerName, instanceName)
- resp, err = c.AdminServerClient.Request("PUT", endPoint, "web", nil, payload)
+ resp, err = c.AdminServerClient.Request(commandCount, "PUT", endPoint, "web", nil, payload)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s", providerName, instanceName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PUT", endPoint, "web", nil, payload)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "PUT", endPoint, "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -772,10 +762,10 @@ func (c *CLI) CommonEnableOrDisableModelCommand(cmd *Command, status string) (Re
switch c.Config.CLIMode {
case AdminMode:
endPoint = fmt.Sprintf("/admin/providers/%s/instances/%s/models/%s", providerName, instanceName, modelName)
- resp, err = c.AdminServerClient.Request("PATCH", endPoint, "web", nil, payload)
+ resp, err = c.AdminServerClient.Request(1, "PATCH", endPoint, "web", nil, payload)
case APIMode:
endPoint = fmt.Sprintf("/providers/%s/instances/%s/models/%s", providerName, instanceName, modelName)
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PATCH", endPoint, "web", nil, payload)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(1, "PATCH", endPoint, "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -794,7 +784,7 @@ func (c *CLI) CommonEnableOrDisableModelCommand(cmd *Command, status string) (Re
}
}
-func (c *CLI) APISetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APISetDefaultModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
modelType, ok := cmd.Params["model_type"].(string)
if !ok {
@@ -823,9 +813,9 @@ func (c *CLI) APISetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
var resp *Response
switch c.Config.CLIMode {
case AdminMode:
- resp, err = c.AdminServerClient.Request("PATCH", "/admin/models", "web", nil, payload)
+ resp, err = c.AdminServerClient.Request(commandCount, "PATCH", "/admin/models", "web", nil, payload)
case APIMode:
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PATCH", "/models", "web", nil, payload)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "PATCH", "/models", "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -837,7 +827,7 @@ func (c *CLI) APISetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "set default model")
}
-func (c *CLI) APIResetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIResetDefaultModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
modelType, ok := cmd.Params["model_type"].(string)
if !ok {
@@ -852,9 +842,9 @@ func (c *CLI) APIResetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
var err error
switch c.Config.CLIMode {
case AdminMode:
- resp, err = c.AdminServerClient.Request("PATCH", "/admin/models", "web", nil, payload)
+ resp, err = c.AdminServerClient.Request(commandCount, "PATCH", "/admin/models", "web", nil, payload)
case APIMode:
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PATCH", "/models", "web", nil, payload)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "PATCH", "/models", "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -866,15 +856,15 @@ func (c *CLI) APIResetDefaultModelCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "reset default model")
}
-func (c *CLI) APIListDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListDefaultModelsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
var resp *Response
var err error
switch c.Config.CLIMode {
case AdminMode:
- resp, err = c.AdminServerClient.Request("GET", "/admin/models", "web", nil, nil)
+ resp, err = c.AdminServerClient.Request(commandCount, "GET", "/admin/models", "web", nil, nil)
case APIMode:
- resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/models/default", "web", nil, nil)
+ resp, err = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request(commandCount, "GET", "/models/default", "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -899,7 +889,7 @@ func (c *CLI) APIListDefaultModelsCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonShowCurrentCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowCurrentCommand(commandCount int, cmd *Command) (ResponseIf, error) {
var result *CommonDataResponse
switch c.Config.CLIMode {
@@ -944,11 +934,11 @@ func (c *CLI) CommonShowCurrentCommand(cmd *Command) (ResponseIf, error) {
return result, nil
}
-func (c *CLI) CommonShowAdminServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowAdminServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
return c.GetAdminServerInfo()
}
-func (c *CLI) CommonShowAPIServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowAPIServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
apiServerName, ok := cmd.Params["api_server_name"].(string)
if !ok {
return nil, fmt.Errorf("api_server_name not provided")
@@ -960,7 +950,7 @@ func (c *CLI) CommonShowAPIServerCommand(cmd *Command) (ResponseIf, error) {
return result, nil
}
-func (c *CLI) CommonListAPIServersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListAPIServersCommand(commandCount int, cmd *Command) (ResponseIf, error) {
var result CommonResponse
result.Data = make([]map[string]interface{}, 0)
@@ -990,7 +980,7 @@ func (c *CLI) CommonListAPIServersCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AddAPIServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AddAPIServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
apiServerName, ok := cmd.Params["server_name"].(string)
if !ok {
return nil, fmt.Errorf("server name not provided")
@@ -1056,7 +1046,7 @@ func (c *CLI) AddAPIServerCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) DeleteAPIServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DeleteAPIServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
apiServerName, ok := cmd.Params["server_name"].(string)
if !ok {
return nil, fmt.Errorf("server name not provided")
@@ -1078,7 +1068,7 @@ func (c *CLI) DeleteAPIServerCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) AddAdminServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) AddAdminServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.AdminServerClient != nil && c.AdminServerClient.LoginToken != nil {
return nil, fmt.Errorf("admin server already login, please logout")
@@ -1132,7 +1122,7 @@ func (c *CLI) AddAdminServerCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) DeleteAdminServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DeleteAdminServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.AdminServerClient == nil && c.Config.AdminClientConfig == nil {
return nil, fmt.Errorf("admin server not exists")
@@ -1153,7 +1143,7 @@ func (c *CLI) DeleteAdminServerCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonSaveServerConfigCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonSaveServerConfigCommand(commandCount int, cmd *Command) (ResponseIf, error) {
switch c.Config.CLIMode {
case AdminMode:
@@ -1230,7 +1220,7 @@ func (c *CLI) GetAPIServerInfo(serverName string) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonListAllModels(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonListAllModels(commandCount int, cmd *Command) (ResponseIf, error) {
page, ok := cmd.Params["page"].(int)
if !ok {
@@ -1254,11 +1244,11 @@ func (c *CLI) CommonListAllModels(cmd *Command) (ResponseIf, error) {
case AdminMode:
httpClient = c.AdminServerClient
apiURL := "/admin/all-models"
- resp, err = httpClient.Request("GET", apiURL, "web", nil, payload)
+ resp, err = httpClient.Request(commandCount, "GET", apiURL, "web", nil, payload)
case APIMode:
httpClient = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
apiURL := "/all-models"
- resp, err = httpClient.Request("GET", apiURL, "web", nil, payload)
+ resp, err = httpClient.Request(commandCount, "GET", apiURL, "web", nil, payload)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -1283,7 +1273,7 @@ func (c *CLI) CommonListAllModels(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) CommonShowModelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonShowModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
modelName, ok := cmd.Params["model_name"].(string)
if !ok {
@@ -1299,11 +1289,11 @@ func (c *CLI) CommonShowModelCommand(cmd *Command) (ResponseIf, error) {
case AdminMode:
baseURL := fmt.Sprintf("/admin/all-models/%s", encodedModelName)
httpClient = c.AdminServerClient
- resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)
+ resp, err = httpClient.Request(commandCount, "GET", baseURL, "web", nil, nil)
case APIMode:
baseURL := fmt.Sprintf("/all-models/%s", encodedModelName)
httpClient = c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err = httpClient.Request("GET", baseURL, "web", nil, nil)
+ resp, err = httpClient.Request(commandCount, "GET", baseURL, "web", nil, nil)
default:
return nil, fmt.Errorf("invalid server type")
}
@@ -1367,7 +1357,7 @@ func FlattenMap(data map[string]interface{}, prefix string, result *[]map[string
}
}
-func (c *CLI) CommonUseAPIServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonUseAPIServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
serverName, ok := cmd.Params["server_name"].(string)
if !ok {
return nil, fmt.Errorf("server_name not provided")
@@ -1407,7 +1397,7 @@ func (c *CLI) CommonUseAPIServerCommand(cmd *Command) (ResponseIf, error) {
}
-func (c *CLI) CommonUseAdminServerCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) CommonUseAdminServerCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode == AdminMode {
return nil, fmt.Errorf("already in admin mode")
@@ -1428,7 +1418,7 @@ func (c *CLI) CommonUseAdminServerCommand(cmd *Command) (ResponseIf, error) {
}
func (c *CLI) getDatasetIDByName(datasetName string) (string, error) {
- response, err := c.APIListDatasetsCommand(nil)
+ response, err := c.APIListDatasetsCommand(1, nil)
if err != nil {
return "", err
}
@@ -1445,7 +1435,7 @@ func (c *CLI) getDatasetIDByName(datasetName string) (string, error) {
}
func (c *CLI) getAgentIDByName(agentName string) (string, error) {
- response, err := c.APIListAgentsCommand(nil)
+ response, err := c.APIListAgentsCommand(1, nil)
if err != nil {
return "", err
}
@@ -1462,7 +1452,7 @@ func (c *CLI) getAgentIDByName(agentName string) (string, error) {
}
func (c *CLI) getSearchIDByName(searchName string) (string, error) {
- response, err := c.APIListSearchesCommand(nil)
+ response, err := c.APIListSearchesCommand(1, nil)
if err != nil {
return "", err
}
@@ -1481,7 +1471,7 @@ func (c *CLI) getSearchIDByName(searchName string) (string, error) {
}
func (c *CLI) getChatIDByName(chatName string) (string, error) {
- response, err := c.APIListChatsCommand(nil)
+ response, err := c.APIListChatsCommand(1, nil)
if err != nil {
return "", err
}
@@ -1498,7 +1488,7 @@ func (c *CLI) getChatIDByName(chatName string) (string, error) {
}
func (c *CLI) getMemoryIDByName(memoryName string) (string, error) {
- response, err := c.APIListMemoriesCommand(nil)
+ response, err := c.APIListMemoriesCommand(1, nil)
if err != nil {
return "", err
}
diff --git a/internal/cli/filesystem_command.go b/internal/cli/filesystem_command.go
index 2f4bd167e0..91942799e5 100644
--- a/internal/cli/filesystem_command.go
+++ b/internal/cli/filesystem_command.go
@@ -29,7 +29,7 @@ import (
)
// ExecuteFilesystemCommand ExecuteFilesystem executes a Filesystem command and returns a ResponseIf.
-func (c *CLI) ExecuteFilesystemCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ExecuteFilesystemCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
diff --git a/internal/cli/http_client.go b/internal/cli/http_client.go
index 59602605b0..211a285edb 100644
--- a/internal/cli/http_client.go
+++ b/internal/cli/http_client.go
@@ -22,10 +22,8 @@ import (
"encoding/json"
"fmt"
"io"
- "mime"
"net/http"
ce "ragflow/internal/cli/filesystem"
- "strings"
"time"
)
@@ -116,8 +114,10 @@ func (c *HTTPClient) Headers(authKind string, extra map[string]string) map[strin
type Response struct {
StatusCode int
Body []byte
- Headers http.Header
+ Header http.Header
Duration float64
+ Success int
+ Fail int
}
// JSON parses the response body as JSON
@@ -130,7 +130,7 @@ func (r *Response) JSON() (map[string]interface{}, error) {
}
// Request makes an HTTP request
-func (c *HTTPClient) Request(method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*Response, error) {
+func (c *HTTPClient) Request(commandCount int, method, path string, authKind string, headers map[string]string, jsonBody map[string]interface{}) (*Response, error) {
if c == nil {
return nil, fmt.Errorf("HTTP Client is nil")
}
@@ -160,144 +160,58 @@ func (c *HTTPClient) Request(method, path string, authKind string, headers map[s
req.Header.Set(k, v)
}
- var resp *http.Response
+ var respBody []byte
startTime := time.Now()
- resp, err = c.client.Do(req)
- if err != nil {
- return nil, err
+ var statusCode int
+
+ successCount := 0
+ failCount := 0
+ var respHeader http.Header
+ for i := 0; i < commandCount; i++ {
+ respBody, respHeader, statusCode, err = c.HttpDo(req)
+ if err == nil {
+ var result struct {
+ Code int `json:"code"`
+ }
+ if err = json.Unmarshal(respBody, &result); err == nil && result.Code != 0 {
+ failCount++
+ } else {
+ successCount++
+ }
+ } else {
+ failCount++
+ }
}
- defer resp.Body.Close()
- respBody, err := io.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
duration := time.Since(startTime).Seconds()
return &Response{
- StatusCode: resp.StatusCode,
+ StatusCode: statusCode,
Body: respBody,
- Headers: resp.Header.Clone(),
+ Header: respHeader,
Duration: duration,
+ Success: successCount,
+ Fail: failCount,
}, nil
}
-func isJSONMediaType(contentType string) bool {
- mediaType, _, _ := mime.ParseMediaType(contentType)
- return mediaType == "application/json" || strings.HasSuffix(mediaType, "+json")
-}
-
-func benchmarkResponseSucceeded(resp *Response) bool {
- if resp.StatusCode != http.StatusOK {
- return false
- }
-
- result, err := resp.JSON()
+func (c *HTTPClient) HttpDo(req *http.Request) ([]byte, http.Header, int, error) {
+ resp, err := c.client.Do(req)
if err != nil {
- // Some successful endpoints, such as ping, return plain text.
- return !isJSONMediaType(resp.Headers.Get("Content-Type"))
- }
- code, hasCode := result["code"].(float64)
- return !hasCode || code == 0
-}
-
-// 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, 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, authKind, headers, jsonBody)
- totalDuration := time.Since(start).Seconds()
- if err != nil {
- return nil, err
- }
-
- response.Code = resp.StatusCode
- response.Duration = totalDuration
- if benchmarkResponseSucceeded(resp) {
- response.SuccessCount = 1
- } else {
- response.FailureCount = 1
- }
- return response, nil
- }
-
- url := c.BuildURL(path, authKind)
- 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"
- }
-
- responseList := make([]*Response, 0, iterations)
- var totalDuration float64
-
- for i := 0; i < iterations; i++ {
- start := time.Now()
-
- var reqBody io.Reader
- if body != nil {
- // Need to create a new reader for each request
- jsonData, _ := json.Marshal(jsonBody)
- reqBody = bytes.NewReader(jsonData)
- }
-
- req, err := http.NewRequest(method, url, reqBody)
- if err != nil {
- return nil, err
- }
-
- for k, v := range mergedHeaders {
- req.Header.Set(k, v)
- }
-
- resp, err := c.client.Do(req)
- if err != nil {
- return nil, err
- }
-
- respBody, err := io.ReadAll(resp.Body)
- resp.Body.Close()
- if err != nil {
- return nil, err
- }
-
- responseList = append(responseList, &Response{
- StatusCode: resp.StatusCode,
- Body: respBody,
- Headers: resp.Header.Clone(),
- })
-
- totalDuration += time.Since(start).Seconds()
+ return nil, nil, 500, err
}
+ defer resp.Body.Close()
- response.Code = 0
- response.Duration = totalDuration
- for _, resp := range responseList {
- if benchmarkResponseSucceeded(resp) {
- response.SuccessCount++
- } else {
- response.FailureCount++
- }
+ respBody, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return nil, nil, resp.StatusCode, err
}
-
- return response, nil
+ return respBody, resp.Header, resp.StatusCode, nil
}
// RequestJSON makes an HTTP request and returns JSON response
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)
+ resp, err := c.Request(1, method, path, authKind, headers, jsonBody)
if err != nil {
return nil, err
}
@@ -341,7 +255,7 @@ func (c *HTTPClient) UploadMultipart(path string, contentType string, body io.Re
Code int `json:"code"`
Message string `json:"message"`
}
- if err := json.Unmarshal(respBody, &result); err == nil && result.Code != 0 {
+ if err = json.Unmarshal(respBody, &result); err == nil && result.Code != 0 {
return fmt.Errorf("upload failed: %s", result.Message)
}
@@ -422,14 +336,14 @@ func (a *httpClientAdapter) Request(method, path string, authKind string, header
authKind = "web" // default
}
}
- resp, err := a.client.Request(method, path, authKind, headers, jsonBody)
+ resp, err := a.client.Request(1, method, path, authKind, headers, jsonBody)
if err != nil {
return nil, err
}
return &ce.HTTPResponse{
StatusCode: resp.StatusCode,
Body: resp.Body,
- Headers: resp.Headers,
+ Headers: resp.Header,
Duration: resp.Duration,
}, nil
}
diff --git a/internal/cli/http_client_test.go b/internal/cli/http_client_test.go
index b158f23567..81560ff80f 100644
--- a/internal/cli/http_client_test.go
+++ b/internal/cli/http_client_test.go
@@ -57,34 +57,12 @@ func TestRequestWithIterationsCountsApplicationErrorsAsFailures(t *testing.T) {
_, _ = w.Write([]byte(`{"code": 100, "message": "request failed"}`))
}))
- result, err := client.RequestWithIterations(http.MethodGet, "/failure", "web", nil, nil, 3)
+ result, err := client.Request(3, http.MethodGet, "/failure", "web", nil, nil)
if err != nil {
- t.Fatalf("RequestWithIterations() error = %v", err)
- }
- if result.SuccessCount != 0 || result.FailureCount != 3 {
- t.Fatalf("successes = %d, failures = %d; want 0 successes and 3 failures", result.SuccessCount, result.FailureCount)
+ t.Fatalf("Request() error = %v", err)
}
-}
-
-func TestRequestWithIterationsCountsMalformedJSONAsFailures(t *testing.T) {
- for _, contentType := range []string{
- "application/json",
- "application/problem+json; charset=utf-8",
- } {
- t.Run(contentType, func(t *testing.T) {
- client := newTestHTTPClient(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
- w.Header().Set("Content-Type", contentType)
- _, _ = w.Write([]byte(`{"code":`))
- }))
-
- result, err := client.RequestWithIterations(http.MethodGet, "/malformed", "web", nil, nil, 3)
- if err != nil {
- t.Fatalf("RequestWithIterations() error = %v", err)
- }
- if result.SuccessCount != 0 || result.FailureCount != 3 {
- t.Fatalf("successes = %d, failures = %d; want 0 successes and 3 failures", result.SuccessCount, result.FailureCount)
- }
- })
+ if result.Success != 0 || result.Fail != 3 {
+ t.Fatalf("successes = %d, failures = %d; want 0 successes and 3 failures", result.Success, result.Fail)
}
}
@@ -94,11 +72,11 @@ func TestRequestWithIterationsPreservesPlainTextSuccess(t *testing.T) {
_, _ = w.Write([]byte("pong"))
}))
- result, err := client.RequestWithIterations(http.MethodGet, "/ping", "none", nil, nil, 3)
+ result, err := client.Request(3, http.MethodGet, "/ping", "none", nil, nil)
if err != nil {
t.Fatalf("RequestWithIterations() error = %v", err)
}
- if result.SuccessCount != 3 || result.FailureCount != 0 {
- t.Fatalf("successes = %d, failures = %d; want 3 successes and 0 failures", result.SuccessCount, result.FailureCount)
+ if result.Success != 3 || result.Fail != 0 {
+ t.Fatalf("successes = %d, failures = %d; want 3 successes and 0 failures", result.Success, result.Fail)
}
}
diff --git a/internal/cli/user_command.go b/internal/cli/user_command.go
index 09a9e95d77..c9b73aee60 100644
--- a/internal/cli/user_command.go
+++ b/internal/cli/user_command.go
@@ -39,22 +39,10 @@ import (
// APIShowVersionCommand show RAGFlow server version
// Returns benchmark result map if iterations > 1, otherwise prints status
-func (c *CLI) APIShowVersionCommand(cmd *Command) (ResponseIf, error) {
- // Get iterations from command params (for benchmark)
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
+func (c *CLI) APIShowVersionCommand(commandCount int, cmd *Command) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- if iterations > 1 {
- // Benchmark mode: multiple iterations
- return httpClient.RequestWithIterations("GET", "/system/version", "web", nil, nil, iterations)
- }
-
- // Single mode
- resp, err := httpClient.Request("GET", "/system/version", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/system/version", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to show version: %w", err)
}
@@ -73,7 +61,7 @@ func (c *CLI) APIShowVersionCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APISetLogLevelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APISetLogLevelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -88,7 +76,7 @@ func (c *CLI) APISetLogLevelCommand(cmd *Command) (ResponseIf, error) {
}
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("PUT", "/system/config/log", "admin", nil, payload)
+ resp, err := httpClient.Request(commandCount, "PUT", "/system/config/log", "admin", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to change log level: %w", err)
}
@@ -96,7 +84,7 @@ func (c *CLI) APISetLogLevelCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "change log level")
}
-func (c *CLI) RegisterUser(cmd *Command) (ResponseIf, error) {
+func (c *CLI) RegisterUser(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -144,7 +132,7 @@ func (c *CLI) RegisterUser(cmd *Command) (ResponseIf, error) {
}
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("POST", "/users", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/users", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to register user: %w", err)
}
@@ -168,7 +156,7 @@ func (c *CLI) RegisterUser(cmd *Command) (ResponseIf, error) {
// APIListDatasetsCommand lists datasets for current user (user mode)
// Returns (result_map, error) - result_map is non-nil for benchmark mode
-func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListDatasetsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -176,7 +164,7 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
// Determine auth kind based on whether API key is being used
- if httpClient.LoginToken == nil && !c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey {
+ if httpClient.LoginToken == nil && !httpClient.useAPIKey {
return nil, fmt.Errorf("no authorization")
}
@@ -190,7 +178,7 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := httpClient.Request("GET", "/datasets", authKind, nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/datasets", authKind, nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list datasets: %w", err)
}
@@ -198,7 +186,7 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list datasets")
}
-func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListDatasetDocumentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -221,7 +209,7 @@ func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) {
url := fmt.Sprintf("/datasets/%s/documents?page=%d&page_size=%d&keywords=%s&return_empty_metadata=%s", datasetID, page, pageSize, keywords, returnEmptyMetadata)
// Normal mode
- resp, err := httpClient.Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list documents: %w", err)
}
@@ -243,7 +231,7 @@ func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIListDatasetFilesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListDatasetFilesCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -267,7 +255,7 @@ func (c *CLI) APIListDatasetFilesCommand(cmd *Command) (ResponseIf, error) {
url := fmt.Sprintf("/datasets/%s/documents", datasetID)
// Normal mode
- resp, err := httpClient.Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list documents: %w", err)
}
@@ -290,7 +278,7 @@ func (c *CLI) APIListDatasetFilesCommand(cmd *Command) (ResponseIf, error) {
}
// APIListAgentsCommand lists agents
-func (c *CLI) APIListAgentsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListAgentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -312,7 +300,7 @@ func (c *CLI) APIListAgentsCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := httpClient.Request("GET", "/agents", authKind, nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/agents", authKind, nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list agents: %w", err)
}
@@ -335,7 +323,7 @@ func (c *CLI) APIListAgentsCommand(cmd *Command) (ResponseIf, error) {
}
// APIListChatsCommand lists chats
-func (c *CLI) APIListChatsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListChatsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -357,7 +345,7 @@ func (c *CLI) APIListChatsCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := httpClient.Request("GET", "/chats", authKind, nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/chats", authKind, nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list chats: %w", err)
}
@@ -380,7 +368,7 @@ func (c *CLI) APIListChatsCommand(cmd *Command) (ResponseIf, error) {
}
// APIListSearchesCommand lists searches
-func (c *CLI) APIListSearchesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListSearchesCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -402,7 +390,7 @@ func (c *CLI) APIListSearchesCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := httpClient.Request("GET", "/searches", authKind, nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/searches", authKind, nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list searches: %w", err)
}
@@ -425,7 +413,7 @@ func (c *CLI) APIListSearchesCommand(cmd *Command) (ResponseIf, error) {
}
// APIListMemoriesCommand lists memories
-func (c *CLI) APIListMemoriesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListMemoriesCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -446,7 +434,7 @@ func (c *CLI) APIListMemoriesCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := httpClient.Request("GET", "/memories", authKind, nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/memories", authKind, nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list memories: %w", err)
}
@@ -469,17 +457,11 @@ func (c *CLI) APIListMemoriesCommand(cmd *Command) (ResponseIf, error) {
}
// ListDatasetDocumentUserCommand lists dataset documents
-func (c *CLI) ListDatasetDocumentUserCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ListDatasetDocumentUserCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- // Check for benchmark iterations
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
// Determine auth kind based on whether API key is being used
if httpClient.LoginToken == nil && !httpClient.useAPIKey {
@@ -497,13 +479,8 @@ func (c *CLI) ListDatasetDocumentUserCommand(cmd *Command) (ResponseIf, error) {
returnEmptyMetadata := "true"
url := fmt.Sprintf("/datasets/%s/documents?page=%d&page_size=%d&keywords=%s&return_empty_metadata=%s", datasetID, page, pageSize, keywords, returnEmptyMetadata)
- if iterations > 1 {
- // Benchmark mode - return raw result for benchmark stats
- return httpClient.RequestWithIterations("GET", url, "web", nil, nil, iterations)
- }
-
// Normal mode
- resp, err := httpClient.Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list documents: %w", err)
}
@@ -529,7 +506,7 @@ func (c *CLI) ListDatasetDocumentUserCommand(cmd *Command) (ResponseIf, error) {
func (c *CLI) getDatasetID(datasetName string) (string, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("GET", "/datasets", "web", nil, nil)
+ resp, err := httpClient.Request(1, "GET", "/datasets", "web", nil, nil)
if err != nil {
return "", fmt.Errorf("failed to list datasets: %w", err)
}
@@ -568,7 +545,7 @@ func (c *CLI) getDatasetID(datasetName string) (string, error) {
}
// DevGetMetadataCommand gets metadata for one or more datasets
-func (c *CLI) DevGetMetadataCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevGetMetadataCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -592,7 +569,7 @@ func (c *CLI) DevGetMetadataCommand(cmd *Command) (ResponseIf, error) {
datasetIDsStr := strings.Join(datasetIDs, ",")
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("GET", "/datasets/metadata/flattened?dataset_ids="+datasetIDsStr, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/datasets/metadata/flattened?dataset_ids="+datasetIDsStr, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list metadata: %w", err)
}
@@ -645,7 +622,7 @@ func retrievalChunkValue(chunk map[string]interface{}, key, fallbackKey string)
// SearchOnDatasets searches for chunks in specified datasets
// Returns (result_map, error) - result_map is non-nil for benchmark mode
-func (c *CLI) SearchOnDatasets(cmd *Command) (ResponseIf, error) {
+func (c *CLI) SearchOnDatasets(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -672,12 +649,6 @@ func (c *CLI) SearchOnDatasets(cmd *Command) (ResponseIf, error) {
datasetIDs = append(datasetIDs, id)
}
- // Check for benchmark iterations
- iterations := 1
- if val, ok := cmd.Params["iterations"].(int); ok && val > 1 {
- iterations = val
- }
-
payload := map[string]interface{}{
"dataset_ids": datasetIDs,
"question": question,
@@ -743,13 +714,9 @@ func (c *CLI) SearchOnDatasets(cmd *Command) (ResponseIf, error) {
}
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- if iterations > 1 {
- // Benchmark mode - return raw result for benchmark stats
- return httpClient.RequestWithIterations("POST", "/datasets/search", "web", nil, payload, iterations)
- }
// Normal mode
- resp, err := httpClient.Request("POST", "/datasets/search", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/datasets/search", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to search on datasets: %w", err)
}
@@ -819,7 +786,7 @@ func (c *CLI) SearchOnDatasets(cmd *Command) (ResponseIf, error) {
}
// APICreateAPIKeyCommand creates a new API key
-func (c *CLI) APICreateAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateAPIKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -831,7 +798,7 @@ func (c *CLI) APICreateAPIKeyCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("no authorization")
}
- resp, err := httpClient.Request("POST", "/system/keys", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "POST", "/system/keys", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create key: %w", err)
}
@@ -856,7 +823,7 @@ func (c *CLI) APICreateAPIKeyCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APICreateDatasetCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateDatasetCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -877,7 +844,7 @@ func (c *CLI) APICreateDatasetCommand(cmd *Command) (ResponseIf, error) {
"name": datasetName,
}
- resp, err := httpClient.Request("POST", "/datasets", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/datasets", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create dataset: %w", err)
}
@@ -885,7 +852,7 @@ func (c *CLI) APICreateDatasetCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "create dataset")
}
-func (c *CLI) APICreateAgentCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateAgentCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -897,7 +864,7 @@ func (c *CLI) APICreateAgentCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("no authorization")
}
- resp, err := httpClient.Request("POST", "/agents", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "POST", "/agents", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create agent: %w", err)
}
@@ -922,7 +889,7 @@ func (c *CLI) APICreateAgentCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APICreateChatCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateChatCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -934,7 +901,7 @@ func (c *CLI) APICreateChatCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("no authorization")
}
- resp, err := httpClient.Request("POST", "/chats", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "POST", "/chats", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create chat: %w", err)
}
@@ -959,7 +926,7 @@ func (c *CLI) APICreateChatCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APICreateSearchCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateSearchCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -980,7 +947,7 @@ func (c *CLI) APICreateSearchCommand(cmd *Command) (ResponseIf, error) {
"name": searchName,
}
- resp, err := httpClient.Request("POST", "/searches", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/searches", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create search: %w", err)
}
@@ -1005,7 +972,7 @@ func (c *CLI) APICreateSearchCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APICreateMemoryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APICreateMemoryCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1026,7 +993,7 @@ func (c *CLI) APICreateMemoryCommand(cmd *Command) (ResponseIf, error) {
"name": memoryName,
}
- resp, err := httpClient.Request("POST", "/memories", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/memories", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create memory: %w", err)
}
@@ -1052,13 +1019,13 @@ func (c *CLI) APICreateMemoryCommand(cmd *Command) (ResponseIf, error) {
}
// APIListAPIKeysCommand lists all API keys for the current user
-func (c *CLI) APIListAPIKeysCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListAPIKeysCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("GET", "/system/keys", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/system/keys", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list keys: %w", err)
}
@@ -1067,7 +1034,7 @@ func (c *CLI) APIListAPIKeysCommand(cmd *Command) (ResponseIf, error) {
}
// APIDeleteAPIKeyCommand deletes an API key
-func (c *CLI) APIDeleteAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDeleteAPIKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1077,7 +1044,9 @@ func (c *CLI) APIDeleteAPIKeyCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("key not provided")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", fmt.Sprintf("/system/keys/%s", apiKey), "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "DELETE", fmt.Sprintf("/system/keys/%s", apiKey), "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to delete key: %w", err)
}
@@ -1086,7 +1055,7 @@ func (c *CLI) APIDeleteAPIKeyCommand(cmd *Command) (ResponseIf, error) {
}
// APISetAPIKeyCommand sets the API key after validating it
-func (c *CLI) APISetAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APISetAPIKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1096,42 +1065,44 @@ func (c *CLI) APISetAPIKeyCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("key not provided")
}
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
// Save current token to restore if validation fails
- savedToken := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey
- savedUseAPIToken := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey
+ savedToken := httpClient.APIKey
+ savedUseAPIToken := httpClient.useAPIKey
// Set the new key temporarily for validation
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey = &apiKey
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey = true
+ httpClient.APIKey = &apiKey
+ httpClient.useAPIKey = true
// Validate token by calling list tokens API
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/system/tokens", "api", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/system/tokens", "api", nil, nil)
if err != nil {
// Restore original token on error
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey = savedToken
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey = savedUseAPIToken
+ httpClient.APIKey = savedToken
+ httpClient.useAPIKey = savedUseAPIToken
return nil, fmt.Errorf("failed to validate token: %w", err)
}
if resp.StatusCode != 200 {
// Restore original token on error
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey = savedToken
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey = savedUseAPIToken
+ httpClient.APIKey = savedToken
+ httpClient.useAPIKey = savedUseAPIToken
return nil, fmt.Errorf("token validation failed: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
}
var result CommonResponse
if err = json.Unmarshal(resp.Body, &result); err != nil {
// Restore original token on error
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey = savedToken
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey = savedUseAPIToken
+ httpClient.APIKey = savedToken
+ httpClient.useAPIKey = savedUseAPIToken
return nil, fmt.Errorf("token validation failed: invalid JSON (%w)", err)
}
if result.Code != 0 {
// Restore original token on error
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey = savedToken
- c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].useAPIKey = savedUseAPIToken
+ httpClient.APIKey = savedToken
+ httpClient.useAPIKey = savedUseAPIToken
return nil, fmt.Errorf("token validation failed: %s", result.Message)
}
@@ -1144,13 +1115,15 @@ func (c *CLI) APISetAPIKeyCommand(cmd *Command) (ResponseIf, error) {
}
// APISetVariableCommand sets variable value
-func (c *CLI) APISetVariableCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APISetVariableCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -1167,7 +1140,7 @@ func (c *CLI) APISetVariableCommand(cmd *Command) (ResponseIf, error) {
"var_name": varName,
"var_value": varValue,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PUT", "/system/variables", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "PUT", "/system/variables", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set variable: %w", err)
}
@@ -1190,7 +1163,7 @@ func (c *CLI) APISetVariableCommand(cmd *Command) (ResponseIf, error) {
}
// APIShowVariableCommand displays variable value
-func (c *CLI) APIShowVariableCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIShowVariableCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
@@ -1211,7 +1184,7 @@ func (c *CLI) APIShowVariableCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/system/variables/%s", EncodedVarName)
- resp, err := httpClient.Request("GET", endPoint, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", endPoint, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get variable: %w", err)
}
@@ -1235,7 +1208,7 @@ func (c *CLI) APIShowVariableCommand(cmd *Command) (ResponseIf, error) {
}
// APIShowAPIKeyCommand displays the current API key
-func (c *CLI) APIShowAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIShowAPIKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1255,7 +1228,7 @@ func (c *CLI) APIShowAPIKeyCommand(cmd *Command) (ResponseIf, error) {
}
// APIUnsetAPIKeyCommand removes the current API key
-func (c *CLI) APIUnsetAPIKeyCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIUnsetAPIKeyCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1275,7 +1248,7 @@ func (c *CLI) APIUnsetAPIKeyCommand(cmd *Command) (ResponseIf, error) {
}
// DevCreateChunkStoreCommand creates a chunk store in doc engine
-func (c *CLI) DevCreateChunkStoreCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevCreateChunkStoreCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1301,7 +1274,9 @@ func (c *CLI) DevCreateChunkStoreCommand(cmd *Command) (ResponseIf, error) {
"vector_size": vectorSize,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/tenant/chunk_store", "web", nil, payload)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "POST", "/tenant/chunk_store", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to create chunk store: %w", err)
}
@@ -1332,7 +1307,7 @@ func (c *CLI) DevCreateChunkStoreCommand(cmd *Command) (ResponseIf, error) {
}
// DevDropChunkStoreCommand drops a chunk store in doc engine
-func (c *CLI) DevDropChunkStoreCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevDropChunkStoreCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1352,13 +1327,15 @@ func (c *CLI) DevDropChunkStoreCommand(cmd *Command) (ResponseIf, error) {
"kb_id": datasetID,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", "/tenant/chunk_store", "web", nil, payload)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "DELETE", "/tenant/chunk_store", "web", nil, payload)
if err != nil {
- return nil, fmt.Errorf("failed to drop dataset: %w", err)
+ return nil, fmt.Errorf("failed to drop chunk store: %w", err)
}
if resp.StatusCode != 200 {
- return nil, fmt.Errorf("failed to drop dataset: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
+ return nil, fmt.Errorf("failed to drop chunk store: HTTP %d, body: %s", resp.StatusCode, string(resp.Body))
}
resJSON, err := resp.JSON()
@@ -1383,12 +1360,14 @@ func (c *CLI) DevDropChunkStoreCommand(cmd *Command) (ResponseIf, error) {
}
// DevCreateMetadataStoreCommand creates the document metadata store for the tenant
-func (c *CLI) DevCreateMetadataStoreCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevCreateMetadataStoreCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/tenant/metadata_store", "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "POST", "/tenant/metadata_store", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to create metadata store: %w", err)
}
@@ -1419,12 +1398,14 @@ func (c *CLI) DevCreateMetadataStoreCommand(cmd *Command) (ResponseIf, error) {
}
// DevDropMetadataStoreCommand drops the document metadata store for the tenant
-func (c *CLI) DevDropMetadataStoreCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevDropMetadataStoreCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", "/tenant/metadata_store", "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "DELETE", "/tenant/metadata_store", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop metadata store: %w", err)
}
@@ -1456,7 +1437,7 @@ func (c *CLI) DevDropMetadataStoreCommand(cmd *Command) (ResponseIf, error) {
// APIAddProviderCommand creates a new model provider
// ADD PROVIDER <name>
-func (c *CLI) APIAddProviderCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIAddProviderCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1476,7 +1457,7 @@ func (c *CLI) APIAddProviderCommand(cmd *Command) (ResponseIf, error) {
"provider_name": providerName,
}
- resp, err := httpClient.Request("PUT", "/providers", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "PUT", "/providers", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add provider: %w", err)
}
@@ -1485,12 +1466,14 @@ func (c *CLI) APIAddProviderCommand(cmd *Command) (ResponseIf, error) {
}
// APIListProvidersCommand lists added providers
-func (c *CLI) APIListProvidersCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListProvidersCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/providers", "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "GET", "/providers", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list providers: %w", err)
}
@@ -1500,7 +1483,7 @@ func (c *CLI) APIListProvidersCommand(cmd *Command) (ResponseIf, error) {
// APIDeleteProviderCommand deletes a provider
// DELETE PROVIDER <name>
-func (c *CLI) APIDeleteProviderCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDeleteProviderCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1517,7 +1500,7 @@ func (c *CLI) APIDeleteProviderCommand(cmd *Command) (ResponseIf, error) {
url := fmt.Sprintf("/providers/%s", providerName)
- resp, err := httpClient.Request("DELETE", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "DELETE", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to delete provider: %w", err)
}
@@ -1526,7 +1509,7 @@ func (c *CLI) APIDeleteProviderCommand(cmd *Command) (ResponseIf, error) {
}
// APIDropDatasetCommand DROP DATASET 'dataset_name'
-func (c *CLI) APIDropDatasetCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDropDatasetCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1552,7 +1535,7 @@ func (c *CLI) APIDropDatasetCommand(cmd *Command) (ResponseIf, error) {
"delete_all": true,
}
- resp, err := httpClient.Request("DELETE", "/datasets", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/datasets", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to drop dataset: %w", err)
}
@@ -1561,7 +1544,7 @@ func (c *CLI) APIDropDatasetCommand(cmd *Command) (ResponseIf, error) {
}
// APIDropAgentCommand DROP AGENT 'agent_name'
-func (c *CLI) APIDropAgentCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDropAgentCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1587,7 +1570,7 @@ func (c *CLI) APIDropAgentCommand(cmd *Command) (ResponseIf, error) {
"delete_all": true,
}
- resp, err := httpClient.Request("DELETE", "/agents", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/agents", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to drop agent: %w", err)
}
@@ -1596,7 +1579,7 @@ func (c *CLI) APIDropAgentCommand(cmd *Command) (ResponseIf, error) {
}
// APIDropChatCommand DROP CHAT 'chat_name'
-func (c *CLI) APIDropChatCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDropChatCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1622,7 +1605,7 @@ func (c *CLI) APIDropChatCommand(cmd *Command) (ResponseIf, error) {
"delete_all": true,
}
- resp, err := httpClient.Request("DELETE", "/chats", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/chats", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to drop chat: %w", err)
}
@@ -1631,7 +1614,7 @@ func (c *CLI) APIDropChatCommand(cmd *Command) (ResponseIf, error) {
}
// APIDropSearchCommand DROP SEARCH 'search_name'
-func (c *CLI) APIDropSearchCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDropSearchCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1654,7 +1637,7 @@ func (c *CLI) APIDropSearchCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/searches/%s", searchID)
- resp, err := httpClient.Request("DELETE", endPoint, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "DELETE", endPoint, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop search: %w", err)
}
@@ -1663,7 +1646,7 @@ func (c *CLI) APIDropSearchCommand(cmd *Command) (ResponseIf, error) {
}
// APIDropMemoryCommand DROP MEMORY 'memory_name'
-func (c *CLI) APIDropMemoryCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIDropMemoryCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1686,7 +1669,7 @@ func (c *CLI) APIDropMemoryCommand(cmd *Command) (ResponseIf, error) {
endPoint := fmt.Sprintf("/memories/%s", memoryID)
- resp, err := httpClient.Request("DELETE", endPoint, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "DELETE", endPoint, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to drop memory: %w", err)
}
@@ -1696,7 +1679,7 @@ func (c *CLI) APIDropMemoryCommand(cmd *Command) (ResponseIf, error) {
// APIAddProviderInstanceCommand creates a new provider instance
// CREATE PROVIDER <name> INSTANCE <instance_name> KEY <api_key> URL <base_url> REGION <region>
-func (c *CLI) APIAddProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIAddProviderInstanceCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1740,7 +1723,7 @@ func (c *CLI) APIAddProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
"region": region,
}
- resp, err := httpClient.Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add provider instance: %w", err)
}
@@ -1748,8 +1731,8 @@ func (c *CLI) APIAddProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "add provider instance")
}
-// DELETE PROVIDER <name> INSTANCE <name>
-func (c *CLI) APIDeleteProviderInstanceCommand(cmd *Command) (ResponseIf, error) {
+// APIDeleteProviderInstanceCommand DELETE PROVIDER <provider_name> INSTANCE <instance_name>
+func (c *CLI) APIDeleteProviderInstanceCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1770,7 +1753,9 @@ func (c *CLI) APIDeleteProviderInstanceCommand(cmd *Command) (ResponseIf, error)
url := fmt.Sprintf("/providers/%s/instances", providerName)
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", url, "web", nil, payload)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "DELETE", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to drop provider instance: %w", err)
}
@@ -1778,8 +1763,8 @@ func (c *CLI) APIDeleteProviderInstanceCommand(cmd *Command) (ResponseIf, error)
return HandleSimpleResponse(resp, "drop provider instance")
}
-// DELETE PROVIDER <name> INSTANCE <instance_name> MODELS <name1 name2 name3>
-func (c *CLI) APIDeleteProviderInstanceModelCommand(cmd *Command) (ResponseIf, error) {
+// APIDeleteProviderInstanceModelCommand DELETE PROVIDER <name> INSTANCE <instance_name> MODELS <name1 name2 name3>
+func (c *CLI) APIDeleteProviderInstanceModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -1805,7 +1790,9 @@ func (c *CLI) APIDeleteProviderInstanceModelCommand(cmd *Command) (ResponseIf, e
url := fmt.Sprintf("/providers/%s/instances/%s/models", providerName, instanceName)
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", url, "web", nil, payload)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "DELETE", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to delete model: %w", err)
}
@@ -1821,7 +1808,7 @@ func isValidURL(str string) bool {
return u.Scheme != "" && u.Host != ""
}
-func (c *CLI) APIChatToModelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIChatToModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -2068,7 +2055,9 @@ func (c *CLI) APIChatToModelCommand(cmd *Command) (ResponseIf, error) {
return result, nil
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, formatRequestError("Chat request", err)
}
@@ -2089,8 +2078,9 @@ func (c *CLI) APIChatToModelCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) EmbedUserTextCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) EmbedUserTextCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2154,7 +2144,7 @@ func (c *CLI) EmbedUserTextCommand(cmd *Command) (ResponseIf, error) {
url := "/embeddings"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to embed text: %w", err)
}
@@ -2172,8 +2162,11 @@ func (c *CLI) EmbedUserTextCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIRerankUserDocumentCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIRerankUserDocumentCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2243,7 +2236,7 @@ func (c *CLI) APIRerankUserDocumentCommand(cmd *Command) (ResponseIf, error) {
url := "/rerank"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to rerank document: %w", err)
}
@@ -2251,8 +2244,10 @@ func (c *CLI) APIRerankUserDocumentCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "rerank document")
}
-func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APITTSUserCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2361,7 +2356,7 @@ func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
url := "/audio/speech"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to TTS document: %w", err)
}
@@ -2406,13 +2401,13 @@ func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
}
localPath := filepath.Join(cwd, fileName)
- if err := os.WriteFile(localPath, audioBytes, 0644); err != nil {
+ if err = os.WriteFile(localPath, audioBytes, 0644); err != nil {
return nil, fmt.Errorf("failed to write local audio file: %w", err)
}
if shouldPlay {
cmdExec := exec.Command("aplay", localPath)
- if err := cmdExec.Run(); err != nil {
+ if err = cmdExec.Run(); err != nil {
fmt.Printf("Play error: %v (Hint: did you use 'format: wav' in your params?)\n", err)
}
}
@@ -2427,12 +2422,12 @@ func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
saveDir = absSaveDir
}
- if err := os.MkdirAll(saveDir, 0755); err != nil {
+ if err = os.MkdirAll(saveDir, 0755); err != nil {
return nil, fmt.Errorf("failed to create save directory: %w", err)
}
finalPath := filepath.Join(saveDir, fileName)
- if err := os.WriteFile(finalPath, audioBytes, 0644); err != nil {
+ if err = os.WriteFile(finalPath, audioBytes, 0644); err != nil {
return nil, fmt.Errorf("failed to save file to target directory: %w", err)
}
@@ -2459,8 +2454,9 @@ func (c *CLI) APITTSUserCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIASRUserCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIASRUserCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2532,7 +2528,7 @@ func (c *CLI) APIASRUserCommand(cmd *Command) (ResponseIf, error) {
url := "/audio/transcriptions"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to ASR document: %w", err)
}
@@ -2563,8 +2559,9 @@ func (c *CLI) APIASRUserCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIOCRUserCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIOCRUserCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2640,15 +2637,16 @@ func (c *CLI) APIOCRUserCommand(cmd *Command) (ResponseIf, error) {
url := "/file/ocr"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to OCR document: %w", err)
}
return HandleCommonDataResponse(resp, "OCR document")
}
-func (c *CLI) APIModelParseFileCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIModelParseFileCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2730,7 +2728,7 @@ func (c *CLI) APIModelParseFileCommand(cmd *Command) (ResponseIf, error) {
url := "/file/parse"
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to PARSE document: %w", err)
}
@@ -2738,8 +2736,9 @@ func (c *CLI) APIModelParseFileCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonDataResponse(resp, "PARSE document")
}
-func (c *CLI) APIListModelInstanceTasksCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIListModelInstanceTasksCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2759,7 +2758,7 @@ func (c *CLI) APIListModelInstanceTasksCommand(cmd *Command) (ResponseIf, error)
url := fmt.Sprintf("/providers/%s/instances/%s/tasks", providerName, instanceName)
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list model parsing tasks: %w", err)
}
@@ -2768,7 +2767,7 @@ func (c *CLI) APIListModelInstanceTasksCommand(cmd *Command) (ResponseIf, error)
}
// APIShowProviderInstanceTaskCommand shows the details of a task
-func (c *CLI) APIShowProviderInstanceTaskCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIShowProviderInstanceTaskCommand(commandCount int, cmd *Command) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
if httpClient.APIKey == nil && httpClient.LoginToken == nil {
@@ -2796,7 +2795,7 @@ func (c *CLI) APIShowProviderInstanceTaskCommand(cmd *Command) (ResponseIf, erro
url := fmt.Sprintf("/providers/%s/instances/%s/tasks/%s", providerName, instanceName, taskID)
- resp, err := httpClient.Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get task: %w", err)
}
@@ -2815,8 +2814,9 @@ func (c *CLI) APIShowProviderInstanceTaskCommand(cmd *Command) (ResponseIf, erro
}
// APIUseModelCommand sets the current model for chat
-func (c *CLI) APIUseModelCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIUseModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
if c.Config.CLIMode != APIMode {
@@ -2855,8 +2855,9 @@ func (c *CLI) APIUseModelCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIAddCustomModelCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIAddCustomModelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -2887,7 +2888,7 @@ func (c *CLI) APIAddCustomModelCommand(cmd *Command) (ResponseIf, error) {
"models": models,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to add custom model: %w", err)
}
@@ -2896,7 +2897,8 @@ func (c *CLI) APIAddCustomModelCommand(cmd *Command) (ResponseIf, error) {
}
// DevUpdateChunkCommand updates a chunk in a dataset
-func (c *CLI) DevUpdateChunkCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevUpdateChunkCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -2938,7 +2940,7 @@ func (c *CLI) DevUpdateChunkCommand(cmd *Command) (ResponseIf, error) {
payload["document_id"] = docID
payload["chunk_id"] = chunkID
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/chunk/update", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/chunk/update", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to update chunk: %w", err)
}
@@ -2969,7 +2971,7 @@ func (c *CLI) DevUpdateChunkCommand(cmd *Command) (ResponseIf, error) {
}
// DevGetChunkCommand retrieves a chunk by ID
-func (c *CLI) DevGetChunkCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevGetChunkCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -2989,7 +2991,8 @@ func (c *CLI) DevGetChunkCommand(cmd *Command) (ResponseIf, error) {
return nil, fmt.Errorf("dataset_id not provided")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", fmt.Sprintf("/datasets/%s/documents/%s/chunks/%s", datasetID, docID, chunkID), "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ resp, err := httpClient.Request(commandCount, "GET", fmt.Sprintf("/datasets/%s/documents/%s/chunks/%s", datasetID, docID, chunkID), "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get chunk: %w", err)
}
@@ -3012,11 +3015,13 @@ func (c *CLI) DevGetChunkCommand(cmd *Command) (ResponseIf, error) {
}
// DevSetMetaCommand sets metadata for a document
-func (c *CLI) DevSetMetaCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevSetMetaCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
docID, ok := cmd.Params["doc_id"].(string)
if !ok {
return nil, fmt.Errorf("doc_id not provided")
@@ -3032,7 +3037,7 @@ func (c *CLI) DevSetMetaCommand(cmd *Command) (ResponseIf, error) {
"meta": metaJSON,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/document/dev_set_meta", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/document/dev_set_meta", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to set metadata: %w", err)
}
@@ -3064,11 +3069,13 @@ func (c *CLI) DevSetMetaCommand(cmd *Command) (ResponseIf, error) {
// DevDeleteMetaCommand deletes metadata for a document
// If keys is provided, deletes specific keys; otherwise deletes entire document metadata
-func (c *CLI) DevDeleteMetaCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevDeleteMetaCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
docID, ok := cmd.Params["doc_id"].(string)
if !ok {
return nil, fmt.Errorf("doc_id not provided")
@@ -3083,7 +3090,7 @@ func (c *CLI) DevDeleteMetaCommand(cmd *Command) (ResponseIf, error) {
payload["keys"] = keysJSON
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", "/document/dev_delete_meta", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", "/document/dev_delete_meta", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to delete metadata: %w", err)
}
@@ -3114,11 +3121,13 @@ func (c *CLI) DevDeleteMetaCommand(cmd *Command) (ResponseIf, error) {
}
// DevRmTagsCommand removes tags from chunks in a dataset
-func (c *CLI) DevRmTagsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevRmTagsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
datasetName, ok := cmd.Params["dataset_name"].(string)
if !ok {
return nil, fmt.Errorf("dataset_name not provided")
@@ -3138,7 +3147,7 @@ func (c *CLI) DevRmTagsCommand(cmd *Command) (ResponseIf, error) {
"tags": tags,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", "/datasets/"+kbID+"/tags", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/datasets/"+kbID+"/tags", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove tags: %w", err)
}
@@ -3169,11 +3178,13 @@ func (c *CLI) DevRmTagsCommand(cmd *Command) (ResponseIf, error) {
}
// DevRemoveChunksCommand removes chunks from a document
-func (c *CLI) DevRemoveChunksCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevRemoveChunksCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
datasetName, ok := cmd.Params["dataset_name"].(string)
if !ok {
return nil, fmt.Errorf("dataset_name not provided")
@@ -3199,7 +3210,7 @@ func (c *CLI) DevRemoveChunksCommand(cmd *Command) (ResponseIf, error) {
payload["chunk_ids"] = chunkIDs
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", "/datasets/"+datasetID+"/documents/"+docID+"/chunks", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/datasets/"+datasetID+"/documents/"+docID+"/chunks", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove chunks: %w", err)
}
@@ -3239,8 +3250,9 @@ func (c *CLI) DevRemoveChunksCommand(cmd *Command) (ResponseIf, error) {
return &result, nil
}
-func (c *CLI) APIParseDocumentsCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIParseDocumentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3265,7 +3277,7 @@ func (c *CLI) APIParseDocumentsCommand(cmd *Command) (ResponseIf, error) {
}
// Normal mode
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to parse documents: %w", err)
}
@@ -3273,7 +3285,7 @@ func (c *CLI) APIParseDocumentsCommand(cmd *Command) (ResponseIf, error) {
return HandleSimpleResponse(resp, "parse documents")
}
-func (c *CLI) APIParseLocalFileCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIParseLocalFileCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -3354,8 +3366,9 @@ func formatRequestError(action string, err error) error {
}
}
-func (c *CLI) APIListIngestionTasks(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIListIngestionTasks(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3372,7 +3385,7 @@ func (c *CLI) APIListIngestionTasks(cmd *Command) (ResponseIf, error) {
"dataset_id": datasetID,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/datasets/ingestion/tasks", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "GET", "/datasets/ingestion/tasks", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to list ingestion tasks: %w", err)
}
@@ -3384,8 +3397,9 @@ func (c *CLI) APIListIngestionTasks(cmd *Command) (ResponseIf, error) {
// LIST SYNC_LOGS; lists the sync logs of all datasets.
// LIST SYNC_LOGS FROM 'dataset_id'; and LIST DATASET 'dataset_name' SYNC_LOGS;
// restrict the listing to one dataset.
-func (c *CLI) APIListSyncLogsCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIListSyncLogsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3428,7 +3442,7 @@ func (c *CLI) APIListSyncLogsCommand(cmd *Command) (ResponseIf, error) {
url += "?" + encoded
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", url, "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", url, "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list sync logs: %w", err)
}
@@ -3451,12 +3465,14 @@ func (c *CLI) APIListSyncLogsCommand(cmd *Command) (ResponseIf, error) {
}
// APIShowLogLevelCommand sets the log level for the system.
-func (c *CLI) APIShowLogLevelCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIShowLogLevelCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/system/config/log", "web", nil, nil)
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+
+ resp, err := httpClient.Request(commandCount, "GET", "/system/config/log", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to get log level config: %w", err)
}
@@ -3466,16 +3482,17 @@ func (c *CLI) APIShowLogLevelCommand(cmd *Command) (ResponseIf, error) {
}
// APIListEnvironmentsCommand lists all system environments (api mode only).
-func (c *CLI) APIListEnvironmentsCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListEnvironmentsCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/system/environments", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/system/environments", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list environments: %w", err)
}
@@ -3484,16 +3501,17 @@ func (c *CLI) APIListEnvironmentsCommand(cmd *Command) (ResponseIf, error) {
}
// APIListVariablesCommand lists all system variables (api mode only).
-func (c *CLI) APIListVariablesCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIListVariablesCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("GET", "/system/variables", "web", nil, nil)
+ resp, err := httpClient.Request(commandCount, "GET", "/system/variables", "web", nil, nil)
if err != nil {
return nil, fmt.Errorf("failed to list variables: %w", err)
}
@@ -3501,8 +3519,9 @@ func (c *CLI) APIListVariablesCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "list variables")
}
-func (c *CLI) APIStartIngestionCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIStartIngestionCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3527,7 +3546,7 @@ func (c *CLI) APIStartIngestionCommand(cmd *Command) (ResponseIf, error) {
url := fmt.Sprintf("/datasets/%s/documents/parse", datasetID)
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("POST", url, "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "POST", url, "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to ingest file: %w", err)
}
@@ -3535,8 +3554,9 @@ func (c *CLI) APIStartIngestionCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "ingest file")
}
-func (c *CLI) APIStopIngestionCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIStopIngestionCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3552,7 +3572,7 @@ func (c *CLI) APIStopIngestionCommand(cmd *Command) (ResponseIf, error) {
"tasks": tasks,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("PUT", "/datasets/ingestion/tasks", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "PUT", "/datasets/ingestion/tasks", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to stop ingestion: %w", err)
}
@@ -3560,8 +3580,9 @@ func (c *CLI) APIStopIngestionCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "stop ingestion")
}
-func (c *CLI) APIRemoveTaskCommand(cmd *Command) (ResponseIf, error) {
- if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey == nil && c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken == nil {
+func (c *CLI) APIRemoveTaskCommand(commandCount int, cmd *Command) (ResponseIf, error) {
+ httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
+ if httpClient.APIKey == nil && httpClient.LoginToken == nil {
return nil, fmt.Errorf("API key not set. Please login first")
}
@@ -3578,7 +3599,7 @@ func (c *CLI) APIRemoveTaskCommand(cmd *Command) (ResponseIf, error) {
"tasks": tasks,
}
- resp, err := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].Request("DELETE", "/datasets/ingestion/tasks", "web", nil, payload)
+ resp, err := httpClient.Request(commandCount, "DELETE", "/datasets/ingestion/tasks", "web", nil, payload)
if err != nil {
return nil, fmt.Errorf("failed to remove tasks: %w", err)
}
@@ -3590,7 +3611,7 @@ func (c *CLI) APIRemoveTaskCommand(cmd *Command) (ResponseIf, error) {
return HandleCommonResponse(resp, "remove tasks")
}
-func (c *CLI) DevChunkCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) DevChunkCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("this command is only allowed in USER mode")
}
@@ -3669,7 +3690,7 @@ func explainChunkOptions(options chunk.ChunkOptions) (string, error) {
// APIOpenaiChatCommand dispatches the parsed OPENAI_CHAT command to either a
// non-streaming oneshot call or a streaming SSE call, depending on the
// `stream` option.
-func (c *CLI) APIOpenaiChatCommand(cmd *Command) (ResponseIf, error) {
+func (c *CLI) APIOpenaiChatCommand(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("OPENAI_CHAT is only allowed in USER mode")
}
@@ -3872,7 +3893,7 @@ func buildOpenaiChatRequestBody(cmd *Command) (map[string]interface{}, error) {
// same HTTPClient.Request used by every other CLI command.
func (c *CLI) oneshotOpenaiChat(url string, body map[string]interface{}) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("POST", url, "web", nil, body)
+ resp, err := httpClient.Request(1, "POST", url, "web", nil, body)
if err != nil {
return nil, fmt.Errorf("openai_chat request: %w", err)
}
@@ -3917,7 +3938,7 @@ func (c *CLI) oneshotOpenaiChat(url string, body map[string]interface{}) (Respon
// stdout as they arrive
func (c *CLI) streamOpenaiChat(url string, body map[string]interface{}) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("POST", url, "web", nil, body)
+ resp, err := httpClient.Request(1, "POST", url, "web", nil, body)
if err != nil {
return nil, fmt.Errorf("openai_chat stream: %w", err)
}
@@ -3987,7 +4008,7 @@ func (c *CLI) streamOpenaiChat(url string, body map[string]interface{}) (Respons
// ChatCompletions dispatches the parsed CHAT COMPLETIONS command to
// POST /api/v1/chat/completions.
-func (c *CLI) ChatCompletions(cmd *Command) (ResponseIf, error) {
+func (c *CLI) ChatCompletions(commandCount int, cmd *Command) (ResponseIf, error) {
if c.Config.CLIMode != APIMode {
return nil, fmt.Errorf("CHAT COMPLETIONS is only allowed in USER mode")
}
@@ -4092,7 +4113,7 @@ func buildChatCompletionsRequestBody(cmd *Command) (map[string]interface{}, erro
// ChatCompletionsResponse parsed from the RAGFlow-internal JSON envelope.
func (c *CLI) oneshotChatCompletions(url string, body map[string]interface{}) (ResponseIf, error) {
httpClient := c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer]
- resp, err := httpClient.Request("POST", url, "web", nil, body)
+ resp, err := httpClient.Request(1, "POST", url, "web", nil, body)
if err != nil {
return nil, fmt.Errorf("chat completions request: %w", err)
}
diff --git a/internal/cli/user_parser.go b/internal/cli/user_parser.go
index 8bbd74498b..af74729a67 100644
--- a/internal/cli/user_parser.go
+++ b/internal/cli/user_parser.go
@@ -264,7 +264,7 @@ func (p *Parser) parseAPIListSyncLogs() (*Command, error) {
p.nextToken() // move past the dataset id
}
- if err := p.parseSyncLogsWithOptions(cmd); err != nil {
+ if err := p.parseSyncLogsWithOptions(1, cmd); err != nil {
return nil, err
}
@@ -282,7 +282,7 @@ func (p *Parser) parseAPIListDatasetSyncLogs(datasetName string) (*Command, erro
cmd := NewCommand("api_list_sync_logs")
cmd.Params["dataset_name"] = datasetName
- if err := p.parseSyncLogsWithOptions(cmd); err != nil {
+ if err := p.parseSyncLogsWithOptions(1, cmd); err != nil {
return nil, err
}
@@ -296,7 +296,7 @@ func (p *Parser) parseAPIListDatasetSyncLogs(datasetName string) (*Command, erro
// parseSyncLogsWithOptions parses the optional WITH clause of the sync logs
// listing commands. Only PAGE and PAGE_SIZE are accepted, both as integers,
// mirroring the search command's space-separated WITH syntax.
-func (p *Parser) parseSyncLogsWithOptions(cmd *Command) error {
+func (p *Parser) parseSyncLogsWithOptions(commandCount int, cmd *Command) error {
if p.curToken.Type != TokenWith && !(p.curToken.Type == TokenIdentifier && strings.EqualFold(p.curToken.Value, "with")) {
return nil
}