@mastra/client-js 1.56.0-alpha.8 → 1.56.0-alpha.9

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/dist/client.d.ts CHANGED
@@ -52,7 +52,7 @@ export declare class MastraClient extends BaseResource {
52
52
  listAgentControllers(): Promise<AgentControllerInfo[]>;
53
53
  /**
54
54
  * Scopes to an agent controller hosted on the connected Mastra instance. Use
55
- * `getAgentController(id).session(resourceId)` to create/resume a session,
55
+ * `getAgentController(id).session(sessionId)` to create/resume a session,
56
56
  * stream its events, and send messages.
57
57
  * @param controllerId - The id the agent controller is registered under on Mastra
58
58
  */
@@ -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.56.0-alpha.8"
6
+ version: "1.56.0-alpha.9"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.56.0-alpha.8",
2
+ "version": "1.56.0-alpha.9",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -90,43 +90,40 @@ Use the same controller for many Sessions. Don't store a current Session on the
90
90
  The controller, Session, and thread have different lifetimes:
91
91
 
92
92
  - **Controller**: A shared host for configuration and runtime services. Initialize it once and reuse it.
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.
93
+ - **Session**: An isolated live runtime for one user, task, or concurrent piece of work, addressed by its session id. 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
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
 
100
- `createSession()` is get-or-create by `resourceId` and optional `scope`:
100
+ `createSession()` is get-or-create by session `id`. The `resourceId` names who owns the session's threads and resource-scoped memory. When you omit `id`, it defaults to `resourceId`:
101
101
 
102
102
  ```typescript
103
103
  const webSession = await controller.createSession({
104
+ id: 'user-123:web',
104
105
  resourceId: 'user-123',
105
- scope: 'web',
106
106
  })
107
107
 
108
- const sameWebSession = await controller.createSession({
109
- resourceId: 'user-123',
110
- scope: 'web',
111
- })
108
+ const sameWebSession = await controller.getSession('user-123:web')
112
109
 
113
110
  const workerSession = await controller.createSession({
111
+ id: 'user-123:background-worker',
114
112
  resourceId: 'user-123',
115
- scope: 'background-worker',
116
113
  })
117
114
 
118
115
  console.log(webSession === sameWebSession) // true
119
116
  console.log(webSession === workerSession) // false
120
117
  ```
121
118
 
122
- Sessions with different scopes have separate event buses, run loops, state, mode and model selections, and current thread bindings. Their stored threads still belong to the shared `resourceId`.
119
+ Sessions with different ids have separate event buses, run loops, state, mode and model selections, and current thread bindings. Their stored threads and resource-scoped memory still belong to the shared `resourceId`, so listing threads by resource returns both sessions' threads.
123
120
 
124
121
  Pass `threadId` when the host must bind the Session to an exact thread. The controller switches to the existing thread or creates it with that ID when it's missing. This behavior also applies when `createSession()` returns a cached Session:
125
122
 
126
123
  ```typescript
127
124
  const session = await controller.createSession({
125
+ id: 'user-123:web',
128
126
  resourceId: 'user-123',
129
- scope: 'web',
130
127
  threadId: 'support-ticket-42',
131
128
  })
132
129
  ```
@@ -430,9 +427,9 @@ channels: {
430
427
  const install = await installs.authorize(requestContext.get('teamId'))
431
428
 
432
429
  return controller.createSession({
430
+ id: `${install.id}:${thread.id}`,
433
431
  resourceId: thread.resourceId,
434
432
  threadId: thread.id,
435
- scope: install.id,
436
433
  ownerId: controller.id,
437
434
  requestContext,
438
435
  })
@@ -440,7 +437,7 @@ channels: {
440
437
  }
441
438
  ```
442
439
 
443
- Create the session under `thread.resourceId`. Because a session can bind only threads it owns, use `resolveResourceId` to assign a different owner to the mapped thread. Pass `threadId: thread.id` so the session opens on the mapped thread. Without it, a session that has tags or a `projectPath` doesn't treat the mapped thread as its own, so it creates an extra empty thread before switching to the mapped one. Sessions are get-or-create for each `resourceId` and `scope` combination. Pass `scope` when one thread needs separate sessions for each installation or principal.
440
+ Create the session under `thread.resourceId`. Because a session can bind only threads it owns, use `resolveResourceId` to assign a different owner to the mapped thread. Pass `threadId: thread.id` so the session opens on the mapped thread. Without it, a session that has tags or a `projectPath` doesn't treat the mapped thread as its own, so it creates an extra empty thread before switching to the mapped one. Sessions are get-or-create by `id`. Give each installation or principal its own `id` when one thread needs separate sessions.
444
441
 
445
442
  Failures that aren't refusals (a storage outage, a bug in your resolver's dependencies) still post an error to the thread, so a broken bot doesn't look like a silent one. If you need to tell them apart in your own code, a refusal is a `ChannelSessionRejectedError` with the original error as its `cause`.
446
443
 
@@ -490,7 +487,7 @@ Subscriptions are isolated by Session. Events from another Session on the same c
490
487
 
491
488
  ### Client-side sessions
492
489
 
493
- [`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:
490
+ [`client.getAgentController(key).session(sessionId)`](https://mastra.ai/reference/client-js/agent-controller) returns a session client addressed by its session id. 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 `resourceId` to `create()` when several sessions share one resource; otherwise the resource defaults to the session id:
494
491
 
495
492
  ```typescript
496
493
  import { MastraClient } from '@mastra/client-js'
@@ -513,7 +510,7 @@ const subscription = await session.subscribe({
513
510
  subscription.unsubscribe()
514
511
  ```
515
512
 
516
- `subscribe()` takes an options object and is async, unlike the in-process listener. Its promise resolves once the stream is established and rejects when it can't connect. A rejected call leaves nothing running in the background. `reconnect: true` re-establishes a stream that drops after it was established, with exponential backoff. A connection that goes silent without closing, for example after the device sleeps, counts as a drop once no data, including server heartbeats, arrives for `idleTimeoutMs` (default `60000`).
513
+ `subscribe()` takes an options object and is async, unlike the in-process listener. Its promise resolves once the stream is established and rejects when it can't connect. A rejected call leaves nothing running in the background. `reconnect: true` re-establishes a stream that drops after it was established, with exponential backoff. A connection that stays open but stops delivering data, for example after the device sleeps, counts as a drop once no data, including server heartbeats, arrives for `idleTimeoutMs` (default `60000`).
517
514
 
518
515
  The server doesn't replay events missed while the stream was down, so read `session.state()` from `onReconnect` for the current mode, model, and thread. The client surface has no `session.displayState.get()`.
519
516
 
@@ -171,13 +171,13 @@ const mastra = new Mastra({
171
171
  return { prompt: `Status as of ${trigger.firedAt.toISOString()}` }
172
172
  },
173
173
  onFinish: async ({ agentId, outcome, runId }) => {
174
- // Runs on any non-error, non-abort outcome
174
+ // Runs on any non-error, non-abort outcome. For a threaded schedule, this is the hand-off, not the end of the run
175
175
  },
176
176
  onError: async ({ agentId, phase, error }) => {
177
- // Runs when prepare, the signal, or the agent run threw
177
+ // Runs when prepare or the signal threw, or a threadless run failed without aborting
178
178
  },
179
179
  onAbort: async ({ agentId, runId }) => {
180
- // Runs when the run was aborted mid-stream
180
+ // Runs when a threadless run was aborted
181
181
  },
182
182
  },
183
183
  })
@@ -186,9 +186,11 @@ const mastra = new Mastra({
186
186
  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
- - `onFinish`: runs once per trigger that reached a non-error, non-abort terminal state.
190
- - `onError`: runs after a failure in `prepare` or the signal. It also runs when the agent run fails.
191
- - `onAbort`: runs when the run was aborted mid-stream.
189
+ - `onFinish`: runs once per trigger that reached a non-error, non-abort outcome. When a threaded schedule starts a new run, it runs with `outcome: 'succeeded'` as soon as the run starts, not when it finishes.
190
+ - `onError`: runs after a failure in `prepare` or the signal. For a schedule without a `threadId`, it also runs when the agent run fails with an error that isn't an abort.
191
+ - `onAbort`: runs when the run of a schedule without a `threadId` was aborted.
192
+
193
+ For a schedule with a `threadId`, the worker sends the prompt to the thread and doesn't wait for the run. Errors and aborts after the run starts surface on that thread's run, not through `onError` or `onAbort`.
192
194
 
193
195
  Every hook context includes `agentId` (the agent the schedule fired for) alongside `schedule` and `trigger`.
194
196
 
@@ -81,11 +81,19 @@ Returns the controller's workspace status.
81
81
 
82
82
  Returns: `Promise<AgentControllerWorkspaceStatus>`
83
83
 
84
- ### `session(resourceId, scope?)`
84
+ ### `session(sessionId)`
85
85
 
86
- Returns an `AgentControllerSession` bound to one resource. Sessions are get-or-create on the server, so calling `create()` on the same `resourceId` and `scope` resumes the existing conversation instead of forking it.
86
+ Returns an `AgentControllerSession` addressed by its session id. Every request goes to `/agent-controller/:controllerId/sessions/:sessionId/...`. Sessions are get-or-create on the server, so calling `create()` with the same `sessionId` resumes the existing conversation instead of forking it.
87
87
 
88
- Pass `scope` to address an independent session over the same `resourceId`. Sessions that share a `resourceId` but use different scopes each get their own run loop, thread binding, mode, model, and state. A common pattern is one session per git worktree with the worktree path as the scope. The scope travels on every request as a `sessionScope` query parameter.
88
+ Sessions that share a resource but use different session ids each get their own run loop, thread binding, mode, model, and state. Their stored threads and resource-scoped memory belong to the shared resource. Pass the resource to `create()`:
89
+
90
+ ```typescript
91
+ const runA = client.getAgentController('code').session('run-a')
92
+ await runA.create({ resourceId: 'factory-1' })
93
+
94
+ const runB = client.getAgentController('code').session('run-b')
95
+ await runB.create({ resourceId: 'factory-1' })
96
+ ```
89
97
 
90
98
  ## Session methods
91
99
 
@@ -93,6 +101,8 @@ Pass `scope` to address an independent session over the same `resourceId`. Sessi
93
101
 
94
102
  Creates or resumes the session.
95
103
 
104
+ **resourceId** (`string`): Memory resource that owns the session's threads. Defaults to the session id, so a session created with only an id keeps one resource of its own.
105
+
96
106
  **tags** (`Record<string, string>`): Scopes initial thread selection. A thread is a resume candidate only when its metadata matches every tag.
97
107
 
98
108
  **threadId** (`string`): Binds the session to one exact thread, creating it with that ID when it does not exist.
@@ -61,7 +61,7 @@ You can also pass `requestContext` as a `Record<string, any>`.
61
61
 
62
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 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.
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(sessionId) 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
 
@@ -105,7 +105,7 @@ Combine predicates with `and`, `or` and `not`. Membership uses `{ op: 'in', valu
105
105
 
106
106
  Each summary includes identity, context, entity lineage, status, timestamps, `durationMs`, model/provider and input/output/error previews. Model/provider are available in returned rows but aren't filterable.
107
107
 
108
- The additional identity, context and parent/root entity filters require an updated storage adapter. With an older adapter, requests using these filters return a structured `422` error.
108
+ Check `capabilities.spanQueryContextFields` from `getObservabilityCapabilities()` before using the additional identity, context and parent/root entity filters. A missing or false value means these filters aren't available. With an older adapter, requests using these filters return a structured `422` error.
109
109
 
110
110
  DuckDB returns `null` for parent/root entity type, ID and name, and for `executionSource`. Equality filters on these fields match no spans. Parent/root entity version IDs remain available.
111
111
 
@@ -30,10 +30,11 @@ The configured observability store must support each API. Call `getObservability
30
30
  | `traceQueryTimeToFirstChunkSort` | `trace-query-time-to-first-chunk-sort` | `orderBy` on `timeToFirstChunkMs` |
31
31
  | `traceQueryContextIds` | `trace-query-context-ids` | `runId`, `sessionId`, `userId`, and `organizationId` predicates |
32
32
  | `traceQueryRootSpanFields` | `trace-query-root-span-fields` | Trace-scope `name` and `spanType` predicates, dimensions, and `countDistinct` measures |
33
+ | `traceQueryRootEntityId` | `trace-query-root-entity-id` | Trace-scope `entityId` predicates, dimensions, and `countDistinct` measures |
33
34
  | `traceQueryDiscovery` | `trace-query-discovery` | [Field and value discovery](#discover-fields-and-values) |
34
35
  | `traceQueryTenantScope` | `trace-query-tenant-scope` | [Trusted tenant scope](#trusted-tenant-scope) |
35
36
 
36
- A missing `traceAggregate` value means the server doesn't support aggregation. Servers without the aggregate route return `404`, and stores without the feature return `501 TRACE_AGGREGATE_UNSUPPORTED`. Against a store without a sub-feature, a request that uses a gated field returns `501` before storage runs. Root span `name` and `spanType` are the exception and return `422` with a `field_not_allowed` issue.
37
+ A missing `traceAggregate` value means the server doesn't support aggregation. Servers without the aggregate route return `404`, and stores without the feature return `501 TRACE_AGGREGATE_UNSUPPORTED`. Against a store without a sub-feature, a request that uses a gated field returns `501` before storage runs. Root span `name`, `spanType`, and `entityId` are the exception and return `422` with a `field_not_allowed` issue.
37
38
 
38
39
  ## Select traces
39
40
 
@@ -76,7 +77,7 @@ Span clauses examine the current root span and current child spans. The root `ti
76
77
 
77
78
  | Predicate context | Fields | Operators |
78
79
  | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------- |
79
- | Trace | `traceId`, `threadId`, `resourceId`, `runId`, `sessionId`, `userId`, `organizationId`, `entityName`, `entityType`, `name`, `spanType`, `environment`, `status` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
80
+ | Trace | `traceId`, `threadId`, `resourceId`, `runId`, `sessionId`, `userId`, `organizationId`, `entityId`, `entityName`, `entityType`, `name`, `spanType`, `environment`, `status` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
80
81
  | Trace metadata | `metadata.<key>` | `eq`, `ne`, `in`, `notIn`, `exists`, `notExists` |
81
82
  | Trace | `startedAt`, `endedAt`, `durationMs`, `timeToFirstChunkMs` | `eq`, `ne`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `exists`, `notExists` |
82
83
  | Trace | `tags` | `includes`, `notIncludes`, `exists`, `notExists` |
@@ -85,7 +86,7 @@ Span clauses examine the current root span and current child spans. The root `ti
85
86
  | Span | `startedAt`, `endedAt`, `durationMs`, `timeToFirstChunkMs` | `eq`, `ne`, `in`, `notIn`, `lt`, `lte`, `gt`, `gte`, `exists`, `notExists` |
86
87
  | Span | `error` | `exists`, `notExists` |
87
88
 
88
- Trace-scope `name` and `spanType` read the current root span, so `{ op: 'eq', left: { path: 'spanType' }, right: { literal: 'workflow_run' } }` selects traces started by a workflow run. Inside `spans.some` or `spans.none`, the same fields match any span in the trace.
89
+ Trace-scope `name`, `spanType`, and `entityId` read the current root span, so `{ op: 'eq', left: { path: 'spanType' }, right: { literal: 'workflow_run' } }` selects traces started by a workflow run. Inside `spans.some` or `spans.none`, the same fields match any span in the trace.
89
90
 
90
91
  Compose predicates with `{ op: 'and', args: [...] }`, `{ op: 'or', args: [...] }`, and `{ op: 'not', arg: ... }`. Comparison predicates place a field reference on the left and a literal on the right. Membership predicates use a field reference in `value` and a homogeneous literal array in `set`. Tag predicates name the stored tag collection in `path`. `includes` and `notIncludes` also take one tag in `value`, while `exists` and `notExists` take only `op` and `path`. See [Filter by tags](#filter-by-tags). Text predicates use the comparison shape with a string literal. See [Filter by text](#filter-by-text).
91
92
 
@@ -664,12 +665,13 @@ Unknown fields are rejected. Aggregation isn't paginated. Narrow the selection,
664
665
 
665
666
  Dimensions read the current root span of each selected trace:
666
667
 
667
- | Dimension | Notes |
668
- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- |
669
- | `entityType`, `entityName`, `environment`, `status`, `serviceName`, `executionSource` | Root span attributes. |
670
- | `threadId`, `resourceId`, `userId`, `sessionId`, `organizationId`, `experimentId` | Context identifiers recorded on the root span. |
671
- | `name`, `spanType` | Root span name and type. Requires the `traceQueryRootSpanFields` capability. |
672
- | `metadata.<key>` | One non-empty top-level metadata key. Values are trimmed. Missing, empty, and non-string values group as `null`. |
668
+ | Dimension | Notes |
669
+ | ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
670
+ | `entityType`, `entityName`, `environment`, `status`, `serviceName`, `executionSource` | Root span attributes. |
671
+ | `threadId`, `resourceId`, `userId`, `sessionId`, `organizationId`, `experimentId` | Context identifiers recorded on the root span. |
672
+ | `name`, `spanType` | Root span name and type. Requires the `traceQueryRootSpanFields` capability. |
673
+ | `entityId` | Root span entity ID. Groups traces that have no `entityName`, such as scorer runs. Requires the `traceQueryRootEntityId` capability. |
674
+ | `metadata.<key>` | One non-empty top-level metadata key. Values are trimmed. Missing, empty, and non-string values group as `null`. |
673
675
 
674
676
  Every dimension except `serviceName`, `executionSource`, and `experimentId` is also a trace-scope `where` field, so you can drill into a group by adding its values to the predicate. `traceId`, `spanId`, `runId`, and `requestId` aren't groupable. Traces with no value for a dimension form their own group with a `null` value.
675
677
 
package/dist/index.cjs CHANGED
@@ -6800,48 +6800,40 @@ function hydrateEventTimestamps(event) {
6800
6800
  return isKnownParsedEvent(event) ? hydrateKnownEvent(event) : event;
6801
6801
  }
6802
6802
  /**
6803
- * A session bound to a `resourceId` within one agent controller. Sessions are
6804
- * get-or-create on the server, so re-creating the same resourceId (and scope)
6805
- * resumes the existing conversation rather than forking it.
6806
- *
6807
- * Pass a `scope` to address an independent session over the same resourceId:
6808
- * two sessions with the same resourceId but different scopes have their own
6809
- * run loop, thread binding, and mode/model/state (e.g. one session per git
6810
- * worktree, with the worktree path as the scope). The scope travels on every
6811
- * request as a `sessionScope` query param.
6803
+ * A session addressed by its `sessionId` within one agent controller. Sessions
6804
+ * are get-or-create on the server, so re-creating the same sessionId resumes
6805
+ * the existing conversation rather than forking it. Many sessions can work on
6806
+ * one `resourceId` (whose threads and memory they use); each has its own run
6807
+ * loop, thread binding, and mode/model/state.
6812
6808
  */
6813
6809
  var AgentControllerSession = class extends BaseResource {
6814
6810
  controllerId;
6815
- resourceId;
6816
- scope;
6817
- constructor(options, controllerId, resourceId, scope) {
6811
+ sessionId;
6812
+ constructor(options, controllerId, sessionId) {
6818
6813
  super(options);
6819
6814
  this.controllerId = controllerId;
6820
- this.resourceId = resourceId;
6821
- this.scope = scope;
6815
+ this.sessionId = sessionId;
6822
6816
  }
6823
6817
  base() {
6824
- return `/agent-controller/${encodeURIComponent(this.controllerId)}/sessions/${encodeURIComponent(this.resourceId)}`;
6825
- }
6826
- /** Append this session's scope (if any) as a `sessionScope` query param. */
6827
- url(path) {
6828
- if (this.scope === void 0) return path;
6829
- return `${path}${path.includes("?") ? "&" : "?"}sessionScope=${encodeURIComponent(this.scope)}`;
6818
+ return `/agent-controller/${encodeURIComponent(this.controllerId)}/sessions/${encodeURIComponent(this.sessionId)}`;
6830
6819
  }
6831
6820
  /**
6832
- * Create or resume this session. Pass `tags` to scope initial thread
6833
- * selection — a thread is a resume candidate only when its metadata matches
6834
- * every tag. Pass `threadId` to bind the session to one exact thread,
6835
- * creating it with that id when it does not exist.
6821
+ * Create or resume this session. `resourceId` names whose threads and memory
6822
+ * the session works on. Without it the server resumes the session on the
6823
+ * resource it already has (the live session's, or the resource of the thread
6824
+ * with the session's id), falling back to the sessionId. Pass `tags` to scope
6825
+ * initial thread selection — a thread is a resume candidate only when its
6826
+ * metadata matches every tag. Pass `threadId` to bind the session to one
6827
+ * exact thread, creating it with that id when it does not exist.
6836
6828
  */
6837
6829
  create(options) {
6838
6830
  return this.request(`/agent-controller/${encodeURIComponent(this.controllerId)}/sessions`, {
6839
6831
  method: "POST",
6840
6832
  body: {
6841
- resourceId: this.resourceId,
6833
+ resourceId: options?.resourceId,
6834
+ sessionId: this.sessionId,
6842
6835
  tags: options?.tags,
6843
- threadId: options?.threadId,
6844
- sessionScope: this.scope
6836
+ threadId: options?.threadId
6845
6837
  }
6846
6838
  });
6847
6839
  }
@@ -6897,7 +6889,7 @@ var AgentControllerSession = class extends BaseResource {
6897
6889
  const abort = new AbortController();
6898
6890
  currentAbort = abort;
6899
6891
  let openTimer;
6900
- const request = this.request(this.url(`${this.base()}/stream`), {
6892
+ const request = this.request(`${this.base()}/stream`, {
6901
6893
  stream: true,
6902
6894
  signal: abort.signal
6903
6895
  });
@@ -7107,7 +7099,7 @@ var AgentControllerSession = class extends BaseResource {
7107
7099
  files: void 0
7108
7100
  } : message;
7109
7101
  const requestContext = parseClientRequestContext(options?.requestContext);
7110
- await this.request(this.url(`${this.base()}/messages`), {
7102
+ await this.request(`${this.base()}/messages`, {
7111
7103
  method: "POST",
7112
7104
  body: {
7113
7105
  message: content,
@@ -7118,7 +7110,7 @@ var AgentControllerSession = class extends BaseResource {
7118
7110
  }
7119
7111
  /** Abort the in-flight run for this session. */
7120
7112
  async abort() {
7121
- await this.request(this.url(`${this.base()}/abort`), { method: "POST" });
7113
+ await this.request(`${this.base()}/abort`, { method: "POST" });
7122
7114
  }
7123
7115
  /**
7124
7116
  * Approve or decline a pending tool call (`tool_approval_required`). Resolves
@@ -7126,7 +7118,7 @@ var AgentControllerSession = class extends BaseResource {
7126
7118
  */
7127
7119
  async approveTool(toolCallId, approved, options) {
7128
7120
  const requestContext = parseClientRequestContext(options?.requestContext);
7129
- return this.request(this.url(`${this.base()}/tool-approval`), {
7121
+ return this.request(`${this.base()}/tool-approval`, {
7130
7122
  method: "POST",
7131
7123
  retries: 0,
7132
7124
  body: {
@@ -7144,7 +7136,7 @@ var AgentControllerSession = class extends BaseResource {
7144
7136
  */
7145
7137
  async respondToToolSuspension(toolCallId, resumeData, options) {
7146
7138
  const requestContext = parseClientRequestContext(options?.requestContext);
7147
- return this.request(this.url(`${this.base()}/tool-suspension`), {
7139
+ return this.request(`${this.base()}/tool-suspension`, {
7148
7140
  method: "POST",
7149
7141
  retries: 0,
7150
7142
  body: {
@@ -7164,7 +7156,7 @@ var AgentControllerSession = class extends BaseResource {
7164
7156
  files: void 0
7165
7157
  } : message;
7166
7158
  const requestContext = parseClientRequestContext(options?.requestContext);
7167
- await this.request(this.url(`${this.base()}/steer`), {
7159
+ await this.request(`${this.base()}/steer`, {
7168
7160
  method: "POST",
7169
7161
  body: {
7170
7162
  message: content,
@@ -7176,18 +7168,18 @@ var AgentControllerSession = class extends BaseResource {
7176
7168
  /** Get the current mode, model, and thread (for initial UI hydration). */
7177
7169
  state(options) {
7178
7170
  const path = options?.threadId ? `${this.base()}?threadId=${encodeURIComponent(options.threadId)}` : this.base();
7179
- return this.request(this.url(path));
7171
+ return this.request(path);
7180
7172
  }
7181
7173
  /** Merge key-value pairs into the session state. Existing keys not in the payload are preserved. */
7182
7174
  async setState(updates) {
7183
- await this.request(this.url(`${this.base()}/state`), {
7175
+ await this.request(`${this.base()}/state`, {
7184
7176
  method: "PUT",
7185
7177
  body: { state: updates }
7186
7178
  });
7187
7179
  }
7188
7180
  /** Switch the active mode (e.g. `build`, `plan`). */
7189
7181
  async switchMode(modeId) {
7190
- await this.request(this.url(`${this.base()}/mode`), {
7182
+ await this.request(`${this.base()}/mode`, {
7191
7183
  method: "POST",
7192
7184
  body: { modeId }
7193
7185
  });
@@ -7197,7 +7189,7 @@ var AgentControllerSession = class extends BaseResource {
7197
7189
  * `thinkingLevel` is provided it is applied and persisted with the model.
7198
7190
  */
7199
7191
  async switchModel(modelId, { thinkingLevel } = {}) {
7200
- await this.request(this.url(`${this.base()}/model`), {
7192
+ await this.request(`${this.base()}/model`, {
7201
7193
  method: "POST",
7202
7194
  body: thinkingLevel !== void 0 ? {
7203
7195
  modelId,
@@ -7218,36 +7210,36 @@ var AgentControllerSession = class extends BaseResource {
7218
7210
  if (opts.limit != null) params.set("limit", String(opts.limit));
7219
7211
  if (opts.tags && Object.keys(opts.tags).length > 0) params.set("tags", JSON.stringify(opts.tags));
7220
7212
  const query = params.toString() ? `?${params.toString()}` : "";
7221
- return (await this.request(this.url(`${this.base()}/threads${query}`))).threads;
7213
+ return (await this.request(`${this.base()}/threads${query}`)).threads;
7222
7214
  }
7223
7215
  /** Switch the session to an existing thread (rebinds stream + state). */
7224
7216
  async switchThread(threadId) {
7225
- await this.request(this.url(`${this.base()}/thread`), {
7217
+ await this.request(`${this.base()}/thread`, {
7226
7218
  method: "POST",
7227
7219
  body: { threadId }
7228
7220
  });
7229
7221
  }
7230
7222
  /** Create a new thread (unbinds previous, binds the new one). */
7231
7223
  async createThread(title) {
7232
- return this.request(this.url(`${this.base()}/threads`), {
7224
+ return this.request(`${this.base()}/threads`, {
7233
7225
  method: "POST",
7234
7226
  body: { title }
7235
7227
  });
7236
7228
  }
7237
7229
  /** Delete a thread. If it's the active thread the session unbinds. */
7238
7230
  async deleteThread(threadId) {
7239
- await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), { method: "DELETE" });
7231
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, { method: "DELETE" });
7240
7232
  }
7241
7233
  /** Rename a thread. */
7242
7234
  async renameThread(threadId, title) {
7243
- await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), {
7235
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
7244
7236
  method: "PUT",
7245
7237
  body: { title }
7246
7238
  });
7247
7239
  }
7248
7240
  /** Clone a thread (and its messages). The session binds to the clone. */
7249
7241
  async cloneThread(options) {
7250
- return this.request(this.url(`${this.base()}/threads/clone`), {
7242
+ return this.request(`${this.base()}/threads/clone`, {
7251
7243
  method: "POST",
7252
7244
  body: options ?? {}
7253
7245
  });
@@ -7268,7 +7260,7 @@ var AgentControllerSession = class extends BaseResource {
7268
7260
  if (include) queryParams.set("include", JSON.stringify(include));
7269
7261
  }
7270
7262
  const query = queryParams.toString();
7271
- const body = await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}/messages${query ? `?${query}` : ""}`));
7263
+ const body = await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}/messages${query ? `?${query}` : ""}`);
7272
7264
  const messages = body.messages.map(hydrateMessage);
7273
7265
  if (legacy) return messages;
7274
7266
  return {
@@ -7287,7 +7279,7 @@ var AgentControllerSession = class extends BaseResource {
7287
7279
  files: void 0
7288
7280
  } : message;
7289
7281
  const requestContext = parseClientRequestContext(options?.requestContext);
7290
- await this.request(this.url(`${this.base()}/follow-up`), {
7282
+ await this.request(`${this.base()}/follow-up`, {
7291
7283
  method: "POST",
7292
7284
  body: {
7293
7285
  message: content,
@@ -7298,26 +7290,26 @@ var AgentControllerSession = class extends BaseResource {
7298
7290
  }
7299
7291
  /** Get the observational memory record for this session's thread. */
7300
7292
  async getOMRecord() {
7301
- return (await this.request(this.url(`${this.base()}/om`))).record;
7293
+ return (await this.request(`${this.base()}/om`)).record;
7302
7294
  }
7303
7295
  /** Change the session's resource identity. */
7304
7296
  async setResourceId(newResourceId) {
7305
- await this.request(this.url(`${this.base()}/resource`), {
7297
+ await this.request(`${this.base()}/resource`, {
7306
7298
  method: "POST",
7307
7299
  body: { newResourceId }
7308
7300
  });
7309
7301
  }
7310
7302
  /** Get known resource IDs for this session. */
7311
7303
  async getResourceIds() {
7312
- return (await this.request(this.url(`${this.base()}/resources`))).resourceIds;
7304
+ return (await this.request(`${this.base()}/resources`)).resourceIds;
7313
7305
  }
7314
7306
  /** Get the current goal for this session's thread. */
7315
7307
  async getGoal() {
7316
- return (await this.request(this.url(`${this.base()}/goal`))).goal;
7308
+ return (await this.request(`${this.base()}/goal`)).goal;
7317
7309
  }
7318
7310
  /** Set a new goal objective. The agent's in-loop judge evaluates progress after each turn. */
7319
7311
  async setGoal(objective, options) {
7320
- return (await this.request(this.url(`${this.base()}/goal`), {
7312
+ return (await this.request(`${this.base()}/goal`, {
7321
7313
  method: "POST",
7322
7314
  body: {
7323
7315
  objective,
@@ -7327,22 +7319,22 @@ var AgentControllerSession = class extends BaseResource {
7327
7319
  }
7328
7320
  /** Update goal options (judge model, max runs, status). */
7329
7321
  async updateGoal(options) {
7330
- return (await this.request(this.url(`${this.base()}/goal`), {
7322
+ return (await this.request(`${this.base()}/goal`, {
7331
7323
  method: "PUT",
7332
7324
  body: options
7333
7325
  })).goal;
7334
7326
  }
7335
7327
  /** Clear the current goal. */
7336
7328
  async clearGoal() {
7337
- await this.request(this.url(`${this.base()}/goal`), { method: "DELETE" });
7329
+ await this.request(`${this.base()}/goal`, { method: "DELETE" });
7338
7330
  }
7339
7331
  /** Get the current permission rules (per-category and per-tool policies). */
7340
7332
  async getPermissions() {
7341
- return this.request(this.url(`${this.base()}/permissions`));
7333
+ return this.request(`${this.base()}/permissions`);
7342
7334
  }
7343
7335
  /** Set the approval policy for a tool category. */
7344
7336
  async setPermissionForCategory(category, policy) {
7345
- await this.request(this.url(`${this.base()}/permissions/category`), {
7337
+ await this.request(`${this.base()}/permissions/category`, {
7346
7338
  method: "PUT",
7347
7339
  body: {
7348
7340
  category,
@@ -7352,7 +7344,7 @@ var AgentControllerSession = class extends BaseResource {
7352
7344
  }
7353
7345
  /** Set the approval policy for a specific tool. */
7354
7346
  async setPermissionForTool(toolName, policy) {
7355
- await this.request(this.url(`${this.base()}/permissions/tool`), {
7347
+ await this.request(`${this.base()}/permissions/tool`, {
7356
7348
  method: "PUT",
7357
7349
  body: {
7358
7350
  toolName,
@@ -7366,7 +7358,7 @@ var AgentControllerSession = class extends BaseResource {
7366
7358
  * or is persisted for later.
7367
7359
  */
7368
7360
  async sendNotification(input) {
7369
- return this.request(this.url(`${this.base()}/notifications`), {
7361
+ return this.request(`${this.base()}/notifications`, {
7370
7362
  method: "POST",
7371
7363
  body: input
7372
7364
  });
@@ -7399,12 +7391,11 @@ var AgentController = class extends BaseResource {
7399
7391
  return this.request(`${this.basePath()}/workspace`);
7400
7392
  }
7401
7393
  /**
7402
- * Scope to a session bound to `resourceId` (e.g. a user or conversation id).
7403
- * Pass `scope` to address an independent session over the same resourceId
7404
- * (e.g. one session per git worktree, with the worktree path as the scope).
7394
+ * Address the session with this `sessionId`. Sessions created without an
7395
+ * explicit id are addressed by their `resourceId`.
7405
7396
  */
7406
- session(resourceId, scope) {
7407
- return new AgentControllerSession(this.options, this.controllerId, resourceId, scope);
7397
+ session(sessionId) {
7398
+ return new AgentControllerSession(this.options, this.controllerId, sessionId);
7408
7399
  }
7409
7400
  };
7410
7401
  /** Pull the plain text out of an assistant message's nested content parts. */
@@ -7478,7 +7469,7 @@ var MastraClient = class extends BaseResource {
7478
7469
  }
7479
7470
  /**
7480
7471
  * Scopes to an agent controller hosted on the connected Mastra instance. Use
7481
- * `getAgentController(id).session(resourceId)` to create/resume a session,
7472
+ * `getAgentController(id).session(sessionId)` to create/resume a session,
7482
7473
  * stream its events, and send messages.
7483
7474
  * @param controllerId - The id the agent controller is registered under on Mastra
7484
7475
  */