@morphllm/morphsdk 0.2.170 → 0.2.172
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-IY7DESC3.js → chunk-2SNAXTUJ.js} +4 -4
- package/dist/chunk-453ZV2AX.js +120 -0
- package/dist/chunk-453ZV2AX.js.map +1 -0
- package/dist/chunk-53ZJMCWU.js +142 -0
- package/dist/chunk-53ZJMCWU.js.map +1 -0
- package/dist/{chunk-5KFQBI4J.js → chunk-5DA6SZQJ.js} +2 -2
- package/dist/chunk-66OHYI24.js +78 -0
- package/dist/chunk-66OHYI24.js.map +1 -0
- package/dist/chunk-6X6QMRQG.js +158 -0
- package/dist/chunk-6X6QMRQG.js.map +1 -0
- package/dist/{chunk-76XER44U.js → chunk-7PVVPLRL.js} +2 -2
- package/dist/{chunk-BCPZAPWY.js → chunk-AE7M2I52.js} +2 -2
- package/dist/{chunk-LNXIVRPY.js → chunk-CQF76HJC.js} +30 -6
- package/dist/chunk-CQF76HJC.js.map +1 -0
- package/dist/{chunk-OJQYBWHR.js → chunk-ESXCQBMU.js} +2 -2
- package/dist/{chunk-LAGN62H5.js → chunk-FOIDGIY4.js} +29 -10
- package/dist/chunk-FOIDGIY4.js.map +1 -0
- package/dist/{chunk-KUPSW5QN.js → chunk-GJZXDRH5.js} +8 -3
- package/dist/{chunk-KUPSW5QN.js.map → chunk-GJZXDRH5.js.map} +1 -1
- package/dist/{chunk-5IR3YE77.js → chunk-IJ33I7P5.js} +4 -4
- package/dist/{chunk-E5QWXVTF.js → chunk-IN2U7AAI.js} +99 -143
- package/dist/chunk-IN2U7AAI.js.map +1 -0
- package/dist/{chunk-LE66XCOI.js → chunk-JWZ5DLAS.js} +27 -10
- package/dist/chunk-JWZ5DLAS.js.map +1 -0
- package/dist/chunk-LKFZBBTD.js +12 -0
- package/dist/chunk-LKFZBBTD.js.map +1 -0
- package/dist/{chunk-6LPWEZ6H.js → chunk-MO6S2LRD.js} +2 -2
- package/dist/{chunk-S4IEM5EG.js → chunk-NI7PWQ3B.js} +4 -4
- package/dist/{chunk-GLQWEINZ.js → chunk-QAXXE4AD.js} +2 -2
- package/dist/{chunk-YG2I377B.js → chunk-QFE5523Q.js} +18 -3
- package/dist/chunk-QFE5523Q.js.map +1 -0
- package/dist/{chunk-G4FPDEUP.js → chunk-QQXNZIVK.js} +4 -4
- package/dist/{chunk-A3ZUWLYX.js → chunk-QZ3V2BP7.js} +2 -2
- package/dist/chunk-QZR7SJ5N.js +24 -0
- package/dist/chunk-QZR7SJ5N.js.map +1 -0
- package/dist/{chunk-SYD6BRQX.js → chunk-SJVLAGUL.js} +4 -4
- package/dist/{chunk-JMEQ6FLB.js → chunk-U4J3BVAQ.js} +4 -4
- package/dist/{chunk-QAWYDWDW.js → chunk-U4MRSZQQ.js} +2 -2
- package/dist/{chunk-WU3D46MH.js → chunk-UADW6FYD.js} +2 -2
- package/dist/{chunk-K7NY5SVR.js → chunk-VBARKJWL.js} +2 -2
- package/dist/{chunk-OPNTDMHH.js → chunk-VLZ6PNAD.js} +4 -4
- package/dist/chunk-VZ7BOH2K.js +1 -0
- package/dist/chunk-VZ7BOH2K.js.map +1 -0
- package/dist/{chunk-GUGHUAJU.js → chunk-XJDXV5VX.js} +2 -2
- package/dist/{chunk-GPNUS3H2.js → chunk-XYTYIAMQ.js} +2 -2
- package/dist/{chunk-MKBVWPU7.js → chunk-Z4GJVN52.js} +23 -8
- package/dist/chunk-Z4GJVN52.js.map +1 -0
- package/dist/chunk-ZLSNL6M2.js +97 -0
- package/dist/chunk-ZLSNL6M2.js.map +1 -0
- package/dist/{client-DsAAqupx.d.ts → client-Dh6yzCm4.d.ts} +14 -5
- package/dist/client.cjs +741 -525
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +5 -1
- package/dist/client.js +31 -27
- package/dist/core/client.cjs +540 -0
- package/dist/core/client.cjs.map +1 -0
- package/dist/core/client.d.ts +79 -0
- package/dist/core/client.js +12 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/error.cjs +309 -0
- package/dist/core/error.cjs.map +1 -0
- package/dist/core/error.d.ts +18 -0
- package/dist/core/error.js +10 -0
- package/dist/core/error.js.map +1 -0
- package/dist/core/index.cjs +552 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/resource.cjs +36 -0
- package/dist/core/resource.cjs.map +1 -0
- package/dist/core/resource.d.ts +18 -0
- package/dist/core/resource.js +8 -0
- package/dist/core/resource.js.map +1 -0
- package/dist/edge.cjs +252 -174
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.d.ts +2 -0
- package/dist/edge.js +8 -5
- package/dist/git/client.cjs +529 -9
- package/dist/git/client.cjs.map +1 -1
- package/dist/git/client.d.ts +8 -2
- package/dist/git/client.js +7 -1
- package/dist/git/index.cjs +529 -9
- package/dist/git/index.cjs.map +1 -1
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +7 -1
- package/dist/index.cjs +688 -466
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +49 -33
- package/dist/modelrouter/core.cjs +204 -125
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.d.ts +36 -9
- package/dist/modelrouter/core.js +6 -3
- package/dist/modelrouter/index.cjs +204 -125
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.d.ts +3 -0
- package/dist/modelrouter/index.js +6 -3
- package/dist/subagents/anthropic.cjs +268 -52
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +10 -6
- package/dist/subagents/vercel.cjs +268 -52
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +10 -6
- package/dist/tools/browser/anthropic.cjs +7 -2
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +9 -6
- package/dist/tools/browser/core.cjs +162 -10
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.d.ts +8 -2
- package/dist/tools/browser/core.js +8 -5
- package/dist/tools/browser/index.cjs +163 -11
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.d.ts +2 -0
- package/dist/tools/browser/index.js +18 -15
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/openai.cjs +7 -2
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +9 -6
- package/dist/tools/browser/profiles/core.cjs +7 -2
- package/dist/tools/browser/profiles/core.cjs.map +1 -1
- package/dist/tools/browser/profiles/core.js +3 -3
- package/dist/tools/browser/profiles/index.cjs +7 -2
- package/dist/tools/browser/profiles/index.cjs.map +1 -1
- package/dist/tools/browser/profiles/index.js +3 -3
- package/dist/tools/browser/vercel.cjs +7 -2
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +9 -6
- package/dist/tools/codebase_search/anthropic.cjs +162 -41
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +7 -4
- package/dist/tools/codebase_search/core.cjs +195 -66
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.d.ts +18 -7
- package/dist/tools/codebase_search/core.js +6 -3
- package/dist/tools/codebase_search/index.cjs +162 -41
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.d.ts +2 -0
- package/dist/tools/codebase_search/index.js +13 -10
- package/dist/tools/codebase_search/openai.cjs +162 -41
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +7 -4
- package/dist/tools/codebase_search/vercel.cjs +162 -41
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +7 -4
- package/dist/tools/compact/core.cjs +551 -47
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.d.ts +16 -3
- package/dist/tools/compact/core.js +7 -1
- package/dist/tools/compact/index.cjs +549 -47
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.d.ts +2 -0
- package/dist/tools/compact/index.js +8 -2
- package/dist/tools/fastapply/anthropic.cjs +32 -3
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +8 -4
- package/dist/tools/fastapply/apply.cjs +23 -3
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +258 -13
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.d.ts +8 -2
- package/dist/tools/fastapply/core.js +7 -3
- package/dist/tools/fastapply/index.cjs +32 -3
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.d.ts +2 -0
- package/dist/tools/fastapply/index.js +13 -9
- package/dist/tools/fastapply/openai.cjs +32 -3
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +8 -4
- package/dist/tools/fastapply/vercel.cjs +32 -3
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +8 -4
- package/dist/tools/index.cjs +32 -3
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +13 -9
- package/dist/tools/reflex/core.cjs +693 -0
- package/dist/tools/reflex/core.cjs.map +1 -0
- package/dist/tools/reflex/core.d.ts +53 -0
- package/dist/tools/reflex/core.js +16 -0
- package/dist/tools/reflex/core.js.map +1 -0
- package/dist/tools/reflex/index.cjs +693 -0
- package/dist/tools/reflex/index.cjs.map +1 -0
- package/dist/tools/reflex/index.d.ts +5 -0
- package/dist/tools/reflex/index.js +16 -0
- package/dist/tools/reflex/index.js.map +1 -0
- package/dist/tools/reflex/types.cjs +19 -0
- package/dist/tools/reflex/types.cjs.map +1 -0
- package/dist/tools/reflex/types.d.ts +113 -0
- package/dist/tools/reflex/types.js +1 -0
- package/dist/tools/reflex/types.js.map +1 -0
- package/dist/tools/utils/resilience.cjs +7 -2
- package/dist/tools/utils/resilience.cjs.map +1 -1
- package/dist/tools/utils/resilience.js +2 -2
- package/dist/tools/warp_grep/agent/runner.cjs +7 -2
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +2 -2
- package/dist/tools/warp_grep/anthropic.cjs +268 -52
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +2 -0
- package/dist/tools/warp_grep/anthropic.js +10 -6
- package/dist/tools/warp_grep/client.cjs +268 -52
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +8 -2
- package/dist/tools/warp_grep/client.js +9 -5
- package/dist/tools/warp_grep/gemini.cjs +268 -52
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +2 -0
- package/dist/tools/warp_grep/gemini.js +9 -5
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/harness.js +5 -5
- package/dist/tools/warp_grep/index.cjs +268 -52
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +2 -0
- package/dist/tools/warp_grep/index.js +12 -8
- package/dist/tools/warp_grep/openai.cjs +268 -52
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +2 -0
- package/dist/tools/warp_grep/openai.js +10 -6
- package/dist/tools/warp_grep/providers/local.js +2 -2
- package/dist/tools/warp_grep/vercel.cjs +268 -52
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +2 -0
- package/dist/tools/warp_grep/vercel.js +10 -6
- package/dist/version.cjs +7 -2
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
- package/dist/chunk-E5QWXVTF.js.map +0 -1
- package/dist/chunk-INBZD4EX.js +0 -197
- package/dist/chunk-INBZD4EX.js.map +0 -1
- package/dist/chunk-LAGN62H5.js.map +0 -1
- package/dist/chunk-LE66XCOI.js.map +0 -1
- package/dist/chunk-LNXIVRPY.js.map +0 -1
- package/dist/chunk-MKBVWPU7.js.map +0 -1
- package/dist/chunk-SCVWDNQP.js +0 -84
- package/dist/chunk-SCVWDNQP.js.map +0 -1
- package/dist/chunk-VE7J6VYX.js +0 -102
- package/dist/chunk-VE7J6VYX.js.map +0 -1
- package/dist/chunk-YG2I377B.js.map +0 -1
- /package/dist/{chunk-IY7DESC3.js.map → chunk-2SNAXTUJ.js.map} +0 -0
- /package/dist/{chunk-5KFQBI4J.js.map → chunk-5DA6SZQJ.js.map} +0 -0
- /package/dist/{chunk-76XER44U.js.map → chunk-7PVVPLRL.js.map} +0 -0
- /package/dist/{chunk-BCPZAPWY.js.map → chunk-AE7M2I52.js.map} +0 -0
- /package/dist/{chunk-OJQYBWHR.js.map → chunk-ESXCQBMU.js.map} +0 -0
- /package/dist/{chunk-5IR3YE77.js.map → chunk-IJ33I7P5.js.map} +0 -0
- /package/dist/{chunk-6LPWEZ6H.js.map → chunk-MO6S2LRD.js.map} +0 -0
- /package/dist/{chunk-S4IEM5EG.js.map → chunk-NI7PWQ3B.js.map} +0 -0
- /package/dist/{chunk-GLQWEINZ.js.map → chunk-QAXXE4AD.js.map} +0 -0
- /package/dist/{chunk-G4FPDEUP.js.map → chunk-QQXNZIVK.js.map} +0 -0
- /package/dist/{chunk-A3ZUWLYX.js.map → chunk-QZ3V2BP7.js.map} +0 -0
- /package/dist/{chunk-SYD6BRQX.js.map → chunk-SJVLAGUL.js.map} +0 -0
- /package/dist/{chunk-JMEQ6FLB.js.map → chunk-U4J3BVAQ.js.map} +0 -0
- /package/dist/{chunk-QAWYDWDW.js.map → chunk-U4MRSZQQ.js.map} +0 -0
- /package/dist/{chunk-WU3D46MH.js.map → chunk-UADW6FYD.js.map} +0 -0
- /package/dist/{chunk-K7NY5SVR.js.map → chunk-VBARKJWL.js.map} +0 -0
- /package/dist/{chunk-OPNTDMHH.js.map → chunk-VLZ6PNAD.js.map} +0 -0
- /package/dist/{chunk-GUGHUAJU.js.map → chunk-XJDXV5VX.js.map} +0 -0
- /package/dist/{chunk-GPNUS3H2.js.map → chunk-XYTYIAMQ.js.map} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
executeGitHubReadFile,
|
|
9
9
|
executeToolCall,
|
|
10
10
|
executeToolCallStreaming
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-CQF76HJC.js";
|
|
12
12
|
|
|
13
13
|
// tools/warp_grep/vercel.ts
|
|
14
14
|
import { tool } from "ai";
|
|
@@ -115,4 +115,4 @@ export {
|
|
|
115
115
|
createGitHubReadFileTool,
|
|
116
116
|
vercel_default
|
|
117
117
|
};
|
|
118
|
-
//# sourceMappingURL=chunk-
|
|
118
|
+
//# sourceMappingURL=chunk-MO6S2LRD.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeEditFile
|
|
3
|
+
} from "./chunk-Z4GJVN52.js";
|
|
1
4
|
import {
|
|
2
5
|
EDIT_FILE_SYSTEM_PROMPT,
|
|
3
6
|
EDIT_FILE_TOOL_DESCRIPTION
|
|
4
7
|
} from "./chunk-63WE2C5R.js";
|
|
5
|
-
import {
|
|
6
|
-
executeEditFile
|
|
7
|
-
} from "./chunk-MKBVWPU7.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -86,4 +86,4 @@ export {
|
|
|
86
86
|
vercel_default,
|
|
87
87
|
vercel_exports
|
|
88
88
|
};
|
|
89
|
-
//# sourceMappingURL=chunk-
|
|
89
|
+
//# sourceMappingURL=chunk-NI7PWQ3B.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CompactClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-66OHYI24.js";
|
|
4
4
|
|
|
5
5
|
// tools/compact/utils.ts
|
|
6
6
|
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
@@ -50,4 +50,4 @@ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4
|
|
|
50
50
|
export {
|
|
51
51
|
compactFileContexts
|
|
52
52
|
};
|
|
53
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-QAXXE4AD.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-F3NCFNUX.js";
|
|
4
4
|
import {
|
|
5
5
|
SDK_VERSION
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-GJZXDRH5.js";
|
|
7
7
|
|
|
8
8
|
// tools/fastapply/apply.ts
|
|
9
9
|
import { createTwoFilesPatch } from "diff";
|
|
@@ -84,11 +84,26 @@ async function callMorphAPI(originalCode, codeEdit, instructions, filepath, conf
|
|
|
84
84
|
return { content, completionId: completion.id };
|
|
85
85
|
} catch (error) {
|
|
86
86
|
const elapsed = Date.now() - startTime;
|
|
87
|
+
const status = error?.status || error?.response?.status;
|
|
87
88
|
logger.error("FastApply", "http_error", {
|
|
88
|
-
status
|
|
89
|
+
status,
|
|
89
90
|
error: error?.message,
|
|
90
91
|
latency_ms: elapsed
|
|
91
92
|
});
|
|
93
|
+
if (status === 401) {
|
|
94
|
+
const err = new Error(
|
|
95
|
+
"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."
|
|
96
|
+
);
|
|
97
|
+
err.status = 401;
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
if (status === 429) {
|
|
101
|
+
const err = new Error(
|
|
102
|
+
"Rate limited: You've exceeded your Morph API usage limits. Please visit https://morphllm.com to check your plan and purchase additional credits."
|
|
103
|
+
);
|
|
104
|
+
err.status = 429;
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
92
107
|
throw error;
|
|
93
108
|
}
|
|
94
109
|
}
|
|
@@ -130,4 +145,4 @@ export {
|
|
|
130
145
|
callMorphAPI,
|
|
131
146
|
applyEdit
|
|
132
147
|
};
|
|
133
|
-
//# sourceMappingURL=chunk-
|
|
148
|
+
//# sourceMappingURL=chunk-QFE5523Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/fastapply/apply.ts"],"sourcesContent":["/**\n * Edge-compatible code application API\n *\n * This module works on:\n * - Node.js\n * - Cloudflare Workers\n * - Vercel Edge Functions\n * - Deno Deploy\n * - Browser environments\n *\n * For file-based operations, use executeEditFile from core.ts\n */\n\nimport { createTwoFilesPatch } from 'diff';\nimport OpenAI from 'openai';\nimport { SDK_VERSION } from '../../version.js';\nimport { logger } from '../../logger.js';\nimport type {\n EditChanges,\n ApplyEditInput,\n ApplyEditResult,\n ApplyEditConfig,\n} from './types.js';\n\nconst DEFAULT_API_URL = 'https://api.morphllm.com';\nconst DEFAULT_TIMEOUT = 90000;\n\n/**\n * Generate a unified diff between two strings\n */\nexport function generateUdiff(\n original: string,\n modified: string,\n filepath: string\n): string {\n return createTwoFilesPatch(\n filepath,\n filepath,\n original,\n modified,\n 'Original',\n 'Modified'\n );\n}\n\n/**\n * Count changes from a unified diff\n */\nexport function countChanges(original: string, modified: string): EditChanges {\n const diff = generateUdiff(original, modified, 'file');\n const lines = diff.split('\\n');\n\n let linesAdded = 0;\n let linesRemoved = 0;\n\n for (const line of lines) {\n if (line.startsWith('+') && !line.startsWith('+++')) {\n linesAdded++;\n } else if (line.startsWith('-') && !line.startsWith('---')) {\n linesRemoved++;\n }\n }\n\n const linesModified = Math.min(linesAdded, linesRemoved);\n\n return {\n linesAdded: linesAdded - linesModified,\n linesRemoved: linesRemoved - linesModified,\n linesModified,\n };\n}\n\n/**\n * Call Morph Apply API to merge code edits\n * Uses OpenAI SDK for reliable connection handling, retries, and timeouts\n */\nexport async function callMorphAPI(\n originalCode: string,\n codeEdit: string,\n instructions: string,\n filepath: string,\n config: ApplyEditConfig\n): Promise<{ content: string; completionId?: string }> {\n const apiKey = config.morphApiKey || (typeof process !== 'undefined' ? process.env?.MORPH_API_KEY : undefined);\n const apiUrl = config.morphApiUrl || DEFAULT_API_URL;\n const useLarge = config.large ?? (typeof process !== 'undefined' ? process.env?.MORPH_LARGE_APPLY !== 'false' : true);\n const model = useLarge ? 'morph-v3-large' : 'morph-v3-fast';\n const timeout = config.timeout || DEFAULT_TIMEOUT;\n const debug = config.debug || false;\n\n if (!apiKey) {\n throw new Error(\n 'Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config.'\n );\n }\n\n // Format message with XML tags as per Morph Fast Apply spec\n const message = `<instruction>${instructions}</instruction>\\n<code>${originalCode}</code>\\n<update>${codeEdit}</update>`;\n\n logger.debug('FastApply', 'http_request', {\n url: `${apiUrl}/v1/chat/completions`,\n model,\n filepath,\n instruction_len: instructions.length,\n original_len: originalCode.length,\n code_edit_len: codeEdit.length,\n });\n\n const startTime = Date.now();\n\n const client = new OpenAI({\n apiKey,\n baseURL: `${apiUrl}/v1`,\n timeout,\n maxRetries: config.retryConfig?.maxRetries ?? 3,\n defaultHeaders: { 'X-Morph-SDK-Version': SDK_VERSION },\n });\n\n try {\n const completion = await client.chat.completions.create({\n model,\n messages: [{ role: 'user', content: message }],\n });\n\n const content = completion.choices[0]?.message?.content;\n if (!content) {\n throw new Error('Morph API returned empty response');\n }\n\n const elapsed = Date.now() - startTime;\n logger.debug('FastApply', 'http_response', { status: 200, completion_id: completion.id, content_len: content.length, latency_ms: elapsed });\n\n return { content, completionId: completion.id };\n } catch (error: any) {\n const elapsed = Date.now() - startTime;\n const status = error?.status || error?.response?.status;\n logger.error('FastApply', 'http_error', {\n status,\n error: error?.message,\n latency_ms: elapsed,\n });\n\n if (status === 401) {\n const err = new Error(\n 'Authentication failed: Your Morph API key is invalid or has been revoked. ' +\n 'Please visit https://morphllm.com to get a valid API key, then update your MCP configuration.'\n );\n (err as any).status = 401;\n throw err;\n }\n\n if (status === 429) {\n const err = new Error(\n 'Rate limited: You\\'ve exceeded your Morph API usage limits. ' +\n 'Please visit https://morphllm.com to check your plan and purchase additional credits.'\n );\n (err as any).status = 429;\n throw err;\n }\n\n throw error;\n }\n}\n\n/**\n * Apply an edit to code directly without file I/O\n *\n * This is the edge-compatible code-in/code-out API that accepts code content directly\n * and returns the merged result without reading or writing any files.\n *\n * Works on Cloudflare Workers, Vercel Edge Functions, Deno, and browsers.\n *\n * @param input - Code and edit parameters\n * @param config - Optional configuration\n * @returns Result with merged code\n *\n * @example\n * ```typescript\n * import { applyEdit } from '@morphllm/morphsdk';\n *\n * const result = await applyEdit({\n * originalCode: fs.readFileSync('file.ts', 'utf-8'),\n * codeEdit: '// ... existing code ...\\nconst newVar = 42;\\n// ... existing code ...',\n * instructions: 'Add a new variable',\n * // filepath is accepted but does nothing\n * });\n *\n * if (result.success) {\n * fs.writeFileSync('file.ts', result.mergedCode);\n * }\n * ```\n */\nexport async function applyEdit(\n input: ApplyEditInput,\n config: ApplyEditConfig = {}\n): Promise<ApplyEditResult> {\n const filepath = input.filepath || 'file';\n\n try {\n logger.debug('FastApply', 'apply_edit_start', { original_len: input.originalCode.length, code_edit_len: input.codeEdit.length });\n\n const instruction = input.instruction ?? input.instructions ?? '';\n const { content: mergedCode, completionId } = await callMorphAPI(\n input.originalCode,\n input.codeEdit,\n instruction,\n filepath,\n config\n );\n\n const udiff = config.generateUdiff !== false\n ? generateUdiff(input.originalCode, mergedCode, filepath)\n : undefined;\n\n const changes = countChanges(input.originalCode, mergedCode);\n\n return {\n success: true,\n mergedCode,\n udiff,\n changes,\n completionId,\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';\n logger.error('FastApply', 'apply_edit_error', { error: errorMessage });\n\n return {\n success: false,\n changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n error: errorMessage,\n };\n }\n}\n"],"mappings":";;;;;;;;AAaA,SAAS,2BAA2B;AACpC,OAAO,YAAY;AAUnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AAKjB,SAAS,cACd,UACA,UACA,UACQ;AACR,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAKO,SAAS,aAAa,UAAkB,UAA+B;AAC5E,QAAM,OAAO,cAAc,UAAU,UAAU,MAAM;AACrD,QAAM,QAAQ,KAAK,MAAM,IAAI;AAE7B,MAAI,aAAa;AACjB,MAAI,eAAe;AAEnB,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,WAAW,KAAK,GAAG;AACnD;AAAA,IACF,WAAW,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,WAAW,KAAK,GAAG;AAC1D;AAAA,IACF;AAAA,EACF;AAEA,QAAM,gBAAgB,KAAK,IAAI,YAAY,YAAY;AAEvD,SAAO;AAAA,IACL,YAAY,aAAa;AAAA,IACzB,cAAc,eAAe;AAAA,IAC7B;AAAA,EACF;AACF;AAMA,eAAsB,aACpB,cACA,UACA,cACA,UACA,QACqD;AACrD,QAAM,SAAS,OAAO,gBAAgB,OAAO,YAAY,cAAc,QAAQ,KAAK,gBAAgB;AACpG,QAAM,SAAS,OAAO,eAAe;AACrC,QAAM,WAAW,OAAO,UAAU,OAAO,YAAY,cAAc,QAAQ,KAAK,sBAAsB,UAAU;AAChH,QAAM,QAAQ,WAAW,mBAAmB;AAC5C,QAAM,UAAU,OAAO,WAAW;AAClC,QAAM,QAAQ,OAAO,SAAS;AAE9B,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,UAAU,gBAAgB,YAAY;AAAA,QAAyB,YAAY;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AAAA,QACd;AAAA,MAEF;AACA,MAAC,IAAY,SAAS;AACtB,YAAM;AAAA,IACR;AAEA,UAAM;AAAA,EACR;AACF;AA8BA,eAAsB,UACpB,OACA,SAA0B,CAAC,GACD;AAC1B,QAAM,WAAW,MAAM,YAAY;AAEnC,MAAI;AACF,WAAO,MAAM,aAAa,oBAAoB,EAAE,cAAc,MAAM,aAAa,QAAQ,eAAe,MAAM,SAAS,OAAO,CAAC;AAE/H,UAAM,cAAc,MAAM,eAAe,MAAM,gBAAgB;AAC/D,UAAM,EAAE,SAAS,YAAY,aAAa,IAAI,MAAM;AAAA,MAClD,MAAM;AAAA,MACN,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,UAAM,QAAQ,OAAO,kBAAkB,QACnC,cAAc,MAAM,cAAc,YAAY,QAAQ,IACtD;AAEJ,UAAM,UAAU,aAAa,MAAM,cAAc,UAAU;AAE3D,WAAO;AAAA,MACL,SAAS;AAAA,MACT;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,UAAM,eAAe,iBAAiB,QAAQ,MAAM,UAAU;AAC9D,WAAO,MAAM,aAAa,oBAAoB,EAAE,OAAO,aAAa,CAAC;AAErE,WAAO;AAAA,MACL,SAAS;AAAA,MACT,SAAS,EAAE,YAAY,GAAG,cAAc,GAAG,eAAe,EAAE;AAAA,MAC5D,OAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeEditFile
|
|
3
|
+
} from "./chunk-Z4GJVN52.js";
|
|
1
4
|
import {
|
|
2
5
|
EDIT_FILE_SYSTEM_PROMPT,
|
|
3
6
|
EDIT_FILE_TOOL_DESCRIPTION
|
|
4
7
|
} from "./chunk-63WE2C5R.js";
|
|
5
|
-
import {
|
|
6
|
-
executeEditFile
|
|
7
|
-
} from "./chunk-MKBVWPU7.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -79,4 +79,4 @@ export {
|
|
|
79
79
|
getSystemPrompt,
|
|
80
80
|
anthropic_exports
|
|
81
81
|
};
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-QQXNZIVK.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
WarpGrepClient,
|
|
3
3
|
formatResult
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-CQF76HJC.js";
|
|
5
5
|
import {
|
|
6
6
|
CODEBASE_SEARCH_TOOL,
|
|
7
7
|
SEND_MESSAGE_TOOL,
|
|
@@ -262,4 +262,4 @@ function deduplicateContexts(contexts) {
|
|
|
262
262
|
export {
|
|
263
263
|
createExploreSubagent
|
|
264
264
|
};
|
|
265
|
-
//# sourceMappingURL=chunk-
|
|
265
|
+
//# sourceMappingURL=chunk-QZ3V2BP7.js.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MorphError
|
|
3
|
+
} from "./chunk-XYTYIAMQ.js";
|
|
4
|
+
|
|
5
|
+
// core/error.ts
|
|
6
|
+
async function toMorphError(response) {
|
|
7
|
+
let message = `Morph API request failed (${response.status})`;
|
|
8
|
+
let code = "api_error";
|
|
9
|
+
try {
|
|
10
|
+
const body = await response.json();
|
|
11
|
+
message = body.error?.message ?? body.message ?? message;
|
|
12
|
+
code = body.error?.code ?? body.error?.type ?? code;
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
if (response.status === 401) code = "authentication_error";
|
|
16
|
+
if (response.status === 429) code = "rate_limit_exceeded";
|
|
17
|
+
const retryable = response.status === 429 || response.status === 503;
|
|
18
|
+
return new MorphError(message, code, response.status, retryable);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
toMorphError
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=chunk-QZR7SJ5N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../core/error.ts"],"sourcesContent":["/**\n * Single error mapper for the SDK transport.\n *\n * Consolidates the per-tool error handling that used to live in every client\n * (compact, reflex, github, …) into one place, preserving the actionable\n * 401/429 messaging. Reuses the existing `MorphError` type so callers that\n * `instanceof MorphError` keep working.\n */\nimport { MorphError } from '../tools/utils/resilience.js';\n\ninterface ApiErrorBody {\n error?: { message?: string; code?: string; type?: string };\n message?: string;\n}\n\n/**\n * Turn a non-OK `Response` into a `MorphError`, extracting the API's error\n * message when present and marking 429/503 as retryable.\n */\nexport async function toMorphError(response: Response): Promise<MorphError> {\n let message = `Morph API request failed (${response.status})`;\n let code = 'api_error';\n\n try {\n const body = (await response.json()) as ApiErrorBody;\n message = body.error?.message ?? body.message ?? message;\n code = body.error?.code ?? body.error?.type ?? code;\n } catch {\n // Non-JSON body — keep the status-based default message.\n }\n\n if (response.status === 401) code = 'authentication_error';\n if (response.status === 429) code = 'rate_limit_exceeded';\n\n const retryable = response.status === 429 || response.status === 503;\n return new MorphError(message, code, response.status, retryable);\n}\n"],"mappings":";;;;;AAmBA,eAAsB,aAAa,UAAyC;AAC1E,MAAI,UAAU,6BAA6B,SAAS,MAAM;AAC1D,MAAI,OAAO;AAEX,MAAI;AACF,UAAM,OAAQ,MAAM,SAAS,KAAK;AAClC,cAAU,KAAK,OAAO,WAAW,KAAK,WAAW;AACjD,WAAO,KAAK,OAAO,QAAQ,KAAK,OAAO,QAAQ;AAAA,EACjD,QAAQ;AAAA,EAER;AAEA,MAAI,SAAS,WAAW,IAAK,QAAO;AACpC,MAAI,SAAS,WAAW,IAAK,QAAO;AAEpC,QAAM,YAAY,SAAS,WAAW,OAAO,SAAS,WAAW;AACjE,SAAO,IAAI,WAAW,SAAS,MAAM,SAAS,QAAQ,SAAS;AACjE;","names":[]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
executeCodebaseSearch
|
|
3
|
-
} from "./chunk-VE7J6VYX.js";
|
|
4
1
|
import {
|
|
5
2
|
CODEBASE_SEARCH_DESCRIPTION,
|
|
6
3
|
CODEBASE_SEARCH_SYSTEM_PROMPT
|
|
7
4
|
} from "./chunk-YQMPVJ2L.js";
|
|
5
|
+
import {
|
|
6
|
+
executeCodebaseSearch
|
|
7
|
+
} from "./chunk-ZLSNL6M2.js";
|
|
8
8
|
|
|
9
9
|
// tools/codebase_search/openai.ts
|
|
10
10
|
var codebaseSearchTool = {
|
|
@@ -125,4 +125,4 @@ export {
|
|
|
125
125
|
getSystemPrompt,
|
|
126
126
|
openai_default
|
|
127
127
|
};
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
128
|
+
//# sourceMappingURL=chunk-SJVLAGUL.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeEditFile
|
|
3
|
+
} from "./chunk-Z4GJVN52.js";
|
|
1
4
|
import {
|
|
2
5
|
EDIT_FILE_SYSTEM_PROMPT,
|
|
3
6
|
EDIT_FILE_TOOL_DESCRIPTION
|
|
4
7
|
} from "./chunk-63WE2C5R.js";
|
|
5
|
-
import {
|
|
6
|
-
executeEditFile
|
|
7
|
-
} from "./chunk-MKBVWPU7.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -91,4 +91,4 @@ export {
|
|
|
91
91
|
openai_default,
|
|
92
92
|
openai_exports
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-U4J3BVAQ.js.map
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
executeToolCall,
|
|
15
15
|
formatGitHubReadFileResult,
|
|
16
16
|
formatResult
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-CQF76HJC.js";
|
|
18
18
|
|
|
19
19
|
// tools/warp_grep/openai.ts
|
|
20
20
|
var TOOL_PARAMETERS = {
|
|
@@ -104,4 +104,4 @@ export {
|
|
|
104
104
|
createGitHubReadFileTool,
|
|
105
105
|
openai_default
|
|
106
106
|
};
|
|
107
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-U4MRSZQQ.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-2HMEZZKK.js";
|
|
5
5
|
import {
|
|
6
6
|
executeBrowserTask
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-FOIDGIY4.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -93,4 +93,4 @@ export {
|
|
|
93
93
|
createBrowserTool,
|
|
94
94
|
openai_exports
|
|
95
95
|
};
|
|
96
|
-
//# sourceMappingURL=chunk-
|
|
96
|
+
//# sourceMappingURL=chunk-UADW6FYD.js.map
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "./chunk-2VERUKO2.js";
|
|
13
13
|
import {
|
|
14
14
|
fetchWithRetry
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-XYTYIAMQ.js";
|
|
16
16
|
|
|
17
17
|
// tools/browser/profiles/core.ts
|
|
18
18
|
var DEFAULT_API_URL = process.env.MORPH_ENVIRONMENT === "DEV" ? "http://localhost:8000" : "https://browser.morphllm.com";
|
|
@@ -386,4 +386,4 @@ export {
|
|
|
386
386
|
listRepos,
|
|
387
387
|
getProfileState
|
|
388
388
|
};
|
|
389
|
-
//# sourceMappingURL=chunk-
|
|
389
|
+
//# sourceMappingURL=chunk-VBARKJWL.js.map
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
readAllLines
|
|
3
|
-
} from "./chunk-G2RSY56Q.js";
|
|
4
1
|
import {
|
|
5
2
|
fixPathRepetition,
|
|
6
3
|
isSymlink,
|
|
@@ -11,6 +8,9 @@ import {
|
|
|
11
8
|
import {
|
|
12
9
|
runRipgrep
|
|
13
10
|
} from "./chunk-TPP2UGQP.js";
|
|
11
|
+
import {
|
|
12
|
+
readAllLines
|
|
13
|
+
} from "./chunk-G2RSY56Q.js";
|
|
14
14
|
import {
|
|
15
15
|
AGENT_CONFIG,
|
|
16
16
|
DEFAULT_EXCLUDES
|
|
@@ -341,4 +341,4 @@ Details: ${res.stderr}` : ""}`
|
|
|
341
341
|
export {
|
|
342
342
|
LocalRipgrepProvider
|
|
343
343
|
};
|
|
344
|
-
//# sourceMappingURL=chunk-
|
|
344
|
+
//# sourceMappingURL=chunk-VLZ6PNAD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-VZ7BOH2K.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-2HMEZZKK.js";
|
|
4
4
|
import {
|
|
5
5
|
executeBrowserTask
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FOIDGIY4.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
browserTool,
|
|
55
55
|
vercel_exports
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-XJDXV5VX.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SDK_VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-GJZXDRH5.js";
|
|
4
4
|
|
|
5
5
|
// tools/utils/resilience.ts
|
|
6
6
|
var DEFAULT_RETRY_CONFIG = {
|
|
@@ -91,4 +91,4 @@ export {
|
|
|
91
91
|
withTimeout,
|
|
92
92
|
MorphError
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-XYTYIAMQ.js.map
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MorphAPIClient
|
|
3
|
+
} from "./chunk-453ZV2AX.js";
|
|
1
4
|
import {
|
|
2
5
|
logger
|
|
3
6
|
} from "./chunk-F3NCFNUX.js";
|
|
7
|
+
import {
|
|
8
|
+
APIResource
|
|
9
|
+
} from "./chunk-LKFZBBTD.js";
|
|
4
10
|
|
|
5
11
|
// tools/fastapply/core.ts
|
|
6
12
|
import { join, resolve, relative } from "path";
|
|
@@ -12,15 +18,24 @@ var DEFAULT_CONFIG = {
|
|
|
12
18
|
timeout: 9e4,
|
|
13
19
|
debug: false
|
|
14
20
|
};
|
|
15
|
-
var FastApplyClient = class {
|
|
21
|
+
var FastApplyClient = class extends APIResource {
|
|
16
22
|
config;
|
|
17
|
-
constructor(
|
|
23
|
+
constructor(clientOrConfig = {}) {
|
|
24
|
+
const isClient = clientOrConfig instanceof MorphAPIClient;
|
|
25
|
+
super(
|
|
26
|
+
isClient ? clientOrConfig : new MorphAPIClient({
|
|
27
|
+
apiKey: clientOrConfig.apiKey,
|
|
28
|
+
timeout: clientOrConfig.timeout ?? DEFAULT_CONFIG.timeout,
|
|
29
|
+
retryConfig: clientOrConfig.retryConfig,
|
|
30
|
+
debug: clientOrConfig.debug
|
|
31
|
+
})
|
|
32
|
+
);
|
|
18
33
|
this.config = {
|
|
19
|
-
morphApiKey:
|
|
20
|
-
morphApiUrl:
|
|
21
|
-
debug:
|
|
22
|
-
timeout:
|
|
23
|
-
retryConfig:
|
|
34
|
+
morphApiKey: this._client.resolveApiKey(),
|
|
35
|
+
morphApiUrl: this._client.baseURL,
|
|
36
|
+
debug: this._client.debug,
|
|
37
|
+
timeout: (isClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_CONFIG.timeout,
|
|
38
|
+
retryConfig: this._client.retryConfig,
|
|
24
39
|
generateUdiff: DEFAULT_CONFIG.generateUdiff,
|
|
25
40
|
autoWrite: DEFAULT_CONFIG.autoWrite
|
|
26
41
|
};
|
|
@@ -124,4 +139,4 @@ export {
|
|
|
124
139
|
FastApplyClient,
|
|
125
140
|
executeEditFile
|
|
126
141
|
};
|
|
127
|
-
//# sourceMappingURL=chunk-
|
|
142
|
+
//# sourceMappingURL=chunk-Z4GJVN52.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/fastapply/core.ts"],"sourcesContent":["/**\n * Core implementation of Morph Fast Apply\n *\n * This module provides file-based operations that require Node.js.\n * For edge-compatible code-in/code-out operations, use applyEdit from ./apply.ts\n */\n\nimport { join, resolve, relative } from 'path';\nimport type {\n EditFileInput,\n EditFileResult,\n EditFileConfig,\n} from './types.js';\nimport { logger } from '../../logger.js';\nimport { MorphAPIClient } from '../../core/client.js';\nimport { APIResource } from '../../core/resource.js';\n\n// Re-export edge-compatible functions\nexport { applyEdit, generateUdiff, countChanges, callMorphAPI } from './apply.js';\n\nconst DEFAULT_CONFIG: Required<Omit<EditFileConfig, 'morphApiKey' | 'systemPrompt' | 'retryConfig' | 'description' | 'large'>> = {\n morphApiUrl: 'https://api.morphllm.com',\n baseDir: process.cwd(),\n generateUdiff: true,\n autoWrite: true,\n timeout: 90000,\n debug: false,\n};\n\n/**\n * FastApply client for programmatic file editing\n * Note: This client requires Node.js for file operations\n *\n * @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).fastApply`).\n * Standalone clients remain only for backwards compatibility and may be removed in a future\n * major version — do not use them in new code.\n */\nexport class FastApplyClient extends APIResource {\n private config: EditFileConfig;\n\n constructor(clientOrConfig: MorphAPIClient | { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {}) {\n const isClient = clientOrConfig instanceof MorphAPIClient;\n super(\n isClient\n ? clientOrConfig\n : new MorphAPIClient({\n apiKey: clientOrConfig.apiKey,\n timeout: clientOrConfig.timeout ?? DEFAULT_CONFIG.timeout,\n retryConfig: clientOrConfig.retryConfig,\n debug: clientOrConfig.debug,\n }),\n );\n // FastApply talks to /v1/chat/completions through the `openai` package, but\n // sources its credentials and host from the shared transport.\n this.config = {\n morphApiKey: this._client.resolveApiKey(),\n morphApiUrl: this._client.baseURL,\n debug: this._client.debug,\n timeout: (isClient ? undefined : clientOrConfig.timeout) ?? DEFAULT_CONFIG.timeout,\n retryConfig: this._client.retryConfig,\n generateUdiff: DEFAULT_CONFIG.generateUdiff,\n autoWrite: DEFAULT_CONFIG.autoWrite,\n };\n }\n\n /**\n * Execute a file edit operation\n *\n * @param input - Edit parameters including filepath, instructions, and code_edit\n * @param overrides - Optional config overrides for this operation\n * @returns Edit result with success status and changes\n */\n async execute(input: EditFileInput, overrides?: Partial<EditFileConfig>): Promise<EditFileResult> {\n return executeEditFile(input, { ...this.config, ...overrides });\n }\n\n /**\n * Apply an edit to code directly without file I/O\n *\n * Useful for sandbox environments or when you manage your own file system.\n * Compatible with the earlier OpenAI client API contract.\n *\n * @param input - Code and edit parameters\n * @param overrides - Optional config overrides for this operation\n * @returns Result with merged code\n *\n * @example\n * ```typescript\n * const result = await client.applyEdit({\n * originalCode: 'function hello() { return \"world\"; }',\n * codeEdit: 'function hello() { return \"universe\"; }',\n * instructions: 'Change return value'\n * });\n * console.log(result.mergedCode);\n * ```\n */\n async applyEdit(input: import('./types.js').ApplyEditInput, overrides?: Partial<import('./types.js').ApplyEditConfig>): Promise<import('./types.js').ApplyEditResult> {\n const { applyEdit } = await import('./apply.js');\n return applyEdit(input, { ...this.config, ...overrides });\n }\n}\n\n/**\n * Execute a file edit using Morph Fast Apply\n * Note: This function requires Node.js for file I/O\n */\nexport async function executeEditFile(\n input: EditFileInput,\n config: EditFileConfig = {}\n): Promise<EditFileResult> {\n const baseDir = config.baseDir || DEFAULT_CONFIG.baseDir;\n const fullPath = resolve(join(baseDir, input.target_filepath));\n\n logger.debug('FastApply', 'execute_start', { target_filepath: input.target_filepath, baseDir, autoWrite: config.autoWrite !== false });\n\n // Security: ensure file is within baseDir\n const relativePath = relative(baseDir, fullPath);\n if (relativePath.startsWith('..') || fullPath === baseDir) {\n logger.warn('FastApply', 'security_check_failed', { target_filepath: input.target_filepath, relative: relativePath });\n return {\n success: false,\n filepath: input.target_filepath,\n changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n error: `Invalid filepath: '${input.target_filepath}' is outside baseDir`,\n };\n }\n\n logger.debug('FastApply', 'security_check', { resolved: fullPath, relative: relativePath });\n\n try {\n // Dynamic import to avoid loading Node.js fs module at module evaluation time\n const { readFile, writeFile } = await import('fs/promises');\n const { callMorphAPI, generateUdiff, countChanges } = await import('./apply.js');\n\n // Handle both existing and non-existent files\n let originalCode = '';\n let fileExists = true;\n try {\n originalCode = await readFile(fullPath, 'utf-8');\n logger.debug('FastApply', 'file_read', { path: fullPath, exists: true, size_bytes: originalCode.length });\n } catch (error: any) {\n if (error.code !== 'ENOENT') {\n throw error; // Re-throw if it's not a \"file not found\" error\n }\n fileExists = false;\n logger.debug('FastApply', 'file_read', { path: fullPath, exists: false });\n }\n\n const instruction = input.instruction ?? input.instructions ?? '';\n logger.debug('FastApply', 'api_call', { instruction_len: instruction.length, code_edit_len: input.code_edit.length, original_len: originalCode.length });\n\n const { content: mergedCode, completionId } = await callMorphAPI(originalCode, input.code_edit, instruction, input.target_filepath, config);\n\n logger.debug('FastApply', 'api_response', { completion_id: completionId, merged_len: mergedCode.length });\n\n const udiff = config.generateUdiff !== false ? generateUdiff(originalCode, mergedCode, input.target_filepath) : undefined;\n\n if (config.autoWrite !== false) {\n await writeFile(fullPath, mergedCode, 'utf-8');\n logger.debug('FastApply', 'file_write', { path: fullPath, size_bytes: mergedCode.length });\n }\n\n const changes = countChanges(originalCode, mergedCode);\n logger.debug('FastApply', 'changes', { added: changes.linesAdded, removed: changes.linesRemoved, modified: changes.linesModified });\n\n return {\n success: true,\n filepath: input.target_filepath,\n udiff,\n changes,\n completionId,\n };\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';\n logger.error('FastApply', 'execute_error', { error: errorMessage, target_filepath: input.target_filepath, stack: error instanceof Error ? error.stack : undefined });\n\n return {\n success: false,\n filepath: input.target_filepath,\n changes: { linesAdded: 0, linesRemoved: 0, linesModified: 0 },\n error: errorMessage,\n };\n }\n}\n"],"mappings":";;;;;;;;;;;AAOA,SAAS,MAAM,SAAS,gBAAgB;AAaxC,IAAM,iBAA2H;AAAA,EAC/H,aAAa;AAAA,EACb,SAAS,QAAQ,IAAI;AAAA,EACrB,eAAe;AAAA,EACf,WAAW;AAAA,EACX,SAAS;AAAA,EACT,OAAO;AACT;AAUO,IAAM,kBAAN,cAA8B,YAAY;AAAA,EACvC;AAAA,EAER,YAAY,iBAA6G,CAAC,GAAG;AAC3H,UAAM,WAAW,0BAA0B;AAC3C;AAAA,MACE,WACI,iBACA,IAAI,eAAe;AAAA,QACjB,QAAQ,eAAe;AAAA,QACvB,SAAS,eAAe,WAAW,eAAe;AAAA,QAClD,aAAa,eAAe;AAAA,QAC5B,OAAO,eAAe;AAAA,MACxB,CAAC;AAAA,IACP;AAGA,SAAK,SAAS;AAAA,MACZ,aAAa,KAAK,QAAQ,cAAc;AAAA,MACxC,aAAa,KAAK,QAAQ;AAAA,MAC1B,OAAO,KAAK,QAAQ;AAAA,MACpB,UAAU,WAAW,SAAY,eAAe,YAAY,eAAe;AAAA,MAC3E,aAAa,KAAK,QAAQ;AAAA,MAC1B,eAAe,eAAe;AAAA,MAC9B,WAAW,eAAe;AAAA,IAC5B;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,QAAQ,OAAsB,WAA8D;AAChG,WAAO,gBAAgB,OAAO,EAAE,GAAG,KAAK,QAAQ,GAAG,UAAU,CAAC;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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A,IACT;AAAA,EACF;AACF;","names":["applyEdit","callMorphAPI","generateUdiff","countChanges"]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MorphAPIClient
|
|
3
|
+
} from "./chunk-453ZV2AX.js";
|
|
4
|
+
import {
|
|
5
|
+
logger
|
|
6
|
+
} from "./chunk-F3NCFNUX.js";
|
|
7
|
+
import {
|
|
8
|
+
MorphError
|
|
9
|
+
} from "./chunk-XYTYIAMQ.js";
|
|
10
|
+
import {
|
|
11
|
+
APIResource
|
|
12
|
+
} from "./chunk-LKFZBBTD.js";
|
|
13
|
+
|
|
14
|
+
// tools/codebase_search/core.ts
|
|
15
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
16
|
+
var emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };
|
|
17
|
+
async function runSearch(client, input, repoId, timeout, baseURL) {
|
|
18
|
+
const startTime = Date.now();
|
|
19
|
+
logger.debug("CodebaseSearch", "request", { query: input.query.slice(0, 100), repo_id: repoId });
|
|
20
|
+
try {
|
|
21
|
+
const data = await client.post(
|
|
22
|
+
"/v1/codebase_search",
|
|
23
|
+
{
|
|
24
|
+
baseURL: baseURL ?? client.reposURL,
|
|
25
|
+
timeout,
|
|
26
|
+
body: {
|
|
27
|
+
query: input.query,
|
|
28
|
+
repoId,
|
|
29
|
+
targetDirectories: input.target_directories || [],
|
|
30
|
+
limit: input.limit || 10,
|
|
31
|
+
candidateLimit: 50
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
const elapsed = Date.now() - startTime;
|
|
36
|
+
logger.debug("CodebaseSearch", "response", { results_count: data.results?.length || 0, latency_ms: elapsed });
|
|
37
|
+
return {
|
|
38
|
+
success: true,
|
|
39
|
+
results: data.results || [],
|
|
40
|
+
stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed }
|
|
41
|
+
};
|
|
42
|
+
} catch (error) {
|
|
43
|
+
const message = error instanceof MorphError && error.statusCode ? `Search failed (${error.statusCode}): ${error.message}` : error instanceof Error ? error.message : "Unknown error";
|
|
44
|
+
logger.error("CodebaseSearch", "error", { error: message, latency_ms: Date.now() - startTime });
|
|
45
|
+
return { success: false, results: [], stats: { ...emptyStats }, error: message };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var CodebaseSearchClient = class extends APIResource {
|
|
49
|
+
timeout;
|
|
50
|
+
constructor(clientOrConfig = {}) {
|
|
51
|
+
super(
|
|
52
|
+
clientOrConfig instanceof MorphAPIClient ? clientOrConfig : new MorphAPIClient({
|
|
53
|
+
apiKey: clientOrConfig.apiKey,
|
|
54
|
+
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
|
|
55
|
+
retryConfig: clientOrConfig.retryConfig,
|
|
56
|
+
debug: clientOrConfig.debug
|
|
57
|
+
})
|
|
58
|
+
);
|
|
59
|
+
this.timeout = (clientOrConfig instanceof MorphAPIClient ? void 0 : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Execute a semantic code search
|
|
63
|
+
*
|
|
64
|
+
* @param input - Search parameters including query, repoId, and target directories
|
|
65
|
+
* @param overrides - Optional config overrides for this operation
|
|
66
|
+
* @returns Search results with ranked code matches
|
|
67
|
+
*/
|
|
68
|
+
async search(input, overrides) {
|
|
69
|
+
return runSearch(
|
|
70
|
+
this._client,
|
|
71
|
+
{ query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },
|
|
72
|
+
input.repoId,
|
|
73
|
+
overrides?.timeout ?? this.timeout,
|
|
74
|
+
overrides?.searchUrl
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
async function executeCodebaseSearch(input, config) {
|
|
79
|
+
const apiKey = config.apiKey || process.env.MORPH_API_KEY;
|
|
80
|
+
if (!apiKey) {
|
|
81
|
+
throw new Error("MORPH_API_KEY not found. Set environment variable or pass in config");
|
|
82
|
+
}
|
|
83
|
+
const client = new MorphAPIClient({
|
|
84
|
+
apiKey,
|
|
85
|
+
reposURL: config.searchUrl,
|
|
86
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT,
|
|
87
|
+
retryConfig: config.retryConfig,
|
|
88
|
+
debug: config.debug
|
|
89
|
+
});
|
|
90
|
+
return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT, config.searchUrl);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export {
|
|
94
|
+
CodebaseSearchClient,
|
|
95
|
+
executeCodebaseSearch
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=chunk-ZLSNL6M2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/codebase_search/core.ts"],"sourcesContent":["/**\n * Core implementation for codebase search.\n * Calls the Morph rerank service for two-stage semantic search over the\n * code-storage host, through the shared `MorphAPIClient` transport.\n */\nimport { MorphAPIClient } from '../../core/client.js';\nimport { APIResource } from '../../core/resource.js';\nimport { MorphError } from '../utils/resilience.js';\nimport { logger } from '../../logger.js';\nimport type { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './types.js';\n\nconst DEFAULT_TIMEOUT = 30000;\n\nconst emptyStats = { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: 0 };\n\n/**\n * Run a search against `/v1/codebase_search` on the repos host. HTTP failures\n * are returned in-band as `{ success: false, error }` (never thrown), matching\n * the long-standing contract callers rely on.\n */\nasync function runSearch(\n client: MorphAPIClient,\n input: CodebaseSearchInput,\n repoId: string,\n timeout: number,\n baseURL?: string,\n): Promise<CodebaseSearchResult> {\n const startTime = Date.now();\n logger.debug('CodebaseSearch', 'request', { query: input.query.slice(0, 100), repo_id: repoId });\n\n try {\n const data = await client.post<{ results?: unknown[]; stats?: CodebaseSearchResult['stats'] }>(\n '/v1/codebase_search',\n {\n baseURL: baseURL ?? client.reposURL,\n timeout,\n body: {\n query: input.query,\n repoId,\n targetDirectories: input.target_directories || [],\n limit: input.limit || 10,\n candidateLimit: 50,\n },\n },\n );\n\n const elapsed = Date.now() - startTime;\n logger.debug('CodebaseSearch', 'response', { results_count: data.results?.length || 0, latency_ms: elapsed });\n return {\n success: true,\n results: (data.results as CodebaseSearchResult['results']) || [],\n stats: data.stats || { totalResults: 0, candidatesRetrieved: 0, searchTimeMs: elapsed },\n };\n } catch (error) {\n const message =\n error instanceof MorphError && error.statusCode\n ? `Search failed (${error.statusCode}): ${error.message}`\n : error instanceof Error\n ? error.message\n : 'Unknown error';\n logger.error('CodebaseSearch', 'error', { error: message, latency_ms: Date.now() - startTime });\n return { success: false, results: [], stats: { ...emptyStats }, error: message };\n }\n}\n\n/**\n * CodebaseSearch client for programmatic semantic search\n *\n * @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).codebaseSearch`).\n * Standalone clients remain only for backwards compatibility and may be removed in a future\n * major version — do not use them in new code.\n */\nexport class CodebaseSearchClient extends APIResource {\n private readonly timeout: number;\n\n constructor(\n clientOrConfig: MorphAPIClient | { apiKey?: string; debug?: boolean; timeout?: number; retryConfig?: any } = {},\n ) {\n super(\n clientOrConfig instanceof MorphAPIClient\n ? clientOrConfig\n : new MorphAPIClient({\n apiKey: clientOrConfig.apiKey,\n timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,\n retryConfig: clientOrConfig.retryConfig,\n debug: clientOrConfig.debug,\n }),\n );\n this.timeout = (clientOrConfig instanceof MorphAPIClient ? undefined : clientOrConfig.timeout) ?? DEFAULT_TIMEOUT;\n }\n\n /**\n * Execute a semantic code search\n *\n * @param input - Search parameters including query, repoId, and target directories\n * @param overrides - Optional config overrides for this operation\n * @returns Search results with ranked code matches\n */\n async search(\n input: { query: string; repoId: string; target_directories?: string[]; explanation?: string; limit?: number },\n overrides?: { searchUrl?: string; timeout?: number },\n ): Promise<CodebaseSearchResult> {\n return runSearch(\n this._client,\n { query: input.query, target_directories: input.target_directories, explanation: input.explanation, limit: input.limit },\n input.repoId,\n overrides?.timeout ?? this.timeout,\n overrides?.searchUrl,\n );\n }\n}\n\n/**\n * Execute semantic code search (standalone — builds its own transport).\n * Throws on a missing API key; returns `{ success: false, error }` on HTTP failure.\n */\nexport async function executeCodebaseSearch(\n input: CodebaseSearchInput,\n config: CodebaseSearchConfig,\n): Promise<CodebaseSearchResult> {\n const apiKey = config.apiKey || process.env.MORPH_API_KEY;\n if (!apiKey) {\n throw new Error('MORPH_API_KEY not found. Set environment variable or pass in config');\n }\n\n const client = new MorphAPIClient({\n apiKey,\n reposURL: config.searchUrl,\n timeout: config.timeout ?? DEFAULT_TIMEOUT,\n retryConfig: config.retryConfig,\n debug: config.debug,\n });\n\n return runSearch(client, input, config.repoId, config.timeout ?? DEFAULT_TIMEOUT, config.searchUrl);\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,IAAM,kBAAkB;AAExB,IAAM,aAAa,EAAE,cAAc,GAAG,qBAAqB,GAAG,cAAc,EAAE;AAO9E,eAAe,UACb,QACA,OACA,QACA,SACA,SAC+B;AAC/B,QAAM,YAAY,KAAK,IAAI;AAC3B,SAAO,MAAM,kBAAkB,WAAW,EAAE,OAAO,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,SAAS,OAAO,CAAC;AAE/F,MAAI;AACF,UAAM,OAAO,MAAM,OAAO;AAAA,MACxB;AAAA,MACA;AAAA,QACE,SAAS,WAAW,OAAO;AAAA,QAC3B;AAAA,QACA,MAAM;AAAA,UACJ,OAAO,MAAM;AAAA,UACb;AAAA,UACA,mBAAmB,MAAM,sBAAsB,CAAC;AAAA,UAChD,OAAO,MAAM,SAAS;AAAA,UACtB,gBAAgB;AAAA,QAClB;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAU,KAAK,IAAI,IAAI;AAC7B,WAAO,MAAM,kBAAkB,YAAY,EAAE,eAAe,KAAK,SAAS,UAAU,GAAG,YAAY,QAAQ,CAAC;AAC5G,WAAO;AAAA,MACL,SAAS;AA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M,SAAS,IAAI,eAAe;AAAA,IAChC;AAAA,IACA,UAAU,OAAO;AAAA,IACjB,SAAS,OAAO,WAAW;AAAA,IAC3B,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,EAChB,CAAC;AAED,SAAO,UAAU,QAAQ,OAAO,OAAO,QAAQ,OAAO,WAAW,iBAAiB,OAAO,SAAS;AACpG;","names":[]}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { RetryConfig } from './tools/utils/resilience.js';
|
|
2
|
+
import { MorphAPIClient } from './core/client.js';
|
|
2
3
|
import { FastApplyClient } from './tools/fastapply/core.js';
|
|
3
4
|
import { CodebaseSearchClient } from './tools/codebase_search/core.js';
|
|
4
5
|
import { BrowserClient } from './tools/browser/core.js';
|
|
5
6
|
import { WarpGrepClient } from './tools/warp_grep/client.js';
|
|
7
|
+
import { APIResource } from './core/resource.js';
|
|
6
8
|
import { MorphGit } from './git/client.js';
|
|
7
9
|
import { CompactClient } from './tools/compact/core.js';
|
|
10
|
+
import { ReflexClient } from './tools/reflex/core.js';
|
|
8
11
|
import { OpenAIRouter, AnthropicRouter, GeminiRouter, RawRouter } from './modelrouter/core.js';
|
|
9
12
|
import { EditFileConfig, EditFileInput, EditFileResult, EditChanges } from './tools/fastapply/types.js';
|
|
10
13
|
import { CodebaseSearchConfig, CodebaseSearchInput, CodebaseSearchResult } from './tools/codebase_search/types.js';
|
|
@@ -515,10 +518,12 @@ declare class PermissionError extends GitHubError {
|
|
|
515
518
|
* number: 42
|
|
516
519
|
* });
|
|
517
520
|
* ```
|
|
521
|
+
*
|
|
522
|
+
* @deprecated Prefer the unified `MorphClient` (`new MorphClient({ apiKey }).github`).
|
|
523
|
+
* Standalone clients remain only for backwards compatibility and may be removed in a future
|
|
524
|
+
* major version — do not use them in new code.
|
|
518
525
|
*/
|
|
519
|
-
declare class GitHubClient {
|
|
520
|
-
private apiKey;
|
|
521
|
-
private baseUrl;
|
|
526
|
+
declare class GitHubClient extends APIResource {
|
|
522
527
|
private timeout;
|
|
523
528
|
private debug;
|
|
524
529
|
private defaultInstallationId?;
|
|
@@ -580,7 +585,9 @@ declare class GitHubClient {
|
|
|
580
585
|
* Users visit this URL once to install the Morph GitHub App on their account/org.
|
|
581
586
|
*/
|
|
582
587
|
getInstallUrl(): string;
|
|
583
|
-
constructor(
|
|
588
|
+
constructor(clientOrConfig?: MorphAPIClient | GitHubClientConfig, options?: {
|
|
589
|
+
installationId?: string;
|
|
590
|
+
});
|
|
584
591
|
/**
|
|
585
592
|
* Make an authenticated API request
|
|
586
593
|
*/
|
|
@@ -961,7 +968,7 @@ interface MorphClientConfig {
|
|
|
961
968
|
* - routers: Intelligent model selection (OpenAI, Anthropic, Gemini)
|
|
962
969
|
* - openai/anthropic/vercel: Tool factories for agent frameworks
|
|
963
970
|
*/
|
|
964
|
-
declare class MorphClient {
|
|
971
|
+
declare class MorphClient extends MorphAPIClient {
|
|
965
972
|
/** Client configuration */
|
|
966
973
|
config: MorphClientConfig;
|
|
967
974
|
/** FastApply tool for editing files with AI-powered merge */
|
|
@@ -991,6 +998,8 @@ declare class MorphClient {
|
|
|
991
998
|
vercel: VercelToolFactory;
|
|
992
999
|
/** Compact context with line ranges */
|
|
993
1000
|
compact: CompactClient['compact'];
|
|
1001
|
+
/** Reflex: train and serve small text classifiers */
|
|
1002
|
+
reflex: ReflexClient;
|
|
994
1003
|
/**
|
|
995
1004
|
* Create a new Morph SDK client
|
|
996
1005
|
*
|