@morphllm/morphsdk 0.2.84 → 0.2.85
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-D4EQYM6O.js → chunk-37SJ3IOY.js} +63 -42
- package/dist/chunk-37SJ3IOY.js.map +1 -0
- package/dist/{chunk-MJ7JODAY.js → chunk-5X7IJXKA.js} +2 -2
- package/dist/{chunk-262WRPS5.js → chunk-AJEE5RRB.js} +2 -2
- package/dist/{chunk-LF2X6YNP.js → chunk-HJOMBO2A.js} +153 -2
- package/dist/chunk-HJOMBO2A.js.map +1 -0
- package/dist/{chunk-LX2WNS3L.js → chunk-IXNX4HMC.js} +2 -2
- package/dist/{chunk-FY32COVL.js → chunk-L5C6E32T.js} +1 -1
- package/dist/{chunk-FY32COVL.js.map → chunk-L5C6E32T.js.map} +1 -1
- package/dist/{chunk-N3RNM4A4.js → chunk-SQF3OG24.js} +5 -5
- package/dist/{client-CsO9LifG.d.ts → client-Drz3OGq-.d.ts} +1 -1
- package/dist/client.cjs +204 -37
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +3 -2
- package/dist/client.js +6 -6
- package/dist/index.cjs +204 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -7
- package/dist/tools/warp_grep/agent/runner.cjs +154 -2
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.d.ts +9 -2
- package/dist/tools/warp_grep/agent/runner.js +5 -3
- package/dist/tools/warp_grep/agent/types.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/types.d.ts +12 -1
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.d.ts +3 -2
- package/dist/tools/warp_grep/anthropic.js +3 -3
- package/dist/tools/warp_grep/client.cjs +209 -39
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.d.ts +39 -6
- package/dist/tools/warp_grep/client.js +2 -2
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.d.ts +3 -2
- package/dist/tools/warp_grep/gemini.js +2 -2
- package/dist/tools/warp_grep/index.cjs +211 -39
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.d.ts +3 -3
- package/dist/tools/warp_grep/index.js +6 -4
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.d.ts +3 -2
- package/dist/tools/warp_grep/openai.js +3 -3
- package/dist/tools/warp_grep/providers/remote.d.ts +1 -1
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.d.ts +2 -1
- package/dist/tools/warp_grep/vercel.js +3 -3
- package/dist/{types-Cv4LpqVl.d.ts → types-BMowL9iZ.d.ts} +5 -0
- package/package.json +1 -1
- package/dist/chunk-D4EQYM6O.js.map +0 -1
- package/dist/chunk-LF2X6YNP.js.map +0 -1
- /package/dist/{chunk-MJ7JODAY.js.map → chunk-5X7IJXKA.js.map} +0 -0
- /package/dist/{chunk-262WRPS5.js.map → chunk-AJEE5RRB.js.map} +0 -0
- /package/dist/{chunk-LX2WNS3L.js.map → chunk-IXNX4HMC.js.map} +0 -0
- /package/dist/{chunk-N3RNM4A4.js.map → chunk-SQF3OG24.js.map} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { FunctionDeclaration } from '@google/generative-ai';
|
|
2
2
|
export { formatResult } from './client.js';
|
|
3
3
|
export { getSystemPrompt } from './agent/prompt.js';
|
|
4
|
-
import { d as WarpGrepToolConfig, b as WarpGrepResult } from '../../types-
|
|
5
|
-
import './
|
|
4
|
+
import { d as WarpGrepToolConfig, b as WarpGrepResult } from '../../types-BMowL9iZ.js';
|
|
5
|
+
import './agent/types.js';
|
|
6
6
|
import '../utils/resilience.js';
|
|
7
|
+
import './providers/types.js';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Google Gemini SDK adapter for morph-warp-grep tool
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
executeToolCall,
|
|
7
7
|
formatResult
|
|
8
|
-
} from "../../chunk-
|
|
9
|
-
import "../../chunk-
|
|
8
|
+
} from "../../chunk-37SJ3IOY.js";
|
|
9
|
+
import "../../chunk-HJOMBO2A.js";
|
|
10
10
|
import "../../chunk-PUGSTXLO.js";
|
|
11
11
|
import "../../chunk-KRDIR7GG.js";
|
|
12
12
|
import "../../chunk-APP75CBN.js";
|
|
@@ -44,6 +44,7 @@ __export(warp_grep_exports, {
|
|
|
44
44
|
normalizeFinishFiles: () => normalizeFinishFiles,
|
|
45
45
|
readFinishFiles: () => readFinishFiles,
|
|
46
46
|
runWarpGrep: () => runWarpGrep,
|
|
47
|
+
runWarpGrepStreaming: () => runWarpGrepStreaming,
|
|
47
48
|
toolGrep: () => toolGrep,
|
|
48
49
|
toolListDirectory: () => toolListDirectory,
|
|
49
50
|
toolRead: () => toolRead,
|
|
@@ -1181,6 +1182,156 @@ async function runWarpGrep(config) {
|
|
|
1181
1182
|
timings
|
|
1182
1183
|
};
|
|
1183
1184
|
}
|
|
1185
|
+
async function* runWarpGrepStreaming(config) {
|
|
1186
|
+
const totalStart = Date.now();
|
|
1187
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1188
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1189
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1190
|
+
const messages = [];
|
|
1191
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
1192
|
+
const initialStateStart = Date.now();
|
|
1193
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
1194
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1195
|
+
messages.push({ role: "user", content: initialState });
|
|
1196
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1197
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1198
|
+
const provider = config.provider;
|
|
1199
|
+
const errors = [];
|
|
1200
|
+
let finishMeta;
|
|
1201
|
+
let terminationReason = "terminated";
|
|
1202
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1203
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1204
|
+
enforceContextLimit(messages);
|
|
1205
|
+
const modelCallStart = Date.now();
|
|
1206
|
+
const assistantContent = await callModel(messages, model, {
|
|
1207
|
+
morphApiKey: config.morphApiKey,
|
|
1208
|
+
morphApiUrl: config.morphApiUrl,
|
|
1209
|
+
retryConfig: config.retryConfig,
|
|
1210
|
+
timeout: timeoutMs
|
|
1211
|
+
}).catch((e) => {
|
|
1212
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
1213
|
+
return "";
|
|
1214
|
+
});
|
|
1215
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1216
|
+
if (!assistantContent) {
|
|
1217
|
+
timings.turns.push(turnMetrics);
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1221
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1222
|
+
if (toolCalls.length === 0) {
|
|
1223
|
+
errors.push({ message: "No tool calls produced by the model. Your MCP is likely out of date! Update it by running: rm -rf ~/.npm/_npx && npm cache clean --force && npx -y @morphllm/morphmcp@latest" });
|
|
1224
|
+
terminationReason = "terminated";
|
|
1225
|
+
timings.turns.push(turnMetrics);
|
|
1226
|
+
break;
|
|
1227
|
+
}
|
|
1228
|
+
yield {
|
|
1229
|
+
turn,
|
|
1230
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1231
|
+
name: c.name,
|
|
1232
|
+
arguments: c.arguments ?? {}
|
|
1233
|
+
}))
|
|
1234
|
+
};
|
|
1235
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1236
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1237
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1238
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1239
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1240
|
+
const formatted = [];
|
|
1241
|
+
for (const c of skipCalls) {
|
|
1242
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1243
|
+
formatted.push(msg);
|
|
1244
|
+
}
|
|
1245
|
+
const allPromises = [];
|
|
1246
|
+
for (const c of grepCalls) {
|
|
1247
|
+
const args = c.arguments ?? {};
|
|
1248
|
+
allPromises.push(
|
|
1249
|
+
toolGrep(provider, args).then(
|
|
1250
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
1251
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1252
|
+
)
|
|
1253
|
+
);
|
|
1254
|
+
}
|
|
1255
|
+
for (const c of listDirCalls) {
|
|
1256
|
+
const args = c.arguments ?? {};
|
|
1257
|
+
allPromises.push(
|
|
1258
|
+
toolListDirectory(provider, args).then(
|
|
1259
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
1260
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1261
|
+
)
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
for (const c of readCalls) {
|
|
1265
|
+
const args = c.arguments ?? {};
|
|
1266
|
+
allPromises.push(
|
|
1267
|
+
toolRead(provider, args).then(
|
|
1268
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
1269
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1270
|
+
)
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
const toolExecStart = Date.now();
|
|
1274
|
+
const allResults = await Promise.all(allPromises);
|
|
1275
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1276
|
+
for (const result of allResults) {
|
|
1277
|
+
formatted.push(result);
|
|
1278
|
+
}
|
|
1279
|
+
if (formatted.length > 0) {
|
|
1280
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1281
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1282
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1283
|
+
}
|
|
1284
|
+
timings.turns.push(turnMetrics);
|
|
1285
|
+
if (finishCalls.length) {
|
|
1286
|
+
const fc = finishCalls[0];
|
|
1287
|
+
const files = fc.arguments?.files ?? [];
|
|
1288
|
+
finishMeta = { files };
|
|
1289
|
+
terminationReason = "completed";
|
|
1290
|
+
break;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1294
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1295
|
+
return { terminationReason, messages, errors, timings };
|
|
1296
|
+
}
|
|
1297
|
+
const parts = ["Relevant context found:"];
|
|
1298
|
+
for (const f of finishMeta.files) {
|
|
1299
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1300
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1301
|
+
}
|
|
1302
|
+
const payload = parts.join("\n");
|
|
1303
|
+
const finishResolutionStart = Date.now();
|
|
1304
|
+
const fileReadErrors = [];
|
|
1305
|
+
const resolved = await readFinishFiles(
|
|
1306
|
+
repoRoot,
|
|
1307
|
+
finishMeta.files,
|
|
1308
|
+
async (p, s, e) => {
|
|
1309
|
+
try {
|
|
1310
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1311
|
+
return rr.lines.map((l) => {
|
|
1312
|
+
const idx = l.indexOf("|");
|
|
1313
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1314
|
+
});
|
|
1315
|
+
} catch (err) {
|
|
1316
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1317
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1318
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1319
|
+
return [`[couldn't find: ${p}]`];
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
);
|
|
1323
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1324
|
+
if (fileReadErrors.length > 0) {
|
|
1325
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1326
|
+
}
|
|
1327
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1328
|
+
return {
|
|
1329
|
+
terminationReason: "completed",
|
|
1330
|
+
messages,
|
|
1331
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1332
|
+
timings
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1184
1335
|
|
|
1185
1336
|
// tools/warp_grep/providers/local.ts
|
|
1186
1337
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
@@ -1774,48 +1925,31 @@ var WarpGrepClient = class {
|
|
|
1774
1925
|
retryConfig: config.retryConfig
|
|
1775
1926
|
};
|
|
1776
1927
|
}
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
* }
|
|
1795
|
-
* }
|
|
1796
|
-
* ```
|
|
1797
|
-
*/
|
|
1798
|
-
async execute(input) {
|
|
1799
|
-
return executeToolCall(
|
|
1800
|
-
{ query: input.query },
|
|
1801
|
-
{
|
|
1802
|
-
repoRoot: input.repoRoot,
|
|
1803
|
-
remoteCommands: input.remoteCommands,
|
|
1804
|
-
provider: input.provider,
|
|
1805
|
-
excludes: input.excludes,
|
|
1806
|
-
includes: input.includes,
|
|
1807
|
-
debug: input.debug ?? this.config.debug,
|
|
1808
|
-
morphApiKey: this.config.morphApiKey,
|
|
1809
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
1810
|
-
retryConfig: this.config.retryConfig,
|
|
1811
|
-
timeout: this.config.timeout
|
|
1812
|
-
}
|
|
1813
|
-
);
|
|
1928
|
+
execute(input) {
|
|
1929
|
+
const toolConfig = {
|
|
1930
|
+
repoRoot: input.repoRoot,
|
|
1931
|
+
remoteCommands: input.remoteCommands,
|
|
1932
|
+
provider: input.provider,
|
|
1933
|
+
excludes: input.excludes,
|
|
1934
|
+
includes: input.includes,
|
|
1935
|
+
debug: input.debug ?? this.config.debug,
|
|
1936
|
+
morphApiKey: this.config.morphApiKey,
|
|
1937
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
1938
|
+
retryConfig: this.config.retryConfig,
|
|
1939
|
+
timeout: this.config.timeout
|
|
1940
|
+
};
|
|
1941
|
+
if (input.streamSteps) {
|
|
1942
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
1943
|
+
}
|
|
1944
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
1814
1945
|
}
|
|
1815
1946
|
};
|
|
1816
|
-
|
|
1947
|
+
function executeWarpGrep(input, config) {
|
|
1817
1948
|
const client = new WarpGrepClient(config);
|
|
1818
|
-
|
|
1949
|
+
if (input.streamSteps) {
|
|
1950
|
+
return client.execute({ ...input, streamSteps: true });
|
|
1951
|
+
}
|
|
1952
|
+
return client.execute({ ...input, streamSteps: false });
|
|
1819
1953
|
}
|
|
1820
1954
|
async function executeToolCall(input, config) {
|
|
1821
1955
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
@@ -1842,6 +1976,43 @@ async function executeToolCall(input, config) {
|
|
|
1842
1976
|
}));
|
|
1843
1977
|
return { success: true, contexts, summary: finish.payload };
|
|
1844
1978
|
}
|
|
1979
|
+
function processAgentResult(result) {
|
|
1980
|
+
const finish = result.finish;
|
|
1981
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1982
|
+
return { success: false, error: "Search did not complete" };
|
|
1983
|
+
}
|
|
1984
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1985
|
+
file: r.path,
|
|
1986
|
+
content: r.content
|
|
1987
|
+
}));
|
|
1988
|
+
return { success: true, contexts, summary: finish.payload };
|
|
1989
|
+
}
|
|
1990
|
+
async function* executeToolCallStreaming(input, config) {
|
|
1991
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
1992
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
1993
|
+
const generator = runWarpGrepStreaming({
|
|
1994
|
+
query: parsed.query,
|
|
1995
|
+
repoRoot: config.repoRoot,
|
|
1996
|
+
provider,
|
|
1997
|
+
excludes: config.excludes,
|
|
1998
|
+
includes: config.includes,
|
|
1999
|
+
debug: config.debug ?? false,
|
|
2000
|
+
morphApiKey: config.morphApiKey,
|
|
2001
|
+
morphApiUrl: config.morphApiUrl,
|
|
2002
|
+
retryConfig: config.retryConfig,
|
|
2003
|
+
timeout: config.timeout
|
|
2004
|
+
});
|
|
2005
|
+
let agentResult;
|
|
2006
|
+
for (; ; ) {
|
|
2007
|
+
const { value, done } = await generator.next();
|
|
2008
|
+
if (done) {
|
|
2009
|
+
agentResult = value;
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
yield value;
|
|
2013
|
+
}
|
|
2014
|
+
return processAgentResult(agentResult);
|
|
2015
|
+
}
|
|
1845
2016
|
function formatResult(result) {
|
|
1846
2017
|
if (!result.success) {
|
|
1847
2018
|
return `Search failed: ${result.error}`;
|
|
@@ -1889,6 +2060,7 @@ var warpGrepInputSchema = import_zod.z.object({
|
|
|
1889
2060
|
normalizeFinishFiles,
|
|
1890
2061
|
readFinishFiles,
|
|
1891
2062
|
runWarpGrep,
|
|
2063
|
+
runWarpGrepStreaming,
|
|
1892
2064
|
toolGrep,
|
|
1893
2065
|
toolListDirectory,
|
|
1894
2066
|
toolRead,
|