@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,306 @@
|
|
|
1
|
+
import { applyRedactions, detectPII, isAllowed, isTypeEnabled, mergeEntities } from './chunk-2GMG5XKU.js';
|
|
2
|
+
|
|
3
|
+
// tools/pii/model.ts
|
|
4
|
+
var DEFAULT_PII_MODEL = "onnx-community/bert-small-pii-detection-ONNX";
|
|
5
|
+
var DEFAULT_LABEL_MAP = {
|
|
6
|
+
EMAIL_ADDRESS: "EMAIL",
|
|
7
|
+
PHONE_NUMBER: "PHONE",
|
|
8
|
+
US_SSN: "SSN",
|
|
9
|
+
IBAN_CODE: "IBAN",
|
|
10
|
+
PASSWORD: "SECRET"
|
|
11
|
+
};
|
|
12
|
+
var DEFAULT_MODEL_EXCLUDED_TYPES = [
|
|
13
|
+
"ORGANIZATION",
|
|
14
|
+
"DATE_TIME",
|
|
15
|
+
"URL",
|
|
16
|
+
"TITLE",
|
|
17
|
+
"AGE",
|
|
18
|
+
"NRP",
|
|
19
|
+
"COORDINATE"
|
|
20
|
+
];
|
|
21
|
+
var REGEX_OWNED_TYPES = ["EMAIL", "IP_ADDRESS", "MAC_ADDRESS"];
|
|
22
|
+
var DEFAULT_PII_ALLOW = [
|
|
23
|
+
"Claude",
|
|
24
|
+
"Sonnet",
|
|
25
|
+
"Opus",
|
|
26
|
+
"Haiku",
|
|
27
|
+
"Gemini",
|
|
28
|
+
"Llama",
|
|
29
|
+
"Mistral",
|
|
30
|
+
"Grok",
|
|
31
|
+
"Copilot",
|
|
32
|
+
"Codex",
|
|
33
|
+
"Siri",
|
|
34
|
+
"Alexa"
|
|
35
|
+
];
|
|
36
|
+
var NAME_LIKE_TYPES = ["PERSON", "LOCATION", "ORGANIZATION"];
|
|
37
|
+
var IDENT_CHAR = /[\p{L}\p{N}_$]/u;
|
|
38
|
+
var JOINER = /[-./@#]/;
|
|
39
|
+
var NAME_PREFIX = /^(?:Mc|Mac|De|Di|Du|La|Le|Van|Von|Fitz|O)\p{Lu}/u;
|
|
40
|
+
function looksLikeIdentifier(text, start, end) {
|
|
41
|
+
if (/\s/.test(text.slice(start, end))) return false;
|
|
42
|
+
const grow = (from, step) => {
|
|
43
|
+
let edge = from;
|
|
44
|
+
for (; ; ) {
|
|
45
|
+
const at = step === 1 ? edge : edge - 1;
|
|
46
|
+
const ch = text[at];
|
|
47
|
+
if (ch === void 0) return edge;
|
|
48
|
+
const crossesJoiner = JOINER.test(ch) && IDENT_CHAR.test(text[at + step] ?? "");
|
|
49
|
+
if (!IDENT_CHAR.test(ch) && !crossesJoiner) return edge;
|
|
50
|
+
edge += step;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const tokenStart = grow(start, -1);
|
|
54
|
+
const tokenEnd = grow(end, 1);
|
|
55
|
+
const token = text.slice(tokenStart, tokenEnd);
|
|
56
|
+
if (text[tokenEnd] === "(") return true;
|
|
57
|
+
if (/[_$]/.test(token)) return true;
|
|
58
|
+
if (/\p{L}/u.test(token) && /\p{N}/u.test(token)) return true;
|
|
59
|
+
if (/[/@#]/.test(token)) return true;
|
|
60
|
+
if (token.includes(".") && !/^(?:\p{Lu}\.)+\p{Lu}?$/u.test(token)) return true;
|
|
61
|
+
if (token.includes("-") && token === token.toLowerCase()) return true;
|
|
62
|
+
return token.split("-").some(
|
|
63
|
+
(word) => /^\p{Ll}+\p{Lu}/u.test(word) || // camelCase
|
|
64
|
+
/^\p{Lu}\p{Ll}+\p{Lu}\p{Ll}/u.test(word) && !NAME_PREFIX.test(word)
|
|
65
|
+
// PascalCase
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
var DEFAULT_MIN_SCORE = 0.75;
|
|
69
|
+
var CHUNK_CHARS = 400;
|
|
70
|
+
var TRUNCATION_TOKENS = 500;
|
|
71
|
+
var MAX_TOKEN_GAP = 64;
|
|
72
|
+
var MIN_SPLIT_CHARS = 64;
|
|
73
|
+
function countTokens(classifier, text) {
|
|
74
|
+
const tokenizer = classifier.tokenizer;
|
|
75
|
+
if (typeof tokenizer !== "function") return void 0;
|
|
76
|
+
try {
|
|
77
|
+
const dims = tokenizer(text)?.input_ids?.dims;
|
|
78
|
+
return Array.isArray(dims) ? Number(dims[dims.length - 1]) : void 0;
|
|
79
|
+
} catch {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function maxTokens(classifier) {
|
|
84
|
+
const max = classifier.tokenizer?.model_max_length;
|
|
85
|
+
return typeof max === "number" && max > 0 && max < 1e5 ? max : 512;
|
|
86
|
+
}
|
|
87
|
+
var SPECIAL_TOKEN = /^(?:\[(?:CLS|SEP|PAD|UNK|MASK)\]|<\/?s>|<(?:pad|unk|mask)>)$/;
|
|
88
|
+
var WORD_CHAR = /[\p{L}\p{N}]/u;
|
|
89
|
+
function normalizeChar(ch) {
|
|
90
|
+
return ch.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
|
91
|
+
}
|
|
92
|
+
function chunkText(text, size = CHUNK_CHARS) {
|
|
93
|
+
const chunks = [];
|
|
94
|
+
let start = 0;
|
|
95
|
+
while (start < text.length) {
|
|
96
|
+
let end = Math.min(start + size, text.length);
|
|
97
|
+
if (end < text.length) {
|
|
98
|
+
const window = text.slice(start, end);
|
|
99
|
+
const paragraph = window.lastIndexOf("\n\n");
|
|
100
|
+
const newline = window.lastIndexOf("\n");
|
|
101
|
+
const space = Math.max(window.lastIndexOf(" "), window.lastIndexOf(" "));
|
|
102
|
+
const cut = paragraph > 0 ? paragraph + 1 : newline > size / 2 ? newline : space > size / 2 ? space : -1;
|
|
103
|
+
if (cut > 0) end = start + cut + 1;
|
|
104
|
+
}
|
|
105
|
+
chunks.push([start, end]);
|
|
106
|
+
start = end;
|
|
107
|
+
}
|
|
108
|
+
return chunks;
|
|
109
|
+
}
|
|
110
|
+
function alignTokens(text, words) {
|
|
111
|
+
let norm = "";
|
|
112
|
+
const starts = [];
|
|
113
|
+
const ends = [];
|
|
114
|
+
let offset = 0;
|
|
115
|
+
for (const ch of text) {
|
|
116
|
+
const n = normalizeChar(ch);
|
|
117
|
+
norm += n;
|
|
118
|
+
for (let k = 0; k < n.length; k++) {
|
|
119
|
+
starts.push(offset);
|
|
120
|
+
ends.push(offset + ch.length);
|
|
121
|
+
}
|
|
122
|
+
offset += ch.length;
|
|
123
|
+
}
|
|
124
|
+
const spans = [];
|
|
125
|
+
let cursor = 0;
|
|
126
|
+
let afterUnknown = false;
|
|
127
|
+
for (const word of words) {
|
|
128
|
+
if (SPECIAL_TOKEN.test(word)) {
|
|
129
|
+
if (/unk/i.test(word)) afterUnknown = true;
|
|
130
|
+
spans.push(null);
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const needle = Array.from(word.replace(/^##|^[▁Ġ]/, ""), normalizeChar).join("");
|
|
134
|
+
const at = needle ? norm.indexOf(needle, cursor) : -1;
|
|
135
|
+
if (at === -1 || !afterUnknown && at - cursor > MAX_TOKEN_GAP) {
|
|
136
|
+
spans.push(null);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
spans.push([starts[at], ends[at + needle.length - 1]]);
|
|
140
|
+
cursor = at + needle.length;
|
|
141
|
+
afterUnknown = false;
|
|
142
|
+
}
|
|
143
|
+
return spans;
|
|
144
|
+
}
|
|
145
|
+
function tokensToEntities(text, tokens, minScore, labelMap) {
|
|
146
|
+
const spans = alignTokens(text, tokens.map((t) => t.word));
|
|
147
|
+
const groups = [];
|
|
148
|
+
let open;
|
|
149
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
150
|
+
const token = tokens[i];
|
|
151
|
+
const span = spans[i];
|
|
152
|
+
const label = token.entity.replace(/^[BIES]-/, "");
|
|
153
|
+
if (label === "O") {
|
|
154
|
+
open = void 0;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (!span) continue;
|
|
158
|
+
if (open && open.label === label && token.index === open.lastIndex + 1) {
|
|
159
|
+
open.end = span[1];
|
|
160
|
+
open.scores.push(token.score);
|
|
161
|
+
open.lastIndex = token.index;
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
open = { label, start: span[0], end: span[1], scores: [token.score], lastIndex: token.index };
|
|
165
|
+
groups.push(open);
|
|
166
|
+
}
|
|
167
|
+
const entities = [];
|
|
168
|
+
for (const group of groups) {
|
|
169
|
+
const score = group.scores.reduce((a, b) => a + b, 0) / group.scores.length;
|
|
170
|
+
if (score < minScore) continue;
|
|
171
|
+
let { start, end } = group;
|
|
172
|
+
while (start > 0 && WORD_CHAR.test(text[start - 1])) start--;
|
|
173
|
+
while (end < text.length && WORD_CHAR.test(text[end])) end++;
|
|
174
|
+
entities.push({
|
|
175
|
+
type: labelMap[group.label] ?? group.label,
|
|
176
|
+
start,
|
|
177
|
+
end,
|
|
178
|
+
value: text.slice(start, end),
|
|
179
|
+
source: "model",
|
|
180
|
+
score
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return entities;
|
|
184
|
+
}
|
|
185
|
+
var TRANSFORMERS = "@huggingface/transformers";
|
|
186
|
+
var viaImport = (name) => import(
|
|
187
|
+
/* webpackIgnore: true */
|
|
188
|
+
/* @vite-ignore */
|
|
189
|
+
name
|
|
190
|
+
);
|
|
191
|
+
var viaRequire = async (name) => {
|
|
192
|
+
const nodeModule = "node:module";
|
|
193
|
+
const { createRequire } = await import(
|
|
194
|
+
/* webpackIgnore: true */
|
|
195
|
+
/* @vite-ignore */
|
|
196
|
+
nodeModule
|
|
197
|
+
);
|
|
198
|
+
return createRequire(typeof __filename === "string" ? __filename : import.meta.url)(name);
|
|
199
|
+
};
|
|
200
|
+
function isNotInstalled(error, name) {
|
|
201
|
+
const { code, message } = error ?? {};
|
|
202
|
+
return (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && String(message).includes(name);
|
|
203
|
+
}
|
|
204
|
+
async function loadOptionalDependency(name, load = { viaImport, viaRequire }) {
|
|
205
|
+
let importError;
|
|
206
|
+
try {
|
|
207
|
+
return await load.viaImport(name);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
importError = error;
|
|
210
|
+
}
|
|
211
|
+
if (!isNotInstalled(importError, name)) {
|
|
212
|
+
try {
|
|
213
|
+
return await load.viaRequire(name);
|
|
214
|
+
} catch (requireError) {
|
|
215
|
+
if (!isNotInstalled(requireError, name)) {
|
|
216
|
+
const reason = importError instanceof Error ? importError.message : String(importError);
|
|
217
|
+
throw new Error(
|
|
218
|
+
`PII model mode could not load '${name}' on Node ${process.versions.node}: ${reason}. It is installed but failed to load. Use a newer Node version, or pass your own \`classifier\`.`,
|
|
219
|
+
{ cause: importError }
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
throw new Error(
|
|
225
|
+
`PII model mode needs the optional dependency '${name}'. Install it (npm install ${name}), or pass your own \`classifier\`.`,
|
|
226
|
+
{ cause: importError }
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
async function loadClassifier(config) {
|
|
230
|
+
const transformers = await loadOptionalDependency(TRANSFORMERS);
|
|
231
|
+
const options = { dtype: config.dtype ?? "q8", device: "cpu" };
|
|
232
|
+
if (config.cacheDir) options.cache_dir = config.cacheDir;
|
|
233
|
+
return transformers.pipeline("token-classification", config.model ?? DEFAULT_PII_MODEL, options);
|
|
234
|
+
}
|
|
235
|
+
function createPIIRedactor(config = {}) {
|
|
236
|
+
const mode = config.mode ?? (config.classifier ? "model" : "regex");
|
|
237
|
+
const minScore = config.minScore ?? DEFAULT_MIN_SCORE;
|
|
238
|
+
const labelMap = { ...DEFAULT_LABEL_MAP, ...config.labelMap };
|
|
239
|
+
const modelFilter = config.types || config.excludeTypes ? config : { excludeTypes: DEFAULT_MODEL_EXCLUDED_TYPES };
|
|
240
|
+
const allow = config.allow ?? (mode === "model" ? DEFAULT_PII_ALLOW : void 0);
|
|
241
|
+
let classifier;
|
|
242
|
+
const getClassifier = () => {
|
|
243
|
+
if (!classifier) {
|
|
244
|
+
classifier = config.classifier ? Promise.resolve(config.classifier) : loadClassifier(config);
|
|
245
|
+
classifier.catch(() => {
|
|
246
|
+
classifier = void 0;
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return classifier;
|
|
250
|
+
};
|
|
251
|
+
function splitPoint(text, start, end) {
|
|
252
|
+
return start + chunkText(text.slice(start, end), Math.ceil((end - start) / 2))[0][1];
|
|
253
|
+
}
|
|
254
|
+
async function classify(text, start, end) {
|
|
255
|
+
const piece = text.slice(start, end);
|
|
256
|
+
if (!piece.trim()) return [];
|
|
257
|
+
const run = await getClassifier();
|
|
258
|
+
const halves = async () => {
|
|
259
|
+
const middle = splitPoint(text, start, end);
|
|
260
|
+
return [...await classify(text, start, middle), ...await classify(text, middle, end)];
|
|
261
|
+
};
|
|
262
|
+
const splittable = piece.length > MIN_SPLIT_CHARS;
|
|
263
|
+
const count = countTokens(run, piece);
|
|
264
|
+
if (splittable && count !== void 0 && count > maxTokens(run)) return halves();
|
|
265
|
+
let output;
|
|
266
|
+
try {
|
|
267
|
+
output = await run(piece, { ignore_labels: [] });
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (splittable && count === void 0) return halves();
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
const tokens = Array.isArray(output[0]) ? output[0] : output;
|
|
273
|
+
if (splittable && count === void 0 && tokens.length >= TRUNCATION_TOKENS) return halves();
|
|
274
|
+
return tokensToEntities(piece, tokens, minScore, labelMap).map((e) => ({
|
|
275
|
+
...e,
|
|
276
|
+
start: e.start + start,
|
|
277
|
+
end: e.end + start
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
async function detect(text) {
|
|
281
|
+
const entities = detectPII(text, { ...config, allow });
|
|
282
|
+
if (mode === "model") {
|
|
283
|
+
for (const [start, end] of chunkText(text)) {
|
|
284
|
+
for (const entity of await classify(text, start, end)) {
|
|
285
|
+
if (REGEX_OWNED_TYPES.includes(entity.type)) continue;
|
|
286
|
+
if (isAllowed(entity.value, allow)) continue;
|
|
287
|
+
if (NAME_LIKE_TYPES.includes(entity.type) && looksLikeIdentifier(text, entity.start, entity.end)) continue;
|
|
288
|
+
if (isTypeEnabled(entity.type, modelFilter)) entities.push(entity);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return mergeEntities(text, entities);
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
detect,
|
|
296
|
+
async redact(text) {
|
|
297
|
+
const entities = await detect(text);
|
|
298
|
+
return { text: applyRedactions(text, entities, config.placeholder), entities };
|
|
299
|
+
},
|
|
300
|
+
async load() {
|
|
301
|
+
if (mode === "model") await getClassifier();
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export { DEFAULT_MODEL_EXCLUDED_TYPES, DEFAULT_PII_ALLOW, DEFAULT_PII_MODEL, alignTokens, chunkText, createPIIRedactor, loadOptionalDependency, looksLikeIdentifier, tokensToEntities };
|
package/dist/chunk-OPDWMD4Q.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
MorphError
|
|
6
|
-
} from "./chunk-VQDDL3UH.js";
|
|
7
|
-
import {
|
|
8
|
-
APIResource
|
|
9
|
-
} from "./chunk-NRG6QX3L.js";
|
|
1
|
+
import { MorphAPIClient } from './chunk-IGXNLXPN.js';
|
|
2
|
+
import { MorphError } from './chunk-4TZBUFVP.js';
|
|
3
|
+
import { APIResource } from './chunk-NRG6QX3L.js';
|
|
10
4
|
|
|
11
5
|
// tools/compact/core.ts
|
|
12
6
|
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
@@ -18,7 +12,8 @@ function resolveClient(clientOrConfig) {
|
|
|
18
12
|
baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL,
|
|
19
13
|
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
|
|
20
14
|
retryConfig: clientOrConfig.retryConfig,
|
|
21
|
-
debug: clientOrConfig.debug
|
|
15
|
+
debug: clientOrConfig.debug,
|
|
16
|
+
redactPII: clientOrConfig.redactPII
|
|
22
17
|
});
|
|
23
18
|
}
|
|
24
19
|
var CompactClient = class extends APIResource {
|
|
@@ -61,8 +56,27 @@ var CompactClient = class extends APIResource {
|
|
|
61
56
|
else if (typeof input.input === "string") body.input = input.input;
|
|
62
57
|
else if (Array.isArray(input.input)) body.messages = input.input;
|
|
63
58
|
else throw new Error("Either 'input' or 'messages' must be provided");
|
|
59
|
+
const pii = this._client.pii?.session();
|
|
60
|
+
if (pii) {
|
|
61
|
+
if (typeof body.query === "string") body.query = await pii.redact(body.query);
|
|
62
|
+
if (typeof body.input === "string") body.input = await pii.redact(body.input);
|
|
63
|
+
if (Array.isArray(body.messages)) {
|
|
64
|
+
body.messages = await Promise.all(
|
|
65
|
+
body.messages.map(
|
|
66
|
+
async (m) => typeof m.content === "string" ? { ...m, content: await pii.redact(m.content) } : m
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
64
71
|
try {
|
|
65
|
-
|
|
72
|
+
const result = await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
|
|
73
|
+
if (pii && result) {
|
|
74
|
+
if (typeof result.output === "string") result.output = pii.restore(result.output);
|
|
75
|
+
for (const m of result.messages ?? []) {
|
|
76
|
+
if (typeof m.content === "string") m.content = pii.restore(m.content);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
66
80
|
} catch (err) {
|
|
67
81
|
if (err instanceof MorphError) {
|
|
68
82
|
throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
|
|
@@ -72,6 +86,4 @@ var CompactClient = class extends APIResource {
|
|
|
72
86
|
}
|
|
73
87
|
};
|
|
74
88
|
|
|
75
|
-
export {
|
|
76
|
-
CompactClient
|
|
77
|
-
};
|
|
89
|
+
export { CompactClient };
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-E6TL6MIH.js";
|
|
7
|
-
|
|
8
|
-
// tools/fastapply/apply.ts
|
|
9
|
-
import { createTwoFilesPatch } from "diff";
|
|
10
|
-
import OpenAI from "openai";
|
|
1
|
+
import { logger } from './chunk-6WP7EA4F.js';
|
|
2
|
+
import { resolvePIIGuard } from './chunk-E63OPKP7.js';
|
|
3
|
+
import { SDK_VERSION } from './chunk-GYE3FY6Z.js';
|
|
4
|
+
import { createTwoFilesPatch } from 'diff';
|
|
5
|
+
import OpenAI from 'openai';
|
|
11
6
|
|
|
12
7
|
// tools/fastapply/anchors.ts
|
|
13
8
|
var DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
|
|
@@ -250,12 +245,23 @@ function countChanges(original, modified) {
|
|
|
250
245
|
};
|
|
251
246
|
}
|
|
252
247
|
async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
|
|
248
|
+
const pii = resolvePIIGuard(config.redactPII)?.session();
|
|
249
|
+
if (pii) {
|
|
250
|
+
const [code, edit, instr] = await Promise.all([
|
|
251
|
+
pii.redact(originalCode),
|
|
252
|
+
pii.redact(codeEdit),
|
|
253
|
+
pii.redact(instructions)
|
|
254
|
+
]);
|
|
255
|
+
logger.debug("FastApply", "pii_redacted", { values: pii.size });
|
|
256
|
+
const merged = await callMorphAPI(code, edit, instr, filepath, { ...config, redactPII: void 0 });
|
|
257
|
+
return { ...merged, content: pii.restoreStrict(merged.content) };
|
|
258
|
+
}
|
|
253
259
|
const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
254
260
|
const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
|
|
255
261
|
const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
|
|
256
262
|
const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
|
|
257
263
|
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
258
|
-
|
|
264
|
+
config.debug || false;
|
|
259
265
|
if (!apiKey) {
|
|
260
266
|
throw new Error(
|
|
261
267
|
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
@@ -388,11 +394,4 @@ async function applyEdit(input, config = {}) {
|
|
|
388
394
|
}
|
|
389
395
|
}
|
|
390
396
|
|
|
391
|
-
export {
|
|
392
|
-
FastApplyAnchorIntegrityError,
|
|
393
|
-
FastApplyContextLengthError,
|
|
394
|
-
generateUdiff,
|
|
395
|
-
countChanges,
|
|
396
|
-
callMorphAPI,
|
|
397
|
-
applyEdit
|
|
398
|
-
};
|
|
397
|
+
export { FastApplyAnchorIntegrityError, FastApplyContextLengthError, applyEdit, callMorphAPI, countChanges, generateUdiff };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/chunk-PA3UTI4A.js
CHANGED
|
@@ -36,7 +36,4 @@ Often this will mean that the start/end of the file will be skipped, but that's
|
|
|
36
36
|
|
|
37
37
|
These edit codeblocks are also read by a less intelligent language model, colloquially called the apply model, to update the file. To help specify the edit to the apply model, you will be very careful when generating the codeblock to not introduce ambiguity. You will specify all unchanged regions (code and comments) of the file with "// ... existing code ..." comment markers. This will ensure the apply model will not delete existing unchanged code or comments when editing the file.`;
|
|
38
38
|
|
|
39
|
-
export {
|
|
40
|
-
EDIT_FILE_TOOL_DESCRIPTION,
|
|
41
|
-
EDIT_FILE_SYSTEM_PROMPT
|
|
42
|
-
};
|
|
39
|
+
export { EDIT_FILE_SYSTEM_PROMPT, EDIT_FILE_TOOL_DESCRIPTION };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
+
|
|
11
|
+
// tools/warp_grep/utils/paths.ts
|
|
12
|
+
function resolveUnderRepo(repoRoot, targetPath) {
|
|
13
|
+
const absRoot = path__default.default.resolve(repoRoot);
|
|
14
|
+
const resolved = path__default.default.resolve(absRoot, targetPath);
|
|
15
|
+
ensureWithinRepo(absRoot, resolved);
|
|
16
|
+
return resolved;
|
|
17
|
+
}
|
|
18
|
+
function ensureWithinRepo(repoRoot, absTarget) {
|
|
19
|
+
const rel = path__default.default.relative(path__default.default.resolve(repoRoot), path__default.default.resolve(absTarget));
|
|
20
|
+
if (rel.startsWith("..") || path__default.default.isAbsolute(rel)) {
|
|
21
|
+
throw new Error(`Path outside repository root: ${absTarget}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function toRepoRelative(repoRoot, absPath) {
|
|
25
|
+
return path__default.default.relative(path__default.default.resolve(repoRoot), path__default.default.resolve(absPath));
|
|
26
|
+
}
|
|
27
|
+
function isSymlink(p) {
|
|
28
|
+
try {
|
|
29
|
+
const st = fs__default.default.lstatSync(p);
|
|
30
|
+
return st.isSymbolicLink();
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function fixPathRepetition(fullPath) {
|
|
36
|
+
const segments = fullPath.split(path__default.default.sep).filter(Boolean);
|
|
37
|
+
if (segments.length < 2) return null;
|
|
38
|
+
for (let len = Math.floor(segments.length / 2); len >= 1; len--) {
|
|
39
|
+
for (let i = 0; i <= segments.length - 2 * len; i++) {
|
|
40
|
+
const first = segments.slice(i, i + len);
|
|
41
|
+
const second = segments.slice(i + len, i + 2 * len);
|
|
42
|
+
if (first.every((seg, idx) => seg === second[idx])) {
|
|
43
|
+
const fixed = [...segments.slice(0, i), ...segments.slice(i + len)];
|
|
44
|
+
return path__default.default.sep + fixed.join(path__default.default.sep);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
51
|
+
try {
|
|
52
|
+
const st = fs__default.default.statSync(filePath);
|
|
53
|
+
if (!st.isFile()) return false;
|
|
54
|
+
if (st.size > maxBytes) return false;
|
|
55
|
+
const fd = fs__default.default.openSync(filePath, "r");
|
|
56
|
+
const buf = Buffer.alloc(512);
|
|
57
|
+
const read = fs__default.default.readSync(fd, buf, 0, buf.length, 0);
|
|
58
|
+
fs__default.default.closeSync(fd);
|
|
59
|
+
for (let i = 0; i < read; i++) {
|
|
60
|
+
const c = buf[i];
|
|
61
|
+
if (c === 0) return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.ensureWithinRepo = ensureWithinRepo;
|
|
70
|
+
exports.fixPathRepetition = fixPathRepetition;
|
|
71
|
+
exports.isSymlink = isSymlink;
|
|
72
|
+
exports.isTextualFile = isTextualFile;
|
|
73
|
+
exports.resolveUnderRepo = resolveUnderRepo;
|
|
74
|
+
exports.toRepoRelative = toRepoRelative;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkDLYDIYDK_cjs = require('./chunk-DLYDIYDK.cjs');
|
|
4
|
+
|
|
5
|
+
// tools/pii/regex.ts
|
|
6
|
+
function isTypeEnabled(type, options) {
|
|
7
|
+
if (options.types && !options.types.includes(type)) return false;
|
|
8
|
+
if (options.excludeTypes?.includes(type)) return false;
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
function isAllowed(value, allow) {
|
|
12
|
+
if (!allow?.length) return false;
|
|
13
|
+
const lower = value.trim().toLowerCase();
|
|
14
|
+
return allow.some(
|
|
15
|
+
(entry) => typeof entry === "string" ? entry.toLowerCase() === lower : new RegExp(entry.source, entry.flags.replace(/[gy]/g, "")).test(value)
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
function mergeEntities(text, entities) {
|
|
19
|
+
const sorted = [...entities].sort(
|
|
20
|
+
(a, b) => a.start - b.start || b.end - a.end || (a.source === b.source ? 0 : a.source === "regex" ? -1 : 1)
|
|
21
|
+
);
|
|
22
|
+
const merged = [];
|
|
23
|
+
for (const entity of sorted) {
|
|
24
|
+
const last = merged[merged.length - 1];
|
|
25
|
+
if (last && entity.start < last.end) {
|
|
26
|
+
if (entity.end > last.end) {
|
|
27
|
+
const longer = entity.end - entity.start > last.end - last.start ? entity : last;
|
|
28
|
+
merged[merged.length - 1] = {
|
|
29
|
+
...longer,
|
|
30
|
+
start: last.start,
|
|
31
|
+
end: entity.end,
|
|
32
|
+
value: text.slice(last.start, entity.end)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
merged.push(entity);
|
|
38
|
+
}
|
|
39
|
+
return merged;
|
|
40
|
+
}
|
|
41
|
+
function applyRedactions(text, entities, placeholder = "type") {
|
|
42
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
43
|
+
const counters = /* @__PURE__ */ new Map();
|
|
44
|
+
let out = "";
|
|
45
|
+
let cursor = 0;
|
|
46
|
+
for (const entity of entities) {
|
|
47
|
+
let replacement;
|
|
48
|
+
if (typeof placeholder === "function") {
|
|
49
|
+
replacement = placeholder(entity);
|
|
50
|
+
} else if (placeholder === "indexed") {
|
|
51
|
+
const key = `${entity.type}\0${entity.value}`;
|
|
52
|
+
let index = indexes.get(key);
|
|
53
|
+
if (index === void 0) {
|
|
54
|
+
index = (counters.get(entity.type) ?? 0) + 1;
|
|
55
|
+
counters.set(entity.type, index);
|
|
56
|
+
indexes.set(key, index);
|
|
57
|
+
}
|
|
58
|
+
replacement = `[${entity.type}_${index}]`;
|
|
59
|
+
} else {
|
|
60
|
+
replacement = `[${entity.type}]`;
|
|
61
|
+
}
|
|
62
|
+
out += text.slice(cursor, entity.start) + replacement;
|
|
63
|
+
cursor = entity.end;
|
|
64
|
+
}
|
|
65
|
+
return out + text.slice(cursor);
|
|
66
|
+
}
|
|
67
|
+
function detectPII(text, options = {}) {
|
|
68
|
+
if (typeof text !== "string") {
|
|
69
|
+
throw new TypeError(`PII detection expects a string, got ${text === null ? "null" : typeof text}`);
|
|
70
|
+
}
|
|
71
|
+
const found = [];
|
|
72
|
+
for (const pattern of chunkDLYDIYDK_cjs.PII_PATTERNS) {
|
|
73
|
+
if (!isTypeEnabled(pattern.type, options)) continue;
|
|
74
|
+
for (const candidate of candidates(pattern, text)) {
|
|
75
|
+
if (!isAllowed(candidate.value, options.allow)) found.push(candidate);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return mergeEntities(text, found);
|
|
79
|
+
}
|
|
80
|
+
function* candidates(pattern, text) {
|
|
81
|
+
const { regex, group, validate, type } = pattern;
|
|
82
|
+
regex.lastIndex = 0;
|
|
83
|
+
let match;
|
|
84
|
+
while ((match = regex.exec(text)) !== null) {
|
|
85
|
+
if (match[0] === "") {
|
|
86
|
+
regex.lastIndex++;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
const value = group ? match[group] : match[0];
|
|
90
|
+
if (!value) continue;
|
|
91
|
+
const start = group ? match.index + match[0].lastIndexOf(value) : match.index;
|
|
92
|
+
const before = text.slice(Math.max(0, match.index - chunkDLYDIYDK_cjs.CONTEXT_CHARS), match.index);
|
|
93
|
+
if (validate && !validate(value, before)) continue;
|
|
94
|
+
yield { type, start, end: start + value.length, value, source: "regex" };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function redactPII(text, options = {}) {
|
|
98
|
+
const entities = detectPII(text, options);
|
|
99
|
+
return { text: applyRedactions(text, entities, options.placeholder), entities };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.applyRedactions = applyRedactions;
|
|
103
|
+
exports.detectPII = detectPII;
|
|
104
|
+
exports.isAllowed = isAllowed;
|
|
105
|
+
exports.isTypeEnabled = isTypeEnabled;
|
|
106
|
+
exports.mergeEntities = mergeEntities;
|
|
107
|
+
exports.redactPII = redactPII;
|
package/dist/chunk-RYVW7RUM.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AGENT_CONFIG
|
|
3
|
-
} from "./chunk-M34E2AMK.js";
|
|
1
|
+
import { AGENT_CONFIG } from './chunk-M34E2AMK.js';
|
|
4
2
|
|
|
5
3
|
// tools/warp_grep/providers/remote.ts
|
|
6
4
|
var SKIP_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -210,6 +208,4 @@ var RemoteCommandsProvider = class {
|
|
|
210
208
|
}
|
|
211
209
|
};
|
|
212
210
|
|
|
213
|
-
export {
|
|
214
|
-
RemoteCommandsProvider
|
|
215
|
-
};
|
|
211
|
+
export { RemoteCommandsProvider };
|