modality-kit 0.6.2 → 0.6.3

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/index.js CHANGED
@@ -4293,34 +4293,23 @@ var DEFAULT_CONFIG = {
4293
4293
  maxSentencesForAnalysis: 500,
4294
4294
  fastModeMaxSentences: 200
4295
4295
  };
4296
- class LanguageDetectionError extends Error {
4297
- fallbackLanguage;
4298
- constructor(message, fallbackLanguage) {
4299
- super(message);
4300
- this.fallbackLanguage = fallbackLanguage;
4301
- this.name = "LanguageDetectionError";
4296
+
4297
+ class CompressionError extends ErrorCode {
4298
+ code;
4299
+ details;
4300
+ constructor(message, code, details, originalError) {
4301
+ super(message, originalError);
4302
+ this.code = code;
4303
+ this.details = details;
4302
4304
  }
4303
4305
  }
4304
4306
 
4305
- class CompressionLogger {
4306
- enabled;
4307
- constructor(enabled = false) {
4308
- this.enabled = enabled;
4309
- }
4310
- info(message, data) {
4311
- if (this.enabled) {
4312
- console.info(`[TextCompression] ${message}`, data || "");
4313
- }
4314
- }
4315
- warn(message, data) {
4316
- if (this.enabled) {
4317
- console.warn(`[TextCompression] ${message}`, data || "");
4318
- }
4319
- }
4320
- error(message, error) {
4321
- if (this.enabled) {
4322
- console.error(`[TextCompression] ${message}`, error || "");
4323
- }
4307
+ class LanguageDetectionError extends ErrorCode {
4308
+ code = "LANGUAGE_DETECTION_ERROR";
4309
+ fallbackLanguage;
4310
+ constructor(message, fallbackLanguage, originalError) {
4311
+ super(message, originalError);
4312
+ this.fallbackLanguage = fallbackLanguage;
4324
4313
  }
4325
4314
  }
4326
4315
 
@@ -4735,7 +4724,7 @@ class TextCompressionUtility {
4735
4724
  config;
4736
4725
  constructor(config = {}) {
4737
4726
  this.config = { ...DEFAULT_CONFIG, ...config };
4738
- this.logger = new CompressionLogger(this.config.enableLogging);
4727
+ this.logger = ModalityLogger.getInstance("TextCompression", this.config.enableLogging ? "info" : "error");
4739
4728
  this.languageDetector = new UniversalLanguageDetector(this.logger);
4740
4729
  this.importanceAnalyzer = new IntelligentImportanceAnalyzer(this.logger, this.config);
4741
4730
  }
@@ -4762,7 +4751,7 @@ class TextCompressionUtility {
4762
4751
  fastMode = false
4763
4752
  } = options;
4764
4753
  if (maxTokens <= 0) {
4765
- throw new Error("maxTokens must be greater than 0");
4754
+ throw new CompressionError("maxTokens must be greater than 0", "INVALID_MAX_TOKENS");
4766
4755
  }
4767
4756
  const trimmedText = text.trim();
4768
4757
  const originalLength = trimmedText.length;
@@ -4991,7 +4980,7 @@ class TextCompressionUtility {
4991
4980
  return Math.ceil(text.length / 4);
4992
4981
  }
4993
4982
  }
4994
- async function compressWithLanguageDetection(text, maxTokens = 4000) {
4983
+ async function compressWithLanguageDetection(text, maxTokens = DEFAULT_CONFIG.maxTokens) {
4995
4984
  const compressor = new TextCompressionUtility;
4996
4985
  return await compressor.compress(text, {
4997
4986
  maxTokens,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Console Mock Utility
3
+ *
4
+ * Provides utilities for mocking console output during testing to keep test output clean.
5
+ * Can be used across multiple test files for consistent console mocking.
6
+ */
7
+ export declare class ConsoleMock {
8
+ private originalMethods;
9
+ private isMocked;
10
+ /**
11
+ * Mock all console methods to prevent output during tests
12
+ */
13
+ mock(): void;
14
+ /**
15
+ * Restore original console methods
16
+ */
17
+ restore(): void;
18
+ /**
19
+ * Check if console is currently mocked
20
+ */
21
+ get isActive(): boolean;
22
+ /**
23
+ * Temporarily restore console methods for debugging purposes
24
+ * Returns a function to re-mock console methods
25
+ */
26
+ temporaryRestore(): () => void;
27
+ }
28
+ export declare const consoleMock: ConsoleMock;
29
+ /**
30
+ * Convenience functions for common usage patterns
31
+ */
32
+ /**
33
+ * Setup console mocking for a test suite (use in beforeAll)
34
+ */
35
+ export declare function setupConsoleMock(): void;
36
+ /**
37
+ * Cleanup console mocking for a test suite (use in afterAll)
38
+ */
39
+ export declare function cleanupConsoleMock(): void;
40
+ /**
41
+ * Higher-order function to run a function with console temporarily restored
42
+ * Useful for debugging specific tests
43
+ */
44
+ export declare function withConsole<T>(fn: () => T): T;
45
+ /**
46
+ * Higher-order function to run an async function with console temporarily restored
47
+ * Useful for debugging specific async tests
48
+ */
49
+ export declare function withConsoleAsync<T>(fn: () => Promise<T>): Promise<T>;
@@ -1,3 +1,5 @@
1
+ import { ModalityLogger } from './util_logger.js';
2
+ import { ErrorCode } from './util_error.js';
1
3
  export interface CompressionConfig {
2
4
  maxTokens: number;
3
5
  compressionLevel: "light" | "moderate" | "aggressive";
@@ -54,26 +56,20 @@ export interface LanguageDetectionResult {
54
56
  script?: string;
55
57
  region?: string;
56
58
  }
57
- export declare class CompressionError extends Error {
58
- code: string;
59
- details?: any | undefined;
60
- constructor(message: string, code: string, details?: any | undefined);
59
+ export declare class CompressionError extends ErrorCode {
60
+ readonly code: string;
61
+ details?: any;
62
+ constructor(message: string, code: string, details?: any, originalError?: unknown);
61
63
  }
62
- export declare class LanguageDetectionError extends Error {
64
+ export declare class LanguageDetectionError extends ErrorCode {
65
+ readonly code: string;
63
66
  fallbackLanguage: string;
64
- constructor(message: string, fallbackLanguage: string);
65
- }
66
- export declare class CompressionLogger {
67
- private enabled;
68
- constructor(enabled?: boolean);
69
- info(message: string, data?: any): void;
70
- warn(message: string, data?: any): void;
71
- error(message: string, error?: Error): void;
67
+ constructor(message: string, fallbackLanguage: string, originalError?: unknown);
72
68
  }
73
69
  export declare class UniversalLanguageDetector {
74
70
  private logger;
75
71
  private cache;
76
- constructor(logger: CompressionLogger);
72
+ constructor(logger: ModalityLogger);
77
73
  detectLanguage(text: string): Promise<LanguageDetectionResult>;
78
74
  private performDetection;
79
75
  private analyzeUnicodeRanges;
@@ -87,7 +83,7 @@ export declare class IntelligentImportanceAnalyzer {
87
83
  private wordFrequencyCache;
88
84
  private logger;
89
85
  private config;
90
- constructor(logger: CompressionLogger, config: CompressionConfig);
86
+ constructor(logger: ModalityLogger, config: CompressionConfig);
91
87
  analyzeImportance(text: string, detectedLanguage?: string): Promise<Array<{
92
88
  text: string;
93
89
  score: number;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.2",
2
+ "version": "0.6.3",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",