@morphllm/morphsdk 0.2.138 → 0.2.140
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-2UGM64A6.js +288 -0
- package/dist/chunk-2UGM64A6.js.map +1 -0
- package/dist/{chunk-ZOC7P5RV.js → chunk-4GCK5HBB.js} +2 -2
- package/dist/{chunk-QNXGYWS3.js → chunk-5TBKX7BU.js} +2 -2
- package/dist/{chunk-KHHSG2LO.js → chunk-7SJZSOHL.js} +4 -4
- package/dist/{chunk-QU5JVTYQ.js → chunk-A4EHCYHH.js} +2 -2
- package/dist/{chunk-QNX4PKPV.js → chunk-AKQSF324.js} +2 -2
- package/dist/{chunk-DOW7Y3AB.js → chunk-D6ABTGRU.js} +1 -1
- package/dist/chunk-DRGK45GP.js +265 -0
- package/dist/chunk-DRGK45GP.js.map +1 -0
- package/dist/{chunk-ZK5GJIAX.js → chunk-ECRKRLYL.js} +2 -2
- package/dist/{chunk-HP64WS73.js → chunk-GONXM4HR.js} +2 -2
- package/dist/{chunk-YOOALIAK.js → chunk-JOQU6S23.js} +4 -4
- package/dist/{chunk-CXSAPFUD.js → chunk-JXZASY3L.js} +21 -6
- package/dist/chunk-JXZASY3L.js.map +1 -0
- package/dist/{chunk-XLDP5S2P.js → chunk-LN5K5NTI.js} +2 -2
- package/dist/{chunk-P4FTR3X4.js → chunk-N5ZSTQ7H.js} +3 -3
- package/dist/{chunk-XIVAX3WB.js → chunk-NSA24AKY.js} +6 -6
- package/dist/{chunk-G5GPLD2E.js → chunk-NX5TNZUM.js} +2 -2
- package/dist/{chunk-IMYH4BD2.js → chunk-QTQOUDQ3.js} +5 -5
- package/dist/{chunk-2GSJGZYK.js → chunk-TQOC3LGM.js} +51 -21
- package/dist/{chunk-2GSJGZYK.js.map → chunk-TQOC3LGM.js.map} +1 -1
- package/dist/{chunk-S3CBEA3Y.js → chunk-UIBAKBGN.js} +4 -4
- package/dist/{chunk-KWFRPYUW.js → chunk-W4UQMCH3.js} +4 -4
- package/dist/{chunk-2PU5V3MK.js → chunk-W72VYYLC.js} +4 -4
- package/dist/{chunk-H7RABA4R.js → chunk-WECWVBX4.js} +2 -2
- package/dist/{chunk-GSOXKIQU.js → chunk-XOMV4AIH.js} +2 -2
- package/dist/{chunk-CUPT64F5.js → chunk-XQMAOAF2.js} +2 -2
- package/dist/{chunk-MDVFAW4F.js → chunk-ZTKJTCIG.js} +4 -4
- package/dist/chunk-ZZ25FZG2.js +73 -0
- package/dist/chunk-ZZ25FZG2.js.map +1 -0
- package/dist/{client-Ca7e11hJ.d.ts → client-B4fX3i7W.d.ts} +41 -0
- package/dist/client.cjs +644 -13
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +30 -27
- package/dist/edge.cjs +20 -5
- package/dist/edge.cjs.map +1 -1
- package/dist/edge.js +9 -9
- package/dist/index.cjs +647 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +37 -34
- package/dist/modelrouter/core.cjs +20 -5
- package/dist/modelrouter/core.cjs.map +1 -1
- package/dist/modelrouter/core.js +3 -3
- package/dist/modelrouter/index.cjs +20 -5
- package/dist/modelrouter/index.cjs.map +1 -1
- package/dist/modelrouter/index.js +3 -3
- package/dist/subagents/anthropic.cjs +2397 -0
- package/dist/subagents/anthropic.cjs.map +1 -0
- package/dist/subagents/anthropic.d.ts +41 -0
- package/dist/subagents/anthropic.js +19 -0
- package/dist/subagents/anthropic.js.map +1 -0
- package/dist/subagents/index.cjs +101 -0
- package/dist/subagents/index.cjs.map +1 -0
- package/dist/subagents/index.d.ts +5 -0
- package/dist/subagents/index.js +12 -0
- package/dist/subagents/index.js.map +1 -0
- package/dist/subagents/prompts.cjs +99 -0
- package/dist/subagents/prompts.cjs.map +1 -0
- package/dist/subagents/prompts.d.ts +42 -0
- package/dist/subagents/prompts.js +12 -0
- package/dist/subagents/prompts.js.map +1 -0
- package/dist/subagents/types.cjs +19 -0
- package/dist/subagents/types.cjs.map +1 -0
- package/dist/subagents/types.d.ts +93 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/types.js.map +1 -0
- package/dist/subagents/vercel.cjs +2374 -0
- package/dist/subagents/vercel.cjs.map +1 -0
- package/dist/subagents/vercel.d.ts +32 -0
- package/dist/subagents/vercel.js +19 -0
- package/dist/subagents/vercel.js.map +1 -0
- package/dist/tools/browser/anthropic.cjs +20 -5
- package/dist/tools/browser/anthropic.cjs.map +1 -1
- package/dist/tools/browser/anthropic.js +6 -6
- package/dist/tools/browser/core.cjs +20 -5
- package/dist/tools/browser/core.cjs.map +1 -1
- package/dist/tools/browser/core.js +5 -5
- package/dist/tools/browser/index.cjs +20 -5
- package/dist/tools/browser/index.cjs.map +1 -1
- package/dist/tools/browser/index.js +15 -15
- package/dist/tools/browser/openai.cjs +20 -5
- package/dist/tools/browser/openai.cjs.map +1 -1
- package/dist/tools/browser/openai.js +6 -6
- package/dist/tools/browser/profiles/core.cjs +20 -5
- 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 +20 -5
- 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 +20 -5
- package/dist/tools/browser/vercel.cjs.map +1 -1
- package/dist/tools/browser/vercel.js +6 -6
- package/dist/tools/codebase_search/anthropic.cjs +20 -5
- package/dist/tools/codebase_search/anthropic.cjs.map +1 -1
- package/dist/tools/codebase_search/anthropic.js +4 -4
- package/dist/tools/codebase_search/core.cjs +20 -5
- package/dist/tools/codebase_search/core.cjs.map +1 -1
- package/dist/tools/codebase_search/core.js +3 -3
- package/dist/tools/codebase_search/index.cjs +20 -5
- package/dist/tools/codebase_search/index.cjs.map +1 -1
- package/dist/tools/codebase_search/index.js +10 -10
- package/dist/tools/codebase_search/openai.cjs +20 -5
- package/dist/tools/codebase_search/openai.cjs.map +1 -1
- package/dist/tools/codebase_search/openai.js +4 -4
- package/dist/tools/codebase_search/vercel.cjs +20 -5
- package/dist/tools/codebase_search/vercel.cjs.map +1 -1
- package/dist/tools/codebase_search/vercel.js +4 -4
- package/dist/tools/fastapply/anthropic.cjs +20 -5
- package/dist/tools/fastapply/anthropic.cjs.map +1 -1
- package/dist/tools/fastapply/anthropic.js +4 -4
- package/dist/tools/fastapply/apply.cjs +20 -5
- package/dist/tools/fastapply/apply.cjs.map +1 -1
- package/dist/tools/fastapply/apply.js +2 -2
- package/dist/tools/fastapply/core.cjs +20 -5
- package/dist/tools/fastapply/core.cjs.map +1 -1
- package/dist/tools/fastapply/core.js +3 -3
- package/dist/tools/fastapply/index.cjs +20 -5
- package/dist/tools/fastapply/index.cjs.map +1 -1
- package/dist/tools/fastapply/index.js +8 -8
- package/dist/tools/fastapply/openai.cjs +20 -5
- package/dist/tools/fastapply/openai.cjs.map +1 -1
- package/dist/tools/fastapply/openai.js +4 -4
- package/dist/tools/fastapply/vercel.cjs +20 -5
- package/dist/tools/fastapply/vercel.cjs.map +1 -1
- package/dist/tools/fastapply/vercel.js +4 -4
- package/dist/tools/index.cjs +20 -5
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.js +8 -8
- package/dist/tools/utils/resilience.cjs +20 -5
- 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 +20 -5
- package/dist/tools/warp_grep/agent/runner.cjs.map +1 -1
- package/dist/tools/warp_grep/agent/runner.js +3 -3
- package/dist/tools/warp_grep/anthropic.cjs +20 -5
- package/dist/tools/warp_grep/anthropic.cjs.map +1 -1
- package/dist/tools/warp_grep/anthropic.js +6 -6
- package/dist/tools/warp_grep/client.cjs +20 -5
- package/dist/tools/warp_grep/client.cjs.map +1 -1
- package/dist/tools/warp_grep/client.js +5 -5
- package/dist/tools/warp_grep/gemini.cjs +20 -5
- package/dist/tools/warp_grep/gemini.cjs.map +1 -1
- package/dist/tools/warp_grep/gemini.js +5 -5
- package/dist/tools/warp_grep/harness.js +4 -4
- package/dist/tools/warp_grep/index.cjs +20 -5
- package/dist/tools/warp_grep/index.cjs.map +1 -1
- package/dist/tools/warp_grep/index.js +7 -7
- package/dist/tools/warp_grep/openai.cjs +20 -5
- package/dist/tools/warp_grep/openai.cjs.map +1 -1
- package/dist/tools/warp_grep/openai.js +6 -6
- package/dist/tools/warp_grep/vercel.cjs +20 -5
- package/dist/tools/warp_grep/vercel.cjs.map +1 -1
- package/dist/tools/warp_grep/vercel.js +6 -6
- package/dist/version.cjs +20 -5
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/package.json +20 -5
- package/dist/chunk-CXSAPFUD.js.map +0 -1
- /package/dist/{chunk-ZOC7P5RV.js.map → chunk-4GCK5HBB.js.map} +0 -0
- /package/dist/{chunk-QNXGYWS3.js.map → chunk-5TBKX7BU.js.map} +0 -0
- /package/dist/{chunk-KHHSG2LO.js.map → chunk-7SJZSOHL.js.map} +0 -0
- /package/dist/{chunk-QU5JVTYQ.js.map → chunk-A4EHCYHH.js.map} +0 -0
- /package/dist/{chunk-QNX4PKPV.js.map → chunk-AKQSF324.js.map} +0 -0
- /package/dist/{chunk-DOW7Y3AB.js.map → chunk-D6ABTGRU.js.map} +0 -0
- /package/dist/{chunk-ZK5GJIAX.js.map → chunk-ECRKRLYL.js.map} +0 -0
- /package/dist/{chunk-HP64WS73.js.map → chunk-GONXM4HR.js.map} +0 -0
- /package/dist/{chunk-YOOALIAK.js.map → chunk-JOQU6S23.js.map} +0 -0
- /package/dist/{chunk-XLDP5S2P.js.map → chunk-LN5K5NTI.js.map} +0 -0
- /package/dist/{chunk-P4FTR3X4.js.map → chunk-N5ZSTQ7H.js.map} +0 -0
- /package/dist/{chunk-XIVAX3WB.js.map → chunk-NSA24AKY.js.map} +0 -0
- /package/dist/{chunk-G5GPLD2E.js.map → chunk-NX5TNZUM.js.map} +0 -0
- /package/dist/{chunk-IMYH4BD2.js.map → chunk-QTQOUDQ3.js.map} +0 -0
- /package/dist/{chunk-S3CBEA3Y.js.map → chunk-UIBAKBGN.js.map} +0 -0
- /package/dist/{chunk-KWFRPYUW.js.map → chunk-W4UQMCH3.js.map} +0 -0
- /package/dist/{chunk-2PU5V3MK.js.map → chunk-W72VYYLC.js.map} +0 -0
- /package/dist/{chunk-H7RABA4R.js.map → chunk-WECWVBX4.js.map} +0 -0
- /package/dist/{chunk-GSOXKIQU.js.map → chunk-XOMV4AIH.js.map} +0 -0
- /package/dist/{chunk-CUPT64F5.js.map → chunk-XQMAOAF2.js.map} +0 -0
- /package/dist/{chunk-MDVFAW4F.js.map → chunk-ZTKJTCIG.js.map} +0 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WarpGrepClient,
|
|
3
|
+
formatResult
|
|
4
|
+
} from "./chunk-QTQOUDQ3.js";
|
|
5
|
+
import {
|
|
6
|
+
CODEBASE_SEARCH_TOOL,
|
|
7
|
+
SEND_MESSAGE_TOOL,
|
|
8
|
+
getSystemPrompt
|
|
9
|
+
} from "./chunk-ZZ25FZG2.js";
|
|
10
|
+
|
|
11
|
+
// subagents/anthropic.ts
|
|
12
|
+
var DEFAULT_MAX_TURNS = {
|
|
13
|
+
quick: 3,
|
|
14
|
+
medium: 6,
|
|
15
|
+
thorough: 12
|
|
16
|
+
};
|
|
17
|
+
function getMaxTurns(config) {
|
|
18
|
+
return config.maxTurns ?? DEFAULT_MAX_TURNS[config.thoroughness ?? "medium"] ?? 6;
|
|
19
|
+
}
|
|
20
|
+
var TOOLS = [
|
|
21
|
+
{
|
|
22
|
+
name: CODEBASE_SEARCH_TOOL.name,
|
|
23
|
+
description: CODEBASE_SEARCH_TOOL.description,
|
|
24
|
+
input_schema: CODEBASE_SEARCH_TOOL.input_schema
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: SEND_MESSAGE_TOOL.name,
|
|
28
|
+
description: SEND_MESSAGE_TOOL.description,
|
|
29
|
+
input_schema: SEND_MESSAGE_TOOL.input_schema
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
function createExploreSubagent(config) {
|
|
33
|
+
if (!config.repoRoot) {
|
|
34
|
+
throw new Error("repoRoot is required for Explore subagent");
|
|
35
|
+
}
|
|
36
|
+
const warpGrep = new WarpGrepClient({
|
|
37
|
+
morphApiKey: config.morphApiKey
|
|
38
|
+
});
|
|
39
|
+
const thoroughness = config.thoroughness ?? "medium";
|
|
40
|
+
const maxTurns = getMaxTurns(config);
|
|
41
|
+
const replyTimeout = config.replyTimeout ?? 3e4;
|
|
42
|
+
async function runExplore(prompt, callbacks = {}) {
|
|
43
|
+
const startTime = Date.now();
|
|
44
|
+
const allContexts = [];
|
|
45
|
+
let searchCount = 0;
|
|
46
|
+
const timeoutMs = config.timeout;
|
|
47
|
+
try {
|
|
48
|
+
const messages = [{ role: "user", content: prompt }];
|
|
49
|
+
let turns = 0;
|
|
50
|
+
while (turns < maxTurns) {
|
|
51
|
+
if (timeoutMs && Date.now() - startTime > timeoutMs) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
summary: "",
|
|
55
|
+
contexts: deduplicateContexts(allContexts),
|
|
56
|
+
searchCount,
|
|
57
|
+
durationMs: Date.now() - startTime,
|
|
58
|
+
error: `Exploration timed out after ${timeoutMs}ms`
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const response = await config.client.messages.create({
|
|
62
|
+
model: config.model,
|
|
63
|
+
max_tokens: 4096,
|
|
64
|
+
system: getSystemPrompt(thoroughness),
|
|
65
|
+
tools: TOOLS,
|
|
66
|
+
messages
|
|
67
|
+
});
|
|
68
|
+
turns++;
|
|
69
|
+
if (response.stop_reason === "end_turn" || !response.content.some((b) => b.type === "tool_use")) {
|
|
70
|
+
const textBlock = response.content.find((b) => b.type === "text");
|
|
71
|
+
const summary = textBlock?.text || "Exploration completed but no summary was generated.";
|
|
72
|
+
callbacks.onStep?.({
|
|
73
|
+
step: searchCount,
|
|
74
|
+
searchRequest: "",
|
|
75
|
+
contextsFound: allContexts.length,
|
|
76
|
+
isFinal: true
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
success: true,
|
|
80
|
+
summary,
|
|
81
|
+
contexts: deduplicateContexts(allContexts),
|
|
82
|
+
searchCount,
|
|
83
|
+
durationMs: Date.now() - startTime
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
messages.push({ role: "assistant", content: response.content });
|
|
87
|
+
const toolResults = [];
|
|
88
|
+
for (const block of response.content) {
|
|
89
|
+
if (block.type !== "tool_use") continue;
|
|
90
|
+
if (block.name === "codebase_search") {
|
|
91
|
+
searchCount++;
|
|
92
|
+
const input = block.input;
|
|
93
|
+
const warpResult = await warpGrep.execute({
|
|
94
|
+
searchTerm: input.searchRequest,
|
|
95
|
+
repoRoot: config.repoRoot,
|
|
96
|
+
excludes: config.excludes,
|
|
97
|
+
includes: config.includes
|
|
98
|
+
});
|
|
99
|
+
if (warpResult.contexts) {
|
|
100
|
+
allContexts.push(...warpResult.contexts);
|
|
101
|
+
}
|
|
102
|
+
callbacks.onStep?.({
|
|
103
|
+
step: searchCount,
|
|
104
|
+
searchRequest: input.searchRequest,
|
|
105
|
+
contextsFound: warpResult.contexts?.length ?? 0,
|
|
106
|
+
isFinal: false
|
|
107
|
+
});
|
|
108
|
+
toolResults.push({
|
|
109
|
+
type: "tool_result",
|
|
110
|
+
tool_use_id: block.id,
|
|
111
|
+
content: formatResult(warpResult)
|
|
112
|
+
});
|
|
113
|
+
} else if (block.name === "send_message") {
|
|
114
|
+
const input = block.input;
|
|
115
|
+
const subagentMsg = {
|
|
116
|
+
from: "explore",
|
|
117
|
+
content: input.message,
|
|
118
|
+
timestamp: Date.now()
|
|
119
|
+
};
|
|
120
|
+
let replyText = "";
|
|
121
|
+
if (callbacks.onMessage) {
|
|
122
|
+
replyText = await Promise.race([
|
|
123
|
+
new Promise((resolve) => {
|
|
124
|
+
callbacks.onMessage(subagentMsg, (text) => {
|
|
125
|
+
resolve(text);
|
|
126
|
+
});
|
|
127
|
+
}),
|
|
128
|
+
new Promise(
|
|
129
|
+
(resolve) => setTimeout(() => resolve(""), replyTimeout)
|
|
130
|
+
)
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
const toolResponse = replyText ? `Response from orchestrator: ${replyText}` : "No response. Continue with your best judgment.";
|
|
134
|
+
toolResults.push({
|
|
135
|
+
type: "tool_result",
|
|
136
|
+
tool_use_id: block.id,
|
|
137
|
+
content: toolResponse
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
messages.push({ role: "user", content: toolResults });
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
success: true,
|
|
145
|
+
summary: "Exploration completed (max turns reached).",
|
|
146
|
+
contexts: deduplicateContexts(allContexts),
|
|
147
|
+
searchCount,
|
|
148
|
+
durationMs: Date.now() - startTime
|
|
149
|
+
};
|
|
150
|
+
} catch (error) {
|
|
151
|
+
return {
|
|
152
|
+
success: false,
|
|
153
|
+
summary: "",
|
|
154
|
+
contexts: deduplicateContexts(allContexts),
|
|
155
|
+
searchCount,
|
|
156
|
+
durationMs: Date.now() - startTime,
|
|
157
|
+
error: error instanceof Error ? error.message : String(error)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const exploreTool = Object.assign(
|
|
162
|
+
{
|
|
163
|
+
name: "explore",
|
|
164
|
+
description: "Explore a codebase to answer questions about code structure, find implementations, trace call chains, and understand architecture. Returns a summary of findings.",
|
|
165
|
+
input_schema: {
|
|
166
|
+
type: "object",
|
|
167
|
+
properties: {
|
|
168
|
+
searchRequest: {
|
|
169
|
+
type: "string",
|
|
170
|
+
description: "What to explore in the codebase. Be specific about what you want to understand."
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
required: ["searchRequest"]
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
execute: async (input) => {
|
|
178
|
+
return runExplore(input.searchRequest);
|
|
179
|
+
},
|
|
180
|
+
formatResult: (result) => {
|
|
181
|
+
if (!result.success) {
|
|
182
|
+
return `Exploration failed: ${result.error}`;
|
|
183
|
+
}
|
|
184
|
+
return result.summary;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
return {
|
|
189
|
+
/** Anthropic Tool definition for use in parent agents */
|
|
190
|
+
tool: exploreTool,
|
|
191
|
+
/** Run exploration with messaging support */
|
|
192
|
+
run(prompt) {
|
|
193
|
+
const messageHandlers = [];
|
|
194
|
+
const stepHandlers = [];
|
|
195
|
+
let resultPromise = null;
|
|
196
|
+
const session = {
|
|
197
|
+
on(event, handler) {
|
|
198
|
+
if (event === "message") messageHandlers.push(handler);
|
|
199
|
+
if (event === "step") stepHandlers.push(handler);
|
|
200
|
+
return session;
|
|
201
|
+
},
|
|
202
|
+
send(_text) {
|
|
203
|
+
},
|
|
204
|
+
get result() {
|
|
205
|
+
if (!resultPromise) {
|
|
206
|
+
resultPromise = runExplore(prompt, {
|
|
207
|
+
onStep: (step) => {
|
|
208
|
+
for (const handler of stepHandlers) handler(step);
|
|
209
|
+
},
|
|
210
|
+
onMessage: (msg, reply) => {
|
|
211
|
+
if (messageHandlers.length > 0) {
|
|
212
|
+
for (const handler of messageHandlers) handler(msg, reply);
|
|
213
|
+
} else {
|
|
214
|
+
reply("");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return resultPromise;
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
return session;
|
|
223
|
+
},
|
|
224
|
+
/** Stream exploration events as an async generator */
|
|
225
|
+
async *stream(prompt) {
|
|
226
|
+
const events = [];
|
|
227
|
+
let resolveNext = null;
|
|
228
|
+
let done = false;
|
|
229
|
+
const resultPromise = runExplore(prompt, {
|
|
230
|
+
onStep: (step) => {
|
|
231
|
+
events.push({
|
|
232
|
+
type: "step",
|
|
233
|
+
step: step.step,
|
|
234
|
+
searchRequest: step.searchRequest,
|
|
235
|
+
contextsFound: step.contextsFound,
|
|
236
|
+
isFinal: step.isFinal
|
|
237
|
+
});
|
|
238
|
+
resolveNext?.();
|
|
239
|
+
},
|
|
240
|
+
onMessage: (msg, reply) => {
|
|
241
|
+
events.push({
|
|
242
|
+
type: "message",
|
|
243
|
+
from: msg.from,
|
|
244
|
+
content: msg.content,
|
|
245
|
+
timestamp: msg.timestamp
|
|
246
|
+
});
|
|
247
|
+
resolveNext?.();
|
|
248
|
+
reply("Continue with your best judgment.");
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
while (!done) {
|
|
252
|
+
if (events.length > 0) {
|
|
253
|
+
yield events.shift();
|
|
254
|
+
} else {
|
|
255
|
+
const raceResult = await Promise.race([
|
|
256
|
+
resultPromise.then((r) => ({ type: "done", result: r })),
|
|
257
|
+
new Promise((resolve) => {
|
|
258
|
+
resolveNext = () => resolve({ type: "event" });
|
|
259
|
+
})
|
|
260
|
+
]);
|
|
261
|
+
if (raceResult.type === "done") {
|
|
262
|
+
while (events.length > 0) {
|
|
263
|
+
yield events.shift();
|
|
264
|
+
}
|
|
265
|
+
done = true;
|
|
266
|
+
return raceResult.result;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return await resultPromise;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
function deduplicateContexts(contexts) {
|
|
275
|
+
const map = /* @__PURE__ */ new Map();
|
|
276
|
+
for (const ctx of contexts) {
|
|
277
|
+
const existing = map.get(ctx.file);
|
|
278
|
+
if (!existing || ctx.content.length > existing.content.length) {
|
|
279
|
+
map.set(ctx.file, ctx);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return Array.from(map.values());
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export {
|
|
286
|
+
createExploreSubagent
|
|
287
|
+
};
|
|
288
|
+
//# sourceMappingURL=chunk-2UGM64A6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../subagents/anthropic.ts"],"sourcesContent":["/**\n * Anthropic SDK adapter for Explore subagent\n */\n\nimport type { Tool } from '@anthropic-ai/sdk/resources/messages';\nimport { WarpGrepClient } from '../tools/warp_grep/client.js';\nimport { formatResult } from '../tools/warp_grep/client.js';\nimport type { WarpGrepContext } from '../tools/warp_grep/types.js';\nimport { getSystemPrompt, CODEBASE_SEARCH_TOOL, SEND_MESSAGE_TOOL } from './prompts.js';\nimport type {\n ExploreSubagentConfig,\n ExploreResult,\n ExploreStep,\n ExploreSession,\n ExploreEvent,\n SubagentMessage,\n MessageHandler,\n StepHandler,\n} from './types.js';\n\n/** Config for Anthropic SDK Explore subagent */\nexport interface AnthropicExploreConfig extends ExploreSubagentConfig {\n /** Anthropic SDK client instance */\n client: AnthropicClient;\n /** Model name (e.g., 'claude-haiku-4-5-20251001') */\n model: string;\n}\n\n/** Minimal Anthropic client interface — avoids hard dependency on @anthropic-ai/sdk */\ninterface AnthropicClient {\n messages: {\n create(params: any): Promise<any>;\n };\n}\n\nconst DEFAULT_MAX_TURNS: Record<string, number> = {\n quick: 3,\n medium: 6,\n thorough: 12,\n};\n\nfunction getMaxTurns(config: ExploreSubagentConfig): number {\n return config.maxTurns ?? DEFAULT_MAX_TURNS[config.thoroughness ?? 'medium'] ?? 6;\n}\n\n/** Anthropic tool definitions */\nconst TOOLS: Tool[] = [\n {\n name: CODEBASE_SEARCH_TOOL.name,\n description: CODEBASE_SEARCH_TOOL.description,\n input_schema: CODEBASE_SEARCH_TOOL.input_schema,\n },\n {\n name: SEND_MESSAGE_TOOL.name,\n description: SEND_MESSAGE_TOOL.description,\n input_schema: SEND_MESSAGE_TOOL.input_schema,\n },\n];\n\n/**\n * Create an Explore subagent using the Anthropic SDK\n */\nexport function createExploreSubagent(config: AnthropicExploreConfig) {\n if (!config.repoRoot) {\n throw new Error('repoRoot is required for Explore subagent');\n }\n\n const warpGrep = new WarpGrepClient({\n morphApiKey: config.morphApiKey,\n });\n\n const thoroughness = config.thoroughness ?? 'medium';\n const maxTurns = getMaxTurns(config);\n const replyTimeout = config.replyTimeout ?? 30_000;\n\n /** Run the agent loop and collect results */\n async function runExplore(\n prompt: string,\n callbacks: {\n onStep?: StepHandler;\n onMessage?: MessageHandler;\n } = {},\n ): Promise<ExploreResult> {\n const startTime = Date.now();\n const allContexts: WarpGrepContext[] = [];\n let searchCount = 0;\n\n const timeoutMs = config.timeout;\n\n try {\n const messages: any[] = [{ role: 'user', content: prompt }];\n let turns = 0;\n\n while (turns < maxTurns) {\n // Check timeout\n if (timeoutMs && Date.now() - startTime > timeoutMs) {\n return {\n success: false,\n summary: '',\n contexts: deduplicateContexts(allContexts),\n searchCount,\n durationMs: Date.now() - startTime,\n error: `Exploration timed out after ${timeoutMs}ms`,\n };\n }\n\n const response = await config.client.messages.create({\n model: config.model,\n max_tokens: 4096,\n system: getSystemPrompt(thoroughness),\n tools: TOOLS,\n messages,\n });\n\n turns++;\n\n // Check if the model is done (no tool use)\n if (response.stop_reason === 'end_turn' || !response.content.some((b: any) => b.type === 'tool_use')) {\n const textBlock = response.content.find((b: any) => b.type === 'text');\n const summary = textBlock?.text || 'Exploration completed but no summary was generated.';\n\n callbacks.onStep?.({\n step: searchCount,\n searchRequest: '',\n contextsFound: allContexts.length,\n isFinal: true,\n });\n\n return {\n success: true,\n summary,\n contexts: deduplicateContexts(allContexts),\n searchCount,\n durationMs: Date.now() - startTime,\n };\n }\n\n // Process tool calls\n messages.push({ role: 'assistant', content: response.content });\n\n const toolResults: any[] = [];\n\n for (const block of response.content) {\n if (block.type !== 'tool_use') continue;\n\n if (block.name === 'codebase_search') {\n searchCount++;\n const input = block.input as { searchRequest: string };\n\n const warpResult = await warpGrep.execute({\n searchTerm: input.searchRequest,\n repoRoot: config.repoRoot,\n excludes: config.excludes,\n includes: config.includes,\n });\n\n if (warpResult.contexts) {\n allContexts.push(...warpResult.contexts);\n }\n\n callbacks.onStep?.({\n step: searchCount,\n searchRequest: input.searchRequest,\n contextsFound: warpResult.contexts?.length ?? 0,\n isFinal: false,\n });\n\n toolResults.push({\n type: 'tool_result',\n tool_use_id: block.id,\n content: formatResult(warpResult),\n });\n } else if (block.name === 'send_message') {\n const input = block.input as { message: string };\n\n const subagentMsg: SubagentMessage = {\n from: 'explore',\n content: input.message,\n timestamp: Date.now(),\n };\n\n let replyText = '';\n\n if (callbacks.onMessage) {\n // Wait for reply with timeout\n replyText = await Promise.race([\n new Promise<string>((resolve) => {\n callbacks.onMessage!(subagentMsg, (text: string) => {\n resolve(text);\n });\n }),\n new Promise<string>((resolve) =>\n setTimeout(() => resolve(''), replyTimeout),\n ),\n ]);\n }\n\n const toolResponse = replyText\n ? `Response from orchestrator: ${replyText}`\n : 'No response. Continue with your best judgment.';\n\n toolResults.push({\n type: 'tool_result',\n tool_use_id: block.id,\n content: toolResponse,\n });\n }\n }\n\n messages.push({ role: 'user', content: toolResults });\n }\n\n // Ran out of turns — extract what we have\n return {\n success: true,\n summary: 'Exploration completed (max turns reached).',\n contexts: deduplicateContexts(allContexts),\n searchCount,\n durationMs: Date.now() - startTime,\n };\n } catch (error) {\n return {\n success: false,\n summary: '',\n contexts: deduplicateContexts(allContexts),\n searchCount,\n durationMs: Date.now() - startTime,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n /** Anthropic Tool definition for use in parent agents */\n const exploreTool: Tool & {\n execute: (input: { searchRequest: string }) => Promise<ExploreResult>;\n formatResult: (result: ExploreResult) => string;\n } = Object.assign(\n {\n name: 'explore',\n description:\n 'Explore a codebase to answer questions about code structure, find implementations, trace call chains, and understand architecture. Returns a summary of findings.',\n input_schema: {\n type: 'object' as const,\n properties: {\n searchRequest: {\n type: 'string' as const,\n description: 'What to explore in the codebase. Be specific about what you want to understand.',\n },\n },\n required: ['searchRequest'] as const,\n },\n },\n {\n execute: async (input: { searchRequest: string }): Promise<ExploreResult> => {\n return runExplore(input.searchRequest);\n },\n formatResult: (result: ExploreResult): string => {\n if (!result.success) {\n return `Exploration failed: ${result.error}`;\n }\n return result.summary;\n },\n },\n );\n\n return {\n /** Anthropic Tool definition for use in parent agents */\n tool: exploreTool,\n\n /** Run exploration with messaging support */\n run(prompt: string): ExploreSession {\n const messageHandlers: MessageHandler[] = [];\n const stepHandlers: StepHandler[] = [];\n\n let resultPromise: Promise<ExploreResult> | null = null;\n\n const session: ExploreSession = {\n on(event: string, handler: any) {\n if (event === 'message') messageHandlers.push(handler);\n if (event === 'step') stepHandlers.push(handler);\n return session;\n },\n send(_text: string) {\n // Convenience method — pause-and-ask flow uses the reply callback\n },\n get result() {\n if (!resultPromise) {\n resultPromise = runExplore(prompt, {\n onStep: (step) => {\n for (const handler of stepHandlers) handler(step);\n },\n onMessage: (msg, reply) => {\n if (messageHandlers.length > 0) {\n for (const handler of messageHandlers) handler(msg, reply);\n } else {\n reply('');\n }\n },\n });\n }\n return resultPromise;\n },\n };\n\n return session;\n },\n\n /** Stream exploration events as an async generator */\n async *stream(prompt: string): AsyncGenerator<ExploreEvent, ExploreResult, undefined> {\n const events: ExploreEvent[] = [];\n let resolveNext: (() => void) | null = null;\n let done = false;\n\n const resultPromise = runExplore(prompt, {\n onStep: (step) => {\n events.push({\n type: 'step',\n step: step.step,\n searchRequest: step.searchRequest,\n contextsFound: step.contextsFound,\n isFinal: step.isFinal,\n });\n resolveNext?.();\n },\n onMessage: (msg, reply) => {\n events.push({\n type: 'message',\n from: msg.from,\n content: msg.content,\n timestamp: msg.timestamp,\n });\n resolveNext?.();\n reply('Continue with your best judgment.');\n },\n });\n\n while (!done) {\n if (events.length > 0) {\n yield events.shift()!;\n } else {\n const raceResult = await Promise.race([\n resultPromise.then((r) => ({ type: 'done' as const, result: r })),\n new Promise<{ type: 'event' }>((resolve) => {\n resolveNext = () => resolve({ type: 'event' });\n }),\n ]);\n\n if (raceResult.type === 'done') {\n while (events.length > 0) {\n yield events.shift()!;\n }\n done = true;\n return raceResult.result;\n }\n }\n }\n\n return await resultPromise;\n },\n };\n}\n\n/** Deduplicate contexts, keeping the latest version of each file */\nfunction deduplicateContexts(contexts: WarpGrepContext[]): WarpGrepContext[] {\n const map = new Map<string, WarpGrepContext>();\n for (const ctx of contexts) {\n const existing = map.get(ctx.file);\n if (!existing || ctx.content.length > existing.content.length) {\n map.set(ctx.file, ctx);\n }\n }\n return Array.from(map.values());\n}\n"],"mappings":";;;;;;;;;;;AAmCA,IAAM,oBAA4C;AAAA,EAChD,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,UAAU;AACZ;AAEA,SAAS,YAAY,QAAuC;AAC1D,SAAO,OAAO,YAAY,kBAAkB,OAAO,gBAAgB,QAAQ,KAAK;AAClF;AAGA,IAAM,QAAgB;AAAA,EACpB;AAAA,IACE,MAAM,qBAAqB;AAAA,IAC3B,aAAa,qBAAqB;AAAA,IAClC,cAAc,qBAAqB;AAAA,EACrC;AAAA,EACA;AAAA,IACE,MAAM,kBAAkB;AAAA,IACxB,aAAa,kBAAkB;AAAA,IAC/B,cAAc,kBAAkB;AAAA,EAClC;AACF;AAKO,SAAS,sBAAsB,QAAgC;AACpE,MAAI,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,2CAA2C;AAAA,EAC7D;AAEA,QAAM,WAAW,IAAI,eAAe;AAAA,IAClC,aAAa,OAAO;AAAA,EACtB,CAAC;AAED,QAAM,eAAe,OAAO,gBAAgB;AAC5C,QAAM,WAAW,YAAY,MAAM;AACnC,QAAM,eAAe,OAAO,gBAAgB;AAG5C,iBAAe,WACb,QACA,YAGI,CAAC,GACmB;AACxB,UAAM,YAAY,KAAK,IAAI;AAC3B,UAAM,cAAiC,CAAC;AACxC,QAAI,cAAc;AAElB,UAAM,YAAY,OAAO;AAEzB,QAAI;AACF,YAAM,WAAkB,CAAC,EAAE,MAAM,QAAQ,SAAS,OAAO,CAAC;AAC1D,UAAI,QAAQ;AAEZ,aAAO,QAAQ,UAAU;AA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;AAAA,QACF;AAAA,MACF;AAEA,aAAO,MAAM;AAAA,IACf;AAAA,EACF;AACF;AAGA,SAAS,oBAAoB,UAAgD;AAC3E,QAAM,MAAM,oBAAI,IAA6B;AAC7C,aAAW,OAAO,UAAU;AAC1B,UAAM,WAAW,IAAI,IAAI,IAAI,IAAI;AACjC,QAAI,CAAC,YAAY,IAAI,QAAQ,SAAS,SAAS,QAAQ,QAAQ;AAC7D,UAAI,IAAI,IAAI,MAAM,GAAG;AAAA,IACvB;AAAA,EACF;AACA,SAAO,MAAM,KAAK,IAAI,OAAO,CAAC;AAChC;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SDK_VERSION
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-JXZASY3L.js";
|
|
4
4
|
|
|
5
5
|
// tools/fastapply/apply.ts
|
|
6
6
|
import { createTwoFilesPatch } from "diff";
|
|
@@ -116,4 +116,4 @@ export {
|
|
|
116
116
|
callMorphAPI,
|
|
117
117
|
applyEdit
|
|
118
118
|
};
|
|
119
|
-
//# sourceMappingURL=chunk-
|
|
119
|
+
//# sourceMappingURL=chunk-4GCK5HBB.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fetchWithRetry,
|
|
3
3
|
withTimeout
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-XOMV4AIH.js";
|
|
5
5
|
|
|
6
6
|
// modelrouter/core.ts
|
|
7
7
|
var DEFAULT_CONFIG = {
|
|
@@ -209,4 +209,4 @@ export {
|
|
|
209
209
|
GeminiRouter,
|
|
210
210
|
RawRouter
|
|
211
211
|
};
|
|
212
|
-
//# sourceMappingURL=chunk-
|
|
212
|
+
//# sourceMappingURL=chunk-5TBKX7BU.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
executeCodebaseSearch
|
|
3
|
+
} from "./chunk-NX5TNZUM.js";
|
|
1
4
|
import {
|
|
2
5
|
CODEBASE_SEARCH_DESCRIPTION
|
|
3
6
|
} from "./chunk-YQMPVJ2L.js";
|
|
4
|
-
import {
|
|
5
|
-
executeCodebaseSearch
|
|
6
|
-
} from "./chunk-G5GPLD2E.js";
|
|
7
7
|
|
|
8
8
|
// tools/codebase_search/vercel.ts
|
|
9
9
|
import { tool } from "ai";
|
|
@@ -55,4 +55,4 @@ export {
|
|
|
55
55
|
getSystemPrompt,
|
|
56
56
|
vercel_default
|
|
57
57
|
};
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
58
|
+
//# sourceMappingURL=chunk-7SJZSOHL.js.map
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
executeToolCall,
|
|
15
15
|
formatGitHubReadFileResult,
|
|
16
16
|
formatResult
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-QTQOUDQ3.js";
|
|
18
18
|
|
|
19
19
|
// tools/warp_grep/anthropic.ts
|
|
20
20
|
var INPUT_SCHEMA = {
|
|
@@ -90,4 +90,4 @@ export {
|
|
|
90
90
|
createGitHubSearchTool,
|
|
91
91
|
createGitHubReadFileTool
|
|
92
92
|
};
|
|
93
|
-
//# sourceMappingURL=chunk-
|
|
93
|
+
//# sourceMappingURL=chunk-A4EHCYHH.js.map
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-2HMEZZKK.js";
|
|
4
4
|
import {
|
|
5
5
|
executeBrowserTask
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-N5ZSTQ7H.js";
|
|
7
7
|
import {
|
|
8
8
|
__export
|
|
9
9
|
} from "./chunk-PZ5AY32C.js";
|
|
@@ -54,4 +54,4 @@ export {
|
|
|
54
54
|
browserTool,
|
|
55
55
|
vercel_exports
|
|
56
56
|
};
|
|
57
|
-
//# sourceMappingURL=chunk-
|
|
57
|
+
//# sourceMappingURL=chunk-AKQSF324.js.map
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WarpGrepClient,
|
|
3
|
+
formatResult
|
|
4
|
+
} from "./chunk-QTQOUDQ3.js";
|
|
5
|
+
import {
|
|
6
|
+
CODEBASE_SEARCH_TOOL,
|
|
7
|
+
SEND_MESSAGE_TOOL,
|
|
8
|
+
getSystemPrompt
|
|
9
|
+
} from "./chunk-ZZ25FZG2.js";
|
|
10
|
+
|
|
11
|
+
// subagents/vercel.ts
|
|
12
|
+
import { tool, generateText, stepCountIs } from "ai";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
var DEFAULT_MAX_TURNS = {
|
|
15
|
+
quick: 3,
|
|
16
|
+
medium: 6,
|
|
17
|
+
thorough: 12
|
|
18
|
+
};
|
|
19
|
+
function getMaxTurns(config) {
|
|
20
|
+
return config.maxTurns ?? DEFAULT_MAX_TURNS[config.thoroughness ?? "medium"] ?? 6;
|
|
21
|
+
}
|
|
22
|
+
function createExploreSubagent(config) {
|
|
23
|
+
if (!config.repoRoot) {
|
|
24
|
+
throw new Error("repoRoot is required for Explore subagent");
|
|
25
|
+
}
|
|
26
|
+
const warpGrep = new WarpGrepClient({
|
|
27
|
+
morphApiKey: config.morphApiKey
|
|
28
|
+
});
|
|
29
|
+
const thoroughness = config.thoroughness ?? "medium";
|
|
30
|
+
const replyTimeout = config.replyTimeout ?? 3e4;
|
|
31
|
+
async function runExplore(prompt, callbacks = {}) {
|
|
32
|
+
const startTime = Date.now();
|
|
33
|
+
const allContexts = [];
|
|
34
|
+
let searchCount = 0;
|
|
35
|
+
const timeoutMs = config.timeout;
|
|
36
|
+
const timeoutPromise = timeoutMs ? new Promise(
|
|
37
|
+
(_, reject) => setTimeout(() => reject(new Error(`Exploration timed out after ${timeoutMs}ms`)), timeoutMs)
|
|
38
|
+
) : null;
|
|
39
|
+
const runPromise = (async () => {
|
|
40
|
+
try {
|
|
41
|
+
const codebaseSearchSchema = z.object({
|
|
42
|
+
searchRequest: z.string().describe("Natural language description of what to search for")
|
|
43
|
+
});
|
|
44
|
+
const sendMessageSchema = z.object({
|
|
45
|
+
message: z.string().describe("The message to send to the orchestrator")
|
|
46
|
+
});
|
|
47
|
+
const result = await generateText({
|
|
48
|
+
model: config.model,
|
|
49
|
+
system: getSystemPrompt(thoroughness),
|
|
50
|
+
prompt,
|
|
51
|
+
tools: {
|
|
52
|
+
codebase_search: tool({
|
|
53
|
+
description: CODEBASE_SEARCH_TOOL.description,
|
|
54
|
+
inputSchema: codebaseSearchSchema,
|
|
55
|
+
execute: async (params) => {
|
|
56
|
+
searchCount++;
|
|
57
|
+
const warpResult = await warpGrep.execute({
|
|
58
|
+
searchTerm: params.searchRequest,
|
|
59
|
+
repoRoot: config.repoRoot,
|
|
60
|
+
excludes: config.excludes,
|
|
61
|
+
includes: config.includes
|
|
62
|
+
});
|
|
63
|
+
if (warpResult.contexts) {
|
|
64
|
+
allContexts.push(...warpResult.contexts);
|
|
65
|
+
}
|
|
66
|
+
callbacks.onStep?.({
|
|
67
|
+
step: searchCount,
|
|
68
|
+
searchRequest: params.searchRequest,
|
|
69
|
+
contextsFound: warpResult.contexts?.length ?? 0,
|
|
70
|
+
isFinal: false
|
|
71
|
+
});
|
|
72
|
+
return formatResult(warpResult);
|
|
73
|
+
}
|
|
74
|
+
}),
|
|
75
|
+
send_message: tool({
|
|
76
|
+
description: SEND_MESSAGE_TOOL.description,
|
|
77
|
+
inputSchema: sendMessageSchema,
|
|
78
|
+
execute: async (params) => {
|
|
79
|
+
const subagentMsg = {
|
|
80
|
+
from: "explore",
|
|
81
|
+
content: params.message,
|
|
82
|
+
timestamp: Date.now()
|
|
83
|
+
};
|
|
84
|
+
const replyPromise = new Promise((resolve) => {
|
|
85
|
+
if (callbacks.onMessage) {
|
|
86
|
+
callbacks.onMessage(subagentMsg, (replyText) => {
|
|
87
|
+
resolve(replyText);
|
|
88
|
+
});
|
|
89
|
+
} else {
|
|
90
|
+
setTimeout(() => resolve(""), replyTimeout);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const reply = await Promise.race([
|
|
94
|
+
replyPromise,
|
|
95
|
+
new Promise(
|
|
96
|
+
(resolve) => setTimeout(() => resolve(""), replyTimeout)
|
|
97
|
+
)
|
|
98
|
+
]);
|
|
99
|
+
if (reply) {
|
|
100
|
+
return `Response from orchestrator: ${reply}`;
|
|
101
|
+
}
|
|
102
|
+
return "No response. Continue with your best judgment.";
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
stopWhen: stepCountIs(getMaxTurns(config))
|
|
107
|
+
});
|
|
108
|
+
callbacks.onStep?.({
|
|
109
|
+
step: searchCount,
|
|
110
|
+
searchRequest: "",
|
|
111
|
+
contextsFound: allContexts.length,
|
|
112
|
+
isFinal: true
|
|
113
|
+
});
|
|
114
|
+
const uniqueContexts = deduplicateContexts(allContexts);
|
|
115
|
+
return {
|
|
116
|
+
success: true,
|
|
117
|
+
summary: result.text || "Exploration completed but no summary was generated.",
|
|
118
|
+
contexts: uniqueContexts,
|
|
119
|
+
searchCount,
|
|
120
|
+
durationMs: Date.now() - startTime
|
|
121
|
+
};
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return {
|
|
124
|
+
success: false,
|
|
125
|
+
summary: "",
|
|
126
|
+
contexts: deduplicateContexts(allContexts),
|
|
127
|
+
searchCount,
|
|
128
|
+
durationMs: Date.now() - startTime,
|
|
129
|
+
error: error instanceof Error ? error.message : String(error)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
})();
|
|
133
|
+
if (timeoutPromise) {
|
|
134
|
+
try {
|
|
135
|
+
return await Promise.race([runPromise, timeoutPromise]);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
summary: "",
|
|
140
|
+
contexts: deduplicateContexts(allContexts),
|
|
141
|
+
searchCount,
|
|
142
|
+
durationMs: Date.now() - startTime,
|
|
143
|
+
error: error instanceof Error ? error.message : String(error)
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return runPromise;
|
|
148
|
+
}
|
|
149
|
+
const exploreToolSchema = z.object({
|
|
150
|
+
searchRequest: z.string().describe("What to explore in the codebase. Be specific about what you want to understand.")
|
|
151
|
+
});
|
|
152
|
+
const exploreTool = tool({
|
|
153
|
+
description: "Explore a codebase to answer questions about code structure, find implementations, trace call chains, and understand architecture. Returns a summary of findings. Use this for broad exploration rather than pinpoint keyword searches.",
|
|
154
|
+
inputSchema: exploreToolSchema,
|
|
155
|
+
execute: async (params) => {
|
|
156
|
+
const result = await runExplore(params.searchRequest);
|
|
157
|
+
return {
|
|
158
|
+
success: result.success,
|
|
159
|
+
summary: result.summary,
|
|
160
|
+
searchCount: result.searchCount,
|
|
161
|
+
error: result.error
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
/** Vercel AI SDK tool for use as a tool in parent agents */
|
|
167
|
+
tool: exploreTool,
|
|
168
|
+
/** Run exploration with messaging support */
|
|
169
|
+
run(prompt) {
|
|
170
|
+
const messageHandlers = [];
|
|
171
|
+
const stepHandlers = [];
|
|
172
|
+
let resultPromise = null;
|
|
173
|
+
const session = {
|
|
174
|
+
on(event, handler) {
|
|
175
|
+
if (event === "message") messageHandlers.push(handler);
|
|
176
|
+
if (event === "step") stepHandlers.push(handler);
|
|
177
|
+
return session;
|
|
178
|
+
},
|
|
179
|
+
send(_text) {
|
|
180
|
+
},
|
|
181
|
+
get result() {
|
|
182
|
+
if (!resultPromise) {
|
|
183
|
+
resultPromise = runExplore(prompt, {
|
|
184
|
+
onStep: (step) => {
|
|
185
|
+
for (const handler of stepHandlers) handler(step);
|
|
186
|
+
},
|
|
187
|
+
onMessage: (msg, reply) => {
|
|
188
|
+
if (messageHandlers.length > 0) {
|
|
189
|
+
for (const handler of messageHandlers) handler(msg, reply);
|
|
190
|
+
} else {
|
|
191
|
+
reply("");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
return resultPromise;
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
return session;
|
|
200
|
+
},
|
|
201
|
+
/** Stream exploration events as an async generator */
|
|
202
|
+
async *stream(prompt) {
|
|
203
|
+
const events = [];
|
|
204
|
+
let resolveNext = null;
|
|
205
|
+
let done = false;
|
|
206
|
+
const resultPromise = runExplore(prompt, {
|
|
207
|
+
onStep: (step) => {
|
|
208
|
+
events.push({
|
|
209
|
+
type: "step",
|
|
210
|
+
step: step.step,
|
|
211
|
+
searchRequest: step.searchRequest,
|
|
212
|
+
contextsFound: step.contextsFound,
|
|
213
|
+
isFinal: step.isFinal
|
|
214
|
+
});
|
|
215
|
+
resolveNext?.();
|
|
216
|
+
},
|
|
217
|
+
onMessage: (msg, reply) => {
|
|
218
|
+
events.push({
|
|
219
|
+
type: "message",
|
|
220
|
+
from: msg.from,
|
|
221
|
+
content: msg.content,
|
|
222
|
+
timestamp: msg.timestamp
|
|
223
|
+
});
|
|
224
|
+
resolveNext?.();
|
|
225
|
+
reply("Continue with your best judgment.");
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
while (!done) {
|
|
229
|
+
if (events.length > 0) {
|
|
230
|
+
yield events.shift();
|
|
231
|
+
} else {
|
|
232
|
+
const raceResult = await Promise.race([
|
|
233
|
+
resultPromise.then((r) => ({ type: "done", result: r })),
|
|
234
|
+
new Promise((resolve) => {
|
|
235
|
+
resolveNext = () => resolve({ type: "event" });
|
|
236
|
+
})
|
|
237
|
+
]);
|
|
238
|
+
if (raceResult.type === "done") {
|
|
239
|
+
while (events.length > 0) {
|
|
240
|
+
yield events.shift();
|
|
241
|
+
}
|
|
242
|
+
done = true;
|
|
243
|
+
return raceResult.result;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return await resultPromise;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
function deduplicateContexts(contexts) {
|
|
252
|
+
const map = /* @__PURE__ */ new Map();
|
|
253
|
+
for (const ctx of contexts) {
|
|
254
|
+
const existing = map.get(ctx.file);
|
|
255
|
+
if (!existing || ctx.content.length > existing.content.length) {
|
|
256
|
+
map.set(ctx.file, ctx);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return Array.from(map.values());
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export {
|
|
263
|
+
createExploreSubagent
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=chunk-DRGK45GP.js.map
|