@morphllm/morphsdk 0.2.202 → 0.2.204

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (246) hide show
  1. package/README.md +101 -0
  2. package/dist/chunk-2GMG5XKU.js +100 -0
  3. package/dist/chunk-2PPYWRMZ.js +3 -4
  4. package/dist/chunk-3HAHJYZQ.cjs +74 -0
  5. package/dist/{chunk-2XU3XXUE.js → chunk-3JROKKS4.js} +3 -25
  6. package/dist/{chunk-26K5EJD3.js → chunk-43JBUEIX.js} +4 -18
  7. package/dist/chunk-44OIEPIO.js +4 -23
  8. package/dist/chunk-4EQQGUZ7.cjs +104 -0
  9. package/dist/chunk-4OUGA3KS.js +1 -5
  10. package/dist/{chunk-VQDDL3UH.js → chunk-4TZBUFVP.js} +2 -8
  11. package/dist/{chunk-YAM6P5OQ.js → chunk-564XJOQP.js} +2 -6
  12. package/dist/chunk-5H3FKFOI.cjs +77 -0
  13. package/dist/chunk-5TTZQF4X.cjs +110 -0
  14. package/dist/chunk-6HAYJA6M.cjs +317 -0
  15. package/dist/chunk-6TZCVTW5.js +3 -4
  16. package/dist/chunk-6WP7EA4F.js +2 -4
  17. package/dist/chunk-74A4HLIO.cjs +42 -0
  18. package/dist/chunk-75ZPJI57.cjs +9 -0
  19. package/dist/chunk-7PJYY46L.cjs +2 -0
  20. package/dist/chunk-AWFZKS27.cjs +11 -0
  21. package/dist/chunk-BJBWWIZV.cjs +2 -0
  22. package/dist/chunk-DLYDIYDK.cjs +305 -0
  23. package/dist/{chunk-65TUD7JV.js → chunk-DYCMPDPV.js} +13 -29
  24. package/dist/{chunk-3CPI6ZIC.js → chunk-DZP7BR66.js} +22 -43
  25. package/dist/chunk-E63OPKP7.js +96 -0
  26. package/dist/chunk-E6V75LI6.cjs +334 -0
  27. package/dist/{chunk-XPHNS7NW.js → chunk-EJ6ID24K.js} +3 -12
  28. package/dist/chunk-EJTL2BOZ.cjs +42 -0
  29. package/dist/chunk-ETBRAKVV.js +1 -5
  30. package/dist/chunk-F633IVQA.cjs +91 -0
  31. package/dist/chunk-FBOZIVVQ.js +1 -0
  32. package/dist/{chunk-UKXCGQPS.js → chunk-FGA6EYC2.js} +35 -37
  33. package/dist/{chunk-CAWQEHKP.js → chunk-G4RODMXA.js} +4 -19
  34. package/dist/chunk-GUNGJC6X.cjs +256 -0
  35. package/dist/chunk-GYE3FY6Z.js +8 -0
  36. package/dist/chunk-HDP4QAZL.js +1 -4
  37. package/dist/chunk-HNMEBYIS.cjs +86 -0
  38. package/dist/chunk-HP3PCOTW.cjs +81 -0
  39. package/dist/{chunk-ICCGLO6V.js → chunk-IGXNLXPN.js} +12 -17
  40. package/dist/chunk-IPJA3ZS6.cjs +10 -0
  41. package/dist/chunk-JHC2R3HU.cjs +317 -0
  42. package/dist/{chunk-IBRBSDLT.js → chunk-JVMIFGZY.js} +5 -8
  43. package/dist/chunk-KF6S3EPJ.cjs +100 -0
  44. package/dist/chunk-KVGZ2TSG.cjs +274 -0
  45. package/dist/{chunk-6OYJC4TZ.js → chunk-L5SCKZVK.js} +13 -22
  46. package/dist/chunk-LDM7RNNN.js +1 -0
  47. package/dist/{chunk-UAZKHSEU.js → chunk-LQST3NW2.js} +5 -15
  48. package/dist/chunk-M34E2AMK.js +1 -5
  49. package/dist/chunk-MF56KEI4.js +1 -4
  50. package/dist/chunk-MLKGABMK.js +1 -3
  51. package/dist/chunk-MLPZKUCO.js +4 -5
  52. package/dist/chunk-MMX5PUGC.cjs +242 -0
  53. package/dist/chunk-MWXJ6DZ2.cjs +21 -0
  54. package/dist/chunk-NJWOWXUR.cjs +137 -0
  55. package/dist/chunk-NNKBKENK.cjs +15 -0
  56. package/dist/chunk-NRG6QX3L.js +1 -3
  57. package/dist/chunk-OCKEEEYE.cjs +433 -0
  58. package/dist/chunk-OENJO7YW.js +306 -0
  59. package/dist/chunk-OKLAYEBC.cjs +2 -0
  60. package/dist/chunk-OPDWMD4Q.js +1 -3
  61. package/dist/{chunk-D6YJ5X3C.js → chunk-OX5GN2KB.js} +26 -14
  62. package/dist/{chunk-JEVLCA5C.js → chunk-OYBOP47A.js} +18 -19
  63. package/dist/chunk-OZHCHPIE.js +1 -0
  64. package/dist/chunk-PA3UTI4A.js +1 -4
  65. package/dist/chunk-QEEAIXL5.cjs +74 -0
  66. package/dist/chunk-QT5LGZG3.cjs +10 -0
  67. package/dist/chunk-R3TUE7O2.cjs +107 -0
  68. package/dist/chunk-RYVW7RUM.js +2 -6
  69. package/dist/{chunk-LVKKICOB.js → chunk-SOQYE5A4.js} +36 -69
  70. package/dist/chunk-ST2OXLT5.cjs +91 -0
  71. package/dist/{chunk-SIFDK4AA.js → chunk-TH4MG73B.js} +3 -24
  72. package/dist/{chunk-OSL4CNSO.js → chunk-TLMAMVAW.js} +7 -23
  73. package/dist/chunk-TPZHMD7J.cjs +72 -0
  74. package/dist/{chunk-PDSIWL7I.js → chunk-U4PYAGNR.js} +6 -19
  75. package/dist/chunk-UAPK3AIJ.js +1 -10
  76. package/dist/chunk-UF5IKELS.cjs +26 -0
  77. package/dist/chunk-UHFVWYSP.cjs +408 -0
  78. package/dist/chunk-UKBSXYKE.cjs +280 -0
  79. package/dist/chunk-UNX7V6P6.cjs +60 -0
  80. package/dist/chunk-UZMMJ47A.cjs +107 -0
  81. package/dist/chunk-VHD7CW5O.cjs +43 -0
  82. package/dist/chunk-VL4QNALG.cjs +50 -0
  83. package/dist/chunk-VYE7O4FM.cjs +51 -0
  84. package/dist/chunk-WIYVT4UO.cjs +173 -0
  85. package/dist/chunk-WJHHO24M.cjs +91 -0
  86. package/dist/chunk-WR7LSUIR.cjs +213 -0
  87. package/dist/chunk-XE6D4J63.cjs +72 -0
  88. package/dist/chunk-YAUXTFIN.cjs +21 -0
  89. package/dist/{chunk-NFPRKZQ5.js → chunk-YJUCGZNN.js} +5 -22
  90. package/dist/chunk-ZSHVXDA2.js +4 -10
  91. package/dist/chunk-ZX6T3LNG.js +302 -0
  92. package/dist/{client-BWhi-vSj.d.ts → client-DSXbcxII.d.ts} +10 -1
  93. package/dist/client.cjs +44 -4360
  94. package/dist/client.d.ts +4 -2
  95. package/dist/client.js +36 -37
  96. package/dist/core/client.cjs +14 -476
  97. package/dist/core/client.d.ts +8 -0
  98. package/dist/core/client.js +10 -11
  99. package/dist/core/error.cjs +8 -251
  100. package/dist/core/error.js +4 -9
  101. package/dist/core/index.cjs +27 -491
  102. package/dist/core/index.d.ts +2 -0
  103. package/dist/core/index.js +12 -19
  104. package/dist/core/resource.cjs +9 -33
  105. package/dist/core/resource.d.ts +2 -0
  106. package/dist/core/resource.js +2 -7
  107. package/dist/edge.cjs +74 -1111
  108. package/dist/edge.d.ts +3 -0
  109. package/dist/edge.js +14 -42
  110. package/dist/guard-CvW03v4u.d.ts +59 -0
  111. package/dist/index.cjs +140 -4431
  112. package/dist/index.d.ts +6 -2
  113. package/dist/index.js +44 -87
  114. package/dist/modelrouter/core.cjs +35 -651
  115. package/dist/modelrouter/core.d.ts +2 -0
  116. package/dist/modelrouter/core.js +12 -21
  117. package/dist/modelrouter/index.cjs +35 -651
  118. package/dist/modelrouter/index.d.ts +2 -0
  119. package/dist/modelrouter/index.js +12 -21
  120. package/dist/modelrouter/types.cjs +1 -17
  121. package/dist/modelrouter/types.d.ts +5 -0
  122. package/dist/modelrouter/types.js +1 -0
  123. package/dist/subagents/anthropic.cjs +31 -2784
  124. package/dist/subagents/anthropic.d.ts +3 -1
  125. package/dist/subagents/anthropic.js +23 -24
  126. package/dist/subagents/index.cjs +14 -95
  127. package/dist/subagents/index.d.ts +3 -1
  128. package/dist/subagents/index.js +2 -11
  129. package/dist/subagents/prompts.cjs +14 -93
  130. package/dist/subagents/prompts.d.ts +3 -1
  131. package/dist/subagents/prompts.js +2 -11
  132. package/dist/subagents/types.cjs +1 -17
  133. package/dist/subagents/types.d.ts +3 -1
  134. package/dist/subagents/types.js +1 -0
  135. package/dist/subagents/vercel.cjs +31 -2761
  136. package/dist/subagents/vercel.d.ts +3 -1
  137. package/dist/subagents/vercel.js +23 -24
  138. package/dist/tools/compact/core.cjs +20 -552
  139. package/dist/tools/compact/core.d.ts +2 -0
  140. package/dist/tools/compact/core.js +12 -13
  141. package/dist/tools/compact/index.cjs +24 -598
  142. package/dist/tools/compact/index.d.ts +3 -1
  143. package/dist/tools/compact/index.js +13 -17
  144. package/dist/tools/compact/types.cjs +1 -17
  145. package/dist/tools/compact/types.d.ts +4 -4
  146. package/dist/tools/compact/types.js +1 -0
  147. package/dist/tools/fastapply/anthropic.cjs +39 -899
  148. package/dist/tools/fastapply/anthropic.d.ts +2 -0
  149. package/dist/tools/fastapply/anthropic.js +15 -24
  150. package/dist/tools/fastapply/apply.cjs +32 -672
  151. package/dist/tools/fastapply/apply.d.ts +2 -0
  152. package/dist/tools/fastapply/apply.js +8 -19
  153. package/dist/tools/fastapply/core.cjs +49 -1069
  154. package/dist/tools/fastapply/core.d.ts +3 -0
  155. package/dist/tools/fastapply/core.js +13 -29
  156. package/dist/tools/fastapply/index.cjs +56 -1052
  157. package/dist/tools/fastapply/index.d.ts +2 -0
  158. package/dist/tools/fastapply/index.js +18 -44
  159. package/dist/tools/fastapply/openai.cjs +45 -910
  160. package/dist/tools/fastapply/openai.d.ts +2 -0
  161. package/dist/tools/fastapply/openai.js +15 -26
  162. package/dist/tools/fastapply/prompts.cjs +10 -62
  163. package/dist/tools/fastapply/prompts.js +2 -9
  164. package/dist/tools/fastapply/types.cjs +1 -17
  165. package/dist/tools/fastapply/types.d.ts +9 -4
  166. package/dist/tools/fastapply/types.js +1 -0
  167. package/dist/tools/fastapply/vercel.cjs +37 -905
  168. package/dist/tools/fastapply/vercel.d.ts +2 -0
  169. package/dist/tools/fastapply/vercel.js +15 -22
  170. package/dist/tools/index.cjs +56 -1052
  171. package/dist/tools/index.d.ts +2 -0
  172. package/dist/tools/index.js +18 -44
  173. package/dist/tools/pii/index.cjs +47 -0
  174. package/dist/tools/pii/index.d.ts +4 -0
  175. package/dist/tools/pii/index.js +6 -0
  176. package/dist/tools/pii/model.cjs +45 -0
  177. package/dist/tools/pii/model.d.ts +83 -0
  178. package/dist/tools/pii/model.js +4 -0
  179. package/dist/tools/pii/patterns.cjs +15 -0
  180. package/dist/tools/pii/patterns.d.ts +31 -0
  181. package/dist/tools/pii/patterns.js +2 -0
  182. package/dist/tools/pii/regex.cjs +32 -0
  183. package/dist/tools/pii/regex.d.ts +48 -0
  184. package/dist/tools/pii/regex.js +3 -0
  185. package/dist/tools/pii/types.cjs +2 -0
  186. package/dist/tools/pii/types.d.ts +108 -0
  187. package/dist/tools/pii/types.js +1 -0
  188. package/dist/tools/utils/resilience.cjs +15 -312
  189. package/dist/tools/utils/resilience.js +3 -12
  190. package/dist/tools/warp_grep/agent/config.cjs +16 -127
  191. package/dist/tools/warp_grep/agent/config.js +2 -11
  192. package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
  193. package/dist/tools/warp_grep/agent/formatter.js +2 -9
  194. package/dist/tools/warp_grep/agent/parser.cjs +16 -83
  195. package/dist/tools/warp_grep/agent/parser.d.ts +2 -0
  196. package/dist/tools/warp_grep/agent/parser.js +2 -11
  197. package/dist/tools/warp_grep/agent/runner.cjs +19 -1081
  198. package/dist/tools/warp_grep/agent/runner.d.ts +2 -0
  199. package/dist/tools/warp_grep/agent/runner.js +11 -14
  200. package/dist/tools/warp_grep/agent/types.cjs +1 -17
  201. package/dist/tools/warp_grep/agent/types.d.ts +4 -0
  202. package/dist/tools/warp_grep/agent/types.js +1 -0
  203. package/dist/tools/warp_grep/anthropic.cjs +51 -2561
  204. package/dist/tools/warp_grep/anthropic.d.ts +3 -1
  205. package/dist/tools/warp_grep/anthropic.js +23 -35
  206. package/dist/tools/warp_grep/client.cjs +53 -2471
  207. package/dist/tools/warp_grep/client.d.ts +3 -1
  208. package/dist/tools/warp_grep/client.js +21 -34
  209. package/dist/tools/warp_grep/gemini.cjs +52 -2490
  210. package/dist/tools/warp_grep/gemini.d.ts +3 -1
  211. package/dist/tools/warp_grep/gemini.js +25 -41
  212. package/dist/tools/warp_grep/harness.cjs +81 -936
  213. package/dist/tools/warp_grep/harness.d.ts +2 -0
  214. package/dist/tools/warp_grep/harness.js +12 -51
  215. package/dist/tools/warp_grep/index.cjs +128 -2575
  216. package/dist/tools/warp_grep/index.d.ts +3 -1
  217. package/dist/tools/warp_grep/index.js +28 -87
  218. package/dist/tools/warp_grep/openai.cjs +57 -2575
  219. package/dist/tools/warp_grep/openai.d.ts +3 -1
  220. package/dist/tools/warp_grep/openai.js +23 -37
  221. package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
  222. package/dist/tools/warp_grep/providers/code_storage_http.d.ts +3 -1
  223. package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
  224. package/dist/tools/warp_grep/providers/local.cjs +10 -589
  225. package/dist/tools/warp_grep/providers/local.js +6 -11
  226. package/dist/tools/warp_grep/providers/remote.cjs +8 -331
  227. package/dist/tools/warp_grep/providers/remote.d.ts +3 -1
  228. package/dist/tools/warp_grep/providers/remote.js +3 -8
  229. package/dist/tools/warp_grep/providers/types.cjs +1 -17
  230. package/dist/tools/warp_grep/providers/types.js +1 -0
  231. package/dist/tools/warp_grep/utils/files.cjs +9 -42
  232. package/dist/tools/warp_grep/utils/files.js +2 -7
  233. package/dist/tools/warp_grep/utils/github.cjs +9 -43
  234. package/dist/tools/warp_grep/utils/github.js +2 -7
  235. package/dist/tools/warp_grep/utils/paths.cjs +28 -104
  236. package/dist/tools/warp_grep/utils/paths.js +2 -17
  237. package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -103
  238. package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
  239. package/dist/tools/warp_grep/vercel.cjs +57 -2557
  240. package/dist/tools/warp_grep/vercel.d.ts +3 -1
  241. package/dist/tools/warp_grep/vercel.js +23 -37
  242. package/dist/{types-DxZLPogx.d.ts → types-BKhXjDCB.d.ts} +6 -1
  243. package/dist/version.cjs +7 -225
  244. package/dist/version.js +2 -7
  245. package/package.json +11 -2
  246. package/dist/chunk-E6TL6MIH.js +0 -203
@@ -0,0 +1,317 @@
1
+ 'use strict';
2
+
3
+ var chunkWR7LSUIR_cjs = require('./chunk-WR7LSUIR.cjs');
4
+ var chunkMWXJ6DZ2_cjs = require('./chunk-MWXJ6DZ2.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
+ var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
10
+ var chunkAWFZKS27_cjs = require('./chunk-AWFZKS27.cjs');
11
+
12
+ // tools/warp_grep/client.ts
13
+ var DEFAULT_CODE_SEARCH_URL = "https://api.morphllm.com";
14
+ async function getLocalProvider(repoRoot, excludes, allowNames) {
15
+ const { LocalRipgrepProvider } = await import('./tools/warp_grep/providers/local.cjs');
16
+ const opts = allowNames?.length ? { allowNames } : void 0;
17
+ return new LocalRipgrepProvider(repoRoot, excludes, opts);
18
+ }
19
+ var WarpGrepClient = class extends chunkAWFZKS27_cjs.APIResource {
20
+ config;
21
+ constructor(clientOrConfig = {}) {
22
+ const isClient = clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient;
23
+ super(
24
+ isClient ? clientOrConfig : new chunk5TTZQF4X_cjs.MorphAPIClient({
25
+ apiKey: clientOrConfig.morphApiKey,
26
+ baseURL: clientOrConfig.morphApiUrl,
27
+ timeout: clientOrConfig.timeout,
28
+ retryConfig: clientOrConfig.retryConfig,
29
+ debug: clientOrConfig.debug
30
+ })
31
+ );
32
+ const cfg = isClient ? {} : clientOrConfig;
33
+ this.config = {
34
+ ...cfg,
35
+ morphApiKey: this._client.resolveApiKey(),
36
+ morphApiUrl: this._client.baseURL,
37
+ timeout: this._client.timeout,
38
+ retryConfig: this._client.retryConfig,
39
+ debug: this._client.debug,
40
+ redactPII: cfg.redactPII ?? this._client.redactPII
41
+ };
42
+ }
43
+ execute(input) {
44
+ const toolConfig = {
45
+ repoRoot: input.repoRoot,
46
+ remoteCommands: input.remoteCommands,
47
+ provider: input.provider,
48
+ excludes: input.excludes,
49
+ includes: input.includes,
50
+ debug: input.debug ?? this.config.debug,
51
+ morphApiKey: this.config.morphApiKey,
52
+ morphApiUrl: this.config.morphApiUrl,
53
+ retryConfig: this.config.retryConfig,
54
+ timeout: this.config.timeout,
55
+ search_type: input.search_type,
56
+ redactPII: this.config.redactPII
57
+ };
58
+ if (input.streamSteps) {
59
+ return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);
60
+ }
61
+ return executeToolCall({ search_term: input.searchTerm }, toolConfig);
62
+ }
63
+ searchGitHub(input) {
64
+ if (input.streamSteps) {
65
+ return this._searchGitHubStreaming(input);
66
+ }
67
+ return this._searchGitHubAsync(input);
68
+ }
69
+ /**
70
+ * Read a single file from a public GitHub repository
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const result = await client.readGitHubFile({
75
+ * github: 'vercel/next.js',
76
+ * path: 'src/server/app-render/index.tsx',
77
+ * startLine: 1,
78
+ * endLine: 50,
79
+ * });
80
+ * if (result.success) console.log(result.content);
81
+ * ```
82
+ */
83
+ async readGitHubFile(input) {
84
+ return executeGitHubReadFile(input, { timeout: this.config.timeout });
85
+ }
86
+ async _resolveGitHubRepo(input) {
87
+ const { owner, repo } = chunkMWXJ6DZ2_cjs.parseGitHubUrl(input.github);
88
+ const baseUrl = this.config.codeSearchUrl || DEFAULT_CODE_SEARCH_URL;
89
+ chunkVL4QNALG_cjs.logger.debug("WarpGrep", "github_resolve", { owner_repo: `${owner}/${repo}`, branch: input.branch });
90
+ const resolveStart = Date.now();
91
+ const importRes = await fetch(`${baseUrl}/api/code-search/get-or-create?url=${encodeURIComponent(`${owner}/${repo}`)}`, {
92
+ headers: this.config.morphApiKey ? { Authorization: `Bearer ${this.config.morphApiKey}` } : void 0
93
+ });
94
+ if (!importRes.ok) {
95
+ const text = await importRes.text().catch(() => importRes.statusText);
96
+ chunkVL4QNALG_cjs.logger.error("WarpGrep", "github_resolve_failed", { owner_repo: `${owner}/${repo}`, status: importRes.status, error: text });
97
+ throw new Error(`Failed to import repo ${owner}/${repo}: ${text}`);
98
+ }
99
+ const { repoId, defaultBranch } = await importRes.json();
100
+ chunkVL4QNALG_cjs.logger.debug("WarpGrep", "github_repo_fetched", { repo_id: repoId, default_branch: defaultBranch, latency_ms: Date.now() - resolveStart });
101
+ return {
102
+ repo,
103
+ remoteCommands: chunkVHD7CW5O_cjs.createCodeStorageHttpCommands({
104
+ baseUrl,
105
+ repoId,
106
+ branch: input.branch || defaultBranch,
107
+ apiKey: this.config.morphApiKey
108
+ })
109
+ };
110
+ }
111
+ async _searchGitHubAsync(input) {
112
+ try {
113
+ const { remoteCommands } = await this._resolveGitHubRepo(input);
114
+ return this.execute({
115
+ searchTerm: input.searchTerm,
116
+ repoRoot: ".",
117
+ remoteCommands
118
+ });
119
+ } catch (error) {
120
+ return { success: false, error: error instanceof Error ? error.message : String(error) };
121
+ }
122
+ }
123
+ async *_searchGitHubStreaming(input) {
124
+ let remoteCommands;
125
+ try {
126
+ ({ remoteCommands } = await this._resolveGitHubRepo(input));
127
+ } catch (error) {
128
+ return { success: false, error: error instanceof Error ? error.message : String(error) };
129
+ }
130
+ const generator = this.execute({
131
+ searchTerm: input.searchTerm,
132
+ repoRoot: ".",
133
+ remoteCommands,
134
+ streamSteps: true
135
+ });
136
+ let result;
137
+ for (; ; ) {
138
+ const { value, done } = await generator.next();
139
+ if (done) {
140
+ result = value;
141
+ break;
142
+ }
143
+ yield value;
144
+ }
145
+ return result;
146
+ }
147
+ };
148
+ function executeWarpGrep(input, config) {
149
+ const client = new WarpGrepClient(config);
150
+ if (input.streamSteps) {
151
+ return client.execute({ ...input, streamSteps: true });
152
+ }
153
+ return client.execute({ ...input, streamSteps: false });
154
+ }
155
+ async function executeToolCall(input, config) {
156
+ const parsed = typeof input === "string" ? JSON.parse(input) : input;
157
+ const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
158
+ const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
159
+ const result = await chunkOCKEEEYE_cjs.runWarpGrep({
160
+ searchTerm: parsed.search_term,
161
+ repoRoot: config.repoRoot,
162
+ provider,
163
+ excludes: config.excludes,
164
+ includes: config.includes,
165
+ debug: config.debug ?? false,
166
+ morphApiKey: config.morphApiKey,
167
+ morphApiUrl: config.morphApiUrl,
168
+ retryConfig: config.retryConfig,
169
+ timeout: config.timeout,
170
+ search_type: config.search_type,
171
+ redactPII: config.redactPII
172
+ });
173
+ return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
174
+ }
175
+ async function processAgentResult(result, searchTerm, apiKey, apiUrl, redactPII) {
176
+ const finish = result.finish;
177
+ if (result.terminationReason !== "completed" || !finish?.metadata) {
178
+ const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
179
+ console.error(`[warp_grep] processAgentResult failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
180
+ return { success: false, error: `Search did not complete: ${errorDetails}` };
181
+ }
182
+ const contexts = (finish.resolved ?? []).map((r) => ({
183
+ file: r.path,
184
+ content: r.content,
185
+ lines: r.ranges
186
+ }));
187
+ try {
188
+ const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
189
+ const compacted = await chunkVYE7O4FM_cjs.compactFileContexts(compactable, searchTerm, apiKey, apiUrl, void 0, void 0, redactPII);
190
+ for (let i = 0; i < contexts.length; i++) {
191
+ contexts[i].content = compacted[i].content;
192
+ }
193
+ } catch (error) {
194
+ console.error(`[warp_grep] Failed to compact result contexts:`, error);
195
+ }
196
+ return { success: true, contexts, summary: finish.payload };
197
+ }
198
+ async function* executeToolCallStreaming(input, config) {
199
+ const parsed = typeof input === "string" ? JSON.parse(input) : input;
200
+ const allowNames = config.search_type === "node_modules" ? ["node_modules"] : void 0;
201
+ const provider = config.remoteCommands ? new chunkWR7LSUIR_cjs.RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);
202
+ const generator = chunkOCKEEEYE_cjs.runWarpGrepStreaming({
203
+ searchTerm: parsed.search_term,
204
+ repoRoot: config.repoRoot,
205
+ provider,
206
+ excludes: config.excludes,
207
+ includes: config.includes,
208
+ debug: config.debug ?? false,
209
+ morphApiKey: config.morphApiKey,
210
+ morphApiUrl: config.morphApiUrl,
211
+ retryConfig: config.retryConfig,
212
+ timeout: config.timeout,
213
+ search_type: config.search_type,
214
+ redactPII: config.redactPII
215
+ });
216
+ let agentResult;
217
+ for (; ; ) {
218
+ const { value, done } = await generator.next();
219
+ if (done) {
220
+ agentResult = value;
221
+ break;
222
+ }
223
+ yield value;
224
+ }
225
+ return await processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl, config.redactPII);
226
+ }
227
+ async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
228
+ const branches = branch ? [branch] : ["HEAD"];
229
+ const fallbacks = ["main", "master", "develop"];
230
+ const fetchWithTimeout = (url) => timeout ? fetch(url, { signal: AbortSignal.timeout(timeout) }) : fetch(url);
231
+ for (const b of branches) {
232
+ const url = `https://raw.githubusercontent.com/${owner}/${repo}/${b}/${filePath}`;
233
+ const res = await fetchWithTimeout(url);
234
+ if (res.ok) return { content: await res.text(), branch: b };
235
+ }
236
+ for (const fb of fallbacks) {
237
+ if (branch && fb === branch) continue;
238
+ const url = `https://raw.githubusercontent.com/${owner}/${repo}/${fb}/${filePath}`;
239
+ const res = await fetchWithTimeout(url);
240
+ if (res.ok) return { content: await res.text(), branch: fb };
241
+ }
242
+ throw new Error(`File not found: ${owner}/${repo}/${filePath}`);
243
+ }
244
+ async function executeGitHubReadFile(input, config) {
245
+ try {
246
+ const { owner, repo } = chunkMWXJ6DZ2_cjs.parseGitHubUrl(input.github);
247
+ const { content: raw, branch } = await fetchRawGitHubFile(
248
+ owner,
249
+ repo,
250
+ input.path,
251
+ input.branch,
252
+ config?.timeout
253
+ );
254
+ const allLines = raw.split("\n");
255
+ const totalLines = allLines.length;
256
+ const start = Math.max(1, input.startLine ?? 1);
257
+ const end = Math.min(totalLines, input.endLine ?? totalLines);
258
+ const selected = allLines.slice(start - 1, end);
259
+ const padWidth = String(end).length;
260
+ const numbered = selected.map((line, i) => `${String(start + i).padStart(padWidth)}|${line}`).join("\n");
261
+ return {
262
+ success: true,
263
+ content: numbered,
264
+ path: input.path,
265
+ github: `${owner}/${repo}`,
266
+ branch,
267
+ lineRange: [start, end],
268
+ totalLines
269
+ };
270
+ } catch (error) {
271
+ return {
272
+ success: false,
273
+ error: error instanceof Error ? error.message : String(error)
274
+ };
275
+ }
276
+ }
277
+ function formatGitHubReadFileResult(result) {
278
+ if (!result.success) {
279
+ return `Failed to read file: ${result.error}`;
280
+ }
281
+ const rangeStr = result.lineRange ? ` (lines ${result.lineRange[0]}-${result.lineRange[1]} of ${result.totalLines})` : "";
282
+ return `File: ${result.github}/${result.path}${rangeStr}
283
+
284
+ ${result.content}`;
285
+ }
286
+ function formatResult(result) {
287
+ if (!result.success) {
288
+ return `Search failed: ${result.error}`;
289
+ }
290
+ if (!result.contexts || result.contexts.length === 0) {
291
+ return "No relevant code found. Try rephrasing your search term.";
292
+ }
293
+ const parts = [];
294
+ parts.push(`Morph Fast Context subagent performed search on repository:
295
+ `);
296
+ parts.push("Relevant context found:");
297
+ for (const ctx of result.contexts) {
298
+ const rangeStr = !ctx.lines || ctx.lines === "*" ? "*" : ctx.lines.map(([s, e]) => `${s}-${e}`).join(",");
299
+ parts.push(`- ${ctx.file}:${rangeStr}`);
300
+ }
301
+ parts.push("\nHere is the content of files:\n");
302
+ for (const ctx of result.contexts) {
303
+ const rangeStr = !ctx.lines || ctx.lines === "*" ? "" : ` lines="${ctx.lines.map(([s, e]) => `${s}-${e}`).join(",")}"`;
304
+ parts.push(`<file path="${ctx.file}"${rangeStr}>`);
305
+ parts.push(ctx.content);
306
+ parts.push("</file>\n");
307
+ }
308
+ return parts.join("\n");
309
+ }
310
+
311
+ exports.WarpGrepClient = WarpGrepClient;
312
+ exports.executeGitHubReadFile = executeGitHubReadFile;
313
+ exports.executeToolCall = executeToolCall;
314
+ exports.executeToolCallStreaming = executeToolCallStreaming;
315
+ exports.executeWarpGrep = executeWarpGrep;
316
+ exports.formatGitHubReadFileResult = formatGitHubReadFileResult;
317
+ exports.formatResult = formatResult;
@@ -1,9 +1,7 @@
1
- import {
2
- CompactClient
3
- } from "./chunk-D6YJ5X3C.js";
1
+ import { CompactClient } from './chunk-OX5GN2KB.js';
4
2
 
5
3
  // tools/compact/utils.ts
6
- async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
4
+ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3, redactPII) {
7
5
  const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
8
6
  const estimatedTokens = totalLength / 3;
9
7
  if (estimatedTokens <= maxTokens) {
@@ -13,7 +11,8 @@ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4
13
11
  compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
14
12
  const client = new CompactClient({
15
13
  morphApiKey: apiKey,
16
- morphApiUrl: apiUrl
14
+ morphApiUrl: apiUrl,
15
+ redactPII
17
16
  });
18
17
  const results = [];
19
18
  const inProgress = /* @__PURE__ */ new Set();
@@ -47,6 +46,4 @@ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4
47
46
  return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
48
47
  }
49
48
 
50
- export {
51
- compactFileContexts
52
- };
49
+ export { compactFileContexts };
@@ -0,0 +1,100 @@
1
+ 'use strict';
2
+
3
+ var chunk6HAYJA6M_cjs = require('./chunk-6HAYJA6M.cjs');
4
+ var chunkR3TUE7O2_cjs = require('./chunk-R3TUE7O2.cjs');
5
+
6
+ // tools/pii/guard.ts
7
+ var PIIRestoreError = class extends Error {
8
+ constructor(tokens) {
9
+ super(
10
+ `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.`
11
+ );
12
+ this.tokens = tokens;
13
+ this.name = "PIIRestoreError";
14
+ }
15
+ };
16
+ var PIISession = class {
17
+ constructor(detect) {
18
+ this.detect = detect;
19
+ }
20
+ nonce = Math.random().toString(36).slice(2, 6).padEnd(4, "0");
21
+ tokenFor = /* @__PURE__ */ new Map();
22
+ valueFor = /* @__PURE__ */ new Map();
23
+ counters = /* @__PURE__ */ new Map();
24
+ cache = /* @__PURE__ */ new Map();
25
+ tokenPattern = new RegExp(`__PII_[A-Z0-9_]+?_\\d+_${this.nonce}__`, "g");
26
+ /** Number of distinct values redacted so far. */
27
+ get size() {
28
+ return this.valueFor.size;
29
+ }
30
+ token(type, value) {
31
+ const key = `${type}\0${value}`;
32
+ let token = this.tokenFor.get(key);
33
+ if (!token) {
34
+ const index = (this.counters.get(type) ?? 0) + 1;
35
+ this.counters.set(type, index);
36
+ token = `__PII_${type.replace(/[^A-Z0-9]+/gi, "_").toUpperCase()}_${index}_${this.nonce}__`;
37
+ this.tokenFor.set(key, token);
38
+ this.valueFor.set(token, value);
39
+ }
40
+ return token;
41
+ }
42
+ /** Replace sensitive values with tokens. Repeated text is answered from a cache. */
43
+ async redact(text) {
44
+ if (!text) return text;
45
+ const cached = this.cache.get(text);
46
+ if (cached !== void 0) return cached;
47
+ const entities = await this.detect(text);
48
+ const out = chunkR3TUE7O2_cjs.applyRedactions(
49
+ text,
50
+ entities,
51
+ (entity) => (
52
+ // One token per line, so the line count (and any line numbers Morph returns)
53
+ // is the same before and after redaction.
54
+ entity.value.split("\n").map((line) => line ? this.token(entity.type, line) : "").join("\n")
55
+ )
56
+ );
57
+ this.cache.set(text, out);
58
+ return out;
59
+ }
60
+ restore(text) {
61
+ if (!text || this.valueFor.size === 0) return text;
62
+ return text.replace(this.tokenPattern, (token) => this.valueFor.get(token) ?? token);
63
+ }
64
+ /**
65
+ * Like `restore`, but throws if the text holds a token this session did not issue, or a
66
+ * damaged one (a token that lost its head or its tail). Use it wherever the result is
67
+ * written somewhere durable.
68
+ */
69
+ restoreStrict(text) {
70
+ const unknown = (text.match(this.tokenPattern) ?? []).filter((token) => !this.valueFor.has(token));
71
+ const restored = this.restore(text);
72
+ const tail = `_${this.nonce}__`;
73
+ if (this.valueFor.size > 0) {
74
+ if (restored.includes(tail)) unknown.push(tail);
75
+ for (const token of this.valueFor.keys()) {
76
+ const head = token.slice(0, -(this.nonce.length + 2));
77
+ if (restored.includes(head)) unknown.push(head);
78
+ }
79
+ }
80
+ if (unknown.length) throw new PIIRestoreError([...new Set(unknown)]);
81
+ return restored;
82
+ }
83
+ };
84
+ var guards = /* @__PURE__ */ new WeakMap();
85
+ var defaultGuard;
86
+ function build(config) {
87
+ const redactor = chunk6HAYJA6M_cjs.createPIIRedactor(config);
88
+ return { session: () => new PIISession((text) => redactor.detect(text)) };
89
+ }
90
+ function resolvePIIGuard(option) {
91
+ if (!option) return void 0;
92
+ if (option === true) return defaultGuard ??= build({});
93
+ let guard = guards.get(option);
94
+ if (!guard) guards.set(option, guard = build(option));
95
+ return guard;
96
+ }
97
+
98
+ exports.PIIRestoreError = PIIRestoreError;
99
+ exports.PIISession = PIISession;
100
+ exports.resolvePIIGuard = resolvePIIGuard;