@morphllm/morphsdk 0.2.153 → 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.
Files changed (170) hide show
  1. package/dist/{chunk-MJQNHIUZ.js → chunk-2WAHX6I2.js} +2 -2
  2. package/dist/{chunk-7AWNEVBE.js → chunk-3BTUUH23.js} +2 -2
  3. package/dist/{chunk-NO2FGIQ7.js → chunk-3XO33KPS.js} +2 -2
  4. package/dist/{chunk-NO2FGIQ7.js.map → chunk-3XO33KPS.js.map} +1 -1
  5. package/dist/{chunk-GAZCVVNY.js → chunk-4R6F66B7.js} +2 -2
  6. package/dist/{chunk-QFRDNJXM.js → chunk-5IKDEESU.js} +3 -3
  7. package/dist/{chunk-5D7DDSZQ.js → chunk-A6T6E636.js} +2 -2
  8. package/dist/{chunk-FWHQH6RG.js → chunk-D5UUKDKL.js} +2 -2
  9. package/dist/{chunk-YBVAKGFE.js → chunk-FOKMTUWC.js} +2 -2
  10. package/dist/chunk-GLQWEINZ.js +53 -0
  11. package/dist/chunk-GLQWEINZ.js.map +1 -0
  12. package/dist/{chunk-KM7RICB6.js → chunk-J43SJUCO.js} +1 -1
  13. package/dist/{chunk-UFPDHAZ2.js → chunk-KRRO7FF2.js} +2 -2
  14. package/dist/{chunk-WTMEO2YB.js → chunk-LK4C3NYX.js} +2 -2
  15. package/dist/{chunk-QMLGJK66.js → chunk-MTRH7FMN.js} +2 -2
  16. package/dist/{chunk-I3ZPXGMZ.js → chunk-N4KLUOXK.js} +2 -2
  17. package/dist/{chunk-GKBKSSUA.js → chunk-P57SFOLD.js} +2 -2
  18. package/dist/{chunk-QVWKDO76.js → chunk-PRHEWGWC.js} +20 -20
  19. package/dist/{chunk-77O2YF4B.js → chunk-Q77CT3RI.js} +2 -2
  20. package/dist/{chunk-ZAADJ3ER.js → chunk-QSATHLZJ.js} +2 -2
  21. package/dist/{chunk-AGFVQOGJ.js → chunk-SCVWDNQP.js} +2 -2
  22. package/dist/chunk-SCVWDNQP.js.map +1 -0
  23. package/dist/{chunk-JB4T3K5T.js → chunk-TAGDMT3K.js} +2 -2
  24. package/dist/{chunk-H6RMMTKF.js → chunk-UDI5U6QV.js} +2 -2
  25. package/dist/{chunk-7IQMKVT4.js → chunk-VK76R3IN.js} +2 -2
  26. package/dist/{chunk-MFKR5VVL.js → chunk-WQU6QXSU.js} +17 -16
  27. package/dist/chunk-WQU6QXSU.js.map +1 -0
  28. package/dist/{chunk-Q4DXGXXU.js → chunk-Y5O3A7SU.js} +2 -2
  29. package/dist/{chunk-6FRGRPUO.js → chunk-YKBVE3CE.js} +2 -2
  30. package/dist/{chunk-3VMW3UJY.js → chunk-ZHKANLAQ.js} +2 -2
  31. package/dist/{chunk-QDDT5L5Y.js → chunk-ZSA3NL5T.js} +2 -2
  32. package/dist/client.cjs +140 -97
  33. package/dist/client.cjs.map +1 -1
  34. package/dist/client.js +24 -23
  35. package/dist/edge.cjs +2 -2
  36. package/dist/edge.cjs.map +1 -1
  37. package/dist/edge.js +7 -7
  38. package/dist/index.cjs +140 -97
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.js +26 -25
  41. package/dist/modelrouter/core.cjs +1 -1
  42. package/dist/modelrouter/core.cjs.map +1 -1
  43. package/dist/modelrouter/core.js +3 -3
  44. package/dist/modelrouter/index.cjs +1 -1
  45. package/dist/modelrouter/index.cjs.map +1 -1
  46. package/dist/modelrouter/index.js +3 -3
  47. package/dist/subagents/anthropic.cjs +138 -15
  48. package/dist/subagents/anthropic.cjs.map +1 -1
  49. package/dist/subagents/anthropic.js +6 -4
  50. package/dist/subagents/vercel.cjs +138 -15
  51. package/dist/subagents/vercel.cjs.map +1 -1
  52. package/dist/subagents/vercel.js +6 -4
  53. package/dist/tools/browser/anthropic.cjs +1 -1
  54. package/dist/tools/browser/anthropic.cjs.map +1 -1
  55. package/dist/tools/browser/anthropic.js +5 -5
  56. package/dist/tools/browser/core.cjs +1 -1
  57. package/dist/tools/browser/core.cjs.map +1 -1
  58. package/dist/tools/browser/core.js +4 -4
  59. package/dist/tools/browser/index.cjs +1 -1
  60. package/dist/tools/browser/index.cjs.map +1 -1
  61. package/dist/tools/browser/index.js +7 -7
  62. package/dist/tools/browser/openai.cjs +1 -1
  63. package/dist/tools/browser/openai.cjs.map +1 -1
  64. package/dist/tools/browser/openai.js +5 -5
  65. package/dist/tools/browser/profiles/core.cjs +1 -1
  66. package/dist/tools/browser/profiles/core.cjs.map +1 -1
  67. package/dist/tools/browser/profiles/core.js +3 -3
  68. package/dist/tools/browser/profiles/index.cjs +1 -1
  69. package/dist/tools/browser/profiles/index.cjs.map +1 -1
  70. package/dist/tools/browser/profiles/index.js +3 -3
  71. package/dist/tools/browser/vercel.cjs +1 -1
  72. package/dist/tools/browser/vercel.cjs.map +1 -1
  73. package/dist/tools/browser/vercel.js +5 -5
  74. package/dist/tools/codebase_search/anthropic.cjs +1 -1
  75. package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
  76. package/dist/tools/codebase_search/anthropic.js +4 -4
  77. package/dist/tools/codebase_search/core.cjs +1 -1
  78. package/dist/tools/codebase_search/core.cjs.map +1 -1
  79. package/dist/tools/codebase_search/core.js +3 -3
  80. package/dist/tools/codebase_search/index.cjs +1 -1
  81. package/dist/tools/codebase_search/index.cjs.map +1 -1
  82. package/dist/tools/codebase_search/index.js +6 -6
  83. package/dist/tools/codebase_search/openai.cjs +1 -1
  84. package/dist/tools/codebase_search/openai.cjs.map +1 -1
  85. package/dist/tools/codebase_search/openai.js +4 -4
  86. package/dist/tools/codebase_search/vercel.cjs +1 -1
  87. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  88. package/dist/tools/codebase_search/vercel.js +4 -4
  89. package/dist/tools/compact/core.cjs +1 -1
  90. package/dist/tools/compact/core.cjs.map +1 -1
  91. package/dist/tools/compact/core.js +1 -1
  92. package/dist/tools/compact/index.cjs +50 -3
  93. package/dist/tools/compact/index.cjs.map +1 -1
  94. package/dist/tools/compact/index.d.ts +10 -0
  95. package/dist/tools/compact/index.js +6 -2
  96. package/dist/tools/fastapply/anthropic.cjs +1 -1
  97. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  98. package/dist/tools/fastapply/anthropic.js +4 -4
  99. package/dist/tools/fastapply/apply.cjs +1 -1
  100. package/dist/tools/fastapply/apply.cjs.map +1 -1
  101. package/dist/tools/fastapply/apply.js +2 -2
  102. package/dist/tools/fastapply/core.cjs +1 -1
  103. package/dist/tools/fastapply/core.cjs.map +1 -1
  104. package/dist/tools/fastapply/core.js +3 -3
  105. package/dist/tools/fastapply/index.cjs +1 -1
  106. package/dist/tools/fastapply/index.cjs.map +1 -1
  107. package/dist/tools/fastapply/index.js +6 -6
  108. package/dist/tools/fastapply/openai.cjs +1 -1
  109. package/dist/tools/fastapply/openai.cjs.map +1 -1
  110. package/dist/tools/fastapply/openai.js +4 -4
  111. package/dist/tools/fastapply/vercel.cjs +1 -1
  112. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  113. package/dist/tools/fastapply/vercel.js +4 -4
  114. package/dist/tools/index.cjs +1 -1
  115. package/dist/tools/index.cjs.map +1 -1
  116. package/dist/tools/index.js +6 -6
  117. package/dist/tools/utils/resilience.cjs +1 -1
  118. package/dist/tools/utils/resilience.cjs.map +1 -1
  119. package/dist/tools/utils/resilience.js +2 -2
  120. package/dist/tools/warp_grep/agent/runner.cjs +1 -1
  121. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
  122. package/dist/tools/warp_grep/agent/runner.js +2 -2
  123. package/dist/tools/warp_grep/anthropic.cjs +138 -15
  124. package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
  125. package/dist/tools/warp_grep/anthropic.js +6 -4
  126. package/dist/tools/warp_grep/client.cjs +138 -15
  127. package/dist/tools/warp_grep/client.cjs.map +1 -1
  128. package/dist/tools/warp_grep/client.js +5 -3
  129. package/dist/tools/warp_grep/gemini.cjs +138 -15
  130. package/dist/tools/warp_grep/gemini.cjs.map +1 -1
  131. package/dist/tools/warp_grep/gemini.js +5 -3
  132. package/dist/tools/warp_grep/gemini.js.map +1 -1
  133. package/dist/tools/warp_grep/index.cjs +138 -15
  134. package/dist/tools/warp_grep/index.cjs.map +1 -1
  135. package/dist/tools/warp_grep/index.js +5 -3
  136. package/dist/tools/warp_grep/openai.cjs +138 -15
  137. package/dist/tools/warp_grep/openai.cjs.map +1 -1
  138. package/dist/tools/warp_grep/openai.js +6 -4
  139. package/dist/tools/warp_grep/vercel.cjs +138 -15
  140. package/dist/tools/warp_grep/vercel.cjs.map +1 -1
  141. package/dist/tools/warp_grep/vercel.js +6 -4
  142. package/dist/version.cjs +1 -1
  143. package/dist/version.cjs.map +1 -1
  144. package/dist/version.js +1 -1
  145. package/package.json +1 -1
  146. package/dist/chunk-AGFVQOGJ.js.map +0 -1
  147. package/dist/chunk-MFKR5VVL.js.map +0 -1
  148. /package/dist/{chunk-MJQNHIUZ.js.map → chunk-2WAHX6I2.js.map} +0 -0
  149. /package/dist/{chunk-7AWNEVBE.js.map → chunk-3BTUUH23.js.map} +0 -0
  150. /package/dist/{chunk-GAZCVVNY.js.map → chunk-4R6F66B7.js.map} +0 -0
  151. /package/dist/{chunk-QFRDNJXM.js.map → chunk-5IKDEESU.js.map} +0 -0
  152. /package/dist/{chunk-5D7DDSZQ.js.map → chunk-A6T6E636.js.map} +0 -0
  153. /package/dist/{chunk-FWHQH6RG.js.map → chunk-D5UUKDKL.js.map} +0 -0
  154. /package/dist/{chunk-YBVAKGFE.js.map → chunk-FOKMTUWC.js.map} +0 -0
  155. /package/dist/{chunk-KM7RICB6.js.map → chunk-J43SJUCO.js.map} +0 -0
  156. /package/dist/{chunk-UFPDHAZ2.js.map → chunk-KRRO7FF2.js.map} +0 -0
  157. /package/dist/{chunk-WTMEO2YB.js.map → chunk-LK4C3NYX.js.map} +0 -0
  158. /package/dist/{chunk-QMLGJK66.js.map → chunk-MTRH7FMN.js.map} +0 -0
  159. /package/dist/{chunk-I3ZPXGMZ.js.map → chunk-N4KLUOXK.js.map} +0 -0
  160. /package/dist/{chunk-GKBKSSUA.js.map → chunk-P57SFOLD.js.map} +0 -0
  161. /package/dist/{chunk-QVWKDO76.js.map → chunk-PRHEWGWC.js.map} +0 -0
  162. /package/dist/{chunk-77O2YF4B.js.map → chunk-Q77CT3RI.js.map} +0 -0
  163. /package/dist/{chunk-ZAADJ3ER.js.map → chunk-QSATHLZJ.js.map} +0 -0
  164. /package/dist/{chunk-JB4T3K5T.js.map → chunk-TAGDMT3K.js.map} +0 -0
  165. /package/dist/{chunk-H6RMMTKF.js.map → chunk-UDI5U6QV.js.map} +0 -0
  166. /package/dist/{chunk-7IQMKVT4.js.map → chunk-VK76R3IN.js.map} +0 -0
  167. /package/dist/{chunk-Q4DXGXXU.js.map → chunk-Y5O3A7SU.js.map} +0 -0
  168. /package/dist/{chunk-6FRGRPUO.js.map → chunk-YKBVE3CE.js.map} +0 -0
  169. /package/dist/{chunk-3VMW3UJY.js.map → chunk-ZHKANLAQ.js.map} +0 -0
  170. /package/dist/{chunk-QDDT5L5Y.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.153",
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
- const finish = result.finish;
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 DEFAULT_TIMEOUT2 = 3e4;
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 || DEFAULT_TIMEOUT2;
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",