@@ -19,6 +19,8 @@ import {
1919 netlifyCommand ,
2020} from '../../utils/command-helpers.js'
2121import detectServerSettings , { getConfigWithPlugins } from '../../utils/detect-server-settings.js'
22+ import { parseAIGatewayContext , setupAIGateway } from '@netlify/ai/bootstrap'
23+
2224import { UNLINKED_SITE_MOCK_ID , getDotEnvVariables , getSiteInformation , injectEnvVariables } from '../../utils/dev.js'
2325import { getEnvelopeEnv } from '../../utils/env/index.js'
2426import { ensureNetlifyIgnore } from '../../utils/gitignore.js'
@@ -143,8 +145,6 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
143145 }
144146
145147 env = await getDotEnvVariables ( { devConfig, env, site } )
146- injectEnvVariables ( env )
147- await promptEditorHelper ( { chalk, config, log, NETLIFYDEVLOG , repositoryRoot, state } )
148148
149149 const { accountId, addonsUrls, capabilities, siteUrl, timeouts } = await getSiteInformation ( {
150150 // inherited from base command --offline
@@ -155,6 +155,14 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
155155 siteInfo,
156156 } )
157157
158+ if ( ! options . offline && ! options . offlineEnv ) {
159+ await setupAIGateway ( { api, env, siteID : site . id , siteURL : siteUrl } )
160+ }
161+
162+ injectEnvVariables ( env )
163+
164+ await promptEditorHelper ( { chalk, config, log, NETLIFYDEVLOG , repositoryRoot, state } )
165+
158166 let settings : ServerSettings
159167 try {
160168 settings = await detectServerSettings ( devConfig , options , command )
@@ -204,7 +212,11 @@ export const dev = async (options: OptionValues, command: BaseCommand) => {
204212 // FIXME(serhalp): `applyMutations` is `(any, any) => any)`. Add types in `@netlify/config`.
205213 const mutatedConfig : typeof config = applyMutations ( config , configMutations )
206214
215+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
216+ const aiGatewayContext = parseAIGatewayContext ( env . AI_GATEWAY ?. value )
217+
207218 const functionsRegistry = await startFunctionsServer ( {
219+ aiGatewayContext,
208220 blobsContext,
209221 command,
210222 config : mutatedConfig ,
0 commit comments