@morphllm/morphsdk 0.2.201 → 0.2.203

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 (180) hide show
  1. package/dist/chunk-2PPYWRMZ.js +3 -4
  2. package/dist/{chunk-DBNSOYQ3.js → chunk-2UIOCSVJ.js} +3 -24
  3. package/dist/chunk-44OIEPIO.js +4 -23
  4. package/dist/chunk-4EQQGUZ7.cjs +104 -0
  5. package/dist/chunk-4OUGA3KS.js +1 -5
  6. package/dist/chunk-4R5MDGL6.cjs +280 -0
  7. package/dist/chunk-65W4I66Q.cjs +103 -0
  8. package/dist/{chunk-WBTXEJOC.js → chunk-66THRMD7.js} +10 -35
  9. package/dist/chunk-6TZCVTW5.js +3 -4
  10. package/dist/chunk-6WP7EA4F.js +2 -4
  11. package/dist/chunk-74A4HLIO.cjs +42 -0
  12. package/dist/chunk-75ZPJI57.cjs +9 -0
  13. package/dist/chunk-7NA7X7W2.cjs +77 -0
  14. package/dist/chunk-7PJYY46L.cjs +2 -0
  15. package/dist/chunk-AFF6XYKL.cjs +71 -0
  16. package/dist/{chunk-P2KW2O5R.js → chunk-AJBZA23L.js} +3 -25
  17. package/dist/chunk-AWFZKS27.cjs +11 -0
  18. package/dist/{chunk-FVT4PU4I.js → chunk-AXEKIRRY.js} +22 -62
  19. package/dist/chunk-B3FD67F2.cjs +256 -0
  20. package/dist/chunk-BJBWWIZV.cjs +2 -0
  21. package/dist/{chunk-M6AVXUM4.js → chunk-E3XNKAMI.js} +5 -15
  22. package/dist/{chunk-TS3OJ4LA.js → chunk-E7FLETFO.js} +2 -8
  23. package/dist/{chunk-EQAWWVKV.js → chunk-EI2M567U.js} +2 -6
  24. package/dist/chunk-EJTL2BOZ.cjs +42 -0
  25. package/dist/chunk-ETBRAKVV.js +1 -5
  26. package/dist/{chunk-VOXUA5ZH.js → chunk-EZ2OFDBJ.js} +5 -19
  27. package/dist/chunk-FBOZIVVQ.js +1 -0
  28. package/dist/{chunk-TZC3EOZS.js → chunk-GDFPZ3NJ.js} +4 -19
  29. package/dist/{chunk-LISSWRUD.js → chunk-GIQAIHUI.js} +8 -33
  30. package/dist/chunk-GSUQGDCL.cjs +235 -0
  31. package/dist/{chunk-5NSYDT36.js → chunk-H3HRSRR5.js} +4 -12
  32. package/dist/chunk-HDP4QAZL.js +1 -4
  33. package/dist/chunk-HMLYJVZM.cjs +410 -0
  34. package/dist/chunk-IPJA3ZS6.cjs +10 -0
  35. package/dist/{chunk-B376VMIH.js → chunk-IUM6CQYX.js} +3 -12
  36. package/dist/{chunk-OVLUL5AC.js → chunk-J56Q6C4Y.js} +4 -18
  37. package/dist/chunk-JBTR3FQD.cjs +135 -0
  38. package/dist/chunk-JNQKQKHS.cjs +81 -0
  39. package/dist/chunk-JOZC4T6C.cjs +168 -0
  40. package/dist/{chunk-ILY5N5NJ.js → chunk-JUGNTIVU.js} +6 -19
  41. package/dist/{chunk-SU7AAS3O.js → chunk-JY6COF3X.js} +5 -22
  42. package/dist/{chunk-JBAY3PRV.js → chunk-KLVJIC2O.js} +5 -17
  43. package/dist/chunk-KSZYOX6S.cjs +91 -0
  44. package/dist/chunk-KVGZ2TSG.cjs +274 -0
  45. package/dist/chunk-LDM7RNNN.js +1 -0
  46. package/dist/{chunk-RZOJ4GSY.js → chunk-LLQH6CCB.js} +10 -28
  47. package/dist/chunk-M34E2AMK.js +1 -5
  48. package/dist/chunk-MF56KEI4.js +1 -4
  49. package/dist/chunk-MLKGABMK.js +1 -3
  50. package/dist/{chunk-I26FQELI.js → chunk-MLPZKUCO.js} +11 -5
  51. package/dist/chunk-MWXJ6DZ2.cjs +21 -0
  52. package/dist/{chunk-NWGRW4V7.js → chunk-N7UKZ5X7.js} +2 -6
  53. package/dist/chunk-NDUC7OV6.cjs +74 -0
  54. package/dist/{chunk-RJXAXR7Q.js → chunk-NLACTMZT.js} +6 -19
  55. package/dist/chunk-NNKBKENK.cjs +15 -0
  56. package/dist/chunk-NRG6QX3L.js +1 -3
  57. package/dist/chunk-OCCGJ4S6.js +8 -0
  58. package/dist/chunk-ODY2NKQU.cjs +50 -0
  59. package/dist/chunk-OM5ZSXQW.cjs +91 -0
  60. package/dist/chunk-OOEORM7H.cjs +334 -0
  61. package/dist/chunk-OPDWMD4Q.js +1 -3
  62. package/dist/{chunk-BZXOAC2R.js → chunk-OSL4CNSO.js} +7 -23
  63. package/dist/chunk-OXXMTDOY.cjs +86 -0
  64. package/dist/chunk-PA3UTI4A.js +1 -4
  65. package/dist/chunk-QEEAIXL5.cjs +74 -0
  66. package/dist/chunk-RYVW7RUM.js +2 -6
  67. package/dist/chunk-S6QBPXBI.cjs +107 -0
  68. package/dist/chunk-TL34BLQD.cjs +10 -0
  69. package/dist/chunk-TPZHMD7J.cjs +72 -0
  70. package/dist/chunk-UAPK3AIJ.js +1 -10
  71. package/dist/chunk-UF5IKELS.cjs +26 -0
  72. package/dist/chunk-UNX7V6P6.cjs +60 -0
  73. package/dist/chunk-UUCRWJJR.cjs +313 -0
  74. package/dist/chunk-VDFLPO7B.cjs +396 -0
  75. package/dist/chunk-VHD7CW5O.cjs +43 -0
  76. package/dist/chunk-VL4QNALG.cjs +50 -0
  77. package/dist/chunk-WR7LSUIR.cjs +213 -0
  78. package/dist/chunk-XE6D4J63.cjs +72 -0
  79. package/dist/chunk-ZLG2M2I4.cjs +21 -0
  80. package/dist/chunk-ZSHVXDA2.js +4 -10
  81. package/dist/client.cjs +40 -4353
  82. package/dist/client.js +32 -37
  83. package/dist/core/client.cjs +10 -476
  84. package/dist/core/client.js +6 -11
  85. package/dist/core/error.cjs +8 -251
  86. package/dist/core/error.js +4 -9
  87. package/dist/core/index.cjs +20 -488
  88. package/dist/core/index.js +8 -19
  89. package/dist/core/resource.cjs +9 -33
  90. package/dist/core/resource.js +2 -7
  91. package/dist/edge.cjs +62 -1111
  92. package/dist/edge.js +10 -42
  93. package/dist/index.cjs +115 -4424
  94. package/dist/index.js +39 -87
  95. package/dist/modelrouter/core.cjs +28 -648
  96. package/dist/modelrouter/core.js +8 -21
  97. package/dist/modelrouter/index.cjs +28 -648
  98. package/dist/modelrouter/index.js +8 -21
  99. package/dist/modelrouter/types.cjs +1 -17
  100. package/dist/modelrouter/types.js +1 -0
  101. package/dist/subagents/anthropic.cjs +27 -2777
  102. package/dist/subagents/anthropic.js +19 -24
  103. package/dist/subagents/index.cjs +14 -95
  104. package/dist/subagents/index.js +2 -11
  105. package/dist/subagents/prompts.cjs +14 -93
  106. package/dist/subagents/prompts.js +2 -11
  107. package/dist/subagents/types.cjs +1 -17
  108. package/dist/subagents/types.js +1 -0
  109. package/dist/subagents/vercel.cjs +27 -2754
  110. package/dist/subagents/vercel.js +19 -24
  111. package/dist/tools/compact/core.cjs +12 -548
  112. package/dist/tools/compact/core.js +8 -13
  113. package/dist/tools/compact/index.cjs +17 -595
  114. package/dist/tools/compact/index.js +9 -17
  115. package/dist/tools/compact/types.cjs +1 -17
  116. package/dist/tools/compact/types.js +1 -0
  117. package/dist/tools/fastapply/anthropic.cjs +27 -891
  118. package/dist/tools/fastapply/anthropic.js +11 -24
  119. package/dist/tools/fastapply/apply.cjs +28 -672
  120. package/dist/tools/fastapply/apply.js +4 -19
  121. package/dist/tools/fastapply/core.cjs +37 -1061
  122. package/dist/tools/fastapply/core.js +9 -29
  123. package/dist/tools/fastapply/index.cjs +62 -1062
  124. package/dist/tools/fastapply/index.js +14 -44
  125. package/dist/tools/fastapply/openai.cjs +32 -901
  126. package/dist/tools/fastapply/openai.js +11 -26
  127. package/dist/tools/fastapply/prompts.cjs +10 -62
  128. package/dist/tools/fastapply/prompts.js +2 -9
  129. package/dist/tools/fastapply/types.cjs +1 -17
  130. package/dist/tools/fastapply/types.js +1 -0
  131. package/dist/tools/fastapply/vercel.cjs +25 -897
  132. package/dist/tools/fastapply/vercel.js +11 -22
  133. package/dist/tools/index.cjs +62 -1062
  134. package/dist/tools/index.js +14 -44
  135. package/dist/tools/utils/resilience.cjs +15 -312
  136. package/dist/tools/utils/resilience.js +3 -12
  137. package/dist/tools/warp_grep/agent/config.cjs +16 -127
  138. package/dist/tools/warp_grep/agent/config.js +2 -11
  139. package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
  140. package/dist/tools/warp_grep/agent/formatter.js +2 -9
  141. package/dist/tools/warp_grep/agent/parser.cjs +16 -83
  142. package/dist/tools/warp_grep/agent/parser.js +2 -11
  143. package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
  144. package/dist/tools/warp_grep/agent/runner.js +7 -14
  145. package/dist/tools/warp_grep/agent/types.cjs +1 -17
  146. package/dist/tools/warp_grep/agent/types.js +1 -0
  147. package/dist/tools/warp_grep/anthropic.cjs +47 -2554
  148. package/dist/tools/warp_grep/anthropic.js +19 -35
  149. package/dist/tools/warp_grep/client.cjs +49 -2464
  150. package/dist/tools/warp_grep/client.js +17 -34
  151. package/dist/tools/warp_grep/gemini.cjs +48 -2483
  152. package/dist/tools/warp_grep/gemini.js +21 -41
  153. package/dist/tools/warp_grep/harness.cjs +81 -929
  154. package/dist/tools/warp_grep/harness.js +12 -51
  155. package/dist/tools/warp_grep/index.cjs +124 -2568
  156. package/dist/tools/warp_grep/index.js +24 -87
  157. package/dist/tools/warp_grep/openai.cjs +53 -2568
  158. package/dist/tools/warp_grep/openai.js +19 -37
  159. package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
  160. package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
  161. package/dist/tools/warp_grep/providers/local.cjs +10 -582
  162. package/dist/tools/warp_grep/providers/local.js +6 -11
  163. package/dist/tools/warp_grep/providers/remote.cjs +8 -331
  164. package/dist/tools/warp_grep/providers/remote.js +3 -8
  165. package/dist/tools/warp_grep/providers/types.cjs +1 -17
  166. package/dist/tools/warp_grep/providers/types.js +1 -0
  167. package/dist/tools/warp_grep/utils/files.cjs +9 -42
  168. package/dist/tools/warp_grep/utils/files.js +2 -7
  169. package/dist/tools/warp_grep/utils/github.cjs +9 -43
  170. package/dist/tools/warp_grep/utils/github.js +2 -7
  171. package/dist/tools/warp_grep/utils/paths.cjs +28 -104
  172. package/dist/tools/warp_grep/utils/paths.js +2 -17
  173. package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -86
  174. package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
  175. package/dist/tools/warp_grep/vercel.cjs +53 -2550
  176. package/dist/tools/warp_grep/vercel.js +19 -37
  177. package/dist/version.cjs +7 -225
  178. package/dist/version.js +2 -7
  179. package/package.json +2 -2
  180. package/dist/chunk-UZCXOOZO.js +0 -203
@@ -1,906 +1,34 @@
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);
1
+ 'use strict';
32
2
 
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
- });
3
+ Object.defineProperty(exports, '__esModule', { value: true });
85
4
 
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.201",
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
- }
286
- });
5
+ var chunkJNQKQKHS_cjs = require('../../chunk-JNQKQKHS.cjs');
6
+ require('../../chunk-74A4HLIO.cjs');
7
+ require('../../chunk-JBTR3FQD.cjs');
8
+ require('../../chunk-VDFLPO7B.cjs');
9
+ require('../../chunk-65W4I66Q.cjs');
10
+ require('../../chunk-VL4QNALG.cjs');
11
+ require('../../chunk-ZLG2M2I4.cjs');
12
+ require('../../chunk-OM5ZSXQW.cjs');
13
+ require('../../chunk-TL34BLQD.cjs');
14
+ require('../../chunk-AWFZKS27.cjs');
15
+ require('../../chunk-75ZPJI57.cjs');
287
16
 
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
17
 
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
18
 
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
- }
19
+ Object.defineProperty(exports, "createEditFileTool", {
20
+ enumerable: true,
21
+ get: function () { return chunkJNQKQKHS_cjs.createEditFileTool; }
471
22
  });
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
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
- 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
- }
702
- });
703
-
704
- // tools/fastapply/vercel.ts
705
- var vercel_exports = {};
706
- __export(vercel_exports, {
707
- createEditFileTool: () => createEditFileTool,
708
- default: () => vercel_default,
709
- editFileTool: () => editFileTool,
710
- getSystemPrompt: () => getSystemPrompt
711
- });
712
- module.exports = __toCommonJS(vercel_exports);
713
- var import_ai = require("ai");
714
- var import_zod = require("zod");
715
-
716
- // tools/fastapply/core.ts
717
- var import_path = require("path");
718
- init_logger();
719
-
720
- // tools/utils/resilience.ts
721
- init_version();
722
-
723
- // core/client.ts
724
- init_logger();
725
- init_version();
726
-
727
- // tools/fastapply/core.ts
728
- init_apply();
729
- init_apply();
730
- var DEFAULT_CONFIG = {
731
- morphApiUrl: "https://api.morphllm.com",
732
- baseDir: process.cwd(),
733
- generateUdiff: true,
734
- autoWrite: true,
735
- timeout: 6e5,
736
- anchorCompaction: true,
737
- anchorCompactionThreshold: 128 * 1024,
738
- debug: false
739
- };
740
- async function executeEditFile(input, config = {}) {
741
- const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;
742
- const fullPath = (0, import_path.resolve)((0, import_path.join)(baseDir, input.target_filepath));
743
- logger.debug("FastApply", "execute_start", { target_filepath: input.target_filepath, baseDir, autoWrite: config.autoWrite !== false });
744
- const relativePath = (0, import_path.relative)(baseDir, fullPath);
745
- if (relativePath.startsWith("..") || fullPath === baseDir) {
746
- logger.warn("FastApply", "security_check_failed", { target_filepath: input.target_filepath, relative: relativePath });
747
- return {
748
- success: false,
749
- filepath: input.target_filepath,
750
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
751
- error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`
752
- };
753
- }
754
- logger.debug("FastApply", "security_check", { resolved: fullPath, relative: relativePath });
755
- try {
756
- const { readFile, writeFile } = await import("fs/promises");
757
- const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await Promise.resolve().then(() => (init_apply(), apply_exports));
758
- let originalCode = "";
759
- let fileExists = true;
760
- try {
761
- originalCode = await readFile(fullPath, "utf-8");
762
- logger.debug("FastApply", "file_read", { path: fullPath, exists: true, size_bytes: originalCode.length });
763
- } catch (error) {
764
- if (error.code !== "ENOENT") {
765
- throw error;
766
- }
767
- fileExists = false;
768
- logger.debug("FastApply", "file_read", { path: fullPath, exists: false });
769
- }
770
- const instruction = input.instruction ?? input.instructions ?? "";
771
- logger.debug("FastApply", "api_call", { instruction_len: instruction.length, code_edit_len: input.code_edit.length, original_len: originalCode.length });
772
- const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
773
- logger.debug("FastApply", "api_response", { completion_id: completionId, merged_len: mergedCode.length });
774
- const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
775
- if (config.autoWrite !== false) {
776
- await writeFile(fullPath, mergedCode, "utf-8");
777
- logger.debug("FastApply", "file_write", { path: fullPath, size_bytes: mergedCode.length });
778
- }
779
- const changes = countChanges2(originalCode, mergedCode);
780
- logger.debug("FastApply", "changes", { added: changes.linesAdded, removed: changes.linesRemoved, modified: changes.linesModified });
781
- return {
782
- success: true,
783
- filepath: input.target_filepath,
784
- udiff,
785
- changes,
786
- completionId
787
- };
788
- } catch (error) {
789
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
790
- const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
791
- logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
792
- return {
793
- success: false,
794
- filepath: input.target_filepath,
795
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
796
- error: errorMessage,
797
- errorCode: structuredError?.code,
798
- completionId: structuredError?.completionId
799
- };
800
- }
801
- }
802
-
803
- // tools/fastapply/prompts.ts
804
- var EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.
805
-
806
- 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.
807
-
808
- 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.
809
-
810
- For example:
811
-
812
- // ... existing code ...
813
- FIRST_EDIT
814
- // ... existing code ...
815
- SECOND_EDIT
816
- // ... existing code ...
817
- THIRD_EDIT
818
- // ... existing code ...
819
-
820
- You should still bias towards repeating as few lines of the original file as possible to convey the change.
821
- But, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
822
-
823
- 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.
824
-
825
- If you plan on deleting a section, you must provide context before and after to delete it.
826
-
827
- Make sure it is clear what the edit should be, and where it should be applied.
828
- 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.`;
829
- 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:
830
-
831
- // ... existing code ...
832
- {{ edit_1 }}
833
- // ... existing code ...
834
- {{ edit_2 }}
835
- // ... existing code ...
836
-
837
- 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.
838
-
839
- 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.`;
840
-
841
- // tools/fastapply/vercel.ts
842
- var editFileSchema = import_zod.z.object({
843
- target_filepath: import_zod.z.string().describe("The path of the target file to modify"),
844
- 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."),
845
- 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.")
23
+ Object.defineProperty(exports, "default", {
24
+ enumerable: true,
25
+ get: function () { return chunkJNQKQKHS_cjs.vercel_default; }
846
26
  });
847
- var editFileTool = (0, import_ai.tool)({
848
- description: EDIT_FILE_TOOL_DESCRIPTION,
849
- inputSchema: editFileSchema,
850
- execute: async (params) => {
851
- const result = await executeEditFile({
852
- target_filepath: params.target_filepath,
853
- instruction: params.instruction,
854
- code_edit: params.code_edit
855
- });
856
- if (!result.success) {
857
- throw new Error(`Failed to edit file: ${result.error}`);
858
- }
859
- return {
860
- success: true,
861
- filepath: result.filepath,
862
- changes: result.changes,
863
- udiff: result.udiff
864
- };
865
- }
27
+ Object.defineProperty(exports, "editFileTool", {
28
+ enumerable: true,
29
+ get: function () { return chunkJNQKQKHS_cjs.editFileTool; }
866
30
  });
867
- function getSystemPrompt() {
868
- return EDIT_FILE_SYSTEM_PROMPT;
869
- }
870
- function createEditFileTool(config = {}) {
871
- const schema = import_zod.z.object({
872
- target_filepath: import_zod.z.string().describe("The path of the target file to modify"),
873
- 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."),
874
- 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.")
875
- });
876
- return (0, import_ai.tool)({
877
- description: config.description || EDIT_FILE_TOOL_DESCRIPTION,
878
- inputSchema: schema,
879
- execute: async (params) => {
880
- const result = await executeEditFile(
881
- {
882
- target_filepath: params.target_filepath,
883
- instruction: params.instruction,
884
- code_edit: params.code_edit
885
- },
886
- config
887
- );
888
- if (!result.success) {
889
- throw new Error(`Failed to edit file: ${result.error}`);
890
- }
891
- return {
892
- success: true,
893
- filepath: result.filepath,
894
- changes: result.changes,
895
- udiff: result.udiff
896
- };
897
- }
898
- });
899
- }
900
- var vercel_default = editFileTool;
901
- // Annotate the CommonJS export names for ESM import in node:
902
- 0 && (module.exports = {
903
- createEditFileTool,
904
- editFileTool,
905
- getSystemPrompt
31
+ Object.defineProperty(exports, "getSystemPrompt", {
32
+ enumerable: true,
33
+ get: function () { return chunkJNQKQKHS_cjs.getSystemPrompt; }
906
34
  });