@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
package/dist/client.cjs
CHANGED
|
@@ -2033,6 +2033,156 @@ async function runWarpGrep(config) {
|
|
|
2033
2033
|
timings
|
|
2034
2034
|
};
|
|
2035
2035
|
}
|
|
2036
|
+
async function* runWarpGrepStreaming(config) {
|
|
2037
|
+
const totalStart = Date.now();
|
|
2038
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
2039
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
2040
|
+
const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
|
|
2041
|
+
const messages = [];
|
|
2042
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
2043
|
+
const initialStateStart = Date.now();
|
|
2044
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
2045
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
2046
|
+
messages.push({ role: "user", content: initialState });
|
|
2047
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
2048
|
+
const model = config.model || DEFAULT_MODEL;
|
|
2049
|
+
const provider = config.provider;
|
|
2050
|
+
const errors = [];
|
|
2051
|
+
let finishMeta;
|
|
2052
|
+
let terminationReason = "terminated";
|
|
2053
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
2054
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
2055
|
+
enforceContextLimit(messages);
|
|
2056
|
+
const modelCallStart = Date.now();
|
|
2057
|
+
const assistantContent = await callModel(messages, model, {
|
|
2058
|
+
morphApiKey: config.morphApiKey,
|
|
2059
|
+
morphApiUrl: config.morphApiUrl,
|
|
2060
|
+
retryConfig: config.retryConfig,
|
|
2061
|
+
timeout: timeoutMs
|
|
2062
|
+
}).catch((e) => {
|
|
2063
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
2064
|
+
return "";
|
|
2065
|
+
});
|
|
2066
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
2067
|
+
if (!assistantContent) {
|
|
2068
|
+
timings.turns.push(turnMetrics);
|
|
2069
|
+
break;
|
|
2070
|
+
}
|
|
2071
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
2072
|
+
const toolCalls = parser.parse(assistantContent);
|
|
2073
|
+
if (toolCalls.length === 0) {
|
|
2074
|
+
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" });
|
|
2075
|
+
terminationReason = "terminated";
|
|
2076
|
+
timings.turns.push(turnMetrics);
|
|
2077
|
+
break;
|
|
2078
|
+
}
|
|
2079
|
+
yield {
|
|
2080
|
+
turn,
|
|
2081
|
+
toolCalls: toolCalls.map((c) => ({
|
|
2082
|
+
name: c.name,
|
|
2083
|
+
arguments: c.arguments ?? {}
|
|
2084
|
+
}))
|
|
2085
|
+
};
|
|
2086
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
2087
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
2088
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
2089
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
2090
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
2091
|
+
const formatted = [];
|
|
2092
|
+
for (const c of skipCalls) {
|
|
2093
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
2094
|
+
formatted.push(msg);
|
|
2095
|
+
}
|
|
2096
|
+
const allPromises = [];
|
|
2097
|
+
for (const c of grepCalls) {
|
|
2098
|
+
const args = c.arguments ?? {};
|
|
2099
|
+
allPromises.push(
|
|
2100
|
+
toolGrep(provider, args).then(
|
|
2101
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
2102
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
2103
|
+
)
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
for (const c of listDirCalls) {
|
|
2107
|
+
const args = c.arguments ?? {};
|
|
2108
|
+
allPromises.push(
|
|
2109
|
+
toolListDirectory(provider, args).then(
|
|
2110
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
2111
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
2112
|
+
)
|
|
2113
|
+
);
|
|
2114
|
+
}
|
|
2115
|
+
for (const c of readCalls) {
|
|
2116
|
+
const args = c.arguments ?? {};
|
|
2117
|
+
allPromises.push(
|
|
2118
|
+
toolRead(provider, args).then(
|
|
2119
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
2120
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
2121
|
+
)
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
const toolExecStart = Date.now();
|
|
2125
|
+
const allResults = await Promise.all(allPromises);
|
|
2126
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
2127
|
+
for (const result of allResults) {
|
|
2128
|
+
formatted.push(result);
|
|
2129
|
+
}
|
|
2130
|
+
if (formatted.length > 0) {
|
|
2131
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
2132
|
+
const contextBudget = calculateContextBudget(messages);
|
|
2133
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
2134
|
+
}
|
|
2135
|
+
timings.turns.push(turnMetrics);
|
|
2136
|
+
if (finishCalls.length) {
|
|
2137
|
+
const fc = finishCalls[0];
|
|
2138
|
+
const files = fc.arguments?.files ?? [];
|
|
2139
|
+
finishMeta = { files };
|
|
2140
|
+
terminationReason = "completed";
|
|
2141
|
+
break;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
2145
|
+
timings.total_ms = Date.now() - totalStart;
|
|
2146
|
+
return { terminationReason, messages, errors, timings };
|
|
2147
|
+
}
|
|
2148
|
+
const parts = ["Relevant context found:"];
|
|
2149
|
+
for (const f of finishMeta.files) {
|
|
2150
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
2151
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
2152
|
+
}
|
|
2153
|
+
const payload = parts.join("\n");
|
|
2154
|
+
const finishResolutionStart = Date.now();
|
|
2155
|
+
const fileReadErrors = [];
|
|
2156
|
+
const resolved = await readFinishFiles(
|
|
2157
|
+
repoRoot,
|
|
2158
|
+
finishMeta.files,
|
|
2159
|
+
async (p, s, e) => {
|
|
2160
|
+
try {
|
|
2161
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
2162
|
+
return rr.lines.map((l) => {
|
|
2163
|
+
const idx = l.indexOf("|");
|
|
2164
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
2165
|
+
});
|
|
2166
|
+
} catch (err) {
|
|
2167
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
2168
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
2169
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
2170
|
+
return [`[couldn't find: ${p}]`];
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
);
|
|
2174
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
2175
|
+
if (fileReadErrors.length > 0) {
|
|
2176
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
2177
|
+
}
|
|
2178
|
+
timings.total_ms = Date.now() - totalStart;
|
|
2179
|
+
return {
|
|
2180
|
+
terminationReason: "completed",
|
|
2181
|
+
messages,
|
|
2182
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
2183
|
+
timings
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2036
2186
|
|
|
2037
2187
|
// tools/warp_grep/providers/local.ts
|
|
2038
2188
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
@@ -2626,43 +2776,23 @@ var WarpGrepClient = class {
|
|
|
2626
2776
|
retryConfig: config.retryConfig
|
|
2627
2777
|
};
|
|
2628
2778
|
}
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
* }
|
|
2647
|
-
* }
|
|
2648
|
-
* ```
|
|
2649
|
-
*/
|
|
2650
|
-
async execute(input) {
|
|
2651
|
-
return executeToolCall(
|
|
2652
|
-
{ query: input.query },
|
|
2653
|
-
{
|
|
2654
|
-
repoRoot: input.repoRoot,
|
|
2655
|
-
remoteCommands: input.remoteCommands,
|
|
2656
|
-
provider: input.provider,
|
|
2657
|
-
excludes: input.excludes,
|
|
2658
|
-
includes: input.includes,
|
|
2659
|
-
debug: input.debug ?? this.config.debug,
|
|
2660
|
-
morphApiKey: this.config.morphApiKey,
|
|
2661
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
2662
|
-
retryConfig: this.config.retryConfig,
|
|
2663
|
-
timeout: this.config.timeout
|
|
2664
|
-
}
|
|
2665
|
-
);
|
|
2779
|
+
execute(input) {
|
|
2780
|
+
const toolConfig = {
|
|
2781
|
+
repoRoot: input.repoRoot,
|
|
2782
|
+
remoteCommands: input.remoteCommands,
|
|
2783
|
+
provider: input.provider,
|
|
2784
|
+
excludes: input.excludes,
|
|
2785
|
+
includes: input.includes,
|
|
2786
|
+
debug: input.debug ?? this.config.debug,
|
|
2787
|
+
morphApiKey: this.config.morphApiKey,
|
|
2788
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
2789
|
+
retryConfig: this.config.retryConfig,
|
|
2790
|
+
timeout: this.config.timeout
|
|
2791
|
+
};
|
|
2792
|
+
if (input.streamSteps) {
|
|
2793
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
2794
|
+
}
|
|
2795
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
2666
2796
|
}
|
|
2667
2797
|
};
|
|
2668
2798
|
async function executeToolCall(input, config) {
|
|
@@ -2690,6 +2820,43 @@ async function executeToolCall(input, config) {
|
|
|
2690
2820
|
}));
|
|
2691
2821
|
return { success: true, contexts, summary: finish.payload };
|
|
2692
2822
|
}
|
|
2823
|
+
function processAgentResult(result) {
|
|
2824
|
+
const finish = result.finish;
|
|
2825
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
2826
|
+
return { success: false, error: "Search did not complete" };
|
|
2827
|
+
}
|
|
2828
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
2829
|
+
file: r.path,
|
|
2830
|
+
content: r.content
|
|
2831
|
+
}));
|
|
2832
|
+
return { success: true, contexts, summary: finish.payload };
|
|
2833
|
+
}
|
|
2834
|
+
async function* executeToolCallStreaming(input, config) {
|
|
2835
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
2836
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
2837
|
+
const generator = runWarpGrepStreaming({
|
|
2838
|
+
query: parsed.query,
|
|
2839
|
+
repoRoot: config.repoRoot,
|
|
2840
|
+
provider,
|
|
2841
|
+
excludes: config.excludes,
|
|
2842
|
+
includes: config.includes,
|
|
2843
|
+
debug: config.debug ?? false,
|
|
2844
|
+
morphApiKey: config.morphApiKey,
|
|
2845
|
+
morphApiUrl: config.morphApiUrl,
|
|
2846
|
+
retryConfig: config.retryConfig,
|
|
2847
|
+
timeout: config.timeout
|
|
2848
|
+
});
|
|
2849
|
+
let agentResult;
|
|
2850
|
+
for (; ; ) {
|
|
2851
|
+
const { value, done } = await generator.next();
|
|
2852
|
+
if (done) {
|
|
2853
|
+
agentResult = value;
|
|
2854
|
+
break;
|
|
2855
|
+
}
|
|
2856
|
+
yield value;
|
|
2857
|
+
}
|
|
2858
|
+
return processAgentResult(agentResult);
|
|
2859
|
+
}
|
|
2693
2860
|
function formatResult(result) {
|
|
2694
2861
|
if (!result.success) {
|
|
2695
2862
|
return `Search failed: ${result.error}`;
|