snow-flow 3.0.23 → 3.0.24

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.
@@ -38,11 +38,36 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  })();
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.ServiceNowMachineLearningMCP = void 0;
41
- // CRITICAL FIX: Add performance polyfill for TensorFlow.js in Node.js environment
41
+ // CRITICAL FIX: Add comprehensive performance polyfill for TensorFlow.js in Node.js environment
42
42
  // This fixes the "Cannot read properties of undefined (reading 'tick')" error
43
- if (typeof global !== 'undefined' && !global.performance) {
44
- const { performance } = require('perf_hooks');
45
- global.performance = performance;
43
+ if (typeof global !== 'undefined') {
44
+ // Import perf_hooks
45
+ const { performance: perfHooksPerformance } = require('perf_hooks');
46
+ // Create comprehensive performance object with type casting
47
+ if (!global.performance || !global.performance.now) {
48
+ global.performance = {
49
+ now: perfHooksPerformance.now.bind(perfHooksPerformance),
50
+ mark: perfHooksPerformance.mark ? perfHooksPerformance.mark.bind(perfHooksPerformance) : () => { },
51
+ measure: perfHooksPerformance.measure ? perfHooksPerformance.measure.bind(perfHooksPerformance) : () => { },
52
+ getEntriesByName: perfHooksPerformance.getEntriesByName ? perfHooksPerformance.getEntriesByName.bind(perfHooksPerformance) : () => [],
53
+ getEntriesByType: perfHooksPerformance.getEntriesByType ? perfHooksPerformance.getEntriesByType.bind(perfHooksPerformance) : () => [],
54
+ clearMarks: perfHooksPerformance.clearMarks ? perfHooksPerformance.clearMarks.bind(perfHooksPerformance) : () => { },
55
+ clearMeasures: perfHooksPerformance.clearMeasures ? perfHooksPerformance.clearMeasures.bind(perfHooksPerformance) : () => { },
56
+ // Add tick method that TensorFlow.js might be looking for
57
+ tick: perfHooksPerformance.now ? perfHooksPerformance.now.bind(perfHooksPerformance) : () => Date.now(),
58
+ timeOrigin: perfHooksPerformance.timeOrigin || Date.now()
59
+ };
60
+ }
61
+ // Additional Node.js specific fixes for TensorFlow.js
62
+ if (typeof global.window === 'undefined') {
63
+ // Mock minimal window object for TensorFlow.js
64
+ global.window = global;
65
+ }
66
+ // Ensure process.hrtime is available for high-resolution timing
67
+ if (!global.process || !global.process.hrtime) {
68
+ global.process = global.process || {};
69
+ global.process.hrtime = process.hrtime;
70
+ }
46
71
  }
47
72
  const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
48
73
  const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
@@ -737,60 +762,161 @@ class ServiceNowMachineLearningMCP {
737
762
  }
738
763
  this.logger.info(`Creating model with vocabulary size: ${vocabularySize}, categories: ${categories.length}`);
739
764
  // Create neural network model with VALIDATED vocabulary size
740
- const model = tf.sequential({
741
- layers: [
742
- // Embedding layer for text - inputDim MUST match the vocabulary size used in data preparation
743
- tf.layers.embedding({
744
- inputDim: vocabularySize, // Use the EXACT vocabulary size from data preparation
745
- outputDim: 128,
746
- inputLength: 100 // Max sequence length
747
- }),
748
- // LSTM for sequence processing
749
- tf.layers.lstm({
750
- units: 64,
751
- returnSequences: false,
752
- dropout: 0.2,
753
- recurrentDropout: 0.2
754
- }),
755
- // Dense layers
756
- tf.layers.dense({
757
- units: 32,
758
- activation: 'relu'
759
- }),
760
- tf.layers.dropout({ rate: 0.3 }),
761
- // Output layer
762
- tf.layers.dense({
763
- units: categories.length,
764
- activation: 'softmax'
765
- })
766
- ]
767
- });
765
+ let model;
766
+ try {
767
+ this.logger.info('Creating TensorFlow.js model...');
768
+ // Additional validation before model creation
769
+ if (typeof tf === 'undefined' || !tf.sequential) {
770
+ throw new Error('TensorFlow.js not properly loaded');
771
+ }
772
+ if (!global.performance || typeof global.performance.tick !== 'function') {
773
+ throw new Error('Performance API not available - TensorFlow.js requires timing functions');
774
+ }
775
+ model = tf.sequential({
776
+ layers: [
777
+ // Embedding layer for text - inputDim MUST match the vocabulary size used in data preparation
778
+ tf.layers.embedding({
779
+ inputDim: vocabularySize, // Use the EXACT vocabulary size from data preparation
780
+ outputDim: 128,
781
+ inputLength: 100 // Max sequence length
782
+ }),
783
+ // LSTM for sequence processing
784
+ tf.layers.lstm({
785
+ units: 64,
786
+ returnSequences: false,
787
+ dropout: 0.2,
788
+ recurrentDropout: 0.2
789
+ }),
790
+ // Dense layers
791
+ tf.layers.dense({
792
+ units: 32,
793
+ activation: 'relu'
794
+ }),
795
+ tf.layers.dropout({ rate: 0.3 }),
796
+ // Output layer
797
+ tf.layers.dense({
798
+ units: categories.length,
799
+ activation: 'softmax'
800
+ })
801
+ ]
802
+ });
803
+ this.logger.info('✅ Model created successfully');
804
+ }
805
+ catch (modelError) {
806
+ this.logger.error('Failed to create TensorFlow.js model:', modelError);
807
+ return {
808
+ content: [{
809
+ type: 'text',
810
+ text: JSON.stringify({
811
+ status: 'error',
812
+ error: 'Failed to create neural network model',
813
+ details: modelError.message,
814
+ troubleshooting: [
815
+ '1. TensorFlow.js initialization issue detected',
816
+ '2. Try restarting the MCP server',
817
+ '3. Check Node.js version compatibility',
818
+ '4. Performance API polyfill may need adjustment'
819
+ ],
820
+ technical_details: {
821
+ vocabulary_size: vocabularySize,
822
+ categories_count: categories.length,
823
+ tensorflow_available: typeof tf !== 'undefined',
824
+ performance_available: typeof global.performance !== 'undefined',
825
+ tick_available: typeof global.performance?.tick === 'function'
826
+ }
827
+ }, null, 2)
828
+ }]
829
+ };
830
+ }
768
831
  // Compile model
769
- model.compile({
770
- optimizer: tf.train.adam(0.001),
771
- loss: 'categoricalCrossentropy',
772
- metrics: ['accuracy']
773
- });
832
+ try {
833
+ this.logger.info('Compiling TensorFlow.js model...');
834
+ model.compile({
835
+ optimizer: tf.train.adam(0.001),
836
+ loss: 'categoricalCrossentropy',
837
+ metrics: ['accuracy']
838
+ });
839
+ this.logger.info('✅ Model compiled successfully');
840
+ }
841
+ catch (compileError) {
842
+ this.logger.error('Failed to compile TensorFlow.js model:', compileError);
843
+ return {
844
+ content: [{
845
+ type: 'text',
846
+ text: JSON.stringify({
847
+ status: 'error',
848
+ error: 'Failed to compile neural network model',
849
+ details: compileError.message,
850
+ troubleshooting: [
851
+ '1. Model architecture validation failed',
852
+ '2. Check TensorFlow.js optimizer availability',
853
+ '3. Verify model layers are compatible',
854
+ '4. Try with simpler model configuration'
855
+ ]
856
+ }, null, 2)
857
+ }]
858
+ };
859
+ }
774
860
  this.logger.info('Training incident classifier...');
775
861
  // Train model with improved error handling
776
- const history = await model.fit(features, labels, {
777
- epochs,
778
- validationSplit: validation_split,
779
- batchSize: 32,
780
- callbacks: {
781
- onEpochEnd: (epoch, logs) => {
782
- try {
783
- const loss = logs?.loss ? logs.loss.toFixed(4) : 'N/A';
784
- const accuracy = logs?.acc ? logs.acc.toFixed(4) : 'N/A';
785
- this.logger.info(`Epoch ${epoch + 1}: loss = ${loss}, accuracy = ${accuracy}`);
786
- }
787
- catch (e) {
788
- // Ignore callback errors to prevent training interruption
789
- this.logger.warn(`Callback error in epoch ${epoch + 1}:`, e);
862
+ let history;
863
+ try {
864
+ this.logger.info(`Starting training with ${epochs} epochs, batch size 32...`);
865
+ history = await model.fit(features, labels, {
866
+ epochs,
867
+ validationSplit: validation_split,
868
+ batchSize: 32,
869
+ callbacks: {
870
+ onEpochEnd: (epoch, logs) => {
871
+ try {
872
+ const loss = logs?.loss ? logs.loss.toFixed(4) : 'N/A';
873
+ const accuracy = logs?.acc ? logs.acc.toFixed(4) : 'N/A';
874
+ this.logger.info(`Epoch ${epoch + 1}: loss = ${loss}, accuracy = ${accuracy}`);
875
+ }
876
+ catch (e) {
877
+ // Ignore callback errors to prevent training interruption
878
+ this.logger.warn(`Callback error in epoch ${epoch + 1}:`, e);
879
+ }
790
880
  }
791
881
  }
882
+ });
883
+ this.logger.info('✅ Training completed successfully');
884
+ }
885
+ catch (trainingError) {
886
+ this.logger.error('Model training failed:', trainingError);
887
+ // Clean up tensors before returning error
888
+ try {
889
+ features.dispose();
890
+ labels.dispose();
891
+ model.dispose();
792
892
  }
793
- });
893
+ catch (cleanupError) {
894
+ this.logger.warn('Cleanup error:', cleanupError);
895
+ }
896
+ return {
897
+ content: [{
898
+ type: 'text',
899
+ text: JSON.stringify({
900
+ status: 'error',
901
+ error: 'Neural network training failed',
902
+ details: trainingError.message,
903
+ troubleshooting: [
904
+ '1. TensorFlow.js training process encountered an error',
905
+ '2. Try reducing epochs or batch_size',
906
+ '3. Check data quality and size',
907
+ '4. Restart MCP server if persistent',
908
+ '5. Verify sufficient system memory'
909
+ ],
910
+ training_parameters: {
911
+ epochs,
912
+ validation_split,
913
+ batch_size: 32,
914
+ samples: incidents.length
915
+ }
916
+ }, null, 2)
917
+ }]
918
+ };
919
+ }
794
920
  // Save model
795
921
  this.incidentClassifier = {
796
922
  model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snow-flow",
3
- "version": "3.0.23",
3
+ "version": "3.0.24",
4
4
  "description": "Snow-Flow v3.0.18: DIRECT API VERIFICATION! 🚀 Replaced unreliable searchRecords with direct API calls (snow_query_table style) for widget verification. All null/403 error recovery now uses GET /api/now/table/sp_widget with precise queries. NO MORE FALSE NEGATIVES - verification works consistently every time!",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",