-
Notifications
You must be signed in to change notification settings - Fork 11
feat: ai gateway disabled check #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| let aiGatewayDisabled = false | ||
| try { | ||
| const api = config.api as import('@netlify/api').NetlifyAPI | ||
| const accounts = await api.listAccountsForUser() | ||
| const account = accounts.find((acc) => acc.slug === config.siteInfo?.account_slug) | ||
| aiGatewayDisabled = | ||
| (account?.capabilities as { ai_gateway_disabled?: { included?: boolean } } | undefined)?.ai_gateway_disabled | ||
| ?.included ?? false | ||
| } catch { | ||
| // If we can't fetch accounts, proceed with AI Gateway enabled | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 This would be the first case of making API requests like this in the @netlify/dev package, which would change the current separation of responsibilities a bit. As is, @netlify/config is responsible for fetching all the account and site information needed and all the primitives packages receive what they need via @netlify/dev which is a sort of orchestrator.
tbh, I would wager that capabilities are already on the config object that's in scope here, but the types are just unfortunately incomplete.
maybe try adding a console.log of the full config and try against a real site?
| } | ||
| } | ||
| } else { | ||
| this.#logger?.log('AI Gateway is disabled for this account') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 This is existing stuff, but is there any reason AI Gateway isn't set up the same way as other primitives?
4:49:05 PM [vite] ⬥ Netlify AI Gateway is disabled for this account
4:49:05 PM [vite] ⬥ Netlify Environment loaded
4:49:05 PM [vite] ⬥ Netlify Middleware loaded. Emulating features: blobs, edgeFunctions, environmentVariables, functions, geolocation, headers, images, redirects, static.
We could just set enabled like the others, maybe?
primitives/packages/dev/src/main.ts
Lines 642 to 646 in c1ae30f
| public getEnabledFeatures(): string[] { | |
| return Object.entries(this.#features) | |
| .filter(([_, enabled]) => enabled) | |
| .map(([feature]) => feature) | |
| } |
Respects opt out flow for ai gateway in
@netlify/devpackage (which vite plugin depends on) by checking account capabilities.https://linear.app/netlify/issue/RUN-1883/build-an-opt-out-flow-for-account-and-sites
Tested locally with
npm linkand runningnpm run devRunning
npm run devWhen disabled, we log: