feat(guardrail): admin ui#113
Conversation
📝 WalkthroughWalkthroughThis PR introduces a complete guardrails management feature to the admin UI. It adds type-safe contracts for regex and bedrock guardrails, CRUD API methods, React Query data hooks, a form component with conditional type-specific fields and validation, three routes for list/create/edit operations, and English/Chinese localization plus sidebar navigation integration. ChangesGuardrails Management Feature
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 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 `@crates/admin-ui/ui/src/components/guardrails/guardrail-form.tsx`:
- Around line 74-76: The form currently pre-populates and reveals persisted
secret_access_key (see the secret_access_key initial state and the
RevealableInput render), which exposes stored secrets; change the edit behavior
to be write-only by initializing secret_access_key to an empty string when
editing (keep required validation only when creating a new guardrail), update
the submit/serialize logic in the form handler (e.g., the submit function that
builds the payload) to include secret_access_key only if the user entered a
non-empty value, and ensure validation rules on secret_access_key apply on
create flows but not on unchanged edits; update any other places that mirror
this pattern (the other initializations at the indicated blocks) to follow the
same write-only approach.
In `@crates/admin-ui/ui/src/lib/api/types.ts`:
- Around line 49-69: The shared Guardrail model currently exposes secret fields
(access_key_id, secret_access_key, session_token) — split it into separate DTOs:
keep the existing BedrockGuardrailConfig but create BedrockGuardrailWrite
(including access_key_id, secret_access_key, session_token) used by
create/update flows and create BedrockGuardrailRead (omit or redact those
fields) used by list/get flows; then replace the union type Guardrail with two
public union types GuardrailWrite (regex | bedrock write) and GuardrailRead
(regex | bedrock read) so read paths never carry raw secrets, and
implement/redact serialization for any secret-bearing struct (e.g.,
BedrockGuardrailWrite) per project guidelines.
In `@crates/admin-ui/ui/src/lib/queries/guardrails.ts`:
- Around line 45-73: The three mutation hooks useCreateGuardrail,
useUpdateGuardrail and useDeleteGuardrail currently assume key! and lack 401
handling; update each to extract openModal from useAdminKey() alongside key and
add an onError handler that checks for ApiClientError with status 401 and calls
openModal() to trigger re-authentication (mirror the pattern used in
useGuardrails()/useGuardrail()); keep existing onSuccess invalidation logic and
ensure the mutationFn still calls guardrailsApi.create/update/delete with the
key.
In `@crates/admin-ui/ui/src/routes/_layout/guardrails/`$id.tsx:
- Around line 27-31: The handleDelete function currently calls
deleteGuardrail.mutateAsync(id) and immediately navigates away, which ignores
failures; wrap the delete call in a try/catch inside handleDelete, await
deleteGuardrail.mutateAsync(id) in the try, and only call navigate({ to:
'/guardrails' }) on success; in the catch block surface the error to the user
(e.g., via existing toast/notification mechanism or set a component error state)
and do not navigate so the user can retry — update references to handleDelete,
deleteGuardrail.mutateAsync, and navigate accordingly.
In `@crates/admin-ui/ui/src/routes/_layout/guardrails/index.tsx`:
- Around line 119-123: The delete calls (deleteGuardrail.mutate in the row
action and the bulk deletion flow) don't handle failures and a single rejection
can stop remaining deletions; change both to use the async API and explicit
error handling: replace deleteGuardrail.mutate(row.original.id) with an async
call to deleteGuardrail.mutateAsync(row.original.id) (or call mutate with an
onError/onSuccess callback) and surface errors via the existing UI feedback
(toast/error state); for the bulk flow, stop using a simple loop that aborts on
the first rejection and instead use Promise.allSettled over the array of ids (or
sequentially await mutateAsync in a try/catch while collecting failures) so each
id is attempted even if others fail, then report successes and failures to the
user and update selection/state accordingly.
🪄 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: b4599d4b-fc23-4bf7-86f0-3fb4379dd42b
📒 Files selected for processing (11)
crates/admin-ui/ui/src/components/guardrails/guardrail-form.tsxcrates/admin-ui/ui/src/components/layout/sidebar.tsxcrates/admin-ui/ui/src/i18n/locales/en.jsoncrates/admin-ui/ui/src/i18n/locales/zh-CN.jsoncrates/admin-ui/ui/src/lib/api/client.tscrates/admin-ui/ui/src/lib/api/types.tscrates/admin-ui/ui/src/lib/queries/guardrails.tscrates/admin-ui/ui/src/routeTree.gen.tscrates/admin-ui/ui/src/routes/_layout/guardrails/$id.tsxcrates/admin-ui/ui/src/routes/_layout/guardrails/create.tsxcrates/admin-ui/ui/src/routes/_layout/guardrails/index.tsx
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 `@crates/admin-ui/ui/src/i18n/locales/zh-CN.json`:
- Line 8: The zh-CN locale values for newly added keys are left in English;
replace the English strings with proper Chinese translations for the keys
introduced (e.g., "guardrails", "regex", "version", "bedrockEndpointOverride"
and any adjacent keys added in the same diff), and ensure the same translation
policy is applied consistently across the other new keys in this locale block;
if a product term must remain untranslated, add a short comment or consistent
marker in the locale file to document the intentional exception so reviewers can
verify consistency.
🪄 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: a132de18-82e6-4e4b-90d0-86bc53b30e97
📒 Files selected for processing (5)
crates/admin-ui/ui/src/i18n/locales/en.jsoncrates/admin-ui/ui/src/i18n/locales/zh-CN.jsoncrates/admin-ui/ui/src/lib/queries/guardrails.tscrates/admin-ui/ui/src/routes/_layout/guardrails/$id.tsxcrates/admin-ui/ui/src/routes/_layout/guardrails/index.tsx
✅ Files skipped from review due to trivial changes (1)
- crates/admin-ui/ui/src/i18n/locales/en.json
🚧 Files skipped from review as they are similar to previous changes (3)
- crates/admin-ui/ui/src/routes/_layout/guardrails/$id.tsx
- crates/admin-ui/ui/src/lib/queries/guardrails.ts
- crates/admin-ui/ui/src/routes/_layout/guardrails/index.tsx
Summary by CodeRabbit
New Features
Documentation