@morphllm/morphsdk 0.2.202 → 0.2.204
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 +101 -0
- package/dist/chunk-2GMG5XKU.js +100 -0
- package/dist/chunk-2PPYWRMZ.js +3 -4
- package/dist/chunk-3HAHJYZQ.cjs +74 -0
- package/dist/{chunk-2XU3XXUE.js → chunk-3JROKKS4.js} +3 -25
- package/dist/{chunk-26K5EJD3.js → chunk-43JBUEIX.js} +4 -18
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/{chunk-VQDDL3UH.js → chunk-4TZBUFVP.js} +2 -8
- package/dist/{chunk-YAM6P5OQ.js → chunk-564XJOQP.js} +2 -6
- package/dist/chunk-5H3FKFOI.cjs +77 -0
- package/dist/chunk-5TTZQF4X.cjs +110 -0
- package/dist/chunk-6HAYJA6M.cjs +317 -0
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/chunk-DLYDIYDK.cjs +305 -0
- package/dist/{chunk-65TUD7JV.js → chunk-DYCMPDPV.js} +13 -29
- package/dist/{chunk-3CPI6ZIC.js → chunk-DZP7BR66.js} +22 -43
- package/dist/chunk-E63OPKP7.js +96 -0
- package/dist/chunk-E6V75LI6.cjs +334 -0
- package/dist/{chunk-XPHNS7NW.js → chunk-EJ6ID24K.js} +3 -12
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/chunk-F633IVQA.cjs +91 -0
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-UKXCGQPS.js → chunk-FGA6EYC2.js} +35 -37
- package/dist/{chunk-CAWQEHKP.js → chunk-G4RODMXA.js} +4 -19
- package/dist/chunk-GUNGJC6X.cjs +256 -0
- package/dist/chunk-GYE3FY6Z.js +8 -0
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HNMEBYIS.cjs +86 -0
- package/dist/chunk-HP3PCOTW.cjs +81 -0
- package/dist/{chunk-ICCGLO6V.js → chunk-IGXNLXPN.js} +12 -17
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/chunk-JHC2R3HU.cjs +317 -0
- package/dist/{chunk-IBRBSDLT.js → chunk-JVMIFGZY.js} +5 -8
- package/dist/chunk-KF6S3EPJ.cjs +100 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/{chunk-6OYJC4TZ.js → chunk-L5SCKZVK.js} +13 -22
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-UAZKHSEU.js → chunk-LQST3NW2.js} +5 -15
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/chunk-MLPZKUCO.js +4 -5
- package/dist/chunk-MMX5PUGC.cjs +242 -0
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/chunk-NJWOWXUR.cjs +137 -0
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCKEEEYE.cjs +433 -0
- package/dist/chunk-OENJO7YW.js +306 -0
- package/dist/chunk-OKLAYEBC.cjs +2 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/{chunk-D6YJ5X3C.js → chunk-OX5GN2KB.js} +26 -14
- package/dist/{chunk-JEVLCA5C.js → chunk-OYBOP47A.js} +18 -19
- package/dist/chunk-OZHCHPIE.js +1 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-QT5LGZG3.cjs +10 -0
- package/dist/chunk-R3TUE7O2.cjs +107 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/{chunk-LVKKICOB.js → chunk-SOQYE5A4.js} +36 -69
- package/dist/chunk-ST2OXLT5.cjs +91 -0
- package/dist/{chunk-SIFDK4AA.js → chunk-TH4MG73B.js} +3 -24
- package/dist/{chunk-OSL4CNSO.js → chunk-TLMAMVAW.js} +7 -23
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/{chunk-PDSIWL7I.js → chunk-U4PYAGNR.js} +6 -19
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UHFVWYSP.cjs +408 -0
- package/dist/chunk-UKBSXYKE.cjs +280 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UZMMJ47A.cjs +107 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-VYE7O4FM.cjs +51 -0
- package/dist/chunk-WIYVT4UO.cjs +173 -0
- package/dist/chunk-WJHHO24M.cjs +91 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-YAUXTFIN.cjs +21 -0
- package/dist/{chunk-NFPRKZQ5.js → chunk-YJUCGZNN.js} +5 -22
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/chunk-ZX6T3LNG.js +302 -0
- package/dist/{client-BWhi-vSj.d.ts → client-DSXbcxII.d.ts} +10 -1
- package/dist/client.cjs +44 -4360
- package/dist/client.d.ts +4 -2
- package/dist/client.js +36 -37
- package/dist/core/client.cjs +14 -476
- package/dist/core/client.d.ts +8 -0
- package/dist/core/client.js +10 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +27 -491
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +12 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.d.ts +2 -0
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +74 -1111
- package/dist/edge.d.ts +3 -0
- package/dist/edge.js +14 -42
- package/dist/guard-CvW03v4u.d.ts +59 -0
- package/dist/index.cjs +140 -4431
- package/dist/index.d.ts +6 -2
- package/dist/index.js +44 -87
- package/dist/modelrouter/core.cjs +35 -651
- package/dist/modelrouter/core.d.ts +2 -0
- package/dist/modelrouter/core.js +12 -21
- package/dist/modelrouter/index.cjs +35 -651
- package/dist/modelrouter/index.d.ts +2 -0
- package/dist/modelrouter/index.js +12 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.d.ts +5 -0
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +31 -2784
- package/dist/subagents/anthropic.d.ts +3 -1
- package/dist/subagents/anthropic.js +23 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.d.ts +3 -1
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.d.ts +3 -1
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.d.ts +3 -1
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +31 -2761
- package/dist/subagents/vercel.d.ts +3 -1
- package/dist/subagents/vercel.js +23 -24
- package/dist/tools/compact/core.cjs +20 -552
- package/dist/tools/compact/core.d.ts +2 -0
- package/dist/tools/compact/core.js +12 -13
- package/dist/tools/compact/index.cjs +24 -598
- package/dist/tools/compact/index.d.ts +3 -1
- package/dist/tools/compact/index.js +13 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.d.ts +4 -4
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +39 -899
- package/dist/tools/fastapply/anthropic.d.ts +2 -0
- package/dist/tools/fastapply/anthropic.js +15 -24
- package/dist/tools/fastapply/apply.cjs +32 -672
- package/dist/tools/fastapply/apply.d.ts +2 -0
- package/dist/tools/fastapply/apply.js +8 -19
- package/dist/tools/fastapply/core.cjs +49 -1069
- package/dist/tools/fastapply/core.d.ts +3 -0
- package/dist/tools/fastapply/core.js +13 -29
- package/dist/tools/fastapply/index.cjs +56 -1052
- package/dist/tools/fastapply/index.d.ts +2 -0
- package/dist/tools/fastapply/index.js +18 -44
- package/dist/tools/fastapply/openai.cjs +45 -910
- package/dist/tools/fastapply/openai.d.ts +2 -0
- package/dist/tools/fastapply/openai.js +15 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.d.ts +9 -4
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +37 -905
- package/dist/tools/fastapply/vercel.d.ts +2 -0
- package/dist/tools/fastapply/vercel.js +15 -22
- package/dist/tools/index.cjs +56 -1052
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +18 -44
- package/dist/tools/pii/index.cjs +47 -0
- package/dist/tools/pii/index.d.ts +4 -0
- package/dist/tools/pii/index.js +6 -0
- package/dist/tools/pii/model.cjs +45 -0
- package/dist/tools/pii/model.d.ts +83 -0
- package/dist/tools/pii/model.js +4 -0
- package/dist/tools/pii/patterns.cjs +15 -0
- package/dist/tools/pii/patterns.d.ts +31 -0
- package/dist/tools/pii/patterns.js +2 -0
- package/dist/tools/pii/regex.cjs +32 -0
- package/dist/tools/pii/regex.d.ts +48 -0
- package/dist/tools/pii/regex.js +3 -0
- package/dist/tools/pii/types.cjs +2 -0
- package/dist/tools/pii/types.d.ts +108 -0
- package/dist/tools/pii/types.js +1 -0
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.d.ts +2 -0
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +19 -1081
- package/dist/tools/warp_grep/agent/runner.d.ts +2 -0
- package/dist/tools/warp_grep/agent/runner.js +11 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.d.ts +4 -0
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +51 -2561
- package/dist/tools/warp_grep/anthropic.d.ts +3 -1
- package/dist/tools/warp_grep/anthropic.js +23 -35
- package/dist/tools/warp_grep/client.cjs +53 -2471
- package/dist/tools/warp_grep/client.d.ts +3 -1
- package/dist/tools/warp_grep/client.js +21 -34
- package/dist/tools/warp_grep/gemini.cjs +52 -2490
- package/dist/tools/warp_grep/gemini.d.ts +3 -1
- package/dist/tools/warp_grep/gemini.js +25 -41
- package/dist/tools/warp_grep/harness.cjs +81 -936
- package/dist/tools/warp_grep/harness.d.ts +2 -0
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +128 -2575
- package/dist/tools/warp_grep/index.d.ts +3 -1
- package/dist/tools/warp_grep/index.js +28 -87
- package/dist/tools/warp_grep/openai.cjs +57 -2575
- package/dist/tools/warp_grep/openai.d.ts +3 -1
- package/dist/tools/warp_grep/openai.js +23 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +3 -1
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -589
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.d.ts +3 -1
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -103
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +57 -2557
- package/dist/tools/warp_grep/vercel.d.ts +3 -1
- package/dist/tools/warp_grep/vercel.js +23 -37
- package/dist/{types-DxZLPogx.d.ts → types-BKhXjDCB.d.ts} +6 -1
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +11 -2
- package/dist/chunk-E6TL6MIH.js +0 -203
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/pii/validators.ts
|
|
4
|
+
function digitCount(value) {
|
|
5
|
+
return value.replace(/\D/g, "").length;
|
|
6
|
+
}
|
|
7
|
+
function isRepeatedDigit(digits) {
|
|
8
|
+
return /^(\d)\1+$/.test(digits);
|
|
9
|
+
}
|
|
10
|
+
function luhn(value) {
|
|
11
|
+
const digits = value.replace(/\D/g, "");
|
|
12
|
+
if (digits.length < 13 || digits.length > 19) return false;
|
|
13
|
+
if (isRepeatedDigit(digits)) return false;
|
|
14
|
+
let sum = 0;
|
|
15
|
+
let double = false;
|
|
16
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
17
|
+
let d = digits.charCodeAt(i) - 48;
|
|
18
|
+
if (double) {
|
|
19
|
+
d *= 2;
|
|
20
|
+
if (d > 9) d -= 9;
|
|
21
|
+
}
|
|
22
|
+
sum += d;
|
|
23
|
+
double = !double;
|
|
24
|
+
}
|
|
25
|
+
return sum % 10 === 0;
|
|
26
|
+
}
|
|
27
|
+
var CARD_CUE = /\b(?:card|credit|debit|visa|mastercard|amex|american express|discover|maestro|jcb|diners)\b/i;
|
|
28
|
+
function isUncheckedCardNumber(value, before) {
|
|
29
|
+
if (isRepeatedDigit(value) || /0{8}/.test(value)) return false;
|
|
30
|
+
if (value.startsWith("123456789")) return false;
|
|
31
|
+
if (value.startsWith("90071992547")) return false;
|
|
32
|
+
const looksLikeTimestamp = /^1[5-9]/.test(value);
|
|
33
|
+
return !looksLikeTimestamp || CARD_CUE.test(before.slice(-48));
|
|
34
|
+
}
|
|
35
|
+
function ibanChecksum(value) {
|
|
36
|
+
const iban = value.replace(/\s/g, "");
|
|
37
|
+
if (iban.length < 15 || iban.length > 34) return false;
|
|
38
|
+
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
|
39
|
+
let remainder = 0;
|
|
40
|
+
for (const ch of rearranged) {
|
|
41
|
+
const code = ch.charCodeAt(0);
|
|
42
|
+
const n = code >= 65 ? String(code - 55) : ch;
|
|
43
|
+
for (const digit of n) remainder = (remainder * 10 + (digit.charCodeAt(0) - 48)) % 97;
|
|
44
|
+
}
|
|
45
|
+
return remainder === 1;
|
|
46
|
+
}
|
|
47
|
+
function isRoutableIPv4(value) {
|
|
48
|
+
return !value.startsWith("127.") && value !== "0.0.0.0" && value !== "255.255.255.255";
|
|
49
|
+
}
|
|
50
|
+
function isIPv6(value) {
|
|
51
|
+
const parts = value.split("::");
|
|
52
|
+
if (parts.length > 2) return false;
|
|
53
|
+
const hextets = parts.flatMap((p) => p === "" ? [] : p.split(":"));
|
|
54
|
+
if (!hextets.every((h) => /^[0-9A-Fa-f]{1,4}$/.test(h))) return false;
|
|
55
|
+
return parts.length === 1 ? hextets.length === 8 : hextets.length >= 3 && hextets.length <= 7;
|
|
56
|
+
}
|
|
57
|
+
function isEmail(value, before) {
|
|
58
|
+
if (/@\dx\./i.test(value)) return false;
|
|
59
|
+
const insideUrlCredentials = /:\/\/[^\s/]*$/.test(before);
|
|
60
|
+
return !insideUrlCredentials;
|
|
61
|
+
}
|
|
62
|
+
function looksLikePassword(value) {
|
|
63
|
+
if (!/\p{L}/u.test(value)) return false;
|
|
64
|
+
if (!/[\d@#$!%^&+?~]/.test(value.replace(/[*:]+$/, ""))) return false;
|
|
65
|
+
if (/^\$|\$\{|^process\.|^os\.|^env\.|^self\.|^this\./.test(value)) return false;
|
|
66
|
+
if (value.startsWith("@")) return false;
|
|
67
|
+
if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(value)) return false;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
function isRealUrlPassword(value) {
|
|
71
|
+
return !/^(?:pass(?:word)?|pwd|secret|x{3,}|\*+|<.*>|\$.*|\{.*\}|%.*%)$/i.test(value);
|
|
72
|
+
}
|
|
73
|
+
var NOT_A_STREET = new RegExp(
|
|
74
|
+
[
|
|
75
|
+
String.raw`\b(?:Hard|Flash|Disk|Disc|Google|Shared|Zip|USB|SSD|Test|Pen|Thumb|Tape|Network) Drive\b`,
|
|
76
|
+
String.raw`\b(?:Supreme|District|Appeals|High|Circuit|Federal|Tennis|Basketball|Food) Court\b`,
|
|
77
|
+
String.raw`\b(?:First|Second|Third|Last|Best|Only|Right|Wrong|Same|Other|Easy|Simple|Better) (?:Place|Way)\b`,
|
|
78
|
+
String.raw`\b(?:Event|Run|Main|Game|For|While|Feedback|Training|Agent|Control|Render|Read|Inner|Outer) Loop\b`
|
|
79
|
+
].join("|")
|
|
80
|
+
);
|
|
81
|
+
function isStreetAddress(value) {
|
|
82
|
+
return !NOT_A_STREET.test(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// tools/pii/patterns.ts
|
|
86
|
+
var CONTEXT_CHARS = 256;
|
|
87
|
+
function re(flags) {
|
|
88
|
+
return (strings, ...fragments) => new RegExp(String.raw(strings, ...fragments), flags);
|
|
89
|
+
}
|
|
90
|
+
var QUOTES = "\"'`";
|
|
91
|
+
var WORD_START = String.raw`(?<![\w-])`;
|
|
92
|
+
var WORD_END = String.raw`(?![\w-])`;
|
|
93
|
+
var NUMBER_START = String.raw`(?<![\w.-])`;
|
|
94
|
+
var NUMBER_END = String.raw`(?![\w-]|\.\d)`;
|
|
95
|
+
var LABEL_START = String.raw`(?<![A-Za-z])`;
|
|
96
|
+
var GAP = String.raw`[\s:=${QUOTES}*#,|–-]{0,10}(?:(?:is|was|of|on|to|as)\s+){0,2}[${QUOTES}]?`;
|
|
97
|
+
var VALUE_END = String.raw`[\s${QUOTES}<>{}()\[\],;]`;
|
|
98
|
+
var PASSWORD_VALUE = String.raw`([^\s${QUOTES}<>{}()\[\],;]{6,64}?)(?=[.:]*(?:${VALUE_END}|$))`;
|
|
99
|
+
var MONTH = "(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)";
|
|
100
|
+
var ORDINAL = "(?:st|nd|rd|th)";
|
|
101
|
+
var DATE = "(?:" + [
|
|
102
|
+
String.raw`\d{4}[-/.]\d{1,2}[-/.]\d{1,2}`,
|
|
103
|
+
String.raw`\d{1,2}[-/.]\d{1,2}[-/.]\d{2,4}`,
|
|
104
|
+
String.raw`${MONTH}\.? \d{1,2}${ORDINAL}?,? \d{4}`,
|
|
105
|
+
String.raw`\d{1,2}${ORDINAL}? (?:of )?${MONTH}\.?,? \d{4}`
|
|
106
|
+
].join("|") + ")";
|
|
107
|
+
var COMPASS = "(?:[NSEW]|[NS][EW]|North|South|East|West)";
|
|
108
|
+
var STREET_TYPES = "(?:Street|St|Road|Rd|Avenue|Ave|Drive|Dr|Lane|Ln|Boulevard|Blvd|Court|Ct|Circle|Cir|Way|Place|Pl|Terrace|Ter|Parkway|Pkwy|Highway|Hwy|Trail|Trl|Crescent|Cres|Loop|Pike)";
|
|
109
|
+
var STREET_NAME_WORD = String.raw`(?:[A-Z][\p{L}'.-]*|\d{1,3}${ORDINAL}?)`;
|
|
110
|
+
var UNIT = String.raw`(?:,? (?:Apt|Apartment|Suite|Ste|Unit|Floor|Fl)\.? ?#?[A-Za-z0-9-]+|,? #[A-Za-z0-9-]+)`;
|
|
111
|
+
var PROVIDER_KEYS = [
|
|
112
|
+
"sk-[A-Za-z0-9_-]{20,}",
|
|
113
|
+
// OpenAI, Anthropic, Morph
|
|
114
|
+
"morph-[A-Za-z0-9_-]{20,}",
|
|
115
|
+
"(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{16,}",
|
|
116
|
+
// Stripe
|
|
117
|
+
"gh[pousr]_[A-Za-z0-9]{36,}",
|
|
118
|
+
// GitHub
|
|
119
|
+
"github_pat_[A-Za-z0-9_]{40,}",
|
|
120
|
+
"glpat-[A-Za-z0-9_-]{20,}",
|
|
121
|
+
// GitLab
|
|
122
|
+
"(?:AKIA|ASIA)[A-Z0-9]{16}",
|
|
123
|
+
// AWS access key id
|
|
124
|
+
"xox[abeoprs]-[A-Za-z0-9-]{10,}",
|
|
125
|
+
// Slack
|
|
126
|
+
"AIza[A-Za-z0-9_-]{35}",
|
|
127
|
+
// Google
|
|
128
|
+
"hf_[A-Za-z0-9]{30,}",
|
|
129
|
+
// Hugging Face
|
|
130
|
+
"npm_[A-Za-z0-9]{36}"
|
|
131
|
+
].join("|");
|
|
132
|
+
var PII_PATTERNS = [
|
|
133
|
+
// --- Secrets -------------------------------------------------------------------
|
|
134
|
+
{
|
|
135
|
+
// PEM private key block. The body is capped (a 16384-bit RSA key is about 13 KB).
|
|
136
|
+
type: "SECRET",
|
|
137
|
+
regex: /-----BEGIN [A-Z ]{0,40}PRIVATE KEY-----[\s\S]{0,20000}?-----END [A-Z ]{0,40}PRIVATE KEY-----/g
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
// JSON Web Token: three base64url parts, the first two starting `eyJ`
|
|
141
|
+
type: "SECRET",
|
|
142
|
+
regex: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
type: "SECRET",
|
|
146
|
+
regex: re("g")`(?<![A-Za-z0-9_-])(?:${PROVIDER_KEYS})(?![A-Za-z0-9_-])`
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
// `Authorization: Bearer <token>`
|
|
150
|
+
type: "SECRET",
|
|
151
|
+
regex: /\bBearer\s+([A-Za-z0-9._~+/-]{20,}=*)/g,
|
|
152
|
+
group: 1
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
// Password in a URL: scheme://user:password@host
|
|
156
|
+
type: "SECRET",
|
|
157
|
+
regex: /\b[a-z][a-z0-9+.-]{0,30}:\/\/[^\s:@/]{1,256}:([^\s@/]{1,256})@/gi,
|
|
158
|
+
group: 1,
|
|
159
|
+
validate: isRealUrlPassword
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
// A value after a password label: `Password: hunter2!`, `the new password Rainbow@2023`
|
|
163
|
+
type: "SECRET",
|
|
164
|
+
regex: re("gi")`${WORD_START}(?:password|passphrase|passcode|pwd)${WORD_END}${GAP}${PASSWORD_VALUE}`,
|
|
165
|
+
group: 1,
|
|
166
|
+
validate: looksLikePassword
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
// `pass:` and `secret:` are common words, so they need an explicit separator
|
|
170
|
+
type: "SECRET",
|
|
171
|
+
regex: re("gi")`${WORD_START}(?:pass|secret)\s?[:=]\s?[${QUOTES}]?${PASSWORD_VALUE}`,
|
|
172
|
+
group: 1,
|
|
173
|
+
validate: looksLikePassword
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
// `login: alice / hunter2`
|
|
177
|
+
type: "SECRET",
|
|
178
|
+
regex: re("gi")`${WORD_START}(?:login|creds|credentials?)(?: (?:info(?:rmation)?|details))?\s?[:=]\s?(\S{1,128}\s{0,8}\/\s{0,8}\S{1,128})`,
|
|
179
|
+
group: 1
|
|
180
|
+
},
|
|
181
|
+
// --- Contact ---------------------------------------------------------------------
|
|
182
|
+
{
|
|
183
|
+
type: "EMAIL",
|
|
184
|
+
regex: /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}(?![A-Za-z0-9])/g,
|
|
185
|
+
validate: isEmail
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
// International: +country code, then groups. +44 20 7946 0958
|
|
189
|
+
type: "PHONE",
|
|
190
|
+
regex: /(?<![\w.+])\+\d{1,3}[ .-]?(?:\(\d{1,4}\)[ .-]?)?\d{1,4}(?:[ .-]?\d{2,4}){1,4}(?!\w)/g,
|
|
191
|
+
validate: (value) => digitCount(value) >= 8 && digitCount(value) <= 15
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
// North American: (415) 555-0199, 415-555-0199, 415.555.0199
|
|
195
|
+
type: "PHONE",
|
|
196
|
+
regex: re("g")`${NUMBER_START}(?:\(\d{3}\)[ .-]?|\d{3}[.-])\d{3}[ .-]\d{4}${NUMBER_END}`
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
// National formats with a trunk zero or a bracketed area code:
|
|
200
|
+
// 0371-52754478, 043.0592407, (352) 9324865, 5607 341-2596
|
|
201
|
+
type: "PHONE",
|
|
202
|
+
regex: re("g")`${NUMBER_START}(?:0\d{2,4}[ .-]\d{6,8}|\(\d{3}\)[ .-]{0,2}\d{7}|\d{4}[ -]\d{3}-\d{4})${NUMBER_END}`
|
|
203
|
+
},
|
|
204
|
+
// --- Identifiers with a recognizable shape ---------------------------------------
|
|
205
|
+
{
|
|
206
|
+
// US SSN: 3-2-4 with one separator throughout, excluding ranges that are never issued
|
|
207
|
+
type: "SSN",
|
|
208
|
+
regex: re("g")`${NUMBER_START}(?!000|666|9\d\d)\d{3}([ .-])(?!00)\d{2}\1(?!0000)\d{4}${NUMBER_END}`
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
// Any digit run of card length, in any grouping, that passes the Luhn checksum
|
|
212
|
+
type: "CREDIT_CARD",
|
|
213
|
+
regex: re("g")`${WORD_START}\d(?:[ -]?\d){12,18}${WORD_END}`,
|
|
214
|
+
validate: luhn
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
// Written in card groups (4-4-4-4, or 4-6-5 for Amex): the shape is evidence enough,
|
|
218
|
+
// so a mistyped or masked-test number is redacted too.
|
|
219
|
+
type: "CREDIT_CARD",
|
|
220
|
+
regex: re("g")`${WORD_START}(?:\d{4}[ -]\d{4}[ -]\d{4}[ -]\d{4}|\d{4}[ -]\d{6}[ -]\d{4,5})${WORD_END}`,
|
|
221
|
+
validate: (value) => /[1-9]/.test(value)
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
// A bare 16-digit number that fails Luhn: kept unless it looks like a timestamp or a placeholder
|
|
225
|
+
type: "CREDIT_CARD",
|
|
226
|
+
regex: re("g")`${NUMBER_START}\d{16}${NUMBER_END}`,
|
|
227
|
+
validate: isUncheckedCardNumber
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
// GB29 NWBK 6016 1331 9268 19
|
|
231
|
+
type: "IBAN",
|
|
232
|
+
regex: /(?<!\w)[A-Z]{2}\d{2}(?: ?[A-Z0-9]{4}){2,7}(?: ?[A-Z0-9]{1,3})?(?!\w)/g,
|
|
233
|
+
validate: ibanChecksum
|
|
234
|
+
},
|
|
235
|
+
// --- Identifiers that need a label: the label is what makes the value sensitive ---
|
|
236
|
+
{
|
|
237
|
+
// `SSN: 123456789`, `social security number is 123 45 6789`
|
|
238
|
+
type: "SSN",
|
|
239
|
+
regex: re("gi")`${LABEL_START}(?:SSN|social security(?: (?:number|no\.?|#))?)${GAP}(\d[\d .-]{7,14}\d)${WORD_END}`,
|
|
240
|
+
group: 1
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
// Swiss AHV number (starts 756), with or without dots
|
|
244
|
+
type: "SSN",
|
|
245
|
+
regex: re("g")`${NUMBER_START}756(?:\.?\d{4}){2}(?:\.?\d{2})?${NUMBER_END}|${NUMBER_START}756\d{8}${NUMBER_END}`
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
// `account number: 12345678`, `routing no. 021000021`
|
|
249
|
+
type: "ACCOUNT_NUMBER",
|
|
250
|
+
regex: re("gi")`${LABEL_START}(?:account|acct|routing|a\/c)[ _-]?(?:number|no\.?|num|nr|#)${GAP}([A-Z]{0,4}-?\d[\d -]{4,24}\d)${WORD_END}`,
|
|
251
|
+
group: 1
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
// `MRN: A-448291`
|
|
255
|
+
type: "MEDICAL_RECORD",
|
|
256
|
+
regex: re("gi")`${LABEL_START}(?:MRN|medical records?(?: (?:number|no\.?|num|#))?)${GAP}([A-Za-z0-9][A-Za-z0-9-]{3,39})${WORD_END}`,
|
|
257
|
+
group: 1,
|
|
258
|
+
validate: (value) => /\d/.test(value)
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
// `DOB: 1990-04-12`, `born on April 12th, 1990`
|
|
262
|
+
type: "DATE_OF_BIRTH",
|
|
263
|
+
regex: re("gi")`${LABEL_START}(?:d\.?o\.?b\.?|date[ _-]?of[ _-]?birth|birth[ _-]?date|birthday|born)${GAP}(${DATE})${WORD_END}`,
|
|
264
|
+
group: 1
|
|
265
|
+
},
|
|
266
|
+
// --- Addresses -------------------------------------------------------------------
|
|
267
|
+
{
|
|
268
|
+
// House number, optional compass point, 1 to 4 name words, street type, optional unit.
|
|
269
|
+
// Case-sensitive on purpose: `42 Wallaby Way` matches, `2 simple ways` does not.
|
|
270
|
+
type: "LOCATION",
|
|
271
|
+
regex: re("gu")`(?<![\w.#-])\d{1,6}[A-Za-z]?(?: ${COMPASS}\.?)?(?: ${STREET_NAME_WORD}){1,4} ${STREET_TYPES}\b\.?${UNIT}?`,
|
|
272
|
+
validate: isStreetAddress
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
// `PO Box 1234`, `P.O. Box 9`
|
|
276
|
+
type: "LOCATION",
|
|
277
|
+
regex: /(?<!\w)P\.? ?O\.? ?Box \d+\b/gi
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
// Numbered street with no house number in front: `W 2nd Street`, `5th Avenue`
|
|
281
|
+
type: "LOCATION",
|
|
282
|
+
regex: re("g")`(?<![\w.#-])(?:${COMPASS}\.? )?\d{1,3}${ORDINAL} ${STREET_TYPES}\b\.?`
|
|
283
|
+
},
|
|
284
|
+
// --- Network ---------------------------------------------------------------------
|
|
285
|
+
{
|
|
286
|
+
// 00:1A:2B:3C:4D:5E, with one separator throughout
|
|
287
|
+
type: "MAC_ADDRESS",
|
|
288
|
+
regex: /(?<![\w:-])[0-9A-Fa-f]{2}([:-])(?:[0-9A-Fa-f]{2}\1){4}[0-9A-Fa-f]{2}(?![\w:-])/g
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
// IPv4, each octet 0 to 255
|
|
292
|
+
type: "IP_ADDRESS",
|
|
293
|
+
regex: /(?<![\w.])(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)(?!\w|\.\d)/g,
|
|
294
|
+
validate: isRoutableIPv4
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
// IPv6, full or `::`-compressed; the validator counts the hextets
|
|
298
|
+
type: "IP_ADDRESS",
|
|
299
|
+
regex: /(?<![\w:.])(?:[0-9A-Fa-f]{1,4}:|::)[0-9A-Fa-f:]{2,37}(?![\w:])/g,
|
|
300
|
+
validate: isIPv6
|
|
301
|
+
}
|
|
302
|
+
];
|
|
303
|
+
|
|
304
|
+
exports.CONTEXT_CHARS = CONTEXT_CHARS;
|
|
305
|
+
exports.PII_PATTERNS = PII_PATTERNS;
|
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from
|
|
5
|
-
import {
|
|
6
|
-
MorphAPIClient
|
|
7
|
-
} from "./chunk-ICCGLO6V.js";
|
|
8
|
-
import {
|
|
9
|
-
logger
|
|
10
|
-
} from "./chunk-6WP7EA4F.js";
|
|
11
|
-
import {
|
|
12
|
-
APIResource
|
|
13
|
-
} from "./chunk-NRG6QX3L.js";
|
|
1
|
+
import { FastApplyContextLengthError, FastApplyAnchorIntegrityError } from './chunk-OYBOP47A.js';
|
|
2
|
+
import { MorphAPIClient } from './chunk-IGXNLXPN.js';
|
|
3
|
+
import { logger } from './chunk-6WP7EA4F.js';
|
|
4
|
+
import { APIResource } from './chunk-NRG6QX3L.js';
|
|
5
|
+
import { resolve, join, relative } from 'path';
|
|
14
6
|
|
|
15
|
-
// tools/fastapply/core.ts
|
|
16
|
-
import { join, resolve, relative } from "path";
|
|
17
7
|
var DEFAULT_CONFIG = {
|
|
18
|
-
morphApiUrl: "https://api.morphllm.com",
|
|
19
8
|
baseDir: process.cwd(),
|
|
20
9
|
generateUdiff: true,
|
|
21
10
|
autoWrite: true,
|
|
22
|
-
timeout: 6e5
|
|
23
|
-
anchorCompaction: true,
|
|
24
|
-
anchorCompactionThreshold: 128 * 1024,
|
|
25
|
-
debug: false
|
|
26
|
-
};
|
|
11
|
+
timeout: 6e5};
|
|
27
12
|
var FastApplyClient = class extends APIResource {
|
|
28
13
|
config;
|
|
29
14
|
constructor(clientOrConfig = {}) {
|
|
@@ -33,7 +18,8 @@ var FastApplyClient = class extends APIResource {
|
|
|
33
18
|
apiKey: clientOrConfig.apiKey,
|
|
34
19
|
timeout: clientOrConfig.timeout ?? DEFAULT_CONFIG.timeout,
|
|
35
20
|
retryConfig: clientOrConfig.retryConfig,
|
|
36
|
-
debug: clientOrConfig.debug
|
|
21
|
+
debug: clientOrConfig.debug,
|
|
22
|
+
redactPII: clientOrConfig.redactPII
|
|
37
23
|
})
|
|
38
24
|
);
|
|
39
25
|
this.config = {
|
|
@@ -42,6 +28,7 @@ var FastApplyClient = class extends APIResource {
|
|
|
42
28
|
debug: this._client.debug,
|
|
43
29
|
timeout: (isClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_CONFIG.timeout,
|
|
44
30
|
retryConfig: this._client.retryConfig,
|
|
31
|
+
redactPII: this._client.redactPII,
|
|
45
32
|
generateUdiff: DEFAULT_CONFIG.generateUdiff,
|
|
46
33
|
autoWrite: DEFAULT_CONFIG.autoWrite
|
|
47
34
|
};
|
|
@@ -77,7 +64,7 @@ var FastApplyClient = class extends APIResource {
|
|
|
77
64
|
* ```
|
|
78
65
|
*/
|
|
79
66
|
async applyEdit(input, overrides) {
|
|
80
|
-
const { applyEdit: applyEdit2 } = await import(
|
|
67
|
+
const { applyEdit: applyEdit2 } = await import('./tools/fastapply/apply.js');
|
|
81
68
|
return applyEdit2(input, { ...this.config, ...overrides });
|
|
82
69
|
}
|
|
83
70
|
};
|
|
@@ -97,8 +84,8 @@ async function executeEditFile(input, config = {}) {
|
|
|
97
84
|
}
|
|
98
85
|
logger.debug("FastApply", "security_check", { resolved: fullPath, relative: relativePath });
|
|
99
86
|
try {
|
|
100
|
-
const { readFile, writeFile } = await import(
|
|
101
|
-
const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await import(
|
|
87
|
+
const { readFile, writeFile } = await import('fs/promises');
|
|
88
|
+
const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await import('./tools/fastapply/apply.js');
|
|
102
89
|
let originalCode = "";
|
|
103
90
|
let fileExists = true;
|
|
104
91
|
try {
|
|
@@ -144,7 +131,4 @@ async function executeEditFile(input, config = {}) {
|
|
|
144
131
|
}
|
|
145
132
|
}
|
|
146
133
|
|
|
147
|
-
export {
|
|
148
|
-
FastApplyClient,
|
|
149
|
-
executeEditFile
|
|
150
|
-
};
|
|
134
|
+
export { FastApplyClient, executeEditFile };
|
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
} from "./chunk-OPDWMD4Q.js";
|
|
10
|
-
import {
|
|
11
|
-
runWarpGrep,
|
|
12
|
-
runWarpGrepStreaming
|
|
13
|
-
} from "./chunk-UKXCGQPS.js";
|
|
14
|
-
import {
|
|
15
|
-
compactFileContexts
|
|
16
|
-
} from "./chunk-IBRBSDLT.js";
|
|
17
|
-
import {
|
|
18
|
-
MorphAPIClient
|
|
19
|
-
} from "./chunk-ICCGLO6V.js";
|
|
20
|
-
import {
|
|
21
|
-
logger
|
|
22
|
-
} from "./chunk-6WP7EA4F.js";
|
|
23
|
-
import {
|
|
24
|
-
APIResource
|
|
25
|
-
} from "./chunk-NRG6QX3L.js";
|
|
1
|
+
import { RemoteCommandsProvider } from './chunk-RYVW7RUM.js';
|
|
2
|
+
import { parseGitHubUrl } from './chunk-OPDWMD4Q.js';
|
|
3
|
+
import { runWarpGrep, runWarpGrepStreaming } from './chunk-FGA6EYC2.js';
|
|
4
|
+
import { createCodeStorageHttpCommands } from './chunk-HDP4QAZL.js';
|
|
5
|
+
import { compactFileContexts } from './chunk-JVMIFGZY.js';
|
|
6
|
+
import { MorphAPIClient } from './chunk-IGXNLXPN.js';
|
|
7
|
+
import { logger } from './chunk-6WP7EA4F.js';
|
|
8
|
+
import { APIResource } from './chunk-NRG6QX3L.js';
|
|
26
9
|
|
|
27
10
|
// tools/warp_grep/client.ts
|
|
28
11
|
var DEFAULT_CODE_SEARCH_URL = "https://api.morphllm.com";
|
|
29
12
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
30
|
-
const { LocalRipgrepProvider } = await import(
|
|
13
|
+
const { LocalRipgrepProvider } = await import('./tools/warp_grep/providers/local.js');
|
|
31
14
|
const opts = allowNames?.length ? { allowNames } : void 0;
|
|
32
15
|
return new LocalRipgrepProvider(repoRoot, excludes, opts);
|
|
33
16
|
}
|
|
@@ -51,7 +34,8 @@ var WarpGrepClient = class extends APIResource {
|
|
|
51
34
|
morphApiUrl: this._client.baseURL,
|
|
52
35
|
timeout: this._client.timeout,
|
|
53
36
|
retryConfig: this._client.retryConfig,
|
|
54
|
-
debug: this._client.debug
|
|
37
|
+
debug: this._client.debug,
|
|
38
|
+
redactPII: cfg.redactPII ?? this._client.redactPII
|
|
55
39
|
};
|
|
56
40
|
}
|
|
57
41
|
execute(input) {
|
|
@@ -66,7 +50,8 @@ var WarpGrepClient = class extends APIResource {
|
|
|
66
50
|
morphApiUrl: this.config.morphApiUrl,
|
|
67
51
|
retryConfig: this.config.retryConfig,
|
|
68
52
|
timeout: this.config.timeout,
|
|
69
|
-
search_type: input.search_type
|
|
53
|
+
search_type: input.search_type,
|
|
54
|
+
redactPII: this.config.redactPII
|
|
70
55
|
};
|
|
71
56
|
if (input.streamSteps) {
|
|
72
57
|
return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);
|
|
@@ -180,11 +165,12 @@ async function executeToolCall(input, config) {
|
|
|
180
165
|
morphApiUrl: config.morphApiUrl,
|
|
181
166
|
retryConfig: config.retryConfig,
|
|
182
167
|
timeout: config.timeout,
|
|
183
|
-
search_type: config.search_type
|
|
168
|
+
search_type: config.search_type,
|
|
169
|
+
redactPII: config.redactPII
|
|
184
170
|
});
|
|
185
|
-
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
171
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
|
|
186
172
|
}
|
|
187
|
-
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
173
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl, redactPII) {
|
|
188
174
|
const finish = result.finish;
|
|
189
175
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
190
176
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -198,7 +184,7 @@ async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
|
198
184
|
}));
|
|
199
185
|
try {
|
|
200
186
|
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
201
|
-
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
187
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl, void 0, void 0, redactPII);
|
|
202
188
|
for (let i = 0; i < contexts.length; i++) {
|
|
203
189
|
contexts[i].content = compacted[i].content;
|
|
204
190
|
}
|
|
@@ -222,7 +208,8 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
222
208
|
morphApiUrl: config.morphApiUrl,
|
|
223
209
|
retryConfig: config.retryConfig,
|
|
224
210
|
timeout: config.timeout,
|
|
225
|
-
search_type: config.search_type
|
|
211
|
+
search_type: config.search_type,
|
|
212
|
+
redactPII: config.redactPII
|
|
226
213
|
});
|
|
227
214
|
let agentResult;
|
|
228
215
|
for (; ; ) {
|
|
@@ -233,7 +220,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
233
220
|
}
|
|
234
221
|
yield value;
|
|
235
222
|
}
|
|
236
|
-
return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
223
|
+
return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
|
|
237
224
|
}
|
|
238
225
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
239
226
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -319,12 +306,4 @@ function formatResult(result) {
|
|
|
319
306
|
return parts.join("\n");
|
|
320
307
|
}
|
|
321
308
|
|
|
322
|
-
export {
|
|
323
|
-
WarpGrepClient,
|
|
324
|
-
executeWarpGrep,
|
|
325
|
-
executeToolCall,
|
|
326
|
-
executeToolCallStreaming,
|
|
327
|
-
executeGitHubReadFile,
|
|
328
|
-
formatGitHubReadFileResult,
|
|
329
|
-
formatResult
|
|
330
|
-
};
|
|
309
|
+
export { WarpGrepClient, executeGitHubReadFile, executeToolCall, executeToolCallStreaming, executeWarpGrep, formatGitHubReadFileResult, formatResult };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { createPIIRedactor } from './chunk-OENJO7YW.js';
|
|
2
|
+
import { applyRedactions } from './chunk-2GMG5XKU.js';
|
|
3
|
+
|
|
4
|
+
// tools/pii/guard.ts
|
|
5
|
+
var PIIRestoreError = class extends Error {
|
|
6
|
+
constructor(tokens) {
|
|
7
|
+
super(
|
|
8
|
+
`Morph returned ${tokens.length} PII placeholder(s) that do not match anything sent. The response was discarded so no placeholder is written in place of real data.`
|
|
9
|
+
);
|
|
10
|
+
this.tokens = tokens;
|
|
11
|
+
this.name = "PIIRestoreError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var PIISession = class {
|
|
15
|
+
constructor(detect) {
|
|
16
|
+
this.detect = detect;
|
|
17
|
+
}
|
|
18
|
+
nonce = Math.random().toString(36).slice(2, 6).padEnd(4, "0");
|
|
19
|
+
tokenFor = /* @__PURE__ */ new Map();
|
|
20
|
+
valueFor = /* @__PURE__ */ new Map();
|
|
21
|
+
counters = /* @__PURE__ */ new Map();
|
|
22
|
+
cache = /* @__PURE__ */ new Map();
|
|
23
|
+
tokenPattern = new RegExp(`__PII_[A-Z0-9_]+?_\\d+_${this.nonce}__`, "g");
|
|
24
|
+
/** Number of distinct values redacted so far. */
|
|
25
|
+
get size() {
|
|
26
|
+
return this.valueFor.size;
|
|
27
|
+
}
|
|
28
|
+
token(type, value) {
|
|
29
|
+
const key = `${type}\0${value}`;
|
|
30
|
+
let token = this.tokenFor.get(key);
|
|
31
|
+
if (!token) {
|
|
32
|
+
const index = (this.counters.get(type) ?? 0) + 1;
|
|
33
|
+
this.counters.set(type, index);
|
|
34
|
+
token = `__PII_${type.replace(/[^A-Z0-9]+/gi, "_").toUpperCase()}_${index}_${this.nonce}__`;
|
|
35
|
+
this.tokenFor.set(key, token);
|
|
36
|
+
this.valueFor.set(token, value);
|
|
37
|
+
}
|
|
38
|
+
return token;
|
|
39
|
+
}
|
|
40
|
+
/** Replace sensitive values with tokens. Repeated text is answered from a cache. */
|
|
41
|
+
async redact(text) {
|
|
42
|
+
if (!text) return text;
|
|
43
|
+
const cached = this.cache.get(text);
|
|
44
|
+
if (cached !== void 0) return cached;
|
|
45
|
+
const entities = await this.detect(text);
|
|
46
|
+
const out = applyRedactions(
|
|
47
|
+
text,
|
|
48
|
+
entities,
|
|
49
|
+
(entity) => (
|
|
50
|
+
// One token per line, so the line count (and any line numbers Morph returns)
|
|
51
|
+
// is the same before and after redaction.
|
|
52
|
+
entity.value.split("\n").map((line) => line ? this.token(entity.type, line) : "").join("\n")
|
|
53
|
+
)
|
|
54
|
+
);
|
|
55
|
+
this.cache.set(text, out);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
restore(text) {
|
|
59
|
+
if (!text || this.valueFor.size === 0) return text;
|
|
60
|
+
return text.replace(this.tokenPattern, (token) => this.valueFor.get(token) ?? token);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Like `restore`, but throws if the text holds a token this session did not issue, or a
|
|
64
|
+
* damaged one (a token that lost its head or its tail). Use it wherever the result is
|
|
65
|
+
* written somewhere durable.
|
|
66
|
+
*/
|
|
67
|
+
restoreStrict(text) {
|
|
68
|
+
const unknown = (text.match(this.tokenPattern) ?? []).filter((token) => !this.valueFor.has(token));
|
|
69
|
+
const restored = this.restore(text);
|
|
70
|
+
const tail = `_${this.nonce}__`;
|
|
71
|
+
if (this.valueFor.size > 0) {
|
|
72
|
+
if (restored.includes(tail)) unknown.push(tail);
|
|
73
|
+
for (const token of this.valueFor.keys()) {
|
|
74
|
+
const head = token.slice(0, -(this.nonce.length + 2));
|
|
75
|
+
if (restored.includes(head)) unknown.push(head);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (unknown.length) throw new PIIRestoreError([...new Set(unknown)]);
|
|
79
|
+
return restored;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var guards = /* @__PURE__ */ new WeakMap();
|
|
83
|
+
var defaultGuard;
|
|
84
|
+
function build(config) {
|
|
85
|
+
const redactor = createPIIRedactor(config);
|
|
86
|
+
return { session: () => new PIISession((text) => redactor.detect(text)) };
|
|
87
|
+
}
|
|
88
|
+
function resolvePIIGuard(option) {
|
|
89
|
+
if (!option) return void 0;
|
|
90
|
+
if (option === true) return defaultGuard ??= build({});
|
|
91
|
+
let guard = guards.get(option);
|
|
92
|
+
if (!guard) guards.set(option, guard = build(option));
|
|
93
|
+
return guard;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { PIIRestoreError, PIISession, resolvePIIGuard };
|