iwgt 2.4.7 → 2.4.10

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.
@@ -1038,7 +1038,30 @@ export function generateWidgetFiles(config) {
1038
1038
  files['settings_form.json'] = settingsForm.form;
1039
1039
  files['settings_form'] = { settingsCount: settingsForm.count }; // метаинформация
1040
1040
  // snippet.liquid
1041
- files['snippet.liquid'] = generateSnippetLiquid(config);
1041
+ const liquidCode = generateSnippetLiquid(config);
1042
+ // Валидируем Liquid код на несуществующие фильтры
1043
+ const validation = validateLiquidFilters(liquidCode);
1044
+ if (!validation.isValid) {
1045
+ console.warn('⚠️ Обнаружены несуществующие фильтры в Liquid коде:');
1046
+ validation.errors.forEach(error => {
1047
+ console.warn(` - Строка ${error.line}: фильтр '${error.filter}' - ${error.suggestion}`);
1048
+ });
1049
+ // Автоматически исправляем несуществующие фильтры
1050
+ const fixed = fixInvalidFilters(liquidCode);
1051
+ if (fixed.fixes.length > 0) {
1052
+ console.log('✅ Автоматически исправлены несуществующие фильтры:');
1053
+ fixed.fixes.forEach(fix => {
1054
+ console.log(` - Строка ${fix.line}: ${fix.suggestion}`);
1055
+ });
1056
+ files['snippet.liquid'] = fixed.fixedCode;
1057
+ }
1058
+ else {
1059
+ files['snippet.liquid'] = liquidCode;
1060
+ }
1061
+ }
1062
+ else {
1063
+ files['snippet.liquid'] = liquidCode;
1064
+ }
1042
1065
  // snippet.scss
1043
1066
  files['snippet.scss'] = generateSnippetScss(config);
1044
1067
  // snippet.js
@@ -1049,4 +1072,71 @@ export function generateWidgetFiles(config) {
1049
1072
  }
1050
1073
  return files;
1051
1074
  }
1075
+ /**
1076
+ * Валидирует Liquid код на наличие несуществующих фильтров
1077
+ */
1078
+ export function validateLiquidFilters(liquidCode) {
1079
+ const invalidFiltersList = [
1080
+ { name: 't', suggestion: 'Используйте messages или widget_messages для переводов' },
1081
+ { name: 'translate', suggestion: 'Используйте messages для переводов' },
1082
+ { name: 'i18n', suggestion: 'Используйте messages для переводов' },
1083
+ { name: 'l', suggestion: 'Используйте messages для переводов' },
1084
+ { name: 'localize', suggestion: 'Используйте messages для переводов' },
1085
+ { name: 'tr', suggestion: 'Используйте messages для переводов' }
1086
+ ];
1087
+ const errors = [];
1088
+ const lines = liquidCode.split('\n');
1089
+ lines.forEach((line, lineIndex) => {
1090
+ invalidFiltersList.forEach(invalidFilter => {
1091
+ // Ищем паттерн | filter_name
1092
+ const regex = new RegExp(`\\|\\s*${invalidFilter.name}\\b`, 'g');
1093
+ let match;
1094
+ while ((match = regex.exec(line)) !== null) {
1095
+ errors.push({
1096
+ filter: invalidFilter.name,
1097
+ line: lineIndex + 1,
1098
+ column: match.index + 1,
1099
+ suggestion: invalidFilter.suggestion
1100
+ });
1101
+ }
1102
+ });
1103
+ });
1104
+ return {
1105
+ isValid: errors.length === 0,
1106
+ errors
1107
+ };
1108
+ }
1109
+ /**
1110
+ * Проверяет и исправляет несуществующие фильтры в Liquid коде
1111
+ */
1112
+ export function fixInvalidFilters(liquidCode) {
1113
+ const fixes = [];
1114
+ let fixedCode = liquidCode;
1115
+ // Исправляем фильтр 't' на messages
1116
+ const tRegex = /\|\s*t\b/g;
1117
+ let match;
1118
+ while ((match = tRegex.exec(fixedCode)) !== null) {
1119
+ const beforeMatch = fixedCode.substring(0, match.index);
1120
+ const afterMatch = fixedCode.substring(match.index + match[0].length);
1121
+ // Определяем, что это за контекст
1122
+ const contextBefore = beforeMatch.substring(Math.max(0, beforeMatch.length - 50));
1123
+ if (contextBefore.includes('widget_messages')) {
1124
+ // Если это в контексте widget_messages, оставляем как есть
1125
+ continue;
1126
+ }
1127
+ else {
1128
+ // Заменяем на messages
1129
+ fixedCode = beforeMatch + '| messages' + afterMatch;
1130
+ fixes.push({
1131
+ filter: 't',
1132
+ line: fixedCode.substring(0, match.index).split('\n').length,
1133
+ suggestion: 'Заменен на messages'
1134
+ });
1135
+ }
1136
+ }
1137
+ return {
1138
+ fixedCode,
1139
+ fixes
1140
+ };
1141
+ }
1052
1142
  //# sourceMappingURL=index.js.map
@@ -57,7 +57,7 @@ const httpServer = createServer(async (req, res) => {
57
57
  res.end(JSON.stringify({
58
58
  status: 'ok',
59
59
  service: 'InSales Widgets MCP Server',
60
- version: '2.4.7',
60
+ version: '2.4.10',
61
61
  transport: 'SSE',
62
62
  endpoints: {
63
63
  sse: '/sse',
package/dist/server.js CHANGED
@@ -16,6 +16,7 @@ import liquidVariables from './data/references/liquid-variables.json' with { typ
16
16
  import liquidFilters from './data/references/liquid-filters.json' with { type: 'json' };
17
17
  import commonjsReference from './data/references/commonjs-reference.json' with { type: 'json' };
18
18
  import collectionsMenuPatterns from './data/references/collections-menu-patterns.json' with { type: 'json' };
19
+ import librariesApiReference from './data/references/libraries-api-reference.json' with { type: 'json' };
19
20
  // Импорт модулей
20
21
  import { generateWidgetFiles } from './generators/index.js';
21
22
  import * as tools from './tools/index.js';
@@ -25,7 +26,7 @@ export class WidgetServer {
25
26
  constructor() {
26
27
  this.server = new Server({
27
28
  name: 'insales-widgets',
28
- version: '2.4.7',
29
+ version: '2.4.10',
29
30
  }, {
30
31
  capabilities: {
31
32
  tools: {},
@@ -216,6 +217,40 @@ export class WidgetServer {
216
217
  },
217
218
  },
218
219
  },
220
+ {
221
+ name: 'get_libraries_api',
222
+ description: 'Получить подробную API документацию библиотек, доступных в виджетах InSales. Включает опции, методы, примеры кода, best practices. Доступны: InsalesCutList (cut-list) - jQuery плагин для сворачивания списков, и другие библиотеки.',
223
+ inputSchema: {
224
+ type: 'object',
225
+ properties: {
226
+ library: {
227
+ type: 'string',
228
+ description: 'Handle или название библиотеки для получения полной API документации (например: "cut-list", "InsalesCutList")',
229
+ },
230
+ search: {
231
+ type: 'string',
232
+ description: 'Поиск по опциям, методам, примерам библиотек',
233
+ },
234
+ category: {
235
+ type: 'string',
236
+ description: 'Фильтр по категории виджетов (headers, navigation, и т.д.)',
237
+ },
238
+ },
239
+ },
240
+ },
241
+ {
242
+ name: 'get_insales_permanent_links',
243
+ description: 'Получить постоянные ссылки InSales для основных разделов сайта (корзина, избранное, сравнение, личный кабинет). Используйте эти ссылки вместо выдуманных типа pages.favorite.url',
244
+ inputSchema: {
245
+ type: 'object',
246
+ properties: {
247
+ search: {
248
+ type: 'string',
249
+ description: 'Поиск ссылок по названию или описанию',
250
+ },
251
+ },
252
+ },
253
+ },
219
254
  ],
220
255
  }));
221
256
  // Список ресурсов
@@ -281,6 +316,12 @@ export class WidgetServer {
281
316
  mimeType: 'text/markdown',
282
317
  description: 'КРИТИЧЕСКИ ВАЖНО: Системная обёртка виджетов, контекст выполнения, data.blocks, запрещённые практики',
283
318
  },
319
+ {
320
+ uri: 'insales://libraries-api',
321
+ name: 'API библиотек',
322
+ mimeType: 'application/json',
323
+ description: 'Подробная API документация библиотек: InsalesCutList и другие',
324
+ },
284
325
  ],
285
326
  }));
286
327
  // Чтение ресурсов
@@ -391,6 +432,16 @@ export class WidgetServer {
391
432
  ],
392
433
  };
393
434
  }
435
+ case 'insales://libraries-api':
436
+ return {
437
+ contents: [
438
+ {
439
+ uri,
440
+ mimeType: 'application/json',
441
+ text: JSON.stringify(librariesApiReference, null, 2),
442
+ },
443
+ ],
444
+ };
394
445
  default:
395
446
  throw new Error(`Unknown resource: ${uri}`);
396
447
  }
@@ -474,6 +525,24 @@ export class WidgetServer {
474
525
  },
475
526
  ],
476
527
  };
528
+ case 'get_libraries_api':
529
+ return {
530
+ content: [
531
+ {
532
+ type: 'text',
533
+ text: JSON.stringify(tools.getLibrariesAPI(args || {}), null, 2),
534
+ },
535
+ ],
536
+ };
537
+ case 'get_insales_permanent_links':
538
+ return {
539
+ content: [
540
+ {
541
+ type: 'text',
542
+ text: JSON.stringify(tools.getInsalesPermanentLinks(args || {}), null, 2),
543
+ },
544
+ ],
545
+ };
477
546
  default:
478
547
  throw new Error(`Unknown tool: ${name}`);
479
548
  }
@@ -14,15 +14,11 @@ export declare function getAvailableIcons(args?: any): any;
14
14
  /**
15
15
  * Получить информацию о категории виджетов
16
16
  */
17
- export declare function getCategoryInfo(args: any): any;
17
+ export declare function getCategoryInfo(args?: any): any;
18
18
  /**
19
19
  * Получить информацию о библиотеках
20
20
  */
21
21
  export declare function getLibrariesInfo(args?: any): any;
22
- /**
23
- * Получить справочник Liquid переменных
24
- */
25
- export declare function getLiquidVariables(args?: any): any;
26
22
  /**
27
23
  * Получить справочник Liquid фильтров
28
24
  */
@@ -35,4 +31,16 @@ export declare function getCommonJSAPI(args?: any): any;
35
31
  * Получить паттерны меню категорий
36
32
  */
37
33
  export declare function getCollectionsMenuPatterns(args?: any): any;
34
+ /**
35
+ * Получить API библиотек
36
+ */
37
+ export declare function getLibrariesAPI(args?: any): any;
38
+ /**
39
+ * Получить справочник Liquid переменных
40
+ */
41
+ export declare function getLiquidVariables(args?: any): any;
42
+ /**
43
+ * Получить постоянные ссылки InSales
44
+ */
45
+ export declare function getInsalesPermanentLinks(args?: any): any;
38
46
  //# sourceMappingURL=index.d.ts.map