@mastra/client-js 1.57.0-alpha.2 → 1.57.0-alpha.4

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) {
@@ -5763,8 +5736,7 @@ var Observability = class extends BaseResource {
5763
5736
  return this.request("/observability/capabilities");
5764
5737
  }
5765
5738
  };
5766
- //#endregion
5767
- //#region src/resources/stored-agent.ts
5739
+ // src/resources/stored-agent.ts
5768
5740
  /**
5769
5741
  * Resource for interacting with a specific stored agent
5770
5742
  */
@@ -5932,8 +5904,7 @@ var StoredAgent = class extends BaseResource {
5932
5904
  return this.request(`/stored/agents/${encodeURIComponent(this.storedAgentId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
5933
5905
  }
5934
5906
  };
5935
- //#endregion
5936
- //#region src/resources/dynamic-workflow.ts
5907
+ // src/resources/dynamic-workflow.ts
5937
5908
  /** Resource for interacting with a specific dynamic workflow definition. */
5938
5909
  var DynamicWorkflow = class extends BaseResource {
5939
5910
  dynamicWorkflowId;
@@ -5956,8 +5927,7 @@ var DynamicWorkflow = class extends BaseResource {
5956
5927
  return this.request(`/stored/workflows/${encodeURIComponent(this.dynamicWorkflowId)}`, { method: "DELETE" });
5957
5928
  }
5958
5929
  };
5959
- //#endregion
5960
- //#region src/resources/stored-prompt-block.ts
5930
+ // src/resources/stored-prompt-block.ts
5961
5931
  /**
5962
5932
  * Resource for interacting with a specific stored prompt block
5963
5933
  */
@@ -6080,8 +6050,7 @@ var StoredPromptBlock = class extends BaseResource {
6080
6050
  return this.request(`/stored/prompt-blocks/${encodeURIComponent(this.storedPromptBlockId)}/versions/compare?${queryParams.toString()}${contextString}`);
6081
6051
  }
6082
6052
  };
6083
- //#endregion
6084
- //#region src/resources/stored-mcp-client.ts
6053
+ // src/resources/stored-mcp-client.ts
6085
6054
  /**
6086
6055
  * Resource for interacting with a specific stored MCP client
6087
6056
  */
@@ -6120,8 +6089,7 @@ var StoredMCPClient = class extends BaseResource {
6120
6089
  return this.request(`/stored/mcp-clients/${encodeURIComponent(this.storedMCPClientId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6121
6090
  }
6122
6091
  };
6123
- //#endregion
6124
- //#region src/resources/stored-scorer.ts
6092
+ // src/resources/stored-scorer.ts
6125
6093
  /**
6126
6094
  * Resource for interacting with a specific stored scorer definition
6127
6095
  */
@@ -6245,8 +6213,7 @@ var StoredScorer = class extends BaseResource {
6245
6213
  return this.request(`/stored/scorers/${encodeURIComponent(this.storedScorerId)}/versions/compare?${queryParams.toString()}${contextString ? `&${contextString.slice(1)}` : ""}`);
6246
6214
  }
6247
6215
  };
6248
- //#endregion
6249
- //#region src/resources/tool-provider.ts
6216
+ // src/resources/tool-provider.ts
6250
6217
  /**
6251
6218
  * Resource for interacting with a specific tool provider.
6252
6219
  *
@@ -6381,8 +6348,7 @@ var ToolProvider = class extends BaseResource {
6381
6348
  return this.request(`/tool-providers/${encodeURIComponent(this.providerId)}/health`);
6382
6349
  }
6383
6350
  };
6384
- //#endregion
6385
- //#region src/resources/processor-provider.ts
6351
+ // src/resources/processor-provider.ts
6386
6352
  /**
6387
6353
  * Resource for interacting with a specific processor provider
6388
6354
  */
@@ -6400,8 +6366,7 @@ var ProcessorProvider = class extends BaseResource {
6400
6366
  return this.request(`/processor-providers/${encodeURIComponent(this.providerId)}`);
6401
6367
  }
6402
6368
  };
6403
- //#endregion
6404
- //#region src/resources/workspace.ts
6369
+ // src/resources/workspace.ts
6405
6370
  /**
6406
6371
  * Resource for interacting with a specific skill via the workspace API
6407
6372
  */
@@ -6671,8 +6636,7 @@ var Workspace = class extends BaseResource {
6671
6636
  });
6672
6637
  }
6673
6638
  };
6674
- //#endregion
6675
- //#region src/resources/stored-skill.ts
6639
+ // src/resources/stored-skill.ts
6676
6640
  /**
6677
6641
  * Resource for interacting with a specific stored skill
6678
6642
  */
@@ -6725,8 +6689,7 @@ var StoredSkill = class extends BaseResource {
6725
6689
  return this.request(`/stored/skills/${encodeURIComponent(this.storedSkillId)}/favorite${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6726
6690
  }
6727
6691
  };
6728
- //#endregion
6729
- //#region src/resources/responses.ts
6692
+ // src/resources/responses.ts
6730
6693
  function getOutputText(output) {
6731
6694
  return output.flatMap((item) => item.type === "message" ? item.content : []).map((part) => typeof part?.text === "string" ? part.text : "").filter(Boolean).join("");
6732
6695
  }
@@ -6831,8 +6794,7 @@ var Responses = class extends BaseResource {
6831
6794
  return this.request(`/v1/responses/${encodeURIComponent(responseId)}${requestContextQueryString(requestContext)}`, { method: "DELETE" });
6832
6795
  }
6833
6796
  };
6834
- //#endregion
6835
- //#region src/resources/channels.ts
6797
+ // src/resources/channels.ts
6836
6798
  var Channels = class extends BaseResource {
6837
6799
  constructor(options) {
6838
6800
  super(options);
@@ -6892,8 +6854,7 @@ var Channels = class extends BaseResource {
6892
6854
  return this.request(`/channels/${platform}/${agentId}/disconnect`, { method: "POST" });
6893
6855
  }
6894
6856
  };
6895
- //#endregion
6896
- //#region src/resources/agent-controller.ts
6857
+ // src/resources/agent-controller.ts
6897
6858
  const KNOWN_AGENT_CONTROLLER_EVENT_TYPES = new Set(Object.keys({
6898
6859
  agent_start: true,
6899
6860
  agent_end: true,
@@ -7593,8 +7554,7 @@ var AgentController = class extends BaseResource {
7593
7554
  function agentControllerMessageText(message) {
7594
7555
  return message.content.parts.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text).join("");
7595
7556
  }
7596
- //#endregion
7597
- //#region src/client.ts
7557
+ // src/client.ts
7598
7558
  /**
7599
7559
  * Provides typed access to agents, workflows, and other APIs on a running Mastra server.
7600
7560
  * Point `baseUrl` at your server and configure authentication when required.
@@ -9364,8 +9324,7 @@ var MastraClient = class extends BaseResource {
9364
9324
  return this.request(`/schedules/${encodeURIComponent(scheduleId)}/resume`, { method: "POST" });
9365
9325
  }
9366
9326
  };
9367
- //#endregion
9368
- //#region src/tools.ts
9327
+ // src/tools.ts
9369
9328
  var ClientTool = class {
9370
9329
  id;
9371
9330
  description;
@@ -9383,7 +9342,6 @@ var ClientTool = class {
9383
9342
  function createTool(opts) {
9384
9343
  return new ClientTool(opts);
9385
9344
  }
9386
- //#endregion
9387
9345
  export { ClientTool, MastraClient, MastraClientError, RequestContext, agentControllerMessageText, createTool, isKnownAgentControllerEvent };
9388
9346
 
9389
9347
  //# sourceMappingURL=index.js.map