Skip to content

Go CLI: fix list provider instance tasks - #16345

Merged
JinHai-CN merged 6 commits into
infiniflow:mainfrom
JinHai-CN:fix493
Jun 25, 2026
Merged

JinHai-CN merged 6 commits into
infiniflow:mainfrom
JinHai-CN:fix493

Conversation

@JinHai-CN

@JinHai-CN JinHai-CN commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

What problem does this PR solve?

RAGFlow(api/default)> list provider 'gitee' instance 'test' tasks;

RAGFlow(api/default)> set key 'ragflow-JgnarFSCUiV99oOvvMDei7ZzZg1cVlqGd1AMHrHeKE4';
SUCCESS
RAGFlow(api/default)> show key;
+-------+-----------------------------------------------------+
| field | value                                               |
+-------+-----------------------------------------------------+
| token | ragflow-JgnarFSCUiV99oOvvMDei7ZzZg1cVlqGd1AMHrHeKE4 |
+-------+-----------------------------------------------------+

RAGFlow(admin)> show api server 'default';
+-----------------+-----------+
| field           | value     |
+-----------------+-----------+
| api_server      | default   |
| api_server_ip   | 127.0.0.1 |
| api_server_port | 9384      |
| auth            | unknown   |
+-----------------+-----------+

RAGFlow(api/default)> save config as 'abc';
CLI error: save server config isn't implemented

Type of change

  • Refactoring

@coderabbitai

coderabbitai Bot commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The CLI now parses API-specific list, show, and use commands in admin and user modes, routes them through renamed command handlers, and updates several shared helper responses and error paths.

Changes

CLI API command routing

Layer / File(s) Summary
User API parser
internal/cli/parser.go, internal/cli/user_parser.go
User-mode parsing now routes SHOW, LIST API, provider-instance TASKS, and related API list/show forms through API-specific helpers, while removing legacy list helpers.
Admin API parser
internal/cli/admin_parser.go
Admin-mode parsing now recognizes LIST API SERVER and USE API / USE ADMIN forms and emits the matching admin command names.
Handler entry points and dispatch
internal/cli/common_command.go, internal/cli/cli_http.go, internal/cli/user_command.go
The dispatcher now calls renamed Common* and API* handler methods for the updated admin and user command types.
Shared CLI behavior
internal/cli/common_command.go, internal/cli/user_command.go
Server-info auth output, server-config errors, dataset lookup type checking, API-key output, and provider-instance task parameter parsing are updated.

Sequence Diagram(s)

sequenceDiagram
  participant CLIInput
  participant parseAdminUseCommand
  participant ExecuteAdminCommand
  participant CommonUseAPIServerCommand
  CLIInput->>parseAdminUseCommand: USE API "server_name"
  parseAdminUseCommand->>ExecuteAdminCommand: admin_use_api_server
  ExecuteAdminCommand->>CommonUseAPIServerCommand: dispatch admin_use_api_server
  CommonUseAPIServerCommand-->>ExecuteAdminCommand: ResponseIf
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • infiniflow/ragflow#15861 — Updates the same admin USE API / USE ADMIN parsing and dispatch paths in internal/cli/admin_parser.go and internal/cli/cli_http.go.
  • infiniflow/ragflow#16213 — Touches the shared CLI dispatch/handler layer around Common* command renames that this PR extends.
  • infiniflow/ragflow#16306 — Changes the same API-key and API list command routing paths in user_parser.go, cli_http.go, and user_command.go.

Suggested labels

🐞 bug

Poem

A rabbit tapped the keys by moonlit glow,
And told the CLI, “hop this way, let’s go.”
API carrots lined the path so neat,
From parser to handler, every hop complete.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change by focusing on the provider instance tasks CLI fix and stays concise.
Description check ✅ Passed The description includes the required problem statement and type-of-change section, with enough context to understand the CLI behavior changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jun 25, 2026
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 25, 2026 07:03
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ☯️ refactor Pull request that refactor/refine code labels Jun 25, 2026
@JinHai-CN
JinHai-CN marked this pull request as draft June 25, 2026 07:03
@JinHai-CN
JinHai-CN marked this pull request as ready for review June 25, 2026 07:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
internal/cli/user_parser.go (1)

396-413: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Fix the double-consumption of MODELS.

parseListProviderInstanceCommands calls this helper while curToken is already TokenModels; after Line 408 advances, Lines 410-413 reject valid LIST PROVIDER ... INSTANCE ... MODELS commands.

Proposed fix
 func (p *Parser) parseListProviderInstanceModels(providerName, instanceName string) (*Command, error) {
 	p.nextToken() // consume MODELS
 
-	if p.curToken.Type != TokenModels {
-		return nil, fmt.Errorf("expected MODELS")
-	}
-	p.nextToken()
-
 	cmd := NewCommand("api_list_provider_instance_models")
 	if p.curToken.Type == TokenSync {
 		cmd = NewCommand("api_list_provider_instance_models_sync")
+		p.nextToken() // consume SYNC
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/user_parser.go` around lines 396 - 413, The LIST parser is
consuming MODELS twice: parseListProviderInstanceCommands already dispatches to
parseListProviderInstanceModels when curToken is TokenModels, so remove the
extra token advance/check in parseListProviderInstanceModels and let it continue
parsing from the current MODELS token. Update the helper to resume with the next
expected token after MODELS, preserving valid LIST PROVIDER ... INSTANCE ...
MODELS commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/cli/common_command.go`:
- Around line 1367-1376: The auth value is being derived from CurrentAPIServer
instead of the requested serverName, so SHOW API SERVER can report the wrong
credentials state. Update the auth population logic in common command handling
to look up the target server using serverName and then read its client entry
from APIServerClientMap, while keeping the existing "unknown"/"login"/"api
key"/"no auth" cases intact. Use the serverName and APIServerClientMap
references to locate the affected branch.

---

Outside diff comments:
In `@internal/cli/user_parser.go`:
- Around line 396-413: The LIST parser is consuming MODELS twice:
parseListProviderInstanceCommands already dispatches to
parseListProviderInstanceModels when curToken is TokenModels, so remove the
extra token advance/check in parseListProviderInstanceModels and let it continue
parsing from the current MODELS token. Update the helper to resume with the next
expected token after MODELS, preserving valid LIST PROVIDER ... INSTANCE ...
MODELS commands.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 96a171f7-b831-49e0-9e5a-4f7255592808

📥 Commits

Reviewing files that changed from the base of the PR and between 3f3a2ec and 4102b27.

📒 Files selected for processing (6)
  • internal/cli/admin_parser.go
  • internal/cli/cli_http.go
  • internal/cli/common_command.go
  • internal/cli/parser.go
  • internal/cli/user_command.go
  • internal/cli/user_parser.go

Comment on lines +1367 to +1376
if c.Config.APIClientConfig.CurrentAPIServer == "" {
result.Data["auth"] = "unknown"
} else {
result.Data["auth"] = "no auth"
if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil {
result.Data["auth"] = "login"
} else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil {
result.Data["auth"] = "api key"
} else {
result.Data["auth"] = "no auth"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use serverName when populating auth.

Line 1367 derives auth from CurrentAPIServer, so SHOW API SERVER "<name>" can report the current server's credentials—or "unknown" in admin mode—instead of the server requested by serverName.

Suggested fix
-		if c.Config.APIClientConfig.CurrentAPIServer == "" {
-			result.Data["auth"] = "unknown"
-		} else {
-			if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil {
-				result.Data["auth"] = "login"
-			} else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil {
-				result.Data["auth"] = "api key"
-			} else {
-				result.Data["auth"] = "no auth"
-			}
-		}
+		if httpClient, ok := c.APIServerClientMap[serverName]; !ok || httpClient == nil {
+			result.Data["auth"] = "unknown"
+		} else if httpClient.LoginToken != nil {
+			result.Data["auth"] = "login"
+		} else if httpClient.APIKey != nil {
+			result.Data["auth"] = "api key"
+		} else {
+			result.Data["auth"] = "no auth"
+		}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if c.Config.APIClientConfig.CurrentAPIServer == "" {
result.Data["auth"] = "unknown"
} else {
result.Data["auth"] = "no auth"
if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].LoginToken != nil {
result.Data["auth"] = "login"
} else if c.APIServerClientMap[c.Config.APIClientConfig.CurrentAPIServer].APIKey != nil {
result.Data["auth"] = "api key"
} else {
result.Data["auth"] = "no auth"
}
if httpClient, ok := c.APIServerClientMap[serverName]; !ok || httpClient == nil {
result.Data["auth"] = "unknown"
} else if httpClient.LoginToken != nil {
result.Data["auth"] = "login"
} else if httpClient.APIKey != nil {
result.Data["auth"] = "api key"
} else {
result.Data["auth"] = "no auth"
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/cli/common_command.go` around lines 1367 - 1376, The auth value is
being derived from CurrentAPIServer instead of the requested serverName, so SHOW
API SERVER can report the wrong credentials state. Update the auth population
logic in common command handling to look up the target server using serverName
and then read its client entry from APIServerClientMap, while keeping the
existing "unknown"/"login"/"api key"/"no auth" cases intact. Use the serverName
and APIServerClientMap references to locate the affected branch.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (06d45c5) to head (4102b27).
⚠️ Report is 15 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16345   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit edfa9be into infiniflow:main Jun 25, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration ☯️ refactor Pull request that refactor/refine code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant