@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/handlers/index.js
CHANGED
|
@@ -318,7 +318,7 @@ var init_package = __esm({
|
|
|
318
318
|
"package.json"() {
|
|
319
319
|
package_default = {
|
|
320
320
|
name: "@retrivora-ai/rag-engine",
|
|
321
|
-
version: "2.5.
|
|
321
|
+
version: "2.5.4",
|
|
322
322
|
description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
|
|
323
323
|
author: "Abhinav Alkuchi",
|
|
324
324
|
license: "UNLICENSED",
|
|
@@ -400,7 +400,7 @@ var init_package = __esm({
|
|
|
400
400
|
lint: "eslint",
|
|
401
401
|
typecheck: "tsc --noEmit -p tsconfig.build.json",
|
|
402
402
|
test: "jest",
|
|
403
|
-
clean:
|
|
403
|
+
clean: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`
|
|
404
404
|
},
|
|
405
405
|
peerDependencies: {
|
|
406
406
|
axios: ">=1.0.0",
|
|
@@ -420,18 +420,24 @@ var init_package = __esm({
|
|
|
420
420
|
"@anthropic-ai/sdk": "^0.95.1",
|
|
421
421
|
"@google/genai": "^0.8.0",
|
|
422
422
|
"@google/generative-ai": "^0.24.1",
|
|
423
|
-
"@retrivora-ai/billing-guards": "*",
|
|
424
423
|
"@pinecone-database/pinecone": "^7.2.0",
|
|
424
|
+
"@retrivora-ai/billing-guards": "*",
|
|
425
425
|
"@types/papaparse": "^5.5.2",
|
|
426
|
+
"framer-motion": "^13.1.0",
|
|
427
|
+
katex: "^0.18.4",
|
|
426
428
|
"lucide-react": "^1.8.0",
|
|
427
429
|
"next-themes": "^0.4.6",
|
|
428
430
|
openai: "^6.34.0",
|
|
429
431
|
papaparse: "^5.5.3",
|
|
430
432
|
"react-is": "^18.3.1",
|
|
431
433
|
"react-markdown": "^10.1.0",
|
|
434
|
+
"react-syntax-highlighter": "^16.1.1",
|
|
432
435
|
recharts: "^3.8.1",
|
|
436
|
+
"rehype-katex": "^7.0.1",
|
|
433
437
|
"remark-gfm": "^4.0.1",
|
|
434
|
-
|
|
438
|
+
"remark-math": "^6.0.0",
|
|
439
|
+
exceljs: "^4.4.0",
|
|
440
|
+
zod: "^4.4.3"
|
|
435
441
|
},
|
|
436
442
|
optionalDependencies: {
|
|
437
443
|
"@langchain/core": "^1.1.42",
|
|
@@ -448,17 +454,19 @@ var init_package = __esm({
|
|
|
448
454
|
"@tailwindcss/postcss": "^4",
|
|
449
455
|
"@types/estree": "^1.0.9",
|
|
450
456
|
"@types/jest": "^30.0.0",
|
|
457
|
+
"@types/katex": "^0.16.8",
|
|
451
458
|
"@types/node": "^20",
|
|
452
459
|
"@types/pdf-parse": "^1.1.5",
|
|
453
460
|
"@types/pg": "^8.20.0",
|
|
454
461
|
"@types/react": "^19.2.14",
|
|
455
462
|
"@types/react-dom": "^19.2.3",
|
|
463
|
+
"@types/react-syntax-highlighter": "^15.5.13",
|
|
456
464
|
axios: "^1.15.0",
|
|
457
465
|
dotenv: "^17.4.2",
|
|
458
466
|
eslint: "^9",
|
|
459
|
-
"eslint-config-next": "16.2
|
|
467
|
+
"eslint-config-next": "16.3.2",
|
|
460
468
|
jest: "^30.4.2",
|
|
461
|
-
next: "16.2
|
|
469
|
+
next: "^16.3.2",
|
|
462
470
|
tailwindcss: "^4",
|
|
463
471
|
"ts-jest": "^29.4.12",
|
|
464
472
|
tsup: "^8.5.1",
|
|
@@ -2769,6 +2777,36 @@ function wrapError(err, defaultCode, defaultMessage) {
|
|
|
2769
2777
|
// src/core/LicenseVerifier.ts
|
|
2770
2778
|
var _LicenseVerifier = class _LicenseVerifier {
|
|
2771
2779
|
// Cache verified license for 5 minutes
|
|
2780
|
+
/**
|
|
2781
|
+
* Computes a deterministic hardware fingerprint to enforce node-locked licensing.
|
|
2782
|
+
*/
|
|
2783
|
+
static async generateMachineFingerprint() {
|
|
2784
|
+
if (typeof window !== "undefined" && typeof navigator !== "undefined") {
|
|
2785
|
+
return navigator.userAgent || "browser-fallback-fingerprint";
|
|
2786
|
+
}
|
|
2787
|
+
try {
|
|
2788
|
+
const os2 = await import("os");
|
|
2789
|
+
const crypto2 = await import("crypto");
|
|
2790
|
+
const interfaces = os2.networkInterfaces();
|
|
2791
|
+
const macAddresses = [];
|
|
2792
|
+
for (const name of Object.keys(interfaces)) {
|
|
2793
|
+
for (const iface of interfaces[name] || []) {
|
|
2794
|
+
if (!iface.internal && iface.mac && iface.mac !== "00:00:00:00:00:00") {
|
|
2795
|
+
macAddresses.push(iface.mac);
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
const rawData = [
|
|
2800
|
+
macAddresses.sort().join(","),
|
|
2801
|
+
os2.platform(),
|
|
2802
|
+
os2.arch(),
|
|
2803
|
+
os2.hostname()
|
|
2804
|
+
].join("|");
|
|
2805
|
+
return crypto2.createHash("sha256").update(rawData).digest("hex");
|
|
2806
|
+
} catch (err) {
|
|
2807
|
+
return "fallback-fingerprint-failed";
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2772
2810
|
/**
|
|
2773
2811
|
* Validates the license key asynchronously by calling the Retrivora backend.
|
|
2774
2812
|
*
|
|
@@ -2812,6 +2850,7 @@ var _LicenseVerifier = class _LicenseVerifier {
|
|
|
2812
2850
|
}
|
|
2813
2851
|
const endpoint = `${baseUrl}/api/v1/license/validate`;
|
|
2814
2852
|
let response;
|
|
2853
|
+
const machineFingerprint = await this.generateMachineFingerprint();
|
|
2815
2854
|
try {
|
|
2816
2855
|
response = await fetch(endpoint, {
|
|
2817
2856
|
method: "POST",
|
|
@@ -2822,7 +2861,8 @@ var _LicenseVerifier = class _LicenseVerifier {
|
|
|
2822
2861
|
body: JSON.stringify({
|
|
2823
2862
|
licenseKey,
|
|
2824
2863
|
projectId: currentProjectId,
|
|
2825
|
-
provider
|
|
2864
|
+
provider,
|
|
2865
|
+
machineFingerprint
|
|
2826
2866
|
})
|
|
2827
2867
|
});
|
|
2828
2868
|
} catch (fetchErr) {
|
|
@@ -3030,7 +3070,6 @@ var PROVIDERS_WITH_EMBEDDINGS = [
|
|
|
3030
3070
|
"rest",
|
|
3031
3071
|
"universal_rest"
|
|
3032
3072
|
];
|
|
3033
|
-
var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
|
|
3034
3073
|
|
|
3035
3074
|
// src/config/serverConfig.ts
|
|
3036
3075
|
var _runtimeConfig = null;
|
|
@@ -3142,7 +3181,7 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3142
3181
|
return true;
|
|
3143
3182
|
}
|
|
3144
3183
|
})();
|
|
3145
|
-
const tierBasedLLMModel = isFreeTier2 ? "
|
|
3184
|
+
const tierBasedLLMModel = isFreeTier2 ? "free-tier-standard" : "qwen-3.6-27b";
|
|
3146
3185
|
const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
|
|
3147
3186
|
const controlPlaneUrl = (_ma = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _ma : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
|
|
3148
3187
|
const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
|
|
@@ -3150,7 +3189,16 @@ function getEnvConfig(env = process.env, base) {
|
|
|
3150
3189
|
const defaultLlmProvider = "universal_rest";
|
|
3151
3190
|
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;
|
|
3152
3191
|
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;
|
|
3153
|
-
|
|
3192
|
+
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;
|
|
3193
|
+
if ((rt == null ? void 0 : rt.allowedModels) && rt.allowedModels.length > 0) {
|
|
3194
|
+
if (!rt.allowedModels.includes(llmModel)) {
|
|
3195
|
+
console.warn(`[Retrivora SDK] Model "${llmModel}" is not permitted on the current license tier. Falling back to default: ${rt.llmModel || tierBasedLLMModel}`);
|
|
3196
|
+
llmModel = rt.llmModel || tierBasedLLMModel;
|
|
3197
|
+
}
|
|
3198
|
+
} else if (isFreeTier2 && llmModel !== "free-tier-standard") {
|
|
3199
|
+
console.warn(`[Retrivora SDK] Explicit models are not permitted on the Free tier. Falling back to default load-balanced pool.`);
|
|
3200
|
+
llmModel = "free-tier-standard";
|
|
3201
|
+
}
|
|
3154
3202
|
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;
|
|
3155
3203
|
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";
|
|
3156
3204
|
const defaultEmbeddingProvider = "universal_rest";
|
|
@@ -3363,6 +3411,9 @@ var ConfigResolver = class {
|
|
|
3363
3411
|
}
|
|
3364
3412
|
};
|
|
3365
3413
|
|
|
3414
|
+
// src/core/ConfigValidator.ts
|
|
3415
|
+
var import_zod = require("zod");
|
|
3416
|
+
|
|
3366
3417
|
// src/llm/providers/OpenAIProvider.ts
|
|
3367
3418
|
var import_openai = __toESM(require("openai"));
|
|
3368
3419
|
|
|
@@ -3386,7 +3437,11 @@ ${context}`;
|
|
|
3386
3437
|
var OpenAIProvider = class {
|
|
3387
3438
|
constructor(llmConfig, embeddingConfig) {
|
|
3388
3439
|
if (!llmConfig.apiKey) throw new Error("[OpenAIProvider] llmConfig.apiKey is required");
|
|
3389
|
-
this.client = new import_openai.default({
|
|
3440
|
+
this.client = new import_openai.default({
|
|
3441
|
+
apiKey: llmConfig.apiKey,
|
|
3442
|
+
baseURL: llmConfig.baseUrl,
|
|
3443
|
+
maxRetries: 5
|
|
3444
|
+
});
|
|
3390
3445
|
this.llmConfig = llmConfig;
|
|
3391
3446
|
this.embeddingConfig = embeddingConfig;
|
|
3392
3447
|
}
|
|
@@ -4148,7 +4203,8 @@ var GroqProvider = class {
|
|
|
4148
4203
|
if (!apiKey) throw new Error("[GroqProvider] llmConfig.apiKey or GROQ_API_KEY environment variable is required");
|
|
4149
4204
|
this.client = new import_openai2.default({
|
|
4150
4205
|
apiKey,
|
|
4151
|
-
baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1"
|
|
4206
|
+
baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1",
|
|
4207
|
+
maxRetries: 5
|
|
4152
4208
|
});
|
|
4153
4209
|
this.llmConfig = llmConfig;
|
|
4154
4210
|
}
|
|
@@ -4168,7 +4224,7 @@ var GroqProvider = class {
|
|
|
4168
4224
|
errors.push({
|
|
4169
4225
|
field: "llm.model",
|
|
4170
4226
|
message: "Groq model name is required",
|
|
4171
|
-
suggestion: 'e.g., "
|
|
4227
|
+
suggestion: 'e.g., "qwen-3.6-27b"',
|
|
4172
4228
|
severity: "error"
|
|
4173
4229
|
});
|
|
4174
4230
|
}
|
|
@@ -5081,24 +5137,69 @@ ProviderRegistry.llmValidators = {};
|
|
|
5081
5137
|
ProviderRegistry.llmHealthCheckers = {};
|
|
5082
5138
|
|
|
5083
5139
|
// src/core/ConfigValidator.ts
|
|
5140
|
+
var UIConfigSchema = import_zod.z.object({
|
|
5141
|
+
primaryColor: import_zod.z.string().optional(),
|
|
5142
|
+
borderRadius: import_zod.z.enum(["none", "sm", "md", "lg", "xl", "full"]).optional()
|
|
5143
|
+
}).passthrough().optional();
|
|
5144
|
+
var VectorDbSchema = import_zod.z.object({
|
|
5145
|
+
provider: import_zod.z.string().min(1, "Vector database provider is required"),
|
|
5146
|
+
indexName: import_zod.z.string().min(1, "Vector database index name is required"),
|
|
5147
|
+
options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
5148
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5149
|
+
const opts = val.options || {};
|
|
5150
|
+
if (val.provider === "milvus") {
|
|
5151
|
+
if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
|
|
5152
|
+
ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Milvus connection info required" });
|
|
5153
|
+
}
|
|
5154
|
+
} else if (val.provider === "qdrant") {
|
|
5155
|
+
if (!opts.baseUrl && !opts.url) {
|
|
5156
|
+
ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Qdrant URL required" });
|
|
5157
|
+
}
|
|
5158
|
+
}
|
|
5159
|
+
});
|
|
5160
|
+
var LLMSchema = import_zod.z.object({
|
|
5161
|
+
provider: import_zod.z.string().min(1, "LLM provider is required"),
|
|
5162
|
+
model: import_zod.z.string().optional(),
|
|
5163
|
+
temperature: import_zod.z.number().min(0, "Temperature must be at least 0").max(2, "Temperature must be at most 2").optional()
|
|
5164
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5165
|
+
if (!val.model) {
|
|
5166
|
+
ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["model"], message: "LLM model name is required" });
|
|
5167
|
+
}
|
|
5168
|
+
});
|
|
5169
|
+
var EmbeddingSchema = import_zod.z.object({
|
|
5170
|
+
provider: import_zod.z.string().min(1, "Embedding provider is required"),
|
|
5171
|
+
model: import_zod.z.string().optional()
|
|
5172
|
+
}).passthrough().superRefine((val, ctx) => {
|
|
5173
|
+
if (!val.model) {
|
|
5174
|
+
ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["model"], message: "Embedding model name is required" });
|
|
5175
|
+
}
|
|
5176
|
+
});
|
|
5177
|
+
var RAGSchema = import_zod.z.object({
|
|
5178
|
+
topK: import_zod.z.number().positive("topK must be a positive integer").optional()
|
|
5179
|
+
}).passthrough().optional();
|
|
5180
|
+
var RagConfigSchema = import_zod.z.object({
|
|
5181
|
+
projectId: import_zod.z.string().min(1, "projectId is required"),
|
|
5182
|
+
vectorDb: VectorDbSchema,
|
|
5183
|
+
llm: LLMSchema,
|
|
5184
|
+
embedding: EmbeddingSchema.optional(),
|
|
5185
|
+
ui: UIConfigSchema,
|
|
5186
|
+
rag: RAGSchema
|
|
5187
|
+
}).passthrough();
|
|
5084
5188
|
var ConfigValidator = class {
|
|
5085
|
-
/**
|
|
5086
|
-
* Validates the entire RagConfig object.
|
|
5087
|
-
*/
|
|
5088
5189
|
static async validate(config) {
|
|
5190
|
+
var _a2, _b, _c, _d, _e;
|
|
5089
5191
|
const errors = [];
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5192
|
+
const result = RagConfigSchema.safeParse(config);
|
|
5193
|
+
if (!result.success) {
|
|
5194
|
+
for (const issue of result.error.issues) {
|
|
5195
|
+
errors.push({
|
|
5196
|
+
field: issue.path.join("."),
|
|
5197
|
+
message: issue.message,
|
|
5198
|
+
severity: "error"
|
|
5199
|
+
});
|
|
5200
|
+
}
|
|
5096
5201
|
}
|
|
5097
|
-
|
|
5098
|
-
errors.push(...await this.validateLLMConfig(config.llm));
|
|
5099
|
-
if (config.embedding) {
|
|
5100
|
-
errors.push(...await this.validateEmbeddingConfig(config.embedding));
|
|
5101
|
-
} else if (config.llm.provider === "anthropic") {
|
|
5202
|
+
if (((_a2 = config.llm) == null ? void 0 : _a2.provider) === "anthropic" && !config.embedding) {
|
|
5102
5203
|
errors.push({
|
|
5103
5204
|
field: "embedding",
|
|
5104
5205
|
message: "Embedding config is required when using Anthropic LLM",
|
|
@@ -5106,113 +5207,35 @@ var ConfigValidator = class {
|
|
|
5106
5207
|
severity: "error"
|
|
5107
5208
|
});
|
|
5108
5209
|
}
|
|
5109
|
-
if (config.ui) {
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
static async validateVectorDbConfig(config) {
|
|
5118
|
-
const errors = [];
|
|
5119
|
-
if (!config.provider) {
|
|
5120
|
-
errors.push({ field: "vectorDb.provider", message: "Vector database provider is required", severity: "error" });
|
|
5121
|
-
return errors;
|
|
5122
|
-
}
|
|
5123
|
-
if (!config.indexName) {
|
|
5124
|
-
errors.push({ field: "vectorDb.indexName", message: "Vector database index name is required", severity: "error" });
|
|
5125
|
-
}
|
|
5126
|
-
const validator = await ProviderRegistry.getVectorValidator(config.provider);
|
|
5127
|
-
if (validator) {
|
|
5128
|
-
errors.push(...validator.validate(config));
|
|
5129
|
-
} else {
|
|
5130
|
-
this.fallbackVectorValidation(config, errors);
|
|
5131
|
-
}
|
|
5132
|
-
return errors;
|
|
5133
|
-
}
|
|
5134
|
-
static async validateLLMConfig(config) {
|
|
5135
|
-
const errors = [];
|
|
5136
|
-
if (!config.provider) {
|
|
5137
|
-
errors.push({ field: "llm.provider", message: "LLM provider is required", severity: "error" });
|
|
5138
|
-
return errors;
|
|
5139
|
-
}
|
|
5140
|
-
const validator = LLMFactory.getValidator(config.provider);
|
|
5141
|
-
if (validator) {
|
|
5142
|
-
errors.push(...validator.validate(config));
|
|
5143
|
-
} else {
|
|
5144
|
-
this.fallbackLLMValidation(config, errors);
|
|
5145
|
-
}
|
|
5146
|
-
if (config.temperature !== void 0 && (config.temperature < 0 || config.temperature > 2)) {
|
|
5147
|
-
errors.push({ field: "llm.temperature", message: "Temperature must be between 0 and 2", severity: "error" });
|
|
5148
|
-
}
|
|
5149
|
-
return errors;
|
|
5150
|
-
}
|
|
5151
|
-
static async validateEmbeddingConfig(config) {
|
|
5152
|
-
const errors = [];
|
|
5153
|
-
if (!config.provider) {
|
|
5154
|
-
errors.push({ field: "embedding.provider", message: "Embedding provider is required", severity: "error" });
|
|
5155
|
-
return errors;
|
|
5156
|
-
}
|
|
5157
|
-
const validator = LLMFactory.getValidator(config.provider);
|
|
5158
|
-
if (validator) {
|
|
5159
|
-
errors.push(...validator.validate(config));
|
|
5160
|
-
} else {
|
|
5161
|
-
this.fallbackEmbeddingValidation(config, errors);
|
|
5162
|
-
}
|
|
5163
|
-
return errors;
|
|
5164
|
-
}
|
|
5165
|
-
/**
|
|
5166
|
-
* Temporary fallbacks for providers not yet migrated to the pluggable architecture.
|
|
5167
|
-
*/
|
|
5168
|
-
static fallbackVectorValidation(config, errors) {
|
|
5169
|
-
const opts = config.options || {};
|
|
5170
|
-
switch (config.provider) {
|
|
5171
|
-
case "milvus":
|
|
5172
|
-
if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
|
|
5173
|
-
errors.push({ field: "vectorDb.options.baseUrl", message: "Milvus connection info required", severity: "error" });
|
|
5174
|
-
}
|
|
5175
|
-
break;
|
|
5176
|
-
case "qdrant":
|
|
5177
|
-
if (!opts.baseUrl && !opts.url) {
|
|
5178
|
-
errors.push({ field: "vectorDb.options.baseUrl", message: "Qdrant URL required", severity: "error" });
|
|
5179
|
-
}
|
|
5180
|
-
break;
|
|
5181
|
-
}
|
|
5182
|
-
}
|
|
5183
|
-
static fallbackLLMValidation(config, errors) {
|
|
5184
|
-
if (!config.model) {
|
|
5185
|
-
errors.push({ field: "llm.model", message: "LLM model name is required", severity: "error" });
|
|
5186
|
-
}
|
|
5187
|
-
}
|
|
5188
|
-
static fallbackEmbeddingValidation(config, errors) {
|
|
5189
|
-
if (!config.model) {
|
|
5190
|
-
errors.push({ field: "embedding.model", message: "Embedding model name is required", severity: "error" });
|
|
5210
|
+
if ((_b = config.ui) == null ? void 0 : _b.primaryColor) {
|
|
5211
|
+
const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
|
|
5212
|
+
const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
|
|
5213
|
+
const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
|
|
5214
|
+
const color = config.ui.primaryColor;
|
|
5215
|
+
if (!hexRegex.test(color) && !rgbRegex.test(color) && !namedColors.includes(color.toLowerCase())) {
|
|
5216
|
+
errors.push({ field: "ui.primaryColor", message: "Invalid CSS color format", severity: "warning" });
|
|
5217
|
+
}
|
|
5191
5218
|
}
|
|
5192
|
-
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5219
|
+
if ((_c = config.vectorDb) == null ? void 0 : _c.provider) {
|
|
5220
|
+
const vectorValidator = await ProviderRegistry.getVectorValidator(config.vectorDb.provider);
|
|
5221
|
+
if (vectorValidator) {
|
|
5222
|
+
errors.push(...vectorValidator.validate(config.vectorDb));
|
|
5223
|
+
}
|
|
5197
5224
|
}
|
|
5198
|
-
if (config.
|
|
5199
|
-
|
|
5225
|
+
if ((_d = config.llm) == null ? void 0 : _d.provider) {
|
|
5226
|
+
const llmValidator = LLMFactory.getValidator(config.llm.provider);
|
|
5227
|
+
if (llmValidator) {
|
|
5228
|
+
errors.push(...llmValidator.validate(config.llm));
|
|
5229
|
+
}
|
|
5200
5230
|
}
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
errors.push({ field: "rag.topK", message: "topK must be a positive integer", severity: "error" });
|
|
5231
|
+
if ((_e = config.embedding) == null ? void 0 : _e.provider) {
|
|
5232
|
+
const embeddingValidator = LLMFactory.getValidator(config.embedding.provider);
|
|
5233
|
+
if (embeddingValidator) {
|
|
5234
|
+
errors.push(...embeddingValidator.validate(config.embedding));
|
|
5235
|
+
}
|
|
5207
5236
|
}
|
|
5208
5237
|
return errors;
|
|
5209
5238
|
}
|
|
5210
|
-
static isValidCSSColor(color) {
|
|
5211
|
-
const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
|
|
5212
|
-
const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
|
|
5213
|
-
const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
|
|
5214
|
-
return hexRegex.test(color) || rgbRegex.test(color) || namedColors.includes(color.toLowerCase());
|
|
5215
|
-
}
|
|
5216
5239
|
static async validateAndThrow(config) {
|
|
5217
5240
|
const errors = await this.validate(config);
|
|
5218
5241
|
const errorItems = errors.filter((e) => e.severity === "error");
|
|
@@ -5858,6 +5881,38 @@ var MCPRegistry = class {
|
|
|
5858
5881
|
}
|
|
5859
5882
|
};
|
|
5860
5883
|
|
|
5884
|
+
// src/utils/logger.ts
|
|
5885
|
+
var Logger = class {
|
|
5886
|
+
static format(level, message, meta) {
|
|
5887
|
+
if (this.isProduction) {
|
|
5888
|
+
return JSON.stringify(__spreadValues({
|
|
5889
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
5890
|
+
level,
|
|
5891
|
+
message
|
|
5892
|
+
}, meta));
|
|
5893
|
+
}
|
|
5894
|
+
const metaString = meta ? `
|
|
5895
|
+
${JSON.stringify(meta, null, 2)}` : "";
|
|
5896
|
+
return `[${(/* @__PURE__ */ new Date()).toISOString()}] [${level}] ${message}${metaString}`;
|
|
5897
|
+
}
|
|
5898
|
+
static info(message, meta) {
|
|
5899
|
+
console.log(this.format("INFO", message, meta));
|
|
5900
|
+
}
|
|
5901
|
+
static warn(message, meta) {
|
|
5902
|
+
console.warn(this.format("WARN", message, meta));
|
|
5903
|
+
}
|
|
5904
|
+
static error(message, error, meta) {
|
|
5905
|
+
const errorMeta = error instanceof Error ? { errorMessage: error.message, stack: error.stack } : { error: String(error) };
|
|
5906
|
+
console.error(this.format("ERROR", message, __spreadValues(__spreadValues({}, meta), errorMeta)));
|
|
5907
|
+
}
|
|
5908
|
+
static debug(message, meta) {
|
|
5909
|
+
if (process.env.DEBUG === "true") {
|
|
5910
|
+
console.debug(this.format("DEBUG", message, meta));
|
|
5911
|
+
}
|
|
5912
|
+
}
|
|
5913
|
+
};
|
|
5914
|
+
Logger.isProduction = process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production";
|
|
5915
|
+
|
|
5861
5916
|
// src/core/MultiAgentCoordinator.ts
|
|
5862
5917
|
function parseToolCall(text) {
|
|
5863
5918
|
const match = text.match(/TOOL_CALL:\s*([\w-]+)\s*\(\s*([\s\S]*?)\s*\)\s*[.,;]?\s*$/m);
|
|
@@ -5875,7 +5930,7 @@ function parseToolCall(text) {
|
|
|
5875
5930
|
} catch (e) {
|
|
5876
5931
|
const pairs = [...argsRaw.matchAll(/"?([\w-]+)"?\s*:\s*"([^"]*)"/g)];
|
|
5877
5932
|
if (pairs.length === 0) {
|
|
5878
|
-
|
|
5933
|
+
Logger.warn("[parseToolCall] Could not parse tool args", { argsRaw });
|
|
5879
5934
|
return null;
|
|
5880
5935
|
}
|
|
5881
5936
|
for (const [, k, v] of pairs) args[k] = v;
|
|
@@ -6278,7 +6333,7 @@ ${errorMessages}`
|
|
|
6278
6333
|
static async mapWithRetry(items, mapper, options) {
|
|
6279
6334
|
const result = await this.processSequential(items, mapper, options);
|
|
6280
6335
|
if (result.errors.length > 0) {
|
|
6281
|
-
|
|
6336
|
+
Logger.warn(
|
|
6282
6337
|
`[BatchProcessor] mapWithRetry: ${result.errors.length} items failed`
|
|
6283
6338
|
);
|
|
6284
6339
|
}
|
|
@@ -9016,7 +9071,7 @@ var Pipeline = class {
|
|
|
9016
9071
|
}
|
|
9017
9072
|
await this.vectorDB.initialize();
|
|
9018
9073
|
if (this.isMultiAgentMode) {
|
|
9019
|
-
|
|
9074
|
+
Logger.info("[Pipeline] Initializing MultiAgentCoordinator (multi-agent / MCP mode).");
|
|
9020
9075
|
this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
|
|
9021
9076
|
this.multiAgentCoordinator = new MultiAgentCoordinator({
|
|
9022
9077
|
llmProvider: this.llmProvider,
|
|
@@ -9026,7 +9081,7 @@ var Pipeline = class {
|
|
|
9026
9081
|
maxIterations: (_a2 = this.config.rag) == null ? void 0 : _a2.agentMaxIterations
|
|
9027
9082
|
});
|
|
9028
9083
|
} else if (this.isLangChainAgentMode) {
|
|
9029
|
-
|
|
9084
|
+
Logger.info("[Pipeline] Initializing LangChainAgent (agentic / ReAct mode).");
|
|
9030
9085
|
this.agent = new LangChainAgent(this, this.config);
|
|
9031
9086
|
await this.agent.initialize(this.llmProvider);
|
|
9032
9087
|
}
|
|
@@ -9049,13 +9104,13 @@ var Pipeline = class {
|
|
|
9049
9104
|
const formatted = coldMatches.map((m, i) => `[Cold Source ${i + 1}]
|
|
9050
9105
|
${m.content}`).join("\n\n---\n\n");
|
|
9051
9106
|
this.coldContexts.set(ns, formatted);
|
|
9052
|
-
|
|
9107
|
+
Logger.info(`[Pipeline] Cold RAG (CAG) loaded ${coldMatches.length} documents into cached context for namespace: ${ns}`);
|
|
9053
9108
|
} else {
|
|
9054
9109
|
this.coldContexts.set(ns, "No cold context found.");
|
|
9055
|
-
|
|
9110
|
+
Logger.warn(`[Pipeline] Cold RAG (CAG) initialized but no documents were found in namespace: ${coldNs}`);
|
|
9056
9111
|
}
|
|
9057
9112
|
} catch (err) {
|
|
9058
|
-
|
|
9113
|
+
Logger.error(`[Pipeline] Failed to load Cold RAG (CAG) context for namespace ${ns}`, err);
|
|
9059
9114
|
this.coldContexts.set(ns, "Failed to load cold context.");
|
|
9060
9115
|
}
|
|
9061
9116
|
}
|
|
@@ -9082,7 +9137,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9082
9137
|
await this.processGraphIngestion(doc.docId, chunks);
|
|
9083
9138
|
}
|
|
9084
9139
|
} catch (error) {
|
|
9085
|
-
|
|
9140
|
+
Logger.error(`[Pipeline] Failed to ingest document ${doc.docId}`, error);
|
|
9086
9141
|
results.push({ docId: doc.docId, chunksIngested: 0 });
|
|
9087
9142
|
}
|
|
9088
9143
|
}
|
|
@@ -9136,10 +9191,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9136
9191
|
upsertBatchOptions
|
|
9137
9192
|
);
|
|
9138
9193
|
if (upsertResult.errors.length > 0) {
|
|
9139
|
-
|
|
9140
|
-
upsertResult.errors.forEach((err, idx) => {
|
|
9141
|
-
console.warn(` Batch ${idx + 1} Error: ${err.error.message || String(err.error)}`);
|
|
9142
|
-
});
|
|
9194
|
+
Logger.warn(`[Pipeline] Ingestion: ${upsertResult.errors.length} batches failed.`, { errors: upsertResult.errors.map((e) => e.error.message || String(e.error)) });
|
|
9143
9195
|
}
|
|
9144
9196
|
return upsertResult.totalProcessed;
|
|
9145
9197
|
}
|
|
@@ -9159,7 +9211,7 @@ ${m.content}`).join("\n\n---\n\n");
|
|
|
9159
9211
|
if (nodes.length > 0) await this.graphDB.addNodes(nodes);
|
|
9160
9212
|
if (edges.length > 0) await this.graphDB.addEdges(edges);
|
|
9161
9213
|
} catch (err) {
|
|
9162
|
-
|
|
9214
|
+
Logger.warn(`[Pipeline] Entity extraction failed for chunk in doc ${docId}`, { error: String(err) });
|
|
9163
9215
|
}
|
|
9164
9216
|
}
|
|
9165
9217
|
},
|
|
@@ -9420,7 +9472,7 @@ ${context}`;
|
|
|
9420
9472
|
cachedSchema,
|
|
9421
9473
|
hasNumericPredicates
|
|
9422
9474
|
).catch((uiError) => {
|
|
9423
|
-
|
|
9475
|
+
Logger.warn("[Pipeline] UI transformation failed concurrently", { error: String(uiError) });
|
|
9424
9476
|
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
9425
9477
|
});
|
|
9426
9478
|
let hallucinationScoringPromise = Promise.resolve(void 0);
|
|
@@ -9622,7 +9674,9 @@ ${context}`;
|
|
|
9622
9674
|
const tokenCount = Number(((_c2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _c2.totalTokens) || 0);
|
|
9623
9675
|
const costEst = Number(((_d2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _d2.estimatedCostUsd) || 0);
|
|
9624
9676
|
const latencyDuration = Number(((_e2 = finalTrace == null ? void 0 : finalTrace.latency) == null ? void 0 : _e2.totalMs) || 0);
|
|
9625
|
-
|
|
9677
|
+
if (typeof window === "undefined") {
|
|
9678
|
+
Logger.info(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
|
|
9679
|
+
}
|
|
9626
9680
|
await fetch(absoluteUrl, {
|
|
9627
9681
|
method: "POST",
|
|
9628
9682
|
headers: {
|
|
@@ -9646,9 +9700,11 @@ ${context}`;
|
|
|
9646
9700
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
9647
9701
|
details: `Org: default-org | Model: ${providerName}/${modelName} | Tokens: ${tokenCount} | Latency: ${latencyDuration}ms | Cost: $${costEst} | SDK: v${SDK_VERSION} | Feature: RAG`
|
|
9648
9702
|
})
|
|
9703
|
+
}).catch((err) => {
|
|
9704
|
+
Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}`, { error: err.message });
|
|
9649
9705
|
});
|
|
9650
9706
|
} catch (err) {
|
|
9651
|
-
|
|
9707
|
+
Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}:`, { error: err.message });
|
|
9652
9708
|
}
|
|
9653
9709
|
})();
|
|
9654
9710
|
}
|
|
@@ -9691,7 +9747,7 @@ ${context}`;
|
|
|
9691
9747
|
try {
|
|
9692
9748
|
return await UITransformer.analyzeAndDecide(question, sources, this.llmRouter.get("fast"));
|
|
9693
9749
|
} catch (err) {
|
|
9694
|
-
|
|
9750
|
+
Logger.warn("[Pipeline] generateUiTransformation failed, using heuristic fallback", { error: String(err) });
|
|
9695
9751
|
return UITransformer.transform(question, sources, this.config, cachedSchema);
|
|
9696
9752
|
}
|
|
9697
9753
|
}
|
|
@@ -9789,7 +9845,7 @@ ${context}`;
|
|
|
9789
9845
|
query,
|
|
9790
9846
|
useGraph ? this.llmRouter.get("fast") : void 0
|
|
9791
9847
|
);
|
|
9792
|
-
|
|
9848
|
+
Logger.debug(`[Pipeline] Determined retrieval strategy: ${strategy}`);
|
|
9793
9849
|
const [retrievedVector, graphData] = await Promise.all([
|
|
9794
9850
|
// Only embed if we need vector search (strategy is 'vector' or 'both')
|
|
9795
9851
|
strategy === "vector" || strategy === "both" ? queryVector ? Promise.resolve(queryVector) : this.embeddingProvider.embed(query, { taskType: "query" }) : Promise.resolve([]),
|
|
@@ -9811,8 +9867,7 @@ ${context}`;
|
|
|
9811
9867
|
baseFilter
|
|
9812
9868
|
) : [];
|
|
9813
9869
|
const resolvedSources = sources;
|
|
9814
|
-
|
|
9815
|
-
query,
|
|
9870
|
+
Logger.info("[Pipeline] retrieve() response", {
|
|
9816
9871
|
namespace: ns,
|
|
9817
9872
|
count: resolvedSources.length,
|
|
9818
9873
|
sample: resolvedSources.slice(0, 2).map((s) => {
|
|
@@ -9892,7 +9947,7 @@ Suggestions:`;
|
|
|
9892
9947
|
}
|
|
9893
9948
|
}
|
|
9894
9949
|
} catch (error) {
|
|
9895
|
-
|
|
9950
|
+
Logger.error("[Pipeline] Failed to generate suggestions", error);
|
|
9896
9951
|
}
|
|
9897
9952
|
return [];
|
|
9898
9953
|
}
|
|
@@ -10200,18 +10255,25 @@ var DocumentParser = class {
|
|
|
10200
10255
|
}
|
|
10201
10256
|
if (extension === "xlsx" || extension === "xls" || mimeType.includes("spreadsheet") || mimeType.includes("excel")) {
|
|
10202
10257
|
try {
|
|
10203
|
-
const
|
|
10258
|
+
const ExcelJS = await import("exceljs");
|
|
10204
10259
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
10205
|
-
const workbook =
|
|
10260
|
+
const workbook = new ExcelJS.Workbook();
|
|
10261
|
+
await workbook.xlsx.load(buffer);
|
|
10206
10262
|
const sheetsText = [];
|
|
10207
|
-
|
|
10208
|
-
const
|
|
10209
|
-
|
|
10263
|
+
workbook.eachSheet((sheet, sheetId) => {
|
|
10264
|
+
const csvLines = [];
|
|
10265
|
+
sheet.eachRow((row, rowNumber) => {
|
|
10266
|
+
const values = row.values;
|
|
10267
|
+
if (Array.isArray(values)) {
|
|
10268
|
+
csvLines.push(values.slice(1).join(","));
|
|
10269
|
+
}
|
|
10270
|
+
});
|
|
10271
|
+
const csv = csvLines.join("\n");
|
|
10210
10272
|
if (csv && csv.trim()) {
|
|
10211
|
-
sheetsText.push(`--- Sheet: ${
|
|
10273
|
+
sheetsText.push(`--- Sheet: ${sheet.name} ---
|
|
10212
10274
|
${csv.trim()}`);
|
|
10213
10275
|
}
|
|
10214
|
-
}
|
|
10276
|
+
});
|
|
10215
10277
|
return sheetsText.join("\n\n") || `[Empty Excel Workbook: ${fileName}]`;
|
|
10216
10278
|
} catch (e) {
|
|
10217
10279
|
try {
|
|
@@ -10223,9 +10285,10 @@ ${csv.trim()}`);
|
|
|
10223
10285
|
}
|
|
10224
10286
|
if (extension === "pdf" || mimeType === "application/pdf") {
|
|
10225
10287
|
try {
|
|
10226
|
-
const
|
|
10288
|
+
const pdfModule = await import("pdf-parse");
|
|
10227
10289
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
10228
|
-
const
|
|
10290
|
+
const pdf = pdfModule.default || pdfModule;
|
|
10291
|
+
const data = await pdf(buffer);
|
|
10229
10292
|
return data.text;
|
|
10230
10293
|
} catch (err) {
|
|
10231
10294
|
console.warn('[DocumentParser] PDF parsing failed. Make sure "pdf-parse" is installed.', err);
|
|
@@ -10969,7 +11032,7 @@ function sanitizeTelemetryUrl(raw) {
|
|
|
10969
11032
|
return null;
|
|
10970
11033
|
}
|
|
10971
11034
|
}
|
|
10972
|
-
function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
11035
|
+
async function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
10973
11036
|
var _a2, _b, _c, _d, _e, _f, _g2;
|
|
10974
11037
|
try {
|
|
10975
11038
|
const config = plugin.getConfig();
|
|
@@ -11004,7 +11067,7 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
|
|
|
11004
11067
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
11005
11068
|
details
|
|
11006
11069
|
};
|
|
11007
|
-
fetch(telemetryUrl, {
|
|
11070
|
+
await fetch(telemetryUrl, {
|
|
11008
11071
|
method: "POST",
|
|
11009
11072
|
headers: __spreadProps(__spreadValues({
|
|
11010
11073
|
"Content-Type": "application/json"
|
|
@@ -11125,14 +11188,14 @@ function createChatHandler(configOrPlugin, options) {
|
|
|
11125
11188
|
uiTransformation: result.ui_transformation,
|
|
11126
11189
|
trace: result.trace
|
|
11127
11190
|
}).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
|
|
11128
|
-
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);
|
|
11191
|
+
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);
|
|
11129
11192
|
return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
|
|
11130
11193
|
messageId: assistantMsgId,
|
|
11131
11194
|
userMessageId: userMsgId
|
|
11132
11195
|
}));
|
|
11133
11196
|
} catch (err) {
|
|
11134
11197
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11135
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
11198
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
|
|
11136
11199
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
11137
11200
|
}
|
|
11138
11201
|
};
|
|
@@ -11270,7 +11333,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11270
11333
|
uiTransformation,
|
|
11271
11334
|
trace: responseChunk == null ? void 0 : responseChunk.trace
|
|
11272
11335
|
}).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
|
|
11273
|
-
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);
|
|
11336
|
+
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);
|
|
11274
11337
|
}
|
|
11275
11338
|
}
|
|
11276
11339
|
} catch (temp) {
|
|
@@ -11290,7 +11353,7 @@ function createStreamHandler(configOrPlugin, options) {
|
|
|
11290
11353
|
errorMessage = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
|
|
11291
11354
|
}
|
|
11292
11355
|
console.error("[createStreamHandler] Stream error:", streamError);
|
|
11293
|
-
reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
11356
|
+
await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
|
|
11294
11357
|
try {
|
|
11295
11358
|
enqueue(sseErrorFrame(errorMessage));
|
|
11296
11359
|
} catch (e) {
|
|
@@ -11352,11 +11415,11 @@ function createIngestHandler(configOrPlugin, options) {
|
|
|
11352
11415
|
}
|
|
11353
11416
|
}
|
|
11354
11417
|
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11355
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11418
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
|
|
11356
11419
|
return import_server.NextResponse.json({ results });
|
|
11357
11420
|
} catch (err) {
|
|
11358
11421
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11359
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11422
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11360
11423
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
11361
11424
|
}
|
|
11362
11425
|
};
|
|
@@ -11517,41 +11580,47 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11517
11580
|
}
|
|
11518
11581
|
}
|
|
11519
11582
|
} else if (isExcel) {
|
|
11520
|
-
const
|
|
11583
|
+
const ExcelJS = await import("exceljs");
|
|
11521
11584
|
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
|
|
11522
|
-
const workbook =
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
const
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
fileName: file.name,
|
|
11543
|
-
sheetName,
|
|
11544
|
-
fileSize: file.size,
|
|
11545
|
-
fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
11546
|
-
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11547
|
-
}, dimension ? { dimension } : {}), {
|
|
11548
|
-
headers
|
|
11549
|
-
}), rowData)
|
|
11550
|
-
});
|
|
11585
|
+
const workbook = new ExcelJS.Workbook();
|
|
11586
|
+
await workbook.xlsx.load(buffer);
|
|
11587
|
+
workbook.eachSheet((sheet, sheetId) => {
|
|
11588
|
+
const sheetName = sheet.name;
|
|
11589
|
+
let headers = [];
|
|
11590
|
+
let i = 0;
|
|
11591
|
+
sheet.eachRow((row, rowNumber) => {
|
|
11592
|
+
const values = Array.isArray(row.values) ? row.values.slice(1) : [];
|
|
11593
|
+
if (rowNumber === 1) {
|
|
11594
|
+
headers = values.map((v) => String(v));
|
|
11595
|
+
return;
|
|
11596
|
+
}
|
|
11597
|
+
i++;
|
|
11598
|
+
const contentParts = [];
|
|
11599
|
+
const rowData = {};
|
|
11600
|
+
values.forEach((val, index) => {
|
|
11601
|
+
const key = headers[index] || `Column${index + 1}`;
|
|
11602
|
+
rowData[key] = val;
|
|
11603
|
+
if (key && val !== void 0 && val !== null && String(val).trim()) {
|
|
11604
|
+
contentParts.push(`${key}: ${val}`);
|
|
11551
11605
|
}
|
|
11606
|
+
});
|
|
11607
|
+
if (contentParts.length > 0) {
|
|
11608
|
+
documents.push({
|
|
11609
|
+
docId: `${file.name}-${sheetName}-row-${i}`,
|
|
11610
|
+
content: contentParts.join(", "),
|
|
11611
|
+
metadata: __spreadValues(__spreadProps(__spreadValues({
|
|
11612
|
+
fileName: file.name,
|
|
11613
|
+
sheetName,
|
|
11614
|
+
fileSize: file.size,
|
|
11615
|
+
fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
11616
|
+
uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11617
|
+
}, dimension ? { dimension } : {}), {
|
|
11618
|
+
headers
|
|
11619
|
+
}), rowData)
|
|
11620
|
+
});
|
|
11552
11621
|
}
|
|
11553
|
-
}
|
|
11554
|
-
}
|
|
11622
|
+
});
|
|
11623
|
+
});
|
|
11555
11624
|
} else {
|
|
11556
11625
|
const content = await DocumentParser.parse(file, file.name, file.type);
|
|
11557
11626
|
documents.push({
|
|
@@ -11567,11 +11636,11 @@ function createUploadHandler(configOrPlugin, options) {
|
|
|
11567
11636
|
}
|
|
11568
11637
|
}
|
|
11569
11638
|
const results = await plugin.ingest(documents, namespaceCheck.namespace);
|
|
11570
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11639
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
|
|
11571
11640
|
return import_server.NextResponse.json({ message: "Upload successful", results });
|
|
11572
11641
|
} catch (err) {
|
|
11573
11642
|
const message = err instanceof Error ? err.message : "Upload failed";
|
|
11574
|
-
reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11643
|
+
await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
|
|
11575
11644
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
11576
11645
|
}
|
|
11577
11646
|
};
|
|
@@ -11611,11 +11680,11 @@ function createSuggestionsHandler(configOrPlugin, options) {
|
|
|
11611
11680
|
const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
|
|
11612
11681
|
if (!namespaceCheck.ok) return namespaceCheck.response;
|
|
11613
11682
|
const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
|
|
11614
|
-
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11683
|
+
await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
|
|
11615
11684
|
return import_server.NextResponse.json({ suggestions });
|
|
11616
11685
|
} catch (err) {
|
|
11617
11686
|
const message = err instanceof Error ? err.message : "Internal server error";
|
|
11618
|
-
reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
11687
|
+
await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
|
|
11619
11688
|
return import_server.NextResponse.json({ error: message }, { status: 500 });
|
|
11620
11689
|
}
|
|
11621
11690
|
};
|