@mastra/client-js 1.35.0 → 1.35.1-alpha.1
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 +14 -0
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-a2a.md +4 -2
- package/dist/docs/references/docs-editor-overview.md +17 -13
- package/dist/docs/references/docs-long-running-agents-schedules.md +3 -3
- package/dist/docs/references/docs-long-running-agents-signals.md +9 -5
- package/dist/docs/references/docs-server-auth-firebase.md +2 -2
- package/dist/docs/references/docs-server-mastra-client.md +3 -3
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-messages.md +1 -1
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +1 -1
- package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +1 -1
- package/dist/docs/references/reference-client-js-agents.md +9 -9
- package/dist/docs/references/reference-client-js-memory.md +2 -2
- package/dist/docs/references/reference-client-js-workflows.md +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.35.1-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`ba369f2`](https://github.com/mastra-ai/mastra/commit/ba369f2a0aaf998da0d6aa033d26f64f96bef8ac), [`dcfed93`](https://github.com/mastra-ai/mastra/commit/dcfed93e1e256c6abfa792cbb7ca836f5d0e8638), [`2876e15`](https://github.com/mastra-ai/mastra/commit/2876e15b4d2f616a3bc1ed3af57d546c268384ce), [`598080f`](https://github.com/mastra-ai/mastra/commit/598080f224edb3f0f5b801035b067fac50a56a03)]:
|
|
8
|
+
- @mastra/core@1.55.0-alpha.1
|
|
9
|
+
|
|
10
|
+
## 1.35.1-alpha.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [[`3f472b4`](https://github.com/mastra-ai/mastra/commit/3f472b468892a1ff14ccb43cc0343b86f7d8fd7d), [`35b929b`](https://github.com/mastra-ai/mastra/commit/35b929b7abc3d20d85c7985880960ac2d04a6c86), [`9b3626a`](https://github.com/mastra-ai/mastra/commit/9b3626aeb1d16fcd34b0a8e94c114ddb80a3b240)]:
|
|
15
|
+
- @mastra/core@1.55.0-alpha.0
|
|
16
|
+
|
|
3
17
|
## 1.35.0
|
|
4
18
|
|
|
5
19
|
### 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.35.
|
|
6
|
+
version: "1.35.1-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -34,7 +34,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
34
34
|
- [Reference: toAISdkStream()](references/reference-ai-sdk-to-ai-sdk-stream.md) - API reference for toAISdkStream(), a function to convert Mastra streams to AI SDK-compatible streams.
|
|
35
35
|
- [Reference: toAISdkV4Messages()](references/reference-ai-sdk-to-ai-sdk-v4-messages.md) - API reference for toAISdkV4Messages(), a function to convert Mastra messages to AI SDK v4 UI messages.
|
|
36
36
|
- [Reference: toAISdkV5Messages()](references/reference-ai-sdk-to-ai-sdk-v5-messages.md) - API reference for toAISdkV5Messages(), a function to convert Mastra messages to AI SDK v5 UI messages.
|
|
37
|
-
- [Reference: Agent Builder API](references/reference-client-js-agent-builder.md) - Learn how to interact with Agent Builder actions, including starting runs
|
|
37
|
+
- [Reference: Agent Builder API](references/reference-client-js-agent-builder.md) - Learn how to interact with Agent Builder actions, including starting runs and streaming progress, plus resuming suspended steps and observing runs using the client-js SDK.
|
|
38
38
|
- [Reference: Agents API](references/reference-client-js-agents.md) - Learn how to interact with Mastra AI agents, including generating responses, streaming interactions, and managing agent tools using the client-js SDK.
|
|
39
39
|
- [Reference: OpenAI Responses API Conversations](references/reference-client-js-conversations.md) - API reference for the client-js helpers that call Mastra's OpenAI-compatible `/v1/conversations` routes.
|
|
40
40
|
- [Reference: Error handling](references/reference-client-js-error-handling.md) - Learn about the built-in retry mechanism and error handling capabilities in the Mastra client-js SDK.
|
|
@@ -53,7 +53,9 @@ An agent card includes fields like the agent name, description, endpoint URL, pr
|
|
|
53
53
|
}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
A2A represents work as messages and tasks. Messages carry text, file, or structured data parts.
|
|
56
|
+
A2A represents work as messages and tasks. Messages carry text, file, or structured data parts.
|
|
57
|
+
|
|
58
|
+
Tasks are stateful units of work with IDs and lifecycle states. Clients can follow long-running work and send follow-up turns. They can also cancel work or resubscribe after a disconnect.
|
|
57
59
|
|
|
58
60
|
## Get started
|
|
59
61
|
|
|
@@ -83,7 +85,7 @@ export const supportAgent = new Agent({
|
|
|
83
85
|
id: 'support-agent',
|
|
84
86
|
name: 'Support Agent',
|
|
85
87
|
instructions: 'Answer user questions and delegate weather questions when needed.',
|
|
86
|
-
model: 'openai/gpt-5.
|
|
88
|
+
model: 'openai/gpt-5.6-sol',
|
|
87
89
|
agents: {
|
|
88
90
|
remoteWeatherAgent,
|
|
89
91
|
},
|
|
@@ -14,9 +14,9 @@ The editor manages two types of resources alongside agents:
|
|
|
14
14
|
Use the editor when you want to:
|
|
15
15
|
|
|
16
16
|
- **Let non-developers iterate**: Give subject-matter experts and prompt engineers a way to tune agent behavior without touching code or waiting for deploys.
|
|
17
|
-
- **Version everything**: Every save creates a snapshot so you can compare changes
|
|
18
|
-
- **Run experiments**: Route different users or requests to different agent versions for A/B testing
|
|
19
|
-
- **Target specific versions**: Pin a version per request
|
|
17
|
+
- **Version everything**: Every save creates a snapshot so you can compare changes and roll back instantly, plus audit what changed and when.
|
|
18
|
+
- **Run experiments**: Route different users or requests to different agent versions for A/B testing or canary rollouts, or alternatively prompt experimentation.
|
|
19
|
+
- **Target specific versions**: Pin a version per request or per user, or alternatively per environment so production stays stable while new versions are tested.
|
|
20
20
|
- **Manage tools at runtime**: Add integration tools from Composio or Arcade, or connect MCP servers, without updating code.
|
|
21
21
|
- **Override code agents**: Change the instructions, tools, or variables of a code-defined agent while keeping the original code as the baseline.
|
|
22
22
|
|
|
@@ -95,7 +95,7 @@ When `source` is `'code'`, the editor writes each override to a deterministic JS
|
|
|
95
95
|
|
|
96
96
|
The code source uses the Git history of each per-agent JSON file as its version history. Each commit that changes a file is shown as a read-only version in Studio, labeled with the commit message. Saving in Studio updates the working file in place rather than creating a database draft, so the version dropdown reflects your actual commit history.
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
As a result, versions and rollbacks are managed through Git rather than through draft and publish actions.
|
|
99
99
|
|
|
100
100
|
## Studio
|
|
101
101
|
|
|
@@ -105,7 +105,7 @@ Modify the system prompt and save a new draft version. Afterwards, publish the d
|
|
|
105
105
|
|
|
106
106
|
## Programmatic control
|
|
107
107
|
|
|
108
|
-
Everything you can do in Studio is also available programmatically through [`mastra.getEditor()`](https://mastra.ai/reference/core/getEditor). This is useful for scripting bulk updates
|
|
108
|
+
Everything you can do in Studio is also available programmatically through [`mastra.getEditor()`](https://mastra.ai/reference/core/getEditor). This is useful for scripting bulk updates or seeding stored configurations from code, or alternatively building automation that tunes agents based on evaluation results.
|
|
109
109
|
|
|
110
110
|
Call `mastra.getEditor()` from anywhere you have access to the `Mastra` instance. It returns the `MastraEditor` instance you registered, with namespaces for each resource type:
|
|
111
111
|
|
|
@@ -167,7 +167,7 @@ Because stored agents are data, you can build automation loops that tune agents
|
|
|
167
167
|
- Re-run the experiment against the draft and compare scores to the baseline.
|
|
168
168
|
- Promote the draft to the published version when the scores improve.
|
|
169
169
|
|
|
170
|
-
This turns agent tuning into a closed feedback loop. One agent owns the production configuration
|
|
170
|
+
This turns agent tuning into a closed feedback loop. One agent owns the production configuration and another agent iterates on it, plus every change is versioned so you can roll back if a round of automated edits makes things worse. Combine this with [version targeting](#version-targeting-and-experimentation) to keep production traffic on the published version while the draft is being tested. See the [MastraEditor reference](https://mastra.ai/reference/editor/mastra-editor) for the full namespace API.
|
|
171
171
|
|
|
172
172
|
## What can be overridden
|
|
173
173
|
|
|
@@ -190,7 +190,7 @@ import { Agent } from '@mastra/core/agent'
|
|
|
190
190
|
export const supportAgent = new Agent({
|
|
191
191
|
id: 'support-agent',
|
|
192
192
|
name: 'support-agent',
|
|
193
|
-
model: 'openai/gpt-5.
|
|
193
|
+
model: 'openai/gpt-5.6-sol',
|
|
194
194
|
editor: { instructions: true, tools: { description: true } },
|
|
195
195
|
})
|
|
196
196
|
```
|
|
@@ -209,7 +209,7 @@ When a field is owned by code, Studio shows it as read-only and the server strip
|
|
|
209
209
|
|
|
210
210
|
## Versioning
|
|
211
211
|
|
|
212
|
-
Every time you save changes to an agent or prompt block, a new version snapshot is created. Versions give you a full history of your agent's configuration. You can roll back to any previous state
|
|
212
|
+
Every time you save changes to an agent or prompt block, a new version snapshot is created. Versions give you a full history of your agent's configuration. You can roll back to any previous state and compare what changed between two snapshots, plus target specific versions per request for A/B testing or gradual rollouts.
|
|
213
213
|
|
|
214
214
|
Version management is available through the server Studio, REST API, the Client SDK, and the React SDK. See the [Client SDK agents reference](https://mastra.ai/reference/client-js/agents) for endpoints, SDK methods, and code examples.
|
|
215
215
|
|
|
@@ -223,7 +223,9 @@ Each version has one of three statuses:
|
|
|
223
223
|
| Published | The active version used in production. Only one version can be published at a time. |
|
|
224
224
|
| Archived | A previous version that's no longer active. You can restore any archived version. |
|
|
225
225
|
|
|
226
|
-
The typical flow is: Edit the draft
|
|
226
|
+
The typical flow is: Edit the draft and test it, plus then activate it to make it the published version.
|
|
227
|
+
|
|
228
|
+
The previously published version becomes archived so you can restore it if needed. You can do this through Studio or programmatically through the API.
|
|
227
229
|
|
|
228
230
|
This lifecycle makes it safe to experiment. Non-technical team members can iterate on a draft without affecting production traffic, then publish when ready. If something goes wrong, restoring a previous version is a single API call.
|
|
229
231
|
|
|
@@ -240,7 +242,9 @@ Pass a `versionId` or `status` when calling the agent through the Client SDK, se
|
|
|
240
242
|
|
|
241
243
|
### Version selection
|
|
242
244
|
|
|
243
|
-
By default, [`mastra.getAgentById()`](https://mastra.ai/reference/core/getAgentById) loads the published (active) version of the stored override.
|
|
245
|
+
By default, [`mastra.getAgentById()`](https://mastra.ai/reference/core/getAgentById) loads the published (active) version of the stored override.
|
|
246
|
+
|
|
247
|
+
Use a specific version to test a draft before publishing or run an A/B experiment. You can also pin a user to a known-good configuration:
|
|
244
248
|
|
|
245
249
|
```typescript
|
|
246
250
|
// Load the published version (default)
|
|
@@ -278,9 +282,9 @@ When a [supervisor agent](https://mastra.ai/docs/agents/supervisor-agents) deleg
|
|
|
278
282
|
|
|
279
283
|
Set version overrides at three levels, with later levels taking priority:
|
|
280
284
|
|
|
281
|
-
1. **Mastra instance config
|
|
282
|
-
2. **Per-invocation options
|
|
283
|
-
3. **Server request body
|
|
285
|
+
1. **Mastra instance config**: global defaults that apply to every `generate()` and `stream()` call.
|
|
286
|
+
2. **Per-invocation options**: overrides passed directly to `generate()` or `stream()`.
|
|
287
|
+
3. **Server request body**: overrides sent in the `versions` field of an API request.
|
|
284
288
|
|
|
285
289
|
Resolution order: **per-invocation > request body > Mastra instance defaults > code-defined agent**.
|
|
286
290
|
|
|
@@ -25,7 +25,7 @@ const pinger = new Agent({
|
|
|
25
25
|
id: 'pinger',
|
|
26
26
|
name: 'Pinger',
|
|
27
27
|
instructions: 'Report the current system status in one sentence.',
|
|
28
|
-
model: 'openai/gpt-5.
|
|
28
|
+
model: 'openai/gpt-5.6-sol',
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
const mastra = new Mastra({
|
|
@@ -136,7 +136,7 @@ await mastra.schedules.create({
|
|
|
136
136
|
})
|
|
137
137
|
```
|
|
138
138
|
|
|
139
|
-
Workflow schedules created this way are independent of the declarative `schedule` field on `createWorkflow
|
|
139
|
+
Workflow schedules created this way are independent of the declarative `schedule` field on `createWorkflow`, see [scheduled workflows](https://mastra.ai/docs/workflows/scheduled-workflows) for the declarative form and Studio views.
|
|
140
140
|
|
|
141
141
|
### Custom IDs
|
|
142
142
|
|
|
@@ -187,7 +187,7 @@ The hooks are:
|
|
|
187
187
|
|
|
188
188
|
- `prepare`: runs before the fire. Return an object to override fire-time parameters such as `prompt` or `threadId`, `null` to skip the fire, or `undefined` to use the stored defaults.
|
|
189
189
|
- `onFinish`: runs once per trigger that reached a non-error, non-abort terminal state.
|
|
190
|
-
- `onError`: runs
|
|
190
|
+
- `onError`: runs after a failure in `prepare` or the signal. It also runs when the agent run fails.
|
|
191
191
|
- `onAbort`: runs when the run was aborted mid-stream.
|
|
192
192
|
|
|
193
193
|
Every hook context includes `agentId` (the agent the schedule fired for) alongside `schedule` and `trigger`.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
> **Beta:** This feature is in beta. Breaking changes may occur without a major version bump until the API is stable.
|
|
8
8
|
|
|
9
|
-
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 messages or signals. Mastra either wakes the agent when the thread is idle
|
|
9
|
+
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 messages or signals. Mastra either wakes the agent when the thread is idle or drops input into the running agent loop, or alternatively queues input for the next turn.
|
|
10
10
|
|
|
11
11
|
Use message APIs for user-authored input. Use `sendSignal()` for lower-level system context, such as background task notifications, policy reminders, or processor-generated context.
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ const agent = new Agent({
|
|
|
29
29
|
id: 'support-agent',
|
|
30
30
|
name: 'Support Agent',
|
|
31
31
|
instructions: 'Help the user compare options.',
|
|
32
|
-
model: 'openai/gpt-5.
|
|
32
|
+
model: 'openai/gpt-5.6-sol',
|
|
33
33
|
})
|
|
34
34
|
|
|
35
35
|
const thread = {
|
|
@@ -143,7 +143,7 @@ The model receives the signal as context like this:
|
|
|
143
143
|
<notification source="github" pr="123">PR #123 has a new review comment from User X about the API surface.</notification>
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
-
Use XML-safe `tagName` and attribute names. They can contain letters, numbers,
|
|
146
|
+
Use XML-safe `tagName` and attribute names. They can contain letters, numbers, shows, periods, and hyphens. They must start with a letter or underscore.
|
|
147
147
|
|
|
148
148
|
#### Storage support
|
|
149
149
|
|
|
@@ -320,7 +320,9 @@ Use `createNotificationInboxTool()` to give agents one tool for inbox actions in
|
|
|
320
320
|
|
|
321
321
|
Signals coordinate runs through a pub/sub backend. When a signal arrives on a backend that implements `LeaseProvider`, Mastra acquires a lease on the target thread so a single process owns the conversation at a time, then either wakes the agent or routes the input into the running loop. Backends without leasing fall back to a no-op that always grants ownership, which is fine in a single process but not across instances.
|
|
322
322
|
|
|
323
|
-
The default in-memory pub/sub can't cross instance boundaries. On serverless platforms like Vercel, or any multi-instance deployment, a follow-up signal can
|
|
323
|
+
The default in-memory pub/sub can't cross instance boundaries. On serverless platforms like Vercel, or any multi-instance deployment, a follow-up signal can be routed to a different instance than the one running the agent.
|
|
324
|
+
|
|
325
|
+
Without a shared pub/sub, that instance can't reach the active run and starts its own, leaving the original run untouched and the thread processed twice.
|
|
324
326
|
|
|
325
327
|
Configure a shared pub/sub backed by Redis Streams on the `Mastra` instance so leases and signals coordinate across instances:
|
|
326
328
|
|
|
@@ -360,7 +362,9 @@ If you call Mastra over HTTP directly, use `POST /api/agents/:agentId/send-messa
|
|
|
360
362
|
|
|
361
363
|
### Use the client SDK
|
|
362
364
|
|
|
363
|
-
The JavaScript client exposes thread signal APIs.
|
|
365
|
+
The JavaScript client exposes thread signal APIs.
|
|
366
|
+
|
|
367
|
+
Use `subscribeToThread()` before sending thread input so the client can render the stream that receives the input or wakes in response to it.
|
|
364
368
|
|
|
365
369
|
```typescript
|
|
366
370
|
const agent = client.getAgent('supportAgent')
|
|
@@ -93,11 +93,11 @@ The `MastraAuthFirebase` class can be configured through constructor options or
|
|
|
93
93
|
- `FIREBASE_SERVICE_ACCOUNT`: Path to Firebase service account JSON file
|
|
94
94
|
- `FIRESTORE_DATABASE_ID` or `FIREBASE_DATABASE_ID`: Firestore database ID
|
|
95
95
|
|
|
96
|
-
> **Note:** When constructor options aren't provided, the class automatically reads these environment variables.
|
|
96
|
+
> **Note:** When constructor options aren't provided, the class automatically reads these environment variables. As a result, you can call `new MastraAuthFirebase()` without any arguments if your environment variables are properly configured.
|
|
97
97
|
|
|
98
98
|
### User Authorization
|
|
99
99
|
|
|
100
|
-
By default, `MastraAuthFirebase` uses Firestore to manage user access. It expects a
|
|
100
|
+
By default, `MastraAuthFirebase` uses Firestore to manage user access. It expects a `user_access` collection with documents keyed by user UIDs. The presence of a document in this collection determines whether a user is authorized.
|
|
101
101
|
|
|
102
102
|
```text
|
|
103
103
|
user_access/
|
|
@@ -138,7 +138,7 @@ Visit [MastraClient](https://mastra.ai/reference/client-js/mastra-client) for mo
|
|
|
138
138
|
|
|
139
139
|
## Credentials and session cookies
|
|
140
140
|
|
|
141
|
-
**Authenticate Mastra API calls with session cookies** when your UI and Mastra API aren't on the same origin
|
|
141
|
+
**Authenticate Mastra API calls with session cookies** when your UI and Mastra API aren't on the same origin, different host, subdomain, or port (for example Mastra Studio on one port and a custom server on another). Add **`credentials: 'include'`** to `MastraClient` so each request carries the cookies the user already has after sign-in. Skip this and you will often get **`401`** responses from Mastra even though login succeeded in the browser.
|
|
142
142
|
|
|
143
143
|
```typescript
|
|
144
144
|
import { MastraClient } from '@mastra/client-js'
|
|
@@ -149,7 +149,7 @@ export const mastraClient = new MastraClient({
|
|
|
149
149
|
})
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
**Allow credentialed cross-origin requests on your server
|
|
152
|
+
**Allow credentialed cross-origin requests on your server**, see [CORS: requests with credentials](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS#requests_with_credentials). You need a concrete `Access-Control-Allow-Origin` (not `*`) and `Access-Control-Allow-Credentials: true`, or the browser will block the call before it reaches Mastra.
|
|
153
153
|
|
|
154
154
|
**Using `@mastra/react`?** Wrap your app with `MastraReactProvider`, set `baseUrl` and `apiPrefix` to match your server, and rely on the default `credentials: 'include'`. Change `credentials` only when you want `same-origin` or `omit` behavior.
|
|
155
155
|
|
|
@@ -237,7 +237,7 @@ export const colorAgent = new Agent({
|
|
|
237
237
|
instructions: `You are a helpful CSS assistant.
|
|
238
238
|
You can change the background color of web pages.
|
|
239
239
|
Respond with a hex reference for the color requested by the user`,
|
|
240
|
-
model: 'openai/gpt-5.
|
|
240
|
+
model: 'openai/gpt-5.6-sol',
|
|
241
241
|
})
|
|
242
242
|
```
|
|
243
243
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# toAISdkMessages()
|
|
4
4
|
|
|
5
|
-
Converts messages from
|
|
5
|
+
Converts messages from input formats to AI SDK UI message format. `toAISdkMessages()` keeps the existing AI SDK v5/default behavior. If your app is typed against AI SDK v6, pass `version: 'v6'`.
|
|
6
6
|
|
|
7
7
|
`version: 'v6'` uses the MessageList AI SDK v6 UI output path. MessageList input detection and ingestion remain unchanged.
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# toAISdkV4Messages()
|
|
4
4
|
|
|
5
|
-
Converts messages from
|
|
5
|
+
Converts messages from input formats to AI SDK V4 UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V4 `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# toAISdkV5Messages()
|
|
4
4
|
|
|
5
|
-
Converts messages from
|
|
5
|
+
Converts messages from input formats to AI SDK V5 (and later) UI message format. This function accepts messages in multiple formats (strings, AI SDK V4/V5 messages, Mastra DB messages, etc.) and normalizes them to the AI SDK V5+ `UIMessage` format, which is suitable for use with AI SDK UI components like `useChat()`.
|
|
6
6
|
|
|
7
7
|
## Usage example
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Agents API
|
|
4
4
|
|
|
5
|
-
The Agents API provides methods to interact with Mastra AI agents, including generating responses
|
|
5
|
+
The Agents API provides methods to interact with Mastra AI agents, including generating responses and streaming interactions. It also provides methods for managing agent tools.
|
|
6
6
|
|
|
7
7
|
## Getting all agents
|
|
8
8
|
|
|
@@ -155,7 +155,7 @@ for await (const part of uiMessageStream) {
|
|
|
155
155
|
|
|
156
156
|
### `sendMessage()`
|
|
157
157
|
|
|
158
|
-
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
|
|
158
|
+
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.
|
|
159
159
|
|
|
160
160
|
```typescript
|
|
161
161
|
const agent = mastraClient.getAgent('support-agent')
|
|
@@ -285,7 +285,7 @@ await subscription.processDataStream({
|
|
|
285
285
|
|
|
286
286
|
### `streamUntilIdle()`
|
|
287
287
|
|
|
288
|
-
Stream a response and keep the stream open until every [background task](https://mastra.ai/docs/long-running-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
|
|
288
|
+
Stream a response and keep the stream open until every [background task](https://mastra.ai/docs/long-running-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 uses a plain `stream()`.
|
|
289
289
|
|
|
290
290
|
```typescript
|
|
291
291
|
const response = await agent.streamUntilIdle('Research solana for me', {
|
|
@@ -307,7 +307,7 @@ response.processDataStream({
|
|
|
307
307
|
|
|
308
308
|
### `resumeStreamUntilIdle()`
|
|
309
309
|
|
|
310
|
-
Resume a suspended agent stream with custom data and keep the stream open until every [background task](https://mastra.ai/docs/long-running-agents/background-tasks) dispatched during the run completes. Use this to continue execution after a suspension point, such as a workflow suspend within an agent. Requires background tasks to be [enabled on the Mastra instance](https://mastra.ai/reference/configuration) and a memory thread; otherwise the call
|
|
310
|
+
Resume a suspended agent stream with custom data and keep the stream open until every [background task](https://mastra.ai/docs/long-running-agents/background-tasks) dispatched during the run completes. Use this to continue execution after a suspension point, such as a workflow suspend within an agent. Requires background tasks to be [enabled on the Mastra instance](https://mastra.ai/reference/configuration) and a memory thread; otherwise the call uses a plain `resumeStream()`:
|
|
311
311
|
|
|
312
312
|
```typescript
|
|
313
313
|
const response = await agent.resumeStreamUntilIdle(
|
|
@@ -366,7 +366,7 @@ response.processDataStream({
|
|
|
366
366
|
|
|
367
367
|
### `listSuspendedRuns()`
|
|
368
368
|
|
|
369
|
-
List suspended runs for the agent from storage
|
|
369
|
+
List suspended runs for the agent from storage: runs waiting on a tool-call approval or on a tool that suspended. Discovery is backed by storage, so it works after a server restart and across server instances. Pass the returned `runId` to `approveToolCall()`, `declineToolCall()`, or `resumeStream()`.
|
|
370
370
|
|
|
371
371
|
```typescript
|
|
372
372
|
const { runs, total } = await agent.listSuspendedRuns({
|
|
@@ -655,9 +655,9 @@ const screenshotTool = createTool({
|
|
|
655
655
|
|
|
656
656
|
### Tracing client tools
|
|
657
657
|
|
|
658
|
-
When `@mastra/observability` is installed and configured on the server, a client-side tool records a `CLIENT_TOOL_CALL` span as a child of the current `AGENT_RUN` span. The server creates that span when the model emits the client tool call
|
|
658
|
+
When `@mastra/observability` is installed and configured on the server, a client-side tool records a `CLIENT_TOOL_CALL` span as a child of the current `AGENT_RUN` span. The server creates that span when the model emits the client tool call and injects a W3C trace carrier into the outgoing tool-call chunk. It ends the span once the tool arguments are available. Without server-side observability configured, client tool tracing is a no-op.
|
|
659
659
|
|
|
660
|
-
The client SDK also measures the wall-clock duration of each client tool's `execute` function and
|
|
660
|
+
The client SDK also measures the wall-clock duration of each client tool's `execute` function and sends it back to the server, where it's emitted as a `mastra_tool_duration_ms` metric with `toolType: "client"`.
|
|
661
661
|
|
|
662
662
|
For richer telemetry from inside your tool's `execute` function, use the `observe` helper on the execution context to add child spans and structured logs:
|
|
663
663
|
|
|
@@ -680,9 +680,9 @@ const fetchUserTool = createTool({
|
|
|
680
680
|
})
|
|
681
681
|
```
|
|
682
682
|
|
|
683
|
-
`observe` is always available
|
|
683
|
+
`observe` is always available: when no tracing context is active (e.g. running outside a traced agent), `span` runs the function directly and `log` is a no-op. No null-checking needed.
|
|
684
684
|
|
|
685
|
-
The SDK serializes everything the collector buffered as OTLP/JSON and
|
|
685
|
+
The SDK serializes everything the collector buffered as OTLP/JSON and sends it back in the next request body. The server's `@mastra/observability` package validates that the spans belong to the correct trace (preventing cross-trace injection) and forwards each span/log into the same observability bus that server-side telemetry uses. Your existing exporters pick them up automatically after observability is configured.
|
|
686
686
|
|
|
687
687
|
## Stored agents
|
|
688
688
|
|
|
@@ -168,7 +168,7 @@ const result = await thread.listMessages({
|
|
|
168
168
|
})
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
-
Metadata filters match shallow scalar values only: `string`, finite `number`, `boolean`, and `null`. Every key-value pair must match with AND semantics. `null` matches
|
|
171
|
+
Metadata filters match shallow scalar values only: `string`, finite `number`, `boolean`, and `null`. Every key-value pair must match with AND semantics. `null` matches only keys explicitly set to `null`. Metadata keys must start with a letter or underscore and contain only alphanumeric or underscore characters. The limit is 128 characters. Reserved prototype keys such as `__proto__`, `constructor`, and `prototype` aren't allowed. Performance depends on the server storage backend, and arbitrary metadata filters may scan candidate messages.
|
|
172
172
|
|
|
173
173
|
### Delete Messages
|
|
174
174
|
|
|
@@ -226,7 +226,7 @@ await mastraClient.updateWorkingMemory({
|
|
|
226
226
|
// Returns: { success: true }
|
|
227
227
|
```
|
|
228
228
|
|
|
229
|
-
|
|
229
|
+
For resource-scoped working memory, you must provide the `resourceId` parameter. It allows the memory to persist across all conversation threads for that user.
|
|
230
230
|
|
|
231
231
|
### Get Memory Status
|
|
232
232
|
|
|
@@ -142,7 +142,7 @@ await run.resume({
|
|
|
142
142
|
})
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
-
When a [`.foreach()`](https://mastra.ai/reference/workflows/workflow-methods/foreach) step suspends across multiple iterations, pass `forEachIndex` (zero-based
|
|
145
|
+
When a [`.foreach()`](https://mastra.ai/reference/workflows/workflow-methods/foreach) step suspends across multiple iterations, pass `forEachIndex` (zero-based. `0` targets the first iteration) to resume one iteration at a time. Iterations you don't target remain suspended.
|
|
146
146
|
|
|
147
147
|
```typescript
|
|
148
148
|
await run.resume({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/client-js",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.1-alpha.1",
|
|
4
4
|
"description": "The official TypeScript library for the Mastra Client API",
|
|
5
5
|
"author": "",
|
|
6
6
|
"type": "module",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"canonicalize": "^1.0.8",
|
|
40
40
|
"jose": "^6.2.1",
|
|
41
41
|
"json-schema": "^0.4.0",
|
|
42
|
-
"@mastra/
|
|
43
|
-
"@mastra/
|
|
42
|
+
"@mastra/core": "1.55.0-alpha.1",
|
|
43
|
+
"@mastra/schema-compat": "1.3.4"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"zod": "^3.25.0 || ^4.0.0"
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"typescript": "^6.0.3",
|
|
57
57
|
"vitest": "4.1.10",
|
|
58
58
|
"zod": "^4.4.3",
|
|
59
|
-
"@internal/ai-sdk-v5": "0.0.65",
|
|
60
|
-
"@internal/lint": "0.0.118",
|
|
61
59
|
"@internal/ai-sdk-v4": "0.0.65",
|
|
62
|
-
"@internal/
|
|
60
|
+
"@internal/ai-sdk-v5": "0.0.65",
|
|
61
|
+
"@internal/types-builder": "0.0.93",
|
|
62
|
+
"@internal/lint": "0.0.118"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=22.13.0"
|