@morphllm/morphsdk 0.2.112 → 0.2.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/{chunk-EQHP36A2.js → chunk-3U7AWFBN.js} +5 -5
  2. package/dist/{chunk-2MAUPERG.js → chunk-FXBT4UDY.js} +19 -34
  3. package/dist/chunk-FXBT4UDY.js.map +1 -0
  4. package/dist/{chunk-HDRLLCAD.js → chunk-HMAX2FEE.js} +2 -2
  5. package/dist/{chunk-TLC3QKE6.js → chunk-M5DR2WOZ.js} +4 -3
  6. package/dist/{chunk-TLC3QKE6.js.map → chunk-M5DR2WOZ.js.map} +1 -1
  7. package/dist/{chunk-I3IN742Q.js → chunk-UNHHRMU7.js} +2 -2
  8. package/dist/{chunk-KQP6ZPYB.js → chunk-Y5BB7JFH.js} +2 -2
  9. package/dist/client.cjs +99 -123
  10. package/dist/client.cjs.map +1 -1
  11. package/dist/client.js +6 -6
  12. package/dist/edge.cjs +102 -104
  13. package/dist/edge.cjs.map +1 -1
  14. package/dist/edge.js +1 -1
  15. package/dist/index.cjs +99 -123
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +6 -6
  18. package/dist/tools/fastapply/anthropic.cjs +22 -112
  19. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  20. package/dist/tools/fastapply/anthropic.js +3 -4
  21. package/dist/tools/fastapply/apply.cjs +28 -104
  22. package/dist/tools/fastapply/apply.cjs.map +1 -1
  23. package/dist/tools/fastapply/apply.d.ts +7 -3
  24. package/dist/tools/fastapply/apply.js +1 -2
  25. package/dist/tools/fastapply/core.cjs +22 -112
  26. package/dist/tools/fastapply/core.cjs.map +1 -1
  27. package/dist/tools/fastapply/core.js +2 -3
  28. package/dist/tools/fastapply/index.cjs +22 -112
  29. package/dist/tools/fastapply/index.cjs.map +1 -1
  30. package/dist/tools/fastapply/index.js +5 -6
  31. package/dist/tools/fastapply/openai.cjs +22 -112
  32. package/dist/tools/fastapply/openai.cjs.map +1 -1
  33. package/dist/tools/fastapply/openai.js +3 -4
  34. package/dist/tools/fastapply/types.cjs.map +1 -1
  35. package/dist/tools/fastapply/types.d.ts +5 -0
  36. package/dist/tools/fastapply/vercel.cjs +22 -112
  37. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  38. package/dist/tools/fastapply/vercel.js +3 -4
  39. package/dist/tools/index.cjs +22 -112
  40. package/dist/tools/index.cjs.map +1 -1
  41. package/dist/tools/index.js +5 -6
  42. package/package.json +1 -1
  43. package/dist/chunk-2MAUPERG.js.map +0 -1
  44. /package/dist/{chunk-EQHP36A2.js.map → chunk-3U7AWFBN.js.map} +0 -0
  45. /package/dist/{chunk-HDRLLCAD.js.map → chunk-HMAX2FEE.js.map} +0 -0
  46. /package/dist/{chunk-I3IN742Q.js.map → chunk-UNHHRMU7.js.map} +0 -0
  47. /package/dist/{chunk-KQP6ZPYB.js.map → chunk-Y5BB7JFH.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -30,86 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // tools/utils/resilience.ts
34
- async function fetchWithRetry(url, options, retryConfig = {}) {
35
- const {
36
- maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
37
- initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
38
- maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
39
- backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
40
- retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
41
- onRetry
42
- } = retryConfig;
43
- let lastError = null;
44
- let delay = initialDelay;
45
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
46
- try {
47
- const response = await fetch(url, options);
48
- if (response.status === 429 || response.status === 503) {
49
- if (attempt < maxRetries) {
50
- const retryAfter = response.headers.get("Retry-After");
51
- const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
52
- const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
53
- if (onRetry) {
54
- onRetry(attempt + 1, error);
55
- }
56
- await sleep(waitTime);
57
- delay *= backoffMultiplier;
58
- continue;
59
- }
60
- }
61
- return response;
62
- } catch (error) {
63
- lastError = error;
64
- const isRetryable = retryableErrors.some(
65
- (errType) => lastError?.message?.includes(errType)
66
- );
67
- if (!isRetryable || attempt === maxRetries) {
68
- throw lastError;
69
- }
70
- const waitTime = Math.min(delay, maxDelay);
71
- if (onRetry) {
72
- onRetry(attempt + 1, lastError);
73
- }
74
- await sleep(waitTime);
75
- delay *= backoffMultiplier;
76
- }
77
- }
78
- throw lastError || new Error("Max retries exceeded");
79
- }
80
- async function withTimeout(promise, timeoutMs, errorMessage) {
81
- let timeoutId;
82
- const timeoutPromise = new Promise((_, reject) => {
83
- timeoutId = setTimeout(() => {
84
- reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
85
- }, timeoutMs);
86
- });
87
- try {
88
- const result = await Promise.race([promise, timeoutPromise]);
89
- clearTimeout(timeoutId);
90
- return result;
91
- } catch (error) {
92
- clearTimeout(timeoutId);
93
- throw error;
94
- }
95
- }
96
- function sleep(ms) {
97
- return new Promise((resolve2) => setTimeout(resolve2, ms));
98
- }
99
- var DEFAULT_RETRY_CONFIG;
100
- var init_resilience = __esm({
101
- "tools/utils/resilience.ts"() {
102
- "use strict";
103
- DEFAULT_RETRY_CONFIG = {
104
- maxRetries: 3,
105
- initialDelay: 1e3,
106
- maxDelay: 3e4,
107
- backoffMultiplier: 2,
108
- retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
109
- };
110
- }
111
- });
112
-
113
33
  // tools/fastapply/apply.ts
114
34
  var apply_exports = {};
115
35
  __export(apply_exports, {
@@ -166,37 +86,25 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
166
86
  console.log(`[FastApply] Original: ${originalCode.length} chars, Edit: ${codeEdit.length} chars`);
167
87
  }
168
88
  const startTime = Date.now();
169
- const fetchPromise = fetchWithRetry(
170
- `${apiUrl}/v1/chat/completions`,
171
- {
172
- method: "POST",
173
- headers: {
174
- "Content-Type": "application/json",
175
- "Authorization": `Bearer ${apiKey}`
176
- },
177
- body: JSON.stringify({
178
- model: "morph-v3-fast",
179
- messages: [{ role: "user", content: message }]
180
- })
181
- },
182
- config.retryConfig
183
- );
184
- const response = await withTimeout(
185
- fetchPromise,
89
+ const client = new import_openai.default({
90
+ apiKey,
91
+ baseURL: `${apiUrl}/v1`,
186
92
  timeout,
187
- `Morph API request timed out after ${timeout}ms`
188
- );
189
- if (!response.ok) {
190
- const error = await response.text();
191
- if (debug) console.error(`[FastApply] API error: ${response.status} - ${error}`);
192
- throw new Error(`Morph API error (${response.status}): ${error}`);
93
+ maxRetries: config.retryConfig?.maxRetries ?? 3
94
+ });
95
+ const completion = await client.chat.completions.create({
96
+ model: "morph-v3-fast",
97
+ messages: [{ role: "user", content: message }]
98
+ });
99
+ const content = completion.choices[0]?.message?.content;
100
+ if (!content) {
101
+ throw new Error("Morph API returned empty response");
193
102
  }
194
- const data = await response.json();
195
103
  const elapsed = Date.now() - startTime;
196
104
  if (debug) {
197
- console.log(`[FastApply] \u2705 Success in ${elapsed}ms, merged: ${data.choices[0].message.content.length} chars`);
105
+ console.log(`[FastApply] Success in ${elapsed}ms, merged: ${content.length} chars`);
198
106
  }
199
- return data.choices[0].message.content;
107
+ return { content, completionId: completion.id };
200
108
  }
201
109
  async function applyEdit(input, config = {}) {
202
110
  const debug = config.debug || false;
@@ -205,7 +113,7 @@ async function applyEdit(input, config = {}) {
205
113
  if (debug) {
206
114
  console.log(`[FastApply] Applying edit to code (${input.originalCode.length} chars)`);
207
115
  }
208
- const mergedCode = await callMorphAPI(
116
+ const { content: mergedCode, completionId } = await callMorphAPI(
209
117
  input.originalCode,
210
118
  input.codeEdit,
211
119
  input.instructions,
@@ -218,7 +126,8 @@ async function applyEdit(input, config = {}) {
218
126
  success: true,
219
127
  mergedCode,
220
128
  udiff,
221
- changes
129
+ changes,
130
+ completionId
222
131
  };
223
132
  } catch (error) {
224
133
  const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
@@ -230,12 +139,12 @@ async function applyEdit(input, config = {}) {
230
139
  };
231
140
  }
232
141
  }
233
- var import_diff, DEFAULT_API_URL, DEFAULT_TIMEOUT;
142
+ var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT;
234
143
  var init_apply = __esm({
235
144
  "tools/fastapply/apply.ts"() {
236
145
  "use strict";
237
146
  import_diff = require("diff");
238
- init_resilience();
147
+ import_openai = __toESM(require("openai"), 1);
239
148
  DEFAULT_API_URL = "https://api.morphllm.com";
240
149
  DEFAULT_TIMEOUT = 3e4;
241
150
  }
@@ -886,7 +795,7 @@ async function executeEditFile(input, config = {}) {
886
795
  }
887
796
  if (debug) console.log(`[FastApply] File doesn't exist, will create new file`);
888
797
  }
889
- const mergedCode = await callMorphAPI2(originalCode, input.code_edit, input.instructions, input.target_filepath, config);
798
+ const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, input.instructions, input.target_filepath, config);
890
799
  const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
891
800
  if (config.autoWrite !== false) {
892
801
  await writeFile(fullPath, mergedCode, "utf-8");
@@ -897,7 +806,8 @@ async function executeEditFile(input, config = {}) {
897
806
  success: true,
898
807
  filepath: input.target_filepath,
899
808
  udiff,
900
- changes
809
+ changes,
810
+ completionId
901
811
  };
902
812
  } catch (error) {
903
813
  const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
@@ -911,8 +821,81 @@ async function executeEditFile(input, config = {}) {
911
821
  }
912
822
  }
913
823
 
824
+ // tools/utils/resilience.ts
825
+ var DEFAULT_RETRY_CONFIG = {
826
+ maxRetries: 3,
827
+ initialDelay: 1e3,
828
+ maxDelay: 3e4,
829
+ backoffMultiplier: 2,
830
+ retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
831
+ };
832
+ async function fetchWithRetry(url, options, retryConfig = {}) {
833
+ const {
834
+ maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
835
+ initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
836
+ maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
837
+ backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
838
+ retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
839
+ onRetry
840
+ } = retryConfig;
841
+ let lastError = null;
842
+ let delay = initialDelay;
843
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
844
+ try {
845
+ const response = await fetch(url, options);
846
+ if (response.status === 429 || response.status === 503) {
847
+ if (attempt < maxRetries) {
848
+ const retryAfter = response.headers.get("Retry-After");
849
+ const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
850
+ const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
851
+ if (onRetry) {
852
+ onRetry(attempt + 1, error);
853
+ }
854
+ await sleep(waitTime);
855
+ delay *= backoffMultiplier;
856
+ continue;
857
+ }
858
+ }
859
+ return response;
860
+ } catch (error) {
861
+ lastError = error;
862
+ const isRetryable = retryableErrors.some(
863
+ (errType) => lastError?.message?.includes(errType)
864
+ );
865
+ if (!isRetryable || attempt === maxRetries) {
866
+ throw lastError;
867
+ }
868
+ const waitTime = Math.min(delay, maxDelay);
869
+ if (onRetry) {
870
+ onRetry(attempt + 1, lastError);
871
+ }
872
+ await sleep(waitTime);
873
+ delay *= backoffMultiplier;
874
+ }
875
+ }
876
+ throw lastError || new Error("Max retries exceeded");
877
+ }
878
+ async function withTimeout(promise, timeoutMs, errorMessage) {
879
+ let timeoutId;
880
+ const timeoutPromise = new Promise((_, reject) => {
881
+ timeoutId = setTimeout(() => {
882
+ reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
883
+ }, timeoutMs);
884
+ });
885
+ try {
886
+ const result = await Promise.race([promise, timeoutPromise]);
887
+ clearTimeout(timeoutId);
888
+ return result;
889
+ } catch (error) {
890
+ clearTimeout(timeoutId);
891
+ throw error;
892
+ }
893
+ }
894
+ function sleep(ms) {
895
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
896
+ }
897
+
914
898
  // tools/codebase_search/core.ts
915
- init_resilience();
916
899
  var CodebaseSearchClient = class {
917
900
  config;
918
901
  constructor(config = {}) {
@@ -1007,9 +990,6 @@ async function executeCodebaseSearch(input, config) {
1007
990
  }
1008
991
  }
1009
992
 
1010
- // tools/browser/core.ts
1011
- init_resilience();
1012
-
1013
993
  // tools/browser/live.ts
1014
994
  var LIVE_PRESETS = {
1015
995
  /** Read-only monitoring (no interaction) */
@@ -1110,9 +1090,6 @@ function resolvePreset(optionsOrPreset) {
1110
1090
  return optionsOrPreset;
1111
1091
  }
1112
1092
 
1113
- // tools/browser/profiles/core.ts
1114
- init_resilience();
1115
-
1116
1093
  // tools/browser/errors.ts
1117
1094
  var MorphError = class extends Error {
1118
1095
  /** Error code for programmatic handling */
@@ -3042,7 +3019,7 @@ function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS
3042
3019
  }
3043
3020
 
3044
3021
  // tools/warp_grep/agent/runner.ts
3045
- var import_openai = __toESM(require("openai"), 1);
3022
+ var import_openai2 = __toESM(require("openai"), 1);
3046
3023
  var import_path3 = __toESM(require("path"), 1);
3047
3024
  var parser = new LLMResponseParser();
3048
3025
  var DEFAULT_API_URL3 = "https://api.morphllm.com";
@@ -3050,7 +3027,7 @@ async function callModel(messages, model, options = {}) {
3050
3027
  const baseUrl = options.morphApiUrl || DEFAULT_API_URL3;
3051
3028
  const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
3052
3029
  const timeoutMs = options.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
3053
- const client = new import_openai.default({
3030
+ const client = new import_openai2.default({
3054
3031
  apiKey,
3055
3032
  baseURL: `${baseUrl}/v1`,
3056
3033
  maxRetries: options.retryConfig?.maxRetries,
@@ -3065,7 +3042,7 @@ async function callModel(messages, model, options = {}) {
3065
3042
  messages
3066
3043
  });
3067
3044
  } catch (error) {
3068
- if (error instanceof import_openai.default.APIError && error.status === 404) {
3045
+ if (error instanceof import_openai2.default.APIError && error.status === 404) {
3069
3046
  throw new Error(
3070
3047
  "The endpoint you are trying to call is likely deprecated. Please update with: npm cache clean --force && npx -y @morphllm/morphmcp@latest or visit: https://morphllm.com/mcp"
3071
3048
  );
@@ -4572,7 +4549,6 @@ var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
4572
4549
  var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
4573
4550
 
4574
4551
  // modelrouter/core.ts
4575
- init_resilience();
4576
4552
  var DEFAULT_CONFIG3 = {
4577
4553
  apiUrl: "https://api.morphllm.com",
4578
4554
  timeout: 5e3,