@retrivora-ai/rag-engine 2.1.1 → 2.1.2

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.
@@ -4535,7 +4535,7 @@ var UniversalLLMAdapter = class {
4535
4535
  });
4536
4536
  }
4537
4537
  async chat(messages, context) {
4538
- var _a2, _b, _c;
4538
+ var _a2, _b, _c, _d, _e;
4539
4539
  const path2 = (_a2 = this.opts.chatPath) != null ? _a2 : "/chat/completions";
4540
4540
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4541
4541
  role: m.role || "user",
@@ -4564,8 +4564,15 @@ ${context != null ? context : "None"}` },
4564
4564
  temperature: this.temperature
4565
4565
  };
4566
4566
  }
4567
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4568
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4567
+ try {
4568
+ const { data: data2 } = await this.http.post(path2, payload);
4569
+ const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4570
+ const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4571
+ if (result2 !== void 0) {
4572
+ return String(result2);
4573
+ }
4574
+ } catch (httpErr) {
4575
+ console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4569
4576
  const _g2 = globalThis;
4570
4577
  let dispatch = _g2.__retrivoraDispatchChat;
4571
4578
  if (typeof dispatch !== "function") {
@@ -4580,28 +4587,22 @@ ${context != null ? context : "None"}` },
4580
4587
  }
4581
4588
  }
4582
4589
  if (typeof dispatch === "function") {
4583
- try {
4584
- const res = await dispatch({
4585
- model: this.model,
4586
- messages: formattedMessages,
4587
- max_tokens: this.maxTokens,
4588
- temperature: this.temperature
4589
- }, this.apiKey);
4590
- const content = extractContent(res == null ? void 0 : res.response);
4591
- if (content !== void 0) {
4592
- return content;
4593
- }
4594
- throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
4595
- } catch (dispatchErr) {
4596
- throw dispatchErr;
4590
+ const res = await dispatch({
4591
+ model: this.model,
4592
+ messages: formattedMessages,
4593
+ max_tokens: this.maxTokens,
4594
+ temperature: this.temperature
4595
+ }, this.apiKey);
4596
+ const content = extractContent(res == null ? void 0 : res.response);
4597
+ if (content !== void 0) {
4598
+ return content;
4597
4599
  }
4598
- } else {
4599
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4600
4600
  }
4601
+ throw httpErr;
4601
4602
  }
4602
4603
  const { data } = await this.http.post(path2, payload);
4603
- const extractPath = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4604
- const result = (_c = resolvePath(data, extractPath)) != null ? _c : extractContent(data);
4604
+ const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4605
+ const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4605
4606
  if (result === void 0) {
4606
4607
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4607
4608
  }
@@ -4743,7 +4744,7 @@ ${context != null ? context : "None"}` },
4743
4744
  });
4744
4745
  }
4745
4746
  async embed(text) {
4746
- var _a2, _b, _c, _d;
4747
+ var _a2, _b, _c, _d, _e;
4747
4748
  const path2 = (_a2 = this.opts.embedPath) != null ? _a2 : "/embeddings";
4748
4749
  let payload;
4749
4750
  if (this.opts.embedPayloadTemplate) {
@@ -4757,8 +4758,15 @@ ${context != null ? context : "None"}` },
4757
4758
  input: text
4758
4759
  };
4759
4760
  }
4760
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4761
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4761
+ try {
4762
+ const { data: data2 } = await this.http.post(path2, payload);
4763
+ const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4764
+ const vector2 = resolvePath(data2, extractPath2);
4765
+ if (Array.isArray(vector2)) {
4766
+ return vector2;
4767
+ }
4768
+ } catch (httpErr) {
4769
+ console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4762
4770
  const _g2 = globalThis;
4763
4771
  let dispatch = _g2.__retrivoraDispatchEmbedding;
4764
4772
  if (typeof dispatch !== "function") {
@@ -4773,24 +4781,18 @@ ${context != null ? context : "None"}` },
4773
4781
  }
4774
4782
  }
4775
4783
  if (typeof dispatch === "function") {
4776
- try {
4777
- const res = await dispatch({
4778
- model: this.model,
4779
- input: text
4780
- }, this.apiKey);
4781
- if ((_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.embedding) {
4782
- return res.data[0].embedding;
4783
- }
4784
- throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
4785
- } catch (dispatchErr) {
4786
- throw dispatchErr;
4784
+ const res = await dispatch({
4785
+ model: this.model,
4786
+ input: text
4787
+ }, this.apiKey);
4788
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4789
+ return res.data[0].embedding;
4787
4790
  }
4788
- } else {
4789
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4790
4791
  }
4792
+ throw httpErr;
4791
4793
  }
4792
4794
  const { data } = await this.http.post(path2, payload);
4793
- const extractPath = (_d = this.opts.embedExtractPath) != null ? _d : "data[0].embedding";
4795
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4794
4796
  const vector = resolvePath(data, extractPath);
4795
4797
  if (!Array.isArray(vector)) {
4796
4798
  throw new Error(`[UniversalLLMAdapter] Expected a number array at '${extractPath}' for embeddings.`);
@@ -4500,7 +4500,7 @@ var UniversalLLMAdapter = class {
4500
4500
  });
4501
4501
  }
4502
4502
  async chat(messages, context) {
4503
- var _a2, _b, _c;
4503
+ var _a2, _b, _c, _d, _e;
4504
4504
  const path2 = (_a2 = this.opts.chatPath) != null ? _a2 : "/chat/completions";
4505
4505
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4506
4506
  role: m.role || "user",
@@ -4529,8 +4529,15 @@ ${context != null ? context : "None"}` },
4529
4529
  temperature: this.temperature
4530
4530
  };
4531
4531
  }
4532
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4533
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4532
+ try {
4533
+ const { data: data2 } = await this.http.post(path2, payload);
4534
+ const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4535
+ const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4536
+ if (result2 !== void 0) {
4537
+ return String(result2);
4538
+ }
4539
+ } catch (httpErr) {
4540
+ console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4534
4541
  const _g2 = globalThis;
4535
4542
  let dispatch = _g2.__retrivoraDispatchChat;
4536
4543
  if (typeof dispatch !== "function") {
@@ -4545,28 +4552,22 @@ ${context != null ? context : "None"}` },
4545
4552
  }
4546
4553
  }
4547
4554
  if (typeof dispatch === "function") {
4548
- try {
4549
- const res = await dispatch({
4550
- model: this.model,
4551
- messages: formattedMessages,
4552
- max_tokens: this.maxTokens,
4553
- temperature: this.temperature
4554
- }, this.apiKey);
4555
- const content = extractContent(res == null ? void 0 : res.response);
4556
- if (content !== void 0) {
4557
- return content;
4558
- }
4559
- throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
4560
- } catch (dispatchErr) {
4561
- throw dispatchErr;
4555
+ const res = await dispatch({
4556
+ model: this.model,
4557
+ messages: formattedMessages,
4558
+ max_tokens: this.maxTokens,
4559
+ temperature: this.temperature
4560
+ }, this.apiKey);
4561
+ const content = extractContent(res == null ? void 0 : res.response);
4562
+ if (content !== void 0) {
4563
+ return content;
4562
4564
  }
4563
- } else {
4564
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4565
4565
  }
4566
+ throw httpErr;
4566
4567
  }
4567
4568
  const { data } = await this.http.post(path2, payload);
4568
- const extractPath = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4569
- const result = (_c = resolvePath(data, extractPath)) != null ? _c : extractContent(data);
4569
+ const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4570
+ const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4570
4571
  if (result === void 0) {
4571
4572
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4572
4573
  }
@@ -4708,7 +4709,7 @@ ${context != null ? context : "None"}` },
4708
4709
  });
4709
4710
  }
4710
4711
  async embed(text) {
4711
- var _a2, _b, _c, _d;
4712
+ var _a2, _b, _c, _d, _e;
4712
4713
  const path2 = (_a2 = this.opts.embedPath) != null ? _a2 : "/embeddings";
4713
4714
  let payload;
4714
4715
  if (this.opts.embedPayloadTemplate) {
@@ -4722,8 +4723,15 @@ ${context != null ? context : "None"}` },
4722
4723
  input: text
4723
4724
  };
4724
4725
  }
4725
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4726
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4726
+ try {
4727
+ const { data: data2 } = await this.http.post(path2, payload);
4728
+ const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4729
+ const vector2 = resolvePath(data2, extractPath2);
4730
+ if (Array.isArray(vector2)) {
4731
+ return vector2;
4732
+ }
4733
+ } catch (httpErr) {
4734
+ console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4727
4735
  const _g2 = globalThis;
4728
4736
  let dispatch = _g2.__retrivoraDispatchEmbedding;
4729
4737
  if (typeof dispatch !== "function") {
@@ -4738,24 +4746,18 @@ ${context != null ? context : "None"}` },
4738
4746
  }
4739
4747
  }
4740
4748
  if (typeof dispatch === "function") {
4741
- try {
4742
- const res = await dispatch({
4743
- model: this.model,
4744
- input: text
4745
- }, this.apiKey);
4746
- if ((_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.embedding) {
4747
- return res.data[0].embedding;
4748
- }
4749
- throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
4750
- } catch (dispatchErr) {
4751
- throw dispatchErr;
4749
+ const res = await dispatch({
4750
+ model: this.model,
4751
+ input: text
4752
+ }, this.apiKey);
4753
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4754
+ return res.data[0].embedding;
4752
4755
  }
4753
- } else {
4754
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4755
4756
  }
4757
+ throw httpErr;
4756
4758
  }
4757
4759
  const { data } = await this.http.post(path2, payload);
4758
- const extractPath = (_d = this.opts.embedExtractPath) != null ? _d : "data[0].embedding";
4760
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4759
4761
  const vector = resolvePath(data, extractPath);
4760
4762
  if (!Array.isArray(vector)) {
4761
4763
  throw new Error(`[UniversalLLMAdapter] Expected a number array at '${extractPath}' for embeddings.`);
package/dist/server.js CHANGED
@@ -4635,7 +4635,7 @@ var UniversalLLMAdapter = class {
4635
4635
  });
4636
4636
  }
4637
4637
  async chat(messages, context) {
4638
- var _a2, _b, _c;
4638
+ var _a2, _b, _c, _d, _e;
4639
4639
  const path2 = (_a2 = this.opts.chatPath) != null ? _a2 : "/chat/completions";
4640
4640
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4641
4641
  role: m.role || "user",
@@ -4664,8 +4664,15 @@ ${context != null ? context : "None"}` },
4664
4664
  temperature: this.temperature
4665
4665
  };
4666
4666
  }
4667
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4668
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4667
+ try {
4668
+ const { data: data2 } = await this.http.post(path2, payload);
4669
+ const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4670
+ const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4671
+ if (result2 !== void 0) {
4672
+ return String(result2);
4673
+ }
4674
+ } catch (httpErr) {
4675
+ console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4669
4676
  const _g2 = globalThis;
4670
4677
  let dispatch = _g2.__retrivoraDispatchChat;
4671
4678
  if (typeof dispatch !== "function") {
@@ -4680,28 +4687,22 @@ ${context != null ? context : "None"}` },
4680
4687
  }
4681
4688
  }
4682
4689
  if (typeof dispatch === "function") {
4683
- try {
4684
- const res = await dispatch({
4685
- model: this.model,
4686
- messages: formattedMessages,
4687
- max_tokens: this.maxTokens,
4688
- temperature: this.temperature
4689
- }, this.apiKey);
4690
- const content = extractContent(res == null ? void 0 : res.response);
4691
- if (content !== void 0) {
4692
- return content;
4693
- }
4694
- throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
4695
- } catch (dispatchErr) {
4696
- throw dispatchErr;
4690
+ const res = await dispatch({
4691
+ model: this.model,
4692
+ messages: formattedMessages,
4693
+ max_tokens: this.maxTokens,
4694
+ temperature: this.temperature
4695
+ }, this.apiKey);
4696
+ const content = extractContent(res == null ? void 0 : res.response);
4697
+ if (content !== void 0) {
4698
+ return content;
4697
4699
  }
4698
- } else {
4699
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4700
4700
  }
4701
+ throw httpErr;
4701
4702
  }
4702
4703
  const { data } = await this.http.post(path2, payload);
4703
- const extractPath = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4704
- const result = (_c = resolvePath(data, extractPath)) != null ? _c : extractContent(data);
4704
+ const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4705
+ const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4705
4706
  if (result === void 0) {
4706
4707
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4707
4708
  }
@@ -4843,7 +4844,7 @@ ${context != null ? context : "None"}` },
4843
4844
  });
4844
4845
  }
4845
4846
  async embed(text) {
4846
- var _a2, _b, _c, _d;
4847
+ var _a2, _b, _c, _d, _e;
4847
4848
  const path2 = (_a2 = this.opts.embedPath) != null ? _a2 : "/embeddings";
4848
4849
  let payload;
4849
4850
  if (this.opts.embedPayloadTemplate) {
@@ -4857,8 +4858,15 @@ ${context != null ? context : "None"}` },
4857
4858
  input: text
4858
4859
  };
4859
4860
  }
4860
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4861
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4861
+ try {
4862
+ const { data: data2 } = await this.http.post(path2, payload);
4863
+ const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4864
+ const vector2 = resolvePath(data2, extractPath2);
4865
+ if (Array.isArray(vector2)) {
4866
+ return vector2;
4867
+ }
4868
+ } catch (httpErr) {
4869
+ console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4862
4870
  const _g2 = globalThis;
4863
4871
  let dispatch = _g2.__retrivoraDispatchEmbedding;
4864
4872
  if (typeof dispatch !== "function") {
@@ -4873,24 +4881,18 @@ ${context != null ? context : "None"}` },
4873
4881
  }
4874
4882
  }
4875
4883
  if (typeof dispatch === "function") {
4876
- try {
4877
- const res = await dispatch({
4878
- model: this.model,
4879
- input: text
4880
- }, this.apiKey);
4881
- if ((_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.embedding) {
4882
- return res.data[0].embedding;
4883
- }
4884
- throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
4885
- } catch (dispatchErr) {
4886
- throw dispatchErr;
4884
+ const res = await dispatch({
4885
+ model: this.model,
4886
+ input: text
4887
+ }, this.apiKey);
4888
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4889
+ return res.data[0].embedding;
4887
4890
  }
4888
- } else {
4889
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4890
4891
  }
4892
+ throw httpErr;
4891
4893
  }
4892
4894
  const { data } = await this.http.post(path2, payload);
4893
- const extractPath = (_d = this.opts.embedExtractPath) != null ? _d : "data[0].embedding";
4895
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4894
4896
  const vector = resolvePath(data, extractPath);
4895
4897
  if (!Array.isArray(vector)) {
4896
4898
  throw new Error(`[UniversalLLMAdapter] Expected a number array at '${extractPath}' for embeddings.`);
package/dist/server.mjs CHANGED
@@ -4539,7 +4539,7 @@ var UniversalLLMAdapter = class {
4539
4539
  });
4540
4540
  }
4541
4541
  async chat(messages, context) {
4542
- var _a2, _b, _c;
4542
+ var _a2, _b, _c, _d, _e;
4543
4543
  const path2 = (_a2 = this.opts.chatPath) != null ? _a2 : "/chat/completions";
4544
4544
  const safeMessages = (Array.isArray(messages) ? messages : []).filter((m) => Boolean(m && typeof m === "object")).map((m) => ({
4545
4545
  role: m.role || "user",
@@ -4568,8 +4568,15 @@ ${context != null ? context : "None"}` },
4568
4568
  temperature: this.temperature
4569
4569
  };
4570
4570
  }
4571
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4572
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4571
+ try {
4572
+ const { data: data2 } = await this.http.post(path2, payload);
4573
+ const extractPath2 = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4574
+ const result2 = (_c = resolvePath(data2, extractPath2)) != null ? _c : extractContent(data2);
4575
+ if (result2 !== void 0) {
4576
+ return String(result2);
4577
+ }
4578
+ } catch (httpErr) {
4579
+ console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4573
4580
  const _g2 = globalThis;
4574
4581
  let dispatch = _g2.__retrivoraDispatchChat;
4575
4582
  if (typeof dispatch !== "function") {
@@ -4584,28 +4591,22 @@ ${context != null ? context : "None"}` },
4584
4591
  }
4585
4592
  }
4586
4593
  if (typeof dispatch === "function") {
4587
- try {
4588
- const res = await dispatch({
4589
- model: this.model,
4590
- messages: formattedMessages,
4591
- max_tokens: this.maxTokens,
4592
- temperature: this.temperature
4593
- }, this.apiKey);
4594
- const content = extractContent(res == null ? void 0 : res.response);
4595
- if (content !== void 0) {
4596
- return content;
4597
- }
4598
- throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
4599
- } catch (dispatchErr) {
4600
- throw dispatchErr;
4594
+ const res = await dispatch({
4595
+ model: this.model,
4596
+ messages: formattedMessages,
4597
+ max_tokens: this.maxTokens,
4598
+ temperature: this.temperature
4599
+ }, this.apiKey);
4600
+ const content = extractContent(res == null ? void 0 : res.response);
4601
+ if (content !== void 0) {
4602
+ return content;
4601
4603
  }
4602
- } else {
4603
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4604
4604
  }
4605
+ throw httpErr;
4605
4606
  }
4606
4607
  const { data } = await this.http.post(path2, payload);
4607
- const extractPath = (_b = this.opts.responseExtractPath) != null ? _b : "choices[0].message.content";
4608
- const result = (_c = resolvePath(data, extractPath)) != null ? _c : extractContent(data);
4608
+ const extractPath = (_d = this.opts.responseExtractPath) != null ? _d : "choices[0].message.content";
4609
+ const result = (_e = resolvePath(data, extractPath)) != null ? _e : extractContent(data);
4609
4610
  if (result === void 0) {
4610
4611
  throw new Error(`[UniversalLLMAdapter] Could not extract text from path '${extractPath}' in response.`);
4611
4612
  }
@@ -4747,7 +4748,7 @@ ${context != null ? context : "None"}` },
4747
4748
  });
4748
4749
  }
4749
4750
  async embed(text) {
4750
- var _a2, _b, _c, _d;
4751
+ var _a2, _b, _c, _d, _e;
4751
4752
  const path2 = (_a2 = this.opts.embedPath) != null ? _a2 : "/embeddings";
4752
4753
  let payload;
4753
4754
  if (this.opts.embedPayloadTemplate) {
@@ -4761,8 +4762,15 @@ ${context != null ? context : "None"}` },
4761
4762
  input: text
4762
4763
  };
4763
4764
  }
4764
- const isSelfHost = this.baseUrl.includes("retrivora.com") || this.baseUrl.includes("localhost");
4765
- if (isSelfHost || Boolean(process.env.VERCEL)) {
4765
+ try {
4766
+ const { data: data2 } = await this.http.post(path2, payload);
4767
+ const extractPath2 = (_b = this.opts.embedExtractPath) != null ? _b : "data[0].embedding";
4768
+ const vector2 = resolvePath(data2, extractPath2);
4769
+ if (Array.isArray(vector2)) {
4770
+ return vector2;
4771
+ }
4772
+ } catch (httpErr) {
4773
+ console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path2} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
4766
4774
  const _g2 = globalThis;
4767
4775
  let dispatch = _g2.__retrivoraDispatchEmbedding;
4768
4776
  if (typeof dispatch !== "function") {
@@ -4777,24 +4785,18 @@ ${context != null ? context : "None"}` },
4777
4785
  }
4778
4786
  }
4779
4787
  if (typeof dispatch === "function") {
4780
- try {
4781
- const res = await dispatch({
4782
- model: this.model,
4783
- input: text
4784
- }, this.apiKey);
4785
- if ((_c = (_b = res == null ? void 0 : res.data) == null ? void 0 : _b[0]) == null ? void 0 : _c.embedding) {
4786
- return res.data[0].embedding;
4787
- }
4788
- throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
4789
- } catch (dispatchErr) {
4790
- throw dispatchErr;
4788
+ const res = await dispatch({
4789
+ model: this.model,
4790
+ input: text
4791
+ }, this.apiKey);
4792
+ if ((_d = (_c = res == null ? void 0 : res.data) == null ? void 0 : _c[0]) == null ? void 0 : _d.embedding) {
4793
+ return res.data[0].embedding;
4791
4794
  }
4792
- } else {
4793
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
4794
4795
  }
4796
+ throw httpErr;
4795
4797
  }
4796
4798
  const { data } = await this.http.post(path2, payload);
4797
- const extractPath = (_d = this.opts.embedExtractPath) != null ? _d : "data[0].embedding";
4799
+ const extractPath = (_e = this.opts.embedExtractPath) != null ? _e : "data[0].embedding";
4798
4800
  const vector = resolvePath(data, extractPath);
4799
4801
  if (!Array.isArray(vector)) {
4800
4802
  throw new Error(`[UniversalLLMAdapter] Expected a number array at '${extractPath}' for embeddings.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@retrivora-ai/rag-engine",
3
- "version": "2.1.1",
3
+ "version": "2.1.2",
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",
@@ -112,8 +112,17 @@ export class UniversalLLMAdapter implements ILLMProvider {
112
112
  };
113
113
  }
114
114
 
115
- const isSelfHost = this.baseUrl.includes('retrivora.com') || this.baseUrl.includes('localhost');
116
- if (isSelfHost || Boolean(process.env.VERCEL)) {
115
+ // Try direct HTTP POST request to llm.retrivora.com first
116
+ try {
117
+ const { data } = await this.http.post(path, payload);
118
+ const extractPath = this.opts.responseExtractPath ?? 'choices[0].message.content';
119
+ const result = resolvePath(data, extractPath) ?? extractContent(data);
120
+ if (result !== undefined) {
121
+ return String(result);
122
+ }
123
+ } catch (httpErr: any) {
124
+ console.warn(`[UniversalLLMAdapter] Direct HTTP POST to ${this.baseUrl}${path} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
125
+
117
126
  const _g = globalThis as any;
118
127
  let dispatch = _g.__retrivoraDispatchChat;
119
128
  if (typeof dispatch !== 'function') {
@@ -128,25 +137,19 @@ export class UniversalLLMAdapter implements ILLMProvider {
128
137
  }
129
138
 
130
139
  if (typeof dispatch === 'function') {
131
- try {
132
- const res = await dispatch({
133
- model: this.model,
134
- messages: formattedMessages as any,
135
- max_tokens: this.maxTokens,
136
- temperature: this.temperature,
137
- }, this.apiKey);
138
-
139
- const content = extractContent(res?.response);
140
- if (content !== undefined) {
141
- return content;
142
- }
143
- throw new Error(`[UniversalLLMAdapter] In-process dispatch returned empty content for model: ${this.model}`);
144
- } catch (dispatchErr) {
145
- throw dispatchErr;
140
+ const res = await dispatch({
141
+ model: this.model,
142
+ messages: formattedMessages as any,
143
+ max_tokens: this.maxTokens,
144
+ temperature: this.temperature,
145
+ }, this.apiKey);
146
+
147
+ const content = extractContent(res?.response);
148
+ if (content !== undefined) {
149
+ return content;
146
150
  }
147
- } else {
148
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
149
151
  }
152
+ throw httpErr;
150
153
  }
151
154
 
152
155
  const { data } = await this.http.post(path, payload);
@@ -328,8 +331,17 @@ export class UniversalLLMAdapter implements ILLMProvider {
328
331
  };
329
332
  }
330
333
 
331
- const isSelfHost = this.baseUrl.includes('retrivora.com') || this.baseUrl.includes('localhost');
332
- if (isSelfHost || Boolean(process.env.VERCEL)) {
334
+ // Try direct HTTP POST request to llm.retrivora.com first
335
+ try {
336
+ const { data } = await this.http.post(path, payload);
337
+ const extractPath = this.opts.embedExtractPath ?? 'data[0].embedding';
338
+ const vector = resolvePath(data, extractPath);
339
+ if (Array.isArray(vector)) {
340
+ return vector as number[];
341
+ }
342
+ } catch (httpErr: any) {
343
+ console.warn(`[UniversalLLMAdapter] Direct HTTP embedding POST to ${this.baseUrl}${path} failed (${httpErr.message}). Attempting in-process gateway dispatch fallback...`);
344
+
333
345
  const _g = globalThis as any;
334
346
  let dispatch = _g.__retrivoraDispatchEmbedding;
335
347
  if (typeof dispatch !== 'function') {
@@ -344,22 +356,16 @@ export class UniversalLLMAdapter implements ILLMProvider {
344
356
  }
345
357
 
346
358
  if (typeof dispatch === 'function') {
347
- try {
348
- const res = await dispatch({
349
- model: this.model,
350
- input: text,
351
- }, this.apiKey);
359
+ const res = await dispatch({
360
+ model: this.model,
361
+ input: text,
362
+ }, this.apiKey);
352
363
 
353
- if (res?.data?.[0]?.embedding) {
354
- return res.data[0].embedding;
355
- }
356
- throw new Error(`[UniversalLLMAdapter] In-process embedding dispatch returned invalid vector for model: ${this.model}`);
357
- } catch (dispatchErr) {
358
- throw dispatchErr;
364
+ if (res?.data?.[0]?.embedding) {
365
+ return res.data[0].embedding;
359
366
  }
360
- } else {
361
- throw new Error(`[UniversalLLMAdapter] In-process gateway dispatch not registered. Direct self-referential HTTP calls to ${this.baseUrl} are disabled on Vercel to prevent HTTP 508 Loop Detected.`);
362
367
  }
368
+ throw httpErr;
363
369
  }
364
370
 
365
371
  const { data } = await this.http.post(path, payload);