@mastra/client-js 1.31.2-alpha.5 → 1.32.0-alpha.10

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
@@ -2503,6 +2503,38 @@ var Agent = class extends BaseResource {
2503
2503
  };
2504
2504
  return streamResponse;
2505
2505
  }
2506
+ /**
2507
+ * Re-drives an orphaned RUNNING durable-agent run after a process restart.
2508
+ *
2509
+ * Only supported when the target agent is a durable agent (createDurableAgent).
2510
+ * The server rebuilds the runtime state from the persisted snapshot, replays
2511
+ * past chunks, and continues the loop to completion.
2512
+ */
2513
+ async recover(params) {
2514
+ const body = {
2515
+ runId: params.runId,
2516
+ requestContext: parseClientRequestContext(params.requestContext),
2517
+ versions: params.versions
2518
+ };
2519
+ const response = await this.request(`/agents/${this.agentId}/recover`, {
2520
+ method: "POST",
2521
+ body,
2522
+ stream: true
2523
+ });
2524
+ if (!response.body) {
2525
+ throw new Error("No response body");
2526
+ }
2527
+ const streamResponse = response;
2528
+ streamResponse.processDataStream = async ({
2529
+ onChunk
2530
+ }) => {
2531
+ await processMastraStream({
2532
+ stream: streamResponse.body,
2533
+ onChunk
2534
+ });
2535
+ };
2536
+ return streamResponse;
2537
+ }
2506
2538
  /**
2507
2539
  * @deprecated Use `resumeStream(resumeData, { untilIdle: true, ... })` instead.
2508
2540
  *
@@ -6108,16 +6140,24 @@ var Channels = class extends BaseResource {
6108
6140
 
6109
6141
  // src/resources/agent-controller.ts
6110
6142
  var AgentControllerSession = class extends BaseResource {
6111
- constructor(options, controllerId, resourceId) {
6143
+ constructor(options, controllerId, resourceId, scope) {
6112
6144
  super(options);
6113
6145
  this.controllerId = controllerId;
6114
6146
  this.resourceId = resourceId;
6147
+ this.scope = scope;
6115
6148
  }
6116
6149
  controllerId;
6117
6150
  resourceId;
6151
+ scope;
6118
6152
  base() {
6119
6153
  return `/agent-controller/${encodeURIComponent(this.controllerId)}/sessions/${encodeURIComponent(this.resourceId)}`;
6120
6154
  }
6155
+ /** Append this session's scope (if any) as a `sessionScope` query param. */
6156
+ url(path) {
6157
+ if (this.scope === void 0) return path;
6158
+ const sep = path.includes("?") ? "&" : "?";
6159
+ return `${path}${sep}sessionScope=${encodeURIComponent(this.scope)}`;
6160
+ }
6121
6161
  /**
6122
6162
  * Create or resume this session. Pass `tags` to scope initial thread
6123
6163
  * selection — a thread is a resume candidate only when its metadata matches
@@ -6128,7 +6168,7 @@ var AgentControllerSession = class extends BaseResource {
6128
6168
  create(options) {
6129
6169
  return this.request(`/agent-controller/${encodeURIComponent(this.controllerId)}/sessions`, {
6130
6170
  method: "POST",
6131
- body: { resourceId: this.resourceId, tags: options?.tags }
6171
+ body: { resourceId: this.resourceId, tags: options?.tags, sessionScope: this.scope }
6132
6172
  });
6133
6173
  }
6134
6174
  /**
@@ -6136,7 +6176,7 @@ var AgentControllerSession = class extends BaseResource {
6136
6176
  * message arrives here as `message_*` events, not on the sendMessage call.
6137
6177
  */
6138
6178
  async subscribe(options) {
6139
- const response = await this.request(`${this.base()}/stream`, { stream: true });
6179
+ const response = await this.request(this.url(`${this.base()}/stream`), { stream: true });
6140
6180
  if (!response.body) {
6141
6181
  throw new Error("No response body for agent controller session stream");
6142
6182
  }
@@ -6178,17 +6218,25 @@ var AgentControllerSession = class extends BaseResource {
6178
6218
  }
6179
6219
  };
6180
6220
  }
6181
- /** Send a user message. The reply streams over `subscribe()`. */
6221
+ /**
6222
+ * Send a user message. The reply streams over `subscribe()`.
6223
+ * Pass a structured message to attach files (e.g. pasted images) as base64-encoded data:
6224
+ * `sendMessage({ content: 'What is in this image?', files })`.
6225
+ */
6182
6226
  async sendMessage(message) {
6183
- await this.request(`${this.base()}/messages`, { method: "POST", body: { message } });
6227
+ const { content, files } = typeof message === "string" ? { content: message, files: void 0 } : message;
6228
+ await this.request(this.url(`${this.base()}/messages`), {
6229
+ method: "POST",
6230
+ body: { message: content, ...files?.length ? { files } : {} }
6231
+ });
6184
6232
  }
6185
6233
  /** Abort the in-flight run for this session. */
6186
6234
  async abort() {
6187
- await this.request(`${this.base()}/abort`, { method: "POST" });
6235
+ await this.request(this.url(`${this.base()}/abort`), { method: "POST" });
6188
6236
  }
6189
6237
  /** Approve or decline a pending tool call (`tool_approval_required`). */
6190
6238
  async approveTool(toolCallId, approved) {
6191
- await this.request(`${this.base()}/tool-approval`, {
6239
+ await this.request(this.url(`${this.base()}/tool-approval`), {
6192
6240
  method: "POST",
6193
6241
  body: { toolCallId, approved }
6194
6242
  });
@@ -6199,35 +6247,34 @@ var AgentControllerSession = class extends BaseResource {
6199
6247
  * `request_access`, and a {@link PlanResume} for `submit_plan`.
6200
6248
  */
6201
6249
  async respondToToolSuspension(toolCallId, resumeData) {
6202
- await this.request(`${this.base()}/tool-suspension`, {
6250
+ await this.request(this.url(`${this.base()}/tool-suspension`), {
6203
6251
  method: "POST",
6204
6252
  body: { toolCallId, resumeData }
6205
6253
  });
6206
6254
  }
6207
6255
  /** Inject a message into the in-flight run without starting a new turn. */
6208
6256
  async steer(message) {
6209
- await this.request(`${this.base()}/steer`, { method: "POST", body: { message } });
6257
+ await this.request(this.url(`${this.base()}/steer`), { method: "POST", body: { message } });
6210
6258
  }
6211
6259
  /** Get the current mode, model, and thread (for initial UI hydration). */
6212
6260
  state() {
6213
- return this.request(this.base());
6261
+ return this.request(this.url(this.base()));
6214
6262
  }
6215
6263
  /** Merge key-value pairs into the session state. Existing keys not in the payload are preserved. */
6216
6264
  async setState(updates) {
6217
- await this.request(`${this.base()}/state`, { method: "PUT", body: { state: updates } });
6265
+ await this.request(this.url(`${this.base()}/state`), { method: "PUT", body: { state: updates } });
6218
6266
  }
6219
6267
  /** Switch the active mode (e.g. `build`, `plan`). */
6220
6268
  async switchMode(modeId) {
6221
- await this.request(`${this.base()}/mode`, { method: "POST", body: { modeId } });
6269
+ await this.request(this.url(`${this.base()}/mode`), { method: "POST", body: { modeId } });
6222
6270
  }
6223
6271
  /** Switch the model. Defaults to thread scope. */
6224
6272
  async switchModel(modelId, options) {
6225
- await this.request(`${this.base()}/model`, {
6273
+ await this.request(this.url(`${this.base()}/model`), {
6226
6274
  method: "POST",
6227
6275
  body: { modelId, scope: options?.scope, modeId: options?.modeId }
6228
6276
  });
6229
6277
  }
6230
- /** List the threads for this session's resource, most-recently-updated first. Pass `limit` for just the newest N. */
6231
6278
  /**
6232
6279
  * List the session's threads, newest first. Pass `limit` to cap the count
6233
6280
  * (e.g. for a sidebar) and `tags` to scope to threads matching every tag —
@@ -6241,36 +6288,38 @@ var AgentControllerSession = class extends BaseResource {
6241
6288
  if (opts.limit != null) params.set("limit", String(opts.limit));
6242
6289
  if (opts.tags && Object.keys(opts.tags).length > 0) params.set("tags", JSON.stringify(opts.tags));
6243
6290
  const query = params.toString() ? `?${params.toString()}` : "";
6244
- const body = await this.request(`${this.base()}/threads${query}`);
6291
+ const body = await this.request(
6292
+ this.url(`${this.base()}/threads${query}`)
6293
+ );
6245
6294
  return body.threads;
6246
6295
  }
6247
6296
  /** Switch the session to an existing thread (rebinds stream + state). */
6248
6297
  async switchThread(threadId) {
6249
- await this.request(`${this.base()}/thread`, { method: "POST", body: { threadId } });
6298
+ await this.request(this.url(`${this.base()}/thread`), { method: "POST", body: { threadId } });
6250
6299
  }
6251
6300
  /** Create a new thread (unbinds previous, binds the new one). */
6252
6301
  async createThread(title) {
6253
- return this.request(`${this.base()}/threads`, {
6302
+ return this.request(this.url(`${this.base()}/threads`), {
6254
6303
  method: "POST",
6255
6304
  body: { title }
6256
6305
  });
6257
6306
  }
6258
6307
  /** Delete a thread. If it's the active thread the session unbinds. */
6259
6308
  async deleteThread(threadId) {
6260
- await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
6309
+ await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), {
6261
6310
  method: "DELETE"
6262
6311
  });
6263
6312
  }
6264
6313
  /** Rename a thread. */
6265
6314
  async renameThread(threadId, title) {
6266
- await this.request(`${this.base()}/threads/${encodeURIComponent(threadId)}`, {
6315
+ await this.request(this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}`), {
6267
6316
  method: "PUT",
6268
6317
  body: { title }
6269
6318
  });
6270
6319
  }
6271
6320
  /** Clone a thread (and its messages). The session binds to the clone. */
6272
6321
  async cloneThread(options) {
6273
- return this.request(`${this.base()}/threads/clone`, {
6322
+ return this.request(this.url(`${this.base()}/threads/clone`), {
6274
6323
  method: "POST",
6275
6324
  body: options ?? {}
6276
6325
  });
@@ -6279,7 +6328,7 @@ var AgentControllerSession = class extends BaseResource {
6279
6328
  async listMessages(threadId, limit) {
6280
6329
  const params = limit != null ? `?limit=${limit}` : "";
6281
6330
  const body = await this.request(
6282
- `${this.base()}/threads/${encodeURIComponent(threadId)}/messages${params}`
6331
+ this.url(`${this.base()}/threads/${encodeURIComponent(threadId)}/messages${params}`)
6283
6332
  );
6284
6333
  return body.messages;
6285
6334
  }
@@ -6288,33 +6337,33 @@ var AgentControllerSession = class extends BaseResource {
6288
6337
  * if a run is active it queues for after completion.
6289
6338
  */
6290
6339
  async followUp(message) {
6291
- await this.request(`${this.base()}/follow-up`, { method: "POST", body: { message } });
6340
+ await this.request(this.url(`${this.base()}/follow-up`), { method: "POST", body: { message } });
6292
6341
  }
6293
6342
  /** Get the observational memory record for this session's thread. */
6294
6343
  async getOMRecord() {
6295
- const body = await this.request(`${this.base()}/om`);
6344
+ const body = await this.request(this.url(`${this.base()}/om`));
6296
6345
  return body.record;
6297
6346
  }
6298
6347
  /** Change the session's resource identity. */
6299
6348
  async setResourceId(newResourceId) {
6300
- await this.request(`${this.base()}/resource`, {
6349
+ await this.request(this.url(`${this.base()}/resource`), {
6301
6350
  method: "POST",
6302
6351
  body: { newResourceId }
6303
6352
  });
6304
6353
  }
6305
6354
  /** Get known resource IDs for this session. */
6306
6355
  async getResourceIds() {
6307
- const body = await this.request(`${this.base()}/resources`);
6356
+ const body = await this.request(this.url(`${this.base()}/resources`));
6308
6357
  return body.resourceIds;
6309
6358
  }
6310
6359
  /** Get the current goal for this session's thread. */
6311
6360
  async getGoal() {
6312
- const body = await this.request(`${this.base()}/goal`);
6361
+ const body = await this.request(this.url(`${this.base()}/goal`));
6313
6362
  return body.goal;
6314
6363
  }
6315
6364
  /** Set a new goal objective. The agent's in-loop judge evaluates progress after each turn. */
6316
6365
  async setGoal(objective, options) {
6317
- const body = await this.request(`${this.base()}/goal`, {
6366
+ const body = await this.request(this.url(`${this.base()}/goal`), {
6318
6367
  method: "POST",
6319
6368
  body: { objective, ...options }
6320
6369
  });
@@ -6322,7 +6371,7 @@ var AgentControllerSession = class extends BaseResource {
6322
6371
  }
6323
6372
  /** Update goal options (judge model, max runs, status). */
6324
6373
  async updateGoal(options) {
6325
- const body = await this.request(`${this.base()}/goal`, {
6374
+ const body = await this.request(this.url(`${this.base()}/goal`), {
6326
6375
  method: "PUT",
6327
6376
  body: options
6328
6377
  });
@@ -6330,25 +6379,25 @@ var AgentControllerSession = class extends BaseResource {
6330
6379
  }
6331
6380
  /** Clear the current goal. */
6332
6381
  async clearGoal() {
6333
- await this.request(`${this.base()}/goal`, { method: "DELETE" });
6382
+ await this.request(this.url(`${this.base()}/goal`), { method: "DELETE" });
6334
6383
  }
6335
6384
  // ---------------------------------------------------------------------------
6336
6385
  // Permissions
6337
6386
  // ---------------------------------------------------------------------------
6338
6387
  /** Get the current permission rules (per-category and per-tool policies). */
6339
6388
  async getPermissions() {
6340
- return this.request(`${this.base()}/permissions`);
6389
+ return this.request(this.url(`${this.base()}/permissions`));
6341
6390
  }
6342
6391
  /** Set the approval policy for a tool category. */
6343
6392
  async setPermissionForCategory(category, policy) {
6344
- await this.request(`${this.base()}/permissions/category`, {
6393
+ await this.request(this.url(`${this.base()}/permissions/category`), {
6345
6394
  method: "PUT",
6346
6395
  body: { category, policy }
6347
6396
  });
6348
6397
  }
6349
6398
  /** Set the approval policy for a specific tool. */
6350
6399
  async setPermissionForTool(toolName, policy) {
6351
- await this.request(`${this.base()}/permissions/tool`, {
6400
+ await this.request(this.url(`${this.base()}/permissions/tool`), {
6352
6401
  method: "PUT",
6353
6402
  body: { toolName, policy }
6354
6403
  });
@@ -6359,7 +6408,7 @@ var AgentControllerSession = class extends BaseResource {
6359
6408
  * or is persisted for later.
6360
6409
  */
6361
6410
  async sendNotification(input) {
6362
- return this.request(`${this.base()}/notifications`, {
6411
+ return this.request(this.url(`${this.base()}/notifications`), {
6363
6412
  method: "POST",
6364
6413
  body: input
6365
6414
  });
@@ -6388,9 +6437,13 @@ var AgentController = class extends BaseResource {
6388
6437
  async workspaceStatus() {
6389
6438
  return this.request(`${this.basePath()}/workspace`);
6390
6439
  }
6391
- /** Scope to a session bound to `resourceId` (e.g. a user or conversation id). */
6392
- session(resourceId) {
6393
- return new AgentControllerSession(this.options, this.controllerId, resourceId);
6440
+ /**
6441
+ * Scope to a session bound to `resourceId` (e.g. a user or conversation id).
6442
+ * Pass `scope` to address an independent session over the same resourceId
6443
+ * (e.g. one session per git worktree, with the worktree path as the scope).
6444
+ */
6445
+ session(resourceId, scope) {
6446
+ return new AgentControllerSession(this.options, this.controllerId, resourceId, scope);
6394
6447
  }
6395
6448
  };
6396
6449
  function agentControllerMessageText(message) {