@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/dist/server.js CHANGED
@@ -332,7 +332,7 @@ var init_package = __esm({
332
332
  "package.json"() {
333
333
  package_default = {
334
334
  name: "@retrivora-ai/rag-engine",
335
- version: "2.5.2",
335
+ version: "2.5.4",
336
336
  description: "Retrivora AI is a plug-and-play AI engine for RAG chat experiences \u2014 generic vector DB + LLM provider, embeddable or standalone.",
337
337
  author: "Abhinav Alkuchi",
338
338
  license: "UNLICENSED",
@@ -414,7 +414,7 @@ var init_package = __esm({
414
414
  lint: "eslint",
415
415
  typecheck: "tsc --noEmit -p tsconfig.build.json",
416
416
  test: "jest",
417
- clean: "rm -rf dist"
417
+ clean: `node -e "require('fs').rmSync('dist', { recursive: true, force: true })"`
418
418
  },
419
419
  peerDependencies: {
420
420
  axios: ">=1.0.0",
@@ -434,18 +434,24 @@ var init_package = __esm({
434
434
  "@anthropic-ai/sdk": "^0.95.1",
435
435
  "@google/genai": "^0.8.0",
436
436
  "@google/generative-ai": "^0.24.1",
437
- "@retrivora-ai/billing-guards": "*",
438
437
  "@pinecone-database/pinecone": "^7.2.0",
438
+ "@retrivora-ai/billing-guards": "*",
439
439
  "@types/papaparse": "^5.5.2",
440
+ "framer-motion": "^13.1.0",
441
+ katex: "^0.18.4",
440
442
  "lucide-react": "^1.8.0",
441
443
  "next-themes": "^0.4.6",
442
444
  openai: "^6.34.0",
443
445
  papaparse: "^5.5.3",
444
446
  "react-is": "^18.3.1",
445
447
  "react-markdown": "^10.1.0",
448
+ "react-syntax-highlighter": "^16.1.1",
446
449
  recharts: "^3.8.1",
450
+ "rehype-katex": "^7.0.1",
447
451
  "remark-gfm": "^4.0.1",
448
- xlsx: "^0.18.5"
452
+ "remark-math": "^6.0.0",
453
+ exceljs: "^4.4.0",
454
+ zod: "^4.4.3"
449
455
  },
450
456
  optionalDependencies: {
451
457
  "@langchain/core": "^1.1.42",
@@ -462,17 +468,19 @@ var init_package = __esm({
462
468
  "@tailwindcss/postcss": "^4",
463
469
  "@types/estree": "^1.0.9",
464
470
  "@types/jest": "^30.0.0",
471
+ "@types/katex": "^0.16.8",
465
472
  "@types/node": "^20",
466
473
  "@types/pdf-parse": "^1.1.5",
467
474
  "@types/pg": "^8.20.0",
468
475
  "@types/react": "^19.2.14",
469
476
  "@types/react-dom": "^19.2.3",
477
+ "@types/react-syntax-highlighter": "^15.5.13",
470
478
  axios: "^1.15.0",
471
479
  dotenv: "^17.4.2",
472
480
  eslint: "^9",
473
- "eslint-config-next": "16.2.4",
481
+ "eslint-config-next": "16.3.2",
474
482
  jest: "^30.4.2",
475
- next: "16.2.10",
483
+ next: "^16.3.2",
476
484
  tailwindcss: "^4",
477
485
  "ts-jest": "^29.4.12",
478
486
  tsup: "^8.5.1",
@@ -2868,6 +2876,36 @@ function wrapError(err, defaultCode, defaultMessage) {
2868
2876
  // src/core/LicenseVerifier.ts
2869
2877
  var _LicenseVerifier = class _LicenseVerifier {
2870
2878
  // Cache verified license for 5 minutes
2879
+ /**
2880
+ * Computes a deterministic hardware fingerprint to enforce node-locked licensing.
2881
+ */
2882
+ static async generateMachineFingerprint() {
2883
+ if (typeof window !== "undefined" && typeof navigator !== "undefined") {
2884
+ return navigator.userAgent || "browser-fallback-fingerprint";
2885
+ }
2886
+ try {
2887
+ const os2 = await import("os");
2888
+ const crypto2 = await import("crypto");
2889
+ const interfaces = os2.networkInterfaces();
2890
+ const macAddresses = [];
2891
+ for (const name of Object.keys(interfaces)) {
2892
+ for (const iface of interfaces[name] || []) {
2893
+ if (!iface.internal && iface.mac && iface.mac !== "00:00:00:00:00:00") {
2894
+ macAddresses.push(iface.mac);
2895
+ }
2896
+ }
2897
+ }
2898
+ const rawData = [
2899
+ macAddresses.sort().join(","),
2900
+ os2.platform(),
2901
+ os2.arch(),
2902
+ os2.hostname()
2903
+ ].join("|");
2904
+ return crypto2.createHash("sha256").update(rawData).digest("hex");
2905
+ } catch (err) {
2906
+ return "fallback-fingerprint-failed";
2907
+ }
2908
+ }
2871
2909
  /**
2872
2910
  * Validates the license key asynchronously by calling the Retrivora backend.
2873
2911
  *
@@ -2911,6 +2949,7 @@ var _LicenseVerifier = class _LicenseVerifier {
2911
2949
  }
2912
2950
  const endpoint = `${baseUrl}/api/v1/license/validate`;
2913
2951
  let response;
2952
+ const machineFingerprint = await this.generateMachineFingerprint();
2914
2953
  try {
2915
2954
  response = await fetch(endpoint, {
2916
2955
  method: "POST",
@@ -2921,7 +2960,8 @@ var _LicenseVerifier = class _LicenseVerifier {
2921
2960
  body: JSON.stringify({
2922
2961
  licenseKey,
2923
2962
  projectId: currentProjectId,
2924
- provider
2963
+ provider,
2964
+ machineFingerprint
2925
2965
  })
2926
2966
  });
2927
2967
  } catch (fetchErr) {
@@ -3129,7 +3169,6 @@ var PROVIDERS_WITH_EMBEDDINGS = [
3129
3169
  "rest",
3130
3170
  "universal_rest"
3131
3171
  ];
3132
- var UI_BORDER_RADIUS_OPTIONS = ["none", "sm", "md", "lg", "xl", "full"];
3133
3172
 
3134
3173
  // src/config/serverConfig.ts
3135
3174
  var _runtimeConfig = null;
@@ -3250,7 +3289,7 @@ function getEnvConfig(env = process.env, base) {
3250
3289
  return true;
3251
3290
  }
3252
3291
  })();
3253
- const tierBasedLLMModel = isFreeTier2 ? "llama-3.1-8b-instant" : "llama-3.3-70b-versatile";
3292
+ const tierBasedLLMModel = isFreeTier2 ? "free-tier-standard" : "qwen-3.6-27b";
3254
3293
  const tierBasedEmbeddingModel = isFreeTier2 ? "text-embedding-004" : "text-embedding-004";
3255
3294
  const controlPlaneUrl = (_ma = readString(env, "RETRIVORA_CONTROL_PLANE_URL")) != null ? _ma : readString(env, "NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL");
3256
3295
  const defaultGatewayUrl = controlPlaneUrl ? `${controlPlaneUrl.replace(/\/$/, "")}/api/v1` : "https://llm.retrivora.com/api/v1";
@@ -3258,7 +3297,16 @@ function getEnvConfig(env = process.env, base) {
3258
3297
  const defaultLlmProvider = "universal_rest";
3259
3298
  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;
3260
3299
  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;
3261
- const 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;
3300
+ 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;
3301
+ if ((rt == null ? void 0 : rt.allowedModels) && rt.allowedModels.length > 0) {
3302
+ if (!rt.allowedModels.includes(llmModel)) {
3303
+ console.warn(`[Retrivora SDK] Model "${llmModel}" is not permitted on the current license tier. Falling back to default: ${rt.llmModel || tierBasedLLMModel}`);
3304
+ llmModel = rt.llmModel || tierBasedLLMModel;
3305
+ }
3306
+ } else if (isFreeTier2 && llmModel !== "free-tier-standard") {
3307
+ console.warn(`[Retrivora SDK] Explicit models are not permitted on the Free tier. Falling back to default load-balanced pool.`);
3308
+ llmModel = "free-tier-standard";
3309
+ }
3262
3310
  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;
3263
3311
  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";
3264
3312
  const defaultEmbeddingProvider = "universal_rest";
@@ -3471,6 +3519,9 @@ var ConfigResolver = class {
3471
3519
  }
3472
3520
  };
3473
3521
 
3522
+ // src/core/ConfigValidator.ts
3523
+ var import_zod = require("zod");
3524
+
3474
3525
  // src/llm/providers/OpenAIProvider.ts
3475
3526
  var import_openai = __toESM(require("openai"));
3476
3527
 
@@ -3494,7 +3545,11 @@ ${context}`;
3494
3545
  var OpenAIProvider = class {
3495
3546
  constructor(llmConfig, embeddingConfig) {
3496
3547
  if (!llmConfig.apiKey) throw new Error("[OpenAIProvider] llmConfig.apiKey is required");
3497
- this.client = new import_openai.default({ apiKey: llmConfig.apiKey });
3548
+ this.client = new import_openai.default({
3549
+ apiKey: llmConfig.apiKey,
3550
+ baseURL: llmConfig.baseUrl,
3551
+ maxRetries: 5
3552
+ });
3498
3553
  this.llmConfig = llmConfig;
3499
3554
  this.embeddingConfig = embeddingConfig;
3500
3555
  }
@@ -4256,7 +4311,8 @@ var GroqProvider = class {
4256
4311
  if (!apiKey) throw new Error("[GroqProvider] llmConfig.apiKey or GROQ_API_KEY environment variable is required");
4257
4312
  this.client = new import_openai2.default({
4258
4313
  apiKey,
4259
- baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1"
4314
+ baseURL: llmConfig.baseUrl || "https://api.groq.com/openai/v1",
4315
+ maxRetries: 5
4260
4316
  });
4261
4317
  this.llmConfig = llmConfig;
4262
4318
  }
@@ -4276,7 +4332,7 @@ var GroqProvider = class {
4276
4332
  errors.push({
4277
4333
  field: "llm.model",
4278
4334
  message: "Groq model name is required",
4279
- suggestion: 'e.g., "llama-3.3-70b-versatile"',
4335
+ suggestion: 'e.g., "qwen-3.6-27b"',
4280
4336
  severity: "error"
4281
4337
  });
4282
4338
  }
@@ -5228,24 +5284,69 @@ ProviderRegistry.llmValidators = {};
5228
5284
  ProviderRegistry.llmHealthCheckers = {};
5229
5285
 
5230
5286
  // src/core/ConfigValidator.ts
5287
+ var UIConfigSchema = import_zod.z.object({
5288
+ primaryColor: import_zod.z.string().optional(),
5289
+ borderRadius: import_zod.z.enum(["none", "sm", "md", "lg", "xl", "full"]).optional()
5290
+ }).passthrough().optional();
5291
+ var VectorDbSchema = import_zod.z.object({
5292
+ provider: import_zod.z.string().min(1, "Vector database provider is required"),
5293
+ indexName: import_zod.z.string().min(1, "Vector database index name is required"),
5294
+ options: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
5295
+ }).passthrough().superRefine((val, ctx) => {
5296
+ const opts = val.options || {};
5297
+ if (val.provider === "milvus") {
5298
+ if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
5299
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Milvus connection info required" });
5300
+ }
5301
+ } else if (val.provider === "qdrant") {
5302
+ if (!opts.baseUrl && !opts.url) {
5303
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["options", "baseUrl"], message: "Qdrant URL required" });
5304
+ }
5305
+ }
5306
+ });
5307
+ var LLMSchema = import_zod.z.object({
5308
+ provider: import_zod.z.string().min(1, "LLM provider is required"),
5309
+ model: import_zod.z.string().optional(),
5310
+ temperature: import_zod.z.number().min(0, "Temperature must be at least 0").max(2, "Temperature must be at most 2").optional()
5311
+ }).passthrough().superRefine((val, ctx) => {
5312
+ if (!val.model) {
5313
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["model"], message: "LLM model name is required" });
5314
+ }
5315
+ });
5316
+ var EmbeddingSchema = import_zod.z.object({
5317
+ provider: import_zod.z.string().min(1, "Embedding provider is required"),
5318
+ model: import_zod.z.string().optional()
5319
+ }).passthrough().superRefine((val, ctx) => {
5320
+ if (!val.model) {
5321
+ ctx.addIssue({ code: import_zod.z.ZodIssueCode.custom, path: ["model"], message: "Embedding model name is required" });
5322
+ }
5323
+ });
5324
+ var RAGSchema = import_zod.z.object({
5325
+ topK: import_zod.z.number().positive("topK must be a positive integer").optional()
5326
+ }).passthrough().optional();
5327
+ var RagConfigSchema = import_zod.z.object({
5328
+ projectId: import_zod.z.string().min(1, "projectId is required"),
5329
+ vectorDb: VectorDbSchema,
5330
+ llm: LLMSchema,
5331
+ embedding: EmbeddingSchema.optional(),
5332
+ ui: UIConfigSchema,
5333
+ rag: RAGSchema
5334
+ }).passthrough();
5231
5335
  var ConfigValidator = class {
5232
- /**
5233
- * Validates the entire RagConfig object.
5234
- */
5235
5336
  static async validate(config) {
5337
+ var _a2, _b, _c, _d, _e;
5236
5338
  const errors = [];
5237
- if (!config.projectId) {
5238
- errors.push({
5239
- field: "projectId",
5240
- message: "projectId is required",
5241
- severity: "error"
5242
- });
5339
+ const result = RagConfigSchema.safeParse(config);
5340
+ if (!result.success) {
5341
+ for (const issue of result.error.issues) {
5342
+ errors.push({
5343
+ field: issue.path.join("."),
5344
+ message: issue.message,
5345
+ severity: "error"
5346
+ });
5347
+ }
5243
5348
  }
5244
- errors.push(...await this.validateVectorDbConfig(config.vectorDb));
5245
- errors.push(...await this.validateLLMConfig(config.llm));
5246
- if (config.embedding) {
5247
- errors.push(...await this.validateEmbeddingConfig(config.embedding));
5248
- } else if (config.llm.provider === "anthropic") {
5349
+ if (((_a2 = config.llm) == null ? void 0 : _a2.provider) === "anthropic" && !config.embedding) {
5249
5350
  errors.push({
5250
5351
  field: "embedding",
5251
5352
  message: "Embedding config is required when using Anthropic LLM",
@@ -5253,113 +5354,35 @@ var ConfigValidator = class {
5253
5354
  severity: "error"
5254
5355
  });
5255
5356
  }
5256
- if (config.ui) {
5257
- errors.push(...this.validateUIConfig(config.ui));
5258
- }
5259
- if (config.rag) {
5260
- errors.push(...this.validateRAGConfig(config.rag));
5261
- }
5262
- return errors;
5263
- }
5264
- static async validateVectorDbConfig(config) {
5265
- const errors = [];
5266
- if (!config.provider) {
5267
- errors.push({ field: "vectorDb.provider", message: "Vector database provider is required", severity: "error" });
5268
- return errors;
5269
- }
5270
- if (!config.indexName) {
5271
- errors.push({ field: "vectorDb.indexName", message: "Vector database index name is required", severity: "error" });
5272
- }
5273
- const validator = await ProviderRegistry.getVectorValidator(config.provider);
5274
- if (validator) {
5275
- errors.push(...validator.validate(config));
5276
- } else {
5277
- this.fallbackVectorValidation(config, errors);
5278
- }
5279
- return errors;
5280
- }
5281
- static async validateLLMConfig(config) {
5282
- const errors = [];
5283
- if (!config.provider) {
5284
- errors.push({ field: "llm.provider", message: "LLM provider is required", severity: "error" });
5285
- return errors;
5286
- }
5287
- const validator = LLMFactory.getValidator(config.provider);
5288
- if (validator) {
5289
- errors.push(...validator.validate(config));
5290
- } else {
5291
- this.fallbackLLMValidation(config, errors);
5292
- }
5293
- if (config.temperature !== void 0 && (config.temperature < 0 || config.temperature > 2)) {
5294
- errors.push({ field: "llm.temperature", message: "Temperature must be between 0 and 2", severity: "error" });
5295
- }
5296
- return errors;
5297
- }
5298
- static async validateEmbeddingConfig(config) {
5299
- const errors = [];
5300
- if (!config.provider) {
5301
- errors.push({ field: "embedding.provider", message: "Embedding provider is required", severity: "error" });
5302
- return errors;
5303
- }
5304
- const validator = LLMFactory.getValidator(config.provider);
5305
- if (validator) {
5306
- errors.push(...validator.validate(config));
5307
- } else {
5308
- this.fallbackEmbeddingValidation(config, errors);
5309
- }
5310
- return errors;
5311
- }
5312
- /**
5313
- * Temporary fallbacks for providers not yet migrated to the pluggable architecture.
5314
- */
5315
- static fallbackVectorValidation(config, errors) {
5316
- const opts = config.options || {};
5317
- switch (config.provider) {
5318
- case "milvus":
5319
- if (!opts.baseUrl && !opts.uri && !(opts.host && opts.port)) {
5320
- errors.push({ field: "vectorDb.options.baseUrl", message: "Milvus connection info required", severity: "error" });
5321
- }
5322
- break;
5323
- case "qdrant":
5324
- if (!opts.baseUrl && !opts.url) {
5325
- errors.push({ field: "vectorDb.options.baseUrl", message: "Qdrant URL required", severity: "error" });
5326
- }
5327
- break;
5328
- }
5329
- }
5330
- static fallbackLLMValidation(config, errors) {
5331
- if (!config.model) {
5332
- errors.push({ field: "llm.model", message: "LLM model name is required", severity: "error" });
5333
- }
5334
- }
5335
- static fallbackEmbeddingValidation(config, errors) {
5336
- if (!config.model) {
5337
- errors.push({ field: "embedding.model", message: "Embedding model name is required", severity: "error" });
5357
+ if ((_b = config.ui) == null ? void 0 : _b.primaryColor) {
5358
+ const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
5359
+ const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
5360
+ const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
5361
+ const color = config.ui.primaryColor;
5362
+ if (!hexRegex.test(color) && !rgbRegex.test(color) && !namedColors.includes(color.toLowerCase())) {
5363
+ errors.push({ field: "ui.primaryColor", message: "Invalid CSS color format", severity: "warning" });
5364
+ }
5338
5365
  }
5339
- }
5340
- static validateUIConfig(config) {
5341
- const errors = [];
5342
- if (config.primaryColor && !this.isValidCSSColor(config.primaryColor)) {
5343
- errors.push({ field: "ui.primaryColor", message: "Invalid CSS color format", severity: "warning" });
5366
+ if ((_c = config.vectorDb) == null ? void 0 : _c.provider) {
5367
+ const vectorValidator = await ProviderRegistry.getVectorValidator(config.vectorDb.provider);
5368
+ if (vectorValidator) {
5369
+ errors.push(...vectorValidator.validate(config.vectorDb));
5370
+ }
5344
5371
  }
5345
- if (config.borderRadius && !UI_BORDER_RADIUS_OPTIONS.includes(config.borderRadius)) {
5346
- errors.push({ field: "ui.borderRadius", message: `borderRadius must be one of: ${UI_BORDER_RADIUS_OPTIONS.join(", ")}`, severity: "warning" });
5372
+ if ((_d = config.llm) == null ? void 0 : _d.provider) {
5373
+ const llmValidator = LLMFactory.getValidator(config.llm.provider);
5374
+ if (llmValidator) {
5375
+ errors.push(...llmValidator.validate(config.llm));
5376
+ }
5347
5377
  }
5348
- return errors;
5349
- }
5350
- static validateRAGConfig(config) {
5351
- const errors = [];
5352
- if (config.topK !== void 0 && (typeof config.topK !== "number" || config.topK <= 0)) {
5353
- errors.push({ field: "rag.topK", message: "topK must be a positive integer", severity: "error" });
5378
+ if ((_e = config.embedding) == null ? void 0 : _e.provider) {
5379
+ const embeddingValidator = LLMFactory.getValidator(config.embedding.provider);
5380
+ if (embeddingValidator) {
5381
+ errors.push(...embeddingValidator.validate(config.embedding));
5382
+ }
5354
5383
  }
5355
5384
  return errors;
5356
5385
  }
5357
- static isValidCSSColor(color) {
5358
- const hexRegex = /^#([0-9a-f]{3}){1,2}$/i;
5359
- const rgbRegex = /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i;
5360
- const namedColors = ["red", "blue", "green", "black", "white", "transparent"];
5361
- return hexRegex.test(color) || rgbRegex.test(color) || namedColors.includes(color.toLowerCase());
5362
- }
5363
5386
  static async validateAndThrow(config) {
5364
5387
  const errors = await this.validate(config);
5365
5388
  const errorItems = errors.filter((e) => e.severity === "error");
@@ -6005,6 +6028,38 @@ var MCPRegistry = class {
6005
6028
  }
6006
6029
  };
6007
6030
 
6031
+ // src/utils/logger.ts
6032
+ var Logger = class {
6033
+ static format(level, message, meta) {
6034
+ if (this.isProduction) {
6035
+ return JSON.stringify(__spreadValues({
6036
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
6037
+ level,
6038
+ message
6039
+ }, meta));
6040
+ }
6041
+ const metaString = meta ? `
6042
+ ${JSON.stringify(meta, null, 2)}` : "";
6043
+ return `[${(/* @__PURE__ */ new Date()).toISOString()}] [${level}] ${message}${metaString}`;
6044
+ }
6045
+ static info(message, meta) {
6046
+ console.log(this.format("INFO", message, meta));
6047
+ }
6048
+ static warn(message, meta) {
6049
+ console.warn(this.format("WARN", message, meta));
6050
+ }
6051
+ static error(message, error, meta) {
6052
+ const errorMeta = error instanceof Error ? { errorMessage: error.message, stack: error.stack } : { error: String(error) };
6053
+ console.error(this.format("ERROR", message, __spreadValues(__spreadValues({}, meta), errorMeta)));
6054
+ }
6055
+ static debug(message, meta) {
6056
+ if (process.env.DEBUG === "true") {
6057
+ console.debug(this.format("DEBUG", message, meta));
6058
+ }
6059
+ }
6060
+ };
6061
+ Logger.isProduction = process.env.NODE_ENV === "production" || process.env.VERCEL_ENV === "production";
6062
+
6008
6063
  // src/core/MultiAgentCoordinator.ts
6009
6064
  function parseToolCall(text) {
6010
6065
  const match = text.match(/TOOL_CALL:\s*([\w-]+)\s*\(\s*([\s\S]*?)\s*\)\s*[.,;]?\s*$/m);
@@ -6022,7 +6077,7 @@ function parseToolCall(text) {
6022
6077
  } catch (e) {
6023
6078
  const pairs = [...argsRaw.matchAll(/"?([\w-]+)"?\s*:\s*"([^"]*)"/g)];
6024
6079
  if (pairs.length === 0) {
6025
- console.warn("[parseToolCall] Could not parse tool args:", argsRaw);
6080
+ Logger.warn("[parseToolCall] Could not parse tool args", { argsRaw });
6026
6081
  return null;
6027
6082
  }
6028
6083
  for (const [, k, v] of pairs) args[k] = v;
@@ -6425,7 +6480,7 @@ ${errorMessages}`
6425
6480
  static async mapWithRetry(items, mapper, options) {
6426
6481
  const result = await this.processSequential(items, mapper, options);
6427
6482
  if (result.errors.length > 0) {
6428
- console.warn(
6483
+ Logger.warn(
6429
6484
  `[BatchProcessor] mapWithRetry: ${result.errors.length} items failed`
6430
6485
  );
6431
6486
  }
@@ -9177,7 +9232,7 @@ var Pipeline = class {
9177
9232
  }
9178
9233
  await this.vectorDB.initialize();
9179
9234
  if (this.isMultiAgentMode) {
9180
- console.log("[Pipeline] Initializing MultiAgentCoordinator (multi-agent / MCP mode).");
9235
+ Logger.info("[Pipeline] Initializing MultiAgentCoordinator (multi-agent / MCP mode).");
9181
9236
  this.mcpRegistry = new MCPRegistry(this.config.mcpServers || []);
9182
9237
  this.multiAgentCoordinator = new MultiAgentCoordinator({
9183
9238
  llmProvider: this.llmProvider,
@@ -9187,7 +9242,7 @@ var Pipeline = class {
9187
9242
  maxIterations: (_a2 = this.config.rag) == null ? void 0 : _a2.agentMaxIterations
9188
9243
  });
9189
9244
  } else if (this.isLangChainAgentMode) {
9190
- console.log("[Pipeline] Initializing LangChainAgent (agentic / ReAct mode).");
9245
+ Logger.info("[Pipeline] Initializing LangChainAgent (agentic / ReAct mode).");
9191
9246
  this.agent = new LangChainAgent(this, this.config);
9192
9247
  await this.agent.initialize(this.llmProvider);
9193
9248
  }
@@ -9210,13 +9265,13 @@ var Pipeline = class {
9210
9265
  const formatted = coldMatches.map((m, i) => `[Cold Source ${i + 1}]
9211
9266
  ${m.content}`).join("\n\n---\n\n");
9212
9267
  this.coldContexts.set(ns, formatted);
9213
- console.log(`[Pipeline] Cold RAG (CAG) loaded ${coldMatches.length} documents into cached context for namespace: ${ns}`);
9268
+ Logger.info(`[Pipeline] Cold RAG (CAG) loaded ${coldMatches.length} documents into cached context for namespace: ${ns}`);
9214
9269
  } else {
9215
9270
  this.coldContexts.set(ns, "No cold context found.");
9216
- console.warn(`[Pipeline] Cold RAG (CAG) initialized but no documents were found in namespace: ${coldNs}`);
9271
+ Logger.warn(`[Pipeline] Cold RAG (CAG) initialized but no documents were found in namespace: ${coldNs}`);
9217
9272
  }
9218
9273
  } catch (err) {
9219
- console.error(`[Pipeline] Failed to load Cold RAG (CAG) context for namespace ${ns}:`, err);
9274
+ Logger.error(`[Pipeline] Failed to load Cold RAG (CAG) context for namespace ${ns}`, err);
9220
9275
  this.coldContexts.set(ns, "Failed to load cold context.");
9221
9276
  }
9222
9277
  }
@@ -9243,7 +9298,7 @@ ${m.content}`).join("\n\n---\n\n");
9243
9298
  await this.processGraphIngestion(doc.docId, chunks);
9244
9299
  }
9245
9300
  } catch (error) {
9246
- console.error(`[Pipeline] Failed to ingest document ${doc.docId}:`, error);
9301
+ Logger.error(`[Pipeline] Failed to ingest document ${doc.docId}`, error);
9247
9302
  results.push({ docId: doc.docId, chunksIngested: 0 });
9248
9303
  }
9249
9304
  }
@@ -9297,10 +9352,7 @@ ${m.content}`).join("\n\n---\n\n");
9297
9352
  upsertBatchOptions
9298
9353
  );
9299
9354
  if (upsertResult.errors.length > 0) {
9300
- console.warn(`[Pipeline] Ingestion: ${upsertResult.errors.length} batches failed. Error details:`);
9301
- upsertResult.errors.forEach((err, idx) => {
9302
- console.warn(` Batch ${idx + 1} Error: ${err.error.message || String(err.error)}`);
9303
- });
9355
+ Logger.warn(`[Pipeline] Ingestion: ${upsertResult.errors.length} batches failed.`, { errors: upsertResult.errors.map((e) => e.error.message || String(e.error)) });
9304
9356
  }
9305
9357
  return upsertResult.totalProcessed;
9306
9358
  }
@@ -9320,7 +9372,7 @@ ${m.content}`).join("\n\n---\n\n");
9320
9372
  if (nodes.length > 0) await this.graphDB.addNodes(nodes);
9321
9373
  if (edges.length > 0) await this.graphDB.addEdges(edges);
9322
9374
  } catch (err) {
9323
- console.warn(`[Pipeline] Entity extraction failed for chunk in doc ${docId}:`, err);
9375
+ Logger.warn(`[Pipeline] Entity extraction failed for chunk in doc ${docId}`, { error: String(err) });
9324
9376
  }
9325
9377
  }
9326
9378
  },
@@ -9581,7 +9633,7 @@ ${context}`;
9581
9633
  cachedSchema,
9582
9634
  hasNumericPredicates
9583
9635
  ).catch((uiError) => {
9584
- console.warn("[Pipeline] UI transformation failed concurrently:", uiError);
9636
+ Logger.warn("[Pipeline] UI transformation failed concurrently", { error: String(uiError) });
9585
9637
  return UITransformer.transform(question, sources, this.config, cachedSchema);
9586
9638
  });
9587
9639
  let hallucinationScoringPromise = Promise.resolve(void 0);
@@ -9783,7 +9835,9 @@ ${context}`;
9783
9835
  const tokenCount = Number(((_c2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _c2.totalTokens) || 0);
9784
9836
  const costEst = Number(((_d2 = finalTrace == null ? void 0 : finalTrace.tokens) == null ? void 0 : _d2.estimatedCostUsd) || 0);
9785
9837
  const latencyDuration = Number(((_e2 = finalTrace == null ? void 0 : finalTrace.latency) == null ? void 0 : _e2.totalMs) || 0);
9786
- console.log(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
9838
+ if (typeof window === "undefined") {
9839
+ Logger.info(`[Retrivora Pipeline Telemetry] \u{1F4CA} Dispatching RAG telemetry -> Project: "${ns}", Tokens: ${tokenCount}, Latency: ${latencyDuration}ms`);
9840
+ }
9787
9841
  await fetch(absoluteUrl, {
9788
9842
  method: "POST",
9789
9843
  headers: {
@@ -9807,9 +9861,11 @@ ${context}`;
9807
9861
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
9808
9862
  details: `Org: default-org | Model: ${providerName}/${modelName} | Tokens: ${tokenCount} | Latency: ${latencyDuration}ms | Cost: $${costEst} | SDK: v${SDK_VERSION} | Feature: RAG`
9809
9863
  })
9864
+ }).catch((err) => {
9865
+ Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}`, { error: err.message });
9810
9866
  });
9811
9867
  } catch (err) {
9812
- console.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}:`, err.message);
9868
+ Logger.warn(`[Pipeline Telemetry] Failed to send trace async to ${absoluteUrl}:`, { error: err.message });
9813
9869
  }
9814
9870
  })();
9815
9871
  }
@@ -9852,7 +9908,7 @@ ${context}`;
9852
9908
  try {
9853
9909
  return await UITransformer.analyzeAndDecide(question, sources, this.llmRouter.get("fast"));
9854
9910
  } catch (err) {
9855
- console.warn("[Pipeline] generateUiTransformation failed, using heuristic fallback:", err);
9911
+ Logger.warn("[Pipeline] generateUiTransformation failed, using heuristic fallback", { error: String(err) });
9856
9912
  return UITransformer.transform(question, sources, this.config, cachedSchema);
9857
9913
  }
9858
9914
  }
@@ -9950,7 +10006,7 @@ ${context}`;
9950
10006
  query,
9951
10007
  useGraph ? this.llmRouter.get("fast") : void 0
9952
10008
  );
9953
- console.debug(`[Pipeline] Determined retrieval strategy: ${strategy}`);
10009
+ Logger.debug(`[Pipeline] Determined retrieval strategy: ${strategy}`);
9954
10010
  const [retrievedVector, graphData] = await Promise.all([
9955
10011
  // Only embed if we need vector search (strategy is 'vector' or 'both')
9956
10012
  strategy === "vector" || strategy === "both" ? queryVector ? Promise.resolve(queryVector) : this.embeddingProvider.embed(query, { taskType: "query" }) : Promise.resolve([]),
@@ -9972,8 +10028,7 @@ ${context}`;
9972
10028
  baseFilter
9973
10029
  ) : [];
9974
10030
  const resolvedSources = sources;
9975
- console.log("[Pipeline] retrieve() response:", {
9976
- query,
10031
+ Logger.info("[Pipeline] retrieve() response", {
9977
10032
  namespace: ns,
9978
10033
  count: resolvedSources.length,
9979
10034
  sample: resolvedSources.slice(0, 2).map((s) => {
@@ -10053,7 +10108,7 @@ Suggestions:`;
10053
10108
  }
10054
10109
  }
10055
10110
  } catch (error) {
10056
- console.error("[Pipeline] Failed to generate suggestions:", error);
10111
+ Logger.error("[Pipeline] Failed to generate suggestions", error);
10057
10112
  }
10058
10113
  return [];
10059
10114
  }
@@ -10649,18 +10704,25 @@ var DocumentParser = class {
10649
10704
  }
10650
10705
  if (extension === "xlsx" || extension === "xls" || mimeType.includes("spreadsheet") || mimeType.includes("excel")) {
10651
10706
  try {
10652
- const xlsx = await import("xlsx");
10707
+ const ExcelJS = await import("exceljs");
10653
10708
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
10654
- const workbook = xlsx.read(buffer, { type: "buffer" });
10709
+ const workbook = new ExcelJS.Workbook();
10710
+ await workbook.xlsx.load(buffer);
10655
10711
  const sheetsText = [];
10656
- for (const sheetName of workbook.SheetNames) {
10657
- const sheet = workbook.Sheets[sheetName];
10658
- const csv = xlsx.utils.sheet_to_csv(sheet);
10712
+ workbook.eachSheet((sheet, sheetId) => {
10713
+ const csvLines = [];
10714
+ sheet.eachRow((row, rowNumber) => {
10715
+ const values = row.values;
10716
+ if (Array.isArray(values)) {
10717
+ csvLines.push(values.slice(1).join(","));
10718
+ }
10719
+ });
10720
+ const csv = csvLines.join("\n");
10659
10721
  if (csv && csv.trim()) {
10660
- sheetsText.push(`--- Sheet: ${sheetName} ---
10722
+ sheetsText.push(`--- Sheet: ${sheet.name} ---
10661
10723
  ${csv.trim()}`);
10662
10724
  }
10663
- }
10725
+ });
10664
10726
  return sheetsText.join("\n\n") || `[Empty Excel Workbook: ${fileName}]`;
10665
10727
  } catch (e) {
10666
10728
  try {
@@ -10672,9 +10734,10 @@ ${csv.trim()}`);
10672
10734
  }
10673
10735
  if (extension === "pdf" || mimeType === "application/pdf") {
10674
10736
  try {
10675
- const pdf = await import("pdf-parse");
10737
+ const pdfModule = await import("pdf-parse");
10676
10738
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
10677
- const data = await pdf.default(buffer);
10739
+ const pdf = pdfModule.default || pdfModule;
10740
+ const data = await pdf(buffer);
10678
10741
  return data.text;
10679
10742
  } catch (err) {
10680
10743
  console.warn('[DocumentParser] PDF parsing failed. Make sure "pdf-parse" is installed.', err);
@@ -11434,7 +11497,7 @@ function sanitizeTelemetryUrl(raw) {
11434
11497
  return null;
11435
11498
  }
11436
11499
  }
11437
- function reportTelemetry(req, plugin, action, status, details, trace) {
11500
+ async function reportTelemetry(req, plugin, action, status, details, trace) {
11438
11501
  var _a2, _b, _c, _d, _e, _f, _g2;
11439
11502
  try {
11440
11503
  const config = plugin.getConfig();
@@ -11469,7 +11532,7 @@ function reportTelemetry(req, plugin, action, status, details, trace) {
11469
11532
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
11470
11533
  details
11471
11534
  };
11472
- fetch(telemetryUrl, {
11535
+ await fetch(telemetryUrl, {
11473
11536
  method: "POST",
11474
11537
  headers: __spreadProps(__spreadValues({
11475
11538
  "Content-Type": "application/json"
@@ -11590,14 +11653,14 @@ function createChatHandler(configOrPlugin, options) {
11590
11653
  uiTransformation: result.ui_transformation,
11591
11654
  trace: result.trace
11592
11655
  }).catch((err) => console.warn("[createChatHandler] Failed to save assistant message:", err));
11593
- 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);
11656
+ 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);
11594
11657
  return import_server.NextResponse.json(__spreadProps(__spreadValues({}, result), {
11595
11658
  messageId: assistantMsgId,
11596
11659
  userMessageId: userMsgId
11597
11660
  }));
11598
11661
  } catch (err) {
11599
11662
  const message = err instanceof Error ? err.message : "Internal server error";
11600
- reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
11663
+ await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", message);
11601
11664
  return import_server.NextResponse.json({ error: message }, { status: 500 });
11602
11665
  }
11603
11666
  };
@@ -11735,7 +11798,7 @@ function createStreamHandler(configOrPlugin, options) {
11735
11798
  uiTransformation,
11736
11799
  trace: responseChunk == null ? void 0 : responseChunk.trace
11737
11800
  }).catch((err) => console.warn("[createStreamHandler] Failed to save assistant message:", err));
11738
- 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);
11801
+ 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);
11739
11802
  }
11740
11803
  }
11741
11804
  } catch (temp) {
@@ -11755,7 +11818,7 @@ function createStreamHandler(configOrPlugin, options) {
11755
11818
  errorMessage = "Your Retrivora license key has been terminated, suspended, or revoked. Access denied.";
11756
11819
  }
11757
11820
  console.error("[createStreamHandler] Stream error:", streamError);
11758
- reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
11821
+ await reportTelemetry(req, plugin, "QUERY_GENERATION", "error", errorMessage);
11759
11822
  try {
11760
11823
  enqueue(sseErrorFrame(errorMessage));
11761
11824
  } catch (e) {
@@ -11817,11 +11880,11 @@ function createIngestHandler(configOrPlugin, options) {
11817
11880
  }
11818
11881
  }
11819
11882
  const results = await plugin.ingest(documents, namespaceCheck.namespace);
11820
- reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
11883
+ await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Ingested ${documents.length} document(s)`);
11821
11884
  return import_server.NextResponse.json({ results });
11822
11885
  } catch (err) {
11823
11886
  const message = err instanceof Error ? err.message : "Internal server error";
11824
- reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
11887
+ await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
11825
11888
  return import_server.NextResponse.json({ error: message }, { status: 500 });
11826
11889
  }
11827
11890
  };
@@ -11982,41 +12045,47 @@ function createUploadHandler(configOrPlugin, options) {
11982
12045
  }
11983
12046
  }
11984
12047
  } else if (isExcel) {
11985
- const xlsx = await import("xlsx");
12048
+ const ExcelJS = await import("exceljs");
11986
12049
  const buffer = Buffer.isBuffer(file) ? file : Buffer.from(await file.arrayBuffer());
11987
- const workbook = xlsx.read(buffer, { type: "buffer" });
11988
- for (const sheetName of workbook.SheetNames) {
11989
- const sheet = workbook.Sheets[sheetName];
11990
- const jsonRows = xlsx.utils.sheet_to_json(sheet, { defval: "" });
11991
- if (jsonRows && jsonRows.length > 0) {
11992
- let i = 0;
11993
- const headers = Object.keys(jsonRows[0] || {});
11994
- for (const rowData of jsonRows) {
11995
- i++;
11996
- const contentParts = [];
11997
- for (const [key, val] of Object.entries(rowData)) {
11998
- if (key && val !== void 0 && val !== null && String(val).trim()) {
11999
- contentParts.push(`${key}: ${val}`);
12000
- }
12001
- }
12002
- if (contentParts.length > 0) {
12003
- documents.push({
12004
- docId: `${file.name}-${sheetName}-row-${i}`,
12005
- content: contentParts.join(", "),
12006
- metadata: __spreadValues(__spreadProps(__spreadValues({
12007
- fileName: file.name,
12008
- sheetName,
12009
- fileSize: file.size,
12010
- fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
12011
- uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
12012
- }, dimension ? { dimension } : {}), {
12013
- headers
12014
- }), rowData)
12015
- });
12050
+ const workbook = new ExcelJS.Workbook();
12051
+ await workbook.xlsx.load(buffer);
12052
+ workbook.eachSheet((sheet, sheetId) => {
12053
+ const sheetName = sheet.name;
12054
+ let headers = [];
12055
+ let i = 0;
12056
+ sheet.eachRow((row, rowNumber) => {
12057
+ const values = Array.isArray(row.values) ? row.values.slice(1) : [];
12058
+ if (rowNumber === 1) {
12059
+ headers = values.map((v) => String(v));
12060
+ return;
12061
+ }
12062
+ i++;
12063
+ const contentParts = [];
12064
+ const rowData = {};
12065
+ values.forEach((val, index) => {
12066
+ const key = headers[index] || `Column${index + 1}`;
12067
+ rowData[key] = val;
12068
+ if (key && val !== void 0 && val !== null && String(val).trim()) {
12069
+ contentParts.push(`${key}: ${val}`);
12016
12070
  }
12071
+ });
12072
+ if (contentParts.length > 0) {
12073
+ documents.push({
12074
+ docId: `${file.name}-${sheetName}-row-${i}`,
12075
+ content: contentParts.join(", "),
12076
+ metadata: __spreadValues(__spreadProps(__spreadValues({
12077
+ fileName: file.name,
12078
+ sheetName,
12079
+ fileSize: file.size,
12080
+ fileType: file.type || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
12081
+ uploadedAt: (/* @__PURE__ */ new Date()).toISOString()
12082
+ }, dimension ? { dimension } : {}), {
12083
+ headers
12084
+ }), rowData)
12085
+ });
12017
12086
  }
12018
- }
12019
- }
12087
+ });
12088
+ });
12020
12089
  } else {
12021
12090
  const content = await DocumentParser.parse(file, file.name, file.type);
12022
12091
  documents.push({
@@ -12032,11 +12101,11 @@ function createUploadHandler(configOrPlugin, options) {
12032
12101
  }
12033
12102
  }
12034
12103
  const results = await plugin.ingest(documents, namespaceCheck.namespace);
12035
- reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
12104
+ await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "success", `Uploaded & ingested ${files.length} file(s)`);
12036
12105
  return import_server.NextResponse.json({ message: "Upload successful", results });
12037
12106
  } catch (err) {
12038
12107
  const message = err instanceof Error ? err.message : "Upload failed";
12039
- reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
12108
+ await reportTelemetry(req, plugin, "DOCUMENT_INGESTION", "error", message);
12040
12109
  return import_server.NextResponse.json({ error: message }, { status: 500 });
12041
12110
  }
12042
12111
  };
@@ -12076,11 +12145,11 @@ function createSuggestionsHandler(configOrPlugin, options) {
12076
12145
  const namespaceCheck = resolveLicensedNamespace(effectiveLicensePayload, namespace);
12077
12146
  if (!namespaceCheck.ok) return namespaceCheck.response;
12078
12147
  const suggestions = await plugin.getSuggestions(query, namespaceCheck.namespace);
12079
- reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
12148
+ await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "success", `Fetched ${suggestions.length} suggestions for: ${query.slice(0, 30)}`);
12080
12149
  return import_server.NextResponse.json({ suggestions });
12081
12150
  } catch (err) {
12082
12151
  const message = err instanceof Error ? err.message : "Internal server error";
12083
- reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
12152
+ await reportTelemetry(req, plugin, "AUTO_SUGGESTIONS", "error", message);
12084
12153
  return import_server.NextResponse.json({ error: message }, { status: 500 });
12085
12154
  }
12086
12155
  };