@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.
Files changed (173) hide show
  1. package/dist/{chunk-WKHAZ732.js → chunk-2WAHX6I2.js} +2 -2
  2. package/dist/{chunk-ZFYFLNRE.js → chunk-3BTUUH23.js} +2 -2
  3. package/dist/{chunk-3ZR5RSJQ.js → chunk-3XO33KPS.js} +2 -2
  4. package/dist/{chunk-3ZR5RSJQ.js.map → chunk-3XO33KPS.js.map} +1 -1
  5. package/dist/{chunk-75C4DV27.js → chunk-4R6F66B7.js} +2 -2
  6. package/dist/{chunk-SVLY35WI.js → chunk-5IKDEESU.js} +3 -3
  7. package/dist/{chunk-YLWVLRWH.js → chunk-A6T6E636.js} +2 -2
  8. package/dist/{chunk-UAGEVTXM.js → chunk-D5UUKDKL.js} +2 -2
  9. package/dist/{chunk-R5IYAFFN.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-P7USBFIJ.js → chunk-J43SJUCO.js} +1 -1
  13. package/dist/{chunk-PO6IPUDB.js → chunk-KRRO7FF2.js} +2 -2
  14. package/dist/{chunk-PIBNTOS7.js → chunk-LK4C3NYX.js} +2 -2
  15. package/dist/{chunk-OLL7QI3Y.js → chunk-MTRH7FMN.js} +2 -2
  16. package/dist/{chunk-I6CWGOEL.js → chunk-N4KLUOXK.js} +2 -2
  17. package/dist/{chunk-U253YYNH.js → chunk-P57SFOLD.js} +2 -2
  18. package/dist/{chunk-BN6IXTDU.js → chunk-PRHEWGWC.js} +23 -23
  19. package/dist/{chunk-ZHRXNOXP.js → chunk-Q77CT3RI.js} +2 -2
  20. package/dist/{chunk-3TARZOBZ.js → chunk-QSATHLZJ.js} +2 -2
  21. package/dist/{chunk-3TARZOBZ.js.map → chunk-QSATHLZJ.js.map} +1 -1
  22. package/dist/{chunk-AGFVQOGJ.js → chunk-SCVWDNQP.js} +2 -2
  23. package/dist/chunk-SCVWDNQP.js.map +1 -0
  24. package/dist/{chunk-G7FGC7EQ.js → chunk-TAGDMT3K.js} +2 -2
  25. package/dist/{chunk-KXN4YMCP.js → chunk-UDI5U6QV.js} +2 -2
  26. package/dist/{chunk-Q72OV4VF.js → chunk-VK76R3IN.js} +2 -2
  27. package/dist/{chunk-DOWJVFKI.js → chunk-WQU6QXSU.js} +17 -16
  28. package/dist/chunk-WQU6QXSU.js.map +1 -0
  29. package/dist/{chunk-55ESIZID.js → chunk-Y5O3A7SU.js} +2 -2
  30. package/dist/{chunk-LYL2MWM6.js → chunk-YKBVE3CE.js} +2 -2
  31. package/dist/{chunk-WU2325QJ.js → chunk-ZHKANLAQ.js} +2 -2
  32. package/dist/{chunk-L7EVPMOK.js → chunk-ZSA3NL5T.js} +2 -2
  33. package/dist/client.cjs +140 -97
  34. package/dist/client.cjs.map +1 -1
  35. package/dist/client.js +24 -23
  36. package/dist/edge.cjs +2 -2
  37. package/dist/edge.cjs.map +1 -1
  38. package/dist/edge.js +7 -7
  39. package/dist/index.cjs +140 -97
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.js +26 -25
  42. package/dist/modelrouter/core.cjs +1 -1
  43. package/dist/modelrouter/core.cjs.map +1 -1
  44. package/dist/modelrouter/core.js +3 -3
  45. package/dist/modelrouter/index.cjs +1 -1
  46. package/dist/modelrouter/index.cjs.map +1 -1
  47. package/dist/modelrouter/index.js +3 -3
  48. package/dist/subagents/anthropic.cjs +138 -15
  49. package/dist/subagents/anthropic.cjs.map +1 -1
  50. package/dist/subagents/anthropic.js +6 -4
  51. package/dist/subagents/vercel.cjs +138 -15
  52. package/dist/subagents/vercel.cjs.map +1 -1
  53. package/dist/subagents/vercel.js +6 -4
  54. package/dist/tools/browser/anthropic.cjs +1 -1
  55. package/dist/tools/browser/anthropic.cjs.map +1 -1
  56. package/dist/tools/browser/anthropic.js +5 -5
  57. package/dist/tools/browser/core.cjs +1 -1
  58. package/dist/tools/browser/core.cjs.map +1 -1
  59. package/dist/tools/browser/core.js +4 -4
  60. package/dist/tools/browser/index.cjs +1 -1
  61. package/dist/tools/browser/index.cjs.map +1 -1
  62. package/dist/tools/browser/index.js +7 -7
  63. package/dist/tools/browser/openai.cjs +1 -1
  64. package/dist/tools/browser/openai.cjs.map +1 -1
  65. package/dist/tools/browser/openai.js +5 -5
  66. package/dist/tools/browser/profiles/core.cjs +1 -1
  67. package/dist/tools/browser/profiles/core.cjs.map +1 -1
  68. package/dist/tools/browser/profiles/core.js +3 -3
  69. package/dist/tools/browser/profiles/index.cjs +1 -1
  70. package/dist/tools/browser/profiles/index.cjs.map +1 -1
  71. package/dist/tools/browser/profiles/index.js +3 -3
  72. package/dist/tools/browser/vercel.cjs +1 -1
  73. package/dist/tools/browser/vercel.cjs.map +1 -1
  74. package/dist/tools/browser/vercel.js +5 -5
  75. package/dist/tools/codebase_search/anthropic.cjs +1 -1
  76. package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
  77. package/dist/tools/codebase_search/anthropic.js +4 -4
  78. package/dist/tools/codebase_search/core.cjs +1 -1
  79. package/dist/tools/codebase_search/core.cjs.map +1 -1
  80. package/dist/tools/codebase_search/core.js +3 -3
  81. package/dist/tools/codebase_search/index.cjs +1 -1
  82. package/dist/tools/codebase_search/index.cjs.map +1 -1
  83. package/dist/tools/codebase_search/index.js +6 -6
  84. package/dist/tools/codebase_search/openai.cjs +1 -1
  85. package/dist/tools/codebase_search/openai.cjs.map +1 -1
  86. package/dist/tools/codebase_search/openai.js +4 -4
  87. package/dist/tools/codebase_search/vercel.cjs +1 -1
  88. package/dist/tools/codebase_search/vercel.cjs.map +1 -1
  89. package/dist/tools/codebase_search/vercel.js +4 -4
  90. package/dist/tools/compact/core.cjs +1 -1
  91. package/dist/tools/compact/core.cjs.map +1 -1
  92. package/dist/tools/compact/core.js +1 -1
  93. package/dist/tools/compact/index.cjs +50 -3
  94. package/dist/tools/compact/index.cjs.map +1 -1
  95. package/dist/tools/compact/index.d.ts +10 -0
  96. package/dist/tools/compact/index.js +6 -2
  97. package/dist/tools/fastapply/anthropic.cjs +1 -1
  98. package/dist/tools/fastapply/anthropic.cjs.map +1 -1
  99. package/dist/tools/fastapply/anthropic.js +4 -4
  100. package/dist/tools/fastapply/apply.cjs +1 -1
  101. package/dist/tools/fastapply/apply.cjs.map +1 -1
  102. package/dist/tools/fastapply/apply.d.ts +1 -1
  103. package/dist/tools/fastapply/apply.js +2 -2
  104. package/dist/tools/fastapply/core.cjs +1 -1
  105. package/dist/tools/fastapply/core.cjs.map +1 -1
  106. package/dist/tools/fastapply/core.js +3 -3
  107. package/dist/tools/fastapply/index.cjs +1 -1
  108. package/dist/tools/fastapply/index.cjs.map +1 -1
  109. package/dist/tools/fastapply/index.js +6 -6
  110. package/dist/tools/fastapply/openai.cjs +1 -1
  111. package/dist/tools/fastapply/openai.cjs.map +1 -1
  112. package/dist/tools/fastapply/openai.js +4 -4
  113. package/dist/tools/fastapply/types.cjs.map +1 -1
  114. package/dist/tools/fastapply/types.d.ts +1 -1
  115. package/dist/tools/fastapply/vercel.cjs +1 -1
  116. package/dist/tools/fastapply/vercel.cjs.map +1 -1
  117. package/dist/tools/fastapply/vercel.js +4 -4
  118. package/dist/tools/index.cjs +1 -1
  119. package/dist/tools/index.cjs.map +1 -1
  120. package/dist/tools/index.js +6 -6
  121. package/dist/tools/utils/resilience.cjs +1 -1
  122. package/dist/tools/utils/resilience.cjs.map +1 -1
  123. package/dist/tools/utils/resilience.js +2 -2
  124. package/dist/tools/warp_grep/agent/runner.cjs +1 -1
  125. package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
  126. package/dist/tools/warp_grep/agent/runner.js +2 -2
  127. package/dist/tools/warp_grep/anthropic.cjs +138 -15
  128. package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
  129. package/dist/tools/warp_grep/anthropic.js +6 -4
  130. package/dist/tools/warp_grep/client.cjs +138 -15
  131. package/dist/tools/warp_grep/client.cjs.map +1 -1
  132. package/dist/tools/warp_grep/client.js +5 -3
  133. package/dist/tools/warp_grep/gemini.cjs +138 -15
  134. package/dist/tools/warp_grep/gemini.cjs.map +1 -1
  135. package/dist/tools/warp_grep/gemini.js +5 -3
  136. package/dist/tools/warp_grep/gemini.js.map +1 -1
  137. package/dist/tools/warp_grep/index.cjs +138 -15
  138. package/dist/tools/warp_grep/index.cjs.map +1 -1
  139. package/dist/tools/warp_grep/index.js +5 -3
  140. package/dist/tools/warp_grep/openai.cjs +138 -15
  141. package/dist/tools/warp_grep/openai.cjs.map +1 -1
  142. package/dist/tools/warp_grep/openai.js +6 -4
  143. package/dist/tools/warp_grep/vercel.cjs +138 -15
  144. package/dist/tools/warp_grep/vercel.cjs.map +1 -1
  145. package/dist/tools/warp_grep/vercel.js +6 -4
  146. package/dist/version.cjs +1 -1
  147. package/dist/version.cjs.map +1 -1
  148. package/dist/version.js +1 -1
  149. package/package.json +1 -1
  150. package/dist/chunk-AGFVQOGJ.js.map +0 -1
  151. package/dist/chunk-DOWJVFKI.js.map +0 -1
  152. /package/dist/{chunk-WKHAZ732.js.map → chunk-2WAHX6I2.js.map} +0 -0
  153. /package/dist/{chunk-ZFYFLNRE.js.map → chunk-3BTUUH23.js.map} +0 -0
  154. /package/dist/{chunk-75C4DV27.js.map → chunk-4R6F66B7.js.map} +0 -0
  155. /package/dist/{chunk-SVLY35WI.js.map → chunk-5IKDEESU.js.map} +0 -0
  156. /package/dist/{chunk-YLWVLRWH.js.map → chunk-A6T6E636.js.map} +0 -0
  157. /package/dist/{chunk-UAGEVTXM.js.map → chunk-D5UUKDKL.js.map} +0 -0
  158. /package/dist/{chunk-R5IYAFFN.js.map → chunk-FOKMTUWC.js.map} +0 -0
  159. /package/dist/{chunk-P7USBFIJ.js.map → chunk-J43SJUCO.js.map} +0 -0
  160. /package/dist/{chunk-PO6IPUDB.js.map → chunk-KRRO7FF2.js.map} +0 -0
  161. /package/dist/{chunk-PIBNTOS7.js.map → chunk-LK4C3NYX.js.map} +0 -0
  162. /package/dist/{chunk-OLL7QI3Y.js.map → chunk-MTRH7FMN.js.map} +0 -0
  163. /package/dist/{chunk-I6CWGOEL.js.map → chunk-N4KLUOXK.js.map} +0 -0
  164. /package/dist/{chunk-U253YYNH.js.map → chunk-P57SFOLD.js.map} +0 -0
  165. /package/dist/{chunk-BN6IXTDU.js.map → chunk-PRHEWGWC.js.map} +0 -0
  166. /package/dist/{chunk-ZHRXNOXP.js.map → chunk-Q77CT3RI.js.map} +0 -0
  167. /package/dist/{chunk-G7FGC7EQ.js.map → chunk-TAGDMT3K.js.map} +0 -0
  168. /package/dist/{chunk-KXN4YMCP.js.map → chunk-UDI5U6QV.js.map} +0 -0
  169. /package/dist/{chunk-Q72OV4VF.js.map → chunk-VK76R3IN.js.map} +0 -0
  170. /package/dist/{chunk-55ESIZID.js.map → chunk-Y5O3A7SU.js.map} +0 -0
  171. /package/dist/{chunk-LYL2MWM6.js.map → chunk-YKBVE3CE.js.map} +0 -0
  172. /package/dist/{chunk-WU2325QJ.js.map → chunk-ZHKANLAQ.js.map} +0 -0
  173. /package/dist/{chunk-L7EVPMOK.js.map → chunk-ZSA3NL5T.js.map} +0 -0
@@ -27,12 +27,12 @@ import {
27
27
  executeWarpGrep,
28
28
  formatGitHubReadFileResult,
29
29
  formatResult
30
- } from "../../chunk-DOWJVFKI.js";
30
+ } from "../../chunk-WQU6QXSU.js";
31
31
  import "../../chunk-63VHBANJ.js";
32
32
  import {
33
33
  runWarpGrep,
34
34
  runWarpGrepStreaming
35
- } from "../../chunk-LYL2MWM6.js";
35
+ } from "../../chunk-YKBVE3CE.js";
36
36
  import {
37
37
  createCodeStorageHttpCommands
38
38
  } from "../../chunk-GVGJIXV2.js";
@@ -48,7 +48,9 @@ import {
48
48
  } from "../../chunk-VNAGVCSP.js";
49
49
  import "../../chunk-CMSHXALI.js";
50
50
  import "../../chunk-I3J46TSB.js";
51
- import "../../chunk-3ZR5RSJQ.js";
51
+ import "../../chunk-GLQWEINZ.js";
52
+ import "../../chunk-SCVWDNQP.js";
53
+ import "../../chunk-3XO33KPS.js";
52
54
  import "../../chunk-PZ5AY32C.js";
53
55
  export {
54
56
  GITHUB_READ_FILE_DESCRIPTION,
@@ -939,7 +939,7 @@ var import_openai = __toESM(require("openai"), 1);
939
939
  // package.json
940
940
  var package_default = {
941
941
  name: "@morphllm/morphsdk",
942
- version: "0.2.152",
942
+ version: "0.2.154",
943
943
  description: "TypeScript SDK and CLI for Morph Fast Apply integration",
944
944
  type: "module",
945
945
  main: "./dist/index.cjs",
@@ -1805,6 +1805,131 @@ function parseGitHubUrl(input) {
1805
1805
  );
1806
1806
  }
1807
1807
 
1808
+ // tools/compact/core.ts
1809
+ var DEFAULT_API_URL2 = "https://api.morphllm.com";
1810
+ var DEFAULT_TIMEOUT = 12e4;
1811
+ var CompactClient = class {
1812
+ config;
1813
+ constructor(config = {}) {
1814
+ this.config = {
1815
+ ...config,
1816
+ morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL2,
1817
+ timeout: config.timeout ?? DEFAULT_TIMEOUT
1818
+ };
1819
+ }
1820
+ /**
1821
+ * Compact messages or text via /v1/compact.
1822
+ * Returns per-message `compacted_line_ranges` showing which lines were removed.
1823
+ *
1824
+ * @example
1825
+ * ```typescript
1826
+ * const client = new CompactClient({ morphApiKey: 'sk-...' });
1827
+ * const result = await client.compact({
1828
+ * input: codeFile,
1829
+ * query: "authentication",
1830
+ * compressionRatio: 0.5,
1831
+ * });
1832
+ * console.log(result.output);
1833
+ * ```
1834
+ */
1835
+ async compact(input) {
1836
+ const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
1837
+ const debug = this.config.debug || false;
1838
+ if (!apiKey) {
1839
+ throw new Error(
1840
+ "Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
1841
+ );
1842
+ }
1843
+ const url = `${this.config.morphApiUrl}/v1/compact`;
1844
+ if (debug) {
1845
+ console.log(`[Compact] Calling ${url}`);
1846
+ }
1847
+ const body = {
1848
+ compression_ratio: input.compressionRatio ?? 0.5,
1849
+ preserve_recent: input.preserveRecent ?? 2,
1850
+ model: input.model ?? "morph-compactor",
1851
+ include_line_ranges: input.includeLineRanges ?? true,
1852
+ include_markers: input.includeMarkers ?? true
1853
+ };
1854
+ if (input.query !== void 0) {
1855
+ body.query = input.query;
1856
+ }
1857
+ if (input.messages) {
1858
+ body.messages = input.messages;
1859
+ } else if (typeof input.input === "string") {
1860
+ body.input = input.input;
1861
+ } else if (Array.isArray(input.input)) {
1862
+ body.messages = input.input;
1863
+ } else {
1864
+ throw new Error("Either 'input' or 'messages' must be provided");
1865
+ }
1866
+ const startTime = Date.now();
1867
+ const response = await fetch(url, {
1868
+ method: "POST",
1869
+ headers: {
1870
+ "Authorization": `Bearer ${apiKey}`,
1871
+ "Content-Type": "application/json"
1872
+ },
1873
+ body: JSON.stringify(body),
1874
+ signal: AbortSignal.timeout(this.config.timeout)
1875
+ });
1876
+ if (!response.ok) {
1877
+ const text = await response.text();
1878
+ throw new Error(`Compact API error ${response.status}: ${text}`);
1879
+ }
1880
+ const data = await response.json();
1881
+ if (debug) {
1882
+ console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
1883
+ }
1884
+ return data;
1885
+ }
1886
+ };
1887
+
1888
+ // tools/compact/utils.ts
1889
+ async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
1890
+ const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
1891
+ const estimatedTokens = totalLength / 3;
1892
+ if (estimatedTokens <= maxTokens) {
1893
+ return files;
1894
+ }
1895
+ let compressionRatio = maxTokens / estimatedTokens;
1896
+ compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
1897
+ const client = new CompactClient({
1898
+ morphApiKey: apiKey,
1899
+ morphApiUrl: apiUrl
1900
+ });
1901
+ const results = [];
1902
+ const inProgress = /* @__PURE__ */ new Set();
1903
+ for (const file of files) {
1904
+ if (file.content.length < 500) {
1905
+ results.push({ path: file.path, content: file.content });
1906
+ continue;
1907
+ }
1908
+ const task = async () => {
1909
+ try {
1910
+ const result = await client.compact({
1911
+ input: file.content,
1912
+ query,
1913
+ compressionRatio,
1914
+ preserveRecent: 0
1915
+ });
1916
+ results.push({ path: file.path, content: result.output });
1917
+ } catch (error) {
1918
+ console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
1919
+ results.push({ path: file.path, content: file.content });
1920
+ }
1921
+ };
1922
+ const promise = task().finally(() => inProgress.delete(promise));
1923
+ inProgress.add(promise);
1924
+ if (inProgress.size >= maxConcurrency) {
1925
+ await Promise.race(inProgress);
1926
+ }
1927
+ }
1928
+ await Promise.all(inProgress);
1929
+ const orderMap = new Map(files.map((f, i) => [f.path, i]));
1930
+ return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
1931
+ }
1932
+
1808
1933
  // tools/warp_grep/client.ts
1809
1934
  var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
1810
1935
  async function getLocalProvider(repoRoot, excludes, allowNames) {
@@ -1927,20 +2052,9 @@ async function executeToolCall(input, config) {
1927
2052
  timeout: config.timeout,
1928
2053
  search_type: config.search_type
1929
2054
  });
1930
- const finish = result.finish;
1931
- if (result.terminationReason !== "completed" || !finish?.metadata) {
1932
- const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
1933
- console.error(`[warp_grep] executeToolCall failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
1934
- return { success: false, error: `Search did not complete: ${errorDetails}` };
1935
- }
1936
- const contexts = (finish.resolved ?? []).map((r) => ({
1937
- file: r.path,
1938
- content: r.content,
1939
- lines: r.ranges
1940
- }));
1941
- return { success: true, contexts, summary: finish.payload };
2055
+ return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
1942
2056
  }
1943
- function processAgentResult(result) {
2057
+ async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
1944
2058
  const finish = result.finish;
1945
2059
  if (result.terminationReason !== "completed" || !finish?.metadata) {
1946
2060
  const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
@@ -1952,6 +2066,15 @@ function processAgentResult(result) {
1952
2066
  content: r.content,
1953
2067
  lines: r.ranges
1954
2068
  }));
2069
+ try {
2070
+ const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
2071
+ const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
2072
+ for (let i = 0; i < contexts.length; i++) {
2073
+ contexts[i].content = compacted[i].content;
2074
+ }
2075
+ } catch (error) {
2076
+ console.error(`[warp_grep] Failed to compact result contexts:`, error);
2077
+ }
1955
2078
  return { success: true, contexts, summary: finish.payload };
1956
2079
  }
1957
2080
  async function* executeToolCallStreaming(input, config) {
@@ -1980,7 +2103,7 @@ async function* executeToolCallStreaming(input, config) {
1980
2103
  }
1981
2104
  yield value;
1982
2105
  }
1983
- return processAgentResult(agentResult);
2106
+ return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
1984
2107
  }
1985
2108
  async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
1986
2109
  const branches = branch ? [branch] : ["HEAD"];