@mastra/client-js 1.22.0-alpha.4 → 1.22.0-alpha.6
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 +55 -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 +18 -2
- package/dist/docs/references/docs-editor-overview.md +70 -8
- package/dist/docs/references/reference-client-js-agents.md +19 -2
- package/dist/index.cjs +224 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +224 -148
- package/dist/index.js.map +1 -1
- package/dist/resources/agent.d.ts +19 -0
- package/dist/resources/agent.d.ts.map +1 -1
- package/dist/resources/stored-agent.d.ts +5 -1
- package/dist/resources/stored-agent.d.ts.map +1 -1
- package/dist/resources/tool-provider.d.ts +7 -1
- package/dist/resources/tool-provider.d.ts.map +1 -1
- package/dist/route-types.generated.d.ts +2615 -382
- package/dist/route-types.generated.d.ts.map +1 -1
- package/dist/types.d.ts +11 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,60 @@
|
|
|
1
1
|
# @mastra/client-js
|
|
2
2
|
|
|
3
|
+
## 1.22.0-alpha.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Separated thread subscription cleanup from active-run aborts so closing or switching a listener only unsubscribes that listener, while explicit cancel still aborts the active run. ([#17310](https://github.com/mastra-ai/mastra/pull/17310))
|
|
8
|
+
|
|
9
|
+
- Added subscription-native tool approval APIs so approving or declining a tool call resumes through the active thread subscription instead of requiring a separate continuation stream. New messages are queued while a tool approval is waiting, preventing overlapping runs from duplicating approval requests. ([#17311](https://github.com/mastra-ai/mastra/pull/17311))
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
await agent.sendToolApproval({
|
|
13
|
+
resourceId: 'user-123',
|
|
14
|
+
threadId: 'thread-123',
|
|
15
|
+
toolCallId: 'tool-call-123',
|
|
16
|
+
approved: true,
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`19a8658`](https://github.com/mastra-ai/mastra/commit/19a86589c788ef48bb6c1b0612cc82a201857379), [`a659a77`](https://github.com/mastra-ai/mastra/commit/a659a779bdebe3a52a518c56d2260592d0240fe0), [`3332be9`](https://github.com/mastra-ai/mastra/commit/3332be9701ecd77aba840959d9a1d1ce7aef02d3)]:
|
|
21
|
+
- @mastra/core@1.38.0-alpha.6
|
|
22
|
+
|
|
23
|
+
## 1.22.0-alpha.5
|
|
24
|
+
|
|
25
|
+
### Minor Changes
|
|
26
|
+
|
|
27
|
+
- Added an agent override export API and server-side ownership enforcement. ([#17228](https://github.com/mastra-ai/mastra/pull/17228))
|
|
28
|
+
|
|
29
|
+
The server and client now expose an agent override export endpoint so Studio can download an agent's overrides as JSON for review or commit workflows. Saves are enforced server-side against each agent's `editor` config, so only owned fields (instructions, tools, or tool descriptions) are persisted and fields locked by the `editor` config are stripped.
|
|
30
|
+
|
|
31
|
+
The system packages response also reports the active editor `source` so clients can render the correct editing experience.
|
|
32
|
+
|
|
33
|
+
- Added a `PATCH /tool-providers/:providerId/connections/:connectionId` endpoint and matching client SDK method so authors can rename a connection's display label after creation. ([#17249](https://github.com/mastra-ai/mastra/pull/17249))
|
|
34
|
+
|
|
35
|
+
**Rename a connection from the client SDK**
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { MastraClient } from '@mastra/client-js';
|
|
39
|
+
|
|
40
|
+
const client = new MastraClient({ baseUrl: '…' });
|
|
41
|
+
|
|
42
|
+
await client.getToolProvider('composio').updateConnection('auth_abc', {
|
|
43
|
+
label: 'Work inbox',
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Pass `label: null` (or an empty string) to clear the existing label. Labels are 1–32 characters and accept letters, digits, spaces, underscores, and hyphens (`[A-Za-z0-9 _-]+`).
|
|
48
|
+
|
|
49
|
+
**Ownership enforced server-side**
|
|
50
|
+
|
|
51
|
+
Non-owners get a 403 unless they hold `tool-providers:admin`. Shared connections are reachable by every author. The label is stored on the connection row itself, so the rename flows to every agent that pins the connection — no per-agent edit needed.
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- Updated dependencies [[`a18775a`](https://github.com/mastra-ai/mastra/commit/a18775a693172546ee2378d39b67d4e32895b251), [`1baf2d1`](https://github.com/mastra-ai/mastra/commit/1baf2d152c6881338ff8f114633d5316fe13dd15)]:
|
|
56
|
+
- @mastra/core@1.38.0-alpha.5
|
|
57
|
+
|
|
3
58
|
## 1.22.0-alpha.4
|
|
4
59
|
|
|
5
60
|
### 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.22.0-alpha.
|
|
6
|
+
version: "1.22.0-alpha.6"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -233,9 +233,24 @@ Existing stored signal rows and older clients continue to load through the compa
|
|
|
233
233
|
|
|
234
234
|
> **Note:** Visit [Agent signals reference](https://mastra.ai/reference/agents/agent) for the full message, signal, and subscription types.
|
|
235
235
|
|
|
236
|
+
## Approve tool calls
|
|
237
|
+
|
|
238
|
+
When a subscribed run pauses for tool approval, approve or decline the tool call with the subscription-native methods. The call returns a JSON acknowledgement. The resumed chunks arrive through the existing thread subscription.
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
await agent.sendToolApproval({
|
|
242
|
+
resourceId: 'user_123',
|
|
243
|
+
threadId: 'thread_456',
|
|
244
|
+
toolCallId: 'tool-call_456',
|
|
245
|
+
approved: true,
|
|
246
|
+
})
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Pass `approved: false` to decline the same pending tool call. Use the older `approveToolCall()` and `declineToolCall()` methods only when you are rendering the separate continuation stream directly.
|
|
250
|
+
|
|
236
251
|
## Use HTTP routes
|
|
237
252
|
|
|
238
|
-
If you call Mastra over HTTP directly, use `POST /api/agents/:agentId/send-message` for immediate messages and `POST /api/agents/:agentId/queue-message` for next-turn messages. See [Server routes reference](https://mastra.ai/reference/server/routes) for request and response schemas.
|
|
253
|
+
If you call Mastra over HTTP directly, use `POST /api/agents/:agentId/send-message` for immediate messages and `POST /api/agents/:agentId/queue-message` for next-turn messages. For subscription-native tool approval, use `POST /api/agents/:agentId/send-tool-approval`. See [Server routes reference](https://mastra.ai/reference/server/routes) for request and response schemas.
|
|
239
254
|
|
|
240
255
|
## Use the client SDK
|
|
241
256
|
|
|
@@ -294,4 +309,5 @@ Use heartbeats together with client-side reconnect logic. Heartbeats reduce idle
|
|
|
294
309
|
- [`Agent.subscribeToThread()`](https://mastra.ai/reference/agents/agent)
|
|
295
310
|
- [Server agent routes](https://mastra.ai/reference/server/routes)
|
|
296
311
|
- [`client.getAgent().sendSignal()`](https://mastra.ai/reference/client-js/agents)
|
|
297
|
-
- [`client.getAgent().subscribeToThread()`](https://mastra.ai/reference/client-js/agents)
|
|
312
|
+
- [`client.getAgent().subscribeToThread()`](https://mastra.ai/reference/client-js/agents)
|
|
313
|
+
- [`client.getAgent().sendToolApproval()`](https://mastra.ai/reference/client-js/agents)
|
|
@@ -66,6 +66,41 @@ Once registered, you can manage agents through [Studio](https://mastra.ai/docs/s
|
|
|
66
66
|
|
|
67
67
|
> **Note:** See the [MastraEditor reference](https://mastra.ai/reference/editor/mastra-editor) for all configuration options.
|
|
68
68
|
|
|
69
|
+
## Code and database sources
|
|
70
|
+
|
|
71
|
+
The editor stores agent overrides in one of two sources, set with the `source` option on `MastraEditor`:
|
|
72
|
+
|
|
73
|
+
| Source | Where overrides live | Studio actions |
|
|
74
|
+
| -------------- | --------------------------------------------------------- | -------------------------------------------------------- |
|
|
75
|
+
| `db` (default) | The configured storage backend. | Save and publish drafts. |
|
|
76
|
+
| `code` | Per-agent JSON files on disk, tracked in your repository. | Download the override file or save it to the filesystem. |
|
|
77
|
+
|
|
78
|
+
The default `db` source is best when non-developers iterate through Studio and you want versioning, drafts, and runtime version targeting. The `code` source is best when overrides should live in your repository alongside the rest of your code, reviewed through pull requests and deployed with your application.
|
|
79
|
+
|
|
80
|
+
To use the code source, set `source: 'code'`:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { Mastra } from '@mastra/core'
|
|
84
|
+
import { MastraEditor } from '@mastra/editor'
|
|
85
|
+
|
|
86
|
+
export const mastra = new Mastra({
|
|
87
|
+
agents: {
|
|
88
|
+
/* your existing agents */
|
|
89
|
+
},
|
|
90
|
+
editor: new MastraEditor({
|
|
91
|
+
source: 'code',
|
|
92
|
+
}),
|
|
93
|
+
})
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
When `source` is `'code'`, the editor writes each override to a deterministic JSON file under `./mastra/editor/agents/<agentId>.json`. Set `codePath` to change the directory. Because the files are deterministic, every save produces a clean diff you can commit and review.
|
|
97
|
+
|
|
98
|
+
### Versioning with the code source
|
|
99
|
+
|
|
100
|
+
The code source uses the Git history of each per-agent JSON file as its version history. Each commit that changes a file appears 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.
|
|
101
|
+
|
|
102
|
+
This means versions and rollbacks are managed through Git rather than through draft and publish actions.
|
|
103
|
+
|
|
69
104
|
## Studio
|
|
70
105
|
|
|
71
106
|
Go to the **Agents** tab in Studio and select an agent to edit. Select the **Editor** tab. You'll be taken to the editor interface, where you can modify the agent's instructions, tools, and variables.
|
|
@@ -114,15 +149,16 @@ The `editor.agent` namespace also exposes `getById`, `list`, `listResolved`, and
|
|
|
114
149
|
|
|
115
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:
|
|
116
151
|
|
|
117
|
-
| Method | Path
|
|
118
|
-
| -------- |
|
|
119
|
-
| `GET` | `/stored/agents`
|
|
120
|
-
| `POST` | `/stored/agents`
|
|
121
|
-
| `GET` | `/stored/agents/:storedAgentId`
|
|
122
|
-
| `PATCH` | `/stored/agents/:storedAgentId`
|
|
123
|
-
| `DELETE` | `/stored/agents/:storedAgentId`
|
|
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
|
+
| `POST` | `/stored/agents/:storedAgentId/export` | Export a stored agent's override as a deterministic JSON config. |
|
|
124
160
|
|
|
125
|
-
The Client SDK wraps these endpoints with `client.listStoredAgents()`, `client.createStoredAgent()`, and `client.getStoredAgent()`. Version management endpoints live under `/stored/agents/:storedAgentId/versions`, see [version management](https://mastra.ai/reference/client-js/agents) for the full list.
|
|
161
|
+
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()`, 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.
|
|
126
162
|
|
|
127
163
|
### Automated experimentation
|
|
128
164
|
|
|
@@ -149,6 +185,32 @@ When you edit a code-defined agent through the editor, only specific fields can
|
|
|
149
185
|
|
|
150
186
|
Fields like the agent's `id`, `name`, and `model` come from your code and can't be changed through the editor for code-defined agents. The variables are also read-only.
|
|
151
187
|
|
|
188
|
+
### Controlling what is editable
|
|
189
|
+
|
|
190
|
+
Use the `editor` field on a code-defined agent to control which fields the editor can override. This lets you keep some fields code-owned while allowing edits to others:
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { Agent } from '@mastra/core/agent'
|
|
194
|
+
|
|
195
|
+
export const supportAgent = new Agent({
|
|
196
|
+
name: 'support-agent',
|
|
197
|
+
model: 'openai/gpt-5.4',
|
|
198
|
+
editor: { instructions: true, tools: { description: true } },
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
The `editor` field accepts these shapes:
|
|
203
|
+
|
|
204
|
+
| Value | Result |
|
|
205
|
+
| ---------------------------------- | ---------------------------------------------------------- |
|
|
206
|
+
| Omitted | Instructions and tools are editable. |
|
|
207
|
+
| `false` | Nothing is editable. The agent is locked. |
|
|
208
|
+
| `{ instructions: true }` | Instructions are editable. |
|
|
209
|
+
| `{ tools: true }` | Tool membership and descriptions are editable. |
|
|
210
|
+
| `{ tools: { description: true } }` | Only tool descriptions are editable. Membership is locked. |
|
|
211
|
+
|
|
212
|
+
When a field is owned by code, Studio shows it as read-only and the server strips it from saved overrides, so the stored config only contains the fields you allow. See the [`editor` overrides reference](https://mastra.ai/reference/agents/agent) for the full type.
|
|
213
|
+
|
|
152
214
|
## Versioning
|
|
153
215
|
|
|
154
216
|
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, compare what changed between two snapshots, and target specific versions per request for A/B testing or gradual rollouts.
|
|
@@ -326,7 +326,7 @@ response.processDataStream({
|
|
|
326
326
|
|
|
327
327
|
### `approveToolCall()`
|
|
328
328
|
|
|
329
|
-
Approve a pending tool call
|
|
329
|
+
Approve a pending tool call and return a continuation stream. Use this when you are rendering the resumed chunks from the approval response.
|
|
330
330
|
|
|
331
331
|
```typescript
|
|
332
332
|
const response = await agent.approveToolCall({
|
|
@@ -341,9 +341,26 @@ response.processDataStream({
|
|
|
341
341
|
})
|
|
342
342
|
```
|
|
343
343
|
|
|
344
|
+
### `sendToolApproval()`
|
|
345
|
+
|
|
346
|
+
Approve or decline a pending tool call for a subscribed thread. Use this with `subscribeToThread()` when the resumed chunks should arrive through the existing thread subscription instead of a separate continuation stream.
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
const result = await agent.sendToolApproval({
|
|
350
|
+
resourceId: 'user-123',
|
|
351
|
+
threadId: 'thread-456',
|
|
352
|
+
toolCallId: 'tool-call-456',
|
|
353
|
+
approved: true,
|
|
354
|
+
})
|
|
355
|
+
|
|
356
|
+
console.log(result.accepted)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Returns `{ accepted: true, runId: string, toolCallId?: string }`.
|
|
360
|
+
|
|
344
361
|
### `declineToolCall()`
|
|
345
362
|
|
|
346
|
-
Decline a pending tool call
|
|
363
|
+
Decline a pending tool call and return a continuation stream. Use this when you are rendering the resumed chunks from the decline response.
|
|
347
364
|
|
|
348
365
|
```typescript
|
|
349
366
|
const response = await agent.declineToolCall({
|