@morphllm/morphsdk 0.2.113 → 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 (45) hide show
  1. package/dist/{chunk-2SOSDQFG.js → chunk-3U7AWFBN.js} +5 -5
  2. package/dist/{chunk-Z6TF5G4R.js → chunk-FXBT4UDY.js} +16 -32
  3. package/dist/chunk-FXBT4UDY.js.map +1 -0
  4. package/dist/{chunk-TGUQHW3I.js → chunk-HMAX2FEE.js} +2 -2
  5. package/dist/{chunk-R3BSIJCL.js → chunk-M5DR2WOZ.js} +1 -1
  6. package/dist/{chunk-A3PK4H7A.js → chunk-UNHHRMU7.js} +2 -2
  7. package/dist/{chunk-JD4H6U3Z.js → chunk-Y5BB7JFH.js} +2 -2
  8. package/dist/client.cjs +93 -119
  9. package/dist/client.cjs.map +1 -1
  10. package/dist/client.js +6 -6
  11. package/dist/edge.cjs +99 -102
  12. package/dist/edge.cjs.map +1 -1
  13. package/dist/edge.js +1 -1
  14. package/dist/index.cjs +93 -119
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.js +6 -6
  17. package/dist/tools/fastapply/anthropic.cjs +16 -108
  18. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  19. package/dist/tools/fastapply/anthropic.js +3 -4
  20. package/dist/tools/fastapply/apply.cjs +25 -102
  21. package/dist/tools/fastapply/apply.cjs.map +1 -1
  22. package/dist/tools/fastapply/apply.d.ts +3 -2
  23. package/dist/tools/fastapply/apply.js +1 -2
  24. package/dist/tools/fastapply/core.cjs +16 -108
  25. package/dist/tools/fastapply/core.cjs.map +1 -1
  26. package/dist/tools/fastapply/core.js +2 -3
  27. package/dist/tools/fastapply/index.cjs +16 -108
  28. package/dist/tools/fastapply/index.cjs.map +1 -1
  29. package/dist/tools/fastapply/index.js +5 -6
  30. package/dist/tools/fastapply/openai.cjs +16 -108
  31. package/dist/tools/fastapply/openai.cjs.map +1 -1
  32. package/dist/tools/fastapply/openai.js +3 -4
  33. package/dist/tools/fastapply/vercel.cjs +16 -108
  34. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  35. package/dist/tools/fastapply/vercel.js +3 -4
  36. package/dist/tools/index.cjs +16 -108
  37. package/dist/tools/index.cjs.map +1 -1
  38. package/dist/tools/index.js +5 -6
  39. package/package.json +1 -1
  40. package/dist/chunk-Z6TF5G4R.js.map +0 -1
  41. /package/dist/{chunk-2SOSDQFG.js.map → chunk-3U7AWFBN.js.map} +0 -0
  42. /package/dist/{chunk-TGUQHW3I.js.map → chunk-HMAX2FEE.js.map} +0 -0
  43. /package/dist/{chunk-R3BSIJCL.js.map → chunk-M5DR2WOZ.js.map} +0 -0
  44. /package/dist/{chunk-A3PK4H7A.js.map → chunk-UNHHRMU7.js.map} +0 -0
  45. /package/dist/{chunk-JD4H6U3Z.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 { content: data.choices[0].message.content, completionId: data.id };
107
+ return { content, completionId: completion.id };
200
108
  }
201
109
  async function applyEdit(input, config = {}) {
202
110
  const debug = config.debug || false;
@@ -231,12 +139,12 @@ async function applyEdit(input, config = {}) {
231
139
  };
232
140
  }
233
141
  }
234
- var import_diff, DEFAULT_API_URL, DEFAULT_TIMEOUT;
142
+ var import_diff, import_openai, DEFAULT_API_URL, DEFAULT_TIMEOUT;
235
143
  var init_apply = __esm({
236
144
  "tools/fastapply/apply.ts"() {
237
145
  "use strict";
238
146
  import_diff = require("diff");
239
- init_resilience();
147
+ import_openai = __toESM(require("openai"), 1);
240
148
  DEFAULT_API_URL = "https://api.morphllm.com";
241
149
  DEFAULT_TIMEOUT = 3e4;
242
150
  }
@@ -913,8 +821,81 @@ async function executeEditFile(input, config = {}) {
913
821
  }
914
822
  }
915
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
+
916
898
  // tools/codebase_search/core.ts
917
- init_resilience();
918
899
  var CodebaseSearchClient = class {
919
900
  config;
920
901
  constructor(config = {}) {
@@ -1009,9 +990,6 @@ async function executeCodebaseSearch(input, config) {
1009
990
  }
1010
991
  }
1011
992
 
1012
- // tools/browser/core.ts
1013
- init_resilience();
1014
-
1015
993
  // tools/browser/live.ts
1016
994
  var LIVE_PRESETS = {
1017
995
  /** Read-only monitoring (no interaction) */
@@ -1112,9 +1090,6 @@ function resolvePreset(optionsOrPreset) {
1112
1090
  return optionsOrPreset;
1113
1091
  }
1114
1092
 
1115
- // tools/browser/profiles/core.ts
1116
- init_resilience();
1117
-
1118
1093
  // tools/browser/errors.ts
1119
1094
  var MorphError = class extends Error {
1120
1095
  /** Error code for programmatic handling */
@@ -3044,7 +3019,7 @@ function enforceContextLimit(messages, maxChars = AGENT_CONFIG.MAX_CONTEXT_CHARS
3044
3019
  }
3045
3020
 
3046
3021
  // tools/warp_grep/agent/runner.ts
3047
- var import_openai = __toESM(require("openai"), 1);
3022
+ var import_openai2 = __toESM(require("openai"), 1);
3048
3023
  var import_path3 = __toESM(require("path"), 1);
3049
3024
  var parser = new LLMResponseParser();
3050
3025
  var DEFAULT_API_URL3 = "https://api.morphllm.com";
@@ -3052,7 +3027,7 @@ async function callModel(messages, model, options = {}) {
3052
3027
  const baseUrl = options.morphApiUrl || DEFAULT_API_URL3;
3053
3028
  const apiKey = options.morphApiKey || process.env.MORPH_API_KEY || "";
3054
3029
  const timeoutMs = options.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
3055
- const client = new import_openai.default({
3030
+ const client = new import_openai2.default({
3056
3031
  apiKey,
3057
3032
  baseURL: `${baseUrl}/v1`,
3058
3033
  maxRetries: options.retryConfig?.maxRetries,
@@ -3067,7 +3042,7 @@ async function callModel(messages, model, options = {}) {
3067
3042
  messages
3068
3043
  });
3069
3044
  } catch (error) {
3070
- if (error instanceof import_openai.default.APIError && error.status === 404) {
3045
+ if (error instanceof import_openai2.default.APIError && error.status === 404) {
3071
3046
  throw new Error(
3072
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"
3073
3048
  );
@@ -4574,7 +4549,6 @@ var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
4574
4549
  var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
4575
4550
 
4576
4551
  // modelrouter/core.ts
4577
- init_resilience();
4578
4552
  var DEFAULT_CONFIG3 = {
4579
4553
  apiUrl: "https://api.morphllm.com",
4580
4554
  timeout: 5e3,