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