11import { OptionValues } from 'commander'
22import execa from 'execa'
33
4- import { getDotEnvVariables , injectEnvVariables } from '../../utils/dev.js'
4+ import { parseAIGatewayContext , setupAIGateway } from '@netlify/ai/bootstrap'
5+
6+ import { NETLIFYDEVLOG , log } from '../../utils/command-helpers.js'
7+ import { getDotEnvVariables , getSiteInformation , injectEnvVariables } from '../../utils/dev.js'
58import { getEnvelopeEnv } from '../../utils/env/index.js'
69import BaseCommand from '../base-command.js'
710
@@ -10,9 +13,33 @@ export const devExec = async (cmd: string, options: OptionValues, command: BaseC
1013
1114 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1215 const withEnvelopeEnvVars = await getEnvelopeEnv ( { api, context : options . context , env : cachedConfig . env , siteInfo } )
13- const withDotEnvVars = await getDotEnvVariables ( { devConfig : { ...config . dev } , env : withEnvelopeEnvVars , site } )
16+ const env = await getDotEnvVariables ( { devConfig : { ...config . dev } , env : withEnvelopeEnvVars , site } )
17+
18+ const { capabilities, siteUrl } = await getSiteInformation ( {
19+ offline : false ,
20+ api,
21+ site,
22+ siteInfo,
23+ } )
24+
25+ if ( ! capabilities . aiGatewayDisabled ) {
26+ await setupAIGateway ( { api, env, siteID : site . id , siteURL : siteUrl } )
27+
28+ const aiGatewayEnv = env . AI_GATEWAY as ( typeof env ) [ string ] | undefined
29+ if ( aiGatewayEnv ) {
30+ const aiGatewayContext = parseAIGatewayContext ( aiGatewayEnv . value )
31+ if ( aiGatewayContext ?. envVars ) {
32+ for ( const envVar of aiGatewayContext . envVars ) {
33+ env [ envVar . key ] = { sources : [ 'internal' ] , value : aiGatewayContext . token }
34+ env [ envVar . url ] = { sources : [ 'internal' ] , value : aiGatewayContext . url }
35+ }
36+ }
37+ }
38+ } else {
39+ log ( `${ NETLIFYDEVLOG } AI Gateway is disabled for this account` )
40+ }
1441
15- injectEnvVariables ( withDotEnvVars )
42+ injectEnvVariables ( env )
1643
1744 await execa ( cmd , command . args . slice ( 1 ) , {
1845 stdio : 'inherit' ,
0 commit comments