@morphllm/morphsdk 0.2.202 → 0.2.203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-2PPYWRMZ.js +3 -4
- package/dist/{chunk-SIFDK4AA.js → chunk-2UIOCSVJ.js} +3 -24
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/chunk-4R5MDGL6.cjs +280 -0
- package/dist/chunk-65W4I66Q.cjs +103 -0
- package/dist/{chunk-3CPI6ZIC.js → chunk-66THRMD7.js} +10 -35
- package/dist/chunk-6TZCVTW5.js +3 -4
- package/dist/chunk-6WP7EA4F.js +2 -4
- package/dist/chunk-74A4HLIO.cjs +42 -0
- package/dist/chunk-75ZPJI57.cjs +9 -0
- package/dist/chunk-7NA7X7W2.cjs +77 -0
- package/dist/chunk-7PJYY46L.cjs +2 -0
- package/dist/chunk-AFF6XYKL.cjs +71 -0
- package/dist/{chunk-2XU3XXUE.js → chunk-AJBZA23L.js} +3 -25
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/{chunk-LVKKICOB.js → chunk-AXEKIRRY.js} +22 -62
- package/dist/chunk-B3FD67F2.cjs +256 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/{chunk-UAZKHSEU.js → chunk-E3XNKAMI.js} +5 -15
- package/dist/{chunk-VQDDL3UH.js → chunk-E7FLETFO.js} +2 -8
- package/dist/{chunk-YAM6P5OQ.js → chunk-EI2M567U.js} +2 -6
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/{chunk-6OYJC4TZ.js → chunk-EZ2OFDBJ.js} +5 -19
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-CAWQEHKP.js → chunk-GDFPZ3NJ.js} +4 -19
- package/dist/{chunk-UKXCGQPS.js → chunk-GIQAIHUI.js} +8 -33
- package/dist/chunk-GSUQGDCL.cjs +235 -0
- package/dist/{chunk-D6YJ5X3C.js → chunk-H3HRSRR5.js} +4 -12
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HMLYJVZM.cjs +410 -0
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/{chunk-XPHNS7NW.js → chunk-IUM6CQYX.js} +3 -12
- package/dist/{chunk-26K5EJD3.js → chunk-J56Q6C4Y.js} +4 -18
- package/dist/chunk-JBTR3FQD.cjs +135 -0
- package/dist/chunk-JNQKQKHS.cjs +81 -0
- package/dist/chunk-JOZC4T6C.cjs +168 -0
- package/dist/{chunk-JEVLCA5C.js → chunk-JUGNTIVU.js} +6 -19
- package/dist/{chunk-NFPRKZQ5.js → chunk-JY6COF3X.js} +5 -22
- package/dist/{chunk-ICCGLO6V.js → chunk-KLVJIC2O.js} +5 -17
- package/dist/chunk-KSZYOX6S.cjs +91 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-65TUD7JV.js → chunk-LLQH6CCB.js} +10 -28
- package/dist/chunk-M34E2AMK.js +1 -5
- package/dist/chunk-MF56KEI4.js +1 -4
- package/dist/chunk-MLKGABMK.js +1 -3
- package/dist/chunk-MLPZKUCO.js +4 -5
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/{chunk-IBRBSDLT.js → chunk-N7UKZ5X7.js} +2 -6
- package/dist/chunk-NDUC7OV6.cjs +74 -0
- package/dist/{chunk-PDSIWL7I.js → chunk-NLACTMZT.js} +6 -19
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCCGJ4S6.js +8 -0
- package/dist/chunk-ODY2NKQU.cjs +50 -0
- package/dist/chunk-OM5ZSXQW.cjs +91 -0
- package/dist/chunk-OOEORM7H.cjs +334 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/chunk-OSL4CNSO.js +7 -23
- package/dist/chunk-OXXMTDOY.cjs +86 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/chunk-S6QBPXBI.cjs +107 -0
- package/dist/chunk-TL34BLQD.cjs +10 -0
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UUCRWJJR.cjs +313 -0
- package/dist/chunk-VDFLPO7B.cjs +396 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-ZLG2M2I4.cjs +21 -0
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/client.cjs +40 -4360
- package/dist/client.js +32 -37
- package/dist/core/client.cjs +10 -476
- package/dist/core/client.js +6 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +20 -488
- package/dist/core/index.js +8 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +62 -1111
- package/dist/edge.js +10 -42
- package/dist/index.cjs +115 -4431
- package/dist/index.js +39 -87
- package/dist/modelrouter/core.cjs +28 -648
- package/dist/modelrouter/core.js +8 -21
- package/dist/modelrouter/index.cjs +28 -648
- package/dist/modelrouter/index.js +8 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +27 -2784
- package/dist/subagents/anthropic.js +19 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +27 -2761
- package/dist/subagents/vercel.js +19 -24
- package/dist/tools/compact/core.cjs +12 -548
- package/dist/tools/compact/core.js +8 -13
- package/dist/tools/compact/index.cjs +17 -595
- package/dist/tools/compact/index.js +9 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +27 -891
- package/dist/tools/fastapply/anthropic.js +11 -24
- package/dist/tools/fastapply/apply.cjs +28 -672
- package/dist/tools/fastapply/apply.js +4 -19
- package/dist/tools/fastapply/core.cjs +37 -1061
- package/dist/tools/fastapply/core.js +9 -29
- package/dist/tools/fastapply/index.cjs +62 -1062
- package/dist/tools/fastapply/index.js +14 -44
- package/dist/tools/fastapply/openai.cjs +32 -901
- package/dist/tools/fastapply/openai.js +11 -26
- package/dist/tools/fastapply/prompts.cjs +10 -62
- package/dist/tools/fastapply/prompts.js +2 -9
- package/dist/tools/fastapply/types.cjs +1 -17
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +25 -897
- package/dist/tools/fastapply/vercel.js +11 -22
- package/dist/tools/index.cjs +62 -1062
- package/dist/tools/index.js +14 -44
- package/dist/tools/utils/resilience.cjs +15 -312
- package/dist/tools/utils/resilience.js +3 -12
- package/dist/tools/warp_grep/agent/config.cjs +16 -127
- package/dist/tools/warp_grep/agent/config.js +2 -11
- package/dist/tools/warp_grep/agent/formatter.cjs +12 -48
- package/dist/tools/warp_grep/agent/formatter.js +2 -9
- package/dist/tools/warp_grep/agent/parser.cjs +16 -83
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +15 -1081
- package/dist/tools/warp_grep/agent/runner.js +7 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +47 -2561
- package/dist/tools/warp_grep/anthropic.js +19 -35
- package/dist/tools/warp_grep/client.cjs +49 -2471
- package/dist/tools/warp_grep/client.js +17 -34
- package/dist/tools/warp_grep/gemini.cjs +48 -2490
- package/dist/tools/warp_grep/gemini.js +21 -41
- package/dist/tools/warp_grep/harness.cjs +81 -936
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +124 -2575
- package/dist/tools/warp_grep/index.js +24 -87
- package/dist/tools/warp_grep/openai.cjs +53 -2575
- package/dist/tools/warp_grep/openai.js +19 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.js +2 -9
- package/dist/tools/warp_grep/providers/local.cjs +10 -589
- package/dist/tools/warp_grep/providers/local.js +6 -11
- package/dist/tools/warp_grep/providers/remote.cjs +8 -331
- package/dist/tools/warp_grep/providers/remote.js +3 -8
- package/dist/tools/warp_grep/providers/types.cjs +1 -17
- package/dist/tools/warp_grep/providers/types.js +1 -0
- package/dist/tools/warp_grep/utils/files.cjs +9 -42
- package/dist/tools/warp_grep/utils/files.js +2 -7
- package/dist/tools/warp_grep/utils/github.cjs +9 -43
- package/dist/tools/warp_grep/utils/github.js +2 -7
- package/dist/tools/warp_grep/utils/paths.cjs +28 -104
- package/dist/tools/warp_grep/utils/paths.js +2 -17
- package/dist/tools/warp_grep/utils/ripgrep.cjs +9 -103
- package/dist/tools/warp_grep/utils/ripgrep.js +2 -7
- package/dist/tools/warp_grep/vercel.cjs +53 -2557
- package/dist/tools/warp_grep/vercel.js +19 -37
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +2 -2
- package/dist/chunk-E6TL6MIH.js +0 -203
package/dist/edge.cjs
CHANGED
|
@@ -1,1116 +1,67 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __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
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
RouterClassifier: () => RouterClassifier,
|
|
41
|
-
SDK_VERSION: () => SDK_VERSION,
|
|
42
|
-
applyEdit: () => applyEdit,
|
|
43
|
-
callMorphAPI: () => callMorphAPI,
|
|
44
|
-
countChanges: () => countChanges,
|
|
45
|
-
generateUdiff: () => generateUdiff
|
|
46
|
-
});
|
|
47
|
-
module.exports = __toCommonJS(edge_exports);
|
|
48
|
-
|
|
49
|
-
// package.json
|
|
50
|
-
var package_default = {
|
|
51
|
-
name: "@morphllm/morphsdk",
|
|
52
|
-
version: "0.2.202",
|
|
53
|
-
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
54
|
-
type: "module",
|
|
55
|
-
main: "./dist/index.cjs",
|
|
56
|
-
module: "./dist/index.js",
|
|
57
|
-
types: "./dist/index.d.ts",
|
|
58
|
-
exports: {
|
|
59
|
-
".": {
|
|
60
|
-
types: "./dist/index.d.ts",
|
|
61
|
-
import: "./dist/index.js",
|
|
62
|
-
require: "./dist/index.cjs"
|
|
63
|
-
},
|
|
64
|
-
"./logger": {
|
|
65
|
-
types: "./dist/logger.d.ts",
|
|
66
|
-
import: "./dist/logger.js",
|
|
67
|
-
require: "./dist/logger.cjs"
|
|
68
|
-
},
|
|
69
|
-
"./edge": {
|
|
70
|
-
types: "./dist/edge.d.ts",
|
|
71
|
-
import: "./dist/edge.js",
|
|
72
|
-
require: "./dist/edge.cjs"
|
|
73
|
-
},
|
|
74
|
-
"./tools/warp-grep": {
|
|
75
|
-
types: "./dist/tools/warp_grep/index.d.ts",
|
|
76
|
-
import: "./dist/tools/warp_grep/index.js",
|
|
77
|
-
require: "./dist/tools/warp_grep/index.cjs"
|
|
78
|
-
},
|
|
79
|
-
"./tools/warp-grep/openai": {
|
|
80
|
-
types: "./dist/tools/warp_grep/openai.d.ts",
|
|
81
|
-
import: "./dist/tools/warp_grep/openai.js",
|
|
82
|
-
require: "./dist/tools/warp_grep/openai.cjs"
|
|
83
|
-
},
|
|
84
|
-
"./tools/warp-grep/anthropic": {
|
|
85
|
-
types: "./dist/tools/warp_grep/anthropic.d.ts",
|
|
86
|
-
import: "./dist/tools/warp_grep/anthropic.js",
|
|
87
|
-
require: "./dist/tools/warp_grep/anthropic.cjs"
|
|
88
|
-
},
|
|
89
|
-
"./tools/warp-grep/vercel": {
|
|
90
|
-
types: "./dist/tools/warp_grep/vercel.d.ts",
|
|
91
|
-
import: "./dist/tools/warp_grep/vercel.js",
|
|
92
|
-
require: "./dist/tools/warp_grep/vercel.cjs"
|
|
93
|
-
},
|
|
94
|
-
"./tools/warp-grep/client": {
|
|
95
|
-
types: "./dist/tools/warp_grep/client.d.ts",
|
|
96
|
-
import: "./dist/tools/warp_grep/client.js",
|
|
97
|
-
require: "./dist/tools/warp_grep/client.cjs"
|
|
98
|
-
},
|
|
99
|
-
"./tools/warp-grep/gemini": {
|
|
100
|
-
types: "./dist/tools/warp_grep/gemini.d.ts",
|
|
101
|
-
import: "./dist/tools/warp_grep/gemini.js",
|
|
102
|
-
require: "./dist/tools/warp_grep/gemini.cjs"
|
|
103
|
-
},
|
|
104
|
-
"./tools/warp-grep/harness": {
|
|
105
|
-
types: "./dist/tools/warp_grep/harness.d.ts",
|
|
106
|
-
import: "./dist/tools/warp_grep/harness.js",
|
|
107
|
-
require: "./dist/tools/warp_grep/harness.cjs"
|
|
108
|
-
},
|
|
109
|
-
"./tools/fastapply": {
|
|
110
|
-
types: "./dist/tools/fastapply/index.d.ts",
|
|
111
|
-
import: "./dist/tools/fastapply/index.js",
|
|
112
|
-
require: "./dist/tools/fastapply/index.cjs"
|
|
113
|
-
},
|
|
114
|
-
"./tools/fastapply/anthropic": {
|
|
115
|
-
types: "./dist/tools/fastapply/anthropic.d.ts",
|
|
116
|
-
import: "./dist/tools/fastapply/anthropic.js",
|
|
117
|
-
require: "./dist/tools/fastapply/anthropic.cjs"
|
|
118
|
-
},
|
|
119
|
-
"./tools/fastapply/openai": {
|
|
120
|
-
types: "./dist/tools/fastapply/openai.d.ts",
|
|
121
|
-
import: "./dist/tools/fastapply/openai.js",
|
|
122
|
-
require: "./dist/tools/fastapply/openai.cjs"
|
|
123
|
-
},
|
|
124
|
-
"./tools/fastapply/vercel": {
|
|
125
|
-
types: "./dist/tools/fastapply/vercel.d.ts",
|
|
126
|
-
import: "./dist/tools/fastapply/vercel.js",
|
|
127
|
-
require: "./dist/tools/fastapply/vercel.cjs"
|
|
128
|
-
},
|
|
129
|
-
"./modelrouter": {
|
|
130
|
-
types: "./dist/modelrouter/index.d.ts",
|
|
131
|
-
import: "./dist/modelrouter/index.js",
|
|
132
|
-
require: "./dist/modelrouter/index.cjs"
|
|
133
|
-
},
|
|
134
|
-
"./tools/compact": {
|
|
135
|
-
types: "./dist/tools/compact/index.d.ts",
|
|
136
|
-
import: "./dist/tools/compact/index.js",
|
|
137
|
-
require: "./dist/tools/compact/index.cjs"
|
|
138
|
-
},
|
|
139
|
-
"./subagents": {
|
|
140
|
-
types: "./dist/subagents/index.d.ts",
|
|
141
|
-
import: "./dist/subagents/index.js",
|
|
142
|
-
require: "./dist/subagents/index.cjs"
|
|
143
|
-
},
|
|
144
|
-
"./subagents/vercel": {
|
|
145
|
-
types: "./dist/subagents/vercel.d.ts",
|
|
146
|
-
import: "./dist/subagents/vercel.js",
|
|
147
|
-
require: "./dist/subagents/vercel.cjs"
|
|
148
|
-
},
|
|
149
|
-
"./subagents/anthropic": {
|
|
150
|
-
types: "./dist/subagents/anthropic.d.ts",
|
|
151
|
-
import: "./dist/subagents/anthropic.js",
|
|
152
|
-
require: "./dist/subagents/anthropic.cjs"
|
|
153
|
-
},
|
|
154
|
-
"./ai-sdk": {
|
|
155
|
-
types: "./dist/ai-sdk/index.d.ts",
|
|
156
|
-
import: "./dist/ai-sdk/index.js",
|
|
157
|
-
require: "./dist/ai-sdk/index.cjs"
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
files: [
|
|
161
|
-
"dist/**/*.js",
|
|
162
|
-
"dist/**/*.cjs",
|
|
163
|
-
"dist/**/*.d.ts",
|
|
164
|
-
"!dist/**/__tests__/**",
|
|
165
|
-
"!dist/**/*.test.*"
|
|
166
|
-
],
|
|
167
|
-
scripts: {
|
|
168
|
-
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",
|
|
169
|
-
prepare: "npm run build",
|
|
170
|
-
typecheck: "tsc --noEmit && tsc --noEmit -p ai-sdk/tsconfig.json",
|
|
171
|
-
lint: "eslint .",
|
|
172
|
-
test: "vitest run",
|
|
173
|
-
"test:watch": "vitest watch",
|
|
174
|
-
"test:anthropic": "vitest run anthropic",
|
|
175
|
-
"test:openai": "vitest run openai",
|
|
176
|
-
"test:vercel": "vitest run vercel",
|
|
177
|
-
"test:git": "vitest run git",
|
|
178
|
-
"test:agent": "npx tsx tests/fullAgentTest.ts",
|
|
179
|
-
"test:integration": "npx tsx tests/fullIntegrationTest.ts",
|
|
180
|
-
"test:e2e": "vitest run --config vitest.e2e.config.ts",
|
|
181
|
-
"release:patch": "npm version patch && npm publish",
|
|
182
|
-
"release:minor": "npm version minor && npm publish",
|
|
183
|
-
"release:major": "npm version major && npm publish"
|
|
184
|
-
},
|
|
185
|
-
keywords: [
|
|
186
|
-
"morph",
|
|
187
|
-
"fast-apply",
|
|
188
|
-
"cli",
|
|
189
|
-
"sdk",
|
|
190
|
-
"edit-file"
|
|
191
|
-
],
|
|
192
|
-
engines: {
|
|
193
|
-
node: ">=18"
|
|
194
|
-
},
|
|
195
|
-
license: "MIT",
|
|
196
|
-
dependencies: {
|
|
197
|
-
"@vscode/ripgrep": "^1.17.0",
|
|
198
|
-
ai: ">=5.0.0",
|
|
199
|
-
diff: "^7.0.0",
|
|
200
|
-
openai: "^4.52.7",
|
|
201
|
-
zod: ">=3.23.0"
|
|
202
|
-
},
|
|
203
|
-
devDependencies: {
|
|
204
|
-
"@ai-sdk/anthropic": "^2.0.70",
|
|
205
|
-
"@ai-sdk/openai": "^2.0.35",
|
|
206
|
-
"@anthropic-ai/sdk": "^0.30.1",
|
|
207
|
-
"@google/generative-ai": "^0.24.1",
|
|
208
|
-
"@types/diff": "^7.0.2",
|
|
209
|
-
"@types/node": "^20.14.10",
|
|
210
|
-
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
211
|
-
"@typescript-eslint/parser": "^7.18.0",
|
|
212
|
-
dotenv: "^16.4.5",
|
|
213
|
-
eslint: "^8.57.0",
|
|
214
|
-
shx: "^0.3.4",
|
|
215
|
-
tsup: "^8.5.0",
|
|
216
|
-
tsx: "^4.16.2",
|
|
217
|
-
typescript: "^5.5.4",
|
|
218
|
-
vitest: "^2.1.6"
|
|
219
|
-
},
|
|
220
|
-
peerDependencies: {
|
|
221
|
-
"@ai-sdk/openai-compatible": ">=2.0.74 <4",
|
|
222
|
-
"@anthropic-ai/sdk": ">=0.25.0",
|
|
223
|
-
"@google/generative-ai": ">=0.21.0",
|
|
224
|
-
ai: ">=5.0.0",
|
|
225
|
-
zod: ">=3.23.0"
|
|
226
|
-
},
|
|
227
|
-
peerDependenciesMeta: {
|
|
228
|
-
"@anthropic-ai/sdk": {
|
|
229
|
-
optional: true
|
|
230
|
-
},
|
|
231
|
-
"@google/generative-ai": {
|
|
232
|
-
optional: true
|
|
233
|
-
},
|
|
234
|
-
ai: {
|
|
235
|
-
optional: true
|
|
236
|
-
},
|
|
237
|
-
zod: {
|
|
238
|
-
optional: true
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
publishConfig: {
|
|
242
|
-
access: "public"
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
// version.ts
|
|
247
|
-
var SDK_VERSION = package_default.version;
|
|
248
|
-
|
|
249
|
-
// tools/fastapply/apply.ts
|
|
250
|
-
var import_diff = require("diff");
|
|
251
|
-
var import_openai = __toESM(require("openai"), 1);
|
|
252
|
-
|
|
253
|
-
// logger.ts
|
|
254
|
-
var MorphLogger = class {
|
|
255
|
-
enabled;
|
|
256
|
-
fileStream;
|
|
257
|
-
/** Resolves once the file stream is initialized (or immediately if no file logging). */
|
|
258
|
-
ready;
|
|
259
|
-
constructor() {
|
|
260
|
-
this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
|
|
261
|
-
this.fileStream = null;
|
|
262
|
-
const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
|
|
263
|
-
if (f) {
|
|
264
|
-
this.ready = import("fs").then((fs) => {
|
|
265
|
-
this.fileStream = fs.createWriteStream(f, { flags: "a" });
|
|
266
|
-
}).catch(() => {
|
|
267
|
-
});
|
|
268
|
-
} else {
|
|
269
|
-
this.ready = Promise.resolve();
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
debug(component, msg, data) {
|
|
273
|
-
this._log("debug", component, msg, data);
|
|
274
|
-
}
|
|
275
|
-
info(component, msg, data) {
|
|
276
|
-
this._log("info", component, msg, data);
|
|
277
|
-
}
|
|
278
|
-
warn(component, msg, data) {
|
|
279
|
-
this._log("warn", component, msg, data);
|
|
280
|
-
}
|
|
281
|
-
error(component, msg, data) {
|
|
282
|
-
this._log("error", component, msg, data);
|
|
283
|
-
}
|
|
284
|
-
enable() {
|
|
285
|
-
this.enabled = true;
|
|
286
|
-
}
|
|
287
|
-
get isEnabled() {
|
|
288
|
-
return this.enabled;
|
|
289
|
-
}
|
|
290
|
-
_log(level, component, msg, data) {
|
|
291
|
-
if (level !== "error" && !this.enabled) return;
|
|
292
|
-
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
293
|
-
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
294
|
-
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
295
|
-
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
296
|
-
}
|
|
297
|
-
};
|
|
298
|
-
var logger = new MorphLogger();
|
|
299
|
-
|
|
300
|
-
// tools/fastapply/anchors.ts
|
|
301
|
-
var DEFAULT_MIN_ANCHOR_LINE_LENGTH = 24;
|
|
302
|
-
var DEFAULT_ANCHOR_COMPACTION_THRESHOLD = 128 * 1024;
|
|
303
|
-
var FastApplyAnchorIntegrityError = class extends Error {
|
|
304
|
-
code = "anchor_integrity_failed";
|
|
305
|
-
completionId;
|
|
306
|
-
constructor(completionId) {
|
|
307
|
-
super(
|
|
308
|
-
"Fast Apply failed large-file anchor integrity checks. The partial result was discarded safely."
|
|
309
|
-
);
|
|
310
|
-
this.name = "FastApplyAnchorIntegrityError";
|
|
311
|
-
this.completionId = completionId;
|
|
312
|
-
}
|
|
313
|
-
};
|
|
314
|
-
function escapeRegExp(value) {
|
|
315
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
316
|
-
}
|
|
317
|
-
function findNamespace(values) {
|
|
318
|
-
for (let namespace = 0; namespace < Number.MAX_SAFE_INTEGER; namespace++) {
|
|
319
|
-
const prefix = `\u27EAM${namespace}:`;
|
|
320
|
-
if (values.every((value) => !value.includes(prefix))) {
|
|
321
|
-
return namespace;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
throw new Error("Unable to allocate a Fast Apply anchor namespace");
|
|
325
|
-
}
|
|
326
|
-
function htmlLabel(token) {
|
|
327
|
-
if (!token.startsWith("<")) return "text";
|
|
328
|
-
const match = token.match(/^<\s*(!doctype|\/?[a-zA-Z][\w:-]*)/);
|
|
329
|
-
return (match?.[1] ?? "tag").toLowerCase();
|
|
330
|
-
}
|
|
331
|
-
function htmlTokenUnits(value, visibleTags = /* @__PURE__ */ new Set()) {
|
|
332
|
-
return (value.match(/<[^>]*>|[^<]+/g) ?? [value]).map((token) => ({
|
|
333
|
-
value: token,
|
|
334
|
-
label: htmlLabel(token),
|
|
335
|
-
anchorable: token.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH && !visibleTags.has(htmlLabel(token).replace(/^\//, ""))
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
function sourceUnits(originalCode, editContext) {
|
|
339
|
-
const trimmed = originalCode.trimStart().toLowerCase();
|
|
340
|
-
const looksLikeHtml = (trimmed.startsWith("<!doctype") || trimmed.startsWith("<html")) && /<\/html\s*>/i.test(originalCode);
|
|
341
|
-
if (looksLikeHtml) {
|
|
342
|
-
const contextWords = new Set(
|
|
343
|
-
editContext.join(" ").toLowerCase().match(/[a-z][\w:-]*/g) ?? []
|
|
344
|
-
);
|
|
345
|
-
return htmlTokenUnits(originalCode, contextWords);
|
|
346
|
-
}
|
|
347
|
-
const parts = originalCode.split(/(\r\n|\n|\r)/);
|
|
348
|
-
const units = [];
|
|
349
|
-
for (let index = 0; index < parts.length; index += 2) {
|
|
350
|
-
const line = parts[index] ?? "";
|
|
351
|
-
const lineEnding = parts[index + 1] ?? "";
|
|
352
|
-
units.push({
|
|
353
|
-
value: line,
|
|
354
|
-
label: "line",
|
|
355
|
-
anchorable: line.length >= DEFAULT_MIN_ANCHOR_LINE_LENGTH
|
|
356
|
-
});
|
|
357
|
-
if (lineEnding) {
|
|
358
|
-
units.push({ value: lineEnding, anchorable: false });
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
return units;
|
|
362
|
-
}
|
|
363
|
-
function copyCount(value) {
|
|
364
|
-
const words = {
|
|
365
|
-
one: 1,
|
|
366
|
-
two: 2,
|
|
367
|
-
three: 3,
|
|
368
|
-
four: 4,
|
|
369
|
-
five: 5,
|
|
370
|
-
six: 6,
|
|
371
|
-
seven: 7,
|
|
372
|
-
eight: 8,
|
|
373
|
-
nine: 9,
|
|
374
|
-
ten: 10
|
|
375
|
-
};
|
|
376
|
-
return /^\d+$/.test(value) ? Number(value) : words[value.toLowerCase()];
|
|
377
|
-
}
|
|
378
|
-
function structuralExpectation(originalCode, editContext) {
|
|
379
|
-
const context = editContext.join(" ");
|
|
380
|
-
const match = context.match(
|
|
381
|
-
/(?: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
|
|
382
|
-
);
|
|
383
|
-
if (!match) return void 0;
|
|
384
|
-
const tag = match[1].toLowerCase();
|
|
385
|
-
const addedCopies = copyCount(match[2]);
|
|
386
|
-
if (addedCopies === void 0) return void 0;
|
|
387
|
-
const tagPattern = new RegExp(`<${escapeRegExp(tag)}(?:\\s|>)`, "gi");
|
|
388
|
-
const originalCount = originalCode.match(tagPattern)?.length ?? 0;
|
|
389
|
-
if (originalCount === 0) return void 0;
|
|
390
|
-
return { tag, expectedCount: originalCount * (addedCopies + 1) };
|
|
391
|
-
}
|
|
392
|
-
function createAnchorCompactionPlan(originalCode, collisionValues = []) {
|
|
393
|
-
const namespace = findNamespace([originalCode, ...collisionValues]);
|
|
394
|
-
const expectation = structuralExpectation(originalCode, collisionValues);
|
|
395
|
-
const markerPrefix = `\u27EAM${namespace}:`;
|
|
396
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
397
|
-
const values = [];
|
|
398
|
-
const markers = [];
|
|
399
|
-
let anchorCount = 0;
|
|
400
|
-
let skeleton = "";
|
|
401
|
-
for (const unit of sourceUnits(originalCode, collisionValues)) {
|
|
402
|
-
if (!unit.anchorable) {
|
|
403
|
-
skeleton += unit.value;
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
let id = definitions.get(unit.value);
|
|
407
|
-
if (id === void 0) {
|
|
408
|
-
id = values.length;
|
|
409
|
-
definitions.set(unit.value, id);
|
|
410
|
-
values.push(unit.value);
|
|
411
|
-
markers.push(`${markerPrefix}${id}:${unit.label ?? "unit"}\u27EB`);
|
|
412
|
-
}
|
|
413
|
-
skeleton += markers[id];
|
|
414
|
-
anchorCount++;
|
|
415
|
-
}
|
|
416
|
-
if (anchorCount === 0 || skeleton.length >= originalCode.length) {
|
|
417
|
-
return void 0;
|
|
418
|
-
}
|
|
419
|
-
const definitionsBegin = `\u27EAMORPH_DEFINITIONS_BEGIN_${namespace}\u27EB`;
|
|
420
|
-
const definitionsEnd = `\u27EAMORPH_DEFINITIONS_END_${namespace}\u27EB`;
|
|
421
|
-
const codeBegin = `\u27EAMORPH_CODE_BEGIN_${namespace}\u27EB`;
|
|
422
|
-
const serializedDefinitions = values.map((value, id) => `${markers[id]}=${JSON.stringify(value)}`).join("\n");
|
|
423
|
-
const code = [
|
|
424
|
-
definitionsBegin,
|
|
425
|
-
serializedDefinitions,
|
|
426
|
-
definitionsEnd,
|
|
427
|
-
codeBegin,
|
|
428
|
-
skeleton
|
|
429
|
-
].join("\n");
|
|
430
|
-
const instructionSuffix = `
|
|
3
|
+
var chunkVDFLPO7B_cjs = require('./chunk-VDFLPO7B.cjs');
|
|
4
|
+
var chunkJOZC4T6C_cjs = require('./chunk-JOZC4T6C.cjs');
|
|
5
|
+
var chunkAFF6XYKL_cjs = require('./chunk-AFF6XYKL.cjs');
|
|
6
|
+
require('./chunk-65W4I66Q.cjs');
|
|
7
|
+
require('./chunk-VL4QNALG.cjs');
|
|
8
|
+
require('./chunk-ZLG2M2I4.cjs');
|
|
9
|
+
require('./chunk-OM5ZSXQW.cjs');
|
|
10
|
+
var chunkTL34BLQD_cjs = require('./chunk-TL34BLQD.cjs');
|
|
11
|
+
require('./chunk-AWFZKS27.cjs');
|
|
12
|
+
require('./chunk-75ZPJI57.cjs');
|
|
431
13
|
|
|
432
|
-
LARGE-FILE ANCHOR PROTOCOL:
|
|
433
|
-
The <code> block starts with an exact anchor definition table, then ${codeBegin}, then the source skeleton.
|
|
434
|
-
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.
|
|
435
|
-
Return only the updated source skeleton after ${codeBegin}; never return the definition table or protocol delimiters.
|
|
436
|
-
Copy a placeholder exactly when its source fragment is unchanged. You may repeat, reorder, or remove placeholders when the requested edit requires it.
|
|
437
|
-
To modify an anchored fragment, output the modified source instead of its placeholder.
|
|
438
|
-
Do not invent or alter placeholder IDs.`;
|
|
439
|
-
const markerPattern = new RegExp(`${escapeRegExp(markerPrefix)}(\\d+):[^\u27EB]+\u27EB`, "g");
|
|
440
|
-
return {
|
|
441
|
-
code,
|
|
442
|
-
instructionSuffix,
|
|
443
|
-
anchorCount,
|
|
444
|
-
uniqueAnchorCount: values.length,
|
|
445
|
-
hasStructuralValidation: expectation !== void 0,
|
|
446
|
-
expand(content) {
|
|
447
|
-
const codeBeginIndex = content.lastIndexOf(codeBegin);
|
|
448
|
-
const skeletonContent = codeBeginIndex >= 0 ? content.slice(codeBeginIndex + codeBegin.length).replace(/^\r?\n/, "") : content;
|
|
449
|
-
const expanded = skeletonContent.replace(markerPattern, (marker, idText) => {
|
|
450
|
-
const id = Number(idText);
|
|
451
|
-
const value = values[id];
|
|
452
|
-
return value === void 0 || markers[id] !== marker ? marker : value;
|
|
453
|
-
});
|
|
454
|
-
if (expanded.includes(markerPrefix)) {
|
|
455
|
-
throw new FastApplyAnchorIntegrityError();
|
|
456
|
-
}
|
|
457
|
-
if (expectation) {
|
|
458
|
-
const tagPattern = new RegExp(`<${escapeRegExp(expectation.tag)}(?:\\s|>)`, "gi");
|
|
459
|
-
const actualCount = expanded.match(tagPattern)?.length ?? 0;
|
|
460
|
-
if (actualCount !== expectation.expectedCount) {
|
|
461
|
-
throw new FastApplyAnchorIntegrityError();
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
return expanded;
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
14
|
|
|
469
|
-
// tools/fastapply/apply.ts
|
|
470
|
-
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
471
|
-
var DEFAULT_TIMEOUT = 6e5;
|
|
472
|
-
var FastApplyContextLengthError = class extends Error {
|
|
473
|
-
code = "context_length_exceeded";
|
|
474
|
-
completionId;
|
|
475
|
-
constructor(completionId) {
|
|
476
|
-
super(
|
|
477
|
-
"Fast Apply exhausted its context window before producing the complete file. Retry with a smaller input/update or use sparse anchors for unchanged code."
|
|
478
|
-
);
|
|
479
|
-
this.name = "FastApplyContextLengthError";
|
|
480
|
-
this.completionId = completionId;
|
|
481
|
-
}
|
|
482
|
-
};
|
|
483
|
-
function isAsyncIterable(value) {
|
|
484
|
-
return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
|
|
485
|
-
}
|
|
486
|
-
async function collectCompletion(response) {
|
|
487
|
-
if (!isAsyncIterable(response)) {
|
|
488
|
-
const completion = response;
|
|
489
|
-
return {
|
|
490
|
-
content: completion.choices?.[0]?.message?.content ?? "",
|
|
491
|
-
completionId: completion.id,
|
|
492
|
-
finishReason: completion.choices?.[0]?.finish_reason
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
const content = [];
|
|
496
|
-
let completionId;
|
|
497
|
-
let finishReason;
|
|
498
|
-
for await (const chunk of response) {
|
|
499
|
-
completionId = chunk.id ?? completionId;
|
|
500
|
-
for (const choice of chunk.choices ?? []) {
|
|
501
|
-
if (choice.delta?.content) {
|
|
502
|
-
content.push(choice.delta.content);
|
|
503
|
-
}
|
|
504
|
-
if (choice.finish_reason !== void 0 && choice.finish_reason !== null) {
|
|
505
|
-
finishReason = choice.finish_reason;
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
return { content: content.join(""), completionId, finishReason };
|
|
510
|
-
}
|
|
511
|
-
function generateUdiff(original, modified, filepath) {
|
|
512
|
-
return (0, import_diff.createTwoFilesPatch)(
|
|
513
|
-
filepath,
|
|
514
|
-
filepath,
|
|
515
|
-
original,
|
|
516
|
-
modified,
|
|
517
|
-
"Original",
|
|
518
|
-
"Modified"
|
|
519
|
-
);
|
|
520
|
-
}
|
|
521
|
-
function countChanges(original, modified) {
|
|
522
|
-
const diff = generateUdiff(original, modified, "file");
|
|
523
|
-
const lines = diff.split("\n");
|
|
524
|
-
let linesAdded = 0;
|
|
525
|
-
let linesRemoved = 0;
|
|
526
|
-
for (const line of lines) {
|
|
527
|
-
if (line.startsWith("+") && !line.startsWith("+++")) {
|
|
528
|
-
linesAdded++;
|
|
529
|
-
} else if (line.startsWith("-") && !line.startsWith("---")) {
|
|
530
|
-
linesRemoved++;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
const linesModified = Math.min(linesAdded, linesRemoved);
|
|
534
|
-
return {
|
|
535
|
-
linesAdded: linesAdded - linesModified,
|
|
536
|
-
linesRemoved: linesRemoved - linesModified,
|
|
537
|
-
linesModified
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
async function callMorphAPI(originalCode, codeEdit, instructions, filepath, config) {
|
|
541
|
-
const apiKey = config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
542
|
-
const apiUrl = config.morphApiUrl || DEFAULT_API_URL;
|
|
543
|
-
const useLarge = config.large ?? (typeof process !== "undefined" ? process.env?.MORPH_LARGE_APPLY !== "false" : true);
|
|
544
|
-
const model = useLarge ? "morph-v3-large" : "morph-v3-fast";
|
|
545
|
-
const timeout = config.timeout ?? DEFAULT_TIMEOUT;
|
|
546
|
-
const debug = config.debug || false;
|
|
547
|
-
if (!apiKey) {
|
|
548
|
-
throw new Error(
|
|
549
|
-
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
550
|
-
);
|
|
551
|
-
}
|
|
552
|
-
const anchorThreshold = config.anchorCompactionThreshold ?? DEFAULT_ANCHOR_COMPACTION_THRESHOLD;
|
|
553
|
-
const anchorPlan = config.anchorCompaction !== false && originalCode.length >= anchorThreshold ? createAnchorCompactionPlan(originalCode, [codeEdit, instructions]) : void 0;
|
|
554
|
-
const requestCode = anchorPlan?.code ?? originalCode;
|
|
555
|
-
const requestInstructions = anchorPlan ? instructions + anchorPlan.instructionSuffix : instructions;
|
|
556
|
-
const message = `<instruction>${requestInstructions}</instruction>
|
|
557
|
-
<code>${requestCode}</code>
|
|
558
|
-
<update>${codeEdit}</update>`;
|
|
559
|
-
logger.debug("FastApply", "http_request", {
|
|
560
|
-
url: `${apiUrl}/v1/chat/completions`,
|
|
561
|
-
model,
|
|
562
|
-
filepath,
|
|
563
|
-
instruction_len: instructions.length,
|
|
564
|
-
original_len: originalCode.length,
|
|
565
|
-
request_code_len: requestCode.length,
|
|
566
|
-
code_edit_len: codeEdit.length,
|
|
567
|
-
anchor_count: anchorPlan?.anchorCount ?? 0,
|
|
568
|
-
unique_anchor_count: anchorPlan?.uniqueAnchorCount ?? 0
|
|
569
|
-
});
|
|
570
|
-
const startTime = Date.now();
|
|
571
|
-
const client = new import_openai.default({
|
|
572
|
-
apiKey,
|
|
573
|
-
baseURL: `${apiUrl}/v1`,
|
|
574
|
-
timeout,
|
|
575
|
-
maxRetries: config.retryConfig?.maxRetries ?? 3,
|
|
576
|
-
defaultHeaders: {
|
|
577
|
-
"X-Morph-SDK-Version": SDK_VERSION,
|
|
578
|
-
...anchorPlan ? { "X-Morph-Apply-Context": "extralong" } : {}
|
|
579
|
-
}
|
|
580
|
-
});
|
|
581
|
-
try {
|
|
582
|
-
const maxAttempts = anchorPlan?.hasStructuralValidation ? 2 : 1;
|
|
583
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
584
|
-
const response = await client.chat.completions.create({
|
|
585
|
-
model,
|
|
586
|
-
messages: [{ role: "user", content: message }],
|
|
587
|
-
stream: true
|
|
588
|
-
});
|
|
589
|
-
const completion = await collectCompletion(response);
|
|
590
|
-
if (completion.finishReason === "length") {
|
|
591
|
-
throw new FastApplyContextLengthError(completion.completionId);
|
|
592
|
-
}
|
|
593
|
-
let content = completion.content;
|
|
594
|
-
if (!content) {
|
|
595
|
-
throw new Error("Morph API returned empty response");
|
|
596
|
-
}
|
|
597
|
-
if (anchorPlan) {
|
|
598
|
-
try {
|
|
599
|
-
content = anchorPlan.expand(content);
|
|
600
|
-
} catch (error) {
|
|
601
|
-
if (error instanceof FastApplyAnchorIntegrityError) {
|
|
602
|
-
if (attempt < maxAttempts) {
|
|
603
|
-
logger.warn("FastApply", "anchor_validation_retry", {
|
|
604
|
-
attempt,
|
|
605
|
-
completion_id: completion.completionId
|
|
606
|
-
});
|
|
607
|
-
continue;
|
|
608
|
-
}
|
|
609
|
-
throw new FastApplyAnchorIntegrityError(completion.completionId);
|
|
610
|
-
}
|
|
611
|
-
throw error;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
const elapsed = Date.now() - startTime;
|
|
615
|
-
logger.debug("FastApply", "http_response", { status: 200, completion_id: completion.completionId, content_len: content.length, latency_ms: elapsed });
|
|
616
|
-
return { content, completionId: completion.completionId };
|
|
617
|
-
}
|
|
618
|
-
throw new FastApplyAnchorIntegrityError();
|
|
619
|
-
} catch (error) {
|
|
620
|
-
const elapsed = Date.now() - startTime;
|
|
621
|
-
const status = error?.status || error?.response?.status;
|
|
622
|
-
logger.error("FastApply", "http_error", {
|
|
623
|
-
status,
|
|
624
|
-
error: error?.message,
|
|
625
|
-
latency_ms: elapsed
|
|
626
|
-
});
|
|
627
|
-
if (status === 401) {
|
|
628
|
-
const err = new Error(
|
|
629
|
-
"Authentication failed: Your Morph API key is invalid or has been revoked. Please visit https://morphllm.com to get a valid API key, then update your MCP configuration."
|
|
630
|
-
);
|
|
631
|
-
err.status = 401;
|
|
632
|
-
throw err;
|
|
633
|
-
}
|
|
634
|
-
if (status === 429) {
|
|
635
|
-
const err = new Error(
|
|
636
|
-
"Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
|
|
637
|
-
);
|
|
638
|
-
err.status = 429;
|
|
639
|
-
throw err;
|
|
640
|
-
}
|
|
641
|
-
throw error;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
async function applyEdit(input, config = {}) {
|
|
645
|
-
const filepath = input.filepath || "file";
|
|
646
|
-
try {
|
|
647
|
-
logger.debug("FastApply", "apply_edit_start", { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });
|
|
648
|
-
const instruction = input.instruction ?? input.instructions ?? "";
|
|
649
|
-
const { content: mergedCode, completionId } = await callMorphAPI(
|
|
650
|
-
input.originalCode,
|
|
651
|
-
input.codeEdit,
|
|
652
|
-
instruction,
|
|
653
|
-
filepath,
|
|
654
|
-
config
|
|
655
|
-
);
|
|
656
|
-
const udiff = config.generateUdiff !== false ? generateUdiff(input.originalCode, mergedCode, filepath) : void 0;
|
|
657
|
-
const changes = countChanges(input.originalCode, mergedCode);
|
|
658
|
-
return {
|
|
659
|
-
success: true,
|
|
660
|
-
mergedCode,
|
|
661
|
-
udiff,
|
|
662
|
-
changes,
|
|
663
|
-
completionId
|
|
664
|
-
};
|
|
665
|
-
} catch (error) {
|
|
666
|
-
const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
|
|
667
|
-
logger.error("FastApply", "apply_edit_error", { error: errorMessage });
|
|
668
|
-
const structuredError = error instanceof FastApplyContextLengthError || error instanceof FastApplyAnchorIntegrityError ? error : void 0;
|
|
669
|
-
return {
|
|
670
|
-
success: false,
|
|
671
|
-
changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },
|
|
672
|
-
error: errorMessage,
|
|
673
|
-
errorCode: structuredError?.code,
|
|
674
|
-
completionId: structuredError?.completionId
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
15
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
throw lastError || new Error("Max retries exceeded");
|
|
733
|
-
}
|
|
734
|
-
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
735
|
-
let timeoutId;
|
|
736
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
737
|
-
timeoutId = setTimeout(() => {
|
|
738
|
-
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
739
|
-
}, timeoutMs);
|
|
740
|
-
});
|
|
741
|
-
try {
|
|
742
|
-
const result = await Promise.race([promise, timeoutPromise]);
|
|
743
|
-
clearTimeout(timeoutId);
|
|
744
|
-
return result;
|
|
745
|
-
} catch (error) {
|
|
746
|
-
clearTimeout(timeoutId);
|
|
747
|
-
throw error;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
function sleep(ms) {
|
|
751
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
752
|
-
}
|
|
753
|
-
var MorphError = class extends Error {
|
|
754
|
-
constructor(message, code, statusCode, retryable = false) {
|
|
755
|
-
super(message);
|
|
756
|
-
this.code = code;
|
|
757
|
-
this.statusCode = statusCode;
|
|
758
|
-
this.retryable = retryable;
|
|
759
|
-
this.name = "MorphError";
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
// core/error.ts
|
|
764
|
-
async function toMorphError(response) {
|
|
765
|
-
let message = `Morph API request failed (${response.status})`;
|
|
766
|
-
let code = "api_error";
|
|
767
|
-
try {
|
|
768
|
-
const body = await response.json();
|
|
769
|
-
message = body.error?.message ?? body.message ?? message;
|
|
770
|
-
code = body.error?.code ?? body.error?.type ?? code;
|
|
771
|
-
} catch {
|
|
772
|
-
}
|
|
773
|
-
if (response.status === 401) code = "authentication_error";
|
|
774
|
-
if (response.status === 429) code = "rate_limit_exceeded";
|
|
775
|
-
const retryable = response.status === 429 || response.status === 503;
|
|
776
|
-
return new MorphError(message, code, response.status, retryable);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// core/client.ts
|
|
780
|
-
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
781
|
-
var DEFAULT_REPOS_URL = "https://repos.morphllm.com";
|
|
782
|
-
var DEFAULT_TIMEOUT2 = 6e4;
|
|
783
|
-
var env = (name) => typeof process !== "undefined" ? process.env?.[name] : void 0;
|
|
784
|
-
var stripTrailingSlash = (url) => url.replace(/\/+$/, "");
|
|
785
|
-
var MorphAPIClient = class {
|
|
786
|
-
/** Explicit key as provided; resolved against env at request time. */
|
|
787
|
-
apiKey;
|
|
788
|
-
baseURL;
|
|
789
|
-
reposURL;
|
|
790
|
-
/** Explicit default timeout (ms), if set. The request default is applied lazily so
|
|
791
|
-
* resources can read an undefined value and supply their own fallback. */
|
|
792
|
-
timeout;
|
|
793
|
-
retryConfig;
|
|
794
|
-
debug;
|
|
795
|
-
constructor(options = {}) {
|
|
796
|
-
this.apiKey = options.apiKey;
|
|
797
|
-
this.baseURL = stripTrailingSlash(options.baseURL ?? DEFAULT_BASE_URL);
|
|
798
|
-
this.reposURL = stripTrailingSlash(options.reposURL ?? env("MORPH_SEARCH_URL") ?? DEFAULT_REPOS_URL);
|
|
799
|
-
this.timeout = options.timeout;
|
|
800
|
-
this.retryConfig = options.retryConfig;
|
|
801
|
-
this.debug = options.debug ?? false;
|
|
802
|
-
if (this.debug) logger.enable();
|
|
803
|
-
}
|
|
804
|
-
/** The key actually used for requests: explicit, else `MORPH_API_KEY`. */
|
|
805
|
-
resolveApiKey() {
|
|
806
|
-
return this.apiKey ?? env("MORPH_API_KEY");
|
|
807
|
-
}
|
|
808
|
-
/** Headers shared with tools that bring their own HTTP client (FastApply/WarpGrep via the `openai` package). */
|
|
809
|
-
defaultHeaders() {
|
|
810
|
-
return { "X-Morph-SDK-Version": SDK_VERSION };
|
|
811
|
-
}
|
|
812
|
-
buildURL(path, baseURL) {
|
|
813
|
-
if (/^https?:\/\//i.test(path)) return path;
|
|
814
|
-
const base = stripTrailingSlash(baseURL ?? this.baseURL);
|
|
815
|
-
return `${base}${path.startsWith("/") ? "" : "/"}${path}`;
|
|
816
|
-
}
|
|
817
|
-
buildHeaders(apiKey, extra) {
|
|
818
|
-
return {
|
|
819
|
-
"Content-Type": "application/json",
|
|
820
|
-
"X-Morph-SDK-Version": SDK_VERSION,
|
|
821
|
-
Authorization: `Bearer ${apiKey}`,
|
|
822
|
-
...extra
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
applyQuery(url, query) {
|
|
826
|
-
if (!query) return url;
|
|
827
|
-
const params = new URLSearchParams();
|
|
828
|
-
for (const [key, value] of Object.entries(query)) {
|
|
829
|
-
if (value !== void 0 && value !== null) params.set(key, String(value));
|
|
830
|
-
}
|
|
831
|
-
const qs = params.toString();
|
|
832
|
-
return qs ? `${url}${url.includes("?") ? "&" : "?"}${qs}` : url;
|
|
833
|
-
}
|
|
834
|
-
async request(method, path, opts = {}) {
|
|
835
|
-
const apiKey = this.resolveApiKey();
|
|
836
|
-
if (!apiKey) {
|
|
837
|
-
throw new MorphError(
|
|
838
|
-
"Morph API key not found. Set the MORPH_API_KEY environment variable or pass apiKey in config.",
|
|
839
|
-
"missing_api_key",
|
|
840
|
-
401
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
const url = this.applyQuery(this.buildURL(path, opts.baseURL), opts.query);
|
|
844
|
-
const timeout = opts.timeout ?? this.timeout ?? DEFAULT_TIMEOUT2;
|
|
845
|
-
const init = {
|
|
846
|
-
method,
|
|
847
|
-
headers: this.buildHeaders(apiKey, opts.headers),
|
|
848
|
-
...opts.body !== void 0 ? { body: JSON.stringify(opts.body) } : {},
|
|
849
|
-
...opts.signal ? { signal: opts.signal } : {}
|
|
850
|
-
};
|
|
851
|
-
logger.debug("MorphAPIClient", "request", { method, url });
|
|
852
|
-
const response = await withTimeout(
|
|
853
|
-
fetchWithRetry(url, init, this.retryConfig ?? {}),
|
|
854
|
-
timeout,
|
|
855
|
-
`Morph request to ${url} timed out after ${timeout}ms`
|
|
856
|
-
);
|
|
857
|
-
if (!response.ok) throw await toMorphError(response);
|
|
858
|
-
if (opts.stream) return response;
|
|
859
|
-
if (response.status === 204) return void 0;
|
|
860
|
-
const text = await response.text();
|
|
861
|
-
return text ? JSON.parse(text) : void 0;
|
|
862
|
-
}
|
|
863
|
-
get(path, opts) {
|
|
864
|
-
return this.request("GET", path, opts);
|
|
865
|
-
}
|
|
866
|
-
post(path, opts) {
|
|
867
|
-
return this.request("POST", path, opts);
|
|
868
|
-
}
|
|
869
|
-
delete(path, opts) {
|
|
870
|
-
return this.request("DELETE", path, opts);
|
|
871
|
-
}
|
|
872
|
-
};
|
|
873
|
-
|
|
874
|
-
// core/resource.ts
|
|
875
|
-
var APIResource = class {
|
|
876
|
-
_client;
|
|
877
|
-
constructor(client) {
|
|
878
|
-
this._client = client;
|
|
879
|
-
}
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
// modelrouter/core.ts
|
|
883
|
-
var DEFAULT_API_URL2 = "https://api.morphllm.com";
|
|
884
|
-
var DEFAULT_TIMEOUT3 = 5e3;
|
|
885
|
-
function resolveClient(clientOrConfig) {
|
|
886
|
-
if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
|
|
887
|
-
return new MorphAPIClient({
|
|
888
|
-
apiKey: clientOrConfig.apiKey,
|
|
889
|
-
baseURL: clientOrConfig.apiUrl ?? DEFAULT_API_URL2,
|
|
890
|
-
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT3,
|
|
891
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
892
|
-
debug: clientOrConfig.debug
|
|
893
|
-
});
|
|
894
|
-
}
|
|
895
|
-
var BaseRouter = class extends APIResource {
|
|
896
|
-
provider;
|
|
897
|
-
timeout;
|
|
898
|
-
constructor(provider, clientOrConfig = {}) {
|
|
899
|
-
super(resolveClient(clientOrConfig));
|
|
900
|
-
this.provider = provider;
|
|
901
|
-
const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
|
|
902
|
-
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT3;
|
|
903
|
-
}
|
|
904
|
-
/** Throw the historical "API key is required" message when no key is resolvable. */
|
|
905
|
-
requireApiKey() {
|
|
906
|
-
if (!this._client.resolveApiKey()) {
|
|
907
|
-
throw new Error(
|
|
908
|
-
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
909
|
-
);
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
/** POST to the router and surface failures as `Router API error (<status>): ...`. */
|
|
913
|
-
async route(provider, input) {
|
|
914
|
-
try {
|
|
915
|
-
return await this._client.post(`/v1/router/${provider}`, {
|
|
916
|
-
body: { input: input.input, mode: input.mode || "balanced" },
|
|
917
|
-
timeout: this.timeout
|
|
918
|
-
});
|
|
919
|
-
} catch (error) {
|
|
920
|
-
if (error instanceof MorphError) {
|
|
921
|
-
throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
|
|
922
|
-
}
|
|
923
|
-
throw error;
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
/**
|
|
927
|
-
* Select the optimal model for a given input and mode
|
|
928
|
-
*/
|
|
929
|
-
async selectModel(input) {
|
|
930
|
-
this.requireApiKey();
|
|
931
|
-
logger.debug("ModelRouter", "request", { provider: this.provider, mode: input.mode || "balanced" });
|
|
932
|
-
const apiResult = await this.route(this.provider, input);
|
|
933
|
-
logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model });
|
|
934
|
-
return { model: apiResult.model };
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
var OpenAIRouter = class extends BaseRouter {
|
|
938
|
-
constructor(clientOrConfig = {}) {
|
|
939
|
-
super("openai", clientOrConfig);
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Select optimal GPT-5 model
|
|
943
|
-
*
|
|
944
|
-
* @param input - User input and mode
|
|
945
|
-
* @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
|
|
946
|
-
*/
|
|
947
|
-
async selectModel(input) {
|
|
948
|
-
return super.selectModel(input);
|
|
949
|
-
}
|
|
950
|
-
};
|
|
951
|
-
var AnthropicRouter = class extends BaseRouter {
|
|
952
|
-
constructor(clientOrConfig = {}) {
|
|
953
|
-
super("anthropic", clientOrConfig);
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Select optimal Claude model
|
|
957
|
-
*
|
|
958
|
-
* @param input - User input and mode
|
|
959
|
-
* @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
|
|
960
|
-
*/
|
|
961
|
-
async selectModel(input) {
|
|
962
|
-
return super.selectModel(input);
|
|
963
|
-
}
|
|
964
|
-
};
|
|
965
|
-
var GeminiRouter = class extends BaseRouter {
|
|
966
|
-
constructor(clientOrConfig = {}) {
|
|
967
|
-
super("gemini", clientOrConfig);
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Select optimal Gemini model
|
|
971
|
-
*
|
|
972
|
-
* @param input - User input and mode
|
|
973
|
-
* @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
|
|
974
|
-
*/
|
|
975
|
-
async selectModel(input) {
|
|
976
|
-
return super.selectModel(input);
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
var RawRouter = class extends BaseRouter {
|
|
980
|
-
constructor(clientOrConfig = {}) {
|
|
981
|
-
super("raw", clientOrConfig);
|
|
982
|
-
}
|
|
983
|
-
/**
|
|
984
|
-
* Get raw difficulty classification
|
|
985
|
-
*
|
|
986
|
-
* @param input - User input and mode
|
|
987
|
-
* @returns Raw difficulty (easy | medium | hard | needs_info)
|
|
988
|
-
*/
|
|
989
|
-
async classify(input) {
|
|
990
|
-
this.requireApiKey();
|
|
991
|
-
logger.debug("RawRouter", "request", { mode: input.mode || "balanced" });
|
|
992
|
-
const apiResult = await this.route("raw", input);
|
|
993
|
-
let difficulty;
|
|
994
|
-
if (apiResult.difficulty === "") {
|
|
995
|
-
difficulty = "medium";
|
|
996
|
-
} else {
|
|
997
|
-
difficulty = apiResult.difficulty || apiResult.model;
|
|
998
|
-
}
|
|
999
|
-
logger.debug("RawRouter", "classified", { difficulty });
|
|
1000
|
-
return { difficulty };
|
|
1001
|
-
}
|
|
1002
|
-
};
|
|
1003
|
-
var RouterClassifier = class extends APIResource {
|
|
1004
|
-
timeout;
|
|
1005
|
-
constructor(clientOrConfig = {}) {
|
|
1006
|
-
super(resolveClient(clientOrConfig));
|
|
1007
|
-
const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
|
|
1008
|
-
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT3;
|
|
1009
|
-
}
|
|
1010
|
-
/** Classify an input across the requested axes (all three by default). */
|
|
1011
|
-
async classify(input) {
|
|
1012
|
-
if (!this._client.resolveApiKey()) {
|
|
1013
|
-
throw new Error(
|
|
1014
|
-
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
1015
|
-
);
|
|
1016
|
-
}
|
|
1017
|
-
logger.debug("RouterClassifier", "request", { classes: input.classes ?? "all" });
|
|
1018
|
-
try {
|
|
1019
|
-
const res = await this._client.post("/v1/router/classify", {
|
|
1020
|
-
body: { input: input.input, ...input.classes ? { classes: input.classes } : {} },
|
|
1021
|
-
timeout: this.timeout
|
|
1022
|
-
});
|
|
1023
|
-
logger.debug("RouterClassifier", "classified", {
|
|
1024
|
-
difficulty: res.classifications.difficulty?.label,
|
|
1025
|
-
ambiguity: res.classifications.ambiguity?.label,
|
|
1026
|
-
domain: res.classifications.domain?.label
|
|
1027
|
-
});
|
|
1028
|
-
return res.classifications;
|
|
1029
|
-
} catch (error) {
|
|
1030
|
-
if (error instanceof MorphError) {
|
|
1031
|
-
throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
|
|
1032
|
-
}
|
|
1033
|
-
throw error;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
};
|
|
1037
|
-
|
|
1038
|
-
// tools/compact/core.ts
|
|
1039
|
-
var DEFAULT_API_URL3 = "https://api.morphllm.com";
|
|
1040
|
-
var DEFAULT_TIMEOUT4 = 12e4;
|
|
1041
|
-
function resolveClient2(clientOrConfig) {
|
|
1042
|
-
if (clientOrConfig instanceof MorphAPIClient) return clientOrConfig;
|
|
1043
|
-
return new MorphAPIClient({
|
|
1044
|
-
apiKey: clientOrConfig.morphApiKey,
|
|
1045
|
-
baseURL: clientOrConfig.morphApiUrl ?? DEFAULT_API_URL3,
|
|
1046
|
-
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT4,
|
|
1047
|
-
retryConfig: clientOrConfig.retryConfig,
|
|
1048
|
-
debug: clientOrConfig.debug
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
var CompactClient = class extends APIResource {
|
|
1052
|
-
/** Resolved URL/timeout, exposed for backwards-compatible introspection. */
|
|
1053
|
-
config;
|
|
1054
|
-
constructor(clientOrConfig = {}) {
|
|
1055
|
-
super(resolveClient2(clientOrConfig));
|
|
1056
|
-
const cfg = clientOrConfig instanceof MorphAPIClient ? {} : clientOrConfig;
|
|
1057
|
-
this.config = {
|
|
1058
|
-
morphApiUrl: this._client.baseURL,
|
|
1059
|
-
timeout: cfg.timeout ?? DEFAULT_TIMEOUT4,
|
|
1060
|
-
debug: cfg.debug ?? false
|
|
1061
|
-
};
|
|
1062
|
-
}
|
|
1063
|
-
/**
|
|
1064
|
-
* Compact messages or text via /v1/compact.
|
|
1065
|
-
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
1066
|
-
*
|
|
1067
|
-
* @example
|
|
1068
|
-
* ```typescript
|
|
1069
|
-
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
1070
|
-
* const result = await client.compact({
|
|
1071
|
-
* input: codeFile,
|
|
1072
|
-
* query: "authentication",
|
|
1073
|
-
* compressionRatio: 0.5,
|
|
1074
|
-
* });
|
|
1075
|
-
* console.log(result.output);
|
|
1076
|
-
* ```
|
|
1077
|
-
*/
|
|
1078
|
-
async compact(input) {
|
|
1079
|
-
const body = {
|
|
1080
|
-
compression_ratio: input.compressionRatio ?? 0.5,
|
|
1081
|
-
preserve_recent: input.preserveRecent ?? 2,
|
|
1082
|
-
model: input.model ?? "morph-compactor",
|
|
1083
|
-
include_line_ranges: input.includeLineRanges ?? true,
|
|
1084
|
-
include_markers: input.includeMarkers ?? true
|
|
1085
|
-
};
|
|
1086
|
-
if (input.query !== void 0) body.query = input.query;
|
|
1087
|
-
if (input.messages) body.messages = input.messages;
|
|
1088
|
-
else if (typeof input.input === "string") body.input = input.input;
|
|
1089
|
-
else if (Array.isArray(input.input)) body.messages = input.input;
|
|
1090
|
-
else throw new Error("Either 'input' or 'messages' must be provided");
|
|
1091
|
-
try {
|
|
1092
|
-
return await this._client.post("/v1/compact", { body, timeout: this.config.timeout });
|
|
1093
|
-
} catch (err) {
|
|
1094
|
-
if (err instanceof MorphError) {
|
|
1095
|
-
throw new Error(`Compact API error ${err.statusCode}: ${err.message}`);
|
|
1096
|
-
}
|
|
1097
|
-
throw err;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
};
|
|
1101
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1102
|
-
0 && (module.exports = {
|
|
1103
|
-
AnthropicRouter,
|
|
1104
|
-
CompactClient,
|
|
1105
|
-
FastApplyAnchorIntegrityError,
|
|
1106
|
-
FastApplyContextLengthError,
|
|
1107
|
-
GeminiRouter,
|
|
1108
|
-
OpenAIRouter,
|
|
1109
|
-
RawRouter,
|
|
1110
|
-
RouterClassifier,
|
|
1111
|
-
SDK_VERSION,
|
|
1112
|
-
applyEdit,
|
|
1113
|
-
callMorphAPI,
|
|
1114
|
-
countChanges,
|
|
1115
|
-
generateUdiff
|
|
16
|
+
Object.defineProperty(exports, "FastApplyAnchorIntegrityError", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return chunkVDFLPO7B_cjs.FastApplyAnchorIntegrityError; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, "FastApplyContextLengthError", {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return chunkVDFLPO7B_cjs.FastApplyContextLengthError; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "applyEdit", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return chunkVDFLPO7B_cjs.applyEdit; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, "callMorphAPI", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return chunkVDFLPO7B_cjs.callMorphAPI; }
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "countChanges", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () { return chunkVDFLPO7B_cjs.countChanges; }
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "generateUdiff", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return chunkVDFLPO7B_cjs.generateUdiff; }
|
|
39
|
+
});
|
|
40
|
+
Object.defineProperty(exports, "AnthropicRouter", {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () { return chunkJOZC4T6C_cjs.AnthropicRouter; }
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "GeminiRouter", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function () { return chunkJOZC4T6C_cjs.GeminiRouter; }
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "OpenAIRouter", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () { return chunkJOZC4T6C_cjs.OpenAIRouter; }
|
|
51
|
+
});
|
|
52
|
+
Object.defineProperty(exports, "RawRouter", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function () { return chunkJOZC4T6C_cjs.RawRouter; }
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "RouterClassifier", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function () { return chunkJOZC4T6C_cjs.RouterClassifier; }
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "CompactClient", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return chunkAFF6XYKL_cjs.CompactClient; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "SDK_VERSION", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return chunkTL34BLQD_cjs.SDK_VERSION; }
|
|
1116
67
|
});
|