@morphllm/morphsdk 0.2.152 → 0.2.154
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-WKHAZ732.js → chunk-2WAHX6I2.js} +2 -2
- package/dist/{chunk-ZFYFLNRE.js → chunk-3BTUUH23.js} +2 -2
- package/dist/{chunk-3ZR5RSJQ.js → chunk-3XO33KPS.js} +2 -2
- package/dist/{chunk-3ZR5RSJQ.js.map → chunk-3XO33KPS.js.map} +1 -1
- package/dist/{chunk-75C4DV27.js → chunk-4R6F66B7.js} +2 -2
- package/dist/{chunk-SVLY35WI.js → chunk-5IKDEESU.js} +3 -3
- package/dist/{chunk-YLWVLRWH.js → chunk-A6T6E636.js} +2 -2
- package/dist/{chunk-UAGEVTXM.js → chunk-D5UUKDKL.js} +2 -2
- package/dist/{chunk-R5IYAFFN.js → chunk-FOKMTUWC.js} +2 -2
- package/dist/chunk-GLQWEINZ.js +53 -0
- package/dist/chunk-GLQWEINZ.js.map +1 -0
- package/dist/{chunk-P7USBFIJ.js → chunk-J43SJUCO.js} +1 -1
- package/dist/{chunk-PO6IPUDB.js → chunk-KRRO7FF2.js} +2 -2
- package/dist/{chunk-PIBNTOS7.js → chunk-LK4C3NYX.js} +2 -2
- package/dist/{chunk-OLL7QI3Y.js → chunk-MTRH7FMN.js} +2 -2
- package/dist/{chunk-I6CWGOEL.js → chunk-N4KLUOXK.js} +2 -2
- package/dist/{chunk-U253YYNH.js → chunk-P57SFOLD.js} +2 -2
- package/dist/{chunk-BN6IXTDU.js → chunk-PRHEWGWC.js} +23 -23
- package/dist/{chunk-ZHRXNOXP.js → chunk-Q77CT3RI.js} +2 -2
- package/dist/{chunk-3TARZOBZ.js → chunk-QSATHLZJ.js} +2 -2
- package/dist/{chunk-3TARZOBZ.js.map → chunk-QSATHLZJ.js.map} +1 -1
- package/dist/{chunk-AGFVQOGJ.js → chunk-SCVWDNQP.js} +2 -2
- package/dist/chunk-SCVWDNQP.js.map +1 -0
- package/dist/{chunk-G7FGC7EQ.js → chunk-TAGDMT3K.js} +2 -2
- package/dist/{chunk-KXN4YMCP.js → chunk-UDI5U6QV.js} +2 -2
- package/dist/{chunk-Q72OV4VF.js → chunk-VK76R3IN.js} +2 -2
- package/dist/{chunk-DOWJVFKI.js → chunk-WQU6QXSU.js} +17 -16
- package/dist/chunk-WQU6QXSU.js.map +1 -0
- package/dist/{chunk-55ESIZID.js → chunk-Y5O3A7SU.js} +2 -2
- package/dist/{chunk-LYL2MWM6.js → chunk-YKBVE3CE.js} +2 -2
- package/dist/{chunk-WU2325QJ.js → chunk-ZHKANLAQ.js} +2 -2
- package/dist/{chunk-L7EVPMOK.js → chunk-ZSA3NL5T.js} +2 -2
- package/dist/client.cjs +140 -97
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +24 -23
- package/dist/edge.cjs +2 -2
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +7 -7
- package/dist/index.cjs +140 -97
- package/dist/index.cjs.map +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 +1 -1
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +4 -4
- package/dist/tools/fastapply/apply.cjs +1 -1
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.d.ts +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +1 -1
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +3 -3
- package/dist/tools/fastapply/index.cjs +1 -1
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +6 -6
- package/dist/tools/fastapply/openai.cjs +1 -1
- 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 +1 -1
- package/dist/tools/fastapply/vercel.cjs +1 -1
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +4 -4
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.cjs.map +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/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-AGFVQOGJ.js.map +0 -1
- package/dist/chunk-DOWJVFKI.js.map +0 -1
- /package/dist/{chunk-WKHAZ732.js.map → chunk-2WAHX6I2.js.map} +0 -0
- /package/dist/{chunk-ZFYFLNRE.js.map → chunk-3BTUUH23.js.map} +0 -0
- /package/dist/{chunk-75C4DV27.js.map → chunk-4R6F66B7.js.map} +0 -0
- /package/dist/{chunk-SVLY35WI.js.map → chunk-5IKDEESU.js.map} +0 -0
- /package/dist/{chunk-YLWVLRWH.js.map → chunk-A6T6E636.js.map} +0 -0
- /package/dist/{chunk-UAGEVTXM.js.map → chunk-D5UUKDKL.js.map} +0 -0
- /package/dist/{chunk-R5IYAFFN.js.map → chunk-FOKMTUWC.js.map} +0 -0
- /package/dist/{chunk-P7USBFIJ.js.map → chunk-J43SJUCO.js.map} +0 -0
- /package/dist/{chunk-PO6IPUDB.js.map → chunk-KRRO7FF2.js.map} +0 -0
- /package/dist/{chunk-PIBNTOS7.js.map → chunk-LK4C3NYX.js.map} +0 -0
- /package/dist/{chunk-OLL7QI3Y.js.map → chunk-MTRH7FMN.js.map} +0 -0
- /package/dist/{chunk-I6CWGOEL.js.map → chunk-N4KLUOXK.js.map} +0 -0
- /package/dist/{chunk-U253YYNH.js.map → chunk-P57SFOLD.js.map} +0 -0
- /package/dist/{chunk-BN6IXTDU.js.map → chunk-PRHEWGWC.js.map} +0 -0
- /package/dist/{chunk-ZHRXNOXP.js.map → chunk-Q77CT3RI.js.map} +0 -0
- /package/dist/{chunk-G7FGC7EQ.js.map → chunk-TAGDMT3K.js.map} +0 -0
- /package/dist/{chunk-KXN4YMCP.js.map → chunk-UDI5U6QV.js.map} +0 -0
- /package/dist/{chunk-Q72OV4VF.js.map → chunk-VK76R3IN.js.map} +0 -0
- /package/dist/{chunk-55ESIZID.js.map → chunk-Y5O3A7SU.js.map} +0 -0
- /package/dist/{chunk-LYL2MWM6.js.map → chunk-YKBVE3CE.js.map} +0 -0
- /package/dist/{chunk-WU2325QJ.js.map → chunk-ZHKANLAQ.js.map} +0 -0
- /package/dist/{chunk-L7EVPMOK.js.map → chunk-ZSA3NL5T.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.154",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -3485,6 +3485,131 @@ function parseGitHubUrl(input) {
|
|
|
3485
3485
|
);
|
|
3486
3486
|
}
|
|
3487
3487
|
|
|
3488
|
+
// tools/compact/core.ts
|
|
3489
|
+
var DEFAULT_API_URL4 = "https://api.morphllm.com";
|
|
3490
|
+
var DEFAULT_TIMEOUT2 = 12e4;
|
|
3491
|
+
var CompactClient = class {
|
|
3492
|
+
config;
|
|
3493
|
+
constructor(config = {}) {
|
|
3494
|
+
this.config = {
|
|
3495
|
+
...config,
|
|
3496
|
+
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
3497
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT2
|
|
3498
|
+
};
|
|
3499
|
+
}
|
|
3500
|
+
/**
|
|
3501
|
+
* Compact messages or text via /v1/compact.
|
|
3502
|
+
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
3503
|
+
*
|
|
3504
|
+
* @example
|
|
3505
|
+
* ```typescript
|
|
3506
|
+
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
3507
|
+
* const result = await client.compact({
|
|
3508
|
+
* input: codeFile,
|
|
3509
|
+
* query: "authentication",
|
|
3510
|
+
* compressionRatio: 0.5,
|
|
3511
|
+
* });
|
|
3512
|
+
* console.log(result.output);
|
|
3513
|
+
* ```
|
|
3514
|
+
*/
|
|
3515
|
+
async compact(input) {
|
|
3516
|
+
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
3517
|
+
const debug = this.config.debug || false;
|
|
3518
|
+
if (!apiKey) {
|
|
3519
|
+
throw new Error(
|
|
3520
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
3521
|
+
);
|
|
3522
|
+
}
|
|
3523
|
+
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
3524
|
+
if (debug) {
|
|
3525
|
+
console.log(`[Compact] Calling ${url}`);
|
|
3526
|
+
}
|
|
3527
|
+
const body = {
|
|
3528
|
+
compression_ratio: input.compressionRatio ?? 0.5,
|
|
3529
|
+
preserve_recent: input.preserveRecent ?? 2,
|
|
3530
|
+
model: input.model ?? "morph-compactor",
|
|
3531
|
+
include_line_ranges: input.includeLineRanges ?? true,
|
|
3532
|
+
include_markers: input.includeMarkers ?? true
|
|
3533
|
+
};
|
|
3534
|
+
if (input.query !== void 0) {
|
|
3535
|
+
body.query = input.query;
|
|
3536
|
+
}
|
|
3537
|
+
if (input.messages) {
|
|
3538
|
+
body.messages = input.messages;
|
|
3539
|
+
} else if (typeof input.input === "string") {
|
|
3540
|
+
body.input = input.input;
|
|
3541
|
+
} else if (Array.isArray(input.input)) {
|
|
3542
|
+
body.messages = input.input;
|
|
3543
|
+
} else {
|
|
3544
|
+
throw new Error("Either 'input' or 'messages' must be provided");
|
|
3545
|
+
}
|
|
3546
|
+
const startTime = Date.now();
|
|
3547
|
+
const response = await fetch(url, {
|
|
3548
|
+
method: "POST",
|
|
3549
|
+
headers: {
|
|
3550
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
3551
|
+
"Content-Type": "application/json"
|
|
3552
|
+
},
|
|
3553
|
+
body: JSON.stringify(body),
|
|
3554
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
3555
|
+
});
|
|
3556
|
+
if (!response.ok) {
|
|
3557
|
+
const text = await response.text();
|
|
3558
|
+
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
3559
|
+
}
|
|
3560
|
+
const data = await response.json();
|
|
3561
|
+
if (debug) {
|
|
3562
|
+
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
3563
|
+
}
|
|
3564
|
+
return data;
|
|
3565
|
+
}
|
|
3566
|
+
};
|
|
3567
|
+
|
|
3568
|
+
// tools/compact/utils.ts
|
|
3569
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
3570
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
3571
|
+
const estimatedTokens = totalLength / 3;
|
|
3572
|
+
if (estimatedTokens <= maxTokens) {
|
|
3573
|
+
return files;
|
|
3574
|
+
}
|
|
3575
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
3576
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
3577
|
+
const client = new CompactClient({
|
|
3578
|
+
morphApiKey: apiKey,
|
|
3579
|
+
morphApiUrl: apiUrl
|
|
3580
|
+
});
|
|
3581
|
+
const results = [];
|
|
3582
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
3583
|
+
for (const file of files) {
|
|
3584
|
+
if (file.content.length < 500) {
|
|
3585
|
+
results.push({ path: file.path, content: file.content });
|
|
3586
|
+
continue;
|
|
3587
|
+
}
|
|
3588
|
+
const task = async () => {
|
|
3589
|
+
try {
|
|
3590
|
+
const result = await client.compact({
|
|
3591
|
+
input: file.content,
|
|
3592
|
+
query,
|
|
3593
|
+
compressionRatio,
|
|
3594
|
+
preserveRecent: 0
|
|
3595
|
+
});
|
|
3596
|
+
results.push({ path: file.path, content: result.output });
|
|
3597
|
+
} catch (error) {
|
|
3598
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
3599
|
+
results.push({ path: file.path, content: file.content });
|
|
3600
|
+
}
|
|
3601
|
+
};
|
|
3602
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
3603
|
+
inProgress.add(promise);
|
|
3604
|
+
if (inProgress.size >= maxConcurrency) {
|
|
3605
|
+
await Promise.race(inProgress);
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3608
|
+
await Promise.all(inProgress);
|
|
3609
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
3610
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
3611
|
+
}
|
|
3612
|
+
|
|
3488
3613
|
// tools/warp_grep/client.ts
|
|
3489
3614
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
3490
3615
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
@@ -3607,20 +3732,9 @@ async function executeToolCall(input, config) {
|
|
|
3607
3732
|
timeout: config.timeout,
|
|
3608
3733
|
search_type: config.search_type
|
|
3609
3734
|
});
|
|
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 };
|
|
3735
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3622
3736
|
}
|
|
3623
|
-
function processAgentResult(result) {
|
|
3737
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
3624
3738
|
const finish = result.finish;
|
|
3625
3739
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3626
3740
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -3632,6 +3746,15 @@ function processAgentResult(result) {
|
|
|
3632
3746
|
content: r.content,
|
|
3633
3747
|
lines: r.ranges
|
|
3634
3748
|
}));
|
|
3749
|
+
try {
|
|
3750
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
3751
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
3752
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
3753
|
+
contexts[i].content = compacted[i].content;
|
|
3754
|
+
}
|
|
3755
|
+
} catch (error) {
|
|
3756
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
3757
|
+
}
|
|
3635
3758
|
return { success: true, contexts, summary: finish.payload };
|
|
3636
3759
|
}
|
|
3637
3760
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -3660,7 +3783,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
3660
3783
|
}
|
|
3661
3784
|
yield value;
|
|
3662
3785
|
}
|
|
3663
|
-
return processAgentResult(agentResult);
|
|
3786
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3664
3787
|
}
|
|
3665
3788
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
3666
3789
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -3768,7 +3891,7 @@ var PermissionError = class extends GitHubError {
|
|
|
3768
3891
|
|
|
3769
3892
|
// tools/github/core.ts
|
|
3770
3893
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
3771
|
-
var
|
|
3894
|
+
var DEFAULT_TIMEOUT3 = 3e4;
|
|
3772
3895
|
var GitHubClient = class {
|
|
3773
3896
|
apiKey;
|
|
3774
3897
|
baseUrl;
|
|
@@ -3799,7 +3922,7 @@ var GitHubClient = class {
|
|
|
3799
3922
|
constructor(config = {}) {
|
|
3800
3923
|
this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
|
|
3801
3924
|
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
3802
|
-
this.timeout = config.timeout ||
|
|
3925
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT3;
|
|
3803
3926
|
this.debug = config.debug || false;
|
|
3804
3927
|
this.defaultInstallationId = config.installationId;
|
|
3805
3928
|
if (!this.apiKey) {
|
|
@@ -4631,86 +4754,6 @@ var MorphGit = class {
|
|
|
4631
4754
|
var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
|
|
4632
4755
|
var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4633
4756
|
|
|
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
4757
|
// modelrouter/core.ts
|
|
4715
4758
|
var DEFAULT_CONFIG3 = {
|
|
4716
4759
|
apiUrl: "https://api.morphllm.com",
|