@reverse-craft/ai-tools 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reverse-craft/ai-tools",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "MCP server for AI-powered JSVMP detection - provides LLM-driven code analysis tools",
5
5
  "type": "module",
6
6
  "main": "dist/server.js",
package/dist/index.js DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * AI Tools - AI-powered code analysis tools
3
- *
4
- * This package provides LLM-driven functionality for code analysis,
5
- * including JSVMP (JavaScript Virtual Machine Protection) detection.
6
- *
7
- * @packageDocumentation
8
- */
9
- // LLM Configuration
10
- export { getLLMConfig, isLLMConfigured, createLLMClient, } from './llmConfig.js';
11
- // JSVMP Detector
12
- export { formatCodeForAnalysis, parseDetectionResult, findJsvmpDispatcher, } from './jsvmpDetector.js';
13
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,oBAAoB;AACpB,OAAO,EAGL,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,OAAO,EAQL,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,oBAAoB,CAAC"}
@@ -1,283 +0,0 @@
1
- /**
2
- * JSVMP Detector Module
3
- * AI-powered detection of JSVMP (JavaScript Virtual Machine Protection) patterns
4
- */
5
- import { SourceMapConsumer } from 'source-map-js';
6
- import { ensureBeautified, truncateCodeHighPerf } from '@reverse-craft/smart-fs';
7
- import { existsSync } from 'fs';
8
- import { getLLMConfig, createLLMClient } from './llmConfig.js';
9
- /**
10
- * Format source position as "L{line}:{column}" or empty placeholder
11
- */
12
- function formatSourcePosition(line, column) {
13
- if (line !== null && column !== null) {
14
- return `L${line}:${column}`;
15
- }
16
- return '';
17
- }
18
- /**
19
- * Format a single code line with line number, source coordinates, and content
20
- * Format: "LineNo SourceLoc Code"
21
- */
22
- function formatCodeLine(lineNumber, sourcePos, code) {
23
- const lineNumStr = String(lineNumber).padStart(5, ' ');
24
- const srcPosPadded = sourcePos ? sourcePos.padEnd(10, ' ') : ' ';
25
- return `${lineNumStr} ${srcPosPadded} ${code}`;
26
- }
27
- /**
28
- * 格式化代码为 LLM 分析格式
29
- * 格式: "LineNo SourceLoc Code"
30
- *
31
- * 处理流程:
32
- * 1. 调用 ensureBeautified 美化代码
33
- * 2. 调用 truncateCodeHighPerf 截断长字符串
34
- * 3. 使用 SourceMapConsumer 获取原始坐标
35
- * 4. 格式化为 "LineNo SourceLoc Code" 格式
36
- *
37
- * @param filePath - Path to the JavaScript file
38
- * @param startLine - Start line number (1-based)
39
- * @param endLine - End line number (1-based)
40
- * @param charLimit - Character limit for string truncation (default 300)
41
- * @returns FormattedCode object with formatted content and metadata
42
- */
43
- export async function formatCodeForAnalysis(filePath, startLine, endLine, charLimit = 300) {
44
- // Step 1: Beautify the file and get source map
45
- const beautifyResult = await ensureBeautified(filePath);
46
- const { code, rawMap } = beautifyResult;
47
- // Step 2: Truncate long strings
48
- const truncatedCode = truncateCodeHighPerf(code, charLimit);
49
- // Split into lines
50
- const lines = truncatedCode.split('\n');
51
- const totalLines = lines.length;
52
- // Step 3: Adjust line range boundaries
53
- const effectiveStartLine = Math.max(1, Math.min(totalLines, startLine));
54
- const effectiveEndLine = Math.max(effectiveStartLine, Math.min(totalLines, endLine));
55
- // Step 4: Format each line with "LineNo SourceLoc Code" format
56
- const formattedLines = [];
57
- // Create source map consumer if available
58
- let consumer = null;
59
- if (rawMap && rawMap.sources && rawMap.names && rawMap.mappings) {
60
- consumer = new SourceMapConsumer({
61
- version: String(rawMap.version),
62
- sources: rawMap.sources,
63
- names: rawMap.names,
64
- mappings: rawMap.mappings,
65
- file: rawMap.file,
66
- sourceRoot: rawMap.sourceRoot,
67
- });
68
- }
69
- for (let lineNum = effectiveStartLine; lineNum <= effectiveEndLine; lineNum++) {
70
- const lineIndex = lineNum - 1;
71
- const lineContent = lines[lineIndex] ?? '';
72
- // Get original position from source map if available
73
- let sourcePos = '';
74
- if (consumer) {
75
- const originalPos = consumer.originalPositionFor({
76
- line: lineNum,
77
- column: 0,
78
- });
79
- sourcePos = formatSourcePosition(originalPos.line, originalPos.column);
80
- }
81
- formattedLines.push(formatCodeLine(lineNum, sourcePos, lineContent));
82
- }
83
- return {
84
- content: formattedLines.join('\n'),
85
- totalLines,
86
- startLine: effectiveStartLine,
87
- endLine: effectiveEndLine,
88
- };
89
- }
90
- /**
91
- * Valid detection types for validation
92
- */
93
- const VALID_DETECTION_TYPES = [
94
- "If-Else Dispatcher",
95
- "Switch Dispatcher",
96
- "Instruction Array",
97
- "Stack Operation"
98
- ];
99
- /**
100
- * Valid confidence levels for validation
101
- */
102
- const VALID_CONFIDENCE_LEVELS = [
103
- "ultra_high",
104
- "high",
105
- "medium",
106
- "low"
107
- ];
108
- /**
109
- * Check if a value is a valid DetectionType
110
- */
111
- function isValidDetectionType(value) {
112
- return VALID_DETECTION_TYPES.includes(value);
113
- }
114
- /**
115
- * Check if a value is a valid ConfidenceLevel
116
- */
117
- function isValidConfidenceLevel(value) {
118
- return VALID_CONFIDENCE_LEVELS.includes(value);
119
- }
120
- /**
121
- * Parse and validate LLM detection result from JSON string
122
- *
123
- * Validates:
124
- * - JSON is parseable
125
- * - Required fields exist: summary, regions
126
- * - Each region has required fields: start, end, type, confidence, description
127
- * - Enum values are valid
128
- *
129
- * @param jsonString - JSON string from LLM response
130
- * @returns Parsed and validated DetectionResult
131
- * @throws Error if JSON is invalid or structure doesn't match expected format
132
- */
133
- export function parseDetectionResult(jsonString) {
134
- // Parse JSON
135
- let parsed;
136
- try {
137
- parsed = JSON.parse(jsonString);
138
- }
139
- catch (error) {
140
- throw new Error(`无法解析 LLM 响应: ${error instanceof Error ? error.message : String(error)}`);
141
- }
142
- // Validate required top-level fields
143
- if (typeof parsed !== 'object' || parsed === null) {
144
- throw new Error('LLM 响应格式无效,期望对象类型');
145
- }
146
- const obj = parsed;
147
- if (typeof obj.summary !== 'string') {
148
- throw new Error('LLM 响应格式无效,缺少必需字段: summary');
149
- }
150
- if (!Array.isArray(obj.regions)) {
151
- throw new Error('LLM 响应格式无效,缺少必需字段: regions');
152
- }
153
- // Validate each region
154
- const validatedRegions = [];
155
- for (let i = 0; i < obj.regions.length; i++) {
156
- const region = obj.regions[i];
157
- // Check region is an object
158
- if (typeof region !== 'object' || region === null) {
159
- throw new Error(`LLM 响应格式无效,regions[${i}] 不是对象`);
160
- }
161
- // Validate required fields exist and have correct types
162
- if (typeof region.start !== 'number') {
163
- throw new Error(`LLM 响应格式无效,regions[${i}] 缺少必需字段: start`);
164
- }
165
- if (typeof region.end !== 'number') {
166
- throw new Error(`LLM 响应格式无效,regions[${i}] 缺少必需字段: end`);
167
- }
168
- if (typeof region.type !== 'string') {
169
- throw new Error(`LLM 响应格式无效,regions[${i}] 缺少必需字段: type`);
170
- }
171
- if (typeof region.confidence !== 'string') {
172
- throw new Error(`LLM 响应格式无效,regions[${i}] 缺少必需字段: confidence`);
173
- }
174
- if (typeof region.description !== 'string') {
175
- throw new Error(`LLM 响应格式无效,regions[${i}] 缺少必需字段: description`);
176
- }
177
- // Validate enum values
178
- if (!isValidDetectionType(region.type)) {
179
- throw new Error(`LLM 响应格式无效,regions[${i}].type 值无效: "${region.type}". ` +
180
- `有效值: ${VALID_DETECTION_TYPES.join(', ')}`);
181
- }
182
- if (!isValidConfidenceLevel(region.confidence)) {
183
- throw new Error(`LLM 响应格式无效,regions[${i}].confidence 值无效: "${region.confidence}". ` +
184
- `有效值: ${VALID_CONFIDENCE_LEVELS.join(', ')}`);
185
- }
186
- validatedRegions.push({
187
- start: region.start,
188
- end: region.end,
189
- type: region.type,
190
- confidence: region.confidence,
191
- description: region.description,
192
- });
193
- }
194
- return {
195
- summary: obj.summary,
196
- regions: validatedRegions,
197
- };
198
- }
199
- /**
200
- * Format detection result for display
201
- */
202
- function formatDetectionResultOutput(result, filePath, startLine, endLine) {
203
- const lines = [];
204
- lines.push('=== JSVMP Dispatcher Detection Result ===');
205
- lines.push(`File: ${filePath} (${startLine}-${endLine})`);
206
- lines.push('');
207
- lines.push(`Summary: ${result.summary}`);
208
- lines.push('');
209
- if (result.regions.length > 0) {
210
- lines.push('Detected Regions:');
211
- for (const region of result.regions) {
212
- lines.push(`[${region.confidence}] Lines ${region.start}-${region.end}: ${region.type}`);
213
- lines.push(` ${region.description}`);
214
- lines.push('');
215
- }
216
- }
217
- else {
218
- lines.push('No JSVMP dispatcher patterns detected.');
219
- }
220
- return lines.join('\n');
221
- }
222
- /**
223
- * Find JSVMP dispatcher patterns in JavaScript code using LLM analysis
224
- *
225
- * @param filePath - Path to the JavaScript file to analyze
226
- * @param startLine - Start line number (1-based)
227
- * @param endLine - End line number (1-based)
228
- * @param options - Optional configuration
229
- * @returns JsvmpDetectionResult with detection results or error
230
- */
231
- export async function findJsvmpDispatcher(filePath, startLine, endLine, options) {
232
- const charLimit = options?.charLimit ?? 300;
233
- // Check LLM configuration
234
- const config = getLLMConfig();
235
- if (!config) {
236
- return {
237
- success: false,
238
- filePath,
239
- startLine,
240
- endLine,
241
- error: '未配置 LLM。请设置环境变量 OPENAI_API_KEY 以启用 JSVMP dispatcher 检测功能。'
242
- };
243
- }
244
- // Check file exists
245
- if (!existsSync(filePath)) {
246
- return {
247
- success: false,
248
- filePath,
249
- startLine,
250
- endLine,
251
- error: `文件不存在: ${filePath}`
252
- };
253
- }
254
- try {
255
- // Format code for analysis
256
- const formattedCode = await formatCodeForAnalysis(filePath, startLine, endLine, charLimit);
257
- // Create LLM client and analyze
258
- const client = createLLMClient(config);
259
- const llmResponse = await client.analyzeJSVMP(formattedCode.content);
260
- // Parse detection result
261
- const result = parseDetectionResult(llmResponse);
262
- // Format output
263
- const formattedOutput = formatDetectionResultOutput(result, filePath, startLine, endLine);
264
- return {
265
- success: true,
266
- filePath,
267
- startLine: formattedCode.startLine,
268
- endLine: formattedCode.endLine,
269
- result,
270
- formattedOutput
271
- };
272
- }
273
- catch (error) {
274
- return {
275
- success: false,
276
- filePath,
277
- startLine,
278
- endLine,
279
- error: error instanceof Error ? error.message : String(error)
280
- };
281
- }
282
- }
283
- //# sourceMappingURL=jsvmpDetector.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jsvmpDetector.js","sourceRoot":"","sources":["../src/jsvmpDetector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAiE/D;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAmB,EAAE,MAAqB;IACtE,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACrC,OAAO,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,UAAkB,EAAE,SAAiB,EAAE,IAAY;IACzE,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACvD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC;IAC1E,OAAO,GAAG,UAAU,IAAI,YAAY,IAAI,IAAI,EAAE,CAAC;AACjD,CAAC;AAED;;;;;;;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C9B,MAAM;YACN,eAAe;SAChB,CAAC;IAEJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,QAAQ;YACR,SAAS;YACT,OAAO;YACP,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;IACJ,CAAC;AACH,CAAC"}
package/dist/llmConfig.js DELETED
@@ -1,133 +0,0 @@
1
- /**
2
- * LLM Configuration Module
3
- * Handles reading and validating LLM configuration from environment variables
4
- */
5
- /**
6
- * 从环境变量读取 LLM 配置
7
- * @returns LLMConfig | null (null 表示未配置)
8
- */
9
- export function getLLMConfig() {
10
- const apiKey = process.env.OPENAI_API_KEY;
11
- // API Key is required
12
- if (!apiKey) {
13
- return null;
14
- }
15
- // Use defaults for optional configuration
16
- const baseUrl = process.env.OPENAI_BASE_URL || "https://api.openai.com/v1";
17
- const model = process.env.OPENAI_MODEL || "gpt-4o-mini";
18
- return {
19
- apiKey,
20
- baseUrl,
21
- model
22
- };
23
- }
24
- /**
25
- * 检查 LLM 是否已配置
26
- */
27
- export function isLLMConfigured() {
28
- return getLLMConfig() !== null;
29
- }
30
- /**
31
- * 构建 JSVMP 检测系统提示词
32
- */
33
- function buildJSVMPSystemPrompt() {
34
- return `你是一个专业的 JavaScript 逆向工程专家,专门识别 JSVMP(JavaScript Virtual Machine Protection)保护代码。
35
-
36
- JSVMP 是一种代码保护技术,将 JavaScript 代码转换为字节码,并通过虚拟机执行。典型特征包括:
37
-
38
- 1. **虚拟栈(Virtual Stack)**:中央数组用于存储操作数和结果
39
- 2. **分发器(Dispatcher)**:大型 switch 语句或嵌套 if-else 链,根据指令码执行不同操作
40
- 3. **指令数组(Instruction Array)**:存储字节码指令的数组
41
- 4. **主循环(Main Loop)**:while 循环持续执行指令
42
-
43
- 检测规则:
44
-
45
- **Ultra High 置信度**:
46
- - 同时出现:主循环 + 分发器 + 栈操作
47
- - 分发器有 >20 个 case 或 >10 层嵌套
48
- - 明确的栈操作模式(push/pop/数组索引)
49
-
50
- **High 置信度**:
51
- - 独立的大型分发器结构(>20 case 的 switch 或 >10 层嵌套的 if-else)
52
- - 明确的指令数组和程序计数器模式
53
-
54
- **Medium 置信度**:
55
- - 孤立的栈操作或可疑的 while 循环
56
- - 部分 JSVMP 特征但不完整
57
-
58
- **Low 置信度**:
59
- - 通用混淆模式
60
- - 可能相关但不确定的结构
61
-
62
- 请分析提供的代码,识别 JSVMP 相关区域。返回 JSON 格式:
63
-
64
- {
65
- "summary": "分析摘要(中文)",
66
- "regions": [
67
- {
68
- "start": 起始行号,
69
- "end": 结束行号,
70
- "type": "If-Else Dispatcher" | "Switch Dispatcher" | "Instruction Array" | "Stack Operation",
71
- "confidence": "ultra_high" | "high" | "medium" | "low",
72
- "description": "详细描述(中文)"
73
- }
74
- ]
75
- }
76
-
77
- 如果没有检测到 JSVMP 特征,返回空的 regions 数组。`;
78
- }
79
- /**
80
- * 创建 LLM 客户端实例
81
- */
82
- export function createLLMClient(config) {
83
- return {
84
- async analyzeJSVMP(formattedCode) {
85
- const systemPrompt = buildJSVMPSystemPrompt();
86
- const requestBody = {
87
- model: config.model,
88
- messages: [
89
- {
90
- role: "system",
91
- content: systemPrompt
92
- },
93
- {
94
- role: "user",
95
- content: `请分析以下代码,识别 JSVMP 保护结构:\n\n${formattedCode}`
96
- }
97
- ],
98
- temperature: 0.1,
99
- response_format: { type: "json_object" }
100
- };
101
- try {
102
- const response = await fetch(`${config.baseUrl}/chat/completions`, {
103
- method: "POST",
104
- headers: {
105
- "Content-Type": "application/json",
106
- "Authorization": `Bearer ${config.apiKey}`
107
- },
108
- body: JSON.stringify(requestBody)
109
- });
110
- if (!response.ok) {
111
- const errorText = await response.text();
112
- throw new Error(`API 请求失败 (${response.status}): ${errorText}`);
113
- }
114
- const data = await response.json();
115
- if (!data.choices || !data.choices[0] || !data.choices[0].message) {
116
- throw new Error("API 响应格式无效:缺少 choices 或 message 字段");
117
- }
118
- const content = data.choices[0].message.content;
119
- if (typeof content !== "string") {
120
- throw new Error("API 响应格式无效:message.content 不是字符串");
121
- }
122
- return content;
123
- }
124
- catch (error) {
125
- if (error instanceof Error) {
126
- throw new Error(`LLM 请求失败: ${error.message}`);
127
- }
128
- throw new Error(`LLM 请求失败: ${String(error)}`);
129
- }
130
- }
131
- };
132
- }
133
- //# sourceMappingURL=llmConfig.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"llmConfig.js","sourceRoot":"","sources":["../src/llmConfig.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAE1C,sBAAsB;IACtB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,0CAA0C;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,2BAA2B,CAAC;IAC3E,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,aAAa,CAAC;IAExD,OAAO;QACL,MAAM;QACN,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,YAAY,EAAE,KAAK,IAAI,CAAC;AACjC,CAAC;AAcD;;GAEG;AACH,SAAS,sBAAsB;IAC7B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCA2CyB,CAAC;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAiB;IAC/C,OAAO;QACL,KAAK,CAAC,YAAY,CAAC,aAAqB;YACtC,MAAM,YAAY,GAAG,sBAAsB,EAAE,CAAC;YAE9C,MAAM,WAAW,GAAG;gBAClB,KAAK,EAAE,MAAM,CAAC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CAAkC,CAAC,CAAC;gBACtD,CAAC;gBAED,OAAO,OAAO,CAAC;YACjB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;oBAC3B,MAAM,IAAI,KAAK,CAAC,aAAa,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAChD,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,aAAa,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YAChD,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,41 +0,0 @@
1
- import { z } from 'zod';
2
- /**
3
- * Input schema for find_jsvmp_dispatcher tool
4
- */
5
- export declare const FindJsvmpDispatcherInputSchema: {
6
- filePath: z.ZodString;
7
- startLine: z.ZodNumber;
8
- endLine: z.ZodNumber;
9
- charLimit: z.ZodOptional<z.ZodNumber>;
10
- };
11
- /**
12
- * MCP Tool: find_jsvmp_dispatcher
13
- *
14
- * Uses LLM to detect JSVMP (JavaScript Virtual Machine Protection) patterns in code.
15
- *
16
- * JSVMP is a code protection technique that converts JavaScript to bytecode
17
- * executed by a virtual machine. This tool identifies:
18
- * - If-Else Dispatchers
19
- * - Switch Dispatchers
20
- * - Instruction Arrays
21
- * - Stack Operations
22
- *
23
- * Requires OPENAI_API_KEY environment variable to be set.
24
- */
25
- export declare const findJsvmpDispatcherTool: {
26
- name: string;
27
- description: string;
28
- schema: {
29
- filePath: z.ZodString;
30
- startLine: z.ZodNumber;
31
- endLine: z.ZodNumber;
32
- charLimit: z.ZodOptional<z.ZodNumber>;
33
- };
34
- handler: (params: {
35
- filePath: string;
36
- startLine: number;
37
- endLine: number;
38
- charLimit?: number;
39
- }) => Promise<string>;
40
- };
41
- //# sourceMappingURL=findJsvmpDispatcher.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findJsvmpDispatcher.d.ts","sourceRoot":"","sources":["../../src/tools/findJsvmpDispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,eAAO,MAAM,8BAA8B;;;;;CAK1C,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;sBAcV;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,KAAG,OAAO,CAAC,MAAM,CAAC;CAapB,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Property-based tests for findJsvmpDispatcherTool
3
- *
4
- * Tests the MCP tool's input validation and response format properties.
5
- */
6
- export {};
7
- //# sourceMappingURL=findJsvmpDispatcherTool.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findJsvmpDispatcherTool.test.d.ts","sourceRoot":"","sources":["../../src/tools/findJsvmpDispatcherTool.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}