@@ -32,6 +32,7 @@ import {
3232 type ServiceAccountSelectorRef ,
3333} from 'components/ui/service-account/service-account-selector' ;
3434import { TagsFieldList } from 'components/ui/tag/tags-field-list' ;
35+ import { isFeatureFlagEnabled } from 'config' ;
3536import { Loader2 } from 'lucide-react' ;
3637import { Scope } from 'protogen/redpanda/api/dataplane/v1/secret_pb' ;
3738import {
@@ -51,6 +52,7 @@ import {
5152import { useEffect , useMemo , useRef , useState } from 'react' ;
5253import { Controller , useFieldArray , useForm } from 'react-hook-form' ;
5354import { useCreateAIAgentMutation } from 'react-query/api/ai-agent' ;
55+ import { useListGatewaysQuery } from 'react-query/api/ai-gateway' ;
5456import { useListMCPServersQuery } from 'react-query/api/remote-mcp' ;
5557import { useCreateSecretMutation , useListSecretsQuery } from 'react-query/api/secret' ;
5658import { toast } from 'sonner' ;
@@ -72,6 +74,38 @@ export const AIAgentCreatePage = () => {
7274 skipInvalidation : true ,
7375 } ) ;
7476
77+ // Feature flag: when true, use legacy API key mode (hardcoded providers)
78+ const isLegacyApiKeyMode = isFeatureFlagEnabled ( 'enableApiKeyConfigurationAgent' ) ;
79+
80+ // Gateway detection and list query (using v1 API from ai-gateway module)
81+ // Only fetch when NOT in legacy mode
82+ const { data : gatewaysData , isLoading : isLoadingGateways } = useListGatewaysQuery (
83+ { } ,
84+ { enabled : ! isLegacyApiKeyMode }
85+ ) ;
86+
87+ const hasGatewayDeployed = useMemo ( ( ) => {
88+ if ( isLegacyApiKeyMode || isLoadingGateways ) {
89+ return false ;
90+ }
91+ return Boolean ( gatewaysData ?. gateways && gatewaysData . gateways . length > 0 ) ;
92+ } , [ isLegacyApiKeyMode , gatewaysData , isLoadingGateways ] ) ;
93+
94+ const availableGateways = useMemo ( ( ) => {
95+ if ( isLegacyApiKeyMode || ! gatewaysData ?. gateways ) {
96+ return [ ] ;
97+ }
98+ return gatewaysData . gateways . map ( ( gw ) => {
99+ // Extract gateway ID from name (format: "gateways/{gateway_id}")
100+ const gatewayId = gw . name . split ( '/' ) . pop ( ) || gw . name ;
101+ return {
102+ id : gatewayId ,
103+ displayName : gw . displayName ,
104+ description : gw . description ,
105+ } ;
106+ } ) ;
107+ } , [ isLegacyApiKeyMode , gatewaysData ] ) ;
108+
75109 // Ref to ServiceAccountSelector to call createServiceAccount
76110 const serviceAccountSelectorRef = useRef < ServiceAccountSelectorRef > ( null ) ;
77111
@@ -107,6 +141,13 @@ export const AIAgentCreatePage = () => {
107141 }
108142 } , [ displayName , form ] ) ;
109143
144+ // Auto-select first gateway when gateways are available (only if not in legacy mode)
145+ useEffect ( ( ) => {
146+ if ( ! isLegacyApiKeyMode && availableGateways . length > 0 && ! form . getValues ( 'gatewayId' ) ) {
147+ form . setValue ( 'gatewayId' , availableGateways [ 0 ] . id ) ;
148+ }
149+ } , [ isLegacyApiKeyMode , availableGateways , form ] ) ;
150+
110151 const {
111152 fields : tagFields ,
112153 append : appendTag ,
@@ -294,7 +335,9 @@ export const AIAgentCreatePage = () => {
294335 } ) ;
295336
296337 // Build provider configuration based on selected provider
297- const apiKeyRef = `\${secrets.${ values . apiKeySecret } }` ;
338+ // When using gateway: api_key can be empty (proto has ignore = IGNORE_IF_ZERO_VALUE)
339+ // When not using gateway: api_key must reference a secret
340+ const apiKeyRef = values . apiKeySecret ? `\${secrets.${ values . apiKeySecret } }` : '' ;
298341 let providerConfig : AIAgent_Provider ;
299342
300343 switch ( values . provider ) {
@@ -464,7 +507,7 @@ export const AIAgentCreatePage = () => {
464507 </ CardHeader >
465508 < CardContent >
466509 < LLMConfigSection
467- availableGateways = { [ ] }
510+ availableGateways = { availableGateways }
468511 availableSecrets = { availableSecrets }
469512 fieldNames = { {
470513 provider : 'provider' ,
@@ -475,7 +518,8 @@ export const AIAgentCreatePage = () => {
475518 gatewayId : 'gatewayId' ,
476519 } }
477520 form = { form }
478- hasGatewayDeployed = { false }
521+ hasGatewayDeployed = { hasGatewayDeployed }
522+ isLoadingGateways = { isLoadingGateways }
479523 mode = "create"
480524 scopes = { [ Scope . MCP_SERVER , Scope . AI_AGENT ] }
481525 showBaseUrl = { form . watch ( 'provider' ) === 'openaiCompatible' }
0 commit comments