diff --git a/internal/cli/cli_http.go b/internal/cli/cli_http.go index a760616fb0..7e53b4b5cc 100644 --- a/internal/cli/cli_http.go +++ b/internal/cli/cli_http.go @@ -301,6 +301,8 @@ func (c *CLI) ExecuteUserCommand(cmd *Command) (ResponseIf, error) { return c.APIListDatasetsCommand(cmd) case "api_list_dataset_documents": return c.APIListDatasetDocumentsCommand(cmd) + case "api_list_dataset_files": + return c.APIListDatasetFilesCommand(cmd) case "api_list_agents": return c.APIListAgentsCommand(cmd) case "api_list_chats": diff --git a/internal/cli/common_command.go b/internal/cli/common_command.go index 4d59c0895d..1da1f202f2 100644 --- a/internal/cli/common_command.go +++ b/internal/cli/common_command.go @@ -1583,3 +1583,17 @@ func (c *CLI) UseAdminServer(cmd *Command) (ResponseIf, error) { result.Duration = 0 return &result, nil } + +func (c *CLI) getDatasetIDByName(datasetName string) (string, error) { + response, err := c.APIListDatasetsCommand(nil) + if err != nil { + return "", err + } + commonResponse := response.(*CommonResponse) + for _, dataset := range commonResponse.Data { + if dataset["name"] == datasetName { + return dataset["id"].(string), nil + } + } + return "", fmt.Errorf("dataset %s not found", datasetName) +} diff --git a/internal/cli/user_command.go b/internal/cli/user_command.go index 97b04a8193..20d24ad834 100644 --- a/internal/cli/user_command.go +++ b/internal/cli/user_command.go @@ -336,12 +336,6 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) { 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 @@ -358,11 +352,6 @@ func (c *CLI) APIListDatasetsCommand(cmd *Command) (ResponseIf, error) { authKind = "web" } - if iterations > 1 { - // Benchmark mode - return raw result for benchmark stats - return httpClient.RequestWithIterations("GET", "/datasets", authKind, nil, nil, iterations) - } - // Normal mode resp, err := httpClient.Request("GET", "/datasets", authKind, nil, nil) if err != nil { @@ -431,6 +420,52 @@ func (c *CLI) APIListDatasetDocumentsCommand(cmd *Command) (ResponseIf, error) { return &result, nil } +func (c *CLI) APIListDatasetFilesCommand(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] + // Determine auth kind based on whether API key is being used + if httpClient.LoginToken == nil && !httpClient.useAPIKey { + return nil, fmt.Errorf("no authorization") + } + + datasetName, ok := cmd.Params["dataset_name"].(string) + if !ok { + return nil, fmt.Errorf("no dataset name") + } + + datasetID, err := c.getDatasetIDByName(datasetName) + if err != nil { + return nil, fmt.Errorf("failed to get dataset id: %w", err) + } + + url := fmt.Sprintf("/datasets/%s/documents", datasetID) + + // Normal mode + resp, err := httpClient.Request("GET", url, "web", nil, nil) + if err != nil { + return nil, fmt.Errorf("failed to list documents: %w", err) + } + + if resp.StatusCode != 200 { + return nil, fmt.Errorf("failed to list documents: HTTP %d, body: %s", resp.StatusCode, string(resp.Body)) + } + + var result ListDocumentsResponse + if err = json.Unmarshal(resp.Body, &result); err != nil { + return nil, fmt.Errorf("list documents failed: invalid JSON (%w)", err) + } + + if result.Code != 0 { + return nil, fmt.Errorf("%s", result.Message) + } + result.Duration = resp.Duration + + return &result, nil +} + // APIListAgentsCommand lists agents func (c *CLI) APIListAgentsCommand(cmd *Command) (ResponseIf, error) { if c.Config.CLIMode != APIMode { diff --git a/internal/handler/document.go b/internal/handler/document.go index ce69207f8c..d77d24d0cb 100644 --- a/internal/handler/document.go +++ b/internal/handler/document.go @@ -483,7 +483,6 @@ func (h *DocumentHandler) BatchUpdateDocumentStatus(c *gin.Context) { } // ListDocuments document list - func (h *DocumentHandler) ListDocuments(c *gin.Context) { datasetID := c.Param("dataset_id")