@retrivora-ai/rag-engine 2.5.2 → 2.5.4
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/FREE_TIER_ARCHITECTURE.md +232 -232
- package/README.md +206 -206
- package/dist/handlers/index.d.mts +2 -2
- package/dist/handlers/index.d.ts +2 -2
- package/dist/handlers/index.js +271 -202
- package/dist/handlers/index.mjs +271 -202
- package/dist/{BatchProcessor-B8OLSahY.d.ts → index--RhMcXrt.d.ts} +380 -379
- package/dist/{index-BC635WW-.d.ts → index-DE8qPWpI.d.mts} +3 -17
- package/dist/{BatchProcessor-OVOIlNfK.d.mts → index-Dex_gQ3P.d.mts} +380 -379
- package/dist/{index-D2mY1CrY.d.mts → index-DkOhRqEc.d.ts} +3 -17
- package/dist/index.css +869 -1302
- package/dist/index.d.mts +37 -18
- package/dist/index.d.ts +37 -18
- package/dist/index.js +421 -225
- package/dist/index.min.css +2 -2
- package/dist/index.mjs +445 -249
- package/dist/server.d.mts +36 -31
- package/dist/server.d.ts +36 -31
- package/dist/server.js +271 -202
- package/dist/server.mjs +271 -202
- package/package.json +156 -148
- package/dist/{ILLMProvider-BynaFBpy.d.mts → ILLMProvider-DO5gj-e5.d.mts} +83 -83
- package/dist/{ILLMProvider-BynaFBpy.d.ts → ILLMProvider-DO5gj-e5.d.ts} +83 -83
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.5.
|
|
329
|
+
version: "2.5.4",
|
|
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",
|
|
@@ -408,7 +408,7 @@ var init_package = __esm({
|
|
|
408
408
|
lint: "eslint",
|
|
409
409
|
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
410
410
|
test: "jest",
|
|
411
|
-
clean:
|
|
411
|
+
clean: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`
|
|
412
412
|
},
|
|
413
413
|
peerDependencies: {
|
|
414
414
|
axios: ">=1.0.0",
|
|
@@ -428,18 +428,24 @@ var init_package = __esm({
|
|
|
428
428
|
"@anthropic-ai/sdk": "^0.95.1",
|
|
429
429
|
"@google/genai": "^0.8.0",
|
|
430
430
|
"@google/generative-ai": "^0.24.1",
|
|
431
|
-
"@retrivora-ai/billing-guards": "*",
|
|
432
431
|
"@pinecone-database/pinecone": "^7.2.0",
|
|
432
|
+
"@retrivora-ai/billing-guards": "*",
|
|
433
433
|
"@types/papaparse": "^5.5.2",
|
|
434
|
+
"framer-motion": "^13.1.0",
|
|
435
|
+
katex: "^0.18.4",
|
|
434
436
|
"lucide-react": "^1.8.0",
|
|
435
437
|
"next-themes": "^0.4.6",
|
|
436
438
|
openai: "^6.34.0",
|
|
437
439
|
papaparse: "^5.5.3",
|
|
438
440
|
"react-is": "^18.3.1",
|
|
439
441
|
"react-markdown": "^10.1.0",
|
|
442
|
+
"react-syntax-highlighter": "^16.1.1",
|
|
440
443
|
recharts: "^3.8.1",
|
|
444
|
+
"rehype-katex": "^7.0.1",
|
|
441
445
|
"remark-gfm": "^4.0.1",
|
|
442
|
-
|
|
446
|
+
"remark-math": "^6.0.0",
|
|
447
|
+
exceljs: "^4.4.0",
|
|
448
|
+
zod: "^4.4.3"
|
|
443
449
|
},
|
|
444
450
|
optionalDependencies: {
|
|
445
451
|
"@langchain/core": "^1.1.42",
|
|
@@ -456,17 +462,19 @@ var init_package = __esm({
|
|
|
456
462
|
"@tailwindcss/postcss": "^4",
|
|
457
463
|
"@types/estree": "^1.0.9",
|
|
458
464
|
"@types/jest": "^30.0.0",
|
|
465
|
+
"@types/katex": "^0.16.8",
|
|
459
466
|
"@types/node": "^20",
|
|
460
467
|
"@types/pdf-parse": "^1.1.5",
|
|
461
468
|
"@types/pg": "^8.20.0",
|
|
462
469
|
"@types/react": "^19.2.14",
|
|
463
470
|
"@types/react-dom": "^19.2.3",
|
|
471
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
464
472
|
axios: "^1.15.0",
|
|
465
473
|
dotenv: "^17.4.2",
|
|
466
474
|
eslint: "^9",
|
|
467
|
-
"eslint-config-next": "16.2
|
|
475
|
+
"eslint-config-next": "16.3.2",
|
|
468
476
|
jest: "^30.4.2",
|
|
469
|
-
next: "16.2
|
|
477
|
+
next: "^16.3.2",
|
|
470
478
|
tailwindcss: "^4",
|
|
471
479
|
"ts-jest": "^29.4.12",
|
|
472
480
|
tsup: "^8.5.1",
|
|
@@ -2763,6 +2771,36 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2763
2771
|
// src/core/LicenseVerifier.ts
|
|
2764
2772
|
var _LicenseVerifier = class _LicenseVerifier {
|
|
2765
2773
|
// Cache verified license for 5 minutes
|
|
2774
|
+
/**
|
|
2775
|
+
* Computes a deterministic hardware fingerprint to enforce node-locked licensing.
|
|
2776
|
+
*/
|
|
2777
|
+
static async generateMachineFingerprint() {
|
|
2778
|
+
if (typeof window !== "undefined" && typeof navigator !== "undefined") {
|
|
2779
|
+
return navigator.userAgent || "browser-fallback-fingerprint";
|
|
2780
|
+
}
|
|
2781
|
+
try {
|
|
2782
|
+
const os2 = await import("os");
|
|
2783
|
+
const crypto2 = await import("crypto");
|
|
2784
|
+
const interfaces = os2.networkInterfaces();
|
|
2785
|
+
const macAddresses = [];
|
|
2786
|
+
for (const name of Object.keys(interfaces)) {
|
|
2787
|
+
for (const iface of interfaces[name] || []) {
|
|
2788
|
+
if (!iface.internal && iface.mac && iface.mac !== "00:00:00:00:00:00") {
|
|
2789
|
+
macAddresses.push(iface.mac);
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
const rawData = [
|
|
2794
|
+
macAddresses.sort().join(","),
|
|
2795
|
+
os2.platform(),
|
|
2796
|
+
os2.arch(),
|
|
2797
|
+
os2.hostname()
|
|
2798
|
+
].join("|");
|
|
2799
|
+
return crypto2.createHash("sha256").update(rawData).digest("hex");
|
|
2800
|
+
} catch (err) {
|
|
2801
|
+
return "fallback-fingerprint-failed";
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2766
2804
|
/**
|
|
2767
2805
|
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2768
2806
|
*
|
|
@@ -2806,6 +2844,7 @@ var _LicenseVerifier = class _LicenseVerifier {
|
|
|
2806
2844
|
}
|
|
2807
2845
|
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2808
2846
|
let response;
|
|
2847
|
+
const machineFingerprint = await this.generateMachineFingerprint();
|
|
2809
2848
|
try {
|
|
2810
2849
|
response = await fetch(endpoint, {
|
|
2811
2850
|
method: "POST",
|
|
@@ -2816,7 +2855,8 @@ var _LicenseVerifier = class _LicenseVerifier {
|
|
|
2816
2855
|
body: JSON.stringify({
|
|
2817
2856
|
licenseKey,
|
|
2818
2857
|
projectId: currentProjectId,
|
|
2819
|
-
provider
|
|
2858
|
+
provider,
|
|
2859
|
+
machineFingerprint
|
|
2820
2860
|
})
|
|
2821
2861
|
});
|
|
2822
2862
|
} catch (fetchErr) {
|
|
@@ -3024,7 +3064,6 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
3024
3064
|
"rest",
|
|
3025
3065
|
"universal_rest"
|
|
3026
3066
|
];
|
|
3027
|
-
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
3028
3067
|
|
|
3029
3068
|
// src/config/serverConfig.ts
|
|
3030
3069
|
var _runtimeConfig = null;
|
|
@@ -3145,7 +3184,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3145
3184
|
return true;
|
|
3146
3185
|
}
|
|
3147
3186
|
})();
|
|
3148
|
-
const tierBasedLLMModel = isFreeTier2 ? "
|
|
3187
|
+
const tierBasedLLMModel = isFreeTier2 ? "free-tier-standard" : "qwen-3.6-27b";
|
|
3149
3188
|
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3150
3189
|
const controlPlaneUrl = (_ma = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _ma : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
|
|
3151
3190
|
const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
|
|
@@ -3153,7 +3192,16 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3153
3192
|
const defaultLlmProvider = "universal_rest";
|
|
3154
3193
|
const llmProvider = (_pa = (_oa = readEnum(env, "LLM_PROVIDER", defaultLlmProvider, LLM_PROVIDERS)) != null ? _oa : (_na = base == null ? void 0 : base.llm) == null ? void 0 : _na.provider) != null ? _pa : defaultLlmProvider;
|
|
3155
3194
|
const llmBaseUrl = (_ua = (_ta = (_sa = (_qa = readString(env, "LITELLM_BASE_URL")) != null ? _qa : readString(env, "LLM_BASE_URL")) != null ? _sa : (_ra = base == null ? void 0 : base.llm) == null ? void 0 : _ra.baseUrl) != null ? _ta : rt == null ? void 0 : rt.llmBaseUrl) != null ? _ua : defaultGatewayUrl;
|
|
3156
|
-
|
|
3195
|
+
let llmModel = (_ya = (_xa = (_wa = readString(env, "LLM_MODEL")) != null ? _wa : (_va = base == null ? void 0 : base.llm) == null ? void 0 : _va.model) != null ? _xa : rt == null ? void 0 : rt.llmModel) != null ? _ya : tierBasedLLMModel;
|
|
3196
|
+
if ((rt == null ? void 0 : rt.allowedModels) && rt.allowedModels.length > 0) {
|
|
3197
|
+
if (!rt.allowedModels.includes(llmModel)) {
|
|
3198
|
+
console.warn(`[Retrivora SDK] Model "${llmModel}" is not permitted on the current license tier. Falling back to default: ${rt.llmModel || tierBasedLLMModel}`);
|
|
3199
|
+
llmModel = rt.llmModel || tierBasedLLMModel;
|
|
3200
|
+
}
|
|
3201
|
+
} else if (isFreeTier2 && llmModel !== "free-tier-standard") {
|
|
3202
|
+
console.warn(`[Retrivora SDK] Explicit models are not permitted on the Free tier. Falling back to default load-balanced pool.`);
|
|
3203
|
+
llmModel = "free-tier-standard";
|
|
3204
|
+
}
|
|
3157
3205
|
const llmApiKey = (_Ca = (_Ba = (_za = readString(env, "LITELLM_MASTER_KEY")) != null ? _za : rt == null ? void 0 : rt.litellmApiKey) != null ? _Ba : (_Aa = base == null ? void 0 : base.llm) == null ? void 0 : _Aa.apiKey) != null ? _Ca : licenseKey;
|
|
3158
3206
|
const llmProfile = (_Ga = (_Fa = readString(env, "LLM_UNIVERSAL_PROFILE")) != null ? _Fa : (_Ea = (_Da = base == null ? void 0 : base.llm) == null ? void 0 : _Da.options) == null ? void 0 : _Ea.profile) != null ? _Ga : "litellm";
|
|
3159
3207
|
const defaultEmbeddingProvider = "universal_rest";
|
|
@@ -3366,6 +3414,9 @@ var ConfigResolver = class {
|
|
|
3366
3414
|
}
|
|
3367
3415
|
};
|
|
3368
3416
|
|
|
3417
|
+
// src/core/ConfigValidator.ts
|
|
3418
|
+
import { z } from "zod";
|
|
3419
|
+
|
|
3369
3420
|
// src/llm/providers/OpenAIProvider.ts
|
|
3370
3421
|
import OpenAI from "openai";
|
|
3371
3422
|
|
|
@@ -3389,7 +3440,11 @@ ${context}`;
|
|
|
3389
3440
|
var OpenAIProvider = class {
|
|
3390
3441
|
constructor(llmConfig, embeddingConfig) {
|
|
3391
3442
|
if (!llmConfig.apiKey) throw new Error("[OpenAIProvider] llmConfig.apiKey is required");
|
|
3392
|
-
this.client = new OpenAI({
|
|
3443
|
+
this.client = new OpenAI({
|
|
3444
|
+
apiKey: llmConfig.apiKey,
|
|
3445
|
+
baseURL: llmConfig.baseUrl,
|
|
3446
|
+
maxRetries: 5
|
|
3447
|
+
});
|
|
3393
3448
|
this.llmConfig = llmConfig;
|
|
3394
3449
|
this.embeddingConfig = embeddingConfig;
|
|
3395
3450
|
}
|
|
@@ -4151,7 +4206,8 @@ var GroqProvider = class {
|
|
|
4151
4206
|
if (!apiKey) throw new Error("[GroqProvider] llmConfig.apiKey or GROQ_API_KEY environment variable is required");
|
|
4152
4207
|
this.client = new OpenAI2({
|
|
4153
4208
|
apiKey,
|
|
4154
|
-
baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1"
|
|
4209
|
+
baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1",
|
|
4210
|
+
maxRetries: 5
|
|
4155
4211
|
});
|
|
4156
4212
|
this.llmConfig = llmConfig;
|
|
4157
4213
|
}
|
|
@@ -4171,7 +4227,7 @@ var GroqProvider = class {
|
|
|
4171
4227
|
errors.push({
|
|
4172
4228
|
field: "llm.model",
|
|
4173
4229
|
message: "Groq model name is required",
|
|
4174
|
-
suggestion: 'e.g., "
|
|
4230
|
+
suggestion: 'e.g., "qwen-3.6-27b"',
|
|
4175
4231
|
severity: "error"
|
|
4176
4232
|
});
|
|
4177
4233
|
}
|
|
@@ -5123,24 +5179,69 @@ ProviderRegistry.llmValidators = {};
|
|
|
5123
5179
|
ProviderRegistry.llmHealthCheckers = {};
|
|
5124
5180
|
|
|
5125
5181
|
// src/core/ConfigValidator.ts
|
|
5182
|
+
var UIConfigSchema = z.object({
|
|
5183
|
+
primaryColor: z.string().optional(),
|
|
5184
|
+
borderRadius: z.enum(["none", "sm", "md", "lg", "xl", "full"]).optional()
|
|
5185
|
+
}).passthrough().optional();
|
|
5186
|
+
var VectorDbSchema = z.object({
|
|
5187
|
+
provider: z.string().min(1, "Vector database provider is required"),
|
|
5188
|
+
indexName: z.string().min(1, "Vector database index name is required"),
|
|
5189
|
+
options: z.record(z.string(), z.unknown()).optional()
|
|
5190
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5191
|
+
const opts = val.options || {};
|
|
5192
|
+
if (val.provider === "milvus") {
|
|
5193
|
+
if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
|
|
5194
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Milvus connection info required" });
|
|
5195
|
+
}
|
|
5196
|
+
} else if (val.provider === "qdrant") {
|
|
5197
|
+
if (!opts.baseUrl && !opts.url) {
|
|
5198
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Qdrant URL required" });
|
|
5199
|
+
}
|
|
5200
|
+
}
|
|
5201
|
+
});
|
|
5202
|
+
var LLMSchema = z.object({
|
|
5203
|
+
provider: z.string().min(1, "LLM provider is required"),
|
|
5204
|
+
model: z.string().optional(),
|
|
5205
|
+
temperature: z.number().min(0, "Temperature must be at least 0").max(2, "Temperature must be at most 2").optional()
|
|
5206
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5207
|
+
if (!val.model) {
|
|
5208
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["model"], message: "LLM model name is required" });
|
|
5209
|
+
}
|
|
5210
|
+
});
|
|
5211
|
+
var EmbeddingSchema = z.object({
|
|
5212
|
+
provider: z.string().min(1, "Embedding provider is required"),
|
|
5213
|
+
model: z.string().optional()
|
|
5214
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5215
|
+
if (!val.model) {
|
|
5216
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["model"], message: "Embedding model name is required" });
|
|
5217
|
+
}
|
|
5218
|
+
});
|
|
5219
|
+
var RAGSchema = z.object({
|
|
5220
|
+
topK: z.number().positive("topK must be a positive integer").optional()
|
|
5221
|
+
}).passthrough().optional();
|
|
5222
|
+
var RagConfigSchema = z.object({
|
|
5223
|
+
projectId: z.string().min(1, "projectId is required"),
|
|
5224
|
+
vectorDb: VectorDbSchema,
|
|
5225
|
+
llm: LLMSchema,
|
|
5226
|
+
embedding: EmbeddingSchema.optional(),
|
|
5227
|
+
ui: UIConfigSchema,
|
|
5228
|
+
rag: RAGSchema
|
|
5229
|
+
}).passthrough();
|
|
5126
5230
|
var ConfigValidator = class {
|
|
5127
|
-
/**
|
|
5128
|
-
* Validates the entire RagConfig object.
|
|
5129
|
-
*/
|
|
5130
5231
|
static async validate(config) {
|
|
5232
|
+
var _a2, _b, _c, _d, _e;
|
|
5131
5233
|
const errors = [];
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5234
|
+
const result = RagConfigSchema.safeParse(config);
|
|
5235
|
+
if (!result.success) {
|
|
5236
|
+
for (const issue of result.error.issues) {
|
|
5237
|
+
errors.push({
|
|
5238
|
+
field: issue.path.join("."),
|
|
5239
|
+
message: issue.message,
|
|
5240
|
+
severity: "error"
|
|
5241
|
+
});
|
|
5242
|
+
}
|
|
5138
5243
|
}
|
|
5139
|
-
|
|
5140
|
-
errors.push(...await this.validateLLMConfig(config.llm));
|
|
5141
|
-
if (config.embedding) {
|
|
5142
|
-
errors.push(...await this.validateEmbeddingConfig(config.embedding));
|
|
5143
|
-
} else if (config.llm.provider === "anthropic") {
|
|
5244
|
+
if (((_a2 = config.llm) == null ? void 0 : _a2.provider) === "anthropic" && !config.embedding) {
|
|
5144
5245
|
errors.push({
|
|
5145
5246
|
field: "embedding",
|
|
5146
5247
|
message: "Embedding config is required when using Anthropic LLM",
|
|
@@ -5148,113 +5249,35 @@ var ConfigValidator = class {
|
|
|
5148
5249
|
severity: "error"
|
|
5149
5250
|
});
|
|
5150
5251
|
}
|
|
5151
|
-
if (config.ui) {
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
static async validateVectorDbConfig(config) {
|
|
5160
|
-
const errors = [];
|
|
5161
|
-
if (!config.provider) {
|
|
5162
|
-
errors.push({ field: "vectorDb.provider", message: "Vector database provider is required", severity: "error" });
|
|
5163
|
-
return errors;
|
|
5164
|
-
}
|
|
5165
|
-
if (!config.indexName) {
|
|
5166
|
-
errors.push({ field: "vectorDb.indexName", message: "Vector database index name is required", severity: "error" });
|
|
5167
|
-
}
|
|
5168
|
-
const validator = await ProviderRegistry.getVectorValidator(config.provider);
|
|
5169
|
-
if (validator) {
|
|
5170
|
-
errors.push(...validator.validate(config));
|
|
5171
|
-
} else {
|
|
5172
|
-
this.fallbackVectorValidation(config, errors);
|
|
5173
|
-
}
|
|
5174
|
-
return errors;
|
|
5175
|
-
}
|
|
5176
|
-
static async validateLLMConfig(config) {
|
|
5177
|
-
const errors = [];
|
|
5178
|
-
if (!config.provider) {
|
|
5179
|
-
errors.push({ field: "llm.provider", message: "LLM provider is required", severity: "error" });
|
|
5180
|
-
return errors;
|
|
5181
|
-
}
|
|
5182
|
-
const validator = LLMFactory.getValidator(config.provider);
|
|
5183
|
-
if (validator) {
|
|
5184
|
-
errors.push(...validator.validate(config));
|
|
5185
|
-
} else {
|
|
5186
|
-
this.fallbackLLMValidation(config, errors);
|
|
5187
|
-
}
|
|
5188
|
-
if (config.temperature !== void 0 && (config.temperature < 0 || config.temperature > 2)) {
|
|
5189
|
-
errors.push({ field: "llm.temperature", message: "Temperature must be between 0 and 2", severity: "error" });
|
|
5190
|
-
}
|
|
5191
|
-
return errors;
|
|
5192
|
-
}
|
|
5193
|
-
static async validateEmbeddingConfig(config) {
|
|
5194
|
-
const errors = [];
|
|
5195
|
-
if (!config.provider) {
|
|
5196
|
-
errors.push({ field: "embedding.provider", message: "Embedding provider is required", severity: "error" });
|
|
5197
|
-
return errors;
|
|
5198
|
-
}
|
|
5199
|
-
const validator = LLMFactory.getValidator(config.provider);
|
|
5200
|
-
if (validator) {
|
|
5201
|
-
errors.push(...validator.validate(config));
|
|
5202
|
-
} else {
|
|
5203
|
-
this.fallbackEmbeddingValidation(config, errors);
|
|
5204
|
-
}
|
|
5205
|
-
return errors;
|
|
5206
|
-
}
|
|
5207
|
-
/**
|
|
5208
|
-
* Temporary fallbacks for providers not yet migrated to the pluggable architecture.
|
|
5209
|
-
*/
|
|
5210
|
-
static fallbackVectorValidation(config, errors) {
|
|
5211
|
-
const opts = config.options || {};
|
|
5212
|
-
switch (config.provider) {
|
|
5213
|
-
case "milvus":
|
|
5214
|
-
if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
|
|
5215
|
-
errors.push({ field: "vectorDb.options.baseUrl", message: "Milvus connection info required", severity: "error" });
|
|
5216
|
-
}
|
|
5217
|
-
break;
|
|
5218
|
-
case "qdrant":
|
|
5219
|
-
if (!opts.baseUrl && !opts.url) {
|
|
5220
|
-
errors.push({ field: "vectorDb.options.baseUrl", message: "Qdrant URL required", severity: "error" });
|
|
5221
|
-
}
|
|
5222
|
-
break;
|
|
5223
|
-
}
|
|
5224
|
-
}
|
|
5225
|
-
static fallbackLLMValidation(config, errors) {
|
|
5226
|
-
if (!config.model) {
|
|
5227
|
-
errors.push({ field: "llm.model", message: "LLM model name is required", severity: "error" });
|
|
5228
|
-
}
|
|
5229
|
-
}
|
|
5230
|
-
static fallbackEmbeddingValidation(config, errors) {
|
|
5231
|
-
if (!config.model) {
|
|
5232
|
-
errors.push({ field: "embedding.model", message: "Embedding model name is required", severity: "error" });
|
|
5252
|
+
if ((_b = config.ui) == null ? void 0 : _b.primaryColor) {
|
|
5253
|
+
const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
|
|
5254
|
+
const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
|
|
5255
|
+
const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
|
|
5256
|
+
const color = config.ui.primaryColor;
|
|
5257
|
+
if (!hexRegex.test(color) && !rgbRegex.test(color) && !namedColors.includes(color.toLowerCase())) {
|
|
5258
|
+
errors.push({ field: "ui.primaryColor", message: "Invalid CSS color format", severity: "warning" });
|
|
5259
|
+
}
|
|
5233
5260
|
}
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5261
|
+
if ((_c = config.vectorDb) == null ? void 0 : _c.provider) {
|
|
5262
|
+
const vectorValidator = await ProviderRegistry.getVectorValidator(config.vectorDb.provider);
|
|
5263
|
+
if (vectorValidator) {
|
|
5264
|
+
errors.push(...vectorValidator.validate(config.vectorDb));
|
|
5265
|
+
}
|
|
5239
5266
|
}
|
|
5240
|
-
if (config.
|
|
5241
|
-
|
|
5267
|
+
if ((_d = config.llm) == null ? void 0 : _d.provider) {
|
|
5268
|
+
const llmValidator = LLMFactory.getValidator(config.llm.provider);
|
|
5269
|
+
if (llmValidator) {
|
|
5270
|
+
errors.push(...llmValidator.validate(config.llm));
|
|
5271
|
+
}
|
|
5242
5272
|
}
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
errors.push({ field: "rag.topK", message: "topK must be a positive integer", severity: "error" });
|
|
5273
|
+
if ((_e = config.embedding) == null ? void 0 : _e.provider) {
|
|
5274
|
+
const embeddingValidator = LLMFactory.getValidator(config.embedding.provider);
|
|
5275
|
+
if (embeddingValidator) {
|
|
5276
|
+
errors.push(...embeddingValidator.validate(config.embedding));
|
|
5277
|
+
}
|
|
5249
5278
|
}
|
|
5250
5279
|
return errors;
|
|
5251
5280
|
}
|
|
5252
|
-
static isValidCSSColor(color) {
|
|
5253
|
-
const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
|
|
5254
|
-
const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
|
|
5255
|
-
const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
|
|
5256
|
-
return hexRegex.test(color) || rgbRegex.test(color) || namedColors.includes(color.toLowerCase());
|
|
5257
|
-
}
|
|
5258
5281
|
static async validateAndThrow(config) {
|
|
5259
5282
|
const errors = await this.validate(config);
|
|
5260
5283
|
const errorItems = errors.filter((e) => e.severity === "error");
|
|
@@ -5900,6 +5923,38 @@ var MCPRegistry = class {
|
|
|
5900
5923
|
}
|
|
5901
5924
|
};
|
|
5902
5925
|
|
|
5926
|
+
// src/utils/logger.ts
|
|
5927
|
+
var Logger = class {
|
|
5928
|
+
static format(level, message, meta) {
|
|
5929
|
+
if (this.isProduction) {
|
|
5930
|
+
return JSON.stringify(__spreadValues({
|
|
5931
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5932
|
+
level,
|
|
5933
|
+
message
|
|
5934
|
+
}, meta));
|
|
5935
|
+
}
|
|
5936
|
+
const metaString = meta ? `
|
|
5937
|
+
${JSON.stringify(meta, null, 2)}` : "";
|
|
5938
|
+
return `[${(/* @__PURE__ */ new Date()).toISOString()}] [${level}] ${message}${metaString}`;
|
|
5939
|
+
}
|
|
5940
|
+
static info(message, meta) {
|
|
5941
|
+
console.log(this.format("INFO", message, meta));
|
|
5942
|
+
}
|
|
5943
|
+
static warn(message, meta) {
|
|
5944
|
+
console.warn(this.format("WARN", message, meta));
|
|
5945
|
+
}
|
|
5946
|
+
static error(message, error, meta) {
|
|
5947
|
+
const errorMeta = error instanceof Error ? { errorMessage: error.message, stack: error.stack } : { error: String(error) };
|
|
5948
|
+
console.error(this.format("ERROR", message, __spreadValues(__spreadValues({}, meta), errorMeta)));
|
|
5949
|
+
}
|
|
5950
|
+
static debug(message, meta) {
|
|
5951
|
+
if (process.env.DEBUG === "true") {
|
|
5952
|
+
console.debug(this.format("DEBUG", message, meta));
|
|
5953
|
+
}
|
|
5954
|
+
}
|
|
5955
|
+
};
|
|
5956
|
+
Logger.isProduction = process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production";
|
|
5957
|
+
|
|
5903
5958
|
// src/core/MultiAgentCoordinator.ts
|
|
5904
5959
|
function parseToolCall(text) {
|
|
5905
5960
|
const match = text.match(/TOOL_CALL:\s*([\w-]+)\s*\(\s*([\s\S]*?)\s*\)\s*[.,;]?\s*$/m);
|
|
@@ -5917,7 +5972,7 @@ function parseToolCall(text) {
|
|
|
5917
5972
|
} catch (e) {
|
|
5918
5973
|
const pairs = [...argsRaw.matchAll(/"?([\w-]+)"?\s*:\s*"([^"]*)"/g)];
|
|
5919
5974
|
if (pairs.length === 0) {
|
|
5920
|
-
|
|
5975
|
+
Logger.warn("[parseToolCall] Could not parse tool args", { argsRaw });
|
|
5921
5976
|
return null;
|
|
5922
5977
|
}
|
|
5923
5978
|
for (const [, k, v] of pairs) args[k] = v;
|
|
@@ -6320,7 +6375,7 @@ ${errorMessages}`
|
|
|
6320
6375
|
static async mapWithRetry(items, mapper, options) {
|
|
6321
6376
|
const result = await this.processSequential(items, mapper, options);
|
|
6322
6377
|
if (result.errors.length > 0) {
|
|
6323
|
-
|
|
6378
|
+
Logger.warn(
|
|
6324
6379
|
`[BatchProcessor] mapWithRetry: ${result.errors.length} items failed`
|
|
6325
6380
|
);
|
|
6326
6381
|
}
|
|
@@ -9072,7 +9127,7 @@ var Pipeline = class {
|
|
|
9072
9127
|
}
|
|
9073
9128
|
await this.vectorDB.initialize();
|
|
9074
9129
|
if (this.isMultiAgentMode) {
|
|
9075
|
-
|
|
9130
|
+
Logger.info("[Pipeline] Initializing MultiAgentCoordinator (multi-agent / MCP mode).");
|
|
9076
9131
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
9077
9132
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
9078
9133
|
llmProvider: this.llmProvider,
|
|
@@ -9082,7 +9137,7 @@ var Pipeline = class {
|
|
|
9082
9137
|
maxIterations: (_a2 = this.config.rag) == null ? void 0 : _a2.agentMaxIterations
|
|
9083
9138
|
});
|
|
9084
9139
|
} else if (this.isLangChainAgentMode) {
|
|
9085
|
-
|
|
9140
|
+
Logger.info("[Pipeline] Initializing LangChainAgent (agentic / ReAct mode).");
|
|
9086
9141
|
this.agent = new LangChainAgent(this, this.config);
|
|
9087
9142
|
await this.agent.initialize(this.llmProvider);
|
|
9088
9143
|
}
|
|
@@ -9105,13 +9160,13 @@ var Pipeline = class {
|
|
|
9105
9160
|
const formatted = coldMatches.map((m, i) => `[Cold Source ${i + 1}]
|
|
9106
9161
|
${m.content}`).join("\n\n---\n\n");
|
|
9107
9162
|
this.coldContexts.set(ns, formatted);
|
|
9108
|
-
|
|
9163
|
+
Logger.info(`[Pipeline] Cold RAG (CAG) loaded ${coldMatches.length} documents into cached context for namespace: ${ns}`);
|
|
9109
9164
|
} else {
|
|
9110
9165
|
this.coldContexts.set(ns, "No cold context found.");
|
|
9111
|
-
|
|
9166
|
+
Logger.warn(`[Pipeline] Cold RAG (CAG) initialized but no documents were found in namespace: ${coldNs}`);
|
|
9112
9167
|
}
|
|
9113
9168
|
} catch (err) {
|
|
9114
|
-
|
|
9169
|
+
Logger.error(`[Pipeline] Failed to load Cold RAG (CAG) context for namespace ${ns}`, err);
|
|
9115
9170
|
this.coldContexts.set(ns, "Failed to load cold context.");
|
|
9116
9171
|
}
|
|
9117
9172
|
}
|
|
@@ -9138,7 +9193,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9138
9193
|
await this.processGraphIngestion(doc.docId, chunks);
|
|
9139
9194
|
}
|
|
9140
9195
|
} catch (error) {
|
|
9141
|
-
|
|
9196
|
+
Logger.error(`[Pipeline] Failed to ingest document ${doc.docId}`, error);
|
|
9142
9197
|
results.push({ docId: doc.docId, chunksIngested: 0 });
|
|
9143
9198
|
}
|
|
9144
9199
|
}
|
|
@@ -9192,10 +9247,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9192
9247
|
upsertBatchOptions
|
|
9193
9248
|
);
|
|
9194
9249
|
if (upsertResult.errors.length > 0) {
|
|
9195
|
-
|
|
9196
|
-
upsertResult.errors.forEach((err, idx) => {
|
|
9197
|
-
console.warn(` Batch ${idx + 1} Error: ${err.error.message || String(err.error)}`);
|
|
9198
|
-
});
|
|
9250
|
+
Logger.warn(`[Pipeline] Ingestion: ${upsertResult.errors.length} batches failed.`, { errors: upsertResult.errors.map((e) => e.error.message || String(e.error)) });
|
|
9199
9251
|
}
|
|
9200
9252
|
return upsertResult.totalProcessed;
|
|
9201
9253
|
}
|
|
@@ -9215,7 +9267,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9215
9267
|
if (nodes.length > 0) await this.graphDB.addNodes(nodes);
|
|
9216
9268
|
if (edges.length > 0) await this.graphDB.addEdges(edges);
|
|
9217
9269
|
} catch (err) {
|
|
9218
|
-
|
|
9270
|
+
Logger.warn(`[Pipeline] Entity extraction failed for chunk in doc ${docId}`, { error: String(err) });
|
|
9219
9271
|
}
|
|
9220
9272
|
}
|
|
9221
9273
|
},
|
|
@@ -9476,7 +9528,7 @@ ${context}`;
|
|
|
9476
9528
|
cachedSchema,
|
|
9477
9529
|
hasNumericPredicates
|
|
9478
9530
|
).catch((uiError) => {
|
|
9479
|
-
|
|
9531
|
+
Logger.warn("[Pipeline] UI transformation failed concurrently", { error: String(uiError) });
|
|
9480
9532
|
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
9481
9533
|
});
|
|
9482
9534
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
@@ -9678,7 +9730,9 @@ ${context}`;
|
|
|
9678
9730
|
const tokenCount = Number(((_c2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _c2.totalTokens) || 0);
|
|
9679
9731
|
const costEst = Number(((_d2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _d2.estimatedCostUsd) || 0);
|
|
9680
9732
|
const latencyDuration = Number(((_e2 = finalTrace == null ? void 0 : finalTrace.latency) == null ? void 0 : _e2.totalMs) || 0);
|
|
9681
|
-
|
|
9733
|
+
if (typeof window === "undefined") {
|
|
9734
|
+
Logger.info(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
|
|
9735
|
+
}
|
|
9682
9736
|
await fetch(absoluteUrl, {
|
|
9683
9737
|
method: "POST",
|
|
9684
9738
|
headers: {
|
|
@@ -9702,9 +9756,11 @@ ${context}`;
|
|
|
9702
9756
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9703
9757
|
details: `Org: default-org | Model: ${providerName}/${modelName} | Tokens: ${tokenCount} | Latency: ${latencyDuration}ms | Cost: $${costEst} | SDK: v${SDK_VERSION} | Feature: RAG`
|
|
9704
9758
|
})
|
|
9759
|
+
}).catch((err) => {
|
|
9760
|
+
Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}`, { error: err.message });
|
|
9705
9761
|
});
|
|
9706
9762
|
} catch (err) {
|
|
9707
|
-
|
|
9763
|
+
Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}:`, { error: err.message });
|
|
9708
9764
|
}
|
|
9709
9765
|
})();
|
|
9710
9766
|
}
|
|
@@ -9747,7 +9803,7 @@ ${context}`;
|
|
|
9747
9803
|
try {
|
|
9748
9804
|
return await UITransformer.analyzeAndDecide(question, sources, this.llmRouter.get("fast"));
|
|
9749
9805
|
} catch (err) {
|
|
9750
|
-
|
|
9806
|
+
Logger.warn("[Pipeline] generateUiTransformation failed, using heuristic fallback", { error: String(err) });
|
|
9751
9807
|
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
9752
9808
|
}
|
|
9753
9809
|
}
|
|
@@ -9845,7 +9901,7 @@ ${context}`;
|
|
|
9845
9901
|
query,
|
|
9846
9902
|
useGraph ? this.llmRouter.get("fast") : void 0
|
|
9847
9903
|
);
|
|
9848
|
-
|
|
9904
|
+
Logger.debug(`[Pipeline] Determined retrieval strategy: ${strategy}`);
|
|
9849
9905
|
const [retrievedVector, graphData] = await Promise.all([
|
|
9850
9906
|
// Only embed if we need vector search (strategy is 'vector' or 'both')
|
|
9851
9907
|
strategy === "vector" || strategy === "both" ? queryVector ? Promise.resolve(queryVector) : this.embeddingProvider.embed(query, { taskType: "query" }) : Promise.resolve([]),
|
|
@@ -9867,8 +9923,7 @@ ${context}`;
|
|
|
9867
9923
|
baseFilter
|
|
9868
9924
|
) : [];
|
|
9869
9925
|
const resolvedSources = sources;
|
|
9870
|
-
|
|
9871
|
-
query,
|
|
9926
|
+
Logger.info("[Pipeline] retrieve() response", {
|
|
9872
9927
|
namespace: ns,
|
|
9873
9928
|
count: resolvedSources.length,
|
|
9874
9929
|
sample: resolvedSources.slice(0, 2).map((s) => {
|
|
@@ -9948,7 +10003,7 @@ Suggestions:`;
|
|
|
9948
10003
|
}
|
|
9949
10004
|
}
|
|
9950
10005
|
} catch (error) {
|
|
9951
|
-
|
|
10006
|
+
Logger.error("[Pipeline] Failed to generate suggestions", error);
|
|
9952
10007
|
}
|
|
9953
10008
|
return [];
|
|
9954
10009
|
}
|
|
@@ -10545,18 +10600,25 @@ var DocumentParser = class {
|
|
|
10545
10600
|
}
|
|
10546
10601
|
if (extension === "xlsx" || extension === "xls" || mimeType.includes("spreadsheet") || mimeType.includes("excel")) {
|
|
10547
10602
|
try {
|
|
10548
|
-
const
|
|
10603
|
+
const ExcelJS = await import("exceljs");
|
|
10549
10604
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
10550
|
-
const workbook =
|
|
10605
|
+
const workbook = new ExcelJS.Workbook();
|
|
10606
|
+
await workbook.xlsx.load(buffer);
|
|
10551
10607
|
const sheetsText = [];
|
|
10552
|
-
|
|
10553
|
-
const
|
|
10554
|
-
|
|
10608
|
+
workbook.eachSheet((sheet, sheetId) => {
|
|
10609
|
+
const csvLines = [];
|
|
10610
|
+
sheet.eachRow((row, rowNumber) => {
|
|
10611
|
+
const values = row.values;
|
|
10612
|
+
if (Array.isArray(values)) {
|
|
10613
|
+
csvLines.push(values.slice(1).join(","));
|
|
10614
|
+
}
|
|
10615
|
+
});
|
|
10616
|
+
const csv = csvLines.join("\n");
|
|
10555
10617
|
if (csv && csv.trim()) {
|
|
10556
|
-
sheetsText.push(`--- Sheet: ${
|
|
10618
|
+
sheetsText.push(`--- Sheet: ${sheet.name} ---
|
|
10557
10619
|
${csv.trim()}`);
|
|
10558
10620
|
}
|
|
10559
|
-
}
|
|
10621
|
+
});
|
|
10560
10622
|
return sheetsText.join("\n\n") || `[Empty Excel Workbook: ${fileName}]`;
|
|
10561
10623
|
} catch (e) {
|
|
10562
10624
|
try {
|
|
@@ -10568,9 +10630,10 @@ ${csv.trim()}`);
|
|
|
10568
10630
|
}
|
|
10569
10631
|
if (extension === "pdf" || mimeType === "application/pdf") {
|
|
10570
10632
|
try {
|
|
10571
|
-
const
|
|
10633
|
+
const pdfModule = await import("pdf-parse");
|
|
10572
10634
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
10573
|
-
const
|
|
10635
|
+
const pdf = pdfModule.default || pdfModule;
|
|
10636
|
+
const data = await pdf(buffer);
|
|
10574
10637
|
return data.text;
|
|
10575
10638
|
} catch (err) {
|
|
10576
10639
|
console.warn('[DocumentParser] PDF parsing failed. Make sure "pdf-parse" is installed.', err);
|
|
@@ -11330,7 +11393,7 @@ function sanitizeTelemetryUrl(raw) {
|
|
|
11330
11393
|
return null;
|
|
11331
11394
|
}
|
|
11332
11395
|
}
|
|
11333
|
-
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
11396
|
+
async function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
11334
11397
|
var _a2, _b, _c, _d, _e, _f, _g2;
|
|
11335
11398
|
try {
|
|
11336
11399
|
const config = plugin.getConfig();
|
|
@@ -11365,7 +11428,7 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
11365
11428
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11366
11429
|
details
|
|
11367
11430
|
};
|
|
11368
|
-
fetch(telemetryUrl, {
|
|
11431
|
+
await fetch(telemetryUrl, {
|
|
11369
11432
|
method: "POST",
|
|
11370
11433
|
headers: __spreadProps(__spreadValues({
|
|
11371
11434
|
"Content-Type": "application/json"
|
|
@@ -11486,14 +11549,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11486
11549
|
uiTransformation: result.ui_transformation,
|
|
11487
11550
|
trace: result.trace
|
|
11488
11551
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
11489
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_d = (_c = result.trace) == null ? void 0 : _c.tokens) == null ? void 0 : _d.totalTokens) || 0}, Latency: ${((_f = (_e = result.trace) == null ? void 0 : _e.latency) == null ? void 0 : _f.totalMs) || 0}ms`, result.trace);
|
|
11552
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_d = (_c = result.trace) == null ? void 0 : _c.tokens) == null ? void 0 : _d.totalTokens) || 0}, Latency: ${((_f = (_e = result.trace) == null ? void 0 : _e.latency) == null ? void 0 : _f.totalMs) || 0}ms`, result.trace);
|
|
11490
11553
|
return NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
11491
11554
|
messageId: assistantMsgId,
|
|
11492
11555
|
userMessageId: userMsgId
|
|
11493
11556
|
}));
|
|
11494
11557
|
} catch (err) {
|
|
11495
11558
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11496
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
11559
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
11497
11560
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
11498
11561
|
}
|
|
11499
11562
|
};
|
|
@@ -11631,7 +11694,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11631
11694
|
uiTransformation,
|
|
11632
11695
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
11633
11696
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
11634
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_c = (_b2 = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _b2.tokens) == null ? void 0 : _c.totalTokens) || 0}, Latency: ${((_e = (_d = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _d.latency) == null ? void 0 : _e.totalMs) || 0}ms`, responseChunk == null ? void 0 : responseChunk.trace);
|
|
11697
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "success", `Tokens: ${((_c = (_b2 = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _b2.tokens) == null ? void 0 : _c.totalTokens) || 0}, Latency: ${((_e = (_d = responseChunk == null ? void 0 : responseChunk.trace) == null ? void 0 : _d.latency) == null ? void 0 : _e.totalMs) || 0}ms`, responseChunk == null ? void 0 : responseChunk.trace);
|
|
11635
11698
|
}
|
|
11636
11699
|
}
|
|
11637
11700
|
} catch (temp) {
|
|
@@ -11651,7 +11714,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11651
11714
|
errorMessage = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
|
|
11652
11715
|
}
|
|
11653
11716
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
11654
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
11717
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
11655
11718
|
try {
|
|
11656
11719
|
enqueue(sseErrorFrame(errorMessage));
|
|
11657
11720
|
} catch (e) {
|
|
@@ -11713,11 +11776,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11713
11776
|
}
|
|
11714
11777
|
}
|
|
11715
11778
|
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11716
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11779
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11717
11780
|
return NextResponse.json({ results });
|
|
11718
11781
|
} catch (err) {
|
|
11719
11782
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11720
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11783
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11721
11784
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
11722
11785
|
}
|
|
11723
11786
|
};
|
|
@@ -11878,41 +11941,47 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11878
11941
|
}
|
|
11879
11942
|
}
|
|
11880
11943
|
} else if (isExcel) {
|
|
11881
|
-
const
|
|
11944
|
+
const ExcelJS = await import("exceljs");
|
|
11882
11945
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
11883
|
-
const workbook =
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
const
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
fileName: file.name,
|
|
11904
|
-
sheetName,
|
|
11905
|
-
fileSize: file.size,
|
|
11906
|
-
fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
11907
|
-
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11908
|
-
}, dimension ? { dimension } : {}), {
|
|
11909
|
-
headers
|
|
11910
|
-
}), rowData)
|
|
11911
|
-
});
|
|
11946
|
+
const workbook = new ExcelJS.Workbook();
|
|
11947
|
+
await workbook.xlsx.load(buffer);
|
|
11948
|
+
workbook.eachSheet((sheet, sheetId) => {
|
|
11949
|
+
const sheetName = sheet.name;
|
|
11950
|
+
let headers = [];
|
|
11951
|
+
let i = 0;
|
|
11952
|
+
sheet.eachRow((row, rowNumber) => {
|
|
11953
|
+
const values = Array.isArray(row.values) ? row.values.slice(1) : [];
|
|
11954
|
+
if (rowNumber === 1) {
|
|
11955
|
+
headers = values.map((v) => String(v));
|
|
11956
|
+
return;
|
|
11957
|
+
}
|
|
11958
|
+
i++;
|
|
11959
|
+
const contentParts = [];
|
|
11960
|
+
const rowData = {};
|
|
11961
|
+
values.forEach((val, index) => {
|
|
11962
|
+
const key = headers[index] || `Column${index + 1}`;
|
|
11963
|
+
rowData[key] = val;
|
|
11964
|
+
if (key && val !== void 0 && val !== null && String(val).trim()) {
|
|
11965
|
+
contentParts.push(`${key}: ${val}`);
|
|
11912
11966
|
}
|
|
11967
|
+
});
|
|
11968
|
+
if (contentParts.length > 0) {
|
|
11969
|
+
documents.push({
|
|
11970
|
+
docId: `${file.name}-${sheetName}-row-${i}`,
|
|
11971
|
+
content: contentParts.join(", "),
|
|
11972
|
+
metadata: __spreadValues(__spreadProps(__spreadValues({
|
|
11973
|
+
fileName: file.name,
|
|
11974
|
+
sheetName,
|
|
11975
|
+
fileSize: file.size,
|
|
11976
|
+
fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
11977
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11978
|
+
}, dimension ? { dimension } : {}), {
|
|
11979
|
+
headers
|
|
11980
|
+
}), rowData)
|
|
11981
|
+
});
|
|
11913
11982
|
}
|
|
11914
|
-
}
|
|
11915
|
-
}
|
|
11983
|
+
});
|
|
11984
|
+
});
|
|
11916
11985
|
} else {
|
|
11917
11986
|
const content = await DocumentParser.parse(file, file.name, file.type);
|
|
11918
11987
|
documents.push({
|
|
@@ -11928,11 +11997,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11928
11997
|
}
|
|
11929
11998
|
}
|
|
11930
11999
|
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11931
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
12000
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11932
12001
|
return NextResponse.json({ message: "Upload successful", results });
|
|
11933
12002
|
} catch (err) {
|
|
11934
12003
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
11935
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
12004
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11936
12005
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
11937
12006
|
}
|
|
11938
12007
|
};
|
|
@@ -11972,11 +12041,11 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11972
12041
|
const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
|
|
11973
12042
|
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11974
12043
|
const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
|
|
11975
|
-
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
12044
|
+
await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11976
12045
|
return NextResponse.json({ suggestions });
|
|
11977
12046
|
} catch (err) {
|
|
11978
12047
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11979
|
-
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
12048
|
+
await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
11980
12049
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
11981
12050
|
}
|
|
11982
12051
|
};
|