@mastra/client-js 1.2.0 → 1.3.0-alpha.1

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 (43) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/dist/_types/@internal_ai-sdk-v5/dist/index.d.ts +2103 -269
  3. package/dist/client.d.ts +30 -2
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/docs/SKILL.md +32 -22
  6. package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
  7. package/dist/docs/{server/07-auth0.md → references/docs-server-auth-auth0.md} +68 -79
  8. package/dist/docs/{server/03-clerk.md → references/docs-server-auth-clerk.md} +41 -52
  9. package/dist/docs/{server/05-firebase.md → references/docs-server-auth-firebase.md} +83 -97
  10. package/dist/docs/{server/02-jwt.md → references/docs-server-auth-jwt.md} +46 -35
  11. package/dist/docs/{server/04-supabase.md → references/docs-server-auth-supabase.md} +33 -44
  12. package/dist/docs/{server/06-workos.md → references/docs-server-auth-workos.md} +45 -56
  13. package/dist/docs/{server/01-mastra-client.md → references/docs-server-mastra-client.md} +32 -20
  14. package/dist/docs/{ai-sdk/01-reference.md → references/reference-ai-sdk-to-ai-sdk-stream.md} +27 -153
  15. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v4-messages.md +79 -0
  16. package/dist/docs/references/reference-ai-sdk-to-ai-sdk-v5-messages.md +73 -0
  17. package/dist/docs/references/reference-client-js-agents.md +438 -0
  18. package/dist/docs/references/reference-client-js-error-handling.md +16 -0
  19. package/dist/docs/references/reference-client-js-logs.md +24 -0
  20. package/dist/docs/references/reference-client-js-mastra-client.md +63 -0
  21. package/dist/docs/references/reference-client-js-memory.md +225 -0
  22. package/dist/docs/references/reference-client-js-observability.md +72 -0
  23. package/dist/docs/references/reference-client-js-telemetry.md +20 -0
  24. package/dist/docs/references/reference-client-js-tools.md +44 -0
  25. package/dist/docs/references/reference-client-js-vectors.md +79 -0
  26. package/dist/docs/references/reference-client-js-workflows.md +199 -0
  27. package/dist/index.cjs +139 -16
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +139 -16
  30. package/dist/index.js.map +1 -1
  31. package/dist/resources/agent.d.ts +7 -1
  32. package/dist/resources/agent.d.ts.map +1 -1
  33. package/dist/resources/base.d.ts +0 -11
  34. package/dist/resources/base.d.ts.map +1 -1
  35. package/dist/resources/index.d.ts +1 -0
  36. package/dist/resources/index.d.ts.map +1 -1
  37. package/dist/resources/stored-scorer.d.ts +30 -0
  38. package/dist/resources/stored-scorer.d.ts.map +1 -0
  39. package/dist/types.d.ts +322 -44
  40. package/dist/types.d.ts.map +1 -1
  41. package/package.json +4 -5
  42. package/dist/docs/README.md +0 -33
  43. package/dist/docs/client-js/01-reference.md +0 -1180
package/dist/index.js CHANGED
@@ -352,7 +352,7 @@ function safeParseJSON({
352
352
  }
353
353
  }
354
354
 
355
- // ../../node_modules/.pnpm/zod-to-json-schema@3.24.6_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
355
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.25.1_zod@3.25.76/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
356
356
  new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
357
357
  function fixJson(input) {
358
358
  const stack = ["ROOT"];
@@ -1250,26 +1250,13 @@ var MastraClientError = class extends Error {
1250
1250
  };
1251
1251
 
1252
1252
  // src/resources/base.ts
1253
- var BaseResource = class _BaseResource {
1253
+ var BaseResource = class {
1254
1254
  options;
1255
1255
  apiPrefix;
1256
1256
  constructor(options) {
1257
1257
  this.options = options;
1258
1258
  this.apiPrefix = normalizeRoutePath(options.apiPrefix ?? "/api");
1259
1259
  }
1260
- /**
1261
- * Path segments that should NOT have the API prefix applied (protocol-specific paths).
1262
- * These are special protocol endpoints that exist at the root level.
1263
- */
1264
- static NON_API_PATHS = ["/a2a", "/.well-known"];
1265
- /**
1266
- * Checks if a path should have the API prefix applied.
1267
- * Returns false for protocol-specific paths like /a2a and /.well-known
1268
- * Matches exact path or path followed by / to avoid false positives (e.g., /a2a-other)
1269
- */
1270
- shouldApplyPrefix(path) {
1271
- return !_BaseResource.NON_API_PATHS.some((nonApiPath) => path === nonApiPath || path.startsWith(nonApiPath + "/"));
1272
- }
1273
1260
  /**
1274
1261
  * Makes an HTTP request to the API with retries and exponential backoff
1275
1262
  * @param path - The API endpoint path (without prefix, e.g., '/agents')
@@ -1289,7 +1276,7 @@ var BaseResource = class _BaseResource {
1289
1276
  } = this.options;
1290
1277
  const fetchFn = customFetch || fetch;
1291
1278
  let delay = backoffMs;
1292
- const fullPath = this.shouldApplyPrefix(path) ? `${this.apiPrefix}${path}` : path;
1279
+ const fullPath = `${this.apiPrefix}${path}`;
1293
1280
  for (let attempt = 0; attempt <= retries; attempt++) {
1294
1281
  try {
1295
1282
  const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${fullPath}`, {
@@ -1465,6 +1452,21 @@ var Agent = class extends BaseResource {
1465
1452
  body: { instructions, comment }
1466
1453
  });
1467
1454
  }
1455
+ /**
1456
+ * Clones this agent to a new stored agent in the database
1457
+ * @param params - Clone parameters including optional newId, newName, metadata, authorId, and requestContext
1458
+ * @returns Promise containing the created stored agent
1459
+ */
1460
+ clone(params) {
1461
+ const { requestContext, ...rest } = params || {};
1462
+ return this.request(`/agents/${this.agentId}/clone`, {
1463
+ method: "POST",
1464
+ body: {
1465
+ ...rest,
1466
+ requestContext: parseClientRequestContext(requestContext)
1467
+ }
1468
+ });
1469
+ }
1468
1470
  async generateLegacy(params) {
1469
1471
  const processedParams = {
1470
1472
  ...params,
@@ -4068,6 +4070,52 @@ var StoredAgent = class extends BaseResource {
4068
4070
  }
4069
4071
  };
4070
4072
 
4073
+ // src/resources/stored-scorer.ts
4074
+ var StoredScorer = class extends BaseResource {
4075
+ constructor(options, storedScorerId) {
4076
+ super(options);
4077
+ this.storedScorerId = storedScorerId;
4078
+ }
4079
+ /**
4080
+ * Retrieves details about the stored scorer definition
4081
+ * @param requestContext - Optional request context to pass as query parameter
4082
+ * @returns Promise containing stored scorer definition details
4083
+ */
4084
+ details(requestContext) {
4085
+ return this.request(
4086
+ `/stored/scorers/${encodeURIComponent(this.storedScorerId)}${requestContextQueryString(requestContext)}`
4087
+ );
4088
+ }
4089
+ /**
4090
+ * Updates the stored scorer definition with the provided fields
4091
+ * @param params - Fields to update
4092
+ * @param requestContext - Optional request context to pass as query parameter
4093
+ * @returns Promise containing the updated stored scorer definition
4094
+ */
4095
+ update(params, requestContext) {
4096
+ return this.request(
4097
+ `/stored/scorers/${encodeURIComponent(this.storedScorerId)}${requestContextQueryString(requestContext)}`,
4098
+ {
4099
+ method: "PATCH",
4100
+ body: params
4101
+ }
4102
+ );
4103
+ }
4104
+ /**
4105
+ * Deletes the stored scorer definition
4106
+ * @param requestContext - Optional request context to pass as query parameter
4107
+ * @returns Promise containing deletion confirmation
4108
+ */
4109
+ delete(requestContext) {
4110
+ return this.request(
4111
+ `/stored/scorers/${encodeURIComponent(this.storedScorerId)}${requestContextQueryString(requestContext)}`,
4112
+ {
4113
+ method: "DELETE"
4114
+ }
4115
+ );
4116
+ }
4117
+ };
4118
+
4071
4119
  // src/resources/workspace.ts
4072
4120
  var WorkspaceSkillResource = class extends BaseResource {
4073
4121
  constructor(options, workspaceId, skillName) {
@@ -4901,6 +4949,12 @@ var MastraClient = class extends BaseResource {
4901
4949
  searchParams.set("orderBy[direction]", params.orderBy.direction);
4902
4950
  }
4903
4951
  }
4952
+ if (params?.authorId) {
4953
+ searchParams.set("authorId", params.authorId);
4954
+ }
4955
+ if (params?.metadata) {
4956
+ searchParams.set("metadata", JSON.stringify(params.metadata));
4957
+ }
4904
4958
  const queryString = searchParams.toString();
4905
4959
  return this.request(`/stored/agents${queryString ? `?${queryString}` : ""}`);
4906
4960
  }
@@ -4924,6 +4978,58 @@ var MastraClient = class extends BaseResource {
4924
4978
  return new StoredAgent(this.options, storedAgentId);
4925
4979
  }
4926
4980
  // ============================================================================
4981
+ // Stored Scorer Definitions
4982
+ // ============================================================================
4983
+ /**
4984
+ * Lists all stored scorer definitions with optional pagination
4985
+ * @param params - Optional pagination and ordering parameters
4986
+ * @returns Promise containing paginated list of stored scorer definitions
4987
+ */
4988
+ listStoredScorers(params) {
4989
+ const searchParams = new URLSearchParams();
4990
+ if (params?.page !== void 0) {
4991
+ searchParams.set("page", String(params.page));
4992
+ }
4993
+ if (params?.perPage !== void 0) {
4994
+ searchParams.set("perPage", String(params.perPage));
4995
+ }
4996
+ if (params?.orderBy) {
4997
+ if (params.orderBy.field) {
4998
+ searchParams.set("orderBy[field]", params.orderBy.field);
4999
+ }
5000
+ if (params.orderBy.direction) {
5001
+ searchParams.set("orderBy[direction]", params.orderBy.direction);
5002
+ }
5003
+ }
5004
+ if (params?.authorId) {
5005
+ searchParams.set("authorId", params.authorId);
5006
+ }
5007
+ if (params?.metadata) {
5008
+ searchParams.set("metadata", JSON.stringify(params.metadata));
5009
+ }
5010
+ const queryString = searchParams.toString();
5011
+ return this.request(`/stored/scorers${queryString ? `?${queryString}` : ""}`);
5012
+ }
5013
+ /**
5014
+ * Creates a new stored scorer definition
5015
+ * @param params - Scorer definition configuration
5016
+ * @returns Promise containing the created stored scorer definition
5017
+ */
5018
+ createStoredScorer(params) {
5019
+ return this.request("/stored/scorers", {
5020
+ method: "POST",
5021
+ body: params
5022
+ });
5023
+ }
5024
+ /**
5025
+ * Gets a stored scorer definition instance by ID for further operations (details, update, delete)
5026
+ * @param storedScorerId - ID of the stored scorer definition
5027
+ * @returns StoredScorer instance
5028
+ */
5029
+ getStoredScorer(storedScorerId) {
5030
+ return new StoredScorer(this.options, storedScorerId);
5031
+ }
5032
+ // ============================================================================
4927
5033
  // System
4928
5034
  // ============================================================================
4929
5035
  /**
@@ -4951,6 +5057,23 @@ var MastraClient = class extends BaseResource {
4951
5057
  getWorkspace(workspaceId) {
4952
5058
  return new Workspace(this.options, workspaceId);
4953
5059
  }
5060
+ // ============================================================================
5061
+ // Vectors & Embedders
5062
+ // ============================================================================
5063
+ /**
5064
+ * Lists all available vector stores
5065
+ * @returns Promise containing list of available vector stores
5066
+ */
5067
+ listVectors() {
5068
+ return this.request("/vectors");
5069
+ }
5070
+ /**
5071
+ * Lists all available embedding models
5072
+ * @returns Promise containing list of available embedders
5073
+ */
5074
+ listEmbedders() {
5075
+ return this.request("/embedders");
5076
+ }
4954
5077
  };
4955
5078
 
4956
5079
  // src/tools.ts