@mastra/client-js 1.0.0-beta.5 → 1.0.0-beta.7
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 +109 -0
- package/README.md +2 -0
- package/dist/client.d.ts +8 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/index.cjs +86 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -30
- package/dist/index.js.map +1 -1
- package/dist/resources/a2a.d.ts.map +1 -1
- package/dist/resources/agent-builder.d.ts +2 -8
- package/dist/resources/agent-builder.d.ts.map +1 -1
- package/dist/resources/base.d.ts.map +1 -1
- package/dist/resources/workflow.d.ts +11 -4
- package/dist/resources/workflow.d.ts.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/process-mastra-stream.d.ts +1 -1
- package/dist/utils/process-mastra-stream.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 { RequestContext } from '@mastra/core/request-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 parseClientRequestContext(requestContext) {
|
|
@@ -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" } : {},
|
|
@@ -1611,15 +1615,21 @@ var Workflow = class extends BaseResource {
|
|
|
1611
1615
|
if (params?.toDate) {
|
|
1612
1616
|
searchParams.set("toDate", params.toDate.toISOString());
|
|
1613
1617
|
}
|
|
1614
|
-
if (params?.
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1618
|
+
if (params?.page !== void 0) {
|
|
1619
|
+
searchParams.set("page", String(params.page));
|
|
1620
|
+
}
|
|
1621
|
+
if (params?.perPage !== void 0) {
|
|
1622
|
+
searchParams.set("perPage", String(params.perPage));
|
|
1623
|
+
}
|
|
1624
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
1625
|
+
if (params.limit === false) {
|
|
1626
|
+
searchParams.set("limit", "false");
|
|
1627
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
1628
|
+
searchParams.set("limit", String(params.limit));
|
|
1619
1629
|
}
|
|
1620
1630
|
}
|
|
1621
|
-
if (params?.
|
|
1622
|
-
searchParams.set("
|
|
1631
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
1632
|
+
searchParams.set("offset", String(params.offset));
|
|
1623
1633
|
}
|
|
1624
1634
|
if (params?.resourceId) {
|
|
1625
1635
|
searchParams.set("resourceId", params.resourceId);
|
|
@@ -1686,6 +1696,7 @@ var Workflow = class extends BaseResource {
|
|
|
1686
1696
|
return this.start({
|
|
1687
1697
|
runId,
|
|
1688
1698
|
inputData: p.inputData,
|
|
1699
|
+
initialState: p.initialState,
|
|
1689
1700
|
requestContext: p.requestContext,
|
|
1690
1701
|
tracingOptions: p.tracingOptions
|
|
1691
1702
|
});
|
|
@@ -1694,12 +1705,18 @@ var Workflow = class extends BaseResource {
|
|
|
1694
1705
|
return this.startAsync({
|
|
1695
1706
|
runId,
|
|
1696
1707
|
inputData: p.inputData,
|
|
1708
|
+
initialState: p.initialState,
|
|
1697
1709
|
requestContext: p.requestContext,
|
|
1698
1710
|
tracingOptions: p.tracingOptions
|
|
1699
1711
|
});
|
|
1700
1712
|
},
|
|
1701
1713
|
stream: async (p) => {
|
|
1702
|
-
return this.stream({
|
|
1714
|
+
return this.stream({
|
|
1715
|
+
runId,
|
|
1716
|
+
inputData: p.inputData,
|
|
1717
|
+
initialState: p.initialState,
|
|
1718
|
+
requestContext: p.requestContext
|
|
1719
|
+
});
|
|
1703
1720
|
},
|
|
1704
1721
|
resume: async (p) => {
|
|
1705
1722
|
return this.resume({
|
|
@@ -1731,14 +1748,19 @@ var Workflow = class extends BaseResource {
|
|
|
1731
1748
|
}
|
|
1732
1749
|
/**
|
|
1733
1750
|
* Starts a workflow run synchronously without waiting for the workflow to complete
|
|
1734
|
-
* @param params - Object containing the runId, inputData and requestContext
|
|
1751
|
+
* @param params - Object containing the runId, inputData, initialState and requestContext
|
|
1735
1752
|
* @returns Promise containing success message
|
|
1736
1753
|
*/
|
|
1737
1754
|
start(params) {
|
|
1738
1755
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1739
1756
|
return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
|
|
1740
1757
|
method: "POST",
|
|
1741
|
-
body: {
|
|
1758
|
+
body: {
|
|
1759
|
+
inputData: params?.inputData,
|
|
1760
|
+
initialState: params?.initialState,
|
|
1761
|
+
requestContext,
|
|
1762
|
+
tracingOptions: params.tracingOptions
|
|
1763
|
+
}
|
|
1742
1764
|
});
|
|
1743
1765
|
}
|
|
1744
1766
|
/**
|
|
@@ -1766,7 +1788,7 @@ var Workflow = class extends BaseResource {
|
|
|
1766
1788
|
}
|
|
1767
1789
|
/**
|
|
1768
1790
|
* Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
|
|
1769
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1791
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1770
1792
|
* @returns Promise containing the workflow execution results
|
|
1771
1793
|
*/
|
|
1772
1794
|
startAsync(params) {
|
|
@@ -1777,12 +1799,17 @@ var Workflow = class extends BaseResource {
|
|
|
1777
1799
|
const requestContext = parseClientRequestContext(params.requestContext);
|
|
1778
1800
|
return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
|
|
1779
1801
|
method: "POST",
|
|
1780
|
-
body: {
|
|
1802
|
+
body: {
|
|
1803
|
+
inputData: params.inputData,
|
|
1804
|
+
initialState: params.initialState,
|
|
1805
|
+
requestContext,
|
|
1806
|
+
tracingOptions: params.tracingOptions
|
|
1807
|
+
}
|
|
1781
1808
|
});
|
|
1782
1809
|
}
|
|
1783
1810
|
/**
|
|
1784
1811
|
* Starts a workflow run and returns a stream
|
|
1785
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1812
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1786
1813
|
* @returns Promise containing the workflow execution results
|
|
1787
1814
|
*/
|
|
1788
1815
|
async stream(params) {
|
|
@@ -1795,7 +1822,12 @@ var Workflow = class extends BaseResource {
|
|
|
1795
1822
|
`/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
|
|
1796
1823
|
{
|
|
1797
1824
|
method: "POST",
|
|
1798
|
-
body: {
|
|
1825
|
+
body: {
|
|
1826
|
+
inputData: params.inputData,
|
|
1827
|
+
initialState: params.initialState,
|
|
1828
|
+
requestContext,
|
|
1829
|
+
tracingOptions: params.tracingOptions
|
|
1830
|
+
},
|
|
1799
1831
|
stream: true
|
|
1800
1832
|
}
|
|
1801
1833
|
);
|
|
@@ -1880,7 +1912,7 @@ var Workflow = class extends BaseResource {
|
|
|
1880
1912
|
}
|
|
1881
1913
|
/**
|
|
1882
1914
|
* Starts a workflow run and returns a stream
|
|
1883
|
-
* @param params - Object containing the optional runId, inputData and requestContext
|
|
1915
|
+
* @param params - Object containing the optional runId, inputData, initialState and requestContext
|
|
1884
1916
|
* @returns Promise containing the workflow execution results
|
|
1885
1917
|
*/
|
|
1886
1918
|
async streamVNext(params) {
|
|
@@ -1895,6 +1927,7 @@ var Workflow = class extends BaseResource {
|
|
|
1895
1927
|
method: "POST",
|
|
1896
1928
|
body: {
|
|
1897
1929
|
inputData: params.inputData,
|
|
1930
|
+
initialState: params.initialState,
|
|
1898
1931
|
requestContext,
|
|
1899
1932
|
closeOnSuspend: params.closeOnSuspend,
|
|
1900
1933
|
tracingOptions: params.tracingOptions
|
|
@@ -2253,7 +2286,8 @@ var A2A = class extends BaseResource {
|
|
|
2253
2286
|
body: {
|
|
2254
2287
|
method: "message/stream",
|
|
2255
2288
|
params
|
|
2256
|
-
}
|
|
2289
|
+
},
|
|
2290
|
+
stream: true
|
|
2257
2291
|
});
|
|
2258
2292
|
return response;
|
|
2259
2293
|
}
|
|
@@ -2684,6 +2718,16 @@ var AgentBuilder = class extends BaseResource {
|
|
|
2684
2718
|
if (params?.page !== void 0) {
|
|
2685
2719
|
searchParams.set("page", String(params.page));
|
|
2686
2720
|
}
|
|
2721
|
+
if (params?.limit !== null && params?.limit !== void 0) {
|
|
2722
|
+
if (params.limit === false) {
|
|
2723
|
+
searchParams.set("limit", "false");
|
|
2724
|
+
} else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
|
|
2725
|
+
searchParams.set("limit", String(params.limit));
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
|
|
2729
|
+
searchParams.set("offset", String(params.offset));
|
|
2730
|
+
}
|
|
2687
2731
|
if (params?.resourceId) {
|
|
2688
2732
|
searchParams.set("resourceId", params.resourceId);
|
|
2689
2733
|
}
|
|
@@ -2802,12 +2846,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2802
2846
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2803
2847
|
* @returns Promise containing map of agent IDs to agent details
|
|
2804
2848
|
*/
|
|
2805
|
-
listAgents(requestContext) {
|
|
2849
|
+
listAgents(requestContext, partial) {
|
|
2806
2850
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2807
2851
|
const searchParams = new URLSearchParams();
|
|
2808
2852
|
if (requestContextParam) {
|
|
2809
2853
|
searchParams.set("requestContext", requestContextParam);
|
|
2810
2854
|
}
|
|
2855
|
+
if (partial) {
|
|
2856
|
+
searchParams.set("partial", "true");
|
|
2857
|
+
}
|
|
2811
2858
|
const queryString = searchParams.toString();
|
|
2812
2859
|
return this.request(`/api/agents${queryString ? `?${queryString}` : ""}`);
|
|
2813
2860
|
}
|
|
@@ -2949,12 +2996,15 @@ var MastraClient = class extends BaseResource {
|
|
|
2949
2996
|
* @param requestContext - Optional request context to pass as query parameter
|
|
2950
2997
|
* @returns Promise containing map of workflow IDs to workflow details
|
|
2951
2998
|
*/
|
|
2952
|
-
listWorkflows(requestContext) {
|
|
2999
|
+
listWorkflows(requestContext, partial) {
|
|
2953
3000
|
const requestContextParam = base64RequestContext(parseClientRequestContext(requestContext));
|
|
2954
3001
|
const searchParams = new URLSearchParams();
|
|
2955
3002
|
if (requestContextParam) {
|
|
2956
3003
|
searchParams.set("requestContext", requestContextParam);
|
|
2957
3004
|
}
|
|
3005
|
+
if (partial) {
|
|
3006
|
+
searchParams.set("partial", "true");
|
|
3007
|
+
}
|
|
2958
3008
|
const queryString = searchParams.toString();
|
|
2959
3009
|
return this.request(`/api/workflows${queryString ? `?${queryString}` : ""}`);
|
|
2960
3010
|
}
|
|
@@ -3084,16 +3134,22 @@ var MastraClient = class extends BaseResource {
|
|
|
3084
3134
|
}
|
|
3085
3135
|
/**
|
|
3086
3136
|
* Retrieves a list of available MCP servers.
|
|
3087
|
-
* @param params - Optional parameters for pagination (perPage,
|
|
3137
|
+
* @param params - Optional parameters for pagination (page, perPage, or deprecated offset, limit).
|
|
3088
3138
|
* @returns Promise containing the list of MCP servers and pagination info.
|
|
3089
3139
|
*/
|
|
3090
3140
|
getMcpServers(params) {
|
|
3091
3141
|
const searchParams = new URLSearchParams();
|
|
3142
|
+
if (params?.page !== void 0) {
|
|
3143
|
+
searchParams.set("page", String(params.page));
|
|
3144
|
+
}
|
|
3092
3145
|
if (params?.perPage !== void 0) {
|
|
3093
3146
|
searchParams.set("perPage", String(params.perPage));
|
|
3094
3147
|
}
|
|
3095
|
-
if (params?.
|
|
3096
|
-
searchParams.set("
|
|
3148
|
+
if (params?.limit !== void 0) {
|
|
3149
|
+
searchParams.set("limit", String(params.limit));
|
|
3150
|
+
}
|
|
3151
|
+
if (params?.offset !== void 0) {
|
|
3152
|
+
searchParams.set("offset", String(params.offset));
|
|
3097
3153
|
}
|
|
3098
3154
|
const queryString = searchParams.toString();
|
|
3099
3155
|
return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
|