@morphllm/morphsdk 0.2.6
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/README.md +39 -0
- package/dist/chunk-4UVEBIDK.js +358 -0
- package/dist/chunk-4UVEBIDK.js.map +1 -0
- package/dist/chunk-4V46N27D.js +169 -0
- package/dist/chunk-4V46N27D.js.map +1 -0
- package/dist/chunk-4VWJFZVS.js +89 -0
- package/dist/chunk-4VWJFZVS.js.map +1 -0
- package/dist/chunk-5COKN3XD.js +91 -0
- package/dist/chunk-5COKN3XD.js.map +1 -0
- package/dist/chunk-5VQEQSJQ.js +394 -0
- package/dist/chunk-5VQEQSJQ.js.map +1 -0
- package/dist/chunk-63WE2C5R.js +43 -0
- package/dist/chunk-63WE2C5R.js.map +1 -0
- package/dist/chunk-74ZHKB54.js +9 -0
- package/dist/chunk-74ZHKB54.js.map +1 -0
- package/dist/chunk-7PZJQFCY.js +39 -0
- package/dist/chunk-7PZJQFCY.js.map +1 -0
- package/dist/chunk-BILUTNBC.js +83 -0
- package/dist/chunk-BILUTNBC.js.map +1 -0
- package/dist/chunk-G4DJ6VSM.js +78 -0
- package/dist/chunk-G4DJ6VSM.js.map +1 -0
- package/dist/chunk-HGIFACNP.js +59 -0
- package/dist/chunk-HGIFACNP.js.map +1 -0
- package/dist/chunk-OI5YYE36.js +189 -0
- package/dist/chunk-OI5YYE36.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-VJK4PH5V.js +105 -0
- package/dist/chunk-VJK4PH5V.js.map +1 -0
- package/dist/chunk-WXBUVKYL.js +128 -0
- package/dist/chunk-WXBUVKYL.js.map +1 -0
- package/dist/chunk-X2K57BH6.js +1 -0
- package/dist/chunk-X2K57BH6.js.map +1 -0
- package/dist/chunk-YQMPVJ2L.js +32 -0
- package/dist/chunk-YQMPVJ2L.js.map +1 -0
- package/dist/chunk-YWS2GRQC.js +97 -0
- package/dist/chunk-YWS2GRQC.js.map +1 -0
- package/dist/chunk-ZQEWQ7LJ.js +97 -0
- package/dist/chunk-ZQEWQ7LJ.js.map +1 -0
- package/dist/client.cjs +1358 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.js +15 -0
- package/dist/client.js.map +1 -0
- package/dist/git/client.cjs +428 -0
- package/dist/git/client.cjs.map +1 -0
- package/dist/git/client.js +8 -0
- package/dist/git/client.js.map +1 -0
- package/dist/git/config.cjs +41 -0
- package/dist/git/config.cjs.map +1 -0
- package/dist/git/config.js +17 -0
- package/dist/git/config.js.map +1 -0
- package/dist/git/index.cjs +438 -0
- package/dist/git/index.cjs.map +1 -0
- package/dist/git/index.js +14 -0
- package/dist/git/index.js.map +1 -0
- package/dist/git/types.cjs +19 -0
- package/dist/git/types.cjs.map +1 -0
- package/dist/git/types.js +1 -0
- package/dist/git/types.js.map +1 -0
- package/dist/index.cjs +1372 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/browser/anthropic.cjs +281 -0
- package/dist/tools/browser/anthropic.cjs.map +1 -0
- package/dist/tools/browser/anthropic.js +72 -0
- package/dist/tools/browser/anthropic.js.map +1 -0
- package/dist/tools/browser/core.cjs +459 -0
- package/dist/tools/browser/core.cjs.map +1 -0
- package/dist/tools/browser/core.js +21 -0
- package/dist/tools/browser/core.js.map +1 -0
- package/dist/tools/browser/index.cjs +497 -0
- package/dist/tools/browser/index.cjs.map +1 -0
- package/dist/tools/browser/index.js +27 -0
- package/dist/tools/browser/index.js.map +1 -0
- package/dist/tools/browser/openai.cjs +297 -0
- package/dist/tools/browser/openai.cjs.map +1 -0
- package/dist/tools/browser/openai.js +85 -0
- package/dist/tools/browser/openai.js.map +1 -0
- package/dist/tools/browser/prompts.cjs +64 -0
- package/dist/tools/browser/prompts.cjs.map +1 -0
- package/dist/tools/browser/prompts.js +10 -0
- package/dist/tools/browser/prompts.js.map +1 -0
- package/dist/tools/browser/types.cjs +19 -0
- package/dist/tools/browser/types.cjs.map +1 -0
- package/dist/tools/browser/types.js +1 -0
- package/dist/tools/browser/types.js.map +1 -0
- package/dist/tools/browser/vercel.cjs +242 -0
- package/dist/tools/browser/vercel.cjs.map +1 -0
- package/dist/tools/browser/vercel.js +49 -0
- package/dist/tools/browser/vercel.js.map +1 -0
- package/dist/tools/codebase_search/anthropic.cjs +267 -0
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -0
- package/dist/tools/codebase_search/anthropic.js +11 -0
- package/dist/tools/codebase_search/anthropic.js.map +1 -0
- package/dist/tools/codebase_search/core.cjs +201 -0
- package/dist/tools/codebase_search/core.cjs.map +1 -0
- package/dist/tools/codebase_search/core.js +11 -0
- package/dist/tools/codebase_search/core.js.map +1 -0
- package/dist/tools/codebase_search/index.cjs +393 -0
- package/dist/tools/codebase_search/index.cjs.map +1 -0
- package/dist/tools/codebase_search/index.js +27 -0
- package/dist/tools/codebase_search/index.js.map +1 -0
- package/dist/tools/codebase_search/openai.cjs +316 -0
- package/dist/tools/codebase_search/openai.cjs.map +1 -0
- package/dist/tools/codebase_search/openai.js +21 -0
- package/dist/tools/codebase_search/openai.js.map +1 -0
- package/dist/tools/codebase_search/prompts.cjs +57 -0
- package/dist/tools/codebase_search/prompts.cjs.map +1 -0
- package/dist/tools/codebase_search/prompts.js +10 -0
- package/dist/tools/codebase_search/prompts.js.map +1 -0
- package/dist/tools/codebase_search/types.cjs +19 -0
- package/dist/tools/codebase_search/types.cjs.map +1 -0
- package/dist/tools/codebase_search/types.js +1 -0
- package/dist/tools/codebase_search/types.js.map +1 -0
- package/dist/tools/codebase_search/vercel.cjs +230 -0
- package/dist/tools/codebase_search/vercel.cjs.map +1 -0
- package/dist/tools/codebase_search/vercel.js +15 -0
- package/dist/tools/codebase_search/vercel.js.map +1 -0
- package/dist/tools/fastapply/anthropic.cjs +335 -0
- package/dist/tools/fastapply/anthropic.cjs.map +1 -0
- package/dist/tools/fastapply/anthropic.js +13 -0
- package/dist/tools/fastapply/anthropic.js.map +1 -0
- package/dist/tools/fastapply/core.cjs +267 -0
- package/dist/tools/fastapply/core.cjs.map +1 -0
- package/dist/tools/fastapply/core.js +15 -0
- package/dist/tools/fastapply/core.js.map +1 -0
- package/dist/tools/fastapply/index.cjs +500 -0
- package/dist/tools/fastapply/index.cjs.map +1 -0
- package/dist/tools/fastapply/index.js +32 -0
- package/dist/tools/fastapply/index.js.map +1 -0
- package/dist/tools/fastapply/openai.cjs +353 -0
- package/dist/tools/fastapply/openai.cjs.map +1 -0
- package/dist/tools/fastapply/openai.js +21 -0
- package/dist/tools/fastapply/openai.js.map +1 -0
- package/dist/tools/fastapply/prompts.cjs +68 -0
- package/dist/tools/fastapply/prompts.cjs.map +1 -0
- package/dist/tools/fastapply/prompts.js +10 -0
- package/dist/tools/fastapply/prompts.js.map +1 -0
- package/dist/tools/fastapply/types.cjs +19 -0
- package/dist/tools/fastapply/types.cjs.map +1 -0
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/types.js.map +1 -0
- package/dist/tools/fastapply/vercel.cjs +347 -0
- package/dist/tools/fastapply/vercel.cjs.map +1 -0
- package/dist/tools/fastapply/vercel.js +17 -0
- package/dist/tools/fastapply/vercel.js.map +1 -0
- package/dist/tools/index.cjs +500 -0
- package/dist/tools/index.cjs.map +1 -0
- package/dist/tools/index.js +32 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/modelrouter/core.cjs +286 -0
- package/dist/tools/modelrouter/core.cjs.map +1 -0
- package/dist/tools/modelrouter/core.js +13 -0
- package/dist/tools/modelrouter/core.js.map +1 -0
- package/dist/tools/modelrouter/index.cjs +286 -0
- package/dist/tools/modelrouter/index.cjs.map +1 -0
- package/dist/tools/modelrouter/index.js +13 -0
- package/dist/tools/modelrouter/index.js.map +1 -0
- package/dist/tools/modelrouter/types.cjs +19 -0
- package/dist/tools/modelrouter/types.cjs.map +1 -0
- package/dist/tools/modelrouter/types.js +1 -0
- package/dist/tools/modelrouter/types.js.map +1 -0
- package/dist/tools/utils/resilience.cjs +115 -0
- package/dist/tools/utils/resilience.cjs.map +1 -0
- package/dist/tools/utils/resilience.js +12 -0
- package/dist/tools/utils/resilience.js.map +1 -0
- package/package.json +159 -0
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// tools/fastapply/openai.ts
|
|
21
|
+
var openai_exports = {};
|
|
22
|
+
__export(openai_exports, {
|
|
23
|
+
createEditFileTool: () => createEditFileTool,
|
|
24
|
+
default: () => openai_default,
|
|
25
|
+
editFileTool: () => editFileTool,
|
|
26
|
+
execute: () => execute,
|
|
27
|
+
formatResult: () => formatResult,
|
|
28
|
+
getSystemPrompt: () => getSystemPrompt
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(openai_exports);
|
|
31
|
+
|
|
32
|
+
// tools/fastapply/core.ts
|
|
33
|
+
var import_promises = require("fs/promises");
|
|
34
|
+
var import_path = require("path");
|
|
35
|
+
var import_diff = require("diff");
|
|
36
|
+
|
|
37
|
+
// tools/utils/resilience.ts
|
|
38
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
39
|
+
maxRetries: 3,
|
|
40
|
+
initialDelay: 1e3,
|
|
41
|
+
maxDelay: 3e4,
|
|
42
|
+
backoffMultiplier: 2,
|
|
43
|
+
retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
|
|
44
|
+
};
|
|
45
|
+
async function fetchWithRetry(url, options, retryConfig = {}) {
|
|
46
|
+
const {
|
|
47
|
+
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
48
|
+
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
49
|
+
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
50
|
+
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
51
|
+
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
52
|
+
onRetry
|
|
53
|
+
} = retryConfig;
|
|
54
|
+
let lastError = null;
|
|
55
|
+
let delay = initialDelay;
|
|
56
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(url, options);
|
|
59
|
+
if (response.status === 429 || response.status === 503) {
|
|
60
|
+
if (attempt < maxRetries) {
|
|
61
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
62
|
+
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
63
|
+
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
64
|
+
if (onRetry) {
|
|
65
|
+
onRetry(attempt + 1, error);
|
|
66
|
+
}
|
|
67
|
+
await sleep(waitTime);
|
|
68
|
+
delay *= backoffMultiplier;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return response;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
lastError = error;
|
|
75
|
+
const isRetryable = retryableErrors.some(
|
|
76
|
+
(errType) => lastError?.message?.includes(errType)
|
|
77
|
+
);
|
|
78
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
79
|
+
throw lastError;
|
|
80
|
+
}
|
|
81
|
+
const waitTime = Math.min(delay, maxDelay);
|
|
82
|
+
if (onRetry) {
|
|
83
|
+
onRetry(attempt + 1, lastError);
|
|
84
|
+
}
|
|
85
|
+
await sleep(waitTime);
|
|
86
|
+
delay *= backoffMultiplier;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw lastError || new Error("Max retries exceeded");
|
|
90
|
+
}
|
|
91
|
+
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
92
|
+
let timeoutId;
|
|
93
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
94
|
+
timeoutId = setTimeout(() => {
|
|
95
|
+
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
96
|
+
}, timeoutMs);
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
100
|
+
clearTimeout(timeoutId);
|
|
101
|
+
return result;
|
|
102
|
+
} catch (error) {
|
|
103
|
+
clearTimeout(timeoutId);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function sleep(ms) {
|
|
108
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// tools/fastapply/core.ts
|
|
112
|
+
var DEFAULT_CONFIG = {
|
|
113
|
+
morphApiUrl: "https://api.morphllm.com",
|
|
114
|
+
baseDir: process.cwd(),
|
|
115
|
+
generateUdiff: true,
|
|
116
|
+
autoWrite: true,
|
|
117
|
+
timeout: 3e4,
|
|
118
|
+
debug: false
|
|
119
|
+
};
|
|
120
|
+
function generateUdiff(original, modified, filepath) {
|
|
121
|
+
return (0, import_diff.createTwoFilesPatch)(
|
|
122
|
+
filepath,
|
|
123
|
+
filepath,
|
|
124
|
+
original,
|
|
125
|
+
modified,
|
|
126
|
+
"Original",
|
|
127
|
+
"Modified"
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
function countChanges(original, modified) {
|
|
131
|
+
const diff = generateUdiff(original, modified, "file");
|
|
132
|
+
const lines = diff.split("\n");
|
|
133
|
+
let linesAdded = 0;
|
|
134
|
+
let linesRemoved = 0;
|
|
135
|
+
for (const line of lines) {
|
|
136
|
+
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
137
|
+
linesAdded++;
|
|
138
|
+
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
139
|
+
linesRemoved++;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const linesModified = Math.min(linesAdded, linesRemoved);
|
|
143
|
+
return {
|
|
144
|
+
linesAdded: linesAdded - linesModified,
|
|
145
|
+
linesRemoved: linesRemoved - linesModified,
|
|
146
|
+
linesModified
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
|
|
150
|
+
const apiKey = config.morphApiKey || process.env.MORPH_API_KEY;
|
|
151
|
+
const apiUrl = config.morphApiUrl || DEFAULT_CONFIG.morphApiUrl;
|
|
152
|
+
const timeout = config.timeout || DEFAULT_CONFIG.timeout;
|
|
153
|
+
const debug = config.debug || false;
|
|
154
|
+
if (!apiKey) {
|
|
155
|
+
throw new Error(
|
|
156
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
const message = `<instruction>${instructions}</instruction>
|
|
160
|
+
<code>${originalCode}</code>
|
|
161
|
+
<update>${codeEdit}</update>`;
|
|
162
|
+
if (debug) {
|
|
163
|
+
console.log(`[FastApply] Calling ${apiUrl}/v1/chat/completions`);
|
|
164
|
+
console.log(`[FastApply] File: ${filepath}, Instructions: ${instructions.slice(0, 60)}...`);
|
|
165
|
+
console.log(`[FastApply] Original: ${originalCode.length} chars, Edit: ${codeEdit.length} chars`);
|
|
166
|
+
}
|
|
167
|
+
const startTime = Date.now();
|
|
168
|
+
const fetchPromise = fetchWithRetry(
|
|
169
|
+
`${apiUrl}/v1/chat/completions`,
|
|
170
|
+
{
|
|
171
|
+
method: "POST",
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json",
|
|
174
|
+
"Authorization": `Bearer ${apiKey}`
|
|
175
|
+
},
|
|
176
|
+
body: JSON.stringify({
|
|
177
|
+
model: "morph-v3-fast",
|
|
178
|
+
messages: [{ role: "user", content: message }]
|
|
179
|
+
})
|
|
180
|
+
},
|
|
181
|
+
config.retryConfig
|
|
182
|
+
);
|
|
183
|
+
const response = await withTimeout(
|
|
184
|
+
fetchPromise,
|
|
185
|
+
timeout,
|
|
186
|
+
`Morph API request timed out after ${timeout}ms`
|
|
187
|
+
);
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
const error = await response.text();
|
|
190
|
+
if (debug) console.error(`[FastApply] API error: ${response.status} - ${error}`);
|
|
191
|
+
throw new Error(`Morph API error (${response.status}): ${error}`);
|
|
192
|
+
}
|
|
193
|
+
const data = await response.json();
|
|
194
|
+
const elapsed = Date.now() - startTime;
|
|
195
|
+
if (debug) {
|
|
196
|
+
console.log(`[FastApply] \u2705 Success in ${elapsed}ms, merged: ${data.choices[0].message.content.length} chars`);
|
|
197
|
+
}
|
|
198
|
+
return data.choices[0].message.content;
|
|
199
|
+
}
|
|
200
|
+
async function executeEditFile(input, config = {}) {
|
|
201
|
+
const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;
|
|
202
|
+
const fullPath = (0, import_path.resolve)((0, import_path.join)(baseDir, input.target_filepath));
|
|
203
|
+
const debug = config.debug || false;
|
|
204
|
+
const relativePath = (0, import_path.relative)(baseDir, fullPath);
|
|
205
|
+
if (relativePath.startsWith("..") || fullPath === baseDir) {
|
|
206
|
+
return {
|
|
207
|
+
success: false,
|
|
208
|
+
filepath: input.target_filepath,
|
|
209
|
+
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
210
|
+
error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
if (debug) console.log(`[FastApply] Reading file: ${input.target_filepath}`);
|
|
215
|
+
const originalCode = await (0, import_promises.readFile)(fullPath, "utf-8");
|
|
216
|
+
const mergedCode = await callMorphAPI(originalCode, input.code_edit, input.instructions, input.target_filepath, config);
|
|
217
|
+
const udiff = config.generateUdiff !== false ? generateUdiff(originalCode, mergedCode, input.target_filepath) : void 0;
|
|
218
|
+
if (config.autoWrite !== false) {
|
|
219
|
+
await (0, import_promises.writeFile)(fullPath, mergedCode, "utf-8");
|
|
220
|
+
if (debug) console.log(`[FastApply] Wrote ${mergedCode.length} chars to ${input.target_filepath}`);
|
|
221
|
+
}
|
|
222
|
+
const changes = countChanges(originalCode, mergedCode);
|
|
223
|
+
return {
|
|
224
|
+
success: true,
|
|
225
|
+
filepath: input.target_filepath,
|
|
226
|
+
udiff,
|
|
227
|
+
changes
|
|
228
|
+
};
|
|
229
|
+
} catch (error) {
|
|
230
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
231
|
+
if (debug) console.error(`[FastApply] Error: ${errorMessage}`);
|
|
232
|
+
return {
|
|
233
|
+
success: false,
|
|
234
|
+
filepath: input.target_filepath,
|
|
235
|
+
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
236
|
+
error: errorMessage
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// tools/fastapply/prompts.ts
|
|
242
|
+
var EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.
|
|
243
|
+
|
|
244
|
+
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.
|
|
245
|
+
|
|
246
|
+
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.
|
|
247
|
+
|
|
248
|
+
For example:
|
|
249
|
+
|
|
250
|
+
// ... existing code ...
|
|
251
|
+
FIRST_EDIT
|
|
252
|
+
// ... existing code ...
|
|
253
|
+
SECOND_EDIT
|
|
254
|
+
// ... existing code ...
|
|
255
|
+
THIRD_EDIT
|
|
256
|
+
// ... existing code ...
|
|
257
|
+
|
|
258
|
+
You should still bias towards repeating as few lines of the original file as possible to convey the change.
|
|
259
|
+
But, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
|
|
260
|
+
|
|
261
|
+
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.
|
|
262
|
+
|
|
263
|
+
If you plan on deleting a section, you must provide context before and after to delete it.
|
|
264
|
+
|
|
265
|
+
Make sure it is clear what the edit should be, and where it should be applied.
|
|
266
|
+
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.`;
|
|
267
|
+
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:
|
|
268
|
+
|
|
269
|
+
// ... existing code ...
|
|
270
|
+
{{ edit_1 }}
|
|
271
|
+
// ... existing code ...
|
|
272
|
+
{{ edit_2 }}
|
|
273
|
+
// ... existing code ...
|
|
274
|
+
|
|
275
|
+
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.
|
|
276
|
+
|
|
277
|
+
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.`;
|
|
278
|
+
|
|
279
|
+
// tools/fastapply/openai.ts
|
|
280
|
+
var editFileTool = {
|
|
281
|
+
type: "function",
|
|
282
|
+
function: {
|
|
283
|
+
name: "edit_file",
|
|
284
|
+
description: EDIT_FILE_TOOL_DESCRIPTION,
|
|
285
|
+
parameters: {
|
|
286
|
+
type: "object",
|
|
287
|
+
properties: {
|
|
288
|
+
target_filepath: {
|
|
289
|
+
type: "string",
|
|
290
|
+
description: "The path of the target file to modify"
|
|
291
|
+
},
|
|
292
|
+
instructions: {
|
|
293
|
+
type: "string",
|
|
294
|
+
description: "A single sentence describing what you are changing (first person)"
|
|
295
|
+
},
|
|
296
|
+
code_edit: {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: "The lazy edit with // ... existing code ... markers"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
required: ["target_filepath", "instructions", "code_edit"]
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
async function execute(input, config) {
|
|
306
|
+
return executeEditFile(input, config);
|
|
307
|
+
}
|
|
308
|
+
function getSystemPrompt() {
|
|
309
|
+
return EDIT_FILE_SYSTEM_PROMPT;
|
|
310
|
+
}
|
|
311
|
+
function formatResult(result) {
|
|
312
|
+
if (!result.success) {
|
|
313
|
+
return `Error editing file: ${result.error}`;
|
|
314
|
+
}
|
|
315
|
+
const { changes } = result;
|
|
316
|
+
const summary = [
|
|
317
|
+
changes.linesAdded && `+${changes.linesAdded} lines`,
|
|
318
|
+
changes.linesRemoved && `-${changes.linesRemoved} lines`,
|
|
319
|
+
changes.linesModified && `~${changes.linesModified} lines modified`
|
|
320
|
+
].filter(Boolean).join(", ");
|
|
321
|
+
if (result.udiff) {
|
|
322
|
+
return `Successfully applied changes to ${result.filepath}:
|
|
323
|
+
|
|
324
|
+
${result.udiff}
|
|
325
|
+
|
|
326
|
+
Summary: ${summary}`;
|
|
327
|
+
}
|
|
328
|
+
return `Successfully applied changes to ${result.filepath}. ${summary}`;
|
|
329
|
+
}
|
|
330
|
+
function createEditFileTool(config = {}) {
|
|
331
|
+
return Object.assign({}, editFileTool, {
|
|
332
|
+
execute: async (input) => {
|
|
333
|
+
const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
|
|
334
|
+
return execute(parsedInput, config);
|
|
335
|
+
},
|
|
336
|
+
formatResult: (result) => {
|
|
337
|
+
return formatResult(result);
|
|
338
|
+
},
|
|
339
|
+
getSystemPrompt: () => {
|
|
340
|
+
return getSystemPrompt();
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
var openai_default = editFileTool;
|
|
345
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
346
|
+
0 && (module.exports = {
|
|
347
|
+
createEditFileTool,
|
|
348
|
+
editFileTool,
|
|
349
|
+
execute,
|
|
350
|
+
formatResult,
|
|
351
|
+
getSystemPrompt
|
|
352
|
+
});
|
|
353
|
+
//# sourceMappingURL=openai.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../tools/fastapply/openai.ts","../../../tools/fastapply/core.ts","../../../tools/utils/resilience.ts","../../../tools/fastapply/prompts.ts"],"sourcesContent":["/**\n * OpenAI SDK adapter for edit_file tool\n */\n\nimport type { ChatCompletionTool } from 'openai/resources/chat/completions';\nimport { executeEditFile } from './core.js';\nimport { EDIT_FILE_TOOL_DESCRIPTION, EDIT_FILE_SYSTEM_PROMPT } from './prompts.js';\nimport type { EditFileInput, EditFileResult, EditFileConfig } from './types.js';\n\n/**\n * OpenAI-native tool definition for edit_file\n * \n * @example\n * ```ts\n * import OpenAI from 'openai';\n * import { editFileTool } from 'morphsdk/tools/openai';\n * \n * const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });\n * \n * const response = await client.chat.completions.create({\n * model: \"gpt-4o\",\n * tools: [editFileTool],\n * messages: [{ role: \"user\", content: \"Fix the bug in app.ts\" }]\n * });\n * ```\n */\nexport const editFileTool: ChatCompletionTool = {\n type: 'function',\n function: {\n name: 'edit_file',\n description: EDIT_FILE_TOOL_DESCRIPTION,\n parameters: {\n type: 'object',\n properties: {\n target_filepath: {\n type: 'string',\n description: 'The path of the target file to modify',\n },\n instructions: {\n type: 'string',\n description: 'A single sentence describing what you are changing (first person)',\n },\n code_edit: {\n type: 'string',\n description: 'The lazy edit with // ... existing code ... markers',\n },\n },\n required: ['target_filepath', 'instructions', 'code_edit'],\n },\n },\n};\n\n/**\n * Execute an edit_file tool call\n * \n * @param input - The tool input from GPT (parsed from tool_calls)\n * @param config - Optional configuration\n * @returns The result of the edit operation\n * \n * @example\n * ```ts\n * const args = JSON.parse(toolCall.function.arguments);\n * const result = await execute(args);\n * console.log('Changes applied:', result.udiff);\n * ```\n */\nexport async function execute(\n input: EditFileInput,\n config?: EditFileConfig\n): Promise<EditFileResult> {\n return executeEditFile(input, config);\n}\n\n/**\n * Get the system prompt for edit_file usage\n * \n * Add this to your system message to guide GPT on using edit_file properly.\n * \n * @example\n * ```ts\n * const response = await client.chat.completions.create({\n * model: \"gpt-4o\",\n * messages: [\n * { role: \"system\", content: getSystemPrompt() },\n * { role: \"user\", content: \"Fix bugs\" }\n * ],\n * tools: [editFileTool]\n * });\n * ```\n */\nexport function getSystemPrompt(): string {\n return EDIT_FILE_SYSTEM_PROMPT;\n}\n\n/**\n * Format the result for passing back to GPT\n * \n * @param result - The edit result\n * @returns Formatted string for tool message\n */\nexport function formatResult(result: EditFileResult): string {\n if (!result.success) {\n return `Error editing file: ${result.error}`;\n }\n \n const { changes } = result;\n const summary = [\n changes.linesAdded && `+${changes.linesAdded} lines`,\n changes.linesRemoved && `-${changes.linesRemoved} lines`,\n changes.linesModified && `~${changes.linesModified} lines modified`,\n ]\n .filter(Boolean)\n .join(', ');\n \n if (result.udiff) {\n return `Successfully applied changes to ${result.filepath}:\\n\\n${result.udiff}\\n\\nSummary: ${summary}`;\n }\n \n return `Successfully applied changes to ${result.filepath}. ${summary}`;\n}\n\n/**\n * Create a custom edit_file tool with configuration and methods\n * \n * @param config - Configuration options\n * @returns Tool definition with execute and formatResult methods\n * \n * @example\n * ```ts\n * import OpenAI from 'openai';\n * import { createEditFileTool } from 'morphsdk/tools/fastapply/openai';\n * \n * const tool = createEditFileTool({\n * baseDir: './src',\n * generateUdiff: true\n * });\n * \n * const client = new OpenAI();\n * \n * const response = await client.chat.completions.create({\n * model: 'gpt-4o',\n * tools: [tool], // tool itself is the ChatCompletionTool\n * messages: [{ role: 'user', content: 'Fix bug in app.ts' }]\n * });\n * \n * // Execute and format\n * const result = await tool.execute(toolCallArgs);\n * const formatted = tool.formatResult(result);\n * ```\n */\nexport function createEditFileTool(config: EditFileConfig = {}) {\n return Object.assign({}, editFileTool, {\n execute: async (input: EditFileInput | string): Promise<EditFileResult> => {\n const parsedInput = typeof input === 'string' ? JSON.parse(input) : input;\n return execute(parsedInput, config);\n },\n formatResult: (result: EditFileResult): string => {\n return formatResult(result);\n },\n getSystemPrompt: (): string => {\n return getSystemPrompt();\n },\n });\n}\n\n// Default export for convenience\nexport default editFileTool;\n\n","/**\n * Core implementation of Morph Fast Apply\n */\n\nimport { readFile, writeFile } from 'fs/promises';\nimport { join, resolve, relative } from 'path';\nimport { createTwoFilesPatch } from 'diff';\nimport { fetchWithRetry, withTimeout } from '../utils/resilience.js';\nimport type {\n EditFileInput,\n EditFileResult,\n EditFileConfig,\n EditChanges,\n MorphApplyResponse,\n} from './types.js';\n\nconst DEFAULT_CONFIG: Required<Omit<EditFileConfig, 'morphApiKey' | 'systemPrompt' | 'retryConfig'>> = {\n morphApiUrl: 'https://api.morphllm.com',\n baseDir: process.cwd(),\n generateUdiff: true,\n autoWrite: true,\n timeout: 30000,\n debug: false,\n};\n\n/**\n * FastApply client for programmatic file editing\n */\nexport class FastApplyClient {\n private config: EditFileConfig;\n\n constructor(config: { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {}) {\n this.config = {\n morphApiKey: config.apiKey,\n morphApiUrl: DEFAULT_CONFIG.morphApiUrl,\n debug: config.debug,\n timeout: config.timeout || DEFAULT_CONFIG.timeout,\n retryConfig: config.retryConfig,\n generateUdiff: DEFAULT_CONFIG.generateUdiff,\n autoWrite: DEFAULT_CONFIG.autoWrite,\n };\n }\n\n /**\n * Execute a file edit operation\n * \n * @param input - Edit parameters including filepath, instructions, and code_edit\n * @param overrides - Optional config overrides for this operation\n * @returns Edit result with success status and changes\n */\n async execute(input: EditFileInput, overrides?: Partial<EditFileConfig>): Promise<EditFileResult> {\n return executeEditFile(input, { ...this.config, ...overrides });\n }\n}\n\n/**\n * Generate a unified diff between two strings\n */\nexport function generateUdiff(\n original: string,\n modified: string,\n filepath: string\n): string {\n return createTwoFilesPatch(\n filepath,\n filepath,\n original,\n modified,\n 'Original',\n 'Modified'\n );\n}\n\n/**\n * Count changes from a unified diff\n */\nexport function countChanges(original: string, modified: string): EditChanges {\n const diff = generateUdiff(original, modified, 'file');\n const lines = diff.split('\\n');\n \n let linesAdded = 0;\n let linesRemoved = 0;\n \n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n linesAdded++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n linesRemoved++;\n }\n }\n \n const linesModified = Math.min(linesAdded, linesRemoved);\n \n return {\n linesAdded: linesAdded - linesModified,\n linesRemoved: linesRemoved - linesModified,\n linesModified,\n };\n}\n\n/**\n * Call Morph Apply API to merge code edits\n * Uses OpenAI-compatible chat completions endpoint with XML-formatted message\n */\nasync function callMorphAPI(\n originalCode: string,\n codeEdit: string,\n instructions: string,\n filepath: string,\n config: EditFileConfig\n): Promise<string> {\n const apiKey = config.morphApiKey || process.env.MORPH_API_KEY;\n const apiUrl = config.morphApiUrl || DEFAULT_CONFIG.morphApiUrl;\n const timeout = config.timeout || DEFAULT_CONFIG.timeout;\n const debug = config.debug || false;\n \n if (!apiKey) {\n throw new Error(\n 'Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config.'\n );\n }\n \n // Format message with XML tags as per Morph Fast Apply spec\n const message = `<instruction>${instructions}</instruction>\\n<code>${originalCode}</code>\\n<update>${codeEdit}</update>`;\n \n if (debug) {\n console.log(`[FastApply] Calling ${apiUrl}/v1/chat/completions`);\n console.log(`[FastApply] File: ${filepath}, Instructions: ${instructions.slice(0, 60)}...`);\n console.log(`[FastApply] Original: ${originalCode.length} chars, Edit: ${codeEdit.length} chars`);\n }\n \n const startTime = Date.now();\n \n // Fetch with retry and timeout\n const fetchPromise = fetchWithRetry(\n `${apiUrl}/v1/chat/completions`,\n {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': `Bearer ${apiKey}`,\n },\n body: JSON.stringify({\n model: 'morph-v3-fast',\n messages: [{ role: 'user', content: message }],\n }),\n },\n config.retryConfig\n );\n\n const response = await withTimeout(\n fetchPromise,\n timeout,\n `Morph API request timed out after ${timeout}ms`\n );\n \n if (!response.ok) {\n const error = await response.text();\n if (debug) console.error(`[FastApply] API error: ${response.status} - ${error}`);\n throw new Error(`Morph API error (${response.status}): ${error}`);\n }\n \n const data: MorphApplyResponse = await response.json();\n const elapsed = Date.now() - startTime;\n \n if (debug) {\n console.log(`[FastApply] ✅ Success in ${elapsed}ms, merged: ${data.choices[0].message.content.length} chars`);\n }\n \n return data.choices[0].message.content;\n}\n\n/**\n * Execute a file edit using Morph Fast Apply\n */\nexport async function executeEditFile(\n input: EditFileInput,\n config: EditFileConfig = {}\n): Promise<EditFileResult> {\n const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;\n const fullPath = resolve(join(baseDir, input.target_filepath));\n const debug = config.debug || false;\n \n // Security: ensure file is within baseDir\n const relativePath = relative(baseDir, fullPath);\n if (relativePath.startsWith('..') || fullPath === baseDir) {\n return {\n success: false,\n filepath: input.target_filepath,\n changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`,\n };\n }\n \n try {\n if (debug) console.log(`[FastApply] Reading file: ${input.target_filepath}`);\n const originalCode = await readFile(fullPath, 'utf-8');\n \n const mergedCode = await callMorphAPI(originalCode, input.code_edit, input.instructions, input.target_filepath, config);\n \n const udiff = config.generateUdiff !== false ? generateUdiff(originalCode, mergedCode, input.target_filepath) : undefined;\n \n if (config.autoWrite !== false) {\n await writeFile(fullPath, mergedCode, 'utf-8');\n if (debug) console.log(`[FastApply] Wrote ${mergedCode.length} chars to ${input.target_filepath}`);\n }\n \n const changes = countChanges(originalCode, mergedCode);\n \n return {\n success: true,\n filepath: input.target_filepath,\n udiff,\n changes,\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';\n if (debug) console.error(`[FastApply] Error: ${errorMessage}`);\n \n return {\n success: false,\n filepath: input.target_filepath,\n changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n error: errorMessage,\n };\n }\n}\n\n","/**\n * Resilience utilities for retry logic and timeout handling\n */\n\nexport interface RetryConfig {\n maxRetries?: number; // Default: 3\n initialDelay?: number; // Default: 1000ms\n maxDelay?: number; // Default: 30000ms\n backoffMultiplier?: number; // Default: 2\n retryableErrors?: string[]; // Default: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND']\n onRetry?: (attempt: number, error: Error) => void;\n}\n\nconst DEFAULT_RETRY_CONFIG: Required<Omit<RetryConfig, 'onRetry'>> = {\n maxRetries: 3,\n initialDelay: 1000,\n maxDelay: 30000,\n backoffMultiplier: 2,\n retryableErrors: ['ECONNREFUSED', 'ETIMEDOUT', 'ENOTFOUND'],\n};\n\n/**\n * Retry a fetch request with exponential backoff\n * \n * @param url - Request URL\n * @param options - Fetch options\n * @param retryConfig - Retry configuration\n * @returns Response from fetch\n * \n * @example\n * ```typescript\n * const response = await fetchWithRetry(\n * 'https://api.example.com/data',\n * { method: 'POST', body: JSON.stringify(data) },\n * { maxRetries: 5, initialDelay: 500 }\n * );\n * ```\n */\nexport async function fetchWithRetry(\n url: string,\n options: RequestInit,\n retryConfig: RetryConfig = {}\n): Promise<Response> {\n const {\n maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,\n initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,\n maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,\n backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,\n retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,\n onRetry,\n } = retryConfig;\n\n let lastError: Error | null = null;\n let delay = initialDelay;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const response = await fetch(url, options);\n \n // Retry on 429 (rate limit) or 503 (service unavailable)\n if (response.status === 429 || response.status === 503) {\n if (attempt < maxRetries) {\n // Check for Retry-After header\n const retryAfter = response.headers.get('Retry-After');\n const waitTime = retryAfter \n ? parseInt(retryAfter) * 1000 \n : Math.min(delay, maxDelay);\n \n const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);\n if (onRetry) {\n onRetry(attempt + 1, error);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n continue;\n }\n }\n\n return response;\n } catch (error) {\n lastError = error as Error;\n \n // Check if error is retryable\n const isRetryable = retryableErrors.some(errType => \n lastError?.message?.includes(errType)\n );\n\n if (!isRetryable || attempt === maxRetries) {\n throw lastError;\n }\n\n // Exponential backoff\n const waitTime = Math.min(delay, maxDelay);\n if (onRetry) {\n onRetry(attempt + 1, lastError);\n }\n \n await sleep(waitTime);\n delay *= backoffMultiplier;\n }\n }\n\n throw lastError || new Error('Max retries exceeded');\n}\n\n/**\n * Add timeout to any promise\n * \n * @param promise - Promise to wrap with timeout\n * @param timeoutMs - Timeout in milliseconds\n * @param errorMessage - Optional custom error message\n * @returns Promise that rejects if timeout is reached\n * \n * @example\n * ```typescript\n * const result = await withTimeout(\n * fetchData(),\n * 5000,\n * 'Data fetch timed out'\n * );\n * ```\n */\nexport async function withTimeout<T>(\n promise: Promise<T>,\n timeoutMs: number,\n errorMessage?: string\n): Promise<T> {\n let timeoutId: NodeJS.Timeout | number;\n \n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));\n }, timeoutMs);\n });\n\n try {\n const result = await Promise.race([promise, timeoutPromise]);\n clearTimeout(timeoutId!);\n return result;\n } catch (error) {\n clearTimeout(timeoutId!);\n throw error;\n }\n}\n\n/**\n * Sleep for specified milliseconds\n */\nfunction sleep(ms: number): Promise<void> {\n return new Promise(resolve => setTimeout(resolve, ms));\n}\n\n/**\n * Unified error type for all tools\n */\nexport class MorphError extends Error {\n constructor(\n message: string,\n public code: string,\n public statusCode?: number,\n public retryable: boolean = false\n ) {\n super(message);\n this.name = 'MorphError';\n }\n}\n\n\n","/**\n * System prompts for edit_file tool\n */\n\nexport const EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.\n\nThis 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.\n\nWhen writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.\n\nFor example:\n\n// ... existing code ...\nFIRST_EDIT\n// ... existing code ...\nSECOND_EDIT\n// ... existing code ...\nTHIRD_EDIT\n// ... existing code ...\n\nYou should still bias towards repeating as few lines of the original file as possible to convey the change.\nBut, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.\n\nDO 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.\n\nIf you plan on deleting a section, you must provide context before and after to delete it.\n\nMake sure it is clear what the edit should be, and where it should be applied.\nMake 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.`;\n\nexport const 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:\n\n// ... existing code ...\n{{ edit_1 }}\n// ... existing code ...\n{{ edit_2 }}\n// ... existing code ...\n\nOften 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.\n\nThese 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.`;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIA,sBAAoC;AACpC,kBAAwC;AACxC,kBAAoC;;;ACOpC,IAAM,uBAA+D;AAAA,EACnE,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,iBAAiB,CAAC,gBAAgB,aAAa,WAAW;AAC5D;AAmBA,eAAsB,eACpB,KACA,SACA,cAA2B,CAAC,GACT;AACnB,QAAM;AAAA,IACJ,aAAa,qBAAqB;AAAA,IAClC,eAAe,qBAAqB;AAAA,IACpC,WAAW,qBAAqB;AAAA,IAChC,oBAAoB,qBAAqB;AAAA,IACzC,kBAAkB,qBAAqB;AAAA,IACvC;AAAA,EACF,IAAI;AAEJ,MAAI,YAA0B;AAC9B,MAAI,QAAQ;AAEZ,WAAS,UAAU,GAAG,WAAW,YAAY,WAAW;AACtD,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,KAAK,OAAO;AAGzC,UAAI,SAAS,WAAW,OAAO,SAAS,WAAW,KAAK;AACtD,YAAI,UAAU,YAAY;AAExB,gBAAM,aAAa,SAAS,QAAQ,IAAI,aAAa;AACrD,gBAAM,WAAW,aACb,SAAS,UAAU,IAAI,MACvB,KAAK,IAAI,OAAO,QAAQ;AAE5B,gBAAM,QAAQ,IAAI,MAAM,QAAQ,SAAS,MAAM,oBAAoB,QAAQ,IAAI;AAC/E,cAAI,SAAS;AACX,oBAAQ,UAAU,GAAG,KAAK;AAAA,UAC5B;AAEA,gBAAM,MAAM,QAAQ;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|
|
3
|
+
editFileTool,
|
|
4
|
+
execute,
|
|
5
|
+
formatResult,
|
|
6
|
+
getSystemPrompt,
|
|
7
|
+
openai_default
|
|
8
|
+
} from "../../chunk-YWS2GRQC.js";
|
|
9
|
+
import "../../chunk-63WE2C5R.js";
|
|
10
|
+
import "../../chunk-4V46N27D.js";
|
|
11
|
+
import "../../chunk-4VWJFZVS.js";
|
|
12
|
+
import "../../chunk-PZ5AY32C.js";
|
|
13
|
+
export {
|
|
14
|
+
createEditFileTool,
|
|
15
|
+
openai_default as default,
|
|
16
|
+
editFileTool,
|
|
17
|
+
execute,
|
|
18
|
+
formatResult,
|
|
19
|
+
getSystemPrompt
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=openai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// tools/fastapply/prompts.ts
|
|
21
|
+
var prompts_exports = {};
|
|
22
|
+
__export(prompts_exports, {
|
|
23
|
+
EDIT_FILE_SYSTEM_PROMPT: () => EDIT_FILE_SYSTEM_PROMPT,
|
|
24
|
+
EDIT_FILE_TOOL_DESCRIPTION: () => EDIT_FILE_TOOL_DESCRIPTION
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(prompts_exports);
|
|
27
|
+
var EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
|
|
33
|
+
For example:
|
|
34
|
+
|
|
35
|
+
// ... existing code ...
|
|
36
|
+
FIRST_EDIT
|
|
37
|
+
// ... existing code ...
|
|
38
|
+
SECOND_EDIT
|
|
39
|
+
// ... existing code ...
|
|
40
|
+
THIRD_EDIT
|
|
41
|
+
// ... existing code ...
|
|
42
|
+
|
|
43
|
+
You should still bias towards repeating as few lines of the original file as possible to convey the change.
|
|
44
|
+
But, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.
|
|
45
|
+
|
|
46
|
+
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.
|
|
47
|
+
|
|
48
|
+
If you plan on deleting a section, you must provide context before and after to delete it.
|
|
49
|
+
|
|
50
|
+
Make sure it is clear what the edit should be, and where it should be applied.
|
|
51
|
+
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.`;
|
|
52
|
+
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:
|
|
53
|
+
|
|
54
|
+
// ... existing code ...
|
|
55
|
+
{{ edit_1 }}
|
|
56
|
+
// ... existing code ...
|
|
57
|
+
{{ edit_2 }}
|
|
58
|
+
// ... existing code ...
|
|
59
|
+
|
|
60
|
+
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.
|
|
61
|
+
|
|
62
|
+
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.`;
|
|
63
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
64
|
+
0 && (module.exports = {
|
|
65
|
+
EDIT_FILE_SYSTEM_PROMPT,
|
|
66
|
+
EDIT_FILE_TOOL_DESCRIPTION
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=prompts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../tools/fastapply/prompts.ts"],"sourcesContent":["/**\n * System prompts for edit_file tool\n */\n\nexport const EDIT_FILE_TOOL_DESCRIPTION = `Use this tool to make an edit to an existing file.\n\nThis 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.\n\nWhen writing the edit, you should specify each edit in sequence, with the special comment // ... existing code ... to represent unchanged code in between edited lines.\n\nFor example:\n\n// ... existing code ...\nFIRST_EDIT\n// ... existing code ...\nSECOND_EDIT\n// ... existing code ...\nTHIRD_EDIT\n// ... existing code ...\n\nYou should still bias towards repeating as few lines of the original file as possible to convey the change.\nBut, each edit should contain minimally sufficient context of unchanged lines around the code you're editing to resolve ambiguity.\n\nDO 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.\n\nIf you plan on deleting a section, you must provide context before and after to delete it.\n\nMake sure it is clear what the edit should be, and where it should be applied.\nMake 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.`;\n\nexport const 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:\n\n// ... existing code ...\n{{ edit_1 }}\n// ... existing code ...\n{{ edit_2 }}\n// ... existing code ...\n\nOften 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.\n\nThese 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.`;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIO,IAAM,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA0BnC,IAAM,0BAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// tools/fastapply/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../tools/fastapply/types.ts"],"sourcesContent":["/**\n * Core types for Morph Fast Apply SDK\n */\n\nimport type { RetryConfig } from '../utils/resilience.js';\n\n/**\n * Input parameters for the edit_file tool\n */\nexport interface EditFileInput {\n /** Path to the file to edit (relative to baseDir) */\n target_filepath: string;\n /** First-person description of what you're changing */\n instructions: string;\n /** Lazy edit with // ... existing code ... markers */\n code_edit: string;\n}\n\n/**\n * Statistics about the changes made\n */\nexport interface EditChanges {\n linesAdded: number;\n linesRemoved: number;\n linesModified: number;\n}\n\n/**\n * Result returned after executing an edit\n */\nexport interface EditFileResult {\n /** Whether the edit was successful */\n success: boolean;\n /** Path to the edited file */\n filepath: string;\n /** Universal diff format showing changes */\n udiff?: string;\n /** Statistics about the changes */\n changes: EditChanges;\n /** Error message if unsuccessful */\n error?: string;\n}\n\n/**\n * Configuration options for the edit_file tool\n */\nexport interface EditFileConfig {\n /** Morph API key (defaults to MORPH_API_KEY env var) */\n morphApiKey?: string;\n /** Morph API base URL */\n morphApiUrl?: string;\n /** Base directory for file operations (defaults to cwd) */\n baseDir?: string;\n /** Whether to generate udiff (default: true) */\n generateUdiff?: boolean;\n /** Whether to automatically write to file (default: true) */\n autoWrite?: boolean;\n /** Custom system prompt (null to disable) */\n systemPrompt?: string | null;\n /** Timeout for API calls in ms (default: 30000) */\n timeout?: number;\n /** Retry configuration for API calls */\n retryConfig?: RetryConfig;\n /** Enable debug logging (default: false) */\n debug?: boolean;\n}\n\n/**\n * Response from Morph Apply API\n */\nexport interface MorphApplyResponse {\n choices: Array<{\n message: {\n content: string;\n };\n }>;\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|