@mastra/client-js 1.53.0-alpha.7 → 1.53.0-alpha.8

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
@@ -368,6 +368,23 @@ function mergeAbortSignals(...signals) {
368
368
  for (const signal of defined) signal.addEventListener("abort", onAbort);
369
369
  return controller.signal;
370
370
  }
371
+ /**
372
+ * Whether an error carries an HTTP status that retrying cannot fix: any 4xx
373
+ * client error (e.g. 401/403 auth failures) or 501 Not Implemented.
374
+ */
375
+ function isTerminalHttpError(error) {
376
+ const status = error?.status;
377
+ return typeof status === "number" && (status >= 400 && status < 500 || status === 501);
378
+ }
379
+ /**
380
+ * Whether a failed resubscribe should end a long-lived subscription instead of
381
+ * retrying. Like {@link isTerminalHttpError}, but 408 Request Timeout and
382
+ * 429 Too Many Requests stay retryable because they mean "try again later".
383
+ */
384
+ function isTerminalReconnectError(error) {
385
+ const status = error?.status;
386
+ return isTerminalHttpError(error) && status !== 408 && status !== 429;
387
+ }
371
388
  //#endregion
372
389
  //#region src/utils/client-tool-model-output.ts
373
390
  /**
@@ -601,8 +618,7 @@ var BaseResource = class {
601
618
  } catch (error) {
602
619
  lastError = error;
603
620
  if (signal?.aborted || error?.name === "AbortError") throw error;
604
- const status = error.status;
605
- if (status !== void 0 && (status >= 400 && status < 500 || status === 501)) throw error;
621
+ if (isTerminalHttpError(error)) throw error;
606
622
  if (attempt === retries) break;
607
623
  await new Promise((resolve, reject) => {
608
624
  const timer = setTimeout(() => {
@@ -1212,10 +1228,8 @@ var Agent = class extends BaseResource {
1212
1228
  response = await requestSubscription();
1213
1229
  break;
1214
1230
  } catch (error) {
1215
- if (isClosed() || attempts >= reconnectOptions.maxRetries) {
1216
- if (isClosed()) return;
1217
- throw error;
1218
- }
1231
+ if (isClosed()) return;
1232
+ if (isTerminalReconnectError(error) || attempts >= reconnectOptions.maxRetries) throw error;
1219
1233
  }
1220
1234
  }
1221
1235
  }
@@ -2508,6 +2522,10 @@ var Agent = class extends BaseResource {
2508
2522
  * Only supported when the target agent is a durable agent (createDurableAgent).
2509
2523
  * The server rebuilds the runtime state from the persisted snapshot, replays
2510
2524
  * past chunks, and continues the loop to completion.
2525
+ *
2526
+ * Responds with 409 when the run is not orphaned: another execution still
2527
+ * owns it (retry once its lease lapses), it is already being recovered, or it
2528
+ * is suspended (use `resumeStream` instead). To follow a live run, use `observe`.
2511
2529
  */
2512
2530
  async recover(params) {
2513
2531
  const body = {
@@ -6305,6 +6323,11 @@ var AgentControllerSession = class extends BaseResource {
6305
6323
  try {
6306
6324
  reconnectedResponse = await requestStream();
6307
6325
  } catch (error) {
6326
+ if (cancelled) return;
6327
+ if (isTerminalReconnectError(error)) {
6328
+ safeOnError(error);
6329
+ return;
6330
+ }
6308
6331
  result = {
6309
6332
  kind: "transport_error",
6310
6333
  error
@@ -8017,6 +8040,15 @@ var MastraClient = class extends BaseResource {
8017
8040
  return this.request(`/datasets/${encodeURIComponent(datasetId)}/experiments/${encodeURIComponent(experimentId)}`);
8018
8041
  }
8019
8042
  /**
8043
+ * Gets an experiment by ID regardless of dataset association, including its
8044
+ * `datasetId` (null for experiments orphaned by dataset deletion). When tenancy
8045
+ * fields are supplied, experiments outside the tenant are reported as not found.
8046
+ */
8047
+ getExperiment(experimentId, options) {
8048
+ const qs = buildTenancyQuery(options);
8049
+ return this.request(`/experiments/${encodeURIComponent(experimentId)}${qs}`);
8050
+ }
8051
+ /**
8020
8052
  * Deletes a dataset experiment and its results. Tenancy fields, when provided,
8021
8053
  * scope the dataset lookup on the server side.
8022
8054
  *