@retrivora-ai/rag-engine 2.3.4 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,14 +155,26 @@ var init_BaseVectorProvider = __esm({
155
155
  });
156
156
 
157
157
  // src/core/ConfigFetcher.ts
158
- var ConfigFetcher;
158
+ var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
159
159
  var init_ConfigFetcher = __esm({
160
160
  "src/core/ConfigFetcher.ts"() {
161
161
  "use strict";
162
+ CONTROL_PLANE_URL = "https://www.retrivora.com";
163
+ LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
162
164
  ConfigFetcher = class {
163
165
  // 5-minute in-memory session cache
164
166
  /**
165
- * Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
167
+ * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
168
+ *
169
+ * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
170
+ * The server validates the license against the database and returns:
171
+ * - validity (tier, isActive, expiresAt)
172
+ * - LLM model info
173
+ * - embedding model info
174
+ * - Pinecone index name and workspace/namespace
175
+ *
176
+ * The Pinecone API key is NOT returned (server-only). The SDK uses local
177
+ * PINECONE_API_KEY if available, or vector operations are handled server-side.
166
178
  */
167
179
  static async fetchRemoteConfig(projectId, licenseKey) {
168
180
  var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
@@ -175,14 +187,11 @@ var init_ConfigFetcher = __esm({
175
187
  const controlPlaneUrls = [
176
188
  process.env.RETRIVORA_CONTROL_PLANE_URL,
177
189
  process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
178
- "https://www.retrivora.com",
179
- "https://retrivora.com",
180
- "http://localhost:3000",
181
- "http://localhost:3001"
182
- ].filter(Boolean);
190
+ CONTROL_PLANE_URL
191
+ ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
183
192
  for (const baseUrl of controlPlaneUrls) {
184
193
  try {
185
- const url = `${baseUrl.replace(/\/$/, "")}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
194
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
186
195
  const res = await fetch(url, {
187
196
  method: "GET",
188
197
  headers: __spreadValues({
@@ -191,29 +200,41 @@ var init_ConfigFetcher = __esm({
191
200
  });
192
201
  if (res.ok) {
193
202
  const data = await res.json();
194
- if ((data == null ? void 0 : data.success) && ((_a3 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a3.apiKey)) {
203
+ if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
195
204
  const fetchedProjectId = data.projectId || projectId;
196
205
  const config = {
197
206
  projectId: fetchedProjectId,
207
+ tier: data.tier,
208
+ isActive: data.isActive,
209
+ expiresAt: data.expiresAt,
198
210
  vectorDb: {
199
- apiKey: data.vectorDb.apiKey,
211
+ // apiKey is not returned by the config API — it's a server-only secret.
212
+ // The SDK uses local PINECONE_API_KEY if available.
213
+ apiKey: data.vectorDb.apiKey || "",
200
214
  indexName: data.vectorDb.indexName || "retrivora-free",
201
215
  provider: data.vectorDb.provider || "pinecone",
202
- projectId: fetchedProjectId
216
+ projectId: fetchedProjectId,
217
+ namespace: ((_a3 = data.workspace) == null ? void 0 : _a3.namespace) || data.vectorDb.namespace || fetchedProjectId
203
218
  },
204
219
  embedding: {
205
220
  provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
206
221
  model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
207
- baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || "https://llm.retrivora.com/api/v1",
222
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
223
+ baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
208
224
  apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
209
225
  profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
210
226
  },
211
227
  llm: {
212
228
  provider: ((_g2 = data.llm) == null ? void 0 : _g2.provider) || "universal_rest",
213
229
  model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
214
- baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || "https://llm.retrivora.com/api/v1",
230
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
231
+ baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
215
232
  apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
216
233
  profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
234
+ },
235
+ workspace: data.workspace || {
236
+ namespace: fetchedProjectId,
237
+ indexName: data.vectorDb.indexName || "retrivora-free"
217
238
  }
218
239
  };
219
240
  this.cache.set(cacheKey, { config, cachedAt: now });
@@ -332,19 +353,26 @@ var init_PineconeProvider = __esm({
332
353
  })();
333
354
  const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
334
355
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
335
- if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
336
- key = remoteConfig.apiKey;
337
- this.apiKey = key;
356
+ if (remoteConfig) {
357
+ if (remoteConfig.apiKey) {
358
+ key = remoteConfig.apiKey;
359
+ this.apiKey = key;
360
+ }
338
361
  if (remoteConfig.indexName) {
339
362
  this.indexName = remoteConfig.indexName;
340
363
  }
341
364
  if (remoteConfig.projectId) {
342
365
  this.projectId = remoteConfig.projectId;
343
366
  }
367
+ if (remoteConfig.namespace) {
368
+ this.namespace = remoteConfig.namespace;
369
+ }
344
370
  }
345
371
  }
346
372
  if (!key) {
347
- console.warn("[PineconeProvider] Warning: No Pinecone API key available locally or remotely.");
373
+ console.warn(
374
+ "[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
375
+ );
348
376
  return;
349
377
  }
350
378
  this.client = new import_pinecone.Pinecone({ apiKey: key });
@@ -2314,6 +2342,10 @@ var LicenseVerifier = class {
2314
2342
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2315
2343
  const isProduction = process.env.NODE_ENV === "production";
2316
2344
  const now = Date.now();
2345
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2346
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2347
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2348
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2317
2349
  if (licenseKey) {
2318
2350
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2319
2351
  const cached = this.cache.get(cacheKey);
@@ -4709,7 +4741,7 @@ var ConfigValidator = class {
4709
4741
  // package.json
4710
4742
  var package_default = {
4711
4743
  name: "@retrivora-ai/rag-engine",
4712
- version: "2.3.4",
4744
+ version: "2.3.5",
4713
4745
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4714
4746
  author: "Abhinav Alkuchi",
4715
4747
  license: "UNLICENSED",
@@ -10626,7 +10658,7 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
10626
10658
  function enforceLicense(req, config, bodyLicenseKey) {
10627
10659
  const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
10628
10660
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
10629
- const projectId = config.projectId || "my-rag-app";
10661
+ const projectId = config.projectId || "";
10630
10662
  try {
10631
10663
  const payload = LicenseVerifier.verify(licenseKey, projectId);
10632
10664
  return { ok: true, payload };
@@ -11102,7 +11134,7 @@ function createLicenseHandler(configOrPlugin, options) {
11102
11134
  const config = plugin.getConfig();
11103
11135
  const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
11104
11136
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11105
- const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "my-rag-app";
11137
+ const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
11106
11138
  const payload = LicenseVerifier.verify(licenseKey, projectId);
11107
11139
  return import_server.NextResponse.json({
11108
11140
  valid: true,
@@ -140,14 +140,26 @@ var init_BaseVectorProvider = __esm({
140
140
  });
141
141
 
142
142
  // src/core/ConfigFetcher.ts
143
- var ConfigFetcher;
143
+ var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
144
144
  var init_ConfigFetcher = __esm({
145
145
  "src/core/ConfigFetcher.ts"() {
146
146
  "use strict";
147
+ CONTROL_PLANE_URL = "https://www.retrivora.com";
148
+ LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
147
149
  ConfigFetcher = class {
148
150
  // 5-minute in-memory session cache
149
151
  /**
150
- * Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
152
+ * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
153
+ *
154
+ * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
155
+ * The server validates the license against the database and returns:
156
+ * - validity (tier, isActive, expiresAt)
157
+ * - LLM model info
158
+ * - embedding model info
159
+ * - Pinecone index name and workspace/namespace
160
+ *
161
+ * The Pinecone API key is NOT returned (server-only). The SDK uses local
162
+ * PINECONE_API_KEY if available, or vector operations are handled server-side.
151
163
  */
152
164
  static async fetchRemoteConfig(projectId, licenseKey) {
153
165
  var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
@@ -160,14 +172,11 @@ var init_ConfigFetcher = __esm({
160
172
  const controlPlaneUrls = [
161
173
  process.env.RETRIVORA_CONTROL_PLANE_URL,
162
174
  process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
163
- "https://www.retrivora.com",
164
- "https://retrivora.com",
165
- "http://localhost:3000",
166
- "http://localhost:3001"
167
- ].filter(Boolean);
175
+ CONTROL_PLANE_URL
176
+ ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
168
177
  for (const baseUrl of controlPlaneUrls) {
169
178
  try {
170
- const url = `${baseUrl.replace(/\/$/, "")}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
179
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
171
180
  const res = await fetch(url, {
172
181
  method: "GET",
173
182
  headers: __spreadValues({
@@ -176,29 +185,41 @@ var init_ConfigFetcher = __esm({
176
185
  });
177
186
  if (res.ok) {
178
187
  const data = await res.json();
179
- if ((data == null ? void 0 : data.success) && ((_a3 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a3.apiKey)) {
188
+ if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
180
189
  const fetchedProjectId = data.projectId || projectId;
181
190
  const config = {
182
191
  projectId: fetchedProjectId,
192
+ tier: data.tier,
193
+ isActive: data.isActive,
194
+ expiresAt: data.expiresAt,
183
195
  vectorDb: {
184
- apiKey: data.vectorDb.apiKey,
196
+ // apiKey is not returned by the config API — it's a server-only secret.
197
+ // The SDK uses local PINECONE_API_KEY if available.
198
+ apiKey: data.vectorDb.apiKey || "",
185
199
  indexName: data.vectorDb.indexName || "retrivora-free",
186
200
  provider: data.vectorDb.provider || "pinecone",
187
- projectId: fetchedProjectId
201
+ projectId: fetchedProjectId,
202
+ namespace: ((_a3 = data.workspace) == null ? void 0 : _a3.namespace) || data.vectorDb.namespace || fetchedProjectId
188
203
  },
189
204
  embedding: {
190
205
  provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
191
206
  model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
192
- baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || "https://llm.retrivora.com/api/v1",
207
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
208
+ baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
193
209
  apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
194
210
  profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
195
211
  },
196
212
  llm: {
197
213
  provider: ((_g2 = data.llm) == null ? void 0 : _g2.provider) || "universal_rest",
198
214
  model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
199
- baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || "https://llm.retrivora.com/api/v1",
215
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
216
+ baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
200
217
  apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
201
218
  profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
219
+ },
220
+ workspace: data.workspace || {
221
+ namespace: fetchedProjectId,
222
+ indexName: data.vectorDb.indexName || "retrivora-free"
202
223
  }
203
224
  };
204
225
  this.cache.set(cacheKey, { config, cachedAt: now });
@@ -317,19 +338,26 @@ var init_PineconeProvider = __esm({
317
338
  })();
318
339
  const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
319
340
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
320
- if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
321
- key = remoteConfig.apiKey;
322
- this.apiKey = key;
341
+ if (remoteConfig) {
342
+ if (remoteConfig.apiKey) {
343
+ key = remoteConfig.apiKey;
344
+ this.apiKey = key;
345
+ }
323
346
  if (remoteConfig.indexName) {
324
347
  this.indexName = remoteConfig.indexName;
325
348
  }
326
349
  if (remoteConfig.projectId) {
327
350
  this.projectId = remoteConfig.projectId;
328
351
  }
352
+ if (remoteConfig.namespace) {
353
+ this.namespace = remoteConfig.namespace;
354
+ }
329
355
  }
330
356
  }
331
357
  if (!key) {
332
- console.warn("[PineconeProvider] Warning: No Pinecone API key available locally or remotely.");
358
+ console.warn(
359
+ "[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
360
+ );
333
361
  return;
334
362
  }
335
363
  this.client = new Pinecone({ apiKey: key });
@@ -2278,6 +2306,10 @@ var LicenseVerifier = class {
2278
2306
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2279
2307
  const isProduction = process.env.NODE_ENV === "production";
2280
2308
  const now = Date.now();
2309
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2310
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2311
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2312
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2281
2313
  if (licenseKey) {
2282
2314
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2283
2315
  const cached = this.cache.get(cacheKey);
@@ -4673,7 +4705,7 @@ var ConfigValidator = class {
4673
4705
  // package.json
4674
4706
  var package_default = {
4675
4707
  name: "@retrivora-ai/rag-engine",
4676
- version: "2.3.4",
4708
+ version: "2.3.5",
4677
4709
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4678
4710
  author: "Abhinav Alkuchi",
4679
4711
  license: "UNLICENSED",
@@ -10590,7 +10622,7 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
10590
10622
  function enforceLicense(req, config, bodyLicenseKey) {
10591
10623
  const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
10592
10624
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
10593
- const projectId = config.projectId || "my-rag-app";
10625
+ const projectId = config.projectId || "";
10594
10626
  try {
10595
10627
  const payload = LicenseVerifier.verify(licenseKey, projectId);
10596
10628
  return { ok: true, payload };
@@ -11066,7 +11098,7 @@ function createLicenseHandler(configOrPlugin, options) {
11066
11098
  const config = plugin.getConfig();
11067
11099
  const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
11068
11100
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11069
- const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "my-rag-app";
11101
+ const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
11070
11102
  const payload = LicenseVerifier.verify(licenseKey, projectId);
11071
11103
  return NextResponse.json({
11072
11104
  valid: true,
package/dist/index.js CHANGED
@@ -3042,7 +3042,7 @@ function useRagChat(projectId, options = {}) {
3042
3042
  // package.json
3043
3043
  var package_default = {
3044
3044
  name: "@retrivora-ai/rag-engine",
3045
- version: "2.3.4",
3045
+ version: "2.3.5",
3046
3046
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
3047
3047
  author: "Abhinav Alkuchi",
3048
3048
  license: "UNLICENSED",
@@ -3246,6 +3246,10 @@ var LicenseVerifier = class {
3246
3246
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
3247
3247
  const isProduction = process.env.NODE_ENV === "production";
3248
3248
  const now = Date.now();
3249
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
3250
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
3251
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
3252
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
3249
3253
  if (licenseKey) {
3250
3254
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
3251
3255
  const cached = this.cache.get(cacheKey);
@@ -3502,8 +3506,17 @@ var _LicenseValidator = class _LicenseValidator {
3502
3506
  }
3503
3507
  return void 0;
3504
3508
  };
3509
+ console.log("LicenseValidator.validate()", request);
3510
+ console.log("LicenseValidator.validate() - licenseKey", licenseKey);
3511
+ console.log("LicenseValidator.validate() - projectId", projectId);
3512
+ console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
3513
+ console.log("LicenseValidator.validate() - sdk", sdk);
3514
+ console.log("LicenseValidator.validate() - platform", platform);
3515
+ console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
3516
+ console.log("LicenseValidator.validate() - customHeaders", customHeaders);
3505
3517
  const rawKey = licenseKey || getHeader("x-license-key") || ((_a = getHeader("authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3506
3518
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
3519
+ console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
3507
3520
  if (!effectiveLicenseKey) {
3508
3521
  this.purgeCache(effectiveLicenseKey);
3509
3522
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -3539,7 +3552,7 @@ var _LicenseValidator = class _LicenseValidator {
3539
3552
  });
3540
3553
  } catch (err) {
3541
3554
  try {
3542
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3555
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
3543
3556
  const fallbackResp = {
3544
3557
  valid: true,
3545
3558
  licenseStatus: "ACTIVE",
@@ -3558,7 +3571,7 @@ var _LicenseValidator = class _LicenseValidator {
3558
3571
  }
3559
3572
  if (res && !res.ok) {
3560
3573
  try {
3561
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3574
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
3562
3575
  const fallbackResp = {
3563
3576
  valid: true,
3564
3577
  licenseStatus: "ACTIVE",
package/dist/index.mjs CHANGED
@@ -3049,7 +3049,7 @@ function useRagChat(projectId, options = {}) {
3049
3049
  // package.json
3050
3050
  var package_default = {
3051
3051
  name: "@retrivora-ai/rag-engine",
3052
- version: "2.3.4",
3052
+ version: "2.3.5",
3053
3053
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
3054
3054
  author: "Abhinav Alkuchi",
3055
3055
  license: "UNLICENSED",
@@ -3253,6 +3253,10 @@ var LicenseVerifier = class {
3253
3253
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
3254
3254
  const isProduction = process.env.NODE_ENV === "production";
3255
3255
  const now = Date.now();
3256
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
3257
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
3258
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
3259
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
3256
3260
  if (licenseKey) {
3257
3261
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
3258
3262
  const cached = this.cache.get(cacheKey);
@@ -3509,8 +3513,17 @@ var _LicenseValidator = class _LicenseValidator {
3509
3513
  }
3510
3514
  return void 0;
3511
3515
  };
3516
+ console.log("LicenseValidator.validate()", request);
3517
+ console.log("LicenseValidator.validate() - licenseKey", licenseKey);
3518
+ console.log("LicenseValidator.validate() - projectId", projectId);
3519
+ console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
3520
+ console.log("LicenseValidator.validate() - sdk", sdk);
3521
+ console.log("LicenseValidator.validate() - platform", platform);
3522
+ console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
3523
+ console.log("LicenseValidator.validate() - customHeaders", customHeaders);
3512
3524
  const rawKey = licenseKey || getHeader("x-license-key") || ((_a = getHeader("authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3513
3525
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
3526
+ console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
3514
3527
  if (!effectiveLicenseKey) {
3515
3528
  this.purgeCache(effectiveLicenseKey);
3516
3529
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -3546,7 +3559,7 @@ var _LicenseValidator = class _LicenseValidator {
3546
3559
  });
3547
3560
  } catch (err) {
3548
3561
  try {
3549
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3562
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
3550
3563
  const fallbackResp = {
3551
3564
  valid: true,
3552
3565
  licenseStatus: "ACTIVE",
@@ -3565,7 +3578,7 @@ var _LicenseValidator = class _LicenseValidator {
3565
3578
  }
3566
3579
  if (res && !res.ok) {
3567
3580
  try {
3568
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
3581
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
3569
3582
  const fallbackResp = {
3570
3583
  valid: true,
3571
3584
  licenseStatus: "ACTIVE",
package/dist/server.js CHANGED
@@ -155,14 +155,26 @@ var init_BaseVectorProvider = __esm({
155
155
  });
156
156
 
157
157
  // src/core/ConfigFetcher.ts
158
- var ConfigFetcher;
158
+ var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
159
159
  var init_ConfigFetcher = __esm({
160
160
  "src/core/ConfigFetcher.ts"() {
161
161
  "use strict";
162
+ CONTROL_PLANE_URL = "https://www.retrivora.com";
163
+ LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
162
164
  ConfigFetcher = class {
163
165
  // 5-minute in-memory session cache
164
166
  /**
165
- * Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
167
+ * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
168
+ *
169
+ * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
170
+ * The server validates the license against the database and returns:
171
+ * - validity (tier, isActive, expiresAt)
172
+ * - LLM model info
173
+ * - embedding model info
174
+ * - Pinecone index name and workspace/namespace
175
+ *
176
+ * The Pinecone API key is NOT returned (server-only). The SDK uses local
177
+ * PINECONE_API_KEY if available, or vector operations are handled server-side.
166
178
  */
167
179
  static async fetchRemoteConfig(projectId, licenseKey) {
168
180
  var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
@@ -175,14 +187,11 @@ var init_ConfigFetcher = __esm({
175
187
  const controlPlaneUrls = [
176
188
  process.env.RETRIVORA_CONTROL_PLANE_URL,
177
189
  process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
178
- "https://www.retrivora.com",
179
- "https://retrivora.com",
180
- "http://localhost:3000",
181
- "http://localhost:3001"
182
- ].filter(Boolean);
190
+ CONTROL_PLANE_URL
191
+ ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
183
192
  for (const baseUrl of controlPlaneUrls) {
184
193
  try {
185
- const url = `${baseUrl.replace(/\/$/, "")}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
194
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
186
195
  const res = await fetch(url, {
187
196
  method: "GET",
188
197
  headers: __spreadValues({
@@ -191,29 +200,41 @@ var init_ConfigFetcher = __esm({
191
200
  });
192
201
  if (res.ok) {
193
202
  const data = await res.json();
194
- if ((data == null ? void 0 : data.success) && ((_a3 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a3.apiKey)) {
203
+ if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
195
204
  const fetchedProjectId = data.projectId || projectId;
196
205
  const config = {
197
206
  projectId: fetchedProjectId,
207
+ tier: data.tier,
208
+ isActive: data.isActive,
209
+ expiresAt: data.expiresAt,
198
210
  vectorDb: {
199
- apiKey: data.vectorDb.apiKey,
211
+ // apiKey is not returned by the config API — it's a server-only secret.
212
+ // The SDK uses local PINECONE_API_KEY if available.
213
+ apiKey: data.vectorDb.apiKey || "",
200
214
  indexName: data.vectorDb.indexName || "retrivora-free",
201
215
  provider: data.vectorDb.provider || "pinecone",
202
- projectId: fetchedProjectId
216
+ projectId: fetchedProjectId,
217
+ namespace: ((_a3 = data.workspace) == null ? void 0 : _a3.namespace) || data.vectorDb.namespace || fetchedProjectId
203
218
  },
204
219
  embedding: {
205
220
  provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
206
221
  model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
207
- baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || "https://llm.retrivora.com/api/v1",
222
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
223
+ baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
208
224
  apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
209
225
  profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
210
226
  },
211
227
  llm: {
212
228
  provider: ((_g2 = data.llm) == null ? void 0 : _g2.provider) || "universal_rest",
213
229
  model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
214
- baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || "https://llm.retrivora.com/api/v1",
230
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
231
+ baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
215
232
  apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
216
233
  profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
234
+ },
235
+ workspace: data.workspace || {
236
+ namespace: fetchedProjectId,
237
+ indexName: data.vectorDb.indexName || "retrivora-free"
217
238
  }
218
239
  };
219
240
  this.cache.set(cacheKey, { config, cachedAt: now });
@@ -332,19 +353,26 @@ var init_PineconeProvider = __esm({
332
353
  })();
333
354
  const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
334
355
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
335
- if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
336
- key = remoteConfig.apiKey;
337
- this.apiKey = key;
356
+ if (remoteConfig) {
357
+ if (remoteConfig.apiKey) {
358
+ key = remoteConfig.apiKey;
359
+ this.apiKey = key;
360
+ }
338
361
  if (remoteConfig.indexName) {
339
362
  this.indexName = remoteConfig.indexName;
340
363
  }
341
364
  if (remoteConfig.projectId) {
342
365
  this.projectId = remoteConfig.projectId;
343
366
  }
367
+ if (remoteConfig.namespace) {
368
+ this.namespace = remoteConfig.namespace;
369
+ }
344
370
  }
345
371
  }
346
372
  if (!key) {
347
- console.warn("[PineconeProvider] Warning: No Pinecone API key available locally or remotely.");
373
+ console.warn(
374
+ "[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
375
+ );
348
376
  return;
349
377
  }
350
378
  this.client = new import_pinecone.Pinecone({ apiKey: key });
@@ -2385,6 +2413,10 @@ var LicenseVerifier = class {
2385
2413
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2386
2414
  const isProduction = process.env.NODE_ENV === "production";
2387
2415
  const now = Date.now();
2416
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2417
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2418
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2419
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2388
2420
  if (licenseKey) {
2389
2421
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2390
2422
  const cached = this.cache.get(cacheKey);
@@ -4822,7 +4854,7 @@ var ConfigValidator = class {
4822
4854
  // package.json
4823
4855
  var package_default = {
4824
4856
  name: "@retrivora-ai/rag-engine",
4825
- version: "2.3.4",
4857
+ version: "2.3.5",
4826
4858
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4827
4859
  author: "Abhinav Alkuchi",
4828
4860
  license: "UNLICENSED",
@@ -11052,7 +11084,7 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
11052
11084
  function enforceLicense(req, config, bodyLicenseKey) {
11053
11085
  const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
11054
11086
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11055
- const projectId = config.projectId || "my-rag-app";
11087
+ const projectId = config.projectId || "";
11056
11088
  try {
11057
11089
  const payload = LicenseVerifier.verify(licenseKey, projectId);
11058
11090
  return { ok: true, payload };
@@ -11528,7 +11560,7 @@ function createLicenseHandler(configOrPlugin, options) {
11528
11560
  const config = plugin.getConfig();
11529
11561
  const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
11530
11562
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11531
- const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "my-rag-app";
11563
+ const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
11532
11564
  const payload = LicenseVerifier.verify(licenseKey, projectId);
11533
11565
  return import_server.NextResponse.json({
11534
11566
  valid: true,
@@ -12002,8 +12034,17 @@ var _LicenseValidator = class _LicenseValidator {
12002
12034
  }
12003
12035
  return void 0;
12004
12036
  };
12037
+ console.log("LicenseValidator.validate()", request);
12038
+ console.log("LicenseValidator.validate() - licenseKey", licenseKey);
12039
+ console.log("LicenseValidator.validate() - projectId", projectId);
12040
+ console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
12041
+ console.log("LicenseValidator.validate() - sdk", sdk);
12042
+ console.log("LicenseValidator.validate() - platform", platform);
12043
+ console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
12044
+ console.log("LicenseValidator.validate() - customHeaders", customHeaders);
12005
12045
  const rawKey = licenseKey || getHeader("x-license-key") || ((_a3 = getHeader("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
12006
12046
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
12047
+ console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
12007
12048
  if (!effectiveLicenseKey) {
12008
12049
  this.purgeCache(effectiveLicenseKey);
12009
12050
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -12039,7 +12080,7 @@ var _LicenseValidator = class _LicenseValidator {
12039
12080
  });
12040
12081
  } catch (err) {
12041
12082
  try {
12042
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
12083
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12043
12084
  const fallbackResp = {
12044
12085
  valid: true,
12045
12086
  licenseStatus: "ACTIVE",
@@ -12058,7 +12099,7 @@ var _LicenseValidator = class _LicenseValidator {
12058
12099
  }
12059
12100
  if (res && !res.ok) {
12060
12101
  try {
12061
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
12102
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
12062
12103
  const fallbackResp = {
12063
12104
  valid: true,
12064
12105
  licenseStatus: "ACTIVE",
package/dist/server.mjs CHANGED
@@ -140,14 +140,26 @@ var init_BaseVectorProvider = __esm({
140
140
  });
141
141
 
142
142
  // src/core/ConfigFetcher.ts
143
- var ConfigFetcher;
143
+ var CONTROL_PLANE_URL, LLM_PROXY_BASE_URL, ConfigFetcher;
144
144
  var init_ConfigFetcher = __esm({
145
145
  "src/core/ConfigFetcher.ts"() {
146
146
  "use strict";
147
+ CONTROL_PLANE_URL = "https://www.retrivora.com";
148
+ LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
147
149
  ConfigFetcher = class {
148
150
  // 5-minute in-memory session cache
149
151
  /**
150
- * Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
152
+ * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
153
+ *
154
+ * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
155
+ * The server validates the license against the database and returns:
156
+ * - validity (tier, isActive, expiresAt)
157
+ * - LLM model info
158
+ * - embedding model info
159
+ * - Pinecone index name and workspace/namespace
160
+ *
161
+ * The Pinecone API key is NOT returned (server-only). The SDK uses local
162
+ * PINECONE_API_KEY if available, or vector operations are handled server-side.
151
163
  */
152
164
  static async fetchRemoteConfig(projectId, licenseKey) {
153
165
  var _a3, _b, _c, _d, _e, _f, _g2, _h, _i, _j, _k;
@@ -160,14 +172,11 @@ var init_ConfigFetcher = __esm({
160
172
  const controlPlaneUrls = [
161
173
  process.env.RETRIVORA_CONTROL_PLANE_URL,
162
174
  process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
163
- "https://www.retrivora.com",
164
- "https://retrivora.com",
165
- "http://localhost:3000",
166
- "http://localhost:3001"
167
- ].filter(Boolean);
175
+ CONTROL_PLANE_URL
176
+ ].filter((url) => Boolean(url) && !url.includes("localhost") && !url.includes("127.0.0.1")).map((url) => url.replace(/\/$/, ""));
168
177
  for (const baseUrl of controlPlaneUrls) {
169
178
  try {
170
- const url = `${baseUrl.replace(/\/$/, "")}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
179
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ""}`;
171
180
  const res = await fetch(url, {
172
181
  method: "GET",
173
182
  headers: __spreadValues({
@@ -176,29 +185,41 @@ var init_ConfigFetcher = __esm({
176
185
  });
177
186
  if (res.ok) {
178
187
  const data = await res.json();
179
- if ((data == null ? void 0 : data.success) && ((_a3 = data == null ? void 0 : data.vectorDb) == null ? void 0 : _a3.apiKey)) {
188
+ if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
180
189
  const fetchedProjectId = data.projectId || projectId;
181
190
  const config = {
182
191
  projectId: fetchedProjectId,
192
+ tier: data.tier,
193
+ isActive: data.isActive,
194
+ expiresAt: data.expiresAt,
183
195
  vectorDb: {
184
- apiKey: data.vectorDb.apiKey,
196
+ // apiKey is not returned by the config API — it's a server-only secret.
197
+ // The SDK uses local PINECONE_API_KEY if available.
198
+ apiKey: data.vectorDb.apiKey || "",
185
199
  indexName: data.vectorDb.indexName || "retrivora-free",
186
200
  provider: data.vectorDb.provider || "pinecone",
187
- projectId: fetchedProjectId
201
+ projectId: fetchedProjectId,
202
+ namespace: ((_a3 = data.workspace) == null ? void 0 : _a3.namespace) || data.vectorDb.namespace || fetchedProjectId
188
203
  },
189
204
  embedding: {
190
205
  provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
191
206
  model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
192
- baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || "https://llm.retrivora.com/api/v1",
207
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
208
+ baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
193
209
  apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
194
210
  profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
195
211
  },
196
212
  llm: {
197
213
  provider: ((_g2 = data.llm) == null ? void 0 : _g2.provider) || "universal_rest",
198
214
  model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
199
- baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || "https://llm.retrivora.com/api/v1",
215
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
216
+ baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
200
217
  apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
201
218
  profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
219
+ },
220
+ workspace: data.workspace || {
221
+ namespace: fetchedProjectId,
222
+ indexName: data.vectorDb.indexName || "retrivora-free"
202
223
  }
203
224
  };
204
225
  this.cache.set(cacheKey, { config, cachedAt: now });
@@ -317,19 +338,26 @@ var init_PineconeProvider = __esm({
317
338
  })();
318
339
  const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || "default";
319
340
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
320
- if (remoteConfig == null ? void 0 : remoteConfig.apiKey) {
321
- key = remoteConfig.apiKey;
322
- this.apiKey = key;
341
+ if (remoteConfig) {
342
+ if (remoteConfig.apiKey) {
343
+ key = remoteConfig.apiKey;
344
+ this.apiKey = key;
345
+ }
323
346
  if (remoteConfig.indexName) {
324
347
  this.indexName = remoteConfig.indexName;
325
348
  }
326
349
  if (remoteConfig.projectId) {
327
350
  this.projectId = remoteConfig.projectId;
328
351
  }
352
+ if (remoteConfig.namespace) {
353
+ this.namespace = remoteConfig.namespace;
354
+ }
329
355
  }
330
356
  }
331
357
  if (!key) {
332
- console.warn("[PineconeProvider] Warning: No Pinecone API key available locally or remotely.");
358
+ console.warn(
359
+ "[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
360
+ );
333
361
  return;
334
362
  }
335
363
  this.client = new Pinecone({ apiKey: key });
@@ -2285,6 +2313,10 @@ var LicenseVerifier = class {
2285
2313
  static verify(licenseKey, currentProjectId, provider, publicKeyOverride) {
2286
2314
  const isProduction = process.env.NODE_ENV === "production";
2287
2315
  const now = Date.now();
2316
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
2317
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
2318
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
2319
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
2288
2320
  if (licenseKey) {
2289
2321
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ""}:${publicKeyOverride || ""}`;
2290
2322
  const cached = this.cache.get(cacheKey);
@@ -4722,7 +4754,7 @@ var ConfigValidator = class {
4722
4754
  // package.json
4723
4755
  var package_default = {
4724
4756
  name: "@retrivora-ai/rag-engine",
4725
- version: "2.3.4",
4757
+ version: "2.3.5",
4726
4758
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
4727
4759
  author: "Abhinav Alkuchi",
4728
4760
  license: "UNLICENSED",
@@ -10952,7 +10984,7 @@ function resolveLicenseKey(req, config, bodyLicenseKey) {
10952
10984
  function enforceLicense(req, config, bodyLicenseKey) {
10953
10985
  const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
10954
10986
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
10955
- const projectId = config.projectId || "my-rag-app";
10987
+ const projectId = config.projectId || "";
10956
10988
  try {
10957
10989
  const payload = LicenseVerifier.verify(licenseKey, projectId);
10958
10990
  return { ok: true, payload };
@@ -11428,7 +11460,7 @@ function createLicenseHandler(configOrPlugin, options) {
11428
11460
  const config = plugin.getConfig();
11429
11461
  const rawKey = req.headers.get("x-license-key") || (body == null ? void 0 : body.licenseKey) || ((_a3 = req.headers.get("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || config.licenseKey || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || "";
11430
11462
  const licenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11431
- const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "my-rag-app";
11463
+ const projectId = (body == null ? void 0 : body.projectId) || config.projectId || "";
11432
11464
  const payload = LicenseVerifier.verify(licenseKey, projectId);
11433
11465
  return NextResponse.json({
11434
11466
  valid: true,
@@ -11902,8 +11934,17 @@ var _LicenseValidator = class _LicenseValidator {
11902
11934
  }
11903
11935
  return void 0;
11904
11936
  };
11937
+ console.log("LicenseValidator.validate()", request);
11938
+ console.log("LicenseValidator.validate() - licenseKey", licenseKey);
11939
+ console.log("LicenseValidator.validate() - projectId", projectId);
11940
+ console.log("LicenseValidator.validate() - sdkVersion", sdkVersion);
11941
+ console.log("LicenseValidator.validate() - sdk", sdk);
11942
+ console.log("LicenseValidator.validate() - platform", platform);
11943
+ console.log("LicenseValidator.validate() - retrivoraApiBase", retrivoraApiBase);
11944
+ console.log("LicenseValidator.validate() - customHeaders", customHeaders);
11905
11945
  const rawKey = licenseKey || getHeader("x-license-key") || ((_a3 = getHeader("authorization")) == null ? void 0 : _a3.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
11906
11946
  const effectiveLicenseKey = (rawKey || "").trim().replace(/^["']|["']$/g, "").trim();
11947
+ console.log("LicenseValidator.validate() - effectiveLicenseKey", effectiveLicenseKey);
11907
11948
  if (!effectiveLicenseKey) {
11908
11949
  this.purgeCache(effectiveLicenseKey);
11909
11950
  throw new LicenseValidationError("Missing RETRIVORA_LICENSE_KEY in request. Set NEXT_PUBLIC_RETRIVORA_LICENSE_KEY in your environment or pass licenseKey as a prop.");
@@ -11939,7 +11980,7 @@ var _LicenseValidator = class _LicenseValidator {
11939
11980
  });
11940
11981
  } catch (err) {
11941
11982
  try {
11942
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
11983
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
11943
11984
  const fallbackResp = {
11944
11985
  valid: true,
11945
11986
  licenseStatus: "ACTIVE",
@@ -11958,7 +11999,7 @@ var _LicenseValidator = class _LicenseValidator {
11958
11999
  }
11959
12000
  if (res && !res.ok) {
11960
12001
  try {
11961
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "my-rag-app");
12002
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || "");
11962
12003
  const fallbackResp = {
11963
12004
  valid: true,
11964
12005
  licenseStatus: "ACTIVE",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.3.4",
3
+ "version": "2.3.5",
4
4
  "description": "Retrivora AI is a plug-and-play AI engine for RAG chat experiences — generic vector DB + LLM provider, embeddable or standalone.",
5
5
  "author": "Abhinav Alkuchi",
6
6
  "license": "UNLICENSED",
@@ -136,4 +136,4 @@
136
136
  "tsup": "^8.5.1",
137
137
  "typescript": "^5"
138
138
  }
139
- }
139
+ }
@@ -1,6 +1,11 @@
1
1
  /**
2
2
  * ConfigFetcher.ts — Dynamically fetches project credentials from Retrivora Control Plane
3
3
  * without hardcoding plain-text master keys in NPM package binaries.
4
+ *
5
+ * SECURITY: The SDK must ONLY call the Retrivora Control Plane at https://www.retrivora.com.
6
+ * It must never call the end user's own localhost or any other endpoint.
7
+ * LLM and embedding calls are proxied through https://www.retrivora.com/api/v1 which
8
+ * forwards to https://llm.retrivora.com with the server-side LITELLM_MASTER_KEY.
4
9
  */
5
10
 
6
11
  export interface RemoteVectorConfig {
@@ -8,6 +13,7 @@ export interface RemoteVectorConfig {
8
13
  indexName: string;
9
14
  provider: string;
10
15
  projectId?: string;
16
+ namespace?: string;
11
17
  }
12
18
 
13
19
  export interface RemoteEmbeddingConfig {
@@ -28,20 +34,51 @@ export interface RemoteLLMConfig {
28
34
 
29
35
  export interface RemoteConfig {
30
36
  projectId?: string;
37
+ tier?: string;
38
+ isActive?: boolean;
39
+ expiresAt?: string;
31
40
  vectorDb: RemoteVectorConfig;
32
41
  embedding: RemoteEmbeddingConfig;
33
42
  llm: RemoteLLMConfig;
43
+ workspace?: {
44
+ namespace: string;
45
+ indexName: string;
46
+ };
34
47
  }
35
48
 
36
49
  // Legacy alias
37
50
  export type { RemoteVectorConfig as RemoteConfig_ };
38
51
 
52
+ /**
53
+ * The single source of truth for the Retrivora Control Plane URL.
54
+ * The SDK must only communicate with this endpoint — never with the end user's localhost.
55
+ */
56
+ const CONTROL_PLANE_URL = 'https://www.retrivora.com';
57
+
58
+ /**
59
+ * The LLM/Embedding proxy gateway. All LLM and embedding requests are routed
60
+ * through https://www.retrivora.com/api/v1, which validates the license key and
61
+ * forwards to https://llm.retrivora.com with the server-side master key.
62
+ * End users never need to know about llm.retrivora.com directly.
63
+ */
64
+ const LLM_PROXY_BASE_URL = 'https://www.retrivora.com/api/v1';
65
+
39
66
  export class ConfigFetcher {
40
67
  private static cache = new Map<string, { config: RemoteConfig; cachedAt: number }>();
41
68
  private static readonly TTL_MS = 5 * 60 * 1000; // 5-minute in-memory session cache
42
69
 
43
70
  /**
44
- * Fetch full project configuration (vectorDb + embedding + llm) from Retrivora Control Plane.
71
+ * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
72
+ *
73
+ * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
74
+ * The server validates the license against the database and returns:
75
+ * - validity (tier, isActive, expiresAt)
76
+ * - LLM model info
77
+ * - embedding model info
78
+ * - Pinecone index name and workspace/namespace
79
+ *
80
+ * The Pinecone API key is NOT returned (server-only). The SDK uses local
81
+ * PINECONE_API_KEY if available, or vector operations are handled server-side.
45
82
  */
46
83
  static async fetchRemoteConfig(projectId: string, licenseKey?: string): Promise<RemoteConfig | null> {
47
84
  const cacheKey = `${projectId}:${licenseKey || ''}`;
@@ -52,18 +89,20 @@ export class ConfigFetcher {
52
89
  return cached.config;
53
90
  }
54
91
 
92
+ // SECURITY: Only call the Retrivora Control Plane — never localhost or any other endpoint.
93
+ // Environment overrides are allowed for explicit server-side configuration, but
94
+ // localhost URLs are explicitly excluded to prevent calling the end user's own app.
55
95
  const controlPlaneUrls = [
56
96
  process.env.RETRIVORA_CONTROL_PLANE_URL,
57
97
  process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
58
- 'https://www.retrivora.com',
59
- 'https://retrivora.com',
60
- 'http://localhost:3000',
61
- 'http://localhost:3001',
62
- ].filter(Boolean) as string[];
98
+ CONTROL_PLANE_URL,
99
+ ]
100
+ .filter((url): url is string => Boolean(url) && !url!.includes('localhost') && !url!.includes('127.0.0.1'))
101
+ .map((url) => url.replace(/\/$/, ''));
63
102
 
64
103
  for (const baseUrl of controlPlaneUrls) {
65
104
  try {
66
- const url = `${baseUrl.replace(/\/$/, '')}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ''}`;
105
+ const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}${licenseKey ? `&licenseKey=${encodeURIComponent(licenseKey)}` : ''}`;
67
106
  const res = await fetch(url, {
68
107
  method: 'GET',
69
108
  headers: {
@@ -74,30 +113,44 @@ export class ConfigFetcher {
74
113
 
75
114
  if (res.ok) {
76
115
  const data = await res.json();
77
- if (data?.success && data?.vectorDb?.apiKey) {
116
+ // NOTE: The config API intentionally does NOT return vectorDb.apiKey (server-only secret).
117
+ // We check for data.success and data.vectorDb presence instead.
118
+ if (data?.success && data?.vectorDb) {
78
119
  const fetchedProjectId = data.projectId || projectId;
79
120
  const config: RemoteConfig = {
80
121
  projectId: fetchedProjectId,
122
+ tier: data.tier,
123
+ isActive: data.isActive,
124
+ expiresAt: data.expiresAt,
81
125
  vectorDb: {
82
- apiKey: data.vectorDb.apiKey,
126
+ // apiKey is not returned by the config API — it's a server-only secret.
127
+ // The SDK uses local PINECONE_API_KEY if available.
128
+ apiKey: data.vectorDb.apiKey || '',
83
129
  indexName: data.vectorDb.indexName || 'retrivora-free',
84
130
  provider: data.vectorDb.provider || 'pinecone',
85
131
  projectId: fetchedProjectId,
132
+ namespace: data.workspace?.namespace || data.vectorDb.namespace || fetchedProjectId,
86
133
  },
87
134
  embedding: {
88
135
  provider: data.embedding?.provider || 'universal_rest',
89
136
  model: data.embedding?.model || 'text-embedding-004',
90
- baseUrl: data.embedding?.baseUrl || 'https://llm.retrivora.com/api/v1',
137
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
138
+ baseUrl: data.embedding?.baseUrl || LLM_PROXY_BASE_URL,
91
139
  apiKey: data.embedding?.apiKey || licenseKey || '',
92
140
  profile: data.embedding?.profile || 'litellm',
93
141
  },
94
142
  llm: {
95
143
  provider: data.llm?.provider || 'universal_rest',
96
144
  model: data.llm?.model || 'llama-3.1-8b-instant',
97
- baseUrl: data.llm?.baseUrl || 'https://llm.retrivora.com/api/v1',
145
+ // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
146
+ baseUrl: data.llm?.baseUrl || LLM_PROXY_BASE_URL,
98
147
  apiKey: data.llm?.apiKey || licenseKey || '',
99
148
  profile: data.llm?.profile || 'litellm',
100
149
  },
150
+ workspace: data.workspace || {
151
+ namespace: fetchedProjectId,
152
+ indexName: data.vectorDb.indexName || 'retrivora-free',
153
+ },
101
154
  };
102
155
  this.cache.set(cacheKey, { config, cachedAt: now });
103
156
  return config;
@@ -139,16 +139,25 @@ export class LicenseValidator {
139
139
  return undefined;
140
140
  };
141
141
 
142
+ console.log('LicenseValidator.validate()', request);
143
+ console.log('LicenseValidator.validate() - licenseKey', licenseKey);
144
+ console.log('LicenseValidator.validate() - projectId', projectId);
145
+ console.log('LicenseValidator.validate() - sdkVersion', sdkVersion);
146
+ console.log('LicenseValidator.validate() - sdk', sdk);
147
+ console.log('LicenseValidator.validate() - platform', platform);
148
+ console.log('LicenseValidator.validate() - retrivoraApiBase', retrivoraApiBase);
149
+ console.log('LicenseValidator.validate() - customHeaders', customHeaders);
142
150
  const rawKey =
143
- licenseKey ||
144
- getHeader('x-license-key') ||
145
- getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
146
- (typeof process !== 'undefined'
147
- ? (process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY)
148
- : '') ||
151
+ licenseKey ||
152
+ getHeader('x-license-key') ||
153
+ getHeader('authorization')?.replace(/^Bearer\s+/i, '') ||
154
+ (typeof process !== 'undefined'
155
+ ? (process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY)
156
+ : '') ||
149
157
  '';
150
-
151
- const effectiveLicenseKey = (rawKey || '').trim().replace(/^["']|["']$/g, '').trim();
158
+
159
+ const effectiveLicenseKey = (rawKey || '').trim().replace(/^["']|["']$/g, '').trim();
160
+ console.log('LicenseValidator.validate() - effectiveLicenseKey', effectiveLicenseKey);
152
161
 
153
162
  if (!effectiveLicenseKey) {
154
163
  this.purgeCache(effectiveLicenseKey);
@@ -192,7 +201,7 @@ export class LicenseValidator {
192
201
  } catch (err: any) {
193
202
  // Fallback: If network error occurs, verify locally via RSA LicenseVerifier
194
203
  try {
195
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || 'my-rag-app');
204
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || '');
196
205
  const fallbackResp: LicenseValidationResponse = {
197
206
  valid: true,
198
207
  licenseStatus: 'ACTIVE',
@@ -213,7 +222,7 @@ export class LicenseValidator {
213
222
  if (res && !res.ok) {
214
223
  // Attempt local verification fallback if API route returned 404 or non-OK response
215
224
  try {
216
- const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || 'my-rag-app');
225
+ const payload = LicenseVerifier.verify(effectiveLicenseKey, projectId || '');
217
226
  const fallbackResp: LicenseValidationResponse = {
218
227
  valid: true,
219
228
  licenseStatus: 'ACTIVE',
@@ -76,6 +76,10 @@ gQIDAQAB
76
76
  const isProduction = process.env.NODE_ENV === 'production';
77
77
  const now = Date.now();
78
78
 
79
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - licenseKey`, licenseKey);
80
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - currentProjectId`, currentProjectId);
81
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - provider`, provider);
82
+ console.log(`[Retrivora SDK] LicenseVerifier.verify() - publicKeyOverride`, publicKeyOverride);
79
83
  // Check verification cache to bypass crypto computations on hot paths
80
84
  if (licenseKey) {
81
85
  const cacheKey = `${licenseKey}:${currentProjectId}:${provider || ''}:${publicKeyOverride || ''}`;
@@ -213,7 +213,7 @@ function enforceLicense(
213
213
  ): { ok: true; payload: LicensePayload } | { ok: false; response: Response } {
214
214
  const rawKey = resolveLicenseKey(req, config, bodyLicenseKey);
215
215
  const licenseKey = (rawKey || '').trim().replace(/^["']|["']$/g, '').trim();
216
- const projectId = config.projectId || 'my-rag-app';
216
+ const projectId = config.projectId || '';
217
217
 
218
218
  try {
219
219
  const payload = LicenseVerifier.verify(licenseKey, projectId);
@@ -935,7 +935,7 @@ export function createLicenseHandler(
935
935
 
936
936
  const licenseKey = (rawKey || '').trim().replace(/^["']|["']$/g, '').trim();
937
937
 
938
- const projectId = body?.projectId || config.projectId || 'my-rag-app';
938
+ const projectId = body?.projectId || config.projectId || '';
939
939
 
940
940
  const payload = LicenseVerifier.verify(licenseKey, projectId);
941
941
 
@@ -104,20 +104,33 @@ export class PineconeProvider extends BaseVectorProvider {
104
104
  const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || jwtProjectId || this.projectId || 'default';
105
105
 
106
106
  const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
107
- if (remoteConfig?.apiKey) {
108
- key = remoteConfig.apiKey;
109
- this.apiKey = key;
107
+
108
+ // The config API does NOT return the Pinecone API key (server-only secret).
109
+ // We still use the remote config for indexName and namespace/workspace info.
110
+ if (remoteConfig) {
111
+ if (remoteConfig.apiKey) {
112
+ key = remoteConfig.apiKey;
113
+ this.apiKey = key;
114
+ }
110
115
  if (remoteConfig.indexName) {
111
116
  this.indexName = remoteConfig.indexName;
112
117
  }
113
118
  if (remoteConfig.projectId) {
114
119
  this.projectId = remoteConfig.projectId;
115
120
  }
121
+ if (remoteConfig.namespace) {
122
+ // Store namespace for use in queries — ensures workspace isolation
123
+ (this as any).namespace = remoteConfig.namespace;
124
+ }
116
125
  }
117
126
  }
118
127
 
119
128
  if (!key) {
120
- console.warn('[PineconeProvider] Warning: No Pinecone API key available locally or remotely.');
129
+ console.warn(
130
+ '[PineconeProvider] Warning: No Pinecone API key available. ' +
131
+ 'Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane ' +
132
+ '(https://www.retrivora.com) is reachable for proxy-based vector operations.'
133
+ );
121
134
  return;
122
135
  }
123
136