@mastra/client-js 1.18.0-alpha.9 → 1.18.1-alpha.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/CHANGELOG.md +292 -0
- package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +9 -12
- package/dist/client.d.ts +7 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-signals.md +151 -0
- package/dist/docs/references/reference-client-js-agents.md +89 -0
- package/dist/index.cjs +117 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +116 -73
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts +1 -1
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent-builder.d.ts +1 -1
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/agent.d.ts +16 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/mcp-tool.d.ts.map +1 -1
- package/dist/resources/memory-thread.d.ts +27 -7
- package/dist/resources/memory-thread.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +2154 -778
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +31 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-a2a-stream.d.ts +1 -1
- package/dist/utils/process-a2a-stream.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +4 -2
- package/dist/utils/process-mastra-stream.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Signals
|
|
2
|
+
|
|
3
|
+
> **Experimental:** Agent signals are experimental. The API may change in a future release.
|
|
4
|
+
|
|
5
|
+
Signals are a way to interact with an agent through a thread. Instead of starting every interaction with `agent.stream()`, subscribe to a thread and send signals. Mastra either wakes the agent when the thread is idle or drops the signal into the running agent loop.
|
|
6
|
+
|
|
7
|
+
Signals are a context engineering tool for guiding the agent in real time as the agent loop progresses. Use them to add system-generated content from external event sources, such as incoming email notifications, GitHub pull request comments, background task notifications, and similar events.
|
|
8
|
+
|
|
9
|
+
## Quickstart
|
|
10
|
+
|
|
11
|
+
Subscribe to the thread before sending signals. The subscription receives the active stream when the signal wakes the agent or enters a running loop.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
const subscription = await agent.subscribeToThread({
|
|
15
|
+
resourceId: 'user_123',
|
|
16
|
+
threadId: 'thread_456',
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
agent.sendSignal(
|
|
20
|
+
{
|
|
21
|
+
type: 'user-message',
|
|
22
|
+
contents: 'Compare that with the previous option.',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
resourceId: 'user_123',
|
|
26
|
+
threadId: 'thread_456',
|
|
27
|
+
},
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
for await (const chunk of subscription.stream) {
|
|
31
|
+
console.log(chunk)
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
When the thread has a running agent stream, the signal becomes new input inside that agent loop. When the thread is idle, Mastra starts a stream with the signal as the first input.
|
|
36
|
+
|
|
37
|
+
## Control signal behavior
|
|
38
|
+
|
|
39
|
+
By default, Mastra delivers signals to active runs and wakes idle threads. Use `ifActive.behavior` and `ifIdle.behavior` to change that behavior.
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
const result = agent.sendSignal(
|
|
43
|
+
{
|
|
44
|
+
type: 'user-message',
|
|
45
|
+
contents: 'Store this for later, but do not wake the agent.',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
resourceId: 'user_123',
|
|
49
|
+
threadId: 'thread_456',
|
|
50
|
+
ifIdle: {
|
|
51
|
+
behavior: 'persist',
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
await result.persisted
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The behavior options are:
|
|
60
|
+
|
|
61
|
+
- `ifActive.behavior: 'deliver'`: Add the signal to the running agent loop. This is the default.
|
|
62
|
+
- `ifActive.behavior: 'persist'`: Save the signal to memory without adding it to the running loop.
|
|
63
|
+
- `ifActive.behavior: 'discard'`: Ignore the signal while the thread is active.
|
|
64
|
+
- `ifIdle.behavior: 'wake'`: Start a stream with the signal as the first input. This is the default.
|
|
65
|
+
- `ifIdle.behavior: 'persist'`: Save the signal to memory without starting a stream.
|
|
66
|
+
- `ifIdle.behavior: 'discard'`: Ignore the signal while the thread is idle.
|
|
67
|
+
|
|
68
|
+
Pass `ifIdle.streamOptions` when the idle wake-up stream needs options such as model settings, tools, or runtime context. You do not need to repeat `memory.resource` or `memory.thread`; Mastra uses the top-level `resourceId` and `threadId` for the thread.
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
agent.sendSignal(
|
|
72
|
+
{
|
|
73
|
+
type: 'user-message',
|
|
74
|
+
contents: 'Continue with the next step.',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
resourceId: 'user_123',
|
|
78
|
+
threadId: 'thread_456',
|
|
79
|
+
ifIdle: {
|
|
80
|
+
behavior: 'wake',
|
|
81
|
+
streamOptions: {
|
|
82
|
+
maxSteps: 3,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Send external event context
|
|
90
|
+
|
|
91
|
+
Use custom signal types for system-generated context. Non-user signal types are rendered as XML-style user-role context so they can appear inside conversation history without looking like assistant output.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
agent.sendSignal(
|
|
95
|
+
{
|
|
96
|
+
type: 'system-reminder',
|
|
97
|
+
contents: 'User X has left a new PR comment asking for a smaller API surface.',
|
|
98
|
+
attributes: {
|
|
99
|
+
type: 'github',
|
|
100
|
+
pr: '123',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
resourceId: 'user_123',
|
|
105
|
+
threadId: 'thread_456',
|
|
106
|
+
},
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The model receives the custom signal as context like this:
|
|
111
|
+
|
|
112
|
+
```xml
|
|
113
|
+
<system-reminder type="github" pr="123">User X has left a new PR comment asking for a smaller API surface.</system-reminder>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use XML-safe signal type names and attribute names. Signal type names and attribute names can contain letters, numbers, underscores, periods, and hyphens. They must start with a letter or underscore.
|
|
117
|
+
|
|
118
|
+
## Use the client SDK
|
|
119
|
+
|
|
120
|
+
The JavaScript client exposes the same thread signal APIs. Use `subscribeToThread()` before `sendSignal()` so the client can render the stream that wakes from, or receives, the signal.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const agent = client.getAgent('supportAgent')
|
|
124
|
+
|
|
125
|
+
const subscription = await agent.subscribeToThread({
|
|
126
|
+
resourceId: 'user_123',
|
|
127
|
+
threadId: 'thread_456',
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
await agent.sendSignal({
|
|
131
|
+
signal: {
|
|
132
|
+
type: 'user-message',
|
|
133
|
+
contents: 'Show the shorter version.',
|
|
134
|
+
},
|
|
135
|
+
resourceId: 'user_123',
|
|
136
|
+
threadId: 'thread_456',
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
await subscription.processDataStream({
|
|
140
|
+
onChunk: chunk => {
|
|
141
|
+
console.log(chunk)
|
|
142
|
+
},
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Related
|
|
147
|
+
|
|
148
|
+
- [`Agent.sendSignal()`](https://mastra.ai/reference/agents/agent)
|
|
149
|
+
- [`Agent.subscribeToThread()`](https://mastra.ai/reference/agents/agent)
|
|
150
|
+
- [`client.getAgent().sendSignal()`](https://mastra.ai/reference/client-js/agents)
|
|
151
|
+
- [`client.getAgent().subscribeToThread()`](https://mastra.ai/reference/client-js/agents)
|
|
@@ -151,6 +151,95 @@ for await (const part of uiMessageStream) {
|
|
|
151
151
|
}
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
### `sendSignal()`
|
|
155
|
+
|
|
156
|
+
Send a signal to an active agent run or memory thread. Use this with `subscribeToThread()` so the client can render the stream that wakes from, or receives, the signal.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const agent = mastraClient.getAgent('support-agent')
|
|
160
|
+
|
|
161
|
+
const result = await agent.sendSignal({
|
|
162
|
+
signal: {
|
|
163
|
+
type: 'user-message',
|
|
164
|
+
contents: 'Also consider the customer note I just added.',
|
|
165
|
+
},
|
|
166
|
+
resourceId: 'user-123',
|
|
167
|
+
threadId: 'thread-abc',
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
console.log(result.runId)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Use `ifActive.behavior` and `ifIdle.behavior` to control whether Mastra delivers, persists, discards, or wakes from a signal:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
await agent.sendSignal({
|
|
177
|
+
signal: { type: 'user-message', contents: 'Store this for later.' },
|
|
178
|
+
resourceId: 'user-123',
|
|
179
|
+
threadId: 'thread-abc',
|
|
180
|
+
ifIdle: {
|
|
181
|
+
behavior: 'persist',
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
Pass `ifIdle.streamOptions` when the idle wake-up stream needs options such as model settings, tools, or runtime context:
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
await agent.sendSignal({
|
|
190
|
+
signal: { type: 'user-message', contents: 'Start from this signal.' },
|
|
191
|
+
resourceId: 'user-123',
|
|
192
|
+
threadId: 'thread-abc',
|
|
193
|
+
ifIdle: {
|
|
194
|
+
behavior: 'wake',
|
|
195
|
+
streamOptions: {
|
|
196
|
+
maxSteps: 3,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Returns `{ accepted: true, runId: string }`.
|
|
203
|
+
|
|
204
|
+
**signal** (`{ type: 'user-message'; contents: MessageListInput } | { type: string; contents: string }`): \`user-message\` signals are treated as user input. Other signal types are converted to contextual XML before the next model call.
|
|
205
|
+
|
|
206
|
+
**runId** (`string`): Run ID to target directly.
|
|
207
|
+
|
|
208
|
+
**resourceId** (`string`): Resource ID for the memory thread. Use with \`threadId\` for thread-targeted signals.
|
|
209
|
+
|
|
210
|
+
**threadId** (`string`): Thread ID to target. Use with \`resourceId\` for thread-targeted signals.
|
|
211
|
+
|
|
212
|
+
**ifActive.behavior** (`'deliver' | 'persist' | 'discard'`): Controls what happens when the target thread is active. Defaults to \`deliver\`.
|
|
213
|
+
|
|
214
|
+
**ifIdle.behavior** (`'wake' | 'persist' | 'discard'`): Controls what happens when the target thread is idle. Defaults to \`wake\`.
|
|
215
|
+
|
|
216
|
+
**ifIdle.streamOptions** (`Omit<AgentExecutionOptions, 'messages'>`): Options for the stream that starts when \`ifIdle.behavior\` is \`wake\`.
|
|
217
|
+
|
|
218
|
+
### `subscribeToThread()`
|
|
219
|
+
|
|
220
|
+
Subscribe to raw stream chunks for a memory thread. Use this to render output from a thread that may be started or continued by `sendSignal()`.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
const agent = mastraClient.getAgent('support-agent')
|
|
224
|
+
|
|
225
|
+
const subscription = await agent.subscribeToThread({
|
|
226
|
+
resourceId: 'user-123',
|
|
227
|
+
threadId: 'thread-abc',
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
await subscription.processDataStream({
|
|
231
|
+
onChunk: async chunk => {
|
|
232
|
+
console.log(chunk)
|
|
233
|
+
},
|
|
234
|
+
})
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
`subscribeToThread()` returns the underlying `Response` plus a `processDataStream()` helper. The helper reads the subscription stream until the connection closes or the request is aborted.
|
|
238
|
+
|
|
239
|
+
**resourceId** (`string`): Resource ID for the memory thread.
|
|
240
|
+
|
|
241
|
+
**threadId** (`string`): Thread ID to subscribe to.
|
|
242
|
+
|
|
154
243
|
### `streamUntilIdle()`
|
|
155
244
|
|
|
156
245
|
Stream a response and keep the stream open until every [background task](https://mastra.ai/docs/agents/background-tasks) dispatched during the run completes. The server re-enters the agentic loop on each task completion so the LLM can react to results in the same call. Requires background tasks to be [enabled on the Mastra instance](https://mastra.ai/reference/configuration) and a memory thread; otherwise the call falls through to a plain `stream()`.
|
package/dist/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var error = require('@mastra/core/error');
|
|
|
6
6
|
var schema = require('@mastra/schema-compat/schema');
|
|
7
7
|
var requestContext = require('@mastra/core/request-context');
|
|
8
8
|
var zodToJson = require('@mastra/schema-compat/zod-to-json');
|
|
9
|
-
var
|
|
9
|
+
var client = require('@mastra/core/a2a/client');
|
|
10
10
|
var canonicalize = require('canonicalize');
|
|
11
11
|
var jose = require('jose');
|
|
12
12
|
|
|
@@ -135,11 +135,15 @@ function processClientTools(clientTools) {
|
|
|
135
135
|
// src/utils/process-mastra-stream.ts
|
|
136
136
|
async function sharedProcessMastraStream({
|
|
137
137
|
stream,
|
|
138
|
-
onChunk
|
|
138
|
+
onChunk,
|
|
139
|
+
signal
|
|
139
140
|
}) {
|
|
140
141
|
const reader = stream.getReader();
|
|
141
142
|
const decoder = new TextDecoder();
|
|
142
143
|
let buffer = "";
|
|
144
|
+
const abort = () => void reader.cancel();
|
|
145
|
+
if (signal?.aborted) abort();
|
|
146
|
+
else signal?.addEventListener("abort", abort, { once: true });
|
|
143
147
|
try {
|
|
144
148
|
while (true) {
|
|
145
149
|
const { done, value } = await reader.read();
|
|
@@ -167,25 +171,30 @@ async function sharedProcessMastraStream({
|
|
|
167
171
|
}
|
|
168
172
|
}
|
|
169
173
|
} finally {
|
|
174
|
+
signal?.removeEventListener("abort", abort);
|
|
170
175
|
reader.releaseLock();
|
|
171
176
|
}
|
|
172
177
|
}
|
|
173
178
|
async function processMastraNetworkStream({
|
|
174
179
|
stream,
|
|
175
|
-
onChunk
|
|
180
|
+
onChunk,
|
|
181
|
+
signal
|
|
176
182
|
}) {
|
|
177
183
|
return sharedProcessMastraStream({
|
|
178
184
|
stream,
|
|
179
|
-
onChunk
|
|
185
|
+
onChunk,
|
|
186
|
+
signal
|
|
180
187
|
});
|
|
181
188
|
}
|
|
182
189
|
async function processMastraStream({
|
|
183
190
|
stream,
|
|
184
|
-
onChunk
|
|
191
|
+
onChunk,
|
|
192
|
+
signal
|
|
185
193
|
}) {
|
|
186
194
|
return sharedProcessMastraStream({
|
|
187
195
|
stream,
|
|
188
|
-
onChunk
|
|
196
|
+
onChunk,
|
|
197
|
+
signal
|
|
189
198
|
});
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -348,8 +357,6 @@ var AgentVoice = class extends BaseResource {
|
|
|
348
357
|
this.version = version;
|
|
349
358
|
this.agentId = agentId;
|
|
350
359
|
}
|
|
351
|
-
agentId;
|
|
352
|
-
version;
|
|
353
360
|
getQueryString(requestContext, delimiter = "?") {
|
|
354
361
|
const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
|
|
355
362
|
if (this.version) {
|
|
@@ -419,8 +426,6 @@ var Agent = class extends BaseResource {
|
|
|
419
426
|
this.version = version;
|
|
420
427
|
this.voice = new AgentVoice(options, this.agentId, this.version);
|
|
421
428
|
}
|
|
422
|
-
agentId;
|
|
423
|
-
version;
|
|
424
429
|
voice;
|
|
425
430
|
getQueryString(requestContext, delimiter = "?") {
|
|
426
431
|
const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
|
|
@@ -446,6 +451,38 @@ var Agent = class extends BaseResource {
|
|
|
446
451
|
body: { instructions, comment }
|
|
447
452
|
});
|
|
448
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* @experimental Agent signals are experimental and may change in a future release.
|
|
456
|
+
*/
|
|
457
|
+
sendSignal(params) {
|
|
458
|
+
return this.request(`/agents/${this.agentId}/signals`, {
|
|
459
|
+
method: "POST",
|
|
460
|
+
body: params
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* @experimental Agent signals are experimental and may change in a future release.
|
|
465
|
+
*/
|
|
466
|
+
async subscribeToThread(params) {
|
|
467
|
+
const streamResponse = await this.request(`/agents/${this.agentId}/threads/subscribe`, {
|
|
468
|
+
method: "POST",
|
|
469
|
+
body: params,
|
|
470
|
+
stream: true
|
|
471
|
+
});
|
|
472
|
+
if (!streamResponse.body) {
|
|
473
|
+
throw new Error("No response body");
|
|
474
|
+
}
|
|
475
|
+
streamResponse.processDataStream = async ({
|
|
476
|
+
onChunk
|
|
477
|
+
}) => {
|
|
478
|
+
await processMastraStream({
|
|
479
|
+
stream: streamResponse.body,
|
|
480
|
+
onChunk,
|
|
481
|
+
signal: this.options.abortSignal
|
|
482
|
+
});
|
|
483
|
+
};
|
|
484
|
+
return streamResponse;
|
|
485
|
+
}
|
|
449
486
|
/**
|
|
450
487
|
* Clones this agent to a new stored agent in the database
|
|
451
488
|
* @param params - Clone parameters including optional newId, newName, metadata, authorId, and requestContext
|
|
@@ -1905,13 +1942,25 @@ var MemoryThread = class extends BaseResource {
|
|
|
1905
1942
|
this.threadId = threadId;
|
|
1906
1943
|
this.agentId = agentId;
|
|
1907
1944
|
}
|
|
1908
|
-
threadId;
|
|
1909
|
-
agentId;
|
|
1910
1945
|
/**
|
|
1911
1946
|
* Builds the query string for agentId (if provided)
|
|
1912
1947
|
*/
|
|
1913
|
-
getAgentIdQueryParam(prefix = "?") {
|
|
1914
|
-
|
|
1948
|
+
getAgentIdQueryParam(prefix = "?", overrideAgentId) {
|
|
1949
|
+
const agentId = overrideAgentId ?? this.agentId;
|
|
1950
|
+
return agentId ? `${prefix}agentId=${agentId}` : "";
|
|
1951
|
+
}
|
|
1952
|
+
/**
|
|
1953
|
+
* Resolves the agentId to use for a write request. Prefers the per-call value, falls back
|
|
1954
|
+
* to the constructor value, and throws if neither is set.
|
|
1955
|
+
*/
|
|
1956
|
+
requireAgentId(perCallAgentId, methodName) {
|
|
1957
|
+
const agentId = perCallAgentId ?? this.agentId;
|
|
1958
|
+
if (!agentId) {
|
|
1959
|
+
throw new Error(
|
|
1960
|
+
`MemoryThread.${methodName}() requires an agentId. Pass it via getMemoryThread({ threadId, agentId }) or as a parameter to ${methodName}().`
|
|
1961
|
+
);
|
|
1962
|
+
}
|
|
1963
|
+
return agentId;
|
|
1915
1964
|
}
|
|
1916
1965
|
/**
|
|
1917
1966
|
* Retrieves the memory thread details
|
|
@@ -1925,25 +1974,30 @@ var MemoryThread = class extends BaseResource {
|
|
|
1925
1974
|
}
|
|
1926
1975
|
/**
|
|
1927
1976
|
* Updates the memory thread properties
|
|
1928
|
-
* @param params - Update parameters including title, metadata, and optional request context
|
|
1977
|
+
* @param params - Update parameters including title, metadata, and optional request context.
|
|
1978
|
+
* `agentId` is required by the server; pass it here if not supplied on the constructor.
|
|
1929
1979
|
* @returns Promise containing updated thread details
|
|
1930
1980
|
*/
|
|
1931
1981
|
update(params) {
|
|
1932
|
-
const
|
|
1933
|
-
const
|
|
1982
|
+
const agentId = this.requireAgentId(params.agentId, "update");
|
|
1983
|
+
const { agentId: _omitAgentId, requestContext, ...body } = params;
|
|
1984
|
+
const agentIdParam = `?agentId=${agentId}`;
|
|
1985
|
+
const contextParam = requestContextQueryString(requestContext, "&");
|
|
1934
1986
|
return this.request(`/memory/threads/${this.threadId}${agentIdParam}${contextParam}`, {
|
|
1935
1987
|
method: "PATCH",
|
|
1936
|
-
body
|
|
1988
|
+
body
|
|
1937
1989
|
});
|
|
1938
1990
|
}
|
|
1939
1991
|
/**
|
|
1940
1992
|
* Deletes the memory thread
|
|
1941
|
-
* @param
|
|
1993
|
+
* @param opts - Optional `agentId` (required by the server when not supplied on the constructor)
|
|
1994
|
+
* and request context.
|
|
1942
1995
|
* @returns Promise containing deletion result
|
|
1943
1996
|
*/
|
|
1944
|
-
delete(
|
|
1945
|
-
const
|
|
1946
|
-
const
|
|
1997
|
+
delete(opts = {}) {
|
|
1998
|
+
const agentId = this.requireAgentId(opts.agentId, "delete");
|
|
1999
|
+
const agentIdParam = `?agentId=${agentId}`;
|
|
2000
|
+
const contextParam = requestContextQueryString(opts.requestContext, "&");
|
|
1947
2001
|
return this.request(`/memory/threads/${this.threadId}${agentIdParam}${contextParam}`, {
|
|
1948
2002
|
method: "DELETE"
|
|
1949
2003
|
});
|
|
@@ -1973,37 +2027,46 @@ var MemoryThread = class extends BaseResource {
|
|
|
1973
2027
|
* Deletes one or more messages from the thread
|
|
1974
2028
|
* @param messageIds - Can be a single message ID (string), array of message IDs,
|
|
1975
2029
|
* message object with id property, or array of message objects
|
|
1976
|
-
* @param
|
|
2030
|
+
* @param opts - Optional `agentId` (required by the server when not supplied on the constructor)
|
|
2031
|
+
* and request context. For backwards compatibility a `RequestContext` may also be
|
|
2032
|
+
* passed directly as the second argument.
|
|
1977
2033
|
* @returns Promise containing deletion result
|
|
1978
2034
|
*/
|
|
1979
|
-
deleteMessages(messageIds,
|
|
1980
|
-
const
|
|
1981
|
-
|
|
1982
|
-
const
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
method: "POST",
|
|
1988
|
-
body: { messageIds }
|
|
1989
|
-
}
|
|
1990
|
-
);
|
|
2035
|
+
deleteMessages(messageIds, opts = {}) {
|
|
2036
|
+
const { agentId: explicitAgentId, requestContext } = normalizeWriteOpts(opts);
|
|
2037
|
+
const agentId = this.requireAgentId(explicitAgentId, "deleteMessages");
|
|
2038
|
+
const queryString = `agentId=${agentId}`;
|
|
2039
|
+
return this.request(`/memory/messages/delete?${queryString}${requestContextQueryString(requestContext, "&")}`, {
|
|
2040
|
+
method: "POST",
|
|
2041
|
+
body: { messageIds }
|
|
2042
|
+
});
|
|
1991
2043
|
}
|
|
1992
2044
|
/**
|
|
1993
2045
|
* Clones the thread with all its messages to a new thread
|
|
1994
|
-
* @param params - Clone parameters including optional new thread ID, title, metadata, and message filters
|
|
2046
|
+
* @param params - Clone parameters including optional new thread ID, title, metadata, and message filters.
|
|
2047
|
+
* `agentId` is required by the server; pass it here if not supplied on the constructor.
|
|
1995
2048
|
* @returns Promise containing the cloned thread and copied messages
|
|
1996
2049
|
*/
|
|
1997
2050
|
clone(params = {}) {
|
|
1998
|
-
const
|
|
1999
|
-
const
|
|
2000
|
-
const
|
|
2051
|
+
const agentId = this.requireAgentId(params.agentId, "clone");
|
|
2052
|
+
const { agentId: _omitAgentId, requestContext, ...body } = params;
|
|
2053
|
+
const agentIdParam = `?agentId=${agentId}`;
|
|
2054
|
+
const contextParam = requestContextQueryString(requestContext, "&");
|
|
2001
2055
|
return this.request(`/memory/threads/${this.threadId}/clone${agentIdParam}${contextParam}`, {
|
|
2002
2056
|
method: "POST",
|
|
2003
2057
|
body
|
|
2004
2058
|
});
|
|
2005
2059
|
}
|
|
2006
2060
|
};
|
|
2061
|
+
function normalizeWriteOpts(opts) {
|
|
2062
|
+
if (!opts || typeof opts !== "object") return {};
|
|
2063
|
+
if ("agentId" in opts || "requestContext" in opts) {
|
|
2064
|
+
const o = opts;
|
|
2065
|
+
return { agentId: o.agentId, requestContext: o.requestContext };
|
|
2066
|
+
}
|
|
2067
|
+
if (Object.keys(opts).length === 0) return {};
|
|
2068
|
+
return { requestContext: opts };
|
|
2069
|
+
}
|
|
2007
2070
|
|
|
2008
2071
|
// src/resources/vector.ts
|
|
2009
2072
|
var Vector = class extends BaseResource {
|
|
@@ -2011,7 +2074,6 @@ var Vector = class extends BaseResource {
|
|
|
2011
2074
|
super(options);
|
|
2012
2075
|
this.vectorName = vectorName;
|
|
2013
2076
|
}
|
|
2014
|
-
vectorName;
|
|
2015
2077
|
/**
|
|
2016
2078
|
* Retrieves details about a specific vector index
|
|
2017
2079
|
* @param indexName - Name of the index to get details for
|
|
@@ -2084,7 +2146,6 @@ var Tool = class extends BaseResource {
|
|
|
2084
2146
|
super(options);
|
|
2085
2147
|
this.toolId = toolId;
|
|
2086
2148
|
}
|
|
2087
|
-
toolId;
|
|
2088
2149
|
/**
|
|
2089
2150
|
* Retrieves details about the tool
|
|
2090
2151
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -2120,7 +2181,6 @@ var Processor = class extends BaseResource {
|
|
|
2120
2181
|
super(options);
|
|
2121
2182
|
this.processorId = processorId;
|
|
2122
2183
|
}
|
|
2123
|
-
processorId;
|
|
2124
2184
|
/**
|
|
2125
2185
|
* Retrieves details about the processor
|
|
2126
2186
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -2202,8 +2262,6 @@ var Run = class extends BaseResource {
|
|
|
2202
2262
|
this.workflowId = workflowId;
|
|
2203
2263
|
this.runId = runId;
|
|
2204
2264
|
}
|
|
2205
|
-
workflowId;
|
|
2206
|
-
runId;
|
|
2207
2265
|
/**
|
|
2208
2266
|
* Creates a transform stream that parses RECORD_SEPARATOR-delimited JSON chunks
|
|
2209
2267
|
*/
|
|
@@ -2596,7 +2654,6 @@ var Workflow = class extends BaseResource {
|
|
|
2596
2654
|
super(options);
|
|
2597
2655
|
this.workflowId = workflowId;
|
|
2598
2656
|
}
|
|
2599
|
-
workflowId;
|
|
2600
2657
|
/**
|
|
2601
2658
|
* Retrieves details about the workflow
|
|
2602
2659
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -2925,7 +2982,7 @@ async function verifyAgentCardSignatureIfPresent(agentCard, options) {
|
|
|
2925
2982
|
function createA2AJsonRpcError(response) {
|
|
2926
2983
|
const error = response.error;
|
|
2927
2984
|
const message = error?.message ?? "Unknown A2A JSON-RPC error";
|
|
2928
|
-
return typeof error?.code === "number" ? new
|
|
2985
|
+
return typeof error?.code === "number" ? new client.MastraA2AError(error.code, message, error.data) : new MastraClientError(200, "OK", `A2A JSON-RPC error - ${message}`, error);
|
|
2929
2986
|
}
|
|
2930
2987
|
function unwrapA2AResult(response) {
|
|
2931
2988
|
if ("error" in response && response.error) {
|
|
@@ -2959,7 +3016,6 @@ var A2A = class extends BaseResource {
|
|
|
2959
3016
|
super(options);
|
|
2960
3017
|
this.agentId = agentId;
|
|
2961
3018
|
}
|
|
2962
|
-
agentId;
|
|
2963
3019
|
/**
|
|
2964
3020
|
* Get the agent card with metadata about the agent.
|
|
2965
3021
|
* @param options - Optional Agent Card verification settings
|
|
@@ -3191,12 +3247,10 @@ var MCPTool = class extends BaseResource {
|
|
|
3191
3247
|
execute(params) {
|
|
3192
3248
|
const body = {};
|
|
3193
3249
|
if (params.data !== void 0) body.data = params.data;
|
|
3194
|
-
if (params.requestContext !== void 0)
|
|
3195
|
-
body.requestContext = params.requestContext;
|
|
3196
|
-
}
|
|
3250
|
+
if (params.requestContext !== void 0) body.requestContext = params.requestContext;
|
|
3197
3251
|
return this.request(`/mcp/${encodeURIComponent(this.serverId)}/tools/${encodeURIComponent(this.toolId)}/execute`, {
|
|
3198
3252
|
method: "POST",
|
|
3199
|
-
body
|
|
3253
|
+
body
|
|
3200
3254
|
});
|
|
3201
3255
|
}
|
|
3202
3256
|
};
|
|
@@ -3208,7 +3262,6 @@ var AgentBuilder = class extends BaseResource {
|
|
|
3208
3262
|
super(options);
|
|
3209
3263
|
this.actionId = actionId;
|
|
3210
3264
|
}
|
|
3211
|
-
actionId;
|
|
3212
3265
|
// Helper function to transform workflow result to action result
|
|
3213
3266
|
transformWorkflowResult(result) {
|
|
3214
3267
|
if (result.status === "success") {
|
|
@@ -3395,13 +3448,14 @@ var AgentBuilder = class extends BaseResource {
|
|
|
3395
3448
|
* This calls `/agent-builder/:actionId/stream`.
|
|
3396
3449
|
*/
|
|
3397
3450
|
async stream(params, runId) {
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
searchParams.set("runId", runId);
|
|
3451
|
+
if (!runId) {
|
|
3452
|
+
throw new Error("runId is required to stream an agent builder action");
|
|
3401
3453
|
}
|
|
3454
|
+
const searchParams = new URLSearchParams();
|
|
3455
|
+
searchParams.set("runId", runId);
|
|
3402
3456
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
3403
3457
|
const { requestContext: _, ...actionParams } = params;
|
|
3404
|
-
const url = `/agent-builder/${this.actionId}/stream
|
|
3458
|
+
const url = `/agent-builder/${this.actionId}/stream?${searchParams.toString()}`;
|
|
3405
3459
|
const response = await this.request(url, {
|
|
3406
3460
|
method: "POST",
|
|
3407
3461
|
body: { ...actionParams, requestContext },
|
|
@@ -3935,7 +3989,6 @@ var StoredAgent = class extends BaseResource {
|
|
|
3935
3989
|
super(options);
|
|
3936
3990
|
this.storedAgentId = storedAgentId;
|
|
3937
3991
|
}
|
|
3938
|
-
storedAgentId;
|
|
3939
3992
|
/**
|
|
3940
3993
|
* Retrieves details about the stored agent
|
|
3941
3994
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4095,7 +4148,6 @@ var StoredPromptBlock = class extends BaseResource {
|
|
|
4095
4148
|
super(options);
|
|
4096
4149
|
this.storedPromptBlockId = storedPromptBlockId;
|
|
4097
4150
|
}
|
|
4098
|
-
storedPromptBlockId;
|
|
4099
4151
|
/**
|
|
4100
4152
|
* Retrieves details about the stored prompt block
|
|
4101
4153
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4255,7 +4307,6 @@ var StoredMCPClient = class extends BaseResource {
|
|
|
4255
4307
|
super(options);
|
|
4256
4308
|
this.storedMCPClientId = storedMCPClientId;
|
|
4257
4309
|
}
|
|
4258
|
-
storedMCPClientId;
|
|
4259
4310
|
/**
|
|
4260
4311
|
* Retrieves details about the stored MCP client
|
|
4261
4312
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4302,7 +4353,6 @@ var StoredScorer = class extends BaseResource {
|
|
|
4302
4353
|
super(options);
|
|
4303
4354
|
this.storedScorerId = storedScorerId;
|
|
4304
4355
|
}
|
|
4305
|
-
storedScorerId;
|
|
4306
4356
|
/**
|
|
4307
4357
|
* Retrieves details about the stored scorer definition
|
|
4308
4358
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4463,7 +4513,6 @@ var ToolProvider = class extends BaseResource {
|
|
|
4463
4513
|
super(options);
|
|
4464
4514
|
this.providerId = providerId;
|
|
4465
4515
|
}
|
|
4466
|
-
providerId;
|
|
4467
4516
|
/**
|
|
4468
4517
|
* Lists available toolkits from this provider
|
|
4469
4518
|
* @returns Promise containing list of toolkits
|
|
@@ -4513,7 +4562,6 @@ var ProcessorProvider = class extends BaseResource {
|
|
|
4513
4562
|
super(options);
|
|
4514
4563
|
this.providerId = providerId;
|
|
4515
4564
|
}
|
|
4516
|
-
providerId;
|
|
4517
4565
|
/**
|
|
4518
4566
|
* Gets details about this processor provider and its available processors
|
|
4519
4567
|
* @returns Promise containing provider info and processor list
|
|
@@ -4533,9 +4581,6 @@ var WorkspaceSkillResource = class extends BaseResource {
|
|
|
4533
4581
|
this.basePath = `/workspaces/${encodeURIComponent(this.workspaceId)}/skills/${encodeURIComponent(this.skillName)}`;
|
|
4534
4582
|
this.pathQuery = this.skillPath ? `?path=${encodeURIComponent(this.skillPath)}` : "";
|
|
4535
4583
|
}
|
|
4536
|
-
workspaceId;
|
|
4537
|
-
skillName;
|
|
4538
|
-
skillPath;
|
|
4539
4584
|
basePath;
|
|
4540
4585
|
pathQuery;
|
|
4541
4586
|
/**
|
|
@@ -4755,7 +4800,6 @@ var StoredSkill = class extends BaseResource {
|
|
|
4755
4800
|
super(options);
|
|
4756
4801
|
this.storedSkillId = storedSkillId;
|
|
4757
4802
|
}
|
|
4758
|
-
storedSkillId;
|
|
4759
4803
|
/**
|
|
4760
4804
|
* Retrieves details about the stored skill
|
|
4761
4805
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -4852,7 +4896,6 @@ var ResponsesStream = class {
|
|
|
4852
4896
|
constructor(response) {
|
|
4853
4897
|
this.response = response;
|
|
4854
4898
|
}
|
|
4855
|
-
response;
|
|
4856
4899
|
asResponse() {
|
|
4857
4900
|
return this.response;
|
|
4858
4901
|
}
|
|
@@ -5112,13 +5155,13 @@ var MastraClient = class extends BaseResource {
|
|
|
5112
5155
|
}
|
|
5113
5156
|
return this.request(url);
|
|
5114
5157
|
}
|
|
5115
|
-
deleteThread(threadId, opts
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5119
|
-
|
|
5120
|
-
url = `/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
5158
|
+
deleteThread(threadId, opts) {
|
|
5159
|
+
if (!opts || !!opts.agentId === !!opts.networkId) {
|
|
5160
|
+
throw new Error(
|
|
5161
|
+
"MastraClient.deleteThread() requires exactly one of agentId or networkId. The server cannot resolve which memory store owns the thread without one, and passing both is ambiguous."
|
|
5162
|
+
);
|
|
5121
5163
|
}
|
|
5164
|
+
const url = opts.agentId ? `/memory/threads/${threadId}?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}` : `/memory/network/threads/${threadId}?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
|
|
5122
5165
|
return this.request(url, { method: "DELETE" });
|
|
5123
5166
|
}
|
|
5124
5167
|
/**
|
|
@@ -5262,7 +5305,7 @@ var MastraClient = class extends BaseResource {
|
|
|
5262
5305
|
* @returns Promise containing map of action IDs to action details
|
|
5263
5306
|
*/
|
|
5264
5307
|
getAgentBuilderActions() {
|
|
5265
|
-
return this.request("/agent-builder
|
|
5308
|
+
return this.request("/agent-builder");
|
|
5266
5309
|
}
|
|
5267
5310
|
/**
|
|
5268
5311
|
* Gets an agent builder instance for executing agent-builder workflows
|