@mastra/client-js 1.14.2 → 1.15.0-alpha.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 1.15.0-alpha.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added support for resuming suspended agent streams over HTTP with custom data. This adds the `POST /agents/:agentId/resume-stream` server endpoint and the client SDK `agent.resumeStream()` method, so apps can continue a suspended agent run through the Mastra client. ([#14579](https://github.com/mastra-ai/mastra/pull/14579))
8
+
9
+ **Usage example (client SDK):**
10
+
11
+ ```typescript
12
+ const agent = mastraClient.getAgent('my-agent');
13
+
14
+ // Resume a suspended agent stream with custom data
15
+ const response = await agent.resumeStream(
16
+ { approved: true, selectedOption: 'plan-b' },
17
+ { runId: 'previous-run-id', toolCallId: 'tool-123' },
18
+ );
19
+
20
+ await response.processDataStream({
21
+ onChunk: chunk => console.log(chunk),
22
+ });
23
+ ```
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [[`b510d36`](https://github.com/mastra-ai/mastra/commit/b510d368f73dab6be2e2c2bc99035aaef1fb7d7a)]:
28
+ - @mastra/core@1.29.0-alpha.0
29
+
3
30
  ## 1.14.2
4
31
 
5
32
  ### Patch Changes
@@ -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.14.2"
6
+ version: "1.15.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.14.2",
2
+ "version": "1.15.0-alpha.0",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {
5
5
  "RequestContext": {
@@ -217,6 +217,26 @@ response.processDataStream({
217
217
  })
218
218
  ```
219
219
 
220
+ ### `resumeStream()`
221
+
222
+ Resume a suspended agent stream with custom data. Use this to continue execution after a suspension point, such as a workflow suspend within an agent:
223
+
224
+ ```typescript
225
+ const response = await agent.resumeStream(
226
+ { approved: true, selectedOption: 'plan-b' },
227
+ {
228
+ runId: 'run-123',
229
+ toolCallId: 'tool-call-456', // optional
230
+ },
231
+ )
232
+
233
+ await response.processDataStream({
234
+ onChunk: chunk => {
235
+ console.log(chunk)
236
+ },
237
+ })
238
+ ```
239
+
220
240
  ### `approveToolCallGenerate()`
221
241
 
222
242
  Approve a pending tool call when using `generate()` (non-streaming). Returns the complete response:
package/dist/index.cjs CHANGED
@@ -1210,9 +1210,14 @@ var Agent = class extends BaseResource {
1210
1210
  const { resource, thread } = memory ?? {};
1211
1211
  const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
1212
1212
  const resourceId = processedParams.resourceId ?? resource;
1213
+ let requestBody = processedParams;
1214
+ if (route === "resume-stream") {
1215
+ const { messages: _messages, ...resumeStreamBody } = processedParams;
1216
+ requestBody = resumeStreamBody;
1217
+ }
1213
1218
  const response = await this.request(`/agents/${this.agentId}/${route}`, {
1214
1219
  method: "POST",
1215
- body: processedParams,
1220
+ body: requestBody,
1216
1221
  stream: true
1217
1222
  });
1218
1223
  if (!response.body) {
@@ -1511,6 +1516,43 @@ var Agent = class extends BaseResource {
1511
1516
  };
1512
1517
  return streamResponse;
1513
1518
  }
1519
+ /**
1520
+ * Resumes a suspended agent stream with custom resume data.
1521
+ * Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
1522
+ */
1523
+ async resumeStream(resumeData, options) {
1524
+ const processedParams = {
1525
+ ...options,
1526
+ resumeData,
1527
+ requestContext: parseClientRequestContext(options.requestContext),
1528
+ clientTools: processClientTools(options.clientTools),
1529
+ structuredOutput: options.structuredOutput ? {
1530
+ ...options.structuredOutput,
1531
+ schema: schema.standardSchemaToJSONSchema(schema.toStandardSchema(options.structuredOutput.schema))
1532
+ } : void 0
1533
+ };
1534
+ let readableController;
1535
+ const readable = new ReadableStream({
1536
+ start(controller) {
1537
+ readableController = controller;
1538
+ }
1539
+ });
1540
+ const response = await this.processStreamResponse(processedParams, readableController, "resume-stream");
1541
+ const streamResponse = new Response(readable, {
1542
+ status: response.status,
1543
+ statusText: response.statusText,
1544
+ headers: response.headers
1545
+ });
1546
+ streamResponse.processDataStream = async ({
1547
+ onChunk
1548
+ }) => {
1549
+ await processMastraStream({
1550
+ stream: streamResponse.body,
1551
+ onChunk
1552
+ });
1553
+ };
1554
+ return streamResponse;
1555
+ }
1514
1556
  /**
1515
1557
  * Approves a pending tool call and returns the complete response (non-streaming).
1516
1558
  * Used when `requireToolApproval` is enabled with generate() to allow the agent to proceed.