@morphllm/morphsdk 0.2.203 → 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.
Files changed (169) hide show
  1. package/README.md +101 -0
  2. package/dist/chunk-2GMG5XKU.js +100 -0
  3. package/dist/{chunk-NDUC7OV6.cjs → chunk-3HAHJYZQ.cjs} +3 -3
  4. package/dist/{chunk-AJBZA23L.js → chunk-3JROKKS4.js} +1 -1
  5. package/dist/{chunk-J56Q6C4Y.js → chunk-43JBUEIX.js} +1 -1
  6. package/dist/{chunk-E7FLETFO.js → chunk-4TZBUFVP.js} +1 -1
  7. package/dist/{chunk-EI2M567U.js → chunk-564XJOQP.js} +1 -1
  8. package/dist/{chunk-7NA7X7W2.cjs → chunk-5H3FKFOI.cjs} +8 -8
  9. package/dist/{chunk-65W4I66Q.cjs → chunk-5TTZQF4X.cjs} +16 -9
  10. package/dist/chunk-6HAYJA6M.cjs +317 -0
  11. package/dist/chunk-DLYDIYDK.cjs +305 -0
  12. package/dist/{chunk-LLQH6CCB.js → chunk-DYCMPDPV.js} +5 -3
  13. package/dist/{chunk-66THRMD7.js → chunk-DZP7BR66.js} +16 -12
  14. package/dist/chunk-E63OPKP7.js +96 -0
  15. package/dist/{chunk-IUM6CQYX.js → chunk-EJ6ID24K.js} +1 -1
  16. package/dist/{chunk-AFF6XYKL.cjs → chunk-F633IVQA.cjs} +28 -8
  17. package/dist/{chunk-GIQAIHUI.js → chunk-FGA6EYC2.js} +29 -6
  18. package/dist/{chunk-GDFPZ3NJ.js → chunk-G4RODMXA.js} +1 -1
  19. package/dist/{chunk-B3FD67F2.cjs → chunk-GUNGJC6X.cjs} +3 -3
  20. package/dist/{chunk-OCCGJ4S6.js → chunk-GYE3FY6Z.js} +1 -1
  21. package/dist/{chunk-OXXMTDOY.cjs → chunk-HNMEBYIS.cjs} +2 -2
  22. package/dist/{chunk-JNQKQKHS.cjs → chunk-HP3PCOTW.cjs} +3 -3
  23. package/dist/{chunk-KLVJIC2O.js → chunk-IGXNLXPN.js} +10 -3
  24. package/dist/{chunk-UUCRWJJR.cjs → chunk-JHC2R3HU.cjs} +20 -16
  25. package/dist/{chunk-N7UKZ5X7.js → chunk-JVMIFGZY.js} +4 -3
  26. package/dist/chunk-KF6S3EPJ.cjs +100 -0
  27. package/dist/{chunk-EZ2OFDBJ.js → chunk-L5SCKZVK.js} +10 -5
  28. package/dist/{chunk-E3XNKAMI.js → chunk-LQST3NW2.js} +1 -1
  29. package/dist/{chunk-GSUQGDCL.cjs → chunk-MMX5PUGC.cjs} +47 -40
  30. package/dist/{chunk-JBTR3FQD.cjs → chunk-NJWOWXUR.cjs} +8 -6
  31. package/dist/{chunk-HMLYJVZM.cjs → chunk-OCKEEEYE.cjs} +30 -7
  32. package/dist/chunk-OENJO7YW.js +306 -0
  33. package/dist/chunk-OKLAYEBC.cjs +2 -0
  34. package/dist/{chunk-H3HRSRR5.js → chunk-OX5GN2KB.js} +24 -4
  35. package/dist/{chunk-JUGNTIVU.js → chunk-OYBOP47A.js} +13 -1
  36. package/dist/chunk-OZHCHPIE.js +1 -0
  37. package/dist/{chunk-TL34BLQD.cjs → chunk-QT5LGZG3.cjs} +1 -1
  38. package/dist/chunk-R3TUE7O2.cjs +107 -0
  39. package/dist/{chunk-AXEKIRRY.js → chunk-SOQYE5A4.js} +27 -20
  40. package/dist/{chunk-KSZYOX6S.cjs → chunk-ST2OXLT5.cjs} +8 -8
  41. package/dist/{chunk-2UIOCSVJ.js → chunk-TH4MG73B.js} +1 -1
  42. package/dist/{chunk-NLACTMZT.js → chunk-U4PYAGNR.js} +1 -1
  43. package/dist/{chunk-VDFLPO7B.cjs → chunk-UHFVWYSP.cjs} +14 -2
  44. package/dist/{chunk-4R5MDGL6.cjs → chunk-UKBSXYKE.cjs} +3 -3
  45. package/dist/{chunk-S6QBPXBI.cjs → chunk-UZMMJ47A.cjs} +5 -5
  46. package/dist/{chunk-ODY2NKQU.cjs → chunk-VYE7O4FM.cjs} +5 -4
  47. package/dist/{chunk-JOZC4T6C.cjs → chunk-WIYVT4UO.cjs} +16 -11
  48. package/dist/{chunk-OM5ZSXQW.cjs → chunk-WJHHO24M.cjs} +2 -2
  49. package/dist/{chunk-ZLG2M2I4.cjs → chunk-YAUXTFIN.cjs} +2 -2
  50. package/dist/{chunk-JY6COF3X.js → chunk-YJUCGZNN.js} +1 -1
  51. package/dist/chunk-ZX6T3LNG.js +302 -0
  52. package/dist/{client-BWhi-vSj.d.ts → client-DSXbcxII.d.ts} +10 -1
  53. package/dist/client.cjs +27 -23
  54. package/dist/client.d.ts +4 -2
  55. package/dist/client.js +26 -22
  56. package/dist/core/client.cjs +9 -5
  57. package/dist/core/client.d.ts +8 -0
  58. package/dist/core/client.js +8 -4
  59. package/dist/core/error.cjs +4 -4
  60. package/dist/core/error.js +3 -3
  61. package/dist/core/index.cjs +10 -6
  62. package/dist/core/index.d.ts +2 -0
  63. package/dist/core/index.js +8 -4
  64. package/dist/core/resource.d.ts +2 -0
  65. package/dist/edge.cjs +43 -31
  66. package/dist/edge.d.ts +3 -0
  67. package/dist/edge.js +11 -7
  68. package/dist/guard-CvW03v4u.d.ts +59 -0
  69. package/dist/index.cjs +73 -48
  70. package/dist/index.d.ts +6 -2
  71. package/dist/index.js +30 -25
  72. package/dist/modelrouter/core.cjs +14 -10
  73. package/dist/modelrouter/core.d.ts +2 -0
  74. package/dist/modelrouter/core.js +9 -5
  75. package/dist/modelrouter/index.cjs +14 -10
  76. package/dist/modelrouter/index.d.ts +2 -0
  77. package/dist/modelrouter/index.js +9 -5
  78. package/dist/modelrouter/types.d.ts +5 -0
  79. package/dist/subagents/anthropic.cjs +16 -12
  80. package/dist/subagents/anthropic.d.ts +3 -1
  81. package/dist/subagents/anthropic.js +15 -11
  82. package/dist/subagents/index.d.ts +3 -1
  83. package/dist/subagents/prompts.d.ts +3 -1
  84. package/dist/subagents/types.d.ts +3 -1
  85. package/dist/subagents/vercel.cjs +16 -12
  86. package/dist/subagents/vercel.d.ts +3 -1
  87. package/dist/subagents/vercel.js +15 -11
  88. package/dist/tools/compact/core.cjs +10 -6
  89. package/dist/tools/compact/core.d.ts +2 -0
  90. package/dist/tools/compact/core.js +9 -5
  91. package/dist/tools/compact/index.cjs +12 -8
  92. package/dist/tools/compact/index.d.ts +3 -1
  93. package/dist/tools/compact/index.js +10 -6
  94. package/dist/tools/compact/types.d.ts +4 -4
  95. package/dist/tools/fastapply/anthropic.cjs +16 -12
  96. package/dist/tools/fastapply/anthropic.d.ts +2 -0
  97. package/dist/tools/fastapply/anthropic.js +11 -7
  98. package/dist/tools/fastapply/apply.cjs +12 -8
  99. package/dist/tools/fastapply/apply.d.ts +2 -0
  100. package/dist/tools/fastapply/apply.js +6 -2
  101. package/dist/tools/fastapply/core.cjs +18 -14
  102. package/dist/tools/fastapply/core.d.ts +3 -0
  103. package/dist/tools/fastapply/core.js +10 -6
  104. package/dist/tools/fastapply/index.cjs +22 -18
  105. package/dist/tools/fastapply/index.d.ts +2 -0
  106. package/dist/tools/fastapply/index.js +13 -9
  107. package/dist/tools/fastapply/openai.cjs +17 -13
  108. package/dist/tools/fastapply/openai.d.ts +2 -0
  109. package/dist/tools/fastapply/openai.js +11 -7
  110. package/dist/tools/fastapply/types.d.ts +9 -4
  111. package/dist/tools/fastapply/vercel.cjs +15 -11
  112. package/dist/tools/fastapply/vercel.d.ts +2 -0
  113. package/dist/tools/fastapply/vercel.js +11 -7
  114. package/dist/tools/index.cjs +22 -18
  115. package/dist/tools/index.d.ts +2 -0
  116. package/dist/tools/index.js +13 -9
  117. package/dist/tools/pii/index.cjs +47 -0
  118. package/dist/tools/pii/index.d.ts +4 -0
  119. package/dist/tools/pii/index.js +6 -0
  120. package/dist/tools/pii/model.cjs +45 -0
  121. package/dist/tools/pii/model.d.ts +83 -0
  122. package/dist/tools/pii/model.js +4 -0
  123. package/dist/tools/pii/patterns.cjs +15 -0
  124. package/dist/tools/pii/patterns.d.ts +31 -0
  125. package/dist/tools/pii/patterns.js +2 -0
  126. package/dist/tools/pii/regex.cjs +32 -0
  127. package/dist/tools/pii/regex.d.ts +48 -0
  128. package/dist/tools/pii/regex.js +3 -0
  129. package/dist/tools/pii/types.cjs +2 -0
  130. package/dist/tools/pii/types.d.ts +108 -0
  131. package/dist/tools/pii/types.js +1 -0
  132. package/dist/tools/utils/resilience.cjs +5 -5
  133. package/dist/tools/utils/resilience.js +2 -2
  134. package/dist/tools/warp_grep/agent/parser.d.ts +2 -0
  135. package/dist/tools/warp_grep/agent/runner.cjs +9 -5
  136. package/dist/tools/warp_grep/agent/runner.d.ts +2 -0
  137. package/dist/tools/warp_grep/agent/runner.js +7 -3
  138. package/dist/tools/warp_grep/agent/types.d.ts +4 -0
  139. package/dist/tools/warp_grep/anthropic.cjs +21 -17
  140. package/dist/tools/warp_grep/anthropic.d.ts +3 -1
  141. package/dist/tools/warp_grep/anthropic.js +15 -11
  142. package/dist/tools/warp_grep/client.cjs +21 -17
  143. package/dist/tools/warp_grep/client.d.ts +3 -1
  144. package/dist/tools/warp_grep/client.js +14 -10
  145. package/dist/tools/warp_grep/gemini.cjs +22 -18
  146. package/dist/tools/warp_grep/gemini.d.ts +3 -1
  147. package/dist/tools/warp_grep/gemini.js +15 -11
  148. package/dist/tools/warp_grep/harness.cjs +16 -16
  149. package/dist/tools/warp_grep/harness.d.ts +2 -0
  150. package/dist/tools/warp_grep/harness.js +4 -4
  151. package/dist/tools/warp_grep/index.cjs +30 -26
  152. package/dist/tools/warp_grep/index.d.ts +3 -1
  153. package/dist/tools/warp_grep/index.js +17 -13
  154. package/dist/tools/warp_grep/openai.cjs +22 -18
  155. package/dist/tools/warp_grep/openai.d.ts +3 -1
  156. package/dist/tools/warp_grep/openai.js +15 -11
  157. package/dist/tools/warp_grep/providers/code_storage_http.d.ts +3 -1
  158. package/dist/tools/warp_grep/providers/local.cjs +3 -3
  159. package/dist/tools/warp_grep/providers/local.js +2 -2
  160. package/dist/tools/warp_grep/providers/remote.d.ts +3 -1
  161. package/dist/tools/warp_grep/vercel.cjs +22 -18
  162. package/dist/tools/warp_grep/vercel.d.ts +3 -1
  163. package/dist/tools/warp_grep/vercel.js +15 -11
  164. package/dist/{types-DxZLPogx.d.ts → types-BKhXjDCB.d.ts} +6 -1
  165. package/dist/version.cjs +2 -2
  166. package/dist/version.js +1 -1
  167. package/package.json +11 -2
  168. package/dist/{chunk-OOEORM7H.cjs → chunk-E6V75LI6.cjs} +1 -1
  169. package/dist/{chunk-OSL4CNSO.js → chunk-TLMAMVAW.js} +1 -1
@@ -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 };
@@ -0,0 +1,2 @@
1
+ 'use strict';
2
+
@@ -1,5 +1,5 @@
1
- import { MorphAPIClient } from './chunk-KLVJIC2O.js';
2
- import { MorphError } from './chunk-E7FLETFO.js';
1
+ import { MorphAPIClient } from './chunk-IGXNLXPN.js';
2
+ import { MorphError } from './chunk-4TZBUFVP.js';
3
3
  import { APIResource } from './chunk-NRG6QX3L.js';
4
4
 
5
5
  // tools/compact/core.ts
@@ -12,7 +12,8 @@ function resolveClient(clientOrConfig) {
12
12
  baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL,
13
13
  timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
14
14
  retryConfig: clientOrConfig.retryConfig,
15
- debug: clientOrConfig.debug
15
+ debug: clientOrConfig.debug,
16
+ redactPII: clientOrConfig.redactPII
16
17
  });
17
18
  }
18
19
  var CompactClient = class extends APIResource {
@@ -55,8 +56,27 @@ var CompactClient = class extends APIResource {
55
56
  else if (typeof input.input === "string") body.input = input.input;
56
57
  else if (Array.isArray(input.input)) body.messages = input.input;
57
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
+ }
58
71
  try {
59
- return await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
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;
60
80
  } catch (err) {
61
81
  if (err instanceof MorphError) {
62
82
  throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
@@ -1,5 +1,6 @@
1
1
  import { logger } from './chunk-6WP7EA4F.js';
2
- import { SDK_VERSION } from './chunk-OCCGJ4S6.js';
2
+ import { resolvePIIGuard } from './chunk-E63OPKP7.js';
3
+ import { SDK_VERSION } from './chunk-GYE3FY6Z.js';
3
4
  import { createTwoFilesPatch } from 'diff';
4
5
  import OpenAI from 'openai';
5
6
 
@@ -244,6 +245,17 @@ function countChanges(original, modified) {
244
245
  };
245
246
  }
246
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
+ }
247
259
  const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
248
260
  const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
249
261
  const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
@@ -0,0 +1 @@
1
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  // package.json
4
4
  var package_default = {
5
- version: "0.2.203"};
5
+ version: "0.2.204"};
6
6
 
7
7
  // version.ts
8
8
  var SDK_VERSION = package_default.version;
@@ -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;
@@ -1,16 +1,16 @@
1
- import { createWarpGrepTool, createGitHubSearchTool } from './chunk-AJBZA23L.js';
2
- import { createWarpGrepTool as createWarpGrepTool$2, createGitHubSearchTool as createGitHubSearchTool$2 } from './chunk-JY6COF3X.js';
3
- import { createWarpGrepTool as createWarpGrepTool$1, createGitHubSearchTool as createGitHubSearchTool$1 } from './chunk-2UIOCSVJ.js';
4
- import { createEditFileTool } from './chunk-GDFPZ3NJ.js';
5
- import { createEditFileTool as createEditFileTool$2 } from './chunk-NLACTMZT.js';
6
- import { createEditFileTool as createEditFileTool$1 } from './chunk-J56Q6C4Y.js';
7
- import { FastApplyClient } from './chunk-LLQH6CCB.js';
8
- import { createExploreSubagent } from './chunk-IUM6CQYX.js';
9
- import { createExploreSubagent as createExploreSubagent$1 } from './chunk-E3XNKAMI.js';
10
- import { WarpGrepClient } from './chunk-66THRMD7.js';
11
- import { RouterClassifier, RawRouter, GeminiRouter, AnthropicRouter, OpenAIRouter } from './chunk-EZ2OFDBJ.js';
12
- import { CompactClient } from './chunk-H3HRSRR5.js';
13
- import { MorphAPIClient } from './chunk-KLVJIC2O.js';
1
+ import { createWarpGrepTool as createWarpGrepTool$2, createGitHubSearchTool as createGitHubSearchTool$2 } from './chunk-YJUCGZNN.js';
2
+ import { createWarpGrepTool as createWarpGrepTool$1, createGitHubSearchTool as createGitHubSearchTool$1 } from './chunk-TH4MG73B.js';
3
+ import { createWarpGrepTool, createGitHubSearchTool } from './chunk-3JROKKS4.js';
4
+ import { createExploreSubagent as createExploreSubagent$1 } from './chunk-LQST3NW2.js';
5
+ import { createEditFileTool } from './chunk-G4RODMXA.js';
6
+ import { createEditFileTool as createEditFileTool$2 } from './chunk-U4PYAGNR.js';
7
+ import { createEditFileTool as createEditFileTool$1 } from './chunk-43JBUEIX.js';
8
+ import { FastApplyClient } from './chunk-DYCMPDPV.js';
9
+ import { createExploreSubagent } from './chunk-EJ6ID24K.js';
10
+ import { WarpGrepClient } from './chunk-DZP7BR66.js';
11
+ import { RouterClassifier, RawRouter, GeminiRouter, AnthropicRouter, OpenAIRouter } from './chunk-L5SCKZVK.js';
12
+ import { CompactClient } from './chunk-OX5GN2KB.js';
13
+ import { MorphAPIClient } from './chunk-IGXNLXPN.js';
14
14
  import { logger } from './chunk-6WP7EA4F.js';
15
15
 
16
16
  // factories/openai.ts
@@ -27,7 +27,8 @@ var OpenAIToolFactory = class {
27
27
  createWarpGrepTool(toolConfig) {
28
28
  return createWarpGrepTool({
29
29
  ...toolConfig,
30
- morphApiKey: this.config.apiKey
30
+ morphApiKey: this.config.apiKey,
31
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
31
32
  });
32
33
  }
33
34
  /**
@@ -39,7 +40,8 @@ var OpenAIToolFactory = class {
39
40
  createEditFileTool(toolConfig = {}) {
40
41
  return createEditFileTool({
41
42
  ...toolConfig,
42
- morphApiKey: this.config.apiKey
43
+ morphApiKey: this.config.apiKey,
44
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
43
45
  });
44
46
  }
45
47
  /**
@@ -70,7 +72,8 @@ var AnthropicToolFactory = class {
70
72
  createWarpGrepTool(toolConfig) {
71
73
  return createWarpGrepTool$1({
72
74
  ...toolConfig,
73
- morphApiKey: this.config.apiKey
75
+ morphApiKey: this.config.apiKey,
76
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
74
77
  });
75
78
  }
76
79
  /**
@@ -82,7 +85,8 @@ var AnthropicToolFactory = class {
82
85
  createEditFileTool(toolConfig = {}) {
83
86
  return createEditFileTool$1({
84
87
  ...toolConfig,
85
- morphApiKey: this.config.apiKey
88
+ morphApiKey: this.config.apiKey,
89
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
86
90
  });
87
91
  }
88
92
  /**
@@ -125,7 +129,8 @@ var VercelToolFactory = class {
125
129
  createWarpGrepTool(toolConfig) {
126
130
  return createWarpGrepTool$2({
127
131
  ...toolConfig,
128
- morphApiKey: this.config.apiKey
132
+ morphApiKey: this.config.apiKey,
133
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
129
134
  });
130
135
  }
131
136
  /**
@@ -137,7 +142,8 @@ var VercelToolFactory = class {
137
142
  createEditFileTool(toolConfig = {}) {
138
143
  return createEditFileTool$2({
139
144
  ...toolConfig,
140
- morphApiKey: this.config.apiKey
145
+ morphApiKey: this.config.apiKey,
146
+ redactPII: toolConfig.redactPII ?? this.config.redactPII
141
147
  });
142
148
  }
143
149
  /**
@@ -203,7 +209,8 @@ var MorphClient = class extends MorphAPIClient {
203
209
  apiKey: config.apiKey,
204
210
  timeout: config.timeout,
205
211
  retryConfig: config.retryConfig,
206
- debug: config.debug
212
+ debug: config.debug,
213
+ redactPII: config.redactPII
207
214
  });
208
215
  if (!config.apiKey) {
209
216
  throw new Error("Morph API key is required. Pass it as { apiKey } when constructing MorphClient.");
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkEJTL2BOZ_cjs = require('./chunk-EJTL2BOZ.cjs');
4
- var chunkUUCRWJJR_cjs = require('./chunk-UUCRWJJR.cjs');
4
+ var chunkJHC2R3HU_cjs = require('./chunk-JHC2R3HU.cjs');
5
5
 
6
6
  // tools/warp_grep/openai.ts
7
7
  var TOOL_PARAMETERS = {
@@ -20,7 +20,7 @@ var warpGrepTool = {
20
20
  }
21
21
  };
22
22
  async function execute(input, config) {
23
- return chunkUUCRWJJR_cjs.executeToolCall(input, config);
23
+ return chunkJHC2R3HU_cjs.executeToolCall(input, config);
24
24
  }
25
25
  function createWarpGrepTool(config) {
26
26
  const tool = {
@@ -33,15 +33,15 @@ function createWarpGrepTool(config) {
33
33
  };
34
34
  return Object.assign(tool, {
35
35
  execute: async (input) => {
36
- return chunkUUCRWJJR_cjs.executeToolCall(input, config);
36
+ return chunkJHC2R3HU_cjs.executeToolCall(input, config);
37
37
  },
38
38
  formatResult: (result) => {
39
- return chunkUUCRWJJR_cjs.formatResult(result);
39
+ return chunkJHC2R3HU_cjs.formatResult(result);
40
40
  }
41
41
  });
42
42
  }
43
43
  function createGitHubSearchTool(config) {
44
- const client = new chunkUUCRWJJR_cjs.WarpGrepClient(config);
44
+ const client = new chunkJHC2R3HU_cjs.WarpGrepClient(config);
45
45
  const tool = {
46
46
  type: "function",
47
47
  function: {
@@ -59,7 +59,7 @@ function createGitHubSearchTool(config) {
59
59
  return client.searchGitHub({ searchTerm: input.search_term, github, branch: input.branch });
60
60
  },
61
61
  formatResult: (result) => {
62
- return chunkUUCRWJJR_cjs.formatResult(result);
62
+ return chunkJHC2R3HU_cjs.formatResult(result);
63
63
  }
64
64
  });
65
65
  }
@@ -74,10 +74,10 @@ function createGitHubReadFileTool(config) {
74
74
  };
75
75
  return Object.assign(tool, {
76
76
  execute: async (input) => {
77
- return chunkUUCRWJJR_cjs.executeGitHubReadFile(input, config);
77
+ return chunkJHC2R3HU_cjs.executeGitHubReadFile(input, config);
78
78
  },
79
79
  formatResult: (result) => {
80
- return chunkUUCRWJJR_cjs.formatGitHubReadFileResult(result);
80
+ return chunkJHC2R3HU_cjs.formatGitHubReadFileResult(result);
81
81
  }
82
82
  });
83
83
  }
@@ -1,5 +1,5 @@
1
1
  import { WARP_GREP_DESCRIPTION, WARP_GREP_TOOL_NAME, GITHUB_SEARCH_INPUT_SCHEMA, GITHUB_SEARCH_DESCRIPTION, GITHUB_SEARCH_TOOL_NAME, GITHUB_READ_FILE_INPUT_SCHEMA, GITHUB_READ_FILE_DESCRIPTION, GITHUB_READ_FILE_TOOL_NAME } from './chunk-UAPK3AIJ.js';
2
- import { executeToolCall, formatResult, WarpGrepClient, formatGitHubReadFileResult, executeGitHubReadFile } from './chunk-66THRMD7.js';
2
+ import { executeToolCall, formatResult, WarpGrepClient, formatGitHubReadFileResult, executeGitHubReadFile } from './chunk-DZP7BR66.js';
3
3
 
4
4
  // tools/warp_grep/anthropic.ts
5
5
  var INPUT_SCHEMA = {
@@ -1,5 +1,5 @@
1
1
  import { EDIT_FILE_TOOL_DESCRIPTION, EDIT_FILE_SYSTEM_PROMPT } from './chunk-PA3UTI4A.js';
2
- import { executeEditFile } from './chunk-LLQH6CCB.js';
2
+ import { executeEditFile } from './chunk-DYCMPDPV.js';
3
3
  import { __export } from './chunk-MLKGABMK.js';
4
4
  import { tool } from 'ai';
5
5
  import { z } from 'zod';