@mastra/client-js 1.57.0-alpha.3 → 1.57.0-alpha.5

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
@@ -7,7 +7,7 @@ import { MastraA2AError } from "@mastra/core/a2a/client";
7
7
  import { AgentCard, CancelTaskRequest, DeleteTaskPushNotificationConfigRequest, GetTaskPushNotificationConfigRequest, GetTaskRequest, ListTaskPushNotificationConfigsRequest, ListTaskPushNotificationConfigsResponse, ListTasksRequest, ListTasksResponse, SendMessageRequest, SendMessageResponse, StreamResponse, SubscribeToTaskRequest, Task, TaskPushNotificationConfig } from "@mastra/core/a2a/v1";
8
8
  import canonicalize from "canonicalize";
9
9
  import { base64url, compactVerify, decodeProtectedHeader, importJWK, importSPKI, importX509 } from "jose";
10
- //#region src/observability/collector.ts
10
+ // src/observability/collector.ts
11
11
  const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
12
12
  const ZERO_TRACE_ID = "00000000000000000000000000000000";
13
13
  const ZERO_SPAN_ID = "0000000000000000";
@@ -206,8 +206,7 @@ var ObservabilityCollectorImpl = class {
206
206
  * `@mastra/client-js/observability` subpath.
207
207
  */
208
208
  const createObservabilityCollector = (parentContext) => new ObservabilityCollectorImpl(parentContext);
209
- //#endregion
210
- //#region src/utils/index.ts
209
+ // src/utils/index.ts
211
210
  /**
212
211
  * Normalizes a route path to ensure consistent formatting.
213
212
  * - Removes leading/trailing whitespace
@@ -395,8 +394,7 @@ function isTerminalReconnectError(error) {
395
394
  const status = error?.status;
396
395
  return isTerminalHttpError(error) && status !== 408 && status !== 429;
397
396
  }
398
- //#endregion
399
- //#region src/utils/ai-sdk-v4/data-stream-parts.ts
397
+ // src/utils/ai-sdk-v4/data-stream-parts.ts
400
398
  const dataStreamParts = [
401
399
  {
402
400
  code: "0",
@@ -609,8 +607,7 @@ const parseDataStreamPart = (line) => {
609
607
  const jsonValue = JSON.parse(textValue);
610
608
  return dataStreamPartsByCode[code].parse(jsonValue);
611
609
  };
612
- //#endregion
613
- //#region src/utils/ai-sdk-v4/fix-json.ts
610
+ // src/utils/ai-sdk-v4/fix-json.ts
614
611
  function fixJson(input) {
615
612
  const stack = ["ROOT"];
616
613
  let lastValidIndex = -1;
@@ -846,8 +843,7 @@ function fixJson(input) {
846
843
  }
847
844
  return result;
848
845
  }
849
- //#endregion
850
- //#region src/utils/ai-sdk-v4/parse-partial-json.ts
846
+ // src/utils/ai-sdk-v4/parse-partial-json.ts
851
847
  function tryParse(text) {
852
848
  try {
853
849
  return {
@@ -878,8 +874,7 @@ function parsePartialJson(jsonText) {
878
874
  state: "failed-parse"
879
875
  };
880
876
  }
881
- //#endregion
882
- //#region src/utils/ai-sdk-v4/process-data-stream.ts
877
+ // src/utils/ai-sdk-v4/process-data-stream.ts
883
878
  const NEWLINE = "\n".charCodeAt(0);
884
879
  function concatChunks(chunks, totalLength) {
885
880
  const concatenatedChunks = new Uint8Array(totalLength);
@@ -960,8 +955,7 @@ async function processDataStream({ stream, onTextPart, onReasoningPart, onReason
960
955
  }
961
956
  }
962
957
  }
963
- //#endregion
964
- //#region src/utils/client-tool-model-output.ts
958
+ // src/utils/client-tool-model-output.ts
965
959
  /**
966
960
  * Normalize modelOutput from toModelOutput() to the AI SDK V2 tool result
967
961
  * content shape. Mirrors `normalizeModelOutput` in @mastra/core's
@@ -1020,8 +1014,7 @@ async function getClientToolModelOutput(clientTool, result) {
1020
1014
  const modelOutput = await toModelOutput(result);
1021
1015
  return modelOutput == null ? void 0 : normalizeModelOutput(modelOutput);
1022
1016
  }
1023
- //#endregion
1024
- //#region src/utils/zod-to-json-schema.ts
1017
+ // src/utils/zod-to-json-schema.ts
1025
1018
  /**
1026
1019
  * Check if a value is a Zod schema type.
1027
1020
  * This is a simple check that doesn't require any Node.js dependencies.
@@ -1041,8 +1034,7 @@ function zodToJsonSchema$1(zodSchema) {
1041
1034
  if (!isZodType(zodSchema)) return zodSchema;
1042
1035
  return zodToJsonSchema(zodSchema);
1043
1036
  }
1044
- //#endregion
1045
- //#region src/utils/process-client-tools.ts
1037
+ // src/utils/process-client-tools.ts
1046
1038
  function processClientTools(clientTools) {
1047
1039
  if (!clientTools) return;
1048
1040
  return Object.fromEntries(Object.entries(clientTools).map(([key, value]) => {
@@ -1055,8 +1047,7 @@ function processClientTools(clientTools) {
1055
1047
  }];
1056
1048
  }));
1057
1049
  }
1058
- //#endregion
1059
- //#region src/utils/sse-event-splitter.ts
1050
+ // src/utils/sse-event-splitter.ts
1060
1051
  /** Split SSE events without rescanning or copying an unfinished event on each read. */
1061
1052
  function createSseEventSplitter() {
1062
1053
  let parts = [];
@@ -1095,8 +1086,7 @@ function createSseEventSplitter() {
1095
1086
  return events;
1096
1087
  };
1097
1088
  }
1098
- //#endregion
1099
- //#region src/utils/process-mastra-stream.ts
1089
+ // src/utils/process-mastra-stream.ts
1100
1090
  async function sharedProcessMastraStream({ stream, onChunk, signal }) {
1101
1091
  const reader = stream.getReader();
1102
1092
  const decoder = new TextDecoder();
@@ -1141,8 +1131,7 @@ async function processMastraStream({ stream, onChunk, signal }) {
1141
1131
  signal
1142
1132
  });
1143
1133
  }
1144
- //#endregion
1145
- //#region src/types.ts
1134
+ // src/types.ts
1146
1135
  /**
1147
1136
  * HTTP error thrown by the Mastra client.
1148
1137
  * Extends Error with additional properties for better error handling.
@@ -1175,8 +1164,7 @@ var MastraClientError = class extends Error {
1175
1164
  this.body = body;
1176
1165
  }
1177
1166
  };
1178
- //#endregion
1179
- //#region src/resources/base.ts
1167
+ // src/resources/base.ts
1180
1168
  var BaseResource = class {
1181
1169
  options;
1182
1170
  apiPrefix;
@@ -1250,8 +1238,7 @@ var BaseResource = class {
1250
1238
  throw lastError || /* @__PURE__ */ new Error("Request failed");
1251
1239
  }
1252
1240
  };
1253
- //#endregion
1254
- //#region src/resources/agent.ts
1241
+ // src/resources/agent.ts
1255
1242
  const SIGNAL_RUNTIME_OPTIONS_TTL_MS = 3e5;
1256
1243
  const signalRuntimeOptionsByRunId = /* @__PURE__ */ new Map();
1257
1244
  /**
@@ -3638,8 +3625,7 @@ var Agent = class extends BaseResource {
3638
3625
  });
3639
3626
  }
3640
3627
  };
3641
- //#endregion
3642
- //#region src/resources/memory-thread.ts
3628
+ // src/resources/memory-thread.ts
3643
3629
  /**
3644
3630
  * Serializes the message-listing filters both memory message routes accept. The network route
3645
3631
  * takes the same filters under a different path, so the two callers share one serializer.
@@ -3808,8 +3794,7 @@ function normalizeWriteOpts(opts) {
3808
3794
  if (Object.keys(opts).length === 0) return {};
3809
3795
  return { requestContext: opts };
3810
3796
  }
3811
- //#endregion
3812
- //#region src/resources/vector.ts
3797
+ // src/resources/vector.ts
3813
3798
  var Vector = class extends BaseResource {
3814
3799
  vectorName;
3815
3800
  constructor(options, vectorName) {
@@ -3875,8 +3860,7 @@ var Vector = class extends BaseResource {
3875
3860
  });
3876
3861
  }
3877
3862
  };
3878
- //#endregion
3879
- //#region src/resources/tool.ts
3863
+ // src/resources/tool.ts
3880
3864
  var Tool = class extends BaseResource {
3881
3865
  toolId;
3882
3866
  constructor(options, toolId) {
@@ -3909,8 +3893,7 @@ var Tool = class extends BaseResource {
3909
3893
  });
3910
3894
  }
3911
3895
  };
3912
- //#endregion
3913
- //#region src/resources/processor.ts
3896
+ // src/resources/processor.ts
3914
3897
  var Processor = class extends BaseResource {
3915
3898
  processorId;
3916
3899
  constructor(options, processorId) {
@@ -3943,8 +3926,7 @@ var Processor = class extends BaseResource {
3943
3926
  });
3944
3927
  }
3945
3928
  };
3946
- //#endregion
3947
- //#region src/resources/conversations.ts
3929
+ // src/resources/conversations.ts
3948
3930
  var ConversationItems = class extends BaseResource {
3949
3931
  constructor(options) {
3950
3932
  super(options);
@@ -3973,8 +3955,7 @@ var Conversations = class extends BaseResource {
3973
3955
  return this.request(`/v1/conversations/${encodeURIComponent(conversationId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
3974
3956
  }
3975
3957
  };
3976
- //#endregion
3977
- //#region src/utils/stream-transforms.ts
3958
+ // src/utils/stream-transforms.ts
3978
3959
  const RECORD_SEPARATOR$1 = "";
3979
3960
  const SSE_FRAME_SEPARATOR = /\r?\n\r?\n/;
3980
3961
  /**
@@ -4042,8 +4023,7 @@ function createSseJsonTransform() {
4042
4023
  }
4043
4024
  });
4044
4025
  }
4045
- //#endregion
4046
- //#region src/resources/run.ts
4026
+ // src/resources/run.ts
4047
4027
  /**
4048
4028
  * Deserializes the error property in a workflow result back to an Error instance.
4049
4029
  * Server sends SerializedError (plain object), client converts to Error for instanceof checks.
@@ -4412,8 +4392,7 @@ var Run = class extends BaseResource {
4412
4392
  return response.body.pipeThrough(this.createChunkTransformStream());
4413
4393
  }
4414
4394
  };
4415
- //#endregion
4416
- //#region src/resources/workflow.ts
4395
+ // src/resources/workflow.ts
4417
4396
  const RECORD_SEPARATOR = "";
4418
4397
  var Workflow = class extends BaseResource {
4419
4398
  workflowId;
@@ -4530,8 +4509,7 @@ var Workflow = class extends BaseResource {
4530
4509
  } });
4531
4510
  }
4532
4511
  };
4533
- //#endregion
4534
- //#region src/utils/process-a2a-stream.ts
4512
+ // src/utils/process-a2a-stream.ts
4535
4513
  function splitNextEvent(buffer) {
4536
4514
  const normalizedBuffer = buffer.replace(/\x1E/g, "\n\n");
4537
4515
  const match = normalizedBuffer.match(/\r?\n\r?\n/);
@@ -4585,8 +4563,7 @@ async function* processA2AStream(stream) {
4585
4563
  reader.releaseLock();
4586
4564
  }
4587
4565
  }
4588
- //#endregion
4589
- //#region src/utils/verify-agent-card-signature.ts
4566
+ // src/utils/verify-agent-card-signature.ts
4590
4567
  const DEFAULT_AGENT_CARD_SIGNATURE_ALGORITHMS = [
4591
4568
  "ES256",
4592
4569
  "ES384",
@@ -4655,8 +4632,7 @@ async function verifyAgentCardSignatureIfPresent(agentCard, options) {
4655
4632
  }
4656
4633
  throw new MastraClientError(200, "OK", `A2A Agent Card signature verification failed: ${verificationErrors.join("; ")}`);
4657
4634
  }
4658
- //#endregion
4659
- //#region src/resources/a2a.ts
4635
+ // src/resources/a2a.ts
4660
4636
  function createA2AJsonRpcError(response) {
4661
4637
  const error = response.error;
4662
4638
  const message = error?.message ?? "Unknown A2A JSON-RPC error";
@@ -4968,8 +4944,7 @@ var A2AV1 = class extends BaseResource {
4968
4944
  for await (const event of processA2AStream(await requireResponseBody(response, "tasks/resubscribe"))) yield StreamResponse.fromJSON(event);
4969
4945
  }
4970
4946
  };
4971
- //#endregion
4972
- //#region src/resources/mcp-tool.ts
4947
+ // src/resources/mcp-tool.ts
4973
4948
  /**
4974
4949
  * Represents a specific tool available on a specific MCP server.
4975
4950
  * Provides methods to get details and execute the tool.
@@ -5006,8 +4981,7 @@ var MCPTool = class extends BaseResource {
5006
4981
  });
5007
4982
  }
5008
4983
  };
5009
- //#endregion
5010
- //#region src/resources/agent-builder.ts
4984
+ // src/resources/agent-builder.ts
5011
4985
  /**
5012
4986
  * Agent Builder resource: operations related to agent-builder workflows via server endpoints.
5013
4987
  */
@@ -5266,8 +5240,7 @@ var AgentBuilder = class extends BaseResource {
5266
5240
  return this.request(url, { method: "POST" });
5267
5241
  }
5268
5242
  };
5269
- //#endregion
5270
- //#region src/resources/observability.ts
5243
+ // src/resources/observability.ts
5271
5244
  /** Client resource for interacting with the Mastra observability API (traces, logs, scores, feedback, and metrics). */
5272
5245
  var Observability = class extends BaseResource {
5273
5246
  constructor(options) {
@@ -5367,10 +5340,11 @@ var Observability = class extends BaseResource {
5367
5340
  * Groups and measures the traces selected by a time range and optional trace-query predicate.
5368
5341
  * Check `capabilities.traceAggregate` from `getObservabilityCapabilities()` first; servers without it return 404 or 501.
5369
5342
  */
5370
- aggregateTraces(params) {
5343
+ aggregateTraces(params, options) {
5371
5344
  return this.request("/observability/traces/aggregate", {
5372
5345
  method: "POST",
5373
- body: params
5346
+ body: params,
5347
+ signal: options?.signal
5374
5348
  });
5375
5349
  }
5376
5350
  /**
@@ -5763,8 +5737,7 @@ var Observability = class extends BaseResource {
5763
5737
  return this.request("/observability/capabilities");
5764
5738
  }
5765
5739
  };
5766
- //#endregion
5767
- //#region src/resources/stored-agent.ts
5740
+ // src/resources/stored-agent.ts
5768
5741
  /**
5769
5742
  * Resource for interacting with a specific stored agent
5770
5743
  */
@@ -5932,8 +5905,7 @@ var StoredAgent = class extends BaseResource {
5932
5905
  return this.request(`/stored/agents/${encodeURIComponent(this.storedAgentId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
5933
5906
  }
5934
5907
  };
5935
- //#endregion
5936
- //#region src/resources/dynamic-workflow.ts
5908
+ // src/resources/dynamic-workflow.ts
5937
5909
  /** Resource for interacting with a specific dynamic workflow definition. */
5938
5910
  var DynamicWorkflow = class extends BaseResource {
5939
5911
  dynamicWorkflowId;
@@ -5956,8 +5928,7 @@ var DynamicWorkflow = class extends BaseResource {
5956
5928
  return this.request(`/stored/workflows/${encodeURIComponent(this.dynamicWorkflowId)}`, { method: "DELETE" });
5957
5929
  }
5958
5930
  };
5959
- //#endregion
5960
- //#region src/resources/stored-prompt-block.ts
5931
+ // src/resources/stored-prompt-block.ts
5961
5932
  /**
5962
5933
  * Resource for interacting with a specific stored prompt block
5963
5934
  */
@@ -6080,8 +6051,7 @@ var StoredPromptBlock = class extends BaseResource {
6080
6051
  return this.request(`/stored/prompt-blocks/${encodeURIComponent(this.storedPromptBlockId)}/versions/compare?${queryParams.toString()}${contextString}`);
6081
6052
  }
6082
6053
  };
6083
- //#endregion
6084
- //#region src/resources/stored-mcp-client.ts
6054
+ // src/resources/stored-mcp-client.ts
6085
6055
  /**
6086
6056
  * Resource for interacting with a specific stored MCP client
6087
6057
  */
@@ -6120,8 +6090,7 @@ var StoredMCPClient = class extends BaseResource {
6120
6090
  return this.request(`/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6121
6091
  }
6122
6092
  };
6123
- //#endregion
6124
- //#region src/resources/stored-scorer.ts
6093
+ // src/resources/stored-scorer.ts
6125
6094
  /**
6126
6095
  * Resource for interacting with a specific stored scorer definition
6127
6096
  */
@@ -6245,8 +6214,7 @@ var StoredScorer = class extends BaseResource {
6245
6214
  return this.request(`/stored/scorers/${encodeURIComponent(this.storedScorerId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
6246
6215
  }
6247
6216
  };
6248
- //#endregion
6249
- //#region src/resources/tool-provider.ts
6217
+ // src/resources/tool-provider.ts
6250
6218
  /**
6251
6219
  * Resource for interacting with a specific tool provider.
6252
6220
  *
@@ -6381,8 +6349,7 @@ var ToolProvider = class extends BaseResource {
6381
6349
  return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/health`);
6382
6350
  }
6383
6351
  };
6384
- //#endregion
6385
- //#region src/resources/processor-provider.ts
6352
+ // src/resources/processor-provider.ts
6386
6353
  /**
6387
6354
  * Resource for interacting with a specific processor provider
6388
6355
  */
@@ -6400,8 +6367,7 @@ var ProcessorProvider = class extends BaseResource {
6400
6367
  return this.request(`/processor-providers/${encodeURIComponent(this.providerId)}`);
6401
6368
  }
6402
6369
  };
6403
- //#endregion
6404
- //#region src/resources/workspace.ts
6370
+ // src/resources/workspace.ts
6405
6371
  /**
6406
6372
  * Resource for interacting with a specific skill via the workspace API
6407
6373
  */
@@ -6671,8 +6637,7 @@ var Workspace = class extends BaseResource {
6671
6637
  });
6672
6638
  }
6673
6639
  };
6674
- //#endregion
6675
- //#region src/resources/stored-skill.ts
6640
+ // src/resources/stored-skill.ts
6676
6641
  /**
6677
6642
  * Resource for interacting with a specific stored skill
6678
6643
  */
@@ -6725,8 +6690,7 @@ var StoredSkill = class extends BaseResource {
6725
6690
  return this.request(`/stored/skills/${encodeURIComponent(this.storedSkillId)}/favorite${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6726
6691
  }
6727
6692
  };
6728
- //#endregion
6729
- //#region src/resources/responses.ts
6693
+ // src/resources/responses.ts
6730
6694
  function getOutputText(output) {
6731
6695
  return output.flatMap((item) => item.type === "message" ? item.content : []).map((part) => typeof part?.text === "string" ? part.text : "").filter(Boolean).join("");
6732
6696
  }
@@ -6831,8 +6795,7 @@ var Responses = class extends BaseResource {
6831
6795
  return this.request(`/v1/responses/${encodeURIComponent(responseId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6832
6796
  }
6833
6797
  };
6834
- //#endregion
6835
- //#region src/resources/channels.ts
6798
+ // src/resources/channels.ts
6836
6799
  var Channels = class extends BaseResource {
6837
6800
  constructor(options) {
6838
6801
  super(options);
@@ -6892,8 +6855,7 @@ var Channels = class extends BaseResource {
6892
6855
  return this.request(`/channels/${platform}/${agentId}/disconnect`, { method: "POST" });
6893
6856
  }
6894
6857
  };
6895
- //#endregion
6896
- //#region src/resources/agent-controller.ts
6858
+ // src/resources/agent-controller.ts
6897
6859
  const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
6898
6860
  agent_start: true,
6899
6861
  agent_end: true,
@@ -7080,7 +7042,7 @@ var AgentControllerSession = class extends BaseResource {
7080
7042
  const abort = new AbortController();
7081
7043
  currentAbort = abort;
7082
7044
  let openTimer;
7083
- const request = this.request(`${this.base()}/stream`, {
7045
+ const request = this.request(`${this.base()}/stream${options.displayState === false ? "?displayState=false" : ""}`, {
7084
7046
  stream: true,
7085
7047
  signal: abort.signal
7086
7048
  });
@@ -7593,8 +7555,7 @@ var AgentController = class extends BaseResource {
7593
7555
  function agentControllerMessageText(message) {
7594
7556
  return message.content.parts.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("");
7595
7557
  }
7596
- //#endregion
7597
- //#region src/client.ts
7558
+ // src/client.ts
7598
7559
  /**
7599
7560
  * Provides typed access to agents, workflows, and other APIs on a running Mastra server.
7600
7561
  * Point `baseUrl` at your server and configure authentication when required.
@@ -8245,8 +8206,8 @@ var MastraClient = class extends BaseResource {
8245
8206
  * Groups and measures the traces selected by a time range and optional trace-query predicate.
8246
8207
  * Check `capabilities.traceAggregate` from `getObservabilityCapabilities()` first; servers without it return 404 or 501.
8247
8208
  */
8248
- aggregateTraces(params) {
8249
- return this.observability.aggregateTraces(params);
8209
+ aggregateTraces(params, options) {
8210
+ return this.observability.aggregateTraces(params, options);
8250
8211
  }
8251
8212
  /**
8252
8213
  * Groups and measures individual completed spans selected by a time range and optional span-query predicate.
@@ -9364,8 +9325,7 @@ var MastraClient = class extends BaseResource {
9364
9325
  return this.request(`/schedules/${encodeURIComponent(scheduleId)}/resume`, { method: "POST" });
9365
9326
  }
9366
9327
  };
9367
- //#endregion
9368
- //#region src/tools.ts
9328
+ // src/tools.ts
9369
9329
  var ClientTool = class {
9370
9330
  id;
9371
9331
  description;
@@ -9383,7 +9343,6 @@ var ClientTool = class {
9383
9343
  function createTool(opts) {
9384
9344
  return new ClientTool(opts);
9385
9345
  }
9386
- //#endregion
9387
9346
  export { ClientTool, MastraClient, MastraClientError, RequestContext, agentControllerMessageText, createTool, isKnownAgentControllerEvent };
9388
9347
 
9389
9348
  //# sourceMappingURL=index.js.map