@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
|
@@ -4,13 +4,16 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
runWarpGrep,
|
|
6
6
|
runWarpGrepStreaming
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-YKBVE3CE.js";
|
|
8
8
|
import {
|
|
9
9
|
createCodeStorageHttpCommands
|
|
10
10
|
} from "./chunk-GVGJIXV2.js";
|
|
11
11
|
import {
|
|
12
12
|
RemoteCommandsProvider
|
|
13
13
|
} from "./chunk-B3AKP3RA.js";
|
|
14
|
+
import {
|
|
15
|
+
compactFileContexts
|
|
16
|
+
} from "./chunk-GLQWEINZ.js";
|
|
14
17
|
|
|
15
18
|
// tools/warp_grep/client.ts
|
|
16
19
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
@@ -141,20 +144,9 @@ async function executeToolCall(input, config) {
|
|
|
141
144
|
timeout: config.timeout,
|
|
142
145
|
search_type: config.search_type
|
|
143
146
|
});
|
|
144
|
-
|
|
145
|
-
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
146
|
-
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
147
|
-
console.error(`[warp_grep] executeToolCall failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
|
|
148
|
-
return { success: false, error: `Search did not complete: ${errorDetails}` };
|
|
149
|
-
}
|
|
150
|
-
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
151
|
-
file: r.path,
|
|
152
|
-
content: r.content,
|
|
153
|
-
lines: r.ranges
|
|
154
|
-
}));
|
|
155
|
-
return { success: true, contexts, summary: finish.payload };
|
|
147
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
156
148
|
}
|
|
157
|
-
function processAgentResult(result) {
|
|
149
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
158
150
|
const finish = result.finish;
|
|
159
151
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
160
152
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -166,6 +158,15 @@ function processAgentResult(result) {
|
|
|
166
158
|
content: r.content,
|
|
167
159
|
lines: r.ranges
|
|
168
160
|
}));
|
|
161
|
+
try {
|
|
162
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
163
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
164
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
165
|
+
contexts[i].content = compacted[i].content;
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
169
|
+
}
|
|
169
170
|
return { success: true, contexts, summary: finish.payload };
|
|
170
171
|
}
|
|
171
172
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -194,7 +195,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
194
195
|
}
|
|
195
196
|
yield value;
|
|
196
197
|
}
|
|
197
|
-
return processAgentResult(agentResult);
|
|
198
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
198
199
|
}
|
|
199
200
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
200
201
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -289,4 +290,4 @@ export {
|
|
|
289
290
|
formatGitHubReadFileResult,
|
|
290
291
|
formatResult
|
|
291
292
|
};
|
|
292
|
-
//# sourceMappingURL=chunk-
|
|
293
|
+
//# sourceMappingURL=chunk-WQU6QXSU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../tools/warp_grep/client.ts"],"sourcesContent":["/**\n * WarpGrep client for programmatic code search\n */\n\nimport { runWarpGrep, runWarpGrepStreaming } from './agent/runner.js';\nimport { RemoteCommandsProvider } from './providers/remote.js';\nimport type { WarpGrepProvider } from './providers/types.js';\nimport type { AgentRunResult, WarpGrepStep } from './agent/types.js';\nimport type {\n WarpGrepClientConfig,\n WarpGrepInput,\n WarpGrepResult,\n WarpGrepContext,\n WarpGrepToolConfig,\n GitHubSearchInput,\n GitHubReadFileInput,\n GitHubReadFileResult,\n RemoteCommands,\n} from './types.js';\nimport { createCodeStorageHttpCommands } from './providers/code_storage_http.js';\nimport { parseGitHubUrl } from './utils/github.js';\nimport { compactFileContexts } from '../compact/utils.js';\n\nconst DEFAULT_CODE_SEARCH_URL = 'https://morphllm.com';\n\n/**\n * Lazy-load LocalRipgrepProvider to avoid importing Node.js-specific\n * modules (child_process, fs) in edge environments like Cloudflare Workers.\n * Only loads when actually needed (i.e., when no remoteCommands or provider is specified).\n */\nasync function getLocalProvider(repoRoot: string, excludes?: string[], allowNames?: string[]): Promise<WarpGrepProvider> {\n const { LocalRipgrepProvider } = await import('./providers/local.js');\n const opts = allowNames?.length ? { allowNames } : undefined;\n return new LocalRipgrepProvider(repoRoot, excludes, opts);\n}\n\n/**\n * WarpGrep client for programmatic code search\n * \n * @example\n * ```typescript\n * import { WarpGrepClient } from '@morphllm/morphsdk';\n * \n * const client = new WarpGrepClient({ morphApiKey: process.env.MORPH_API_KEY });\n * \n * // Simple usage - defaults to LocalRipgrepProvider\n * const result = await client.execute({\n * searchTerm: 'Find authentication middleware',\n * repoRoot: '.'\n * });\n *\n * // With custom excludes\n * const result = await client.execute({\n * searchTerm: 'Find database models',\n * repoRoot: '.',\n * excludes: ['node_modules', '.git', 'dist']\n * });\n * ```\n */\nexport class WarpGrepClient {\n private config: WarpGrepClientConfig;\n\n constructor(config: WarpGrepClientConfig = {}) {\n this.config = { ...config };\n }\n\n /**\n * Execute a code search\n *\n * @param input - Search parameters including searchTerm, repoRoot, and optional provider\n * @returns Search results with relevant code contexts, or an AsyncGenerator if streamSteps is true\n *\n * @example\n * ```typescript\n * // Standard execution\n * const result = await client.execute({\n * searchTerm: 'Find authentication middleware',\n * repoRoot: '.'\n * });\n *\n * if (result.success) {\n * for (const ctx of result.contexts) {\n * console.log(`File: ${ctx.file}`);\n * console.log(ctx.content);\n * }\n * }\n *\n * // Streaming execution\n * const stream = client.execute({\n * searchTerm: 'Find auth middleware',\n * repoRoot: '.',\n * streamSteps: true\n * });\n *\n * for await (const step of stream) {\n * console.log(`Turn ${step.turn}:`, step.toolCalls);\n * }\n * ```\n */\n execute(input: WarpGrepInput & { streamSteps: true }): AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined>;\n execute(input: WarpGrepInput & { streamSteps?: false | undefined }): Promise<WarpGrepResult>;\n execute(input: WarpGrepInput): Promise<WarpGrepResult> | AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined> {\n const toolConfig: WarpGrepToolConfig = {\n repoRoot: input.repoRoot,\n remoteCommands: input.remoteCommands,\n provider: input.provider,\n excludes: input.excludes,\n includes: input.includes,\n debug: input.debug ?? this.config.debug,\n morphApiKey: this.config.morphApiKey,\n morphApiUrl: this.config.morphApiUrl,\n retryConfig: this.config.retryConfig,\n timeout: this.config.timeout,\n search_type: input.search_type,\n };\n\n if (input.streamSteps) {\n return executeToolCallStreaming({ search_term: input.searchTerm }, toolConfig);\n }\n return executeToolCall({ search_term: input.searchTerm }, toolConfig);\n }\n\n /**\n * Search a public GitHub repository\n *\n * @example\n * ```typescript\n * // Simple usage\n * const result = await client.searchGitHub({\n * searchTerm: 'Find authentication middleware',\n * github: 'vercel/next.js',\n * });\n *\n * // With streaming\n * const stream = client.searchGitHub({\n * searchTerm: 'Find auth middleware',\n * github: 'https://github.com/vercel/next.js',\n * streamSteps: true,\n * });\n * for await (const step of stream) {\n * console.log(`Turn ${step.turn}:`, step.toolCalls);\n * }\n * ```\n */\n searchGitHub(input: GitHubSearchInput & { streamSteps: true }): AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined>;\n searchGitHub(input: GitHubSearchInput & { streamSteps?: false | undefined }): Promise<WarpGrepResult>;\n searchGitHub(input: GitHubSearchInput): Promise<WarpGrepResult> | AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined> {\n if (input.streamSteps) {\n return this._searchGitHubStreaming(input);\n }\n return this._searchGitHubAsync(input);\n }\n\n /**\n * Read a single file from a public GitHub repository\n *\n * @example\n * ```typescript\n * const result = await client.readGitHubFile({\n * github: 'vercel/next.js',\n * path: 'src/server/app-render/index.tsx',\n * startLine: 1,\n * endLine: 50,\n * });\n * if (result.success) console.log(result.content);\n * ```\n */\n async readGitHubFile(input: GitHubReadFileInput): Promise<GitHubReadFileResult> {\n return executeGitHubReadFile(input, { timeout: this.config.timeout });\n }\n\n private async _resolveGitHubRepo(input: GitHubSearchInput): Promise<{ repo: string; remoteCommands: RemoteCommands }> {\n const { owner, repo } = parseGitHubUrl(input.github);\n const baseUrl = this.config.codeSearchUrl || DEFAULT_CODE_SEARCH_URL;\n const importRes = await fetch(`${baseUrl}/api/code-search/get-or-create?url=${encodeURIComponent(`${owner}/${repo}`)}`);\n if (!importRes.ok) {\n const text = await importRes.text().catch(() => importRes.statusText);\n throw new Error(`Failed to import repo ${owner}/${repo}: ${text}`);\n }\n const { repoId, defaultBranch } = await importRes.json();\n return {\n repo,\n remoteCommands: createCodeStorageHttpCommands({ baseUrl, repoId, branch: input.branch || defaultBranch }),\n };\n }\n\n private async _searchGitHubAsync(input: GitHubSearchInput): Promise<WarpGrepResult> {\n try {\n const { remoteCommands } = await this._resolveGitHubRepo(input);\n return this.execute({\n searchTerm: input.searchTerm,\n repoRoot: '.',\n remoteCommands,\n });\n } catch (error) {\n return { success: false, error: error instanceof Error ? error.message : String(error) };\n }\n }\n\n private async *_searchGitHubStreaming(input: GitHubSearchInput): AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined> {\n let remoteCommands: RemoteCommands;\n try {\n ({ remoteCommands } = await this._resolveGitHubRepo(input));\n } catch (error) {\n return { success: false, error: error instanceof Error ? error.message : String(error) };\n }\n\n const generator = this.execute({\n searchTerm: input.searchTerm,\n repoRoot: '.',\n remoteCommands,\n streamSteps: true,\n });\n\n let result: WarpGrepResult;\n for (;;) {\n const { value, done } = await generator.next();\n if (done) {\n result = value;\n break;\n }\n yield value;\n }\n return result;\n }\n}\n\n/**\n * Execute a warp grep search directly\n *\n * @param input - Search parameters\n * @param config - Optional client configuration\n * @returns Search results, or an AsyncGenerator if streamSteps is true\n *\n * @example\n * ```typescript\n * import { executeWarpGrep } from '@morphllm/morphsdk/tools/warp-grep';\n *\n * const result = await executeWarpGrep({\n * searchTerm: 'Find authentication middleware',\n * repoRoot: '.'\n * });\n *\n * // Streaming\n * const stream = executeWarpGrep({\n * searchTerm: 'Find auth',\n * repoRoot: '.',\n * streamSteps: true\n * });\n * for await (const step of stream) {\n * console.log(step.turn, step.toolCalls);\n * }\n * ```\n */\nexport function executeWarpGrep(\n input: WarpGrepInput & { streamSteps: true },\n config?: WarpGrepClientConfig\n): AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined>;\nexport function executeWarpGrep(\n input: WarpGrepInput & { streamSteps?: false | undefined },\n config?: WarpGrepClientConfig\n): Promise<WarpGrepResult>;\nexport function executeWarpGrep(\n input: WarpGrepInput,\n config?: WarpGrepClientConfig\n): Promise<WarpGrepResult> | AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined> {\n const client = new WarpGrepClient(config);\n if (input.streamSteps) {\n return client.execute({ ...input, streamSteps: true });\n }\n return client.execute({ ...input, streamSteps: false });\n}\n\nexport async function executeToolCall(\n input: { search_term: string } | string,\n config: WarpGrepToolConfig\n): Promise<WarpGrepResult> {\n const parsed = typeof input === 'string' ? JSON.parse(input) : input;\n\n // Priority: remoteCommands > provider > LocalRipgrepProvider (lazy-loaded for edge compatibility)\n const allowNames = config.search_type === 'node_modules' ? ['node_modules'] : undefined;\n const provider = config.remoteCommands\n ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands)\n : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);\n\n const result = await runWarpGrep({\n searchTerm: parsed.search_term,\n repoRoot: config.repoRoot,\n provider,\n excludes: config.excludes,\n includes: config.includes,\n debug: config.debug ?? false,\n morphApiKey: config.morphApiKey,\n morphApiUrl: config.morphApiUrl,\n retryConfig: config.retryConfig,\n timeout: config.timeout,\n search_type: config.search_type,\n });\n\n return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);\n}\n\n/**\n * Helper to process AgentRunResult into WarpGrepResult\n */\nasync function processAgentResult(\n result: AgentRunResult,\n searchTerm: string,\n apiKey?: string,\n apiUrl?: string\n): Promise<WarpGrepResult> {\n const finish = result.finish;\n if (result.terminationReason !== 'completed' || !finish?.metadata) {\n const errorDetails = result.errors?.map(e => e.message).join('; ') || 'unknown reason';\n console.error(`[warp_grep] processAgentResult failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);\n return { success: false, error: `Search did not complete: ${errorDetails}` };\n }\n\n const contexts: WarpGrepContext[] = (finish.resolved ?? []).map(r => ({\n file: r.path,\n content: r.content,\n lines: r.ranges,\n }));\n\n try {\n const compactable = contexts.map(c => ({ path: c.file, content: c.content }));\n const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);\n for (let i = 0; i < contexts.length; i++) {\n contexts[i].content = compacted[i].content;\n }\n } catch (error) {\n console.error(`[warp_grep] Failed to compact result contexts:`, error);\n }\n\n return { success: true, contexts, summary: finish.payload };\n}\n\n/**\n * Streaming version of executeToolCall that yields WarpGrepStep for each turn.\n */\nexport async function* executeToolCallStreaming(\n input: { search_term: string } | string,\n config: WarpGrepToolConfig\n): AsyncGenerator<WarpGrepStep, WarpGrepResult, undefined> {\n const parsed = typeof input === 'string' ? JSON.parse(input) : input;\n\n // Priority: remoteCommands > provider > LocalRipgrepProvider (lazy-loaded for edge compatibility)\n const allowNames = config.search_type === 'node_modules' ? ['node_modules'] : undefined;\n const provider = config.remoteCommands\n ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands)\n : config.provider ?? await getLocalProvider(config.repoRoot, config.excludes, allowNames);\n\n const generator = runWarpGrepStreaming({\n searchTerm: parsed.search_term,\n repoRoot: config.repoRoot,\n provider,\n excludes: config.excludes,\n includes: config.includes,\n debug: config.debug ?? false,\n morphApiKey: config.morphApiKey,\n morphApiUrl: config.morphApiUrl,\n retryConfig: config.retryConfig,\n timeout: config.timeout,\n search_type: config.search_type,\n });\n\n // Forward all yielded steps\n let agentResult: AgentRunResult;\n for (;;) {\n const { value, done } = await generator.next();\n if (done) {\n agentResult = value;\n break;\n }\n yield value;\n }\n\n return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);\n}\n\n/**\n * Fetch raw file content from a public GitHub repository.\n * Tries the given branch first, then falls back to main/master/develop.\n */\nasync function fetchRawGitHubFile(\n owner: string,\n repo: string,\n filePath: string,\n branch?: string,\n timeout?: number,\n): Promise<{ content: string; branch: string }> {\n const branches = branch ? [branch] : ['HEAD'];\n const fallbacks = ['main', 'master', 'develop'];\n\n const fetchWithTimeout = (url: string) =>\n timeout ? fetch(url, { signal: AbortSignal.timeout(timeout) }) : fetch(url);\n\n for (const b of branches) {\n const url = `https://raw.githubusercontent.com/${owner}/${repo}/${b}/${filePath}`;\n const res = await fetchWithTimeout(url);\n if (res.ok) return { content: await res.text(), branch: b };\n }\n\n for (const fb of fallbacks) {\n if (branch && fb === branch) continue;\n const url = `https://raw.githubusercontent.com/${owner}/${repo}/${fb}/${filePath}`;\n const res = await fetchWithTimeout(url);\n if (res.ok) return { content: await res.text(), branch: fb };\n }\n\n throw new Error(`File not found: ${owner}/${repo}/${filePath}`);\n}\n\n/**\n * Read a single file (or line range) from a public GitHub repository\n */\nexport async function executeGitHubReadFile(\n input: GitHubReadFileInput,\n config?: { timeout?: number },\n): Promise<GitHubReadFileResult> {\n try {\n const { owner, repo } = parseGitHubUrl(input.github);\n const { content: raw, branch } = await fetchRawGitHubFile(\n owner, repo, input.path, input.branch, config?.timeout,\n );\n\n const allLines = raw.split('\\n');\n const totalLines = allLines.length;\n const start = Math.max(1, input.startLine ?? 1);\n const end = Math.min(totalLines, input.endLine ?? totalLines);\n\n const selected = allLines.slice(start - 1, end);\n const padWidth = String(end).length;\n const numbered = selected\n .map((line, i) => `${String(start + i).padStart(padWidth)}|${line}`)\n .join('\\n');\n\n return {\n success: true,\n content: numbered,\n path: input.path,\n github: `${owner}/${repo}`,\n branch,\n lineRange: [start, end],\n totalLines,\n };\n } catch (error) {\n return {\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n}\n\n/**\n * Format a GitHub read file result for display or tool responses\n */\nexport function formatGitHubReadFileResult(result: GitHubReadFileResult): string {\n if (!result.success) {\n return `Failed to read file: ${result.error}`;\n }\n\n const rangeStr = result.lineRange\n ? ` (lines ${result.lineRange[0]}-${result.lineRange[1]} of ${result.totalLines})`\n : '';\n\n return `File: ${result.github}/${result.path}${rangeStr}\\n\\n${result.content}`;\n}\n\n/**\n * Format warp grep results for display or tool responses\n * \n * @param result - The search result\n * @returns Formatted string representation\n */\nexport function formatResult(result: WarpGrepResult): string {\n if (!result.success) {\n return `Search failed: ${result.error}`;\n }\n\n if (!result.contexts || result.contexts.length === 0) {\n return 'No relevant code found. Try rephrasing your search term.';\n }\n\n const parts: string[] = [];\n parts.push(`Morph Fast Context subagent performed search on repository:\\n`);\n parts.push('Relevant context found:');\n\n for (const ctx of result.contexts) {\n const rangeStr = !ctx.lines || ctx.lines === '*'\n ? '*'\n : ctx.lines.map(([s, e]) => `${s}-${e}`).join(',');\n parts.push(`- ${ctx.file}:${rangeStr}`);\n }\n\n parts.push('\\nHere is the content of files:\\n');\n\n for (const ctx of result.contexts) {\n const rangeStr = !ctx.lines || ctx.lines === '*'\n ? ''\n : ` lines=\"${ctx.lines.map(([s, e]) => `${s}-${e}`).join(',')}\"`;\n parts.push(`<file path=\"${ctx.file}\"${rangeStr}>`);\n parts.push(ctx.content);\n parts.push('</file>\\n');\n }\n\n return parts.join('\\n');\n}\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAuBA,IAAM,0BAA0B;AAOhC,eAAe,iBAAiB,UAAkB,UAAqB,YAAkD;AACvH,QAAM,EAAE,qBAAqB,IAAI,MAAM,OAAO,sCAAsB;AACpE,QAAM,OAAO,YAAY,SAAS,EAAE,WAAW,IAAI;AACnD,SAAO,IAAI,qBAAqB,UAAU,UAAU,IAAI;AAC1D;AAyBO,IAAM,iBAAN,MAAqB;AAAA,EAClB;AAAA,EAER,YAAY,SAA+B,CAAC,GAAG;AAC7C,SAAK,SAAS,EAAE,GAAG,OAAO;AAAA,EAC5B;AAAA,EAqCA,QAAQ,OAAyG;AAC/G,UAAM,aAAiC;AAAA,MACrC,UAAU,MAAM;AAAA,MAChB,gBAAgB,MAAM;AAAA,MACtB,UAAU,MAAM;AAAA,MAChB,UAAU,MAAM;AAAA,MAChB,UAAU,MAAM;AAAA,MAChB,OAAO,MAAM,SAAS,KAAK,OAAO;AAAA,MAClC,aAAa,KAAK,OAAO;AAAA,MACzB,aAAa,KAAK,OAAO;AAAA,MACzB,aAAa,KAAK,OAAO;AAAA,MACzB,SAAS,KAAK,OAAO;AAAA,MACrB,aAAa,MAAM;AAAA,IACrB;AAEA,QAAI,MAAM,aAAa;AACrB,aAAO,yBAAyB,EAAE,aAAa,MAAM,WAAW,GAAG,UAAU;AAAA,IAC/E;AACA,WAAO,gBAAgB,EAAE,aAAa,MAAM,WAAW,GAAG,UAAU;AAAA,EACtE;AAAA,EA0BA,aAAa,OAA6G;AACxH,QAAI,MAAM,aAAa;AACrB,aAAO,KAAK,uBA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
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5IKDEESU.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
browserTool,
|
|
55
55
|
vercel_exports
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-Y5O3A7SU.js.map
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "./chunk-I3J46TSB.js";
|
|
21
21
|
import {
|
|
22
22
|
SDK_VERSION
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-3XO33KPS.js";
|
|
24
24
|
|
|
25
25
|
// tools/warp_grep/agent/runner.ts
|
|
26
26
|
import OpenAI from "openai";
|
|
@@ -398,4 +398,4 @@ export {
|
|
|
398
398
|
runWarpGrepStreaming,
|
|
399
399
|
runWarpGrep
|
|
400
400
|
};
|
|
401
|
-
//# sourceMappingURL=chunk-
|
|
401
|
+
//# sourceMappingURL=chunk-YKBVE3CE.js.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-63WE2C5R.js";
|
|
5
5
|
import {
|
|
6
6
|
executeEditFile
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-J43SJUCO.js";
|
|
8
8
|
import {
|
|
9
9
|
__export
|
|
10
10
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -91,4 +91,4 @@ export {
|
|
|
91
91
|
openai_default,
|
|
92
92
|
openai_exports
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-ZHKANLAQ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SDK_VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3XO33KPS.js";
|
|
4
4
|
|
|
5
5
|
// tools/utils/resilience.ts
|
|
6
6
|
var DEFAULT_RETRY_CONFIG = {
|
|
@@ -91,4 +91,4 @@ export {
|
|
|
91
91
|
withTimeout,
|
|
92
92
|
MorphError
|
|
93
93
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
94
|
+
//# sourceMappingURL=chunk-ZSA3NL5T.js.map
|
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.154",
|
|
40
40
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
41
41
|
type: "module",
|
|
42
42
|
main: "./dist/index.cjs",
|
|
@@ -3463,6 +3463,131 @@ function parseGitHubUrl(input) {
|
|
|
3463
3463
|
);
|
|
3464
3464
|
}
|
|
3465
3465
|
|
|
3466
|
+
// tools/compact/core.ts
|
|
3467
|
+
var DEFAULT_API_URL4 = "https://api.morphllm.com";
|
|
3468
|
+
var DEFAULT_TIMEOUT2 = 12e4;
|
|
3469
|
+
var CompactClient = class {
|
|
3470
|
+
config;
|
|
3471
|
+
constructor(config = {}) {
|
|
3472
|
+
this.config = {
|
|
3473
|
+
...config,
|
|
3474
|
+
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL4,
|
|
3475
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT2
|
|
3476
|
+
};
|
|
3477
|
+
}
|
|
3478
|
+
/**
|
|
3479
|
+
* Compact messages or text via /v1/compact.
|
|
3480
|
+
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
3481
|
+
*
|
|
3482
|
+
* @example
|
|
3483
|
+
* ```typescript
|
|
3484
|
+
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
3485
|
+
* const result = await client.compact({
|
|
3486
|
+
* input: codeFile,
|
|
3487
|
+
* query: "authentication",
|
|
3488
|
+
* compressionRatio: 0.5,
|
|
3489
|
+
* });
|
|
3490
|
+
* console.log(result.output);
|
|
3491
|
+
* ```
|
|
3492
|
+
*/
|
|
3493
|
+
async compact(input) {
|
|
3494
|
+
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
3495
|
+
const debug = this.config.debug || false;
|
|
3496
|
+
if (!apiKey) {
|
|
3497
|
+
throw new Error(
|
|
3498
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
3499
|
+
);
|
|
3500
|
+
}
|
|
3501
|
+
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
3502
|
+
if (debug) {
|
|
3503
|
+
console.log(`[Compact] Calling ${url}`);
|
|
3504
|
+
}
|
|
3505
|
+
const body = {
|
|
3506
|
+
compression_ratio: input.compressionRatio ?? 0.5,
|
|
3507
|
+
preserve_recent: input.preserveRecent ?? 2,
|
|
3508
|
+
model: input.model ?? "morph-compactor",
|
|
3509
|
+
include_line_ranges: input.includeLineRanges ?? true,
|
|
3510
|
+
include_markers: input.includeMarkers ?? true
|
|
3511
|
+
};
|
|
3512
|
+
if (input.query !== void 0) {
|
|
3513
|
+
body.query = input.query;
|
|
3514
|
+
}
|
|
3515
|
+
if (input.messages) {
|
|
3516
|
+
body.messages = input.messages;
|
|
3517
|
+
} else if (typeof input.input === "string") {
|
|
3518
|
+
body.input = input.input;
|
|
3519
|
+
} else if (Array.isArray(input.input)) {
|
|
3520
|
+
body.messages = input.input;
|
|
3521
|
+
} else {
|
|
3522
|
+
throw new Error("Either 'input' or 'messages' must be provided");
|
|
3523
|
+
}
|
|
3524
|
+
const startTime = Date.now();
|
|
3525
|
+
const response = await fetch(url, {
|
|
3526
|
+
method: "POST",
|
|
3527
|
+
headers: {
|
|
3528
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
3529
|
+
"Content-Type": "application/json"
|
|
3530
|
+
},
|
|
3531
|
+
body: JSON.stringify(body),
|
|
3532
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
3533
|
+
});
|
|
3534
|
+
if (!response.ok) {
|
|
3535
|
+
const text = await response.text();
|
|
3536
|
+
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
3537
|
+
}
|
|
3538
|
+
const data = await response.json();
|
|
3539
|
+
if (debug) {
|
|
3540
|
+
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
3541
|
+
}
|
|
3542
|
+
return data;
|
|
3543
|
+
}
|
|
3544
|
+
};
|
|
3545
|
+
|
|
3546
|
+
// tools/compact/utils.ts
|
|
3547
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
3548
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
3549
|
+
const estimatedTokens = totalLength / 3;
|
|
3550
|
+
if (estimatedTokens <= maxTokens) {
|
|
3551
|
+
return files;
|
|
3552
|
+
}
|
|
3553
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
3554
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
3555
|
+
const client = new CompactClient({
|
|
3556
|
+
morphApiKey: apiKey,
|
|
3557
|
+
morphApiUrl: apiUrl
|
|
3558
|
+
});
|
|
3559
|
+
const results = [];
|
|
3560
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
3561
|
+
for (const file of files) {
|
|
3562
|
+
if (file.content.length < 500) {
|
|
3563
|
+
results.push({ path: file.path, content: file.content });
|
|
3564
|
+
continue;
|
|
3565
|
+
}
|
|
3566
|
+
const task = async () => {
|
|
3567
|
+
try {
|
|
3568
|
+
const result = await client.compact({
|
|
3569
|
+
input: file.content,
|
|
3570
|
+
query,
|
|
3571
|
+
compressionRatio,
|
|
3572
|
+
preserveRecent: 0
|
|
3573
|
+
});
|
|
3574
|
+
results.push({ path: file.path, content: result.output });
|
|
3575
|
+
} catch (error) {
|
|
3576
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
3577
|
+
results.push({ path: file.path, content: file.content });
|
|
3578
|
+
}
|
|
3579
|
+
};
|
|
3580
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
3581
|
+
inProgress.add(promise);
|
|
3582
|
+
if (inProgress.size >= maxConcurrency) {
|
|
3583
|
+
await Promise.race(inProgress);
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
await Promise.all(inProgress);
|
|
3587
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
3588
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
3589
|
+
}
|
|
3590
|
+
|
|
3466
3591
|
// tools/warp_grep/client.ts
|
|
3467
3592
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
3468
3593
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
@@ -3585,20 +3710,9 @@ async function executeToolCall(input, config) {
|
|
|
3585
3710
|
timeout: config.timeout,
|
|
3586
3711
|
search_type: config.search_type
|
|
3587
3712
|
});
|
|
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 };
|
|
3713
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3600
3714
|
}
|
|
3601
|
-
function processAgentResult(result) {
|
|
3715
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
3602
3716
|
const finish = result.finish;
|
|
3603
3717
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
3604
3718
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -3610,6 +3724,15 @@ function processAgentResult(result) {
|
|
|
3610
3724
|
content: r.content,
|
|
3611
3725
|
lines: r.ranges
|
|
3612
3726
|
}));
|
|
3727
|
+
try {
|
|
3728
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
3729
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
3730
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
3731
|
+
contexts[i].content = compacted[i].content;
|
|
3732
|
+
}
|
|
3733
|
+
} catch (error) {
|
|
3734
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
3735
|
+
}
|
|
3613
3736
|
return { success: true, contexts, summary: finish.payload };
|
|
3614
3737
|
}
|
|
3615
3738
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -3638,7 +3761,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
3638
3761
|
}
|
|
3639
3762
|
yield value;
|
|
3640
3763
|
}
|
|
3641
|
-
return processAgentResult(agentResult);
|
|
3764
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
3642
3765
|
}
|
|
3643
3766
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
3644
3767
|
const branches = branch ? [branch] : ["HEAD"];
|
|
@@ -3746,7 +3869,7 @@ var PermissionError = class extends GitHubError {
|
|
|
3746
3869
|
|
|
3747
3870
|
// tools/github/core.ts
|
|
3748
3871
|
var DEFAULT_BASE_URL = "https://api.morphllm.com";
|
|
3749
|
-
var
|
|
3872
|
+
var DEFAULT_TIMEOUT3 = 3e4;
|
|
3750
3873
|
var GitHubClient = class {
|
|
3751
3874
|
apiKey;
|
|
3752
3875
|
baseUrl;
|
|
@@ -3777,7 +3900,7 @@ var GitHubClient = class {
|
|
|
3777
3900
|
constructor(config = {}) {
|
|
3778
3901
|
this.apiKey = config.apiKey || process.env.MORPH_API_KEY || "";
|
|
3779
3902
|
this.baseUrl = config.baseUrl || DEFAULT_BASE_URL;
|
|
3780
|
-
this.timeout = config.timeout ||
|
|
3903
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT3;
|
|
3781
3904
|
this.debug = config.debug || false;
|
|
3782
3905
|
this.defaultInstallationId = config.installationId;
|
|
3783
3906
|
if (!this.apiKey) {
|
|
@@ -4609,86 +4732,6 @@ var MorphGit = class {
|
|
|
4609
4732
|
var import_isomorphic_git2 = __toESM(require("isomorphic-git"), 1);
|
|
4610
4733
|
var import_node2 = __toESM(require("isomorphic-git/http/node"), 1);
|
|
4611
4734
|
|
|
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
4735
|
// modelrouter/core.ts
|
|
4693
4736
|
var DEFAULT_CONFIG3 = {
|
|
4694
4737
|
apiUrl: "https://api.morphllm.com",
|