Repository navigation
feat: implement GET /api/v1/agents/<agent_id>/versions/<version_id> API - #15640
Conversation
- 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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds 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. ChangesAgent Version Retrieval Endpoint
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
internal/handler/agent.gointernal/handler/agent_test.gointernal/router/router.gointernal/service/agent_test.goweb/vite.config.ts
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
internal/handler/agent.gointernal/handler/agent_test.go
💤 Files with no reviewable changes (1)
- internal/handler/agent_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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
UserCanvasVersionDAOinfrastructure.Changes
internal/handler/agent.go— AddedGetAgentVersionhandler with auth check and ownership verificationinternal/router/router.go— RegisteredGET /:agent_id/versions/:version_idrouteTesting
Co-Authored-By: Claude Opus 4.8 [email protected]