@morphllm/morphsdk 0.2.153 → 0.2.155
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-MJQNHIUZ.js → chunk-372QEHFA.js} +2 -2
- package/dist/{chunk-QMLGJK66.js → chunk-3ULQXPPO.js} +2 -2
- package/dist/{chunk-UFPDHAZ2.js → chunk-AEYK5XL5.js} +2 -2
- package/dist/{chunk-7IQMKVT4.js → chunk-CNKSTKRM.js} +2 -2
- package/dist/{chunk-ZAADJ3ER.js → chunk-CZ2LZ4GV.js} +4 -3
- package/dist/{chunk-ZAADJ3ER.js.map → chunk-CZ2LZ4GV.js.map} +1 -1
- package/dist/{chunk-H6RMMTKF.js → chunk-D34NUQGV.js} +2 -2
- package/dist/{chunk-NO2FGIQ7.js → chunk-DQJBEM4O.js} +2 -2
- package/dist/{chunk-NO2FGIQ7.js.map → chunk-DQJBEM4O.js.map} +1 -1
- package/dist/chunk-GLQWEINZ.js +53 -0
- package/dist/chunk-GLQWEINZ.js.map +1 -0
- package/dist/{chunk-GKBKSSUA.js → chunk-GOKSI67V.js} +2 -2
- package/dist/{chunk-QFRDNJXM.js → chunk-GPK433QG.js} +3 -3
- package/dist/{chunk-WTMEO2YB.js → chunk-GZXWWB4Z.js} +2 -2
- package/dist/{chunk-Q4DXGXXU.js → chunk-KQR3VCGR.js} +2 -2
- package/dist/{chunk-JB4T3K5T.js → chunk-L4GXXQEO.js} +2 -2
- package/dist/{chunk-QDDT5L5Y.js → chunk-MBVOMNXG.js} +2 -2
- package/dist/{chunk-KM7RICB6.js → chunk-NMBM37CB.js} +3 -2
- package/dist/{chunk-KM7RICB6.js.map → chunk-NMBM37CB.js.map} +1 -1
- package/dist/{chunk-5D7DDSZQ.js → chunk-Q3HZGVQ2.js} +2 -2
- package/dist/{chunk-AGFVQOGJ.js → chunk-SCVWDNQP.js} +2 -2
- package/dist/chunk-SCVWDNQP.js.map +1 -0
- package/dist/{chunk-6FRGRPUO.js → chunk-TZCNMJHF.js} +2 -2
- package/dist/{chunk-GAZCVVNY.js → chunk-V2BUYOKP.js} +2 -2
- package/dist/{chunk-QVWKDO76.js → chunk-Y23PQQRM.js} +20 -20
- package/dist/{chunk-FWHQH6RG.js → chunk-Y3LQWQHU.js} +4 -4
- package/dist/chunk-Y3LQWQHU.js.map +1 -0
- package/dist/{chunk-MFKR5VVL.js → chunk-YCUX3ZNQ.js} +17 -16
- package/dist/chunk-YCUX3ZNQ.js.map +1 -0
- package/dist/{chunk-77O2YF4B.js → chunk-YIUOPGWE.js} +2 -2
- package/dist/{chunk-3VMW3UJY.js → chunk-YJEXFOLJ.js} +4 -4
- package/dist/chunk-YJEXFOLJ.js.map +1 -0
- package/dist/{chunk-YBVAKGFE.js → chunk-YRHDWJDA.js} +2 -2
- package/dist/{chunk-I3ZPXGMZ.js → chunk-YYOPTKC3.js} +2 -2
- package/dist/{chunk-7AWNEVBE.js → chunk-ZMGKZNII.js} +6 -6
- package/dist/chunk-ZMGKZNII.js.map +1 -0
- package/dist/{client-BcO_qte8.d.ts → client-PkB7g9SA.d.ts} +1 -1
- package/dist/client.cjs +152 -107
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +24 -23
- package/dist/edge.cjs +4 -3
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +152 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -25
- package/dist/modelrouter/core.cjs +1 -1
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +3 -3
- package/dist/modelrouter/index.cjs +1 -1
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +3 -3
- package/dist/subagents/anthropic.cjs +138 -15
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +6 -4
- package/dist/subagents/vercel.cjs +138 -15
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +6 -4
- package/dist/tools/browser/anthropic.cjs +1 -1
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +5 -5
- package/dist/tools/browser/core.cjs +1 -1
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +4 -4
- package/dist/tools/browser/index.cjs +1 -1
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +7 -7
- package/dist/tools/browser/openai.cjs +1 -1
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +5 -5
- package/dist/tools/browser/profiles/core.cjs +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +5 -5
- package/dist/tools/codebase_search/anthropic.cjs +1 -1
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +4 -4
- package/dist/tools/codebase_search/core.cjs +1 -1
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +3 -3
- package/dist/tools/codebase_search/index.cjs +1 -1
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +6 -6
- package/dist/tools/codebase_search/openai.cjs +1 -1
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +4 -4
- package/dist/tools/codebase_search/vercel.cjs +1 -1
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +4 -4
- package/dist/tools/compact/core.cjs +1 -1
- package/dist/tools/compact/core.cjs.map +1 -1
- package/dist/tools/compact/core.js +1 -1
- package/dist/tools/compact/index.cjs +50 -3
- package/dist/tools/compact/index.cjs.map +1 -1
- package/dist/tools/compact/index.d.ts +10 -0
- package/dist/tools/compact/index.js +6 -2
- package/dist/tools/fastapply/anthropic.cjs +7 -5
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +4 -4
- package/dist/tools/fastapply/apply.cjs +3 -2
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +5 -3
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +3 -3
- package/dist/tools/fastapply/index.cjs +13 -11
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.d.ts +1 -1
- package/dist/tools/fastapply/index.js +6 -6
- package/dist/tools/fastapply/openai.cjs +7 -5
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +4 -4
- package/dist/tools/fastapply/types.cjs.map +1 -1
- package/dist/tools/fastapply/types.d.ts +6 -2
- package/dist/tools/fastapply/vercel.cjs +9 -7
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.d.ts +1 -1
- package/dist/tools/fastapply/vercel.js +4 -4
- package/dist/tools/index.cjs +13 -11
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +6 -6
- package/dist/tools/utils/resilience.cjs +1 -1
- 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 +1 -1
- 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 +138 -15
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +6 -4
- package/dist/tools/warp_grep/client.cjs +138 -15
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +5 -3
- package/dist/tools/warp_grep/gemini.cjs +138 -15
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +5 -3
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/index.cjs +138 -15
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +5 -3
- package/dist/tools/warp_grep/openai.cjs +138 -15
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +6 -4
- package/dist/tools/warp_grep/vercel.cjs +138 -15
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +6 -4
- package/dist/{vercel-B1GZ_g9N.d.ts → vercel-Cg38kNm4.d.ts} +2 -2
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-3VMW3UJY.js.map +0 -1
- package/dist/chunk-7AWNEVBE.js.map +0 -1
- package/dist/chunk-AGFVQOGJ.js.map +0 -1
- package/dist/chunk-FWHQH6RG.js.map +0 -1
- package/dist/chunk-MFKR5VVL.js.map +0 -1
- /package/dist/{chunk-MJQNHIUZ.js.map → chunk-372QEHFA.js.map} +0 -0
- /package/dist/{chunk-QMLGJK66.js.map → chunk-3ULQXPPO.js.map} +0 -0
- /package/dist/{chunk-UFPDHAZ2.js.map → chunk-AEYK5XL5.js.map} +0 -0
- /package/dist/{chunk-7IQMKVT4.js.map → chunk-CNKSTKRM.js.map} +0 -0
- /package/dist/{chunk-H6RMMTKF.js.map → chunk-D34NUQGV.js.map} +0 -0
- /package/dist/{chunk-GKBKSSUA.js.map → chunk-GOKSI67V.js.map} +0 -0
- /package/dist/{chunk-QFRDNJXM.js.map → chunk-GPK433QG.js.map} +0 -0
- /package/dist/{chunk-WTMEO2YB.js.map → chunk-GZXWWB4Z.js.map} +0 -0
- /package/dist/{chunk-Q4DXGXXU.js.map → chunk-KQR3VCGR.js.map} +0 -0
- /package/dist/{chunk-JB4T3K5T.js.map → chunk-L4GXXQEO.js.map} +0 -0
- /package/dist/{chunk-QDDT5L5Y.js.map → chunk-MBVOMNXG.js.map} +0 -0
- /package/dist/{chunk-5D7DDSZQ.js.map → chunk-Q3HZGVQ2.js.map} +0 -0
- /package/dist/{chunk-6FRGRPUO.js.map → chunk-TZCNMJHF.js.map} +0 -0
- /package/dist/{chunk-GAZCVVNY.js.map → chunk-V2BUYOKP.js.map} +0 -0
- /package/dist/{chunk-QVWKDO76.js.map → chunk-Y23PQQRM.js.map} +0 -0
- /package/dist/{chunk-77O2YF4B.js.map → chunk-YIUOPGWE.js.map} +0 -0
- /package/dist/{chunk-YBVAKGFE.js.map → chunk-YRHDWJDA.js.map} +0 -0
- /package/dist/{chunk-I3ZPXGMZ.js.map → chunk-YYOPTKC3.js.map} +0 -0
package/dist/client.cjs
CHANGED
|
@@ -36,7 +36,7 @@ var init_package = __esm({
|
|
|
36
36
|
"package.json"() {
|
|
37
37
|
package_default = {
|
|
38
38
|
name: "@morphllm/morphsdk",
|
|
39
|
-
version: "0.2.
|
|
39
|
+
version: "0.2.155",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -367,10 +367,11 @@ async function applyEdit(input, config = {}) {
|
|
|
367
367
|
if (debug) {
|
|
368
368
|
console.log(`[FastApply] Applying edit to code (${input.originalCode.length} chars)`);
|
|
369
369
|
}
|
|
370
|
+
const instruction = input.instruction ?? input.instructions ?? "";
|
|
370
371
|
const { content: mergedCode, completionId } = await callMorphAPI(
|
|
371
372
|
input.originalCode,
|
|
372
373
|
input.codeEdit,
|
|
373
|
-
|
|
374
|
+
instruction,
|
|
374
375
|
filepath,
|
|
375
376
|
config
|
|
376
377
|
);
|
|
@@ -1084,7 +1085,8 @@ async function executeEditFile(input, config = {}) {
|
|
|
1084
1085
|
}
|
|
1085
1086
|
if (debug) console.log(`[FastApply] File doesn't exist, will create new file`);
|
|
1086
1087
|
}
|
|
1087
|
-
const
|
|
1088
|
+
const instruction = input.instruction ?? input.instructions ?? "";
|
|
1089
|
+
const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
|
|
1088
1090
|
const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
|
|
1089
1091
|
if (config.autoWrite !== false) {
|
|
1090
1092
|
await writeFile(fullPath, mergedCode, "utf-8");
|
|
@@ -3463,6 +3465,131 @@ function parseGitHubUrl(input) {
|
|
|
3463
3465
|
);
|
|
3464
3466
|
}
|
|
3465
3467
|
|
|
3468
|
+
// tools/compact/core.ts
|
|
3469
|
+
var DEFAULT_API_URL4 = "https://api.morphllm.com";
|
|
3470
|
+
var DEFAULT_TIMEOUT2 = 12e4;
|
|
3471
|
+
var CompactClient = class {
|
|
3472
|
+
config;
|
|
3473
|
+
constructor(config = {}) {
|
|
3474
|
+
this.config = {
|
|
3475
|
+
...config,
|
|
3476
|
+
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
3477
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT2
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3480
|
+
/**
|
|
3481
|
+
* Compact messages or text via /v1/compact.
|
|
3482
|
+
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
3483
|
+
*
|
|
3484
|
+
* @example
|
|
3485
|
+
* ```typescript
|
|
3486
|
+
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
3487
|
+
* const result = await client.compact({
|
|
3488
|
+
* input: codeFile,
|
|
3489
|
+
* query: "authentication",
|
|
3490
|
+
* compressionRatio: 0.5,
|
|
3491
|
+
* });
|
|
3492
|
+
* console.log(result.output);
|
|
3493
|
+
* ```
|
|
3494
|
+
*/
|
|
3495
|
+
async compact(input) {
|
|
3496
|
+
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
3497
|
+
const debug = this.config.debug || false;
|
|
3498
|
+
if (!apiKey) {
|
|
3499
|
+
throw new Error(
|
|
3500
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
3501
|
+
);
|
|
3502
|
+
}
|
|
3503
|
+
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
3504
|
+
if (debug) {
|
|
3505
|
+
console.log(`[Compact] Calling ${url}`);
|
|
3506
|
+
}
|
|
3507
|
+
const body = {
|
|
3508
|
+
compression_ratio: input.compressionRatio ?? 0.5,
|
|
3509
|
+
preserve_recent: input.preserveRecent ?? 2,
|
|
3510
|
+
model: input.model ?? "morph-compactor",
|
|
3511
|
+
include_line_ranges: input.includeLineRanges ?? true,
|
|
3512
|
+
include_markers: input.includeMarkers ?? true
|
|
3513
|
+
};
|
|
3514
|
+
if (input.query !== void 0) {
|
|
3515
|
+
body.query = input.query;
|
|
3516
|
+
}
|
|
3517
|
+
if (input.messages) {
|
|
3518
|
+
body.messages = input.messages;
|
|
3519
|
+
} else if (typeof input.input === "string") {
|
|
3520
|
+
body.input = input.input;
|
|
3521
|
+
} else if (Array.isArray(input.input)) {
|
|
3522
|
+
body.messages = input.input;
|
|
3523
|
+
} else {
|
|
3524
|
+
throw new Error("Either 'input' or 'messages' must be provided");
|
|
3525
|
+
}
|
|
3526
|
+
const startTime = Date.now();
|
|
3527
|
+
const response = await fetch(url, {
|
|
3528
|
+
method: "POST",
|
|
3529
|
+
headers: {
|
|
3530
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
3531
|
+
"Content-Type": "application/json"
|
|
3532
|
+
},
|
|
3533
|
+
body: JSON.stringify(body),
|
|
3534
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
3535
|
+
});
|
|
3536
|
+
if (!response.ok) {
|
|
3537
|
+
const text = await response.text();
|
|
3538
|
+
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
3539
|
+
}
|
|
3540
|
+
const data = await response.json();
|
|
3541
|
+
if (debug) {
|
|
3542
|
+
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
3543
|
+
}
|
|
3544
|
+
return data;
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
3547
|
+
|
|
3548
|
+
// tools/compact/utils.ts
|
|
3549
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
3550
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
3551
|
+
const estimatedTokens = totalLength / 3;
|
|
3552
|
+
if (estimatedTokens <= maxTokens) {
|
|
3553
|
+
return files;
|
|
3554
|
+
}
|
|
3555
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
3556
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
3557
|
+
const client = new CompactClient({
|
|
3558
|
+
morphApiKey: apiKey,
|
|
3559
|
+
morphApiUrl: apiUrl
|
|
3560
|
+
});
|
|
3561
|
+
const results = [];
|
|
3562
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
3563
|
+
for (const file of files) {
|
|
3564
|
+
if (file.content.length < 500) {
|
|
3565
|
+
results.push({ path: file.path, content: file.content });
|
|
3566
|
+
continue;
|
|
3567
|
+
}
|
|
3568
|
+
const task = async () => {
|
|
3569
|
+
try {
|
|
3570
|
+
const result = await client.compact({
|
|
3571
|
+
input: file.content,
|
|
3572
|
+
query,
|
|
3573
|
+
compressionRatio,
|
|
3574
|
+
preserveRecent: 0
|
|
3575
|
+
});
|
|
3576
|
+
results.push({ path: file.path, content: result.output });
|
|
3577
|
+
} catch (error) {
|
|
3578
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
3579
|
+
results.push({ path: file.path, content: file.content });
|
|
3580
|
+
}
|
|
3581
|
+
};
|
|
3582
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
3583
|
+
inProgress.add(promise);
|
|
3584
|
+
if (inProgress.size >= maxConcurrency) {
|
|
3585
|
+
await Promise.race(inProgress);
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
await Promise.all(inProgress);
|
|
3589
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
3590
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3466
3593
|
// tools/warp_grep/client.ts
|
|
3467
3594
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
3468
3595
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
@@ -3585,20 +3712,9 @@ async function executeToolCall(input, config) {
|
|
|
3585
3712
|
timeout: config.timeout,
|
|
3586
3713
|
search_type: config.search_type
|
|
3587
3714
|
});
|
|
3588
|
-
|
|
3589
|
-
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3590
|
-
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
3591
|
-
console.error(`[warp_grep] executeToolCall failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
|
|
3592
|
-
return { success: false, error: `Search did not complete: ${errorDetails}` };
|
|
3593
|
-
}
|
|
3594
|
-
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
3595
|
-
file: r.path,
|
|
3596
|
-
content: r.content,
|
|
3597
|
-
lines: r.ranges
|
|
3598
|
-
}));
|
|
3599
|
-
return { success: true, contexts, summary: finish.payload };
|
|
3715
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3600
3716
|
}
|
|
3601
|
-
function processAgentResult(result) {
|
|
3717
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
3602
3718
|
const finish = result.finish;
|
|
3603
3719
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3604
3720
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -3610,6 +3726,15 @@ function processAgentResult(result) {
|
|
|
3610
3726
|
content: r.content,
|
|
3611
3727
|
lines: r.ranges
|
|
3612
3728
|
}));
|
|
3729
|
+
try {
|
|
3730
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
3731
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
3732
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
3733
|
+
contexts[i].content = compacted[i].content;
|
|
3734
|
+
}
|
|
3735
|
+
} catch (error) {
|
|
3736
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
3737
|
+
}
|
|
3613
3738
|
return { success: true, contexts, summary: finish.payload };
|
|
3614
3739
|
}
|
|
3615
3740
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -3638,7 +3763,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
3638
3763
|
}
|
|
3639
3764
|
yield value;
|
|
3640
3765
|
}
|
|
3641
|
-
return processAgentResult(agentResult);
|
|
3766
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3642
3767
|
}
|
|
3643
3768
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
3644
3769
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -3746,7 +3871,7 @@ var PermissionError = class extends GitHubError {
|
|
|
3746
3871
|
|
|
3747
3872
|
// tools/github/core.ts
|
|
3748
3873
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
3749
|
-
var
|
|
3874
|
+
var DEFAULT_TIMEOUT3 = 3e4;
|
|
3750
3875
|
var GitHubClient = class {
|
|
3751
3876
|
apiKey;
|
|
3752
3877
|
baseUrl;
|
|
@@ -3777,7 +3902,7 @@ var GitHubClient = class {
|
|
|
3777
3902
|
constructor(config = {}) {
|
|
3778
3903
|
this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
|
|
3779
3904
|
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
3780
|
-
this.timeout = config.timeout ||
|
|
3905
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT3;
|
|
3781
3906
|
this.debug = config.debug || false;
|
|
3782
3907
|
this.defaultInstallationId = config.installationId;
|
|
3783
3908
|
if (!this.apiKey) {
|
|
@@ -4609,86 +4734,6 @@ var MorphGit = class {
|
|
|
4609
4734
|
var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
|
|
4610
4735
|
var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4611
4736
|
|
|
4612
|
-
// tools/compact/core.ts
|
|
4613
|
-
var DEFAULT_API_URL4 = "http://192.222.56.183:8811";
|
|
4614
|
-
var DEFAULT_TIMEOUT3 = 12e4;
|
|
4615
|
-
var CompactClient = class {
|
|
4616
|
-
config;
|
|
4617
|
-
constructor(config = {}) {
|
|
4618
|
-
this.config = {
|
|
4619
|
-
...config,
|
|
4620
|
-
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
4621
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT3
|
|
4622
|
-
};
|
|
4623
|
-
}
|
|
4624
|
-
/**
|
|
4625
|
-
* Compact messages or text via /v1/compact.
|
|
4626
|
-
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
4627
|
-
*
|
|
4628
|
-
* @example
|
|
4629
|
-
* ```typescript
|
|
4630
|
-
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
4631
|
-
* const result = await client.compact({
|
|
4632
|
-
* input: codeFile,
|
|
4633
|
-
* query: "authentication",
|
|
4634
|
-
* compressionRatio: 0.5,
|
|
4635
|
-
* });
|
|
4636
|
-
* console.log(result.output);
|
|
4637
|
-
* ```
|
|
4638
|
-
*/
|
|
4639
|
-
async compact(input) {
|
|
4640
|
-
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
4641
|
-
const debug = this.config.debug || false;
|
|
4642
|
-
if (!apiKey) {
|
|
4643
|
-
throw new Error(
|
|
4644
|
-
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
4645
|
-
);
|
|
4646
|
-
}
|
|
4647
|
-
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
4648
|
-
if (debug) {
|
|
4649
|
-
console.log(`[Compact] Calling ${url}`);
|
|
4650
|
-
}
|
|
4651
|
-
const body = {
|
|
4652
|
-
compression_ratio: input.compressionRatio ?? 0.5,
|
|
4653
|
-
preserve_recent: input.preserveRecent ?? 2,
|
|
4654
|
-
model: input.model ?? "morph-compactor",
|
|
4655
|
-
include_line_ranges: input.includeLineRanges ?? true,
|
|
4656
|
-
include_markers: input.includeMarkers ?? true
|
|
4657
|
-
};
|
|
4658
|
-
if (input.query !== void 0) {
|
|
4659
|
-
body.query = input.query;
|
|
4660
|
-
}
|
|
4661
|
-
if (input.messages) {
|
|
4662
|
-
body.messages = input.messages;
|
|
4663
|
-
} else if (typeof input.input === "string") {
|
|
4664
|
-
body.input = input.input;
|
|
4665
|
-
} else if (Array.isArray(input.input)) {
|
|
4666
|
-
body.messages = input.input;
|
|
4667
|
-
} else {
|
|
4668
|
-
throw new Error("Either 'input' or 'messages' must be provided");
|
|
4669
|
-
}
|
|
4670
|
-
const startTime = Date.now();
|
|
4671
|
-
const response = await fetch(url, {
|
|
4672
|
-
method: "POST",
|
|
4673
|
-
headers: {
|
|
4674
|
-
"Authorization": `Bearer ${apiKey}`,
|
|
4675
|
-
"Content-Type": "application/json"
|
|
4676
|
-
},
|
|
4677
|
-
body: JSON.stringify(body),
|
|
4678
|
-
signal: AbortSignal.timeout(this.config.timeout)
|
|
4679
|
-
});
|
|
4680
|
-
if (!response.ok) {
|
|
4681
|
-
const text = await response.text();
|
|
4682
|
-
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
4683
|
-
}
|
|
4684
|
-
const data = await response.json();
|
|
4685
|
-
if (debug) {
|
|
4686
|
-
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
4687
|
-
}
|
|
4688
|
-
return data;
|
|
4689
|
-
}
|
|
4690
|
-
};
|
|
4691
|
-
|
|
4692
4737
|
// modelrouter/core.ts
|
|
4693
4738
|
var DEFAULT_CONFIG3 = {
|
|
4694
4739
|
apiUrl: "https://api.morphllm.com",
|
|
@@ -5110,7 +5155,7 @@ var editFileTool = {
|
|
|
5110
5155
|
type: "string",
|
|
5111
5156
|
description: "The path of the target file to modify"
|
|
5112
5157
|
},
|
|
5113
|
-
|
|
5158
|
+
instruction: {
|
|
5114
5159
|
type: "string",
|
|
5115
5160
|
description: "A single sentence describing what you are changing (first person)"
|
|
5116
5161
|
},
|
|
@@ -5119,7 +5164,7 @@ var editFileTool = {
|
|
|
5119
5164
|
description: "The lazy edit with // ... existing code ... markers"
|
|
5120
5165
|
}
|
|
5121
5166
|
},
|
|
5122
|
-
required: ["target_filepath", "
|
|
5167
|
+
required: ["target_filepath", "instruction", "code_edit"]
|
|
5123
5168
|
}
|
|
5124
5169
|
}
|
|
5125
5170
|
};
|
|
@@ -5341,7 +5386,7 @@ var editFileTool2 = {
|
|
|
5341
5386
|
type: "string",
|
|
5342
5387
|
description: "The path of the target file to modify"
|
|
5343
5388
|
},
|
|
5344
|
-
|
|
5389
|
+
instruction: {
|
|
5345
5390
|
type: "string",
|
|
5346
5391
|
description: "A single sentence describing what you are changing (first person)"
|
|
5347
5392
|
},
|
|
@@ -5350,7 +5395,7 @@ var editFileTool2 = {
|
|
|
5350
5395
|
description: "The lazy edit with // ... existing code ... markers"
|
|
5351
5396
|
}
|
|
5352
5397
|
},
|
|
5353
|
-
required: ["target_filepath", "
|
|
5398
|
+
required: ["target_filepath", "instruction", "code_edit"]
|
|
5354
5399
|
}
|
|
5355
5400
|
};
|
|
5356
5401
|
function formatResult5(result) {
|
|
@@ -5895,7 +5940,7 @@ var import_ai3 = require("ai");
|
|
|
5895
5940
|
var import_zod3 = require("zod");
|
|
5896
5941
|
var editFileSchema = import_zod3.z.object({
|
|
5897
5942
|
target_filepath: import_zod3.z.string().describe("The path of the target file to modify"),
|
|
5898
|
-
|
|
5943
|
+
instruction: import_zod3.z.string().describe("A single sentence describing what you are changing (first person)"),
|
|
5899
5944
|
code_edit: import_zod3.z.string().describe("The lazy edit with // ... existing code ... markers")
|
|
5900
5945
|
});
|
|
5901
5946
|
var editFileTool3 = (0, import_ai3.tool)({
|
|
@@ -5904,7 +5949,7 @@ var editFileTool3 = (0, import_ai3.tool)({
|
|
|
5904
5949
|
execute: async (params) => {
|
|
5905
5950
|
const result = await executeEditFile({
|
|
5906
5951
|
target_filepath: params.target_filepath,
|
|
5907
|
-
|
|
5952
|
+
instruction: params.instruction,
|
|
5908
5953
|
code_edit: params.code_edit
|
|
5909
5954
|
});
|
|
5910
5955
|
if (!result.success) {
|
|
@@ -5921,7 +5966,7 @@ var editFileTool3 = (0, import_ai3.tool)({
|
|
|
5921
5966
|
function createEditFileTool3(config = {}) {
|
|
5922
5967
|
const schema = import_zod3.z.object({
|
|
5923
5968
|
target_filepath: import_zod3.z.string().describe("The path of the target file to modify"),
|
|
5924
|
-
|
|
5969
|
+
instruction: import_zod3.z.string().describe("A single sentence describing what you are changing (first person)"),
|
|
5925
5970
|
code_edit: import_zod3.z.string().describe("The lazy edit with // ... existing code ... markers")
|
|
5926
5971
|
});
|
|
5927
5972
|
return (0, import_ai3.tool)({
|
|
@@ -5931,7 +5976,7 @@ function createEditFileTool3(config = {}) {
|
|
|
5931
5976
|
const result = await executeEditFile(
|
|
5932
5977
|
{
|
|
5933
5978
|
target_filepath: params.target_filepath,
|
|
5934
|
-
|
|
5979
|
+
instruction: params.instruction,
|
|
5935
5980
|
code_edit: params.code_edit
|
|
5936
5981
|
},
|
|
5937
5982
|
config
|