@morphllm/morphsdk 0.2.201 → 0.2.203

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/chunk-2PPYWRMZ.js +3 -4
  2. package/dist/{chunk-DBNSOYQ3.js → chunk-2UIOCSVJ.js} +3 -24
  3. package/dist/chunk-44OIEPIO.js +4 -23
  4. package/dist/chunk-4EQQGUZ7.cjs +104 -0
  5. package/dist/chunk-4OUGA3KS.js +1 -5
  6. package/dist/chunk-4R5MDGL6.cjs +280 -0
  7. package/dist/chunk-65W4I66Q.cjs +103 -0
  8. package/dist/{chunk-WBTXEJOC.js → chunk-66THRMD7.js} +10 -35
  9. package/dist/chunk-6TZCVTW5.js +3 -4
  10. package/dist/chunk-6WP7EA4F.js +2 -4
  11. package/dist/chunk-74A4HLIO.cjs +42 -0
  12. package/dist/chunk-75ZPJI57.cjs +9 -0
  13. package/dist/chunk-7NA7X7W2.cjs +77 -0
  14. package/dist/chunk-7PJYY46L.cjs +2 -0
  15. package/dist/chunk-AFF6XYKL.cjs +71 -0
  16. package/dist/{chunk-P2KW2O5R.js → chunk-AJBZA23L.js} +3 -25
  17. package/dist/chunk-AWFZKS27.cjs +11 -0
  18. package/dist/{chunk-FVT4PU4I.js → chunk-AXEKIRRY.js} +22 -62
  19. package/dist/chunk-B3FD67F2.cjs +256 -0
  20. package/dist/chunk-BJBWWIZV.cjs +2 -0
  21. package/dist/{chunk-M6AVXUM4.js → chunk-E3XNKAMI.js} +5 -15
  22. package/dist/{chunk-TS3OJ4LA.js → chunk-E7FLETFO.js} +2 -8
  23. package/dist/{chunk-EQAWWVKV.js → chunk-EI2M567U.js} +2 -6
  24. package/dist/chunk-EJTL2BOZ.cjs +42 -0
  25. package/dist/chunk-ETBRAKVV.js +1 -5
  26. package/dist/{chunk-VOXUA5ZH.js → chunk-EZ2OFDBJ.js} +5 -19
  27. package/dist/chunk-FBOZIVVQ.js +1 -0
  28. package/dist/{chunk-TZC3EOZS.js → chunk-GDFPZ3NJ.js} +4 -19
  29. package/dist/{chunk-LISSWRUD.js → chunk-GIQAIHUI.js} +8 -33
  30. package/dist/chunk-GSUQGDCL.cjs +235 -0
  31. package/dist/{chunk-5NSYDT36.js → chunk-H3HRSRR5.js} +4 -12
  32. package/dist/chunk-HDP4QAZL.js +1 -4
  33. package/dist/chunk-HMLYJVZM.cjs +410 -0
  34. package/dist/chunk-IPJA3ZS6.cjs +10 -0
  35. package/dist/{chunk-B376VMIH.js → chunk-IUM6CQYX.js} +3 -12
  36. package/dist/{chunk-OVLUL5AC.js → chunk-J56Q6C4Y.js} +4 -18
  37. package/dist/chunk-JBTR3FQD.cjs +135 -0
  38. package/dist/chunk-JNQKQKHS.cjs +81 -0
  39. package/dist/chunk-JOZC4T6C.cjs +168 -0
  40. package/dist/{chunk-ILY5N5NJ.js → chunk-JUGNTIVU.js} +6 -19
  41. package/dist/{chunk-SU7AAS3O.js → chunk-JY6COF3X.js} +5 -22
  42. package/dist/{chunk-JBAY3PRV.js → chunk-KLVJIC2O.js} +5 -17
  43. package/dist/chunk-KSZYOX6S.cjs +91 -0
  44. package/dist/chunk-KVGZ2TSG.cjs +274 -0
  45. package/dist/chunk-LDM7RNNN.js +1 -0
  46. package/dist/{chunk-RZOJ4GSY.js → chunk-LLQH6CCB.js} +10 -28
  47. package/dist/chunk-M34E2AMK.js +1 -5
  48. package/dist/chunk-MF56KEI4.js +1 -4
  49. package/dist/chunk-MLKGABMK.js +1 -3
  50. package/dist/{chunk-I26FQELI.js → chunk-MLPZKUCO.js} +11 -5
  51. package/dist/chunk-MWXJ6DZ2.cjs +21 -0
  52. package/dist/{chunk-NWGRW4V7.js → chunk-N7UKZ5X7.js} +2 -6
  53. package/dist/chunk-NDUC7OV6.cjs +74 -0
  54. package/dist/{chunk-RJXAXR7Q.js → chunk-NLACTMZT.js} +6 -19
  55. package/dist/chunk-NNKBKENK.cjs +15 -0
  56. package/dist/chunk-NRG6QX3L.js +1 -3
  57. package/dist/chunk-OCCGJ4S6.js +8 -0
  58. package/dist/chunk-ODY2NKQU.cjs +50 -0
  59. package/dist/chunk-OM5ZSXQW.cjs +91 -0
  60. package/dist/chunk-OOEORM7H.cjs +334 -0
  61. package/dist/chunk-OPDWMD4Q.js +1 -3
  62. package/dist/{chunk-BZXOAC2R.js → chunk-OSL4CNSO.js} +7 -23
  63. package/dist/chunk-OXXMTDOY.cjs +86 -0
  64. package/dist/chunk-PA3UTI4A.js +1 -4
  65. package/dist/chunk-QEEAIXL5.cjs +74 -0
  66. package/dist/chunk-RYVW7RUM.js +2 -6
  67. package/dist/chunk-S6QBPXBI.cjs +107 -0
  68. package/dist/chunk-TL34BLQD.cjs +10 -0
  69. package/dist/chunk-TPZHMD7J.cjs +72 -0
  70. package/dist/chunk-UAPK3AIJ.js +1 -10
  71. package/dist/chunk-UF5IKELS.cjs +26 -0
  72. package/dist/chunk-UNX7V6P6.cjs +60 -0
  73. package/dist/chunk-UUCRWJJR.cjs +313 -0
  74. package/dist/chunk-VDFLPO7B.cjs +396 -0
  75. package/dist/chunk-VHD7CW5O.cjs +43 -0
  76. package/dist/chunk-VL4QNALG.cjs +50 -0
  77. package/dist/chunk-WR7LSUIR.cjs +213 -0
  78. package/dist/chunk-XE6D4J63.cjs +72 -0
  79. package/dist/chunk-ZLG2M2I4.cjs +21 -0
  80. package/dist/chunk-ZSHVXDA2.js +4 -10
  81. package/dist/client.cjs +40 -4353
  82. package/dist/client.js +32 -37
  83. package/dist/core/client.cjs +10 -476
  84. package/dist/core/client.js +6 -11
  85. package/dist/core/error.cjs +8 -251
  86. package/dist/core/error.js +4 -9
  87. package/dist/core/index.cjs +20 -488
  88. package/dist/core/index.js +8 -19
  89. package/dist/core/resource.cjs +9 -33
  90. package/dist/core/resource.js +2 -7
  91. package/dist/edge.cjs +62 -1111
  92. package/dist/edge.js +10 -42
  93. package/dist/index.cjs +115 -4424
  94. package/dist/index.js +39 -87
  95. package/dist/modelrouter/core.cjs +28 -648
  96. package/dist/modelrouter/core.js +8 -21
  97. package/dist/modelrouter/index.cjs +28 -648
  98. package/dist/modelrouter/index.js +8 -21
  99. package/dist/modelrouter/types.cjs +1 -17
  100. package/dist/modelrouter/types.js +1 -0
  101. package/dist/subagents/anthropic.cjs +27 -2777
  102. package/dist/subagents/anthropic.js +19 -24
  103. package/dist/subagents/index.cjs +14 -95
  104. package/dist/subagents/index.js +2 -11
  105. package/dist/subagents/prompts.cjs +14 -93
  106. package/dist/subagents/prompts.js +2 -11
  107. package/dist/subagents/types.cjs +1 -17
  108. package/dist/subagents/types.js +1 -0
  109. package/dist/subagents/vercel.cjs +27 -2754
  110. package/dist/subagents/vercel.js +19 -24
  111. package/dist/tools/compact/core.cjs +12 -548
  112. package/dist/tools/compact/core.js +8 -13
  113. package/dist/tools/compact/index.cjs +17 -595
  114. package/dist/tools/compact/index.js +9 -17
  115. package/dist/tools/compact/types.cjs +1 -17
  116. package/dist/tools/compact/types.js +1 -0
  117. package/dist/tools/fastapply/anthropic.cjs +27 -891
  118. package/dist/tools/fastapply/anthropic.js +11 -24
  119. package/dist/tools/fastapply/apply.cjs +28 -672
  120. package/dist/tools/fastapply/apply.js +4 -19
  121. package/dist/tools/fastapply/core.cjs +37 -1061
  122. package/dist/tools/fastapply/core.js +9 -29
  123. package/dist/tools/fastapply/index.cjs +62 -1062
  124. package/dist/tools/fastapply/index.js +14 -44
  125. package/dist/tools/fastapply/openai.cjs +32 -901
  126. package/dist/tools/fastapply/openai.js +11 -26
  127. package/dist/tools/fastapply/prompts.cjs +10 -62
  128. package/dist/tools/fastapply/prompts.js +2 -9
  129. package/dist/tools/fastapply/types.cjs +1 -17
  130. package/dist/tools/fastapply/types.js +1 -0
  131. package/dist/tools/fastapply/vercel.cjs +25 -897
  132. package/dist/tools/fastapply/vercel.js +11 -22
  133. package/dist/tools/index.cjs +62 -1062
  134. package/dist/tools/index.js +14 -44
  135. package/dist/tools/utils/resilience.cjs +15 -312
  136. package/dist/tools/utils/resilience.js +3 -12
  137. package/dist/tools/warp_grep/agent/config.cjs +16 -127
  138. package/dist/tools/warp_grep/agent/config.js +2 -11
  139. package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
  140. package/dist/tools/warp_grep/agent/formatter.js +2 -9
  141. package/dist/tools/warp_grep/agent/parser.cjs +16 -83
  142. package/dist/tools/warp_grep/agent/parser.js +2 -11
  143. package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
  144. package/dist/tools/warp_grep/agent/runner.js +7 -14
  145. package/dist/tools/warp_grep/agent/types.cjs +1 -17
  146. package/dist/tools/warp_grep/agent/types.js +1 -0
  147. package/dist/tools/warp_grep/anthropic.cjs +47 -2554
  148. package/dist/tools/warp_grep/anthropic.js +19 -35
  149. package/dist/tools/warp_grep/client.cjs +49 -2464
  150. package/dist/tools/warp_grep/client.js +17 -34
  151. package/dist/tools/warp_grep/gemini.cjs +48 -2483
  152. package/dist/tools/warp_grep/gemini.js +21 -41
  153. package/dist/tools/warp_grep/harness.cjs +81 -929
  154. package/dist/tools/warp_grep/harness.js +12 -51
  155. package/dist/tools/warp_grep/index.cjs +124 -2568
  156. package/dist/tools/warp_grep/index.js +24 -87
  157. package/dist/tools/warp_grep/openai.cjs +53 -2568
  158. package/dist/tools/warp_grep/openai.js +19 -37
  159. package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
  160. package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
  161. package/dist/tools/warp_grep/providers/local.cjs +10 -582
  162. package/dist/tools/warp_grep/providers/local.js +6 -11
  163. package/dist/tools/warp_grep/providers/remote.cjs +8 -331
  164. package/dist/tools/warp_grep/providers/remote.js +3 -8
  165. package/dist/tools/warp_grep/providers/types.cjs +1 -17
  166. package/dist/tools/warp_grep/providers/types.js +1 -0
  167. package/dist/tools/warp_grep/utils/files.cjs +9 -42
  168. package/dist/tools/warp_grep/utils/files.js +2 -7
  169. package/dist/tools/warp_grep/utils/github.cjs +9 -43
  170. package/dist/tools/warp_grep/utils/github.js +2 -7
  171. package/dist/tools/warp_grep/utils/paths.cjs +28 -104
  172. package/dist/tools/warp_grep/utils/paths.js +2 -17
  173. package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -86
  174. package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
  175. package/dist/tools/warp_grep/vercel.cjs +53 -2550
  176. package/dist/tools/warp_grep/vercel.js +19 -37
  177. package/dist/version.cjs +7 -225
  178. package/dist/version.js +2 -7
  179. package/package.json +2 -2
  180. package/dist/chunk-UZCXOOZO.js +0 -203
@@ -1,677 +1,33 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
29
2
 
30
- // tools/fastapply/apply.ts
31
- var apply_exports = {};
32
- __export(apply_exports, {
33
- FastApplyAnchorIntegrityError: () => FastApplyAnchorIntegrityError,
34
- FastApplyContextLengthError: () => FastApplyContextLengthError,
35
- applyEdit: () => applyEdit,
36
- callMorphAPI: () => callMorphAPI,
37
- countChanges: () => countChanges,
38
- generateUdiff: () => generateUdiff
39
- });
40
- module.exports = __toCommonJS(apply_exports);
41
- var import_diff = require("diff");
42
- var import_openai = __toESM(require("openai"), 1);
43
-
44
- // package.json
45
- var package_default = {
46
- name: "@morphllm/morphsdk",
47
- version: "0.2.201",
48
- description: "TypeScript SDK and CLI for Morph Fast Apply integration",
49
- type: "module",
50
- main: "./dist/index.cjs",
51
- module: "./dist/index.js",
52
- types: "./dist/index.d.ts",
53
- exports: {
54
- ".": {
55
- types: "./dist/index.d.ts",
56
- import: "./dist/index.js",
57
- require: "./dist/index.cjs"
58
- },
59
- "./logger": {
60
- types: "./dist/logger.d.ts",
61
- import: "./dist/logger.js",
62
- require: "./dist/logger.cjs"
63
- },
64
- "./edge": {
65
- types: "./dist/edge.d.ts",
66
- import: "./dist/edge.js",
67
- require: "./dist/edge.cjs"
68
- },
69
- "./tools/warp-grep": {
70
- types: "./dist/tools/warp_grep/index.d.ts",
71
- import: "./dist/tools/warp_grep/index.js",
72
- require: "./dist/tools/warp_grep/index.cjs"
73
- },
74
- "./tools/warp-grep/openai": {
75
- types: "./dist/tools/warp_grep/openai.d.ts",
76
- import: "./dist/tools/warp_grep/openai.js",
77
- require: "./dist/tools/warp_grep/openai.cjs"
78
- },
79
- "./tools/warp-grep/anthropic": {
80
- types: "./dist/tools/warp_grep/anthropic.d.ts",
81
- import: "./dist/tools/warp_grep/anthropic.js",
82
- require: "./dist/tools/warp_grep/anthropic.cjs"
83
- },
84
- "./tools/warp-grep/vercel": {
85
- types: "./dist/tools/warp_grep/vercel.d.ts",
86
- import: "./dist/tools/warp_grep/vercel.js",
87
- require: "./dist/tools/warp_grep/vercel.cjs"
88
- },
89
- "./tools/warp-grep/client": {
90
- types: "./dist/tools/warp_grep/client.d.ts",
91
- import: "./dist/tools/warp_grep/client.js",
92
- require: "./dist/tools/warp_grep/client.cjs"
93
- },
94
- "./tools/warp-grep/gemini": {
95
- types: "./dist/tools/warp_grep/gemini.d.ts",
96
- import: "./dist/tools/warp_grep/gemini.js",
97
- require: "./dist/tools/warp_grep/gemini.cjs"
98
- },
99
- "./tools/warp-grep/harness": {
100
- types: "./dist/tools/warp_grep/harness.d.ts",
101
- import: "./dist/tools/warp_grep/harness.js",
102
- require: "./dist/tools/warp_grep/harness.cjs"
103
- },
104
- "./tools/fastapply": {
105
- types: "./dist/tools/fastapply/index.d.ts",
106
- import: "./dist/tools/fastapply/index.js",
107
- require: "./dist/tools/fastapply/index.cjs"
108
- },
109
- "./tools/fastapply/anthropic": {
110
- types: "./dist/tools/fastapply/anthropic.d.ts",
111
- import: "./dist/tools/fastapply/anthropic.js",
112
- require: "./dist/tools/fastapply/anthropic.cjs"
113
- },
114
- "./tools/fastapply/openai": {
115
- types: "./dist/tools/fastapply/openai.d.ts",
116
- import: "./dist/tools/fastapply/openai.js",
117
- require: "./dist/tools/fastapply/openai.cjs"
118
- },
119
- "./tools/fastapply/vercel": {
120
- types: "./dist/tools/fastapply/vercel.d.ts",
121
- import: "./dist/tools/fastapply/vercel.js",
122
- require: "./dist/tools/fastapply/vercel.cjs"
123
- },
124
- "./modelrouter": {
125
- types: "./dist/modelrouter/index.d.ts",
126
- import: "./dist/modelrouter/index.js",
127
- require: "./dist/modelrouter/index.cjs"
128
- },
129
- "./tools/compact": {
130
- types: "./dist/tools/compact/index.d.ts",
131
- import: "./dist/tools/compact/index.js",
132
- require: "./dist/tools/compact/index.cjs"
133
- },
134
- "./subagents": {
135
- types: "./dist/subagents/index.d.ts",
136
- import: "./dist/subagents/index.js",
137
- require: "./dist/subagents/index.cjs"
138
- },
139
- "./subagents/vercel": {
140
- types: "./dist/subagents/vercel.d.ts",
141
- import: "./dist/subagents/vercel.js",
142
- require: "./dist/subagents/vercel.cjs"
143
- },
144
- "./subagents/anthropic": {
145
- types: "./dist/subagents/anthropic.d.ts",
146
- import: "./dist/subagents/anthropic.js",
147
- require: "./dist/subagents/anthropic.cjs"
148
- },
149
- "./ai-sdk": {
150
- types: "./dist/ai-sdk/index.d.ts",
151
- import: "./dist/ai-sdk/index.js",
152
- require: "./dist/ai-sdk/index.cjs"
153
- }
154
- },
155
- files: [
156
- "dist/**/*.js",
157
- "dist/**/*.cjs",
158
- "dist/**/*.d.ts",
159
- "!dist/**/__tests__/**",
160
- "!dist/**/*.test.*"
161
- ],
162
- scripts: {
163
- 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",
164
- prepare: "npm run build",
165
- typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
166
- lint: "eslint .",
167
- test: "vitest run",
168
- "test:watch": "vitest watch",
169
- "test:anthropic": "vitest run anthropic",
170
- "test:openai": "vitest run openai",
171
- "test:vercel": "vitest run vercel",
172
- "test:git": "vitest run git",
173
- "test:agent": "npx tsx tests/fullAgentTest.ts",
174
- "test:integration": "npx tsx tests/fullIntegrationTest.ts",
175
- "test:e2e": "vitest run --config vitest.e2e.config.ts",
176
- "release:patch": "npm version patch && npm publish",
177
- "release:minor": "npm version minor && npm publish",
178
- "release:major": "npm version major && npm publish"
179
- },
180
- keywords: [
181
- "morph",
182
- "fast-apply",
183
- "cli",
184
- "sdk",
185
- "edit-file"
186
- ],
187
- engines: {
188
- node: ">=18"
189
- },
190
- license: "MIT",
191
- dependencies: {
192
- "@vscode/ripgrep": "^1.17.0",
193
- ai: ">=5.0.0",
194
- diff: "^7.0.0",
195
- openai: "^4.52.7",
196
- zod: ">=3.23.0"
197
- },
198
- devDependencies: {
199
- "@ai-sdk/anthropic": "^2.0.70",
200
- "@ai-sdk/openai": "^2.0.35",
201
- "@anthropic-ai/sdk": "^0.30.1",
202
- "@google/generative-ai": "^0.24.1",
203
- "@types/diff": "^7.0.2",
204
- "@types/node": "^20.14.10",
205
- "@typescript-eslint/eslint-plugin": "^7.18.0",
206
- "@typescript-eslint/parser": "^7.18.0",
207
- dotenv: "^16.4.5",
208
- eslint: "^8.57.0",
209
- shx: "^0.3.4",
210
- tsup: "^8.5.0",
211
- tsx: "^4.16.2",
212
- typescript: "^5.5.4",
213
- vitest: "^2.1.6"
214
- },
215
- peerDependencies: {
216
- "@ai-sdk/openai-compatible": ">=2.0.74 <4",
217
- "@anthropic-ai/sdk": ">=0.25.0",
218
- "@google/generative-ai": ">=0.21.0",
219
- ai: ">=5.0.0",
220
- zod: ">=3.23.0"
221
- },
222
- peerDependenciesMeta: {
223
- "@anthropic-ai/sdk": {
224
- optional: true
225
- },
226
- "@google/generative-ai": {
227
- optional: true
228
- },
229
- ai: {
230
- optional: true
231
- },
232
- zod: {
233
- optional: true
234
- }
235
- },
236
- publishConfig: {
237
- access: "public"
238
- }
239
- };
240
-
241
- // version.ts
242
- var SDK_VERSION = package_default.version;
3
+ var chunkVDFLPO7B_cjs = require('../../chunk-VDFLPO7B.cjs');
4
+ require('../../chunk-VL4QNALG.cjs');
5
+ require('../../chunk-TL34BLQD.cjs');
6
+ require('../../chunk-75ZPJI57.cjs');
243
7
 
244
- // logger.ts
245
- var MorphLogger = class {
246
- enabled;
247
- fileStream;
248
- /** Resolves once the file stream is initialized (or immediately if no file logging). */
249
- ready;
250
- constructor() {
251
- this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
252
- this.fileStream = null;
253
- const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
254
- if (f) {
255
- this.ready = import("fs").then((fs) => {
256
- this.fileStream = fs.createWriteStream(f, { flags: "a" });
257
- }).catch(() => {
258
- });
259
- } else {
260
- this.ready = Promise.resolve();
261
- }
262
- }
263
- debug(component, msg, data) {
264
- this._log("debug", component, msg, data);
265
- }
266
- info(component, msg, data) {
267
- this._log("info", component, msg, data);
268
- }
269
- warn(component, msg, data) {
270
- this._log("warn", component, msg, data);
271
- }
272
- error(component, msg, data) {
273
- this._log("error", component, msg, data);
274
- }
275
- enable() {
276
- this.enabled = true;
277
- }
278
- get isEnabled() {
279
- return this.enabled;
280
- }
281
- _log(level, component, msg, data) {
282
- if (level !== "error" && !this.enabled) return;
283
- const ts = (/* @__PURE__ */ new Date()).toISOString();
284
- const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
285
- console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
286
- this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
287
- }
288
- };
289
- var logger = new MorphLogger();
290
8
 
291
- // tools/fastapply/anchors.ts
292
- var DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
293
- var DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
294
- var FastApplyAnchorIntegrityError = class extends Error {
295
- code = "anchor_integrity_failed";
296
- completionId;
297
- constructor(completionId) {
298
- super(
299
- "Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
300
- );
301
- this.name = "FastApplyAnchorIntegrityError";
302
- this.completionId = completionId;
303
- }
304
- };
305
- function escapeRegExp(value) {
306
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
307
- }
308
- function findNamespace(values) {
309
- for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
310
- const prefix = `\u27EAM${namespace}:`;
311
- if (values.every((value) => !value.includes(prefix))) {
312
- return namespace;
313
- }
314
- }
315
- throw new Error("Unable to allocate a Fast Apply anchor namespace");
316
- }
317
- function htmlLabel(token) {
318
- if (!token.startsWith("<")) return "text";
319
- const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
320
- return (match?.[1] ?? "tag").toLowerCase();
321
- }
322
- function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
323
- return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
324
- value: token,
325
- label: htmlLabel(token),
326
- anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
327
- }));
328
- }
329
- function sourceUnits(originalCode, editContext) {
330
- const trimmed = originalCode.trimStart().toLowerCase();
331
- const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
332
- if (looksLikeHtml) {
333
- const contextWords = new Set(
334
- editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
335
- );
336
- return htmlTokenUnits(originalCode, contextWords);
337
- }
338
- const parts = originalCode.split(/(\r\n|\n|\r)/);
339
- const units = [];
340
- for (let index = 0; index < parts.length; index += 2) {
341
- const line = parts[index] ?? "";
342
- const lineEnding = parts[index + 1] ?? "";
343
- units.push({
344
- value: line,
345
- label: "line",
346
- anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
347
- });
348
- if (lineEnding) {
349
- units.push({ value: lineEnding, anchorable: false });
350
- }
351
- }
352
- return units;
353
- }
354
- function copyCount(value) {
355
- const words = {
356
- one: 1,
357
- two: 2,
358
- three: 3,
359
- four: 4,
360
- five: 5,
361
- six: 6,
362
- seven: 7,
363
- eight: 8,
364
- nine: 9,
365
- ten: 10
366
- };
367
- return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
368
- }
369
- function structuralExpectation(originalCode, editContext) {
370
- const context = editContext.join(" ");
371
- const match = context.match(
372
- /(?: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
373
- );
374
- if (!match) return void 0;
375
- const tag = match[1].toLowerCase();
376
- const addedCopies = copyCount(match[2]);
377
- if (addedCopies === void 0) return void 0;
378
- const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
379
- const originalCount = originalCode.match(tagPattern)?.length ?? 0;
380
- if (originalCount === 0) return void 0;
381
- return { tag, expectedCount: originalCount * (addedCopies + 1) };
382
- }
383
- function createAnchorCompactionPlan(originalCode, collisionValues = []) {
384
- const namespace = findNamespace([originalCode, ...collisionValues]);
385
- const expectation = structuralExpectation(originalCode, collisionValues);
386
- const markerPrefix = `\u27EAM${namespace}:`;
387
- const definitions = /* @__PURE__ */ new Map();
388
- const values = [];
389
- const markers = [];
390
- let anchorCount = 0;
391
- let skeleton = "";
392
- for (const unit of sourceUnits(originalCode, collisionValues)) {
393
- if (!unit.anchorable) {
394
- skeleton += unit.value;
395
- continue;
396
- }
397
- let id = definitions.get(unit.value);
398
- if (id === void 0) {
399
- id = values.length;
400
- definitions.set(unit.value, id);
401
- values.push(unit.value);
402
- markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
403
- }
404
- skeleton += markers[id];
405
- anchorCount++;
406
- }
407
- if (anchorCount === 0 || skeleton.length >= originalCode.length) {
408
- return void 0;
409
- }
410
- const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
411
- const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
412
- const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
413
- const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
414
- const code = [
415
- definitionsBegin,
416
- serializedDefinitions,
417
- definitionsEnd,
418
- codeBegin,
419
- skeleton
420
- ].join("\n");
421
- const instructionSuffix = `
422
9
 
423
- LARGE-FILE ANCHOR PROTOCOL:
424
- The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
425
- Each ${markerPrefix}N:kind\u27EB placeholder represents the exact source fragment in its matching JSON-string definition. The kind suffix describes its HTML tag, text, or source line.
426
- Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
427
- Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
428
- To modify an anchored fragment, output the modified source instead of its placeholder.
429
- Do not invent or alter placeholder IDs.`;
430
- const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
431
- return {
432
- code,
433
- instructionSuffix,
434
- anchorCount,
435
- uniqueAnchorCount: values.length,
436
- hasStructuralValidation: expectation !== void 0,
437
- expand(content) {
438
- const codeBeginIndex = content.lastIndexOf(codeBegin);
439
- const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
440
- const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
441
- const id = Number(idText);
442
- const value = values[id];
443
- return value === void 0 || markers[id] !== marker ? marker : value;
444
- });
445
- if (expanded.includes(markerPrefix)) {
446
- throw new FastApplyAnchorIntegrityError();
447
- }
448
- if (expectation) {
449
- const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
450
- const actualCount = expanded.match(tagPattern)?.length ?? 0;
451
- if (actualCount !== expectation.expectedCount) {
452
- throw new FastApplyAnchorIntegrityError();
453
- }
454
- }
455
- return expanded;
456
- }
457
- };
458
- }
459
-
460
- // tools/fastapply/apply.ts
461
- var DEFAULT_API_URL = "https://api.morphllm.com";
462
- var DEFAULT_TIMEOUT = 6e5;
463
- var FastApplyContextLengthError = class extends Error {
464
- code = "context_length_exceeded";
465
- completionId;
466
- constructor(completionId) {
467
- super(
468
- "Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
469
- );
470
- this.name = "FastApplyContextLengthError";
471
- this.completionId = completionId;
472
- }
473
- };
474
- function isAsyncIterable(value) {
475
- return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
476
- }
477
- async function collectCompletion(response) {
478
- if (!isAsyncIterable(response)) {
479
- const completion = response;
480
- return {
481
- content: completion.choices?.[0]?.message?.content ?? "",
482
- completionId: completion.id,
483
- finishReason: completion.choices?.[0]?.finish_reason
484
- };
485
- }
486
- const content = [];
487
- let completionId;
488
- let finishReason;
489
- for await (const chunk of response) {
490
- completionId = chunk.id ?? completionId;
491
- for (const choice of chunk.choices ?? []) {
492
- if (choice.delta?.content) {
493
- content.push(choice.delta.content);
494
- }
495
- if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
496
- finishReason = choice.finish_reason;
497
- }
498
- }
499
- }
500
- return { content: content.join(""), completionId, finishReason };
501
- }
502
- function generateUdiff(original, modified, filepath) {
503
- return (0, import_diff.createTwoFilesPatch)(
504
- filepath,
505
- filepath,
506
- original,
507
- modified,
508
- "Original",
509
- "Modified"
510
- );
511
- }
512
- function countChanges(original, modified) {
513
- const diff = generateUdiff(original, modified, "file");
514
- const lines = diff.split("\n");
515
- let linesAdded = 0;
516
- let linesRemoved = 0;
517
- for (const line of lines) {
518
- if (line.startsWith("+") && !line.startsWith("+++")) {
519
- linesAdded++;
520
- } else if (line.startsWith("-") && !line.startsWith("---")) {
521
- linesRemoved++;
522
- }
523
- }
524
- const linesModified = Math.min(linesAdded, linesRemoved);
525
- return {
526
- linesAdded: linesAdded - linesModified,
527
- linesRemoved: linesRemoved - linesModified,
528
- linesModified
529
- };
530
- }
531
- async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
532
- const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
533
- const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
534
- const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
535
- const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
536
- const timeout = config.timeout ?? DEFAULT_TIMEOUT;
537
- const debug = config.debug || false;
538
- if (!apiKey) {
539
- throw new Error(
540
- "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
541
- );
542
- }
543
- const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
544
- const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
545
- const requestCode = anchorPlan?.code ?? originalCode;
546
- const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
547
- const message = `<instruction>${requestInstructions}</instruction>
548
- <code>${requestCode}</code>
549
- <update>${codeEdit}</update>`;
550
- logger.debug("FastApply", "http_request", {
551
- url: `${apiUrl}/v1/chat/completions`,
552
- model,
553
- filepath,
554
- instruction_len: instructions.length,
555
- original_len: originalCode.length,
556
- request_code_len: requestCode.length,
557
- code_edit_len: codeEdit.length,
558
- anchor_count: anchorPlan?.anchorCount ?? 0,
559
- unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
560
- });
561
- const startTime = Date.now();
562
- const client = new import_openai.default({
563
- apiKey,
564
- baseURL: `${apiUrl}/v1`,
565
- timeout,
566
- maxRetries: config.retryConfig?.maxRetries ?? 3,
567
- defaultHeaders: {
568
- "X-Morph-SDK-Version": SDK_VERSION,
569
- ...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
570
- }
571
- });
572
- try {
573
- const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
574
- for (let attempt = 1; attempt <= maxAttempts; attempt++) {
575
- const response = await client.chat.completions.create({
576
- model,
577
- messages: [{ role: "user", content: message }],
578
- stream: true
579
- });
580
- const completion = await collectCompletion(response);
581
- if (completion.finishReason === "length") {
582
- throw new FastApplyContextLengthError(completion.completionId);
583
- }
584
- let content = completion.content;
585
- if (!content) {
586
- throw new Error("Morph API returned empty response");
587
- }
588
- if (anchorPlan) {
589
- try {
590
- content = anchorPlan.expand(content);
591
- } catch (error) {
592
- if (error instanceof FastApplyAnchorIntegrityError) {
593
- if (attempt < maxAttempts) {
594
- logger.warn("FastApply", "anchor_validation_retry", {
595
- attempt,
596
- completion_id: completion.completionId
597
- });
598
- continue;
599
- }
600
- throw new FastApplyAnchorIntegrityError(completion.completionId);
601
- }
602
- throw error;
603
- }
604
- }
605
- const elapsed = Date.now() - startTime;
606
- logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
607
- return { content, completionId: completion.completionId };
608
- }
609
- throw new FastApplyAnchorIntegrityError();
610
- } catch (error) {
611
- const elapsed = Date.now() - startTime;
612
- const status = error?.status || error?.response?.status;
613
- logger.error("FastApply", "http_error", {
614
- status,
615
- error: error?.message,
616
- latency_ms: elapsed
617
- });
618
- if (status === 401) {
619
- const err = new Error(
620
- "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."
621
- );
622
- err.status = 401;
623
- throw err;
624
- }
625
- if (status === 429) {
626
- const err = new Error(
627
- "Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
628
- );
629
- err.status = 429;
630
- throw err;
631
- }
632
- throw error;
633
- }
634
- }
635
- async function applyEdit(input, config = {}) {
636
- const filepath = input.filepath || "file";
637
- try {
638
- logger.debug("FastApply", "apply_edit_start", { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });
639
- const instruction = input.instruction ?? input.instructions ?? "";
640
- const { content: mergedCode, completionId } = await callMorphAPI(
641
- input.originalCode,
642
- input.codeEdit,
643
- instruction,
644
- filepath,
645
- config
646
- );
647
- const udiff = config.generateUdiff !== false ? generateUdiff(input.originalCode, mergedCode, filepath) : void 0;
648
- const changes = countChanges(input.originalCode, mergedCode);
649
- return {
650
- success: true,
651
- mergedCode,
652
- udiff,
653
- changes,
654
- completionId
655
- };
656
- } catch (error) {
657
- const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
658
- logger.error("FastApply", "apply_edit_error", { error: errorMessage });
659
- const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
660
- return {
661
- success: false,
662
- changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
663
- error: errorMessage,
664
- errorCode: structuredError?.code,
665
- completionId: structuredError?.completionId
666
- };
667
- }
668
- }
669
- // Annotate the CommonJS export names for ESM import in node:
670
- 0 && (module.exports = {
671
- FastApplyAnchorIntegrityError,
672
- FastApplyContextLengthError,
673
- applyEdit,
674
- callMorphAPI,
675
- countChanges,
676
- generateUdiff
10
+ Object.defineProperty(exports, "FastApplyAnchorIntegrityError", {
11
+ enumerable: true,
12
+ get: function () { return chunkVDFLPO7B_cjs.FastApplyAnchorIntegrityError; }
13
+ });
14
+ Object.defineProperty(exports, "FastApplyContextLengthError", {
15
+ enumerable: true,
16
+ get: function () { return chunkVDFLPO7B_cjs.FastApplyContextLengthError; }
17
+ });
18
+ Object.defineProperty(exports, "applyEdit", {
19
+ enumerable: true,
20
+ get: function () { return chunkVDFLPO7B_cjs.applyEdit; }
21
+ });
22
+ Object.defineProperty(exports, "callMorphAPI", {
23
+ enumerable: true,
24
+ get: function () { return chunkVDFLPO7B_cjs.callMorphAPI; }
25
+ });
26
+ Object.defineProperty(exports, "countChanges", {
27
+ enumerable: true,
28
+ get: function () { return chunkVDFLPO7B_cjs.countChanges; }
29
+ });
30
+ Object.defineProperty(exports, "generateUdiff", {
31
+ enumerable: true,
32
+ get: function () { return chunkVDFLPO7B_cjs.generateUdiff; }
677
33
  });