@mastra/client-js 1.22.0 → 1.23.0-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 +31 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-signals.md +229 -9
- package/dist/docs/references/docs-editor-overview.md +11 -10
- package/dist/docs/references/reference-client-js-agents.md +41 -7
- package/dist/index.cjs +81 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +81 -50
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +21 -1
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/stored-agent.d.ts +8 -1
- package/dist/resources/stored-agent.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +36 -0
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.23.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added `GET /stored/agents/:storedAgentId/dependents` endpoint that lists agents ([#17183](https://github.com/mastra-ai/mastra/pull/17183))
|
|
8
|
+
referencing a stored agent as a sub-agent.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
const { dependents, hiddenCount } = await client.getStoredAgent(id).dependents();
|
|
12
|
+
// { dependents: [{ id: 'parent-1', name: 'Triager' }], hiddenCount: 2 }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- `dependents` — caller-readable agents (public agents and the caller's own private
|
|
16
|
+
agents) with `id` + `name`.
|
|
17
|
+
- `hiddenCount` — cross-workspace dependents the caller cannot read, only surfaced
|
|
18
|
+
when the target agent is public.
|
|
19
|
+
|
|
20
|
+
Access mirrors `GET /stored/agents/:storedAgentId` — 404 when the caller cannot
|
|
21
|
+
read the target.
|
|
22
|
+
|
|
23
|
+
- Add experimental `agent.sendMessage()` and `agent.queueMessage()` helpers for the new message-first server routes. ([#17238](https://github.com/mastra-ai/mastra/pull/17238))
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Improved agent message, stream, and observational-memory type handling across the client SDKs and playground UI. ([#17208](https://github.com/mastra-ai/mastra/pull/17208))
|
|
28
|
+
|
|
29
|
+
- Fixed subscribed client tools so browser-executed tool results continue through the existing thread subscription instead of opening and canceling a second stream. This prevents closed-stream errors in apps like Agent Builder when multiple client tools run during one response. ([#17532](https://github.com/mastra-ai/mastra/pull/17532))
|
|
30
|
+
|
|
31
|
+
- Updated dependencies [[`c973db4`](https://github.com/mastra-ai/mastra/commit/c973db428df1b564ff0c35d4b2a90e8f4f1e13fd), [`552285e`](https://github.com/mastra-ai/mastra/commit/552285e5af43cfc680a0972032cab8de8776c6a0), [`77e686c`](https://github.com/mastra-ai/mastra/commit/77e686c264e493e99ae5024e4dfe3ea5d5a09718), [`ece8dba`](https://github.com/mastra-ai/mastra/commit/ece8dba7ec1a5089eee8c33167cd762bfa91e509), [`e751af2`](https://github.com/mastra-ai/mastra/commit/e751af219433fbf4c7035b2d771b4c9ec8813b05), [`e2a8380`](https://github.com/mastra-ai/mastra/commit/e2a838017a7657850404c1e94c70d79ffdc6f14a), [`be3f1cd`](https://github.com/mastra-ai/mastra/commit/be3f1cd81f0e2a649e8eac15a024d542d814aef8), [`a34d9db`](https://github.com/mastra-ai/mastra/commit/a34d9dbc39fedb722f271318e9355ecee70489ab)]:
|
|
32
|
+
- @mastra/core@1.39.0-alpha.0
|
|
33
|
+
|
|
3
34
|
## 1.22.0
|
|
4
35
|
|
|
5
36
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-client-js
|
|
|
3
3
|
description: Documentation for @mastra/client-js. Use when working with @mastra/client-js APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/client-js"
|
|
6
|
-
version: "1.
|
|
6
|
+
version: "1.23.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -97,7 +97,7 @@ The behavior options are:
|
|
|
97
97
|
- `ifIdle.behavior: 'persist'`: Save the signal or message to memory without starting a stream.
|
|
98
98
|
- `ifIdle.behavior: 'discard'`: Ignore the signal or message while the thread is idle.
|
|
99
99
|
|
|
100
|
-
Pass `ifIdle.streamOptions` when the idle wake-up stream needs options such as model settings, tools, or runtime context. You
|
|
100
|
+
Pass `ifIdle.streamOptions` when the idle wake-up stream needs options such as model settings, tools, or runtime context. You don't need to repeat `memory.resource` or `memory.thread`; Mastra uses the top-level `resourceId` and `threadId` for the thread.
|
|
101
101
|
|
|
102
102
|
```typescript
|
|
103
103
|
agent.sendMessage('Continue with the next step.', {
|
|
@@ -143,6 +143,10 @@ The model receives the signal as context like this:
|
|
|
143
143
|
|
|
144
144
|
Use XML-safe `tagName` and attribute names. They can contain letters, numbers, underscores, periods, and hyphens. They must start with a letter or underscore.
|
|
145
145
|
|
|
146
|
+
### Storage support
|
|
147
|
+
|
|
148
|
+
Notification inbox storage is available in the storage adapters that support richer memory and signal workflows: [libSQL](https://mastra.ai/reference/storage/libsql), [PostgreSQL](https://mastra.ai/reference/storage/postgresql), and [MongoDB](https://mastra.ai/reference/storage/mongodb). These adapters expose notification records through `getStore('notifications')`.
|
|
149
|
+
|
|
146
150
|
## Send processor context
|
|
147
151
|
|
|
148
152
|
Processors can send reactive signals during a run. A processor should inspect the chat history, react to a specific trigger, and avoid sending the same context more than once.
|
|
@@ -220,7 +224,224 @@ When the agent is idle:
|
|
|
220
224
|
<user source="chat" delivery="new-message">Also cover the edge cases.</user>
|
|
221
225
|
```
|
|
222
226
|
|
|
223
|
-
Top-level `attributes` always apply. The selected branch's `attributes` are merged into them at delivery time. The `delivery` name shown above
|
|
227
|
+
Top-level `attributes` always apply. The selected branch's `attributes` are merged into them at delivery time. The `delivery` name shown above isn't a special Mastra API field. It's a custom attribute name used for this example. Add any attribute names that suit your use case.
|
|
228
|
+
|
|
229
|
+
## State signals
|
|
230
|
+
|
|
231
|
+
State signals expose named, thread-scoped context lanes. Use them for durable context that changes over time, such as browser state, editor state, or a background watcher result.
|
|
232
|
+
|
|
233
|
+
Each state signal needs:
|
|
234
|
+
|
|
235
|
+
- `id`: The state lane name, such as `browser`.
|
|
236
|
+
- `cacheKey`: A producer-owned key for deduping the current state.
|
|
237
|
+
- `mode`: `snapshot` for an authoritative state copy, or `delta` for a change event.
|
|
238
|
+
|
|
239
|
+
Use `sendStateSignal()` when an external producer detects a state change.
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
await agent.sendStateSignal(
|
|
243
|
+
{
|
|
244
|
+
id: 'browser',
|
|
245
|
+
mode: 'snapshot',
|
|
246
|
+
cacheKey: 'browser:https://example.com:3-tabs',
|
|
247
|
+
contents: 'Browser is open on https://example.com with 3 tabs.',
|
|
248
|
+
value: {
|
|
249
|
+
activeUrl: 'https://example.com',
|
|
250
|
+
tabCount: 3,
|
|
251
|
+
open: true,
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
resourceId: 'user_123',
|
|
256
|
+
threadId: 'thread_456',
|
|
257
|
+
},
|
|
258
|
+
)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
When Mastra accepts a state signal, it stores compact tracking metadata on the thread. The metadata records the lane's current `cacheKey`, current mode, version, last signal id, and last snapshot signal id. If a producer sends the same `cacheKey` and mode again while that state is still current, Mastra skips the duplicate.
|
|
262
|
+
|
|
263
|
+
State signal fields have separate roles:
|
|
264
|
+
|
|
265
|
+
- `contents`: The representation the model reads.
|
|
266
|
+
- `value`: The structured snapshot for `mode: 'snapshot'`.
|
|
267
|
+
- `delta`: The structured change for `mode: 'delta'`.
|
|
268
|
+
- `metadata.state`: The runtime tracking envelope with `id`, `mode`, `cacheKey`, `version`, and `threadId`.
|
|
269
|
+
|
|
270
|
+
Use `computeStateSignal()` when a processor owns a state lane. Mastra calls it once per model input step after `processInputStep()`. If the processor omits `id`, Mastra uses the processor id as the state lane id. Set `stateId` when the public state lane should differ from the processor id.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import type { ComputeStateSignalArgs, Processor } from '@mastra/core/processors'
|
|
274
|
+
|
|
275
|
+
export const browserStateProcessor: Processor = {
|
|
276
|
+
id: 'browser-state',
|
|
277
|
+
stateId: 'browser',
|
|
278
|
+
computeStateSignal(args: ComputeStateSignalArgs) {
|
|
279
|
+
const browser = readCurrentBrowserState()
|
|
280
|
+
const previous = readMostRecentBrowserState(args.activeStateSignals)
|
|
281
|
+
const changed = previous ? diffBrowserState(previous, browser) : browser
|
|
282
|
+
const shouldRefreshSnapshot = Boolean(args.lastSnapshot && !args.contextWindow.hasSnapshot)
|
|
283
|
+
|
|
284
|
+
if (previous && Object.keys(changed).length === 0 && !shouldRefreshSnapshot) {
|
|
285
|
+
return
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const isDelta = Boolean(previous && !shouldRefreshSnapshot)
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
mode: isDelta ? 'delta' : 'snapshot',
|
|
292
|
+
cacheKey: stableBrowserStateCacheKey(browser),
|
|
293
|
+
contents: isDelta ? describeBrowserDelta(changed) : describeBrowserSnapshot(browser),
|
|
294
|
+
value: browser,
|
|
295
|
+
...(isDelta ? { delta: changed } : {}),
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
}
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Mastra passes `lastSnapshot` and `deltasSinceSnapshot` into `computeStateSignal()`. It resolves them from message history when the current message list doesn't contain the latest snapshot. The processor still owns merge and diff logic.
|
|
302
|
+
|
|
303
|
+
`contextWindow.hasSnapshot` tells the processor whether the active message window already contains a snapshot for this state lane. If it's `false`, return a fresh `snapshot` so the model sees the current state even after older state messages are trimmed from the context window.
|
|
304
|
+
|
|
305
|
+
The built-in browser context processor emits state under the `browser` id with snapshot and delta modes.
|
|
306
|
+
|
|
307
|
+
## Notification signals
|
|
308
|
+
|
|
309
|
+
Notification signals represent external events such as GitHub activity, email, Slack mentions, CI status, incidents, recordings, or direct messages. Use `agent.sendNotificationSignal()` when the event should create a durable inbox record.
|
|
310
|
+
|
|
311
|
+
Notification delivery has two phases:
|
|
312
|
+
|
|
313
|
+
- **Ingress**: `agent.sendNotificationSignal()` stores a notification record, then resolves the agent's delivery policy.
|
|
314
|
+
- **Dispatch**: Mastra consumes due records stamped with `deliverAt` or `summaryAt` and emits full notification or summary signals.
|
|
315
|
+
|
|
316
|
+
A notification record stores the source, kind, priority, summary, payload, resource id, thread id, agent id, coalescing keys, and delivery metadata. The delivery decision controls what happens after ingress:
|
|
317
|
+
|
|
318
|
+
- `deliver` or `queue`: Emit a full `<notification>` signal and mark the record `delivered`.
|
|
319
|
+
- `defer`: Keep the record `pending` with `deliverAt`.
|
|
320
|
+
- `summarize`: Keep the record `pending` with `summaryAt`, or emit an immediate summary when the policy requests it.
|
|
321
|
+
- `persist`: Keep the record `pending` in the inbox without scheduled delivery.
|
|
322
|
+
- `discard`: Mark the record `discarded` and emit no signal.
|
|
323
|
+
|
|
324
|
+
The default delivery policy is priority-aware:
|
|
325
|
+
|
|
326
|
+
| Priority | Active thread | Idle thread |
|
|
327
|
+
| -------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
328
|
+
| `urgent` | Deliver a full notification immediately | Deliver a full notification immediately |
|
|
329
|
+
| `high` | Emit a summary immediately, keep `deliverAt`, then deliver the full notification when the thread is idle | Deliver a full notification immediately |
|
|
330
|
+
| `medium` | Batch with `summaryAt` and later deliver one notification summary | Deliver a full notification immediately |
|
|
331
|
+
| `low` | Batch with `summaryAt` and later deliver one notification summary | Batch with `summaryAt` and later deliver one notification summary without waking the model loop |
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
await agent.sendNotificationSignal(
|
|
335
|
+
{
|
|
336
|
+
source: 'github',
|
|
337
|
+
kind: 'ci-status',
|
|
338
|
+
priority: 'high',
|
|
339
|
+
summary: 'CI failed on main: 3 tests failed.',
|
|
340
|
+
payload: {
|
|
341
|
+
repository: 'acme/app',
|
|
342
|
+
branch: 'main',
|
|
343
|
+
},
|
|
344
|
+
dedupeKey: 'github:acme/app:main:ci',
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
resourceId: 'user_123',
|
|
348
|
+
threadId: 'thread_456',
|
|
349
|
+
},
|
|
350
|
+
)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
The model receives full notifications as context:
|
|
354
|
+
|
|
355
|
+
```xml
|
|
356
|
+
<notification source="github" type="ci-status" priority="high" status="delivered">CI failed on main: 3 tests failed.</notification>
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Notification summaries tell the model that inbox records are waiting:
|
|
360
|
+
|
|
361
|
+
```xml
|
|
362
|
+
<notification-summary pending="10">github: 3, email: 5, slack: 2</notification-summary>
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
When Mastra emits a summary, it clears `summaryAt` and sets `summarySignalId` on each summarized record. The records stay pending and readable. When Mastra emits a full notification, it sets `deliveredSignalId` and marks the record `delivered`. If the inbox tool reads a notification first, it can inject the full notification signal and mark the record `seen`, which prevents duplicate full delivery.
|
|
366
|
+
|
|
367
|
+
Configure a delivery policy on the agent when some notifications should wait for a different dispatch window or summary rollup.
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
export const supportAgent = new Agent({
|
|
371
|
+
id: 'support-agent',
|
|
372
|
+
name: 'Support Agent',
|
|
373
|
+
instructions: 'Help the user triage updates.',
|
|
374
|
+
model: 'openai/gpt-5.5',
|
|
375
|
+
notifications: {
|
|
376
|
+
deliveryPolicy: {
|
|
377
|
+
priorities: {
|
|
378
|
+
urgent: 'deliver',
|
|
379
|
+
},
|
|
380
|
+
decide: ({ record }) => {
|
|
381
|
+
if (record.priority === 'low') {
|
|
382
|
+
return {
|
|
383
|
+
action: 'summarize',
|
|
384
|
+
summaryAt: new Date(Date.now() + 30 * 60 * 1000),
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
})
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Enable scheduled dispatch at the Mastra level so deferred notifications and summary rollups are delivered through the existing workflow scheduler.
|
|
394
|
+
|
|
395
|
+
```typescript
|
|
396
|
+
export const mastra = new Mastra({
|
|
397
|
+
agents: { supportAgent },
|
|
398
|
+
storage,
|
|
399
|
+
notifications: {
|
|
400
|
+
dispatch: {
|
|
401
|
+
enabled: true,
|
|
402
|
+
cron: '*/1 * * * *',
|
|
403
|
+
batchSize: 100,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
})
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`notifications.dispatch.enabled` registers an internal workflow with the default cron `*/1 * * * *`. The dispatcher reads due notification records from storage, groups summaries by `agentId`, `resourceId`, and `threadId`, and emits signals through the Agent thread runtime. It isn't a user-facing entrypoint.
|
|
410
|
+
|
|
411
|
+
### Notification inbox tool
|
|
412
|
+
|
|
413
|
+
Use `createNotificationInboxTool()` to give agents one tool for inbox actions instead of many CRUD tools.
|
|
414
|
+
|
|
415
|
+
```typescript
|
|
416
|
+
import { createNotificationInboxTool } from '@mastra/core/notifications'
|
|
417
|
+
|
|
418
|
+
const notificationsStorage = await storage.getStore('notifications')
|
|
419
|
+
|
|
420
|
+
export const supportAgent = new Agent({
|
|
421
|
+
id: 'support-agent',
|
|
422
|
+
name: 'Support Agent',
|
|
423
|
+
instructions: 'Help the user triage updates.',
|
|
424
|
+
model: 'openai/gpt-5.5',
|
|
425
|
+
tools: {
|
|
426
|
+
notificationInbox: createNotificationInboxTool({ storage: notificationsStorage }),
|
|
427
|
+
},
|
|
428
|
+
})
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
The tool id is `notification-inbox`. It supports these actions:
|
|
432
|
+
|
|
433
|
+
- `list`: List notifications for the current thread.
|
|
434
|
+
- `read`: Deliver readable full notification signals into the chat when possible, then mark records `seen`.
|
|
435
|
+
- `markSeen`: Mark one record `seen`.
|
|
436
|
+
- `dismiss`: Mark one record `dismissed`.
|
|
437
|
+
- `archive`: Mark one record `archived`.
|
|
438
|
+
- `search`: Search notification summaries in the current thread.
|
|
439
|
+
|
|
440
|
+
The tool uses the current `threadId` from the tool execution context unless one is provided. Use `read` after a `<notification-summary>` signal when the agent needs the full records behind the summary. The `read` result reports how many notifications will be delivered; it doesn't use normal tool output as the main context channel for the notification contents.
|
|
441
|
+
|
|
442
|
+
`sendNotificationSignal()` requires a storage domain with `notifications` support. LibSQL supports notifications. Other storage adapters need matching notification domain support before they can store notification records.
|
|
443
|
+
|
|
444
|
+
Use `sendSignal({ type: 'notification' })` only for lower-level notification-shaped context that should bypass inbox storage.
|
|
224
445
|
|
|
225
446
|
## Compatibility
|
|
226
447
|
|
|
@@ -229,7 +450,7 @@ Mastra still accepts legacy signal payloads such as `type: 'user-message'` and `
|
|
|
229
450
|
- `type: 'user-message'`: Normalizes to `type: 'user'` and `tagName: 'user'`
|
|
230
451
|
- `type: 'system-reminder'`: Normalizes to `type: 'reactive'` and `tagName: 'system-reminder'`
|
|
231
452
|
|
|
232
|
-
Existing stored signal rows and older clients continue to load through the compatibility layer.
|
|
453
|
+
Existing stored signal rows and older clients continue to load through the compatibility layer. New clients call the message routes when the server supports them; React's thread signal path falls back to the legacy `/signals` route when it detects an older server.
|
|
233
454
|
|
|
234
455
|
> **Note:** Visit [Agent signals reference](https://mastra.ai/reference/agents/agent) for the full message, signal, and subscription types.
|
|
235
456
|
|
|
@@ -264,11 +485,8 @@ const subscription = await agent.subscribeToThread({
|
|
|
264
485
|
threadId: 'thread_456',
|
|
265
486
|
})
|
|
266
487
|
|
|
267
|
-
await agent.
|
|
268
|
-
|
|
269
|
-
type: 'user-message',
|
|
270
|
-
contents: 'Show the shorter version.',
|
|
271
|
-
},
|
|
488
|
+
await agent.sendMessage({
|
|
489
|
+
message: 'Show the shorter version.',
|
|
272
490
|
resourceId: 'user_123',
|
|
273
491
|
threadId: 'thread_456',
|
|
274
492
|
})
|
|
@@ -307,7 +525,9 @@ Use heartbeats together with client-side reconnect logic. Heartbeats reduce idle
|
|
|
307
525
|
- [`Agent.queueMessage()`](https://mastra.ai/reference/agents/agent)
|
|
308
526
|
- [`Agent.sendSignal()`](https://mastra.ai/reference/agents/agent)
|
|
309
527
|
- [`Agent.subscribeToThread()`](https://mastra.ai/reference/agents/agent)
|
|
310
|
-
- [
|
|
528
|
+
- [`client.getAgent().sendMessage()`](https://mastra.ai/reference/client-js/agents)
|
|
529
|
+
- [`client.getAgent().queueMessage()`](https://mastra.ai/reference/client-js/agents)
|
|
311
530
|
- [`client.getAgent().sendSignal()`](https://mastra.ai/reference/client-js/agents)
|
|
531
|
+
- [Server agent routes](https://mastra.ai/reference/server/routes)
|
|
312
532
|
- [`client.getAgent().subscribeToThread()`](https://mastra.ai/reference/client-js/agents)
|
|
313
533
|
- [`client.getAgent().sendToolApproval()`](https://mastra.ai/reference/client-js/agents)
|
|
@@ -149,16 +149,17 @@ The `editor.agent` namespace also exposes `getById`, `list`, `listResolved`, and
|
|
|
149
149
|
|
|
150
150
|
The same operations are available over HTTP through the Mastra server. Use these when you want to manage stored agents from a separate service or from a non-TypeScript client:
|
|
151
151
|
|
|
152
|
-
| Method | Path
|
|
153
|
-
| -------- |
|
|
154
|
-
| `GET` | `/stored/agents`
|
|
155
|
-
| `POST` | `/stored/agents`
|
|
156
|
-
| `GET` | `/stored/agents/:storedAgentId`
|
|
157
|
-
| `PATCH` | `/stored/agents/:storedAgentId`
|
|
158
|
-
| `DELETE` | `/stored/agents/:storedAgentId`
|
|
159
|
-
| `
|
|
160
|
-
|
|
161
|
-
|
|
152
|
+
| Method | Path | Description |
|
|
153
|
+
| -------- | ------------------------------------------ | ---------------------------------------------------------------- |
|
|
154
|
+
| `GET` | `/stored/agents` | List all stored agents. |
|
|
155
|
+
| `POST` | `/stored/agents` | Create a stored agent. |
|
|
156
|
+
| `GET` | `/stored/agents/:storedAgentId` | Get a stored agent by ID. |
|
|
157
|
+
| `PATCH` | `/stored/agents/:storedAgentId` | Update a stored agent. |
|
|
158
|
+
| `DELETE` | `/stored/agents/:storedAgentId` | Delete a stored agent. |
|
|
159
|
+
| `GET` | `/stored/agents/:storedAgentId/dependents` | List agents that reference this agent as a sub-agent. |
|
|
160
|
+
| `POST` | `/stored/agents/:storedAgentId/export` | Export a stored agent's override as a deterministic JSON config. |
|
|
161
|
+
|
|
162
|
+
The dependents endpoint helps warn before deleting or unsharing an agent that other agents depend on: `dependents` lists caller-readable agents by `id` and `name`, while `hiddenCount` aggregates cross-workspace references the caller cannot read (surfaced only when the target is public). The export endpoint returns only the fields the agent's [`editor` config](https://mastra.ai/reference/agents/agent) allows, so the output matches the per-agent file the code source writes to disk. The Client SDK wraps these endpoints with `client.listStoredAgents()`, `client.createStoredAgent()`, `client.getStoredAgent()`, `client.getStoredAgent(id).dependents()`, and `client.getStoredAgent(id).export()`. Version management endpoints live under `/stored/agents/:storedAgentId/versions`, see [version management](https://mastra.ai/reference/client-js/agents) for the full list.
|
|
162
163
|
|
|
163
164
|
### Automated experimentation
|
|
164
165
|
|
|
@@ -151,17 +151,51 @@ for await (const part of uiMessageStream) {
|
|
|
151
151
|
}
|
|
152
152
|
```
|
|
153
153
|
|
|
154
|
+
### `sendMessage()`
|
|
155
|
+
|
|
156
|
+
Send user-authored input to an active agent run or idle memory thread. Use this with `subscribeToThread()` so the client can render the stream that wakes from, or receives, the message.
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
const agent = mastraClient.getAgent('support-agent')
|
|
160
|
+
|
|
161
|
+
const result = await agent.sendMessage({
|
|
162
|
+
message: {
|
|
163
|
+
contents: 'Also consider the customer note I just added.',
|
|
164
|
+
attributes: { sentFrom: 'web' },
|
|
165
|
+
},
|
|
166
|
+
resourceId: 'user-123',
|
|
167
|
+
threadId: 'thread-abc',
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
console.log(result.runId)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
`message` accepts a string, an array of text/file parts, or an object with `contents`, `attributes`, `metadata`, and `providerOptions`.
|
|
174
|
+
|
|
175
|
+
### `queueMessage()`
|
|
176
|
+
|
|
177
|
+
Queue user-authored input for the next thread turn. If the thread is active, Mastra starts a new run after the current run completes. If the thread is idle, Mastra starts a run immediately.
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
await agent.queueMessage({
|
|
181
|
+
message: 'Also check whether the tests need updates.',
|
|
182
|
+
resourceId: 'user-123',
|
|
183
|
+
threadId: 'thread-abc',
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
154
187
|
### `sendSignal()`
|
|
155
188
|
|
|
156
|
-
Send a signal to an active agent run or memory thread. Use this
|
|
189
|
+
Send a lower-level signal to an active agent run or memory thread. Use this for system-generated context such as reactive reminders or notification-shaped context that doesn't need inbox storage. For durable notification records, use the server-side [`Agent.sendNotificationSignal()`](https://mastra.ai/reference/agents/agent) API. For user-authored input, prefer `sendMessage()` or `queueMessage()`.
|
|
157
190
|
|
|
158
191
|
```typescript
|
|
159
192
|
const agent = mastraClient.getAgent('support-agent')
|
|
160
193
|
|
|
161
194
|
const result = await agent.sendSignal({
|
|
162
195
|
signal: {
|
|
163
|
-
type: '
|
|
164
|
-
|
|
196
|
+
type: 'reactive',
|
|
197
|
+
tagName: 'system-reminder',
|
|
198
|
+
contents: 'Also consider the latest customer note.',
|
|
165
199
|
},
|
|
166
200
|
resourceId: 'user-123',
|
|
167
201
|
threadId: 'thread-abc',
|
|
@@ -174,7 +208,7 @@ Use `ifActive.behavior` and `ifIdle.behavior` to control whether Mastra delivers
|
|
|
174
208
|
|
|
175
209
|
```typescript
|
|
176
210
|
await agent.sendSignal({
|
|
177
|
-
signal: { type: '
|
|
211
|
+
signal: { type: 'reactive', tagName: 'system-reminder', contents: 'Store this for later.' },
|
|
178
212
|
resourceId: 'user-123',
|
|
179
213
|
threadId: 'thread-abc',
|
|
180
214
|
ifIdle: {
|
|
@@ -187,7 +221,7 @@ Pass `ifIdle.streamOptions` when the idle wake-up stream needs options such as m
|
|
|
187
221
|
|
|
188
222
|
```typescript
|
|
189
223
|
await agent.sendSignal({
|
|
190
|
-
signal: { type: '
|
|
224
|
+
signal: { type: 'reactive', tagName: 'system-reminder', contents: 'Start from this signal.' },
|
|
191
225
|
resourceId: 'user-123',
|
|
192
226
|
threadId: 'thread-abc',
|
|
193
227
|
ifIdle: {
|
|
@@ -201,7 +235,7 @@ await agent.sendSignal({
|
|
|
201
235
|
|
|
202
236
|
Returns `{ accepted: true, runId: string }`.
|
|
203
237
|
|
|
204
|
-
**signal** (`{ type: 'user
|
|
238
|
+
**signal** (`{ type: 'user' | 'reactive' | 'notification' | string; tagName?: string; contents: string | Array<TextPart | FilePart>; attributes?: Record<string, JSONValue>; metadata?: Record<string, unknown>; providerOptions?: ProviderMetadata }`): Lower-level signal payload. Use \`type\` for the semantic signal category and \`tagName\` for the XML tag shown to the model. \`providerOptions\` is attached to the resulting prompt turn and persisted on the stored signal message.
|
|
205
239
|
|
|
206
240
|
**runId** (`string`): Run ID to target directly.
|
|
207
241
|
|
|
@@ -217,7 +251,7 @@ Returns `{ accepted: true, runId: string }`.
|
|
|
217
251
|
|
|
218
252
|
### `subscribeToThread()`
|
|
219
253
|
|
|
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()
|
|
254
|
+
Subscribe to raw stream chunks for a memory thread. Use this to render output from a thread that may be started or continued by `sendMessage()`, `queueMessage()`, `sendSignal()`, or server-side notification dispatch.
|
|
221
255
|
|
|
222
256
|
```typescript
|
|
223
257
|
const agent = mastraClient.getAgent('support-agent')
|
package/dist/index.cjs
CHANGED
|
@@ -760,6 +760,53 @@ var Agent = class extends BaseResource {
|
|
|
760
760
|
const threadKey = this.getSignalRuntimeThreadKey({ resourceId, threadId });
|
|
761
761
|
if (threadKey) deleteSignalRuntimeOptionsEntry(latestSignalRuntimeOptionsByThread, threadKey);
|
|
762
762
|
}
|
|
763
|
+
prepareSignalRouteBody(params) {
|
|
764
|
+
const streamOptions = params.ifIdle?.streamOptions;
|
|
765
|
+
if (!streamOptions) return { body: params };
|
|
766
|
+
this.setSignalRuntimeOptions({
|
|
767
|
+
resourceId: params.resourceId,
|
|
768
|
+
threadId: params.threadId,
|
|
769
|
+
streamOptions
|
|
770
|
+
});
|
|
771
|
+
return {
|
|
772
|
+
body: {
|
|
773
|
+
...params,
|
|
774
|
+
ifIdle: {
|
|
775
|
+
...params.ifIdle,
|
|
776
|
+
streamOptions: {
|
|
777
|
+
...streamOptions,
|
|
778
|
+
requestContext: parseClientRequestContext(streamOptions.requestContext),
|
|
779
|
+
clientTools: processClientTools(streamOptions.clientTools)
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
streamOptions
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
async requestSignalRoute(path, params) {
|
|
787
|
+
const { body, streamOptions } = this.prepareSignalRouteBody(params);
|
|
788
|
+
let response;
|
|
789
|
+
try {
|
|
790
|
+
response = await this.request(path, {
|
|
791
|
+
method: "POST",
|
|
792
|
+
body
|
|
793
|
+
});
|
|
794
|
+
} catch (error) {
|
|
795
|
+
if (streamOptions) {
|
|
796
|
+
this.deleteLatestSignalRuntimeOptions({ resourceId: params.resourceId, threadId: params.threadId });
|
|
797
|
+
}
|
|
798
|
+
throw error;
|
|
799
|
+
}
|
|
800
|
+
if (streamOptions) {
|
|
801
|
+
this.setSignalRuntimeOptions({
|
|
802
|
+
runId: response.runId,
|
|
803
|
+
resourceId: params.resourceId,
|
|
804
|
+
threadId: params.threadId,
|
|
805
|
+
streamOptions
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
return response;
|
|
809
|
+
}
|
|
763
810
|
/**
|
|
764
811
|
* Retrieves details about the agent
|
|
765
812
|
* @param requestContext - Optional request context to pass as query parameter
|
|
@@ -802,50 +849,23 @@ var Agent = class extends BaseResource {
|
|
|
802
849
|
body: { instructions, comment }
|
|
803
850
|
});
|
|
804
851
|
}
|
|
852
|
+
/**
|
|
853
|
+
* @experimental Agent message APIs are experimental and may change in a future release.
|
|
854
|
+
*/
|
|
855
|
+
sendMessage(params) {
|
|
856
|
+
return this.requestSignalRoute(`/agents/${this.agentId}/send-message`, params);
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* @experimental Agent message APIs are experimental and may change in a future release.
|
|
860
|
+
*/
|
|
861
|
+
queueMessage(params) {
|
|
862
|
+
return this.requestSignalRoute(`/agents/${this.agentId}/queue-message`, params);
|
|
863
|
+
}
|
|
805
864
|
/**
|
|
806
865
|
* @experimental Agent signals are experimental and may change in a future release.
|
|
807
866
|
*/
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
if (streamOptions) {
|
|
811
|
-
this.setSignalRuntimeOptions({
|
|
812
|
-
resourceId: params.resourceId,
|
|
813
|
-
threadId: params.threadId,
|
|
814
|
-
streamOptions
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
const body = params.ifIdle?.streamOptions ? {
|
|
818
|
-
...params,
|
|
819
|
-
ifIdle: {
|
|
820
|
-
...params.ifIdle,
|
|
821
|
-
streamOptions: {
|
|
822
|
-
...params.ifIdle.streamOptions,
|
|
823
|
-
requestContext: parseClientRequestContext(params.ifIdle.streamOptions.requestContext),
|
|
824
|
-
clientTools: processClientTools(params.ifIdle.streamOptions.clientTools)
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
} : params;
|
|
828
|
-
let response;
|
|
829
|
-
try {
|
|
830
|
-
response = await this.request(`/agents/${this.agentId}/signals`, {
|
|
831
|
-
method: "POST",
|
|
832
|
-
body
|
|
833
|
-
});
|
|
834
|
-
} catch (error) {
|
|
835
|
-
if (streamOptions) {
|
|
836
|
-
this.deleteLatestSignalRuntimeOptions({ resourceId: params.resourceId, threadId: params.threadId });
|
|
837
|
-
}
|
|
838
|
-
throw error;
|
|
839
|
-
}
|
|
840
|
-
if (streamOptions) {
|
|
841
|
-
this.setSignalRuntimeOptions({
|
|
842
|
-
runId: response.runId,
|
|
843
|
-
resourceId: params.resourceId,
|
|
844
|
-
threadId: params.threadId,
|
|
845
|
-
streamOptions
|
|
846
|
-
});
|
|
847
|
-
}
|
|
848
|
-
return response;
|
|
867
|
+
sendSignal(params) {
|
|
868
|
+
return this.requestSignalRoute(`/agents/${this.agentId}/signals`, params);
|
|
849
869
|
}
|
|
850
870
|
/**
|
|
851
871
|
* @experimental Agent signals are experimental and may change in a future release.
|
|
@@ -978,20 +998,20 @@ var Agent = class extends BaseResource {
|
|
|
978
998
|
return;
|
|
979
999
|
}
|
|
980
1000
|
try {
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1001
|
+
await agent.sendToolApproval({
|
|
1002
|
+
resourceId: resourceId || agent.agentId,
|
|
1003
|
+
threadId,
|
|
1004
|
+
toolCallId: pendingToolCalls[0].toolCallId,
|
|
1005
|
+
approved: true,
|
|
1006
|
+
requestContext: processedRequestContext,
|
|
1007
|
+
messages: threadId ? toolResultMessages : [...finishPayload.payload?.messages?.nonUser ?? [], ...toolResultMessages],
|
|
1008
|
+
streamOptions: {
|
|
984
1009
|
...activeRuntimeOptions,
|
|
985
|
-
runId: uuid.v4(),
|
|
986
1010
|
requestContext: processedRequestContext,
|
|
987
1011
|
memory: threadId ? { thread: threadId, resource: resourceId } : void 0,
|
|
988
1012
|
clientTools: processedClientTools
|
|
989
1013
|
}
|
|
990
|
-
);
|
|
991
|
-
try {
|
|
992
|
-
void continuation.body?.cancel?.();
|
|
993
|
-
} catch {
|
|
994
|
-
}
|
|
1014
|
+
});
|
|
995
1015
|
} catch (error) {
|
|
996
1016
|
console.error("Error running client-tool continuation:", error);
|
|
997
1017
|
} finally {
|
|
@@ -4785,6 +4805,17 @@ var StoredAgent = class extends BaseResource {
|
|
|
4785
4805
|
}
|
|
4786
4806
|
);
|
|
4787
4807
|
}
|
|
4808
|
+
/**
|
|
4809
|
+
* Lists other stored agents that reference this agent as a sub-agent.
|
|
4810
|
+
* @param requestContext - Optional request context to pass as query parameter
|
|
4811
|
+
* @returns Promise containing the list of dependent agents and a hidden count
|
|
4812
|
+
* for cross-workspace private dependents (only non-zero when this agent is public).
|
|
4813
|
+
*/
|
|
4814
|
+
dependents(requestContext) {
|
|
4815
|
+
return this.request(
|
|
4816
|
+
`/stored/agents/${encodeURIComponent(this.storedAgentId)}/dependents${requestContextQueryString(requestContext)}`
|
|
4817
|
+
);
|
|
4818
|
+
}
|
|
4788
4819
|
// ==========================================================================
|
|
4789
4820
|
// Favorite Methods (EE feature)
|
|
4790
4821
|
// ==========================================================================
|