Skip to content

feat: implement GET /api/v1/agents/<agent_id>/versions/<version_id> API - #15640

Merged
yingfeng merged 12 commits into
infiniflow:mainfrom
xugangqiang:feat/go-agent-version-detail
Jun 4, 2026
Merged

yingfeng merged 12 commits into
infiniflow:mainfrom
xugangqiang:feat/go-agent-version-detail

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

Summary

Implement the GET /api/v1/agents/<agent_id>/versions/<version_id> endpoint in Go, returning full version details including DSL.

Depends on #15629 which introduced the version list endpoint and UserCanvasVersionDAO infrastructure.

Changes

  • Modified: internal/handler/agent.go — Added GetAgentVersion handler with auth check and ownership verification
  • Modified: internal/router/router.go — Registered GET /:agent_id/versions/:version_id route
  • New/Modified tests: Service and handler tests for the version detail endpoint

Testing

=== RUN   TestGetVersion_Success       --- PASS
=== RUN   TestGetVersion_WrongCanvas   --- PASS
=== RUN   TestGetVersion_NotFound      --- PASS
=== RUN   TestGetAgentVersionHandler_Success      --- PASS
=== RUN   TestGetAgentVersionHandler_VersionNotFound --- PASS

Co-Authored-By: Claude Opus 4.8 [email protected]

xugangqiang and others added 7 commits June 4, 2026 12:04
- Add UserCanvasVersionDAO with ListByCanvasID and GetByID
- Add CheckCanvasAccess, ListVersions, GetVersion to AgentService
- Add ListAgentVersions handler with auth check
- Register route GET /api/v1/agents/:agent_id/versions
- Add service-level tests (5 test cases, zero mock)
- Add handler-level tests (3 test cases, SQLite in-memory DB)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Add Select(...) to ListByCanvasID to only return metadata fields
- Add gin.Logger() middleware for request debugging
- Register migrated agent endpoints in vite hybrid proxy config
- Fix test compilation issues

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Add Select(...) to ListByCanvasID to only return metadata fields
- Add gin.Logger() middleware for request debugging
- Register migrated agent endpoints in vite hybrid proxy config
- Fix test compilation issues

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Before this fix, any tenant member whose tenant ID matched
canvas.UserID could access the canvas, even if the canvas
had permission="me" (private).

Now the method:
- Owner always has access (unchanged)
- Non-owner: only team-level permission grants tenant access
- Non-owner + private canvas → denied even if in same tenant

Co-Authored-By: Claude Opus 4.8 <[email protected]>
- Add GetAgentVersion handler with auth check and ownership verification
- Add route to router
- Add service and handler tests (5 new test cases)
- Update vite hybrid proxy config for the new endpoint

The service layer and DAO were already implemented in the previous commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 💞 feature Feature request, pull request that fullfill a new feature. labels Jun 4, 2026
@coderabbitai

coderabbitai Bot commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 06542b62-6d56-413a-9ade-32703de9e930

📥 Commits

Reviewing files that changed from the base of the PR and between ff65530 and b585133.

📒 Files selected for processing (3)
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/router/router.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • internal/router/router.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go

📝 Walkthrough

Walkthrough

Adds GET /api/v1/agents/:agent_id/versions/:version_id to fetch a specific agent version. Implements handler with auth and not-found mapping, adds service-level GetVersion tests, handler tests for success and not-found, registers the route, and updates Vite dev proxy to forward version-detail requests.

Changes

Agent Version Retrieval Endpoint

Layer / File(s) Summary
Service-layer GetVersion tests
internal/service/agent_test.go
Three test cases validate version lookup: successful retrieval when version ID exists on canvas, error when version belongs to a different canvas, and error when version ID does not exist.
GetAgentVersion handler implementation and tests
internal/handler/agent.go, internal/handler/agent_test.go
Adds GetAgentVersion handler (imports updated for error handling and logging), which authenticates the user, validates agent_id and version_id, calls CheckCanvasAccess, invokes service GetVersion, maps not-found cases to CodeNotFound, logs unexpected errors, and returns CodeSuccess with version payload. Includes tests for success (verifies title and DSL) and version-not-found. Removes a local sptr helper definition.
Route registration and dev proxy
internal/router/router.go, web/vite.config.ts
Registers protected route GET /api/v1/agents/:agent_id/versions/:version_id wired to the handler; Vite dev proxy extended to forward agent version detail requests to the backend dev server.

Sequence Diagram

sequenceDiagram
  participant Client
  participant Handler as GetAgentVersion
  participant Service as AgentService
  participant DB
  
  Client->>Handler: GET /api/v1/agents/{agent_id}/versions/{version_id}
  Handler->>Handler: Extract & validate user, agent_id, version_id
  Handler->>Handler: CheckCanvasAccess(agent_id)
  Handler->>Service: GetVersion(canvas_id, version_id)
  Service->>DB: Query UserCanvasVersion
  alt Version found
    DB-->>Service: Version record
    Service-->>Handler: Success with version data
    Handler-->>Client: HTTP 200 CodeSuccess + version payload
  else Version not found
    DB-->>Service: No record
    Service-->>Handler: Error
    Handler-->>Client: HTTP 200 CodeNotFound + error message
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • infiniflow/ragflow#15629: Overlapping implementation work for the GetAgentVersion endpoint and GetVersion service method using shared UserCanvasVersion retrieval logic.
  • infiniflow/ragflow#15633: Modifies agent handler/router flow and touches the same CheckCanvasAccess handler/service wiring used by this endpoint.
  • infiniflow/ragflow#15329: Adds other AgentHandler routes and touches the same routing/handler area.

Suggested reviewers

  • yingfeng
  • yuzhichang
  • JinHai-CN
  • Haruko386
  • Hz-186

Poem

🐰 I hopped through code to fetch a version true,
I checked the canvas and looked for you,
If hidden, I whisper "not found" with grace,
If present, I bring the DSL in place,
Hooray — a route and tests now join the race!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description provides context, lists concrete changes, and includes test results, but does not follow the provided repository template which requires 'What problem does this PR solve?' and 'Type of change' sections. Align the description with the repository template by adding 'What problem does this PR solve?' and 'Type of change' sections to provide consistent documentation.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: implementing a new GET endpoint for retrieving specific agent versions with a full path specification.
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 and usage tips.

@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

🤖 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/handler/agent.go`:
- Around line 210-217: GetAgentVersion currently treats any error from
h.agentService.GetVersion(agentID, versionID) as CodeNotFound; change the error
handling in GetAgentVersion (internal/handler/agent.go) to distinguish real "not
found" cases from other failures: if errors.Is(err, gorm.ErrRecordNotFound) OR
the error message equals the service's sentinel "version not found" string
returned by AgentService.GetVersion, return the existing common.CodeNotFound
response, otherwise return common.CodeServerError (or common.CodeOperatingError)
with an appropriate error message and nil data; use errors.Is to detect
gorm.ErrRecordNotFound and string comparison for the service-level "version not
found" sentinel to locate the correct branch in GetAgentVersion.
🪄 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: 8625f7ba-7b70-4e09-8ac9-dae2c7fbcea8

📥 Commits

Reviewing files that changed from the base of the PR and between 02d163a and 28e94cc.

📒 Files selected for processing (5)
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/router/router.go
  • internal/service/agent_test.go
  • web/vite.config.ts

Comment thread internal/handler/agent.go Resolved
@xugangqiang xugangqiang added the ci Continue Integration label Jun 4, 2026
@xugangqiang
xugangqiang marked this pull request as draft June 4, 2026 09:10
@xugangqiang
xugangqiang marked this pull request as ready for review June 4, 2026 09:10

@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

🤖 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/handler/agent.go`:
- Around line 217-221: The handler currently logs the full error but returns
err.Error() in the JSON response (in the GetVersion handler block using
common.Warn and c.JSON), which can leak internal details; change the c.JSON call
to return a generic message (e.g. "internal server error" or a
localized/constant server error message) and keep the detailed err.Error() only
in the common.Warn log call (or include it as a structured field), ensuring the
response uses common.CodeServerError and nil data but not err.Error().
🪄 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: e8792ca7-1314-4960-835a-aff42a1b2618

📥 Commits

Reviewing files that changed from the base of the PR and between 28e94cc and ff65530.

📒 Files selected for processing (2)
  • internal/handler/agent.go
  • internal/handler/agent_test.go
💤 Files with no reviewable changes (1)
  • internal/handler/agent_test.go

Comment thread internal/handler/agent.go Resolved
@codecov

codecov Bot commented Jun 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (b65b18b) to head (b585133).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15640   +/-   ##
=======================================
  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.

@yingfeng
yingfeng merged commit 6143205 into infiniflow:main Jun 4, 2026
1 check passed
@xugangqiang
xugangqiang deleted the feat/go-agent-version-detail branch August 7, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration 💞 feature Feature request, pull request that fullfill a new feature. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants