@mastra/client-js 1.60.1-alpha.2 → 1.60.1-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.
@@ -3,7 +3,7 @@ name: mastra-client-js
3
3
  description: Documentation for @mastra/client-js. Use when working with @mastra/client-js APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/client-js"
6
- version: "1.60.1-alpha.2"
6
+ version: "1.60.1-alpha.4"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,16 +1,16 @@
1
1
  {
2
- "version": "1.60.1-alpha.2",
2
+ "version": "1.60.1-alpha.4",
3
3
  "package": "@mastra/client-js",
4
4
  "exports": {
5
5
  "ClientTool": {
6
6
  "types": "dist/tools.d.ts",
7
7
  "implementation": "dist/index.js",
8
- "line": 9628
8
+ "line": 9659
9
9
  },
10
10
  "MastraClient": {
11
11
  "types": "dist/client.d.ts",
12
12
  "implementation": "dist/index.js",
13
- "line": 7771
13
+ "line": 7802
14
14
  },
15
15
  "MastraClientError": {
16
16
  "types": "dist/types.d.ts",
@@ -20,17 +20,17 @@
20
20
  "agentControllerMessageText": {
21
21
  "types": "dist/resources/agent-controller.d.ts",
22
22
  "implementation": "dist/index.js",
23
- "line": 7748
23
+ "line": 7779
24
24
  },
25
25
  "createTool": {
26
26
  "types": "dist/tools.d.ts",
27
27
  "implementation": "dist/index.js",
28
- "line": 9642
28
+ "line": 9673
29
29
  },
30
30
  "isKnownAgentControllerEvent": {
31
31
  "types": "dist/resources/agent-controller.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 7111
33
+ "line": 7142
34
34
  }
35
35
  },
36
36
  "modules": {}
@@ -183,6 +183,8 @@ const testAgent = async () => {
183
183
 
184
184
  `MastraClient` accepts optional parameters like `retries`, `backoffMs`, and `headers` to control request behavior. These parameters are useful for controlling retry behavior and including diagnostic metadata.
185
185
 
186
+ By default, retries apply to read requests only. `GET`, `HEAD`, and `OPTIONS` are retried on failure, while `POST`, `PUT`, `PATCH`, and `DELETE` are sent once unless you set `retries` explicitly, so a failed write can't repeat a state-changing request such as an agent generation or workflow start. The observability queries that travel as `POST` only read server state, so `aggregateTraces()`, `aggregateSpans()`, `queryTraceThreads()`, and `querySpans()` keep the read default.
187
+
186
188
  ```typescript
187
189
  import { MastraClient } from '@mastra/client-js'
188
190
 
@@ -43,7 +43,7 @@ You can also pass `requestContext` as a `Record<string, any>`.
43
43
 
44
44
  **baseUrl** (`string`): The base URL for the Mastra API. All requests will be sent relative to this URL.
45
45
 
46
- **retries** (`number`): The number of times a request will be retried on failure before throwing an error. (Default: `3`)
46
+ **retries** (`number`): The number of times a request will be retried on failure before throwing an error. Retries apply to read requests (GET, HEAD, OPTIONS) by default, and to the observability queries that read server state even though they are sent as POST (aggregateTraces, aggregateSpans, queryTraceThreads, querySpans). Write requests (POST, PUT, PATCH, DELETE) are sent once unless you set this explicitly, so a server error can't repeat a state-changing request. (Default: `3 for read requests, 0 for write requests`)
47
47
 
48
48
  **backoffMs** (`number`): The initial delay in milliseconds before retrying a failed request. This value is doubled with each retry (exponential backoff). (Default: `300`)
49
49
 
package/dist/index.cjs CHANGED
@@ -1211,6 +1211,24 @@ var MastraClientError = class extends Error {
1211
1211
  }
1212
1212
  };
1213
1213
  // src/resources/base.ts
1214
+ /**
1215
+ * Retry attempts applied when the caller has not configured one. Only read
1216
+ * methods keep this default; every other method is attempted once unless the
1217
+ * caller opts in with an explicit `retries` count.
1218
+ */
1219
+ const DEFAULT_RETRIES = 3;
1220
+ /**
1221
+ * HTTP methods that read server state. A retried read only repeats a lookup,
1222
+ * so it is safe to retry by default. Methods outside this set (POST, PUT,
1223
+ * PATCH, DELETE and anything unrecognized) may already have applied a side
1224
+ * effect when the attempt failed, so they are not retried unless the caller
1225
+ * asks for it.
1226
+ */
1227
+ const READ_METHODS = /* @__PURE__ */ new Set([
1228
+ "GET",
1229
+ "HEAD",
1230
+ "OPTIONS"
1231
+ ]);
1214
1232
  var BaseResource = class {
1215
1233
  options;
1216
1234
  apiPrefix;
@@ -1219,6 +1237,14 @@ var BaseResource = class {
1219
1237
  this.apiPrefix = normalizeRoutePath(options.apiPrefix ?? "/api");
1220
1238
  }
1221
1239
  /**
1240
+ * Retry count for a request that only reads server state even though its HTTP method is not a
1241
+ * read method, such as a query sent as POST. It keeps the read default unless the client was
1242
+ * configured with an explicit `retries` count, which always wins.
1243
+ */
1244
+ readRetries() {
1245
+ return this.options.retries ?? DEFAULT_RETRIES;
1246
+ }
1247
+ /**
1222
1248
  * Makes an HTTP request to the API with retries and exponential backoff
1223
1249
  * @param path - The API endpoint path (without prefix, e.g., '/agents')
1224
1250
  * @param options - Optional request configuration
@@ -1226,9 +1252,10 @@ var BaseResource = class {
1226
1252
  */
1227
1253
  async request(path, options = {}) {
1228
1254
  let lastError = null;
1229
- const { baseUrl, retries: defaultRetries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials, fetch: customFetch } = this.options;
1255
+ const { baseUrl, retries: configuredRetries, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials, fetch: customFetch } = this.options;
1230
1256
  const { retries: requestRetries, ...fetchOptions } = options;
1231
- const retries = requestRetries ?? defaultRetries;
1257
+ const method = (fetchOptions.method ?? "GET").toUpperCase();
1258
+ const retries = requestRetries ?? configuredRetries ?? (READ_METHODS.has(method) ? DEFAULT_RETRIES : 0);
1232
1259
  if (!Number.isSafeInteger(retries) || retries < 0) throw new RangeError("retries must be a non-negative safe integer");
1233
1260
  const signal = mergeAbortSignals(this.options.abortSignal, fetchOptions.signal);
1234
1261
  const fetchFn = customFetch || fetch;
@@ -5532,6 +5559,7 @@ var Observability = class extends BaseResource {
5532
5559
  return this.request("/observability/traces/aggregate", {
5533
5560
  method: "POST",
5534
5561
  body: params,
5562
+ retries: this.readRetries(),
5535
5563
  signal: options?.signal
5536
5564
  });
5537
5565
  }
@@ -5543,7 +5571,8 @@ var Observability = class extends BaseResource {
5543
5571
  aggregateSpans(params) {
5544
5572
  return this.request("/observability/spans/aggregate", {
5545
5573
  method: "POST",
5546
- body: params
5574
+ body: params,
5575
+ retries: this.readRetries()
5547
5576
  });
5548
5577
  }
5549
5578
  /** Returns canonical and observed fields available to the advanced trace-query grammar. */
@@ -5573,7 +5602,8 @@ var Observability = class extends BaseResource {
5573
5602
  queryTraceThreads(params) {
5574
5603
  return this.request("/observability/threads/query", {
5575
5604
  method: "POST",
5576
- body: params
5605
+ body: params,
5606
+ retries: this.readRetries()
5577
5607
  });
5578
5608
  }
5579
5609
  /**
@@ -5585,7 +5615,8 @@ var Observability = class extends BaseResource {
5585
5615
  querySpans(params) {
5586
5616
  return this.request("/observability/spans/query", {
5587
5617
  method: "POST",
5588
- body: params
5618
+ body: params,
5619
+ retries: this.readRetries()
5589
5620
  });
5590
5621
  }
5591
5622
  /**