@ryuhq/sdk 0.1.13 → 0.2.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/README.md +19 -6
- package/dist/agent-plugin.cjs +46 -0
- package/dist/agent-plugin.d.cts +42 -32
- package/dist/agent-plugin.d.ts +42 -32
- package/dist/agent-plugin.js +1 -1
- package/dist/agent.cjs +9 -0
- package/dist/agent.d.cts +377 -1
- package/dist/agent.d.ts +377 -1
- package/dist/agent.js +4 -2
- package/dist/app-Bkw7LlCK.d.ts +129 -0
- package/dist/app-DNaGmLVf.d.cts +129 -0
- package/dist/builder.cjs +1095 -0
- package/dist/builder.d.cts +212 -0
- package/dist/builder.d.ts +212 -0
- package/dist/builder.js +28 -0
- package/dist/chunk-A3RGEPDG.js +250 -0
- package/dist/chunk-FZSFZOIN.js +200 -0
- package/dist/{chunk-ODFEUVPW.js → chunk-HACAGK65.js} +1 -18
- package/dist/{chunk-AO2KJRDD.js → chunk-IEUQ3CDG.js} +125 -2
- package/dist/chunk-IKEDLLFY.js +19 -0
- package/dist/chunk-IOLP5FFE.js +354 -0
- package/dist/{chunk-G6FLVEC4.js → chunk-JX6DDRXV.js} +46 -0
- package/dist/chunk-T5676WL2.js +240 -0
- package/dist/chunk-TLDPEGC7.js +21 -0
- package/dist/chunk-TXSHHZF2.js +0 -0
- package/dist/{chunk-MTUBUPIV.js → chunk-ULSVL7EC.js} +8 -227
- package/dist/chunk-VLIRNNAE.js +154 -0
- package/dist/chunk-W3KPP4WN.js +135 -0
- package/dist/cli.cjs +258 -14
- package/dist/cli.js +96 -16
- package/dist/client-D5U6ssPc.d.cts +84 -0
- package/dist/client-D5U6ssPc.d.ts +84 -0
- package/dist/index.cjs +519 -5
- package/dist/index.d.cts +16 -632
- package/dist/index.d.ts +16 -632
- package/dist/index.js +63 -695
- package/dist/manifest.cjs +129 -3
- package/dist/manifest.d.cts +105 -2
- package/dist/manifest.d.ts +105 -2
- package/dist/manifest.js +7 -1
- package/dist/mcp/client.cjs +180 -0
- package/dist/mcp/client.d.cts +49 -0
- package/dist/mcp/client.d.ts +49 -0
- package/dist/mcp/client.js +10 -0
- package/dist/mcp/server.cjs +370 -0
- package/dist/mcp/server.d.cts +126 -0
- package/dist/mcp/server.d.ts +126 -0
- package/dist/mcp/server.js +9 -0
- package/dist/mcp.cjs +376 -0
- package/dist/mcp.d.cts +2 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +17 -0
- package/dist/model.cjs +141 -0
- package/dist/model.d.cts +33 -0
- package/dist/model.d.ts +33 -0
- package/dist/model.js +18 -0
- package/dist/plugin.cjs +46 -0
- package/dist/plugin.d.cts +215 -0
- package/dist/plugin.d.ts +215 -0
- package/dist/plugin.js +8 -0
- package/dist/runnable.cjs +1230 -0
- package/dist/runnable.d.cts +271 -0
- package/dist/runnable.d.ts +271 -0
- package/dist/runnable.js +28 -0
- package/dist/{index-B6SkaAjJ.d.ts → tool-DSx2bFx8.d.ts} +35 -458
- package/dist/{index-BvAB5eMk.d.cts → tool-u-VR0fLF.d.cts} +35 -458
- package/package.json +38 -2
- package/src/agent/loop.test.ts +4 -4
- package/src/agent/tools.ts +3 -3
- package/src/agent-plugin.test.ts +58 -0
- package/src/agent-plugin.ts +108 -35
- package/src/cli/dev.test.ts +26 -47
- package/src/cli/dev.ts +10 -2
- package/src/cli.ts +98 -15
- package/src/exports-lockstep.test.ts +92 -0
- package/src/generated/plugin-manifest.ts +243 -27
- package/src/index.ts +35 -0
- package/src/manifest-schema.test.ts +30 -1
- package/src/manifest.fixtures.test.ts +13 -3
- package/src/manifest.test.ts +96 -10
- package/src/manifest.ts +334 -187
- package/src/mcp/index.ts +18 -0
- package/src/model/index.ts +22 -0
- package/src/plugin/ryu-plugin.ts +82 -0
- package/src/runnable/app.test.ts +2 -0
- package/src/runnable/app.ts +5 -2
- package/src/runnable/index.ts +2 -0
- package/src/runnable/primitives.ts +57 -0
- package/src/runnable/tool.ts +1 -1
- package/src/runnable/turn-hook.ts +4 -1
package/dist/agent.d.cts
CHANGED
|
@@ -1,3 +1,379 @@
|
|
|
1
|
-
|
|
1
|
+
import { T as ToolRunnable, j as RunnableContext } from './tool-u-VR0fLF.cjs';
|
|
2
2
|
import './manifest.cjs';
|
|
3
3
|
import 'zod';
|
|
4
|
+
import './client-D5U6ssPc.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Native tool-calling model call for the Ryu agent runtime.
|
|
8
|
+
*
|
|
9
|
+
* The gateway-mandatory `ModelClient` (packages/sdk/src/model/client.ts) only
|
|
10
|
+
* exposes text `chat`/`stream` — it cannot pass a `tools` array or receive
|
|
11
|
+
* `tool_calls`. The autonomous agent loop needs both, so this module makes a
|
|
12
|
+
* direct request to the node's gateway `POST /v1/chat/completions` endpoint
|
|
13
|
+
* with the caller's own `tools` and reads back `message.tool_calls`.
|
|
14
|
+
*
|
|
15
|
+
* The no-direct-provider guarantee is preserved: `assertAllowedEgressUrl` (the
|
|
16
|
+
* same Rust-cored blocklist the ModelClient uses) is called before every fetch,
|
|
17
|
+
* so a direct provider base URL throws exactly as it would elsewhere in the SDK.
|
|
18
|
+
*
|
|
19
|
+
* `x-ryu-raw-tools: on` is always sent. On a plain gateway it is a harmless
|
|
20
|
+
* no-op; on a Composio-on managed node it forces the plain completion branch so
|
|
21
|
+
* the caller's `tool_calls` are returned verbatim instead of being intercepted
|
|
22
|
+
* and executed by Core's own tool loop (see apps/gateway/src/pipeline/mod.rs).
|
|
23
|
+
*/
|
|
24
|
+
/** An OpenAI function tool definition passed to the model. */
|
|
25
|
+
interface ToolFunctionDef {
|
|
26
|
+
function: {
|
|
27
|
+
description?: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** JSON Schema for the function's arguments. */
|
|
30
|
+
parameters: Record<string, unknown>;
|
|
31
|
+
};
|
|
32
|
+
type: "function";
|
|
33
|
+
}
|
|
34
|
+
/** A single tool call emitted by the model. */
|
|
35
|
+
interface ToolCall {
|
|
36
|
+
function: {
|
|
37
|
+
/** JSON-encoded arguments string (per the OpenAI wire format). */
|
|
38
|
+
arguments: string;
|
|
39
|
+
name: string;
|
|
40
|
+
};
|
|
41
|
+
id: string;
|
|
42
|
+
type: "function";
|
|
43
|
+
}
|
|
44
|
+
/** An assistant turn — may carry text, tool calls, or both. */
|
|
45
|
+
interface AssistantMessage {
|
|
46
|
+
content: string | null;
|
|
47
|
+
role: "assistant";
|
|
48
|
+
tool_calls?: ToolCall[];
|
|
49
|
+
}
|
|
50
|
+
/** A message in the loop's running transcript. */
|
|
51
|
+
type LoopMessage = {
|
|
52
|
+
content: string;
|
|
53
|
+
role: "system" | "user";
|
|
54
|
+
} | AssistantMessage | {
|
|
55
|
+
content: string;
|
|
56
|
+
role: "tool";
|
|
57
|
+
tool_call_id: string;
|
|
58
|
+
};
|
|
59
|
+
/** Token usage as reported by the gateway (optional — gateway may omit). */
|
|
60
|
+
interface ModelUsage {
|
|
61
|
+
completionTokens: number;
|
|
62
|
+
promptTokens: number;
|
|
63
|
+
totalTokens: number;
|
|
64
|
+
}
|
|
65
|
+
/** Options for a single native tool-calling completion. */
|
|
66
|
+
interface ModelCallOptions {
|
|
67
|
+
/** Gateway base URL (no trailing `/v1`). */
|
|
68
|
+
baseUrl: string;
|
|
69
|
+
/** Running transcript. */
|
|
70
|
+
messages: LoopMessage[];
|
|
71
|
+
/** Model id routed by the gateway (provider is derived from the id). */
|
|
72
|
+
model: string;
|
|
73
|
+
/** Abort signal for cancellation. */
|
|
74
|
+
signal?: AbortSignal;
|
|
75
|
+
/** Bearer token forwarded to the gateway (never a provider key). */
|
|
76
|
+
token?: string;
|
|
77
|
+
/** How the model should choose tools; defaults to gateway/provider default. */
|
|
78
|
+
toolChoice?: "auto" | "none" | "required";
|
|
79
|
+
/** Function tool definitions the model may call. */
|
|
80
|
+
tools?: ToolFunctionDef[];
|
|
81
|
+
}
|
|
82
|
+
/** Result of a single completion. */
|
|
83
|
+
interface ModelCallResult {
|
|
84
|
+
finishReason: string | null;
|
|
85
|
+
message: AssistantMessage;
|
|
86
|
+
usage?: ModelUsage;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Call the node's gateway with the caller's own tools and return the first
|
|
90
|
+
* choice, including any `tool_calls`.
|
|
91
|
+
*
|
|
92
|
+
* Throws when the base URL is a direct provider (egress enforcement) or when
|
|
93
|
+
* the gateway returns a non-2xx status.
|
|
94
|
+
*/
|
|
95
|
+
declare function callModelWithTools(options: ModelCallOptions): Promise<ModelCallResult>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Tool resolution + execution for the Ryu agent runtime.
|
|
99
|
+
*
|
|
100
|
+
* Two kinds of tool feed the same model `tools[]` array:
|
|
101
|
+
*
|
|
102
|
+
* - **Local** tools are `ToolRunnable`s from `defineTool` — they run in-process
|
|
103
|
+
* via their `run(input, ctx)` implementation.
|
|
104
|
+
* - **Remote** tools are references to existing Ryu tools (e.g.
|
|
105
|
+
* `composio.GMAIL_SEARCH_EMAILS`) created with `ryuTool(id)`. Their schema is
|
|
106
|
+
* lazily fetched from Core `GET /api/tools/describe` and they execute through
|
|
107
|
+
* Core `POST /api/mcp/tools/call`, which enforces the agent's allowlist and
|
|
108
|
+
* selects the Composio connected-account entity via `user_id`.
|
|
109
|
+
*
|
|
110
|
+
* The model-facing function name is the **config key** the developer chose (e.g.
|
|
111
|
+
* `gmailSearch`), not the raw Composio slug — internals stay hidden and names
|
|
112
|
+
* stay OpenAI-safe.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/** A reference to an existing Ryu tool, resolved + executed via Core. */
|
|
116
|
+
interface RemoteToolRef {
|
|
117
|
+
/** One-line description shown to the model (overrides Core's describe). */
|
|
118
|
+
description?: string;
|
|
119
|
+
/** Fully-qualified Ryu tool id, e.g. `composio.GMAIL_SEARCH_EMAILS`. */
|
|
120
|
+
id: string;
|
|
121
|
+
readonly kind: "remote";
|
|
122
|
+
/**
|
|
123
|
+
* JSON Schema for the tool's arguments. Optional: when omitted, a permissive
|
|
124
|
+
* open-object schema is used (Composio `describe` is shallow), so supplying
|
|
125
|
+
* this materially improves the model's tool-call accuracy.
|
|
126
|
+
*/
|
|
127
|
+
parameters?: Record<string, unknown>;
|
|
128
|
+
}
|
|
129
|
+
/** Options accepted by `ryuTool`. */
|
|
130
|
+
interface RyuToolOptions {
|
|
131
|
+
description?: string;
|
|
132
|
+
parameters?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Reference an existing Ryu tool by id so an `Agent` can call it.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* ryuTool("composio.GMAIL_SEARCH_EMAILS", {
|
|
140
|
+
* description: "Search the user's Gmail",
|
|
141
|
+
* parameters: { type: "object", properties: { query: { type: "string" } }, required: ["query"] },
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare function ryuTool(id: string, opts?: RyuToolOptions): RemoteToolRef;
|
|
146
|
+
/** A tool an `Agent` can expose to the model: local runnable or remote ref. */
|
|
147
|
+
type AgentTool = RemoteToolRef | ToolRunnable;
|
|
148
|
+
/** Everything the tool layer needs to resolve schemas + execute calls. */
|
|
149
|
+
interface ToolExecContext {
|
|
150
|
+
/** Core agent id — REQUIRED for remote tools (governs execution). */
|
|
151
|
+
agentId?: string;
|
|
152
|
+
/** Core base URL (no trailing `/api`). */
|
|
153
|
+
coreBaseUrl: string;
|
|
154
|
+
/** Bearer token for Core (`RYU_TOKEN`); may be undefined on loopback dev. */
|
|
155
|
+
coreToken?: string;
|
|
156
|
+
/** RunnableContext handed to local tools so they may call the gateway. */
|
|
157
|
+
runnableContext: RunnableContext;
|
|
158
|
+
/** Abort signal. */
|
|
159
|
+
signal?: AbortSignal;
|
|
160
|
+
/** Composio connected-account entity selector. */
|
|
161
|
+
userId?: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Build the OpenAI `tools[]` array the model sees, keyed by the developer's
|
|
165
|
+
* config names. Remote tools without an explicit `parameters` schema are
|
|
166
|
+
* described from Core (`describe` is shallow) and given a permissive schema.
|
|
167
|
+
*/
|
|
168
|
+
declare function resolveToolDefs(tools: Record<string, AgentTool>, ctx: ToolExecContext): Promise<ToolFunctionDef[]>;
|
|
169
|
+
/** Result of executing one tool call. */
|
|
170
|
+
interface ToolExecResult {
|
|
171
|
+
/** Raw tool output (already JSON-parsed when the tool returned JSON). */
|
|
172
|
+
output: unknown;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Execute a single model tool call by config `name`, dispatching to the local
|
|
176
|
+
* runnable or the Core `/api/mcp/tools/call` endpoint.
|
|
177
|
+
*
|
|
178
|
+
* `argsJson` is the raw JSON string from `tool_call.function.arguments`.
|
|
179
|
+
*/
|
|
180
|
+
declare function executeTool(name: string, argsJson: string, tools: Record<string, AgentTool>, ctx: ToolExecContext): Promise<ToolExecResult>;
|
|
181
|
+
/** The connect-required envelope Core returns when an account isn't linked. */
|
|
182
|
+
interface Elicitation {
|
|
183
|
+
kind?: string;
|
|
184
|
+
message?: string;
|
|
185
|
+
url?: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Detect Ryu's connection-required envelope in a tool output. Mirrors Core's
|
|
189
|
+
* `detect_elicitation` (apps/core/src/sidecar/mcp/composio.rs): the first Gmail
|
|
190
|
+
* call for an unconnected account returns `{ "__ryu_elicitation__": { url } }`.
|
|
191
|
+
*/
|
|
192
|
+
declare function detectElicitation(output: unknown): Elicitation | null;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The autonomous agent loop for the Ryu SDK runtime.
|
|
196
|
+
*
|
|
197
|
+
* This is what `defineAgent` never had: a real multi-turn tool-calling loop that
|
|
198
|
+
* runs in TypeScript. Each round calls the node's gateway with the resolved
|
|
199
|
+
* tool definitions; if the model emits `tool_calls`, each is executed (local
|
|
200
|
+
* runnable or Core `/api/mcp/tools/call`), results are fed back, and the loop
|
|
201
|
+
* repeats until the model stops calling tools or `maxSteps` is reached.
|
|
202
|
+
*
|
|
203
|
+
* Emitted events mirror Core's `AcpEvent` categories (see cli/dev.ts) plus an
|
|
204
|
+
* `auth_required` pause — when a remote tool returns Ryu's connection-required
|
|
205
|
+
* envelope (first-run Gmail OAuth), the loop surfaces the connect URL and stops
|
|
206
|
+
* instead of feeding the envelope back as a normal tool result.
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
/** A streamed text fragment from the assistant. */
|
|
210
|
+
interface AgentEventText {
|
|
211
|
+
content: string;
|
|
212
|
+
type: "text";
|
|
213
|
+
}
|
|
214
|
+
/** The model initiated a tool call. */
|
|
215
|
+
interface AgentEventToolCall {
|
|
216
|
+
id: string;
|
|
217
|
+
input: unknown;
|
|
218
|
+
name: string;
|
|
219
|
+
type: "tool_call";
|
|
220
|
+
}
|
|
221
|
+
/** A tool finished (or failed with an error output the model can recover from). */
|
|
222
|
+
interface AgentEventToolResult {
|
|
223
|
+
id: string;
|
|
224
|
+
name: string;
|
|
225
|
+
output: unknown;
|
|
226
|
+
type: "tool_result";
|
|
227
|
+
}
|
|
228
|
+
/** A remote tool needs an account connection — the loop paused. */
|
|
229
|
+
interface AgentEventAuthRequired {
|
|
230
|
+
message?: string;
|
|
231
|
+
tool: string;
|
|
232
|
+
type: "auth_required";
|
|
233
|
+
url?: string;
|
|
234
|
+
}
|
|
235
|
+
/** A fatal loop error — the stream ends after this. */
|
|
236
|
+
interface AgentEventError {
|
|
237
|
+
message: string;
|
|
238
|
+
type: "error";
|
|
239
|
+
}
|
|
240
|
+
/** Terminal event carrying the final text, step count, and aggregate usage. */
|
|
241
|
+
interface AgentEventResult {
|
|
242
|
+
steps: number;
|
|
243
|
+
text: string;
|
|
244
|
+
type: "result";
|
|
245
|
+
usage?: ModelUsage;
|
|
246
|
+
}
|
|
247
|
+
/** Union of everything the loop yields. */
|
|
248
|
+
type AgentEvent = AgentEventAuthRequired | AgentEventError | AgentEventResult | AgentEventText | AgentEventToolCall | AgentEventToolResult;
|
|
249
|
+
/** Inputs for a single loop run. */
|
|
250
|
+
interface LoopConfig {
|
|
251
|
+
/** Gateway base URL for inference (the target node). */
|
|
252
|
+
gatewayBaseUrl: string;
|
|
253
|
+
/** Gateway bearer token. */
|
|
254
|
+
gatewayToken?: string;
|
|
255
|
+
/** Hard ceiling on model→tool rounds. */
|
|
256
|
+
maxSteps: number;
|
|
257
|
+
/** Seed transcript (system + user messages already assembled). */
|
|
258
|
+
messages: LoopMessage[];
|
|
259
|
+
/** Model id routed by the gateway. */
|
|
260
|
+
model: string;
|
|
261
|
+
/** Abort signal. */
|
|
262
|
+
signal?: AbortSignal;
|
|
263
|
+
/** Context for resolving + executing tools. */
|
|
264
|
+
toolCtx: ToolExecContext;
|
|
265
|
+
/** Tools keyed by model-facing name. */
|
|
266
|
+
tools: Record<string, AgentTool>;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Run the autonomous loop, yielding events as they occur. The generator returns
|
|
270
|
+
* after a terminal `result`, `auth_required`, or `error` event.
|
|
271
|
+
*/
|
|
272
|
+
declare function runAgentLoop(config: LoopConfig): AsyncGenerator<AgentEvent>;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* `Agent` — the declarative agent runtime for `@ryu/sdk`.
|
|
276
|
+
*
|
|
277
|
+
* Unlike `defineAgent` (a declaration wrapper whose `run()` you write by hand),
|
|
278
|
+
* `Agent` OWNS the loop: give it instructions, a model, a target node, and a
|
|
279
|
+
* set of tools, then call `generate()` / `stream()`. Inference is pointed at the
|
|
280
|
+
* node's gateway; tool calls resolve to local `defineTool` runnables or existing
|
|
281
|
+
* Ryu tools (`ryuTool`) executed through Core.
|
|
282
|
+
*
|
|
283
|
+
* Mirrors Mastra's config-object + `.generate()`/`.stream()` shape; `query()`
|
|
284
|
+
* (see query.ts) wraps the same runtime in a Claude-Agent-SDK-style streaming
|
|
285
|
+
* call.
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
/** A target node for inference / tool execution: a base URL + optional token. */
|
|
289
|
+
interface Endpoint {
|
|
290
|
+
baseUrl?: string;
|
|
291
|
+
token?: string;
|
|
292
|
+
}
|
|
293
|
+
/** Declarative configuration for an `Agent`. */
|
|
294
|
+
interface AgentConfig {
|
|
295
|
+
/** Core agent id — REQUIRED when using `ryuTool` remote tools (governance). */
|
|
296
|
+
agentId?: string;
|
|
297
|
+
/** Core endpoint for tool discovery/execution. Defaults to env/localhost. */
|
|
298
|
+
core?: Endpoint;
|
|
299
|
+
/** System prompt / persona. */
|
|
300
|
+
instructions?: string;
|
|
301
|
+
/** Hard ceiling on model→tool rounds (default 10). */
|
|
302
|
+
maxSteps?: number;
|
|
303
|
+
/** Model id routed by the node's gateway. */
|
|
304
|
+
model: string;
|
|
305
|
+
/** Display name. */
|
|
306
|
+
name: string;
|
|
307
|
+
/** Target node for inference. Defaults to the local gateway. */
|
|
308
|
+
node?: Endpoint;
|
|
309
|
+
/**
|
|
310
|
+
* Reverse-domain plugin id. When set, the composable primitive surface
|
|
311
|
+
* (`ctx.rag`, `ctx.memory`, `ctx.engines`, …) is mounted on the run context,
|
|
312
|
+
* routed through this node via the governed host bridge / capability broker.
|
|
313
|
+
* Omitted = no primitives mounted (the bridge families authenticate a plugin
|
|
314
|
+
* id, so a half-wired transport is never attached).
|
|
315
|
+
*/
|
|
316
|
+
pluginId?: string;
|
|
317
|
+
/** Tools keyed by the model-facing name. */
|
|
318
|
+
tools?: Record<string, AgentTool>;
|
|
319
|
+
/** Composio connected-account entity selector. */
|
|
320
|
+
userId?: string;
|
|
321
|
+
}
|
|
322
|
+
/** Result of a non-streaming `generate()`. */
|
|
323
|
+
interface GenerateResult {
|
|
324
|
+
/** Present when the run paused for an account connection. */
|
|
325
|
+
authRequired?: AgentEventAuthRequired;
|
|
326
|
+
/** Number of model→tool rounds taken. */
|
|
327
|
+
steps: number;
|
|
328
|
+
/** Final assistant text. */
|
|
329
|
+
text: string;
|
|
330
|
+
/** Aggregate token usage across all rounds (when reported). */
|
|
331
|
+
usage?: ModelUsage;
|
|
332
|
+
}
|
|
333
|
+
/** A declarative, loop-owning agent. */
|
|
334
|
+
declare class Agent {
|
|
335
|
+
readonly config: AgentConfig;
|
|
336
|
+
constructor(config: AgentConfig);
|
|
337
|
+
/** Assemble the loop config for a given prompt. */
|
|
338
|
+
private buildLoopConfig;
|
|
339
|
+
/** Stream loop events (text / tool_call / tool_result / auth_required / …). */
|
|
340
|
+
stream(prompt: string, signal?: AbortSignal): AsyncGenerator<AgentEvent>;
|
|
341
|
+
/** Run to completion and return the final text, step count, and usage. */
|
|
342
|
+
generate(prompt: string, signal?: AbortSignal): Promise<GenerateResult>;
|
|
343
|
+
}
|
|
344
|
+
/** Factory alias for `new Agent(config)`. */
|
|
345
|
+
declare function createAgent(config: AgentConfig): Agent;
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* `query()` — Claude-Agent-SDK-style streaming entry over the same `Agent`.
|
|
349
|
+
*
|
|
350
|
+
* Where `Agent` gives you Mastra's config-object + method shape, `query()` gives
|
|
351
|
+
* you the `for await (const msg of query({ prompt, options }))` ergonomics of
|
|
352
|
+
* the Claude Agent SDK. Both drive the identical loop; this is a thin wrapper.
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
/** Options accepted by `query` — an `AgentConfig` with an optional `name`. */
|
|
356
|
+
type QueryOptions = Omit<AgentConfig, "name"> & {
|
|
357
|
+
name?: string;
|
|
358
|
+
};
|
|
359
|
+
/** Input to `query`: a prompt plus agent options. */
|
|
360
|
+
interface QueryInput {
|
|
361
|
+
options: QueryOptions;
|
|
362
|
+
prompt: string;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Run an agent for a single prompt and stream its events.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* for await (const msg of query({
|
|
370
|
+
* prompt: "Find my expenses from last month.",
|
|
371
|
+
* options: { model: "gpt-4o", agentId: "agent-expense", tools: { gmailSearch } },
|
|
372
|
+
* })) {
|
|
373
|
+
* if (msg.type === "result") console.log(msg.text);
|
|
374
|
+
* }
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
declare function query(input: QueryInput): AsyncGenerator<AgentEvent>;
|
|
378
|
+
|
|
379
|
+
export { Agent, type AgentConfig, type AgentEvent, type AgentEventAuthRequired, type AgentEventError, type AgentEventResult, type AgentEventText, type AgentEventToolCall, type AgentEventToolResult, type AgentTool, type AssistantMessage, type Elicitation, type Endpoint, type GenerateResult, type LoopConfig, type LoopMessage, type ModelCallOptions, type ModelCallResult, type ModelUsage, type QueryInput, type QueryOptions, type RemoteToolRef, type RyuToolOptions, type ToolCall, type ToolExecContext, type ToolExecResult, type ToolFunctionDef, callModelWithTools, createAgent, detectElicitation, executeTool, query, resolveToolDefs, runAgentLoop, ryuTool };
|