Add Custom policy feature in AI Workspcae#2775
Conversation
|
Warning Review limit reached
Next review available in: 24 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughGateway identifiers now use URL-friendly handles across API resolution and custom-policy synchronization. The workspace adds typed policy APIs, merged policy state, custom-policy management routes, gateway policy views, and custom-policy support in guardrail selection and provider configuration flows. ChangesGateway custom policy integration
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant ProviderGuardrails
participant gatewayPolicyApis
participant policyHubApis
participant PolicyDefinitionEditor
ProviderGuardrails->>gatewayPolicyApis: Fetch gateway custom policies
ProviderGuardrails->>policyHubApis: Fetch paginated guardrails
gatewayPolicyApis-->>ProviderGuardrails: Return custom policy definitions
policyHubApis-->>ProviderGuardrails: Return Policy Hub definitions
ProviderGuardrails->>PolicyDefinitionEditor: Open selected policy definition
Suggested reviewers: 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
platform-api/internal/service/gateway.go (1)
116-121: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winHandle empty manifest data to prevent JSON marshaling errors.
If
s.gatewayRepo.GetGatewayManifestsuccessfully returns an empty byte slice ([]byte{})—for example, if the database column is an empty string—passing it tojson.RawMessagewill result in an invalid JSON fragment. Whenhttputil.WriteJSONsubsequently attempts to marshal this struct, Go'sencoding/jsonpackage will fail with aMarshalerError("unexpected end of JSON input"), causing a 500 Internal Server Error.Add a safeguard to map an empty slice to an empty JSON array
[](or handle it gracefully) to ensure valid JSON serialization.🐛 Proposed fix
raw, err := s.gatewayRepo.GetGatewayManifest(gateway.ID) if err != nil { return nil, fmt.Errorf("failed to get gateway manifest: %w", err) } + if len(raw) == 0 { + raw = []byte("[]") + } return &Manifest{Policies: json.RawMessage(raw)}, nil🤖 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 `@platform-api/internal/service/gateway.go` around lines 116 - 121, Update the manifest construction flow after s.gatewayRepo.GetGatewayManifest succeeds to detect an empty raw byte slice and substitute valid empty-array JSON before assigning it to Manifest.Policies. Preserve the existing error wrapping and non-empty manifest behavior.
🤖 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
`@portals/ai-workspace/src/pages/appShell/appShellPages/gateways/CustomPoliciesList.tsx`:
- Around line 267-289: Update the search-field condition in CustomPoliciesList
so it remains mounted when an active search query produces no pageItems, while
still avoiding the field when no policies have been loaded. Preserve the
existing loading, value, and change-handler behavior so users can edit or clear
the query from the empty search-results state.
In
`@portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/AddNewProvider/GuardrailsSection.tsx`:
- Around line 496-503: Add a bounded maxHeight to the Box containing
handleGuardrailListScroll so it forms an actual scroll region and triggers
infinite-scroll loading. Keep overflowY set to auto and preserve the existing
handleGuardrailListScroll and handleLoadMoreGuardrails behavior.
---
Outside diff comments:
In `@platform-api/internal/service/gateway.go`:
- Around line 116-121: Update the manifest construction flow after
s.gatewayRepo.GetGatewayManifest succeeds to detect an empty raw byte slice and
substitute valid empty-array JSON before assigning it to Manifest.Policies.
Preserve the existing error wrapping and non-empty manifest behavior.
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7bc113b3-fcd9-452d-99a5-28fe65eb65e7
📒 Files selected for processing (19)
platform-api/api/generated.goplatform-api/internal/handler/gateway.goplatform-api/internal/service/custom_policy_test.goplatform-api/internal/service/gateway.goplatform-api/internal/service/gateway_manifest_test.goplatform-api/resources/openapi.yamlportals/ai-workspace/src/App.tsxportals/ai-workspace/src/apis/gatewayPolicyApis.tsportals/ai-workspace/src/apis/policyHubApis.tsportals/ai-workspace/src/contexts/GatewayPoliciesContext.tsxportals/ai-workspace/src/pages/appShell/appShellPages/externalServers/PolicyMapper.tsxportals/ai-workspace/src/pages/appShell/appShellPages/gateways/CustomPoliciesList.tsxportals/ai-workspace/src/pages/appShell/appShellPages/gateways/GatewayPolicies.tsxportals/ai-workspace/src/pages/appShell/appShellPages/gateways/ViewGateway.tsxportals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyGuardrailsTab.tsxportals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/AddNewProvider/GuardrailsSection.tsxportals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderGuardrailsTab.tsxportals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderNew.tsxportals/ai-workspace/src/pages/appShell/appShellPages/settings/Main.tsx
This pull request introduces several backend and frontend changes to support identifying gateways by their handle (URL-friendly slug) instead of UUID, especially for custom policy management. It also adds new API integrations and UI routes for managing gateway custom policies in the frontend. The most important changes are summarized below:
Issue: #2676
Backend: Gateway Handle Support and Service Logic Updates
GetByHandleAndOrgIDinstead ofGetByUUID, ensuring organization scoping and correct manifest retrieval. Updated mocks and added a new test to validate handle-to-UUID resolution. [1] [2]Frontend: Gateway Custom Policy Management Integration
gatewayPolicyApis.ts) for managing gateway custom policies, including listing, syncing, retrieving, and deleting custom policies via the platform API.CustomPoliciesList) under the settings section for viewing and managing custom policies in the frontend application. [1] [2]Frontend: Policy Hub API Improvements
These changes collectively improve the developer experience by allowing gateway operations to use more user-friendly identifiers, and they lay the groundwork for enhanced custom policy management in the UI.