@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
@@ -1,9 +1,9 @@
1
- import { createCodeStorageHttpCommands } from './chunk-HDP4QAZL.js';
2
1
  import { RemoteCommandsProvider } from './chunk-RYVW7RUM.js';
3
2
  import { parseGitHubUrl } from './chunk-OPDWMD4Q.js';
4
- import { runWarpGrep, runWarpGrepStreaming } from './chunk-GIQAIHUI.js';
5
- import { compactFileContexts } from './chunk-N7UKZ5X7.js';
6
- import { MorphAPIClient } from './chunk-KLVJIC2O.js';
3
+ import { runWarpGrep, runWarpGrepStreaming } from './chunk-FGA6EYC2.js';
4
+ import { createCodeStorageHttpCommands } from './chunk-HDP4QAZL.js';
5
+ import { compactFileContexts } from './chunk-JVMIFGZY.js';
6
+ import { MorphAPIClient } from './chunk-IGXNLXPN.js';
7
7
  import { logger } from './chunk-6WP7EA4F.js';
8
8
  import { APIResource } from './chunk-NRG6QX3L.js';
9
9
 
@@ -34,7 +34,8 @@ var WarpGrepClient = class extends APIResource {
34
34
  morphApiUrl: this._client.baseURL,
35
35
  timeout: this._client.timeout,
36
36
  retryConfig: this._client.retryConfig,
37
- debug: this._client.debug
37
+ debug: this._client.debug,
38
+ redactPII: cfg.redactPII ?? this._client.redactPII
38
39
  };
39
40
  }
40
41
  execute(input) {
@@ -49,7 +50,8 @@ var WarpGrepClient = class extends APIResource {
49
50
  morphApiUrl: this.config.morphApiUrl,
50
51
  retryConfig: this.config.retryConfig,
51
52
  timeout: this.config.timeout,
52
- search_type: input.search_type
53
+ search_type: input.search_type,
54
+ redactPII: this.config.redactPII
53
55
  };
54
56
  if (input.streamSteps) {
55
57
  return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);
@@ -163,11 +165,12 @@ async function executeToolCall(input, config) {
163
165
  morphApiUrl: config.morphApiUrl,
164
166
  retryConfig: config.retryConfig,
165
167
  timeout: config.timeout,
166
- search_type: config.search_type
168
+ search_type: config.search_type,
169
+ redactPII: config.redactPII
167
170
  });
168
- return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
171
+ return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
169
172
  }
170
- async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
173
+ async function processAgentResult(result, searchTerm, apiKey, apiUrl, redactPII) {
171
174
  const finish = result.finish;
172
175
  if (result.terminationReason !== "completed" || !finish?.metadata) {
173
176
  const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
@@ -181,7 +184,7 @@ async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
181
184
  }));
182
185
  try {
183
186
  const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
184
- const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
187
+ const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl, void 0, void 0, redactPII);
185
188
  for (let i = 0; i < contexts.length; i++) {
186
189
  contexts[i].content = compacted[i].content;
187
190
  }
@@ -205,7 +208,8 @@ async function* executeToolCallStreaming(input, config) {
205
208
  morphApiUrl: config.morphApiUrl,
206
209
  retryConfig: config.retryConfig,
207
210
  timeout: config.timeout,
208
- search_type: config.search_type
211
+ search_type: config.search_type,
212
+ redactPII: config.redactPII
209
213
  });
210
214
  let agentResult;
211
215
  for (; ; ) {
@@ -216,7 +220,7 @@ async function* executeToolCallStreaming(input, config) {
216
220
  }
217
221
  yield value;
218
222
  }
219
- return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
223
+ return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
220
224
  }
221
225
  async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
222
226
  const branches = branch ? [branch] : ["HEAD"];
@@ -0,0 +1,96 @@
1
+ import { createPIIRedactor } from './chunk-OENJO7YW.js';
2
+ import { applyRedactions } from './chunk-2GMG5XKU.js';
3
+
4
+ // tools/pii/guard.ts
5
+ var PIIRestoreError = class extends Error {
6
+ constructor(tokens) {
7
+ super(
8
+ `Morph returned ${tokens.length} PII placeholder(s) that do not match anything sent. The response was discarded so no placeholder is written in place of real data.`
9
+ );
10
+ this.tokens = tokens;
11
+ this.name = "PIIRestoreError";
12
+ }
13
+ };
14
+ var PIISession = class {
15
+ constructor(detect) {
16
+ this.detect = detect;
17
+ }
18
+ nonce = Math.random().toString(36).slice(2, 6).padEnd(4, "0");
19
+ tokenFor = /* @__PURE__ */ new Map();
20
+ valueFor = /* @__PURE__ */ new Map();
21
+ counters = /* @__PURE__ */ new Map();
22
+ cache = /* @__PURE__ */ new Map();
23
+ tokenPattern = new RegExp(`__PII_[A-Z0-9_]+?_\\d+_${this.nonce}__`, "g");
24
+ /** Number of distinct values redacted so far. */
25
+ get size() {
26
+ return this.valueFor.size;
27
+ }
28
+ token(type, value) {
29
+ const key = `${type}\0${value}`;
30
+ let token = this.tokenFor.get(key);
31
+ if (!token) {
32
+ const index = (this.counters.get(type) ?? 0) + 1;
33
+ this.counters.set(type, index);
34
+ token = `__PII_${type.replace(/[^A-Z0-9]+/gi, "_").toUpperCase()}_${index}_${this.nonce}__`;
35
+ this.tokenFor.set(key, token);
36
+ this.valueFor.set(token, value);
37
+ }
38
+ return token;
39
+ }
40
+ /** Replace sensitive values with tokens. Repeated text is answered from a cache. */
41
+ async redact(text) {
42
+ if (!text) return text;
43
+ const cached = this.cache.get(text);
44
+ if (cached !== void 0) return cached;
45
+ const entities = await this.detect(text);
46
+ const out = applyRedactions(
47
+ text,
48
+ entities,
49
+ (entity) => (
50
+ // One token per line, so the line count (and any line numbers Morph returns)
51
+ // is the same before and after redaction.
52
+ entity.value.split("\n").map((line) => line ? this.token(entity.type, line) : "").join("\n")
53
+ )
54
+ );
55
+ this.cache.set(text, out);
56
+ return out;
57
+ }
58
+ restore(text) {
59
+ if (!text || this.valueFor.size === 0) return text;
60
+ return text.replace(this.tokenPattern, (token) => this.valueFor.get(token) ?? token);
61
+ }
62
+ /**
63
+ * Like `restore`, but throws if the text holds a token this session did not issue, or a
64
+ * damaged one (a token that lost its head or its tail). Use it wherever the result is
65
+ * written somewhere durable.
66
+ */
67
+ restoreStrict(text) {
68
+ const unknown = (text.match(this.tokenPattern) ?? []).filter((token) => !this.valueFor.has(token));
69
+ const restored = this.restore(text);
70
+ const tail = `_${this.nonce}__`;
71
+ if (this.valueFor.size > 0) {
72
+ if (restored.includes(tail)) unknown.push(tail);
73
+ for (const token of this.valueFor.keys()) {
74
+ const head = token.slice(0, -(this.nonce.length + 2));
75
+ if (restored.includes(head)) unknown.push(head);
76
+ }
77
+ }
78
+ if (unknown.length) throw new PIIRestoreError([...new Set(unknown)]);
79
+ return restored;
80
+ }
81
+ };
82
+ var guards = /* @__PURE__ */ new WeakMap();
83
+ var defaultGuard;
84
+ function build(config) {
85
+ const redactor = createPIIRedactor(config);
86
+ return { session: () => new PIISession((text) => redactor.detect(text)) };
87
+ }
88
+ function resolvePIIGuard(option) {
89
+ if (!option) return void 0;
90
+ if (option === true) return defaultGuard ??= build({});
91
+ let guard = guards.get(option);
92
+ if (!guard) guards.set(option, guard = build(option));
93
+ return guard;
94
+ }
95
+
96
+ export { PIIRestoreError, PIISession, resolvePIIGuard };
@@ -1,4 +1,4 @@
1
- import { WarpGrepClient, formatResult } from './chunk-66THRMD7.js';
1
+ import { WarpGrepClient, formatResult } from './chunk-DZP7BR66.js';
2
2
  import { CODEBASE_SEARCH_TOOL, SEND_MESSAGE_TOOL, getSystemPrompt } from './chunk-ETBRAKVV.js';
3
3
 
4
4
  // subagents/anthropic.ts
@@ -1,20 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var chunk65W4I66Q_cjs = require('./chunk-65W4I66Q.cjs');
4
- var chunkOM5ZSXQW_cjs = require('./chunk-OM5ZSXQW.cjs');
3
+ var chunk5TTZQF4X_cjs = require('./chunk-5TTZQF4X.cjs');
4
+ var chunkWJHHO24M_cjs = require('./chunk-WJHHO24M.cjs');
5
5
  var chunkAWFZKS27_cjs = require('./chunk-AWFZKS27.cjs');
6
6
 
7
7
  // tools/compact/core.ts
8
8
  var DEFAULT_API_URL = "https://api.morphllm.com";
9
9
  var DEFAULT_TIMEOUT = 12e4;
10
10
  function resolveClient(clientOrConfig) {
11
- if (clientOrConfig instanceof chunk65W4I66Q_cjs.MorphAPIClient) return clientOrConfig;
12
- return new chunk65W4I66Q_cjs.MorphAPIClient({
11
+ if (clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient) return clientOrConfig;
12
+ return new chunk5TTZQF4X_cjs.MorphAPIClient({
13
13
  apiKey: clientOrConfig.morphApiKey,
14
14
  baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL,
15
15
  timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
16
16
  retryConfig: clientOrConfig.retryConfig,
17
- debug: clientOrConfig.debug
17
+ debug: clientOrConfig.debug,
18
+ redactPII: clientOrConfig.redactPII
18
19
  });
19
20
  }
20
21
  var CompactClient = class extends chunkAWFZKS27_cjs.APIResource {
@@ -22,7 +23,7 @@ var CompactClient = class extends chunkAWFZKS27_cjs.APIResource {
22
23
  config;
23
24
  constructor(clientOrConfig = {}) {
24
25
  super(resolveClient(clientOrConfig));
25
- const cfg = clientOrConfig instanceof chunk65W4I66Q_cjs.MorphAPIClient ? {} : clientOrConfig;
26
+ const cfg = clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient ? {} : clientOrConfig;
26
27
  this.config = {
27
28
  morphApiUrl: this._client.baseURL,
28
29
  timeout: cfg.timeout ?? DEFAULT_TIMEOUT,
@@ -57,10 +58,29 @@ var CompactClient = class extends chunkAWFZKS27_cjs.APIResource {
57
58
  else if (typeof input.input === "string") body.input = input.input;
58
59
  else if (Array.isArray(input.input)) body.messages = input.input;
59
60
  else throw new Error("Either 'input' or 'messages' must be provided");
61
+ const pii = this._client.pii?.session();
62
+ if (pii) {
63
+ if (typeof body.query === "string") body.query = await pii.redact(body.query);
64
+ if (typeof body.input === "string") body.input = await pii.redact(body.input);
65
+ if (Array.isArray(body.messages)) {
66
+ body.messages = await Promise.all(
67
+ body.messages.map(
68
+ async (m) => typeof m.content === "string" ? { ...m, content: await pii.redact(m.content) } : m
69
+ )
70
+ );
71
+ }
72
+ }
60
73
  try {
61
- return await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
74
+ const result = await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
75
+ if (pii && result) {
76
+ if (typeof result.output === "string") result.output = pii.restore(result.output);
77
+ for (const m of result.messages ?? []) {
78
+ if (typeof m.content === "string") m.content = pii.restore(m.content);
79
+ }
80
+ }
81
+ return result;
62
82
  } catch (err) {
63
- if (err instanceof chunkOM5ZSXQW_cjs.MorphError) {
83
+ if (err instanceof chunkWJHHO24M_cjs.MorphError) {
64
84
  throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
65
85
  }
66
86
  throw err;
@@ -1,8 +1,9 @@
1
1
  import { buildInitialState, enforceContextLimit, formatTurnMessage, calculateContextBudget, readFinishFiles, toolRead, toolListDirectory, toolGlob, toolGrep } from './chunk-44OIEPIO.js';
2
- import { AGENT_CONFIG, DEFAULT_MODEL } from './chunk-M34E2AMK.js';
3
2
  import { parseFinishFiles, parseReadLines, extractPathFromCommand } from './chunk-4OUGA3KS.js';
3
+ import { AGENT_CONFIG, DEFAULT_MODEL } from './chunk-M34E2AMK.js';
4
4
  import { logger } from './chunk-6WP7EA4F.js';
5
- import { SDK_VERSION } from './chunk-OCCGJ4S6.js';
5
+ import { resolvePIIGuard } from './chunk-E63OPKP7.js';
6
+ import { SDK_VERSION } from './chunk-GYE3FY6Z.js';
6
7
  import OpenAI from 'openai';
7
8
  import path from 'path';
8
9
 
@@ -114,6 +115,23 @@ var TOOL_SPECS = [
114
115
  }
115
116
  }
116
117
  ];
118
+ async function redactMessages(messages, pii) {
119
+ return Promise.all(
120
+ messages.map(async (message) => {
121
+ const out = { ...message };
122
+ if (typeof message.content === "string") out.content = await pii.redact(message.content);
123
+ if (message.role === "assistant" && out.role === "assistant" && message.tool_calls) {
124
+ out.tool_calls = await Promise.all(
125
+ message.tool_calls.map(async (tc) => ({
126
+ ...tc,
127
+ function: { ...tc.function, arguments: await pii.redact(tc.function.arguments) }
128
+ }))
129
+ );
130
+ }
131
+ return out;
132
+ })
133
+ );
134
+ }
117
135
  async function callModel(messages, model, options = {}) {
118
136
  const baseUrl = options.morphApiUrl || DEFAULT_API_URL;
119
137
  const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
@@ -128,6 +146,8 @@ async function callModel(messages, model, options = {}) {
128
146
  defaultHeaders: { "X-Morph-SDK-Version": SDK_VERSION }
129
147
  });
130
148
  const MAX_EMPTY_RETRIES = 1;
149
+ const pii = options.pii;
150
+ const outgoing = pii ? await redactMessages(messages, pii) : messages;
131
151
  logger.debug("WarpGrep", "model_call", { url: baseURL, model, message_count: messages.length });
132
152
  const callStartTime = Date.now();
133
153
  for (let attempt = 0; attempt <= MAX_EMPTY_RETRIES; attempt++) {
@@ -137,7 +157,7 @@ async function callModel(messages, model, options = {}) {
137
157
  model,
138
158
  temperature: 0,
139
159
  max_tokens: 2048,
140
- messages,
160
+ messages: outgoing,
141
161
  tools: TOOL_SPECS,
142
162
  ...options.search_type ? { search_type: options.search_type } : {}
143
163
  });
@@ -167,11 +187,12 @@ async function callModel(messages, model, options = {}) {
167
187
  const toolCalls = (message.tool_calls || []).map((tc) => ({
168
188
  id: tc.id,
169
189
  type: "function",
170
- function: { name: tc.function.name, arguments: tc.function.arguments }
190
+ // Restore real values so grep patterns and file paths work against the local repo.
191
+ function: { name: tc.function.name, arguments: pii ? pii.restore(tc.function.arguments) : tc.function.arguments }
171
192
  }));
172
193
  if (message.content || toolCalls.length > 0) {
173
194
  logger.debug("WarpGrep", "model_call_complete", { latency_ms: Date.now() - callStartTime, tool_calls_count: toolCalls.length, finish_reason: choice?.finish_reason ?? "unknown" });
174
- return { content: message.content ?? null, tool_calls: toolCalls };
195
+ return { content: pii ? pii.restore(message.content ?? null) ?? null : message.content ?? null, tool_calls: toolCalls };
175
196
  }
176
197
  if (attempt === MAX_EMPTY_RETRIES) {
177
198
  const finishReason = choice?.finish_reason ?? "unknown";
@@ -240,6 +261,7 @@ async function* runWarpGrepStreaming(config) {
240
261
  const repoRoot = config.repoRoot || process.cwd();
241
262
  const model = config.model || DEFAULT_MODEL;
242
263
  const messages = [];
264
+ const pii = resolvePIIGuard(config.redactPII)?.session();
243
265
  const maxTurns = AGENT_CONFIG.MAX_TURNS;
244
266
  logger.debug("WarpGrep", "session_start", { search_term: config.searchTerm, model, max_turns: maxTurns });
245
267
  const initialStateStart = Date.now();
@@ -266,7 +288,8 @@ async function* runWarpGrepStreaming(config) {
266
288
  morphApiUrl: config.morphApiUrl,
267
289
  retryConfig: config.retryConfig,
268
290
  timeout: timeoutMs,
269
- search_type: config.search_type
291
+ search_type: config.search_type,
292
+ pii
270
293
  }).catch((e) => {
271
294
  const errMsg = e instanceof Error ? e.message : String(e);
272
295
  console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
@@ -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
 
5
5
  // tools/fastapply/openai.ts
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkUUCRWJJR_cjs = require('./chunk-UUCRWJJR.cjs');
3
+ var chunkJHC2R3HU_cjs = require('./chunk-JHC2R3HU.cjs');
4
4
  var chunkTPZHMD7J_cjs = require('./chunk-TPZHMD7J.cjs');
5
5
  var ai = require('ai');
6
6
  var zod = require('zod');
@@ -17,7 +17,7 @@ function createExploreSubagent(config) {
17
17
  if (!config.repoRoot) {
18
18
  throw new Error("repoRoot is required for Explore subagent");
19
19
  }
20
- const warpGrep = new chunkUUCRWJJR_cjs.WarpGrepClient({
20
+ const warpGrep = new chunkJHC2R3HU_cjs.WarpGrepClient({
21
21
  morphApiKey: config.morphApiKey
22
22
  });
23
23
  const thoroughness = config.thoroughness ?? "medium";
@@ -63,7 +63,7 @@ function createExploreSubagent(config) {
63
63
  contextsFound: warpResult.contexts?.length ?? 0,
64
64
  isFinal: false
65
65
  });
66
- return chunkUUCRWJJR_cjs.formatResult(warpResult);
66
+ return chunkJHC2R3HU_cjs.formatResult(warpResult);
67
67
  }
68
68
  }),
69
69
  send_message: ai.tool({
@@ -1,6 +1,6 @@
1
1
  // package.json
2
2
  var package_default = {
3
- version: "0.2.203"};
3
+ version: "0.2.204"};
4
4
 
5
5
  // version.ts
6
6
  var SDK_VERSION = package_default.version;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk74A4HLIO_cjs = require('./chunk-74A4HLIO.cjs');
4
- var chunkJBTR3FQD_cjs = require('./chunk-JBTR3FQD.cjs');
4
+ var chunkNJWOWXUR_cjs = require('./chunk-NJWOWXUR.cjs');
5
5
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
6
 
7
7
  // tools/fastapply/openai.ts
@@ -40,7 +40,7 @@ var editFileTool = {
40
40
  }
41
41
  };
42
42
  async function execute(input, config) {
43
- return chunkJBTR3FQD_cjs.executeEditFile(input, config);
43
+ return chunkNJWOWXUR_cjs.executeEditFile(input, config);
44
44
  }
45
45
  function getSystemPrompt() {
46
46
  return chunk74A4HLIO_cjs.EDIT_FILE_SYSTEM_PROMPT;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunk74A4HLIO_cjs = require('./chunk-74A4HLIO.cjs');
4
- var chunkJBTR3FQD_cjs = require('./chunk-JBTR3FQD.cjs');
4
+ var chunkNJWOWXUR_cjs = require('./chunk-NJWOWXUR.cjs');
5
5
  var chunk75ZPJI57_cjs = require('./chunk-75ZPJI57.cjs');
6
6
  var ai = require('ai');
7
7
  var zod = require('zod');
@@ -23,7 +23,7 @@ var editFileTool = ai.tool({
23
23
  description: chunk74A4HLIO_cjs.EDIT_FILE_TOOL_DESCRIPTION,
24
24
  inputSchema: editFileSchema,
25
25
  execute: async (params) => {
26
- const result = await chunkJBTR3FQD_cjs.executeEditFile({
26
+ const result = await chunkNJWOWXUR_cjs.executeEditFile({
27
27
  target_filepath: params.target_filepath,
28
28
  instruction: params.instruction,
29
29
  code_edit: params.code_edit
@@ -52,7 +52,7 @@ function createEditFileTool(config = {}) {
52
52
  description: config.description || chunk74A4HLIO_cjs.EDIT_FILE_TOOL_DESCRIPTION,
53
53
  inputSchema: schema,
54
54
  execute: async (params) => {
55
- const result = await chunkJBTR3FQD_cjs.executeEditFile(
55
+ const result = await chunkNJWOWXUR_cjs.executeEditFile(
56
56
  {
57
57
  target_filepath: params.target_filepath,
58
58
  instruction: params.instruction,
@@ -1,7 +1,8 @@
1
1
  import { logger } from './chunk-6WP7EA4F.js';
2
- import { toMorphError } from './chunk-EI2M567U.js';
3
- import { MorphError, withTimeout, fetchWithRetry } from './chunk-E7FLETFO.js';
4
- import { SDK_VERSION } from './chunk-OCCGJ4S6.js';
2
+ import { resolvePIIGuard } from './chunk-E63OPKP7.js';
3
+ import { toMorphError } from './chunk-564XJOQP.js';
4
+ import { MorphError, withTimeout, fetchWithRetry } from './chunk-4TZBUFVP.js';
5
+ import { SDK_VERSION } from './chunk-GYE3FY6Z.js';
5
6
 
6
7
  // core/client.ts
7
8
  var DEFAULT_BASE_URL = "https://api.morphllm.com";
@@ -19,6 +20,10 @@ var MorphAPIClient = class {
19
20
  timeout;
20
21
  retryConfig;
21
22
  debug;
23
+ /** The `redactPII` option as given, for resources that build their own HTTP client. */
24
+ redactPII;
25
+ /** Set when `redactPII` is on. Resources open a session per request or run. */
26
+ pii;
22
27
  constructor(options = {}) {
23
28
  this.apiKey = options.apiKey;
24
29
  this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
@@ -26,6 +31,8 @@ var MorphAPIClient = class {
26
31
  this.timeout = options.timeout;
27
32
  this.retryConfig = options.retryConfig;
28
33
  this.debug = options.debug ?? false;
34
+ this.redactPII = options.redactPII;
35
+ this.pii = resolvePIIGuard(options.redactPII);
29
36
  if (this.debug) logger.enable();
30
37
  }
31
38
  /** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var chunkVHD7CW5O_cjs = require('./chunk-VHD7CW5O.cjs');
4
3
  var chunkWR7LSUIR_cjs = require('./chunk-WR7LSUIR.cjs');
5
4
  var chunkMWXJ6DZ2_cjs = require('./chunk-MWXJ6DZ2.cjs');
6
- var chunkHMLYJVZM_cjs = require('./chunk-HMLYJVZM.cjs');
7
- var chunkODY2NKQU_cjs = require('./chunk-ODY2NKQU.cjs');
8
- var chunk65W4I66Q_cjs = require('./chunk-65W4I66Q.cjs');
5
+ var chunkOCKEEEYE_cjs = require('./chunk-OCKEEEYE.cjs');
6
+ var chunkVHD7CW5O_cjs = require('./chunk-VHD7CW5O.cjs');
7
+ var chunkVYE7O4FM_cjs = require('./chunk-VYE7O4FM.cjs');
8
+ var chunk5TTZQF4X_cjs = require('./chunk-5TTZQF4X.cjs');
9
9
  var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
10
10
  var chunkAWFZKS27_cjs = require('./chunk-AWFZKS27.cjs');
11
11
 
@@ -19,9 +19,9 @@ async function getLocalProvider(repoRoot, excludes, allowNames) {
19
19
  var WarpGrepClient = class extends chunkAWFZKS27_cjs.APIResource {
20
20
  config;
21
21
  constructor(clientOrConfig = {}) {
22
- const isClient = clientOrConfig instanceof chunk65W4I66Q_cjs.MorphAPIClient;
22
+ const isClient = clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient;
23
23
  super(
24
- isClient ? clientOrConfig : new chunk65W4I66Q_cjs.MorphAPIClient({
24
+ isClient ? clientOrConfig : new chunk5TTZQF4X_cjs.MorphAPIClient({
25
25
  apiKey: clientOrConfig.morphApiKey,
26
26
  baseURL: clientOrConfig.morphApiUrl,
27
27
  timeout: clientOrConfig.timeout,
@@ -36,7 +36,8 @@ var WarpGrepClient = class extends chunkAWFZKS27_cjs.APIResource {
36
36
  morphApiUrl: this._client.baseURL,
37
37
  timeout: this._client.timeout,
38
38
  retryConfig: this._client.retryConfig,
39
- debug: this._client.debug
39
+ debug: this._client.debug,
40
+ redactPII: cfg.redactPII ?? this._client.redactPII
40
41
  };
41
42
  }
42
43
  execute(input) {
@@ -51,7 +52,8 @@ var WarpGrepClient = class extends chunkAWFZKS27_cjs.APIResource {
51
52
  morphApiUrl: this.config.morphApiUrl,
52
53
  retryConfig: this.config.retryConfig,
53
54
  timeout: this.config.timeout,
54
- search_type: input.search_type
55
+ search_type: input.search_type,
56
+ redactPII: this.config.redactPII
55
57
  };
56
58
  if (input.streamSteps) {
57
59
  return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);
@@ -154,7 +156,7 @@ async function executeToolCall(input, config) {
154
156
  const parsed = typeof input === "string" ? JSON.parse(input) : input;
155
157
  const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
156
158
  const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
157
- const result = await chunkHMLYJVZM_cjs.runWarpGrep({
159
+ const result = await chunkOCKEEEYE_cjs.runWarpGrep({
158
160
  searchTerm: parsed.search_term,
159
161
  repoRoot: config.repoRoot,
160
162
  provider,
@@ -165,11 +167,12 @@ async function executeToolCall(input, config) {
165
167
  morphApiUrl: config.morphApiUrl,
166
168
  retryConfig: config.retryConfig,
167
169
  timeout: config.timeout,
168
- search_type: config.search_type
170
+ search_type: config.search_type,
171
+ redactPII: config.redactPII
169
172
  });
170
- return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
173
+ return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
171
174
  }
172
- async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
175
+ async function processAgentResult(result, searchTerm, apiKey, apiUrl, redactPII) {
173
176
  const finish = result.finish;
174
177
  if (result.terminationReason !== "completed" || !finish?.metadata) {
175
178
  const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
@@ -183,7 +186,7 @@ async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
183
186
  }));
184
187
  try {
185
188
  const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
186
- const compacted = await chunkODY2NKQU_cjs.compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
189
+ const compacted = await chunkVYE7O4FM_cjs.compactFileContexts(compactable, searchTerm, apiKey, apiUrl, void 0, void 0, redactPII);
187
190
  for (let i = 0; i < contexts.length; i++) {
188
191
  contexts[i].content = compacted[i].content;
189
192
  }
@@ -196,7 +199,7 @@ async function* executeToolCallStreaming(input, config) {
196
199
  const parsed = typeof input === "string" ? JSON.parse(input) : input;
197
200
  const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
198
201
  const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
199
- const generator = chunkHMLYJVZM_cjs.runWarpGrepStreaming({
202
+ const generator = chunkOCKEEEYE_cjs.runWarpGrepStreaming({
200
203
  searchTerm: parsed.search_term,
201
204
  repoRoot: config.repoRoot,
202
205
  provider,
@@ -207,7 +210,8 @@ async function* executeToolCallStreaming(input, config) {
207
210
  morphApiUrl: config.morphApiUrl,
208
211
  retryConfig: config.retryConfig,
209
212
  timeout: config.timeout,
210
- search_type: config.search_type
213
+ search_type: config.search_type,
214
+ redactPII: config.redactPII
211
215
  });
212
216
  let agentResult;
213
217
  for (; ; ) {
@@ -218,7 +222,7 @@ async function* executeToolCallStreaming(input, config) {
218
222
  }
219
223
  yield value;
220
224
  }
221
- return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
225
+ return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
222
226
  }
223
227
  async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
224
228
  const branches = branch ? [branch] : ["HEAD"];
@@ -1,7 +1,7 @@
1
- import { CompactClient } from './chunk-H3HRSRR5.js';
1
+ import { CompactClient } from './chunk-OX5GN2KB.js';
2
2
 
3
3
  // tools/compact/utils.ts
4
- async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
4
+ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3, redactPII) {
5
5
  const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
6
6
  const estimatedTokens = totalLength / 3;
7
7
  if (estimatedTokens <= maxTokens) {
@@ -11,7 +11,8 @@ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4
11
11
  compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
12
12
  const client = new CompactClient({
13
13
  morphApiKey: apiKey,
14
- morphApiUrl: apiUrl
14
+ morphApiUrl: apiUrl,
15
+ redactPII
15
16
  });
16
17
  const results = [];
17
18
  const inProgress = /* @__PURE__ */ new Set();