recker 1.0.15-next.905f0e7 → 1.0.15-next.b59c9d1
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/README.md +10 -1
- package/dist/ai/providers/anthropic.d.ts.map +1 -1
- package/dist/ai/providers/anthropic.js +4 -1
- package/dist/ai/providers/base.d.ts.map +1 -1
- package/dist/ai/providers/base.js +7 -2
- package/dist/ai/rate-limiter.d.ts.map +1 -1
- package/dist/ai/rate-limiter.js +4 -1
- package/dist/bench/generator.d.ts.map +1 -1
- package/dist/bench/generator.js +7 -3
- package/dist/bench/stats.d.ts.map +1 -1
- package/dist/bench/stats.js +43 -10
- package/dist/cache/memory-storage.d.ts.map +1 -1
- package/dist/cache/memory-storage.js +3 -2
- package/dist/cli/handler.js +14 -14
- package/dist/cli/index.js +582 -49
- package/dist/cli/presets.js +5 -5
- package/dist/cli/tui/ai-chat.js +10 -10
- package/dist/cli/tui/load-dashboard.d.ts.map +1 -1
- package/dist/cli/tui/load-dashboard.js +96 -55
- package/dist/cli/tui/scroll-buffer.d.ts +1 -1
- package/dist/cli/tui/scroll-buffer.d.ts.map +1 -1
- package/dist/cli/tui/scroll-buffer.js +2 -2
- package/dist/cli/tui/shell.d.ts +3 -0
- package/dist/cli/tui/shell.d.ts.map +1 -1
- package/dist/cli/tui/shell.js +166 -4
- package/dist/cli/tui/websocket.js +17 -17
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +18 -26
- package/dist/core/errors.d.ts +109 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +214 -1
- package/dist/core/request-promise.d.ts.map +1 -1
- package/dist/core/request-promise.js +5 -6
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +5 -6
- package/dist/dns/propagation.d.ts +3 -1
- package/dist/dns/propagation.d.ts.map +1 -1
- package/dist/dns/propagation.js +99 -59
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +10 -11
- package/dist/mcp/embeddings-loader.d.ts.map +1 -1
- package/dist/mcp/embeddings-loader.js +12 -2
- package/dist/mcp/geoip-loader.d.ts +11 -0
- package/dist/mcp/geoip-loader.d.ts.map +1 -0
- package/dist/mcp/geoip-loader.js +107 -0
- package/dist/mcp/ip-intel.d.ts +28 -0
- package/dist/mcp/ip-intel.d.ts.map +1 -0
- package/dist/mcp/ip-intel.js +209 -0
- package/dist/mcp/search/hybrid-search.d.ts.map +1 -1
- package/dist/mcp/search/hybrid-search.js +5 -1
- package/dist/mcp/search/math.d.ts.map +1 -1
- package/dist/mcp/search/math.js +5 -1
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +114 -1
- package/dist/plugins/compression.js +4 -2
- package/dist/plugins/har-player.d.ts.map +1 -1
- package/dist/plugins/har-player.js +8 -11
- package/dist/plugins/odata.d.ts.map +1 -1
- package/dist/plugins/odata.js +5 -2
- package/dist/protocols/ftp.d.ts.map +1 -1
- package/dist/protocols/ftp.js +69 -16
- package/dist/protocols/sftp.d.ts.map +1 -1
- package/dist/protocols/sftp.js +13 -3
- package/dist/protocols/telnet.d.ts.map +1 -1
- package/dist/protocols/telnet.js +25 -6
- package/dist/transport/base-udp.d.ts.map +1 -1
- package/dist/transport/base-udp.js +7 -4
- package/dist/transport/udp-response.d.ts.map +1 -1
- package/dist/transport/udp-response.js +10 -3
- package/dist/transport/udp.d.ts.map +1 -1
- package/dist/transport/udp.js +5 -1
- package/dist/transport/undici.d.ts.map +1 -1
- package/dist/transport/undici.js +75 -63
- package/dist/utils/agent-manager.d.ts +1 -0
- package/dist/utils/agent-manager.d.ts.map +1 -1
- package/dist/utils/agent-manager.js +11 -0
- package/dist/utils/client-pool.d.ts.map +1 -1
- package/dist/utils/client-pool.js +4 -1
- package/dist/utils/dns-toolkit.d.ts +88 -1
- package/dist/utils/dns-toolkit.d.ts.map +1 -1
- package/dist/utils/dns-toolkit.js +704 -6
- package/dist/utils/doh.d.ts.map +1 -1
- package/dist/utils/doh.js +13 -16
- package/dist/utils/download.d.ts.map +1 -1
- package/dist/utils/download.js +10 -11
- package/dist/utils/rdap.d.ts +9 -0
- package/dist/utils/rdap.d.ts.map +1 -1
- package/dist/utils/rdap.js +78 -9
- package/dist/utils/security-grader.d.ts +47 -0
- package/dist/utils/security-grader.d.ts.map +1 -0
- package/dist/utils/security-grader.js +637 -0
- package/dist/utils/sparkline.d.ts +18 -0
- package/dist/utils/sparkline.d.ts.map +1 -0
- package/dist/utils/sparkline.js +55 -0
- package/dist/utils/sse.d.ts.map +1 -1
- package/dist/utils/sse.js +5 -6
- package/dist/utils/system-metrics.d.ts +26 -0
- package/dist/utils/system-metrics.d.ts.map +1 -0
- package/dist/utils/system-metrics.js +81 -0
- package/dist/webrtc/index.d.ts.map +1 -1
- package/dist/webrtc/index.js +21 -7
- package/dist/websocket/client.d.ts.map +1 -1
- package/dist/websocket/client.js +13 -16
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"propagation.d.ts","sourceRoot":"","sources":["../../src/dns/propagation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"propagation.d.ts","sourceRoot":"","sources":["../../src/dns/propagation.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,SAAS,EAAE,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAgDD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAsB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,GAAE,MAAY,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA6D5G;AAyCD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CA2D1G"}
|
package/dist/dns/propagation.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Client } from '../core/client.js';
|
|
2
2
|
import pc from '../utils/colors.js';
|
|
3
3
|
const PROVIDERS = [
|
|
4
|
-
{ id: 'google', name: 'Google DNS', url: 'https://dns.google/resolve' },
|
|
5
|
-
{ id: 'cloudflare', name: 'Cloudflare', url: 'https://cloudflare-dns.com/dns-query' },
|
|
6
|
-
{ id: '
|
|
7
|
-
{ id: 'alidns', name: 'AliDNS (China)', url: 'https://dns.alidns.com/resolve' },
|
|
4
|
+
{ id: 'google', name: 'Google DNS', url: 'https://dns.google/resolve', location: 'Global' },
|
|
5
|
+
{ id: 'cloudflare', name: 'Cloudflare', url: 'https://cloudflare-dns.com/dns-query', location: 'Global' },
|
|
6
|
+
{ id: 'nextdns', name: 'NextDNS', url: 'https://dns.nextdns.io/dns-query', location: 'Global' },
|
|
8
7
|
];
|
|
9
8
|
const TYPE_MAP = {
|
|
10
9
|
'A': '1',
|
|
@@ -22,79 +21,116 @@ const TYPE_ID_MAP = Object.entries(TYPE_MAP).reduce((acc, [k, v]) => {
|
|
|
22
21
|
acc[Number(v)] = k;
|
|
23
22
|
return acc;
|
|
24
23
|
}, {});
|
|
25
|
-
|
|
24
|
+
const DNS_STATUS_MAP = {
|
|
25
|
+
0: 'NoError',
|
|
26
|
+
1: 'FormErr',
|
|
27
|
+
2: 'ServFail',
|
|
28
|
+
3: 'NXDomain',
|
|
29
|
+
4: 'NotImp',
|
|
30
|
+
5: 'Refused',
|
|
31
|
+
6: 'YXDomain',
|
|
32
|
+
7: 'YXRRSet',
|
|
33
|
+
8: 'NXRRSet',
|
|
34
|
+
9: 'NotAuth',
|
|
35
|
+
10: 'NotZone'
|
|
36
|
+
};
|
|
37
|
+
export function getTypeName(typeId) {
|
|
38
|
+
return TYPE_ID_MAP[typeId] || `TYPE${typeId}`;
|
|
39
|
+
}
|
|
40
|
+
export async function checkPropagation(domainInput, type = 'A') {
|
|
41
|
+
const domain = domainInput.replace(/^https?:\/\//, '').split('/')[0].split('?')[0];
|
|
26
42
|
const typeId = TYPE_MAP[type.toUpperCase()] || type;
|
|
43
|
+
const client = new Client({
|
|
44
|
+
baseUrl: 'http://localhost',
|
|
45
|
+
http2: true,
|
|
46
|
+
timeout: 5000,
|
|
47
|
+
});
|
|
27
48
|
const queries = PROVIDERS.map(async (provider) => {
|
|
28
49
|
const start = performance.now();
|
|
29
50
|
try {
|
|
30
51
|
const url = new URL(provider.url);
|
|
31
52
|
url.searchParams.set('name', domain);
|
|
32
53
|
url.searchParams.set('type', typeId);
|
|
33
|
-
const
|
|
34
|
-
method: 'GET',
|
|
54
|
+
const json = await client.get(url.toString(), {
|
|
35
55
|
headers: { 'Accept': 'application/dns-json' }
|
|
36
|
-
});
|
|
37
|
-
if (statusCode !== 200) {
|
|
38
|
-
throw new Error(`HTTP ${statusCode}`);
|
|
39
|
-
}
|
|
40
|
-
const json = await body.json();
|
|
56
|
+
}).json();
|
|
41
57
|
const duration = performance.now() - start;
|
|
42
|
-
|
|
43
|
-
const statusMap = {
|
|
44
|
-
1: 'FormErr', 2: 'ServFail', 3: 'NXDomain', 4: 'NotImp', 5: 'Refused'
|
|
45
|
-
};
|
|
46
|
-
const errorName = statusMap[json.Status] || `Code ${json.Status}`;
|
|
47
|
-
return {
|
|
48
|
-
id: provider.id,
|
|
49
|
-
provider: provider.name,
|
|
50
|
-
status: 'error',
|
|
51
|
-
records: [],
|
|
52
|
-
rawRecords: [],
|
|
53
|
-
latency: duration,
|
|
54
|
-
error: errorName
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
const answers = (json.Answer || []);
|
|
58
|
-
const records = answers.map(r => r.data);
|
|
59
|
-
return {
|
|
60
|
-
id: provider.id,
|
|
61
|
-
provider: provider.name,
|
|
62
|
-
status: 'ok',
|
|
63
|
-
records,
|
|
64
|
-
rawRecords: answers,
|
|
65
|
-
latency: duration
|
|
66
|
-
};
|
|
58
|
+
return processJsonResponse(json, provider, duration);
|
|
67
59
|
}
|
|
68
60
|
catch (err) {
|
|
61
|
+
const duration = performance.now() - start;
|
|
62
|
+
let errorMessage;
|
|
63
|
+
if (err.name === 'TimeoutError' || err.name === 'AbortError' || err.code === 'UND_ERR_ABORTED') {
|
|
64
|
+
errorMessage = `Timeout (>${client.defaultTimeout || 5000}ms)`;
|
|
65
|
+
}
|
|
66
|
+
else if (err.name === 'HttpError') {
|
|
67
|
+
errorMessage = `HTTP ${err.status} ${err.statusText}`;
|
|
68
|
+
}
|
|
69
|
+
else if (err.name === 'NetworkError') {
|
|
70
|
+
errorMessage = `Network error: ${err.code || err.message}`;
|
|
71
|
+
}
|
|
72
|
+
else if (err.name === 'ParseError') {
|
|
73
|
+
errorMessage = `Parse error: ${err.message}`;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
errorMessage = err.message || 'Unknown error';
|
|
77
|
+
}
|
|
69
78
|
return {
|
|
70
79
|
id: provider.id,
|
|
71
80
|
provider: provider.name,
|
|
72
81
|
status: 'error',
|
|
73
82
|
records: [],
|
|
74
83
|
rawRecords: [],
|
|
75
|
-
latency:
|
|
76
|
-
error:
|
|
84
|
+
latency: duration,
|
|
85
|
+
error: errorMessage,
|
|
86
|
+
location: provider.location
|
|
77
87
|
};
|
|
78
88
|
}
|
|
79
89
|
});
|
|
80
90
|
return Promise.all(queries);
|
|
81
91
|
}
|
|
92
|
+
function processJsonResponse(json, provider, duration) {
|
|
93
|
+
if (json.Status !== 0) {
|
|
94
|
+
const errorName = DNS_STATUS_MAP[json.Status] || `Code ${json.Status}`;
|
|
95
|
+
return {
|
|
96
|
+
id: provider.id,
|
|
97
|
+
provider: provider.name,
|
|
98
|
+
status: 'error',
|
|
99
|
+
records: [],
|
|
100
|
+
rawRecords: [],
|
|
101
|
+
latency: duration,
|
|
102
|
+
error: errorName,
|
|
103
|
+
location: provider.location
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const answers = (json.Answer || []);
|
|
107
|
+
const records = answers.map(r => r.data);
|
|
108
|
+
const minTTL = answers.length ? Math.min(...answers.map(r => r.TTL)) : undefined;
|
|
109
|
+
return {
|
|
110
|
+
id: provider.id,
|
|
111
|
+
provider: provider.name,
|
|
112
|
+
status: 'ok',
|
|
113
|
+
records,
|
|
114
|
+
rawRecords: answers,
|
|
115
|
+
latency: duration,
|
|
116
|
+
location: provider.location,
|
|
117
|
+
minTTL
|
|
118
|
+
};
|
|
119
|
+
}
|
|
82
120
|
export function formatPropagationReport(results, domain, type) {
|
|
83
121
|
let output = '';
|
|
84
|
-
|
|
85
|
-
${pc.bold(pc.cyan('🌍 Global DNS Propagation Check'))}
|
|
86
|
-
`;
|
|
87
|
-
output += `${pc.gray('Domain:')} ${pc.white(domain)} ${pc.gray('Type:')} ${pc.white(type.toUpperCase())}
|
|
88
|
-
|
|
89
|
-
`;
|
|
122
|
+
const displayDomain = domain.replace(/^https?:\/\//, '').split('/')[0];
|
|
123
|
+
output += `\n${pc.bold(pc.cyan('🌍 Global DNS Propagation Check'))}\n`;
|
|
124
|
+
output += `${pc.gray('Domain:')} ${pc.white(displayDomain)} ${pc.gray('Type:')} ${pc.white(type.toUpperCase())}\n\n`;
|
|
90
125
|
const consensus = {};
|
|
91
126
|
results.forEach(res => {
|
|
92
127
|
const key = res.status === 'ok' ? res.records.sort().join(', ') : `Error: ${res.error}`;
|
|
93
128
|
consensus[key] = (consensus[key] || 0) + 1;
|
|
94
129
|
const statusIcon = res.status === 'ok' ? pc.green('✔') : pc.red('✖');
|
|
95
130
|
const latencyColor = res.latency < 50 ? pc.green : res.latency < 200 ? pc.yellow : pc.red;
|
|
96
|
-
const latencyText = latencyColor(`${Math.round(res.latency)}ms`.padStart(
|
|
97
|
-
const providerName = pc.bold(res.provider.padEnd(
|
|
131
|
+
const latencyText = latencyColor(`${Math.round(res.latency)}ms`.padStart(6));
|
|
132
|
+
const providerName = pc.bold(res.provider.padEnd(12));
|
|
133
|
+
const ttlText = res.minTTL !== undefined ? pc.gray(`[TTL ${res.minTTL}s]`) : '';
|
|
98
134
|
let recordsText = '';
|
|
99
135
|
if (res.status === 'ok') {
|
|
100
136
|
if (res.records.length === 0) {
|
|
@@ -102,28 +138,32 @@ ${pc.bold(pc.cyan('🌍 Global DNS Propagation Check'))}
|
|
|
102
138
|
}
|
|
103
139
|
else {
|
|
104
140
|
recordsText = res.records.join(', ');
|
|
105
|
-
if (recordsText.length >
|
|
106
|
-
recordsText = recordsText.substring(0,
|
|
141
|
+
if (recordsText.length > 50)
|
|
142
|
+
recordsText = recordsText.substring(0, 47) + '...';
|
|
107
143
|
}
|
|
108
144
|
}
|
|
109
145
|
else {
|
|
110
146
|
recordsText = pc.red(res.error || 'Unknown Error');
|
|
111
147
|
}
|
|
112
|
-
output += ` ${statusIcon} ${providerName} ${latencyText} ${recordsText}
|
|
113
|
-
`;
|
|
148
|
+
output += ` ${statusIcon} ${providerName} ${latencyText} ${recordsText} ${ttlText}\n`;
|
|
114
149
|
});
|
|
115
150
|
output += '\n';
|
|
151
|
+
const okResults = results.filter(r => r.status === 'ok');
|
|
152
|
+
const errorResults = results.filter(r => r.status === 'error');
|
|
116
153
|
const distinctAnswers = Object.keys(consensus);
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
154
|
+
if (errorResults.length === results.length) {
|
|
155
|
+
output += pc.red('❌ All providers returned errors.\n');
|
|
156
|
+
}
|
|
157
|
+
else if (okResults.length === results.length && distinctAnswers.length === 1) {
|
|
158
|
+
output += pc.green('✅ All providers agree. Propagation is complete.\n');
|
|
159
|
+
}
|
|
160
|
+
else if (distinctAnswers.length > 1) {
|
|
161
|
+
if (errorResults.length > 0) {
|
|
162
|
+
output += pc.yellow(`⚠ ${okResults.length}/${results.length} providers responded. Some errors occurred.\n`);
|
|
120
163
|
}
|
|
121
164
|
else {
|
|
122
|
-
output += pc.
|
|
165
|
+
output += pc.yellow('⚠ Inconsistent results (propagation in progress or split-horizon DNS).\n');
|
|
123
166
|
}
|
|
124
167
|
}
|
|
125
|
-
else if (distinctAnswers.length > 1) {
|
|
126
|
-
output += pc.yellow('⚠ Inconsistent results detected (Propagation in progress or Split-Horizon DNS).\n');
|
|
127
|
-
}
|
|
128
168
|
return output;
|
|
129
169
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export * from './constants/http-status.js';
|
|
|
58
58
|
export * from './utils/env-proxy.js';
|
|
59
59
|
export * from './utils/charset.js';
|
|
60
60
|
export * from './utils/client-pool.js';
|
|
61
|
+
export * from './utils/security-grader.js';
|
|
61
62
|
export * as presets from './presets/index.js';
|
|
62
63
|
export * as testing from './testing/index.js';
|
|
63
64
|
export * as protocols from './protocols/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAo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GlD,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAGlC,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAOpD,OAAO,EACL,GAAG,EACH,IAAI,EACJ,GAAG,EACH,KAAK,EACL,GAAG,EACH,GAAG,IAAI,MAAM,EACb,IAAI,EACJ,OAAO,EACP,KAAK,EACL,cAAc,EACd,GAAG,EACH,WAAW,EACX,EAAE,EACF,MAAM,GACP,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,7 @@ export * from './constants/http-status.js';
|
|
|
58
58
|
export * from './utils/env-proxy.js';
|
|
59
59
|
export * from './utils/charset.js';
|
|
60
60
|
export * from './utils/client-pool.js';
|
|
61
|
+
export * from './utils/security-grader.js';
|
|
61
62
|
export * as presets from './presets/index.js';
|
|
62
63
|
export * as testing from './testing/index.js';
|
|
63
64
|
export * as protocols from './protocols/index.js';
|
package/dist/mcp/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAItC,OAAO,KAAK,EAGV,aAAa,EACb,OAAO,EAEP,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAYjB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,C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from '../core/client.js';
|
|
3
|
-
import {
|
|
3
|
+
import { StateError, ProtocolError } from '../core/errors.js';
|
|
4
4
|
import { consoleLogger } from '../types/logger.js';
|
|
5
5
|
export class MCPClient extends EventEmitter {
|
|
6
6
|
client;
|
|
@@ -128,11 +128,10 @@ export class MCPClient extends EventEmitter {
|
|
|
128
128
|
}
|
|
129
129
|
async request(method, params) {
|
|
130
130
|
if (!this.initialized && method !== 'initialize') {
|
|
131
|
-
throw new
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
]);
|
|
131
|
+
throw new StateError('MCP client not initialized. Call connect() first.', {
|
|
132
|
+
expectedState: 'connected',
|
|
133
|
+
actualState: 'disconnected',
|
|
134
|
+
});
|
|
136
135
|
}
|
|
137
136
|
const request = {
|
|
138
137
|
jsonrpc: '2.0',
|
|
@@ -146,11 +145,11 @@ export class MCPClient extends EventEmitter {
|
|
|
146
145
|
.json();
|
|
147
146
|
this.emit('response', response);
|
|
148
147
|
if (response.error) {
|
|
149
|
-
const error = new
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const error = new ProtocolError(response.error.message, {
|
|
149
|
+
protocol: 'mcp',
|
|
150
|
+
code: response.error.code,
|
|
151
|
+
retriable: false,
|
|
152
|
+
});
|
|
154
153
|
error.code = response.error.code;
|
|
155
154
|
error.data = response.error.data;
|
|
156
155
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embeddings-loader.d.ts","sourceRoot":"","sources":["../../src/mcp/embeddings-loader.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"embeddings-loader.d.ts","sourceRoot":"","sources":["../../src/mcp/embeddings-loader.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAgCxD,iBAAS,iBAAiB,IAAI,MAAM,CAKnC;AAyBD,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAI/D;AAKD,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5D;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAa3E;AAKD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAUhF;AAKD,wBAAsB,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CA4BlF;AAKD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsB5E;AAED,MAAM,WAAW,qBAAqB;IAEpC,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAsBD,wBAAsB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsCxG;AAKD,wBAAgB,oBAAoB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAW3D;AAKD,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
|
2
2
|
import { join, dirname } from 'path';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
|
+
import { DownloadError } from '../core/errors.js';
|
|
4
5
|
function getPackageVersionFromPkg() {
|
|
5
6
|
try {
|
|
6
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -78,14 +79,23 @@ export async function downloadEmbeddings(version) {
|
|
|
78
79
|
try {
|
|
79
80
|
const response = await fetch(url);
|
|
80
81
|
if (!response.ok) {
|
|
81
|
-
throw new
|
|
82
|
+
throw new DownloadError(`Failed to download embeddings: ${response.status} ${response.statusText}`, {
|
|
83
|
+
url,
|
|
84
|
+
statusCode: response.status,
|
|
85
|
+
retriable: response.status >= 500,
|
|
86
|
+
});
|
|
82
87
|
}
|
|
83
88
|
const data = await response.json();
|
|
84
89
|
saveLocalEmbeddings(data, ver);
|
|
85
90
|
return data;
|
|
86
91
|
}
|
|
87
92
|
catch (error) {
|
|
88
|
-
|
|
93
|
+
if (error instanceof DownloadError)
|
|
94
|
+
throw error;
|
|
95
|
+
throw new DownloadError(`Failed to download embeddings from ${url}: ${error}`, {
|
|
96
|
+
url,
|
|
97
|
+
retriable: true,
|
|
98
|
+
});
|
|
89
99
|
}
|
|
90
100
|
}
|
|
91
101
|
export async function loadBundledEmbeddings() {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function getGeoIPDatabasePath(): string;
|
|
2
|
+
export declare function hasLocalGeoIPDatabase(): boolean;
|
|
3
|
+
export declare function downloadGeoIPDatabase(): Promise<string>;
|
|
4
|
+
export interface LoadGeoIPOptions {
|
|
5
|
+
forceDownload?: boolean;
|
|
6
|
+
offline?: boolean;
|
|
7
|
+
debug?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function ensureGeoIPDatabase(options?: LoadGeoIPOptions): Promise<string | null>;
|
|
10
|
+
export declare function clearGeoIPCache(): void;
|
|
11
|
+
//# sourceMappingURL=geoip-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geoip-loader.d.ts","sourceRoot":"","sources":["../../src/mcp/geoip-loader.ts"],"names":[],"mappings":"AA4CA,wBAAgB,oBAAoB,IAAI,MAAM,CAG7C;AAKD,wBAAgB,qBAAqB,IAAI,OAAO,CAE/C;AAKD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CAiD7D;AAED,MAAM,WAAW,gBAAgB;IAE/B,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAuBD,wBAAsB,mBAAmB,CAAC,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoChG;AAKD,wBAAgB,eAAe,IAAI,IAAI,CAUtC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, createWriteStream, unlinkSync } from 'fs';
|
|
2
|
+
import { join, dirname } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { createGunzip } from 'zlib';
|
|
5
|
+
import { pipeline } from 'stream/promises';
|
|
6
|
+
import { Readable } from 'stream';
|
|
7
|
+
import { DownloadError } from '../core/errors.js';
|
|
8
|
+
const GEOLITE2_CDN_URL = 'https://cdn.jsdelivr.net/npm/geolite2-city/GeoLite2-City.mmdb.gz';
|
|
9
|
+
const DB_FILENAME = 'GeoLite2-City.mmdb';
|
|
10
|
+
function getCacheDir() {
|
|
11
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || '';
|
|
12
|
+
if (homeDir) {
|
|
13
|
+
return join(homeDir, '.cache', 'recker');
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
return join(__dirname, '..', '..', 'node_modules', '.cache', 'recker');
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return join(process.cwd(), 'node_modules', '.cache', 'recker');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function getGeoIPDatabasePath() {
|
|
24
|
+
const cacheDir = getCacheDir();
|
|
25
|
+
return join(cacheDir, DB_FILENAME);
|
|
26
|
+
}
|
|
27
|
+
export function hasLocalGeoIPDatabase() {
|
|
28
|
+
return existsSync(getGeoIPDatabasePath());
|
|
29
|
+
}
|
|
30
|
+
export async function downloadGeoIPDatabase() {
|
|
31
|
+
const dbPath = getGeoIPDatabasePath();
|
|
32
|
+
const cacheDir = dirname(dbPath);
|
|
33
|
+
if (!existsSync(cacheDir)) {
|
|
34
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(GEOLITE2_CDN_URL);
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
throw new DownloadError(`Failed to download GeoLite2 database: ${response.status} ${response.statusText}`, {
|
|
40
|
+
url: GEOLITE2_CDN_URL,
|
|
41
|
+
statusCode: response.status,
|
|
42
|
+
retriable: response.status >= 500,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (!response.body) {
|
|
46
|
+
throw new DownloadError('No response body received', {
|
|
47
|
+
url: GEOLITE2_CDN_URL,
|
|
48
|
+
retriable: true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const tempPath = dbPath + '.tmp';
|
|
52
|
+
const gunzip = createGunzip();
|
|
53
|
+
const writeStream = createWriteStream(tempPath);
|
|
54
|
+
const nodeStream = Readable.fromWeb(response.body);
|
|
55
|
+
await pipeline(nodeStream, gunzip, writeStream);
|
|
56
|
+
const fs = await import('fs/promises');
|
|
57
|
+
await fs.rename(tempPath, dbPath);
|
|
58
|
+
return dbPath;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if (error instanceof DownloadError)
|
|
62
|
+
throw error;
|
|
63
|
+
throw new DownloadError(`Failed to download GeoLite2 database: ${error}`, {
|
|
64
|
+
url: GEOLITE2_CDN_URL,
|
|
65
|
+
retriable: true,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export async function ensureGeoIPDatabase(options = {}) {
|
|
70
|
+
const { forceDownload = false, offline = false, debug = false } = options;
|
|
71
|
+
const log = (msg) => {
|
|
72
|
+
if (debug)
|
|
73
|
+
console.log(`[geoip-loader] ${msg}`);
|
|
74
|
+
};
|
|
75
|
+
const dbPath = getGeoIPDatabasePath();
|
|
76
|
+
if (!forceDownload && hasLocalGeoIPDatabase()) {
|
|
77
|
+
log(`Using cached database: ${dbPath}`);
|
|
78
|
+
return dbPath;
|
|
79
|
+
}
|
|
80
|
+
if (!offline) {
|
|
81
|
+
try {
|
|
82
|
+
log('Downloading GeoLite2-City database...');
|
|
83
|
+
const downloaded = await downloadGeoIPDatabase();
|
|
84
|
+
log(`Downloaded and cached: ${downloaded}`);
|
|
85
|
+
return downloaded;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
log(`Download failed: ${error}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (hasLocalGeoIPDatabase()) {
|
|
92
|
+
log(`Using stale cached database: ${dbPath}`);
|
|
93
|
+
return dbPath;
|
|
94
|
+
}
|
|
95
|
+
log('No GeoIP database available');
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
export function clearGeoIPCache() {
|
|
99
|
+
const dbPath = getGeoIPDatabasePath();
|
|
100
|
+
try {
|
|
101
|
+
if (existsSync(dbPath)) {
|
|
102
|
+
unlinkSync(dbPath);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface IpInfo {
|
|
2
|
+
ip: string;
|
|
3
|
+
hostname?: string;
|
|
4
|
+
city?: string;
|
|
5
|
+
region?: string;
|
|
6
|
+
country?: string;
|
|
7
|
+
countryCode?: string;
|
|
8
|
+
continent?: string;
|
|
9
|
+
loc?: string;
|
|
10
|
+
org?: string;
|
|
11
|
+
asn?: number;
|
|
12
|
+
timezone?: string;
|
|
13
|
+
postal?: string;
|
|
14
|
+
accuracy?: number;
|
|
15
|
+
bogon?: boolean;
|
|
16
|
+
bogonType?: string;
|
|
17
|
+
isIPv6?: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function isIPv6(ip: string): boolean;
|
|
20
|
+
export declare function isBogon(ip: string): {
|
|
21
|
+
isBogon: boolean;
|
|
22
|
+
type?: string;
|
|
23
|
+
};
|
|
24
|
+
export declare function isValidIP(ip: string): boolean;
|
|
25
|
+
export declare function getIpInfo(ip: string): Promise<IpInfo>;
|
|
26
|
+
export declare function isGeoIPAvailable(): boolean;
|
|
27
|
+
export { getGeoIPDatabasePath } from './geoip-loader.js';
|
|
28
|
+
//# sourceMappingURL=ip-intel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ip-intel.d.ts","sourceRoot":"","sources":["../../src/mcp/ip-intel.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAyID,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE1C;AAKD,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAKvE;AAKD,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAoB7C;AAsCD,wBAAsB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAqD3D;AAKD,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAKD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|