@retrivora-ai/rag-engine 2.4.7 → 2.4.8

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.
@@ -318,7 +318,7 @@ var init_package = __esm({
318
318
  "package.json"() {
319
319
  package_default = {
320
320
  name: "@retrivora-ai/rag-engine",
321
- version: "2.4.7",
321
+ version: "2.4.8",
322
322
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
323
323
  author: "Abhinav Alkuchi",
324
324
  license: "UNLICENSED",
@@ -525,10 +525,10 @@ var init_ConfigFetcher = __esm({
525
525
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
526
526
  const res = await fetch(url, {
527
527
  method: "GET",
528
- headers: __spreadValues({
528
+ headers: __spreadValues(__spreadValues({
529
529
  "Content-Type": "application/json",
530
530
  "x-sdk-version": SDK_VERSION
531
- }, licenseKey ? { "x-license-key": licenseKey } : {})
531
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
532
532
  });
533
533
  if (!res.ok) {
534
534
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -580,9 +580,9 @@ var init_ConfigFetcher = __esm({
580
580
  const credUrl = `${baseUrl}/api/v1/credentials`;
581
581
  const credRes = await fetch(credUrl, {
582
582
  method: "POST",
583
- headers: {
583
+ headers: __spreadValues(__spreadValues({
584
584
  "Content-Type": "application/json"
585
- },
585
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
586
586
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
587
587
  });
588
588
  if (credRes.ok) {
@@ -768,7 +768,10 @@ var init_PineconeProvider = __esm({
768
768
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
769
769
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
770
770
  method: "POST",
771
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
771
+ headers: __spreadValues({
772
+ "Content-Type": "application/json",
773
+ "x-license-key": this.licenseKey
774
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
772
775
  body: JSON.stringify({
773
776
  projectId: this.projectId,
774
777
  indexName: this.indexName,
@@ -803,7 +806,10 @@ var init_PineconeProvider = __esm({
803
806
  });
804
807
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
805
808
  method: "POST",
806
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
809
+ headers: __spreadValues({
810
+ "Content-Type": "application/json",
811
+ "x-license-key": this.licenseKey
812
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
807
813
  body: JSON.stringify({
808
814
  projectId: this.projectId,
809
815
  indexName: this.indexName,
@@ -835,7 +841,10 @@ var init_PineconeProvider = __esm({
835
841
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
836
842
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
837
843
  method: "POST",
838
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
844
+ headers: __spreadValues({
845
+ "Content-Type": "application/json",
846
+ "x-license-key": this.licenseKey
847
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
839
848
  body: JSON.stringify({
840
849
  projectId: this.projectId,
841
850
  indexName: this.indexName,
@@ -312,7 +312,7 @@ var init_package = __esm({
312
312
  "package.json"() {
313
313
  package_default = {
314
314
  name: "@retrivora-ai/rag-engine",
315
- version: "2.4.7",
315
+ version: "2.4.8",
316
316
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
317
317
  author: "Abhinav Alkuchi",
318
318
  license: "UNLICENSED",
@@ -519,10 +519,10 @@ var init_ConfigFetcher = __esm({
519
519
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
520
520
  const res = await fetch(url, {
521
521
  method: "GET",
522
- headers: __spreadValues({
522
+ headers: __spreadValues(__spreadValues({
523
523
  "Content-Type": "application/json",
524
524
  "x-sdk-version": SDK_VERSION
525
- }, licenseKey ? { "x-license-key": licenseKey } : {})
525
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
526
526
  });
527
527
  if (!res.ok) {
528
528
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -574,9 +574,9 @@ var init_ConfigFetcher = __esm({
574
574
  const credUrl = `${baseUrl}/api/v1/credentials`;
575
575
  const credRes = await fetch(credUrl, {
576
576
  method: "POST",
577
- headers: {
577
+ headers: __spreadValues(__spreadValues({
578
578
  "Content-Type": "application/json"
579
- },
579
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
580
580
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
581
581
  });
582
582
  if (credRes.ok) {
@@ -762,7 +762,10 @@ var init_PineconeProvider = __esm({
762
762
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
763
763
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
764
764
  method: "POST",
765
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
765
+ headers: __spreadValues({
766
+ "Content-Type": "application/json",
767
+ "x-license-key": this.licenseKey
768
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
766
769
  body: JSON.stringify({
767
770
  projectId: this.projectId,
768
771
  indexName: this.indexName,
@@ -797,7 +800,10 @@ var init_PineconeProvider = __esm({
797
800
  });
798
801
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
799
802
  method: "POST",
800
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
803
+ headers: __spreadValues({
804
+ "Content-Type": "application/json",
805
+ "x-license-key": this.licenseKey
806
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
801
807
  body: JSON.stringify({
802
808
  projectId: this.projectId,
803
809
  indexName: this.indexName,
@@ -829,7 +835,10 @@ var init_PineconeProvider = __esm({
829
835
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
830
836
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
831
837
  method: "POST",
832
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
838
+ headers: __spreadValues({
839
+ "Content-Type": "application/json",
840
+ "x-license-key": this.licenseKey
841
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
833
842
  body: JSON.stringify({
834
843
  projectId: this.projectId,
835
844
  indexName: this.indexName,
package/dist/index.js CHANGED
@@ -356,7 +356,7 @@ function projectSettingsToUiConfig(settings) {
356
356
  // package.json
357
357
  var package_default = {
358
358
  name: "@retrivora-ai/rag-engine",
359
- version: "2.4.7",
359
+ version: "2.4.8",
360
360
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
361
361
  author: "Abhinav Alkuchi",
362
362
  license: "UNLICENSED",
@@ -548,10 +548,10 @@ var ConfigFetcher = class {
548
548
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
549
549
  const res = await fetch(url, {
550
550
  method: "GET",
551
- headers: __spreadValues({
551
+ headers: __spreadValues(__spreadValues({
552
552
  "Content-Type": "application/json",
553
553
  "x-sdk-version": SDK_VERSION
554
- }, licenseKey ? { "x-license-key": licenseKey } : {})
554
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
555
555
  });
556
556
  if (!res.ok) {
557
557
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -603,9 +603,9 @@ var ConfigFetcher = class {
603
603
  const credUrl = `${baseUrl}/api/v1/credentials`;
604
604
  const credRes = await fetch(credUrl, {
605
605
  method: "POST",
606
- headers: {
606
+ headers: __spreadValues(__spreadValues({
607
607
  "Content-Type": "application/json"
608
- },
608
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
609
609
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
610
610
  });
611
611
  if (credRes.ok) {
@@ -828,7 +828,7 @@ function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploadComple
828
828
  formData.append("dimension", dimension.toString());
829
829
  const apiBase = retrivoraApiBase || configuredApiBase || "https://www.retrivora.com/api/retrivora";
830
830
  const primaryUrl = uploadUrl || `${apiBase.replace(/\/$/, "")}/upload`;
831
- const uploadHeaders = __spreadValues(__spreadValues({}, configHeaders || {}), licenseKey ? { "x-license-key": licenseKey } : {});
831
+ const uploadHeaders = __spreadValues(__spreadValues(__spreadValues({}, configHeaders || {}), licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {});
832
832
  try {
833
833
  let response = await fetch(primaryUrl, {
834
834
  method: "POST",
@@ -2599,8 +2599,8 @@ function UIBlockRenderer({
2599
2599
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
2600
2600
  ProductCarousel,
2601
2601
  {
2602
- products: items.map((item) => ({
2603
- id: item.id || `carousel_${Math.random()}`,
2602
+ products: items.map((item, idx) => ({
2603
+ id: item.id || `carousel_${idx}`,
2604
2604
  name: item.name || item.title || "Product",
2605
2605
  brand: item.brand,
2606
2606
  price: item.price,
@@ -3579,12 +3579,45 @@ function useRagChat(projectId, options = {}) {
3579
3579
  const lastInputRef = (0, import_react12.useRef)("");
3580
3580
  const messagesRef = (0, import_react12.useRef)(messages);
3581
3581
  const abortControllerRef = (0, import_react12.useRef)(null);
3582
+ const errorTimeoutRef = (0, import_react12.useRef)(null);
3583
+ const resolvedLicenseKey = (0, import_react12.useMemo)(() => {
3584
+ var _a;
3585
+ const getHeader = (headersObj, name) => {
3586
+ if (!headersObj) return void 0;
3587
+ const target = name.toLowerCase();
3588
+ for (const [k, v] of Object.entries(headersObj)) {
3589
+ if (k.toLowerCase() === target) return v;
3590
+ }
3591
+ return void 0;
3592
+ };
3593
+ return options.licenseKey || getHeader(options.headers, "x-license-key") || ((_a = getHeader(options.headers, "authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3594
+ }, [options.licenseKey, options.headers]);
3595
+ const setTemporaryError = (0, import_react12.useCallback)((msg) => {
3596
+ setError(msg);
3597
+ if (errorTimeoutRef.current) {
3598
+ clearTimeout(errorTimeoutRef.current);
3599
+ errorTimeoutRef.current = null;
3600
+ }
3601
+ if (msg) {
3602
+ errorTimeoutRef.current = setTimeout(() => {
3603
+ setError(null);
3604
+ errorTimeoutRef.current = null;
3605
+ }, 5e3);
3606
+ }
3607
+ }, []);
3608
+ (0, import_react12.useEffect)(() => {
3609
+ return () => {
3610
+ if (errorTimeoutRef.current) {
3611
+ clearTimeout(errorTimeoutRef.current);
3612
+ }
3613
+ };
3614
+ }, []);
3582
3615
  (0, import_react12.useEffect)(() => {
3583
3616
  messagesRef.current = messages;
3584
3617
  }, [messages]);
3585
3618
  const sendMessage = (0, import_react12.useCallback)(
3586
3619
  async (text, opts) => {
3587
- var _a, _b, _c, _d, _e, _f;
3620
+ var _a, _b, _c, _d, _e;
3588
3621
  const trimmed = text.trim();
3589
3622
  if (!trimmed || isLoading) return;
3590
3623
  lastInputRef.current = trimmed;
@@ -3616,18 +3649,9 @@ function useRagChat(projectId, options = {}) {
3616
3649
  messageId: assistantMessageId,
3617
3650
  userMessageId: userMsgId
3618
3651
  });
3619
- const getHeader = (headersObj, name) => {
3620
- if (!headersObj) return void 0;
3621
- const target = name.toLowerCase();
3622
- for (const [k, v] of Object.entries(headersObj)) {
3623
- if (k.toLowerCase() === target) return v;
3624
- }
3625
- return void 0;
3626
- };
3627
- const resolvedLicenseKey = options.licenseKey || getHeader(options.headers, "x-license-key") || ((_b = getHeader(options.headers, "authorization")) == null ? void 0 : _b.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3628
- const fetchHeaders = __spreadValues(__spreadValues({
3652
+ const fetchHeaders = __spreadValues(__spreadValues(__spreadValues({
3629
3653
  "Content-Type": "application/json"
3630
- }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), options.headers || {});
3654
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {});
3631
3655
  let response = await fetch(primaryUrl, {
3632
3656
  method: "POST",
3633
3657
  headers: fetchHeaders,
@@ -3635,7 +3659,7 @@ function useRagChat(projectId, options = {}) {
3635
3659
  body: payloadBody
3636
3660
  });
3637
3661
  if (response.status === 404 && !apiUrl && primaryUrl !== "/api/chat") {
3638
- console.warn(`[Retrivora SDK] \u26A0\uFE0F Chat endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/chat"...`);
3662
+ console.warn(`[Retrivora SDK] Chat endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/chat"...`);
3639
3663
  response = await fetch("/api/chat", {
3640
3664
  method: "POST",
3641
3665
  headers: fetchHeaders,
@@ -3645,10 +3669,10 @@ function useRagChat(projectId, options = {}) {
3645
3669
  }
3646
3670
  if (!response.ok) {
3647
3671
  const errorData = await response.json().catch(() => ({}));
3648
- if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_c = errorData.error) == null ? void 0 : _c.type) === "license_revoked") {
3672
+ if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_b = errorData.error) == null ? void 0 : _b.type) === "license_revoked") {
3649
3673
  throw new Error("Your Retrivora license is no longer valid. Please contact your administrator or obtain a valid license key.");
3650
3674
  }
3651
- throw new Error(((_d = errorData.error) == null ? void 0 : _d.message) || errorData.error || `Server returned ${response.status}`);
3675
+ throw new Error(((_c = errorData.error) == null ? void 0 : _c.message) || errorData.error || `Server returned ${response.status}`);
3652
3676
  }
3653
3677
  if (!response.body) {
3654
3678
  throw new Error("No response body received from server");
@@ -3712,7 +3736,7 @@ function useRagChat(projectId, options = {}) {
3712
3736
  pendingThinkingRef.current = thinkingContent;
3713
3737
  scheduleFlush(assistantMessageId);
3714
3738
  } else if (frame.type === "metadata") {
3715
- sources = (_e = frame.sources) != null ? _e : [];
3739
+ sources = (_d = frame.sources) != null ? _d : [];
3716
3740
  thinkingMs = frame.thinkingMs;
3717
3741
  } else if (frame.type === "ui_transformation") {
3718
3742
  uiTransformation = frame.data;
@@ -3728,7 +3752,7 @@ function useRagChat(projectId, options = {}) {
3728
3752
  if (frame.type === "text" && frame.text) assistantContent += frame.text;
3729
3753
  else if (frame.type === "thinking" && frame.text) thinkingContent += frame.text;
3730
3754
  else if (frame.type === "metadata") {
3731
- sources = (_f = frame.sources) != null ? _f : [];
3755
+ sources = (_e = frame.sources) != null ? _e : [];
3732
3756
  thinkingMs = frame.thinkingMs;
3733
3757
  } else if (frame.type === "observability") trace = frame.data;
3734
3758
  }
@@ -3756,14 +3780,14 @@ function useRagChat(projectId, options = {}) {
3756
3780
  if (msg.includes("403") || msg.toLowerCase().includes("license") || msg.toLowerCase().includes("revoked") || msg.toLowerCase().includes("terminated")) {
3757
3781
  msg = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
3758
3782
  }
3759
- setError(msg);
3783
+ setTemporaryError(msg);
3760
3784
  onError == null ? void 0 : onError(msg);
3761
3785
  } finally {
3762
3786
  setIsLoading(false);
3763
3787
  abortControllerRef.current = null;
3764
3788
  }
3765
3789
  },
3766
- [apiUrl, isLoading, namespace, onError, onReply, projectId, setMessages, options.headers, options.sessionId]
3790
+ [apiUrl, isLoading, namespace, onError, onReply, projectId, setMessages, options.headers, options.sessionId, setTemporaryError, resolvedLicenseKey]
3767
3791
  );
3768
3792
  const clear = (0, import_react12.useCallback)(() => {
3769
3793
  setMessages([]);
@@ -3789,8 +3813,16 @@ function useRagChat(projectId, options = {}) {
3789
3813
  setIsLoading(true);
3790
3814
  setError(null);
3791
3815
  try {
3792
- const res = await fetch(`${retrivoraApiBase}/history?sessionId=${encodeURIComponent(sessionId)}`);
3793
- if (!res.ok) throw new Error(`Failed to load history: ${res.statusText}`);
3816
+ const res = await fetch(`${retrivoraApiBase}/history?sessionId=${encodeURIComponent(sessionId)}`, {
3817
+ headers: __spreadValues(__spreadValues(__spreadValues({}, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {})
3818
+ });
3819
+ if (!res.ok) {
3820
+ if (res.status === 404) {
3821
+ setMessages([]);
3822
+ return;
3823
+ }
3824
+ throw new Error(`Failed to load history: ${res.statusText}`);
3825
+ }
3794
3826
  const data = await res.json();
3795
3827
  const loadedMessages = (data.history || []).map((msg) => ({
3796
3828
  id: msg.id,
@@ -3804,19 +3836,21 @@ function useRagChat(projectId, options = {}) {
3804
3836
  setMessages(loadedMessages);
3805
3837
  } catch (err) {
3806
3838
  const msg = err instanceof Error ? err.message : "Failed to load history";
3807
- setError(msg);
3839
+ setTemporaryError(msg);
3808
3840
  onError == null ? void 0 : onError(msg);
3809
3841
  } finally {
3810
3842
  setIsLoading(false);
3811
3843
  }
3812
- }, [retrivoraApiBase, onError, setMessages]);
3844
+ }, [retrivoraApiBase, onError, setMessages, setTemporaryError, resolvedLicenseKey, projectId, options.headers]);
3813
3845
  const clearHistory = (0, import_react12.useCallback)(async (sessionId) => {
3814
3846
  setIsLoading(true);
3815
3847
  setError(null);
3816
3848
  try {
3817
3849
  const res = await fetch(`${retrivoraApiBase}/history/clear`, {
3818
3850
  method: "POST",
3819
- headers: { "Content-Type": "application/json" },
3851
+ headers: __spreadValues(__spreadValues(__spreadValues({
3852
+ "Content-Type": "application/json"
3853
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {}),
3820
3854
  body: JSON.stringify({ sessionId })
3821
3855
  });
3822
3856
  if (!res.ok) throw new Error(`Failed to clear history: ${res.statusText}`);
@@ -3824,17 +3858,19 @@ function useRagChat(projectId, options = {}) {
3824
3858
  if (persist) localStorage.removeItem(storageKey);
3825
3859
  } catch (err) {
3826
3860
  const msg = err instanceof Error ? err.message : "Failed to clear history";
3827
- setError(msg);
3861
+ setTemporaryError(msg);
3828
3862
  onError == null ? void 0 : onError(msg);
3829
3863
  } finally {
3830
3864
  setIsLoading(false);
3831
3865
  }
3832
- }, [retrivoraApiBase, onError, persist, setMessages, storageKey]);
3866
+ }, [retrivoraApiBase, onError, persist, setMessages, storageKey, setTemporaryError, resolvedLicenseKey, projectId, options.headers]);
3833
3867
  const submitFeedback = (0, import_react12.useCallback)(async (messageId, rating, comment) => {
3834
3868
  try {
3835
3869
  const res = await fetch(`${retrivoraApiBase}/feedback`, {
3836
3870
  method: "POST",
3837
- headers: { "Content-Type": "application/json" },
3871
+ headers: __spreadValues(__spreadValues(__spreadValues({
3872
+ "Content-Type": "application/json"
3873
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {}),
3838
3874
  body: JSON.stringify({
3839
3875
  messageId,
3840
3876
  sessionId: options.sessionId || "default",
@@ -3848,7 +3884,7 @@ function useRagChat(projectId, options = {}) {
3848
3884
  onError == null ? void 0 : onError(msg);
3849
3885
  throw err;
3850
3886
  }
3851
- }, [retrivoraApiBase, onError, options.sessionId]);
3887
+ }, [retrivoraApiBase, onError, options.sessionId, resolvedLicenseKey, projectId, options.headers]);
3852
3888
  return {
3853
3889
  messages,
3854
3890
  isLoading,
@@ -4369,7 +4405,9 @@ function ChatWindow({
4369
4405
  const fetchSessions = (0, import_react13.useCallback)(async () => {
4370
4406
  try {
4371
4407
  const base = effectiveApiBase || "https://www.retrivora.com/api/retrivora";
4372
- const res = await fetch(`${base}/sessions`);
4408
+ const res = await fetch(`${base}/sessions`, {
4409
+ headers: __spreadValues(__spreadValues(__spreadValues({}, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), effectiveHeaders || {})
4410
+ });
4373
4411
  if (res.ok) {
4374
4412
  const data = await res.json();
4375
4413
  if (data.sessions) {
@@ -4404,7 +4442,7 @@ function ChatWindow({
4404
4442
  } catch (e) {
4405
4443
  console.warn("[ChatWindow] Failed to load sessions list:", e);
4406
4444
  }
4407
- }, [effectiveApiBase]);
4445
+ }, [effectiveApiBase, effectiveLicenseKey, projectId, effectiveHeaders]);
4408
4446
  (0, import_react13.useEffect)(() => {
4409
4447
  if (showHistory && mounted) {
4410
4448
  fetchSessions();
@@ -4582,9 +4620,9 @@ function ChatWindow({
4582
4620
  try {
4583
4621
  const base = effectiveApiBase || "https://www.retrivora.com/api/retrivora";
4584
4622
  const primaryUrl = `${base}/suggestions`;
4585
- const suggestionHeaders = __spreadValues(__spreadValues({
4623
+ const suggestionHeaders = __spreadValues(__spreadValues(__spreadValues({
4586
4624
  "Content-Type": "application/json"
4587
- }, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), effectiveHeaders || {});
4625
+ }, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), effectiveHeaders || {});
4588
4626
  let response = await fetch(primaryUrl, {
4589
4627
  method: "POST",
4590
4628
  headers: suggestionHeaders,
package/dist/index.mjs CHANGED
@@ -312,7 +312,7 @@ function projectSettingsToUiConfig(settings) {
312
312
  // package.json
313
313
  var package_default = {
314
314
  name: "@retrivora-ai/rag-engine",
315
- version: "2.4.7",
315
+ version: "2.4.8",
316
316
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
317
317
  author: "Abhinav Alkuchi",
318
318
  license: "UNLICENSED",
@@ -504,10 +504,10 @@ var ConfigFetcher = class {
504
504
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
505
505
  const res = await fetch(url, {
506
506
  method: "GET",
507
- headers: __spreadValues({
507
+ headers: __spreadValues(__spreadValues({
508
508
  "Content-Type": "application/json",
509
509
  "x-sdk-version": SDK_VERSION
510
- }, licenseKey ? { "x-license-key": licenseKey } : {})
510
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
511
511
  });
512
512
  if (!res.ok) {
513
513
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -559,9 +559,9 @@ var ConfigFetcher = class {
559
559
  const credUrl = `${baseUrl}/api/v1/credentials`;
560
560
  const credRes = await fetch(credUrl, {
561
561
  method: "POST",
562
- headers: {
562
+ headers: __spreadValues(__spreadValues({
563
563
  "Content-Type": "application/json"
564
- },
564
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
565
565
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
566
566
  });
567
567
  if (credRes.ok) {
@@ -784,7 +784,7 @@ function DocumentUpload({ namespace, uploadUrl, retrivoraApiBase, onUploadComple
784
784
  formData.append("dimension", dimension.toString());
785
785
  const apiBase = retrivoraApiBase || configuredApiBase || "https://www.retrivora.com/api/retrivora";
786
786
  const primaryUrl = uploadUrl || `${apiBase.replace(/\/$/, "")}/upload`;
787
- const uploadHeaders = __spreadValues(__spreadValues({}, configHeaders || {}), licenseKey ? { "x-license-key": licenseKey } : {});
787
+ const uploadHeaders = __spreadValues(__spreadValues(__spreadValues({}, configHeaders || {}), licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {});
788
788
  try {
789
789
  let response = await fetch(primaryUrl, {
790
790
  method: "POST",
@@ -2601,8 +2601,8 @@ function UIBlockRenderer({
2601
2601
  /* @__PURE__ */ jsx9(
2602
2602
  ProductCarousel,
2603
2603
  {
2604
- products: items.map((item) => ({
2605
- id: item.id || `carousel_${Math.random()}`,
2604
+ products: items.map((item, idx) => ({
2605
+ id: item.id || `carousel_${idx}`,
2606
2606
  name: item.name || item.title || "Product",
2607
2607
  brand: item.brand,
2608
2608
  price: item.price,
@@ -3503,7 +3503,7 @@ ${match.trim()}
3503
3503
  }
3504
3504
 
3505
3505
  // src/hooks/useRagChat.ts
3506
- import { useState as useState7, useCallback, useRef as useRef5, useEffect as useEffect5 } from "react";
3506
+ import { useState as useState7, useCallback, useRef as useRef5, useEffect as useEffect5, useMemo as useMemo2 } from "react";
3507
3507
 
3508
3508
  // src/hooks/useStoredMessages.ts
3509
3509
  import * as React12 from "react";
@@ -3581,12 +3581,45 @@ function useRagChat(projectId, options = {}) {
3581
3581
  const lastInputRef = useRef5("");
3582
3582
  const messagesRef = useRef5(messages);
3583
3583
  const abortControllerRef = useRef5(null);
3584
+ const errorTimeoutRef = useRef5(null);
3585
+ const resolvedLicenseKey = useMemo2(() => {
3586
+ var _a;
3587
+ const getHeader = (headersObj, name) => {
3588
+ if (!headersObj) return void 0;
3589
+ const target = name.toLowerCase();
3590
+ for (const [k, v] of Object.entries(headersObj)) {
3591
+ if (k.toLowerCase() === target) return v;
3592
+ }
3593
+ return void 0;
3594
+ };
3595
+ return options.licenseKey || getHeader(options.headers, "x-license-key") || ((_a = getHeader(options.headers, "authorization")) == null ? void 0 : _a.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3596
+ }, [options.licenseKey, options.headers]);
3597
+ const setTemporaryError = useCallback((msg) => {
3598
+ setError(msg);
3599
+ if (errorTimeoutRef.current) {
3600
+ clearTimeout(errorTimeoutRef.current);
3601
+ errorTimeoutRef.current = null;
3602
+ }
3603
+ if (msg) {
3604
+ errorTimeoutRef.current = setTimeout(() => {
3605
+ setError(null);
3606
+ errorTimeoutRef.current = null;
3607
+ }, 5e3);
3608
+ }
3609
+ }, []);
3610
+ useEffect5(() => {
3611
+ return () => {
3612
+ if (errorTimeoutRef.current) {
3613
+ clearTimeout(errorTimeoutRef.current);
3614
+ }
3615
+ };
3616
+ }, []);
3584
3617
  useEffect5(() => {
3585
3618
  messagesRef.current = messages;
3586
3619
  }, [messages]);
3587
3620
  const sendMessage = useCallback(
3588
3621
  async (text, opts) => {
3589
- var _a, _b, _c, _d, _e, _f;
3622
+ var _a, _b, _c, _d, _e;
3590
3623
  const trimmed = text.trim();
3591
3624
  if (!trimmed || isLoading) return;
3592
3625
  lastInputRef.current = trimmed;
@@ -3618,18 +3651,9 @@ function useRagChat(projectId, options = {}) {
3618
3651
  messageId: assistantMessageId,
3619
3652
  userMessageId: userMsgId
3620
3653
  });
3621
- const getHeader = (headersObj, name) => {
3622
- if (!headersObj) return void 0;
3623
- const target = name.toLowerCase();
3624
- for (const [k, v] of Object.entries(headersObj)) {
3625
- if (k.toLowerCase() === target) return v;
3626
- }
3627
- return void 0;
3628
- };
3629
- const resolvedLicenseKey = options.licenseKey || getHeader(options.headers, "x-license-key") || ((_b = getHeader(options.headers, "authorization")) == null ? void 0 : _b.replace(/^Bearer\s+/i, "")) || (typeof process !== "undefined" ? process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY : "") || "";
3630
- const fetchHeaders = __spreadValues(__spreadValues({
3654
+ const fetchHeaders = __spreadValues(__spreadValues(__spreadValues({
3631
3655
  "Content-Type": "application/json"
3632
- }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), options.headers || {});
3656
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {});
3633
3657
  let response = await fetch(primaryUrl, {
3634
3658
  method: "POST",
3635
3659
  headers: fetchHeaders,
@@ -3637,7 +3661,7 @@ function useRagChat(projectId, options = {}) {
3637
3661
  body: payloadBody
3638
3662
  });
3639
3663
  if (response.status === 404 && !apiUrl && primaryUrl !== "/api/chat") {
3640
- console.warn(`[Retrivora SDK] \u26A0\uFE0F Chat endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/chat"...`);
3664
+ console.warn(`[Retrivora SDK] Chat endpoint "${primaryUrl}" returned 404. Retrying fallback to "/api/chat"...`);
3641
3665
  response = await fetch("/api/chat", {
3642
3666
  method: "POST",
3643
3667
  headers: fetchHeaders,
@@ -3647,10 +3671,10 @@ function useRagChat(projectId, options = {}) {
3647
3671
  }
3648
3672
  if (!response.ok) {
3649
3673
  const errorData = await response.json().catch(() => ({}));
3650
- if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_c = errorData.error) == null ? void 0 : _c.type) === "license_revoked") {
3674
+ if (response.status === 403 || response.status === 401 || typeof errorData.error === "string" && errorData.error.toLowerCase().includes("license") || ((_b = errorData.error) == null ? void 0 : _b.type) === "license_revoked") {
3651
3675
  throw new Error("Your Retrivora license is no longer valid. Please contact your administrator or obtain a valid license key.");
3652
3676
  }
3653
- throw new Error(((_d = errorData.error) == null ? void 0 : _d.message) || errorData.error || `Server returned ${response.status}`);
3677
+ throw new Error(((_c = errorData.error) == null ? void 0 : _c.message) || errorData.error || `Server returned ${response.status}`);
3654
3678
  }
3655
3679
  if (!response.body) {
3656
3680
  throw new Error("No response body received from server");
@@ -3714,7 +3738,7 @@ function useRagChat(projectId, options = {}) {
3714
3738
  pendingThinkingRef.current = thinkingContent;
3715
3739
  scheduleFlush(assistantMessageId);
3716
3740
  } else if (frame.type === "metadata") {
3717
- sources = (_e = frame.sources) != null ? _e : [];
3741
+ sources = (_d = frame.sources) != null ? _d : [];
3718
3742
  thinkingMs = frame.thinkingMs;
3719
3743
  } else if (frame.type === "ui_transformation") {
3720
3744
  uiTransformation = frame.data;
@@ -3730,7 +3754,7 @@ function useRagChat(projectId, options = {}) {
3730
3754
  if (frame.type === "text" && frame.text) assistantContent += frame.text;
3731
3755
  else if (frame.type === "thinking" && frame.text) thinkingContent += frame.text;
3732
3756
  else if (frame.type === "metadata") {
3733
- sources = (_f = frame.sources) != null ? _f : [];
3757
+ sources = (_e = frame.sources) != null ? _e : [];
3734
3758
  thinkingMs = frame.thinkingMs;
3735
3759
  } else if (frame.type === "observability") trace = frame.data;
3736
3760
  }
@@ -3758,14 +3782,14 @@ function useRagChat(projectId, options = {}) {
3758
3782
  if (msg.includes("403") || msg.toLowerCase().includes("license") || msg.toLowerCase().includes("revoked") || msg.toLowerCase().includes("terminated")) {
3759
3783
  msg = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
3760
3784
  }
3761
- setError(msg);
3785
+ setTemporaryError(msg);
3762
3786
  onError == null ? void 0 : onError(msg);
3763
3787
  } finally {
3764
3788
  setIsLoading(false);
3765
3789
  abortControllerRef.current = null;
3766
3790
  }
3767
3791
  },
3768
- [apiUrl, isLoading, namespace, onError, onReply, projectId, setMessages, options.headers, options.sessionId]
3792
+ [apiUrl, isLoading, namespace, onError, onReply, projectId, setMessages, options.headers, options.sessionId, setTemporaryError, resolvedLicenseKey]
3769
3793
  );
3770
3794
  const clear = useCallback(() => {
3771
3795
  setMessages([]);
@@ -3791,8 +3815,16 @@ function useRagChat(projectId, options = {}) {
3791
3815
  setIsLoading(true);
3792
3816
  setError(null);
3793
3817
  try {
3794
- const res = await fetch(`${retrivoraApiBase}/history?sessionId=${encodeURIComponent(sessionId)}`);
3795
- if (!res.ok) throw new Error(`Failed to load history: ${res.statusText}`);
3818
+ const res = await fetch(`${retrivoraApiBase}/history?sessionId=${encodeURIComponent(sessionId)}`, {
3819
+ headers: __spreadValues(__spreadValues(__spreadValues({}, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {})
3820
+ });
3821
+ if (!res.ok) {
3822
+ if (res.status === 404) {
3823
+ setMessages([]);
3824
+ return;
3825
+ }
3826
+ throw new Error(`Failed to load history: ${res.statusText}`);
3827
+ }
3796
3828
  const data = await res.json();
3797
3829
  const loadedMessages = (data.history || []).map((msg) => ({
3798
3830
  id: msg.id,
@@ -3806,19 +3838,21 @@ function useRagChat(projectId, options = {}) {
3806
3838
  setMessages(loadedMessages);
3807
3839
  } catch (err) {
3808
3840
  const msg = err instanceof Error ? err.message : "Failed to load history";
3809
- setError(msg);
3841
+ setTemporaryError(msg);
3810
3842
  onError == null ? void 0 : onError(msg);
3811
3843
  } finally {
3812
3844
  setIsLoading(false);
3813
3845
  }
3814
- }, [retrivoraApiBase, onError, setMessages]);
3846
+ }, [retrivoraApiBase, onError, setMessages, setTemporaryError, resolvedLicenseKey, projectId, options.headers]);
3815
3847
  const clearHistory = useCallback(async (sessionId) => {
3816
3848
  setIsLoading(true);
3817
3849
  setError(null);
3818
3850
  try {
3819
3851
  const res = await fetch(`${retrivoraApiBase}/history/clear`, {
3820
3852
  method: "POST",
3821
- headers: { "Content-Type": "application/json" },
3853
+ headers: __spreadValues(__spreadValues(__spreadValues({
3854
+ "Content-Type": "application/json"
3855
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {}),
3822
3856
  body: JSON.stringify({ sessionId })
3823
3857
  });
3824
3858
  if (!res.ok) throw new Error(`Failed to clear history: ${res.statusText}`);
@@ -3826,17 +3860,19 @@ function useRagChat(projectId, options = {}) {
3826
3860
  if (persist) localStorage.removeItem(storageKey);
3827
3861
  } catch (err) {
3828
3862
  const msg = err instanceof Error ? err.message : "Failed to clear history";
3829
- setError(msg);
3863
+ setTemporaryError(msg);
3830
3864
  onError == null ? void 0 : onError(msg);
3831
3865
  } finally {
3832
3866
  setIsLoading(false);
3833
3867
  }
3834
- }, [retrivoraApiBase, onError, persist, setMessages, storageKey]);
3868
+ }, [retrivoraApiBase, onError, persist, setMessages, storageKey, setTemporaryError, resolvedLicenseKey, projectId, options.headers]);
3835
3869
  const submitFeedback = useCallback(async (messageId, rating, comment) => {
3836
3870
  try {
3837
3871
  const res = await fetch(`${retrivoraApiBase}/feedback`, {
3838
3872
  method: "POST",
3839
- headers: { "Content-Type": "application/json" },
3873
+ headers: __spreadValues(__spreadValues(__spreadValues({
3874
+ "Content-Type": "application/json"
3875
+ }, resolvedLicenseKey ? { "x-license-key": resolvedLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), options.headers || {}),
3840
3876
  body: JSON.stringify({
3841
3877
  messageId,
3842
3878
  sessionId: options.sessionId || "default",
@@ -3850,7 +3886,7 @@ function useRagChat(projectId, options = {}) {
3850
3886
  onError == null ? void 0 : onError(msg);
3851
3887
  throw err;
3852
3888
  }
3853
- }, [retrivoraApiBase, onError, options.sessionId]);
3889
+ }, [retrivoraApiBase, onError, options.sessionId, resolvedLicenseKey, projectId, options.headers]);
3854
3890
  return {
3855
3891
  messages,
3856
3892
  isLoading,
@@ -4371,7 +4407,9 @@ function ChatWindow({
4371
4407
  const fetchSessions = useCallback2(async () => {
4372
4408
  try {
4373
4409
  const base = effectiveApiBase || "https://www.retrivora.com/api/retrivora";
4374
- const res = await fetch(`${base}/sessions`);
4410
+ const res = await fetch(`${base}/sessions`, {
4411
+ headers: __spreadValues(__spreadValues(__spreadValues({}, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), effectiveHeaders || {})
4412
+ });
4375
4413
  if (res.ok) {
4376
4414
  const data = await res.json();
4377
4415
  if (data.sessions) {
@@ -4406,7 +4444,7 @@ function ChatWindow({
4406
4444
  } catch (e) {
4407
4445
  console.warn("[ChatWindow] Failed to load sessions list:", e);
4408
4446
  }
4409
- }, [effectiveApiBase]);
4447
+ }, [effectiveApiBase, effectiveLicenseKey, projectId, effectiveHeaders]);
4410
4448
  useEffect6(() => {
4411
4449
  if (showHistory && mounted) {
4412
4450
  fetchSessions();
@@ -4584,9 +4622,9 @@ function ChatWindow({
4584
4622
  try {
4585
4623
  const base = effectiveApiBase || "https://www.retrivora.com/api/retrivora";
4586
4624
  const primaryUrl = `${base}/suggestions`;
4587
- const suggestionHeaders = __spreadValues(__spreadValues({
4625
+ const suggestionHeaders = __spreadValues(__spreadValues(__spreadValues({
4588
4626
  "Content-Type": "application/json"
4589
- }, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), effectiveHeaders || {});
4627
+ }, effectiveLicenseKey ? { "x-license-key": effectiveLicenseKey } : {}), projectId ? { "x-project-id": projectId } : {}), effectiveHeaders || {});
4590
4628
  let response = await fetch(primaryUrl, {
4591
4629
  method: "POST",
4592
4630
  headers: suggestionHeaders,
@@ -5344,9 +5382,9 @@ function CodeViewer({ snippet }) {
5344
5382
  }
5345
5383
 
5346
5384
  // src/hooks/useProjectSettings.ts
5347
- import { useEffect as useEffect8, useMemo as useMemo2, useState as useState10 } from "react";
5385
+ import { useEffect as useEffect8, useMemo as useMemo3, useState as useState10 } from "react";
5348
5386
  function useProjectSettings(projectId, options = {}) {
5349
- const initialSettings = useMemo2(
5387
+ const initialSettings = useMemo3(
5350
5388
  () => normalizeProjectSettings(projectId, options.initialSettings || createDefaultProjectSettings(projectId)),
5351
5389
  [options.initialSettings, projectId]
5352
5390
  );
package/dist/server.js CHANGED
@@ -332,7 +332,7 @@ var init_package = __esm({
332
332
  "package.json"() {
333
333
  package_default = {
334
334
  name: "@retrivora-ai/rag-engine",
335
- version: "2.4.7",
335
+ version: "2.4.8",
336
336
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
337
337
  author: "Abhinav Alkuchi",
338
338
  license: "UNLICENSED",
@@ -539,10 +539,10 @@ var init_ConfigFetcher = __esm({
539
539
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
540
540
  const res = await fetch(url, {
541
541
  method: "GET",
542
- headers: __spreadValues({
542
+ headers: __spreadValues(__spreadValues({
543
543
  "Content-Type": "application/json",
544
544
  "x-sdk-version": SDK_VERSION
545
- }, licenseKey ? { "x-license-key": licenseKey } : {})
545
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
546
546
  });
547
547
  if (!res.ok) {
548
548
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -594,9 +594,9 @@ var init_ConfigFetcher = __esm({
594
594
  const credUrl = `${baseUrl}/api/v1/credentials`;
595
595
  const credRes = await fetch(credUrl, {
596
596
  method: "POST",
597
- headers: {
597
+ headers: __spreadValues(__spreadValues({
598
598
  "Content-Type": "application/json"
599
- },
599
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
600
600
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
601
601
  });
602
602
  if (credRes.ok) {
@@ -782,7 +782,10 @@ var init_PineconeProvider = __esm({
782
782
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
783
783
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
784
784
  method: "POST",
785
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
785
+ headers: __spreadValues({
786
+ "Content-Type": "application/json",
787
+ "x-license-key": this.licenseKey
788
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
786
789
  body: JSON.stringify({
787
790
  projectId: this.projectId,
788
791
  indexName: this.indexName,
@@ -817,7 +820,10 @@ var init_PineconeProvider = __esm({
817
820
  });
818
821
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
819
822
  method: "POST",
820
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
823
+ headers: __spreadValues({
824
+ "Content-Type": "application/json",
825
+ "x-license-key": this.licenseKey
826
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
821
827
  body: JSON.stringify({
822
828
  projectId: this.projectId,
823
829
  indexName: this.indexName,
@@ -849,7 +855,10 @@ var init_PineconeProvider = __esm({
849
855
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
850
856
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
851
857
  method: "POST",
852
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
858
+ headers: __spreadValues({
859
+ "Content-Type": "application/json",
860
+ "x-license-key": this.licenseKey
861
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
853
862
  body: JSON.stringify({
854
863
  projectId: this.projectId,
855
864
  indexName: this.indexName,
package/dist/server.mjs CHANGED
@@ -326,7 +326,7 @@ var init_package = __esm({
326
326
  "package.json"() {
327
327
  package_default = {
328
328
  name: "@retrivora-ai/rag-engine",
329
- version: "2.4.7",
329
+ version: "2.4.8",
330
330
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
331
331
  author: "Abhinav Alkuchi",
332
332
  license: "UNLICENSED",
@@ -533,10 +533,10 @@ var init_ConfigFetcher = __esm({
533
533
  const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
534
534
  const res = await fetch(url, {
535
535
  method: "GET",
536
- headers: __spreadValues({
536
+ headers: __spreadValues(__spreadValues({
537
537
  "Content-Type": "application/json",
538
538
  "x-sdk-version": SDK_VERSION
539
- }, licenseKey ? { "x-license-key": licenseKey } : {})
539
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
540
540
  });
541
541
  if (!res.ok) {
542
542
  console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
@@ -588,9 +588,9 @@ var init_ConfigFetcher = __esm({
588
588
  const credUrl = `${baseUrl}/api/v1/credentials`;
589
589
  const credRes = await fetch(credUrl, {
590
590
  method: "POST",
591
- headers: {
591
+ headers: __spreadValues(__spreadValues({
592
592
  "Content-Type": "application/json"
593
- },
593
+ }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
594
594
  body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
595
595
  });
596
596
  if (credRes.ok) {
@@ -776,7 +776,10 @@ var init_PineconeProvider = __esm({
776
776
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
777
777
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
778
778
  method: "POST",
779
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
779
+ headers: __spreadValues({
780
+ "Content-Type": "application/json",
781
+ "x-license-key": this.licenseKey
782
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
780
783
  body: JSON.stringify({
781
784
  projectId: this.projectId,
782
785
  indexName: this.indexName,
@@ -811,7 +814,10 @@ var init_PineconeProvider = __esm({
811
814
  });
812
815
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
813
816
  method: "POST",
814
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
817
+ headers: __spreadValues({
818
+ "Content-Type": "application/json",
819
+ "x-license-key": this.licenseKey
820
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
815
821
  body: JSON.stringify({
816
822
  projectId: this.projectId,
817
823
  indexName: this.indexName,
@@ -843,7 +849,10 @@ var init_PineconeProvider = __esm({
843
849
  if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
844
850
  const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
845
851
  method: "POST",
846
- headers: { "Content-Type": "application/json", "x-license-key": this.licenseKey },
852
+ headers: __spreadValues({
853
+ "Content-Type": "application/json",
854
+ "x-license-key": this.licenseKey
855
+ }, this.projectId ? { "x-project-id": this.projectId } : {}),
847
856
  body: JSON.stringify({
848
857
  projectId: this.projectId,
849
858
  indexName: this.indexName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.4.7",
3
+ "version": "2.4.8",
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",