@mastra/client-js 1.0.0-beta.14 → 1.0.0-beta.15

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
@@ -1061,6 +1061,41 @@ async function processDataStream({
1061
1061
  }
1062
1062
  }
1063
1063
  }
1064
+ function isComplexValue(value) {
1065
+ if (value === null || value === void 0) return false;
1066
+ if (value instanceof Date) return false;
1067
+ return typeof value === "object";
1068
+ }
1069
+ function serializeQueryValue(value) {
1070
+ if (value instanceof Date) {
1071
+ return value.toISOString();
1072
+ }
1073
+ if (isComplexValue(value)) {
1074
+ return JSON.stringify(value, (_key, val) => {
1075
+ if (val instanceof Date) {
1076
+ return val.toISOString();
1077
+ }
1078
+ return val;
1079
+ });
1080
+ }
1081
+ return String(value);
1082
+ }
1083
+ function toQueryParams(params, flattenKeys = []) {
1084
+ const searchParams = new URLSearchParams();
1085
+ const keysToFlatten = flattenKeys;
1086
+ function addParams(obj) {
1087
+ for (const [key, value] of Object.entries(obj)) {
1088
+ if (value === void 0 || value === null) continue;
1089
+ if (keysToFlatten.includes(key) && typeof value === "object" && !Array.isArray(value) && !(value instanceof Date)) {
1090
+ addParams(value);
1091
+ } else {
1092
+ searchParams.set(key, serializeQueryValue(value));
1093
+ }
1094
+ }
1095
+ }
1096
+ addParams(params);
1097
+ return searchParams.toString();
1098
+ }
1064
1099
  function parseClientRequestContext(requestContext) {
1065
1100
  if (requestContext) {
1066
1101
  if (requestContext instanceof RequestContext) {
@@ -2424,7 +2459,8 @@ var Agent = class extends BaseResource {
2424
2459
  */
2425
2460
  resetModel() {
2426
2461
  return this.request(`/api/agents/${this.agentId}/model/reset`, {
2427
- method: "POST"
2462
+ method: "POST",
2463
+ body: {}
2428
2464
  });
2429
2465
  }
2430
2466
  /**
@@ -2706,7 +2742,8 @@ var Run = class extends BaseResource {
2706
2742
  inputData: params?.inputData,
2707
2743
  initialState: params?.initialState,
2708
2744
  requestContext,
2709
- tracingOptions: params.tracingOptions
2745
+ tracingOptions: params.tracingOptions,
2746
+ perStep: params.perStep
2710
2747
  }
2711
2748
  });
2712
2749
  }
@@ -2719,6 +2756,7 @@ var Run = class extends BaseResource {
2719
2756
  step,
2720
2757
  resumeData,
2721
2758
  tracingOptions,
2759
+ perStep,
2722
2760
  ...rest
2723
2761
  }) {
2724
2762
  const requestContext = parseClientRequestContext(rest.requestContext);
@@ -2728,7 +2766,8 @@ var Run = class extends BaseResource {
2728
2766
  step,
2729
2767
  resumeData,
2730
2768
  requestContext,
2731
- tracingOptions
2769
+ tracingOptions,
2770
+ perStep
2732
2771
  }
2733
2772
  });
2734
2773
  }
@@ -2748,7 +2787,8 @@ var Run = class extends BaseResource {
2748
2787
  initialState: params.initialState,
2749
2788
  requestContext,
2750
2789
  tracingOptions: params.tracingOptions,
2751
- resourceId: params.resourceId
2790
+ resourceId: params.resourceId,
2791
+ perStep: params.perStep
2752
2792
  }
2753
2793
  }).then(deserializeWorkflowError);
2754
2794
  }
@@ -2770,7 +2810,8 @@ var Run = class extends BaseResource {
2770
2810
  initialState: params.initialState,
2771
2811
  requestContext,
2772
2812
  tracingOptions: params.tracingOptions,
2773
- resourceId: params.resourceId
2813
+ resourceId: params.resourceId,
2814
+ perStep: params.perStep
2774
2815
  },
2775
2816
  stream: true
2776
2817
  }
@@ -2824,7 +2865,8 @@ var Run = class extends BaseResource {
2824
2865
  requestContext,
2825
2866
  closeOnSuspend: params.closeOnSuspend,
2826
2867
  tracingOptions: params.tracingOptions,
2827
- resourceId: params.resourceId
2868
+ resourceId: params.resourceId,
2869
+ perStep: params.perStep
2828
2870
  },
2829
2871
  stream: true
2830
2872
  }
@@ -2872,7 +2914,8 @@ var Run = class extends BaseResource {
2872
2914
  step: params.step,
2873
2915
  resumeData: params.resumeData,
2874
2916
  requestContext,
2875
- tracingOptions: params.tracingOptions
2917
+ tracingOptions: params.tracingOptions,
2918
+ perStep: params.perStep
2876
2919
  }
2877
2920
  }).then(deserializeWorkflowError);
2878
2921
  }
@@ -2893,7 +2936,8 @@ var Run = class extends BaseResource {
2893
2936
  step: params.step,
2894
2937
  resumeData: params.resumeData,
2895
2938
  requestContext,
2896
- tracingOptions: params.tracingOptions
2939
+ tracingOptions: params.tracingOptions,
2940
+ perStep: params.perStep
2897
2941
  },
2898
2942
  stream: true
2899
2943
  }
@@ -3672,9 +3716,12 @@ var Observability = class extends BaseResource {
3672
3716
  return this.request(`/api/observability/traces/${traceId}`);
3673
3717
  }
3674
3718
  /**
3675
- * Retrieves paginated list of traces with optional filtering
3676
- * @param params - Parameters for pagination and filtering
3719
+ * Retrieves paginated list of traces with optional filtering.
3720
+ * This is the legacy API preserved for backward compatibility.
3721
+ *
3722
+ * @param params - Parameters for pagination and filtering (legacy format)
3677
3723
  * @returns Promise containing paginated traces and pagination info
3724
+ * @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
3678
3725
  */
3679
3726
  getTraces(params) {
3680
3727
  const { pagination, filters } = params;
@@ -3707,25 +3754,34 @@ var Observability = class extends BaseResource {
3707
3754
  const queryString = searchParams.toString();
3708
3755
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
3709
3756
  }
3757
+ /**
3758
+ * Retrieves paginated list of traces with optional filtering and sorting.
3759
+ * This is the new API with improved filtering options.
3760
+ *
3761
+ * @param params - Parameters for pagination, filtering, and ordering
3762
+ * @returns Promise containing paginated traces and pagination info
3763
+ */
3764
+ listTraces(params = {}) {
3765
+ const queryString = toQueryParams(params, ["filters", "pagination", "orderBy"]);
3766
+ return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
3767
+ }
3710
3768
  /**
3711
3769
  * Retrieves scores by trace ID and span ID
3712
3770
  * @param params - Parameters containing trace ID, span ID, and pagination options
3713
3771
  * @returns Promise containing scores and pagination info
3714
3772
  */
3715
3773
  listScoresBySpan(params) {
3716
- const { traceId, spanId, page, perPage } = params;
3717
- const searchParams = new URLSearchParams();
3718
- if (page !== void 0) {
3719
- searchParams.set("page", String(page));
3720
- }
3721
- if (perPage !== void 0) {
3722
- searchParams.set("perPage", String(perPage));
3723
- }
3724
- const queryString = searchParams.toString();
3774
+ const { traceId, spanId, ...pagination } = params;
3775
+ const queryString = toQueryParams(pagination);
3725
3776
  return this.request(
3726
3777
  `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
3727
3778
  );
3728
3779
  }
3780
+ /**
3781
+ * Scores one or more traces using a specified scorer.
3782
+ * @param params - Scorer name and targets to score
3783
+ * @returns Promise containing the scoring status
3784
+ */
3729
3785
  score(params) {
3730
3786
  return this.request(`/api/observability/traces/score`, {
3731
3787
  method: "POST",
@@ -4275,9 +4331,27 @@ var MastraClient = class extends BaseResource {
4275
4331
  getTrace(traceId) {
4276
4332
  return this.observability.getTrace(traceId);
4277
4333
  }
4334
+ /**
4335
+ * Retrieves paginated list of traces with optional filtering.
4336
+ * This is the legacy API preserved for backward compatibility.
4337
+ *
4338
+ * @param params - Parameters for pagination and filtering (legacy format)
4339
+ * @returns Promise containing paginated traces and pagination info
4340
+ * @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
4341
+ */
4278
4342
  getTraces(params) {
4279
4343
  return this.observability.getTraces(params);
4280
4344
  }
4345
+ /**
4346
+ * Retrieves paginated list of traces with optional filtering and sorting.
4347
+ * This is the new API with improved filtering options.
4348
+ *
4349
+ * @param params - Parameters for pagination, filtering, and ordering
4350
+ * @returns Promise containing paginated traces and pagination info
4351
+ */
4352
+ listTraces(params = {}) {
4353
+ return this.observability.listTraces(params);
4354
+ }
4281
4355
  listScoresBySpan(params) {
4282
4356
  return this.observability.listScoresBySpan(params);
4283
4357
  }
@@ -4330,6 +4404,16 @@ var MastraClient = class extends BaseResource {
4330
4404
  getStoredAgent(storedAgentId) {
4331
4405
  return new StoredAgent(this.options, storedAgentId);
4332
4406
  }
4407
+ // ============================================================================
4408
+ // System
4409
+ // ============================================================================
4410
+ /**
4411
+ * Retrieves installed Mastra packages and their versions
4412
+ * @returns Promise containing the list of installed Mastra packages
4413
+ */
4414
+ getSystemPackages() {
4415
+ return this.request("/api/system/packages");
4416
+ }
4333
4417
  };
4334
4418
 
4335
4419
  // src/tools.ts