Skip to content

Add Custom policy feature in AI Workspcae#2775

Merged
Thushani-Jayasekera merged 3 commits into
wso2:mainfrom
Induwara04:test-3
Jul 23, 2026
Merged

Add Custom policy feature in AI Workspcae#2775
Thushani-Jayasekera merged 3 commits into
wso2:mainfrom
Induwara04:test-3

Conversation

@Induwara04

Copy link
Copy Markdown
Contributor

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

Screenshot 2026-07-21 at 16 05 26 Screenshot 2026-07-21 at 16 06 01 Screenshot 2026-07-21 at 16 06 18

Backend: Gateway Handle Support and Service Logic Updates

  • Changed all relevant API parameters, service methods, and repository calls to use the gateway handle (slug) instead of UUID for identifying gateways in custom policy management and manifest retrieval. This includes updating OpenAPI specs, handler logic, and service methods. [1] [2] [3] [4] [5] [6]
  • Refactored repository and service layer lookups to use GetByHandleAndOrgID instead of GetByUUID, 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

  • Added a new API module (gatewayPolicyApis.ts) for managing gateway custom policies, including listing, syncing, retrieving, and deleting custom policies via the platform API.
  • Added a new UI route and page (CustomPoliciesList) under the settings section for viewing and managing custom policies in the frontend application. [1] [2]

Frontend: Policy Hub API Improvements

  • Enhanced the Policy Hub API integration to support pagination and a new method for fetching all policies for the gateway policy catalogue. [1] [2]

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.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Induwara04, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a722a701-f2d1-4643-a7f6-f5b8fd453579

📥 Commits

Reviewing files that changed from the base of the PR and between a689d3d and d1d5786.

📒 Files selected for processing (1)
  • platform-api/resources/openapi.yaml
📝 Walkthrough

Walkthrough

Gateway 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.

Changes

Gateway custom policy integration

Layer / File(s) Summary
Handle-based gateway resolution
platform-api/api/generated.go, platform-api/internal/handler/gateway.go, platform-api/internal/service/gateway.go, platform-api/internal/service/*test.go, platform-api/resources/openapi.yaml
Gateway manifest and custom-policy synchronization accept organization-scoped handles, while stored manifests and audit fields use gateway UUIDs.
Workspace policy API and aggregation
portals/ai-workspace/src/apis/gatewayPolicyApis.ts, portals/ai-workspace/src/apis/policyHubApis.ts, portals/ai-workspace/src/contexts/GatewayPoliciesContext.tsx
Typed gateway policy operations, paginated Policy Hub queries, and merged policy context state are added.
Policy management pages and routing
portals/ai-workspace/src/App.tsx, portals/ai-workspace/src/pages/appShell/appShellPages/gateways/*, portals/ai-workspace/src/pages/appShell/appShellPages/settings/*
Custom-policy listing, deletion, gateway synchronization views, permission-aware settings navigation, and gateway policy tabs are added.
Unified policy selection
portals/ai-workspace/src/pages/appShell/appShellPages/externalServers/PolicyMapper.tsx, portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyGuardrailsTab.tsx
Policy Hub guardrails and gateway custom policies share drawer models, version formatting, inline definitions, selection flows, and provider metadata.
Provider guardrail integration
portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/*
Provider guardrail drawers load both policy sources, support pagination and custom definitions, and pass selected policy identity and version into provider state.

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
Loading

Suggested reviewers: lasanthas, renuka-fernando, thushani-jayasekera, krishanx92, piumal1999

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description summarizes the change but omits most required template sections like tests, security checks, and documentation. Add the missing template sections, especially Purpose, Goals, Approach, user stories, documentation, tests, security checks, samples, related PRs, and test environment.
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main feature: adding custom policy support in AI Workspace.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@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: 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 win

Handle empty manifest data to prevent JSON marshaling errors.

If s.gatewayRepo.GetGatewayManifest successfully returns an empty byte slice ([]byte{})—for example, if the database column is an empty string—passing it to json.RawMessage will result in an invalid JSON fragment. When httputil.WriteJSON subsequently attempts to marshal this struct, Go's encoding/json package will fail with a MarshalerError ("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

📥 Commits

Reviewing files that changed from the base of the PR and between 05139c4 and 4755d43.

📒 Files selected for processing (19)
  • platform-api/api/generated.go
  • platform-api/internal/handler/gateway.go
  • platform-api/internal/service/custom_policy_test.go
  • platform-api/internal/service/gateway.go
  • platform-api/internal/service/gateway_manifest_test.go
  • platform-api/resources/openapi.yaml
  • portals/ai-workspace/src/App.tsx
  • portals/ai-workspace/src/apis/gatewayPolicyApis.ts
  • portals/ai-workspace/src/apis/policyHubApis.ts
  • portals/ai-workspace/src/contexts/GatewayPoliciesContext.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/externalServers/PolicyMapper.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/gateways/CustomPoliciesList.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/gateways/GatewayPolicies.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/gateways/ViewGateway.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyGuardrailsTab.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/AddNewProvider/GuardrailsSection.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderGuardrailsTab.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderNew.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/settings/Main.tsx

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 21, 2026
Comment thread platform-api/resources/openapi.yaml Outdated
@Thushani-Jayasekera
Thushani-Jayasekera merged commit be3e3a0 into wso2:main Jul 23, 2026
10 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants