@mastra/client-js 1.22.0-alpha.3 → 1.22.0-alpha.5

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 CHANGED
@@ -1,5 +1,137 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 1.22.0-alpha.5
4
+
5
+ ### Minor Changes
6
+
7
+ - Added an agent override export API and server-side ownership enforcement. ([#17228](https://github.com/mastra-ai/mastra/pull/17228))
8
+
9
+ 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.
10
+
11
+ The system packages response also reports the active editor `source` so clients can render the correct editing experience.
12
+
13
+ - 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))
14
+
15
+ **Rename a connection from the client SDK**
16
+
17
+ ```ts
18
+ import { MastraClient } from '@mastra/client-js';
19
+
20
+ const client = new MastraClient({ baseUrl: '…' });
21
+
22
+ await client.getToolProvider('composio').updateConnection('auth_abc', {
23
+ label: 'Work inbox',
24
+ });
25
+ ```
26
+
27
+ 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 _-]+`).
28
+
29
+ **Ownership enforced server-side**
30
+
31
+ 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.
32
+
33
+ ### Patch Changes
34
+
35
+ - Updated dependencies [[`a18775a`](https://github.com/mastra-ai/mastra/commit/a18775a693172546ee2378d39b67d4e32895b251), [`1baf2d1`](https://github.com/mastra-ai/mastra/commit/1baf2d152c6881338ff8f114633d5316fe13dd15)]:
36
+ - @mastra/core@1.38.0-alpha.5
37
+
38
+ ## 1.22.0-alpha.4
39
+
40
+ ### Minor Changes
41
+
42
+ - Added the v1 ToolProvider runtime, server routes, client SDK methods, and editor wiring that power OAuth-backed integrations on stored agents. ([#17248](https://github.com/mastra-ai/mastra/pull/17248))
43
+
44
+ **Stored agents can now pin OAuth connections per toolkit**
45
+
46
+ A stored agent's config accepts a new `toolProviders` shape that tells the runtime which connection to bind for each toolkit at execution time. Connections can be scoped per-author, shared across an org, or supplied by the caller.
47
+
48
+ ```ts
49
+ {
50
+ toolProviders: {
51
+ composio: {
52
+ connections: {
53
+ gmail: [{ kind: 'author', toolkit: 'gmail', connectionId: 'auth_abc', scope: 'per-author' }],
54
+ },
55
+ tools: {
56
+ GMAIL_FETCH_EMAILS: { toolkit: 'gmail' },
57
+ },
58
+ },
59
+ },
60
+ }
61
+ ```
62
+
63
+ **New client SDK surface for managing connections**
64
+
65
+ ```ts
66
+ import { MastraClient } from '@mastra/client-js';
67
+
68
+ const client = new MastraClient({ baseUrl: '…' });
69
+ const composio = client.toolProvider('composio');
70
+
71
+ const { items } = await composio.listConnections({ toolkit: 'gmail' });
72
+ await composio.disconnectConnection('auth_abc');
73
+ ```
74
+
75
+ **New `ToolProvider` interface for custom providers**
76
+
77
+ Providers implement a VNext surface (`listToolkitsVNext`, `listToolsVNext`, `resolveToolsVNext`) plus the auth round-trip (`authorize`, `getAuthStatus`, `listConnections`, `disconnectConnection`, `listConnectionFields`, `health`). The Composio provider has been rewritten on this surface; the older catalog methods remain as `@deprecated` shims for back-compat.
78
+
79
+ Connections list responses use `page`/`perPage` pagination, matching the rest of the server surface.
80
+
81
+ Both stored agents (`editor.agent.getById(...)`) and code-defined agents with stored overrides (`editor.agent.applyStoredOverrides(...)`) resolve `toolProviders` at request time, merging provider-resolved tools alongside code/registry/MCP/integration tools.
82
+
83
+ Stored agents that don't set `toolProviders` continue to work unchanged. The Studio/Builder UI ships separately.
84
+
85
+ ### Patch Changes
86
+
87
+ - Hardened v1 ToolProvider connection routes and SDK forwarding. ([#17248](https://github.com/mastra-ai/mastra/pull/17248))
88
+
89
+ **Fail closed on unknown `connectionId`**
90
+
91
+ `DELETE /tool-providers/:providerId/connections/:connectionId` and
92
+ `GET …/usage` now return `403` when storage is configured but no persisted
93
+ row matches the supplied `connectionId` and the caller isn't an admin.
94
+ Previously these routes fell through to the caller's own `authorId`, which
95
+ let non-admin callers probe (and trigger provider-side `revokeConnection`
96
+ for) IDs that didn't belong to them.
97
+
98
+ **Aligned authorize label validation with stored label rules**
99
+
100
+ `POST /tool-providers/:providerId/authorize` now enforces the same label
101
+ rules the stored `toolProviders` config uses (`min(1)`, `max(32)`,
102
+ `/^[A-Za-z0-9 _-]+$/`). Labels that pass `authorize` are now guaranteed to
103
+ pass downstream stored-agent validation.
104
+
105
+ **SDK forwards `toolkit` on connection-scoped operations**
106
+
107
+ `@mastra/client-js`:
108
+
109
+ ```ts
110
+ await client.toolProviders.get('composio').disconnectConnection('ca_xxx', {
111
+ toolkit: 'gmail',
112
+ force: true,
113
+ });
114
+
115
+ const usage = await client.toolProviders.get('composio').getConnectionUsage('ca_xxx', { toolkit: 'gmail' });
116
+ ```
117
+
118
+ `disconnectConnection` now forwards `params.toolkit` (previously dropped)
119
+ and `getConnectionUsage` accepts an optional `{ toolkit }` parameter so
120
+ toolkit-scoped connection lookups disambiguate correctly server-side.
121
+
122
+ - Improved observability and error isolation in the v1 ToolProvider runtime. ([#17248](https://github.com/mastra-ai/mastra/pull/17248))
123
+
124
+ **Better visibility into connection-scope misconfiguration**
125
+
126
+ When an agent runs with a stored ToolProvider connection whose scope cannot be resolved from the request context, the runtime now logs a one-shot warning and falls back to a shared bucket instead of silently routing every caller to the same OAuth account. Multi-tenant deployments get a clear signal when their identity wiring isn't reaching the runtime.
127
+
128
+ **One bad toolkit no longer disables sibling providers**
129
+
130
+ If a provider returns more connections for a toolkit than its declared capabilities allow, the runtime now logs and skips that toolkit instead of throwing. Other providers and other toolkits on the same agent continue to resolve normally.
131
+
132
+ - Updated dependencies [[`50ed00c`](https://github.com/mastra-ai/mastra/commit/50ed00caa914a85969b33de83f26b48e328ef641), [`9283971`](https://github.com/mastra-ai/mastra/commit/928397157009b4aef4d5fdf3a0a273cb371beb55), [`0bf2d93`](https://github.com/mastra-ai/mastra/commit/0bf2d932d20e2936f2d9abb8c0a86e24fbc97ec6), [`94dfef6`](https://github.com/mastra-ai/mastra/commit/94dfef6e2bf19a88467ea3940afcbce88a433f0f), [`a122f79`](https://github.com/mastra-ai/mastra/commit/a122f79427ae225ec79c7b2ed46278da48d04b17), [`4c02027`](https://github.com/mastra-ai/mastra/commit/4c020277235eaa6b1dc957c90ad0639eef213992), [`6855012`](https://github.com/mastra-ai/mastra/commit/685501247cc4717506f3e89beed03509d63a5370), [`7fef31c`](https://github.com/mastra-ai/mastra/commit/7fef31c0d2a6d362a43a647a8a4f6ab893758a23), [`7fef31c`](https://github.com/mastra-ai/mastra/commit/7fef31c0d2a6d362a43a647a8a4f6ab893758a23)]:
133
+ - @mastra/core@1.38.0-alpha.4
134
+
3
135
  ## 1.22.0-alpha.3
4
136
 
5
137
  ### Minor Changes
@@ -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.3"
6
+ version: "1.22.0-alpha.5"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.22.0-alpha.3",
2
+ "version": "1.22.0-alpha.5",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {
5
5
  "RequestContext": {
@@ -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 | Description |
118
- | -------- | ------------------------------- | ------------------------- |
119
- | `GET` | `/stored/agents` | List all stored agents. |
120
- | `POST` | `/stored/agents` | Create a stored agent. |
121
- | `GET` | `/stored/agents/:storedAgentId` | Get a stored agent by ID. |
122
- | `PATCH` | `/stored/agents/:storedAgentId` | Update a stored agent. |
123
- | `DELETE` | `/stored/agents/:storedAgentId` | Delete a stored agent. |
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.
package/dist/index.cjs CHANGED
@@ -4710,6 +4710,15 @@ var StoredAgent = class extends BaseResource {
4710
4710
  }
4711
4711
  );
4712
4712
  }
4713
+ /**
4714
+ * Exports deterministic JSON for this agent without mutating storage.
4715
+ */
4716
+ export(params) {
4717
+ return this.request(`/stored/agents/${encodeURIComponent(this.storedAgentId)}/export`, {
4718
+ method: "POST",
4719
+ body: params
4720
+ });
4721
+ }
4713
4722
  /**
4714
4723
  * Deletes the stored agent
4715
4724
  * @param requestContext - Optional request context to pass as query parameter
@@ -5243,16 +5252,13 @@ var ToolProvider = class extends BaseResource {
5243
5252
  }
5244
5253
  providerId;
5245
5254
  /**
5246
- * Lists available toolkits from this provider
5247
- * @returns Promise containing list of toolkits
5255
+ * Lists available toolkits from this provider.
5248
5256
  */
5249
5257
  listToolkits() {
5250
5258
  return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/toolkits`);
5251
5259
  }
5252
5260
  /**
5253
- * Lists available tools from this provider, with optional filtering
5254
- * @param params - Optional filtering and pagination parameters
5255
- * @returns Promise containing list of tools
5261
+ * Lists available tools from this provider, with optional filtering.
5256
5262
  */
5257
5263
  listTools(params) {
5258
5264
  const searchParams = new URLSearchParams();
@@ -5274,15 +5280,139 @@ var ToolProvider = class extends BaseResource {
5274
5280
  );
5275
5281
  }
5276
5282
  /**
5277
- * Gets the input schema for a specific tool
5278
- * @param toolSlug - The slug of the tool
5279
- * @returns Promise containing the tool's JSON schema
5283
+ * Gets the input schema for a specific tool.
5280
5284
  */
5281
5285
  getToolSchema(toolSlug) {
5282
5286
  return this.request(
5283
5287
  `/tool-providers/${encodeURIComponent(this.providerId)}/tools/${encodeURIComponent(toolSlug)}/schema`
5284
5288
  );
5285
5289
  }
5290
+ /**
5291
+ * Starts an OAuth flow for a (toolkit, connectionId) pair. Returns a
5292
+ * redirect URL and an opaque auth handle to poll with `getAuthStatus`.
5293
+ */
5294
+ authorize(params) {
5295
+ return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/authorize`, {
5296
+ method: "POST",
5297
+ body: params
5298
+ });
5299
+ }
5300
+ /**
5301
+ * Polls the OAuth flow status for an outstanding authorize call.
5302
+ */
5303
+ getAuthStatus(authId) {
5304
+ return this.request(
5305
+ `/tool-providers/${encodeURIComponent(this.providerId)}/auth-status/${encodeURIComponent(authId)}`
5306
+ );
5307
+ }
5308
+ /**
5309
+ * Batch-checks whether a set of (connectionId, toolkit) tuples are
5310
+ * currently connected.
5311
+ */
5312
+ getConnectionStatus(params) {
5313
+ return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/connection-status`, {
5314
+ method: "POST",
5315
+ body: params
5316
+ });
5317
+ }
5318
+ /**
5319
+ * Lists existing provider connections, scoped to a toolkit.
5320
+ *
5321
+ * Default: the connection owner is resolved server-side from the request's
5322
+ * auth context. Admin callers (with `tool-providers:admin` permission) may
5323
+ * pass `authorId` to target a specific author, or omit it to receive
5324
+ * connections across all authors known to `tool_provider_connections` for
5325
+ * this provider/toolkit. Pagination is page-based via `page` (1-indexed)
5326
+ * and `perPage` (default 50, max 200).
5327
+ */
5328
+ listConnections(params) {
5329
+ const searchParams = new URLSearchParams();
5330
+ searchParams.set("toolkit", params.toolkit);
5331
+ if (params.authorId) {
5332
+ searchParams.set("authorId", params.authorId);
5333
+ }
5334
+ if (params.page !== void 0 && params.page !== null) {
5335
+ searchParams.set("page", String(params.page));
5336
+ }
5337
+ if (params.perPage !== void 0 && params.perPage !== null) {
5338
+ searchParams.set("perPage", String(params.perPage));
5339
+ }
5340
+ if (params.scope) {
5341
+ searchParams.set("scope", params.scope);
5342
+ }
5343
+ return this.request(
5344
+ `/tool-providers/${encodeURIComponent(this.providerId)}/connections?${searchParams.toString()}`
5345
+ );
5346
+ }
5347
+ /**
5348
+ * Lists provider-specific fields the picker should collect before
5349
+ * initiating a new connection (e.g. Confluence subdomain). Most toolkits
5350
+ * return an empty array.
5351
+ */
5352
+ listConnectionFields(params) {
5353
+ const searchParams = new URLSearchParams();
5354
+ searchParams.set("toolkit", params.toolkit);
5355
+ return this.request(
5356
+ `/tool-providers/${encodeURIComponent(this.providerId)}/connection-fields?${searchParams.toString()}`
5357
+ );
5358
+ }
5359
+ /**
5360
+ * Disconnects (revokes + deletes) a persisted connection.
5361
+ *
5362
+ * Without `force: true` the server refuses if any agent still pins the
5363
+ * connection. With `force: true` the provider-side revoke is best-effort
5364
+ * (errors are tolerated) and the local row is always removed.
5365
+ */
5366
+ disconnectConnection(connectionId, params) {
5367
+ const searchParams = new URLSearchParams();
5368
+ if (params?.toolkit) {
5369
+ searchParams.set("toolkit", params.toolkit);
5370
+ }
5371
+ if (params?.force) {
5372
+ searchParams.set("force", "true");
5373
+ }
5374
+ const queryString = searchParams.toString();
5375
+ return this.request(
5376
+ `/tool-providers/${encodeURIComponent(this.providerId)}/connections/${encodeURIComponent(connectionId)}${queryString ? `?${queryString}` : ""}`,
5377
+ {
5378
+ method: "DELETE"
5379
+ }
5380
+ );
5381
+ }
5382
+ /**
5383
+ * Updates the persisted display label on a connection row. Pass `label: null`
5384
+ * (or an empty string) to clear the existing label. Only the connection owner
5385
+ * or an admin may rename, unless the row is `scope: 'shared'`.
5386
+ */
5387
+ updateConnection(connectionId, params) {
5388
+ return this.request(
5389
+ `/tool-providers/${encodeURIComponent(this.providerId)}/connections/${encodeURIComponent(connectionId)}`,
5390
+ {
5391
+ method: "PATCH",
5392
+ body: params
5393
+ }
5394
+ );
5395
+ }
5396
+ /**
5397
+ * Lists the agents that currently pin a given connection. Used by the
5398
+ * picker to warn the user before disconnecting a shared account.
5399
+ */
5400
+ getConnectionUsage(connectionId, params) {
5401
+ const searchParams = new URLSearchParams();
5402
+ if (params?.toolkit) {
5403
+ searchParams.set("toolkit", params.toolkit);
5404
+ }
5405
+ const queryString = searchParams.toString();
5406
+ return this.request(
5407
+ `/tool-providers/${encodeURIComponent(this.providerId)}/connections/${encodeURIComponent(connectionId)}/usage${queryString ? `?${queryString}` : ""}`
5408
+ );
5409
+ }
5410
+ /**
5411
+ * Returns provider-level health (config, reachability, etc.).
5412
+ */
5413
+ getHealth() {
5414
+ return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/health`);
5415
+ }
5286
5416
  };
5287
5417
 
5288
5418
  // src/resources/processor-provider.ts