maestro-agent-sdk 0.1.0
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/LICENSE +21 -0
- package/NOTICE +24 -0
- package/README.md +133 -0
- package/dist/agents/contracts.d.ts +49 -0
- package/dist/agents/contracts.d.ts.map +1 -0
- package/dist/agents/contracts.js +2 -0
- package/dist/agents/contracts.js.map +1 -0
- package/dist/agents/rollout/shared.d.ts +24 -0
- package/dist/agents/rollout/shared.d.ts.map +1 -0
- package/dist/agents/rollout/shared.js +105 -0
- package/dist/agents/rollout/shared.js.map +1 -0
- package/dist/core/agent.d.ts +71 -0
- package/dist/core/agent.d.ts.map +1 -0
- package/dist/core/agent.js +22 -0
- package/dist/core/agent.js.map +1 -0
- package/dist/core/loop.d.ts +26 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +317 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +79 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +176 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/pool-cache.d.ts +103 -0
- package/dist/mcp/pool-cache.d.ts.map +1 -0
- package/dist/mcp/pool-cache.js +249 -0
- package/dist/mcp/pool-cache.js.map +1 -0
- package/dist/mcp/pool.d.ts +65 -0
- package/dist/mcp/pool.d.ts.map +1 -0
- package/dist/mcp/pool.js +86 -0
- package/dist/mcp/pool.js.map +1 -0
- package/dist/media/file-events.d.ts +8 -0
- package/dist/media/file-events.d.ts.map +1 -0
- package/dist/media/file-events.js +15 -0
- package/dist/media/file-events.js.map +1 -0
- package/dist/memory/active-task-template.d.ts +34 -0
- package/dist/memory/active-task-template.d.ts.map +1 -0
- package/dist/memory/active-task-template.js +63 -0
- package/dist/memory/active-task-template.js.map +1 -0
- package/dist/memory/compressor.d.ts +87 -0
- package/dist/memory/compressor.d.ts.map +1 -0
- package/dist/memory/compressor.js +164 -0
- package/dist/memory/compressor.js.map +1 -0
- package/dist/memory/hash.d.ts +17 -0
- package/dist/memory/hash.d.ts.map +1 -0
- package/dist/memory/hash.js +20 -0
- package/dist/memory/hash.js.map +1 -0
- package/dist/memory/prune.d.ts +117 -0
- package/dist/memory/prune.d.ts.map +1 -0
- package/dist/memory/prune.js +416 -0
- package/dist/memory/prune.js.map +1 -0
- package/dist/memory/reminder.d.ts +57 -0
- package/dist/memory/reminder.d.ts.map +1 -0
- package/dist/memory/reminder.js +57 -0
- package/dist/memory/reminder.js.map +1 -0
- package/dist/memory/scrubber.d.ts +28 -0
- package/dist/memory/scrubber.d.ts.map +1 -0
- package/dist/memory/scrubber.js +147 -0
- package/dist/memory/scrubber.js.map +1 -0
- package/dist/memory/token-estimate.d.ts +10 -0
- package/dist/memory/token-estimate.d.ts.map +1 -0
- package/dist/memory/token-estimate.js +69 -0
- package/dist/memory/token-estimate.js.map +1 -0
- package/dist/platform/config.d.ts +12 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +54 -0
- package/dist/platform/config.js.map +1 -0
- package/dist/platform/jsonl.d.ts +15 -0
- package/dist/platform/jsonl.d.ts.map +1 -0
- package/dist/platform/jsonl.js +80 -0
- package/dist/platform/jsonl.js.map +1 -0
- package/dist/platform/lifecycle.d.ts +22 -0
- package/dist/platform/lifecycle.d.ts.map +1 -0
- package/dist/platform/lifecycle.js +60 -0
- package/dist/platform/lifecycle.js.map +1 -0
- package/dist/platform/logger.d.ts +26 -0
- package/dist/platform/logger.d.ts.map +1 -0
- package/dist/platform/logger.js +41 -0
- package/dist/platform/logger.js.map +1 -0
- package/dist/platform/mcp-config.d.ts +15 -0
- package/dist/platform/mcp-config.d.ts.map +1 -0
- package/dist/platform/mcp-config.js +8 -0
- package/dist/platform/mcp-config.js.map +1 -0
- package/dist/provider.d.ts +81 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +444 -0
- package/dist/provider.js.map +1 -0
- package/dist/providers/anthropic.d.ts +132 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +518 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/base.d.ts +140 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +2 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/deepseek.d.ts +118 -0
- package/dist/providers/deepseek.d.ts.map +1 -0
- package/dist/providers/deepseek.js +467 -0
- package/dist/providers/deepseek.js.map +1 -0
- package/dist/registry.d.ts +3 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +94 -0
- package/dist/registry.js.map +1 -0
- package/dist/session-store.d.ts +133 -0
- package/dist/session-store.d.ts.map +1 -0
- package/dist/session-store.js +277 -0
- package/dist/session-store.js.map +1 -0
- package/dist/skills/curator.d.ts +104 -0
- package/dist/skills/curator.d.ts.map +1 -0
- package/dist/skills/curator.js +162 -0
- package/dist/skills/curator.js.map +1 -0
- package/dist/skills/index-builder.d.ts +42 -0
- package/dist/skills/index-builder.d.ts.map +1 -0
- package/dist/skills/index-builder.js +94 -0
- package/dist/skills/index-builder.js.map +1 -0
- package/dist/skills/loader.d.ts +107 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +286 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/preprocess.d.ts +45 -0
- package/dist/skills/preprocess.d.ts.map +1 -0
- package/dist/skills/preprocess.js +126 -0
- package/dist/skills/preprocess.js.map +1 -0
- package/dist/skills/usage.d.ts +75 -0
- package/dist/skills/usage.d.ts.map +1 -0
- package/dist/skills/usage.js +147 -0
- package/dist/skills/usage.js.map +1 -0
- package/dist/state/todos.d.ts +95 -0
- package/dist/state/todos.d.ts.map +1 -0
- package/dist/state/todos.js +198 -0
- package/dist/state/todos.js.map +1 -0
- package/dist/storage/conversations.d.ts +28 -0
- package/dist/storage/conversations.d.ts.map +1 -0
- package/dist/storage/conversations.js +8 -0
- package/dist/storage/conversations.js.map +1 -0
- package/dist/sub-agent/runner.d.ts +78 -0
- package/dist/sub-agent/runner.d.ts.map +1 -0
- package/dist/sub-agent/runner.js +215 -0
- package/dist/sub-agent/runner.js.map +1 -0
- package/dist/tools/builtin/agent.d.ts +33 -0
- package/dist/tools/builtin/agent.d.ts.map +1 -0
- package/dist/tools/builtin/agent.js +76 -0
- package/dist/tools/builtin/agent.js.map +1 -0
- package/dist/tools/builtin/bash.d.ts +11 -0
- package/dist/tools/builtin/bash.d.ts.map +1 -0
- package/dist/tools/builtin/bash.js +91 -0
- package/dist/tools/builtin/bash.js.map +1 -0
- package/dist/tools/builtin/edit.d.ts +21 -0
- package/dist/tools/builtin/edit.d.ts.map +1 -0
- package/dist/tools/builtin/edit.js +238 -0
- package/dist/tools/builtin/edit.js.map +1 -0
- package/dist/tools/builtin/read.d.ts +17 -0
- package/dist/tools/builtin/read.d.ts.map +1 -0
- package/dist/tools/builtin/read.js +139 -0
- package/dist/tools/builtin/read.js.map +1 -0
- package/dist/tools/builtin/sandbox.d.ts +16 -0
- package/dist/tools/builtin/sandbox.d.ts.map +1 -0
- package/dist/tools/builtin/sandbox.js +58 -0
- package/dist/tools/builtin/sandbox.js.map +1 -0
- package/dist/tools/builtin/skill_view.d.ts +37 -0
- package/dist/tools/builtin/skill_view.d.ts.map +1 -0
- package/dist/tools/builtin/skill_view.js +82 -0
- package/dist/tools/builtin/skill_view.js.map +1 -0
- package/dist/tools/builtin/todo_write.d.ts +29 -0
- package/dist/tools/builtin/todo_write.d.ts.map +1 -0
- package/dist/tools/builtin/todo_write.js +96 -0
- package/dist/tools/builtin/todo_write.js.map +1 -0
- package/dist/tools/builtin/web_fetch.d.ts +10 -0
- package/dist/tools/builtin/web_fetch.d.ts.map +1 -0
- package/dist/tools/builtin/web_fetch.js +150 -0
- package/dist/tools/builtin/web_fetch.js.map +1 -0
- package/dist/tools/builtin/write.d.ts +35 -0
- package/dist/tools/builtin/write.d.ts.map +1 -0
- package/dist/tools/builtin/write.js +70 -0
- package/dist/tools/builtin/write.js.map +1 -0
- package/dist/tools/file-state.d.ts +99 -0
- package/dist/tools/file-state.d.ts.map +1 -0
- package/dist/tools/file-state.js +133 -0
- package/dist/tools/file-state.js.map +1 -0
- package/dist/tools/hooks/sandbox-fs.d.ts +25 -0
- package/dist/tools/hooks/sandbox-fs.d.ts.map +1 -0
- package/dist/tools/hooks/sandbox-fs.js +48 -0
- package/dist/tools/hooks/sandbox-fs.js.map +1 -0
- package/dist/tools/registry.d.ts +102 -0
- package/dist/tools/registry.d.ts.map +1 -0
- package/dist/tools/registry.js +93 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { compressIfNeeded } from "../memory/compressor.js";
|
|
2
|
+
import { StreamingContextScrubber, scrubString } from "../memory/scrubber.js";
|
|
3
|
+
import { extractFileEvents } from "../media/file-events.js";
|
|
4
|
+
import { logger } from "../platform/logger.js";
|
|
5
|
+
/**
|
|
6
|
+
* Cap applied to the `content` field of `tool_result` UnifiedEvents emitted to
|
|
7
|
+
* the dispatcher. Matches the 200-char ceiling already enforced by
|
|
8
|
+
* claude-provider.ts:373 and codex-provider.ts's `summarizeMcpToolCallResult`.
|
|
9
|
+
* Downstream telegram renderers are sized for that ceiling — letting raw
|
|
10
|
+
* 16KB+ bash payloads or full MCP results through would break their layout
|
|
11
|
+
* assumptions.
|
|
12
|
+
*
|
|
13
|
+
* Critically, this cap applies ONLY to the surfaced UnifiedEvent. The
|
|
14
|
+
* `tool_result` block pushed back into `messages` for the next API turn keeps
|
|
15
|
+
* the full payload, so the model still sees complete tool output — same as
|
|
16
|
+
* claude/codex, where the SDK passes full results to the model and only the
|
|
17
|
+
* UnifiedEvent emit path truncates.
|
|
18
|
+
*/
|
|
19
|
+
const TOOL_RESULT_PREVIEW_MAX = 200;
|
|
20
|
+
/**
|
|
21
|
+
* run_conversation — Maestro agent loop (TS port).
|
|
22
|
+
*
|
|
23
|
+
* Yields UnifiedEvents so the Clawgram dispatcher can stream them to telegram
|
|
24
|
+
* without caring about the underlying provider format.
|
|
25
|
+
*
|
|
26
|
+
* Multi-turn: the caller owns the `messages` array and passes it in
|
|
27
|
+
* pre-populated with prior history (loaded from `~/.maestro/sessions/<id>.jsonl`
|
|
28
|
+
* by `maestroProvider`) plus the new user prompt as the last entry. The loop
|
|
29
|
+
* mutates that array in place, appending assistant turns and tool-result
|
|
30
|
+
* user turns as the conversation progresses; once the generator drains, the
|
|
31
|
+
* caller persists the final `messages` back to disk for the next resume.
|
|
32
|
+
*
|
|
33
|
+
* This shape avoids returning the final history through the async iterator
|
|
34
|
+
* (which would either require a special "internal" UnifiedEvent variant or a
|
|
35
|
+
* companion side-channel — both worse than just sharing the array).
|
|
36
|
+
*
|
|
37
|
+
* Upstream reference: `run_agent.py::AIAgent.run_conversation` — same control
|
|
38
|
+
* flow, just `client.chat.completions.create` swapped for `provider.complete`
|
|
39
|
+
* and OpenAI message blocks swapped for Anthropic blocks.
|
|
40
|
+
*/
|
|
41
|
+
export async function* runConversation(agent, messages) {
|
|
42
|
+
let iterations = 0;
|
|
43
|
+
const maxIter = agent.config.maxIterations;
|
|
44
|
+
const usageAcc = {
|
|
45
|
+
inputTokens: 0,
|
|
46
|
+
outputTokens: 0,
|
|
47
|
+
cacheCreationInputTokens: 0,
|
|
48
|
+
cacheReadInputTokens: 0,
|
|
49
|
+
};
|
|
50
|
+
while (iterations < maxIter) {
|
|
51
|
+
if (agent.config.abortSignal?.aborted) {
|
|
52
|
+
yield { type: "error", content: "maestro loop aborted" };
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
// Two-stage context shrink before the provider call:
|
|
56
|
+
// 1. compressIfNeeded — runs pruneMessages internally, then if still
|
|
57
|
+
// over 80% of the context window dispatches the aux LLM (cheap
|
|
58
|
+
// haiku) to summarize the middle into the Active Task template.
|
|
59
|
+
// Returns the caller's array as-is when below threshold so the
|
|
60
|
+
// common case is just a token-estimate pass.
|
|
61
|
+
// 2. compressIfNeeded already prunes — no second pruneMessages call.
|
|
62
|
+
//
|
|
63
|
+
// Pure with respect to `messages` (canonical history kept intact for
|
|
64
|
+
// resume); only the on-wire slice is reshaped. Anti-thrashing on the
|
|
65
|
+
// array reference (both in prune.ts and compressor.ts) keeps back-to-
|
|
66
|
+
// back iterations near-zero CPU once the conversation stabilizes.
|
|
67
|
+
//
|
|
68
|
+
// Aux provider is the same Provider instance as the agent's main
|
|
69
|
+
// provider — Anthropic adapter accepts the haiku model id directly,
|
|
70
|
+
// so no second client needed. Fallback inside compressIfNeeded handles
|
|
71
|
+
// aux LLM failure by dropping to prune-only.
|
|
72
|
+
const wireMessages = await compressIfNeeded(messages, {
|
|
73
|
+
auxProvider: agent.provider,
|
|
74
|
+
...(agent.config.abortSignal ? { abortSignal: agent.config.abortSignal } : {}),
|
|
75
|
+
});
|
|
76
|
+
// Drive the API call via stream() when available so we can emit
|
|
77
|
+
// text_delta UnifiedEvents as the tokens arrive — matches claude/codex
|
|
78
|
+
// progressive typing UX. complete() stays as the fallback for providers
|
|
79
|
+
// that haven't implemented stream() yet (e.g. an early Phase 5 OpenAI
|
|
80
|
+
// adapter could ship stream() in a follow-up).
|
|
81
|
+
const callOpts = {
|
|
82
|
+
model: agent.config.model,
|
|
83
|
+
messages: wireMessages,
|
|
84
|
+
system: agent.config.systemPrompt,
|
|
85
|
+
tools: agent.tools.schemas(),
|
|
86
|
+
maxTokens: agent.config.maxTokens,
|
|
87
|
+
...(agent.config.thinkingBudget ? { thinkingBudget: agent.config.thinkingBudget } : {}),
|
|
88
|
+
...(agent.config.effort ? { effort: agent.config.effort } : {}),
|
|
89
|
+
...(agent.config.abortSignal ? { abortSignal: agent.config.abortSignal } : {}),
|
|
90
|
+
};
|
|
91
|
+
let response;
|
|
92
|
+
let assistantText = "";
|
|
93
|
+
const toolUses = [];
|
|
94
|
+
const assistantBlocks = [];
|
|
95
|
+
if (agent.provider.stream) {
|
|
96
|
+
// Per-tool_use scratch: accumulate the JSON input arriving across
|
|
97
|
+
// multiple `tool_use_input_delta` chunks, then parse on _complete.
|
|
98
|
+
const toolInputBuffer = new Map();
|
|
99
|
+
let streamUsage = { inputTokens: 0, outputTokens: 0 };
|
|
100
|
+
let streamStopReason = "end_turn";
|
|
101
|
+
// Strip any `<compacted-history>...</compacted-history>` fence the
|
|
102
|
+
// model echoes from a prior compaction. The scrubber buffers up to a
|
|
103
|
+
// marker's worth of bytes across chunk boundaries so a split tag
|
|
104
|
+
// (`...<comp` | `acted-history>...`) still matches. See
|
|
105
|
+
// `memory/scrubber.ts` — also used as `scrubString` for the
|
|
106
|
+
// consolidated end-of-turn text below.
|
|
107
|
+
const scrubber = new StreamingContextScrubber();
|
|
108
|
+
for await (const chunk of agent.provider.stream(callOpts)) {
|
|
109
|
+
if (chunk.type === "text_delta") {
|
|
110
|
+
const scrubbed = scrubber.feed(chunk.text);
|
|
111
|
+
assistantText += scrubbed;
|
|
112
|
+
if (scrubbed.length > 0)
|
|
113
|
+
yield { type: "text_delta", content: scrubbed };
|
|
114
|
+
}
|
|
115
|
+
else if (chunk.type === "tool_use_start") {
|
|
116
|
+
toolInputBuffer.set(chunk.id, { name: chunk.name, partial: "" });
|
|
117
|
+
}
|
|
118
|
+
else if (chunk.type === "tool_use_input_delta") {
|
|
119
|
+
const buf = toolInputBuffer.get(chunk.id);
|
|
120
|
+
if (buf)
|
|
121
|
+
buf.partial += chunk.partial_json;
|
|
122
|
+
}
|
|
123
|
+
else if (chunk.type === "tool_use_complete") {
|
|
124
|
+
const buf = toolInputBuffer.get(chunk.id);
|
|
125
|
+
if (!buf)
|
|
126
|
+
continue;
|
|
127
|
+
let input = {};
|
|
128
|
+
if (buf.partial.length > 0) {
|
|
129
|
+
try {
|
|
130
|
+
input = JSON.parse(buf.partial);
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
logger.warn({ err: e, toolName: chunk.name, raw: buf.partial.slice(0, 200) }, "maestro stream: tool_use input_json parse failed — using empty input");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
toolUses.push({ id: chunk.id, name: chunk.name, input });
|
|
137
|
+
assistantBlocks.push({ type: "tool_use", id: chunk.id, name: chunk.name, input });
|
|
138
|
+
yield { type: "tool_use", name: chunk.name, input };
|
|
139
|
+
toolInputBuffer.delete(chunk.id);
|
|
140
|
+
}
|
|
141
|
+
else if (chunk.type === "thinking_complete") {
|
|
142
|
+
assistantBlocks.push(chunk.block);
|
|
143
|
+
}
|
|
144
|
+
else if (chunk.type === "message_complete") {
|
|
145
|
+
streamUsage = chunk.usage;
|
|
146
|
+
streamStopReason = chunk.stopReason;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Flush any bytes the scrubber was holding (matching-open buffer that
|
|
150
|
+
// turned out not to be a real marker). `finish()` is also where an
|
|
151
|
+
// unclosed `<compacted-history>` block gets silently dropped.
|
|
152
|
+
const tail = scrubber.finish();
|
|
153
|
+
if (tail.length > 0) {
|
|
154
|
+
assistantText += tail;
|
|
155
|
+
yield { type: "text_delta", content: tail };
|
|
156
|
+
}
|
|
157
|
+
// Reconstruct the text block(s) once at the end — the loop only
|
|
158
|
+
// needs a single concatenated block to push back into history, which
|
|
159
|
+
// matches what Anthropic's non-streaming response would have given us.
|
|
160
|
+
if (assistantText.length > 0) {
|
|
161
|
+
assistantBlocks.unshift({ type: "text", text: assistantText });
|
|
162
|
+
}
|
|
163
|
+
response = { content: assistantBlocks, stopReason: streamStopReason, usage: streamUsage };
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
response = await agent.provider.complete(callOpts);
|
|
167
|
+
// Walk the assistant's content blocks once: emit text/tool_use events
|
|
168
|
+
// to the caller, build the assistant-turn message for the next
|
|
169
|
+
// iteration, and collect tool_use blocks that need dispatching.
|
|
170
|
+
for (const block of response.content) {
|
|
171
|
+
if (block.type === "text") {
|
|
172
|
+
// Non-streaming path: scrub the whole block at once. Mirrors the
|
|
173
|
+
// streaming scrubber so consumers see the same shape regardless
|
|
174
|
+
// of which provider mode produced the response.
|
|
175
|
+
const cleaned = scrubString(block.text);
|
|
176
|
+
assistantText += cleaned;
|
|
177
|
+
if (cleaned.length > 0) {
|
|
178
|
+
assistantBlocks.push({ type: "text", text: cleaned });
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (block.type === "tool_use") {
|
|
182
|
+
toolUses.push({ id: block.id, name: block.name, input: block.input });
|
|
183
|
+
assistantBlocks.push(block);
|
|
184
|
+
yield { type: "tool_use", name: block.name, input: block.input };
|
|
185
|
+
}
|
|
186
|
+
else if (block.type === "thinking" || block.type === "redacted_thinking") {
|
|
187
|
+
assistantBlocks.push(block);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
usageAcc.inputTokens += response.usage.inputTokens;
|
|
192
|
+
usageAcc.outputTokens += response.usage.outputTokens;
|
|
193
|
+
usageAcc.cacheCreationInputTokens += response.usage.cacheCreationInputTokens ?? 0;
|
|
194
|
+
usageAcc.cacheReadInputTokens += response.usage.cacheReadInputTokens ?? 0;
|
|
195
|
+
if (assistantText.length > 0) {
|
|
196
|
+
// Streaming emitted text_delta chunks during the run; this terminal
|
|
197
|
+
// `text` event is the consolidated assistant turn so non-streaming
|
|
198
|
+
// consumers (recorders, log archives) still see one canonical entry
|
|
199
|
+
// per turn — same shape claude-provider.ts surfaces.
|
|
200
|
+
yield { type: "text", content: assistantText };
|
|
201
|
+
// Surface [FILE:/abs/path] tags emitted mid-turn (e.g. assistant
|
|
202
|
+
// narrating a file before calling a tool) so the dispatcher sends them
|
|
203
|
+
// immediately, matching codex-provider.ts's agent_message extract.
|
|
204
|
+
yield* extractFileEvents(assistantText, "text");
|
|
205
|
+
}
|
|
206
|
+
// Persist the assistant turn into the shared history before we either
|
|
207
|
+
// exit (so the next resume sees it) or run tools and continue. Doing
|
|
208
|
+
// this even for the no-tool exit keeps the caller's persistence call
|
|
209
|
+
// schema-consistent: every successful provider.complete() lands in the
|
|
210
|
+
// history exactly once.
|
|
211
|
+
messages.push({ role: "assistant", content: assistantBlocks });
|
|
212
|
+
if (toolUses.length === 0) {
|
|
213
|
+
// No more tools — turn complete.
|
|
214
|
+
yield {
|
|
215
|
+
type: "result",
|
|
216
|
+
content: assistantText,
|
|
217
|
+
stopReason: response.stopReason,
|
|
218
|
+
usage: {
|
|
219
|
+
inputTokens: usageAcc.inputTokens,
|
|
220
|
+
outputTokens: usageAcc.outputTokens,
|
|
221
|
+
...(usageAcc.cacheCreationInputTokens > 0 && {
|
|
222
|
+
cacheCreationInputTokens: usageAcc.cacheCreationInputTokens,
|
|
223
|
+
}),
|
|
224
|
+
...(usageAcc.cacheReadInputTokens > 0 && {
|
|
225
|
+
cacheReadInputTokens: usageAcc.cacheReadInputTokens,
|
|
226
|
+
}),
|
|
227
|
+
},
|
|
228
|
+
};
|
|
229
|
+
// Final pass on the result text — matches claude-provider.ts:352 and
|
|
230
|
+
// codex-provider.ts's turn.completed extract so [FILE:...] tags in the
|
|
231
|
+
// final assistant message reach the send-file path.
|
|
232
|
+
yield* extractFileEvents(assistantText, "result");
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Dispatch tools in two phases so independent reads / fetches run in
|
|
236
|
+
// parallel while side-effecting calls (Write/Edit/Bash/most MCP) stay
|
|
237
|
+
// sequential:
|
|
238
|
+
// Phase A — every tool whose handler is `parallelSafe: true` runs via
|
|
239
|
+
// Promise.all. dispatch() never throws (errors are wrapped as
|
|
240
|
+
// {error: ...} strings) so the batch always settles.
|
|
241
|
+
// Phase B — remaining tools run one-by-one in their original order so
|
|
242
|
+
// write/edit ordering is deterministic and unrelated bash
|
|
243
|
+
// invocations don't race on ports/files/env.
|
|
244
|
+
//
|
|
245
|
+
// `results` is indexed by the position in `toolUses` so the final yield
|
|
246
|
+
// + push order matches what the model emitted, regardless of completion
|
|
247
|
+
// order. Anthropic requires `tool_result` blocks in one user turn to
|
|
248
|
+
// align with their corresponding `tool_use` ids; preserving the order
|
|
249
|
+
// also keeps the conversation log easier to read.
|
|
250
|
+
const results = new Array(toolUses.length);
|
|
251
|
+
const parallelIndices = [];
|
|
252
|
+
const serialIndices = [];
|
|
253
|
+
for (let i = 0; i < toolUses.length; i++) {
|
|
254
|
+
if (agent.tools.isParallelSafe(toolUses[i].name)) {
|
|
255
|
+
parallelIndices.push(i);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
serialIndices.push(i);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (parallelIndices.length > 0) {
|
|
262
|
+
const parallelResults = await Promise.all(parallelIndices.map((i) => agent.tools.dispatch(toolUses[i].name, toolUses[i].input)));
|
|
263
|
+
for (let k = 0; k < parallelIndices.length; k++) {
|
|
264
|
+
results[parallelIndices[k]] = parallelResults[k];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
for (const i of serialIndices) {
|
|
268
|
+
results[i] = await agent.tools.dispatch(toolUses[i].name, toolUses[i].input);
|
|
269
|
+
}
|
|
270
|
+
// Cap the surfaced UnifiedEvent `content` at TOOL_RESULT_PREVIEW_MAX to
|
|
271
|
+
// match claude/codex, but push the FULL `result` into `toolResultBlocks`
|
|
272
|
+
// so the model sees complete tool output on the next turn — claude/codex
|
|
273
|
+
// do the same (SDK feeds full payload to model, UnifiedEvent emit is the
|
|
274
|
+
// only place truncation happens).
|
|
275
|
+
const toolResultBlocks = [];
|
|
276
|
+
for (let i = 0; i < toolUses.length; i++) {
|
|
277
|
+
const tu = toolUses[i];
|
|
278
|
+
const result = results[i];
|
|
279
|
+
const preview = result.length > TOOL_RESULT_PREVIEW_MAX ? result.slice(0, TOOL_RESULT_PREVIEW_MAX) : result;
|
|
280
|
+
yield { type: "tool_result", toolUseId: tu.id, content: preview };
|
|
281
|
+
toolResultBlocks.push({
|
|
282
|
+
type: "tool_result",
|
|
283
|
+
tool_use_id: tu.id,
|
|
284
|
+
content: result,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// Append a fresh `<system-reminder>` text block AFTER the tool_result
|
|
288
|
+
// blocks so the model's next turn sees an up-to-date "iterations
|
|
289
|
+
// remaining" line. Budget = `maxIter - (iterations + 1)` because we
|
|
290
|
+
// haven't bumped `iterations` for this turn yet — the value reflects
|
|
291
|
+
// what the model will have AFTER consuming this turn.
|
|
292
|
+
//
|
|
293
|
+
// Anthropic accepts mixed tool_result+text blocks in a single user
|
|
294
|
+
// message; the trailing text block reads as meta annotation rather
|
|
295
|
+
// than user intent (claude/codex use the same shape).
|
|
296
|
+
//
|
|
297
|
+
// Freezing the reminder into `messages` (rather than re-injecting at
|
|
298
|
+
// wire time each iteration) keeps prefix-cache hits intact: turn N's
|
|
299
|
+
// reminder is byte-stable across every subsequent call, so the cache
|
|
300
|
+
// boundary moves forward one turn at a time instead of invalidating
|
|
301
|
+
// on every API hit.
|
|
302
|
+
if (agent.config.buildIterReminder) {
|
|
303
|
+
const remaining = Math.max(0, maxIter - (iterations + 1));
|
|
304
|
+
const reminderText = agent.config.buildIterReminder(remaining);
|
|
305
|
+
if (reminderText && reminderText.length > 0) {
|
|
306
|
+
toolResultBlocks.push({ type: "text", text: reminderText });
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
messages.push({ role: "user", content: toolResultBlocks });
|
|
310
|
+
iterations++;
|
|
311
|
+
}
|
|
312
|
+
yield {
|
|
313
|
+
type: "error",
|
|
314
|
+
content: `maestro loop hit max_iterations (${maxIter}) without resolving`,
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loop.js","sourceRoot":"","sources":["../../src/core/loop.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,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J,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,oCAAoC,OAAO,qBAAqB;KAC1E,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* maestro-agent-sdk — public API.
|
|
3
|
+
*
|
|
4
|
+
* Provider-agnostic agent loop with built-in tools, skills, memory, and MCP.
|
|
5
|
+
* See README.md for a quick start.
|
|
6
|
+
*
|
|
7
|
+
* Originally derived from Nous Research's hermes-agent (MIT); see NOTICE.
|
|
8
|
+
*/
|
|
9
|
+
export declare const MAESTRO_SDK_VERSION: "0.1.0";
|
|
10
|
+
export declare const MAESTRO_UPSTREAM_SNAPSHOT: "v0.13.0 (2026-05-07)";
|
|
11
|
+
export { AIAgent, type AIAgentConfig } from "./core/agent.js";
|
|
12
|
+
export { runConversation } from "./core/loop.js";
|
|
13
|
+
export { ToolRegistry, type ToolHandler, type HookRegistration, type PreToolUseHook, type PostToolUseHook, type PreToolUseContext, type PreToolUseDecision, type PostToolUseContext, type PostToolUseResult, } from "./tools/registry.js";
|
|
14
|
+
export { bashTool } from "./tools/builtin/bash.js";
|
|
15
|
+
export { createReadTool } from "./tools/builtin/read.js";
|
|
16
|
+
export { createWriteTool } from "./tools/builtin/write.js";
|
|
17
|
+
export { createEditTool } from "./tools/builtin/edit.js";
|
|
18
|
+
export { createTodoWriteTool } from "./tools/builtin/todo_write.js";
|
|
19
|
+
export { createSkillViewTool } from "./tools/builtin/skill_view.js";
|
|
20
|
+
export { createAgentTool } from "./tools/builtin/agent.js";
|
|
21
|
+
export { isSandboxEnabled, checkFilesystemAccess } from "./tools/builtin/sandbox.js";
|
|
22
|
+
export { createSandboxFsHook } from "./tools/hooks/sandbox-fs.js";
|
|
23
|
+
export { getFileStateTracker, dropFileStateTracker } from "./tools/file-state.js";
|
|
24
|
+
export type { Provider, ProviderToolSchema, ProviderMessage, ProviderContentBlock, ProviderResponse, ProviderStreamChunk, ProviderCompleteOptions, } from "./providers/base.js";
|
|
25
|
+
export { AnthropicProvider, effortToThinkingBudget, effortToMaxIter, applyThinkingBudget, buildCacheableSystem, buildCacheableTools, buildCacheableMessages, } from "./providers/anthropic.js";
|
|
26
|
+
export { DeepseekProvider, effortForDeepseek, translateToolsToOpenAI, translateMessagesToOpenAI, } from "./providers/deepseek.js";
|
|
27
|
+
export { maestroRegistry } from "./registry.js";
|
|
28
|
+
export { maestroProvider, providerForModel, isAbortError, iterationBudgetLine } from "./provider.js";
|
|
29
|
+
export { loadSkillsCached, findSkillByName, type SkillEntry } from "./skills/loader.js";
|
|
30
|
+
export { buildSkillsIndex } from "./skills/index-builder.js";
|
|
31
|
+
export { curateSkills } from "./skills/curator.js";
|
|
32
|
+
export { loadUsage, bumpView, type SkillCounters } from "./skills/usage.js";
|
|
33
|
+
export { compressIfNeeded } from "./memory/compressor.js";
|
|
34
|
+
export { estimateTokens } from "./memory/token-estimate.js";
|
|
35
|
+
export { buildSystemReminder } from "./memory/reminder.js";
|
|
36
|
+
export { hashToolContent } from "./memory/hash.js";
|
|
37
|
+
export { ACTIVE_TASK_TEMPLATE, wrapCompactedSummary } from "./memory/active-task-template.js";
|
|
38
|
+
export { getTodoStore, dropTodoStore } from "./state/todos.js";
|
|
39
|
+
export type { MaestroMcpServerSpec, MaestroMcpClient, MaestroMcpTool } from "./mcp/client.js";
|
|
40
|
+
export { deleteMaestroSession } from "./session-store.js";
|
|
41
|
+
export { setLogger, type Logger, type LogFn } from "./platform/logger.js";
|
|
42
|
+
export { onShutdown, runShutdown } from "./platform/lifecycle.js";
|
|
43
|
+
export { setMcpResolver, type McpResolver, type McpServerMap } from "./platform/mcp-config.js";
|
|
44
|
+
export { setConversationReader, type ConversationReader } from "./storage/conversations.js";
|
|
45
|
+
export type { TokenUsage, EffortLevel, AgentKind, AgentQueryOptions, UnifiedEvent, } from "./types.js";
|
|
46
|
+
export { MAESTRO_EFFORT_VALUES, SUPPORTED_AGENTS, FALLBACK_AGENT, isAgentKind, } from "./types.js";
|
|
47
|
+
export type { ConversationEntry } from "./storage/conversations.js";
|
|
48
|
+
export type { AgentRegistry, WriteRolloutOptions, WriteRolloutResult, ForkRegistryOptions, ForkRegistryResult, CleanupRolloutsOptions, } from "./agents/contracts.js";
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,mBAAmB,EAAG,OAAgB,CAAC;AACpD,eAAO,MAAM,yBAAyB,EAAG,sBAA+B,CAAC;AAGzE,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,OAAO,EACL,YAAY,EACZ,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE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c,CAAC;AAG3F,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,EAAE,SAAS,EAAE,KAAK,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAAE,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGzF,YAAY,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,YAAY,GACb,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* maestro-agent-sdk — public API.
|
|
3
|
+
*
|
|
4
|
+
* Provider-agnostic agent loop with built-in tools, skills, memory, and MCP.
|
|
5
|
+
* See README.md for a quick start.
|
|
6
|
+
*
|
|
7
|
+
* Originally derived from Nous Research's hermes-agent (MIT); see NOTICE.
|
|
8
|
+
*/
|
|
9
|
+
export const MAESTRO_SDK_VERSION = "0.1.0";
|
|
10
|
+
export const MAESTRO_UPSTREAM_SNAPSHOT = "v0.13.0 (2026-05-07)";
|
|
11
|
+
// ─── Core agent loop ─────────────────────────────────────────────────────────
|
|
12
|
+
export { AIAgent } from "./core/agent.js";
|
|
13
|
+
export { runConversation } from "./core/loop.js";
|
|
14
|
+
// ─── Tool registry + hook surface ────────────────────────────────────────────
|
|
15
|
+
export { ToolRegistry, } from "./tools/registry.js";
|
|
16
|
+
// ─── Built-in tools ──────────────────────────────────────────────────────────
|
|
17
|
+
export { bashTool } from "./tools/builtin/bash.js";
|
|
18
|
+
export { createReadTool } from "./tools/builtin/read.js";
|
|
19
|
+
export { createWriteTool } from "./tools/builtin/write.js";
|
|
20
|
+
export { createEditTool } from "./tools/builtin/edit.js";
|
|
21
|
+
export { createTodoWriteTool } from "./tools/builtin/todo_write.js";
|
|
22
|
+
export { createSkillViewTool } from "./tools/builtin/skill_view.js";
|
|
23
|
+
export { createAgentTool } from "./tools/builtin/agent.js";
|
|
24
|
+
export { isSandboxEnabled, checkFilesystemAccess } from "./tools/builtin/sandbox.js";
|
|
25
|
+
export { createSandboxFsHook } from "./tools/hooks/sandbox-fs.js";
|
|
26
|
+
export { getFileStateTracker, dropFileStateTracker } from "./tools/file-state.js";
|
|
27
|
+
export { AnthropicProvider, effortToThinkingBudget, effortToMaxIter, applyThinkingBudget, buildCacheableSystem, buildCacheableTools, buildCacheableMessages, } from "./providers/anthropic.js";
|
|
28
|
+
export { DeepseekProvider, effortForDeepseek, translateToolsToOpenAI, translateMessagesToOpenAI, } from "./providers/deepseek.js";
|
|
29
|
+
// ─── Maestro registry + top-level provider entry point ───────────────────────
|
|
30
|
+
export { maestroRegistry } from "./registry.js";
|
|
31
|
+
export { maestroProvider, providerForModel, isAbortError, iterationBudgetLine } from "./provider.js";
|
|
32
|
+
// ─── Skills ──────────────────────────────────────────────────────────────────
|
|
33
|
+
export { loadSkillsCached, findSkillByName } from "./skills/loader.js";
|
|
34
|
+
export { buildSkillsIndex } from "./skills/index-builder.js";
|
|
35
|
+
export { curateSkills } from "./skills/curator.js";
|
|
36
|
+
export { loadUsage, bumpView } from "./skills/usage.js";
|
|
37
|
+
// ─── Memory / compression ────────────────────────────────────────────────────
|
|
38
|
+
export { compressIfNeeded } from "./memory/compressor.js";
|
|
39
|
+
export { estimateTokens } from "./memory/token-estimate.js";
|
|
40
|
+
export { buildSystemReminder } from "./memory/reminder.js";
|
|
41
|
+
export { hashToolContent } from "./memory/hash.js";
|
|
42
|
+
export { ACTIVE_TASK_TEMPLATE, wrapCompactedSummary } from "./memory/active-task-template.js";
|
|
43
|
+
// ─── State (todos) ───────────────────────────────────────────────────────────
|
|
44
|
+
export { getTodoStore, dropTodoStore } from "./state/todos.js";
|
|
45
|
+
// ─── Session store ───────────────────────────────────────────────────────────
|
|
46
|
+
export { deleteMaestroSession } from "./session-store.js";
|
|
47
|
+
// ─── Host integration points (dependency injection) ──────────────────────────
|
|
48
|
+
export { setLogger } from "./platform/logger.js";
|
|
49
|
+
export { onShutdown, runShutdown } from "./platform/lifecycle.js";
|
|
50
|
+
export { setMcpResolver } from "./platform/mcp-config.js";
|
|
51
|
+
export { setConversationReader } from "./storage/conversations.js";
|
|
52
|
+
export { MAESTRO_EFFORT_VALUES, SUPPORTED_AGENTS, FALLBACK_AGENT, isAgentKind, } from "./types.js";
|
|
53
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE,gFAAgF;AAChF,OAAO,EAAE,OAAO,EAAsB,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,gFAAgF;AAChF,OAAO,EACL,YAAY,GASb,MAAM,kBAAkB,CAAC;AAE1B,gFAAgF;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO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AAe,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE3F,gFAAgF;AAChF,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAK5D,gFAAgF;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,gFAAgF;AAChF,OAAO,EAAE,SAAS,EAA2B,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAuC,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,qBAAqB,EAA2B,MAAM,yBAAyB,CAAC;AAUzF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,cAAc,EACd,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
|
+
import type { ProviderToolSchema } from "../providers/base.js";
|
|
4
|
+
/**
|
|
5
|
+
* Maestro MCP client wrapper.
|
|
6
|
+
*
|
|
7
|
+
* Wraps `@modelcontextprotocol/sdk` Client so the Maestro loop can spawn /
|
|
8
|
+
* connect / list_tools / call_tool / close in a single namespace, mirroring
|
|
9
|
+
* what `@anthropic-ai/claude-agent-sdk` and `@openai/codex-sdk` do internally
|
|
10
|
+
* for the claude / codex providers.
|
|
11
|
+
*
|
|
12
|
+
* Unlike claude/codex, Maestro hits Anthropic's Messages API directly via
|
|
13
|
+
* fetch (see `providers/anthropic.ts`) — no SDK manages MCP for us, so we
|
|
14
|
+
* spawn the servers ourselves and surface their tools through Maestro's
|
|
15
|
+
* existing `ToolRegistry`.
|
|
16
|
+
*/
|
|
17
|
+
/** Raw spawn shape — matches `getMcpServersForQuery()` output (Claude-SDK shape). */
|
|
18
|
+
export interface MaestroMcpServerSpec {
|
|
19
|
+
/** stdio servers. */
|
|
20
|
+
command?: string;
|
|
21
|
+
args?: string[];
|
|
22
|
+
env?: Record<string, string>;
|
|
23
|
+
/** sse servers. */
|
|
24
|
+
type?: "sse";
|
|
25
|
+
url?: string;
|
|
26
|
+
}
|
|
27
|
+
/** One tool resolved from an MCP server, ready to register with a ToolRegistry. */
|
|
28
|
+
export interface MaestroMcpTool {
|
|
29
|
+
/** Name exposed to the model (`mcp__<server>__<tool>`). */
|
|
30
|
+
publicName: string;
|
|
31
|
+
/** Original MCP tool name — used in `client.callTool`. */
|
|
32
|
+
originalName: string;
|
|
33
|
+
/** Owning MCP server name. */
|
|
34
|
+
serverName: string;
|
|
35
|
+
/** Anthropic-style tool schema for the API `tools` array. */
|
|
36
|
+
schema: ProviderToolSchema;
|
|
37
|
+
}
|
|
38
|
+
export declare class MaestroMcpClient {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
private readonly spec;
|
|
41
|
+
/**
|
|
42
|
+
* Test-only override: when supplied, `start()` connects to this transport
|
|
43
|
+
* instead of building one from `spec`. Production callers pass two args.
|
|
44
|
+
*/
|
|
45
|
+
private readonly transportOverride?;
|
|
46
|
+
readonly client: Client;
|
|
47
|
+
private transport?;
|
|
48
|
+
private started;
|
|
49
|
+
constructor(name: string, spec: MaestroMcpServerSpec,
|
|
50
|
+
/**
|
|
51
|
+
* Test-only override: when supplied, `start()` connects to this transport
|
|
52
|
+
* instead of building one from `spec`. Production callers pass two args.
|
|
53
|
+
*/
|
|
54
|
+
transportOverride?: Transport | undefined);
|
|
55
|
+
start(): Promise<void>;
|
|
56
|
+
/** Fetch `tools/list` and convert to Maestro/Anthropic shape with prefixed names. */
|
|
57
|
+
listTools(): Promise<MaestroMcpTool[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Invoke an MCP tool. Returns the FULL rendered payload string for the
|
|
60
|
+
* Maestro tool_result block — the model needs to see complete tool output on
|
|
61
|
+
* the next turn, matching how claude/codex SDKs feed full payloads back.
|
|
62
|
+
* The 200-char cap that claude-provider.ts:373 and codex-provider.ts apply
|
|
63
|
+
* is a UnifiedEvent display concern only; Maestro enforces it inside the
|
|
64
|
+
* agent loop (`loop.ts:TOOL_RESULT_PREVIEW_MAX`) at the emit site, not here.
|
|
65
|
+
*
|
|
66
|
+
* Optional `abortSignal` propagates the Maestro-level abort down into the
|
|
67
|
+
* SDK's JSON-RPC request, so an in-flight `tools/call` is cancelled instead
|
|
68
|
+
* of left blocking on a dead server.
|
|
69
|
+
*/
|
|
70
|
+
callTool(originalName: string, input: Record<string, unknown>, abortSignal?: AbortSignal): Promise<string>;
|
|
71
|
+
close(): Promise<void>;
|
|
72
|
+
private buildTransport;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Public MCP tool name. Mirrors Claude SDK's `mcp__<server>__<tool>` convention
|
|
76
|
+
* so the model sees consistent names across providers in the same topic.
|
|
77
|
+
*/
|
|
78
|
+
export declare function makePublicName(server: string, tool: string): string;
|
|
79
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D;;;;;;;;;;;;GAYG;AAEH,qFAAqF;AACrF,MAAM,WAAW,oBAAoB;IACnC,qBAAqB;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,mBAAmB;IACnB,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,GAAG,CAAC,E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