@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.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ import './tools/browser/core.js';
|
|
|
5
5
|
import './tools/warp_grep/client.js';
|
|
6
6
|
import './git/client.js';
|
|
7
7
|
import './modelrouter/core.js';
|
|
8
|
-
export { M as MorphClient, a as MorphClientConfig } from './client-
|
|
8
|
+
export { M as MorphClient, a as MorphClientConfig } from './client-Drz3OGq-.js';
|
|
9
9
|
import './tools/fastapply/types.js';
|
|
10
10
|
import './tools/codebase_search/types.js';
|
|
11
11
|
import './tools/browser/types.js';
|
|
12
|
-
import './types
|
|
12
|
+
import './tools/warp_grep/agent/types.js';
|
|
13
|
+
import './types-BMowL9iZ.js';
|
|
13
14
|
import './tools/warp_grep/providers/types.js';
|
|
14
15
|
import './git/types.js';
|
|
15
16
|
import 'isomorphic-git';
|
package/dist/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MorphClient
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
6
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-SQF3OG24.js";
|
|
4
|
+
import "./chunk-AJEE5RRB.js";
|
|
5
|
+
import "./chunk-IXNX4HMC.js";
|
|
6
|
+
import "./chunk-5X7IJXKA.js";
|
|
7
7
|
import "./chunk-KW7OEGZK.js";
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
8
|
+
import "./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";
|
package/dist/index.cjs
CHANGED
|
@@ -2047,6 +2047,156 @@ async function runWarpGrep(config) {
|
|
|
2047
2047
|
timings
|
|
2048
2048
|
};
|
|
2049
2049
|
}
|
|
2050
|
+
async function* runWarpGrepStreaming(config) {
|
|
2051
|
+
const totalStart = Date.now();
|
|
2052
|
+
const timeoutMs = config.timeout ?? AGENT_CONFIG.TIMEOUT_MS;
|
|
2053
|
+
const timings = { turns: [], timeout_ms: timeoutMs };
|
|
2054
|
+
const repoRoot = import_path3.default.resolve(config.repoRoot || process.cwd());
|
|
2055
|
+
const messages = [];
|
|
2056
|
+
messages.push({ role: "system", content: getSystemPrompt() });
|
|
2057
|
+
const initialStateStart = Date.now();
|
|
2058
|
+
const initialState = await buildInitialState(repoRoot, config.query, config.provider);
|
|
2059
|
+
timings.initial_state_ms = Date.now() - initialStateStart;
|
|
2060
|
+
messages.push({ role: "user", content: initialState });
|
|
2061
|
+
const maxTurns = AGENT_CONFIG.MAX_TURNS;
|
|
2062
|
+
const model = config.model || DEFAULT_MODEL;
|
|
2063
|
+
const provider = config.provider;
|
|
2064
|
+
const errors = [];
|
|
2065
|
+
let finishMeta;
|
|
2066
|
+
let terminationReason = "terminated";
|
|
2067
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
2068
|
+
const turnMetrics = { turn, morph_api_ms: 0, local_tools_ms: 0 };
|
|
2069
|
+
enforceContextLimit(messages);
|
|
2070
|
+
const modelCallStart = Date.now();
|
|
2071
|
+
const assistantContent = await callModel(messages, model, {
|
|
2072
|
+
morphApiKey: config.morphApiKey,
|
|
2073
|
+
morphApiUrl: config.morphApiUrl,
|
|
2074
|
+
retryConfig: config.retryConfig,
|
|
2075
|
+
timeout: timeoutMs
|
|
2076
|
+
}).catch((e) => {
|
|
2077
|
+
errors.push({ message: e instanceof Error ? e.message : String(e) });
|
|
2078
|
+
return "";
|
|
2079
|
+
});
|
|
2080
|
+
turnMetrics.morph_api_ms = Date.now() - modelCallStart;
|
|
2081
|
+
if (!assistantContent) {
|
|
2082
|
+
timings.turns.push(turnMetrics);
|
|
2083
|
+
break;
|
|
2084
|
+
}
|
|
2085
|
+
messages.push({ role: "assistant", content: assistantContent });
|
|
2086
|
+
const toolCalls = parser.parse(assistantContent);
|
|
2087
|
+
if (toolCalls.length === 0) {
|
|
2088
|
+
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" });
|
|
2089
|
+
terminationReason = "terminated";
|
|
2090
|
+
timings.turns.push(turnMetrics);
|
|
2091
|
+
break;
|
|
2092
|
+
}
|
|
2093
|
+
yield {
|
|
2094
|
+
turn,
|
|
2095
|
+
toolCalls: toolCalls.map((c) => ({
|
|
2096
|
+
name: c.name,
|
|
2097
|
+
arguments: c.arguments ?? {}
|
|
2098
|
+
}))
|
|
2099
|
+
};
|
|
2100
|
+
const finishCalls = toolCalls.filter((c) => c.name === "finish");
|
|
2101
|
+
const grepCalls = toolCalls.filter((c) => c.name === "grep");
|
|
2102
|
+
const listDirCalls = toolCalls.filter((c) => c.name === "list_directory");
|
|
2103
|
+
const readCalls = toolCalls.filter((c) => c.name === "read");
|
|
2104
|
+
const skipCalls = toolCalls.filter((c) => c.name === "_skip");
|
|
2105
|
+
const formatted = [];
|
|
2106
|
+
for (const c of skipCalls) {
|
|
2107
|
+
const msg = c.arguments?.message || "Command skipped due to parsing error";
|
|
2108
|
+
formatted.push(msg);
|
|
2109
|
+
}
|
|
2110
|
+
const allPromises = [];
|
|
2111
|
+
for (const c of grepCalls) {
|
|
2112
|
+
const args = c.arguments ?? {};
|
|
2113
|
+
allPromises.push(
|
|
2114
|
+
toolGrep(provider, args).then(
|
|
2115
|
+
({ output }) => formatAgentToolOutput("grep", args, output, { isError: false }),
|
|
2116
|
+
(err) => formatAgentToolOutput("grep", args, String(err), { isError: true })
|
|
2117
|
+
)
|
|
2118
|
+
);
|
|
2119
|
+
}
|
|
2120
|
+
for (const c of listDirCalls) {
|
|
2121
|
+
const args = c.arguments ?? {};
|
|
2122
|
+
allPromises.push(
|
|
2123
|
+
toolListDirectory(provider, args).then(
|
|
2124
|
+
(p) => formatAgentToolOutput("list_directory", args, p, { isError: false }),
|
|
2125
|
+
(err) => formatAgentToolOutput("list_directory", args, String(err), { isError: true })
|
|
2126
|
+
)
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
for (const c of readCalls) {
|
|
2130
|
+
const args = c.arguments ?? {};
|
|
2131
|
+
allPromises.push(
|
|
2132
|
+
toolRead(provider, args).then(
|
|
2133
|
+
(p) => formatAgentToolOutput("read", args, p, { isError: false }),
|
|
2134
|
+
(err) => formatAgentToolOutput("read", args, String(err), { isError: true })
|
|
2135
|
+
)
|
|
2136
|
+
);
|
|
2137
|
+
}
|
|
2138
|
+
const toolExecStart = Date.now();
|
|
2139
|
+
const allResults = await Promise.all(allPromises);
|
|
2140
|
+
turnMetrics.local_tools_ms = Date.now() - toolExecStart;
|
|
2141
|
+
for (const result of allResults) {
|
|
2142
|
+
formatted.push(result);
|
|
2143
|
+
}
|
|
2144
|
+
if (formatted.length > 0) {
|
|
2145
|
+
const turnMessage = formatTurnMessage(turn, maxTurns);
|
|
2146
|
+
const contextBudget = calculateContextBudget(messages);
|
|
2147
|
+
messages.push({ role: "user", content: formatted.join("\n") + turnMessage + "\n" + contextBudget });
|
|
2148
|
+
}
|
|
2149
|
+
timings.turns.push(turnMetrics);
|
|
2150
|
+
if (finishCalls.length) {
|
|
2151
|
+
const fc = finishCalls[0];
|
|
2152
|
+
const files = fc.arguments?.files ?? [];
|
|
2153
|
+
finishMeta = { files };
|
|
2154
|
+
terminationReason = "completed";
|
|
2155
|
+
break;
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
if (terminationReason !== "completed" || !finishMeta) {
|
|
2159
|
+
timings.total_ms = Date.now() - totalStart;
|
|
2160
|
+
return { terminationReason, messages, errors, timings };
|
|
2161
|
+
}
|
|
2162
|
+
const parts = ["Relevant context found:"];
|
|
2163
|
+
for (const f of finishMeta.files) {
|
|
2164
|
+
const ranges = f.lines === "*" ? "*" : Array.isArray(f.lines) ? f.lines.map(([s, e]) => `${s}-${e}`).join(", ") : "*";
|
|
2165
|
+
parts.push(`- ${f.path}: ${ranges}`);
|
|
2166
|
+
}
|
|
2167
|
+
const payload = parts.join("\n");
|
|
2168
|
+
const finishResolutionStart = Date.now();
|
|
2169
|
+
const fileReadErrors = [];
|
|
2170
|
+
const resolved = await readFinishFiles(
|
|
2171
|
+
repoRoot,
|
|
2172
|
+
finishMeta.files,
|
|
2173
|
+
async (p, s, e) => {
|
|
2174
|
+
try {
|
|
2175
|
+
const rr = await provider.read({ path: p, start: s, end: e });
|
|
2176
|
+
return rr.lines.map((l) => {
|
|
2177
|
+
const idx = l.indexOf("|");
|
|
2178
|
+
return idx >= 0 ? l.slice(idx + 1) : l;
|
|
2179
|
+
});
|
|
2180
|
+
} catch (err) {
|
|
2181
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
2182
|
+
fileReadErrors.push({ path: p, error: errorMsg });
|
|
2183
|
+
console.error(`[warp_grep] Failed to read file: ${p} - ${errorMsg}`);
|
|
2184
|
+
return [`[couldn't find: ${p}]`];
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
);
|
|
2188
|
+
timings.finish_resolution_ms = Date.now() - finishResolutionStart;
|
|
2189
|
+
if (fileReadErrors.length > 0) {
|
|
2190
|
+
errors.push(...fileReadErrors.map((e) => ({ message: `File read error: ${e.path} - ${e.error}` })));
|
|
2191
|
+
}
|
|
2192
|
+
timings.total_ms = Date.now() - totalStart;
|
|
2193
|
+
return {
|
|
2194
|
+
terminationReason: "completed",
|
|
2195
|
+
messages,
|
|
2196
|
+
finish: { payload, metadata: finishMeta, resolved },
|
|
2197
|
+
timings
|
|
2198
|
+
};
|
|
2199
|
+
}
|
|
2050
2200
|
|
|
2051
2201
|
// tools/warp_grep/providers/local.ts
|
|
2052
2202
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
@@ -2640,43 +2790,23 @@ var WarpGrepClient = class {
|
|
|
2640
2790
|
retryConfig: config.retryConfig
|
|
2641
2791
|
};
|
|
2642
2792
|
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
* }
|
|
2661
|
-
* }
|
|
2662
|
-
* ```
|
|
2663
|
-
*/
|
|
2664
|
-
async execute(input) {
|
|
2665
|
-
return executeToolCall(
|
|
2666
|
-
{ query: input.query },
|
|
2667
|
-
{
|
|
2668
|
-
repoRoot: input.repoRoot,
|
|
2669
|
-
remoteCommands: input.remoteCommands,
|
|
2670
|
-
provider: input.provider,
|
|
2671
|
-
excludes: input.excludes,
|
|
2672
|
-
includes: input.includes,
|
|
2673
|
-
debug: input.debug ?? this.config.debug,
|
|
2674
|
-
morphApiKey: this.config.morphApiKey,
|
|
2675
|
-
morphApiUrl: this.config.morphApiUrl,
|
|
2676
|
-
retryConfig: this.config.retryConfig,
|
|
2677
|
-
timeout: this.config.timeout
|
|
2678
|
-
}
|
|
2679
|
-
);
|
|
2793
|
+
execute(input) {
|
|
2794
|
+
const toolConfig = {
|
|
2795
|
+
repoRoot: input.repoRoot,
|
|
2796
|
+
remoteCommands: input.remoteCommands,
|
|
2797
|
+
provider: input.provider,
|
|
2798
|
+
excludes: input.excludes,
|
|
2799
|
+
includes: input.includes,
|
|
2800
|
+
debug: input.debug ?? this.config.debug,
|
|
2801
|
+
morphApiKey: this.config.morphApiKey,
|
|
2802
|
+
morphApiUrl: this.config.morphApiUrl,
|
|
2803
|
+
retryConfig: this.config.retryConfig,
|
|
2804
|
+
timeout: this.config.timeout
|
|
2805
|
+
};
|
|
2806
|
+
if (input.streamSteps) {
|
|
2807
|
+
return executeToolCallStreaming({ query: input.query }, toolConfig);
|
|
2808
|
+
}
|
|
2809
|
+
return executeToolCall({ query: input.query }, toolConfig);
|
|
2680
2810
|
}
|
|
2681
2811
|
};
|
|
2682
2812
|
async function executeToolCall(input, config) {
|
|
@@ -2704,6 +2834,43 @@ async function executeToolCall(input, config) {
|
|
|
2704
2834
|
}));
|
|
2705
2835
|
return { success: true, contexts, summary: finish.payload };
|
|
2706
2836
|
}
|
|
2837
|
+
function processAgentResult(result) {
|
|
2838
|
+
const finish = result.finish;
|
|
2839
|
+
if (result.terminationReason !== "completed" || !finish?.metadata) {
|
|
2840
|
+
return { success: false, error: "Search did not complete" };
|
|
2841
|
+
}
|
|
2842
|
+
const contexts = (finish.resolved ?? []).map((r) => ({
|
|
2843
|
+
file: r.path,
|
|
2844
|
+
content: r.content
|
|
2845
|
+
}));
|
|
2846
|
+
return { success: true, contexts, summary: finish.payload };
|
|
2847
|
+
}
|
|
2848
|
+
async function* executeToolCallStreaming(input, config) {
|
|
2849
|
+
const parsed = typeof input === "string" ? JSON.parse(input) : input;
|
|
2850
|
+
const provider = config.remoteCommands ? new RemoteCommandsProvider(config.repoRoot, config.remoteCommands) : config.provider ?? new LocalRipgrepProvider(config.repoRoot, config.excludes);
|
|
2851
|
+
const generator = runWarpGrepStreaming({
|
|
2852
|
+
query: parsed.query,
|
|
2853
|
+
repoRoot: config.repoRoot,
|
|
2854
|
+
provider,
|
|
2855
|
+
excludes: config.excludes,
|
|
2856
|
+
includes: config.includes,
|
|
2857
|
+
debug: config.debug ?? false,
|
|
2858
|
+
morphApiKey: config.morphApiKey,
|
|
2859
|
+
morphApiUrl: config.morphApiUrl,
|
|
2860
|
+
retryConfig: config.retryConfig,
|
|
2861
|
+
timeout: config.timeout
|
|
2862
|
+
});
|
|
2863
|
+
let agentResult;
|
|
2864
|
+
for (; ; ) {
|
|
2865
|
+
const { value, done } = await generator.next();
|
|
2866
|
+
if (done) {
|
|
2867
|
+
agentResult = value;
|
|
2868
|
+
break;
|
|
2869
|
+
}
|
|
2870
|
+
yield value;
|
|
2871
|
+
}
|
|
2872
|
+
return processAgentResult(agentResult);
|
|
2873
|
+
}
|
|
2707
2874
|
function formatResult(result) {
|
|
2708
2875
|
if (!result.success) {
|
|
2709
2876
|
return `Search failed: ${result.error}`;
|