Skip to content

Commit

Permalink
fix: register vectorize utils even if not running remotely (#396)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <[email protected]>
Co-authored-by: Sébastien Chopin <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 67514e8 commit efeabf9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export async function setupAI(nuxt: Nuxt, hub: HubConfig) {
if (nuxt.options.dev && !hub.remote && !hub.projectKey) {
return log.warn('`hubAI()` is disabled: link a project with `npx nuxthub link` to run AI models in development mode.')
}

// Register auto-imports first so types are correct even when not running remotely
addServerImportsDir(resolve('./runtime/ai/server/utils'))
// If we are in dev mode and the project is linked, verify it
if (nuxt.options.dev && !hub.remote && hub.projectKey) {
try {
Expand All @@ -115,7 +118,6 @@ export async function setupAI(nuxt: Nuxt, hub: HubConfig) {
}
// Add Server scanning
addServerScanDir(resolve('./runtime/ai/server'))
addServerImportsDir(resolve('./runtime/ai/server/utils'))
}

export function setupAnalytics(_nuxt: Nuxt) {
Expand All @@ -134,6 +136,8 @@ export function setupBlob(_nuxt: Nuxt) {
}

export async function setupBrowser(nuxt: Nuxt) {
// Register auto-imports first so types are correct even when not running remotely
addServerImportsDir(resolve('./runtime/browser/server/utils'))
// Check if dependencies are installed
const missingDeps = []
try {
Expand All @@ -156,7 +160,6 @@ export async function setupBrowser(nuxt: Nuxt) {
}
// Add Server scanning
// addServerScanDir(resolve('./runtime/browser/server'))
addServerImportsDir(resolve('./runtime/browser/server/utils'))
}

export async function setupCache(nuxt: Nuxt) {
Expand Down Expand Up @@ -206,13 +209,14 @@ export function setupKV(_nuxt: Nuxt) {
}

export function setupVectorize(nuxt: Nuxt, hub: HubConfig) {
// Register auto-imports first so types are correct even when not running remotely
addServerImportsDir(resolve('./runtime/vectorize/server/utils'))
if (nuxt.options.dev && !hub.remote) {
log.warn('`hubVectorize()` is disabled: it is currently only supported with `--remote`.')
log.warn('`hubVectorize()` is disabled: only supported with remote storage in development mode.')
return
}
// Add Server scanning
addServerScanDir(resolve('./runtime/vectorize/server'))
addServerImportsDir(resolve('./runtime/vectorize/server/utils'))
}

export function vectorizeRemoteCheck(hub: HubConfig) {
Expand Down
7 changes: 7 additions & 0 deletions src/runtime/vectorize/server/utils/vectorize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ export function hubVectorize(index: VectorizeIndexes): Vectorize {
_vectorize[index] = binding as Vectorize
return _vectorize[index]
}
if (import.meta.dev && !hub.remote) {
throw createError({
statusCode: 500,
message: 'hubVectorize() is only supported with remote storage in development mode'
})
}

throw createError(`Missing Cloudflare Vectorize binding (${bindingName})`)
}

Expand Down

0 comments on commit efeabf9

Please sign in to comment.