@mastra/client-js 1.56.0-alpha.7 → 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/index.js CHANGED
@@ -6776,48 +6776,40 @@ function hydrateEventTimestamps(event) {
6776
6776
  return isKnownParsedEvent(event) ? hydrateKnownEvent(event) : event;
6777
6777
  }
6778
6778
  /**
6779
- * A session bound to a `resourceId` within one agent controller. Sessions are
6780
- * get-or-create on the server, so re-creating the same resourceId (and scope)
6781
- * resumes the existing conversation rather than forking it.
6782
- *
6783
- * Pass a `scope` to address an independent session over the same resourceId:
6784
- * two sessions with the same resourceId but different scopes have their own
6785
- * run loop, thread binding, and mode/model/state (e.g. one session per git
6786
- * worktree, with the worktree path as the scope). The scope travels on every
6787
- * request as a `sessionScope` query param.
6779
+ * A session addressed by its `sessionId` within one agent controller. Sessions
6780
+ * are get-or-create on the server, so re-creating the same sessionId resumes
6781
+ * the existing conversation rather than forking it. Many sessions can work on
6782
+ * one `resourceId` (whose threads and memory they use); each has its own run
6783
+ * loop, thread binding, and mode/model/state.
6788
6784
  */
6789
6785
  var AgentControllerSession = class extends BaseResource {
6790
6786
  controllerId;
6791
- resourceId;
6792
- scope;
6793
- constructor(options, controllerId, resourceId, scope) {
6787
+ sessionId;
6788
+ constructor(options, controllerId, sessionId) {
6794
6789
  super(options);
6795
6790
  this.controllerId = controllerId;
6796
- this.resourceId = resourceId;
6797
- this.scope = scope;
6791
+ this.sessionId = sessionId;
6798
6792
  }
6799
6793
  base() {
6800
- return `/agent-controller/${encodeURIComponent(this.controllerId)}/sessions/${encodeURIComponent(this.resourceId)}`;
6801
- }
6802
- /** Append this session's scope (if any) as a `sessionScope` query param. */
6803
- url(path) {
6804
- if (this.scope === void 0) return path;
6805
- return `${path}${path.includes("?") ? "&" : "?"}sessionScope=${encodeURIComponent(this.scope)}`;
6794
+ return `/agent-controller/${encodeURIComponent(this.controllerId)}/sessions/${encodeURIComponent(this.sessionId)}`;
6806
6795
  }
6807
6796
  /**
6808
- * Create or resume this session. Pass `tags` to scope initial thread
6809
- * selection — a thread is a resume candidate only when its metadata matches
6810
- * every tag. Pass `threadId` to bind the session to one exact thread,
6811
- * creating it with that id when it does not exist.
6797
+ * Create or resume this session. `resourceId` names whose threads and memory
6798
+ * the session works on. Without it the server resumes the session on the
6799
+ * resource it already has (the live session's, or the resource of the thread
6800
+ * with the session's id), falling back to the sessionId. Pass `tags` to scope
6801
+ * initial thread selection — a thread is a resume candidate only when its
6802
+ * metadata matches every tag. Pass `threadId` to bind the session to one
6803
+ * exact thread, creating it with that id when it does not exist.
6812
6804
  */
6813
6805
  create(options) {
6814
6806
  return this.request(`/agent-controller/${encodeURIComponent(this.controllerId)}/sessions`, {
6815
6807
  method: "POST",
6816
6808
  body: {
6817
- resourceId: this.resourceId,
6809
+ resourceId: options?.resourceId,
6810
+ sessionId: this.sessionId,
6818
6811
  tags: options?.tags,
6819
- threadId: options?.threadId,
6820
- sessionScope: this.scope
6812
+ threadId: options?.threadId
6821
6813
  }
6822
6814
  });
6823
6815
  }
@@ -6873,7 +6865,7 @@ var AgentControllerSession = class extends BaseResource {
6873
6865
  const abort = new AbortController();
6874
6866
  currentAbort = abort;
6875
6867
  let openTimer;
6876
- const request = this.request(this.url(`${this.base()}/stream`), {
6868
+ const request = this.request(`${this.base()}/stream`, {
6877
6869
  stream: true,
6878
6870
  signal: abort.signal
6879
6871
  });
@@ -7083,7 +7075,7 @@ var AgentControllerSession = class extends BaseResource {
7083
7075
  files: void 0
7084
7076
  } : message;
7085
7077
  const requestContext = parseClientRequestContext(options?.requestContext);
7086
- await this.request(this.url(`${this.base()}/messages`), {
7078
+ await this.request(`${this.base()}/messages`, {
7087
7079
  method: "POST",
7088
7080
  body: {
7089
7081
  message: content,
@@ -7094,7 +7086,7 @@ var AgentControllerSession = class extends BaseResource {
7094
7086
  }
7095
7087
  /** Abort the in-flight run for this session. */
7096
7088
  async abort() {
7097
- await this.request(this.url(`${this.base()}/abort`), { method: "POST" });
7089
+ await this.request(`${this.base()}/abort`, { method: "POST" });
7098
7090
  }
7099
7091
  /**
7100
7092
  * Approve or decline a pending tool call (`tool_approval_required`). Resolves
@@ -7102,7 +7094,7 @@ var AgentControllerSession = class extends BaseResource {
7102
7094
  */
7103
7095
  async approveTool(toolCallId, approved, options) {
7104
7096
  const requestContext = parseClientRequestContext(options?.requestContext);
7105
- return this.request(this.url(`${this.base()}/tool-approval`), {
7097
+ return this.request(`${this.base()}/tool-approval`, {
7106
7098
  method: "POST",
7107
7099
  retries: 0,
7108
7100
  body: {
@@ -7120,7 +7112,7 @@ var AgentControllerSession = class extends BaseResource {
7120
7112
  */
7121
7113
  async respondToToolSuspension(toolCallId, resumeData, options) {
7122
7114
  const requestContext = parseClientRequestContext(options?.requestContext);
7123
- return this.request(this.url(`${this.base()}/tool-suspension`), {
7115
+ return this.request(`${this.base()}/tool-suspension`, {
7124
7116
  method: "POST",
7125
7117
  retries: 0,
7126
7118
  body: {
@@ -7140,7 +7132,7 @@ var AgentControllerSession = class extends BaseResource {
7140
7132
  files: void 0
7141
7133
  } : message;
7142
7134
  const requestContext = parseClientRequestContext(options?.requestContext);
7143
- await this.request(this.url(`${this.base()}/steer`), {
7135
+ await this.request(`${this.base()}/steer`, {
7144
7136
  method: "POST",
7145
7137
  body: {
7146
7138
  message: content,
@@ -7152,18 +7144,18 @@ var AgentControllerSession = class extends BaseResource {
7152
7144
  /** Get the current mode, model, and thread (for initial UI hydration). */
7153
7145
  state(options) {
7154
7146
  const path = options?.threadId ? `${this.base()}?threadId=${encodeURIComponent(options.threadId)}` : this.base();
7155
- return this.request(this.url(path));
7147
+ return this.request(path);
7156
7148
  }
7157
7149
  /** Merge key-value pairs into the session state. Existing keys not in the payload are preserved. */
7158
7150
  async setState(updates) {
7159
- await this.request(this.url(`${this.base()}/state`), {
7151
+ await this.request(`${this.base()}/state`, {
7160
7152
  method: "PUT",
7161
7153
  body: { state: updates }
7162
7154
  });
7163
7155
  }
7164
7156
  /** Switch the active mode (e.g. `build`, `plan`). */
7165
7157
  async switchMode(modeId) {
7166
- await this.request(this.url(`${this.base()}/mode`), {
7158
+ await this.request(`${this.base()}/mode`, {
7167
7159
  method: "POST",
7168
7160
  body: { modeId }
7169
7161
  });
@@ -7173,7 +7165,7 @@ var AgentControllerSession = class extends BaseResource {
7173
7165
  * `thinkingLevel` is provided it is applied and persisted with the model.
7174
7166
  */
7175
7167
  async switchModel(modelId, { thinkingLevel } = {}) {
7176
- await this.request(this.url(`${this.base()}/model`), {
7168
+ await this.request(`${this.base()}/model`, {
7177
7169
  method: "POST",
7178
7170
  body: thinkingLevel !== void 0 ? {
7179
7171
  modelId,
@@ -7194,36 +7186,36 @@ var AgentControllerSession = class extends BaseResource {
7194
7186
  if (opts.limit != null) params.set("limit", String(opts.limit));
7195
7187
  if (opts.tags && Object.keys(opts.tags).length > 0) params.set("tags", JSON.stringify(opts.tags));
7196
7188
  const query = params.toString() ? `?${params.toString()}` : "";
7197
- return (await this.request(this.url(`${this.base()}/threads${query}`))).threads;
7189
+ return (await this.request(`${this.base()}/threads${query}`)).threads;
7198
7190
  }
7199
7191
  /** Switch the session to an existing thread (rebinds stream + state). */
7200
7192
  async switchThread(threadId) {
7201
- await this.request(this.url(`${this.base()}/thread`), {
7193
+ await this.request(`${this.base()}/thread`, {
7202
7194
  method: "POST",
7203
7195
  body: { threadId }
7204
7196
  });
7205
7197
  }
7206
7198
  /** Create a new thread (unbinds previous, binds the new one). */
7207
7199
  async createThread(title) {
7208
- return this.request(this.url(`${this.base()}/threads`), {
7200
+ return this.request(`${this.base()}/threads`, {
7209
7201
  method: "POST",
7210
7202
  body: { title }
7211
7203
  });
7212
7204
  }
7213
7205
  /** Delete a thread. If it's the active thread the session unbinds. */
7214
7206
  async deleteThread(threadId) {
7215
- await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), { method: "DELETE" });
7207
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, { method: "DELETE" });
7216
7208
  }
7217
7209
  /** Rename a thread. */
7218
7210
  async renameThread(threadId, title) {
7219
- await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), {
7211
+ await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
7220
7212
  method: "PUT",
7221
7213
  body: { title }
7222
7214
  });
7223
7215
  }
7224
7216
  /** Clone a thread (and its messages). The session binds to the clone. */
7225
7217
  async cloneThread(options) {
7226
- return this.request(this.url(`${this.base()}/threads/clone`), {
7218
+ return this.request(`${this.base()}/threads/clone`, {
7227
7219
  method: "POST",
7228
7220
  body: options ?? {}
7229
7221
  });
@@ -7244,7 +7236,7 @@ var AgentControllerSession = class extends BaseResource {
7244
7236
  if (include) queryParams.set("include", JSON.stringify(include));
7245
7237
  }
7246
7238
  const query = queryParams.toString();
7247
- const body = await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}/messages${query ? `?${query}` : ""}`));
7239
+ const body = await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}/messages${query ? `?${query}` : ""}`);
7248
7240
  const messages = body.messages.map(hydrateMessage);
7249
7241
  if (legacy) return messages;
7250
7242
  return {
@@ -7263,7 +7255,7 @@ var AgentControllerSession = class extends BaseResource {
7263
7255
  files: void 0
7264
7256
  } : message;
7265
7257
  const requestContext = parseClientRequestContext(options?.requestContext);
7266
- await this.request(this.url(`${this.base()}/follow-up`), {
7258
+ await this.request(`${this.base()}/follow-up`, {
7267
7259
  method: "POST",
7268
7260
  body: {
7269
7261
  message: content,
@@ -7274,26 +7266,26 @@ var AgentControllerSession = class extends BaseResource {
7274
7266
  }
7275
7267
  /** Get the observational memory record for this session's thread. */
7276
7268
  async getOMRecord() {
7277
- return (await this.request(this.url(`${this.base()}/om`))).record;
7269
+ return (await this.request(`${this.base()}/om`)).record;
7278
7270
  }
7279
7271
  /** Change the session's resource identity. */
7280
7272
  async setResourceId(newResourceId) {
7281
- await this.request(this.url(`${this.base()}/resource`), {
7273
+ await this.request(`${this.base()}/resource`, {
7282
7274
  method: "POST",
7283
7275
  body: { newResourceId }
7284
7276
  });
7285
7277
  }
7286
7278
  /** Get known resource IDs for this session. */
7287
7279
  async getResourceIds() {
7288
- return (await this.request(this.url(`${this.base()}/resources`))).resourceIds;
7280
+ return (await this.request(`${this.base()}/resources`)).resourceIds;
7289
7281
  }
7290
7282
  /** Get the current goal for this session's thread. */
7291
7283
  async getGoal() {
7292
- return (await this.request(this.url(`${this.base()}/goal`))).goal;
7284
+ return (await this.request(`${this.base()}/goal`)).goal;
7293
7285
  }
7294
7286
  /** Set a new goal objective. The agent's in-loop judge evaluates progress after each turn. */
7295
7287
  async setGoal(objective, options) {
7296
- return (await this.request(this.url(`${this.base()}/goal`), {
7288
+ return (await this.request(`${this.base()}/goal`, {
7297
7289
  method: "POST",
7298
7290
  body: {
7299
7291
  objective,
@@ -7303,22 +7295,22 @@ var AgentControllerSession = class extends BaseResource {
7303
7295
  }
7304
7296
  /** Update goal options (judge model, max runs, status). */
7305
7297
  async updateGoal(options) {
7306
- return (await this.request(this.url(`${this.base()}/goal`), {
7298
+ return (await this.request(`${this.base()}/goal`, {
7307
7299
  method: "PUT",
7308
7300
  body: options
7309
7301
  })).goal;
7310
7302
  }
7311
7303
  /** Clear the current goal. */
7312
7304
  async clearGoal() {
7313
- await this.request(this.url(`${this.base()}/goal`), { method: "DELETE" });
7305
+ await this.request(`${this.base()}/goal`, { method: "DELETE" });
7314
7306
  }
7315
7307
  /** Get the current permission rules (per-category and per-tool policies). */
7316
7308
  async getPermissions() {
7317
- return this.request(this.url(`${this.base()}/permissions`));
7309
+ return this.request(`${this.base()}/permissions`);
7318
7310
  }
7319
7311
  /** Set the approval policy for a tool category. */
7320
7312
  async setPermissionForCategory(category, policy) {
7321
- await this.request(this.url(`${this.base()}/permissions/category`), {
7313
+ await this.request(`${this.base()}/permissions/category`, {
7322
7314
  method: "PUT",
7323
7315
  body: {
7324
7316
  category,
@@ -7328,7 +7320,7 @@ var AgentControllerSession = class extends BaseResource {
7328
7320
  }
7329
7321
  /** Set the approval policy for a specific tool. */
7330
7322
  async setPermissionForTool(toolName, policy) {
7331
- await this.request(this.url(`${this.base()}/permissions/tool`), {
7323
+ await this.request(`${this.base()}/permissions/tool`, {
7332
7324
  method: "PUT",
7333
7325
  body: {
7334
7326
  toolName,
@@ -7342,7 +7334,7 @@ var AgentControllerSession = class extends BaseResource {
7342
7334
  * or is persisted for later.
7343
7335
  */
7344
7336
  async sendNotification(input) {
7345
- return this.request(this.url(`${this.base()}/notifications`), {
7337
+ return this.request(`${this.base()}/notifications`, {
7346
7338
  method: "POST",
7347
7339
  body: input
7348
7340
  });
@@ -7375,12 +7367,11 @@ var AgentController = class extends BaseResource {
7375
7367
  return this.request(`${this.basePath()}/workspace`);
7376
7368
  }
7377
7369
  /**
7378
- * Scope to a session bound to `resourceId` (e.g. a user or conversation id).
7379
- * Pass `scope` to address an independent session over the same resourceId
7380
- * (e.g. one session per git worktree, with the worktree path as the scope).
7370
+ * Address the session with this `sessionId`. Sessions created without an
7371
+ * explicit id are addressed by their `resourceId`.
7381
7372
  */
7382
- session(resourceId, scope) {
7383
- return new AgentControllerSession(this.options, this.controllerId, resourceId, scope);
7373
+ session(sessionId) {
7374
+ return new AgentControllerSession(this.options, this.controllerId, sessionId);
7384
7375
  }
7385
7376
  };
7386
7377
  /** Pull the plain text out of an assistant message's nested content parts. */
@@ -7454,7 +7445,7 @@ var MastraClient = class extends BaseResource {
7454
7445
  }
7455
7446
  /**
7456
7447
  * Scopes to an agent controller hosted on the connected Mastra instance. Use
7457
- * `getAgentController(id).session(resourceId)` to create/resume a session,
7448
+ * `getAgentController(id).session(sessionId)` to create/resume a session,
7458
7449
  * stream its events, and send messages.
7459
7450
  * @param controllerId - The id the agent controller is registered under on Mastra
7460
7451
  */