@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.
- package/dist/{chunk-MJQNHIUZ.js → chunk-2WAHX6I2.js} +2 -2
- package/dist/{chunk-7AWNEVBE.js → chunk-3BTUUH23.js} +2 -2
- package/dist/{chunk-NO2FGIQ7.js → chunk-3XO33KPS.js} +2 -2
- package/dist/{chunk-NO2FGIQ7.js.map → chunk-3XO33KPS.js.map} +1 -1
- package/dist/{chunk-GAZCVVNY.js → chunk-4R6F66B7.js} +2 -2
- package/dist/{chunk-QFRDNJXM.js → chunk-5IKDEESU.js} +3 -3
- package/dist/{chunk-5D7DDSZQ.js → chunk-A6T6E636.js} +2 -2
- package/dist/{chunk-FWHQH6RG.js → chunk-D5UUKDKL.js} +2 -2
- package/dist/{chunk-YBVAKGFE.js → chunk-FOKMTUWC.js} +2 -2
- package/dist/chunk-GLQWEINZ.js +53 -0
- package/dist/chunk-GLQWEINZ.js.map +1 -0
- package/dist/{chunk-KM7RICB6.js → chunk-J43SJUCO.js} +1 -1
- package/dist/{chunk-UFPDHAZ2.js → chunk-KRRO7FF2.js} +2 -2
- package/dist/{chunk-WTMEO2YB.js → chunk-LK4C3NYX.js} +2 -2
- package/dist/{chunk-QMLGJK66.js → chunk-MTRH7FMN.js} +2 -2
- package/dist/{chunk-I3ZPXGMZ.js → chunk-N4KLUOXK.js} +2 -2
- package/dist/{chunk-GKBKSSUA.js → chunk-P57SFOLD.js} +2 -2
- package/dist/{chunk-QVWKDO76.js → chunk-PRHEWGWC.js} +20 -20
- package/dist/{chunk-77O2YF4B.js → chunk-Q77CT3RI.js} +2 -2
- package/dist/{chunk-ZAADJ3ER.js → chunk-QSATHLZJ.js} +2 -2
- package/dist/{chunk-AGFVQOGJ.js → chunk-SCVWDNQP.js} +2 -2
- package/dist/chunk-SCVWDNQP.js.map +1 -0
- package/dist/{chunk-JB4T3K5T.js → chunk-TAGDMT3K.js} +2 -2
- package/dist/{chunk-H6RMMTKF.js → chunk-UDI5U6QV.js} +2 -2
- package/dist/{chunk-7IQMKVT4.js → chunk-VK76R3IN.js} +2 -2
- package/dist/{chunk-MFKR5VVL.js → chunk-WQU6QXSU.js} +17 -16
- package/dist/chunk-WQU6QXSU.js.map +1 -0
- package/dist/{chunk-Q4DXGXXU.js → chunk-Y5O3A7SU.js} +2 -2
- package/dist/{chunk-6FRGRPUO.js → chunk-YKBVE3CE.js} +2 -2
- package/dist/{chunk-3VMW3UJY.js → chunk-ZHKANLAQ.js} +2 -2
- package/dist/{chunk-QDDT5L5Y.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.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/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-MFKR5VVL.js.map +0 -1
- /package/dist/{chunk-MJQNHIUZ.js.map → chunk-2WAHX6I2.js.map} +0 -0
- /package/dist/{chunk-7AWNEVBE.js.map → chunk-3BTUUH23.js.map} +0 -0
- /package/dist/{chunk-GAZCVVNY.js.map → chunk-4R6F66B7.js.map} +0 -0
- /package/dist/{chunk-QFRDNJXM.js.map → chunk-5IKDEESU.js.map} +0 -0
- /package/dist/{chunk-5D7DDSZQ.js.map → chunk-A6T6E636.js.map} +0 -0
- /package/dist/{chunk-FWHQH6RG.js.map → chunk-D5UUKDKL.js.map} +0 -0
- /package/dist/{chunk-YBVAKGFE.js.map → chunk-FOKMTUWC.js.map} +0 -0
- /package/dist/{chunk-KM7RICB6.js.map → chunk-J43SJUCO.js.map} +0 -0
- /package/dist/{chunk-UFPDHAZ2.js.map → chunk-KRRO7FF2.js.map} +0 -0
- /package/dist/{chunk-WTMEO2YB.js.map → chunk-LK4C3NYX.js.map} +0 -0
- /package/dist/{chunk-QMLGJK66.js.map → chunk-MTRH7FMN.js.map} +0 -0
- /package/dist/{chunk-I3ZPXGMZ.js.map → chunk-N4KLUOXK.js.map} +0 -0
- /package/dist/{chunk-GKBKSSUA.js.map → chunk-P57SFOLD.js.map} +0 -0
- /package/dist/{chunk-QVWKDO76.js.map → chunk-PRHEWGWC.js.map} +0 -0
- /package/dist/{chunk-77O2YF4B.js.map → chunk-Q77CT3RI.js.map} +0 -0
- /package/dist/{chunk-ZAADJ3ER.js.map → chunk-QSATHLZJ.js.map} +0 -0
- /package/dist/{chunk-JB4T3K5T.js.map → chunk-TAGDMT3K.js.map} +0 -0
- /package/dist/{chunk-H6RMMTKF.js.map → chunk-UDI5U6QV.js.map} +0 -0
- /package/dist/{chunk-7IQMKVT4.js.map → chunk-VK76R3IN.js.map} +0 -0
- /package/dist/{chunk-Q4DXGXXU.js.map → chunk-Y5O3A7SU.js.map} +0 -0
- /package/dist/{chunk-6FRGRPUO.js.map → chunk-YKBVE3CE.js.map} +0 -0
- /package/dist/{chunk-3VMW3UJY.js.map → chunk-ZHKANLAQ.js.map} +0 -0
- /package/dist/{chunk-QDDT5L5Y.js.map → chunk-ZSA3NL5T.js.map} +0 -0
|
@@ -12,15 +12,17 @@ import {
|
|
|
12
12
|
executeToolCall,
|
|
13
13
|
formatGitHubReadFileResult,
|
|
14
14
|
formatResult
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-WQU6QXSU.js";
|
|
16
16
|
import "../../chunk-63VHBANJ.js";
|
|
17
|
-
import "../../chunk-
|
|
17
|
+
import "../../chunk-YKBVE3CE.js";
|
|
18
18
|
import "../../chunk-GVGJIXV2.js";
|
|
19
19
|
import "../../chunk-B3AKP3RA.js";
|
|
20
20
|
import "../../chunk-VNAGVCSP.js";
|
|
21
21
|
import "../../chunk-CMSHXALI.js";
|
|
22
22
|
import "../../chunk-I3J46TSB.js";
|
|
23
|
-
import "../../chunk-
|
|
23
|
+
import "../../chunk-GLQWEINZ.js";
|
|
24
|
+
import "../../chunk-SCVWDNQP.js";
|
|
25
|
+
import "../../chunk-3XO33KPS.js";
|
|
24
26
|
import "../../chunk-PZ5AY32C.js";
|
|
25
27
|
|
|
26
28
|
// tools/warp_grep/gemini.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../tools/warp_grep/gemini.ts"],"sourcesContent":["/**\n * Google Gemini SDK adapter for morph-warp-grep tool\n * \n * Requires @google/generative-ai as a peer dependency.\n * Install with: npm install @google/generative-ai\n */\n\nimport type { FunctionDeclaration, FunctionDeclarationSchema } from '@google/generative-ai';\nimport { executeToolCall, formatResult, WarpGrepClient, executeGitHubReadFile, formatGitHubReadFileResult } from './client.js';\nimport { WARP_GREP_DESCRIPTION, WARP_GREP_TOOL_NAME, GITHUB_SEARCH_TOOL_NAME, GITHUB_SEARCH_DESCRIPTION, GITHUB_READ_FILE_TOOL_NAME, GITHUB_READ_FILE_DESCRIPTION, GITHUB_READ_FILE_INPUT_SCHEMA } from './prompts.js';\nimport type { WarpGrepToolConfig, WarpGrepResult, GitHubSearchToolConfig, GitHubReadFileInput, GitHubReadFileResult, GitHubReadFileToolConfig } from './types.js';\n\n// Use plain object to avoid runtime import of SchemaType enum\nconst TOOL_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n search_term: { \n type: 'STRING', \n description: 'Search problem statement that this subagent is supposed to research for' \n },\n },\n required: ['search_term'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Gemini-native warp grep function declaration\n * \n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { warpGrepFunctionDeclaration, execute } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n * \n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [warpGrepFunctionDeclaration] }]\n * });\n * \n * const chat = model.startChat();\n * const result = await chat.sendMessage('Find authentication middleware');\n * \n * // Handle function call\n * const call = result.response.functionCalls()?.[0];\n * if (call) {\n * const searchResult = await execute(call.args, { repoRoot: '.' });\n * console.log(searchResult);\n * }\n * ```\n */\nexport const warpGrepFunctionDeclaration: FunctionDeclaration = {\n name: WARP_GREP_TOOL_NAME,\n description: WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n};\n\n/**\n * Execute warp grep search\n * \n * @param input - Tool input with search_term\n * @param config - Configuration with repoRoot and optional provider\n * @returns Search results\n */\nexport async function execute(\n input: { search_term: string } | string,\n config: WarpGrepToolConfig\n): Promise<WarpGrepResult> {\n return executeToolCall(input, config);\n}\n\nexport { formatResult };\n\n/**\n * Gemini tool with execute method attached\n */\nexport interface GeminiWarpGrepTool extends FunctionDeclaration {\n execute: (input: unknown) => Promise<WarpGrepResult>;\n formatResult: (result: WarpGrepResult) => string;\n}\n\n/**\n * Create a custom warp grep tool with configuration and methods\n * \n * @param config - Configuration options\n * @returns Function declaration with execute and formatResult methods\n * \n * @example Local usage\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createMorphWarpGrepTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n * \n * const tool = createMorphWarpGrepTool({ repoRoot: '.' });\n * \n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n * \n * const chat = model.startChat();\n * const result = await chat.sendMessage('Find authentication middleware');\n * \n * // Handle function call\n * const call = result.response.functionCalls()?.[0];\n * if (call && call.name === tool.name) {\n * const searchResult = await tool.execute(call.args);\n * console.log(tool.formatResult(searchResult));\n * \n * // Send result back to model\n * await chat.sendMessage([{\n * functionResponse: {\n * name: call.name,\n * response: { result: tool.formatResult(searchResult) }\n * }\n * }]);\n * }\n * ```\n * \n * @example Remote sandbox (E2B, Modal, etc.)\n * ```typescript\n * const tool = createMorphWarpGrepTool({\n * repoRoot: '/home/repo',\n * remoteCommands: {\n * grep: async (pattern, path) => (await sandbox.run(`rg '${pattern}' '${path}'`)).stdout,\n * read: async (path, start, end) => (await sandbox.run(`sed -n '${start},${end}p' '${path}'`)).stdout,\n * listDir: async (path, maxDepth) => (await sandbox.run(`find '${path}' -maxdepth ${maxDepth}`)).stdout,\n * },\n * });\n * ```\n */\nexport function createWarpGrepTool(config: WarpGrepToolConfig): GeminiWarpGrepTool {\n const declaration: FunctionDeclaration = {\n name: config.name ?? WARP_GREP_TOOL_NAME,\n description: config.description ?? WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: unknown): Promise<WarpGrepResult> => {\n return executeToolCall(input as { search_term: string } | string, config);\n },\n formatResult: (result: WarpGrepResult): string => {\n return formatResult(result);\n },\n });\n}\n\n// Legacy alias for backwards compatibility\nexport const createMorphWarpGrepTool = createWarpGrepTool;\n\nconst GITHUB_SEARCH_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n search_term: { type: 'STRING', description: 'Search problem statement that this subagent is supposed to research for' },\n github_url: { type: 'STRING', description: 'GitHub repository URL to search (e.g. \"https://github.com/vercel/next.js\"). You must provide either github_url or owner_repo.' },\n owner_repo: { type: 'STRING', description: 'Repository owner/repo shorthand (e.g. \"vercel/next.js\"). You must provide either github_url or owner_repo.' },\n branch: { type: 'STRING', description: 'Branch to search (defaults to repo default branch)' },\n },\n required: ['search_term'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Create a GitHub search tool for Google Gemini SDK\n *\n * @param config - Configuration options (morphApiKey, morphApiUrl, codeSearchUrl, timeout)\n * @returns Gemini FunctionDeclaration with execute and formatResult methods\n *\n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createGitHubSearchTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n *\n * const tool = createGitHubSearchTool({ morphApiKey: process.env.MORPH_API_KEY });\n *\n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n *\n * // Execute\n * const result = await tool.execute({ search_term: 'auth middleware', github_url: 'https://github.com/vercel/next.js' });\n * console.log(tool.formatResult(result));\n * ```\n */\nexport function createGitHubSearchTool(config: GitHubSearchToolConfig) {\n const client = new WarpGrepClient(config);\n\n const declaration: FunctionDeclaration = {\n name: GITHUB_SEARCH_TOOL_NAME,\n description: GITHUB_SEARCH_DESCRIPTION,\n parameters: GITHUB_SEARCH_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: { search_term: string; github_url?: string; owner_repo?: string; branch?: string }): Promise<WarpGrepResult> => {\n const github = input.github_url || input.owner_repo;\n if (!github) {\n throw new Error('Please provide github search url or owner/repo id');\n }\n return client.searchGitHub({ searchTerm: input.search_term, github, branch: input.branch });\n },\n formatResult: (result: WarpGrepResult): string => {\n return formatResult(result);\n },\n });\n}\n\nconst GITHUB_READ_FILE_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n github: { type: 'STRING', description: 'owner/repo shorthand (e.g., \"vercel/next.js\")' },\n path: { type: 'STRING', description: 'File path within the repository' },\n startLine: { type: 'NUMBER', description: 'Start line number (1-based)' },\n endLine: { type: 'NUMBER', description: 'End line number (1-based, inclusive)' },\n branch: { type: 'STRING', description: 'Branch to read from (defaults to repo default branch)' },\n },\n required: ['github', 'path'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Create a GitHub read file tool for Google Gemini SDK\n *\n * @param config - Optional configuration (timeout)\n * @returns Gemini FunctionDeclaration with execute and formatResult methods\n *\n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createGitHubReadFileTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n *\n * const tool = createGitHubReadFileTool();\n *\n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n *\n * const result = await tool.execute({ github: 'vercel/next.js', path: 'package.json' });\n * console.log(tool.formatResult(result));\n * ```\n */\nexport function createGitHubReadFileTool(config?: GitHubReadFileToolConfig) {\n const declaration: FunctionDeclaration = {\n name: GITHUB_READ_FILE_TOOL_NAME,\n description: GITHUB_READ_FILE_DESCRIPTION,\n parameters: GITHUB_READ_FILE_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: GitHubReadFileInput): Promise<GitHubReadFileResult> => {\n return executeGitHubReadFile(input, config);\n },\n formatResult: (result: GitHubReadFileResult): string => {\n return formatGitHubReadFileResult(result);\n },\n });\n}\n\nexport default warpGrepFunctionDeclaration;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAM,kBAAkB;AAAA,EACtB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,aAAa;AAAA,MACX,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,UAAU,CAAC,aAAa;AAC1B;AA2BO,IAAM,8BAAmD;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,YAAY;AACd;AASA,eAAsB,QACpB,OACA,QACyB;AACzB,SAAO,gBAAgB,OAAO,MAAM;AACtC;AA8DO,SAAS,mBAAmB,QAAgD;AACjF,QAAM,cAAmC;AAAA,IACvC,MAAM,OAAO,QAAQ;AAAA,IACrB,aAAa,OAAO,eAAe;AAAA,IACnC,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAA4C;AAC1D,aAAO,gBAAgB,OAA2C,MAAM;AAAA,IAC1E;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAGO,IAAM,0BAA0B;AAEvC,IAAM,2BAA2B;AAAA,EAC/B,MAAM;AAAA,EACN,YAAY;AAAA,IACV,aAAa,EAAE,MAAM,UAAU,aAAa,0EAA0E;AAAA,IACtH,YAAY,EAAE,MAAM,UAAU,aAAa,gIAAgI;AAAA,IAC3K,YAAY,EAAE,MAAM,UAAU,aAAa,6GAA6G;AAAA,IACxJ,QAAQ,EAAE,MAAM,UAAU,aAAa,qDAAqD;AAAA,EAC9F;AAAA,EACA,UAAU,CAAC,aAAa;AAC1B;AA0BO,SAAS,uBAAuB,QAAgC;AACrE,QAAM,SAAS,IAAI,eAAe,MAAM;AAExC,QAAM,cAAmC;AAAA,IACvC,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAAuH;AACrI,YAAM,SAAS,MAAM,cAAc,MAAM;AACzC,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,mDAAmD;AAAA,MACrE;AACA,aAAO,OAAO,aAAa,EAAE,YAAY,MAAM,aAAa,QAAQ,QAAQ,MAAM,OAAO,CAAC;AAAA,IAC5F;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAEA,IAAM,8BAA8B;AAAA,EAClC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ,EAAE,MAAM,UAAU,aAAa,gDAAgD;AAAA,IACvF,MAAM,EAAE,MAAM,UAAU,aAAa,kCAAkC;AAAA,IACvE,WAAW,EAAE,MAAM,UAAU,aAAa,8BAA8B;AAAA,IACxE,SAAS,EAAE,MAAM,UAAU,aAAa,uCAAuC;AAAA,IAC/E,QAAQ,EAAE,MAAM,UAAU,aAAa,wDAAwD;AAAA,EACjG;AAAA,EACA,UAAU,CAAC,UAAU,MAAM;AAC7B;AAyBO,SAAS,yBAAyB,QAAmC;AAC1E,QAAM,cAAmC;AAAA,IACvC,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAA8D;AAC5E,aAAO,sBAAsB,OAAO,MAAM;AAAA,IAC5C;AAAA,IACA,cAAc,CAAC,WAAyC;AACtD,aAAO,2BAA2B,MAAM;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;AAEA,IAAO,iBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../tools/warp_grep/gemini.ts"],"sourcesContent":["/**\n * Google Gemini SDK adapter for morph-warp-grep tool\n * \n * Requires @google/generative-ai as a peer dependency.\n * Install with: npm install @google/generative-ai\n */\n\nimport type { FunctionDeclaration, FunctionDeclarationSchema } from '@google/generative-ai';\nimport { executeToolCall, formatResult, WarpGrepClient, executeGitHubReadFile, formatGitHubReadFileResult } from './client.js';\nimport { WARP_GREP_DESCRIPTION, WARP_GREP_TOOL_NAME, GITHUB_SEARCH_TOOL_NAME, GITHUB_SEARCH_DESCRIPTION, GITHUB_READ_FILE_TOOL_NAME, GITHUB_READ_FILE_DESCRIPTION, GITHUB_READ_FILE_INPUT_SCHEMA } from './prompts.js';\nimport type { WarpGrepToolConfig, WarpGrepResult, GitHubSearchToolConfig, GitHubReadFileInput, GitHubReadFileResult, GitHubReadFileToolConfig } from './types.js';\n\n// Use plain object to avoid runtime import of SchemaType enum\nconst TOOL_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n search_term: { \n type: 'STRING', \n description: 'Search problem statement that this subagent is supposed to research for' \n },\n },\n required: ['search_term'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Gemini-native warp grep function declaration\n * \n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { warpGrepFunctionDeclaration, execute } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n * \n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [warpGrepFunctionDeclaration] }]\n * });\n * \n * const chat = model.startChat();\n * const result = await chat.sendMessage('Find authentication middleware');\n * \n * // Handle function call\n * const call = result.response.functionCalls()?.[0];\n * if (call) {\n * const searchResult = await execute(call.args, { repoRoot: '.' });\n * console.log(searchResult);\n * }\n * ```\n */\nexport const warpGrepFunctionDeclaration: FunctionDeclaration = {\n name: WARP_GREP_TOOL_NAME,\n description: WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n};\n\n/**\n * Execute warp grep search\n * \n * @param input - Tool input with search_term\n * @param config - Configuration with repoRoot and optional provider\n * @returns Search results\n */\nexport async function execute(\n input: { search_term: string } | string,\n config: WarpGrepToolConfig\n): Promise<WarpGrepResult> {\n return executeToolCall(input, config);\n}\n\nexport { formatResult };\n\n/**\n * Gemini tool with execute method attached\n */\nexport interface GeminiWarpGrepTool extends FunctionDeclaration {\n execute: (input: unknown) => Promise<WarpGrepResult>;\n formatResult: (result: WarpGrepResult) => string;\n}\n\n/**\n * Create a custom warp grep tool with configuration and methods\n * \n * @param config - Configuration options\n * @returns Function declaration with execute and formatResult methods\n * \n * @example Local usage\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createMorphWarpGrepTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n * \n * const tool = createMorphWarpGrepTool({ repoRoot: '.' });\n * \n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n * \n * const chat = model.startChat();\n * const result = await chat.sendMessage('Find authentication middleware');\n * \n * // Handle function call\n * const call = result.response.functionCalls()?.[0];\n * if (call && call.name === tool.name) {\n * const searchResult = await tool.execute(call.args);\n * console.log(tool.formatResult(searchResult));\n * \n * // Send result back to model\n * await chat.sendMessage([{\n * functionResponse: {\n * name: call.name,\n * response: { result: tool.formatResult(searchResult) }\n * }\n * }]);\n * }\n * ```\n * \n * @example Remote sandbox (E2B, Modal, etc.)\n * ```typescript\n * const tool = createMorphWarpGrepTool({\n * repoRoot: '/home/repo',\n * remoteCommands: {\n * grep: async (pattern, path) => (await sandbox.run(`rg '${pattern}' '${path}'`)).stdout,\n * read: async (path, start, end) => (await sandbox.run(`sed -n '${start},${end}p' '${path}'`)).stdout,\n * listDir: async (path, maxDepth) => (await sandbox.run(`find '${path}' -maxdepth ${maxDepth}`)).stdout,\n * },\n * });\n * ```\n */\nexport function createWarpGrepTool(config: WarpGrepToolConfig): GeminiWarpGrepTool {\n const declaration: FunctionDeclaration = {\n name: config.name ?? WARP_GREP_TOOL_NAME,\n description: config.description ?? WARP_GREP_DESCRIPTION,\n parameters: TOOL_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: unknown): Promise<WarpGrepResult> => {\n return executeToolCall(input as { search_term: string } | string, config);\n },\n formatResult: (result: WarpGrepResult): string => {\n return formatResult(result);\n },\n });\n}\n\n// Legacy alias for backwards compatibility\nexport const createMorphWarpGrepTool = createWarpGrepTool;\n\nconst GITHUB_SEARCH_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n search_term: { type: 'STRING', description: 'Search problem statement that this subagent is supposed to research for' },\n github_url: { type: 'STRING', description: 'GitHub repository URL to search (e.g. \"https://github.com/vercel/next.js\"). You must provide either github_url or owner_repo.' },\n owner_repo: { type: 'STRING', description: 'Repository owner/repo shorthand (e.g. \"vercel/next.js\"). You must provide either github_url or owner_repo.' },\n branch: { type: 'STRING', description: 'Branch to search (defaults to repo default branch)' },\n },\n required: ['search_term'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Create a GitHub search tool for Google Gemini SDK\n *\n * @param config - Configuration options (morphApiKey, morphApiUrl, codeSearchUrl, timeout)\n * @returns Gemini FunctionDeclaration with execute and formatResult methods\n *\n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createGitHubSearchTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n *\n * const tool = createGitHubSearchTool({ morphApiKey: process.env.MORPH_API_KEY });\n *\n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n *\n * // Execute\n * const result = await tool.execute({ search_term: 'auth middleware', github_url: 'https://github.com/vercel/next.js' });\n * console.log(tool.formatResult(result));\n * ```\n */\nexport function createGitHubSearchTool(config: GitHubSearchToolConfig) {\n const client = new WarpGrepClient(config);\n\n const declaration: FunctionDeclaration = {\n name: GITHUB_SEARCH_TOOL_NAME,\n description: GITHUB_SEARCH_DESCRIPTION,\n parameters: GITHUB_SEARCH_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: { search_term: string; github_url?: string; owner_repo?: string; branch?: string }): Promise<WarpGrepResult> => {\n const github = input.github_url || input.owner_repo;\n if (!github) {\n throw new Error('Please provide github search url or owner/repo id');\n }\n return client.searchGitHub({ searchTerm: input.search_term, github, branch: input.branch });\n },\n formatResult: (result: WarpGrepResult): string => {\n return formatResult(result);\n },\n });\n}\n\nconst GITHUB_READ_FILE_PARAMETERS = {\n type: 'OBJECT',\n properties: {\n github: { type: 'STRING', description: 'owner/repo shorthand (e.g., \"vercel/next.js\")' },\n path: { type: 'STRING', description: 'File path within the repository' },\n startLine: { type: 'NUMBER', description: 'Start line number (1-based)' },\n endLine: { type: 'NUMBER', description: 'End line number (1-based, inclusive)' },\n branch: { type: 'STRING', description: 'Branch to read from (defaults to repo default branch)' },\n },\n required: ['github', 'path'],\n} as unknown as FunctionDeclarationSchema;\n\n/**\n * Create a GitHub read file tool for Google Gemini SDK\n *\n * @param config - Optional configuration (timeout)\n * @returns Gemini FunctionDeclaration with execute and formatResult methods\n *\n * @example\n * ```typescript\n * import { GoogleGenerativeAI } from '@google/generative-ai';\n * import { createGitHubReadFileTool } from '@morphllm/morphsdk/tools/warp-grep/gemini';\n *\n * const tool = createGitHubReadFileTool();\n *\n * const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY);\n * const model = genAI.getGenerativeModel({\n * model: 'gemini-2.0-flash',\n * tools: [{ functionDeclarations: [tool] }]\n * });\n *\n * const result = await tool.execute({ github: 'vercel/next.js', path: 'package.json' });\n * console.log(tool.formatResult(result));\n * ```\n */\nexport function createGitHubReadFileTool(config?: GitHubReadFileToolConfig) {\n const declaration: FunctionDeclaration = {\n name: GITHUB_READ_FILE_TOOL_NAME,\n description: GITHUB_READ_FILE_DESCRIPTION,\n parameters: GITHUB_READ_FILE_PARAMETERS,\n };\n\n return Object.assign(declaration, {\n execute: async (input: GitHubReadFileInput): Promise<GitHubReadFileResult> => {\n return executeGitHubReadFile(input, config);\n },\n formatResult: (result: GitHubReadFileResult): string => {\n return formatGitHubReadFileResult(result);\n },\n });\n}\n\nexport default warpGrepFunctionDeclaration;\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,IAAM,kBAAkB;AAAA,EACtB,MAAM;AAAA,EACN,YAAY;AAAA,IACV,aAAa;AAAA,MACX,MAAM;AAAA,MACN,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EACA,UAAU,CAAC,aAAa;AAC1B;AA2BO,IAAM,8BAAmD;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,YAAY;AACd;AASA,eAAsB,QACpB,OACA,QACyB;AACzB,SAAO,gBAAgB,OAAO,MAAM;AACtC;AA8DO,SAAS,mBAAmB,QAAgD;AACjF,QAAM,cAAmC;AAAA,IACvC,MAAM,OAAO,QAAQ;AAAA,IACrB,aAAa,OAAO,eAAe;AAAA,IACnC,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAA4C;AAC1D,aAAO,gBAAgB,OAA2C,MAAM;AAAA,IAC1E;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAGO,IAAM,0BAA0B;AAEvC,IAAM,2BAA2B;AAAA,EAC/B,MAAM;AAAA,EACN,YAAY;AAAA,IACV,aAAa,EAAE,MAAM,UAAU,aAAa,0EAA0E;AAAA,IACtH,YAAY,EAAE,MAAM,UAAU,aAAa,gIAAgI;AAAA,IAC3K,YAAY,EAAE,MAAM,UAAU,aAAa,6GAA6G;AAAA,IACxJ,QAAQ,EAAE,MAAM,UAAU,aAAa,qDAAqD;AAAA,EAC9F;AAAA,EACA,UAAU,CAAC,aAAa;AAC1B;AA0BO,SAAS,uBAAuB,QAAgC;AACrE,QAAM,SAAS,IAAI,eAAe,MAAM;AAExC,QAAM,cAAmC;AAAA,IACvC,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAAuH;AACrI,YAAM,SAAS,MAAM,cAAc,MAAM;AACzC,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,MAAM,mDAAmD;AAAA,MACrE;AACA,aAAO,OAAO,aAAa,EAAE,YAAY,MAAM,aAAa,QAAQ,QAAQ,MAAM,OAAO,CAAC;AAAA,IAC5F;AAAA,IACA,cAAc,CAAC,WAAmC;AAChD,aAAO,aAAa,MAAM;AAAA,IAC5B;AAAA,EACF,CAAC;AACH;AAEA,IAAM,8BAA8B;AAAA,EAClC,MAAM;AAAA,EACN,YAAY;AAAA,IACV,QAAQ,EAAE,MAAM,UAAU,aAAa,gDAAgD;AAAA,IACvF,MAAM,EAAE,MAAM,UAAU,aAAa,kCAAkC;AAAA,IACvE,WAAW,EAAE,MAAM,UAAU,aAAa,8BAA8B;AAAA,IACxE,SAAS,EAAE,MAAM,UAAU,aAAa,uCAAuC;AAAA,IAC/E,QAAQ,EAAE,MAAM,UAAU,aAAa,wDAAwD;AAAA,EACjG;AAAA,EACA,UAAU,CAAC,UAAU,MAAM;AAC7B;AAyBO,SAAS,yBAAyB,QAAmC;AAC1E,QAAM,cAAmC;AAAA,IACvC,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,EACd;AAEA,SAAO,OAAO,OAAO,aAAa;AAAA,IAChC,SAAS,OAAO,UAA8D;AAC5E,aAAO,sBAAsB,OAAO,MAAM;AAAA,IAC5C;AAAA,IACA,cAAc,CAAC,WAAyC;AACtD,aAAO,2BAA2B,MAAM;AAAA,IAC1C;AAAA,EACF,CAAC;AACH;AAEA,IAAO,iBAAQ;","names":[]}
|
|
@@ -967,7 +967,7 @@ var import_openai = __toESM(require("openai"), 1);
|
|
|
967
967
|
// package.json
|
|
968
968
|
var package_default = {
|
|
969
969
|
name: "@morphllm/morphsdk",
|
|
970
|
-
version: "0.2.
|
|
970
|
+
version: "0.2.154",
|
|
971
971
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
972
972
|
type: "module",
|
|
973
973
|
main: "./dist/index.cjs",
|
|
@@ -1833,6 +1833,131 @@ function parseGitHubUrl(input) {
|
|
|
1833
1833
|
);
|
|
1834
1834
|
}
|
|
1835
1835
|
|
|
1836
|
+
// tools/compact/core.ts
|
|
1837
|
+
var DEFAULT_API_URL2 = "https://api.morphllm.com";
|
|
1838
|
+
var DEFAULT_TIMEOUT = 12e4;
|
|
1839
|
+
var CompactClient = class {
|
|
1840
|
+
config;
|
|
1841
|
+
constructor(config = {}) {
|
|
1842
|
+
this.config = {
|
|
1843
|
+
...config,
|
|
1844
|
+
morphApiUrl: config.morphApiUrl ?? DEFAULT_API_URL2,
|
|
1845
|
+
timeout: config.timeout ?? DEFAULT_TIMEOUT
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
/**
|
|
1849
|
+
* Compact messages or text via /v1/compact.
|
|
1850
|
+
* Returns per-message `compacted_line_ranges` showing which lines were removed.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```typescript
|
|
1854
|
+
* const client = new CompactClient({ morphApiKey: 'sk-...' });
|
|
1855
|
+
* const result = await client.compact({
|
|
1856
|
+
* input: codeFile,
|
|
1857
|
+
* query: "authentication",
|
|
1858
|
+
* compressionRatio: 0.5,
|
|
1859
|
+
* });
|
|
1860
|
+
* console.log(result.output);
|
|
1861
|
+
* ```
|
|
1862
|
+
*/
|
|
1863
|
+
async compact(input) {
|
|
1864
|
+
const apiKey = this.config.morphApiKey || (typeof process !== "undefined" ? process.env?.MORPH_API_KEY : void 0);
|
|
1865
|
+
const debug = this.config.debug || false;
|
|
1866
|
+
if (!apiKey) {
|
|
1867
|
+
throw new Error(
|
|
1868
|
+
"Morph API key not found. Set MORPH_API_KEY environment variable or pass morphApiKey in config."
|
|
1869
|
+
);
|
|
1870
|
+
}
|
|
1871
|
+
const url = `${this.config.morphApiUrl}/v1/compact`;
|
|
1872
|
+
if (debug) {
|
|
1873
|
+
console.log(`[Compact] Calling ${url}`);
|
|
1874
|
+
}
|
|
1875
|
+
const body = {
|
|
1876
|
+
compression_ratio: input.compressionRatio ?? 0.5,
|
|
1877
|
+
preserve_recent: input.preserveRecent ?? 2,
|
|
1878
|
+
model: input.model ?? "morph-compactor",
|
|
1879
|
+
include_line_ranges: input.includeLineRanges ?? true,
|
|
1880
|
+
include_markers: input.includeMarkers ?? true
|
|
1881
|
+
};
|
|
1882
|
+
if (input.query !== void 0) {
|
|
1883
|
+
body.query = input.query;
|
|
1884
|
+
}
|
|
1885
|
+
if (input.messages) {
|
|
1886
|
+
body.messages = input.messages;
|
|
1887
|
+
} else if (typeof input.input === "string") {
|
|
1888
|
+
body.input = input.input;
|
|
1889
|
+
} else if (Array.isArray(input.input)) {
|
|
1890
|
+
body.messages = input.input;
|
|
1891
|
+
} else {
|
|
1892
|
+
throw new Error("Either 'input' or 'messages' must be provided");
|
|
1893
|
+
}
|
|
1894
|
+
const startTime = Date.now();
|
|
1895
|
+
const response = await fetch(url, {
|
|
1896
|
+
method: "POST",
|
|
1897
|
+
headers: {
|
|
1898
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
1899
|
+
"Content-Type": "application/json"
|
|
1900
|
+
},
|
|
1901
|
+
body: JSON.stringify(body),
|
|
1902
|
+
signal: AbortSignal.timeout(this.config.timeout)
|
|
1903
|
+
});
|
|
1904
|
+
if (!response.ok) {
|
|
1905
|
+
const text = await response.text();
|
|
1906
|
+
throw new Error(`Compact API error ${response.status}: ${text}`);
|
|
1907
|
+
}
|
|
1908
|
+
const data = await response.json();
|
|
1909
|
+
if (debug) {
|
|
1910
|
+
console.log(`[Compact] compact() done in ${Date.now() - startTime}ms`);
|
|
1911
|
+
}
|
|
1912
|
+
return data;
|
|
1913
|
+
}
|
|
1914
|
+
};
|
|
1915
|
+
|
|
1916
|
+
// tools/compact/utils.ts
|
|
1917
|
+
async function compactFileContexts(files, query, apiKey, apiUrl, maxTokens = 1e4, maxConcurrency = 3) {
|
|
1918
|
+
const totalLength = files.reduce((sum, file) => sum + file.content.length, 0);
|
|
1919
|
+
const estimatedTokens = totalLength / 3;
|
|
1920
|
+
if (estimatedTokens <= maxTokens) {
|
|
1921
|
+
return files;
|
|
1922
|
+
}
|
|
1923
|
+
let compressionRatio = maxTokens / estimatedTokens;
|
|
1924
|
+
compressionRatio = Math.max(0.3, Math.min(0.99, compressionRatio));
|
|
1925
|
+
const client = new CompactClient({
|
|
1926
|
+
morphApiKey: apiKey,
|
|
1927
|
+
morphApiUrl: apiUrl
|
|
1928
|
+
});
|
|
1929
|
+
const results = [];
|
|
1930
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
1931
|
+
for (const file of files) {
|
|
1932
|
+
if (file.content.length < 500) {
|
|
1933
|
+
results.push({ path: file.path, content: file.content });
|
|
1934
|
+
continue;
|
|
1935
|
+
}
|
|
1936
|
+
const task = async () => {
|
|
1937
|
+
try {
|
|
1938
|
+
const result = await client.compact({
|
|
1939
|
+
input: file.content,
|
|
1940
|
+
query,
|
|
1941
|
+
compressionRatio,
|
|
1942
|
+
preserveRecent: 0
|
|
1943
|
+
});
|
|
1944
|
+
results.push({ path: file.path, content: result.output });
|
|
1945
|
+
} catch (error) {
|
|
1946
|
+
console.error(`[compactFileContexts] Failed to compact file ${file.path}:`, error);
|
|
1947
|
+
results.push({ path: file.path, content: file.content });
|
|
1948
|
+
}
|
|
1949
|
+
};
|
|
1950
|
+
const promise = task().finally(() => inProgress.delete(promise));
|
|
1951
|
+
inProgress.add(promise);
|
|
1952
|
+
if (inProgress.size >= maxConcurrency) {
|
|
1953
|
+
await Promise.race(inProgress);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
await Promise.all(inProgress);
|
|
1957
|
+
const orderMap = new Map(files.map((f, i) => [f.path, i]));
|
|
1958
|
+
return results.sort((a, b) => (orderMap.get(a.path) ?? 0) - (orderMap.get(b.path) ?? 0));
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1836
1961
|
// tools/warp_grep/client.ts
|
|
1837
1962
|
var DEFAULT_CODE_SEARCH_URL = "https://morphllm.com";
|
|
1838
1963
|
async function getLocalProvider(repoRoot, excludes, allowNames) {
|
|
@@ -1962,20 +2087,9 @@ async function executeToolCall(input, config) {
|
|
|
1962
2087
|
timeout: config.timeout,
|
|
1963
2088
|
search_type: config.search_type
|
|
1964
2089
|
});
|
|
1965
|
-
|
|
1966
|
-
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1967
|
-
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
1968
|
-
console.error(`[warp_grep] executeToolCall failed. Reason: ${result.terminationReason}. Errors: ${errorDetails}. Turns: ${result.timings?.turns?.length ?? 0}`);
|
|
1969
|
-
return { success: false, error: `Search did not complete: ${errorDetails}` };
|
|
1970
|
-
}
|
|
1971
|
-
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1972
|
-
file: r.path,
|
|
1973
|
-
content: r.content,
|
|
1974
|
-
lines: r.ranges
|
|
1975
|
-
}));
|
|
1976
|
-
return { success: true, contexts, summary: finish.payload };
|
|
2090
|
+
return processAgentResult(result, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
1977
2091
|
}
|
|
1978
|
-
function processAgentResult(result) {
|
|
2092
|
+
async function processAgentResult(result, searchTerm, apiKey, apiUrl) {
|
|
1979
2093
|
const finish = result.finish;
|
|
1980
2094
|
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1981
2095
|
const errorDetails = result.errors?.map((e) => e.message).join("; ") || "unknown reason";
|
|
@@ -1987,6 +2101,15 @@ function processAgentResult(result) {
|
|
|
1987
2101
|
content: r.content,
|
|
1988
2102
|
lines: r.ranges
|
|
1989
2103
|
}));
|
|
2104
|
+
try {
|
|
2105
|
+
const compactable = contexts.map((c) => ({ path: c.file, content: c.content }));
|
|
2106
|
+
const compacted = await compactFileContexts(compactable, searchTerm, apiKey, apiUrl);
|
|
2107
|
+
for (let i = 0; i < contexts.length; i++) {
|
|
2108
|
+
contexts[i].content = compacted[i].content;
|
|
2109
|
+
}
|
|
2110
|
+
} catch (error) {
|
|
2111
|
+
console.error(`[warp_grep] Failed to compact result contexts:`, error);
|
|
2112
|
+
}
|
|
1990
2113
|
return { success: true, contexts, summary: finish.payload };
|
|
1991
2114
|
}
|
|
1992
2115
|
async function* executeToolCallStreaming(input, config) {
|
|
@@ -2015,7 +2138,7 @@ async function* executeToolCallStreaming(input, config) {
|
|
|
2015
2138
|
}
|
|
2016
2139
|
yield value;
|
|
2017
2140
|
}
|
|
2018
|
-
return processAgentResult(agentResult);
|
|
2141
|
+
return processAgentResult(agentResult, parsed.search_term, config.morphApiKey, config.morphApiUrl);
|
|
2019
2142
|
}
|
|
2020
2143
|
async function fetchRawGitHubFile(owner, repo, filePath, branch, timeout) {
|
|
2021
2144
|
const branches = branch ? [branch] : ["HEAD"];
|