@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
@@ -1,1063 +1,67 @@
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 __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // logger.ts
34
- var MorphLogger, logger;
35
- var init_logger = __esm({
36
- "logger.ts"() {
37
- "use strict";
38
- MorphLogger = class {
39
- enabled;
40
- fileStream;
41
- /** Resolves once the file stream is initialized (or immediately if no file logging). */
42
- ready;
43
- constructor() {
44
- this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
45
- this.fileStream = null;
46
- const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
47
- if (f) {
48
- this.ready = import("fs").then((fs) => {
49
- this.fileStream = fs.createWriteStream(f, { flags: "a" });
50
- }).catch(() => {
51
- });
52
- } else {
53
- this.ready = Promise.resolve();
54
- }
55
- }
56
- debug(component, msg, data) {
57
- this._log("debug", component, msg, data);
58
- }
59
- info(component, msg, data) {
60
- this._log("info", component, msg, data);
61
- }
62
- warn(component, msg, data) {
63
- this._log("warn", component, msg, data);
64
- }
65
- error(component, msg, data) {
66
- this._log("error", component, msg, data);
67
- }
68
- enable() {
69
- this.enabled = true;
70
- }
71
- get isEnabled() {
72
- return this.enabled;
73
- }
74
- _log(level, component, msg, data) {
75
- if (level !== "error" && !this.enabled) return;
76
- const ts = (/* @__PURE__ */ new Date()).toISOString();
77
- const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
78
- console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
79
- this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
80
- }
81
- };
82
- logger = new MorphLogger();
83
- }
84
- });
85
-
86
- // package.json
87
- var package_default;
88
- var init_package = __esm({
89
- "package.json"() {
90
- package_default = {
91
- name: "@morphllm/morphsdk",
92
- version: "0.2.202",
93
- description: "TypeScript SDK and CLI for Morph Fast Apply integration",
94
- type: "module",
95
- main: "./dist/index.cjs",
96
- module: "./dist/index.js",
97
- types: "./dist/index.d.ts",
98
- exports: {
99
- ".": {
100
- types: "./dist/index.d.ts",
101
- import: "./dist/index.js",
102
- require: "./dist/index.cjs"
103
- },
104
- "./logger": {
105
- types: "./dist/logger.d.ts",
106
- import: "./dist/logger.js",
107
- require: "./dist/logger.cjs"
108
- },
109
- "./edge": {
110
- types: "./dist/edge.d.ts",
111
- import: "./dist/edge.js",
112
- require: "./dist/edge.cjs"
113
- },
114
- "./tools/warp-grep": {
115
- types: "./dist/tools/warp_grep/index.d.ts",
116
- import: "./dist/tools/warp_grep/index.js",
117
- require: "./dist/tools/warp_grep/index.cjs"
118
- },
119
- "./tools/warp-grep/openai": {
120
- types: "./dist/tools/warp_grep/openai.d.ts",
121
- import: "./dist/tools/warp_grep/openai.js",
122
- require: "./dist/tools/warp_grep/openai.cjs"
123
- },
124
- "./tools/warp-grep/anthropic": {
125
- types: "./dist/tools/warp_grep/anthropic.d.ts",
126
- import: "./dist/tools/warp_grep/anthropic.js",
127
- require: "./dist/tools/warp_grep/anthropic.cjs"
128
- },
129
- "./tools/warp-grep/vercel": {
130
- types: "./dist/tools/warp_grep/vercel.d.ts",
131
- import: "./dist/tools/warp_grep/vercel.js",
132
- require: "./dist/tools/warp_grep/vercel.cjs"
133
- },
134
- "./tools/warp-grep/client": {
135
- types: "./dist/tools/warp_grep/client.d.ts",
136
- import: "./dist/tools/warp_grep/client.js",
137
- require: "./dist/tools/warp_grep/client.cjs"
138
- },
139
- "./tools/warp-grep/gemini": {
140
- types: "./dist/tools/warp_grep/gemini.d.ts",
141
- import: "./dist/tools/warp_grep/gemini.js",
142
- require: "./dist/tools/warp_grep/gemini.cjs"
143
- },
144
- "./tools/warp-grep/harness": {
145
- types: "./dist/tools/warp_grep/harness.d.ts",
146
- import: "./dist/tools/warp_grep/harness.js",
147
- require: "./dist/tools/warp_grep/harness.cjs"
148
- },
149
- "./tools/fastapply": {
150
- types: "./dist/tools/fastapply/index.d.ts",
151
- import: "./dist/tools/fastapply/index.js",
152
- require: "./dist/tools/fastapply/index.cjs"
153
- },
154
- "./tools/fastapply/anthropic": {
155
- types: "./dist/tools/fastapply/anthropic.d.ts",
156
- import: "./dist/tools/fastapply/anthropic.js",
157
- require: "./dist/tools/fastapply/anthropic.cjs"
158
- },
159
- "./tools/fastapply/openai": {
160
- types: "./dist/tools/fastapply/openai.d.ts",
161
- import: "./dist/tools/fastapply/openai.js",
162
- require: "./dist/tools/fastapply/openai.cjs"
163
- },
164
- "./tools/fastapply/vercel": {
165
- types: "./dist/tools/fastapply/vercel.d.ts",
166
- import: "./dist/tools/fastapply/vercel.js",
167
- require: "./dist/tools/fastapply/vercel.cjs"
168
- },
169
- "./modelrouter": {
170
- types: "./dist/modelrouter/index.d.ts",
171
- import: "./dist/modelrouter/index.js",
172
- require: "./dist/modelrouter/index.cjs"
173
- },
174
- "./tools/compact": {
175
- types: "./dist/tools/compact/index.d.ts",
176
- import: "./dist/tools/compact/index.js",
177
- require: "./dist/tools/compact/index.cjs"
178
- },
179
- "./subagents": {
180
- types: "./dist/subagents/index.d.ts",
181
- import: "./dist/subagents/index.js",
182
- require: "./dist/subagents/index.cjs"
183
- },
184
- "./subagents/vercel": {
185
- types: "./dist/subagents/vercel.d.ts",
186
- import: "./dist/subagents/vercel.js",
187
- require: "./dist/subagents/vercel.cjs"
188
- },
189
- "./subagents/anthropic": {
190
- types: "./dist/subagents/anthropic.d.ts",
191
- import: "./dist/subagents/anthropic.js",
192
- require: "./dist/subagents/anthropic.cjs"
193
- },
194
- "./ai-sdk": {
195
- types: "./dist/ai-sdk/index.d.ts",
196
- import: "./dist/ai-sdk/index.js",
197
- require: "./dist/ai-sdk/index.cjs"
198
- }
199
- },
200
- files: [
201
- "dist/**/*.js",
202
- "dist/**/*.cjs",
203
- "dist/**/*.d.ts",
204
- "!dist/**/__tests__/**",
205
- "!dist/**/*.test.*"
206
- ],
207
- scripts: {
208
- 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",
209
- prepare: "npm run build",
210
- typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
211
- lint: "eslint .",
212
- test: "vitest run",
213
- "test:watch": "vitest watch",
214
- "test:anthropic": "vitest run anthropic",
215
- "test:openai": "vitest run openai",
216
- "test:vercel": "vitest run vercel",
217
- "test:git": "vitest run git",
218
- "test:agent": "npx tsx tests/fullAgentTest.ts",
219
- "test:integration": "npx tsx tests/fullIntegrationTest.ts",
220
- "test:e2e": "vitest run --config vitest.e2e.config.ts",
221
- "release:patch": "npm version patch && npm publish",
222
- "release:minor": "npm version minor && npm publish",
223
- "release:major": "npm version major && npm publish"
224
- },
225
- keywords: [
226
- "morph",
227
- "fast-apply",
228
- "cli",
229
- "sdk",
230
- "edit-file"
231
- ],
232
- engines: {
233
- node: ">=18"
234
- },
235
- license: "MIT",
236
- dependencies: {
237
- "@vscode/ripgrep": "^1.17.0",
238
- ai: ">=5.0.0",
239
- diff: "^7.0.0",
240
- openai: "^4.52.7",
241
- zod: ">=3.23.0"
242
- },
243
- devDependencies: {
244
- "@ai-sdk/anthropic": "^2.0.70",
245
- "@ai-sdk/openai": "^2.0.35",
246
- "@anthropic-ai/sdk": "^0.30.1",
247
- "@google/generative-ai": "^0.24.1",
248
- "@types/diff": "^7.0.2",
249
- "@types/node": "^20.14.10",
250
- "@typescript-eslint/eslint-plugin": "^7.18.0",
251
- "@typescript-eslint/parser": "^7.18.0",
252
- dotenv: "^16.4.5",
253
- eslint: "^8.57.0",
254
- shx: "^0.3.4",
255
- tsup: "^8.5.0",
256
- tsx: "^4.16.2",
257
- typescript: "^5.5.4",
258
- vitest: "^2.1.6"
259
- },
260
- peerDependencies: {
261
- "@ai-sdk/openai-compatible": ">=2.0.74 <4",
262
- "@anthropic-ai/sdk": ">=0.25.0",
263
- "@google/generative-ai": ">=0.21.0",
264
- ai: ">=5.0.0",
265
- zod: ">=3.23.0"
266
- },
267
- peerDependenciesMeta: {
268
- "@anthropic-ai/sdk": {
269
- optional: true
270
- },
271
- "@google/generative-ai": {
272
- optional: true
273
- },
274
- ai: {
275
- optional: true
276
- },
277
- zod: {
278
- optional: true
279
- }
280
- },
281
- publishConfig: {
282
- access: "public"
283
- }
284
- };
285
- }
1
+ 'use strict';
2
+
3
+ require('../../chunk-BJBWWIZV.cjs');
4
+ var chunkHNMEBYIS_cjs = require('../../chunk-HNMEBYIS.cjs');
5
+ var chunkHP3PCOTW_cjs = require('../../chunk-HP3PCOTW.cjs');
6
+ var chunk3HAHJYZQ_cjs = require('../../chunk-3HAHJYZQ.cjs');
7
+ var chunk74A4HLIO_cjs = require('../../chunk-74A4HLIO.cjs');
8
+ var chunkNJWOWXUR_cjs = require('../../chunk-NJWOWXUR.cjs');
9
+ var chunkUHFVWYSP_cjs = require('../../chunk-UHFVWYSP.cjs');
10
+ require('../../chunk-5TTZQF4X.cjs');
11
+ require('../../chunk-VL4QNALG.cjs');
12
+ require('../../chunk-KF6S3EPJ.cjs');
13
+ require('../../chunk-6HAYJA6M.cjs');
14
+ require('../../chunk-R3TUE7O2.cjs');
15
+ require('../../chunk-DLYDIYDK.cjs');
16
+ require('../../chunk-YAUXTFIN.cjs');
17
+ require('../../chunk-WJHHO24M.cjs');
18
+ require('../../chunk-QT5LGZG3.cjs');
19
+ require('../../chunk-AWFZKS27.cjs');
20
+ require('../../chunk-75ZPJI57.cjs');
21
+
22
+
23
+
24
+ Object.defineProperty(exports, "openai", {
25
+ enumerable: true,
26
+ get: function () { return chunkHNMEBYIS_cjs.openai_exports; }
286
27
  });
287
-
288
- // version.ts
289
- var SDK_VERSION;
290
- var init_version = __esm({
291
- "version.ts"() {
292
- "use strict";
293
- init_package();
294
- SDK_VERSION = package_default.version;
295
- }
296
- });
297
-
298
- // tools/fastapply/anchors.ts
299
- function escapeRegExp(value) {
300
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
301
- }
302
- function findNamespace(values) {
303
- for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
304
- const prefix = `\u27EAM${namespace}:`;
305
- if (values.every((value) => !value.includes(prefix))) {
306
- return namespace;
307
- }
308
- }
309
- throw new Error("Unable to allocate a Fast Apply anchor namespace");
310
- }
311
- function htmlLabel(token) {
312
- if (!token.startsWith("<")) return "text";
313
- const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
314
- return (match?.[1] ?? "tag").toLowerCase();
315
- }
316
- function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
317
- return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
318
- value: token,
319
- label: htmlLabel(token),
320
- anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
321
- }));
322
- }
323
- function sourceUnits(originalCode, editContext) {
324
- const trimmed = originalCode.trimStart().toLowerCase();
325
- const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
326
- if (looksLikeHtml) {
327
- const contextWords = new Set(
328
- editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
329
- );
330
- return htmlTokenUnits(originalCode, contextWords);
331
- }
332
- const parts = originalCode.split(/(\r\n|\n|\r)/);
333
- const units = [];
334
- for (let index = 0; index < parts.length; index += 2) {
335
- const line = parts[index] ?? "";
336
- const lineEnding = parts[index + 1] ?? "";
337
- units.push({
338
- value: line,
339
- label: "line",
340
- anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
341
- });
342
- if (lineEnding) {
343
- units.push({ value: lineEnding, anchorable: false });
344
- }
345
- }
346
- return units;
347
- }
348
- function copyCount(value) {
349
- const words = {
350
- one: 1,
351
- two: 2,
352
- three: 3,
353
- four: 4,
354
- five: 5,
355
- six: 6,
356
- seven: 7,
357
- eight: 8,
358
- nine: 9,
359
- ten: 10
360
- };
361
- return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
362
- }
363
- function structuralExpectation(originalCode, editContext) {
364
- const context = editContext.join(" ");
365
- const match = context.match(
366
- /(?: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
367
- );
368
- if (!match) return void 0;
369
- const tag = match[1].toLowerCase();
370
- const addedCopies = copyCount(match[2]);
371
- if (addedCopies === void 0) return void 0;
372
- const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
373
- const originalCount = originalCode.match(tagPattern)?.length ?? 0;
374
- if (originalCount === 0) return void 0;
375
- return { tag, expectedCount: originalCount * (addedCopies + 1) };
376
- }
377
- function createAnchorCompactionPlan(originalCode, collisionValues = []) {
378
- const namespace = findNamespace([originalCode, ...collisionValues]);
379
- const expectation = structuralExpectation(originalCode, collisionValues);
380
- const markerPrefix = `\u27EAM${namespace}:`;
381
- const definitions = /* @__PURE__ */ new Map();
382
- const values = [];
383
- const markers = [];
384
- let anchorCount = 0;
385
- let skeleton = "";
386
- for (const unit of sourceUnits(originalCode, collisionValues)) {
387
- if (!unit.anchorable) {
388
- skeleton += unit.value;
389
- continue;
390
- }
391
- let id = definitions.get(unit.value);
392
- if (id === void 0) {
393
- id = values.length;
394
- definitions.set(unit.value, id);
395
- values.push(unit.value);
396
- markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
397
- }
398
- skeleton += markers[id];
399
- anchorCount++;
400
- }
401
- if (anchorCount === 0 || skeleton.length >= originalCode.length) {
402
- return void 0;
403
- }
404
- const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
405
- const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
406
- const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
407
- const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
408
- const code = [
409
- definitionsBegin,
410
- serializedDefinitions,
411
- definitionsEnd,
412
- codeBegin,
413
- skeleton
414
- ].join("\n");
415
- const instructionSuffix = `
416
-
417
- LARGE-FILE ANCHOR PROTOCOL:
418
- The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
419
- 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.
420
- Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
421
- Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
422
- To modify an anchored fragment, output the modified source instead of its placeholder.
423
- Do not invent or alter placeholder IDs.`;
424
- const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
425
- return {
426
- code,
427
- instructionSuffix,
428
- anchorCount,
429
- uniqueAnchorCount: values.length,
430
- hasStructuralValidation: expectation !== void 0,
431
- expand(content) {
432
- const codeBeginIndex = content.lastIndexOf(codeBegin);
433
- const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
434
- const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
435
- const id = Number(idText);
436
- const value = values[id];
437
- return value === void 0 || markers[id] !== marker ? marker : value;
438
- });
439
- if (expanded.includes(markerPrefix)) {
440
- throw new FastApplyAnchorIntegrityError();
441
- }
442
- if (expectation) {
443
- const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
444
- const actualCount = expanded.match(tagPattern)?.length ?? 0;
445
- if (actualCount !== expectation.expectedCount) {
446
- throw new FastApplyAnchorIntegrityError();
447
- }
448
- }
449
- return expanded;
450
- }
451
- };
452
- }
453
- var DEFAULT_MIN_ANCHOR_LINE_LENGTH, DEFAULT_ANCHOR_COMPACTION_THRESHOLD, FastApplyAnchorIntegrityError;
454
- var init_anchors = __esm({
455
- "tools/fastapply/anchors.ts"() {
456
- "use strict";
457
- DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
458
- DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
459
- FastApplyAnchorIntegrityError = class extends Error {
460
- code = "anchor_integrity_failed";
461
- completionId;
462
- constructor(completionId) {
463
- super(
464
- "Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
465
- );
466
- this.name = "FastApplyAnchorIntegrityError";
467
- this.completionId = completionId;
468
- }
469
- };
470
- }
28
+ Object.defineProperty(exports, "vercel", {
29
+ enumerable: true,
30
+ get: function () { return chunkHP3PCOTW_cjs.vercel_exports; }
471
31
  });
472
-
473
- // tools/fastapply/apply.ts
474
- var apply_exports = {};
475
- __export(apply_exports, {
476
- FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
477
- FastApplyContextLengthError: () => FastApplyContextLengthError,
478
- applyEdit: () => applyEdit,
479
- callMorphAPI: () => callMorphAPI,
480
- countChanges: () => countChanges,
481
- generateUdiff: () => generateUdiff
32
+ Object.defineProperty(exports, "anthropic", {
33
+ enumerable: true,
34
+ get: function () { return chunk3HAHJYZQ_cjs.anthropic_exports; }
482
35
  });
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
- var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT, FastApplyContextLengthError;
679
- var init_apply = __esm({
680
- "tools/fastapply/apply.ts"() {
681
- "use strict";
682
- import_diff = require("diff");
683
- import_openai = __toESM(require("openai"), 1);
684
- init_version();
685
- init_logger();
686
- init_anchors();
687
- init_anchors();
688
- DEFAULT_API_URL = "https://api.morphllm.com";
689
- DEFAULT_TIMEOUT = 6e5;
690
- FastApplyContextLengthError = class extends Error {
691
- code = "context_length_exceeded";
692
- completionId;
693
- constructor(completionId) {
694
- super(
695
- "Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
696
- );
697
- this.name = "FastApplyContextLengthError";
698
- this.completionId = completionId;
699
- }
700
- };
701
- }
36
+ Object.defineProperty(exports, "EDIT_FILE_SYSTEM_PROMPT", {
37
+ enumerable: true,
38
+ get: function () { return chunk74A4HLIO_cjs.EDIT_FILE_SYSTEM_PROMPT; }
702
39
  });
703
-
704
- // tools/fastapply/index.ts
705
- var fastapply_exports = {};
706
- __export(fastapply_exports, {
707
- EDIT_FILE_SYSTEM_PROMPT: () => EDIT_FILE_SYSTEM_PROMPT,
708
- EDIT_FILE_TOOL_DESCRIPTION: () => EDIT_FILE_TOOL_DESCRIPTION,
709
- FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
710
- FastApplyContextLengthError: () => FastApplyContextLengthError,
711
- anthropic: () => anthropic_exports,
712
- applyEdit: () => applyEdit,
713
- countChanges: () => countChanges,
714
- executeEditFile: () => executeEditFile,
715
- generateUdiff: () => generateUdiff,
716
- openai: () => openai_exports,
717
- vercel: () => vercel_exports
40
+ Object.defineProperty(exports, "EDIT_FILE_TOOL_DESCRIPTION", {
41
+ enumerable: true,
42
+ get: function () { return chunk74A4HLIO_cjs.EDIT_FILE_TOOL_DESCRIPTION; }
718
43
  });
719
- module.exports = __toCommonJS(fastapply_exports);
720
-
721
- // tools/fastapply/core.ts
722
- var import_path = require("path");
723
- init_logger();
724
-
725
- // tools/utils/resilience.ts
726
- init_version();
727
-
728
- // core/client.ts
729
- init_logger();
730
- init_version();
731
-
732
- // tools/fastapply/core.ts
733
- init_apply();
734
- init_apply();
735
- var DEFAULT_CONFIG = {
736
- morphApiUrl: "https://api.morphllm.com",
737
- baseDir: process.cwd(),
738
- generateUdiff: true,
739
- autoWrite: true,
740
- timeout: 6e5,
741
- anchorCompaction: true,
742
- anchorCompactionThreshold: 128 * 1024,
743
- debug: false
744
- };
745
- async function executeEditFile(input, config = {}) {
746
- const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;
747
- const fullPath = (0, import_path.resolve)((0, import_path.join)(baseDir, input.target_filepath));
748
- logger.debug("FastApply", "execute_start", { target_filepath: input.target_filepath, baseDir, autoWrite: config.autoWrite !== false });
749
- const relativePath = (0, import_path.relative)(baseDir, fullPath);
750
- if (relativePath.startsWith("..") || fullPath === baseDir) {
751
- logger.warn("FastApply", "security_check_failed", { target_filepath: input.target_filepath, relative: relativePath });
752
- return {
753
- success: false,
754
- filepath: input.target_filepath,
755
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
756
- error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`
757
- };
758
- }
759
- logger.debug("FastApply", "security_check", { resolved: fullPath, relative: relativePath });
760
- try {
761
- const { readFile, writeFile } = await import("fs/promises");
762
- const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await Promise.resolve().then(() => (init_apply(), apply_exports));
763
- let originalCode = "";
764
- let fileExists = true;
765
- try {
766
- originalCode = await readFile(fullPath, "utf-8");
767
- logger.debug("FastApply", "file_read", { path: fullPath, exists: true, size_bytes: originalCode.length });
768
- } catch (error) {
769
- if (error.code !== "ENOENT") {
770
- throw error;
771
- }
772
- fileExists = false;
773
- logger.debug("FastApply", "file_read", { path: fullPath, exists: false });
774
- }
775
- const instruction = input.instruction ?? input.instructions ?? "";
776
- logger.debug("FastApply", "api_call", { instruction_len: instruction.length, code_edit_len: input.code_edit.length, original_len: originalCode.length });
777
- const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
778
- logger.debug("FastApply", "api_response", { completion_id: completionId, merged_len: mergedCode.length });
779
- const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
780
- if (config.autoWrite !== false) {
781
- await writeFile(fullPath, mergedCode, "utf-8");
782
- logger.debug("FastApply", "file_write", { path: fullPath, size_bytes: mergedCode.length });
783
- }
784
- const changes = countChanges2(originalCode, mergedCode);
785
- logger.debug("FastApply", "changes", { added: changes.linesAdded, removed: changes.linesRemoved, modified: changes.linesModified });
786
- return {
787
- success: true,
788
- filepath: input.target_filepath,
789
- udiff,
790
- changes,
791
- completionId
792
- };
793
- } catch (error) {
794
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
795
- const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
796
- logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
797
- return {
798
- success: false,
799
- filepath: input.target_filepath,
800
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
801
- error: errorMessage,
802
- errorCode: structuredError?.code,
803
- completionId: structuredError?.completionId
804
- };
805
- }
806
- }
807
-
808
- // tools/fastapply/prompts.ts
809
- var EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.
810
-
811
- This will be read by a less intelligent model, which will quickly apply the edit. You should make it clear what the edit is, while also minimizing the unchanged code you write.
812
-
813
- When writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.
814
-
815
- For example:
816
-
817
- // ... existing code ...
818
- FIRST_EDIT
819
- // ... existing code ...
820
- SECOND_EDIT
821
- // ... existing code ...
822
- THIRD_EDIT
823
- // ... existing code ...
824
-
825
- You should still bias towards repeating as few lines of the original file as possible to convey the change.
826
- But, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
827
-
828
- DO NOT omit spans of pre-existing code (or comments) without using the // ... existing code ... comment to indicate its absence. If you omit the existing code comment, the model may inadvertently delete these lines.
829
-
830
- If you plan on deleting a section, you must provide context before and after to delete it.
831
-
832
- Make sure it is clear what the edit should be, and where it should be applied.
833
- Make edits to a file in a single edit_file call instead of multiple edit_file calls to the same file. The apply model can handle many distinct edits at once.`;
834
- var EDIT_FILE_SYSTEM_PROMPT = `When the user is asking for edits to their code, use the edit_file tool to highlight the changes necessary and add comments to indicate where unchanged code has been skipped. For example:
835
-
836
- // ... existing code ...
837
- {{ edit_1 }}
838
- // ... existing code ...
839
- {{ edit_2 }}
840
- // ... existing code ...
841
-
842
- Often this will mean that the start/end of the file will be skipped, but that's okay! Rewrite the entire file ONLY if specifically requested. Always provide a brief explanation of the updates, unless the user specifically requests only the code.
843
-
844
- These edit codeblocks are also read by a less intelligent language model, colloquially called the apply model, to update the file. To help specify the edit to the apply model, you will be very careful when generating the codeblock to not introduce ambiguity. You will specify all unchanged regions (code and comments) of the file with "// ... existing code ..." comment markers. This will ensure the apply model will not delete existing unchanged code or comments when editing the file.`;
845
-
846
- // tools/fastapply/anthropic.ts
847
- var anthropic_exports = {};
848
- __export(anthropic_exports, {
849
- createEditFileTool: () => createEditFileTool,
850
- editFileTool: () => editFileTool,
851
- execute: () => execute,
852
- formatResult: () => formatResult,
853
- getSystemPrompt: () => getSystemPrompt
44
+ Object.defineProperty(exports, "executeEditFile", {
45
+ enumerable: true,
46
+ get: function () { return chunkNJWOWXUR_cjs.executeEditFile; }
854
47
  });
855
- var editFileTool = {
856
- name: "edit_file",
857
- description: EDIT_FILE_TOOL_DESCRIPTION,
858
- input_schema: {
859
- type: "object",
860
- properties: {
861
- target_filepath: {
862
- type: "string",
863
- description: "The path of the target file to modify"
864
- },
865
- instruction: {
866
- type: "string",
867
- description: "A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit."
868
- },
869
- code_edit: {
870
- type: "string",
871
- description: "Specify ONLY the precise lines of code that you wish to edit. Use `// ... existing code ...` for unchanged sections."
872
- }
873
- },
874
- required: ["target_filepath", "instruction", "code_edit"]
875
- }
876
- };
877
- function formatResult(result) {
878
- if (!result.success) {
879
- return `Error editing file: ${result.error}`;
880
- }
881
- const { changes } = result;
882
- return `Successfully applied changes to ${result.filepath}. Added ${changes.linesAdded}, removed ${changes.linesRemoved}, modified ${changes.linesModified}.`;
883
- }
884
- function createEditFileTool(config = {}) {
885
- const toolDef = {
886
- ...editFileTool,
887
- ...config.description && { description: config.description }
888
- };
889
- return Object.assign({}, toolDef, {
890
- execute: async (input) => {
891
- return executeEditFile(input, config);
892
- },
893
- formatResult: (result) => {
894
- return formatResult(result);
895
- },
896
- getSystemPrompt: () => {
897
- return EDIT_FILE_SYSTEM_PROMPT;
898
- }
899
- });
900
- }
901
- async function execute(input, config) {
902
- return executeEditFile(input, config);
903
- }
904
- function getSystemPrompt() {
905
- return EDIT_FILE_SYSTEM_PROMPT;
906
- }
907
-
908
- // tools/fastapply/openai.ts
909
- var openai_exports = {};
910
- __export(openai_exports, {
911
- createEditFileTool: () => createEditFileTool2,
912
- default: () => openai_default,
913
- editFileTool: () => editFileTool2,
914
- execute: () => execute2,
915
- formatResult: () => formatResult2,
916
- getSystemPrompt: () => getSystemPrompt2
48
+ Object.defineProperty(exports, "FastApplyAnchorIntegrityError", {
49
+ enumerable: true,
50
+ get: function () { return chunkUHFVWYSP_cjs.FastApplyAnchorIntegrityError; }
917
51
  });
918
- var editFileTool2 = {
919
- type: "function",
920
- function: {
921
- name: "edit_file",
922
- description: EDIT_FILE_TOOL_DESCRIPTION,
923
- parameters: {
924
- type: "object",
925
- properties: {
926
- target_filepath: {
927
- type: "string",
928
- description: "The path of the target file to modify"
929
- },
930
- instruction: {
931
- type: "string",
932
- description: "A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit."
933
- },
934
- code_edit: {
935
- type: "string",
936
- description: "Specify ONLY the precise lines of code that you wish to edit. Use `// ... existing code ...` for unchanged sections."
937
- }
938
- },
939
- required: ["target_filepath", "instruction", "code_edit"]
940
- }
941
- }
942
- };
943
- async function execute2(input, config) {
944
- return executeEditFile(input, config);
945
- }
946
- function getSystemPrompt2() {
947
- return EDIT_FILE_SYSTEM_PROMPT;
948
- }
949
- function formatResult2(result) {
950
- if (!result.success) {
951
- return `Error editing file: ${result.error}`;
952
- }
953
- const { changes } = result;
954
- return `Successfully applied changes to ${result.filepath}. Added ${changes.linesAdded}, removed ${changes.linesRemoved}, modified ${changes.linesModified}.`;
955
- }
956
- function createEditFileTool2(config = {}) {
957
- const toolDef = {
958
- ...editFileTool2,
959
- ...config.description && {
960
- function: {
961
- ...editFileTool2.function,
962
- description: config.description
963
- }
964
- }
965
- };
966
- return Object.assign({}, toolDef, {
967
- execute: async (input) => {
968
- const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
969
- return execute2(parsedInput, config);
970
- },
971
- formatResult: (result) => {
972
- return formatResult2(result);
973
- },
974
- getSystemPrompt: () => {
975
- return getSystemPrompt2();
976
- }
977
- });
978
- }
979
- var openai_default = editFileTool2;
980
-
981
- // tools/fastapply/vercel.ts
982
- var vercel_exports = {};
983
- __export(vercel_exports, {
984
- createEditFileTool: () => createEditFileTool3,
985
- default: () => vercel_default,
986
- editFileTool: () => editFileTool3,
987
- getSystemPrompt: () => getSystemPrompt3
52
+ Object.defineProperty(exports, "FastApplyContextLengthError", {
53
+ enumerable: true,
54
+ get: function () { return chunkUHFVWYSP_cjs.FastApplyContextLengthError; }
988
55
  });
989
- var import_ai = require("ai");
990
- var import_zod = require("zod");
991
- var editFileSchema = import_zod.z.object({
992
- target_filepath: import_zod.z.string().describe("The path of the target file to modify"),
993
- instruction: import_zod.z.string().describe("A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit."),
994
- code_edit: import_zod.z.string().describe("Specify ONLY the precise lines of code that you wish to edit. Use `// ... existing code ...` for unchanged sections.")
56
+ Object.defineProperty(exports, "applyEdit", {
57
+ enumerable: true,
58
+ get: function () { return chunkUHFVWYSP_cjs.applyEdit; }
995
59
  });
996
- var editFileTool3 = (0, import_ai.tool)({
997
- description: EDIT_FILE_TOOL_DESCRIPTION,
998
- inputSchema: editFileSchema,
999
- execute: async (params) => {
1000
- const result = await executeEditFile({
1001
- target_filepath: params.target_filepath,
1002
- instruction: params.instruction,
1003
- code_edit: params.code_edit
1004
- });
1005
- if (!result.success) {
1006
- throw new Error(`Failed to edit file: ${result.error}`);
1007
- }
1008
- return {
1009
- success: true,
1010
- filepath: result.filepath,
1011
- changes: result.changes,
1012
- udiff: result.udiff
1013
- };
1014
- }
60
+ Object.defineProperty(exports, "countChanges", {
61
+ enumerable: true,
62
+ get: function () { return chunkUHFVWYSP_cjs.countChanges; }
1015
63
  });
1016
- function getSystemPrompt3() {
1017
- return EDIT_FILE_SYSTEM_PROMPT;
1018
- }
1019
- function createEditFileTool3(config = {}) {
1020
- const schema = import_zod.z.object({
1021
- target_filepath: import_zod.z.string().describe("The path of the target file to modify"),
1022
- instruction: import_zod.z.string().describe("A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit."),
1023
- code_edit: import_zod.z.string().describe("Specify ONLY the precise lines of code that you wish to edit. Use `// ... existing code ...` for unchanged sections.")
1024
- });
1025
- return (0, import_ai.tool)({
1026
- description: config.description || EDIT_FILE_TOOL_DESCRIPTION,
1027
- inputSchema: schema,
1028
- execute: async (params) => {
1029
- const result = await executeEditFile(
1030
- {
1031
- target_filepath: params.target_filepath,
1032
- instruction: params.instruction,
1033
- code_edit: params.code_edit
1034
- },
1035
- config
1036
- );
1037
- if (!result.success) {
1038
- throw new Error(`Failed to edit file: ${result.error}`);
1039
- }
1040
- return {
1041
- success: true,
1042
- filepath: result.filepath,
1043
- changes: result.changes,
1044
- udiff: result.udiff
1045
- };
1046
- }
1047
- });
1048
- }
1049
- var vercel_default = editFileTool3;
1050
- // Annotate the CommonJS export names for ESM import in node:
1051
- 0 && (module.exports = {
1052
- EDIT_FILE_SYSTEM_PROMPT,
1053
- EDIT_FILE_TOOL_DESCRIPTION,
1054
- FastApplyAnchorIntegrityError,
1055
- FastApplyContextLengthError,
1056
- anthropic,
1057
- applyEdit,
1058
- countChanges,
1059
- executeEditFile,
1060
- generateUdiff,
1061
- openai,
1062
- vercel
64
+ Object.defineProperty(exports, "generateUdiff", {
65
+ enumerable: true,
66
+ get: function () { return chunkUHFVWYSP_cjs.generateUdiff; }
1063
67
  });