feat(ui): collect Azure AI Foundry resource on key add#2691
Conversation
The provider key dialog had no fields for azure-ai-foundry, so keys were saved without options.azure_ai_foundry_resource. The gateway then threw "Azure AI Foundry resource is required" at request/validation time. Add a required Resource Name field (with format validation) and an optional API Version field, mirroring the Azure OpenAI handling. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Walkthrough
ChangesAzure AI Foundry provider key support in CreateProviderKeyDialog
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx (1)
255-270:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReset only runs through
handleClose, so some close paths retain sensitive form state.
handleCloseclears state, but the success path closes viasetOpen(false)andonOpenChange={setOpen}does not invoke reset logic. This can keep API key/resource values in state when reopening.Suggested fix
-const handleClose = () => { +const handleClose = () => { setOpen(false); setTimeout(() => { setSelectedProvider(preselectedProvider ?? ""); setBaseUrl(""); setCustomName(""); setToken(""); setAzureResource(""); setAzureApiVersion("2024-10-21"); setAzureDeploymentType("ai-foundry"); setAzureValidationModel("gpt-4o-mini"); setAzureAiFoundryResource(""); setAzureAiFoundryApiVersion("2024-05-01-preview"); setSelectedRegion(""); setGoogleVertexProjectId(""); }, 300); }; ... -<Dialog open={open} onOpenChange={setOpen}> +<Dialog + open={open} + onOpenChange={(nextOpen) => { + if (!nextOpen) { + handleClose(); + return; + } + setOpen(nextOpen); + }} +> ... - setOpen(false); + handleClose();🤖 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 `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx` around lines 255 - 270, The handleClose function properly resets form state, but alternative close paths (such as the success path) call setOpen(false) directly without triggering the reset logic, leaving sensitive values like API tokens and resource names in state. Ensure that whenever the dialog closes through any path, the state reset logic runs. Either modify the onOpenChange handler to invoke the reset logic when transitioning to open=false, or refactor all close paths to use handleClose instead of calling setOpen(false) directly, so that sensitive form fields (setToken, setAzureResource, setBaseUrl, setCustomName, setGoogleVertexProjectId, setAzureAiFoundryResource, and others) are consistently cleared when the dialog is closed.
🧹 Nitpick comments (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx (1)
60-62: ⚡ Quick winExtract the Azure AI Foundry default API version to one constant (DRY).
"2024-05-01-preview"is repeated in state init, reset, placeholder, and helper text. A single constant prevents drift.Suggested refactor
+const DEFAULT_AZURE_AI_FOUNDRY_API_VERSION = "2024-05-01-preview"; ... -const [azureAiFoundryApiVersion, setAzureAiFoundryApiVersion] = - useState("2024-05-01-preview"); +const [azureAiFoundryApiVersion, setAzureAiFoundryApiVersion] = useState( + DEFAULT_AZURE_AI_FOUNDRY_API_VERSION, +); ... -setAzureAiFoundryApiVersion("2024-05-01-preview"); +setAzureAiFoundryApiVersion(DEFAULT_AZURE_AI_FOUNDRY_API_VERSION); ... -placeholder="2024-05-01-preview" +placeholder={DEFAULT_AZURE_AI_FOUNDRY_API_VERSION} ... -Azure AI Foundry API version (default: 2024-05-01-preview) +Azure AI Foundry API version (default: {DEFAULT_AZURE_AI_FOUNDRY_API_VERSION})As per coding guidelines, “Apply DRY (Don't Repeat Yourself) principles for code reuse.”
Also applies to: 266-267, 456-462
🤖 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 `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx` around lines 60 - 62, Extract the repeated Azure AI Foundry API version string "2024-05-01-preview" into a single exported constant at the top of the create-provider-key-dialog.tsx file (e.g., DEFAULT_AZURE_AI_FOUNDRY_API_VERSION), then replace all occurrences of this hardcoded string with references to the constant. This includes the initial state value in the useState call for azureAiFoundryApiVersion (lines 60-62), the reset logic around lines 266-267, and the placeholder or helper text usages around lines 456-462, ensuring a single source of truth for this default value across the entire component.Source: Coding guidelines
🤖 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.
Outside diff comments:
In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx`:
- Around line 255-270: The handleClose function properly resets form state, but
alternative close paths (such as the success path) call setOpen(false) directly
without triggering the reset logic, leaving sensitive values like API tokens and
resource names in state. Ensure that whenever the dialog closes through any
path, the state reset logic runs. Either modify the onOpenChange handler to
invoke the reset logic when transitioning to open=false, or refactor all close
paths to use handleClose instead of calling setOpen(false) directly, so that
sensitive form fields (setToken, setAzureResource, setBaseUrl, setCustomName,
setGoogleVertexProjectId, setAzureAiFoundryResource, and others) are
consistently cleared when the dialog is closed.
---
Nitpick comments:
In `@apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx`:
- Around line 60-62: Extract the repeated Azure AI Foundry API version string
"2024-05-01-preview" into a single exported constant at the top of the
create-provider-key-dialog.tsx file (e.g.,
DEFAULT_AZURE_AI_FOUNDRY_API_VERSION), then replace all occurrences of this
hardcoded string with references to the constant. This includes the initial
state value in the useState call for azureAiFoundryApiVersion (lines 60-62), the
reset logic around lines 266-267, and the placeholder or helper text usages
around lines 456-462, ensuring a single source of truth for this default value
across the entire component.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2203d84f-4574-412e-b13b-a1ca8a3c5d6d
📒 Files selected for processing (1)
apps/ui/src/components/provider-keys/create-provider-key-dialog.tsx
Problem
Adding an Azure AI Foundry provider key in the dashboard failed server-side with:
The create-provider-key dialog had special-cased handling for
azure(Azure OpenAI),google-vertex,custom, and region-based providers — but not forazure-ai-foundry. As a result the dialog only collected the API key and submitted a payload with nooptions.azure_ai_foundry_resource. Both key validation (validate-provider-key.ts, which callsgetProviderEndpointwithskipEnvVars: true) and request-time routing then hit theif (!resource)branch and threw. Because BYOK keys skip env vars, theLLM_AZURE_AI_FOUNDRY_RESOURCEfallback never applied.Fix
Add the missing form handling for
azure-ai-foundryin the create provider key dialog, mirroring the existing Azure OpenAI block:^[a-zA-Z0-9-]{1,64}$(same regex the gateway enforces) so the error can no longer reach the server. Written tooptions.azure_ai_foundry_resource.2024-05-01-preview, written tooptions.azure_ai_foundry_api_version.The requirement is now enforced before submission, so it is no longer possible to create a foundry key that errors at validation/request time for a missing resource.
Testing
pnpm formatpnpm exec turbo run build --filter=ui✅🤖 Generated with Claude Code
Summary by CodeRabbit