fix(embeddings): defer EMBED_* validation to embed() runtime, not constructor
Constructor threw if EMBED_BASE_URL/API_KEY/MODEL unset, which broke next build SSG collection (imports search pkg before .env exists). Validation now happens in embed() so the package is build-safe; a missing config still errors clearly when a semantic/hybrid search actually runs. With the DATABASE_URL import-time throw also removed, the whole monorepo now builds in CI without any .env present.
This commit is contained in:
1 parent
f4fb43c1a5
commit
b454a0fbac
1 file changed
+10
-5
@@ -32,11 +32,11 @@ export class OpenRouterEmbeddingProvider implements EmbeddingProvider {
|
|||||||
this.baseUrl = (opts?.baseUrl ?? EMBED_BASE_URL).replace(/\/$/, "");
|
this.baseUrl = (opts?.baseUrl ?? EMBED_BASE_URL).replace(/\/$/, "");
|
||||||
this.apiKey = opts?.apiKey ?? EMBED_API_KEY;
|
this.apiKey = opts?.apiKey ?? EMBED_API_KEY;
|
||||||
this.model = opts?.model ?? EMBED_MODEL;
|
this.model = opts?.model ?? EMBED_MODEL;
|
||||||
if (!this.baseUrl || !this.apiKey || !this.model) {
|
// NOTE: we do NOT validate baseUrl/apiKey/model here. Throwing in the
|
||||||
throw new Error(
|
// constructor breaks `next build` (SSG data collection imports the search
|
||||||
"OpenRouterEmbeddingProvider: missing EMBED_BASE_URL / EMBED_API_KEY / EMBED_MODEL",
|
// package before any .env is present) and any runtime-injected env. The
|
||||||
);
|
// provider is constructed lazily at first query, so an unset config
|
||||||
}
|
// surfaces as a clear error from embed() at request time, not a build crash.
|
||||||
}
|
}
|
||||||
|
|
||||||
get dimensions(): number {
|
get dimensions(): number {
|
||||||
@@ -45,6 +45,11 @@ export class OpenRouterEmbeddingProvider implements EmbeddingProvider {
|
|||||||
|
|
||||||
async embed(texts: string[]): Promise<number[][]> {
|
async embed(texts: string[]): Promise<number[][]> {
|
||||||
if (texts.length === 0) return [];
|
if (texts.length === 0) return [];
|
||||||
|
if (!this.baseUrl || !this.apiKey || !this.model) {
|
||||||
|
throw new Error(
|
||||||
|
"OpenRouterEmbeddingProvider: missing EMBED_BASE_URL / EMBED_API_KEY / EMBED_MODEL at request time",
|
||||||
|
);
|
||||||
|
}
|
||||||
const res = await fetch(`${this.baseUrl}/embeddings`, {
|
const res = await fetch(`${this.baseUrl}/embeddings`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Reference in new issue
Block a user