@mastra/client-js 1.0.0-beta.13 → 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
  }
@@ -3077,13 +3121,26 @@ var Workflow = class extends BaseResource {
3077
3121
  /**
3078
3122
  * Retrieves the execution result for a specific workflow run by its ID
3079
3123
  * @param runId - The ID of the workflow run to retrieve the execution result for
3080
- * @param requestContext - Optional request context to pass as query parameter
3124
+ * @param options - Optional configuration
3125
+ * @param options.requestContext - Optional request context to pass as query parameter
3126
+ * @param options.fields - Optional array of fields to return (e.g., ['status', 'result']). Available fields: status, result, error, payload, steps, activeStepsPath, serializedStepGraph. Omitting this returns all fields.
3127
+ * @param options.withNestedWorkflows - Whether to include nested workflow data in steps. Defaults to true. Set to false for better performance when you don't need nested workflow details.
3081
3128
  * @returns Promise containing the workflow run execution result
3082
3129
  */
3083
- runExecutionResult(runId, requestContext) {
3084
- return this.request(
3085
- `/api/workflows/${this.workflowId}/runs/${runId}/execution-result${requestContextQueryString(requestContext)}`
3086
- );
3130
+ runExecutionResult(runId, options) {
3131
+ const searchParams = new URLSearchParams();
3132
+ if (options?.fields && options.fields.length > 0) {
3133
+ searchParams.set("fields", options.fields.join(","));
3134
+ }
3135
+ if (options?.withNestedWorkflows !== void 0) {
3136
+ searchParams.set("withNestedWorkflows", String(options.withNestedWorkflows));
3137
+ }
3138
+ const requestContextParam = base64RequestContext(parseClientRequestContext(options?.requestContext));
3139
+ if (requestContextParam) {
3140
+ searchParams.set("requestContext", requestContextParam);
3141
+ }
3142
+ const queryString = searchParams.size > 0 ? `?${searchParams.toString()}` : "";
3143
+ return this.request(`/api/workflows/${this.workflowId}/runs/${runId}/execution-result${queryString}`);
3087
3144
  }
3088
3145
  /**
3089
3146
  * Creates a new workflow run
@@ -3659,9 +3716,12 @@ var Observability = class extends BaseResource {
3659
3716
  return this.request(`/api/observability/traces/${traceId}`);
3660
3717
  }
3661
3718
  /**
3662
- * Retrieves paginated list of traces with optional filtering
3663
- * @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)
3664
3723
  * @returns Promise containing paginated traces and pagination info
3724
+ * @deprecated Use {@link listTraces} instead for new features like ordering and more filters.
3665
3725
  */
3666
3726
  getTraces(params) {
3667
3727
  const { pagination, filters } = params;
@@ -3694,25 +3754,34 @@ var Observability = class extends BaseResource {
3694
3754
  const queryString = searchParams.toString();
3695
3755
  return this.request(`/api/observability/traces${queryString ? `?${queryString}` : ""}`);
3696
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
+ }
3697
3768
  /**
3698
3769
  * Retrieves scores by trace ID and span ID
3699
3770
  * @param params - Parameters containing trace ID, span ID, and pagination options
3700
3771
  * @returns Promise containing scores and pagination info
3701
3772
  */
3702
3773
  listScoresBySpan(params) {
3703
- const { traceId, spanId, page, perPage } = params;
3704
- const searchParams = new URLSearchParams();
3705
- if (page !== void 0) {
3706
- searchParams.set("page", String(page));
3707
- }
3708
- if (perPage !== void 0) {
3709
- searchParams.set("perPage", String(perPage));
3710
- }
3711
- const queryString = searchParams.toString();
3774
+ const { traceId, spanId, ...pagination } = params;
3775
+ const queryString = toQueryParams(pagination);
3712
3776
  return this.request(
3713
3777
  `/api/observability/traces/${encodeURIComponent(traceId)}/${encodeURIComponent(spanId)}/scores${queryString ? `?${queryString}` : ""}`
3714
3778
  );
3715
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
+ */
3716
3785
  score(params) {
3717
3786
  return this.request(`/api/observability/traces/score`, {
3718
3787
  method: "POST",
@@ -4262,9 +4331,27 @@ var MastraClient = class extends BaseResource {
4262
4331
  getTrace(traceId) {
4263
4332
  return this.observability.getTrace(traceId);
4264
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
+ */
4265
4342
  getTraces(params) {
4266
4343
  return this.observability.getTraces(params);
4267
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
+ }
4268
4355
  listScoresBySpan(params) {
4269
4356
  return this.observability.listScoresBySpan(params);
4270
4357
  }
@@ -4317,6 +4404,16 @@ var MastraClient = class extends BaseResource {
4317
4404
  getStoredAgent(storedAgentId) {
4318
4405
  return new StoredAgent(this.options, storedAgentId);
4319
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
+ }
4320
4417
  };
4321
4418
 
4322
4419
  // src/tools.ts