recker 1.0.15 → 1.0.17
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 +86 -97
- 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 +8 -3
- package/dist/bench/stats.d.ts +15 -1
- package/dist/bench/stats.d.ts.map +1 -1
- package/dist/bench/stats.js +117 -5
- 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 +602 -48
- 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 +127 -32
- package/dist/cli/tui/scroll-buffer.d.ts +43 -0
- package/dist/cli/tui/scroll-buffer.d.ts.map +1 -0
- package/dist/cli/tui/scroll-buffer.js +162 -0
- package/dist/cli/tui/search-panel.d.ts +41 -0
- package/dist/cli/tui/search-panel.d.ts.map +1 -0
- package/dist/cli/tui/search-panel.js +420 -0
- package/dist/cli/tui/shell.d.ts +14 -0
- package/dist/cli/tui/shell.d.ts.map +1 -1
- package/dist/cli/tui/shell.js +424 -46
- package/dist/cli/tui/websocket.js +17 -17
- package/dist/contract/index.js +3 -2
- 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/index.d.ts +1 -0
- package/dist/dns/index.d.ts.map +1 -1
- package/dist/dns/index.js +1 -0
- package/dist/dns/propagation.d.ts +21 -0
- package/dist/dns/propagation.d.ts.map +1 -0
- package/dist/dns/propagation.js +169 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +10 -11
- package/dist/mcp/embeddings-loader.d.ts +18 -0
- package/dist/mcp/embeddings-loader.d.ts.map +1 -0
- package/dist/mcp/embeddings-loader.js +162 -0
- 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/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -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 +59 -38
- package/dist/mcp/search/math.d.ts.map +1 -1
- package/dist/mcp/search/math.js +5 -1
- package/dist/mcp/server.d.ts +6 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +122 -2
- 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/recker.d.ts +47 -0
- package/dist/recker.d.ts.map +1 -0
- package/dist/recker.js +99 -0
- 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/colors.d.ts +16 -0
- package/dist/utils/colors.d.ts.map +1 -1
- package/dist/utils/colors.js +16 -0
- 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/utils/tls-inspector.d.ts +6 -0
- package/dist/utils/tls-inspector.d.ts.map +1 -1
- package/dist/utils/tls-inspector.js +35 -1
- 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 +4 -3
- package/dist/mcp/data/embeddings.json +0 -1
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { Reader } from '@maxmind/geoip2-node';
|
|
2
|
+
import { ensureGeoIPDatabase, hasLocalGeoIPDatabase } from './geoip-loader.js';
|
|
3
|
+
const IPV4_BOGON_RANGES = [
|
|
4
|
+
{ prefix: '0.', desc: 'This Network (RFC 1122)' },
|
|
5
|
+
{ prefix: '10.', desc: 'Private-Use (RFC 1918)' },
|
|
6
|
+
{ prefix: '100.64.', desc: 'Carrier-Grade NAT (RFC 6598)' },
|
|
7
|
+
{ prefix: '127.', desc: 'Loopback (RFC 1122)' },
|
|
8
|
+
{ prefix: '169.254.', desc: 'Link-Local (RFC 3927)' },
|
|
9
|
+
{ prefix: '172.16.', desc: 'Private-Use (RFC 1918)' },
|
|
10
|
+
{ prefix: '172.17.', desc: 'Private-Use (RFC 1918)' },
|
|
11
|
+
{ prefix: '172.18.', desc: 'Private-Use (RFC 1918)' },
|
|
12
|
+
{ prefix: '172.19.', desc: 'Private-Use (RFC 1918)' },
|
|
13
|
+
{ prefix: '172.20.', desc: 'Private-Use (RFC 1918)' },
|
|
14
|
+
{ prefix: '172.21.', desc: 'Private-Use (RFC 1918)' },
|
|
15
|
+
{ prefix: '172.22.', desc: 'Private-Use (RFC 1918)' },
|
|
16
|
+
{ prefix: '172.23.', desc: 'Private-Use (RFC 1918)' },
|
|
17
|
+
{ prefix: '172.24.', desc: 'Private-Use (RFC 1918)' },
|
|
18
|
+
{ prefix: '172.25.', desc: 'Private-Use (RFC 1918)' },
|
|
19
|
+
{ prefix: '172.26.', desc: 'Private-Use (RFC 1918)' },
|
|
20
|
+
{ prefix: '172.27.', desc: 'Private-Use (RFC 1918)' },
|
|
21
|
+
{ prefix: '172.28.', desc: 'Private-Use (RFC 1918)' },
|
|
22
|
+
{ prefix: '172.29.', desc: 'Private-Use (RFC 1918)' },
|
|
23
|
+
{ prefix: '172.30.', desc: 'Private-Use (RFC 1918)' },
|
|
24
|
+
{ prefix: '172.31.', desc: 'Private-Use (RFC 1918)' },
|
|
25
|
+
{ prefix: '192.0.0.', desc: 'IETF Protocol Assignments (RFC 6890)' },
|
|
26
|
+
{ prefix: '192.0.2.', desc: 'Documentation TEST-NET-1 (RFC 5737)' },
|
|
27
|
+
{ prefix: '192.88.99.', desc: '6to4 Relay Anycast (RFC 3068)' },
|
|
28
|
+
{ prefix: '192.168.', desc: 'Private-Use (RFC 1918)' },
|
|
29
|
+
{ prefix: '198.18.', desc: 'Benchmarking (RFC 2544)' },
|
|
30
|
+
{ prefix: '198.19.', desc: 'Benchmarking (RFC 2544)' },
|
|
31
|
+
{ prefix: '198.51.100.', desc: 'Documentation TEST-NET-2 (RFC 5737)' },
|
|
32
|
+
{ prefix: '203.0.113.', desc: 'Documentation TEST-NET-3 (RFC 5737)' },
|
|
33
|
+
{ prefix: '224.', desc: 'Multicast (RFC 5771)' },
|
|
34
|
+
{ prefix: '240.', desc: 'Reserved for Future Use (RFC 1112)' },
|
|
35
|
+
{ prefix: '255.255.255.255', desc: 'Limited Broadcast (RFC 919)' }
|
|
36
|
+
];
|
|
37
|
+
function checkIPv4Bogon(ip) {
|
|
38
|
+
if (ip.startsWith('100.')) {
|
|
39
|
+
const secondOctet = parseInt(ip.split('.')[1], 10);
|
|
40
|
+
if (secondOctet >= 64 && secondOctet <= 127) {
|
|
41
|
+
return { isBogon: true, type: 'Carrier-Grade NAT (RFC 6598)' };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const firstOctet = parseInt(ip.split('.')[0], 10);
|
|
45
|
+
if (firstOctet >= 224 && firstOctet <= 239) {
|
|
46
|
+
return { isBogon: true, type: 'Multicast (RFC 5771)' };
|
|
47
|
+
}
|
|
48
|
+
for (const range of IPV4_BOGON_RANGES) {
|
|
49
|
+
if (ip.startsWith(range.prefix) || ip === range.prefix.slice(0, -1)) {
|
|
50
|
+
return { isBogon: true, type: range.desc };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { isBogon: false };
|
|
54
|
+
}
|
|
55
|
+
function normalizeIPv6(ip) {
|
|
56
|
+
const lower = ip.toLowerCase();
|
|
57
|
+
if (lower.includes('.')) {
|
|
58
|
+
if (lower.startsWith('::ffff:')) {
|
|
59
|
+
return '0000:0000:0000:0000:0000:ffff:' + lower.slice(7);
|
|
60
|
+
}
|
|
61
|
+
if (lower.startsWith('::')) {
|
|
62
|
+
return '0000:0000:0000:0000:0000:0000:' + lower.slice(2);
|
|
63
|
+
}
|
|
64
|
+
return lower;
|
|
65
|
+
}
|
|
66
|
+
const parts = lower.split(':');
|
|
67
|
+
const emptyIndex = parts.findIndex((p, i) => p === '' && parts[i + 1] === '');
|
|
68
|
+
if (emptyIndex !== -1) {
|
|
69
|
+
const nonEmptyParts = parts.filter(p => p !== '');
|
|
70
|
+
const missingParts = 8 - nonEmptyParts.length;
|
|
71
|
+
const expansion = Array(missingParts).fill('0000');
|
|
72
|
+
const before = parts.slice(0, emptyIndex).filter(p => p !== '');
|
|
73
|
+
const after = parts.slice(emptyIndex).filter(p => p !== '');
|
|
74
|
+
const expanded = [...before, ...expansion, ...after];
|
|
75
|
+
return expanded.map(p => p.padStart(4, '0')).join(':');
|
|
76
|
+
}
|
|
77
|
+
if (parts[0] === '') {
|
|
78
|
+
const nonEmpty = parts.filter(p => p !== '');
|
|
79
|
+
const padding = Array(8 - nonEmpty.length).fill('0000');
|
|
80
|
+
return [...padding, ...nonEmpty].map(p => p.padStart(4, '0')).join(':');
|
|
81
|
+
}
|
|
82
|
+
return parts.map(p => p.padStart(4, '0')).join(':');
|
|
83
|
+
}
|
|
84
|
+
function checkIPv6Bogon(ip) {
|
|
85
|
+
const normalized = normalizeIPv6(ip);
|
|
86
|
+
if (normalized === '0000:0000:0000:0000:0000:0000:0000:0000') {
|
|
87
|
+
return { isBogon: true, type: 'Unspecified Address (RFC 4291)' };
|
|
88
|
+
}
|
|
89
|
+
if (normalized === '0000:0000:0000:0000:0000:0000:0000:0001') {
|
|
90
|
+
return { isBogon: true, type: 'Loopback (RFC 4291)' };
|
|
91
|
+
}
|
|
92
|
+
if (normalized.startsWith('0000:0000:0000:0000:0000:ffff:')) {
|
|
93
|
+
return { isBogon: true, type: 'IPv4-Mapped IPv6 (RFC 4291)' };
|
|
94
|
+
}
|
|
95
|
+
if (normalized.startsWith('fe8') || normalized.startsWith('fe9') ||
|
|
96
|
+
normalized.startsWith('fea') || normalized.startsWith('feb')) {
|
|
97
|
+
return { isBogon: true, type: 'Link-Local Unicast (RFC 4291)' };
|
|
98
|
+
}
|
|
99
|
+
if (normalized.startsWith('fc') || normalized.startsWith('fd')) {
|
|
100
|
+
return { isBogon: true, type: 'Unique Local Address (RFC 4193)' };
|
|
101
|
+
}
|
|
102
|
+
if (normalized.startsWith('ff')) {
|
|
103
|
+
return { isBogon: true, type: 'Multicast (RFC 4291)' };
|
|
104
|
+
}
|
|
105
|
+
if (normalized.startsWith('2001:0db8:')) {
|
|
106
|
+
return { isBogon: true, type: 'Documentation (RFC 3849)' };
|
|
107
|
+
}
|
|
108
|
+
return { isBogon: false };
|
|
109
|
+
}
|
|
110
|
+
export function isIPv6(ip) {
|
|
111
|
+
return ip.includes(':');
|
|
112
|
+
}
|
|
113
|
+
export function isBogon(ip) {
|
|
114
|
+
if (isIPv6(ip)) {
|
|
115
|
+
return checkIPv6Bogon(ip);
|
|
116
|
+
}
|
|
117
|
+
return checkIPv4Bogon(ip);
|
|
118
|
+
}
|
|
119
|
+
export function isValidIP(ip) {
|
|
120
|
+
if (!ip.includes(':')) {
|
|
121
|
+
const parts = ip.split('.');
|
|
122
|
+
if (parts.length !== 4)
|
|
123
|
+
return false;
|
|
124
|
+
return parts.every(p => {
|
|
125
|
+
const num = parseInt(p, 10);
|
|
126
|
+
return !isNaN(num) && num >= 0 && num <= 255 && p === num.toString();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const parts = ip.split(':');
|
|
130
|
+
if (parts.length < 2 || parts.length > 8)
|
|
131
|
+
return false;
|
|
132
|
+
const emptyParts = parts.filter(p => p === '').length;
|
|
133
|
+
if (emptyParts > 1 && !(emptyParts === 2 && parts[0] === '' && parts[1] === ''))
|
|
134
|
+
return false;
|
|
135
|
+
return parts.every(p => {
|
|
136
|
+
if (p === '')
|
|
137
|
+
return true;
|
|
138
|
+
if (p.includes('.'))
|
|
139
|
+
return isValidIP(p);
|
|
140
|
+
return /^[0-9a-fA-F]{1,4}$/.test(p);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
let _reader = null;
|
|
144
|
+
async function getReader() {
|
|
145
|
+
if (_reader) {
|
|
146
|
+
return _reader;
|
|
147
|
+
}
|
|
148
|
+
const dbPath = await ensureGeoIPDatabase();
|
|
149
|
+
if (!dbPath) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
_reader = await Reader.open(dbPath);
|
|
154
|
+
return _reader;
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export async function getIpInfo(ip) {
|
|
161
|
+
const ipv6 = isIPv6(ip);
|
|
162
|
+
const bogonCheck = isBogon(ip);
|
|
163
|
+
if (bogonCheck.isBogon) {
|
|
164
|
+
return {
|
|
165
|
+
ip,
|
|
166
|
+
bogon: true,
|
|
167
|
+
bogonType: bogonCheck.type,
|
|
168
|
+
isIPv6: ipv6,
|
|
169
|
+
org: bogonCheck.type
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
const reader = await getReader();
|
|
173
|
+
if (!reader) {
|
|
174
|
+
return {
|
|
175
|
+
ip,
|
|
176
|
+
isIPv6: ipv6,
|
|
177
|
+
org: 'GeoIP database not available'
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
try {
|
|
181
|
+
const result = reader.city(ip);
|
|
182
|
+
return {
|
|
183
|
+
ip,
|
|
184
|
+
city: result.city?.names?.en,
|
|
185
|
+
region: result.subdivisions?.[0]?.names?.en,
|
|
186
|
+
country: result.country?.names?.en,
|
|
187
|
+
countryCode: result.country?.isoCode,
|
|
188
|
+
continent: result.continent?.names?.en,
|
|
189
|
+
loc: result.location?.latitude && result.location?.longitude
|
|
190
|
+
? `${result.location.latitude},${result.location.longitude}`
|
|
191
|
+
: undefined,
|
|
192
|
+
timezone: result.location?.timeZone,
|
|
193
|
+
postal: result.postal?.code,
|
|
194
|
+
accuracy: result.location?.accuracyRadius,
|
|
195
|
+
isIPv6: ipv6,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
return {
|
|
200
|
+
ip,
|
|
201
|
+
isIPv6: ipv6,
|
|
202
|
+
org: 'IP not found in GeoIP database'
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
export function isGeoIPAvailable() {
|
|
207
|
+
return hasLocalGeoIPDatabase();
|
|
208
|
+
}
|
|
209
|
+
export { getGeoIPDatabasePath } from './geoip-loader.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hybrid-search.d.ts","sourceRoot":"","sources":["../../../src/mcp/search/hybrid-search.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hybrid-search.d.ts","sourceRoot":"","sources":["../../../src/mcp/search/hybrid-search.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,aAAa,EACb,kBAAkB,EAGnB,MAAM,YAAY,CAAC;AAkBpB,qBAAa,YAAY;IACvB,OAAO,CAAC,IAAI,CAAiC;IAC7C,OAAO,CAAC,IAAI,CAAoB;IAChC,OAAO,CAAC,OAAO,CAAoC;IACnD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAA+B;gBAEjC,MAAM,GAAE,kBAAuB;IAYrC,UAAU,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAmCrC,yBAAyB;IAoCjC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAsDjF,OAAO,CAAC,WAAW;IA4EnB,OAAO,CAAC,cAAc;IA8GtB,OAAO,CAAC,cAAc;IAoDtB,OAAO,CAAC,MAAM,CAAC,UAAU,CAoCtB;IAKH,OAAO,CAAC,UAAU;IAYlB,OAAO,CAAC,QAAQ;IAUhB,OAAO,CAAC,cAAc;IAmBtB,aAAa,IAAI,OAAO;IAOxB,QAAQ,IAAI;QACV,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB;IAYD,OAAO,CAAC,GAAG;CAKZ;AAKD,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,YAAY,CAE5E"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Fuse from 'fuse.js';
|
|
2
2
|
import { cosineSimilarity, combineScores, levenshtein } from './math.js';
|
|
3
|
+
import { loadEmbeddings } from '../embeddings-loader.js';
|
|
4
|
+
import { StateError } from '../../core/errors.js';
|
|
3
5
|
let cachedEmbeddings = null;
|
|
4
6
|
export class HybridSearch {
|
|
5
7
|
fuse = null;
|
|
@@ -10,7 +12,7 @@ export class HybridSearch {
|
|
|
10
12
|
config;
|
|
11
13
|
constructor(config = {}) {
|
|
12
14
|
this.config = {
|
|
13
|
-
fuzzyThreshold: config.fuzzyThreshold ?? 0.
|
|
15
|
+
fuzzyThreshold: config.fuzzyThreshold ?? 0.3,
|
|
14
16
|
fuzzyWeight: config.fuzzyWeight ?? 0.5,
|
|
15
17
|
semanticWeight: config.semanticWeight ?? 0.5,
|
|
16
18
|
debug: config.debug ?? false,
|
|
@@ -20,11 +22,11 @@ export class HybridSearch {
|
|
|
20
22
|
this.docs = docs;
|
|
21
23
|
this.fuse = new Fuse(docs, {
|
|
22
24
|
keys: [
|
|
23
|
-
{ name: 'keywords', weight:
|
|
24
|
-
{ name: 'title', weight:
|
|
25
|
-
{ name: 'section', weight:
|
|
26
|
-
{ name: 'path', weight:
|
|
27
|
-
{ name: 'content', weight: 0.
|
|
25
|
+
{ name: 'keywords', weight: 10 },
|
|
26
|
+
{ name: 'title', weight: 6 },
|
|
27
|
+
{ name: 'section', weight: 4 },
|
|
28
|
+
{ name: 'path', weight: 2 },
|
|
29
|
+
{ name: 'content', weight: 0.5 },
|
|
28
30
|
],
|
|
29
31
|
includeScore: true,
|
|
30
32
|
threshold: this.config.fuzzyThreshold,
|
|
@@ -43,27 +45,12 @@ export class HybridSearch {
|
|
|
43
45
|
this.embeddingsData = cachedEmbeddings;
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
try {
|
|
56
|
-
const fs = await import('fs');
|
|
57
|
-
const path = await import('path');
|
|
58
|
-
const embeddingsFile = path.join(path.dirname(new URL(import.meta.url).pathname), '../data/embeddings.json');
|
|
59
|
-
if (fs.existsSync(embeddingsFile)) {
|
|
60
|
-
const data = fs.readFileSync(embeddingsFile, 'utf-8');
|
|
61
|
-
this.embeddingsData = JSON.parse(data);
|
|
62
|
-
cachedEmbeddings = this.embeddingsData;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
}
|
|
48
|
+
const data = await loadEmbeddings({
|
|
49
|
+
debug: this.config.debug,
|
|
50
|
+
});
|
|
51
|
+
if (data) {
|
|
52
|
+
this.embeddingsData = data;
|
|
53
|
+
cachedEmbeddings = data;
|
|
67
54
|
}
|
|
68
55
|
}
|
|
69
56
|
if (this.embeddingsData) {
|
|
@@ -82,7 +69,10 @@ export class HybridSearch {
|
|
|
82
69
|
async search(query, options = {}) {
|
|
83
70
|
const { limit = 10, category, mode = 'hybrid', minScore = 0 } = options;
|
|
84
71
|
if (!this.initialized) {
|
|
85
|
-
throw new
|
|
72
|
+
throw new StateError('HybridSearch not initialized. Call initialize() first.', {
|
|
73
|
+
expectedState: 'initialized',
|
|
74
|
+
actualState: 'not-initialized',
|
|
75
|
+
});
|
|
86
76
|
}
|
|
87
77
|
const cleanedQuery = this.cleanQuery(query);
|
|
88
78
|
this.log(`Original query: "${query}" → Cleaned: "${cleanedQuery}"`);
|
|
@@ -121,13 +111,44 @@ export class HybridSearch {
|
|
|
121
111
|
if (category) {
|
|
122
112
|
results = results.filter((r) => r.item.category.toLowerCase().includes(category.toLowerCase()));
|
|
123
113
|
}
|
|
124
|
-
|
|
114
|
+
const queryTerms = this.tokenize(query);
|
|
115
|
+
const scored = results.slice(0, limit).map((r) => {
|
|
116
|
+
const fuseScore = r.score || 0;
|
|
117
|
+
const baseScore = 1 - fuseScore;
|
|
118
|
+
let boost = 0;
|
|
119
|
+
if (fuseScore < 0.3) {
|
|
120
|
+
const keywords = r.item.keywords || [];
|
|
121
|
+
const titleLower = r.item.title.toLowerCase();
|
|
122
|
+
for (const term of queryTerms) {
|
|
123
|
+
if (keywords.some(k => k.toLowerCase() === term)) {
|
|
124
|
+
boost += 0.15;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
for (const term of queryTerms) {
|
|
128
|
+
if (titleLower.includes(term)) {
|
|
129
|
+
boost += 0.10;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
boost = -0.3;
|
|
135
|
+
}
|
|
136
|
+
return {
|
|
137
|
+
item: r.item,
|
|
138
|
+
baseScore,
|
|
139
|
+
boost,
|
|
140
|
+
finalScore: baseScore + boost,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
scored.sort((a, b) => b.finalScore - a.finalScore);
|
|
144
|
+
const maxScore = scored[0]?.finalScore || 1;
|
|
145
|
+
return scored.map((r) => ({
|
|
125
146
|
id: r.item.id,
|
|
126
147
|
path: r.item.path,
|
|
127
148
|
title: r.item.title,
|
|
128
149
|
content: r.item.content,
|
|
129
150
|
snippet: this.extractSnippet(r.item.content, query),
|
|
130
|
-
score: 1
|
|
151
|
+
score: Math.max(0, Math.min(1, r.finalScore / maxScore)),
|
|
131
152
|
source: 'fuzzy',
|
|
132
153
|
}));
|
|
133
154
|
}
|
|
@@ -272,14 +293,14 @@ export class HybridSearch {
|
|
|
272
293
|
'sim', 'nao', 'ja', 'ainda', 'sempre', 'nunca', 'tambem', 'so', 'apenas',
|
|
273
294
|
'muito', 'pouco', 'mais', 'menos', 'bem', 'mal', 'assim', 'entao', 'logo',
|
|
274
295
|
'yo', 'hey', 'oi', 'ola', 'bom', 'boa', 'obrigado', 'por favor',
|
|
275
|
-
'configure', 'configuro', 'configurar', 'configurando',
|
|
276
|
-
'use', 'usar', 'using', '
|
|
277
|
-
'create', 'criar', 'creating', 'criando',
|
|
278
|
-
'setup', 'setar', 'setting', 'setando',
|
|
279
|
-
'add', 'adicionar', 'adding', 'adicionando',
|
|
280
|
-
'get', 'getting', 'pegar', 'pegando',
|
|
281
|
-
'set', 'setting', 'definir', 'definindo',
|
|
282
|
-
'make', 'making', 'fazer', 'fazendo',
|
|
296
|
+
'configure', 'configuro', 'configurar', 'configurando', 'configura',
|
|
297
|
+
'use', 'usar', 'using', 'uso', 'usa',
|
|
298
|
+
'create', 'criar', 'creating', 'criando', 'cria', 'crio',
|
|
299
|
+
'setup', 'setar', 'setting', 'setando', 'seta', 'seto',
|
|
300
|
+
'add', 'adicionar', 'adding', 'adicionando', 'adiciona', 'adiciono',
|
|
301
|
+
'get', 'getting', 'pegar', 'pegando', 'pega', 'pego',
|
|
302
|
+
'set', 'setting', 'definir', 'definindo', 'define', 'defino',
|
|
303
|
+
'make', 'making', 'fazer', 'fazendo', 'faz', 'faço', 'faco',
|
|
283
304
|
]);
|
|
284
305
|
cleanQuery(query) {
|
|
285
306
|
const words = query
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/mcp/search/math.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/mcp/search/math.ts"],"names":[],"mappings":"AAsBA,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAwBjE;AAgBD,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAyCxD;AAeD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAI7D;AAmBD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,SAAK,GAAG,MAAM,CAEpE;AAWD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,SAAK,GAAG,MAAM,CAK5E"}
|
package/dist/mcp/search/math.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { ValidationError } from '../../core/errors.js';
|
|
1
2
|
export function cosineSimilarity(a, b) {
|
|
2
3
|
if (a.length !== b.length) {
|
|
3
|
-
throw new
|
|
4
|
+
throw new ValidationError(`Vector length mismatch: ${a.length} vs ${b.length}`, {
|
|
5
|
+
field: 'vectorLength',
|
|
6
|
+
value: { a: a.length, b: b.length },
|
|
7
|
+
});
|
|
4
8
|
}
|
|
5
9
|
if (a.length === 0) {
|
|
6
10
|
return 0;
|
package/dist/mcp/server.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ export declare class MCPServer {
|
|
|
21
21
|
private sseClients;
|
|
22
22
|
private initialized;
|
|
23
23
|
constructor(options?: MCPServerOptions);
|
|
24
|
+
private indexReady;
|
|
25
|
+
private ensureIndexReady;
|
|
24
26
|
private log;
|
|
25
27
|
private findDocsPath;
|
|
26
28
|
private findExamplesPath;
|
|
@@ -49,6 +51,10 @@ export declare class MCPServer {
|
|
|
49
51
|
private getCodeExamples;
|
|
50
52
|
private getApiSchema;
|
|
51
53
|
private getSuggestions;
|
|
54
|
+
private ipLookupResult;
|
|
55
|
+
private ipLookupPending;
|
|
56
|
+
private ipLookup;
|
|
57
|
+
private formatIpResult;
|
|
52
58
|
private getFeatureConfig;
|
|
53
59
|
private getCombinedConfig;
|
|
54
60
|
handleRequest(req: JsonRpcRequest): JsonRpcResponse;
|
package/dist/mcp/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAMhB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAMhB,MAAM,YAAY,CAAC;AAIpB,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAExD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;AA0CD,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,MAAM,CAAC,CAAkC;IACjD,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,UAAU,CAAkC;IACpD,OAAO,CAAC,WAAW,CAAS;gBAEhB,OAAO,GAAE,gBAAqB;IAsB1C,OAAO,CAAC,UAAU,CAA8B;YAKlC,gBAAgB;IAO9B,OAAO,CAAC,GAAG;IAUX,OAAO,CAAC,YAAY;IAyBpB,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,WAAW;YAwBL,UAAU;YAoBV,SAAS;IAiCvB,OAAO,CAAC,iBAAiB;IA6BzB,OAAO,CAAC,gBAAgB;IAqCxB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,YAAY;IA0BpB,OAAO,CAAC,eAAe;IA4BvB,OAAO,CAAC,mBAAmB;IA6B3B,OAAO,CAAC,oBAAoB;IA8B5B,OAAO,CAAC,sBAAsB;IA0E9B,OAAO,CAAC,wBAAwB;IAoBhC,OAAO,CAAC,OAAO;IAyBf,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,QAAQ;IAgIhB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,cAAc;IAsBtB,OAAO,CAAC,UAAU;IA0ElB,OAAO,CAAC,cAAc;IA6BtB,OAAO,CAAC,MAAM;IAmCd,OAAO,CAAC,eAAe;IAgDvB,OAAO,CAAC,YAAY;IAmEpB,OAAO,CAAC,cAAc;IAmFtB,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,eAAe,CAA8B;IAErD,OAAO,CAAC,QAAQ;IA+DhB,OAAO,CAAC,cAAc;IA6CtB,OAAO,CAAC,gBAAgB;IA+DxB,OAAO,CAAC,iBAAiB;IAuCzB,aAAa,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe;IA8DnD,OAAO,CAAC,gBAAgB;YAOV,UAAU;YAgCV,SAAS;YA8CT,QAAQ;IAuFhB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAe3B,OAAO,IAAI,MAAM;IAIjB,YAAY,IAAI,MAAM;IAItB,gBAAgB,IAAI,MAAM;IAI1B,aAAa,IAAI,MAAM;IAIvB,YAAY,IAAI,gBAAgB;CAGjC;AAoBD,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAErE"}
|
package/dist/mcp/server.js
CHANGED
|
@@ -4,6 +4,8 @@ import { join, relative, extname, basename, dirname } from 'path';
|
|
|
4
4
|
import { createInterface } from 'readline';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { createHybridSearch } from './search/index.js';
|
|
7
|
+
import { UnsupportedError } from '../core/errors.js';
|
|
8
|
+
import { getIpInfo, isValidIP, isGeoIPAvailable, isBogon, isIPv6 } from './ip-intel.js';
|
|
7
9
|
export class MCPServer {
|
|
8
10
|
options;
|
|
9
11
|
server;
|
|
@@ -26,7 +28,13 @@ export class MCPServer {
|
|
|
26
28
|
toolsFilter: options.toolsFilter || [],
|
|
27
29
|
};
|
|
28
30
|
this.hybridSearch = createHybridSearch({ debug: this.options.debug });
|
|
29
|
-
|
|
31
|
+
}
|
|
32
|
+
indexReady = null;
|
|
33
|
+
async ensureIndexReady() {
|
|
34
|
+
if (!this.indexReady) {
|
|
35
|
+
this.indexReady = this.buildIndex();
|
|
36
|
+
}
|
|
37
|
+
await this.indexReady;
|
|
30
38
|
}
|
|
31
39
|
log(message, data) {
|
|
32
40
|
if (this.options.debug) {
|
|
@@ -499,6 +507,20 @@ export class MCPServer {
|
|
|
499
507
|
required: ['useCase'],
|
|
500
508
|
},
|
|
501
509
|
},
|
|
510
|
+
{
|
|
511
|
+
name: 'ip_lookup',
|
|
512
|
+
description: 'Get geolocation and network information for an IP address using the local MaxMind GeoLite2 database. Returns city, country, coordinates, timezone, and more. Works offline after first download.',
|
|
513
|
+
inputSchema: {
|
|
514
|
+
type: 'object',
|
|
515
|
+
properties: {
|
|
516
|
+
ip: {
|
|
517
|
+
type: 'string',
|
|
518
|
+
description: 'IPv4 or IPv6 address to lookup (e.g., "8.8.8.8", "2001:4860:4860::8888")',
|
|
519
|
+
},
|
|
520
|
+
},
|
|
521
|
+
required: ['ip'],
|
|
522
|
+
},
|
|
523
|
+
},
|
|
502
524
|
];
|
|
503
525
|
if (this.options.toolsFilter.length > 0) {
|
|
504
526
|
return allTools.filter(tool => this.isToolEnabled(tool.name));
|
|
@@ -540,6 +562,8 @@ export class MCPServer {
|
|
|
540
562
|
return this.getApiSchema(args);
|
|
541
563
|
case 'suggest':
|
|
542
564
|
return this.getSuggestions(args);
|
|
565
|
+
case 'ip_lookup':
|
|
566
|
+
return this.ipLookup(args);
|
|
543
567
|
default:
|
|
544
568
|
return {
|
|
545
569
|
content: [{ type: 'text', text: `Unknown tool: ${name}` }],
|
|
@@ -814,6 +838,99 @@ export class MCPServer {
|
|
|
814
838
|
}],
|
|
815
839
|
};
|
|
816
840
|
}
|
|
841
|
+
ipLookupResult = null;
|
|
842
|
+
ipLookupPending = null;
|
|
843
|
+
ipLookup(args) {
|
|
844
|
+
const ip = String(args.ip || '').trim();
|
|
845
|
+
if (!ip) {
|
|
846
|
+
return {
|
|
847
|
+
content: [{ type: 'text', text: 'Error: ip is required' }],
|
|
848
|
+
isError: true,
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
if (!isValidIP(ip)) {
|
|
852
|
+
return {
|
|
853
|
+
content: [{ type: 'text', text: `Error: "${ip}" is not a valid IP address` }],
|
|
854
|
+
isError: true,
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
const bogonCheck = isBogon(ip);
|
|
858
|
+
const ipv6 = isIPv6(ip);
|
|
859
|
+
if (bogonCheck.isBogon) {
|
|
860
|
+
return {
|
|
861
|
+
content: [{
|
|
862
|
+
type: 'text',
|
|
863
|
+
text: this.formatIpResult({
|
|
864
|
+
ip,
|
|
865
|
+
bogon: true,
|
|
866
|
+
bogonType: bogonCheck.type,
|
|
867
|
+
isIPv6: ipv6,
|
|
868
|
+
org: bogonCheck.type,
|
|
869
|
+
}),
|
|
870
|
+
}],
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
if (!isGeoIPAvailable()) {
|
|
874
|
+
getIpInfo(ip).catch(() => { });
|
|
875
|
+
return {
|
|
876
|
+
content: [{
|
|
877
|
+
type: 'text',
|
|
878
|
+
text: `# GeoIP Database Required\n\nThe MaxMind GeoLite2 database is being downloaded (~70MB).\n\nPlease try again in a few seconds, or use the CLI:\n\n\`\`\`bash\nrek ip ${ip}\n\`\`\``,
|
|
879
|
+
}],
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
this.ipLookupPending = getIpInfo(ip).then(info => {
|
|
883
|
+
this.ipLookupResult = info;
|
|
884
|
+
});
|
|
885
|
+
return {
|
|
886
|
+
content: [{
|
|
887
|
+
type: 'text',
|
|
888
|
+
text: `# IP Intelligence: ${ip}\n\n**Status:** Public ${ipv6 ? 'IPv6' : 'IPv4'} Address\n\nFor detailed geolocation data (city, country, coordinates, timezone), use the CLI:\n\n\`\`\`bash\nrek ip ${ip}\n\`\`\`\n\n_Note: The MCP server uses a synchronous protocol. Full GeoIP lookups are available via CLI._`,
|
|
889
|
+
}],
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
formatIpResult(info) {
|
|
893
|
+
const lines = [`# IP Intelligence: ${info.ip}\n`];
|
|
894
|
+
if (info.bogon) {
|
|
895
|
+
lines.push(`**Type:** Private/Reserved IP (Bogon)`);
|
|
896
|
+
lines.push(`**Category:** ${info.bogonType}`);
|
|
897
|
+
lines.push(`\nThis is a non-routable IP address used for internal networks or special purposes.`);
|
|
898
|
+
}
|
|
899
|
+
else {
|
|
900
|
+
if (info.city || info.region || info.country) {
|
|
901
|
+
const location = [info.city, info.region, info.country].filter(Boolean).join(', ');
|
|
902
|
+
lines.push(`**Location:** ${location}`);
|
|
903
|
+
}
|
|
904
|
+
if (info.countryCode) {
|
|
905
|
+
lines.push(`**Country Code:** ${info.countryCode}`);
|
|
906
|
+
}
|
|
907
|
+
if (info.continent) {
|
|
908
|
+
lines.push(`**Continent:** ${info.continent}`);
|
|
909
|
+
}
|
|
910
|
+
if (info.loc) {
|
|
911
|
+
lines.push(`**Coordinates:** ${info.loc}`);
|
|
912
|
+
}
|
|
913
|
+
if (info.timezone) {
|
|
914
|
+
lines.push(`**Timezone:** ${info.timezone}`);
|
|
915
|
+
}
|
|
916
|
+
if (info.postal) {
|
|
917
|
+
lines.push(`**Postal Code:** ${info.postal}`);
|
|
918
|
+
}
|
|
919
|
+
if (info.org) {
|
|
920
|
+
lines.push(`**Organization:** ${info.org}`);
|
|
921
|
+
}
|
|
922
|
+
if (info.asn) {
|
|
923
|
+
lines.push(`**ASN:** ${info.asn}`);
|
|
924
|
+
}
|
|
925
|
+
if (info.accuracy) {
|
|
926
|
+
lines.push(`**Accuracy:** ~${info.accuracy} km`);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
if (info.isIPv6) {
|
|
930
|
+
lines.push(`\n_IPv6 Address_`);
|
|
931
|
+
}
|
|
932
|
+
return lines.join('\n');
|
|
933
|
+
}
|
|
817
934
|
getFeatureConfig(feature) {
|
|
818
935
|
const configs = {
|
|
819
936
|
retry: `retry: {
|
|
@@ -1112,6 +1229,7 @@ const client = createClient({
|
|
|
1112
1229
|
});
|
|
1113
1230
|
}
|
|
1114
1231
|
async start() {
|
|
1232
|
+
await this.ensureIndexReady();
|
|
1115
1233
|
switch (this.options.transport) {
|
|
1116
1234
|
case 'stdio':
|
|
1117
1235
|
return this.startStdio();
|
|
@@ -1120,7 +1238,9 @@ const client = createClient({
|
|
|
1120
1238
|
case 'sse':
|
|
1121
1239
|
return this.startSSE();
|
|
1122
1240
|
default:
|
|
1123
|
-
throw new
|
|
1241
|
+
throw new UnsupportedError(`Unknown transport: ${this.options.transport}`, {
|
|
1242
|
+
feature: this.options.transport,
|
|
1243
|
+
});
|
|
1124
1244
|
}
|
|
1125
1245
|
}
|
|
1126
1246
|
async stop() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { gzip, deflate, brotliCompress } from 'node:zlib';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import {
|
|
3
|
+
import { UnsupportedError } from '../core/errors.js';
|
|
4
4
|
const gzipAsync = promisify(gzip);
|
|
5
5
|
const deflateAsync = promisify(deflate);
|
|
6
6
|
const brotliAsync = promisify(brotliCompress);
|
|
@@ -72,7 +72,9 @@ async function compress(data, algorithm) {
|
|
|
72
72
|
case 'br':
|
|
73
73
|
return await brotliAsync(data);
|
|
74
74
|
default:
|
|
75
|
-
throw new
|
|
75
|
+
throw new UnsupportedError(`Unsupported compression algorithm: ${algorithm}`, {
|
|
76
|
+
feature: algorithm,
|
|
77
|
+
});
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
export function compression(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"har-player.d.ts","sourceRoot":"","sources":["../../src/plugins/har-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6C,MAAM,mBAAmB,CAAC;AAKtF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAgBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"har-player.d.ts","sourceRoot":"","sources":["../../src/plugins/har-player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6C,MAAM,mBAAmB,CAAC;AAKtF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAgBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAgF3D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { HttpResponse } from '../core/response.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ParseError, NotFoundError } from '../core/errors.js';
|
|
4
4
|
export function harPlayer(options) {
|
|
5
5
|
let entries = [];
|
|
6
6
|
try {
|
|
@@ -9,11 +9,9 @@ export function harPlayer(options) {
|
|
|
9
9
|
entries = har.log.entries;
|
|
10
10
|
}
|
|
11
11
|
catch (err) {
|
|
12
|
-
throw new
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
'Verify the HAR file has the correct structure (log.entries).'
|
|
16
|
-
]);
|
|
12
|
+
throw new ParseError(`Failed to load HAR file: ${options.path}`, {
|
|
13
|
+
format: 'har',
|
|
14
|
+
});
|
|
17
15
|
}
|
|
18
16
|
const matchEntry = (req, entry) => {
|
|
19
17
|
if (req.method !== entry.request.method)
|
|
@@ -48,11 +46,10 @@ export function harPlayer(options) {
|
|
|
48
46
|
return new HttpResponse(nativeRes);
|
|
49
47
|
}
|
|
50
48
|
if (options.strict) {
|
|
51
|
-
throw new
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
]);
|
|
49
|
+
throw new NotFoundError(`[Recker HAR Player] No matching recording found for ${req.method} ${req.url}`, {
|
|
50
|
+
resource: `${req.method} ${req.url}`,
|
|
51
|
+
request: req,
|
|
52
|
+
});
|
|
56
53
|
}
|
|
57
54
|
return next(req);
|
|
58
55
|
};
|