@mastra/client-js 0.0.0-studio-deploy-20260404182525 → 0.0.0-studio-cli-20260504022012

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.
Files changed (42) hide show
  1. package/CHANGELOG.md +917 -3
  2. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +466 -1764
  3. package/dist/client.d.ts +46 -3
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/docs/SKILL.md +3 -1
  6. package/dist/docs/assets/SOURCE_MAP.json +7 -2
  7. package/dist/docs/references/docs-editor-overview.md +290 -0
  8. package/dist/docs/references/docs-server-mastra-client.md +2 -2
  9. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-messages.md +95 -0
  10. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-stream.md +15 -0
  11. package/dist/docs/references/reference-client-js-agents.md +166 -0
  12. package/dist/docs/references/reference-client-js-conversations.md +1 -1
  13. package/dist/docs/references/reference-client-js-mastra-client.md +23 -0
  14. package/dist/docs/references/reference-client-js-observability.md +2 -2
  15. package/dist/docs/references/reference-client-js-responses.md +1 -1
  16. package/dist/docs/references/reference-client-js-workflows.md +62 -1
  17. package/dist/index.cjs +660 -35
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +657 -35
  22. package/dist/index.js.map +1 -1
  23. package/dist/resources/a2a.d.ts +56 -10
  24. package/dist/resources/a2a.d.ts.map +1 -1
  25. package/dist/resources/agent.d.ts +69 -0
  26. package/dist/resources/agent.d.ts.map +1 -1
  27. package/dist/resources/channels.d.ts +63 -0
  28. package/dist/resources/channels.d.ts.map +1 -0
  29. package/dist/resources/index.d.ts +1 -0
  30. package/dist/resources/index.d.ts.map +1 -1
  31. package/dist/resources/memory-thread.d.ts.map +1 -1
  32. package/dist/resources/observability.d.ts +18 -1
  33. package/dist/resources/observability.d.ts.map +1 -1
  34. package/dist/resources/run.d.ts +26 -2
  35. package/dist/resources/run.d.ts.map +1 -1
  36. package/dist/resources/vector.d.ts +5 -5
  37. package/dist/resources/vector.d.ts.map +1 -1
  38. package/dist/types.d.ts +115 -6
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/utils/process-a2a-stream.d.ts +4 -0
  41. package/dist/utils/process-a2a-stream.d.ts.map +1 -0
  42. package/package.json +12 -12
package/dist/index.js CHANGED
@@ -3,7 +3,9 @@ import { v4 } from '@lukeed/uuid';
3
3
  import { getErrorFromUnknown } from '@mastra/core/error';
4
4
  import { standardSchemaToJSONSchema, toStandardSchema } from '@mastra/schema-compat/schema';
5
5
  import { RequestContext } from '@mastra/core/request-context';
6
+ export { RequestContext } from '@mastra/core/request-context';
6
7
  import { zodToJsonSchema as zodToJsonSchema$1 } from '@mastra/schema-compat/zod-to-json';
8
+ import { MastraA2AError } from '@mastra/core/a2a';
7
9
 
8
10
  // src/resources/agent.ts
9
11
  function normalizeRoutePath(path) {
@@ -339,6 +341,8 @@ var AgentVoice = class extends BaseResource {
339
341
  this.version = version;
340
342
  this.agentId = agentId;
341
343
  }
344
+ agentId;
345
+ version;
342
346
  getQueryString(requestContext, delimiter = "?") {
343
347
  const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
344
348
  if (this.version) {
@@ -408,6 +412,8 @@ var Agent = class extends BaseResource {
408
412
  this.version = version;
409
413
  this.voice = new AgentVoice(options, this.agentId, this.version);
410
414
  }
415
+ agentId;
416
+ version;
411
417
  voice;
412
418
  getQueryString(requestContext, delimiter = "?") {
413
419
  const searchParams = new URLSearchParams(requestContextQueryString(requestContext).slice(1));
@@ -1204,9 +1210,14 @@ var Agent = class extends BaseResource {
1204
1210
  const { resource, thread } = memory ?? {};
1205
1211
  const threadId = processedParams.threadId ?? (typeof thread === "string" ? thread : thread?.id);
1206
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
+ }
1207
1218
  const response = await this.request(`/agents/${this.agentId}/${route}`, {
1208
1219
  method: "POST",
1209
- body: processedParams,
1220
+ body: requestBody,
1210
1221
  stream: true
1211
1222
  });
1212
1223
  if (!response.body) {
@@ -1302,7 +1313,8 @@ var Agent = class extends BaseResource {
1302
1313
  ...processedParams,
1303
1314
  messages: updatedMessages
1304
1315
  },
1305
- controller
1316
+ controller,
1317
+ route
1306
1318
  );
1307
1319
  } catch (error) {
1308
1320
  console.error("Error processing recursive stream response:", error);
@@ -1455,6 +1467,46 @@ var Agent = class extends BaseResource {
1455
1467
  };
1456
1468
  return streamResponse;
1457
1469
  }
1470
+ async streamUntilIdle(messagesOrParams, options) {
1471
+ let params = {
1472
+ messages: messagesOrParams,
1473
+ ...options
1474
+ };
1475
+ let structuredOutput = void 0;
1476
+ if (params.structuredOutput?.schema) {
1477
+ structuredOutput = {
1478
+ ...params.structuredOutput,
1479
+ schema: standardSchemaToJSONSchema(toStandardSchema(params.structuredOutput.schema))
1480
+ };
1481
+ }
1482
+ const processedParams = {
1483
+ ...params,
1484
+ requestContext: parseClientRequestContext(params.requestContext),
1485
+ clientTools: processClientTools(params.clientTools),
1486
+ structuredOutput
1487
+ };
1488
+ let readableController;
1489
+ const readable = new ReadableStream({
1490
+ start(controller) {
1491
+ readableController = controller;
1492
+ }
1493
+ });
1494
+ const response = await this.processStreamResponse(processedParams, readableController, "stream-until-idle");
1495
+ const streamResponse = new Response(readable, {
1496
+ status: response.status,
1497
+ statusText: response.statusText,
1498
+ headers: response.headers
1499
+ });
1500
+ streamResponse.processDataStream = async ({
1501
+ onChunk
1502
+ }) => {
1503
+ await processMastraStream({
1504
+ stream: streamResponse.body,
1505
+ onChunk
1506
+ });
1507
+ };
1508
+ return streamResponse;
1509
+ }
1458
1510
  async approveToolCall(params) {
1459
1511
  const { requestContext, ...rest } = params;
1460
1512
  const processedParams = { ...rest, requestContext: parseClientRequestContext(requestContext) };
@@ -1505,6 +1557,88 @@ var Agent = class extends BaseResource {
1505
1557
  };
1506
1558
  return streamResponse;
1507
1559
  }
1560
+ /**
1561
+ * Observe (reconnect to) an existing agent stream.
1562
+ * Use this to resume receiving events after a disconnection.
1563
+ *
1564
+ * @param params.runId - The run ID to observe
1565
+ * @param params.offset - Optional position to resume from (0-based). If omitted, replays all events.
1566
+ * @returns Promise containing a streaming Response
1567
+ *
1568
+ * @example
1569
+ * ```typescript
1570
+ * // Reconnect to a stream from a specific position
1571
+ * const response = await client.agents('my-agent').observe({
1572
+ * runId: 'run-123',
1573
+ * offset: 42, // Resume from event 42
1574
+ * });
1575
+ *
1576
+ * await response.processDataStream({
1577
+ * onChunk: (chunk) => console.log('Received:', chunk),
1578
+ * });
1579
+ * ```
1580
+ */
1581
+ async observe(params) {
1582
+ const response = await this.request(`/agents/${this.agentId}/observe`, {
1583
+ method: "POST",
1584
+ body: params,
1585
+ stream: true
1586
+ });
1587
+ if (!response.body) {
1588
+ throw new Error("No response body");
1589
+ }
1590
+ const streamResponse = new Response(response.body, {
1591
+ status: response.status,
1592
+ statusText: response.statusText,
1593
+ headers: response.headers
1594
+ });
1595
+ streamResponse.processDataStream = async ({
1596
+ onChunk
1597
+ }) => {
1598
+ await processMastraStream({
1599
+ stream: streamResponse.body,
1600
+ onChunk
1601
+ });
1602
+ };
1603
+ return streamResponse;
1604
+ }
1605
+ /**
1606
+ * Resumes a suspended agent stream with custom resume data.
1607
+ * Used to continue execution after a suspension point (e.g., workflow suspend within an agent).
1608
+ */
1609
+ async resumeStream(resumeData, options) {
1610
+ const processedParams = {
1611
+ ...options,
1612
+ resumeData,
1613
+ requestContext: parseClientRequestContext(options.requestContext),
1614
+ clientTools: processClientTools(options.clientTools),
1615
+ structuredOutput: options.structuredOutput ? {
1616
+ ...options.structuredOutput,
1617
+ schema: standardSchemaToJSONSchema(toStandardSchema(options.structuredOutput.schema))
1618
+ } : void 0
1619
+ };
1620
+ let readableController;
1621
+ const readable = new ReadableStream({
1622
+ start(controller) {
1623
+ readableController = controller;
1624
+ }
1625
+ });
1626
+ const response = await this.processStreamResponse(processedParams, readableController, "resume-stream");
1627
+ const streamResponse = new Response(readable, {
1628
+ status: response.status,
1629
+ statusText: response.statusText,
1630
+ headers: response.headers
1631
+ });
1632
+ streamResponse.processDataStream = async ({
1633
+ onChunk
1634
+ }) => {
1635
+ await processMastraStream({
1636
+ stream: streamResponse.body,
1637
+ onChunk
1638
+ });
1639
+ };
1640
+ return streamResponse;
1641
+ }
1508
1642
  /**
1509
1643
  * Approves a pending tool call and returns the complete response (non-streaming).
1510
1644
  * Used when `requireToolApproval` is enabled with generate() to allow the agent to proceed.
@@ -1721,6 +1855,8 @@ var MemoryThread = class extends BaseResource {
1721
1855
  this.threadId = threadId;
1722
1856
  this.agentId = agentId;
1723
1857
  }
1858
+ threadId;
1859
+ agentId;
1724
1860
  /**
1725
1861
  * Builds the query string for agentId (if provided)
1726
1862
  */
@@ -1768,7 +1904,7 @@ var MemoryThread = class extends BaseResource {
1768
1904
  * @returns Promise containing paginated thread messages with pagination metadata (total, page, perPage, hasMore)
1769
1905
  */
1770
1906
  listMessages(params = {}) {
1771
- const { page, perPage, orderBy, filter, include, resourceId, requestContext } = params;
1907
+ const { page, perPage, orderBy, filter, include, resourceId, requestContext, includeSystemReminders } = params;
1772
1908
  const queryParams = {};
1773
1909
  if (this.agentId) queryParams.agentId = this.agentId;
1774
1910
  if (resourceId) queryParams.resourceId = resourceId;
@@ -1777,6 +1913,7 @@ var MemoryThread = class extends BaseResource {
1777
1913
  if (orderBy) queryParams.orderBy = JSON.stringify(orderBy);
1778
1914
  if (filter) queryParams.filter = JSON.stringify(filter);
1779
1915
  if (include) queryParams.include = JSON.stringify(include);
1916
+ if (includeSystemReminders !== void 0) queryParams.includeSystemReminders = String(includeSystemReminders);
1780
1917
  const query = new URLSearchParams(queryParams);
1781
1918
  const queryString = query.toString();
1782
1919
  const url = `/memory/threads/${this.threadId}/messages${queryString ? `?${queryString}` : ""}${requestContextQueryString(requestContext, queryString ? "&" : "?")}`;
@@ -1824,6 +1961,7 @@ var Vector = class extends BaseResource {
1824
1961
  super(options);
1825
1962
  this.vectorName = vectorName;
1826
1963
  }
1964
+ vectorName;
1827
1965
  /**
1828
1966
  * Retrieves details about a specific vector index
1829
1967
  * @param indexName - Name of the index to get details for
@@ -1869,7 +2007,7 @@ var Vector = class extends BaseResource {
1869
2007
  /**
1870
2008
  * Upserts vectors into an index
1871
2009
  * @param params - Parameters containing vectors, metadata, and optional IDs
1872
- * @returns Promise containing array of vector IDs
2010
+ * @returns Promise containing the inserted vector IDs
1873
2011
  */
1874
2012
  upsert(params) {
1875
2013
  return this.request(`/vector/${encodeURIComponent(this.vectorName)}/upsert`, {
@@ -1896,6 +2034,7 @@ var Tool = class extends BaseResource {
1896
2034
  super(options);
1897
2035
  this.toolId = toolId;
1898
2036
  }
2037
+ toolId;
1899
2038
  /**
1900
2039
  * Retrieves details about the tool
1901
2040
  * @param requestContext - Optional request context to pass as query parameter
@@ -1931,6 +2070,7 @@ var Processor = class extends BaseResource {
1931
2070
  super(options);
1932
2071
  this.processorId = processorId;
1933
2072
  }
2073
+ processorId;
1934
2074
  /**
1935
2075
  * Retrieves details about the processor
1936
2076
  * @param requestContext - Optional request context to pass as query parameter
@@ -2012,6 +2152,8 @@ var Run = class extends BaseResource {
2012
2152
  this.workflowId = workflowId;
2013
2153
  this.runId = runId;
2014
2154
  }
2155
+ workflowId;
2156
+ runId;
2015
2157
  /**
2016
2158
  * Creates a transform stream that parses RECORD_SEPARATOR-delimited JSON chunks
2017
2159
  */
@@ -2145,6 +2287,7 @@ var Run = class extends BaseResource {
2145
2287
  resumeData,
2146
2288
  tracingOptions,
2147
2289
  perStep,
2290
+ forEachIndex,
2148
2291
  ...rest
2149
2292
  }) {
2150
2293
  const requestContext = parseClientRequestContext(rest.requestContext);
@@ -2155,7 +2298,8 @@ var Run = class extends BaseResource {
2155
2298
  resumeData,
2156
2299
  requestContext,
2157
2300
  tracingOptions,
2158
- perStep
2301
+ perStep,
2302
+ forEachIndex
2159
2303
  }
2160
2304
  });
2161
2305
  }
@@ -2211,19 +2355,32 @@ var Run = class extends BaseResource {
2211
2355
  return response.body.pipeThrough(this.createChunkTransformStream());
2212
2356
  }
2213
2357
  /**
2214
- * Observes workflow stream for a workflow run
2215
- * @returns Promise containing the workflow execution results
2358
+ * Observe (reconnect to) an existing workflow stream.
2359
+ * Use this to resume receiving events after a disconnection.
2360
+ *
2361
+ * @param params.offset - Optional position to resume from (0-based). If omitted, replays all events.
2362
+ * @returns Promise containing a ReadableStream of workflow events
2363
+ *
2364
+ * @example
2365
+ * ```typescript
2366
+ * // Reconnect to a workflow stream from a specific position
2367
+ * const stream = await run.observe({ offset: 42 });
2368
+ *
2369
+ * for await (const event of stream) {
2370
+ * console.log('Received:', event);
2371
+ * }
2372
+ * ```
2216
2373
  */
2217
- async observeStream() {
2374
+ async observe(params) {
2218
2375
  const searchParams = new URLSearchParams();
2219
2376
  searchParams.set("runId", this.runId);
2220
- const response = await this.request(
2221
- `/workflows/${this.workflowId}/observe-stream?${searchParams.toString()}`,
2222
- {
2223
- method: "POST",
2224
- stream: true
2225
- }
2226
- );
2377
+ if (params?.offset !== void 0) {
2378
+ searchParams.set("offset", String(params.offset));
2379
+ }
2380
+ const response = await this.request(`/workflows/${this.workflowId}/observe?${searchParams.toString()}`, {
2381
+ method: "POST",
2382
+ stream: true
2383
+ });
2227
2384
  if (!response.ok) {
2228
2385
  throw new Error(`Failed to observe workflow stream: ${response.statusText}`);
2229
2386
  }
@@ -2232,6 +2389,14 @@ var Run = class extends BaseResource {
2232
2389
  }
2233
2390
  return response.body.pipeThrough(this.createChunkTransformStream());
2234
2391
  }
2392
+ /**
2393
+ * Observes workflow stream for a workflow run
2394
+ * @deprecated Use `observe()` instead for better control over replay position
2395
+ * @returns Promise containing the workflow execution results
2396
+ */
2397
+ async observeStream() {
2398
+ return this.observe();
2399
+ }
2235
2400
  /**
2236
2401
  * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
2237
2402
  * @param params - Object containing the step, resumeData and requestContext
@@ -2246,7 +2411,8 @@ var Run = class extends BaseResource {
2246
2411
  resumeData: params.resumeData,
2247
2412
  requestContext,
2248
2413
  tracingOptions: params.tracingOptions,
2249
- perStep: params.perStep
2414
+ perStep: params.perStep,
2415
+ forEachIndex: params.forEachIndex
2250
2416
  }
2251
2417
  }).then(deserializeWorkflowError);
2252
2418
  }
@@ -2268,7 +2434,8 @@ var Run = class extends BaseResource {
2268
2434
  resumeData: params.resumeData,
2269
2435
  requestContext,
2270
2436
  tracingOptions: params.tracingOptions,
2271
- perStep: params.perStep
2437
+ perStep: params.perStep,
2438
+ forEachIndex: params.forEachIndex
2272
2439
  },
2273
2440
  stream: true
2274
2441
  }
@@ -2379,6 +2546,7 @@ var Workflow = class extends BaseResource {
2379
2546
  super(options);
2380
2547
  this.workflowId = workflowId;
2381
2548
  }
2549
+ workflowId;
2382
2550
  /**
2383
2551
  * Retrieves details about the workflow
2384
2552
  * @param requestContext - Optional request context to pass as query parameter
@@ -2526,26 +2694,162 @@ var Workflow = class extends BaseResource {
2526
2694
  }
2527
2695
  };
2528
2696
 
2697
+ // src/utils/process-a2a-stream.ts
2698
+ function splitNextEvent(buffer) {
2699
+ const normalizedBuffer = buffer.replace(/\x1E/g, "\n\n");
2700
+ const match = normalizedBuffer.match(/\r?\n\r?\n/);
2701
+ if (!match || match.index === void 0) {
2702
+ return { rest: normalizedBuffer };
2703
+ }
2704
+ const separatorLength = match[0].length;
2705
+ return {
2706
+ eventBlock: normalizedBuffer.slice(0, match.index),
2707
+ rest: normalizedBuffer.slice(match.index + separatorLength)
2708
+ };
2709
+ }
2710
+ function parseEventBlock(eventBlock) {
2711
+ const trimmedBlock = eventBlock.trim();
2712
+ if (!trimmedBlock) {
2713
+ return {};
2714
+ }
2715
+ const lines = trimmedBlock.split(/\r?\n/);
2716
+ const dataLines = lines.filter((line) => line.startsWith("data:")).map((line) => line.slice(5).trimStart());
2717
+ const payload = dataLines.length > 0 ? dataLines.join("\n") : trimmedBlock;
2718
+ if (!payload || payload === "[DONE]") {
2719
+ return { done: true };
2720
+ }
2721
+ let parsed;
2722
+ try {
2723
+ parsed = JSON.parse(payload);
2724
+ } catch (error) {
2725
+ throw new Error(
2726
+ `Failed to parse A2A stream event: ${error instanceof Error ? error.message : "unknown parse error"}`
2727
+ );
2728
+ }
2729
+ if (parsed && typeof parsed === "object" && "error" in parsed && parsed.error) {
2730
+ throw new MastraClientError(200, "OK", `A2A stream error - ${JSON.stringify(parsed.error)}`, parsed.error);
2731
+ }
2732
+ if (parsed && typeof parsed === "object" && "result" in parsed) {
2733
+ return { event: parsed.result };
2734
+ }
2735
+ return { event: parsed };
2736
+ }
2737
+ async function* processA2AStream(stream) {
2738
+ const reader = stream.getReader();
2739
+ const decoder = new TextDecoder();
2740
+ let buffer = "";
2741
+ try {
2742
+ while (true) {
2743
+ const { done, value } = await reader.read();
2744
+ if (done) {
2745
+ buffer += decoder.decode();
2746
+ } else {
2747
+ buffer += decoder.decode(value, { stream: true });
2748
+ }
2749
+ while (true) {
2750
+ const { eventBlock, rest } = splitNextEvent(buffer);
2751
+ buffer = rest;
2752
+ if (!eventBlock) {
2753
+ break;
2754
+ }
2755
+ const parsedEvent = parseEventBlock(eventBlock);
2756
+ if (parsedEvent.done) {
2757
+ return;
2758
+ }
2759
+ if (parsedEvent.event) {
2760
+ yield parsedEvent.event;
2761
+ }
2762
+ }
2763
+ if (done) {
2764
+ break;
2765
+ }
2766
+ }
2767
+ if (buffer.trim()) {
2768
+ const parsedEvent = parseEventBlock(buffer);
2769
+ if (!parsedEvent.done && parsedEvent.event) {
2770
+ yield parsedEvent.event;
2771
+ }
2772
+ }
2773
+ } finally {
2774
+ reader.releaseLock();
2775
+ }
2776
+ }
2777
+
2529
2778
  // src/resources/a2a.ts
2779
+ function createA2AJsonRpcError(response) {
2780
+ const error = response.error;
2781
+ const message = error?.message ?? "Unknown A2A JSON-RPC error";
2782
+ return typeof error?.code === "number" ? new MastraA2AError(error.code, message, error.data) : new MastraClientError(200, "OK", `A2A JSON-RPC error - ${message}`, error);
2783
+ }
2784
+ function unwrapA2AResult(response) {
2785
+ if ("error" in response && response.error) {
2786
+ throw createA2AJsonRpcError(response);
2787
+ }
2788
+ if ("result" in response) {
2789
+ return response.result;
2790
+ }
2791
+ throw new MastraClientError(200, "OK", "A2A JSON-RPC response did not include a result", response);
2792
+ }
2793
+ async function requireResponseBody(response, method) {
2794
+ if (response.body) {
2795
+ return response.body;
2796
+ }
2797
+ const headerSummary = Array.from(response.headers.entries()).map(([key, value]) => `${key}: ${value}`).join(", ");
2798
+ let responseText = "";
2799
+ try {
2800
+ responseText = await response.text();
2801
+ } catch {
2802
+ }
2803
+ const details = [
2804
+ `A2A ${method} stream response did not include a body`,
2805
+ `(status: ${response.status} ${response.statusText})`,
2806
+ headerSummary ? `headers: ${headerSummary}` : "",
2807
+ responseText ? `body: ${responseText}` : ""
2808
+ ].filter(Boolean).join(" ");
2809
+ throw new MastraClientError(response.status, response.statusText, details);
2810
+ }
2530
2811
  var A2A = class extends BaseResource {
2531
2812
  constructor(options, agentId) {
2532
2813
  super(options);
2533
2814
  this.agentId = agentId;
2534
2815
  }
2816
+ agentId;
2535
2817
  /**
2536
- * Get the agent card with metadata about the agent
2818
+ * Get the agent card with metadata about the agent.
2537
2819
  * @returns Promise containing the agent card information
2538
2820
  */
2539
- async getCard() {
2821
+ async getAgentCard() {
2540
2822
  return this.request(`/.well-known/${this.agentId}/agent-card.json`);
2541
2823
  }
2542
2824
  /**
2543
- * Send a message to the agent and gets a message or task response
2825
+ * @deprecated Use getAgentCard() instead.
2826
+ */
2827
+ async getCard() {
2828
+ return this.getAgentCard();
2829
+ }
2830
+ /**
2831
+ * Get the authenticated extended agent card.
2832
+ * @returns Promise containing the authenticated extended agent card
2833
+ */
2834
+ async getExtendedAgentCard() {
2835
+ const response = await this.request(`/a2a/${this.agentId}`, {
2836
+ method: "POST",
2837
+ body: {
2838
+ jsonrpc: "2.0",
2839
+ id: crypto.randomUUID(),
2840
+ method: "agent/getAuthenticatedExtendedCard"
2841
+ }
2842
+ });
2843
+ return unwrapA2AResult(response);
2844
+ }
2845
+ /**
2846
+ * @deprecated Use sendMessageStream() for the streaming experience.
2847
+ * Send a message to the agent and gets a message or task response.
2544
2848
  * @param params - Parameters for the task
2545
- * @returns Promise containing the response
2849
+ * @returns Promise containing the JSON-RPC response envelope
2546
2850
  */
2547
2851
  async sendMessage(params) {
2548
- const response = await this.request(`/a2a/${this.agentId}`, {
2852
+ return this.request(`/a2a/${this.agentId}`, {
2549
2853
  method: "POST",
2550
2854
  body: {
2551
2855
  jsonrpc: "2.0",
@@ -2554,15 +2858,14 @@ var A2A = class extends BaseResource {
2554
2858
  params
2555
2859
  }
2556
2860
  });
2557
- return response;
2558
2861
  }
2559
2862
  /**
2560
- * Sends a message to an agent to initiate/continue a task and subscribes
2863
+ * Sends a message to an agent to initiate or continue a task and subscribes
2561
2864
  * the client to real-time updates for that task via Server-Sent Events (SSE).
2562
2865
  * @param params - Parameters for the task
2563
- * @returns A stream of Server-Sent Events. Each SSE `data` field contains a `SendStreamingMessageResponse`
2866
+ * @returns An async generator of typed A2A stream events
2564
2867
  */
2565
- async sendStreamingMessage(params) {
2868
+ async *sendMessageStream(params) {
2566
2869
  const response = await this.request(`/a2a/${this.agentId}`, {
2567
2870
  method: "POST",
2568
2871
  body: {
@@ -2573,15 +2876,30 @@ var A2A = class extends BaseResource {
2573
2876
  },
2574
2877
  stream: true
2575
2878
  });
2576
- return response;
2879
+ yield* processA2AStream(await requireResponseBody(response, "message/stream"));
2880
+ }
2881
+ /**
2882
+ * @deprecated Use sendMessageStream() instead.
2883
+ */
2884
+ async sendStreamingMessage(params) {
2885
+ return this.request(`/a2a/${this.agentId}`, {
2886
+ method: "POST",
2887
+ body: {
2888
+ jsonrpc: "2.0",
2889
+ id: crypto.randomUUID(),
2890
+ method: "message/stream",
2891
+ params
2892
+ },
2893
+ stream: true
2894
+ });
2577
2895
  }
2578
2896
  /**
2579
- * Get the status and result of a task
2897
+ * Get the status and result of a task.
2580
2898
  * @param params - Parameters for querying the task
2581
- * @returns Promise containing the task response
2899
+ * @returns Promise containing the JSON-RPC response envelope
2582
2900
  */
2583
2901
  async getTask(params) {
2584
- const response = await this.request(`/a2a/${this.agentId}`, {
2902
+ return this.request(`/a2a/${this.agentId}`, {
2585
2903
  method: "POST",
2586
2904
  body: {
2587
2905
  jsonrpc: "2.0",
@@ -2590,10 +2908,9 @@ var A2A = class extends BaseResource {
2590
2908
  params
2591
2909
  }
2592
2910
  });
2593
- return response;
2594
2911
  }
2595
2912
  /**
2596
- * Cancel a running task
2913
+ * Cancel a running task.
2597
2914
  * @param params - Parameters identifying the task to cancel
2598
2915
  * @returns Promise containing the task response
2599
2916
  */
@@ -2608,6 +2925,92 @@ var A2A = class extends BaseResource {
2608
2925
  }
2609
2926
  });
2610
2927
  }
2928
+ /**
2929
+ * Resume a task stream for an existing task.
2930
+ * @param params - Parameters identifying the task to resubscribe to
2931
+ * @returns An async generator of typed A2A stream events
2932
+ */
2933
+ async *resubscribeTask(params) {
2934
+ const response = await this.request(`/a2a/${this.agentId}`, {
2935
+ method: "POST",
2936
+ body: {
2937
+ jsonrpc: "2.0",
2938
+ id: crypto.randomUUID(),
2939
+ method: "tasks/resubscribe",
2940
+ params
2941
+ },
2942
+ stream: true
2943
+ });
2944
+ yield* processA2AStream(await requireResponseBody(response, "tasks/resubscribe"));
2945
+ }
2946
+ /**
2947
+ * Set push notification config for a task.
2948
+ * @param params - Push notification configuration for the task
2949
+ * @returns Promise containing the push notification configuration
2950
+ */
2951
+ async setTaskPushNotificationConfig(params) {
2952
+ const response = await this.request(`/a2a/${this.agentId}`, {
2953
+ method: "POST",
2954
+ body: {
2955
+ jsonrpc: "2.0",
2956
+ id: crypto.randomUUID(),
2957
+ method: "tasks/pushNotificationConfig/set",
2958
+ params
2959
+ }
2960
+ });
2961
+ return unwrapA2AResult(response);
2962
+ }
2963
+ /**
2964
+ * Get push notification config for a task.
2965
+ * @param params - Parameters identifying the task
2966
+ * @returns Promise containing the push notification configuration
2967
+ */
2968
+ async getTaskPushNotificationConfig(params) {
2969
+ const response = await this.request(`/a2a/${this.agentId}`, {
2970
+ method: "POST",
2971
+ body: {
2972
+ jsonrpc: "2.0",
2973
+ id: crypto.randomUUID(),
2974
+ method: "tasks/pushNotificationConfig/get",
2975
+ params
2976
+ }
2977
+ });
2978
+ return unwrapA2AResult(response);
2979
+ }
2980
+ /**
2981
+ * List push notification configs for a task.
2982
+ * @param params - Parameters identifying the task
2983
+ * @returns Promise containing the push notification configurations
2984
+ */
2985
+ async listTaskPushNotificationConfig(params) {
2986
+ const response = await this.request(`/a2a/${this.agentId}`, {
2987
+ method: "POST",
2988
+ body: {
2989
+ jsonrpc: "2.0",
2990
+ id: crypto.randomUUID(),
2991
+ method: "tasks/pushNotificationConfig/list",
2992
+ params
2993
+ }
2994
+ });
2995
+ return unwrapA2AResult(response);
2996
+ }
2997
+ /**
2998
+ * Delete a push notification config for a task.
2999
+ * @param params - Parameters identifying the config to delete
3000
+ * @returns Promise that resolves when the config is deleted
3001
+ */
3002
+ async deleteTaskPushNotificationConfig(params) {
3003
+ const response = await this.request(`/a2a/${this.agentId}`, {
3004
+ method: "POST",
3005
+ body: {
3006
+ jsonrpc: "2.0",
3007
+ id: crypto.randomUUID(),
3008
+ method: "tasks/pushNotificationConfig/delete",
3009
+ params
3010
+ }
3011
+ });
3012
+ unwrapA2AResult(response);
3013
+ }
2611
3014
  };
2612
3015
 
2613
3016
  // src/resources/mcp-tool.ts
@@ -2654,6 +3057,7 @@ var AgentBuilder = class extends BaseResource {
2654
3057
  super(options);
2655
3058
  this.actionId = actionId;
2656
3059
  }
3060
+ actionId;
2657
3061
  // Helper function to transform workflow result to action result
2658
3062
  transformWorkflowResult(result) {
2659
3063
  if (result.status === "success") {
@@ -3021,6 +3425,27 @@ var Observability = class extends BaseResource {
3021
3425
  getTrace(traceId) {
3022
3426
  return this.request(`/observability/traces/${traceId}`);
3023
3427
  }
3428
+ /**
3429
+ * Retrieves a lightweight trace by ID (timeline fields only).
3430
+ * Excludes heavy fields (input, output, attributes, metadata, tags, links)
3431
+ * for ~97% payload reduction compared to getTrace.
3432
+ *
3433
+ * @param traceId - ID of the trace to retrieve
3434
+ * @returns Promise containing the trace with lightweight spans
3435
+ */
3436
+ getTraceLight(traceId) {
3437
+ return this.request(`/observability/traces/${traceId}/light`);
3438
+ }
3439
+ /**
3440
+ * Retrieves a single span with full details by trace ID and span ID.
3441
+ *
3442
+ * @param traceId - ID of the trace containing the span
3443
+ * @param spanId - ID of the span to retrieve
3444
+ * @returns Promise containing the full span record
3445
+ */
3446
+ getSpan(traceId, spanId) {
3447
+ return this.request(`/observability/traces/${traceId}/spans/${spanId}`);
3448
+ }
3024
3449
  /**
3025
3450
  * Extracts a structured trajectory from a trace's spans.
3026
3451
  *
@@ -3328,6 +3753,7 @@ var StoredAgent = class extends BaseResource {
3328
3753
  super(options);
3329
3754
  this.storedAgentId = storedAgentId;
3330
3755
  }
3756
+ storedAgentId;
3331
3757
  /**
3332
3758
  * Retrieves details about the stored agent
3333
3759
  * @param requestContext - Optional request context to pass as query parameter
@@ -3481,6 +3907,7 @@ var StoredPromptBlock = class extends BaseResource {
3481
3907
  super(options);
3482
3908
  this.storedPromptBlockId = storedPromptBlockId;
3483
3909
  }
3910
+ storedPromptBlockId;
3484
3911
  /**
3485
3912
  * Retrieves details about the stored prompt block
3486
3913
  * @param requestContext - Optional request context to pass as query parameter
@@ -3634,6 +4061,7 @@ var StoredMCPClient = class extends BaseResource {
3634
4061
  super(options);
3635
4062
  this.storedMCPClientId = storedMCPClientId;
3636
4063
  }
4064
+ storedMCPClientId;
3637
4065
  /**
3638
4066
  * Retrieves details about the stored MCP client
3639
4067
  * @param requestContext - Optional request context to pass as query parameter
@@ -3680,6 +4108,7 @@ var StoredScorer = class extends BaseResource {
3680
4108
  super(options);
3681
4109
  this.storedScorerId = storedScorerId;
3682
4110
  }
4111
+ storedScorerId;
3683
4112
  /**
3684
4113
  * Retrieves details about the stored scorer definition
3685
4114
  * @param requestContext - Optional request context to pass as query parameter
@@ -3834,6 +4263,7 @@ var ToolProvider = class extends BaseResource {
3834
4263
  super(options);
3835
4264
  this.providerId = providerId;
3836
4265
  }
4266
+ providerId;
3837
4267
  /**
3838
4268
  * Lists available toolkits from this provider
3839
4269
  * @returns Promise containing list of toolkits
@@ -3883,6 +4313,7 @@ var ProcessorProvider = class extends BaseResource {
3883
4313
  super(options);
3884
4314
  this.providerId = providerId;
3885
4315
  }
4316
+ providerId;
3886
4317
  /**
3887
4318
  * Gets details about this processor provider and its available processors
3888
4319
  * @returns Promise containing provider info and processor list
@@ -3902,6 +4333,9 @@ var WorkspaceSkillResource = class extends BaseResource {
3902
4333
  this.basePath = `/workspaces/${encodeURIComponent(this.workspaceId)}/skills/${encodeURIComponent(this.skillName)}`;
3903
4334
  this.pathQuery = this.skillPath ? `?path=${encodeURIComponent(this.skillPath)}` : "";
3904
4335
  }
4336
+ workspaceId;
4337
+ skillName;
4338
+ skillPath;
3905
4339
  basePath;
3906
4340
  pathQuery;
3907
4341
  /**
@@ -4121,6 +4555,7 @@ var StoredSkill = class extends BaseResource {
4121
4555
  super(options);
4122
4556
  this.storedSkillId = storedSkillId;
4123
4557
  }
4558
+ storedSkillId;
4124
4559
  /**
4125
4560
  * Retrieves details about the stored skill
4126
4561
  * @param requestContext - Optional request context to pass as query parameter
@@ -4217,6 +4652,7 @@ var ResponsesStream = class {
4217
4652
  constructor(response) {
4218
4653
  this.response = response;
4219
4654
  }
4655
+ response;
4220
4656
  asResponse() {
4221
4657
  return this.response;
4222
4658
  }
@@ -4296,16 +4732,68 @@ var Responses = class extends BaseResource {
4296
4732
  }
4297
4733
  };
4298
4734
 
4735
+ // src/resources/channels.ts
4736
+ var Channels = class extends BaseResource {
4737
+ constructor(options) {
4738
+ super(options);
4739
+ }
4740
+ /**
4741
+ * Lists all registered channel platforms and their configuration status.
4742
+ * @returns Array of available platforms
4743
+ */
4744
+ listPlatforms() {
4745
+ return this.request("/channels/platforms");
4746
+ }
4747
+ /**
4748
+ * Lists installations for a given platform, optionally filtered by agent.
4749
+ * @param platform - Platform identifier (e.g., "slack")
4750
+ * @param agentId - Optional agent ID to filter by (client-side)
4751
+ * @returns Array of installations
4752
+ */
4753
+ async listInstallations(platform, agentId) {
4754
+ const all = await this.request(`/channels/${platform}/installations`);
4755
+ if (agentId) {
4756
+ return all.filter((i) => i.agentId === agentId);
4757
+ }
4758
+ return all;
4759
+ }
4760
+ /**
4761
+ * Connects an agent to a channel platform.
4762
+ * @param platform - Platform identifier (e.g., "slack")
4763
+ * @param agentId - Agent to connect
4764
+ * @param options - Platform-specific connection options
4765
+ * @returns Discriminated connect result — check `type` for the authorization flow
4766
+ */
4767
+ connect(platform, agentId, options) {
4768
+ return this.request(`/channels/${platform}/connect`, {
4769
+ method: "POST",
4770
+ body: { agentId, options }
4771
+ });
4772
+ }
4773
+ /**
4774
+ * Disconnects an agent from a channel platform.
4775
+ * @param platform - Platform identifier (e.g., "slack")
4776
+ * @param agentId - Agent to disconnect
4777
+ */
4778
+ disconnect(platform, agentId) {
4779
+ return this.request(`/channels/${platform}/${agentId}/disconnect`, {
4780
+ method: "POST"
4781
+ });
4782
+ }
4783
+ };
4784
+
4299
4785
  // src/client.ts
4300
4786
  var MastraClient = class extends BaseResource {
4301
4787
  observability;
4302
4788
  conversations;
4303
4789
  responses;
4790
+ channels;
4304
4791
  constructor(options) {
4305
4792
  super(options);
4306
4793
  this.observability = new Observability(options);
4307
4794
  this.conversations = new Conversations(options);
4308
4795
  this.responses = new Responses(options);
4796
+ this.channels = new Channels(options);
4309
4797
  }
4310
4798
  /**
4311
4799
  * Retrieves all available agents
@@ -4408,12 +4896,13 @@ var MastraClient = class extends BaseResource {
4408
4896
  */
4409
4897
  listThreadMessages(threadId, opts = {}) {
4410
4898
  let url = "";
4899
+ const includeSystemRemindersQuery = opts.includeSystemReminders === void 0 ? "" : `includeSystemReminders=${opts.includeSystemReminders}`;
4411
4900
  if (opts.networkId) {
4412
- url = `/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${requestContextQueryString(opts.requestContext, "&")}`;
4901
+ url = `/memory/network/threads/${threadId}/messages?networkId=${opts.networkId}${includeSystemRemindersQuery ? `&${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, includeSystemRemindersQuery ? "&" : "&")}`;
4413
4902
  } else if (opts.agentId) {
4414
- url = `/memory/threads/${threadId}/messages?agentId=${opts.agentId}${requestContextQueryString(opts.requestContext, "&")}`;
4903
+ url = `/memory/threads/${threadId}/messages?agentId=${opts.agentId}${includeSystemRemindersQuery ? `&${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, "&")}`;
4415
4904
  } else {
4416
- url = `/memory/threads/${threadId}/messages${requestContextQueryString(opts.requestContext, "?")}`;
4905
+ url = `/memory/threads/${threadId}/messages${includeSystemRemindersQuery ? `?${includeSystemRemindersQuery}` : ""}${requestContextQueryString(opts.requestContext, includeSystemRemindersQuery ? "&" : "?")}`;
4417
4906
  }
4418
4907
  return this.request(url);
4419
4908
  }
@@ -4462,6 +4951,14 @@ var MastraClient = class extends BaseResource {
4462
4951
  const queryParams = new URLSearchParams({ agentId: params.agentId });
4463
4952
  if (params.resourceId) queryParams.set("resourceId", params.resourceId);
4464
4953
  if (params.threadId) queryParams.set("threadId", params.threadId);
4954
+ if (params.from) {
4955
+ queryParams.set("from", params.from instanceof Date ? params.from.toISOString() : params.from);
4956
+ }
4957
+ if (params.to) {
4958
+ queryParams.set("to", params.to instanceof Date ? params.to.toISOString() : params.to);
4959
+ }
4960
+ if (params.offset != null) queryParams.set("offset", String(params.offset));
4961
+ if (params.limit != null) queryParams.set("limit", String(params.limit));
4465
4962
  const queryString = queryParams.toString();
4466
4963
  return this.request(
4467
4964
  `/memory/observational-memory?${queryString}${requestContextQueryString(params.requestContext, "&")}`
@@ -4880,6 +5377,14 @@ var MastraClient = class extends BaseResource {
4880
5377
  getTrace(traceId) {
4881
5378
  return this.observability.getTrace(traceId);
4882
5379
  }
5380
+ /** Retrieves a lightweight trace by ID (timeline fields only, excludes heavy fields). */
5381
+ getTraceLight(traceId) {
5382
+ return this.observability.getTraceLight(traceId);
5383
+ }
5384
+ /** Retrieves a single span with full details by trace ID and span ID. */
5385
+ getSpan(traceId, spanId) {
5386
+ return this.observability.getSpan(traceId, spanId);
5387
+ }
4883
5388
  /** Extracts a structured trajectory from a trace's spans. */
4884
5389
  getTraceTrajectory(traceId) {
4885
5390
  return this.observability.getTraceTrajectory(traceId);
@@ -5627,6 +6132,123 @@ var MastraClient = class extends BaseResource {
5627
6132
  body
5628
6133
  });
5629
6134
  }
6135
+ // ============================================================================
6136
+ // Background Tasks
6137
+ // ============================================================================
6138
+ /**
6139
+ * Lists background tasks with optional filtering and pagination.
6140
+ */
6141
+ listBackgroundTasks(params = {}) {
6142
+ const searchParams = new URLSearchParams();
6143
+ if (params.agentId) searchParams.set("agentId", params.agentId);
6144
+ if (params.status) searchParams.set("status", params.status);
6145
+ if (params.runId) searchParams.set("runId", params.runId);
6146
+ if (params.threadId) searchParams.set("threadId", params.threadId);
6147
+ if (params.resourceId) searchParams.set("resourceId", params.resourceId);
6148
+ if (params.fromDate) searchParams.set("fromDate", params.fromDate.toISOString());
6149
+ if (params.toDate) searchParams.set("toDate", params.toDate.toISOString());
6150
+ if (params.dateFilterBy) searchParams.set("dateFilterBy", params.dateFilterBy);
6151
+ if (params.orderBy) searchParams.set("orderBy", params.orderBy);
6152
+ if (params.orderDirection) searchParams.set("orderDirection", params.orderDirection);
6153
+ if (params.page !== void 0) searchParams.set("page", String(params.page));
6154
+ if (params.perPage !== void 0) searchParams.set("perPage", String(params.perPage));
6155
+ const qs = searchParams.toString();
6156
+ return this.request(`/background-tasks${qs ? `?${qs}` : ""}`);
6157
+ }
6158
+ /**
6159
+ * Gets a single background task by ID.
6160
+ */
6161
+ getBackgroundTask(backgroundTaskId) {
6162
+ return this.request(`/background-tasks/${encodeURIComponent(backgroundTaskId)}`);
6163
+ }
6164
+ /**
6165
+ * Opens an SSE stream of background task events (completed/failed).
6166
+ * Returns a Response that can be consumed as a ReadableStream.
6167
+ */
6168
+ async streamBackgroundTasks(params = {}) {
6169
+ const searchParams = new URLSearchParams();
6170
+ if (params.agentId) searchParams.set("agentId", params.agentId);
6171
+ if (params.runId) searchParams.set("runId", params.runId);
6172
+ if (params.threadId) searchParams.set("threadId", params.threadId);
6173
+ if (params.resourceId) searchParams.set("resourceId", params.resourceId);
6174
+ if (params.taskId) searchParams.set("taskId", params.taskId);
6175
+ const qs = searchParams.toString();
6176
+ const response = await this.request(`/background-tasks/stream${qs ? `?${qs}` : ""}`, { stream: true });
6177
+ if (!response.ok) {
6178
+ throw new Error(`Failed to stream background tasks: ${response.statusText}`);
6179
+ }
6180
+ if (!response.body) {
6181
+ throw new Error("Response body is null");
6182
+ }
6183
+ let failedChunk = void 0;
6184
+ return response.body.pipeThrough(
6185
+ new TransformStream({
6186
+ async transform(chunk, controller) {
6187
+ try {
6188
+ const decoded = new TextDecoder().decode(chunk);
6189
+ const chunks = decoded.split("\n\n");
6190
+ for (const chunk2 of chunks) {
6191
+ if (chunk2) {
6192
+ const cleanChunk = chunk2.substring("data: ".length);
6193
+ const newChunk = failedChunk ? failedChunk + cleanChunk : cleanChunk;
6194
+ try {
6195
+ const parsedChunk = JSON.parse(newChunk);
6196
+ controller.enqueue(parsedChunk);
6197
+ failedChunk = void 0;
6198
+ } catch {
6199
+ failedChunk = newChunk;
6200
+ }
6201
+ }
6202
+ }
6203
+ } catch {
6204
+ }
6205
+ }
6206
+ })
6207
+ );
6208
+ }
6209
+ /**
6210
+ * Lists workflow schedules with optional filtering by workflowId or status.
6211
+ */
6212
+ listSchedules(params = {}) {
6213
+ const searchParams = new URLSearchParams();
6214
+ if (params.workflowId) searchParams.set("workflowId", params.workflowId);
6215
+ if (params.status) searchParams.set("status", params.status);
6216
+ const qs = searchParams.toString();
6217
+ return this.request(`/schedules${qs ? `?${qs}` : ""}`);
6218
+ }
6219
+ /**
6220
+ * Gets a single schedule by ID.
6221
+ */
6222
+ getSchedule(scheduleId) {
6223
+ return this.request(`/schedules/${encodeURIComponent(scheduleId)}`);
6224
+ }
6225
+ /**
6226
+ * Lists trigger history for a schedule, ordered by actualFireAt descending.
6227
+ */
6228
+ listScheduleTriggers(scheduleId, params = {}) {
6229
+ const searchParams = new URLSearchParams();
6230
+ if (params.limit !== void 0) searchParams.set("limit", String(params.limit));
6231
+ if (params.fromActualFireAt !== void 0) searchParams.set("fromActualFireAt", String(params.fromActualFireAt));
6232
+ if (params.toActualFireAt !== void 0) searchParams.set("toActualFireAt", String(params.toActualFireAt));
6233
+ const qs = searchParams.toString();
6234
+ return this.request(`/schedules/${encodeURIComponent(scheduleId)}/triggers${qs ? `?${qs}` : ""}`);
6235
+ }
6236
+ /**
6237
+ * Pauses a schedule. The scheduler tick loop will skip paused schedules.
6238
+ * Idempotent — pausing an already-paused schedule returns the current state unchanged.
6239
+ * Pause status survives redeploys.
6240
+ */
6241
+ pauseSchedule(scheduleId) {
6242
+ return this.request(`/schedules/${encodeURIComponent(scheduleId)}/pause`, { method: "POST" });
6243
+ }
6244
+ /**
6245
+ * Resumes a paused schedule. Recomputes nextFireAt from "now" so a long-paused schedule
6246
+ * does not fire a backlog. Idempotent — resuming an already-active schedule returns
6247
+ * the current state unchanged.
6248
+ */
6249
+ resumeSchedule(scheduleId) {
6250
+ return this.request(`/schedules/${encodeURIComponent(scheduleId)}/resume`, { method: "POST" });
6251
+ }
5630
6252
  };
5631
6253
 
5632
6254
  // src/tools.ts