@easynet/agent-tool 1.0.46 → 1.0.48
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 +31 -105
- package/dist/api/extension/groupPrefix.d.ts.map +1 -1
- package/dist/api/main.cjs +19 -20
- package/dist/api/main.js +2 -3
- package/dist/api/runtimeFromConfig.d.ts.map +1 -1
- package/dist/{chunk-5GFSI7ZJ.js → chunk-2ZPDD7ZO.js} +722 -280
- package/dist/chunk-2ZPDD7ZO.js.map +1 -0
- package/dist/{chunk-SRTE2OUH.js → chunk-64ZQQV5C.js} +79 -75
- package/dist/chunk-64ZQQV5C.js.map +1 -0
- package/dist/{chunk-XC7KPJLZ.cjs → chunk-A5B6Q6EG.cjs} +710 -295
- package/dist/chunk-A5B6Q6EG.cjs.map +1 -0
- package/dist/{chunk-QW27JAFS.cjs → chunk-IAEVDXWS.cjs} +15 -16
- package/dist/chunk-IAEVDXWS.cjs.map +1 -0
- package/dist/{chunk-H66TKSG4.js → chunk-KYBIKD5R.js} +5 -5
- package/dist/chunk-KYBIKD5R.js.map +1 -0
- package/dist/{chunk-LG5K7WOK.cjs → chunk-MDPU7EIO.cjs} +83 -87
- package/dist/chunk-MDPU7EIO.cjs.map +1 -0
- package/dist/index.cjs +195 -413
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -63
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +171 -281
- package/dist/index.js.map +1 -1
- package/dist/utils/cli/index.cjs +16 -17
- package/dist/utils/cli/index.cjs.map +1 -1
- package/dist/utils/cli/index.js +3 -4
- package/dist/utils/cli/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5GFSI7ZJ.js.map +0 -1
- package/dist/chunk-H66TKSG4.js.map +0 -1
- package/dist/chunk-LG5K7WOK.cjs.map +0 -1
- package/dist/chunk-O4XXNLNE.cjs +0 -480
- package/dist/chunk-O4XXNLNE.cjs.map +0 -1
- package/dist/chunk-QW27JAFS.cjs.map +0 -1
- package/dist/chunk-SRTE2OUH.js.map +0 -1
- package/dist/chunk-XC7KPJLZ.cjs.map +0 -1
- package/dist/chunk-YDYG4HF5.js +0 -474
- package/dist/chunk-YDYG4HF5.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,194 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
import { scanForTools
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
export { BudgetManager, EventLog, Metrics, PTCRuntime, PolicyDeniedError, PolicyEngine, SchemaValidationError, SchemaValidator, Tracing, buildEvidence, createLogger, ensurePackageInCache, expandToolDescriptorsToRegistryNames, getPackageEntryPath, importFromCache, isNpmToolDescriptor, loadToolConfig, normalizeToolList, npmDescriptorToRegistryPrefix, parseNpmToolDescriptor, resolveLatestVersionFromRegistry, resolveNpmToolDescriptor, resolveSandboxedPath, resolveToolDescriptor, sanitizeForLog, setSandboxValidationEnabled, summarizeForLog } from './chunk-5GFSI7ZJ.js';
|
|
1
|
+
export { createAgentTools, createLangChainToolsAsync } from './chunk-KYBIKD5R.js';
|
|
2
|
+
import { scanForTools } from './chunk-64ZQQV5C.js';
|
|
3
|
+
export { buildFunctionToTool, buildMcpPackage, initProject, runGeneratedMCP, runMcpServer, scan, scanForTools } from './chunk-64ZQQV5C.js';
|
|
4
|
+
export { PTCRuntime, createMCPServer, createMCPServerStreamableHttp, createMCPStreamableHttpHandler, createHttpService as createOpenAPIServer, createRuntimeFromConfig, createRuntimeFromConfigSync, loadToolConfig, resolveSandboxedPath2 as resolveSandboxedPath, runMCPServerOverStdio, setSandboxValidationEnabled } from './chunk-2ZPDD7ZO.js';
|
|
6
5
|
import { createTaggedError } from './chunk-ZRHPGW7W.js';
|
|
7
|
-
export { ToolRegistry, createTaggedError
|
|
8
|
-
import { createToolSpec
|
|
6
|
+
export { ToolRegistry, createTaggedError } from './chunk-ZRHPGW7W.js';
|
|
7
|
+
import { createToolSpec } from './chunk-KDB3MY2H.js';
|
|
9
8
|
export { DEFAULT_INPUT_SCHEMA, DEFAULT_OUTPUT_SCHEMA, createToolSpec, normalizeToolName } from './chunk-KDB3MY2H.js';
|
|
10
9
|
import './chunk-NTWOVFEY.js';
|
|
11
|
-
import { lookup } from 'dns/promises';
|
|
12
10
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
13
|
-
import path6
|
|
11
|
+
import path6 from 'path';
|
|
14
12
|
import { pathToFileURL, fileURLToPath } from 'url';
|
|
15
13
|
import { existsSync, readFileSync, statSync, mkdirSync, writeFileSync, readdirSync, copyFileSync } from 'fs';
|
|
16
14
|
import yaml from 'js-yaml';
|
|
15
|
+
import { lookup } from 'dns/promises';
|
|
17
16
|
|
|
18
|
-
async function validateUrl(url, options) {
|
|
19
|
-
let parsed;
|
|
20
|
-
try {
|
|
21
|
-
parsed = new URL(url);
|
|
22
|
-
} catch {
|
|
23
|
-
throw createTaggedError(
|
|
24
|
-
"HTTP_DISALLOWED_HOST",
|
|
25
|
-
`Invalid URL: ${url}`,
|
|
26
|
-
{ url }
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
30
|
-
throw createTaggedError(
|
|
31
|
-
"HTTP_DISALLOWED_HOST",
|
|
32
|
-
`Protocol not allowed: ${parsed.protocol}. Only http: and https: are supported.`,
|
|
33
|
-
{ url, protocol: parsed.protocol }
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
const hostname = parsed.hostname;
|
|
37
|
-
if (!isHostAllowed(hostname, options.allowedHosts)) {
|
|
38
|
-
throw createTaggedError(
|
|
39
|
-
"HTTP_DISALLOWED_HOST",
|
|
40
|
-
`Host "${hostname}" is not in the allowed hosts list`,
|
|
41
|
-
{ url, hostname, allowedHosts: options.allowedHosts }
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
if (isHostBlocked(hostname, options.blockedHosts)) {
|
|
45
|
-
throw createTaggedError(
|
|
46
|
-
"HTTP_DISALLOWED_HOST",
|
|
47
|
-
`Host "${hostname}" is in the blocked hosts list`,
|
|
48
|
-
{ url, hostname, blockedHosts: options.blockedHosts }
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const { address } = await lookup(hostname);
|
|
53
|
-
if (isIpInBlockedCidrs(address, options.blockedCidrs)) {
|
|
54
|
-
throw createTaggedError(
|
|
55
|
-
"HTTP_DISALLOWED_HOST",
|
|
56
|
-
`Host "${hostname}" resolves to blocked IP: ${address}`,
|
|
57
|
-
{ url, hostname, resolvedIp: address }
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
} catch (err) {
|
|
61
|
-
if (err instanceof Error && err.kind === "HTTP_DISALLOWED_HOST") {
|
|
62
|
-
throw err;
|
|
63
|
-
}
|
|
64
|
-
throw createTaggedError(
|
|
65
|
-
"HTTP_DISALLOWED_HOST",
|
|
66
|
-
`DNS resolution failed for host "${hostname}": ${err instanceof Error ? err.message : String(err)}`,
|
|
67
|
-
{ url, hostname }
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
return parsed;
|
|
71
|
-
}
|
|
72
|
-
function isHostAllowed(hostname, allowedHosts) {
|
|
73
|
-
for (const pattern of allowedHosts) {
|
|
74
|
-
if (pattern === "*") {
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
if (pattern.startsWith("*.")) {
|
|
78
|
-
const suffix = pattern.slice(1);
|
|
79
|
-
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
} else if (hostname === pattern) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
function isHostBlocked(hostname, blockedHosts) {
|
|
89
|
-
for (const pattern of blockedHosts) {
|
|
90
|
-
if (pattern === "*") {
|
|
91
|
-
return true;
|
|
92
|
-
}
|
|
93
|
-
if (pattern.startsWith("*.")) {
|
|
94
|
-
const suffix = pattern.slice(1);
|
|
95
|
-
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
} else if (hostname === pattern) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
function isIpInBlockedCidrs(ip, cidrs) {
|
|
105
|
-
const normalizedIp = normalizeIp(ip);
|
|
106
|
-
if (!normalizedIp) return false;
|
|
107
|
-
for (const cidr of cidrs) {
|
|
108
|
-
if (cidr.includes(":")) {
|
|
109
|
-
if (!ip.includes(":")) continue;
|
|
110
|
-
if (isIpv6InCidr(ip, cidr)) return true;
|
|
111
|
-
} else {
|
|
112
|
-
if (isIpv4InCidr(normalizedIp, cidr)) return true;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
function normalizeIp(ip) {
|
|
118
|
-
if (ip.startsWith("::ffff:")) {
|
|
119
|
-
return ip.slice(7);
|
|
120
|
-
}
|
|
121
|
-
if (/^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
|
|
122
|
-
return ip;
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
function isIpv4InCidr(ip, cidr) {
|
|
127
|
-
const [cidrIp, prefixStr] = cidr.split("/");
|
|
128
|
-
if (!cidrIp || !prefixStr) return false;
|
|
129
|
-
const prefix = parseInt(prefixStr, 10);
|
|
130
|
-
if (isNaN(prefix) || prefix < 0 || prefix > 32) return false;
|
|
131
|
-
const ipNum = ipv4ToNum(ip);
|
|
132
|
-
const cidrNum = ipv4ToNum(cidrIp);
|
|
133
|
-
if (ipNum === null || cidrNum === null) return false;
|
|
134
|
-
const mask = prefix === 0 ? 0 : -1 << 32 - prefix >>> 0;
|
|
135
|
-
return (ipNum & mask) === (cidrNum & mask);
|
|
136
|
-
}
|
|
137
|
-
function ipv4ToNum(ip) {
|
|
138
|
-
const parts = ip.split(".");
|
|
139
|
-
if (parts.length !== 4) return null;
|
|
140
|
-
let num = 0;
|
|
141
|
-
for (const part of parts) {
|
|
142
|
-
const n = parseInt(part, 10);
|
|
143
|
-
if (isNaN(n) || n < 0 || n > 255) return null;
|
|
144
|
-
num = num << 8 | n;
|
|
145
|
-
}
|
|
146
|
-
return num >>> 0;
|
|
147
|
-
}
|
|
148
|
-
function isIpv6InCidr(ip, cidr) {
|
|
149
|
-
const [cidrIp, prefixStr] = cidr.split("/");
|
|
150
|
-
if (!cidrIp || !prefixStr) return false;
|
|
151
|
-
const prefix = parseInt(prefixStr, 10);
|
|
152
|
-
if (isNaN(prefix)) return false;
|
|
153
|
-
const ipBytes = expandIpv6(ip);
|
|
154
|
-
const cidrBytes = expandIpv6(cidrIp);
|
|
155
|
-
if (!ipBytes || !cidrBytes) return false;
|
|
156
|
-
const fullBytes = Math.floor(prefix / 8);
|
|
157
|
-
for (let i = 0; i < fullBytes && i < 16; i++) {
|
|
158
|
-
if (ipBytes[i] !== cidrBytes[i]) return false;
|
|
159
|
-
}
|
|
160
|
-
const remainingBits = prefix % 8;
|
|
161
|
-
if (remainingBits > 0 && fullBytes < 16) {
|
|
162
|
-
const mask = -1 << 8 - remainingBits & 255;
|
|
163
|
-
if ((ipBytes[fullBytes] & mask) !== (cidrBytes[fullBytes] & mask)) return false;
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
}
|
|
167
|
-
function expandIpv6(ip) {
|
|
168
|
-
const zoneIdx = ip.indexOf("%");
|
|
169
|
-
if (zoneIdx !== -1) ip = ip.slice(0, zoneIdx);
|
|
170
|
-
const parts = ip.split("::");
|
|
171
|
-
if (parts.length > 2) return null;
|
|
172
|
-
const bytes = new Array(16).fill(0);
|
|
173
|
-
const expandGroup = (group) => {
|
|
174
|
-
if (!group) return [];
|
|
175
|
-
return group.split(":").flatMap((hex) => {
|
|
176
|
-
const val = parseInt(hex || "0", 16);
|
|
177
|
-
return [val >> 8 & 255, val & 255];
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
if (parts.length === 1) {
|
|
181
|
-
const expanded = expandGroup(parts[0]);
|
|
182
|
-
if (expanded.length !== 16) return null;
|
|
183
|
-
return expanded;
|
|
184
|
-
}
|
|
185
|
-
const left = expandGroup(parts[0]);
|
|
186
|
-
const right = expandGroup(parts[1]);
|
|
187
|
-
if (left.length + right.length > 16) return null;
|
|
188
|
-
for (let i = 0; i < left.length; i++) bytes[i] = left[i];
|
|
189
|
-
for (let i = 0; i < right.length; i++) bytes[16 - right.length + i] = right[i];
|
|
190
|
-
return bytes;
|
|
191
|
-
}
|
|
192
17
|
function createContextRunner() {
|
|
193
18
|
const storage = new AsyncLocalStorage();
|
|
194
19
|
return {
|
|
@@ -510,122 +335,187 @@ function overrideWithConfig(defaults, config) {
|
|
|
510
335
|
function getGroupNamePrefixes(options) {
|
|
511
336
|
const { groups, only, groupPrefixMap } = options;
|
|
512
337
|
const onlySet = only?.length ? new Set(only) : null;
|
|
513
|
-
const namePrefixes = !onlySet && groups?.length ? groups.map((g) => groupPrefixMap[g]).filter(
|
|
338
|
+
const namePrefixes = !onlySet && groups?.length ? groups.map((g) => groupPrefixMap[g]).filter((x) => x != null) : void 0;
|
|
514
339
|
return {
|
|
515
340
|
...onlySet ? { only: Array.from(onlySet) } : {},
|
|
516
341
|
...namePrefixes?.length ? { namePrefixes } : {}
|
|
517
342
|
};
|
|
518
343
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
344
|
+
async function validateUrl(url, options) {
|
|
345
|
+
let parsed;
|
|
346
|
+
try {
|
|
347
|
+
parsed = new URL(url);
|
|
348
|
+
} catch {
|
|
349
|
+
throw createTaggedError(
|
|
350
|
+
"HTTP_DISALLOWED_HOST",
|
|
351
|
+
`Invalid URL: ${url}`,
|
|
352
|
+
{ url }
|
|
353
|
+
);
|
|
525
354
|
}
|
|
526
|
-
if (
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
355
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
356
|
+
throw createTaggedError(
|
|
357
|
+
"HTTP_DISALLOWED_HOST",
|
|
358
|
+
`Protocol not allowed: ${parsed.protocol}. Only http: and https: are supported.`,
|
|
359
|
+
{ url, protocol: parsed.protocol }
|
|
360
|
+
);
|
|
532
361
|
}
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
resultValue = JSON.parse(text);
|
|
541
|
-
} catch {
|
|
542
|
-
}
|
|
543
|
-
return { result: resultValue, raw: result };
|
|
362
|
+
const hostname = parsed.hostname;
|
|
363
|
+
if (!isHostAllowed(hostname, options.allowedHosts)) {
|
|
364
|
+
throw createTaggedError(
|
|
365
|
+
"HTTP_DISALLOWED_HOST",
|
|
366
|
+
`Host "${hostname}" is not in the allowed hosts list`,
|
|
367
|
+
{ url, hostname, allowedHosts: options.allowedHosts }
|
|
368
|
+
);
|
|
544
369
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
throw new Error(
|
|
551
|
-
`MCP stdio requires connectionInfo.type "stdio" and command; got type=${connectionInfo.type}`
|
|
370
|
+
if (isHostBlocked(hostname, options.blockedHosts)) {
|
|
371
|
+
throw createTaggedError(
|
|
372
|
+
"HTTP_DISALLOWED_HOST",
|
|
373
|
+
`Host "${hostname}" is in the blocked hosts list`,
|
|
374
|
+
{ url, hostname, blockedHosts: options.blockedHosts }
|
|
552
375
|
);
|
|
553
376
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
377
|
+
try {
|
|
378
|
+
const { address } = await lookup(hostname);
|
|
379
|
+
if (isIpInBlockedCidrs(address, options.blockedCidrs)) {
|
|
380
|
+
throw createTaggedError(
|
|
381
|
+
"HTTP_DISALLOWED_HOST",
|
|
382
|
+
`Host "${hostname}" resolves to blocked IP: ${address}`,
|
|
383
|
+
{ url, hostname, resolvedIp: address }
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
} catch (err) {
|
|
387
|
+
if (err instanceof Error && err.kind === "HTTP_DISALLOWED_HOST") {
|
|
388
|
+
throw err;
|
|
389
|
+
}
|
|
390
|
+
throw createTaggedError(
|
|
391
|
+
"HTTP_DISALLOWED_HOST",
|
|
392
|
+
`DNS resolution failed for host "${hostname}": ${err instanceof Error ? err.message : String(err)}`,
|
|
393
|
+
{ url, hostname }
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
return parsed;
|
|
569
397
|
}
|
|
570
|
-
function
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
398
|
+
function isHostAllowed(hostname, allowedHosts) {
|
|
399
|
+
for (const pattern of allowedHosts) {
|
|
400
|
+
if (pattern === "*") {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
if (pattern.startsWith("*.")) {
|
|
404
|
+
const suffix = pattern.slice(1);
|
|
405
|
+
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
} else if (hostname === pattern) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
580
413
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
};
|
|
595
|
-
this.connections.set(toolName, info);
|
|
596
|
-
return info;
|
|
414
|
+
function isHostBlocked(hostname, blockedHosts) {
|
|
415
|
+
for (const pattern of blockedHosts) {
|
|
416
|
+
if (pattern === "*") {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
if (pattern.startsWith("*.")) {
|
|
420
|
+
const suffix = pattern.slice(1);
|
|
421
|
+
if (hostname.endsWith(suffix) || hostname === pattern.slice(2)) {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
} else if (hostname === pattern) {
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
597
427
|
}
|
|
598
|
-
|
|
599
|
-
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
function isIpInBlockedCidrs(ip, cidrs) {
|
|
431
|
+
const normalizedIp = normalizeIp(ip);
|
|
432
|
+
if (!normalizedIp) return false;
|
|
433
|
+
for (const cidr of cidrs) {
|
|
434
|
+
if (cidr.includes(":")) {
|
|
435
|
+
if (!ip.includes(":")) continue;
|
|
436
|
+
if (isIpv6InCidr(ip, cidr)) return true;
|
|
437
|
+
} else {
|
|
438
|
+
if (isIpv4InCidr(normalizedIp, cidr)) return true;
|
|
439
|
+
}
|
|
600
440
|
}
|
|
601
|
-
|
|
602
|
-
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
function normalizeIp(ip) {
|
|
444
|
+
if (ip.startsWith("::ffff:")) {
|
|
445
|
+
return ip.slice(7);
|
|
603
446
|
}
|
|
604
|
-
|
|
605
|
-
|
|
447
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(ip)) {
|
|
448
|
+
return ip;
|
|
606
449
|
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
const
|
|
615
|
-
const
|
|
616
|
-
if (
|
|
617
|
-
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
function isIpv4InCidr(ip, cidr) {
|
|
453
|
+
const [cidrIp, prefixStr] = cidr.split("/");
|
|
454
|
+
if (!cidrIp || !prefixStr) return false;
|
|
455
|
+
const prefix = parseInt(prefixStr, 10);
|
|
456
|
+
if (isNaN(prefix) || prefix < 0 || prefix > 32) return false;
|
|
457
|
+
const ipNum = ipv4ToNum(ip);
|
|
458
|
+
const cidrNum = ipv4ToNum(cidrIp);
|
|
459
|
+
if (ipNum === null || cidrNum === null) return false;
|
|
460
|
+
const mask = prefix === 0 ? 0 : -1 << 32 - prefix >>> 0;
|
|
461
|
+
return (ipNum & mask) === (cidrNum & mask);
|
|
462
|
+
}
|
|
463
|
+
function ipv4ToNum(ip) {
|
|
464
|
+
const parts = ip.split(".");
|
|
465
|
+
if (parts.length !== 4) return null;
|
|
466
|
+
let num = 0;
|
|
467
|
+
for (const part of parts) {
|
|
468
|
+
const n = parseInt(part, 10);
|
|
469
|
+
if (isNaN(n) || n < 0 || n > 255) return null;
|
|
470
|
+
num = num << 8 | n;
|
|
471
|
+
}
|
|
472
|
+
return num >>> 0;
|
|
473
|
+
}
|
|
474
|
+
function isIpv6InCidr(ip, cidr) {
|
|
475
|
+
const [cidrIp, prefixStr] = cidr.split("/");
|
|
476
|
+
if (!cidrIp || !prefixStr) return false;
|
|
477
|
+
const prefix = parseInt(prefixStr, 10);
|
|
478
|
+
if (isNaN(prefix)) return false;
|
|
479
|
+
const ipBytes = expandIpv6(ip);
|
|
480
|
+
const cidrBytes = expandIpv6(cidrIp);
|
|
481
|
+
if (!ipBytes || !cidrBytes) return false;
|
|
482
|
+
const fullBytes = Math.floor(prefix / 8);
|
|
483
|
+
for (let i = 0; i < fullBytes && i < 16; i++) {
|
|
484
|
+
if (ipBytes[i] !== cidrBytes[i]) return false;
|
|
485
|
+
}
|
|
486
|
+
const remainingBits = prefix % 8;
|
|
487
|
+
if (remainingBits > 0 && fullBytes < 16) {
|
|
488
|
+
const mask = -1 << 8 - remainingBits & 255;
|
|
489
|
+
if ((ipBytes[fullBytes] & mask) !== (cidrBytes[fullBytes] & mask)) return false;
|
|
618
490
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
491
|
+
return true;
|
|
492
|
+
}
|
|
493
|
+
function expandIpv6(ip) {
|
|
494
|
+
const zoneIdx = ip.indexOf("%");
|
|
495
|
+
if (zoneIdx !== -1) ip = ip.slice(0, zoneIdx);
|
|
496
|
+
const parts = ip.split("::");
|
|
497
|
+
if (parts.length > 2) return null;
|
|
498
|
+
const bytes = new Array(16).fill(0);
|
|
499
|
+
const expandGroup = (group) => {
|
|
500
|
+
if (!group) return [];
|
|
501
|
+
return group.split(":").flatMap((hex) => {
|
|
502
|
+
const val = parseInt(hex || "0", 16);
|
|
503
|
+
return [val >> 8 & 255, val & 255];
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
if (parts.length === 1) {
|
|
507
|
+
const expanded = expandGroup(parts[0]);
|
|
508
|
+
if (expanded.length !== 16) return null;
|
|
509
|
+
return expanded;
|
|
510
|
+
}
|
|
511
|
+
const left = expandGroup(parts[0]);
|
|
512
|
+
const right = expandGroup(parts[1]);
|
|
513
|
+
if (left.length + right.length > 16) return null;
|
|
514
|
+
for (let i = 0; i < left.length; i++) bytes[i] = left[i];
|
|
515
|
+
for (let i = 0; i < right.length; i++) bytes[16 - right.length + i] = right[i];
|
|
516
|
+
return bytes;
|
|
627
517
|
}
|
|
628
518
|
|
|
629
|
-
export {
|
|
519
|
+
export { createContextRunner, createDynamicImportAdapter, createExtension, generateExtensionManifest, generateManifest, getGroupNamePrefixes, isIpInBlockedCidrs, loadExtensionManifest, loadToolYaml, overrideWithConfig, registerExtension, registerToolsFromManifest, resolveExtensionPackageRoot, validateUrl };
|
|
630
520
|
//# sourceMappingURL=index.js.map
|
|
631
521
|
//# sourceMappingURL=index.js.map
|