@mastra/client-js 1.52.0-alpha.5 → 1.52.0-alpha.8

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.
@@ -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.52.0-alpha.5"
6
+ version: "1.52.0-alpha.8"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.52.0-alpha.5",
2
+ "version": "1.52.0-alpha.8",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -69,7 +69,7 @@ Inside [Studio](https://mastra.ai/docs/studio/overview), go to **Settings** and
69
69
 
70
70
  ## Configuring `MastraClient`
71
71
 
72
- When `auth` is enabled, all requests made with `MastraClient` must include a valid JWT in the `Authorization` header:
72
+ When `auth` is enabled, requests to protected routes made with `MastraClient` must include a valid JWT in the `Authorization` header:
73
73
 
74
74
  ```typescript
75
75
  import { MastraClient } from '@mastra/client-js'
@@ -93,7 +93,7 @@ The controller, Session, and thread have different lifetimes:
93
93
  - **Session**: An isolated live runtime for one user, task, or concurrent work scope. It owns the active mode, model, state, event bus, run state, grants, and current thread binding.
94
94
  - **Thread**: A stored conversation containing messages and thread settings. Threads can survive controller and process recreation when you configure storage.
95
95
 
96
- A Session is live state. Arbitrary [`session.state`](https://mastra.ai/reference/agent-controller/session), permission grants, pending approvals, and active runs don't automatically survive process recreation. Thread messages and selected thread settings, including mode and per-mode model choices, can persist through storage.
96
+ A Session is live state. Arbitrary [`session.state`](https://mastra.ai/reference/agent-controller/session), permission grants, pending approvals, and active runs don't automatically survive process recreation. Thread messages and selected thread settings, including the active mode and the current model, can persist through storage, but switching modes doesn't change the model.
97
97
 
98
98
  ## Sessions and threads
99
99
 
@@ -193,19 +193,14 @@ console.log(session.mode.get()) // "build"
193
193
  console.log(session.mode.resolve().instructions)
194
194
  ```
195
195
 
196
- Switch models independently with [`session.model.switch()`](https://mastra.ai/reference/agent-controller/session), then read the active selection with [`session.model.get()`](https://mastra.ai/reference/agent-controller/session). Thread-scoped selections are stored per mode and restored when the Session returns to that mode:
196
+ Switch models independently with [`session.model.switch()`](https://mastra.ai/reference/agent-controller/session), then read the active selection with [`session.model.get()`](https://mastra.ai/reference/agent-controller/session). The selection is stored as the thread's current model and remains active when the Session changes modes:
197
197
 
198
198
  ```typescript
199
- await session.model.switch({
200
- modelId: 'anthropic/claude-sonnet-4-6',
201
- scope: 'thread',
202
- })
199
+ await session.model.switch('anthropic/claude-sonnet-4-6')
203
200
 
204
201
  console.log(session.model.get())
205
202
  ```
206
203
 
207
- Use `scope: 'global'` for an in-memory selection that shouldn't be written to thread settings.
208
-
209
204
  ## Manage threads and state
210
205
 
211
206
  List stored conversations with [`session.thread.list()`](https://mastra.ai/reference/agent-controller/session):
@@ -285,6 +280,8 @@ session.subscribe(event => {
285
280
 
286
281
  For `submit_plan`, resume with `{ action: 'approved' }` or `{ action: 'rejected', feedback }`. An approved plan can switch to the mode configured by `transitionsTo` before the run continues.
287
282
 
283
+ The built-in `submit_plan` tool takes a plan file path, not the plan text. The agent writes the plan to a file and submits its path. It needs a filesystem it can write to, such as a workspace filesystem. To show the plan for approval, your app reads the file at the submitted `path`.
284
+
288
285
  ## Delegate to subagents
289
286
 
290
287
  Configure available subagent types on the controller. The built-in `subagent` tool can then delegate focused tasks using those definitions:
@@ -354,7 +351,7 @@ const controller = new AgentController({
354
351
  },
355
352
  onSessionStart: async ({ session, thread }) => {
356
353
  const plan = await billing.planFor(thread.resourceId)
357
- await session.model.switch({ modelId: plan.modelId })
354
+ await session.model.switch(plan.modelId)
358
355
  },
359
356
  },
360
357
  })
@@ -445,7 +442,7 @@ Subscriptions are isolated by Session. Events from another Session on the same c
445
442
 
446
443
  ### Client-side sessions
447
444
 
448
- [`client.getAgentController(id).session(resourceId, scope?)`](https://mastra.ai/reference/client-js/agent-controller) returns a session client bound to one resource. Sessions are get-or-create on the server, so `create()` resumes an existing conversation instead of forking it. Pass `scope` when one resource needs independent sessions, such as one per git worktree:
445
+ [`client.getAgentController(key).session(resourceId, scope?)`](https://mastra.ai/reference/client-js/agent-controller) returns a session client bound to one resource. Pass the key the controller is registered under in `new Mastra({ agentControllers })`, which can differ from the controller's `id`. Sessions are get-or-create on the server, so `create()` resumes an existing conversation instead of forking it. Pass `scope` when one resource needs independent sessions, such as one per git worktree:
449
446
 
450
447
  ```typescript
451
448
  import { MastraClient } from '@mastra/client-js'
@@ -39,12 +39,22 @@ Retrieve the agent controllers hosted on the connected Mastra instance:
39
39
  const controllers = await client.listAgentControllers()
40
40
  ```
41
41
 
42
+ Each entry's `id` is the key the controller is registered under in `new Mastra({ agentControllers })`, not the controller's own `id`.
43
+
42
44
  ## Working with a specific agent controller
43
45
 
44
- Get an instance of an agent controller by the ID it's registered under:
46
+ Get an instance of an agent controller by the key it's registered under in `new Mastra({ agentControllers })`. The key can differ from the controller's `id`. In this example, pass `'coding'`, not `'coding-controller'`:
47
+
48
+ ```typescript
49
+ const codingController = new AgentController({ id: 'coding-controller', agent, modes })
50
+
51
+ export const mastra = new Mastra({
52
+ agentControllers: { coding: codingController },
53
+ })
54
+ ```
45
55
 
46
56
  ```typescript
47
- const controller = client.getAgentController('coding-controller')
57
+ const controller = client.getAgentController('coding')
48
58
  ```
49
59
 
50
60
  ### `listModes()`
@@ -155,7 +165,13 @@ Switches the active mode.
155
165
 
156
166
  ### `switchModel(modelId, options?)`
157
167
 
158
- Switches the model. `options.scope` is `'thread'` (default) or `'global'`. `options.modeId` targets a specific mode.
168
+ Switches the session's active model and persists it as the current model for the active thread. Switching modes doesn't change it. Pass `{ thinkingLevel }` as the second argument to apply and persist a thinking level with the model.
169
+
170
+ ```typescript
171
+ await session.switchModel('anthropic/claude-sonnet-4-6', {
172
+ thinkingLevel: 'high',
173
+ })
174
+ ```
159
175
 
160
176
  ### `listThreads(options?)`
161
177
 
@@ -122,7 +122,7 @@ console.log(items.data)
122
122
  - `data`: Conversation items such as `message`, `function_call`, and `function_call_output`
123
123
  - `first_id`: The first item ID in the page
124
124
  - `last_id`: The last item ID in the page
125
- - `has_more`: Whether more items exist beyond the current page
125
+ - `has_more`: Currently always `false`. `items.list()` returns up to 1000 items in a single response.
126
126
 
127
127
  ## Parameters
128
128
 
@@ -59,9 +59,9 @@ You can also pass `requestContext` as a `Record<string, any>`.
59
59
 
60
60
  **getAgent(agentId)** (`Agent`): Retrieves a specific agent instance by ID.
61
61
 
62
- **listAgentControllers()** (`Promise<AgentControllerInfo[]>`): Returns the agent controllers hosted on the connected Mastra instance.
62
+ **listAgentControllers()** (`Promise<AgentControllerInfo[]>`): Returns the agent controllers hosted on the connected Mastra instance. Each entry's id is the key the controller is registered under in new Mastra({ agentControllers }).
63
63
 
64
- **getAgentController(controllerId)** (`AgentController`): Retrieves a specific agent controller by ID. .session(resourceId) returns a session client; call await session.create() to create or resume the server session.
64
+ **getAgentController(controllerId)** (`AgentController`): Retrieves a specific agent controller by the key it is registered under in new Mastra({ agentControllers }), which can differ from the controller id. .session(resourceId) returns a session client; call await session.create() to create or resume the server session.
65
65
 
66
66
  **listMemoryThreads(params)** (`Promise<StorageThreadType[]>`): Retrieves memory threads for the specified resource and agent. Requires a resourceId and an agentId.
67
67
 
@@ -223,9 +223,25 @@ A workflow run result yields the following:
223
223
 
224
224
  **runId** (`string`): Unique identifier for this workflow run instance
225
225
 
226
- **eventTimestamp** (`Date`): The timestamp of the event
226
+ **workflowName** (`string`): Name of the workflow this run belongs to
227
227
 
228
- **payload** (`object`): Contains currentStep (id, status, output, payload) and workflowState (status, steps record)
228
+ **resourceId** (`string`): Resource ID associated with the run, if one was set
229
+
230
+ **createdAt** (`string`): ISO 8601 timestamp of when the run was created
231
+
232
+ **updatedAt** (`string`): ISO 8601 timestamp of when the run was last updated
233
+
234
+ **status** (`WorkflowRunStatus`): Current status of the run, such as 'running', 'success', 'failed', 'suspended', 'waiting', or 'canceled'
235
+
236
+ **payload** (`Record<string, any>`): Input data the run was started with
237
+
238
+ **result** (`Record<string, any>`): Final output of the workflow when the run succeeded
239
+
240
+ **error** (`SerializedError`): Error details when the run failed
241
+
242
+ **steps** (`Record<string, WorkflowStateStepResult>`): Per-step results, including status, output, payload, and timing
243
+
244
+ Use the `fields` option to limit which optional fields are returned. Metadata fields and `status` are always included.
229
245
 
230
246
  ## Dynamic workflows
231
247
 
package/dist/index.cjs CHANGED
@@ -6443,15 +6443,17 @@ var AgentControllerSession = class extends BaseResource {
6443
6443
  body: { modeId }
6444
6444
  });
6445
6445
  }
6446
- /** Switch the model. Defaults to thread scope. */
6447
- async switchModel(modelId, options) {
6446
+ /**
6447
+ * Switch the session model and persist it to the active thread. When
6448
+ * `thinkingLevel` is provided it is applied and persisted with the model.
6449
+ */
6450
+ async switchModel(modelId, { thinkingLevel } = {}) {
6448
6451
  await this.request(this.url(`${this.base()}/model`), {
6449
6452
  method: "POST",
6450
- body: {
6453
+ body: thinkingLevel !== void 0 ? {
6451
6454
  modelId,
6452
- scope: options?.scope,
6453
- modeId: options?.modeId
6454
- }
6455
+ thinkingLevel
6456
+ } : { modelId }
6455
6457
  });
6456
6458
  }
6457
6459
  /**