@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.
- package/README.md +101 -0
- package/dist/chunk-2GMG5XKU.js +100 -0
- package/dist/{chunk-NDUC7OV6.cjs → chunk-3HAHJYZQ.cjs} +3 -3
- package/dist/{chunk-AJBZA23L.js → chunk-3JROKKS4.js} +1 -1
- package/dist/{chunk-J56Q6C4Y.js → chunk-43JBUEIX.js} +1 -1
- package/dist/{chunk-E7FLETFO.js → chunk-4TZBUFVP.js} +1 -1
- package/dist/{chunk-EI2M567U.js → chunk-564XJOQP.js} +1 -1
- package/dist/{chunk-7NA7X7W2.cjs → chunk-5H3FKFOI.cjs} +8 -8
- package/dist/{chunk-65W4I66Q.cjs → chunk-5TTZQF4X.cjs} +16 -9
- package/dist/chunk-6HAYJA6M.cjs +317 -0
- package/dist/chunk-DLYDIYDK.cjs +305 -0
- package/dist/{chunk-LLQH6CCB.js → chunk-DYCMPDPV.js} +5 -3
- package/dist/{chunk-66THRMD7.js → chunk-DZP7BR66.js} +16 -12
- package/dist/chunk-E63OPKP7.js +96 -0
- package/dist/{chunk-IUM6CQYX.js → chunk-EJ6ID24K.js} +1 -1
- package/dist/{chunk-AFF6XYKL.cjs → chunk-F633IVQA.cjs} +28 -8
- package/dist/{chunk-GIQAIHUI.js → chunk-FGA6EYC2.js} +29 -6
- package/dist/{chunk-GDFPZ3NJ.js → chunk-G4RODMXA.js} +1 -1
- package/dist/{chunk-B3FD67F2.cjs → chunk-GUNGJC6X.cjs} +3 -3
- package/dist/{chunk-OCCGJ4S6.js → chunk-GYE3FY6Z.js} +1 -1
- package/dist/{chunk-OXXMTDOY.cjs → chunk-HNMEBYIS.cjs} +2 -2
- package/dist/{chunk-JNQKQKHS.cjs → chunk-HP3PCOTW.cjs} +3 -3
- package/dist/{chunk-KLVJIC2O.js → chunk-IGXNLXPN.js} +10 -3
- package/dist/{chunk-UUCRWJJR.cjs → chunk-JHC2R3HU.cjs} +20 -16
- package/dist/{chunk-N7UKZ5X7.js → chunk-JVMIFGZY.js} +4 -3
- package/dist/chunk-KF6S3EPJ.cjs +100 -0
- package/dist/{chunk-EZ2OFDBJ.js → chunk-L5SCKZVK.js} +10 -5
- package/dist/{chunk-E3XNKAMI.js → chunk-LQST3NW2.js} +1 -1
- package/dist/{chunk-GSUQGDCL.cjs → chunk-MMX5PUGC.cjs} +47 -40
- package/dist/{chunk-JBTR3FQD.cjs → chunk-NJWOWXUR.cjs} +8 -6
- package/dist/{chunk-HMLYJVZM.cjs → chunk-OCKEEEYE.cjs} +30 -7
- package/dist/chunk-OENJO7YW.js +306 -0
- package/dist/chunk-OKLAYEBC.cjs +2 -0
- package/dist/{chunk-H3HRSRR5.js → chunk-OX5GN2KB.js} +24 -4
- package/dist/{chunk-JUGNTIVU.js → chunk-OYBOP47A.js} +13 -1
- package/dist/chunk-OZHCHPIE.js +1 -0
- package/dist/{chunk-TL34BLQD.cjs → chunk-QT5LGZG3.cjs} +1 -1
- package/dist/chunk-R3TUE7O2.cjs +107 -0
- package/dist/{chunk-AXEKIRRY.js → chunk-SOQYE5A4.js} +27 -20
- package/dist/{chunk-KSZYOX6S.cjs → chunk-ST2OXLT5.cjs} +8 -8
- package/dist/{chunk-2UIOCSVJ.js → chunk-TH4MG73B.js} +1 -1
- package/dist/{chunk-NLACTMZT.js → chunk-U4PYAGNR.js} +1 -1
- package/dist/{chunk-VDFLPO7B.cjs → chunk-UHFVWYSP.cjs} +14 -2
- package/dist/{chunk-4R5MDGL6.cjs → chunk-UKBSXYKE.cjs} +3 -3
- package/dist/{chunk-S6QBPXBI.cjs → chunk-UZMMJ47A.cjs} +5 -5
- package/dist/{chunk-ODY2NKQU.cjs → chunk-VYE7O4FM.cjs} +5 -4
- package/dist/{chunk-JOZC4T6C.cjs → chunk-WIYVT4UO.cjs} +16 -11
- package/dist/{chunk-OM5ZSXQW.cjs → chunk-WJHHO24M.cjs} +2 -2
- package/dist/{chunk-ZLG2M2I4.cjs → chunk-YAUXTFIN.cjs} +2 -2
- package/dist/{chunk-JY6COF3X.js → chunk-YJUCGZNN.js} +1 -1
- package/dist/chunk-ZX6T3LNG.js +302 -0
- package/dist/{client-BWhi-vSj.d.ts → client-DSXbcxII.d.ts} +10 -1
- package/dist/client.cjs +27 -23
- package/dist/client.d.ts +4 -2
- package/dist/client.js +26 -22
- package/dist/core/client.cjs +9 -5
- package/dist/core/client.d.ts +8 -0
- package/dist/core/client.js +8 -4
- package/dist/core/error.cjs +4 -4
- package/dist/core/error.js +3 -3
- package/dist/core/index.cjs +10 -6
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +8 -4
- package/dist/core/resource.d.ts +2 -0
- package/dist/edge.cjs +43 -31
- package/dist/edge.d.ts +3 -0
- package/dist/edge.js +11 -7
- package/dist/guard-CvW03v4u.d.ts +59 -0
- package/dist/index.cjs +73 -48
- package/dist/index.d.ts +6 -2
- package/dist/index.js +30 -25
- package/dist/modelrouter/core.cjs +14 -10
- package/dist/modelrouter/core.d.ts +2 -0
- package/dist/modelrouter/core.js +9 -5
- package/dist/modelrouter/index.cjs +14 -10
- package/dist/modelrouter/index.d.ts +2 -0
- package/dist/modelrouter/index.js +9 -5
- package/dist/modelrouter/types.d.ts +5 -0
- package/dist/subagents/anthropic.cjs +16 -12
- package/dist/subagents/anthropic.d.ts +3 -1
- package/dist/subagents/anthropic.js +15 -11
- package/dist/subagents/index.d.ts +3 -1
- package/dist/subagents/prompts.d.ts +3 -1
- package/dist/subagents/types.d.ts +3 -1
- package/dist/subagents/vercel.cjs +16 -12
- package/dist/subagents/vercel.d.ts +3 -1
- package/dist/subagents/vercel.js +15 -11
- package/dist/tools/compact/core.cjs +10 -6
- package/dist/tools/compact/core.d.ts +2 -0
- package/dist/tools/compact/core.js +9 -5
- package/dist/tools/compact/index.cjs +12 -8
- package/dist/tools/compact/index.d.ts +3 -1
- package/dist/tools/compact/index.js +10 -6
- package/dist/tools/compact/types.d.ts +4 -4
- package/dist/tools/fastapply/anthropic.cjs +16 -12
- package/dist/tools/fastapply/anthropic.d.ts +2 -0
- package/dist/tools/fastapply/anthropic.js +11 -7
- package/dist/tools/fastapply/apply.cjs +12 -8
- package/dist/tools/fastapply/apply.d.ts +2 -0
- package/dist/tools/fastapply/apply.js +6 -2
- package/dist/tools/fastapply/core.cjs +18 -14
- package/dist/tools/fastapply/core.d.ts +3 -0
- package/dist/tools/fastapply/core.js +10 -6
- package/dist/tools/fastapply/index.cjs +22 -18
- package/dist/tools/fastapply/index.d.ts +2 -0
- package/dist/tools/fastapply/index.js +13 -9
- package/dist/tools/fastapply/openai.cjs +17 -13
- package/dist/tools/fastapply/openai.d.ts +2 -0
- package/dist/tools/fastapply/openai.js +11 -7
- package/dist/tools/fastapply/types.d.ts +9 -4
- package/dist/tools/fastapply/vercel.cjs +15 -11
- package/dist/tools/fastapply/vercel.d.ts +2 -0
- package/dist/tools/fastapply/vercel.js +11 -7
- package/dist/tools/index.cjs +22 -18
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +13 -9
- 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 +5 -5
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/parser.d.ts +2 -0
- package/dist/tools/warp_grep/agent/runner.cjs +9 -5
- package/dist/tools/warp_grep/agent/runner.d.ts +2 -0
- package/dist/tools/warp_grep/agent/runner.js +7 -3
- package/dist/tools/warp_grep/agent/types.d.ts +4 -0
- package/dist/tools/warp_grep/anthropic.cjs +21 -17
- package/dist/tools/warp_grep/anthropic.d.ts +3 -1
- package/dist/tools/warp_grep/anthropic.js +15 -11
- package/dist/tools/warp_grep/client.cjs +21 -17
- package/dist/tools/warp_grep/client.d.ts +3 -1
- package/dist/tools/warp_grep/client.js +14 -10
- package/dist/tools/warp_grep/gemini.cjs +22 -18
- package/dist/tools/warp_grep/gemini.d.ts +3 -1
- package/dist/tools/warp_grep/gemini.js +15 -11
- package/dist/tools/warp_grep/harness.cjs +16 -16
- package/dist/tools/warp_grep/harness.d.ts +2 -0
- package/dist/tools/warp_grep/harness.js +4 -4
- package/dist/tools/warp_grep/index.cjs +30 -26
- package/dist/tools/warp_grep/index.d.ts +3 -1
- package/dist/tools/warp_grep/index.js +17 -13
- package/dist/tools/warp_grep/openai.cjs +22 -18
- package/dist/tools/warp_grep/openai.d.ts +3 -1
- package/dist/tools/warp_grep/openai.js +15 -11
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +3 -1
- package/dist/tools/warp_grep/providers/local.cjs +3 -3
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/providers/remote.d.ts +3 -1
- package/dist/tools/warp_grep/vercel.cjs +22 -18
- package/dist/tools/warp_grep/vercel.d.ts +3 -1
- package/dist/tools/warp_grep/vercel.js +15 -11
- package/dist/{types-DxZLPogx.d.ts → types-BKhXjDCB.d.ts} +6 -1
- package/dist/version.cjs +2 -2
- package/dist/version.js +1 -1
- package/package.json +11 -2
- package/dist/{chunk-OOEORM7H.cjs → chunk-E6V75LI6.cjs} +1 -1
- package/dist/{chunk-OSL4CNSO.js → chunk-TLMAMVAW.js} +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ export MORPH_API_KEY="sk-your-key-here"
|
|
|
21
21
|
- **🔍 WarpGrep** - Intelligent code search agent that explores your codebase with parallel grep/read operations
|
|
22
22
|
- **⚡ Fast Apply** - 98% 1st pass accuracy, AI-powered code editing at 10,500 tokens/s
|
|
23
23
|
- **📦 Repo Storage** - Agent native git with automatic code indexing and agent metadata
|
|
24
|
+
- **🛡️ PII Redaction** - Strip emails, keys, names and addresses from text locally, with regex or a small CPU model
|
|
24
25
|
- **🤖 Agent Tools** - Ready-to-use tools for Anthropic, OpenAI, Gemini, and Vercel AI SDK
|
|
25
26
|
|
|
26
27
|
## Quick Start
|
|
@@ -162,6 +163,106 @@ await morph.git.branch({ dir: './my-project', name: 'feature' });
|
|
|
162
163
|
await morph.git.checkout({ dir: './my-project', ref: 'main' });
|
|
163
164
|
```
|
|
164
165
|
|
|
166
|
+
## PII Redaction
|
|
167
|
+
|
|
168
|
+
Remove personal data and secrets from text before you log it, store it or send it to a model. Both modes run on your machine. No text is sent to Morph or anywhere else, and no API key is needed.
|
|
169
|
+
|
|
170
|
+
**Regex mode** has no dependencies and is synchronous. It also works from `@morphllm/morphsdk/edge`.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
import { redactPII } from '@morphllm/morphsdk';
|
|
174
|
+
|
|
175
|
+
const { text, entities } = redactPII(
|
|
176
|
+
'Mail sarah@example.com, key sk-proj-abc123def456ghi789jkl012, host 203.0.113.7'
|
|
177
|
+
);
|
|
178
|
+
// text: 'Mail [EMAIL], key [SECRET], host [IP_ADDRESS]'
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
It finds:
|
|
182
|
+
|
|
183
|
+
| Type | What it matches |
|
|
184
|
+
|------|-----------------|
|
|
185
|
+
| `EMAIL` | Email addresses |
|
|
186
|
+
| `PHONE` | International numbers with a `+` prefix, North American numbers, and national formats with a trunk zero or bracketed area code |
|
|
187
|
+
| `SSN` | US SSNs separated by dashes, dots or spaces; Swiss AHV numbers; any number after an `SSN` or `social security` label |
|
|
188
|
+
| `CREDIT_CARD` | Numbers that pass the Luhn checksum, numbers written in card groups (`4242 4242 4242 4241`), and bare 16-digit numbers |
|
|
189
|
+
| `IBAN` | IBANs with a valid checksum |
|
|
190
|
+
| `ACCOUNT_NUMBER` | A number after an `account number` or `routing number` label |
|
|
191
|
+
| `DATE_OF_BIRTH` | A date after `born`, `DOB`, `date of birth` or `birthday` |
|
|
192
|
+
| `MEDICAL_RECORD` | An identifier after `MRN` or `medical record number` |
|
|
193
|
+
| `LOCATION` | Street addresses (`42 Wallaby Way`, `W 2nd Street`) and PO boxes |
|
|
194
|
+
| `IP_ADDRESS`, `MAC_ADDRESS` | IPv4, IPv6 and MAC addresses |
|
|
195
|
+
| `SECRET` | Provider API keys, JWTs, bearer tokens, private key blocks, passwords in URLs, and values after a `password` or `secret` label |
|
|
196
|
+
|
|
197
|
+
Street addresses need a capitalized street name and a street-type word; cities, states, countries and people's names need model mode.
|
|
198
|
+
|
|
199
|
+
Matching time is linear in the input: a 600 KB minified JSON file takes about 25 ms. The patterns use regex lookbehind, so regex mode needs Node 10+, or Safari 16.4+ in a browser.
|
|
200
|
+
|
|
201
|
+
**Model mode** adds a small token-classification model that runs on CPU, so it also finds names, addresses and other free-text PII. Install the optional dependency first:
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
npm install @huggingface/transformers
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
import { createPIIRedactor } from '@morphllm/morphsdk';
|
|
209
|
+
|
|
210
|
+
const redactor = createPIIRedactor({ mode: 'model' });
|
|
211
|
+
|
|
212
|
+
const { text } = await redactor.redact(
|
|
213
|
+
"I'm Sarah Connor, 42 Wallaby Way, Sydney. Reach me at sarah@example.com"
|
|
214
|
+
);
|
|
215
|
+
// text: "I'm [PERSON], [LOCATION]. Reach me at [EMAIL]"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
The default model is [`onnx-community/bert-small-pii-detection-ONNX`](https://huggingface.co/onnx-community/bert-small-pii-detection-ONNX) (Apache 2.0, English, about 29 MB). It is downloaded from Hugging Face on the first call and cached; call `redactor.load()` to do that at startup. Model mode runs the regex detector too.
|
|
219
|
+
|
|
220
|
+
| Option | Default | What it does |
|
|
221
|
+
|--------|---------|--------------|
|
|
222
|
+
| `types` | all | Only redact these entity types |
|
|
223
|
+
| `excludeTypes` | none | Never redact these entity types |
|
|
224
|
+
| `placeholder` | `'type'` | `'type'` gives `[EMAIL]`; `'indexed'` gives `[EMAIL_1]`, the same value always getting the same index; or pass a function |
|
|
225
|
+
| `allow` | see below | Values that are never redacted: strings match a whole entity ignoring case, or pass a RegExp |
|
|
226
|
+
| `mode` | `'regex'` | `'regex'` or `'model'` |
|
|
227
|
+
| `model` | see above | Any Hugging Face token-classification model with ONNX weights |
|
|
228
|
+
| `minScore` | `0.75` | Drop model entities below this confidence |
|
|
229
|
+
| `classifier` | none | Your own transformers.js pipeline, for bundled or browser builds |
|
|
230
|
+
|
|
231
|
+
In model mode, `ORGANIZATION`, `DATE_TIME`, `URL`, `TITLE`, `AGE`, `NRP` and `COORDINATE` are skipped unless you list them in `types`.
|
|
232
|
+
|
|
233
|
+
Model mode is tuned for code and agent transcripts:
|
|
234
|
+
|
|
235
|
+
- A name-like hit shaped like a code identifier is ignored (`getWeather`, `StepHandler`, `claude-sonnet-4-5`, `fs.readFile`). A name inside code, such as `{ user: "Sarah Connor" }`, is still redacted.
|
|
236
|
+
- AI product names that read as human names (`Claude`, `Gemini`, `Llama` and a few more, exported as `DEFAULT_PII_ALLOW`) are not redacted. Pass `allow` to replace that list, for example `allow: [...DEFAULT_PII_ALLOW, 'Stripe', 'Vercel']`, or `allow: []` to turn it off.
|
|
237
|
+
|
|
238
|
+
Each entity in `entities` carries the original value. Treat that array as sensitive.
|
|
239
|
+
|
|
240
|
+
### Redact everything the client sends
|
|
241
|
+
|
|
242
|
+
Set `redactPII` on `MorphClient`. Fast Apply, WarpGrep, Compact and the routers then send tokens in place of sensitive values, and put the real values back in what they return.
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
const morph = new MorphClient({ apiKey: process.env.MORPH_API_KEY, redactPII: true });
|
|
246
|
+
|
|
247
|
+
await morph.fastApply.execute({ target_filepath: 'src/config.ts', instructions, code_edit });
|
|
248
|
+
// Morph received: const owner = "__PII_EMAIL_1_k3x9__";
|
|
249
|
+
// Written to disk: const owner = "jane.doe@example.com";
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
`true` uses regex mode. Pass a config for anything else:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
new MorphClient({ redactPII: { mode: 'model' } }); // regex + local model
|
|
256
|
+
new MorphClient({ redactPII: { types: ['EMAIL', 'SECRET'] } }); // only these types
|
|
257
|
+
new MorphClient({ redactPII: { allow: ['support@acme.com'] } }); // never redact these
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- Tokens are unique per request (per search for WarpGrep), so the same value always maps to the same token inside one call and never collides across calls.
|
|
261
|
+
- Fast Apply fails closed. If the merged code holds a token that was never sent, or a damaged one, the edit returns `success: false` and nothing is written.
|
|
262
|
+
- WarpGrep runs its tools locally against the real files. The model sees tokens; a grep for a token runs as a grep for the value.
|
|
263
|
+
- The tool factories (`morph.openai`, `morph.anthropic`, `morph.vercel`) inherit the option.
|
|
264
|
+
- Not covered: GitHub search, repo storage (`morph.git`), browser, subagents, and the `@morphllm/morphsdk/ai-sdk` provider. Redact those inputs yourself with `redactPII()`.
|
|
265
|
+
|
|
165
266
|
## Agent Tools
|
|
166
267
|
|
|
167
268
|
Ready-to-use tools for popular AI frameworks:
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { PII_PATTERNS, CONTEXT_CHARS } from './chunk-ZX6T3LNG.js';
|
|
2
|
+
|
|
3
|
+
// tools/pii/regex.ts
|
|
4
|
+
function isTypeEnabled(type, options) {
|
|
5
|
+
if (options.types && !options.types.includes(type)) return false;
|
|
6
|
+
if (options.excludeTypes?.includes(type)) return false;
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
function isAllowed(value, allow) {
|
|
10
|
+
if (!allow?.length) return false;
|
|
11
|
+
const lower = value.trim().toLowerCase();
|
|
12
|
+
return allow.some(
|
|
13
|
+
(entry) => typeof entry === "string" ? entry.toLowerCase() === lower : new RegExp(entry.source, entry.flags.replace(/[gy]/g, "")).test(value)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function mergeEntities(text, entities) {
|
|
17
|
+
const sorted = [...entities].sort(
|
|
18
|
+
(a, b) => a.start - b.start || b.end - a.end || (a.source === b.source ? 0 : a.source === "regex" ? -1 : 1)
|
|
19
|
+
);
|
|
20
|
+
const merged = [];
|
|
21
|
+
for (const entity of sorted) {
|
|
22
|
+
const last = merged[merged.length - 1];
|
|
23
|
+
if (last && entity.start < last.end) {
|
|
24
|
+
if (entity.end > last.end) {
|
|
25
|
+
const longer = entity.end - entity.start > last.end - last.start ? entity : last;
|
|
26
|
+
merged[merged.length - 1] = {
|
|
27
|
+
...longer,
|
|
28
|
+
start: last.start,
|
|
29
|
+
end: entity.end,
|
|
30
|
+
value: text.slice(last.start, entity.end)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
merged.push(entity);
|
|
36
|
+
}
|
|
37
|
+
return merged;
|
|
38
|
+
}
|
|
39
|
+
function applyRedactions(text, entities, placeholder = "type") {
|
|
40
|
+
const indexes = /* @__PURE__ */ new Map();
|
|
41
|
+
const counters = /* @__PURE__ */ new Map();
|
|
42
|
+
let out = "";
|
|
43
|
+
let cursor = 0;
|
|
44
|
+
for (const entity of entities) {
|
|
45
|
+
let replacement;
|
|
46
|
+
if (typeof placeholder === "function") {
|
|
47
|
+
replacement = placeholder(entity);
|
|
48
|
+
} else if (placeholder === "indexed") {
|
|
49
|
+
const key = `${entity.type}\0${entity.value}`;
|
|
50
|
+
let index = indexes.get(key);
|
|
51
|
+
if (index === void 0) {
|
|
52
|
+
index = (counters.get(entity.type) ?? 0) + 1;
|
|
53
|
+
counters.set(entity.type, index);
|
|
54
|
+
indexes.set(key, index);
|
|
55
|
+
}
|
|
56
|
+
replacement = `[${entity.type}_${index}]`;
|
|
57
|
+
} else {
|
|
58
|
+
replacement = `[${entity.type}]`;
|
|
59
|
+
}
|
|
60
|
+
out += text.slice(cursor, entity.start) + replacement;
|
|
61
|
+
cursor = entity.end;
|
|
62
|
+
}
|
|
63
|
+
return out + text.slice(cursor);
|
|
64
|
+
}
|
|
65
|
+
function detectPII(text, options = {}) {
|
|
66
|
+
if (typeof text !== "string") {
|
|
67
|
+
throw new TypeError(`PII detection expects a string, got ${text === null ? "null" : typeof text}`);
|
|
68
|
+
}
|
|
69
|
+
const found = [];
|
|
70
|
+
for (const pattern of PII_PATTERNS) {
|
|
71
|
+
if (!isTypeEnabled(pattern.type, options)) continue;
|
|
72
|
+
for (const candidate of candidates(pattern, text)) {
|
|
73
|
+
if (!isAllowed(candidate.value, options.allow)) found.push(candidate);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return mergeEntities(text, found);
|
|
77
|
+
}
|
|
78
|
+
function* candidates(pattern, text) {
|
|
79
|
+
const { regex, group, validate, type } = pattern;
|
|
80
|
+
regex.lastIndex = 0;
|
|
81
|
+
let match;
|
|
82
|
+
while ((match = regex.exec(text)) !== null) {
|
|
83
|
+
if (match[0] === "") {
|
|
84
|
+
regex.lastIndex++;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const value = group ? match[group] : match[0];
|
|
88
|
+
if (!value) continue;
|
|
89
|
+
const start = group ? match.index + match[0].lastIndexOf(value) : match.index;
|
|
90
|
+
const before = text.slice(Math.max(0, match.index - CONTEXT_CHARS), match.index);
|
|
91
|
+
if (validate && !validate(value, before)) continue;
|
|
92
|
+
yield { type, start, end: start + value.length, value, source: "regex" };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function redactPII(text, options = {}) {
|
|
96
|
+
const entities = detectPII(text, options);
|
|
97
|
+
return { text: applyRedactions(text, entities, options.placeholder), entities };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { applyRedactions, detectPII, isAllowed, isTypeEnabled, mergeEntities, redactPII };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunk74A4HLIO_cjs = require('./chunk-74A4HLIO.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkNJWOWXUR_cjs = require('./chunk-NJWOWXUR.cjs');
|
|
5
5
|
var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
|
|
6
6
|
|
|
7
7
|
// tools/fastapply/anthropic.ts
|
|
@@ -49,7 +49,7 @@ function createEditFileTool(config = {}) {
|
|
|
49
49
|
};
|
|
50
50
|
return Object.assign({}, toolDef, {
|
|
51
51
|
execute: async (input) => {
|
|
52
|
-
return
|
|
52
|
+
return chunkNJWOWXUR_cjs.executeEditFile(input, config);
|
|
53
53
|
},
|
|
54
54
|
formatResult: (result) => {
|
|
55
55
|
return formatResult(result);
|
|
@@ -60,7 +60,7 @@ function createEditFileTool(config = {}) {
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
async function execute(input, config) {
|
|
63
|
-
return
|
|
63
|
+
return chunkNJWOWXUR_cjs.executeEditFile(input, config);
|
|
64
64
|
}
|
|
65
65
|
function getSystemPrompt() {
|
|
66
66
|
return chunk74A4HLIO_cjs.EDIT_FILE_SYSTEM_PROMPT;
|
|
@@ -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-
|
|
2
|
+
import { executeToolCall, formatResult, WarpGrepClient, formatGitHubReadFileResult, executeGitHubReadFile } from './chunk-DZP7BR66.js';
|
|
3
3
|
|
|
4
4
|
// tools/warp_grep/openai.ts
|
|
5
5
|
var TOOL_PARAMETERS = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EDIT_FILE_TOOL_DESCRIPTION, EDIT_FILE_SYSTEM_PROMPT } from './chunk-PA3UTI4A.js';
|
|
2
|
-
import { executeEditFile } from './chunk-
|
|
2
|
+
import { executeEditFile } from './chunk-DYCMPDPV.js';
|
|
3
3
|
import { __export } from './chunk-MLKGABMK.js';
|
|
4
4
|
|
|
5
5
|
// tools/fastapply/anthropic.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkEJTL2BOZ_cjs = require('./chunk-EJTL2BOZ.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunkJHC2R3HU_cjs = require('./chunk-JHC2R3HU.cjs');
|
|
5
5
|
|
|
6
6
|
// tools/warp_grep/anthropic.ts
|
|
7
7
|
var INPUT_SCHEMA = {
|
|
@@ -17,7 +17,7 @@ var warpGrepTool = {
|
|
|
17
17
|
input_schema: INPUT_SCHEMA
|
|
18
18
|
};
|
|
19
19
|
async function execute(input, config) {
|
|
20
|
-
return
|
|
20
|
+
return chunkJHC2R3HU_cjs.executeToolCall(input, config);
|
|
21
21
|
}
|
|
22
22
|
function createWarpGrepTool(config) {
|
|
23
23
|
const tool = {
|
|
@@ -27,15 +27,15 @@ function createWarpGrepTool(config) {
|
|
|
27
27
|
};
|
|
28
28
|
return Object.assign(tool, {
|
|
29
29
|
execute: async (input) => {
|
|
30
|
-
return
|
|
30
|
+
return chunkJHC2R3HU_cjs.executeToolCall(input, config);
|
|
31
31
|
},
|
|
32
32
|
formatResult: (result) => {
|
|
33
|
-
return
|
|
33
|
+
return chunkJHC2R3HU_cjs.formatResult(result);
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
function createGitHubSearchTool(config) {
|
|
38
|
-
const client = new
|
|
38
|
+
const client = new chunkJHC2R3HU_cjs.WarpGrepClient(config);
|
|
39
39
|
const tool = {
|
|
40
40
|
name: chunkEJTL2BOZ_cjs.GITHUB_SEARCH_TOOL_NAME,
|
|
41
41
|
description: chunkEJTL2BOZ_cjs.GITHUB_SEARCH_DESCRIPTION,
|
|
@@ -50,7 +50,7 @@ function createGitHubSearchTool(config) {
|
|
|
50
50
|
return client.searchGitHub({ searchTerm: input.search_term, github, branch: input.branch });
|
|
51
51
|
},
|
|
52
52
|
formatResult: (result) => {
|
|
53
|
-
return
|
|
53
|
+
return chunkJHC2R3HU_cjs.formatResult(result);
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -62,10 +62,10 @@ function createGitHubReadFileTool(config) {
|
|
|
62
62
|
};
|
|
63
63
|
return Object.assign(tool, {
|
|
64
64
|
execute: async (input) => {
|
|
65
|
-
return
|
|
65
|
+
return chunkJHC2R3HU_cjs.executeGitHubReadFile(input, config);
|
|
66
66
|
},
|
|
67
67
|
formatResult: (result) => {
|
|
68
|
-
return
|
|
68
|
+
return chunkJHC2R3HU_cjs.formatGitHubReadFileResult(result);
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
4
|
+
var chunkKF6S3EPJ_cjs = require('./chunk-KF6S3EPJ.cjs');
|
|
5
|
+
var chunkYAUXTFIN_cjs = require('./chunk-YAUXTFIN.cjs');
|
|
6
|
+
var chunkWJHHO24M_cjs = require('./chunk-WJHHO24M.cjs');
|
|
7
|
+
var chunkQT5LGZG3_cjs = require('./chunk-QT5LGZG3.cjs');
|
|
7
8
|
|
|
8
9
|
// core/client.ts
|
|
9
10
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
@@ -21,6 +22,10 @@ var MorphAPIClient = class {
|
|
|
21
22
|
timeout;
|
|
22
23
|
retryConfig;
|
|
23
24
|
debug;
|
|
25
|
+
/** The `redactPII` option as given, for resources that build their own HTTP client. */
|
|
26
|
+
redactPII;
|
|
27
|
+
/** Set when `redactPII` is on. Resources open a session per request or run. */
|
|
28
|
+
pii;
|
|
24
29
|
constructor(options = {}) {
|
|
25
30
|
this.apiKey = options.apiKey;
|
|
26
31
|
this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
|
|
@@ -28,6 +33,8 @@ var MorphAPIClient = class {
|
|
|
28
33
|
this.timeout = options.timeout;
|
|
29
34
|
this.retryConfig = options.retryConfig;
|
|
30
35
|
this.debug = options.debug ?? false;
|
|
36
|
+
this.redactPII = options.redactPII;
|
|
37
|
+
this.pii = chunkKF6S3EPJ_cjs.resolvePIIGuard(options.redactPII);
|
|
31
38
|
if (this.debug) chunkVL4QNALG_cjs.logger.enable();
|
|
32
39
|
}
|
|
33
40
|
/** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
|
|
@@ -36,7 +43,7 @@ var MorphAPIClient = class {
|
|
|
36
43
|
}
|
|
37
44
|
/** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
|
|
38
45
|
defaultHeaders() {
|
|
39
|
-
return { "X-Morph-SDK-Version":
|
|
46
|
+
return { "X-Morph-SDK-Version": chunkQT5LGZG3_cjs.SDK_VERSION };
|
|
40
47
|
}
|
|
41
48
|
buildURL(path, baseURL) {
|
|
42
49
|
if (/^https?:\/\//i.test(path)) return path;
|
|
@@ -46,7 +53,7 @@ var MorphAPIClient = class {
|
|
|
46
53
|
buildHeaders(apiKey, extra) {
|
|
47
54
|
return {
|
|
48
55
|
"Content-Type": "application/json",
|
|
49
|
-
"X-Morph-SDK-Version":
|
|
56
|
+
"X-Morph-SDK-Version": chunkQT5LGZG3_cjs.SDK_VERSION,
|
|
50
57
|
Authorization: `Bearer ${apiKey}`,
|
|
51
58
|
...extra
|
|
52
59
|
};
|
|
@@ -63,7 +70,7 @@ var MorphAPIClient = class {
|
|
|
63
70
|
async request(method, path, opts = {}) {
|
|
64
71
|
const apiKey = this.resolveApiKey();
|
|
65
72
|
if (!apiKey) {
|
|
66
|
-
throw new
|
|
73
|
+
throw new chunkWJHHO24M_cjs.MorphError(
|
|
67
74
|
"Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
|
|
68
75
|
"missing_api_key",
|
|
69
76
|
401
|
|
@@ -78,12 +85,12 @@ var MorphAPIClient = class {
|
|
|
78
85
|
...opts.signal ? { signal: opts.signal } : {}
|
|
79
86
|
};
|
|
80
87
|
chunkVL4QNALG_cjs.logger.debug("MorphAPIClient", "request", { method, url });
|
|
81
|
-
const response = await
|
|
82
|
-
|
|
88
|
+
const response = await chunkWJHHO24M_cjs.withTimeout(
|
|
89
|
+
chunkWJHHO24M_cjs.fetchWithRetry(url, init, this.retryConfig ?? {}),
|
|
83
90
|
timeout,
|
|
84
91
|
`Morph request to ${url} timed out after ${timeout}ms`
|
|
85
92
|
);
|
|
86
|
-
if (!response.ok) throw await
|
|
93
|
+
if (!response.ok) throw await chunkYAUXTFIN_cjs.toMorphError(response);
|
|
87
94
|
if (opts.stream) return response;
|
|
88
95
|
if (response.status === 204) return void 0;
|
|
89
96
|
const text = await response.text();
|