@morphllm/morphsdk 0.2.161 → 0.2.163
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-JIPYZNK3.js → chunk-2KDJKRZG.js} +2 -2
- package/dist/chunk-5AM23TC7.js +42 -0
- package/dist/chunk-5AM23TC7.js.map +1 -0
- package/dist/{chunk-PQXJ32G4.js → chunk-5BMWOPYW.js} +2 -2
- package/dist/{chunk-F2SBKBBS.js → chunk-5FYJMU6H.js} +2 -2
- package/dist/{chunk-KP3CAEH5.js → chunk-6PFGM4CM.js} +2 -2
- package/dist/{chunk-5R3QCYHW.js → chunk-6YOSNPHS.js} +2 -2
- package/dist/{chunk-G3E75GPM.js → chunk-6YTCBLRI.js} +2 -2
- package/dist/{chunk-2CE4PG2F.js → chunk-COUYHTIO.js} +2 -2
- package/dist/{chunk-KCJRKSMG.js → chunk-CUMC7Z5R.js} +11 -26
- package/dist/chunk-CUMC7Z5R.js.map +1 -0
- package/dist/{chunk-HDZ4XYUX.js → chunk-EJBWDGTH.js} +2 -2
- package/dist/{chunk-DKQMGEHV.js → chunk-FNCPPCPV.js} +2 -2
- package/dist/{chunk-IHSLH64T.js → chunk-FQXUOZBX.js} +9 -12
- package/dist/chunk-FQXUOZBX.js.map +1 -0
- package/dist/{chunk-27VVVW57.js → chunk-HBH56DLN.js} +2 -2
- package/dist/{chunk-5GVI7L4O.js → chunk-HFN3YCF4.js} +2 -2
- package/dist/{chunk-QQBEGCX2.js → chunk-HMGC7FLZ.js} +2 -2
- package/dist/{chunk-KF2AYKGJ.js → chunk-KHR4CZMX.js} +24 -17
- package/dist/{chunk-KF2AYKGJ.js.map → chunk-KHR4CZMX.js.map} +1 -1
- package/dist/{chunk-LGF2WTXG.js → chunk-LSHQISAX.js} +9 -2
- package/dist/chunk-LSHQISAX.js.map +1 -0
- package/dist/{chunk-L6WYOSFK.js → chunk-LST7MZOZ.js} +7 -2
- package/dist/chunk-LST7MZOZ.js.map +1 -0
- package/dist/{chunk-63JAZOI3.js → chunk-LW5EAPZ6.js} +2 -2
- package/dist/{chunk-N4EFVT45.js → chunk-NNATBEOF.js} +2 -2
- package/dist/{chunk-RZS5DQAX.js → chunk-OKFW4KGU.js} +2 -2
- package/dist/{chunk-QR34LBOS.js → chunk-QXGOEDZD.js} +2 -2
- package/dist/{chunk-442YHCTX.js → chunk-SELI567A.js} +12 -21
- package/dist/chunk-SELI567A.js.map +1 -0
- package/dist/{chunk-VM4TVOBU.js → chunk-VMNEYCFP.js} +17 -6
- package/dist/chunk-VMNEYCFP.js.map +1 -0
- package/dist/{chunk-NBGHPRU6.js → chunk-WM6SBI4B.js} +37 -29
- package/dist/chunk-WM6SBI4B.js.map +1 -0
- package/dist/{chunk-CMRUAJYD.js → chunk-ZMCDGAGF.js} +33 -6
- package/dist/chunk-ZMCDGAGF.js.map +1 -0
- package/dist/client.cjs +186 -117
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +23 -22
- package/dist/edge.cjs +84 -52
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +5 -4
- package/dist/index.cjs +188 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +23 -22
- package/dist/modelrouter/core.cjs +50 -25
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +4 -3
- package/dist/modelrouter/index.cjs +50 -25
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +4 -3
- package/dist/subagents/anthropic.cjs +85 -12
- package/dist/subagents/anthropic.cjs.map +1 -1
- package/dist/subagents/anthropic.js +5 -4
- package/dist/subagents/vercel.cjs +85 -12
- package/dist/subagents/vercel.cjs.map +1 -1
- package/dist/subagents/vercel.js +5 -4
- package/dist/tools/browser/anthropic.cjs +47 -9
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +6 -5
- package/dist/tools/browser/core.cjs +50 -19
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +5 -4
- package/dist/tools/browser/index.cjs +50 -19
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +8 -7
- package/dist/tools/browser/index.js.map +1 -1
- package/dist/tools/browser/openai.cjs +47 -9
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +6 -5
- package/dist/tools/browser/profiles/core.cjs +6 -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 +6 -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 +47 -9
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +6 -5
- package/dist/tools/codebase_search/anthropic.cjs +48 -11
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +5 -4
- package/dist/tools/codebase_search/core.cjs +48 -11
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +4 -3
- package/dist/tools/codebase_search/index.cjs +48 -11
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +7 -6
- package/dist/tools/codebase_search/openai.cjs +48 -11
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +5 -4
- package/dist/tools/codebase_search/vercel.cjs +48 -11
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +5 -4
- package/dist/tools/fastapply/anthropic.cjs +96 -33
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +5 -4
- package/dist/tools/fastapply/apply.cjs +76 -28
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +3 -2
- package/dist/tools/fastapply/core.cjs +96 -33
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +4 -3
- package/dist/tools/fastapply/index.cjs +96 -33
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +7 -6
- package/dist/tools/fastapply/openai.cjs +96 -33
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +5 -4
- package/dist/tools/fastapply/types.cjs.map +1 -1
- package/dist/tools/fastapply/types.d.ts +4 -4
- package/dist/tools/fastapply/vercel.cjs +96 -33
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +5 -4
- package/dist/tools/index.cjs +96 -33
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +7 -6
- package/dist/tools/utils/resilience.cjs +6 -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 +74 -5
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -2
- package/dist/tools/warp_grep/anthropic.cjs +85 -12
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +5 -4
- package/dist/tools/warp_grep/client.cjs +85 -12
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +4 -3
- package/dist/tools/warp_grep/gemini.cjs +85 -12
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +4 -3
- package/dist/tools/warp_grep/gemini.js.map +1 -1
- package/dist/tools/warp_grep/index.cjs +85 -12
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +4 -3
- package/dist/tools/warp_grep/openai.cjs +85 -12
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +5 -4
- package/dist/tools/warp_grep/vercel.cjs +85 -12
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.js +5 -4
- package/dist/version.cjs +6 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
- package/dist/chunk-442YHCTX.js.map +0 -1
- package/dist/chunk-CMRUAJYD.js.map +0 -1
- package/dist/chunk-IHSLH64T.js.map +0 -1
- package/dist/chunk-KCJRKSMG.js.map +0 -1
- package/dist/chunk-L6WYOSFK.js.map +0 -1
- package/dist/chunk-LGF2WTXG.js.map +0 -1
- package/dist/chunk-NBGHPRU6.js.map +0 -1
- package/dist/chunk-VM4TVOBU.js.map +0 -1
- package/dist/{chunk-JIPYZNK3.js.map → chunk-2KDJKRZG.js.map} +0 -0
- package/dist/{chunk-PQXJ32G4.js.map → chunk-5BMWOPYW.js.map} +0 -0
- package/dist/{chunk-F2SBKBBS.js.map → chunk-5FYJMU6H.js.map} +0 -0
- package/dist/{chunk-KP3CAEH5.js.map → chunk-6PFGM4CM.js.map} +0 -0
- package/dist/{chunk-5R3QCYHW.js.map → chunk-6YOSNPHS.js.map} +0 -0
- package/dist/{chunk-G3E75GPM.js.map → chunk-6YTCBLRI.js.map} +0 -0
- package/dist/{chunk-2CE4PG2F.js.map → chunk-COUYHTIO.js.map} +0 -0
- package/dist/{chunk-HDZ4XYUX.js.map → chunk-EJBWDGTH.js.map} +0 -0
- package/dist/{chunk-DKQMGEHV.js.map → chunk-FNCPPCPV.js.map} +0 -0
- package/dist/{chunk-27VVVW57.js.map → chunk-HBH56DLN.js.map} +0 -0
- package/dist/{chunk-5GVI7L4O.js.map → chunk-HFN3YCF4.js.map} +0 -0
- package/dist/{chunk-QQBEGCX2.js.map → chunk-HMGC7FLZ.js.map} +0 -0
- package/dist/{chunk-63JAZOI3.js.map → chunk-LW5EAPZ6.js.map} +0 -0
- package/dist/{chunk-N4EFVT45.js.map → chunk-NNATBEOF.js.map} +0 -0
- package/dist/{chunk-RZS5DQAX.js.map → chunk-OKFW4KGU.js.map} +0 -0
- package/dist/{chunk-QR34LBOS.js.map → chunk-QXGOEDZD.js.map} +0 -0
- package/dist/{client-PkB7g9SA.d.ts → client-DsAAqupx.d.ts} +1 -1
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
executeToolCall,
|
|
13
13
|
formatGitHubReadFileResult,
|
|
14
14
|
formatResult
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-LSHQISAX.js";
|
|
16
16
|
import "../../chunk-63VHBANJ.js";
|
|
17
|
-
import "../../chunk-
|
|
17
|
+
import "../../chunk-ZMCDGAGF.js";
|
|
18
18
|
import "../../chunk-GVGJIXV2.js";
|
|
19
19
|
import "../../chunk-B3AKP3RA.js";
|
|
20
20
|
import "../../chunk-VNAGVCSP.js";
|
|
@@ -22,7 +22,8 @@ import "../../chunk-FBRNUWEB.js";
|
|
|
22
22
|
import "../../chunk-I3J46TSB.js";
|
|
23
23
|
import "../../chunk-GLQWEINZ.js";
|
|
24
24
|
import "../../chunk-SCVWDNQP.js";
|
|
25
|
-
import "../../chunk-
|
|
25
|
+
import "../../chunk-5AM23TC7.js";
|
|
26
|
+
import "../../chunk-LST7MZOZ.js";
|
|
26
27
|
import "../../chunk-PZ5AY32C.js";
|
|
27
28
|
|
|
28
29
|
// 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":[]}
|
|
@@ -220,7 +220,7 @@ function toRepoRelative(repoRoot, absPath) {
|
|
|
220
220
|
}
|
|
221
221
|
function isSymlink(p) {
|
|
222
222
|
try {
|
|
223
|
-
const st =
|
|
223
|
+
const st = import_fs2.default.lstatSync(p);
|
|
224
224
|
return st.isSymbolicLink();
|
|
225
225
|
} catch {
|
|
226
226
|
return false;
|
|
@@ -243,13 +243,13 @@ function fixPathRepetition(fullPath) {
|
|
|
243
243
|
}
|
|
244
244
|
function isTextualFile(filePath, maxBytes = 2e6) {
|
|
245
245
|
try {
|
|
246
|
-
const st =
|
|
246
|
+
const st = import_fs2.default.statSync(filePath);
|
|
247
247
|
if (!st.isFile()) return false;
|
|
248
248
|
if (st.size > maxBytes) return false;
|
|
249
|
-
const fd =
|
|
249
|
+
const fd = import_fs2.default.openSync(filePath, "r");
|
|
250
250
|
const buf = Buffer.alloc(512);
|
|
251
|
-
const read =
|
|
252
|
-
|
|
251
|
+
const read = import_fs2.default.readSync(fd, buf, 0, buf.length, 0);
|
|
252
|
+
import_fs2.default.closeSync(fd);
|
|
253
253
|
for (let i = 0; i < read; i++) {
|
|
254
254
|
const c = buf[i];
|
|
255
255
|
if (c === 0) return false;
|
|
@@ -259,11 +259,11 @@ function isTextualFile(filePath, maxBytes = 2e6) {
|
|
|
259
259
|
return false;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
var
|
|
262
|
+
var import_fs2, import_path4;
|
|
263
263
|
var init_paths = __esm({
|
|
264
264
|
"tools/warp_grep/utils/paths.ts"() {
|
|
265
265
|
"use strict";
|
|
266
|
-
|
|
266
|
+
import_fs2 = __toESM(require("fs"), 1);
|
|
267
267
|
import_path4 = __toESM(require("path"), 1);
|
|
268
268
|
}
|
|
269
269
|
});
|
|
@@ -968,7 +968,7 @@ var import_openai = __toESM(require("openai"), 1);
|
|
|
968
968
|
// package.json
|
|
969
969
|
var package_default = {
|
|
970
970
|
name: "@morphllm/morphsdk",
|
|
971
|
-
version: "0.2.
|
|
971
|
+
version: "0.2.163",
|
|
972
972
|
description: "TypeScript SDK and CLI for Morph Fast Apply integration",
|
|
973
973
|
type: "module",
|
|
974
974
|
main: "./dist/index.cjs",
|
|
@@ -980,6 +980,11 @@ var package_default = {
|
|
|
980
980
|
import: "./dist/index.js",
|
|
981
981
|
require: "./dist/index.cjs"
|
|
982
982
|
},
|
|
983
|
+
"./logger": {
|
|
984
|
+
types: "./dist/logger.d.ts",
|
|
985
|
+
import: "./dist/logger.js",
|
|
986
|
+
require: "./dist/logger.cjs"
|
|
987
|
+
},
|
|
983
988
|
"./edge": {
|
|
984
989
|
types: "./dist/edge.d.ts",
|
|
985
990
|
import: "./dist/edge.js",
|
|
@@ -1208,6 +1213,46 @@ var SDK_VERSION = package_default.version;
|
|
|
1208
1213
|
|
|
1209
1214
|
// tools/warp_grep/agent/runner.ts
|
|
1210
1215
|
var import_path3 = __toESM(require("path"), 1);
|
|
1216
|
+
|
|
1217
|
+
// logger.ts
|
|
1218
|
+
var import_fs = require("fs");
|
|
1219
|
+
var MorphLogger = class {
|
|
1220
|
+
enabled;
|
|
1221
|
+
fileStream;
|
|
1222
|
+
constructor() {
|
|
1223
|
+
this.enabled = process.env.MORPH_DEBUG === "1" || !!process.env.MORPH_LOG_FILE;
|
|
1224
|
+
const f = process.env.MORPH_LOG_FILE;
|
|
1225
|
+
this.fileStream = f ? (0, import_fs.createWriteStream)(f, { flags: "a" }) : null;
|
|
1226
|
+
}
|
|
1227
|
+
debug(component, msg, data) {
|
|
1228
|
+
this._log("debug", component, msg, data);
|
|
1229
|
+
}
|
|
1230
|
+
info(component, msg, data) {
|
|
1231
|
+
this._log("info", component, msg, data);
|
|
1232
|
+
}
|
|
1233
|
+
warn(component, msg, data) {
|
|
1234
|
+
this._log("warn", component, msg, data);
|
|
1235
|
+
}
|
|
1236
|
+
error(component, msg, data) {
|
|
1237
|
+
this._log("error", component, msg, data);
|
|
1238
|
+
}
|
|
1239
|
+
enable() {
|
|
1240
|
+
this.enabled = true;
|
|
1241
|
+
}
|
|
1242
|
+
get isEnabled() {
|
|
1243
|
+
return this.enabled;
|
|
1244
|
+
}
|
|
1245
|
+
_log(level, component, msg, data) {
|
|
1246
|
+
if (level !== "error" && !this.enabled) return;
|
|
1247
|
+
const ts = (/* @__PURE__ */ new Date()).toISOString();
|
|
1248
|
+
const prefix = `[${ts}] [${level.toUpperCase()}] [${component}]`;
|
|
1249
|
+
console.error(data ? `${prefix} ${msg} ${JSON.stringify(data)}` : `${prefix} ${msg}`);
|
|
1250
|
+
this.fileStream?.write(JSON.stringify({ ts, level, component, msg, ...data && { data } }) + "\n");
|
|
1251
|
+
}
|
|
1252
|
+
};
|
|
1253
|
+
var logger = new MorphLogger();
|
|
1254
|
+
|
|
1255
|
+
// tools/warp_grep/agent/runner.ts
|
|
1211
1256
|
var DEFAULT_API_URL = "https://api.morphllm.com";
|
|
1212
1257
|
var TOOL_SPECS = [
|
|
1213
1258
|
{
|
|
@@ -1330,6 +1375,8 @@ async function callModel(messages, model, options = {}) {
|
|
|
1330
1375
|
defaultHeaders: { "X-Morph-SDK-Version": SDK_VERSION }
|
|
1331
1376
|
});
|
|
1332
1377
|
const MAX_EMPTY_RETRIES = 1;
|
|
1378
|
+
logger.debug("WarpGrep", "model_call", { url: baseURL, model, message_count: messages.length });
|
|
1379
|
+
const callStartTime = Date.now();
|
|
1333
1380
|
for (let attempt = 0; attempt <= MAX_EMPTY_RETRIES; attempt++) {
|
|
1334
1381
|
let data;
|
|
1335
1382
|
try {
|
|
@@ -1342,10 +1389,16 @@ async function callModel(messages, model, options = {}) {
|
|
|
1342
1389
|
...options.search_type ? { search_type: options.search_type } : {}
|
|
1343
1390
|
});
|
|
1344
1391
|
} catch (error) {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1392
|
+
const callLatencyMs = Date.now() - callStartTime;
|
|
1393
|
+
if (error instanceof import_openai.default.APIError) {
|
|
1394
|
+
logger.error("WarpGrep", "model_call_error", { status: error.status, error: error.message, latency_ms: callLatencyMs });
|
|
1395
|
+
if (error.status === 404) {
|
|
1396
|
+
const defaultMsg = "The endpoint you are trying to call is likely deprecated. Please update with: npm cache clean --force && npx -y @morphllm/morphmcp@latest or visit: https://morphllm.com/mcp";
|
|
1397
|
+
const errorText = error.message?.trim();
|
|
1398
|
+
throw new Error(errorText || defaultMsg);
|
|
1399
|
+
}
|
|
1400
|
+
} else {
|
|
1401
|
+
logger.error("WarpGrep", "model_call_error", { status: void 0, error: error instanceof Error ? error.message : String(error), latency_ms: callLatencyMs });
|
|
1349
1402
|
}
|
|
1350
1403
|
throw error;
|
|
1351
1404
|
}
|
|
@@ -1364,6 +1417,7 @@ async function callModel(messages, model, options = {}) {
|
|
|
1364
1417
|
function: { name: tc.function.name, arguments: tc.function.arguments }
|
|
1365
1418
|
}));
|
|
1366
1419
|
if (message.content || toolCalls.length > 0) {
|
|
1420
|
+
logger.debug("WarpGrep", "model_call_complete", { latency_ms: Date.now() - callStartTime, tool_calls_count: toolCalls.length, finish_reason: choice?.finish_reason ?? "unknown" });
|
|
1367
1421
|
return { content: message.content ?? null, tool_calls: toolCalls };
|
|
1368
1422
|
}
|
|
1369
1423
|
if (attempt === MAX_EMPTY_RETRIES) {
|
|
@@ -1434,9 +1488,11 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1434
1488
|
const model = config.model || DEFAULT_MODEL;
|
|
1435
1489
|
const messages = [];
|
|
1436
1490
|
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1491
|
+
logger.debug("WarpGrep", "session_start", { search_term: config.searchTerm, model, max_turns: maxTurns });
|
|
1437
1492
|
const initialStateStart = Date.now();
|
|
1438
1493
|
const initialState = await buildInitialState(repoRoot, config.searchTerm, config.provider, { search_type: config.search_type });
|
|
1439
1494
|
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1495
|
+
logger.debug("WarpGrep", "initial_state", { system_prompt_len: initialState.length, user_message_len: initialState.length });
|
|
1440
1496
|
messages.push({ role: "user", content: initialState });
|
|
1441
1497
|
const provider = config.provider;
|
|
1442
1498
|
const errors = [];
|
|
@@ -1444,7 +1500,13 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1444
1500
|
let terminationReason = "terminated";
|
|
1445
1501
|
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1446
1502
|
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1503
|
+
logger.debug("WarpGrep", "turn_start", { turn, message_count: messages.length });
|
|
1504
|
+
const beforeChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
1447
1505
|
enforceContextLimit(messages);
|
|
1506
|
+
const afterChars = messages.reduce((sum, m) => sum + (typeof m.content === "string" ? m.content.length : 0), 0);
|
|
1507
|
+
if (afterChars < beforeChars) {
|
|
1508
|
+
logger.debug("WarpGrep", "context_truncated", { before_chars: beforeChars, after_chars: afterChars });
|
|
1509
|
+
}
|
|
1448
1510
|
const modelCallStart = Date.now();
|
|
1449
1511
|
const response = await callModel(messages, model, {
|
|
1450
1512
|
morphApiKey: config.morphApiKey,
|
|
@@ -1455,6 +1517,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1455
1517
|
}).catch((e) => {
|
|
1456
1518
|
const errMsg = e instanceof Error ? e.message : String(e);
|
|
1457
1519
|
console.error(`[warp_grep] Morph API call failed on turn ${turn}:`, errMsg);
|
|
1520
|
+
logger.error("WarpGrep", "error", { turn, error: errMsg, phase: "model_call" });
|
|
1458
1521
|
errors.push({ message: errMsg });
|
|
1459
1522
|
return null;
|
|
1460
1523
|
});
|
|
@@ -1464,6 +1527,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1464
1527
|
break;
|
|
1465
1528
|
}
|
|
1466
1529
|
const toolCalls = response.tool_calls;
|
|
1530
|
+
logger.debug("WarpGrep", "model_response", { turn, tool_calls: toolCalls.map((tc) => tc.function.name), latency_ms: turnMetrics.morph_api_ms });
|
|
1467
1531
|
messages.push({
|
|
1468
1532
|
role: "assistant",
|
|
1469
1533
|
content: response.content,
|
|
@@ -1490,6 +1554,7 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1490
1554
|
const files = parseFinishFiles(filesStr);
|
|
1491
1555
|
finishMeta = { files };
|
|
1492
1556
|
terminationReason = "completed";
|
|
1557
|
+
logger.debug("WarpGrep", "finish", { turns: turn, files: files.map((f) => f.path) });
|
|
1493
1558
|
if (files.length === 0) {
|
|
1494
1559
|
const payload2 = filesStr || "No relevant code found.";
|
|
1495
1560
|
timings.turns.push(turnMetrics);
|
|
@@ -1508,7 +1573,11 @@ async function* runWarpGrepStreaming(config) {
|
|
|
1508
1573
|
const results = await Promise.all(
|
|
1509
1574
|
toolCalls.map(async (tc) => {
|
|
1510
1575
|
const args = safeParseJSON(tc.function.arguments);
|
|
1576
|
+
const argsSummary = Object.fromEntries(Object.entries(args).map(([k, v]) => [k, typeof v === "string" && v.length > 100 ? v.slice(0, 100) + "..." : v]));
|
|
1577
|
+
logger.debug("WarpGrep", "tool_exec", { turn, tool: tc.function.name, args_summary: argsSummary });
|
|
1578
|
+
const toolStart = Date.now();
|
|
1511
1579
|
const output = await executeTool(provider, tc.function.name, args, repoRoot).catch((err) => String(err));
|
|
1580
|
+
logger.debug("WarpGrep", "tool_result", { turn, tool: tc.function.name, result_len: output.length, latency_ms: Date.now() - toolStart });
|
|
1512
1581
|
return { tool_call_id: tc.id, content: output };
|
|
1513
1582
|
})
|
|
1514
1583
|
);
|
|
@@ -2016,12 +2085,16 @@ var WarpGrepClient = class {
|
|
|
2016
2085
|
async _resolveGitHubRepo(input) {
|
|
2017
2086
|
const { owner, repo } = parseGitHubUrl(input.github);
|
|
2018
2087
|
const baseUrl = this.config.codeSearchUrl || DEFAULT_CODE_SEARCH_URL;
|
|
2088
|
+
logger.debug("WarpGrep", "github_resolve", { owner_repo: `${owner}/${repo}`, branch: input.branch });
|
|
2089
|
+
const resolveStart = Date.now();
|
|
2019
2090
|
const importRes = await fetch(`${baseUrl}/api/code-search/get-or-create?url=${encodeURIComponent(`${owner}/${repo}`)}`);
|
|
2020
2091
|
if (!importRes.ok) {
|
|
2021
2092
|
const text = await importRes.text().catch(() => importRes.statusText);
|
|
2093
|
+
logger.error("WarpGrep", "github_resolve_failed", { owner_repo: `${owner}/${repo}`, status: importRes.status, error: text });
|
|
2022
2094
|
throw new Error(`Failed to import repo ${owner}/${repo}: ${text}`);
|
|
2023
2095
|
}
|
|
2024
2096
|
const { repoId, defaultBranch } = await importRes.json();
|
|
2097
|
+
logger.debug("WarpGrep", "github_repo_fetched", { repo_id: repoId, default_branch: defaultBranch, latency_ms: Date.now() - resolveStart });
|
|
2025
2098
|
return {
|
|
2026
2099
|
repo,
|
|
2027
2100
|
remoteCommands: createCodeStorageHttpCommands({ baseUrl, repoId, branch: input.branch || defaultBranch })
|