@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.
- package/dist/chunk-2PPYWRMZ.js +3 -4
- package/dist/{chunk-DBNSOYQ3.js → chunk-2UIOCSVJ.js} +3 -24
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/chunk-4R5MDGL6.cjs +280 -0
- package/dist/chunk-65W4I66Q.cjs +103 -0
- package/dist/{chunk-WBTXEJOC.js → chunk-66THRMD7.js} +10 -35
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7NA7X7W2.cjs +77 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AFF6XYKL.cjs +71 -0
- package/dist/{chunk-P2KW2O5R.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-FVT4PU4I.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-M6AVXUM4.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-TS3OJ4LA.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-EQAWWVKV.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-VOXUA5ZH.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-TZC3EOZS.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-LISSWRUD.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-5NSYDT36.js → chunk-H3HRSRR5.js} +4 -12
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HMLYJVZM.cjs +410 -0
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/{chunk-B376VMIH.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-OVLUL5AC.js → chunk-J56Q6C4Y.js} +4 -18
- package/dist/chunk-JBTR3FQD.cjs +135 -0
- package/dist/chunk-JNQKQKHS.cjs +81 -0
- package/dist/chunk-JOZC4T6C.cjs +168 -0
- package/dist/{chunk-ILY5N5NJ.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-SU7AAS3O.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-JBAY3PRV.js → chunk-KLVJIC2O.js} +5 -17
- package/dist/chunk-KSZYOX6S.cjs +91 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-RZOJ4GSY.js → chunk-LLQH6CCB.js} +10 -28
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/{chunk-I26FQELI.js → chunk-MLPZKUCO.js} +11 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-NWGRW4V7.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-RJXAXR7Q.js → chunk-NLACTMZT.js} +6 -19
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCCGJ4S6.js +8 -0
- package/dist/chunk-ODY2NKQU.cjs +50 -0
- package/dist/chunk-OM5ZSXQW.cjs +91 -0
- package/dist/chunk-OOEORM7H.cjs +334 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/{chunk-BZXOAC2R.js → chunk-OSL4CNSO.js} +7 -23
- package/dist/chunk-OXXMTDOY.cjs +86 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/chunk-S6QBPXBI.cjs +107 -0
- package/dist/chunk-TL34BLQD.cjs +10 -0
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UUCRWJJR.cjs +313 -0
- package/dist/chunk-VDFLPO7B.cjs +396 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-ZLG2M2I4.cjs +21 -0
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/client.cjs +40 -4353
- package/dist/client.js +32 -37
- package/dist/core/client.cjs +10 -476
- package/dist/core/client.js +6 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +20 -488
- package/dist/core/index.js +8 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +62 -1111
- package/dist/edge.js +10 -42
- package/dist/index.cjs +115 -4424
- package/dist/index.js +39 -87
- package/dist/modelrouter/core.cjs +28 -648
- package/dist/modelrouter/core.js +8 -21
- package/dist/modelrouter/index.cjs +28 -648
- package/dist/modelrouter/index.js +8 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +27 -2777
- package/dist/subagents/anthropic.js +19 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +27 -2754
- package/dist/subagents/vercel.js +19 -24
- package/dist/tools/compact/core.cjs +12 -548
- package/dist/tools/compact/core.js +8 -13
- package/dist/tools/compact/index.cjs +17 -595
- package/dist/tools/compact/index.js +9 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +27 -891
- package/dist/tools/fastapply/anthropic.js +11 -24
- package/dist/tools/fastapply/apply.cjs +28 -672
- package/dist/tools/fastapply/apply.js +4 -19
- package/dist/tools/fastapply/core.cjs +37 -1061
- package/dist/tools/fastapply/core.js +9 -29
- package/dist/tools/fastapply/index.cjs +62 -1062
- package/dist/tools/fastapply/index.js +14 -44
- package/dist/tools/fastapply/openai.cjs +32 -901
- package/dist/tools/fastapply/openai.js +11 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +25 -897
- package/dist/tools/fastapply/vercel.js +11 -22
- package/dist/tools/index.cjs +62 -1062
- package/dist/tools/index.js +14 -44
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
- package/dist/tools/warp_grep/agent/runner.js +7 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +47 -2554
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2464
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2483
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -929
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2568
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2568
- package/dist/tools/warp_grep/openai.js +19 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -582
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -86
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2550
- package/dist/tools/warp_grep/vercel.js +19 -37
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +2 -2
- package/dist/chunk-UZCXOOZO.js +0 -203
|
@@ -1,1070 +1,46 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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.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
|
-
});
|
|
3
|
+
var chunkJBTR3FQD_cjs = require('../../chunk-JBTR3FQD.cjs');
|
|
4
|
+
var chunkVDFLPO7B_cjs = require('../../chunk-VDFLPO7B.cjs');
|
|
5
|
+
require('../../chunk-65W4I66Q.cjs');
|
|
6
|
+
require('../../chunk-VL4QNALG.cjs');
|
|
7
|
+
require('../../chunk-ZLG2M2I4.cjs');
|
|
8
|
+
require('../../chunk-OM5ZSXQW.cjs');
|
|
9
|
+
require('../../chunk-TL34BLQD.cjs');
|
|
10
|
+
require('../../chunk-AWFZKS27.cjs');
|
|
11
|
+
require('../../chunk-75ZPJI57.cjs');
|
|
287
12
|
|
|
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
13
|
|
|
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
14
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
}
|
|
15
|
+
Object.defineProperty(exports, "FastApplyClient", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkJBTR3FQD_cjs.FastApplyClient; }
|
|
471
18
|
});
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
__export(apply_exports, {
|
|
476
|
-
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
477
|
-
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
478
|
-
applyEdit: () => applyEdit,
|
|
479
|
-
callMorphAPI: () => callMorphAPI,
|
|
480
|
-
countChanges: () => countChanges,
|
|
481
|
-
generateUdiff: () => generateUdiff
|
|
19
|
+
Object.defineProperty(exports, "executeEditFile", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkJBTR3FQD_cjs.executeEditFile; }
|
|
482
22
|
});
|
|
483
|
-
|
|
484
|
-
|
|
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_TIMEOUT2;
|
|
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_TIMEOUT2, 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_TIMEOUT2 = 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
|
-
}
|
|
23
|
+
Object.defineProperty(exports, "FastApplyAnchorIntegrityError", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return chunkVDFLPO7B_cjs.FastApplyAnchorIntegrityError; }
|
|
702
26
|
});
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
__export(core_exports, {
|
|
707
|
-
FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
|
|
708
|
-
FastApplyClient: () => FastApplyClient,
|
|
709
|
-
FastApplyContextLengthError: () => FastApplyContextLengthError,
|
|
710
|
-
applyEdit: () => applyEdit,
|
|
711
|
-
callMorphAPI: () => callMorphAPI,
|
|
712
|
-
countChanges: () => countChanges,
|
|
713
|
-
executeEditFile: () => executeEditFile,
|
|
714
|
-
generateUdiff: () => generateUdiff
|
|
27
|
+
Object.defineProperty(exports, "FastApplyContextLengthError", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return chunkVDFLPO7B_cjs.FastApplyContextLengthError; }
|
|
715
30
|
});
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
732
|
-
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
733
|
-
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
734
|
-
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
735
|
-
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
736
|
-
onRetry
|
|
737
|
-
} = retryConfig;
|
|
738
|
-
let lastError = null;
|
|
739
|
-
let delay = initialDelay;
|
|
740
|
-
options = { ...options, headers: { "X-Morph-SDK-Version": SDK_VERSION, ...options.headers } };
|
|
741
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
742
|
-
try {
|
|
743
|
-
const response = await fetch(url, options);
|
|
744
|
-
if (response.status === 429 || response.status === 503) {
|
|
745
|
-
if (attempt < maxRetries) {
|
|
746
|
-
const retryAfter = response.headers.get("Retry-After");
|
|
747
|
-
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
748
|
-
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
749
|
-
if (onRetry) {
|
|
750
|
-
onRetry(attempt + 1, error);
|
|
751
|
-
}
|
|
752
|
-
await sleep(waitTime);
|
|
753
|
-
delay *= backoffMultiplier;
|
|
754
|
-
continue;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
return response;
|
|
758
|
-
} catch (error) {
|
|
759
|
-
lastError = error;
|
|
760
|
-
const isRetryable = retryableErrors.some(
|
|
761
|
-
(errType) => lastError?.message?.includes(errType)
|
|
762
|
-
);
|
|
763
|
-
if (!isRetryable || attempt === maxRetries) {
|
|
764
|
-
throw lastError;
|
|
765
|
-
}
|
|
766
|
-
const waitTime = Math.min(delay, maxDelay);
|
|
767
|
-
if (onRetry) {
|
|
768
|
-
onRetry(attempt + 1, lastError);
|
|
769
|
-
}
|
|
770
|
-
await sleep(waitTime);
|
|
771
|
-
delay *= backoffMultiplier;
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
throw lastError || new Error("Max retries exceeded");
|
|
775
|
-
}
|
|
776
|
-
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
777
|
-
let timeoutId;
|
|
778
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
779
|
-
timeoutId = setTimeout(() => {
|
|
780
|
-
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
781
|
-
}, timeoutMs);
|
|
782
|
-
});
|
|
783
|
-
try {
|
|
784
|
-
const result = await Promise.race([promise, timeoutPromise]);
|
|
785
|
-
clearTimeout(timeoutId);
|
|
786
|
-
return result;
|
|
787
|
-
} catch (error) {
|
|
788
|
-
clearTimeout(timeoutId);
|
|
789
|
-
throw error;
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
function sleep(ms) {
|
|
793
|
-
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
794
|
-
}
|
|
795
|
-
var MorphError = class extends Error {
|
|
796
|
-
constructor(message, code, statusCode, retryable = false) {
|
|
797
|
-
super(message);
|
|
798
|
-
this.code = code;
|
|
799
|
-
this.statusCode = statusCode;
|
|
800
|
-
this.retryable = retryable;
|
|
801
|
-
this.name = "MorphError";
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
|
|
805
|
-
// core/client.ts
|
|
806
|
-
init_logger();
|
|
807
|
-
init_version();
|
|
808
|
-
|
|
809
|
-
// core/error.ts
|
|
810
|
-
async function toMorphError(response) {
|
|
811
|
-
let message = `Morph API request failed (${response.status})`;
|
|
812
|
-
let code = "api_error";
|
|
813
|
-
try {
|
|
814
|
-
const body = await response.json();
|
|
815
|
-
message = body.error?.message ?? body.message ?? message;
|
|
816
|
-
code = body.error?.code ?? body.error?.type ?? code;
|
|
817
|
-
} catch {
|
|
818
|
-
}
|
|
819
|
-
if (response.status === 401) code = "authentication_error";
|
|
820
|
-
if (response.status === 429) code = "rate_limit_exceeded";
|
|
821
|
-
const retryable = response.status === 429 || response.status === 503;
|
|
822
|
-
return new MorphError(message, code, response.status, retryable);
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
// core/client.ts
|
|
826
|
-
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
827
|
-
var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
|
|
828
|
-
var DEFAULT_TIMEOUT = 6e4;
|
|
829
|
-
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
830
|
-
var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
831
|
-
var MorphAPIClient = class {
|
|
832
|
-
/** Explicit key as provided; resolved against env at request time. */
|
|
833
|
-
apiKey;
|
|
834
|
-
baseURL;
|
|
835
|
-
reposURL;
|
|
836
|
-
/** Explicit default timeout (ms), if set. The request default is applied lazily so
|
|
837
|
-
* resources can read an undefined value and supply their own fallback. */
|
|
838
|
-
timeout;
|
|
839
|
-
retryConfig;
|
|
840
|
-
debug;
|
|
841
|
-
constructor(options = {}) {
|
|
842
|
-
this.apiKey = options.apiKey;
|
|
843
|
-
this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
|
|
844
|
-
this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
|
|
845
|
-
this.timeout = options.timeout;
|
|
846
|
-
this.retryConfig = options.retryConfig;
|
|
847
|
-
this.debug = options.debug ?? false;
|
|
848
|
-
if (this.debug) logger.enable();
|
|
849
|
-
}
|
|
850
|
-
/** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
|
|
851
|
-
resolveApiKey() {
|
|
852
|
-
return this.apiKey ?? env("MORPH_API_KEY");
|
|
853
|
-
}
|
|
854
|
-
/** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
|
|
855
|
-
defaultHeaders() {
|
|
856
|
-
return { "X-Morph-SDK-Version": SDK_VERSION };
|
|
857
|
-
}
|
|
858
|
-
buildURL(path, baseURL) {
|
|
859
|
-
if (/^https?:\/\//i.test(path)) return path;
|
|
860
|
-
const base = stripTrailingSlash(baseURL ?? this.baseURL);
|
|
861
|
-
return `${base}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
862
|
-
}
|
|
863
|
-
buildHeaders(apiKey, extra) {
|
|
864
|
-
return {
|
|
865
|
-
"Content-Type": "application/json",
|
|
866
|
-
"X-Morph-SDK-Version": SDK_VERSION,
|
|
867
|
-
Authorization: `Bearer ${apiKey}`,
|
|
868
|
-
...extra
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
applyQuery(url, query) {
|
|
872
|
-
if (!query) return url;
|
|
873
|
-
const params = new URLSearchParams();
|
|
874
|
-
for (const [key, value] of Object.entries(query)) {
|
|
875
|
-
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
876
|
-
}
|
|
877
|
-
const qs = params.toString();
|
|
878
|
-
return qs ? `${url}${url.includes("?") ? "&" : "?"}${qs}` : url;
|
|
879
|
-
}
|
|
880
|
-
async request(method, path, opts = {}) {
|
|
881
|
-
const apiKey = this.resolveApiKey();
|
|
882
|
-
if (!apiKey) {
|
|
883
|
-
throw new MorphError(
|
|
884
|
-
"Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
|
|
885
|
-
"missing_api_key",
|
|
886
|
-
401
|
|
887
|
-
);
|
|
888
|
-
}
|
|
889
|
-
const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);
|
|
890
|
-
const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT;
|
|
891
|
-
const init = {
|
|
892
|
-
method,
|
|
893
|
-
headers: this.buildHeaders(apiKey, opts.headers),
|
|
894
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
895
|
-
...opts.signal ? { signal: opts.signal } : {}
|
|
896
|
-
};
|
|
897
|
-
logger.debug("MorphAPIClient", "request", { method, url });
|
|
898
|
-
const response = await withTimeout(
|
|
899
|
-
fetchWithRetry(url, init, this.retryConfig ?? {}),
|
|
900
|
-
timeout,
|
|
901
|
-
`Morph request to ${url} timed out after ${timeout}ms`
|
|
902
|
-
);
|
|
903
|
-
if (!response.ok) throw await toMorphError(response);
|
|
904
|
-
if (opts.stream) return response;
|
|
905
|
-
if (response.status === 204) return void 0;
|
|
906
|
-
const text = await response.text();
|
|
907
|
-
return text ? JSON.parse(text) : void 0;
|
|
908
|
-
}
|
|
909
|
-
get(path, opts) {
|
|
910
|
-
return this.request("GET", path, opts);
|
|
911
|
-
}
|
|
912
|
-
post(path, opts) {
|
|
913
|
-
return this.request("POST", path, opts);
|
|
914
|
-
}
|
|
915
|
-
delete(path, opts) {
|
|
916
|
-
return this.request("DELETE", path, opts);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
919
|
-
|
|
920
|
-
// core/resource.ts
|
|
921
|
-
var APIResource = class {
|
|
922
|
-
_client;
|
|
923
|
-
constructor(client) {
|
|
924
|
-
this._client = client;
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
|
|
928
|
-
// tools/fastapply/core.ts
|
|
929
|
-
init_apply();
|
|
930
|
-
init_apply();
|
|
931
|
-
var DEFAULT_CONFIG = {
|
|
932
|
-
morphApiUrl: "https://api.morphllm.com",
|
|
933
|
-
baseDir: process.cwd(),
|
|
934
|
-
generateUdiff: true,
|
|
935
|
-
autoWrite: true,
|
|
936
|
-
timeout: 6e5,
|
|
937
|
-
anchorCompaction: true,
|
|
938
|
-
anchorCompactionThreshold: 128 * 1024,
|
|
939
|
-
debug: false
|
|
940
|
-
};
|
|
941
|
-
var FastApplyClient = class extends APIResource {
|
|
942
|
-
config;
|
|
943
|
-
constructor(clientOrConfig = {}) {
|
|
944
|
-
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
945
|
-
super(
|
|
946
|
-
isClient ? clientOrConfig : new MorphAPIClient({
|
|
947
|
-
apiKey: clientOrConfig.apiKey,
|
|
948
|
-
timeout: clientOrConfig.timeout ?? DEFAULT_CONFIG.timeout,
|
|
949
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
950
|
-
debug: clientOrConfig.debug
|
|
951
|
-
})
|
|
952
|
-
);
|
|
953
|
-
this.config = {
|
|
954
|
-
morphApiKey: this._client.resolveApiKey(),
|
|
955
|
-
morphApiUrl: this._client.baseURL,
|
|
956
|
-
debug: this._client.debug,
|
|
957
|
-
timeout: (isClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_CONFIG.timeout,
|
|
958
|
-
retryConfig: this._client.retryConfig,
|
|
959
|
-
generateUdiff: DEFAULT_CONFIG.generateUdiff,
|
|
960
|
-
autoWrite: DEFAULT_CONFIG.autoWrite
|
|
961
|
-
};
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Execute a file edit operation
|
|
965
|
-
*
|
|
966
|
-
* @param input - Edit parameters including filepath, instructions, and code_edit
|
|
967
|
-
* @param overrides - Optional config overrides for this operation
|
|
968
|
-
* @returns Edit result with success status and changes
|
|
969
|
-
*/
|
|
970
|
-
async execute(input, overrides) {
|
|
971
|
-
return executeEditFile(input, { ...this.config, ...overrides });
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Apply an edit to code directly without file I/O
|
|
975
|
-
*
|
|
976
|
-
* Useful for sandbox environments or when you manage your own file system.
|
|
977
|
-
* Compatible with the earlier OpenAI client API contract.
|
|
978
|
-
*
|
|
979
|
-
* @param input - Code and edit parameters
|
|
980
|
-
* @param overrides - Optional config overrides for this operation
|
|
981
|
-
* @returns Result with merged code
|
|
982
|
-
*
|
|
983
|
-
* @example
|
|
984
|
-
* ```typescript
|
|
985
|
-
* const result = await client.applyEdit({
|
|
986
|
-
* originalCode: 'function hello() { return "world"; }',
|
|
987
|
-
* codeEdit: 'function hello() { return "universe"; }',
|
|
988
|
-
* instructions: 'Change return value'
|
|
989
|
-
* });
|
|
990
|
-
* console.log(result.mergedCode);
|
|
991
|
-
* ```
|
|
992
|
-
*/
|
|
993
|
-
async applyEdit(input, overrides) {
|
|
994
|
-
const { applyEdit: applyEdit2 } = await Promise.resolve().then(() => (init_apply(), apply_exports));
|
|
995
|
-
return applyEdit2(input, { ...this.config, ...overrides });
|
|
996
|
-
}
|
|
997
|
-
};
|
|
998
|
-
async function executeEditFile(input, config = {}) {
|
|
999
|
-
const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;
|
|
1000
|
-
const fullPath = (0, import_path.resolve)((0, import_path.join)(baseDir, input.target_filepath));
|
|
1001
|
-
logger.debug("FastApply", "execute_start", { target_filepath: input.target_filepath, baseDir, autoWrite: config.autoWrite !== false });
|
|
1002
|
-
const relativePath = (0, import_path.relative)(baseDir, fullPath);
|
|
1003
|
-
if (relativePath.startsWith("..") || fullPath === baseDir) {
|
|
1004
|
-
logger.warn("FastApply", "security_check_failed", { target_filepath: input.target_filepath, relative: relativePath });
|
|
1005
|
-
return {
|
|
1006
|
-
success: false,
|
|
1007
|
-
filepath: input.target_filepath,
|
|
1008
|
-
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
1009
|
-
error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`
|
|
1010
|
-
};
|
|
1011
|
-
}
|
|
1012
|
-
logger.debug("FastApply", "security_check", { resolved: fullPath, relative: relativePath });
|
|
1013
|
-
try {
|
|
1014
|
-
const { readFile, writeFile } = await import("fs/promises");
|
|
1015
|
-
const { callMorphAPI: callMorphAPI2, generateUdiff: generateUdiff2, countChanges: countChanges2 } = await Promise.resolve().then(() => (init_apply(), apply_exports));
|
|
1016
|
-
let originalCode = "";
|
|
1017
|
-
let fileExists = true;
|
|
1018
|
-
try {
|
|
1019
|
-
originalCode = await readFile(fullPath, "utf-8");
|
|
1020
|
-
logger.debug("FastApply", "file_read", { path: fullPath, exists: true, size_bytes: originalCode.length });
|
|
1021
|
-
} catch (error) {
|
|
1022
|
-
if (error.code !== "ENOENT") {
|
|
1023
|
-
throw error;
|
|
1024
|
-
}
|
|
1025
|
-
fileExists = false;
|
|
1026
|
-
logger.debug("FastApply", "file_read", { path: fullPath, exists: false });
|
|
1027
|
-
}
|
|
1028
|
-
const instruction = input.instruction ?? input.instructions ?? "";
|
|
1029
|
-
logger.debug("FastApply", "api_call", { instruction_len: instruction.length, code_edit_len: input.code_edit.length, original_len: originalCode.length });
|
|
1030
|
-
const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
|
|
1031
|
-
logger.debug("FastApply", "api_response", { completion_id: completionId, merged_len: mergedCode.length });
|
|
1032
|
-
const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
|
|
1033
|
-
if (config.autoWrite !== false) {
|
|
1034
|
-
await writeFile(fullPath, mergedCode, "utf-8");
|
|
1035
|
-
logger.debug("FastApply", "file_write", { path: fullPath, size_bytes: mergedCode.length });
|
|
1036
|
-
}
|
|
1037
|
-
const changes = countChanges2(originalCode, mergedCode);
|
|
1038
|
-
logger.debug("FastApply", "changes", { added: changes.linesAdded, removed: changes.linesRemoved, modified: changes.linesModified });
|
|
1039
|
-
return {
|
|
1040
|
-
success: true,
|
|
1041
|
-
filepath: input.target_filepath,
|
|
1042
|
-
udiff,
|
|
1043
|
-
changes,
|
|
1044
|
-
completionId
|
|
1045
|
-
};
|
|
1046
|
-
} catch (error) {
|
|
1047
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1048
|
-
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
1049
|
-
logger.error("FastApply", "execute_error", { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : void 0 });
|
|
1050
|
-
return {
|
|
1051
|
-
success: false,
|
|
1052
|
-
filepath: input.target_filepath,
|
|
1053
|
-
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
1054
|
-
error: errorMessage,
|
|
1055
|
-
errorCode: structuredError?.code,
|
|
1056
|
-
completionId: structuredError?.completionId
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1061
|
-
0 && (module.exports = {
|
|
1062
|
-
FastApplyAnchorIntegrityError,
|
|
1063
|
-
FastApplyClient,
|
|
1064
|
-
FastApplyContextLengthError,
|
|
1065
|
-
applyEdit,
|
|
1066
|
-
callMorphAPI,
|
|
1067
|
-
countChanges,
|
|
1068
|
-
executeEditFile,
|
|
1069
|
-
generateUdiff
|
|
31
|
+
Object.defineProperty(exports, "applyEdit", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () { return chunkVDFLPO7B_cjs.applyEdit; }
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "callMorphAPI", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return chunkVDFLPO7B_cjs.callMorphAPI; }
|
|
38
|
+
});
|
|
39
|
+
Object.defineProperty(exports, "countChanges", {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return chunkVDFLPO7B_cjs.countChanges; }
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "generateUdiff", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return chunkVDFLPO7B_cjs.generateUdiff; }
|
|
1070
46
|
});
|