@@ -4,6 +4,7 @@ import type { IncomingMessage, ClientRequest } from 'http'
44import { join , resolve } from 'path'
55
66import * as bundler from '@netlify/edge-bundler'
7+ import type { AIGatewayContext } from '@netlify/ai/bootstrap'
78import getAvailablePort from 'get-port'
89
910import type BaseCommand from '../../commands/base-command.js'
@@ -75,6 +76,7 @@ const createAccountInfoHeader = ({ id }: { id: string }) => {
7576
7677export const initializeProxy = async ( {
7778 accountId,
79+ aiGatewayContext,
7880 blobsContext,
7981 command,
8082 config,
@@ -95,6 +97,7 @@ export const initializeProxy = async ({
9597 state,
9698} : {
9799 accountId : string
100+ aiGatewayContext ?: AIGatewayContext | null
98101 blobsContext : BlobsContextWithEdgeAccess
99102 command : BaseCommand
100103 config : NormalizedCachedConfigConfig
@@ -124,6 +127,7 @@ export const initializeProxy = async ({
124127 // the network if needed. We don't want to wait for that to be completed, or
125128 // the command will be left hanging.
126129 const server = prepareServer ( {
130+ aiGatewayContext,
127131 command,
128132 config,
129133 configPath,
@@ -162,6 +166,10 @@ export const initializeProxy = async ({
162166 ) . toString ( 'base64' )
163167 }
164168
169+ if ( aiGatewayContext ) {
170+ req . headers [ headers . AIGateway ] = Buffer . from ( JSON . stringify ( aiGatewayContext ) ) . toString ( 'base64' )
171+ }
172+
165173 await registry . initialize ( )
166174
167175 const url = new URL ( req . url ! , `http://${ LOCAL_HOST } :${ mainPort } ` )
@@ -194,6 +202,7 @@ export const isEdgeFunctionsRequest = (req: IncomingMessage): req is ExtendedInc
194202 Object . hasOwn ( req , headersSymbol )
195203
196204const prepareServer = async ( {
205+ aiGatewayContext,
197206 command,
198207 config,
199208 configPath,
@@ -207,6 +216,7 @@ const prepareServer = async ({
207216 projectDir,
208217 repositoryRoot,
209218} : {
219+ aiGatewayContext ?: AIGatewayContext | null
210220 command : BaseCommand
211221 config : NormalizedCachedConfigConfig
212222 configPath : string
@@ -245,8 +255,9 @@ const prepareServer = async ({
245255 servePath,
246256 } )
247257 const registry = new EdgeFunctionsRegistry ( {
248- command ,
258+ aiGatewayContext ,
249259 bundler,
260+ command,
250261 config,
251262 configPath,
252263 debug,
0 commit comments