@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/index.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
|
);
|
|
@@ -1106,7 +1107,8 @@ async function executeEditFile(input, config = {}) {
|
|
|
1106
1107
|
}
|
|
1107
1108
|
if (debug) console.log(`[FastApply] File doesn't exist, will create new file`);
|
|
1108
1109
|
}
|
|
1109
|
-
const
|
|
1110
|
+
const instruction = input.instruction ?? input.instructions ?? "";
|
|
1111
|
+
const { content: mergedCode, completionId } = await callMorphAPI2(originalCode, input.code_edit, instruction, input.target_filepath, config);
|
|
1110
1112
|
const udiff = config.generateUdiff !== false ? generateUdiff2(originalCode, mergedCode, input.target_filepath) : void 0;
|
|
1111
1113
|
if (config.autoWrite !== false) {
|
|
1112
1114
|
await writeFile(fullPath, mergedCode, "utf-8");
|
|
@@ -3485,6 +3487,131 @@ function parseGitHubUrl(input) {
|
|
|
3485
3487
|
);
|
|
3486
3488
|
}
|
|
3487
3489
|
|
|
3490
|
+
// tools/compact/core.ts
|
|
3491
|
+
var DEFAULT_API_URL4 = "https://api.morphllm.com";
|
|
3492
|
+
var DEFAULT_TIMEOUT2 = 12e4;
|
|
3493
|
+
var CompactClient = class {
|
|
3494
|
+
config;
|
|
3495
|
+
constructor(config = {}) {
|
|
3496
|
+
this.config = {
|
|
3497
|
+
...config,
|
|
3498
|
+
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
3499
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT2
|
|
3500
|
+
};
|
|
3501
|
+
}
|
|
3502
|
+
/**
|
|
3503
|
+
* Compact messages or text via /v1/compact.
|
|
3504
|
+
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
3505
|
+
*
|
|
3506
|
+
* @example
|
|
3507
|
+
* ```typescript
|
|
3508
|
+
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
3509
|
+
* const result = await client.compact({
|
|
3510
|
+
* input: codeFile,
|
|
3511
|
+
* query: "authentication",
|
|
3512
|
+
* compressionRatio: 0.5,
|
|
3513
|
+
* });
|
|
3514
|
+
* console.log(result.output);
|
|
3515
|
+
* ```
|
|
3516
|
+
*/
|
|
3517
|
+
async compact(input) {
|
|
3518
|
+
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
3519
|
+
const debug = this.config.debug || false;
|
|
3520
|
+
if (!apiKey) {
|
|
3521
|
+
throw new Error(
|
|
3522
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
3523
|
+
);
|
|
3524
|
+
}
|
|
3525
|
+
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
3526
|
+
if (debug) {
|
|
3527
|
+
console.log(`[Compact] Calling ${url}`);
|
|
3528
|
+
}
|
|
3529
|
+
const body = {
|
|
3530
|
+
compression_ratio: input.compressionRatio ?? 0.5,
|
|
3531
|
+
preserve_recent: input.preserveRecent ?? 2,
|
|
3532
|
+
model: input.model ?? "morph-compactor",
|
|
3533
|
+
include_line_ranges: input.includeLineRanges ?? true,
|
|
3534
|
+
include_markers: input.includeMarkers ?? true
|
|
3535
|
+
};
|
|
3536
|
+
if (input.query !== void 0) {
|
|
3537
|
+
body.query = input.query;
|
|
3538
|
+
}
|
|
3539
|
+
if (input.messages) {
|
|
3540
|
+
body.messages = input.messages;
|
|
3541
|
+
} else if (typeof input.input === "string") {
|
|
3542
|
+
body.input = input.input;
|
|
3543
|
+
} else if (Array.isArray(input.input)) {
|
|
3544
|
+
body.messages = input.input;
|
|
3545
|
+
} else {
|
|
3546
|
+
throw new Error("Either 'input' or 'messages' must be provided");
|
|
3547
|
+
}
|
|
3548
|
+
const startTime = Date.now();
|
|
3549
|
+
const response = await fetch(url, {
|
|
3550
|
+
method: "POST",
|
|
3551
|
+
headers: {
|
|
3552
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
3553
|
+
"Content-Type": "application/json"
|
|
3554
|
+
},
|
|
3555
|
+
body: JSON.stringify(body),
|
|
3556
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
3557
|
+
});
|
|
3558
|
+
if (!response.ok) {
|
|
3559
|
+
const text = await response.text();
|
|
3560
|
+
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
3561
|
+
}
|
|
3562
|
+
const data = await response.json();
|
|
3563
|
+
if (debug) {
|
|
3564
|
+
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
3565
|
+
}
|
|
3566
|
+
return data;
|
|
3567
|
+
}
|
|
3568
|
+
};
|
|
3569
|
+
|
|
3570
|
+
// tools/compact/utils.ts
|
|
3571
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
3572
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
3573
|
+
const estimatedTokens = totalLength / 3;
|
|
3574
|
+
if (estimatedTokens <= maxTokens) {
|
|
3575
|
+
return files;
|
|
3576
|
+
}
|
|
3577
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
3578
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
3579
|
+
const client = new CompactClient({
|
|
3580
|
+
morphApiKey: apiKey,
|
|
3581
|
+
morphApiUrl: apiUrl
|
|
3582
|
+
});
|
|
3583
|
+
const results = [];
|
|
3584
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
3585
|
+
for (const file of files) {
|
|
3586
|
+
if (file.content.length < 500) {
|
|
3587
|
+
results.push({ path: file.path, content: file.content });
|
|
3588
|
+
continue;
|
|
3589
|
+
}
|
|
3590
|
+
const task = async () => {
|
|
3591
|
+
try {
|
|
3592
|
+
const result = await client.compact({
|
|
3593
|
+
input: file.content,
|
|
3594
|
+
query,
|
|
3595
|
+
compressionRatio,
|
|
3596
|
+
preserveRecent: 0
|
|
3597
|
+
});
|
|
3598
|
+
results.push({ path: file.path, content: result.output });
|
|
3599
|
+
} catch (error) {
|
|
3600
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
3601
|
+
results.push({ path: file.path, content: file.content });
|
|
3602
|
+
}
|
|
3603
|
+
};
|
|
3604
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
3605
|
+
inProgress.add(promise);
|
|
3606
|
+
if (inProgress.size >= maxConcurrency) {
|
|
3607
|
+
await Promise.race(inProgress);
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
await Promise.all(inProgress);
|
|
3611
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
3612
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
3613
|
+
}
|
|
3614
|
+
|
|
3488
3615
|
// tools/warp_grep/client.ts
|
|
3489
3616
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
3490
3617
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
@@ -3607,20 +3734,9 @@ async function executeToolCall(input, config) {
|
|
|
3607
3734
|
timeout: config.timeout,
|
|
3608
3735
|
search_type: config.search_type
|
|
3609
3736
|
});
|
|
3610
|
-
|
|
3611
|
-
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3612
|
-
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
3613
|
-
console.error(`[warp_grep] executeToolCall failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
|
|
3614
|
-
return { success: false, error: `Search did not complete: ${errorDetails}` };
|
|
3615
|
-
}
|
|
3616
|
-
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
3617
|
-
file: r.path,
|
|
3618
|
-
content: r.content,
|
|
3619
|
-
lines: r.ranges
|
|
3620
|
-
}));
|
|
3621
|
-
return { success: true, contexts, summary: finish.payload };
|
|
3737
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3622
3738
|
}
|
|
3623
|
-
function processAgentResult(result) {
|
|
3739
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
3624
3740
|
const finish = result.finish;
|
|
3625
3741
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3626
3742
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -3632,6 +3748,15 @@ function processAgentResult(result) {
|
|
|
3632
3748
|
content: r.content,
|
|
3633
3749
|
lines: r.ranges
|
|
3634
3750
|
}));
|
|
3751
|
+
try {
|
|
3752
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
3753
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
3754
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
3755
|
+
contexts[i].content = compacted[i].content;
|
|
3756
|
+
}
|
|
3757
|
+
} catch (error) {
|
|
3758
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
3759
|
+
}
|
|
3635
3760
|
return { success: true, contexts, summary: finish.payload };
|
|
3636
3761
|
}
|
|
3637
3762
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -3660,7 +3785,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
3660
3785
|
}
|
|
3661
3786
|
yield value;
|
|
3662
3787
|
}
|
|
3663
|
-
return processAgentResult(agentResult);
|
|
3788
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3664
3789
|
}
|
|
3665
3790
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
3666
3791
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -3768,7 +3893,7 @@ var PermissionError = class extends GitHubError {
|
|
|
3768
3893
|
|
|
3769
3894
|
// tools/github/core.ts
|
|
3770
3895
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
3771
|
-
var
|
|
3896
|
+
var DEFAULT_TIMEOUT3 = 3e4;
|
|
3772
3897
|
var GitHubClient = class {
|
|
3773
3898
|
apiKey;
|
|
3774
3899
|
baseUrl;
|
|
@@ -3799,7 +3924,7 @@ var GitHubClient = class {
|
|
|
3799
3924
|
constructor(config = {}) {
|
|
3800
3925
|
this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
|
|
3801
3926
|
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
3802
|
-
this.timeout = config.timeout ||
|
|
3927
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT3;
|
|
3803
3928
|
this.debug = config.debug || false;
|
|
3804
3929
|
this.defaultInstallationId = config.installationId;
|
|
3805
3930
|
if (!this.apiKey) {
|
|
@@ -4631,86 +4756,6 @@ var MorphGit = class {
|
|
|
4631
4756
|
var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
|
|
4632
4757
|
var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4633
4758
|
|
|
4634
|
-
// tools/compact/core.ts
|
|
4635
|
-
var DEFAULT_API_URL4 = "http://192.222.56.183:8811";
|
|
4636
|
-
var DEFAULT_TIMEOUT3 = 12e4;
|
|
4637
|
-
var CompactClient = class {
|
|
4638
|
-
config;
|
|
4639
|
-
constructor(config = {}) {
|
|
4640
|
-
this.config = {
|
|
4641
|
-
...config,
|
|
4642
|
-
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
4643
|
-
timeout: config.timeout ?? DEFAULT_TIMEOUT3
|
|
4644
|
-
};
|
|
4645
|
-
}
|
|
4646
|
-
/**
|
|
4647
|
-
* Compact messages or text via /v1/compact.
|
|
4648
|
-
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
4649
|
-
*
|
|
4650
|
-
* @example
|
|
4651
|
-
* ```typescript
|
|
4652
|
-
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
4653
|
-
* const result = await client.compact({
|
|
4654
|
-
* input: codeFile,
|
|
4655
|
-
* query: "authentication",
|
|
4656
|
-
* compressionRatio: 0.5,
|
|
4657
|
-
* });
|
|
4658
|
-
* console.log(result.output);
|
|
4659
|
-
* ```
|
|
4660
|
-
*/
|
|
4661
|
-
async compact(input) {
|
|
4662
|
-
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
4663
|
-
const debug = this.config.debug || false;
|
|
4664
|
-
if (!apiKey) {
|
|
4665
|
-
throw new Error(
|
|
4666
|
-
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
4667
|
-
);
|
|
4668
|
-
}
|
|
4669
|
-
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
4670
|
-
if (debug) {
|
|
4671
|
-
console.log(`[Compact] Calling ${url}`);
|
|
4672
|
-
}
|
|
4673
|
-
const body = {
|
|
4674
|
-
compression_ratio: input.compressionRatio ?? 0.5,
|
|
4675
|
-
preserve_recent: input.preserveRecent ?? 2,
|
|
4676
|
-
model: input.model ?? "morph-compactor",
|
|
4677
|
-
include_line_ranges: input.includeLineRanges ?? true,
|
|
4678
|
-
include_markers: input.includeMarkers ?? true
|
|
4679
|
-
};
|
|
4680
|
-
if (input.query !== void 0) {
|
|
4681
|
-
body.query = input.query;
|
|
4682
|
-
}
|
|
4683
|
-
if (input.messages) {
|
|
4684
|
-
body.messages = input.messages;
|
|
4685
|
-
} else if (typeof input.input === "string") {
|
|
4686
|
-
body.input = input.input;
|
|
4687
|
-
} else if (Array.isArray(input.input)) {
|
|
4688
|
-
body.messages = input.input;
|
|
4689
|
-
} else {
|
|
4690
|
-
throw new Error("Either 'input' or 'messages' must be provided");
|
|
4691
|
-
}
|
|
4692
|
-
const startTime = Date.now();
|
|
4693
|
-
const response = await fetch(url, {
|
|
4694
|
-
method: "POST",
|
|
4695
|
-
headers: {
|
|
4696
|
-
"Authorization": `Bearer ${apiKey}`,
|
|
4697
|
-
"Content-Type": "application/json"
|
|
4698
|
-
},
|
|
4699
|
-
body: JSON.stringify(body),
|
|
4700
|
-
signal: AbortSignal.timeout(this.config.timeout)
|
|
4701
|
-
});
|
|
4702
|
-
if (!response.ok) {
|
|
4703
|
-
const text = await response.text();
|
|
4704
|
-
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
4705
|
-
}
|
|
4706
|
-
const data = await response.json();
|
|
4707
|
-
if (debug) {
|
|
4708
|
-
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
4709
|
-
}
|
|
4710
|
-
return data;
|
|
4711
|
-
}
|
|
4712
|
-
};
|
|
4713
|
-
|
|
4714
4759
|
// modelrouter/core.ts
|
|
4715
4760
|
var DEFAULT_CONFIG3 = {
|
|
4716
4761
|
apiUrl: "https://api.morphllm.com",
|
|
@@ -5132,7 +5177,7 @@ var editFileTool = {
|
|
|
5132
5177
|
type: "string",
|
|
5133
5178
|
description: "The path of the target file to modify"
|
|
5134
5179
|
},
|
|
5135
|
-
|
|
5180
|
+
instruction: {
|
|
5136
5181
|
type: "string",
|
|
5137
5182
|
description: "A single sentence describing what you are changing (first person)"
|
|
5138
5183
|
},
|
|
@@ -5141,7 +5186,7 @@ var editFileTool = {
|
|
|
5141
5186
|
description: "The lazy edit with // ... existing code ... markers"
|
|
5142
5187
|
}
|
|
5143
5188
|
},
|
|
5144
|
-
required: ["target_filepath", "
|
|
5189
|
+
required: ["target_filepath", "instruction", "code_edit"]
|
|
5145
5190
|
}
|
|
5146
5191
|
}
|
|
5147
5192
|
};
|
|
@@ -5363,7 +5408,7 @@ var editFileTool2 = {
|
|
|
5363
5408
|
type: "string",
|
|
5364
5409
|
description: "The path of the target file to modify"
|
|
5365
5410
|
},
|
|
5366
|
-
|
|
5411
|
+
instruction: {
|
|
5367
5412
|
type: "string",
|
|
5368
5413
|
description: "A single sentence describing what you are changing (first person)"
|
|
5369
5414
|
},
|
|
@@ -5372,7 +5417,7 @@ var editFileTool2 = {
|
|
|
5372
5417
|
description: "The lazy edit with // ... existing code ... markers"
|
|
5373
5418
|
}
|
|
5374
5419
|
},
|
|
5375
|
-
required: ["target_filepath", "
|
|
5420
|
+
required: ["target_filepath", "instruction", "code_edit"]
|
|
5376
5421
|
}
|
|
5377
5422
|
};
|
|
5378
5423
|
function formatResult5(result) {
|
|
@@ -5917,7 +5962,7 @@ var import_ai3 = require("ai");
|
|
|
5917
5962
|
var import_zod3 = require("zod");
|
|
5918
5963
|
var editFileSchema = import_zod3.z.object({
|
|
5919
5964
|
target_filepath: import_zod3.z.string().describe("The path of the target file to modify"),
|
|
5920
|
-
|
|
5965
|
+
instruction: import_zod3.z.string().describe("A single sentence describing what you are changing (first person)"),
|
|
5921
5966
|
code_edit: import_zod3.z.string().describe("The lazy edit with // ... existing code ... markers")
|
|
5922
5967
|
});
|
|
5923
5968
|
var editFileTool3 = (0, import_ai3.tool)({
|
|
@@ -5926,7 +5971,7 @@ var editFileTool3 = (0, import_ai3.tool)({
|
|
|
5926
5971
|
execute: async (params) => {
|
|
5927
5972
|
const result = await executeEditFile({
|
|
5928
5973
|
target_filepath: params.target_filepath,
|
|
5929
|
-
|
|
5974
|
+
instruction: params.instruction,
|
|
5930
5975
|
code_edit: params.code_edit
|
|
5931
5976
|
});
|
|
5932
5977
|
if (!result.success) {
|
|
@@ -5943,7 +5988,7 @@ var editFileTool3 = (0, import_ai3.tool)({
|
|
|
5943
5988
|
function createEditFileTool3(config = {}) {
|
|
5944
5989
|
const schema = import_zod3.z.object({
|
|
5945
5990
|
target_filepath: import_zod3.z.string().describe("The path of the target file to modify"),
|
|
5946
|
-
|
|
5991
|
+
instruction: import_zod3.z.string().describe("A single sentence describing what you are changing (first person)"),
|
|
5947
5992
|
code_edit: import_zod3.z.string().describe("The lazy edit with // ... existing code ... markers")
|
|
5948
5993
|
});
|
|
5949
5994
|
return (0, import_ai3.tool)({
|
|
@@ -5953,7 +5998,7 @@ function createEditFileTool3(config = {}) {
|
|
|
5953
5998
|
const result = await executeEditFile(
|
|
5954
5999
|
{
|
|
5955
6000
|
target_filepath: params.target_filepath,
|
|
5956
|
-
|
|
6001
|
+
instruction: params.instruction,
|
|
5957
6002
|
code_edit: params.code_edit
|
|
5958
6003
|
},
|
|
5959
6004
|
config
|