Skip to content

Commit f9c4cea

Browse files
authored
feat: support specifying account id to wrangler
1 parent b4bc819 commit f9c4cea

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default defineNuxtModule<ModuleOptions>({
3030
remoteArg = (remoteArg === '' ? 'true' : remoteArg)
3131
const runtimeConfig = nuxt.options.runtimeConfig
3232
const hub = defu(runtimeConfig.hub || {}, options, {
33+
accountId: process.env.CLOUDFLARE_ACCOUNT_ID || '',
3334
// Self-hosted project
3435
projectUrl: process.env.NUXT_HUB_PROJECT_URL || '',
3536
projectSecretKey: process.env.NUXT_HUB_PROJECT_SECRET_KEY || '',

src/runtime/ai/server/utils/ai.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function hubAi(): Ai {
2323
return _ai
2424
}
2525
// @ts-expect-error globalThis.__env__ is not defined
26-
const binding = process.env.AI || globalThis.__env__?.AI || globalThis.AI;
26+
const binding = process.env.AI || globalThis.__env__?.AI || globalThis.AI
2727
if (binding) {
2828
_ai = binding as Ai
2929
return _ai

src/types/module.ts

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ export interface ModuleOptions {
22
/**
33
* Set `true` to enable AI for the project.
44
*
5+
* Requires running `npx wrangler login` for local development one time system wide.
6+
* Set `accountId` if logged-in user has access to several accounts.
7+
*
58
* @default false
69
* @see https://developers.cloudflare.com/workers-ai/configuration/bindings/#methods
710
*/
@@ -77,4 +80,10 @@ export interface ModuleOptions {
7780
* @default '.data/hub'
7881
*/
7982
dir?: string
83+
/**
84+
* The account ID of the Cloudflare account to use for local development.
85+
* Only necessary if using AI and logged-in user has access to multiple accounts.
86+
* @default process.env.CLOUDFLARE_ACCOUNT_ID
87+
*/
88+
accountId?: string
8089
}

src/utils/wrangler.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { stringifyTOML } from 'confbox'
22

3-
export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, analytics: boolean, ai: boolean }) {
3+
export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, analytics: boolean, ai: boolean, accountId?: string }) {
44
const wrangler: { [key: string]: any } = {}
55

6+
if (hub.accountId) {
7+
wrangler['account_id'] = hub.accountId
8+
}
9+
610
if (hub.ai) {
711
wrangler['ai'] = {
812
binding: 'AI'

0 commit comments

Comments
 (0)