@mastra/client-js 0.16.15 → 0.17.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.
package/dist/index.js CHANGED
@@ -144,11 +144,20 @@ var BaseResource = class {
144
144
  */
145
145
  async request(path, options = {}) {
146
146
  let lastError = null;
147
- const { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
147
+ const {
148
+ baseUrl,
149
+ retries = 3,
150
+ backoffMs = 100,
151
+ maxBackoffMs = 1e3,
152
+ headers = {},
153
+ credentials,
154
+ fetch: customFetch
155
+ } = this.options;
156
+ const fetchFn = customFetch || fetch;
148
157
  let delay = backoffMs;
149
158
  for (let attempt = 0; attempt <= retries; attempt++) {
150
159
  try {
151
- const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
160
+ const response = await fetchFn(`${baseUrl.replace(/\/$/, "")}${path}`, {
152
161
  ...options,
153
162
  headers: {
154
163
  ...options.body && !(options.body instanceof FormData) && (options.method === "POST" || options.method === "PUT") ? { "content-type": "application/json" } : {},
@@ -2211,6 +2220,142 @@ var Workflow = class extends BaseResource {
2211
2220
  }
2212
2221
  });
2213
2222
  }
2223
+ /**
2224
+ * Restarts an active workflow run synchronously without waiting for the workflow to complete
2225
+ * @param params - Object containing the runId and runtimeContext
2226
+ * @returns Promise containing success message
2227
+ */
2228
+ restart(params) {
2229
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2230
+ return this.request(`/api/workflows/${this.workflowId}/restart?runId=${params.runId}`, {
2231
+ method: "POST",
2232
+ body: {
2233
+ runtimeContext,
2234
+ tracingOptions: params.tracingOptions
2235
+ }
2236
+ });
2237
+ }
2238
+ /**
2239
+ * Restarts an active workflow run asynchronously
2240
+ * @param params - Object containing the runId and runtimeContext
2241
+ * @returns Promise containing the workflow restart results
2242
+ */
2243
+ restartAsync(params) {
2244
+ const runtimeContext = parseClientRuntimeContext(params.runtimeContext);
2245
+ return this.request(`/api/workflows/${this.workflowId}/restart-async?runId=${params.runId}`, {
2246
+ method: "POST",
2247
+ body: {
2248
+ runtimeContext,
2249
+ tracingOptions: params.tracingOptions
2250
+ }
2251
+ });
2252
+ }
2253
+ /**
2254
+ * Restart all active workflow runs synchronously without waiting for the workflow to complete
2255
+ * @returns Promise containing success message
2256
+ */
2257
+ restartAllActiveWorkflowRuns() {
2258
+ return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs`, {
2259
+ method: "POST"
2260
+ });
2261
+ }
2262
+ /**
2263
+ * Restart all active workflow runs asynchronously
2264
+ * @returns Promise containing success message
2265
+ */
2266
+ restartAllActiveWorkflowRunsAsync() {
2267
+ return this.request(`/api/workflows/${this.workflowId}/restart-all-active-workflow-runs-async`, {
2268
+ method: "POST"
2269
+ });
2270
+ }
2271
+ /**
2272
+ * Time travels a workflow run synchronously without waiting for the workflow to complete
2273
+ * @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, runtimeContext and tracingOptions
2274
+ * @returns Promise containing success message
2275
+ */
2276
+ timeTravel({
2277
+ runId,
2278
+ runtimeContext: paramsRuntimeContext,
2279
+ ...params
2280
+ }) {
2281
+ const runtimeContext = parseClientRuntimeContext(paramsRuntimeContext);
2282
+ return this.request(`/api/workflows/${this.workflowId}/time-travel?runId=${runId}`, {
2283
+ method: "POST",
2284
+ body: {
2285
+ ...params,
2286
+ runtimeContext
2287
+ }
2288
+ });
2289
+ }
2290
+ /**
2291
+ * Time travels a workflow run asynchronously
2292
+ * @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, runtimeContext and tracingOptions
2293
+ * @returns Promise containing the workflow time travel results
2294
+ */
2295
+ timeTravelAsync({
2296
+ runId,
2297
+ runtimeContext: paramsRuntimeContext,
2298
+ ...params
2299
+ }) {
2300
+ const runtimeContext = parseClientRuntimeContext(paramsRuntimeContext);
2301
+ return this.request(`/api/workflows/${this.workflowId}/time-travel-async?runId=${runId}`, {
2302
+ method: "POST",
2303
+ body: {
2304
+ ...params,
2305
+ runtimeContext
2306
+ }
2307
+ });
2308
+ }
2309
+ /**
2310
+ * Time travels a workflow run and returns a stream
2311
+ * @param params - Object containing the runId, step, inputData, resumeData, initialState, context, nestedStepsContext, runtimeContext and tracingOptions
2312
+ * @returns Promise containing the workflow execution results
2313
+ */
2314
+ async timeTravelStream({ runId, runtimeContext: paramsRuntimeContext, ...params }) {
2315
+ const runtimeContext = parseClientRuntimeContext(paramsRuntimeContext);
2316
+ const response = await this.request(
2317
+ `/api/workflows/${this.workflowId}/time-travel-stream?runId=${runId}`,
2318
+ {
2319
+ method: "POST",
2320
+ body: {
2321
+ ...params,
2322
+ runtimeContext
2323
+ },
2324
+ stream: true
2325
+ }
2326
+ );
2327
+ if (!response.ok) {
2328
+ throw new Error(`Failed to time travel workflow: ${response.statusText}`);
2329
+ }
2330
+ if (!response.body) {
2331
+ throw new Error("Response body is null");
2332
+ }
2333
+ let failedChunk = void 0;
2334
+ const transformStream = new TransformStream({
2335
+ start() {
2336
+ },
2337
+ async transform(chunk, controller) {
2338
+ try {
2339
+ const decoded = new TextDecoder().decode(chunk);
2340
+ const chunks = decoded.split(RECORD_SEPARATOR);
2341
+ for (const chunk2 of chunks) {
2342
+ if (chunk2) {
2343
+ const newChunk = failedChunk ? failedChunk + chunk2 : chunk2;
2344
+ try {
2345
+ const parsedChunk = JSON.parse(newChunk);
2346
+ controller.enqueue(parsedChunk);
2347
+ failedChunk = void 0;
2348
+ } catch {
2349
+ failedChunk = newChunk;
2350
+ }
2351
+ }
2352
+ }
2353
+ } catch {
2354
+ }
2355
+ }
2356
+ });
2357
+ return response.body.pipeThrough(transformStream);
2358
+ }
2214
2359
  };
2215
2360
 
2216
2361
  // src/resources/a2a.ts
@@ -2841,14 +2986,18 @@ var MastraClient = class extends BaseResource {
2841
2986
  /**
2842
2987
  * Retrieves all available agents
2843
2988
  * @param runtimeContext - Optional runtime context to pass as query parameter
2989
+ * @param partial - Optional flag to return minimal data without schemas
2844
2990
  * @returns Promise containing map of agent IDs to agent details
2845
2991
  */
2846
- getAgents(runtimeContext) {
2992
+ getAgents(runtimeContext, partial) {
2847
2993
  const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
2848
2994
  const searchParams = new URLSearchParams();
2849
2995
  if (runtimeContextParam) {
2850
2996
  searchParams.set("runtimeContext", runtimeContextParam);
2851
2997
  }
2998
+ if (partial) {
2999
+ searchParams.set("partial", "true");
3000
+ }
2852
3001
  const queryString = searchParams.toString();
2853
3002
  return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
2854
3003
  }
@@ -3007,14 +3156,18 @@ var MastraClient = class extends BaseResource {
3007
3156
  /**
3008
3157
  * Retrieves all available workflows
3009
3158
  * @param runtimeContext - Optional runtime context to pass as query parameter
3159
+ * @param partial - Optional flag to return minimal data without schemas
3010
3160
  * @returns Promise containing map of workflow IDs to workflow details
3011
3161
  */
3012
- getWorkflows(runtimeContext) {
3162
+ getWorkflows(runtimeContext, partial) {
3013
3163
  const runtimeContextParam = base64RuntimeContext(parseClientRuntimeContext(runtimeContext));
3014
3164
  const searchParams = new URLSearchParams();
3015
3165
  if (runtimeContextParam) {
3016
3166
  searchParams.set("runtimeContext", runtimeContextParam);
3017
3167
  }
3168
+ if (partial) {
3169
+ searchParams.set("partial", "true");
3170
+ }
3018
3171
  const queryString = searchParams.toString();
3019
3172
  return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
3020
3173
  }