@mastra/client-js 1.18.0-alpha.12 → 1.18.0-alpha.13

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
@@ -130,11 +130,15 @@ function processClientTools(clientTools) {
130
130
  // src/utils/process-mastra-stream.ts
131
131
  async function sharedProcessMastraStream({
132
132
  stream,
133
- onChunk
133
+ onChunk,
134
+ signal
134
135
  }) {
135
136
  const reader = stream.getReader();
136
137
  const decoder = new TextDecoder();
137
138
  let buffer = "";
139
+ const abort = () => void reader.cancel();
140
+ if (signal?.aborted) abort();
141
+ else signal?.addEventListener("abort", abort, { once: true });
138
142
  try {
139
143
  while (true) {
140
144
  const { done, value } = await reader.read();
@@ -162,25 +166,30 @@ async function sharedProcessMastraStream({
162
166
  }
163
167
  }
164
168
  } finally {
169
+ signal?.removeEventListener("abort", abort);
165
170
  reader.releaseLock();
166
171
  }
167
172
  }
168
173
  async function processMastraNetworkStream({
169
174
  stream,
170
- onChunk
175
+ onChunk,
176
+ signal
171
177
  }) {
172
178
  return sharedProcessMastraStream({
173
179
  stream,
174
- onChunk
180
+ onChunk,
181
+ signal
175
182
  });
176
183
  }
177
184
  async function processMastraStream({
178
185
  stream,
179
- onChunk
186
+ onChunk,
187
+ signal
180
188
  }) {
181
189
  return sharedProcessMastraStream({
182
190
  stream,
183
- onChunk
191
+ onChunk,
192
+ signal
184
193
  });
185
194
  }
186
195
 
@@ -441,6 +450,38 @@ var Agent = class extends BaseResource {
441
450
  body: { instructions, comment }
442
451
  });
443
452
  }
453
+ /**
454
+ * @experimental Agent signals are experimental and may change in a future release.
455
+ */
456
+ sendSignal(params) {
457
+ return this.request(`/agents/${this.agentId}/signals`, {
458
+ method: "POST",
459
+ body: params
460
+ });
461
+ }
462
+ /**
463
+ * @experimental Agent signals are experimental and may change in a future release.
464
+ */
465
+ async subscribeToThread(params) {
466
+ const streamResponse = await this.request(`/agents/${this.agentId}/threads/subscribe`, {
467
+ method: "POST",
468
+ body: params,
469
+ stream: true
470
+ });
471
+ if (!streamResponse.body) {
472
+ throw new Error("No response body");
473
+ }
474
+ streamResponse.processDataStream = async ({
475
+ onChunk
476
+ }) => {
477
+ await processMastraStream({
478
+ stream: streamResponse.body,
479
+ onChunk,
480
+ signal: this.options.abortSignal
481
+ });
482
+ };
483
+ return streamResponse;
484
+ }
444
485
  /**
445
486
  * Clones this agent to a new stored agent in the database
446
487
  * @param params - Clone parameters including optional newId, newName, metadata, authorId, and requestContext
@@ -3418,13 +3459,14 @@ var AgentBuilder = class extends BaseResource {
3418
3459
  * This calls `/agent-builder/:actionId/stream`.
3419
3460
  */
3420
3461
  async stream(params, runId) {
3421
- const searchParams = new URLSearchParams();
3422
- if (runId) {
3423
- searchParams.set("runId", runId);
3462
+ if (!runId) {
3463
+ throw new Error("runId is required to stream an agent builder action");
3424
3464
  }
3465
+ const searchParams = new URLSearchParams();
3466
+ searchParams.set("runId", runId);
3425
3467
  const requestContext = parseClientRequestContext(params.requestContext);
3426
3468
  const { requestContext: _, ...actionParams } = params;
3427
- const url = `/agent-builder/${this.actionId}/stream${searchParams.toString() ? `?${searchParams.toString()}` : ""}`;
3469
+ const url = `/agent-builder/${this.actionId}/stream?${searchParams.toString()}`;
3428
3470
  const response = await this.request(url, {
3429
3471
  method: "POST",
3430
3472
  body: { ...actionParams, requestContext },
@@ -5285,7 +5327,7 @@ var MastraClient = class extends BaseResource {
5285
5327
  * @returns Promise containing map of action IDs to action details
5286
5328
  */
5287
5329
  getAgentBuilderActions() {
5288
- return this.request("/agent-builder/");
5330
+ return this.request("/agent-builder");
5289
5331
  }
5290
5332
  /**
5291
5333
  * Gets an agent builder instance for executing agent-builder workflows