@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.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let _lukeed_uuid = require("@lukeed/uuid");
25
24
  let _mastra_core_error = require("@mastra/core/error");
26
25
  let _mastra_core_request_context = require("@mastra/core/request-context");
@@ -31,7 +30,7 @@ let _mastra_core_a2a_v1 = require("@mastra/core/a2a/v1");
31
30
  let canonicalize = require("canonicalize");
32
31
  canonicalize = __toESM(canonicalize, 1);
33
32
  let jose = require("jose");
34
- //#region src/observability/collector.ts
33
+ // src/observability/collector.ts
35
34
  const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
36
35
  const ZERO_TRACE_ID = "00000000000000000000000000000000";
37
36
  const ZERO_SPAN_ID = "0000000000000000";
@@ -230,8 +229,7 @@ var ObservabilityCollectorImpl = class {
230
229
  * `@mastra/client-js/observability` subpath.
231
230
  */
232
231
  const createObservabilityCollector = (parentContext) => new ObservabilityCollectorImpl(parentContext);
233
- //#endregion
234
- //#region src/utils/index.ts
232
+ // src/utils/index.ts
235
233
  /**
236
234
  * Normalizes a route path to ensure consistent formatting.
237
235
  * - Removes leading/trailing whitespace
@@ -419,8 +417,7 @@ function isTerminalReconnectError(error) {
419
417
  const status = error?.status;
420
418
  return isTerminalHttpError(error) && status !== 408 && status !== 429;
421
419
  }
422
- //#endregion
423
- //#region src/utils/ai-sdk-v4/data-stream-parts.ts
420
+ // src/utils/ai-sdk-v4/data-stream-parts.ts
424
421
  const dataStreamParts = [
425
422
  {
426
423
  code: "0",
@@ -633,8 +630,7 @@ const parseDataStreamPart = (line) => {
633
630
  const jsonValue = JSON.parse(textValue);
634
631
  return dataStreamPartsByCode[code].parse(jsonValue);
635
632
  };
636
- //#endregion
637
- //#region src/utils/ai-sdk-v4/fix-json.ts
633
+ // src/utils/ai-sdk-v4/fix-json.ts
638
634
  function fixJson(input) {
639
635
  const stack = ["ROOT"];
640
636
  let lastValidIndex = -1;
@@ -870,8 +866,7 @@ function fixJson(input) {
870
866
  }
871
867
  return result;
872
868
  }
873
- //#endregion
874
- //#region src/utils/ai-sdk-v4/parse-partial-json.ts
869
+ // src/utils/ai-sdk-v4/parse-partial-json.ts
875
870
  function tryParse(text) {
876
871
  try {
877
872
  return {
@@ -902,8 +897,7 @@ function parsePartialJson(jsonText) {
902
897
  state: "failed-parse"
903
898
  };
904
899
  }
905
- //#endregion
906
- //#region src/utils/ai-sdk-v4/process-data-stream.ts
900
+ // src/utils/ai-sdk-v4/process-data-stream.ts
907
901
  const NEWLINE = "\n".charCodeAt(0);
908
902
  function concatChunks(chunks, totalLength) {
909
903
  const concatenatedChunks = new Uint8Array(totalLength);
@@ -984,8 +978,7 @@ async function processDataStream({ stream, onTextPart, onReasoningPart, onReason
984
978
  }
985
979
  }
986
980
  }
987
- //#endregion
988
- //#region src/utils/client-tool-model-output.ts
981
+ // src/utils/client-tool-model-output.ts
989
982
  /**
990
983
  * Normalize modelOutput from toModelOutput() to the AI SDK V2 tool result
991
984
  * content shape. Mirrors `normalizeModelOutput` in @mastra/core's
@@ -1044,8 +1037,7 @@ async function getClientToolModelOutput(clientTool, result) {
1044
1037
  const modelOutput = await toModelOutput(result);
1045
1038
  return modelOutput == null ? void 0 : normalizeModelOutput(modelOutput);
1046
1039
  }
1047
- //#endregion
1048
- //#region src/utils/zod-to-json-schema.ts
1040
+ // src/utils/zod-to-json-schema.ts
1049
1041
  /**
1050
1042
  * Check if a value is a Zod schema type.
1051
1043
  * This is a simple check that doesn't require any Node.js dependencies.
@@ -1065,8 +1057,7 @@ function zodToJsonSchema(zodSchema) {
1065
1057
  if (!isZodType(zodSchema)) return zodSchema;
1066
1058
  return (0, _mastra_schema_compat_zod_to_json.zodToJsonSchema)(zodSchema);
1067
1059
  }
1068
- //#endregion
1069
- //#region src/utils/process-client-tools.ts
1060
+ // src/utils/process-client-tools.ts
1070
1061
  function processClientTools(clientTools) {
1071
1062
  if (!clientTools) return;
1072
1063
  return Object.fromEntries(Object.entries(clientTools).map(([key, value]) => {
@@ -1079,8 +1070,7 @@ function processClientTools(clientTools) {
1079
1070
  }];
1080
1071
  }));
1081
1072
  }
1082
- //#endregion
1083
- //#region src/utils/sse-event-splitter.ts
1073
+ // src/utils/sse-event-splitter.ts
1084
1074
  /** Split SSE events without rescanning or copying an unfinished event on each read. */
1085
1075
  function createSseEventSplitter() {
1086
1076
  let parts = [];
@@ -1119,8 +1109,7 @@ function createSseEventSplitter() {
1119
1109
  return events;
1120
1110
  };
1121
1111
  }
1122
- //#endregion
1123
- //#region src/utils/process-mastra-stream.ts
1112
+ // src/utils/process-mastra-stream.ts
1124
1113
  async function sharedProcessMastraStream({ stream, onChunk, signal }) {
1125
1114
  const reader = stream.getReader();
1126
1115
  const decoder = new TextDecoder();
@@ -1165,8 +1154,7 @@ async function processMastraStream({ stream, onChunk, signal }) {
1165
1154
  signal
1166
1155
  });
1167
1156
  }
1168
- //#endregion
1169
- //#region src/types.ts
1157
+ // src/types.ts
1170
1158
  /**
1171
1159
  * HTTP error thrown by the Mastra client.
1172
1160
  * Extends Error with additional properties for better error handling.
@@ -1199,8 +1187,7 @@ var MastraClientError = class extends Error {
1199
1187
  this.body = body;
1200
1188
  }
1201
1189
  };
1202
- //#endregion
1203
- //#region src/resources/base.ts
1190
+ // src/resources/base.ts
1204
1191
  var BaseResource = class {
1205
1192
  options;
1206
1193
  apiPrefix;
@@ -1274,8 +1261,7 @@ var BaseResource = class {
1274
1261
  throw lastError || /* @__PURE__ */ new Error("Request failed");
1275
1262
  }
1276
1263
  };
1277
- //#endregion
1278
- //#region src/resources/agent.ts
1264
+ // src/resources/agent.ts
1279
1265
  const SIGNAL_RUNTIME_OPTIONS_TTL_MS = 3e5;
1280
1266
  const signalRuntimeOptionsByRunId = /* @__PURE__ */ new Map();
1281
1267
  /**
@@ -3662,8 +3648,7 @@ var Agent = class extends BaseResource {
3662
3648
  });
3663
3649
  }
3664
3650
  };
3665
- //#endregion
3666
- //#region src/resources/memory-thread.ts
3651
+ // src/resources/memory-thread.ts
3667
3652
  /**
3668
3653
  * Serializes the message-listing filters both memory message routes accept. The network route
3669
3654
  * takes the same filters under a different path, so the two callers share one serializer.
@@ -3832,8 +3817,7 @@ function normalizeWriteOpts(opts) {
3832
3817
  if (Object.keys(opts).length === 0) return {};
3833
3818
  return { requestContext: opts };
3834
3819
  }
3835
- //#endregion
3836
- //#region src/resources/vector.ts
3820
+ // src/resources/vector.ts
3837
3821
  var Vector = class extends BaseResource {
3838
3822
  vectorName;
3839
3823
  constructor(options, vectorName) {
@@ -3899,8 +3883,7 @@ var Vector = class extends BaseResource {
3899
3883
  });
3900
3884
  }
3901
3885
  };
3902
- //#endregion
3903
- //#region src/resources/tool.ts
3886
+ // src/resources/tool.ts
3904
3887
  var Tool = class extends BaseResource {
3905
3888
  toolId;
3906
3889
  constructor(options, toolId) {
@@ -3933,8 +3916,7 @@ var Tool = class extends BaseResource {
3933
3916
  });
3934
3917
  }
3935
3918
  };
3936
- //#endregion
3937
- //#region src/resources/processor.ts
3919
+ // src/resources/processor.ts
3938
3920
  var Processor = class extends BaseResource {
3939
3921
  processorId;
3940
3922
  constructor(options, processorId) {
@@ -3967,8 +3949,7 @@ var Processor = class extends BaseResource {
3967
3949
  });
3968
3950
  }
3969
3951
  };
3970
- //#endregion
3971
- //#region src/resources/conversations.ts
3952
+ // src/resources/conversations.ts
3972
3953
  var ConversationItems = class extends BaseResource {
3973
3954
  constructor(options) {
3974
3955
  super(options);
@@ -3997,8 +3978,7 @@ var Conversations = class extends BaseResource {
3997
3978
  return this.request(`/v1/conversations/${encodeURIComponent(conversationId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
3998
3979
  }
3999
3980
  };
4000
- //#endregion
4001
- //#region src/utils/stream-transforms.ts
3981
+ // src/utils/stream-transforms.ts
4002
3982
  const RECORD_SEPARATOR$1 = "";
4003
3983
  const SSE_FRAME_SEPARATOR = /\r?\n\r?\n/;
4004
3984
  /**
@@ -4066,8 +4046,7 @@ function createSseJsonTransform() {
4066
4046
  }
4067
4047
  });
4068
4048
  }
4069
- //#endregion
4070
- //#region src/resources/run.ts
4049
+ // src/resources/run.ts
4071
4050
  /**
4072
4051
  * Deserializes the error property in a workflow result back to an Error instance.
4073
4052
  * Server sends SerializedError (plain object), client converts to Error for instanceof checks.
@@ -4436,8 +4415,7 @@ var Run = class extends BaseResource {
4436
4415
  return response.body.pipeThrough(this.createChunkTransformStream());
4437
4416
  }
4438
4417
  };
4439
- //#endregion
4440
- //#region src/resources/workflow.ts
4418
+ // src/resources/workflow.ts
4441
4419
  const RECORD_SEPARATOR = "";
4442
4420
  var Workflow = class extends BaseResource {
4443
4421
  workflowId;
@@ -4554,8 +4532,7 @@ var Workflow = class extends BaseResource {
4554
4532
  } });
4555
4533
  }
4556
4534
  };
4557
- //#endregion
4558
- //#region src/utils/process-a2a-stream.ts
4535
+ // src/utils/process-a2a-stream.ts
4559
4536
  function splitNextEvent(buffer) {
4560
4537
  const normalizedBuffer = buffer.replace(/\x1E/g, "\n\n");
4561
4538
  const match = normalizedBuffer.match(/\r?\n\r?\n/);
@@ -4609,8 +4586,7 @@ async function* processA2AStream(stream) {
4609
4586
  reader.releaseLock();
4610
4587
  }
4611
4588
  }
4612
- //#endregion
4613
- //#region src/utils/verify-agent-card-signature.ts
4589
+ // src/utils/verify-agent-card-signature.ts
4614
4590
  const DEFAULT_AGENT_CARD_SIGNATURE_ALGORITHMS = [
4615
4591
  "ES256",
4616
4592
  "ES384",
@@ -4679,8 +4655,7 @@ async function verifyAgentCardSignatureIfPresent(agentCard, options) {
4679
4655
  }
4680
4656
  throw new MastraClientError(200, "OK", `A2A Agent Card signature verification failed: ${verificationErrors.join("; ")}`);
4681
4657
  }
4682
- //#endregion
4683
- //#region src/resources/a2a.ts
4658
+ // src/resources/a2a.ts
4684
4659
  function createA2AJsonRpcError(response) {
4685
4660
  const error = response.error;
4686
4661
  const message = error?.message ?? "Unknown A2A JSON-RPC error";
@@ -4992,8 +4967,7 @@ var A2AV1 = class extends BaseResource {
4992
4967
  for await (const event of processA2AStream(await requireResponseBody(response, "tasks/resubscribe"))) yield _mastra_core_a2a_v1.StreamResponse.fromJSON(event);
4993
4968
  }
4994
4969
  };
4995
- //#endregion
4996
- //#region src/resources/mcp-tool.ts
4970
+ // src/resources/mcp-tool.ts
4997
4971
  /**
4998
4972
  * Represents a specific tool available on a specific MCP server.
4999
4973
  * Provides methods to get details and execute the tool.
@@ -5030,8 +5004,7 @@ var MCPTool = class extends BaseResource {
5030
5004
  });
5031
5005
  }
5032
5006
  };
5033
- //#endregion
5034
- //#region src/resources/agent-builder.ts
5007
+ // src/resources/agent-builder.ts
5035
5008
  /**
5036
5009
  * Agent Builder resource: operations related to agent-builder workflows via server endpoints.
5037
5010
  */
@@ -5290,8 +5263,7 @@ var AgentBuilder = class extends BaseResource {
5290
5263
  return this.request(url, { method: "POST" });
5291
5264
  }
5292
5265
  };
5293
- //#endregion
5294
- //#region src/resources/observability.ts
5266
+ // src/resources/observability.ts
5295
5267
  /** Client resource for interacting with the Mastra observability API (traces, logs, scores, feedback, and metrics). */
5296
5268
  var Observability = class extends BaseResource {
5297
5269
  constructor(options) {
@@ -5391,10 +5363,11 @@ var Observability = class extends BaseResource {
5391
5363
  * Groups and measures the traces selected by a time range and optional trace-query predicate.
5392
5364
  * Check `capabilities.traceAggregate` from `getObservabilityCapabilities()` first; servers without it return 404 or 501.
5393
5365
  */
5394
- aggregateTraces(params) {
5366
+ aggregateTraces(params, options) {
5395
5367
  return this.request("/observability/traces/aggregate", {
5396
5368
  method: "POST",
5397
- body: params
5369
+ body: params,
5370
+ signal: options?.signal
5398
5371
  });
5399
5372
  }
5400
5373
  /**
@@ -5787,8 +5760,7 @@ var Observability = class extends BaseResource {
5787
5760
  return this.request("/observability/capabilities");
5788
5761
  }
5789
5762
  };
5790
- //#endregion
5791
- //#region src/resources/stored-agent.ts
5763
+ // src/resources/stored-agent.ts
5792
5764
  /**
5793
5765
  * Resource for interacting with a specific stored agent
5794
5766
  */
@@ -5956,8 +5928,7 @@ var StoredAgent = class extends BaseResource {
5956
5928
  return this.request(`/stored/agents/${encodeURIComponent(this.storedAgentId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
5957
5929
  }
5958
5930
  };
5959
- //#endregion
5960
- //#region src/resources/dynamic-workflow.ts
5931
+ // src/resources/dynamic-workflow.ts
5961
5932
  /** Resource for interacting with a specific dynamic workflow definition. */
5962
5933
  var DynamicWorkflow = class extends BaseResource {
5963
5934
  dynamicWorkflowId;
@@ -5980,8 +5951,7 @@ var DynamicWorkflow = class extends BaseResource {
5980
5951
  return this.request(`/stored/workflows/${encodeURIComponent(this.dynamicWorkflowId)}`, { method: "DELETE" });
5981
5952
  }
5982
5953
  };
5983
- //#endregion
5984
- //#region src/resources/stored-prompt-block.ts
5954
+ // src/resources/stored-prompt-block.ts
5985
5955
  /**
5986
5956
  * Resource for interacting with a specific stored prompt block
5987
5957
  */
@@ -6104,8 +6074,7 @@ var StoredPromptBlock = class extends BaseResource {
6104
6074
  return this.request(`/stored/prompt-blocks/${encodeURIComponent(this.storedPromptBlockId)}/versions/compare?${queryParams.toString()}${contextString}`);
6105
6075
  }
6106
6076
  };
6107
- //#endregion
6108
- //#region src/resources/stored-mcp-client.ts
6077
+ // src/resources/stored-mcp-client.ts
6109
6078
  /**
6110
6079
  * Resource for interacting with a specific stored MCP client
6111
6080
  */
@@ -6144,8 +6113,7 @@ var StoredMCPClient = class extends BaseResource {
6144
6113
  return this.request(`/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6145
6114
  }
6146
6115
  };
6147
- //#endregion
6148
- //#region src/resources/stored-scorer.ts
6116
+ // src/resources/stored-scorer.ts
6149
6117
  /**
6150
6118
  * Resource for interacting with a specific stored scorer definition
6151
6119
  */
@@ -6269,8 +6237,7 @@ var StoredScorer = class extends BaseResource {
6269
6237
  return this.request(`/stored/scorers/${encodeURIComponent(this.storedScorerId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
6270
6238
  }
6271
6239
  };
6272
- //#endregion
6273
- //#region src/resources/tool-provider.ts
6240
+ // src/resources/tool-provider.ts
6274
6241
  /**
6275
6242
  * Resource for interacting with a specific tool provider.
6276
6243
  *
@@ -6405,8 +6372,7 @@ var ToolProvider = class extends BaseResource {
6405
6372
  return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/health`);
6406
6373
  }
6407
6374
  };
6408
- //#endregion
6409
- //#region src/resources/processor-provider.ts
6375
+ // src/resources/processor-provider.ts
6410
6376
  /**
6411
6377
  * Resource for interacting with a specific processor provider
6412
6378
  */
@@ -6424,8 +6390,7 @@ var ProcessorProvider = class extends BaseResource {
6424
6390
  return this.request(`/processor-providers/${encodeURIComponent(this.providerId)}`);
6425
6391
  }
6426
6392
  };
6427
- //#endregion
6428
- //#region src/resources/workspace.ts
6393
+ // src/resources/workspace.ts
6429
6394
  /**
6430
6395
  * Resource for interacting with a specific skill via the workspace API
6431
6396
  */
@@ -6695,8 +6660,7 @@ var Workspace = class extends BaseResource {
6695
6660
  });
6696
6661
  }
6697
6662
  };
6698
- //#endregion
6699
- //#region src/resources/stored-skill.ts
6663
+ // src/resources/stored-skill.ts
6700
6664
  /**
6701
6665
  * Resource for interacting with a specific stored skill
6702
6666
  */
@@ -6749,8 +6713,7 @@ var StoredSkill = class extends BaseResource {
6749
6713
  return this.request(`/stored/skills/${encodeURIComponent(this.storedSkillId)}/favorite${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6750
6714
  }
6751
6715
  };
6752
- //#endregion
6753
- //#region src/resources/responses.ts
6716
+ // src/resources/responses.ts
6754
6717
  function getOutputText(output) {
6755
6718
  return output.flatMap((item) => item.type === "message" ? item.content : []).map((part) => typeof part?.text === "string" ? part.text : "").filter(Boolean).join("");
6756
6719
  }
@@ -6855,8 +6818,7 @@ var Responses = class extends BaseResource {
6855
6818
  return this.request(`/v1/responses/${encodeURIComponent(responseId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6856
6819
  }
6857
6820
  };
6858
- //#endregion
6859
- //#region src/resources/channels.ts
6821
+ // src/resources/channels.ts
6860
6822
  var Channels = class extends BaseResource {
6861
6823
  constructor(options) {
6862
6824
  super(options);
@@ -6916,8 +6878,7 @@ var Channels = class extends BaseResource {
6916
6878
  return this.request(`/channels/${platform}/${agentId}/disconnect`, { method: "POST" });
6917
6879
  }
6918
6880
  };
6919
- //#endregion
6920
- //#region src/resources/agent-controller.ts
6881
+ // src/resources/agent-controller.ts
6921
6882
  const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
6922
6883
  agent_start: true,
6923
6884
  agent_end: true,
@@ -7104,7 +7065,7 @@ var AgentControllerSession = class extends BaseResource {
7104
7065
  const abort = new AbortController();
7105
7066
  currentAbort = abort;
7106
7067
  let openTimer;
7107
- const request = this.request(`${this.base()}/stream`, {
7068
+ const request = this.request(`${this.base()}/stream${options.displayState === false ? "?displayState=false" : ""}`, {
7108
7069
  stream: true,
7109
7070
  signal: abort.signal
7110
7071
  });
@@ -7617,8 +7578,7 @@ var AgentController = class extends BaseResource {
7617
7578
  function agentControllerMessageText(message) {
7618
7579
  return message.content.parts.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("");
7619
7580
  }
7620
- //#endregion
7621
- //#region src/client.ts
7581
+ // src/client.ts
7622
7582
  /**
7623
7583
  * Provides typed access to agents, workflows, and other APIs on a running Mastra server.
7624
7584
  * Point `baseUrl` at your server and configure authentication when required.
@@ -8269,8 +8229,8 @@ var MastraClient = class extends BaseResource {
8269
8229
  * Groups and measures the traces selected by a time range and optional trace-query predicate.
8270
8230
  * Check `capabilities.traceAggregate` from `getObservabilityCapabilities()` first; servers without it return 404 or 501.
8271
8231
  */
8272
- aggregateTraces(params) {
8273
- return this.observability.aggregateTraces(params);
8232
+ aggregateTraces(params, options) {
8233
+ return this.observability.aggregateTraces(params, options);
8274
8234
  }
8275
8235
  /**
8276
8236
  * Groups and measures individual completed spans selected by a time range and optional span-query predicate.
@@ -9388,8 +9348,7 @@ var MastraClient = class extends BaseResource {
9388
9348
  return this.request(`/schedules/${encodeURIComponent(scheduleId)}/resume`, { method: "POST" });
9389
9349
  }
9390
9350
  };
9391
- //#endregion
9392
- //#region src/tools.ts
9351
+ // src/tools.ts
9393
9352
  var ClientTool = class {
9394
9353
  id;
9395
9354
  description;
@@ -9407,7 +9366,6 @@ var ClientTool = class {
9407
9366
  function createTool(opts) {
9408
9367
  return new ClientTool(opts);
9409
9368
  }
9410
- //#endregion
9411
9369
  exports.ClientTool = ClientTool;
9412
9370
  exports.MastraClient = MastraClient;
9413
9371
  exports.MastraClientError = MastraClientError;