@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 { Tool } from '@anthropic-ai/sdk/resources/messages';
|
|
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
|
* Anthropic SDK adapter for morph-warp-grep tool
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
createWarpGrepTool,
|
|
3
3
|
execute,
|
|
4
4
|
warpGrepTool
|
|
5
|
-
} from "../../chunk-
|
|
5
|
+
} from "../../chunk-AJEE5RRB.js";
|
|
6
6
|
import "../../chunk-KW7OEGZK.js";
|
|
7
7
|
import {
|
|
8
8
|
formatResult
|
|
9
|
-
} from "../../chunk-
|
|
10
|
-
import "../../chunk-
|
|
9
|
+
} from "../../chunk-37SJ3IOY.js";
|
|
10
|
+
import "../../chunk-HJOMBO2A.js";
|
|
11
11
|
import "../../chunk-PUGSTXLO.js";
|
|
12
12
|
import "../../chunk-KRDIR7GG.js";
|
|
13
13
|
import "../../chunk-APP75CBN.js";
|
|
@@ -1158,6 +1158,156 @@ async function runWarpGrep(config) {
|
|
|
1158
1158
|
timings
|
|
1159
1159
|
};
|
|
1160
1160
|
}
|
|
1161
|
+
async function* runWarpGrepStreaming(config) {
|
|
1162
|
+
const totalStart = Date.now();
|
|
1163
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
1164
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
1165
|
+
const repoRoot = import_path2.default.resolve(config.repoRoot || process.cwd());
|
|
1166
|
+
const messages = [];
|
|
1167
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
1168
|
+
const initialStateStart = Date.now();
|
|
1169
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
1170
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
1171
|
+
messages.push({ role: "user", content: initialState });
|
|
1172
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
1173
|
+
const model = config.model || DEFAULT_MODEL;
|
|
1174
|
+
const provider = config.provider;
|
|
1175
|
+
const errors = [];
|
|
1176
|
+
let finishMeta;
|
|
1177
|
+
let terminationReason = "terminated";
|
|
1178
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
1179
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
1180
|
+
enforceContextLimit(messages);
|
|
1181
|
+
const modelCallStart = Date.now();
|
|
1182
|
+
const assistantContent = await callModel(messages, model, {
|
|
1183
|
+
morphApiKey: config.morphApiKey,
|
|
1184
|
+
morphApiUrl: config.morphApiUrl,
|
|
1185
|
+
retryConfig: config.retryConfig,
|
|
1186
|
+
timeout: timeoutMs
|
|
1187
|
+
}).catch((e) => {
|
|
1188
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
1189
|
+
return "";
|
|
1190
|
+
});
|
|
1191
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
1192
|
+
if (!assistantContent) {
|
|
1193
|
+
timings.turns.push(turnMetrics);
|
|
1194
|
+
break;
|
|
1195
|
+
}
|
|
1196
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
1197
|
+
const toolCalls = parser.parse(assistantContent);
|
|
1198
|
+
if (toolCalls.length === 0) {
|
|
1199
|
+
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" });
|
|
1200
|
+
terminationReason = "terminated";
|
|
1201
|
+
timings.turns.push(turnMetrics);
|
|
1202
|
+
break;
|
|
1203
|
+
}
|
|
1204
|
+
yield {
|
|
1205
|
+
turn,
|
|
1206
|
+
toolCalls: toolCalls.map((c) => ({
|
|
1207
|
+
name: c.name,
|
|
1208
|
+
arguments: c.arguments ?? {}
|
|
1209
|
+
}))
|
|
1210
|
+
};
|
|
1211
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
1212
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
1213
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
1214
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
1215
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
1216
|
+
const formatted = [];
|
|
1217
|
+
for (const c of skipCalls) {
|
|
1218
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
1219
|
+
formatted.push(msg);
|
|
1220
|
+
}
|
|
1221
|
+
const allPromises = [];
|
|
1222
|
+
for (const c of grepCalls) {
|
|
1223
|
+
const args = c.arguments ?? {};
|
|
1224
|
+
allPromises.push(
|
|
1225
|
+
toolGrep(provider, args).then(
|
|
1226
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
1227
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
1228
|
+
)
|
|
1229
|
+
);
|
|
1230
|
+
}
|
|
1231
|
+
for (const c of listDirCalls) {
|
|
1232
|
+
const args = c.arguments ?? {};
|
|
1233
|
+
allPromises.push(
|
|
1234
|
+
toolListDirectory(provider, args).then(
|
|
1235
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
1236
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
1237
|
+
)
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
for (const c of readCalls) {
|
|
1241
|
+
const args = c.arguments ?? {};
|
|
1242
|
+
allPromises.push(
|
|
1243
|
+
toolRead(provider, args).then(
|
|
1244
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
1245
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
1246
|
+
)
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
const toolExecStart = Date.now();
|
|
1250
|
+
const allResults = await Promise.all(allPromises);
|
|
1251
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
1252
|
+
for (const result of allResults) {
|
|
1253
|
+
formatted.push(result);
|
|
1254
|
+
}
|
|
1255
|
+
if (formatted.length > 0) {
|
|
1256
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
1257
|
+
const contextBudget = calculateContextBudget(messages);
|
|
1258
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
1259
|
+
}
|
|
1260
|
+
timings.turns.push(turnMetrics);
|
|
1261
|
+
if (finishCalls.length) {
|
|
1262
|
+
const fc = finishCalls[0];
|
|
1263
|
+
const files = fc.arguments?.files ?? [];
|
|
1264
|
+
finishMeta = { files };
|
|
1265
|
+
terminationReason = "completed";
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
1270
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1271
|
+
return { terminationReason, messages, errors, timings };
|
|
1272
|
+
}
|
|
1273
|
+
const parts = ["Relevant context found:"];
|
|
1274
|
+
for (const f of finishMeta.files) {
|
|
1275
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
1276
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
1277
|
+
}
|
|
1278
|
+
const payload = parts.join("\n");
|
|
1279
|
+
const finishResolutionStart = Date.now();
|
|
1280
|
+
const fileReadErrors = [];
|
|
1281
|
+
const resolved = await readFinishFiles(
|
|
1282
|
+
repoRoot,
|
|
1283
|
+
finishMeta.files,
|
|
1284
|
+
async (p, s, e) => {
|
|
1285
|
+
try {
|
|
1286
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
1287
|
+
return rr.lines.map((l) => {
|
|
1288
|
+
const idx = l.indexOf("|");
|
|
1289
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
1290
|
+
});
|
|
1291
|
+
} catch (err) {
|
|
1292
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
1293
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
1294
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
1295
|
+
return [`[couldn't find: ${p}]`];
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
1300
|
+
if (fileReadErrors.length > 0) {
|
|
1301
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
1302
|
+
}
|
|
1303
|
+
timings.total_ms = Date.now() - totalStart;
|
|
1304
|
+
return {
|
|
1305
|
+
terminationReason: "completed",
|
|
1306
|
+
messages,
|
|
1307
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
1308
|
+
timings
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1161
1311
|
|
|
1162
1312
|
// tools/warp_grep/providers/local.ts
|
|
1163
1313
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
@@ -1751,48 +1901,31 @@ var WarpGrepClient = class {
|
|
|
1751
1901
|
retryConfig: config.retryConfig
|
|
1752
1902
|
};
|
|
1753
1903
|
}
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
* }
|
|
1772
|
-
* }
|
|
1773
|
-
* ```
|
|
1774
|
-
*/
|
|
1775
|
-
async execute(input) {
|
|
1776
|
-
return executeToolCall(
|
|
1777
|
-
{ query: input.query },
|
|
1778
|
-
{
|
|
1779
|
-
repoRoot: input.repoRoot,
|
|
1780
|
-
remoteCommands: input.remoteCommands,
|
|
1781
|
-
provider: input.provider,
|
|
1782
|
-
excludes: input.excludes,
|
|
1783
|
-
includes: input.includes,
|
|
1784
|
-
debug: input.debug ?? this.config.debug,
|
|
1785
|
-
morphApiKey: this.config.morphApiKey,
|
|
1786
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
1787
|
-
retryConfig: this.config.retryConfig,
|
|
1788
|
-
timeout: this.config.timeout
|
|
1789
|
-
}
|
|
1790
|
-
);
|
|
1904
|
+
execute(input) {
|
|
1905
|
+
const toolConfig = {
|
|
1906
|
+
repoRoot: input.repoRoot,
|
|
1907
|
+
remoteCommands: input.remoteCommands,
|
|
1908
|
+
provider: input.provider,
|
|
1909
|
+
excludes: input.excludes,
|
|
1910
|
+
includes: input.includes,
|
|
1911
|
+
debug: input.debug ?? this.config.debug,
|
|
1912
|
+
morphApiKey: this.config.morphApiKey,
|
|
1913
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
1914
|
+
retryConfig: this.config.retryConfig,
|
|
1915
|
+
timeout: this.config.timeout
|
|
1916
|
+
};
|
|
1917
|
+
if (input.streamSteps) {
|
|
1918
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
1919
|
+
}
|
|
1920
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
1791
1921
|
}
|
|
1792
1922
|
};
|
|
1793
|
-
|
|
1923
|
+
function executeWarpGrep(input, config) {
|
|
1794
1924
|
const client = new WarpGrepClient(config);
|
|
1795
|
-
|
|
1925
|
+
if (input.streamSteps) {
|
|
1926
|
+
return client.execute({ ...input, streamSteps: true });
|
|
1927
|
+
}
|
|
1928
|
+
return client.execute({ ...input, streamSteps: false });
|
|
1796
1929
|
}
|
|
1797
1930
|
async function executeToolCall(input, config) {
|
|
1798
1931
|
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
@@ -1819,6 +1952,43 @@ async function executeToolCall(input, config) {
|
|
|
1819
1952
|
}));
|
|
1820
1953
|
return { success: true, contexts, summary: finish.payload };
|
|
1821
1954
|
}
|
|
1955
|
+
function processAgentResult(result) {
|
|
1956
|
+
const finish = result.finish;
|
|
1957
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
1958
|
+
return { success: false, error: "Search did not complete" };
|
|
1959
|
+
}
|
|
1960
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
1961
|
+
file: r.path,
|
|
1962
|
+
content: r.content
|
|
1963
|
+
}));
|
|
1964
|
+
return { success: true, contexts, summary: finish.payload };
|
|
1965
|
+
}
|
|
1966
|
+
async function* executeToolCallStreaming(input, config) {
|
|
1967
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
1968
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
1969
|
+
const generator = runWarpGrepStreaming({
|
|
1970
|
+
query: parsed.query,
|
|
1971
|
+
repoRoot: config.repoRoot,
|
|
1972
|
+
provider,
|
|
1973
|
+
excludes: config.excludes,
|
|
1974
|
+
includes: config.includes,
|
|
1975
|
+
debug: config.debug ?? false,
|
|
1976
|
+
morphApiKey: config.morphApiKey,
|
|
1977
|
+
morphApiUrl: config.morphApiUrl,
|
|
1978
|
+
retryConfig: config.retryConfig,
|
|
1979
|
+
timeout: config.timeout
|
|
1980
|
+
});
|
|
1981
|
+
let agentResult;
|
|
1982
|
+
for (; ; ) {
|
|
1983
|
+
const { value, done } = await generator.next();
|
|
1984
|
+
if (done) {
|
|
1985
|
+
agentResult = value;
|
|
1986
|
+
break;
|
|
1987
|
+
}
|
|
1988
|
+
yield value;
|
|
1989
|
+
}
|
|
1990
|
+
return processAgentResult(agentResult);
|
|
1991
|
+
}
|
|
1822
1992
|
function formatResult(result) {
|
|
1823
1993
|
if (!result.success) {
|
|
1824
1994
|
return `Search failed: ${result.error}`;
|