@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
package/dist/edge.cjs CHANGED
@@ -1,1116 +1,79 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
29
2
 
30
- // edge.ts
31
- var edge_exports = {};
32
- __export(edge_exports, {
33
- AnthropicRouter: () => AnthropicRouter,
34
- CompactClient: () => CompactClient,
35
- FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
36
- FastApplyContextLengthError: () => FastApplyContextLengthError,
37
- GeminiRouter: () => GeminiRouter,
38
- OpenAIRouter: () => OpenAIRouter,
39
- RawRouter: () => RawRouter,
40
- RouterClassifier: () => RouterClassifier,
41
- SDK_VERSION: () => SDK_VERSION,
42
- applyEdit: () => applyEdit,
43
- callMorphAPI: () => callMorphAPI,
44
- countChanges: () => countChanges,
45
- generateUdiff: () => generateUdiff
46
- });
47
- module.exports = __toCommonJS(edge_exports);
48
-
49
- // package.json
50
- var package_default = {
51
- name: "@morphllm/morphsdk",
52
- version: "0.2.202",
53
- description: "TypeScript SDK and CLI for Morph Fast Apply integration",
54
- type: "module",
55
- main: "./dist/index.cjs",
56
- module: "./dist/index.js",
57
- types: "./dist/index.d.ts",
58
- exports: {
59
- ".": {
60
- types: "./dist/index.d.ts",
61
- import: "./dist/index.js",
62
- require: "./dist/index.cjs"
63
- },
64
- "./logger": {
65
- types: "./dist/logger.d.ts",
66
- import: "./dist/logger.js",
67
- require: "./dist/logger.cjs"
68
- },
69
- "./edge": {
70
- types: "./dist/edge.d.ts",
71
- import: "./dist/edge.js",
72
- require: "./dist/edge.cjs"
73
- },
74
- "./tools/warp-grep": {
75
- types: "./dist/tools/warp_grep/index.d.ts",
76
- import: "./dist/tools/warp_grep/index.js",
77
- require: "./dist/tools/warp_grep/index.cjs"
78
- },
79
- "./tools/warp-grep/openai": {
80
- types: "./dist/tools/warp_grep/openai.d.ts",
81
- import: "./dist/tools/warp_grep/openai.js",
82
- require: "./dist/tools/warp_grep/openai.cjs"
83
- },
84
- "./tools/warp-grep/anthropic": {
85
- types: "./dist/tools/warp_grep/anthropic.d.ts",
86
- import: "./dist/tools/warp_grep/anthropic.js",
87
- require: "./dist/tools/warp_grep/anthropic.cjs"
88
- },
89
- "./tools/warp-grep/vercel": {
90
- types: "./dist/tools/warp_grep/vercel.d.ts",
91
- import: "./dist/tools/warp_grep/vercel.js",
92
- require: "./dist/tools/warp_grep/vercel.cjs"
93
- },
94
- "./tools/warp-grep/client": {
95
- types: "./dist/tools/warp_grep/client.d.ts",
96
- import: "./dist/tools/warp_grep/client.js",
97
- require: "./dist/tools/warp_grep/client.cjs"
98
- },
99
- "./tools/warp-grep/gemini": {
100
- types: "./dist/tools/warp_grep/gemini.d.ts",
101
- import: "./dist/tools/warp_grep/gemini.js",
102
- require: "./dist/tools/warp_grep/gemini.cjs"
103
- },
104
- "./tools/warp-grep/harness": {
105
- types: "./dist/tools/warp_grep/harness.d.ts",
106
- import: "./dist/tools/warp_grep/harness.js",
107
- require: "./dist/tools/warp_grep/harness.cjs"
108
- },
109
- "./tools/fastapply": {
110
- types: "./dist/tools/fastapply/index.d.ts",
111
- import: "./dist/tools/fastapply/index.js",
112
- require: "./dist/tools/fastapply/index.cjs"
113
- },
114
- "./tools/fastapply/anthropic": {
115
- types: "./dist/tools/fastapply/anthropic.d.ts",
116
- import: "./dist/tools/fastapply/anthropic.js",
117
- require: "./dist/tools/fastapply/anthropic.cjs"
118
- },
119
- "./tools/fastapply/openai": {
120
- types: "./dist/tools/fastapply/openai.d.ts",
121
- import: "./dist/tools/fastapply/openai.js",
122
- require: "./dist/tools/fastapply/openai.cjs"
123
- },
124
- "./tools/fastapply/vercel": {
125
- types: "./dist/tools/fastapply/vercel.d.ts",
126
- import: "./dist/tools/fastapply/vercel.js",
127
- require: "./dist/tools/fastapply/vercel.cjs"
128
- },
129
- "./modelrouter": {
130
- types: "./dist/modelrouter/index.d.ts",
131
- import: "./dist/modelrouter/index.js",
132
- require: "./dist/modelrouter/index.cjs"
133
- },
134
- "./tools/compact": {
135
- types: "./dist/tools/compact/index.d.ts",
136
- import: "./dist/tools/compact/index.js",
137
- require: "./dist/tools/compact/index.cjs"
138
- },
139
- "./subagents": {
140
- types: "./dist/subagents/index.d.ts",
141
- import: "./dist/subagents/index.js",
142
- require: "./dist/subagents/index.cjs"
143
- },
144
- "./subagents/vercel": {
145
- types: "./dist/subagents/vercel.d.ts",
146
- import: "./dist/subagents/vercel.js",
147
- require: "./dist/subagents/vercel.cjs"
148
- },
149
- "./subagents/anthropic": {
150
- types: "./dist/subagents/anthropic.d.ts",
151
- import: "./dist/subagents/anthropic.js",
152
- require: "./dist/subagents/anthropic.cjs"
153
- },
154
- "./ai-sdk": {
155
- types: "./dist/ai-sdk/index.d.ts",
156
- import: "./dist/ai-sdk/index.js",
157
- require: "./dist/ai-sdk/index.cjs"
158
- }
159
- },
160
- files: [
161
- "dist/**/*.js",
162
- "dist/**/*.cjs",
163
- "dist/**/*.d.ts",
164
- "!dist/**/__tests__/**",
165
- "!dist/**/*.test.*"
166
- ],
167
- scripts: {
168
- build: "tsup version.ts index.ts edge.ts client.ts core/index.ts core/client.ts core/resource.ts core/error.ts tools/index.ts tools/fastapply/index.ts tools/fastapply/core.ts tools/fastapply/apply.ts tools/fastapply/types.ts tools/fastapply/prompts.ts tools/fastapply/anthropic.ts tools/fastapply/openai.ts tools/fastapply/vercel.ts tools/warp_grep/index.ts tools/warp_grep/client.ts tools/warp_grep/openai.ts tools/warp_grep/anthropic.ts tools/warp_grep/vercel.ts tools/warp_grep/gemini.ts tools/warp_grep/harness.ts tools/warp_grep/agent/config.ts tools/warp_grep/agent/parser.ts tools/warp_grep/agent/runner.ts tools/warp_grep/agent/types.ts tools/warp_grep/agent/formatter.ts tools/warp_grep/providers/types.ts tools/warp_grep/providers/local.ts tools/warp_grep/providers/remote.ts tools/warp_grep/providers/code_storage_http.ts tools/warp_grep/tools/grep.ts tools/warp_grep/tools/analyse.ts tools/warp_grep/tools/read.ts tools/warp_grep/tools/finish.ts tools/warp_grep/utils/paths.ts tools/warp_grep/utils/github.ts tools/warp_grep/utils/ripgrep.ts tools/warp_grep/utils/format.ts tools/warp_grep/utils/files.ts modelrouter/index.ts modelrouter/core.ts modelrouter/types.ts tools/compact/index.ts tools/compact/core.ts tools/compact/types.ts tools/utils/resilience.ts subagents/index.ts subagents/types.ts subagents/prompts.ts subagents/vercel.ts subagents/anthropic.ts --format esm,cjs --clean --dts --dts-resolve && tsup ai-sdk/index.ts --format esm,cjs --dts --no-clean --out-dir dist/ai-sdk",
169
- prepare: "npm run build",
170
- typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
171
- lint: "eslint .",
172
- test: "vitest run",
173
- "test:watch": "vitest watch",
174
- "test:anthropic": "vitest run anthropic",
175
- "test:openai": "vitest run openai",
176
- "test:vercel": "vitest run vercel",
177
- "test:git": "vitest run git",
178
- "test:agent": "npx tsx tests/fullAgentTest.ts",
179
- "test:integration": "npx tsx tests/fullIntegrationTest.ts",
180
- "test:e2e": "vitest run --config vitest.e2e.config.ts",
181
- "release:patch": "npm version patch && npm publish",
182
- "release:minor": "npm version minor && npm publish",
183
- "release:major": "npm version major && npm publish"
184
- },
185
- keywords: [
186
- "morph",
187
- "fast-apply",
188
- "cli",
189
- "sdk",
190
- "edit-file"
191
- ],
192
- engines: {
193
- node: ">=18"
194
- },
195
- license: "MIT",
196
- dependencies: {
197
- "@vscode/ripgrep": "^1.17.0",
198
- ai: ">=5.0.0",
199
- diff: "^7.0.0",
200
- openai: "^4.52.7",
201
- zod: ">=3.23.0"
202
- },
203
- devDependencies: {
204
- "@ai-sdk/anthropic": "^2.0.70",
205
- "@ai-sdk/openai": "^2.0.35",
206
- "@anthropic-ai/sdk": "^0.30.1",
207
- "@google/generative-ai": "^0.24.1",
208
- "@types/diff": "^7.0.2",
209
- "@types/node": "^20.14.10",
210
- "@typescript-eslint/eslint-plugin": "^7.18.0",
211
- "@typescript-eslint/parser": "^7.18.0",
212
- dotenv: "^16.4.5",
213
- eslint: "^8.57.0",
214
- shx: "^0.3.4",
215
- tsup: "^8.5.0",
216
- tsx: "^4.16.2",
217
- typescript: "^5.5.4",
218
- vitest: "^2.1.6"
219
- },
220
- peerDependencies: {
221
- "@ai-sdk/openai-compatible": ">=2.0.74 <4",
222
- "@anthropic-ai/sdk": ">=0.25.0",
223
- "@google/generative-ai": ">=0.21.0",
224
- ai: ">=5.0.0",
225
- zod: ">=3.23.0"
226
- },
227
- peerDependenciesMeta: {
228
- "@anthropic-ai/sdk": {
229
- optional: true
230
- },
231
- "@google/generative-ai": {
232
- optional: true
233
- },
234
- ai: {
235
- optional: true
236
- },
237
- zod: {
238
- optional: true
239
- }
240
- },
241
- publishConfig: {
242
- access: "public"
243
- }
244
- };
245
-
246
- // version.ts
247
- var SDK_VERSION = package_default.version;
248
-
249
- // tools/fastapply/apply.ts
250
- var import_diff = require("diff");
251
- var import_openai = __toESM(require("openai"), 1);
252
-
253
- // logger.ts
254
- var MorphLogger = class {
255
- enabled;
256
- fileStream;
257
- /** Resolves once the file stream is initialized (or immediately if no file logging). */
258
- ready;
259
- constructor() {
260
- this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
261
- this.fileStream = null;
262
- const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
263
- if (f) {
264
- this.ready = import("fs").then((fs) => {
265
- this.fileStream = fs.createWriteStream(f, { flags: "a" });
266
- }).catch(() => {
267
- });
268
- } else {
269
- this.ready = Promise.resolve();
270
- }
271
- }
272
- debug(component, msg, data) {
273
- this._log("debug", component, msg, data);
274
- }
275
- info(component, msg, data) {
276
- this._log("info", component, msg, data);
277
- }
278
- warn(component, msg, data) {
279
- this._log("warn", component, msg, data);
280
- }
281
- error(component, msg, data) {
282
- this._log("error", component, msg, data);
283
- }
284
- enable() {
285
- this.enabled = true;
286
- }
287
- get isEnabled() {
288
- return this.enabled;
289
- }
290
- _log(level, component, msg, data) {
291
- if (level !== "error" && !this.enabled) return;
292
- const ts = (/* @__PURE__ */ new Date()).toISOString();
293
- const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
294
- console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
295
- this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
296
- }
297
- };
298
- var logger = new MorphLogger();
299
-
300
- // tools/fastapply/anchors.ts
301
- var DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
302
- var DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
303
- var FastApplyAnchorIntegrityError = class extends Error {
304
- code = "anchor_integrity_failed";
305
- completionId;
306
- constructor(completionId) {
307
- super(
308
- "Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
309
- );
310
- this.name = "FastApplyAnchorIntegrityError";
311
- this.completionId = completionId;
312
- }
313
- };
314
- function escapeRegExp(value) {
315
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
316
- }
317
- function findNamespace(values) {
318
- for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
319
- const prefix = `\u27EAM${namespace}:`;
320
- if (values.every((value) => !value.includes(prefix))) {
321
- return namespace;
322
- }
323
- }
324
- throw new Error("Unable to allocate a Fast Apply anchor namespace");
325
- }
326
- function htmlLabel(token) {
327
- if (!token.startsWith("<")) return "text";
328
- const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
329
- return (match?.[1] ?? "tag").toLowerCase();
330
- }
331
- function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
332
- return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
333
- value: token,
334
- label: htmlLabel(token),
335
- anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
336
- }));
337
- }
338
- function sourceUnits(originalCode, editContext) {
339
- const trimmed = originalCode.trimStart().toLowerCase();
340
- const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
341
- if (looksLikeHtml) {
342
- const contextWords = new Set(
343
- editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
344
- );
345
- return htmlTokenUnits(originalCode, contextWords);
346
- }
347
- const parts = originalCode.split(/(\r\n|\n|\r)/);
348
- const units = [];
349
- for (let index = 0; index < parts.length; index += 2) {
350
- const line = parts[index] ?? "";
351
- const lineEnding = parts[index + 1] ?? "";
352
- units.push({
353
- value: line,
354
- label: "line",
355
- anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
356
- });
357
- if (lineEnding) {
358
- units.push({ value: lineEnding, anchorable: false });
359
- }
360
- }
361
- return units;
362
- }
363
- function copyCount(value) {
364
- const words = {
365
- one: 1,
366
- two: 2,
367
- three: 3,
368
- four: 4,
369
- five: 5,
370
- six: 6,
371
- seven: 7,
372
- eight: 8,
373
- nine: 9,
374
- ten: 10
375
- };
376
- return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
377
- }
378
- function structuralExpectation(originalCode, editContext) {
379
- const context = editContext.join(" ");
380
- const match = context.match(
381
- /(?:for every|for each|each)\s+([a-z][\w:-]*)[\s\S]{0,120}?add\s+(one|two|three|four|five|six|seven|eight|nine|ten|\d+)\s+identical cop(?:y|ies)/i
382
- );
383
- if (!match) return void 0;
384
- const tag = match[1].toLowerCase();
385
- const addedCopies = copyCount(match[2]);
386
- if (addedCopies === void 0) return void 0;
387
- const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
388
- const originalCount = originalCode.match(tagPattern)?.length ?? 0;
389
- if (originalCount === 0) return void 0;
390
- return { tag, expectedCount: originalCount * (addedCopies + 1) };
391
- }
392
- function createAnchorCompactionPlan(originalCode, collisionValues = []) {
393
- const namespace = findNamespace([originalCode, ...collisionValues]);
394
- const expectation = structuralExpectation(originalCode, collisionValues);
395
- const markerPrefix = `\u27EAM${namespace}:`;
396
- const definitions = /* @__PURE__ */ new Map();
397
- const values = [];
398
- const markers = [];
399
- let anchorCount = 0;
400
- let skeleton = "";
401
- for (const unit of sourceUnits(originalCode, collisionValues)) {
402
- if (!unit.anchorable) {
403
- skeleton += unit.value;
404
- continue;
405
- }
406
- let id = definitions.get(unit.value);
407
- if (id === void 0) {
408
- id = values.length;
409
- definitions.set(unit.value, id);
410
- values.push(unit.value);
411
- markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
412
- }
413
- skeleton += markers[id];
414
- anchorCount++;
415
- }
416
- if (anchorCount === 0 || skeleton.length >= originalCode.length) {
417
- return void 0;
418
- }
419
- const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
420
- const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
421
- const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
422
- const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
423
- const code = [
424
- definitionsBegin,
425
- serializedDefinitions,
426
- definitionsEnd,
427
- codeBegin,
428
- skeleton
429
- ].join("\n");
430
- const instructionSuffix = `
431
-
432
- LARGE-FILE ANCHOR PROTOCOL:
433
- The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
434
- Each ${markerPrefix}N:kind\u27EB placeholder represents the exact source fragment in its matching JSON-string definition. The kind suffix describes its HTML tag, text, or source line.
435
- Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
436
- Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
437
- To modify an anchored fragment, output the modified source instead of its placeholder.
438
- Do not invent or alter placeholder IDs.`;
439
- const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
440
- return {
441
- code,
442
- instructionSuffix,
443
- anchorCount,
444
- uniqueAnchorCount: values.length,
445
- hasStructuralValidation: expectation !== void 0,
446
- expand(content) {
447
- const codeBeginIndex = content.lastIndexOf(codeBegin);
448
- const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
449
- const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
450
- const id = Number(idText);
451
- const value = values[id];
452
- return value === void 0 || markers[id] !== marker ? marker : value;
453
- });
454
- if (expanded.includes(markerPrefix)) {
455
- throw new FastApplyAnchorIntegrityError();
456
- }
457
- if (expectation) {
458
- const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
459
- const actualCount = expanded.match(tagPattern)?.length ?? 0;
460
- if (actualCount !== expectation.expectedCount) {
461
- throw new FastApplyAnchorIntegrityError();
462
- }
463
- }
464
- return expanded;
465
- }
466
- };
467
- }
3
+ var chunkWIYVT4UO_cjs = require('./chunk-WIYVT4UO.cjs');
4
+ var chunkUHFVWYSP_cjs = require('./chunk-UHFVWYSP.cjs');
5
+ var chunkF633IVQA_cjs = require('./chunk-F633IVQA.cjs');
6
+ require('./chunk-5TTZQF4X.cjs');
7
+ require('./chunk-VL4QNALG.cjs');
8
+ require('./chunk-KF6S3EPJ.cjs');
9
+ require('./chunk-6HAYJA6M.cjs');
10
+ var chunkR3TUE7O2_cjs = require('./chunk-R3TUE7O2.cjs');
11
+ require('./chunk-DLYDIYDK.cjs');
12
+ require('./chunk-YAUXTFIN.cjs');
13
+ require('./chunk-WJHHO24M.cjs');
14
+ var chunkQT5LGZG3_cjs = require('./chunk-QT5LGZG3.cjs');
15
+ require('./chunk-AWFZKS27.cjs');
16
+ require('./chunk-75ZPJI57.cjs');
468
17
 
469
- // tools/fastapply/apply.ts
470
- var DEFAULT_API_URL = "https://api.morphllm.com";
471
- var DEFAULT_TIMEOUT = 6e5;
472
- var FastApplyContextLengthError = class extends Error {
473
- code = "context_length_exceeded";
474
- completionId;
475
- constructor(completionId) {
476
- super(
477
- "Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
478
- );
479
- this.name = "FastApplyContextLengthError";
480
- this.completionId = completionId;
481
- }
482
- };
483
- function isAsyncIterable(value) {
484
- return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
485
- }
486
- async function collectCompletion(response) {
487
- if (!isAsyncIterable(response)) {
488
- const completion = response;
489
- return {
490
- content: completion.choices?.[0]?.message?.content ?? "",
491
- completionId: completion.id,
492
- finishReason: completion.choices?.[0]?.finish_reason
493
- };
494
- }
495
- const content = [];
496
- let completionId;
497
- let finishReason;
498
- for await (const chunk of response) {
499
- completionId = chunk.id ?? completionId;
500
- for (const choice of chunk.choices ?? []) {
501
- if (choice.delta?.content) {
502
- content.push(choice.delta.content);
503
- }
504
- if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
505
- finishReason = choice.finish_reason;
506
- }
507
- }
508
- }
509
- return { content: content.join(""), completionId, finishReason };
510
- }
511
- function generateUdiff(original, modified, filepath) {
512
- return (0, import_diff.createTwoFilesPatch)(
513
- filepath,
514
- filepath,
515
- original,
516
- modified,
517
- "Original",
518
- "Modified"
519
- );
520
- }
521
- function countChanges(original, modified) {
522
- const diff = generateUdiff(original, modified, "file");
523
- const lines = diff.split("\n");
524
- let linesAdded = 0;
525
- let linesRemoved = 0;
526
- for (const line of lines) {
527
- if (line.startsWith("+") && !line.startsWith("+++")) {
528
- linesAdded++;
529
- } else if (line.startsWith("-") && !line.startsWith("---")) {
530
- linesRemoved++;
531
- }
532
- }
533
- const linesModified = Math.min(linesAdded, linesRemoved);
534
- return {
535
- linesAdded: linesAdded - linesModified,
536
- linesRemoved: linesRemoved - linesModified,
537
- linesModified
538
- };
539
- }
540
- async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
541
- const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
542
- const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
543
- const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
544
- const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
545
- const timeout = config.timeout ?? DEFAULT_TIMEOUT;
546
- const debug = config.debug || false;
547
- if (!apiKey) {
548
- throw new Error(
549
- "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
550
- );
551
- }
552
- const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
553
- const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
554
- const requestCode = anchorPlan?.code ?? originalCode;
555
- const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
556
- const message = `<instruction>${requestInstructions}</instruction>
557
- <code>${requestCode}</code>
558
- <update>${codeEdit}</update>`;
559
- logger.debug("FastApply", "http_request", {
560
- url: `${apiUrl}/v1/chat/completions`,
561
- model,
562
- filepath,
563
- instruction_len: instructions.length,
564
- original_len: originalCode.length,
565
- request_code_len: requestCode.length,
566
- code_edit_len: codeEdit.length,
567
- anchor_count: anchorPlan?.anchorCount ?? 0,
568
- unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
569
- });
570
- const startTime = Date.now();
571
- const client = new import_openai.default({
572
- apiKey,
573
- baseURL: `${apiUrl}/v1`,
574
- timeout,
575
- maxRetries: config.retryConfig?.maxRetries ?? 3,
576
- defaultHeaders: {
577
- "X-Morph-SDK-Version": SDK_VERSION,
578
- ...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
579
- }
580
- });
581
- try {
582
- const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
583
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
584
- const response = await client.chat.completions.create({
585
- model,
586
- messages: [{ role: "user", content: message }],
587
- stream: true
588
- });
589
- const completion = await collectCompletion(response);
590
- if (completion.finishReason === "length") {
591
- throw new FastApplyContextLengthError(completion.completionId);
592
- }
593
- let content = completion.content;
594
- if (!content) {
595
- throw new Error("Morph API returned empty response");
596
- }
597
- if (anchorPlan) {
598
- try {
599
- content = anchorPlan.expand(content);
600
- } catch (error) {
601
- if (error instanceof FastApplyAnchorIntegrityError) {
602
- if (attempt < maxAttempts) {
603
- logger.warn("FastApply", "anchor_validation_retry", {
604
- attempt,
605
- completion_id: completion.completionId
606
- });
607
- continue;
608
- }
609
- throw new FastApplyAnchorIntegrityError(completion.completionId);
610
- }
611
- throw error;
612
- }
613
- }
614
- const elapsed = Date.now() - startTime;
615
- logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
616
- return { content, completionId: completion.completionId };
617
- }
618
- throw new FastApplyAnchorIntegrityError();
619
- } catch (error) {
620
- const elapsed = Date.now() - startTime;
621
- const status = error?.status || error?.response?.status;
622
- logger.error("FastApply", "http_error", {
623
- status,
624
- error: error?.message,
625
- latency_ms: elapsed
626
- });
627
- if (status === 401) {
628
- const err = new Error(
629
- "Authentication failed: Your Morph API key is invalid or has been revoked. Please visit https://morphllm.com to get a valid API key, then update your MCP configuration."
630
- );
631
- err.status = 401;
632
- throw err;
633
- }
634
- if (status === 429) {
635
- const err = new Error(
636
- "Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
637
- );
638
- err.status = 429;
639
- throw err;
640
- }
641
- throw error;
642
- }
643
- }
644
- async function applyEdit(input, config = {}) {
645
- const filepath = input.filepath || "file";
646
- try {
647
- logger.debug("FastApply", "apply_edit_start", { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });
648
- const instruction = input.instruction ?? input.instructions ?? "";
649
- const { content: mergedCode, completionId } = await callMorphAPI(
650
- input.originalCode,
651
- input.codeEdit,
652
- instruction,
653
- filepath,
654
- config
655
- );
656
- const udiff = config.generateUdiff !== false ? generateUdiff(input.originalCode, mergedCode, filepath) : void 0;
657
- const changes = countChanges(input.originalCode, mergedCode);
658
- return {
659
- success: true,
660
- mergedCode,
661
- udiff,
662
- changes,
663
- completionId
664
- };
665
- } catch (error) {
666
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
667
- logger.error("FastApply", "apply_edit_error", { error: errorMessage });
668
- const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
669
- return {
670
- success: false,
671
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
672
- error: errorMessage,
673
- errorCode: structuredError?.code,
674
- completionId: structuredError?.completionId
675
- };
676
- }
677
- }
678
18
 
679
- // tools/utils/resilience.ts
680
- var DEFAULT_RETRY_CONFIG = {
681
- maxRetries: 3,
682
- initialDelay: 1e3,
683
- maxDelay: 3e4,
684
- backoffMultiplier: 2,
685
- retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
686
- };
687
- async function fetchWithRetry(url, options, retryConfig = {}) {
688
- const {
689
- maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
690
- initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
691
- maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
692
- backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
693
- retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
694
- onRetry
695
- } = retryConfig;
696
- let lastError = null;
697
- let delay = initialDelay;
698
- options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
699
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
700
- try {
701
- const response = await fetch(url, options);
702
- if (response.status === 429 || response.status === 503) {
703
- if (attempt < maxRetries) {
704
- const retryAfter = response.headers.get("Retry-After");
705
- const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
706
- const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
707
- if (onRetry) {
708
- onRetry(attempt + 1, error);
709
- }
710
- await sleep(waitTime);
711
- delay *= backoffMultiplier;
712
- continue;
713
- }
714
- }
715
- return response;
716
- } catch (error) {
717
- lastError = error;
718
- const isRetryable = retryableErrors.some(
719
- (errType) => lastError?.message?.includes(errType)
720
- );
721
- if (!isRetryable || attempt === maxRetries) {
722
- throw lastError;
723
- }
724
- const waitTime = Math.min(delay, maxDelay);
725
- if (onRetry) {
726
- onRetry(attempt + 1, lastError);
727
- }
728
- await sleep(waitTime);
729
- delay *= backoffMultiplier;
730
- }
731
- }
732
- throw lastError || new Error("Max retries exceeded");
733
- }
734
- async function withTimeout(promise, timeoutMs, errorMessage) {
735
- let timeoutId;
736
- const timeoutPromise = new Promise((_, reject) => {
737
- timeoutId = setTimeout(() => {
738
- reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
739
- }, timeoutMs);
740
- });
741
- try {
742
- const result = await Promise.race([promise, timeoutPromise]);
743
- clearTimeout(timeoutId);
744
- return result;
745
- } catch (error) {
746
- clearTimeout(timeoutId);
747
- throw error;
748
- }
749
- }
750
- function sleep(ms) {
751
- return new Promise((resolve) => setTimeout(resolve, ms));
752
- }
753
- var MorphError = class extends Error {
754
- constructor(message, code, statusCode, retryable = false) {
755
- super(message);
756
- this.code = code;
757
- this.statusCode = statusCode;
758
- this.retryable = retryable;
759
- this.name = "MorphError";
760
- }
761
- };
762
19
 
763
- // core/error.ts
764
- async function toMorphError(response) {
765
- let message = `Morph API request failed (${response.status})`;
766
- let code = "api_error";
767
- try {
768
- const body = await response.json();
769
- message = body.error?.message ?? body.message ?? message;
770
- code = body.error?.code ?? body.error?.type ?? code;
771
- } catch {
772
- }
773
- if (response.status === 401) code = "authentication_error";
774
- if (response.status === 429) code = "rate_limit_exceeded";
775
- const retryable = response.status === 429 || response.status === 503;
776
- return new MorphError(message, code, response.status, retryable);
777
- }
778
-
779
- // core/client.ts
780
- var DEFAULT_BASE_URL = "https://api.morphllm.com";
781
- var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
782
- var DEFAULT_TIMEOUT2 = 6e4;
783
- var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
784
- var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
785
- var MorphAPIClient = class {
786
- /** Explicit key as provided; resolved against env at request time. */
787
- apiKey;
788
- baseURL;
789
- reposURL;
790
- /** Explicit default timeout (ms), if set. The request default is applied lazily so
791
- * resources can read an undefined value and supply their own fallback. */
792
- timeout;
793
- retryConfig;
794
- debug;
795
- constructor(options = {}) {
796
- this.apiKey = options.apiKey;
797
- this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
798
- this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
799
- this.timeout = options.timeout;
800
- this.retryConfig = options.retryConfig;
801
- this.debug = options.debug ?? false;
802
- if (this.debug) logger.enable();
803
- }
804
- /** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
805
- resolveApiKey() {
806
- return this.apiKey ?? env("MORPH_API_KEY");
807
- }
808
- /** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
809
- defaultHeaders() {
810
- return { "X-Morph-SDK-Version": SDK_VERSION };
811
- }
812
- buildURL(path, baseURL) {
813
- if (/^https?:\/\//i.test(path)) return path;
814
- const base = stripTrailingSlash(baseURL ?? this.baseURL);
815
- return `${base}${path.startsWith("/") ? "" : "/"}${path}`;
816
- }
817
- buildHeaders(apiKey, extra) {
818
- return {
819
- "Content-Type": "application/json",
820
- "X-Morph-SDK-Version": SDK_VERSION,
821
- Authorization: `Bearer ${apiKey}`,
822
- ...extra
823
- };
824
- }
825
- applyQuery(url, query) {
826
- if (!query) return url;
827
- const params = new URLSearchParams();
828
- for (const [key, value] of Object.entries(query)) {
829
- if (value !== void 0 && value !== null) params.set(key, String(value));
830
- }
831
- const qs = params.toString();
832
- return qs ? `${url}${url.includes("?") ? "&" : "?"}${qs}` : url;
833
- }
834
- async request(method, path, opts = {}) {
835
- const apiKey = this.resolveApiKey();
836
- if (!apiKey) {
837
- throw new MorphError(
838
- "Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
839
- "missing_api_key",
840
- 401
841
- );
842
- }
843
- const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);
844
- const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT2;
845
- const init = {
846
- method,
847
- headers: this.buildHeaders(apiKey, opts.headers),
848
- ...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
849
- ...opts.signal ? { signal: opts.signal } : {}
850
- };
851
- logger.debug("MorphAPIClient", "request", { method, url });
852
- const response = await withTimeout(
853
- fetchWithRetry(url, init, this.retryConfig ?? {}),
854
- timeout,
855
- `Morph request to ${url} timed out after ${timeout}ms`
856
- );
857
- if (!response.ok) throw await toMorphError(response);
858
- if (opts.stream) return response;
859
- if (response.status === 204) return void 0;
860
- const text = await response.text();
861
- return text ? JSON.parse(text) : void 0;
862
- }
863
- get(path, opts) {
864
- return this.request("GET", path, opts);
865
- }
866
- post(path, opts) {
867
- return this.request("POST", path, opts);
868
- }
869
- delete(path, opts) {
870
- return this.request("DELETE", path, opts);
871
- }
872
- };
873
-
874
- // core/resource.ts
875
- var APIResource = class {
876
- _client;
877
- constructor(client) {
878
- this._client = client;
879
- }
880
- };
881
-
882
- // modelrouter/core.ts
883
- var DEFAULT_API_URL2 = "https://api.morphllm.com";
884
- var DEFAULT_TIMEOUT3 = 5e3;
885
- function resolveClient(clientOrConfig) {
886
- if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
887
- return new MorphAPIClient({
888
- apiKey: clientOrConfig.apiKey,
889
- baseURL: clientOrConfig.apiUrl ?? DEFAULT_API_URL2,
890
- timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT3,
891
- retryConfig: clientOrConfig.retryConfig,
892
- debug: clientOrConfig.debug
893
- });
894
- }
895
- var BaseRouter = class extends APIResource {
896
- provider;
897
- timeout;
898
- constructor(provider, clientOrConfig = {}) {
899
- super(resolveClient(clientOrConfig));
900
- this.provider = provider;
901
- const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
902
- this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT3;
903
- }
904
- /** Throw the historical "API key is required" message when no key is resolvable. */
905
- requireApiKey() {
906
- if (!this._client.resolveApiKey()) {
907
- throw new Error(
908
- "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
909
- );
910
- }
911
- }
912
- /** POST to the router and surface failures as `Router API error (<status>): ...`. */
913
- async route(provider, input) {
914
- try {
915
- return await this._client.post(`/v1/router/${provider}`, {
916
- body: { input: input.input, mode: input.mode || "balanced" },
917
- timeout: this.timeout
918
- });
919
- } catch (error) {
920
- if (error instanceof MorphError) {
921
- throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
922
- }
923
- throw error;
924
- }
925
- }
926
- /**
927
- * Select the optimal model for a given input and mode
928
- */
929
- async selectModel(input) {
930
- this.requireApiKey();
931
- logger.debug("ModelRouter", "request", { provider: this.provider, mode: input.mode || "balanced" });
932
- const apiResult = await this.route(this.provider, input);
933
- logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model });
934
- return { model: apiResult.model };
935
- }
936
- };
937
- var OpenAIRouter = class extends BaseRouter {
938
- constructor(clientOrConfig = {}) {
939
- super("openai", clientOrConfig);
940
- }
941
- /**
942
- * Select optimal GPT-5 model
943
- *
944
- * @param input - User input and mode
945
- * @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
946
- */
947
- async selectModel(input) {
948
- return super.selectModel(input);
949
- }
950
- };
951
- var AnthropicRouter = class extends BaseRouter {
952
- constructor(clientOrConfig = {}) {
953
- super("anthropic", clientOrConfig);
954
- }
955
- /**
956
- * Select optimal Claude model
957
- *
958
- * @param input - User input and mode
959
- * @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
960
- */
961
- async selectModel(input) {
962
- return super.selectModel(input);
963
- }
964
- };
965
- var GeminiRouter = class extends BaseRouter {
966
- constructor(clientOrConfig = {}) {
967
- super("gemini", clientOrConfig);
968
- }
969
- /**
970
- * Select optimal Gemini model
971
- *
972
- * @param input - User input and mode
973
- * @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
974
- */
975
- async selectModel(input) {
976
- return super.selectModel(input);
977
- }
978
- };
979
- var RawRouter = class extends BaseRouter {
980
- constructor(clientOrConfig = {}) {
981
- super("raw", clientOrConfig);
982
- }
983
- /**
984
- * Get raw difficulty classification
985
- *
986
- * @param input - User input and mode
987
- * @returns Raw difficulty (easy | medium | hard | needs_info)
988
- */
989
- async classify(input) {
990
- this.requireApiKey();
991
- logger.debug("RawRouter", "request", { mode: input.mode || "balanced" });
992
- const apiResult = await this.route("raw", input);
993
- let difficulty;
994
- if (apiResult.difficulty === "") {
995
- difficulty = "medium";
996
- } else {
997
- difficulty = apiResult.difficulty || apiResult.model;
998
- }
999
- logger.debug("RawRouter", "classified", { difficulty });
1000
- return { difficulty };
1001
- }
1002
- };
1003
- var RouterClassifier = class extends APIResource {
1004
- timeout;
1005
- constructor(clientOrConfig = {}) {
1006
- super(resolveClient(clientOrConfig));
1007
- const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
1008
- this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT3;
1009
- }
1010
- /** Classify an input across the requested axes (all three by default). */
1011
- async classify(input) {
1012
- if (!this._client.resolveApiKey()) {
1013
- throw new Error(
1014
- "Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
1015
- );
1016
- }
1017
- logger.debug("RouterClassifier", "request", { classes: input.classes ?? "all" });
1018
- try {
1019
- const res = await this._client.post("/v1/router/classify", {
1020
- body: { input: input.input, ...input.classes ? { classes: input.classes } : {} },
1021
- timeout: this.timeout
1022
- });
1023
- logger.debug("RouterClassifier", "classified", {
1024
- difficulty: res.classifications.difficulty?.label,
1025
- ambiguity: res.classifications.ambiguity?.label,
1026
- domain: res.classifications.domain?.label
1027
- });
1028
- return res.classifications;
1029
- } catch (error) {
1030
- if (error instanceof MorphError) {
1031
- throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
1032
- }
1033
- throw error;
1034
- }
1035
- }
1036
- };
1037
-
1038
- // tools/compact/core.ts
1039
- var DEFAULT_API_URL3 = "https://api.morphllm.com";
1040
- var DEFAULT_TIMEOUT4 = 12e4;
1041
- function resolveClient2(clientOrConfig) {
1042
- if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
1043
- return new MorphAPIClient({
1044
- apiKey: clientOrConfig.morphApiKey,
1045
- baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL3,
1046
- timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT4,
1047
- retryConfig: clientOrConfig.retryConfig,
1048
- debug: clientOrConfig.debug
1049
- });
1050
- }
1051
- var CompactClient = class extends APIResource {
1052
- /** Resolved URL/timeout, exposed for backwards-compatible introspection. */
1053
- config;
1054
- constructor(clientOrConfig = {}) {
1055
- super(resolveClient2(clientOrConfig));
1056
- const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
1057
- this.config = {
1058
- morphApiUrl: this._client.baseURL,
1059
- timeout: cfg.timeout ?? DEFAULT_TIMEOUT4,
1060
- debug: cfg.debug ?? false
1061
- };
1062
- }
1063
- /**
1064
- * Compact messages or text via /v1/compact.
1065
- * Returns per-message `compacted_line_ranges` showing which lines were removed.
1066
- *
1067
- * @example
1068
- * ```typescript
1069
- * const client = new CompactClient({ morphApiKey: 'sk-...' });
1070
- * const result = await client.compact({
1071
- * input: codeFile,
1072
- * query: "authentication",
1073
- * compressionRatio: 0.5,
1074
- * });
1075
- * console.log(result.output);
1076
- * ```
1077
- */
1078
- async compact(input) {
1079
- const body = {
1080
- compression_ratio: input.compressionRatio ?? 0.5,
1081
- preserve_recent: input.preserveRecent ?? 2,
1082
- model: input.model ?? "morph-compactor",
1083
- include_line_ranges: input.includeLineRanges ?? true,
1084
- include_markers: input.includeMarkers ?? true
1085
- };
1086
- if (input.query !== void 0) body.query = input.query;
1087
- if (input.messages) body.messages = input.messages;
1088
- else if (typeof input.input === "string") body.input = input.input;
1089
- else if (Array.isArray(input.input)) body.messages = input.input;
1090
- else throw new Error("Either 'input' or 'messages' must be provided");
1091
- try {
1092
- return await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
1093
- } catch (err) {
1094
- if (err instanceof MorphError) {
1095
- throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
1096
- }
1097
- throw err;
1098
- }
1099
- }
1100
- };
1101
- // Annotate the CommonJS export names for ESM import in node:
1102
- 0 && (module.exports = {
1103
- AnthropicRouter,
1104
- CompactClient,
1105
- FastApplyAnchorIntegrityError,
1106
- FastApplyContextLengthError,
1107
- GeminiRouter,
1108
- OpenAIRouter,
1109
- RawRouter,
1110
- RouterClassifier,
1111
- SDK_VERSION,
1112
- applyEdit,
1113
- callMorphAPI,
1114
- countChanges,
1115
- generateUdiff
20
+ Object.defineProperty(exports, "AnthropicRouter", {
21
+ enumerable: true,
22
+ get: function () { return chunkWIYVT4UO_cjs.AnthropicRouter; }
23
+ });
24
+ Object.defineProperty(exports, "GeminiRouter", {
25
+ enumerable: true,
26
+ get: function () { return chunkWIYVT4UO_cjs.GeminiRouter; }
27
+ });
28
+ Object.defineProperty(exports, "OpenAIRouter", {
29
+ enumerable: true,
30
+ get: function () { return chunkWIYVT4UO_cjs.OpenAIRouter; }
31
+ });
32
+ Object.defineProperty(exports, "RawRouter", {
33
+ enumerable: true,
34
+ get: function () { return chunkWIYVT4UO_cjs.RawRouter; }
35
+ });
36
+ Object.defineProperty(exports, "RouterClassifier", {
37
+ enumerable: true,
38
+ get: function () { return chunkWIYVT4UO_cjs.RouterClassifier; }
39
+ });
40
+ Object.defineProperty(exports, "FastApplyAnchorIntegrityError", {
41
+ enumerable: true,
42
+ get: function () { return chunkUHFVWYSP_cjs.FastApplyAnchorIntegrityError; }
43
+ });
44
+ Object.defineProperty(exports, "FastApplyContextLengthError", {
45
+ enumerable: true,
46
+ get: function () { return chunkUHFVWYSP_cjs.FastApplyContextLengthError; }
47
+ });
48
+ Object.defineProperty(exports, "applyEdit", {
49
+ enumerable: true,
50
+ get: function () { return chunkUHFVWYSP_cjs.applyEdit; }
51
+ });
52
+ Object.defineProperty(exports, "callMorphAPI", {
53
+ enumerable: true,
54
+ get: function () { return chunkUHFVWYSP_cjs.callMorphAPI; }
55
+ });
56
+ Object.defineProperty(exports, "countChanges", {
57
+ enumerable: true,
58
+ get: function () { return chunkUHFVWYSP_cjs.countChanges; }
59
+ });
60
+ Object.defineProperty(exports, "generateUdiff", {
61
+ enumerable: true,
62
+ get: function () { return chunkUHFVWYSP_cjs.generateUdiff; }
63
+ });
64
+ Object.defineProperty(exports, "CompactClient", {
65
+ enumerable: true,
66
+ get: function () { return chunkF633IVQA_cjs.CompactClient; }
67
+ });
68
+ Object.defineProperty(exports, "detectPII", {
69
+ enumerable: true,
70
+ get: function () { return chunkR3TUE7O2_cjs.detectPII; }
71
+ });
72
+ Object.defineProperty(exports, "redactPII", {
73
+ enumerable: true,
74
+ get: function () { return chunkR3TUE7O2_cjs.redactPII; }
75
+ });
76
+ Object.defineProperty(exports, "SDK_VERSION", {
77
+ enumerable: true,
78
+ get: function () { return chunkQT5LGZG3_cjs.SDK_VERSION; }
1116
79
  });