modality-kit 0.5.7 → 0.6.0

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
@@ -105,7 +105,7 @@ class ModalityLogger {
105
105
  setLogLevel(level) {
106
106
  this.logLevel = level;
107
107
  }
108
- format(level, payload, categroy) {
108
+ format(level, categroy) {
109
109
  const timestamp = this.getTimestamp();
110
110
  let prefix = "";
111
111
  switch (level) {
@@ -134,80 +134,63 @@ class ModalityLogger {
134
134
  if (categroy) {
135
135
  prefix += ` [${categroy}]`;
136
136
  }
137
- return { prefix, result: payload };
137
+ return prefix;
138
138
  }
139
139
  log(level, payload, categroy) {
140
140
  if (!this.shouldLog(level))
141
141
  return;
142
- const { prefix, result } = this.format(level, payload, categroy);
142
+ const prefix = this.format(level, categroy);
143
+ console.group(prefix);
143
144
  switch (level) {
144
145
  case "debug":
145
- console.debug(`
146
- `, prefix, result, `
147
- `);
146
+ console.debug(payload);
148
147
  break;
149
148
  case "info":
150
- console.log(`
151
- `, prefix);
152
- console.dir(result, {
149
+ console.dir(payload, {
153
150
  depth: null,
154
151
  colors: true,
155
152
  maxArrayLength: null
156
153
  });
157
- console.log(`
158
- `);
159
154
  break;
160
155
  case "warn":
161
- console.log(`
162
- `, prefix);
163
- console.warn(result);
156
+ console.warn(payload);
164
157
  console.log(`
165
158
  `);
166
159
  break;
167
160
  case "error":
168
- const error = result.error;
169
- if (error instanceof Error) {
170
- delete result.error;
161
+ const error = payload.error;
162
+ if (error instanceof Error || error.stack) {
163
+ delete payload.error;
171
164
  const { message, stack, ...restError } = error;
172
165
  if (stack) {
173
166
  if (Object.keys(restError).length) {
174
- console.error(`
175
- `, prefix, restError, `
176
- `, stack, `
177
- `);
167
+ console.error(restError, `
168
+ `, stack);
178
169
  } else {
179
- console.error(`
180
- `, prefix, `
181
- `, stack, `
182
- `);
170
+ console.error(stack);
183
171
  }
184
172
  } else {
185
173
  if (message) {
186
- result.error = message;
174
+ payload.error = message;
187
175
  }
188
- console.error(`
189
- `, prefix, result, `
190
- `);
176
+ console.error(payload);
191
177
  }
192
178
  } else {
193
- console.error(`
194
- `, prefix, result, `
195
- `);
179
+ console.error(payload);
196
180
  }
197
181
  break;
198
182
  case "success":
199
- console.log(`
200
- `, prefix, result, `
201
- `);
183
+ console.error(payload);
202
184
  break;
203
185
  }
186
+ console.groupEnd();
204
187
  }
205
- cook(message, data) {
206
- const payload = typeof message === "string" ? { message } : message;
188
+ cook(payload, data) {
189
+ const newPayload = typeof payload === "string" ? { message: payload } : payload;
207
190
  if (data) {
208
- payload.data = data;
191
+ newPayload.data = data;
209
192
  }
210
- return payload;
193
+ return newPayload;
211
194
  }
212
195
  debug(message, data) {
213
196
  this.log("debug", this.cook(message, data));
@@ -246,7 +229,7 @@ function withErrorHandling(fn, operation) {
246
229
  return await fn(...args);
247
230
  } catch (error) {
248
231
  if (error instanceof ErrorCode) {
249
- logger.error(`${operation || "Task operation"} failed: ${error.code}`, {
232
+ logger.error(`${operation || "Unknown operation"} failed: ${error.code}`, {
250
233
  code: error.code,
251
234
  cause: error.cause,
252
235
  stack: error.stack
@@ -21,7 +21,7 @@ export declare class ModalityLogger {
21
21
  * For control display logging level, the level could not set by user.
22
22
  */
23
23
  log(level: LogLevel, payload: any, categroy?: string): void;
24
- cook(message: any, data?: any): any;
24
+ cook(payload: any, data?: any): any;
25
25
  debug(message: string, data?: any): void;
26
26
  info(message: string, data?: any): void;
27
27
  warn(message: string, data?: any): void;
@@ -0,0 +1,139 @@
1
+ export interface CompressionConfig {
2
+ maxTokens: number;
3
+ compressionLevel: 'light' | 'moderate' | 'aggressive';
4
+ preserveCodeBlocks: boolean;
5
+ autoDetectLanguage: boolean;
6
+ enableLogging: boolean;
7
+ maxSentencesForAnalysis: number;
8
+ fastModeMaxSentences: number;
9
+ }
10
+ export declare const DEFAULT_CONFIG: CompressionConfig;
11
+ export interface CompressionOptions {
12
+ maxTokens?: number;
13
+ compressionLevel?: 'light' | 'moderate' | 'aggressive';
14
+ preserveCodeBlocks?: boolean;
15
+ autoDetectLanguage?: boolean;
16
+ locale?: string;
17
+ prioritizeFirst?: boolean;
18
+ prioritizeLast?: boolean;
19
+ preserveStructure?: boolean;
20
+ bufferPercentage?: number;
21
+ maxSentences?: number;
22
+ fastMode?: boolean;
23
+ enableLogging?: boolean;
24
+ sentenceSplitPattern?: RegExp;
25
+ importanceWeights?: ImportanceWeights;
26
+ tokenizationMethod?: 'simple' | 'advanced';
27
+ }
28
+ export interface ImportanceWeights {
29
+ position: number;
30
+ length: number;
31
+ wordRarity: number;
32
+ codeElements: number;
33
+ }
34
+ export interface CompressionResult {
35
+ compressedText: string;
36
+ originalLength: number;
37
+ compressedLength: number;
38
+ compressionRatio: number;
39
+ tokensEstimate: number;
40
+ detectedLanguage?: string;
41
+ importanceScores?: Array<{
42
+ text: string;
43
+ score: number;
44
+ reasons: string[];
45
+ }>;
46
+ processingTime?: number;
47
+ errors?: string[];
48
+ warnings?: string[];
49
+ }
50
+ export interface LanguageDetectionResult {
51
+ code: string;
52
+ locale: string;
53
+ confidence: number;
54
+ script?: string;
55
+ region?: string;
56
+ }
57
+ export declare class CompressionError extends Error {
58
+ code: string;
59
+ details?: any | undefined;
60
+ constructor(message: string, code: string, details?: any | undefined);
61
+ }
62
+ export declare class LanguageDetectionError extends Error {
63
+ 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;
72
+ }
73
+ export declare class UniversalLanguageDetector {
74
+ private logger;
75
+ private cache;
76
+ constructor(logger: CompressionLogger);
77
+ detectLanguage(text: string): Promise<LanguageDetectionResult>;
78
+ private performDetection;
79
+ private analyzeUnicodeRanges;
80
+ private prioritizeLocalesBasedOnUnicode;
81
+ private getAvailableTestLocales;
82
+ private getUnicodeRelevanceScore;
83
+ private getUnicodeBoost;
84
+ private testLocaleWithIntlAPIs;
85
+ private enhanceWithTextAnalysis;
86
+ private detectFromTextHeuristics;
87
+ }
88
+ export declare class IntelligentImportanceAnalyzer {
89
+ private wordFrequencyCache;
90
+ private logger;
91
+ private config;
92
+ constructor(logger: CompressionLogger, config: CompressionConfig);
93
+ analyzeImportance(text: string, detectedLanguage?: string): Promise<Array<{
94
+ text: string;
95
+ score: number;
96
+ reasons: string[];
97
+ }>>;
98
+ fastAnalyzeImportance(text: string, detectedLanguage?: string): Promise<Array<{
99
+ text: string;
100
+ score: number;
101
+ reasons: string[];
102
+ }>>;
103
+ private segmentSentences;
104
+ private analyzePosition;
105
+ private analyzeLengthDeviation;
106
+ private analyzeWordRarity;
107
+ private calculateWordFrequencies;
108
+ }
109
+ export declare class TextCompressionUtility {
110
+ private languageDetector;
111
+ private importanceAnalyzer;
112
+ private logger;
113
+ private config;
114
+ constructor(config?: Partial<CompressionConfig>);
115
+ compress(text: string, options?: CompressionOptions): Promise<CompressionResult>;
116
+ private extractCodeElements;
117
+ private applyUserPriorities;
118
+ private applyCompression;
119
+ private getCompressionThreshold;
120
+ private segmentSentences;
121
+ private trimToTokenLimit;
122
+ private estimateTokens;
123
+ }
124
+ export declare function compressUserInput(text: string, maxTokens?: number): Promise<string>;
125
+ export declare function compressConversationHistory(messages: Array<{
126
+ role: string;
127
+ content: string;
128
+ }>, maxTokens: number): Promise<Array<{
129
+ role: string;
130
+ content: string;
131
+ }>>;
132
+ export declare function analyzeTextImportance(text: string): Promise<Array<{
133
+ text: string;
134
+ score: number;
135
+ reasons: string[];
136
+ }>>;
137
+ export declare function compressText(text: string, options?: CompressionOptions): Promise<CompressionResult>;
138
+ export declare function fastCompressText(text: string, maxTokens?: number): Promise<string>;
139
+ export declare function compressWithLanguageDetection(text: string, maxTokens?: number): Promise<CompressionResult>;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.5.7",
2
+ "version": "0.6.0",
3
3
  "name": "modality-kit",
4
4
  "repository": {
5
5
  "type": "git",
@@ -13,7 +13,7 @@
13
13
  "author": "Hill <hill@kimo.com>",
14
14
  "license": "ISC",
15
15
  "devDependencies": {
16
- "@types/node": "^24.1.0",
16
+ "@types/bun": "^1.2.19",
17
17
  "fastmcp": "^3.12.0",
18
18
  "typescript": "^5.8.3",
19
19
  "zod": "3.x"
@@ -31,7 +31,7 @@
31
31
  "build:types": "bunx tsc -p ./",
32
32
  "build:src": "bun build src/index.ts --outdir dist",
33
33
  "build": "bun run build:clean && bun run build:src && bun run build:types",
34
- "test": "npm run build",
34
+ "test": "bun test",
35
35
  "prepublishOnly": "npm run test"
36
36
  },
37
37
  "types": "./dist/types/index.d.ts",