brave-real-browser-mcp-server 2.14.7 → 2.14.9
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/browser-manager.js +5 -0
- package/dist/handlers/APPLY_OPTIMIZATION_PATTERN.js +2 -2
- package/dist/handlers/advanced-video-media-handlers.js +7 -7
- package/dist/handlers/ai-powered-handlers.js +0 -197
- package/dist/handlers/data-extraction-handlers.js +0 -98
- package/dist/handlers/data-processing-handlers.js +0 -275
- package/dist/handlers/data-quality-handlers.js +0 -220
- package/dist/handlers/dynamic-session-handlers.js +0 -204
- package/dist/handlers/monitoring-reporting-handlers.js +0 -170
- package/dist/handlers/multi-element-handlers.js +0 -144
- package/dist/handlers/pagination-handlers.js +0 -191
- package/dist/handlers/visual-tools-handlers.js +0 -56
- package/dist/index.js +10 -85
- package/dist/mcp-server.js +2 -11
- package/dist/optimization-utils.js +3 -3
- package/dist/tool-definitions.js +0 -313
- package/package.json +3 -12
|
@@ -2,45 +2,6 @@
|
|
|
2
2
|
// Text cleaning, validation, formatting utilities
|
|
3
3
|
// @ts-nocheck
|
|
4
4
|
import { withErrorHandling } from '../system-utils.js';
|
|
5
|
-
import { parsePhoneNumber } from 'libphonenumber-js';
|
|
6
|
-
import * as chrono from 'chrono-node';
|
|
7
|
-
import Ajv from 'ajv/dist/2020.js';
|
|
8
|
-
/**
|
|
9
|
-
* Extra whitespace और special characters remove करता है
|
|
10
|
-
*/
|
|
11
|
-
export async function handleSmartTextCleaner(args) {
|
|
12
|
-
return await withErrorHandling(async () => {
|
|
13
|
-
let text = args.text;
|
|
14
|
-
const removeExtraWhitespace = args.removeExtraWhitespace !== false;
|
|
15
|
-
const removeSpecialChars = args.removeSpecialChars || false;
|
|
16
|
-
const toLowerCase = args.toLowerCase || false;
|
|
17
|
-
const trim = args.trim !== false;
|
|
18
|
-
// Remove extra whitespace
|
|
19
|
-
if (removeExtraWhitespace) {
|
|
20
|
-
text = text.replace(/\s+/g, ' ');
|
|
21
|
-
}
|
|
22
|
-
// Remove special characters
|
|
23
|
-
if (removeSpecialChars) {
|
|
24
|
-
text = text.replace(/[^\w\s]/g, '');
|
|
25
|
-
}
|
|
26
|
-
// Convert to lowercase
|
|
27
|
-
if (toLowerCase) {
|
|
28
|
-
text = text.toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
// Trim
|
|
31
|
-
if (trim) {
|
|
32
|
-
text = text.trim();
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
content: [
|
|
36
|
-
{
|
|
37
|
-
type: 'text',
|
|
38
|
-
text: `✅ Text cleaned\n\nOriginal length: ${args.text.length}\nCleaned length: ${text.length}\n\nCleaned text:\n${text}`,
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
};
|
|
42
|
-
}, 'Failed to clean text');
|
|
43
|
-
}
|
|
44
5
|
/**
|
|
45
6
|
* HTML tags intelligently remove करता है
|
|
46
7
|
*/
|
|
@@ -85,242 +46,6 @@ export async function handleHTMLToText(args) {
|
|
|
85
46
|
};
|
|
86
47
|
}, 'Failed to convert HTML to text');
|
|
87
48
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Currency symbols और formatting से actual numbers निकालता है
|
|
90
|
-
*/
|
|
91
|
-
export async function handlePriceParser(args) {
|
|
92
|
-
return await withErrorHandling(async () => {
|
|
93
|
-
const text = args.text;
|
|
94
|
-
const currency = args.currency;
|
|
95
|
-
// Regular expressions for price patterns
|
|
96
|
-
const pricePatterns = [
|
|
97
|
-
/\$\s?(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g, // $1,234.56
|
|
98
|
-
/(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)\s?USD/gi, // 1234.56 USD
|
|
99
|
-
/€\s?(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g, // €1,234.56
|
|
100
|
-
/£\s?(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g, // £1,234.56
|
|
101
|
-
/₹\s?(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g, // ₹1,234.56
|
|
102
|
-
/(\d{1,3}(?:,\d{3})*(?:\.\d{2})?)/g, // 1,234.56
|
|
103
|
-
];
|
|
104
|
-
const prices = [];
|
|
105
|
-
pricePatterns.forEach((pattern) => {
|
|
106
|
-
let match;
|
|
107
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
108
|
-
const priceStr = match[1] || match[0];
|
|
109
|
-
const numericValue = parseFloat(priceStr.replace(/,/g, ''));
|
|
110
|
-
if (!isNaN(numericValue)) {
|
|
111
|
-
// Detect currency symbol
|
|
112
|
-
let detectedCurrency = currency || 'Unknown';
|
|
113
|
-
if (match[0].includes('$'))
|
|
114
|
-
detectedCurrency = 'USD';
|
|
115
|
-
else if (match[0].includes('€'))
|
|
116
|
-
detectedCurrency = 'EUR';
|
|
117
|
-
else if (match[0].includes('£'))
|
|
118
|
-
detectedCurrency = 'GBP';
|
|
119
|
-
else if (match[0].includes('₹'))
|
|
120
|
-
detectedCurrency = 'INR';
|
|
121
|
-
prices.push({
|
|
122
|
-
original: match[0],
|
|
123
|
-
value: numericValue,
|
|
124
|
-
currency: detectedCurrency,
|
|
125
|
-
formatted: `${detectedCurrency} ${numericValue.toFixed(2)}`,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
// Remove duplicates
|
|
131
|
-
const uniquePrices = prices.filter((price, index, self) => index === self.findIndex((p) => p.value === price.value && p.currency === price.currency));
|
|
132
|
-
return {
|
|
133
|
-
content: [
|
|
134
|
-
{
|
|
135
|
-
type: 'text',
|
|
136
|
-
text: `✅ Parsed ${uniquePrices.length} price(s)\n\n${JSON.stringify(uniquePrices, null, 2)}`,
|
|
137
|
-
},
|
|
138
|
-
],
|
|
139
|
-
};
|
|
140
|
-
}, 'Failed to parse prices');
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Different date formats को standard format में convert करता है
|
|
144
|
-
*/
|
|
145
|
-
export async function handleDateNormalizer(args) {
|
|
146
|
-
return await withErrorHandling(async () => {
|
|
147
|
-
const text = args.text;
|
|
148
|
-
const outputFormat = args.outputFormat || 'iso';
|
|
149
|
-
// Parse dates using chrono-node
|
|
150
|
-
const parsedDates = chrono.parse(text);
|
|
151
|
-
const dates = [];
|
|
152
|
-
parsedDates.forEach((parsed) => {
|
|
153
|
-
const date = parsed.start.date();
|
|
154
|
-
let formatted;
|
|
155
|
-
if (outputFormat === 'iso') {
|
|
156
|
-
formatted = date.toISOString();
|
|
157
|
-
}
|
|
158
|
-
else if (outputFormat === 'locale') {
|
|
159
|
-
formatted = date.toLocaleString();
|
|
160
|
-
}
|
|
161
|
-
else if (outputFormat === 'unix') {
|
|
162
|
-
formatted = Math.floor(date.getTime() / 1000);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
formatted = date.toISOString();
|
|
166
|
-
}
|
|
167
|
-
dates.push({
|
|
168
|
-
original: parsed.text,
|
|
169
|
-
parsed: formatted,
|
|
170
|
-
components: {
|
|
171
|
-
year: date.getFullYear(),
|
|
172
|
-
month: date.getMonth() + 1,
|
|
173
|
-
day: date.getDate(),
|
|
174
|
-
hour: date.getHours(),
|
|
175
|
-
minute: date.getMinutes(),
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
content: [
|
|
181
|
-
{
|
|
182
|
-
type: 'text',
|
|
183
|
-
text: `✅ Normalized ${dates.length} date(s)\n\n${JSON.stringify(dates, null, 2)}`,
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
};
|
|
187
|
-
}, 'Failed to normalize dates');
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Contact information automatically detect करता है
|
|
191
|
-
*/
|
|
192
|
-
export async function handleContactExtractor(args) {
|
|
193
|
-
return await withErrorHandling(async () => {
|
|
194
|
-
const text = args.text;
|
|
195
|
-
const types = args.types || ['phone', 'email'];
|
|
196
|
-
const defaultCountry = args.defaultCountry || 'US';
|
|
197
|
-
const results = {
|
|
198
|
-
phones: [],
|
|
199
|
-
emails: [],
|
|
200
|
-
};
|
|
201
|
-
// Extract emails
|
|
202
|
-
if (types.includes('email')) {
|
|
203
|
-
const emailPattern = /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/g;
|
|
204
|
-
const emails = text.match(emailPattern) || [];
|
|
205
|
-
results.emails = [...new Set(emails)].map((email) => ({
|
|
206
|
-
value: email,
|
|
207
|
-
domain: email.split('@')[1],
|
|
208
|
-
username: email.split('@')[0],
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
// Extract phone numbers
|
|
212
|
-
if (types.includes('phone')) {
|
|
213
|
-
// Common phone patterns
|
|
214
|
-
const phonePatterns = [
|
|
215
|
-
/\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9}/g,
|
|
216
|
-
/\(\d{3}\)\s?\d{3}-?\d{4}/g,
|
|
217
|
-
/\d{3}[-.\s]?\d{3}[-.\s]?\d{4}/g,
|
|
218
|
-
];
|
|
219
|
-
const potentialPhones = [];
|
|
220
|
-
phonePatterns.forEach((pattern) => {
|
|
221
|
-
const matches = text.match(pattern) || [];
|
|
222
|
-
potentialPhones.push(...matches);
|
|
223
|
-
});
|
|
224
|
-
// Parse and validate phone numbers
|
|
225
|
-
potentialPhones.forEach((phone) => {
|
|
226
|
-
try {
|
|
227
|
-
const parsed = parsePhoneNumber(phone, defaultCountry);
|
|
228
|
-
if (parsed && parsed.isValid()) {
|
|
229
|
-
results.phones.push({
|
|
230
|
-
original: phone,
|
|
231
|
-
international: parsed.formatInternational(),
|
|
232
|
-
national: parsed.formatNational(),
|
|
233
|
-
country: parsed.country,
|
|
234
|
-
type: parsed.getType(),
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
catch (e) {
|
|
239
|
-
// Invalid phone number, skip
|
|
240
|
-
results.phones.push({
|
|
241
|
-
original: phone,
|
|
242
|
-
valid: false,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
return {
|
|
248
|
-
content: [
|
|
249
|
-
{
|
|
250
|
-
type: 'text',
|
|
251
|
-
text: `✅ Extracted contact info\n\nEmails: ${results.emails.length}\nPhones: ${results.phones.length}\n\n${JSON.stringify(results, null, 2)}`,
|
|
252
|
-
},
|
|
253
|
-
],
|
|
254
|
-
};
|
|
255
|
-
}, 'Failed to extract contact info');
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Extracted data की structure verify करता है
|
|
259
|
-
*/
|
|
260
|
-
export async function handleSchemaValidator(args) {
|
|
261
|
-
return await withErrorHandling(async () => {
|
|
262
|
-
const data = args.data;
|
|
263
|
-
const schema = args.schema;
|
|
264
|
-
const ajv = new Ajv({ allErrors: true });
|
|
265
|
-
const validate = ajv.compile(schema);
|
|
266
|
-
const valid = validate(data);
|
|
267
|
-
if (valid) {
|
|
268
|
-
return {
|
|
269
|
-
content: [
|
|
270
|
-
{
|
|
271
|
-
type: 'text',
|
|
272
|
-
text: '✅ Data validation passed\n\nAll fields match the schema.',
|
|
273
|
-
},
|
|
274
|
-
],
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
const errors = validate.errors?.map((err) => ({
|
|
279
|
-
field: err.instancePath,
|
|
280
|
-
message: err.message,
|
|
281
|
-
params: err.params,
|
|
282
|
-
}));
|
|
283
|
-
return {
|
|
284
|
-
content: [
|
|
285
|
-
{
|
|
286
|
-
type: 'text',
|
|
287
|
-
text: `❌ Data validation failed\n\n${JSON.stringify(errors, null, 2)}`,
|
|
288
|
-
},
|
|
289
|
-
],
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
}, 'Failed to validate schema');
|
|
293
|
-
}
|
|
294
|
-
/**
|
|
295
|
-
* Missing data detect करता है
|
|
296
|
-
*/
|
|
297
|
-
export async function handleRequiredFieldsChecker(args) {
|
|
298
|
-
return await withErrorHandling(async () => {
|
|
299
|
-
const data = args.data;
|
|
300
|
-
const requiredFields = args.requiredFields;
|
|
301
|
-
const missing = [];
|
|
302
|
-
const present = [];
|
|
303
|
-
requiredFields.forEach((field) => {
|
|
304
|
-
// Support nested fields with dot notation
|
|
305
|
-
const value = field.split('.').reduce((obj, key) => obj?.[key], data);
|
|
306
|
-
if (value === undefined || value === null || value === '') {
|
|
307
|
-
missing.push(field);
|
|
308
|
-
}
|
|
309
|
-
else {
|
|
310
|
-
present.push(field);
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
const isValid = missing.length === 0;
|
|
314
|
-
return {
|
|
315
|
-
content: [
|
|
316
|
-
{
|
|
317
|
-
type: 'text',
|
|
318
|
-
text: `${isValid ? '✅' : '❌'} Required fields check\n\nPresent: ${present.length}/${requiredFields.length}\nMissing: ${missing.join(', ') || 'None'}\n\n${isValid ? 'All required fields are present!' : 'Some required fields are missing.'}`,
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
};
|
|
322
|
-
}, 'Failed to check required fields');
|
|
323
|
-
}
|
|
324
49
|
/**
|
|
325
50
|
* Repeated data filter करता है
|
|
326
51
|
*/
|
|
@@ -74,94 +74,6 @@ export async function handleDataDeduplication(args) {
|
|
|
74
74
|
/**
|
|
75
75
|
* Missing Data Handler - Detect and handle missing data
|
|
76
76
|
*/
|
|
77
|
-
export async function handleMissingDataHandler(args) {
|
|
78
|
-
const { data, requiredFields, strategy = 'report' } = args;
|
|
79
|
-
try {
|
|
80
|
-
if (!Array.isArray(data)) {
|
|
81
|
-
throw new Error('Data must be an array');
|
|
82
|
-
}
|
|
83
|
-
const results = [];
|
|
84
|
-
const missingReport = {};
|
|
85
|
-
let totalMissing = 0;
|
|
86
|
-
data.forEach((item, index) => {
|
|
87
|
-
const itemMissing = {};
|
|
88
|
-
let hasMissing = false;
|
|
89
|
-
if (requiredFields && Array.isArray(requiredFields)) {
|
|
90
|
-
requiredFields.forEach(field => {
|
|
91
|
-
const value = item[field];
|
|
92
|
-
if (value === undefined || value === null || value === '') {
|
|
93
|
-
itemMissing[field] = true;
|
|
94
|
-
hasMissing = true;
|
|
95
|
-
totalMissing++;
|
|
96
|
-
if (!missingReport[field]) {
|
|
97
|
-
missingReport[field] = { count: 0, indices: [] };
|
|
98
|
-
}
|
|
99
|
-
missingReport[field].count++;
|
|
100
|
-
missingReport[field].indices.push(index);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
// Handle missing data based on strategy
|
|
105
|
-
let processedItem = { ...item };
|
|
106
|
-
switch (strategy) {
|
|
107
|
-
case 'remove':
|
|
108
|
-
if (!hasMissing)
|
|
109
|
-
results.push(processedItem);
|
|
110
|
-
break;
|
|
111
|
-
case 'fill':
|
|
112
|
-
Object.keys(itemMissing).forEach(field => {
|
|
113
|
-
if (typeof item[field] === 'number') {
|
|
114
|
-
processedItem[field] = 0;
|
|
115
|
-
}
|
|
116
|
-
else if (typeof item[field] === 'string') {
|
|
117
|
-
processedItem[field] = 'N/A';
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
processedItem[field] = null;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
results.push(processedItem);
|
|
124
|
-
break;
|
|
125
|
-
case 'flag':
|
|
126
|
-
processedItem._hasMissingData = hasMissing;
|
|
127
|
-
processedItem._missingFields = Object.keys(itemMissing);
|
|
128
|
-
results.push(processedItem);
|
|
129
|
-
break;
|
|
130
|
-
case 'report':
|
|
131
|
-
default:
|
|
132
|
-
results.push(processedItem);
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
const itemsWithMissing = Object.values(missingReport).length > 0 ?
|
|
137
|
-
[...new Set(Object.values(missingReport).flatMap((r) => r.indices))].length : 0;
|
|
138
|
-
const missingRate = ((totalMissing / (data.length * (requiredFields?.length || 1))) * 100).toFixed(2);
|
|
139
|
-
let summary = `Missing Data Analysis:\n\nStatistics:\n- Total Items: ${data.length}\n- Items with Missing Data: ${itemsWithMissing}\n- Total Missing Fields: ${totalMissing}\n- Missing Rate: ${missingRate}%\n- Strategy: ${strategy}`;
|
|
140
|
-
if (Object.keys(missingReport).length > 0) {
|
|
141
|
-
summary += `\n\nMissing Fields Report:\n${Object.entries(missingReport).map(([field, info]) => `- ${field}: ${info.count} occurrences (indices: ${info.indices.slice(0, 5).join(', ')}${info.indices.length > 5 ? '...' : ''})`).join('\n')}`;
|
|
142
|
-
}
|
|
143
|
-
summary += `\n\nProcessed Items: ${results.length}`;
|
|
144
|
-
return {
|
|
145
|
-
content: [
|
|
146
|
-
{
|
|
147
|
-
type: "text",
|
|
148
|
-
text: summary
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
return {
|
|
155
|
-
content: [
|
|
156
|
-
{
|
|
157
|
-
type: "text",
|
|
158
|
-
text: `Missing Data Handler Error: ${error.message}`
|
|
159
|
-
}
|
|
160
|
-
],
|
|
161
|
-
isError: true
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
77
|
/**
|
|
166
78
|
* Data Type Validator - Validate data types against schema
|
|
167
79
|
*/
|
|
@@ -343,135 +255,3 @@ export async function handleOutlierDetection(args) {
|
|
|
343
255
|
/**
|
|
344
256
|
* Consistency Checker - Check data consistency across fields
|
|
345
257
|
*/
|
|
346
|
-
export async function handleConsistencyChecker(args) {
|
|
347
|
-
const { data, rules } = args;
|
|
348
|
-
try {
|
|
349
|
-
if (!Array.isArray(data)) {
|
|
350
|
-
throw new Error('Data must be an array');
|
|
351
|
-
}
|
|
352
|
-
if (!rules || !Array.isArray(rules)) {
|
|
353
|
-
throw new Error('Rules must be provided as an array');
|
|
354
|
-
}
|
|
355
|
-
const violations = [];
|
|
356
|
-
const ruleResults = {};
|
|
357
|
-
rules.forEach(rule => {
|
|
358
|
-
ruleResults[rule.name] = { passed: 0, failed: 0, violations: [] };
|
|
359
|
-
});
|
|
360
|
-
data.forEach((item, index) => {
|
|
361
|
-
rules.forEach(rule => {
|
|
362
|
-
let passed = true;
|
|
363
|
-
let reason = '';
|
|
364
|
-
try {
|
|
365
|
-
switch (rule.type) {
|
|
366
|
-
case 'required':
|
|
367
|
-
if (item[rule.field] === undefined || item[rule.field] === null || item[rule.field] === '') {
|
|
368
|
-
passed = false;
|
|
369
|
-
reason = `Field '${rule.field}' is required but missing`;
|
|
370
|
-
}
|
|
371
|
-
break;
|
|
372
|
-
case 'range':
|
|
373
|
-
const value = parseFloat(item[rule.field]);
|
|
374
|
-
if (isNaN(value) || value < rule.min || value > rule.max) {
|
|
375
|
-
passed = false;
|
|
376
|
-
reason = `Field '${rule.field}' value ${value} is outside range [${rule.min}, ${rule.max}]`;
|
|
377
|
-
}
|
|
378
|
-
break;
|
|
379
|
-
case 'pattern':
|
|
380
|
-
const regex = new RegExp(rule.pattern);
|
|
381
|
-
if (!regex.test(String(item[rule.field]))) {
|
|
382
|
-
passed = false;
|
|
383
|
-
reason = `Field '${rule.field}' does not match pattern ${rule.pattern}`;
|
|
384
|
-
}
|
|
385
|
-
break;
|
|
386
|
-
case 'dependency':
|
|
387
|
-
if (item[rule.field] && !item[rule.dependsOn]) {
|
|
388
|
-
passed = false;
|
|
389
|
-
reason = `Field '${rule.field}' requires '${rule.dependsOn}' to be present`;
|
|
390
|
-
}
|
|
391
|
-
break;
|
|
392
|
-
case 'unique':
|
|
393
|
-
// Check uniqueness within dataset
|
|
394
|
-
const duplicates = data.filter(d => d[rule.field] === item[rule.field]);
|
|
395
|
-
if (duplicates.length > 1) {
|
|
396
|
-
passed = false;
|
|
397
|
-
reason = `Field '${rule.field}' value '${item[rule.field]}' is not unique`;
|
|
398
|
-
}
|
|
399
|
-
break;
|
|
400
|
-
case 'comparison':
|
|
401
|
-
const val1 = parseFloat(item[rule.field1]);
|
|
402
|
-
const val2 = parseFloat(item[rule.field2]);
|
|
403
|
-
let comparisonPassed = false;
|
|
404
|
-
switch (rule.operator) {
|
|
405
|
-
case '>':
|
|
406
|
-
comparisonPassed = val1 > val2;
|
|
407
|
-
break;
|
|
408
|
-
case '<':
|
|
409
|
-
comparisonPassed = val1 < val2;
|
|
410
|
-
break;
|
|
411
|
-
case '>=':
|
|
412
|
-
comparisonPassed = val1 >= val2;
|
|
413
|
-
break;
|
|
414
|
-
case '<=':
|
|
415
|
-
comparisonPassed = val1 <= val2;
|
|
416
|
-
break;
|
|
417
|
-
case '==':
|
|
418
|
-
comparisonPassed = val1 === val2;
|
|
419
|
-
break;
|
|
420
|
-
case '!=':
|
|
421
|
-
comparisonPassed = val1 !== val2;
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
if (!comparisonPassed) {
|
|
425
|
-
passed = false;
|
|
426
|
-
reason = `Comparison failed: ${rule.field1} (${val1}) ${rule.operator} ${rule.field2} (${val2})`;
|
|
427
|
-
}
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
catch (err) {
|
|
432
|
-
passed = false;
|
|
433
|
-
reason = `Error checking rule: ${err.message}`;
|
|
434
|
-
}
|
|
435
|
-
if (passed) {
|
|
436
|
-
ruleResults[rule.name].passed++;
|
|
437
|
-
}
|
|
438
|
-
else {
|
|
439
|
-
ruleResults[rule.name].failed++;
|
|
440
|
-
const violation = {
|
|
441
|
-
index,
|
|
442
|
-
item,
|
|
443
|
-
rule: rule.name,
|
|
444
|
-
reason
|
|
445
|
-
};
|
|
446
|
-
ruleResults[rule.name].violations.push(violation);
|
|
447
|
-
violations.push(violation);
|
|
448
|
-
}
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
const consistencyRate = (((data.length - violations.length) / data.length) * 100).toFixed(2);
|
|
452
|
-
let summary = `Consistency Check Results:\n\nSummary:\n- Total Items: ${data.length}\n- Rules Checked: ${rules.length}\n- Total Violations: ${violations.length}\n- Consistency Rate: ${consistencyRate}%`;
|
|
453
|
-
summary += `\n\nRule Results:\n${Object.entries(ruleResults).map(([name, result]) => `- ${name}: ${result.passed} passed, ${result.failed} failed`).join('\n')}`;
|
|
454
|
-
if (violations.length > 0) {
|
|
455
|
-
summary += `\n\nViolations (Top 10):\n${violations.slice(0, 10).map((v, i) => `${i + 1}. Index ${v.index} - Rule: ${v.rule}\n Reason: ${v.reason}`).join('\n')}`;
|
|
456
|
-
}
|
|
457
|
-
return {
|
|
458
|
-
content: [
|
|
459
|
-
{
|
|
460
|
-
type: "text",
|
|
461
|
-
text: summary
|
|
462
|
-
}
|
|
463
|
-
]
|
|
464
|
-
};
|
|
465
|
-
}
|
|
466
|
-
catch (error) {
|
|
467
|
-
return {
|
|
468
|
-
content: [
|
|
469
|
-
{
|
|
470
|
-
type: "text",
|
|
471
|
-
text: `Consistency Checker Error: ${error.message}`
|
|
472
|
-
}
|
|
473
|
-
],
|
|
474
|
-
isError: true
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
}
|