@retrivora-ai/rag-engine 2.0.0 → 2.0.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.
- package/dist/handlers/index.js +5 -4
- package/dist/handlers/index.mjs +5 -4
- package/dist/server.js +5 -4
- package/dist/server.mjs +5 -4
- package/package.json +1 -1
- package/src/config/serverConfig.ts +1 -1
- package/src/core/Pipeline.ts +23 -19
- package/src/handlers/index.ts +10 -8
package/dist/handlers/index.js
CHANGED
|
@@ -2305,7 +2305,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2305
2305
|
},
|
|
2306
2306
|
telemetry: {
|
|
2307
2307
|
enabled: telemetryEnabled,
|
|
2308
|
-
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2308
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
|
|
2309
2309
|
}
|
|
2310
2310
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2311
2311
|
graphDb: {
|
|
@@ -7796,7 +7796,8 @@ ${context}`;
|
|
|
7796
7796
|
const trace = buildTrace(hallucinationResult);
|
|
7797
7797
|
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
7798
7798
|
if (isTelemetryActive) {
|
|
7799
|
-
const
|
|
7799
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
7800
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
7800
7801
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7801
7802
|
(async () => {
|
|
7802
7803
|
try {
|
|
@@ -9059,8 +9060,8 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
9059
9060
|
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9060
9061
|
const telemetryConfig = config.telemetry;
|
|
9061
9062
|
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9062
|
-
|
|
9063
|
-
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL ||
|
|
9063
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
9064
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
9064
9065
|
const host = req.headers.get("host") || "localhost";
|
|
9065
9066
|
let absoluteUrl = telemetryUrl;
|
|
9066
9067
|
if (!telemetryUrl.startsWith("http")) {
|
package/dist/handlers/index.mjs
CHANGED
|
@@ -2270,7 +2270,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2270
2270
|
},
|
|
2271
2271
|
telemetry: {
|
|
2272
2272
|
enabled: telemetryEnabled,
|
|
2273
|
-
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2273
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
|
|
2274
2274
|
}
|
|
2275
2275
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2276
2276
|
graphDb: {
|
|
@@ -7761,7 +7761,8 @@ ${context}`;
|
|
|
7761
7761
|
const trace = buildTrace(hallucinationResult);
|
|
7762
7762
|
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
7763
7763
|
if (isTelemetryActive) {
|
|
7764
|
-
const
|
|
7764
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
7765
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
7765
7766
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
7766
7767
|
(async () => {
|
|
7767
7768
|
try {
|
|
@@ -9024,8 +9025,8 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
9024
9025
|
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9025
9026
|
const telemetryConfig = config.telemetry;
|
|
9026
9027
|
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9027
|
-
|
|
9028
|
-
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL ||
|
|
9028
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
9029
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
9029
9030
|
const host = req.headers.get("host") || "localhost";
|
|
9030
9031
|
let absoluteUrl = telemetryUrl;
|
|
9031
9032
|
if (!telemetryUrl.startsWith("http")) {
|
package/dist/server.js
CHANGED
|
@@ -2349,7 +2349,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2349
2349
|
},
|
|
2350
2350
|
telemetry: {
|
|
2351
2351
|
enabled: telemetryEnabled,
|
|
2352
|
-
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2352
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
|
|
2353
2353
|
}
|
|
2354
2354
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2355
2355
|
graphDb: {
|
|
@@ -8090,7 +8090,8 @@ ${context}`;
|
|
|
8090
8090
|
const trace = buildTrace(hallucinationResult);
|
|
8091
8091
|
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
8092
8092
|
if (isTelemetryActive) {
|
|
8093
|
-
const
|
|
8093
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
8094
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
8094
8095
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
8095
8096
|
(async () => {
|
|
8096
8097
|
try {
|
|
@@ -9447,8 +9448,8 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
9447
9448
|
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9448
9449
|
const telemetryConfig = config.telemetry;
|
|
9449
9450
|
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9450
|
-
|
|
9451
|
-
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL ||
|
|
9451
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
9452
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
9452
9453
|
const host = req.headers.get("host") || "localhost";
|
|
9453
9454
|
let absoluteUrl = telemetryUrl;
|
|
9454
9455
|
if (!telemetryUrl.startsWith("http")) {
|
package/dist/server.mjs
CHANGED
|
@@ -2270,7 +2270,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
2270
2270
|
},
|
|
2271
2271
|
telemetry: {
|
|
2272
2272
|
enabled: telemetryEnabled,
|
|
2273
|
-
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : "/api/telemetry"
|
|
2273
|
+
url: (_Ua = (_Ta = (_Ra = readString(env, "TELEMETRY_URL")) != null ? _Ra : readString(env, "NEXT_PUBLIC_TELEMETRY_URL")) != null ? _Ta : (_Sa = base == null ? void 0 : base.telemetry) == null ? void 0 : _Sa.url) != null ? _Ua : process.env.NODE_ENV === "development" ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry"
|
|
2274
2274
|
}
|
|
2275
2275
|
}, readString(env, "GRAPH_DB_PROVIDER") ? {
|
|
2276
2276
|
graphDb: {
|
|
@@ -8011,7 +8011,8 @@ ${context}`;
|
|
|
8011
8011
|
const trace = buildTrace(hallucinationResult);
|
|
8012
8012
|
const isTelemetryActive = (_B = (_A = this.config.telemetry) == null ? void 0 : _A.enabled) != null ? _B : Boolean(this.config.licenseKey);
|
|
8013
8013
|
if (isTelemetryActive) {
|
|
8014
|
-
const
|
|
8014
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
8015
|
+
const telemetryUrl = ((_C = this.config.telemetry) == null ? void 0 : _C.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
8015
8016
|
const absoluteUrl = telemetryUrl.startsWith("http") ? telemetryUrl : (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3e3}`) + telemetryUrl;
|
|
8016
8017
|
(async () => {
|
|
8017
8018
|
try {
|
|
@@ -9368,8 +9369,8 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
9368
9369
|
const licenseKey = config.licenseKey || process.env.RAG_LICENSE_KEY || process.env.RETRIVORA_LICENSE_KEY || process.env.NEXT_PUBLIC_RETRIVORA_LICENSE_KEY;
|
|
9369
9370
|
const telemetryConfig = config.telemetry;
|
|
9370
9371
|
const enabled = (_a2 = telemetryConfig == null ? void 0 : telemetryConfig.enabled) != null ? _a2 : Boolean(licenseKey);
|
|
9371
|
-
|
|
9372
|
-
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL ||
|
|
9372
|
+
const defaultUrl = process.env.NODE_ENV === "development" && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL ? "http://localhost:3001/api/telemetry" : "https://retrivora.com/api/telemetry";
|
|
9373
|
+
const telemetryUrl = (telemetryConfig == null ? void 0 : telemetryConfig.url) || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
9373
9374
|
const host = req.headers.get("host") || "localhost";
|
|
9374
9375
|
let absoluteUrl = telemetryUrl;
|
|
9375
9376
|
if (!telemetryUrl.startsWith("http")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@retrivora-ai/rag-engine",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -233,7 +233,7 @@ export function getEnvConfig(env: Record<string, string | undefined> = process.e
|
|
|
233
233
|
},
|
|
234
234
|
telemetry: {
|
|
235
235
|
enabled: telemetryEnabled,
|
|
236
|
-
url: readString(env, 'TELEMETRY_URL') ?? readString(env, 'NEXT_PUBLIC_TELEMETRY_URL') ?? base?.telemetry?.url ?? '/api/telemetry',
|
|
236
|
+
url: readString(env, 'TELEMETRY_URL') ?? readString(env, 'NEXT_PUBLIC_TELEMETRY_URL') ?? base?.telemetry?.url ?? (process.env.NODE_ENV === 'development' ? 'http://localhost:3001/api/telemetry' : 'https://retrivora.com/api/telemetry'),
|
|
237
237
|
},
|
|
238
238
|
// Optional graph DB — driven by GRAPH_DB_PROVIDER env var
|
|
239
239
|
...(readString(env, 'GRAPH_DB_PROVIDER') ? {
|
package/src/core/Pipeline.ts
CHANGED
|
@@ -663,19 +663,19 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
663
663
|
const uiTransformationPromise = isProductQ
|
|
664
664
|
// Product carousel: pure heuristic, zero LLM latency
|
|
665
665
|
? Promise.resolve(
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
)
|
|
666
|
+
UITransformer.transform(question, sources, this.config, cachedSchema,
|
|
667
|
+
{ visualizationHint: 'product_browse', recommendedChart: 'text', filterInStockOnly: false, wantsExplicitTable: false, isTemporal: false, isComparison: false, language: 'en' }
|
|
669
668
|
)
|
|
669
|
+
)
|
|
670
670
|
: this.generateUiTransformation(
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
671
|
+
question,
|
|
672
|
+
sources,
|
|
673
|
+
cachedSchema,
|
|
674
|
+
hasNumericPredicates,
|
|
675
|
+
).catch(uiError => {
|
|
676
|
+
console.warn('[Pipeline] UI transformation failed concurrently:', uiError);
|
|
677
|
+
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
678
|
+
});
|
|
679
679
|
|
|
680
680
|
// 5. Generation (Streaming)
|
|
681
681
|
// Start hallucination scoring as a background promise BEFORE streaming
|
|
@@ -687,14 +687,14 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
687
687
|
Promise.resolve(undefined);
|
|
688
688
|
|
|
689
689
|
const restrictionSuffix = '\n\n(IMPORTANT: Format your response beautifully using rich Markdown! Use bolding for emphasis, headings (##) for structure, bullet points for lists, and proper line breaks between paragraphs to make it highly readable. However, NEVER generate Markdown tables, HTML figures, or text charts (the UI renders requested charts separately, so NEVER say you cannot create, display, draw, render, or provide a chart/visualization). If listing products, use simple markdown bullet points or comma-separated names. NEVER use plus signs (+) to separate product names, category names, or list items. For product description/detail questions, provide customer-facing prose only and do NOT list internal catalog fields such as Handle, Body (HTML), Vendor, Type, Tags, Published, Option, Variant, SKU, or raw metadata labels. You CAN use numbers for years/counts like 2006 or 5800, but NEVER put a dollar sign ($) before them.)';
|
|
690
|
-
|
|
690
|
+
|
|
691
691
|
const isClaude37 = this.config.llm.model.includes('claude-3-7-sonnet');
|
|
692
692
|
const isNativeThinking = isClaude37 && (this.config.llm.options?.thinking === true || this.config.llm.options?.thinking === 'enabled' || this.config.llm.options?.thinking !== false);
|
|
693
|
-
|
|
693
|
+
|
|
694
694
|
const modelNameLower = this.config.llm.model.toLowerCase();
|
|
695
695
|
const isReasoningModel = modelNameLower.includes('-r1') || modelNameLower.includes('deepseek-r1') || modelNameLower.includes('reasoning') || modelNameLower.includes('thinking');
|
|
696
696
|
const isSimulatedThinking = !isNativeThinking && (
|
|
697
|
-
this.config.llm.options?.thinking === true ||
|
|
697
|
+
this.config.llm.options?.thinking === true ||
|
|
698
698
|
this.config.llm.options?.thinking === 'enabled' ||
|
|
699
699
|
(isReasoningModel && this.config.llm.options?.thinking !== false)
|
|
700
700
|
);
|
|
@@ -720,7 +720,7 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
720
720
|
if (this.llmProvider.chatStream) {
|
|
721
721
|
const stream = this.llmProvider.chatStream(messages, context);
|
|
722
722
|
if (!stream) throw new Error(`[Pipeline] ${this.config.llm.provider} chatStream returned undefined`);
|
|
723
|
-
|
|
723
|
+
|
|
724
724
|
let inThinking = false;
|
|
725
725
|
let textBuffer = '';
|
|
726
726
|
|
|
@@ -820,7 +820,7 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
820
820
|
// Kick off hallucination scoring now that we have the full reply.
|
|
821
821
|
// It runs in parallel with the remaining post-processing below.
|
|
822
822
|
const runHallucination = this.config.llm.options?.hallucinationScoring === true ||
|
|
823
|
-
|
|
823
|
+
(this.config.llm.provider !== 'ollama' && this.config.llm.options?.hallucinationScoring !== false);
|
|
824
824
|
if (runHallucination) {
|
|
825
825
|
hallucinationScoringPromise = scoreHallucination(this.llmProvider, fullReply, context)
|
|
826
826
|
.catch(() => undefined);
|
|
@@ -850,7 +850,7 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
850
850
|
|
|
851
851
|
// 7. Await UI transformation and optionally hallucination score before yielding the metadata frame.
|
|
852
852
|
const awaitHallucination = this.config.llm.options?.awaitHallucination === true;
|
|
853
|
-
|
|
853
|
+
|
|
854
854
|
const [uiTransformation, hallucinationResult] = await Promise.all([
|
|
855
855
|
uiTransformationPromise,
|
|
856
856
|
awaitHallucination ? hallucinationScoringPromise : Promise.resolve(undefined),
|
|
@@ -883,7 +883,11 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
883
883
|
// Asynchronously trigger telemetry logging without blocking response yield
|
|
884
884
|
const isTelemetryActive = this.config.telemetry?.enabled ?? Boolean(this.config.licenseKey);
|
|
885
885
|
if (isTelemetryActive) {
|
|
886
|
-
const
|
|
886
|
+
const defaultUrl = process.env.NODE_ENV === 'development' && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL
|
|
887
|
+
? 'http://localhost:3001/api/telemetry'
|
|
888
|
+
: 'https://retrivora.com/api/telemetry';
|
|
889
|
+
|
|
890
|
+
const telemetryUrl = this.config.telemetry?.url || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
887
891
|
const absoluteUrl = telemetryUrl.startsWith('http')
|
|
888
892
|
? telemetryUrl
|
|
889
893
|
: (process.env.NEXT_PUBLIC_APP_URL || `http://localhost:${process.env.PORT || 3000}`) + telemetryUrl;
|
|
@@ -898,7 +902,7 @@ You are a helpful assistant. Use the provided context to answer questions accura
|
|
|
898
902
|
finalTrace = buildTrace(backgroundScoreResult);
|
|
899
903
|
}
|
|
900
904
|
}
|
|
901
|
-
|
|
905
|
+
|
|
902
906
|
await fetch(absoluteUrl, {
|
|
903
907
|
method: 'POST',
|
|
904
908
|
headers: {
|
package/src/handlers/index.ts
CHANGED
|
@@ -165,9 +165,11 @@ function reportTelemetry(
|
|
|
165
165
|
const telemetryConfig = config.telemetry;
|
|
166
166
|
|
|
167
167
|
const enabled = telemetryConfig?.enabled ?? Boolean(licenseKey);
|
|
168
|
-
|
|
168
|
+
const defaultUrl = process.env.NODE_ENV === 'development' && !process.env.TELEMETRY_URL && !process.env.NEXT_PUBLIC_TELEMETRY_URL
|
|
169
|
+
? 'http://localhost:3001/api/telemetry'
|
|
170
|
+
: 'https://retrivora.com/api/telemetry';
|
|
169
171
|
|
|
170
|
-
const telemetryUrl = telemetryConfig?.url || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL ||
|
|
172
|
+
const telemetryUrl = telemetryConfig?.url || process.env.TELEMETRY_URL || process.env.NEXT_PUBLIC_TELEMETRY_URL || defaultUrl;
|
|
171
173
|
const host = req.headers.get('host') || 'localhost';
|
|
172
174
|
|
|
173
175
|
let absoluteUrl = telemetryUrl;
|
|
@@ -578,17 +580,17 @@ export function createUploadHandler(
|
|
|
578
580
|
const text = await file.text();
|
|
579
581
|
const Papa = await import('papaparse');
|
|
580
582
|
const parsed = Papa.default.parse(text, { header: true, skipEmptyLines: true });
|
|
581
|
-
|
|
583
|
+
|
|
582
584
|
if (parsed.data && parsed.data.length > 0) {
|
|
583
585
|
let i = 0;
|
|
584
586
|
let lastRowData: Record<string, string> | null = null;
|
|
585
587
|
const csvCols = Object.keys(parsed.data[0] as Record<string, string>);
|
|
586
|
-
|
|
588
|
+
|
|
587
589
|
for (const row of parsed.data) {
|
|
588
590
|
i++;
|
|
589
591
|
const rowData = row as Record<string, string>;
|
|
590
592
|
const groupingKey = Object.keys(rowData)[0];
|
|
591
|
-
|
|
593
|
+
|
|
592
594
|
if (lastRowData && groupingKey && rowData[groupingKey] && rowData[groupingKey] === lastRowData[groupingKey]) {
|
|
593
595
|
for (const key of Object.keys(rowData)) {
|
|
594
596
|
if (!rowData[key] && lastRowData[key]) {
|
|
@@ -597,14 +599,14 @@ export function createUploadHandler(
|
|
|
597
599
|
}
|
|
598
600
|
}
|
|
599
601
|
lastRowData = { ...rowData };
|
|
600
|
-
|
|
602
|
+
|
|
601
603
|
const contentParts: string[] = [];
|
|
602
604
|
for (const [key, val] of Object.entries(rowData)) {
|
|
603
605
|
if (key && val) {
|
|
604
606
|
contentParts.push(`${key}: ${val}`);
|
|
605
607
|
}
|
|
606
608
|
}
|
|
607
|
-
|
|
609
|
+
|
|
608
610
|
documents.push({
|
|
609
611
|
docId: `${file.name}-row-${i}`,
|
|
610
612
|
content: contentParts.join(', '),
|
|
@@ -879,7 +881,7 @@ export function createRagHandler(
|
|
|
879
881
|
const resolvedParams = typeof context?.params?.then === 'function'
|
|
880
882
|
? await context.params
|
|
881
883
|
: context?.params;
|
|
882
|
-
|
|
884
|
+
|
|
883
885
|
const segments: string[] = resolvedParams?.retrivora || [];
|
|
884
886
|
return segments.join('/') || 'chat';
|
|
885
887
|
}
|