@retrivora-ai/rag-engine 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handlers/index.js +167 -50
- package/dist/handlers/index.mjs +167 -50
- package/dist/index.js +79 -22
- package/dist/index.mjs +79 -22
- package/dist/server.js +167 -50
- package/dist/server.mjs +167 -50
- package/package.json +1 -1
- package/src/core/Pipeline.ts +51 -13
- package/src/core/QueryProcessor.ts +3 -3
- package/src/llm/providers/UniversalLLMAdapter.ts +17 -15
- package/src/rag/Reranker.ts +2 -2
- package/src/rendering/IntentClassifier.ts +1 -1
- package/src/rendering/RendererRegistry.ts +1 -1
- package/src/utils/ProductExtractor.ts +1 -1
- package/src/utils/UITransformer.ts +62 -17
package/dist/index.js
CHANGED
|
@@ -1750,7 +1750,7 @@ function extractProductsFromSources(sources, isUser) {
|
|
|
1750
1750
|
const hasPricePattern = /\$\s*\d+/.test(s.content);
|
|
1751
1751
|
return hasStrongProductKey || hasProductIdentity || hasPricePattern || m.type === "product";
|
|
1752
1752
|
}).map((s) => {
|
|
1753
|
-
var _a, _b;
|
|
1753
|
+
var _a, _b, _c;
|
|
1754
1754
|
const m = (_a = s.metadata) != null ? _a : {};
|
|
1755
1755
|
const name = resolveMetadataValue(m, "name");
|
|
1756
1756
|
const brand = resolveMetadataValue(m, "brand");
|
|
@@ -1758,7 +1758,7 @@ function extractProductsFromSources(sources, isUser) {
|
|
|
1758
1758
|
const description = resolveMetadataValue(m, "description");
|
|
1759
1759
|
return {
|
|
1760
1760
|
id: s.id,
|
|
1761
|
-
name: (
|
|
1761
|
+
name: (_c = name != null ? name : ((_b = s == null ? void 0 : s.content) != null ? _b : "").split("\n")[0]) != null ? _c : "Unknown Product",
|
|
1762
1762
|
brand,
|
|
1763
1763
|
price,
|
|
1764
1764
|
image: resolveImage(m),
|
|
@@ -3654,7 +3654,10 @@ var IntentClassifier = class {
|
|
|
3654
3654
|
hasCategoricalFields = catKeys.size > 0;
|
|
3655
3655
|
numericFieldCount = numericKeys.size;
|
|
3656
3656
|
categoricalFieldCount = catKeys.size;
|
|
3657
|
-
if (productKeyMatches >= 2 || docs.some((d) =>
|
|
3657
|
+
if (productKeyMatches >= 2 || docs.some((d) => {
|
|
3658
|
+
var _a, _b;
|
|
3659
|
+
return ((_a = d == null ? void 0 : d.content) != null ? _a : "").toLowerCase().includes("price") || ((_b = d == null ? void 0 : d.content) != null ? _b : "").toLowerCase().includes("brand");
|
|
3660
|
+
})) {
|
|
3658
3661
|
isProductLike = true;
|
|
3659
3662
|
}
|
|
3660
3663
|
}
|
|
@@ -4045,6 +4048,19 @@ var UITransformer = class _UITransformer {
|
|
|
4045
4048
|
if (!retrievedData || retrievedData.length === 0) {
|
|
4046
4049
|
return this.createTextResponse("No data available", "No relevant data found for your query.");
|
|
4047
4050
|
}
|
|
4051
|
+
console.log("[UITransformer.transform] Processing retrievedData:", {
|
|
4052
|
+
userQuery,
|
|
4053
|
+
retrievedCount: retrievedData.length,
|
|
4054
|
+
sample: retrievedData.slice(0, 2).map((item) => {
|
|
4055
|
+
var _a2;
|
|
4056
|
+
return {
|
|
4057
|
+
id: item == null ? void 0 : item.id,
|
|
4058
|
+
contentType: typeof (item == null ? void 0 : item.content),
|
|
4059
|
+
contentSnippet: String((_a2 = item == null ? void 0 : item.content) != null ? _a2 : "").substring(0, 150),
|
|
4060
|
+
metadataKeys: Object.keys((item == null ? void 0 : item.metadata) || {})
|
|
4061
|
+
};
|
|
4062
|
+
})
|
|
4063
|
+
});
|
|
4048
4064
|
const resolvedIntent = intent != null ? intent : this.detectIntentHeuristic(userQuery);
|
|
4049
4065
|
const filteredData = resolvedIntent.filterInStockOnly ? retrievedData.filter((item) => this.determineStockStatus(item)) : retrievedData;
|
|
4050
4066
|
const profile = this.profileData(filteredData);
|
|
@@ -4534,7 +4550,10 @@ ${schemaProfileText}` : ""}`;
|
|
|
4534
4550
|
type: "radar_chart",
|
|
4535
4551
|
title: "Product Comparison",
|
|
4536
4552
|
description: `Comparing ${data.length} items across ${radarData.length} attributes`,
|
|
4537
|
-
data: radarData.length > 0 ? radarData : data.map((d) =>
|
|
4553
|
+
data: radarData.length > 0 ? radarData : data.map((d) => {
|
|
4554
|
+
var _a;
|
|
4555
|
+
return { attribute: ((_a = d == null ? void 0 : d.content) != null ? _a : "").substring(0, 40) };
|
|
4556
|
+
})
|
|
4538
4557
|
};
|
|
4539
4558
|
}
|
|
4540
4559
|
static transformToTable(data, query = "") {
|
|
@@ -4551,7 +4570,10 @@ ${schemaProfileText}` : ""}`;
|
|
|
4551
4570
|
static transformToText(data) {
|
|
4552
4571
|
return this.createTextResponse(
|
|
4553
4572
|
"Retrieved Context",
|
|
4554
|
-
data.map((item) =>
|
|
4573
|
+
data.map((item) => {
|
|
4574
|
+
var _a;
|
|
4575
|
+
return (_a = item == null ? void 0 : item.content) != null ? _a : "";
|
|
4576
|
+
}).join("\n\n"),
|
|
4555
4577
|
`Found ${data.length} relevant results`
|
|
4556
4578
|
);
|
|
4557
4579
|
}
|
|
@@ -4712,6 +4734,7 @@ ${schemaProfileText}` : ""}`;
|
|
|
4712
4734
|
return productTerms && productAction && !nonProductEntityTerms;
|
|
4713
4735
|
}
|
|
4714
4736
|
static isProductData(item) {
|
|
4737
|
+
if (!item) return false;
|
|
4715
4738
|
const content = (item.content || "").toLowerCase();
|
|
4716
4739
|
const productKeywords = [
|
|
4717
4740
|
"product",
|
|
@@ -4970,12 +4993,12 @@ ${schemaProfileText}` : ""}`;
|
|
|
4970
4993
|
}
|
|
4971
4994
|
static extractTimeSeriesData(data) {
|
|
4972
4995
|
return data.map((item) => {
|
|
4973
|
-
var _a, _b, _c, _d, _e;
|
|
4996
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4974
4997
|
const meta = item.metadata || {};
|
|
4975
4998
|
return {
|
|
4976
4999
|
timestamp: (_b = (_a = meta.timestamp) != null ? _a : meta.date) != null ? _b : (/* @__PURE__ */ new Date()).toISOString(),
|
|
4977
5000
|
value: (_d = (_c = meta.value) != null ? _c : item.score) != null ? _d : 0,
|
|
4978
|
-
label: (
|
|
5001
|
+
label: (_f = meta.label) != null ? _f : ((_e = item == null ? void 0 : item.content) != null ? _e : "").substring(0, 50)
|
|
4979
5002
|
};
|
|
4980
5003
|
});
|
|
4981
5004
|
}
|
|
@@ -5089,7 +5112,8 @@ ${schemaProfileText}` : ""}`;
|
|
|
5089
5112
|
}, query.includes(normalizedField) ? 3 : 0);
|
|
5090
5113
|
}
|
|
5091
5114
|
static resolveTableCellValue(item, column) {
|
|
5092
|
-
|
|
5115
|
+
var _a, _b, _c;
|
|
5116
|
+
if (column === "Content") return ((_a = item == null ? void 0 : item.content) != null ? _a : "").substring(0, 100);
|
|
5093
5117
|
const meta = item.metadata || {};
|
|
5094
5118
|
const normalizedColumn = this.normalizeComparableField(column);
|
|
5095
5119
|
const exactMetadata = Object.entries(meta).find(
|
|
@@ -5100,9 +5124,9 @@ ${schemaProfileText}` : ""}`;
|
|
|
5100
5124
|
}
|
|
5101
5125
|
const aliasValue = this.resolveAliasedTableCell(meta, column);
|
|
5102
5126
|
if (aliasValue !== void 0) return this.toDisplayValue(aliasValue);
|
|
5103
|
-
const contentValue = this.extractContentFieldValue(item.content, column);
|
|
5127
|
+
const contentValue = this.extractContentFieldValue((_b = item == null ? void 0 : item.content) != null ? _b : "", column);
|
|
5104
5128
|
if (contentValue !== null) return contentValue;
|
|
5105
|
-
const aliasContentValue = this.extractAliasedContentFieldValue(item.content, column);
|
|
5129
|
+
const aliasContentValue = this.extractAliasedContentFieldValue((_c = item == null ? void 0 : item.content) != null ? _c : "", column);
|
|
5106
5130
|
return aliasContentValue != null ? aliasContentValue : "";
|
|
5107
5131
|
}
|
|
5108
5132
|
static resolveAliasedTableCell(meta, column) {
|
|
@@ -5152,6 +5176,7 @@ ${schemaProfileText}` : ""}`;
|
|
|
5152
5176
|
return { inStockCount: inStock, outOfStockCount: outOfStock };
|
|
5153
5177
|
}
|
|
5154
5178
|
static determineStockStatus(item) {
|
|
5179
|
+
if (!item) return true;
|
|
5155
5180
|
const meta = item.metadata || {};
|
|
5156
5181
|
const stockValue = resolveMetadataValue(meta, "stock");
|
|
5157
5182
|
if (stockValue !== void 0) {
|
|
@@ -5197,35 +5222,64 @@ ${schemaProfileText}` : ""}`;
|
|
|
5197
5222
|
return resolveMetadataValue(meta, uiKey);
|
|
5198
5223
|
}
|
|
5199
5224
|
static extractProductInfo(item, config, trainedSchema) {
|
|
5200
|
-
var _a;
|
|
5225
|
+
var _a, _b;
|
|
5226
|
+
if (!item) return null;
|
|
5201
5227
|
const meta = item.metadata || {};
|
|
5228
|
+
const content = item.content || "";
|
|
5202
5229
|
const name = this.getDynamicVal(meta, "name", config, trainedSchema);
|
|
5203
5230
|
const price = this.getDynamicVal(meta, "price", config, trainedSchema);
|
|
5204
5231
|
const brand = this.getDynamicVal(meta, "brand", config, trainedSchema);
|
|
5205
5232
|
const description = this.cleanProductDescription(
|
|
5206
|
-
(_a = this.extractProductDescriptionFromContent(
|
|
5233
|
+
(_a = this.extractProductDescriptionFromContent(content)) != null ? _a : this.getProductDescriptionValue(meta, config, trainedSchema)
|
|
5207
5234
|
);
|
|
5208
5235
|
if (name || this.isProductData(item)) {
|
|
5209
5236
|
let finalName = name ? String(name) : void 0;
|
|
5237
|
+
if (!finalName && content) {
|
|
5238
|
+
const nameMatch = content.match(/(?:Product|Item|Name):\s*([^\n]+)/i);
|
|
5239
|
+
finalName = nameMatch ? nameMatch[1].trim() : (_b = content.split("\n")[0]) == null ? void 0 : _b.substring(0, 60);
|
|
5240
|
+
}
|
|
5210
5241
|
if (!finalName) {
|
|
5211
|
-
|
|
5212
|
-
|
|
5242
|
+
console.warn(
|
|
5243
|
+
`[UITransformer] Unable to read product name from metadata or content for item ${item.id}. Defaulting to 'Unnamed Product'.`,
|
|
5244
|
+
{ metadataKeys: Object.keys(meta), contentLength: content.length }
|
|
5245
|
+
);
|
|
5213
5246
|
}
|
|
5214
5247
|
let finalPrice = typeof price === "number" || typeof price === "string" ? price : void 0;
|
|
5215
|
-
if (!finalPrice) {
|
|
5216
|
-
const priceMatch =
|
|
5248
|
+
if (!finalPrice && content) {
|
|
5249
|
+
const priceMatch = content.match(/(?:Price|Cost):\s*\$?([\d,.]+)/i) || content.match(/\$\s*([\d,.]+)/);
|
|
5217
5250
|
if (priceMatch) finalPrice = priceMatch[1].replace(/,/g, "");
|
|
5218
5251
|
}
|
|
5252
|
+
if (finalPrice === void 0) {
|
|
5253
|
+
console.warn(
|
|
5254
|
+
`[UITransformer] Unable to read product price from metadata or content for item ${item.id}.`,
|
|
5255
|
+
{ metadataKeys: Object.keys(meta), contentSnippet: content.substring(0, 100) }
|
|
5256
|
+
);
|
|
5257
|
+
}
|
|
5219
5258
|
const imageValue = this.getDynamicVal(meta, "image", config, trainedSchema);
|
|
5259
|
+
if (!imageValue) {
|
|
5260
|
+
console.debug(
|
|
5261
|
+
`[UITransformer] Unable to read product image URL from metadata for item ${item.id}.`
|
|
5262
|
+
);
|
|
5263
|
+
}
|
|
5264
|
+
if (!description) {
|
|
5265
|
+
console.debug(
|
|
5266
|
+
`[UITransformer] Unable to read product description from metadata or content for item ${item.id}.`
|
|
5267
|
+
);
|
|
5268
|
+
}
|
|
5220
5269
|
return {
|
|
5221
5270
|
id: item.id,
|
|
5222
|
-
name: finalName,
|
|
5271
|
+
name: finalName || "Unnamed Product",
|
|
5223
5272
|
price: finalPrice,
|
|
5224
5273
|
image: typeof imageValue === "string" ? imageValue : void 0,
|
|
5225
5274
|
brand: brand ? String(brand) : void 0,
|
|
5226
5275
|
description,
|
|
5227
5276
|
inStock: this.determineStockStatus(item)
|
|
5228
5277
|
};
|
|
5278
|
+
} else {
|
|
5279
|
+
console.warn(
|
|
5280
|
+
`[UITransformer] Item ${item.id} skipped: unable to read name or identify as product data from metadata/content.`,
|
|
5281
|
+
{ metadataKeys: Object.keys(meta), contentSnippet: content.substring(0, 100) }
|
|
5282
|
+
);
|
|
5229
5283
|
}
|
|
5230
5284
|
return null;
|
|
5231
5285
|
}
|
|
@@ -5310,13 +5364,13 @@ RULES:
|
|
|
5310
5364
|
5. If no relevant data is found, return text: "I cannot answer this question based on the available information."`;
|
|
5311
5365
|
}
|
|
5312
5366
|
static buildContextSummary(sources, maxChars = 6e3) {
|
|
5313
|
-
const items = sources.map((s, i) => {
|
|
5367
|
+
const items = (sources || []).filter(Boolean).map((s, i) => {
|
|
5314
5368
|
var _a, _b, _c, _d;
|
|
5315
5369
|
return {
|
|
5316
5370
|
index: i + 1,
|
|
5317
|
-
content: (_b = (_a = s.content) == null ? void 0 : _a.substring(0, 400)) != null ? _b : "",
|
|
5318
|
-
metadata: (_c = s.metadata) != null ? _c : {},
|
|
5319
|
-
score: (_d = s.score) != null ? _d : 0
|
|
5371
|
+
content: (_b = (_a = s == null ? void 0 : s.content) == null ? void 0 : _a.substring(0, 400)) != null ? _b : "",
|
|
5372
|
+
metadata: (_c = s == null ? void 0 : s.metadata) != null ? _c : {},
|
|
5373
|
+
score: (_d = s == null ? void 0 : s.score) != null ? _d : 0
|
|
5320
5374
|
};
|
|
5321
5375
|
});
|
|
5322
5376
|
const full = JSON.stringify(items, null, 2);
|
|
@@ -5344,7 +5398,10 @@ var TextRendererStrategy = class {
|
|
|
5344
5398
|
return { type: "text", title, data: { content: data } };
|
|
5345
5399
|
}
|
|
5346
5400
|
const docs = Array.isArray(data) ? data : [];
|
|
5347
|
-
const text = docs.map((d) =>
|
|
5401
|
+
const text = docs.map((d) => {
|
|
5402
|
+
var _a;
|
|
5403
|
+
return (_a = d == null ? void 0 : d.content) != null ? _a : "";
|
|
5404
|
+
}).join("\n\n");
|
|
5348
5405
|
return { type: "text", title, data: { content: text || "No detailed content available." } };
|
|
5349
5406
|
}
|
|
5350
5407
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1752,7 +1752,7 @@ function extractProductsFromSources(sources, isUser) {
|
|
|
1752
1752
|
const hasPricePattern = /\$\s*\d+/.test(s.content);
|
|
1753
1753
|
return hasStrongProductKey || hasProductIdentity || hasPricePattern || m.type === "product";
|
|
1754
1754
|
}).map((s) => {
|
|
1755
|
-
var _a, _b;
|
|
1755
|
+
var _a, _b, _c;
|
|
1756
1756
|
const m = (_a = s.metadata) != null ? _a : {};
|
|
1757
1757
|
const name = resolveMetadataValue(m, "name");
|
|
1758
1758
|
const brand = resolveMetadataValue(m, "brand");
|
|
@@ -1760,7 +1760,7 @@ function extractProductsFromSources(sources, isUser) {
|
|
|
1760
1760
|
const description = resolveMetadataValue(m, "description");
|
|
1761
1761
|
return {
|
|
1762
1762
|
id: s.id,
|
|
1763
|
-
name: (
|
|
1763
|
+
name: (_c = name != null ? name : ((_b = s == null ? void 0 : s.content) != null ? _b : "").split("\n")[0]) != null ? _c : "Unknown Product",
|
|
1764
1764
|
brand,
|
|
1765
1765
|
price,
|
|
1766
1766
|
image: resolveImage(m),
|
|
@@ -3656,7 +3656,10 @@ var IntentClassifier = class {
|
|
|
3656
3656
|
hasCategoricalFields = catKeys.size > 0;
|
|
3657
3657
|
numericFieldCount = numericKeys.size;
|
|
3658
3658
|
categoricalFieldCount = catKeys.size;
|
|
3659
|
-
if (productKeyMatches >= 2 || docs.some((d) =>
|
|
3659
|
+
if (productKeyMatches >= 2 || docs.some((d) => {
|
|
3660
|
+
var _a, _b;
|
|
3661
|
+
return ((_a = d == null ? void 0 : d.content) != null ? _a : "").toLowerCase().includes("price") || ((_b = d == null ? void 0 : d.content) != null ? _b : "").toLowerCase().includes("brand");
|
|
3662
|
+
})) {
|
|
3660
3663
|
isProductLike = true;
|
|
3661
3664
|
}
|
|
3662
3665
|
}
|
|
@@ -4047,6 +4050,19 @@ var UITransformer = class _UITransformer {
|
|
|
4047
4050
|
if (!retrievedData || retrievedData.length === 0) {
|
|
4048
4051
|
return this.createTextResponse("No data available", "No relevant data found for your query.");
|
|
4049
4052
|
}
|
|
4053
|
+
console.log("[UITransformer.transform] Processing retrievedData:", {
|
|
4054
|
+
userQuery,
|
|
4055
|
+
retrievedCount: retrievedData.length,
|
|
4056
|
+
sample: retrievedData.slice(0, 2).map((item) => {
|
|
4057
|
+
var _a2;
|
|
4058
|
+
return {
|
|
4059
|
+
id: item == null ? void 0 : item.id,
|
|
4060
|
+
contentType: typeof (item == null ? void 0 : item.content),
|
|
4061
|
+
contentSnippet: String((_a2 = item == null ? void 0 : item.content) != null ? _a2 : "").substring(0, 150),
|
|
4062
|
+
metadataKeys: Object.keys((item == null ? void 0 : item.metadata) || {})
|
|
4063
|
+
};
|
|
4064
|
+
})
|
|
4065
|
+
});
|
|
4050
4066
|
const resolvedIntent = intent != null ? intent : this.detectIntentHeuristic(userQuery);
|
|
4051
4067
|
const filteredData = resolvedIntent.filterInStockOnly ? retrievedData.filter((item) => this.determineStockStatus(item)) : retrievedData;
|
|
4052
4068
|
const profile = this.profileData(filteredData);
|
|
@@ -4536,7 +4552,10 @@ ${schemaProfileText}` : ""}`;
|
|
|
4536
4552
|
type: "radar_chart",
|
|
4537
4553
|
title: "Product Comparison",
|
|
4538
4554
|
description: `Comparing ${data.length} items across ${radarData.length} attributes`,
|
|
4539
|
-
data: radarData.length > 0 ? radarData : data.map((d) =>
|
|
4555
|
+
data: radarData.length > 0 ? radarData : data.map((d) => {
|
|
4556
|
+
var _a;
|
|
4557
|
+
return { attribute: ((_a = d == null ? void 0 : d.content) != null ? _a : "").substring(0, 40) };
|
|
4558
|
+
})
|
|
4540
4559
|
};
|
|
4541
4560
|
}
|
|
4542
4561
|
static transformToTable(data, query = "") {
|
|
@@ -4553,7 +4572,10 @@ ${schemaProfileText}` : ""}`;
|
|
|
4553
4572
|
static transformToText(data) {
|
|
4554
4573
|
return this.createTextResponse(
|
|
4555
4574
|
"Retrieved Context",
|
|
4556
|
-
data.map((item) =>
|
|
4575
|
+
data.map((item) => {
|
|
4576
|
+
var _a;
|
|
4577
|
+
return (_a = item == null ? void 0 : item.content) != null ? _a : "";
|
|
4578
|
+
}).join("\n\n"),
|
|
4557
4579
|
`Found ${data.length} relevant results`
|
|
4558
4580
|
);
|
|
4559
4581
|
}
|
|
@@ -4714,6 +4736,7 @@ ${schemaProfileText}` : ""}`;
|
|
|
4714
4736
|
return productTerms && productAction && !nonProductEntityTerms;
|
|
4715
4737
|
}
|
|
4716
4738
|
static isProductData(item) {
|
|
4739
|
+
if (!item) return false;
|
|
4717
4740
|
const content = (item.content || "").toLowerCase();
|
|
4718
4741
|
const productKeywords = [
|
|
4719
4742
|
"product",
|
|
@@ -4972,12 +4995,12 @@ ${schemaProfileText}` : ""}`;
|
|
|
4972
4995
|
}
|
|
4973
4996
|
static extractTimeSeriesData(data) {
|
|
4974
4997
|
return data.map((item) => {
|
|
4975
|
-
var _a, _b, _c, _d, _e;
|
|
4998
|
+
var _a, _b, _c, _d, _e, _f;
|
|
4976
4999
|
const meta = item.metadata || {};
|
|
4977
5000
|
return {
|
|
4978
5001
|
timestamp: (_b = (_a = meta.timestamp) != null ? _a : meta.date) != null ? _b : (/* @__PURE__ */ new Date()).toISOString(),
|
|
4979
5002
|
value: (_d = (_c = meta.value) != null ? _c : item.score) != null ? _d : 0,
|
|
4980
|
-
label: (
|
|
5003
|
+
label: (_f = meta.label) != null ? _f : ((_e = item == null ? void 0 : item.content) != null ? _e : "").substring(0, 50)
|
|
4981
5004
|
};
|
|
4982
5005
|
});
|
|
4983
5006
|
}
|
|
@@ -5091,7 +5114,8 @@ ${schemaProfileText}` : ""}`;
|
|
|
5091
5114
|
}, query.includes(normalizedField) ? 3 : 0);
|
|
5092
5115
|
}
|
|
5093
5116
|
static resolveTableCellValue(item, column) {
|
|
5094
|
-
|
|
5117
|
+
var _a, _b, _c;
|
|
5118
|
+
if (column === "Content") return ((_a = item == null ? void 0 : item.content) != null ? _a : "").substring(0, 100);
|
|
5095
5119
|
const meta = item.metadata || {};
|
|
5096
5120
|
const normalizedColumn = this.normalizeComparableField(column);
|
|
5097
5121
|
const exactMetadata = Object.entries(meta).find(
|
|
@@ -5102,9 +5126,9 @@ ${schemaProfileText}` : ""}`;
|
|
|
5102
5126
|
}
|
|
5103
5127
|
const aliasValue = this.resolveAliasedTableCell(meta, column);
|
|
5104
5128
|
if (aliasValue !== void 0) return this.toDisplayValue(aliasValue);
|
|
5105
|
-
const contentValue = this.extractContentFieldValue(item.content, column);
|
|
5129
|
+
const contentValue = this.extractContentFieldValue((_b = item == null ? void 0 : item.content) != null ? _b : "", column);
|
|
5106
5130
|
if (contentValue !== null) return contentValue;
|
|
5107
|
-
const aliasContentValue = this.extractAliasedContentFieldValue(item.content, column);
|
|
5131
|
+
const aliasContentValue = this.extractAliasedContentFieldValue((_c = item == null ? void 0 : item.content) != null ? _c : "", column);
|
|
5108
5132
|
return aliasContentValue != null ? aliasContentValue : "";
|
|
5109
5133
|
}
|
|
5110
5134
|
static resolveAliasedTableCell(meta, column) {
|
|
@@ -5154,6 +5178,7 @@ ${schemaProfileText}` : ""}`;
|
|
|
5154
5178
|
return { inStockCount: inStock, outOfStockCount: outOfStock };
|
|
5155
5179
|
}
|
|
5156
5180
|
static determineStockStatus(item) {
|
|
5181
|
+
if (!item) return true;
|
|
5157
5182
|
const meta = item.metadata || {};
|
|
5158
5183
|
const stockValue = resolveMetadataValue(meta, "stock");
|
|
5159
5184
|
if (stockValue !== void 0) {
|
|
@@ -5199,35 +5224,64 @@ ${schemaProfileText}` : ""}`;
|
|
|
5199
5224
|
return resolveMetadataValue(meta, uiKey);
|
|
5200
5225
|
}
|
|
5201
5226
|
static extractProductInfo(item, config, trainedSchema) {
|
|
5202
|
-
var _a;
|
|
5227
|
+
var _a, _b;
|
|
5228
|
+
if (!item) return null;
|
|
5203
5229
|
const meta = item.metadata || {};
|
|
5230
|
+
const content = item.content || "";
|
|
5204
5231
|
const name = this.getDynamicVal(meta, "name", config, trainedSchema);
|
|
5205
5232
|
const price = this.getDynamicVal(meta, "price", config, trainedSchema);
|
|
5206
5233
|
const brand = this.getDynamicVal(meta, "brand", config, trainedSchema);
|
|
5207
5234
|
const description = this.cleanProductDescription(
|
|
5208
|
-
(_a = this.extractProductDescriptionFromContent(
|
|
5235
|
+
(_a = this.extractProductDescriptionFromContent(content)) != null ? _a : this.getProductDescriptionValue(meta, config, trainedSchema)
|
|
5209
5236
|
);
|
|
5210
5237
|
if (name || this.isProductData(item)) {
|
|
5211
5238
|
let finalName = name ? String(name) : void 0;
|
|
5239
|
+
if (!finalName && content) {
|
|
5240
|
+
const nameMatch = content.match(/(?:Product|Item|Name):\s*([^\n]+)/i);
|
|
5241
|
+
finalName = nameMatch ? nameMatch[1].trim() : (_b = content.split("\n")[0]) == null ? void 0 : _b.substring(0, 60);
|
|
5242
|
+
}
|
|
5212
5243
|
if (!finalName) {
|
|
5213
|
-
|
|
5214
|
-
|
|
5244
|
+
console.warn(
|
|
5245
|
+
`[UITransformer] Unable to read product name from metadata or content for item ${item.id}. Defaulting to 'Unnamed Product'.`,
|
|
5246
|
+
{ metadataKeys: Object.keys(meta), contentLength: content.length }
|
|
5247
|
+
);
|
|
5215
5248
|
}
|
|
5216
5249
|
let finalPrice = typeof price === "number" || typeof price === "string" ? price : void 0;
|
|
5217
|
-
if (!finalPrice) {
|
|
5218
|
-
const priceMatch =
|
|
5250
|
+
if (!finalPrice && content) {
|
|
5251
|
+
const priceMatch = content.match(/(?:Price|Cost):\s*\$?([\d,.]+)/i) || content.match(/\$\s*([\d,.]+)/);
|
|
5219
5252
|
if (priceMatch) finalPrice = priceMatch[1].replace(/,/g, "");
|
|
5220
5253
|
}
|
|
5254
|
+
if (finalPrice === void 0) {
|
|
5255
|
+
console.warn(
|
|
5256
|
+
`[UITransformer] Unable to read product price from metadata or content for item ${item.id}.`,
|
|
5257
|
+
{ metadataKeys: Object.keys(meta), contentSnippet: content.substring(0, 100) }
|
|
5258
|
+
);
|
|
5259
|
+
}
|
|
5221
5260
|
const imageValue = this.getDynamicVal(meta, "image", config, trainedSchema);
|
|
5261
|
+
if (!imageValue) {
|
|
5262
|
+
console.debug(
|
|
5263
|
+
`[UITransformer] Unable to read product image URL from metadata for item ${item.id}.`
|
|
5264
|
+
);
|
|
5265
|
+
}
|
|
5266
|
+
if (!description) {
|
|
5267
|
+
console.debug(
|
|
5268
|
+
`[UITransformer] Unable to read product description from metadata or content for item ${item.id}.`
|
|
5269
|
+
);
|
|
5270
|
+
}
|
|
5222
5271
|
return {
|
|
5223
5272
|
id: item.id,
|
|
5224
|
-
name: finalName,
|
|
5273
|
+
name: finalName || "Unnamed Product",
|
|
5225
5274
|
price: finalPrice,
|
|
5226
5275
|
image: typeof imageValue === "string" ? imageValue : void 0,
|
|
5227
5276
|
brand: brand ? String(brand) : void 0,
|
|
5228
5277
|
description,
|
|
5229
5278
|
inStock: this.determineStockStatus(item)
|
|
5230
5279
|
};
|
|
5280
|
+
} else {
|
|
5281
|
+
console.warn(
|
|
5282
|
+
`[UITransformer] Item ${item.id} skipped: unable to read name or identify as product data from metadata/content.`,
|
|
5283
|
+
{ metadataKeys: Object.keys(meta), contentSnippet: content.substring(0, 100) }
|
|
5284
|
+
);
|
|
5231
5285
|
}
|
|
5232
5286
|
return null;
|
|
5233
5287
|
}
|
|
@@ -5312,13 +5366,13 @@ RULES:
|
|
|
5312
5366
|
5. If no relevant data is found, return text: "I cannot answer this question based on the available information."`;
|
|
5313
5367
|
}
|
|
5314
5368
|
static buildContextSummary(sources, maxChars = 6e3) {
|
|
5315
|
-
const items = sources.map((s, i) => {
|
|
5369
|
+
const items = (sources || []).filter(Boolean).map((s, i) => {
|
|
5316
5370
|
var _a, _b, _c, _d;
|
|
5317
5371
|
return {
|
|
5318
5372
|
index: i + 1,
|
|
5319
|
-
content: (_b = (_a = s.content) == null ? void 0 : _a.substring(0, 400)) != null ? _b : "",
|
|
5320
|
-
metadata: (_c = s.metadata) != null ? _c : {},
|
|
5321
|
-
score: (_d = s.score) != null ? _d : 0
|
|
5373
|
+
content: (_b = (_a = s == null ? void 0 : s.content) == null ? void 0 : _a.substring(0, 400)) != null ? _b : "",
|
|
5374
|
+
metadata: (_c = s == null ? void 0 : s.metadata) != null ? _c : {},
|
|
5375
|
+
score: (_d = s == null ? void 0 : s.score) != null ? _d : 0
|
|
5322
5376
|
};
|
|
5323
5377
|
});
|
|
5324
5378
|
const full = JSON.stringify(items, null, 2);
|
|
@@ -5346,7 +5400,10 @@ var TextRendererStrategy = class {
|
|
|
5346
5400
|
return { type: "text", title, data: { content: data } };
|
|
5347
5401
|
}
|
|
5348
5402
|
const docs = Array.isArray(data) ? data : [];
|
|
5349
|
-
const text = docs.map((d) =>
|
|
5403
|
+
const text = docs.map((d) => {
|
|
5404
|
+
var _a;
|
|
5405
|
+
return (_a = d == null ? void 0 : d.content) != null ? _a : "";
|
|
5406
|
+
}).join("\n\n");
|
|
5350
5407
|
return { type: "text", title, data: { content: text || "No detailed content available." } };
|
|
5351
5408
|
}
|
|
5352
5409
|
};
|