Skip to content
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

fix: register vectorize utils even if not running remotely #396

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading