@morphllm/morphsdk 0.2.202 → 0.2.204
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/README.md +101 -0
- package/dist/chunk-2GMG5XKU.js +100 -0
- package/dist/chunk-2PPYWRMZ.js +3 -4
- package/dist/chunk-3HAHJYZQ.cjs +74 -0
- package/dist/{chunk-2XU3XXUE.js → chunk-3JROKKS4.js} +3 -25
- package/dist/{chunk-26K5EJD3.js → chunk-43JBUEIX.js} +4 -18
- package/dist/chunk-44OIEPIO.js +4 -23
- package/dist/chunk-4EQQGUZ7.cjs +104 -0
- package/dist/chunk-4OUGA3KS.js +1 -5
- package/dist/{chunk-VQDDL3UH.js → chunk-4TZBUFVP.js} +2 -8
- package/dist/{chunk-YAM6P5OQ.js → chunk-564XJOQP.js} +2 -6
- package/dist/chunk-5H3FKFOI.cjs +77 -0
- package/dist/chunk-5TTZQF4X.cjs +110 -0
- package/dist/chunk-6HAYJA6M.cjs +317 -0
- 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-7PJYY46L.cjs +2 -0
- package/dist/chunk-AWFZKS27.cjs +11 -0
- package/dist/chunk-BJBWWIZV.cjs +2 -0
- package/dist/chunk-DLYDIYDK.cjs +305 -0
- package/dist/{chunk-65TUD7JV.js → chunk-DYCMPDPV.js} +13 -29
- package/dist/{chunk-3CPI6ZIC.js → chunk-DZP7BR66.js} +22 -43
- package/dist/chunk-E63OPKP7.js +96 -0
- package/dist/chunk-E6V75LI6.cjs +334 -0
- package/dist/{chunk-XPHNS7NW.js → chunk-EJ6ID24K.js} +3 -12
- package/dist/chunk-EJTL2BOZ.cjs +42 -0
- package/dist/chunk-ETBRAKVV.js +1 -5
- package/dist/chunk-F633IVQA.cjs +91 -0
- package/dist/chunk-FBOZIVVQ.js +1 -0
- package/dist/{chunk-UKXCGQPS.js → chunk-FGA6EYC2.js} +35 -37
- package/dist/{chunk-CAWQEHKP.js → chunk-G4RODMXA.js} +4 -19
- package/dist/chunk-GUNGJC6X.cjs +256 -0
- package/dist/chunk-GYE3FY6Z.js +8 -0
- package/dist/chunk-HDP4QAZL.js +1 -4
- package/dist/chunk-HNMEBYIS.cjs +86 -0
- package/dist/chunk-HP3PCOTW.cjs +81 -0
- package/dist/{chunk-ICCGLO6V.js → chunk-IGXNLXPN.js} +12 -17
- package/dist/chunk-IPJA3ZS6.cjs +10 -0
- package/dist/chunk-JHC2R3HU.cjs +317 -0
- package/dist/{chunk-IBRBSDLT.js → chunk-JVMIFGZY.js} +5 -8
- package/dist/chunk-KF6S3EPJ.cjs +100 -0
- package/dist/chunk-KVGZ2TSG.cjs +274 -0
- package/dist/{chunk-6OYJC4TZ.js → chunk-L5SCKZVK.js} +13 -22
- package/dist/chunk-LDM7RNNN.js +1 -0
- package/dist/{chunk-UAZKHSEU.js → chunk-LQST3NW2.js} +5 -15
- 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-MMX5PUGC.cjs +242 -0
- package/dist/chunk-MWXJ6DZ2.cjs +21 -0
- package/dist/chunk-NJWOWXUR.cjs +137 -0
- package/dist/chunk-NNKBKENK.cjs +15 -0
- package/dist/chunk-NRG6QX3L.js +1 -3
- package/dist/chunk-OCKEEEYE.cjs +433 -0
- package/dist/chunk-OENJO7YW.js +306 -0
- package/dist/chunk-OKLAYEBC.cjs +2 -0
- package/dist/chunk-OPDWMD4Q.js +1 -3
- package/dist/{chunk-D6YJ5X3C.js → chunk-OX5GN2KB.js} +26 -14
- package/dist/{chunk-JEVLCA5C.js → chunk-OYBOP47A.js} +18 -19
- package/dist/chunk-OZHCHPIE.js +1 -0
- package/dist/chunk-PA3UTI4A.js +1 -4
- package/dist/chunk-QEEAIXL5.cjs +74 -0
- package/dist/chunk-QT5LGZG3.cjs +10 -0
- package/dist/chunk-R3TUE7O2.cjs +107 -0
- package/dist/chunk-RYVW7RUM.js +2 -6
- package/dist/{chunk-LVKKICOB.js → chunk-SOQYE5A4.js} +36 -69
- package/dist/chunk-ST2OXLT5.cjs +91 -0
- package/dist/{chunk-SIFDK4AA.js → chunk-TH4MG73B.js} +3 -24
- package/dist/{chunk-OSL4CNSO.js → chunk-TLMAMVAW.js} +7 -23
- package/dist/chunk-TPZHMD7J.cjs +72 -0
- package/dist/{chunk-PDSIWL7I.js → chunk-U4PYAGNR.js} +6 -19
- package/dist/chunk-UAPK3AIJ.js +1 -10
- package/dist/chunk-UF5IKELS.cjs +26 -0
- package/dist/chunk-UHFVWYSP.cjs +408 -0
- package/dist/chunk-UKBSXYKE.cjs +280 -0
- package/dist/chunk-UNX7V6P6.cjs +60 -0
- package/dist/chunk-UZMMJ47A.cjs +107 -0
- package/dist/chunk-VHD7CW5O.cjs +43 -0
- package/dist/chunk-VL4QNALG.cjs +50 -0
- package/dist/chunk-VYE7O4FM.cjs +51 -0
- package/dist/chunk-WIYVT4UO.cjs +173 -0
- package/dist/chunk-WJHHO24M.cjs +91 -0
- package/dist/chunk-WR7LSUIR.cjs +213 -0
- package/dist/chunk-XE6D4J63.cjs +72 -0
- package/dist/chunk-YAUXTFIN.cjs +21 -0
- package/dist/{chunk-NFPRKZQ5.js → chunk-YJUCGZNN.js} +5 -22
- package/dist/chunk-ZSHVXDA2.js +4 -10
- package/dist/chunk-ZX6T3LNG.js +302 -0
- package/dist/{client-BWhi-vSj.d.ts → client-DSXbcxII.d.ts} +10 -1
- package/dist/client.cjs +44 -4360
- package/dist/client.d.ts +4 -2
- package/dist/client.js +36 -37
- package/dist/core/client.cjs +14 -476
- package/dist/core/client.d.ts +8 -0
- package/dist/core/client.js +10 -11
- package/dist/core/error.cjs +8 -251
- package/dist/core/error.js +4 -9
- package/dist/core/index.cjs +27 -491
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +12 -19
- package/dist/core/resource.cjs +9 -33
- package/dist/core/resource.d.ts +2 -0
- package/dist/core/resource.js +2 -7
- package/dist/edge.cjs +74 -1111
- package/dist/edge.d.ts +3 -0
- package/dist/edge.js +14 -42
- package/dist/guard-CvW03v4u.d.ts +59 -0
- package/dist/index.cjs +140 -4431
- package/dist/index.d.ts +6 -2
- package/dist/index.js +44 -87
- package/dist/modelrouter/core.cjs +35 -651
- package/dist/modelrouter/core.d.ts +2 -0
- package/dist/modelrouter/core.js +12 -21
- package/dist/modelrouter/index.cjs +35 -651
- package/dist/modelrouter/index.d.ts +2 -0
- package/dist/modelrouter/index.js +12 -21
- package/dist/modelrouter/types.cjs +1 -17
- package/dist/modelrouter/types.d.ts +5 -0
- package/dist/modelrouter/types.js +1 -0
- package/dist/subagents/anthropic.cjs +31 -2784
- package/dist/subagents/anthropic.d.ts +3 -1
- package/dist/subagents/anthropic.js +23 -24
- package/dist/subagents/index.cjs +14 -95
- package/dist/subagents/index.d.ts +3 -1
- package/dist/subagents/index.js +2 -11
- package/dist/subagents/prompts.cjs +14 -93
- package/dist/subagents/prompts.d.ts +3 -1
- package/dist/subagents/prompts.js +2 -11
- package/dist/subagents/types.cjs +1 -17
- package/dist/subagents/types.d.ts +3 -1
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/vercel.cjs +31 -2761
- package/dist/subagents/vercel.d.ts +3 -1
- package/dist/subagents/vercel.js +23 -24
- package/dist/tools/compact/core.cjs +20 -552
- package/dist/tools/compact/core.d.ts +2 -0
- package/dist/tools/compact/core.js +12 -13
- package/dist/tools/compact/index.cjs +24 -598
- package/dist/tools/compact/index.d.ts +3 -1
- package/dist/tools/compact/index.js +13 -17
- package/dist/tools/compact/types.cjs +1 -17
- package/dist/tools/compact/types.d.ts +4 -4
- package/dist/tools/compact/types.js +1 -0
- package/dist/tools/fastapply/anthropic.cjs +39 -899
- package/dist/tools/fastapply/anthropic.d.ts +2 -0
- package/dist/tools/fastapply/anthropic.js +15 -24
- package/dist/tools/fastapply/apply.cjs +32 -672
- package/dist/tools/fastapply/apply.d.ts +2 -0
- package/dist/tools/fastapply/apply.js +8 -19
- package/dist/tools/fastapply/core.cjs +49 -1069
- package/dist/tools/fastapply/core.d.ts +3 -0
- package/dist/tools/fastapply/core.js +13 -29
- package/dist/tools/fastapply/index.cjs +56 -1052
- package/dist/tools/fastapply/index.d.ts +2 -0
- package/dist/tools/fastapply/index.js +18 -44
- package/dist/tools/fastapply/openai.cjs +45 -910
- package/dist/tools/fastapply/openai.d.ts +2 -0
- package/dist/tools/fastapply/openai.js +15 -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.d.ts +9 -4
- package/dist/tools/fastapply/types.js +1 -0
- package/dist/tools/fastapply/vercel.cjs +37 -905
- package/dist/tools/fastapply/vercel.d.ts +2 -0
- package/dist/tools/fastapply/vercel.js +15 -22
- package/dist/tools/index.cjs +56 -1052
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +18 -44
- package/dist/tools/pii/index.cjs +47 -0
- package/dist/tools/pii/index.d.ts +4 -0
- package/dist/tools/pii/index.js +6 -0
- package/dist/tools/pii/model.cjs +45 -0
- package/dist/tools/pii/model.d.ts +83 -0
- package/dist/tools/pii/model.js +4 -0
- package/dist/tools/pii/patterns.cjs +15 -0
- package/dist/tools/pii/patterns.d.ts +31 -0
- package/dist/tools/pii/patterns.js +2 -0
- package/dist/tools/pii/regex.cjs +32 -0
- package/dist/tools/pii/regex.d.ts +48 -0
- package/dist/tools/pii/regex.js +3 -0
- package/dist/tools/pii/types.cjs +2 -0
- package/dist/tools/pii/types.d.ts +108 -0
- package/dist/tools/pii/types.js +1 -0
- 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.d.ts +2 -0
- package/dist/tools/warp_grep/agent/parser.js +2 -11
- package/dist/tools/warp_grep/agent/runner.cjs +19 -1081
- package/dist/tools/warp_grep/agent/runner.d.ts +2 -0
- package/dist/tools/warp_grep/agent/runner.js +11 -14
- package/dist/tools/warp_grep/agent/types.cjs +1 -17
- package/dist/tools/warp_grep/agent/types.d.ts +4 -0
- package/dist/tools/warp_grep/agent/types.js +1 -0
- package/dist/tools/warp_grep/anthropic.cjs +51 -2561
- package/dist/tools/warp_grep/anthropic.d.ts +3 -1
- package/dist/tools/warp_grep/anthropic.js +23 -35
- package/dist/tools/warp_grep/client.cjs +53 -2471
- package/dist/tools/warp_grep/client.d.ts +3 -1
- package/dist/tools/warp_grep/client.js +21 -34
- package/dist/tools/warp_grep/gemini.cjs +52 -2490
- package/dist/tools/warp_grep/gemini.d.ts +3 -1
- package/dist/tools/warp_grep/gemini.js +25 -41
- package/dist/tools/warp_grep/harness.cjs +81 -936
- package/dist/tools/warp_grep/harness.d.ts +2 -0
- package/dist/tools/warp_grep/harness.js +12 -51
- package/dist/tools/warp_grep/index.cjs +128 -2575
- package/dist/tools/warp_grep/index.d.ts +3 -1
- package/dist/tools/warp_grep/index.js +28 -87
- package/dist/tools/warp_grep/openai.cjs +57 -2575
- package/dist/tools/warp_grep/openai.d.ts +3 -1
- package/dist/tools/warp_grep/openai.js +23 -37
- package/dist/tools/warp_grep/providers/code_storage_http.cjs +12 -65
- package/dist/tools/warp_grep/providers/code_storage_http.d.ts +3 -1
- 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.d.ts +3 -1
- 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 +57 -2557
- package/dist/tools/warp_grep/vercel.d.ts +3 -1
- package/dist/tools/warp_grep/vercel.js +23 -37
- package/dist/{types-DxZLPogx.d.ts → types-BKhXjDCB.d.ts} +6 -1
- package/dist/version.cjs +7 -225
- package/dist/version.js +2 -7
- package/package.json +11 -2
- package/dist/chunk-E6TL6MIH.js +0 -203
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/warp_grep/agent/parser.ts
|
|
4
|
+
function parseReadLines(linesStr) {
|
|
5
|
+
const ranges = [];
|
|
6
|
+
for (const rangeStr of linesStr.split(",")) {
|
|
7
|
+
const trimmed = rangeStr.trim();
|
|
8
|
+
if (!trimmed) continue;
|
|
9
|
+
const parts = trimmed.split("-").map((v) => parseInt(v.trim(), 10));
|
|
10
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
11
|
+
ranges.push([parts[0], parts[1]]);
|
|
12
|
+
} else if (Number.isFinite(parts[0])) {
|
|
13
|
+
ranges.push([parts[0], parts[0]]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (ranges.length === 1) return { start: ranges[0][0], end: ranges[0][1] };
|
|
17
|
+
if (ranges.length > 1) return { lines: ranges };
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
function parseFinishFiles(filesStr) {
|
|
21
|
+
const files = [];
|
|
22
|
+
for (const line of filesStr.trim().split(/\s+/)) {
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (!trimmed) continue;
|
|
25
|
+
const searchFrom = /^[A-Za-z]:/.test(trimmed) ? 2 : 0;
|
|
26
|
+
const colonIdx = trimmed.indexOf(":", searchFrom);
|
|
27
|
+
if (colonIdx === -1) {
|
|
28
|
+
files.push({ path: trimmed, lines: "*" });
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const filePath = trimmed.slice(0, colonIdx);
|
|
32
|
+
const rangesPart = trimmed.slice(colonIdx + 1);
|
|
33
|
+
if (!rangesPart.trim() || rangesPart.trim() === "*") {
|
|
34
|
+
files.push({ path: filePath, lines: "*" });
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const ranges = [];
|
|
38
|
+
for (const rangeStr of rangesPart.split(",")) {
|
|
39
|
+
const rt = rangeStr.trim();
|
|
40
|
+
if (!rt) continue;
|
|
41
|
+
const parts = rt.split("-").map((v) => parseInt(v.trim(), 10));
|
|
42
|
+
if (parts.length >= 2 && Number.isFinite(parts[0]) && Number.isFinite(parts[1])) {
|
|
43
|
+
ranges.push([parts[0], parts[1]]);
|
|
44
|
+
} else if (Number.isFinite(parts[0])) {
|
|
45
|
+
ranges.push([parts[0], parts[0]]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
files.push({ path: filePath, lines: ranges.length > 0 ? ranges : "*" });
|
|
49
|
+
}
|
|
50
|
+
return files;
|
|
51
|
+
}
|
|
52
|
+
function extractPathFromCommand(command) {
|
|
53
|
+
const tokens = command.trim().split(/\s+/);
|
|
54
|
+
const pathTokens = tokens.slice(1).filter((t) => !t.startsWith("-") && !t.startsWith("|") && !t.startsWith("\\("));
|
|
55
|
+
return pathTokens[0] || ".";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.extractPathFromCommand = extractPathFromCommand;
|
|
59
|
+
exports.parseFinishFiles = parseFinishFiles;
|
|
60
|
+
exports.parseReadLines = parseReadLines;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkEJTL2BOZ_cjs = require('./chunk-EJTL2BOZ.cjs');
|
|
4
|
+
var chunkJHC2R3HU_cjs = require('./chunk-JHC2R3HU.cjs');
|
|
5
|
+
var ai = require('ai');
|
|
6
|
+
var zod = require('zod');
|
|
7
|
+
|
|
8
|
+
var warpGrepJsonSchema = {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
search_term: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Search problem statement that this subagent is supposed to research for"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
required: ["search_term"],
|
|
17
|
+
additionalProperties: false
|
|
18
|
+
};
|
|
19
|
+
async function execute(input, config) {
|
|
20
|
+
return chunkJHC2R3HU_cjs.executeToolCall(input, config);
|
|
21
|
+
}
|
|
22
|
+
function createWarpGrepTool(config) {
|
|
23
|
+
const schema = config.inputSchema ?? zod.z.object({
|
|
24
|
+
search_term: zod.z.string().describe("Search problem statement that this subagent is supposed to research for")
|
|
25
|
+
});
|
|
26
|
+
return ai.tool({
|
|
27
|
+
description: config.description ?? chunkEJTL2BOZ_cjs.WARP_GREP_DESCRIPTION,
|
|
28
|
+
inputSchema: schema,
|
|
29
|
+
execute: async (params) => {
|
|
30
|
+
const steps = [];
|
|
31
|
+
const generator = chunkJHC2R3HU_cjs.executeToolCallStreaming(params, config);
|
|
32
|
+
let result;
|
|
33
|
+
for (; ; ) {
|
|
34
|
+
const { value, done } = await generator.next();
|
|
35
|
+
if (done) {
|
|
36
|
+
result = value;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
steps.push(value);
|
|
40
|
+
}
|
|
41
|
+
if (!result.success) {
|
|
42
|
+
throw new Error(`Failed to search codebase: ${result.error}`);
|
|
43
|
+
}
|
|
44
|
+
const allToolCalls = steps.flatMap((s) => s.toolCalls);
|
|
45
|
+
return {
|
|
46
|
+
success: true,
|
|
47
|
+
contexts: result.contexts,
|
|
48
|
+
summary: result.summary,
|
|
49
|
+
progress: allToolCalls.length > 0 ? { turn: steps.length, toolCalls: allToolCalls } : void 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function createGitHubSearchTool(config) {
|
|
55
|
+
const client = new chunkJHC2R3HU_cjs.WarpGrepClient(config);
|
|
56
|
+
return ai.tool({
|
|
57
|
+
description: chunkEJTL2BOZ_cjs.GITHUB_SEARCH_DESCRIPTION,
|
|
58
|
+
inputSchema: zod.z.object({
|
|
59
|
+
search_term: zod.z.string().describe("Search problem statement that this subagent is supposed to research for"),
|
|
60
|
+
github_url: zod.z.string().optional().describe('GitHub repository URL to search (e.g. "https://github.com/vercel/next.js"). You must provide either github_url or owner_repo.'),
|
|
61
|
+
owner_repo: zod.z.string().optional().describe('Repository owner/repo shorthand (e.g. "vercel/next.js"). You must provide either github_url or owner_repo.'),
|
|
62
|
+
branch: zod.z.string().optional().describe("Branch to search (defaults to repo default branch)")
|
|
63
|
+
}),
|
|
64
|
+
execute: async (params) => {
|
|
65
|
+
const github = params.github_url || params.owner_repo;
|
|
66
|
+
if (!github) {
|
|
67
|
+
throw new Error("Please provide github search url or owner/repo id");
|
|
68
|
+
}
|
|
69
|
+
const result = await client.searchGitHub({ searchTerm: params.search_term, github, branch: params.branch });
|
|
70
|
+
if (!result.success) {
|
|
71
|
+
throw new Error(`GitHub search failed: ${result.error}`);
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
success: true,
|
|
75
|
+
contexts: result.contexts,
|
|
76
|
+
summary: result.summary
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function createGitHubReadFileTool(config) {
|
|
82
|
+
return ai.tool({
|
|
83
|
+
description: chunkEJTL2BOZ_cjs.GITHUB_READ_FILE_DESCRIPTION,
|
|
84
|
+
inputSchema: zod.z.object({
|
|
85
|
+
github: zod.z.string().describe('owner/repo shorthand (e.g., "vercel/next.js")'),
|
|
86
|
+
path: zod.z.string().describe("File path within the repository"),
|
|
87
|
+
startLine: zod.z.number().optional().describe("Start line number (1-based)"),
|
|
88
|
+
endLine: zod.z.number().optional().describe("End line number (1-based, inclusive)"),
|
|
89
|
+
branch: zod.z.string().optional().describe("Branch to read from (defaults to repo default branch)")
|
|
90
|
+
}),
|
|
91
|
+
execute: async (params) => {
|
|
92
|
+
const result = await chunkJHC2R3HU_cjs.executeGitHubReadFile(params, config);
|
|
93
|
+
if (!result.success) {
|
|
94
|
+
throw new Error(`GitHub read file failed: ${result.error}`);
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
var vercel_default = createWarpGrepTool;
|
|
101
|
+
|
|
102
|
+
exports.createGitHubReadFileTool = createGitHubReadFileTool;
|
|
103
|
+
exports.createGitHubSearchTool = createGitHubSearchTool;
|
|
104
|
+
exports.createWarpGrepTool = createWarpGrepTool;
|
|
105
|
+
exports.execute = execute;
|
|
106
|
+
exports.vercel_default = vercel_default;
|
|
107
|
+
exports.warpGrepJsonSchema = warpGrepJsonSchema;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// tools/warp_grep/providers/code_storage_http.ts
|
|
4
|
+
var MODEL_REPO_ROOT = /^\/?home\/ubuntu\/repo(?:\/|$)/;
|
|
5
|
+
function toRepoRelative(path) {
|
|
6
|
+
if (!path) return path;
|
|
7
|
+
const stripped = path.replace(MODEL_REPO_ROOT, "").replace(/^\.?\/+/, "");
|
|
8
|
+
return stripped || ".";
|
|
9
|
+
}
|
|
10
|
+
async function post(url, body, op, apiKey) {
|
|
11
|
+
const res = await fetch(url, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
...apiKey ? { Authorization: `Bearer ${apiKey}` } : {}
|
|
16
|
+
},
|
|
17
|
+
body: JSON.stringify(body)
|
|
18
|
+
});
|
|
19
|
+
if (!res.ok) {
|
|
20
|
+
const text = await res.text().catch(() => res.statusText);
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(text);
|
|
23
|
+
if (parsed.error) return `Error: ${parsed.error}`;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
return `Error: ${op} failed (${res.status}): ${text}`;
|
|
27
|
+
}
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
if (data.error) throw new Error(data.error);
|
|
30
|
+
return data.stdout;
|
|
31
|
+
}
|
|
32
|
+
function createCodeStorageHttpCommands(config) {
|
|
33
|
+
const { baseUrl, repoId, branch, apiKey } = config;
|
|
34
|
+
const encodedRepoId = encodeURIComponent(repoId);
|
|
35
|
+
return {
|
|
36
|
+
grep: (pattern, path, glob) => post(`${baseUrl}/api/code-search/${encodedRepoId}/grep`, { pattern, path: toRepoRelative(path), glob, branch }, "grep", apiKey),
|
|
37
|
+
read: (path, start, end) => post(`${baseUrl}/api/code-search/${encodedRepoId}/read`, { path: toRepoRelative(path), start, end, branch }, "read", apiKey),
|
|
38
|
+
listDir: (path, maxDepth) => post(`${baseUrl}/api/code-search/${encodedRepoId}/list`, { path: toRepoRelative(path), maxDepth, branch }, "list", apiKey)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.createCodeStorageHttpCommands = createCodeStorageHttpCommands;
|
|
43
|
+
exports.toRepoRelative = toRepoRelative;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// logger.ts
|
|
4
|
+
var MorphLogger = class {
|
|
5
|
+
enabled;
|
|
6
|
+
fileStream;
|
|
7
|
+
/** Resolves once the file stream is initialized (or immediately if no file logging). */
|
|
8
|
+
ready;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.enabled = typeof process !== "undefined" && (process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE);
|
|
11
|
+
this.fileStream = null;
|
|
12
|
+
const f = typeof process !== "undefined" ? process.env.MORPH_LOG_FILE : void 0;
|
|
13
|
+
if (f) {
|
|
14
|
+
this.ready = import('fs').then((fs) => {
|
|
15
|
+
this.fileStream = fs.createWriteStream(f, { flags: "a" });
|
|
16
|
+
}).catch(() => {
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
this.ready = Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
debug(component, msg, data) {
|
|
23
|
+
this._log("debug", component, msg, data);
|
|
24
|
+
}
|
|
25
|
+
info(component, msg, data) {
|
|
26
|
+
this._log("info", component, msg, data);
|
|
27
|
+
}
|
|
28
|
+
warn(component, msg, data) {
|
|
29
|
+
this._log("warn", component, msg, data);
|
|
30
|
+
}
|
|
31
|
+
error(component, msg, data) {
|
|
32
|
+
this._log("error", component, msg, data);
|
|
33
|
+
}
|
|
34
|
+
enable() {
|
|
35
|
+
this.enabled = true;
|
|
36
|
+
}
|
|
37
|
+
get isEnabled() {
|
|
38
|
+
return this.enabled;
|
|
39
|
+
}
|
|
40
|
+
_log(level, component, msg, data) {
|
|
41
|
+
if (level !== "error" && !this.enabled) return;
|
|
42
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
43
|
+
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
44
|
+
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
45
|
+
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var logger = new MorphLogger();
|
|
49
|
+
|
|
50
|
+
exports.logger = logger;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkF633IVQA_cjs = require('./chunk-F633IVQA.cjs');
|
|
4
|
+
|
|
5
|
+
// tools/compact/utils.ts
|
|
6
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3, redactPII) {
|
|
7
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
8
|
+
const estimatedTokens = totalLength / 3;
|
|
9
|
+
if (estimatedTokens <= maxTokens) {
|
|
10
|
+
return files;
|
|
11
|
+
}
|
|
12
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
13
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
14
|
+
const client = new chunkF633IVQA_cjs.CompactClient({
|
|
15
|
+
morphApiKey: apiKey,
|
|
16
|
+
morphApiUrl: apiUrl,
|
|
17
|
+
redactPII
|
|
18
|
+
});
|
|
19
|
+
const results = [];
|
|
20
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
if (file.content.length < 500) {
|
|
23
|
+
results.push({ path: file.path, content: file.content });
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const task = async () => {
|
|
27
|
+
try {
|
|
28
|
+
const result = await client.compact({
|
|
29
|
+
input: file.content,
|
|
30
|
+
query,
|
|
31
|
+
compressionRatio,
|
|
32
|
+
preserveRecent: 0
|
|
33
|
+
});
|
|
34
|
+
results.push({ path: file.path, content: result.output });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
37
|
+
results.push({ path: file.path, content: file.content });
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
41
|
+
inProgress.add(promise);
|
|
42
|
+
if (inProgress.size >= maxConcurrency) {
|
|
43
|
+
await Promise.race(inProgress);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
await Promise.all(inProgress);
|
|
47
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
48
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
exports.compactFileContexts = compactFileContexts;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk5TTZQF4X_cjs = require('./chunk-5TTZQF4X.cjs');
|
|
4
|
+
var chunkVL4QNALG_cjs = require('./chunk-VL4QNALG.cjs');
|
|
5
|
+
var chunkWJHHO24M_cjs = require('./chunk-WJHHO24M.cjs');
|
|
6
|
+
var chunkAWFZKS27_cjs = require('./chunk-AWFZKS27.cjs');
|
|
7
|
+
|
|
8
|
+
// modelrouter/core.ts
|
|
9
|
+
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
10
|
+
var DEFAULT_TIMEOUT = 5e3;
|
|
11
|
+
function resolveClient(clientOrConfig) {
|
|
12
|
+
if (clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient) return clientOrConfig;
|
|
13
|
+
return new chunk5TTZQF4X_cjs.MorphAPIClient({
|
|
14
|
+
apiKey: clientOrConfig.apiKey,
|
|
15
|
+
baseURL: clientOrConfig.apiUrl ?? DEFAULT_API_URL,
|
|
16
|
+
timeout: clientOrConfig.timeout ?? DEFAULT_TIMEOUT,
|
|
17
|
+
retryConfig: clientOrConfig.retryConfig,
|
|
18
|
+
debug: clientOrConfig.debug,
|
|
19
|
+
redactPII: clientOrConfig.redactPII
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
async function redactInput(client, input) {
|
|
23
|
+
const pii = client.pii?.session();
|
|
24
|
+
return pii && typeof input === "string" ? await pii.redact(input) : input;
|
|
25
|
+
}
|
|
26
|
+
var BaseRouter = class extends chunkAWFZKS27_cjs.APIResource {
|
|
27
|
+
provider;
|
|
28
|
+
timeout;
|
|
29
|
+
constructor(provider, clientOrConfig = {}) {
|
|
30
|
+
super(resolveClient(clientOrConfig));
|
|
31
|
+
this.provider = provider;
|
|
32
|
+
const cfg = clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient ? {} : clientOrConfig;
|
|
33
|
+
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT;
|
|
34
|
+
}
|
|
35
|
+
/** Throw the historical "API key is required" message when no key is resolvable. */
|
|
36
|
+
requireApiKey() {
|
|
37
|
+
if (!this._client.resolveApiKey()) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** POST to the router and surface failures as `Router API error (<status>): ...`. */
|
|
44
|
+
async route(provider, input) {
|
|
45
|
+
try {
|
|
46
|
+
return await this._client.post(`/v1/router/${provider}`, {
|
|
47
|
+
body: { input: await redactInput(this._client, input.input), mode: input.mode || "balanced" },
|
|
48
|
+
timeout: this.timeout
|
|
49
|
+
});
|
|
50
|
+
} catch (error) {
|
|
51
|
+
if (error instanceof chunkWJHHO24M_cjs.MorphError) {
|
|
52
|
+
throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
|
|
53
|
+
}
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Select the optimal model for a given input and mode
|
|
59
|
+
*/
|
|
60
|
+
async selectModel(input) {
|
|
61
|
+
this.requireApiKey();
|
|
62
|
+
chunkVL4QNALG_cjs.logger.debug("ModelRouter", "request", { provider: this.provider, mode: input.mode || "balanced" });
|
|
63
|
+
const apiResult = await this.route(this.provider, input);
|
|
64
|
+
chunkVL4QNALG_cjs.logger.debug("ModelRouter", "selected", { provider: this.provider, model: apiResult.model });
|
|
65
|
+
return { model: apiResult.model };
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var OpenAIRouter = class extends BaseRouter {
|
|
69
|
+
constructor(clientOrConfig = {}) {
|
|
70
|
+
super("openai", clientOrConfig);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Select optimal GPT-5 model
|
|
74
|
+
*
|
|
75
|
+
* @param input - User input and mode
|
|
76
|
+
* @returns Selected model name (gpt-5-mini | gpt-5-low | gpt-5-medium | gpt-5-high)
|
|
77
|
+
*/
|
|
78
|
+
async selectModel(input) {
|
|
79
|
+
return super.selectModel(input);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var AnthropicRouter = class extends BaseRouter {
|
|
83
|
+
constructor(clientOrConfig = {}) {
|
|
84
|
+
super("anthropic", clientOrConfig);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Select optimal Claude model
|
|
88
|
+
*
|
|
89
|
+
* @param input - User input and mode
|
|
90
|
+
* @returns Selected model name (claude-4.5-haiku | claude-4.5-sonnet)
|
|
91
|
+
*/
|
|
92
|
+
async selectModel(input) {
|
|
93
|
+
return super.selectModel(input);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var GeminiRouter = class extends BaseRouter {
|
|
97
|
+
constructor(clientOrConfig = {}) {
|
|
98
|
+
super("gemini", clientOrConfig);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Select optimal Gemini model
|
|
102
|
+
*
|
|
103
|
+
* @param input - User input and mode
|
|
104
|
+
* @returns Selected model name (gemini-2.5-flash | gemini-2.5-pro)
|
|
105
|
+
*/
|
|
106
|
+
async selectModel(input) {
|
|
107
|
+
return super.selectModel(input);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var RawRouter = class extends BaseRouter {
|
|
111
|
+
constructor(clientOrConfig = {}) {
|
|
112
|
+
super("raw", clientOrConfig);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get raw difficulty classification
|
|
116
|
+
*
|
|
117
|
+
* @param input - User input and mode
|
|
118
|
+
* @returns Raw difficulty (easy | medium | hard | needs_info)
|
|
119
|
+
*/
|
|
120
|
+
async classify(input) {
|
|
121
|
+
this.requireApiKey();
|
|
122
|
+
chunkVL4QNALG_cjs.logger.debug("RawRouter", "request", { mode: input.mode || "balanced" });
|
|
123
|
+
const apiResult = await this.route("raw", input);
|
|
124
|
+
let difficulty;
|
|
125
|
+
if (apiResult.difficulty === "") {
|
|
126
|
+
difficulty = "medium";
|
|
127
|
+
} else {
|
|
128
|
+
difficulty = apiResult.difficulty || apiResult.model;
|
|
129
|
+
}
|
|
130
|
+
chunkVL4QNALG_cjs.logger.debug("RawRouter", "classified", { difficulty });
|
|
131
|
+
return { difficulty };
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var RouterClassifier = class extends chunkAWFZKS27_cjs.APIResource {
|
|
135
|
+
timeout;
|
|
136
|
+
constructor(clientOrConfig = {}) {
|
|
137
|
+
super(resolveClient(clientOrConfig));
|
|
138
|
+
const cfg = clientOrConfig instanceof chunk5TTZQF4X_cjs.MorphAPIClient ? {} : clientOrConfig;
|
|
139
|
+
this.timeout = cfg.timeout ?? DEFAULT_TIMEOUT;
|
|
140
|
+
}
|
|
141
|
+
/** Classify an input across the requested axes (all three by default). */
|
|
142
|
+
async classify(input) {
|
|
143
|
+
if (!this._client.resolveApiKey()) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"Morph API key is required. Set MORPH_API_KEY environment variable or pass apiKey in config."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
chunkVL4QNALG_cjs.logger.debug("RouterClassifier", "request", { classes: input.classes ?? "all" });
|
|
149
|
+
try {
|
|
150
|
+
const res = await this._client.post("/v1/router/classify", {
|
|
151
|
+
body: { input: await redactInput(this._client, input.input), ...input.classes ? { classes: input.classes } : {} },
|
|
152
|
+
timeout: this.timeout
|
|
153
|
+
});
|
|
154
|
+
chunkVL4QNALG_cjs.logger.debug("RouterClassifier", "classified", {
|
|
155
|
+
difficulty: res.classifications.difficulty?.label,
|
|
156
|
+
ambiguity: res.classifications.ambiguity?.label,
|
|
157
|
+
domain: res.classifications.domain?.label
|
|
158
|
+
});
|
|
159
|
+
return res.classifications;
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error instanceof chunkWJHHO24M_cjs.MorphError) {
|
|
162
|
+
throw new Error(`Router API error (${error.statusCode}): ${error.message}`);
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
exports.AnthropicRouter = AnthropicRouter;
|
|
170
|
+
exports.GeminiRouter = GeminiRouter;
|
|
171
|
+
exports.OpenAIRouter = OpenAIRouter;
|
|
172
|
+
exports.RawRouter = RawRouter;
|
|
173
|
+
exports.RouterClassifier = RouterClassifier;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkQT5LGZG3_cjs = require('./chunk-QT5LGZG3.cjs');
|
|
4
|
+
|
|
5
|
+
// tools/utils/resilience.ts
|
|
6
|
+
var DEFAULT_RETRY_CONFIG = {
|
|
7
|
+
maxRetries: 3,
|
|
8
|
+
initialDelay: 1e3,
|
|
9
|
+
maxDelay: 3e4,
|
|
10
|
+
backoffMultiplier: 2,
|
|
11
|
+
retryableErrors: ["ECONNREFUSED", "ETIMEDOUT", "ENOTFOUND"]
|
|
12
|
+
};
|
|
13
|
+
async function fetchWithRetry(url, options, retryConfig = {}) {
|
|
14
|
+
const {
|
|
15
|
+
maxRetries = DEFAULT_RETRY_CONFIG.maxRetries,
|
|
16
|
+
initialDelay = DEFAULT_RETRY_CONFIG.initialDelay,
|
|
17
|
+
maxDelay = DEFAULT_RETRY_CONFIG.maxDelay,
|
|
18
|
+
backoffMultiplier = DEFAULT_RETRY_CONFIG.backoffMultiplier,
|
|
19
|
+
retryableErrors = DEFAULT_RETRY_CONFIG.retryableErrors,
|
|
20
|
+
onRetry
|
|
21
|
+
} = retryConfig;
|
|
22
|
+
let lastError = null;
|
|
23
|
+
let delay = initialDelay;
|
|
24
|
+
options = { ...options, headers: { "X-Morph-SDK-Version": chunkQT5LGZG3_cjs.SDK_VERSION, ...options.headers } };
|
|
25
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(url, options);
|
|
28
|
+
if (response.status === 429 || response.status === 503) {
|
|
29
|
+
if (attempt < maxRetries) {
|
|
30
|
+
const retryAfter = response.headers.get("Retry-After");
|
|
31
|
+
const waitTime = retryAfter ? parseInt(retryAfter) * 1e3 : Math.min(delay, maxDelay);
|
|
32
|
+
const error = new Error(`HTTP ${response.status}: Retrying after ${waitTime}ms`);
|
|
33
|
+
if (onRetry) {
|
|
34
|
+
onRetry(attempt + 1, error);
|
|
35
|
+
}
|
|
36
|
+
await sleep(waitTime);
|
|
37
|
+
delay *= backoffMultiplier;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
lastError = error;
|
|
44
|
+
const isRetryable = retryableErrors.some(
|
|
45
|
+
(errType) => lastError?.message?.includes(errType)
|
|
46
|
+
);
|
|
47
|
+
if (!isRetryable || attempt === maxRetries) {
|
|
48
|
+
throw lastError;
|
|
49
|
+
}
|
|
50
|
+
const waitTime = Math.min(delay, maxDelay);
|
|
51
|
+
if (onRetry) {
|
|
52
|
+
onRetry(attempt + 1, lastError);
|
|
53
|
+
}
|
|
54
|
+
await sleep(waitTime);
|
|
55
|
+
delay *= backoffMultiplier;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw lastError || new Error("Max retries exceeded");
|
|
59
|
+
}
|
|
60
|
+
async function withTimeout(promise, timeoutMs, errorMessage) {
|
|
61
|
+
let timeoutId;
|
|
62
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
63
|
+
timeoutId = setTimeout(() => {
|
|
64
|
+
reject(new Error(errorMessage || `Operation timed out after ${timeoutMs}ms`));
|
|
65
|
+
}, timeoutMs);
|
|
66
|
+
});
|
|
67
|
+
try {
|
|
68
|
+
const result = await Promise.race([promise, timeoutPromise]);
|
|
69
|
+
clearTimeout(timeoutId);
|
|
70
|
+
return result;
|
|
71
|
+
} catch (error) {
|
|
72
|
+
clearTimeout(timeoutId);
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function sleep(ms) {
|
|
77
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
78
|
+
}
|
|
79
|
+
var MorphError = class extends Error {
|
|
80
|
+
constructor(message, code, statusCode, retryable = false) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.code = code;
|
|
83
|
+
this.statusCode = statusCode;
|
|
84
|
+
this.retryable = retryable;
|
|
85
|
+
this.name = "MorphError";
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
exports.MorphError = MorphError;
|
|
90
|
+
exports.fetchWithRetry = fetchWithRetry;
|
|
91
|
+
exports.withTimeout = withTimeout;
|