@mastra/client-js 1.0.0-beta.5 → 1.0.0-beta.6

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
@@ -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 { z } from 'zod';
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
- if ("toJSONSchema" in z) {
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 { baseUrl, retries = 3, backoffMs = 100, maxBackoffMs = 1e3, headers = {}, credentials } = this.options;
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 fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
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,15 @@ var Workflow = class extends BaseResource {
1611
1615
  if (params?.toDate) {
1612
1616
  searchParams.set("toDate", params.toDate.toISOString());
1613
1617
  }
1614
- if (params?.perPage !== null && params?.perPage !== void 0) {
1615
- if (params.perPage === false) {
1616
- searchParams.set("perPage", "false");
1617
- } else if (typeof params.perPage === "number" && params.perPage > 0 && Number.isInteger(params.perPage)) {
1618
- searchParams.set("perPage", String(params.perPage));
1618
+ if (params?.limit !== null && params?.limit !== void 0) {
1619
+ if (params.limit === false) {
1620
+ searchParams.set("limit", "false");
1621
+ } else if (typeof params.limit === "number" && params.limit > 0 && Number.isInteger(params.limit)) {
1622
+ searchParams.set("limit", String(params.limit));
1619
1623
  }
1620
1624
  }
1621
- if (params?.page !== null && params?.page !== void 0 && !isNaN(Number(params?.page))) {
1622
- searchParams.set("page", String(params.page));
1625
+ if (params?.offset !== null && params?.offset !== void 0 && !isNaN(Number(params?.offset))) {
1626
+ searchParams.set("offset", String(params.offset));
1623
1627
  }
1624
1628
  if (params?.resourceId) {
1625
1629
  searchParams.set("resourceId", params.resourceId);
@@ -1686,6 +1690,7 @@ var Workflow = class extends BaseResource {
1686
1690
  return this.start({
1687
1691
  runId,
1688
1692
  inputData: p.inputData,
1693
+ initialState: p.initialState,
1689
1694
  requestContext: p.requestContext,
1690
1695
  tracingOptions: p.tracingOptions
1691
1696
  });
@@ -1694,12 +1699,18 @@ var Workflow = class extends BaseResource {
1694
1699
  return this.startAsync({
1695
1700
  runId,
1696
1701
  inputData: p.inputData,
1702
+ initialState: p.initialState,
1697
1703
  requestContext: p.requestContext,
1698
1704
  tracingOptions: p.tracingOptions
1699
1705
  });
1700
1706
  },
1701
1707
  stream: async (p) => {
1702
- return this.stream({ runId, inputData: p.inputData, requestContext: p.requestContext });
1708
+ return this.stream({
1709
+ runId,
1710
+ inputData: p.inputData,
1711
+ initialState: p.initialState,
1712
+ requestContext: p.requestContext
1713
+ });
1703
1714
  },
1704
1715
  resume: async (p) => {
1705
1716
  return this.resume({
@@ -1731,14 +1742,19 @@ var Workflow = class extends BaseResource {
1731
1742
  }
1732
1743
  /**
1733
1744
  * Starts a workflow run synchronously without waiting for the workflow to complete
1734
- * @param params - Object containing the runId, inputData and requestContext
1745
+ * @param params - Object containing the runId, inputData, initialState and requestContext
1735
1746
  * @returns Promise containing success message
1736
1747
  */
1737
1748
  start(params) {
1738
1749
  const requestContext = parseClientRequestContext(params.requestContext);
1739
1750
  return this.request(`/api/workflows/${this.workflowId}/start?runId=${params.runId}`, {
1740
1751
  method: "POST",
1741
- body: { inputData: params?.inputData, requestContext, tracingOptions: params.tracingOptions }
1752
+ body: {
1753
+ inputData: params?.inputData,
1754
+ initialState: params?.initialState,
1755
+ requestContext,
1756
+ tracingOptions: params.tracingOptions
1757
+ }
1742
1758
  });
1743
1759
  }
1744
1760
  /**
@@ -1766,7 +1782,7 @@ var Workflow = class extends BaseResource {
1766
1782
  }
1767
1783
  /**
1768
1784
  * 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
1785
+ * @param params - Object containing the optional runId, inputData, initialState and requestContext
1770
1786
  * @returns Promise containing the workflow execution results
1771
1787
  */
1772
1788
  startAsync(params) {
@@ -1777,12 +1793,17 @@ var Workflow = class extends BaseResource {
1777
1793
  const requestContext = parseClientRequestContext(params.requestContext);
1778
1794
  return this.request(`/api/workflows/${this.workflowId}/start-async?${searchParams.toString()}`, {
1779
1795
  method: "POST",
1780
- body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions }
1796
+ body: {
1797
+ inputData: params.inputData,
1798
+ initialState: params.initialState,
1799
+ requestContext,
1800
+ tracingOptions: params.tracingOptions
1801
+ }
1781
1802
  });
1782
1803
  }
1783
1804
  /**
1784
1805
  * Starts a workflow run and returns a stream
1785
- * @param params - Object containing the optional runId, inputData and requestContext
1806
+ * @param params - Object containing the optional runId, inputData, initialState and requestContext
1786
1807
  * @returns Promise containing the workflow execution results
1787
1808
  */
1788
1809
  async stream(params) {
@@ -1795,7 +1816,12 @@ var Workflow = class extends BaseResource {
1795
1816
  `/api/workflows/${this.workflowId}/stream?${searchParams.toString()}`,
1796
1817
  {
1797
1818
  method: "POST",
1798
- body: { inputData: params.inputData, requestContext, tracingOptions: params.tracingOptions },
1819
+ body: {
1820
+ inputData: params.inputData,
1821
+ initialState: params.initialState,
1822
+ requestContext,
1823
+ tracingOptions: params.tracingOptions
1824
+ },
1799
1825
  stream: true
1800
1826
  }
1801
1827
  );
@@ -1880,7 +1906,7 @@ var Workflow = class extends BaseResource {
1880
1906
  }
1881
1907
  /**
1882
1908
  * Starts a workflow run and returns a stream
1883
- * @param params - Object containing the optional runId, inputData and requestContext
1909
+ * @param params - Object containing the optional runId, inputData, initialState and requestContext
1884
1910
  * @returns Promise containing the workflow execution results
1885
1911
  */
1886
1912
  async streamVNext(params) {
@@ -1895,6 +1921,7 @@ var Workflow = class extends BaseResource {
1895
1921
  method: "POST",
1896
1922
  body: {
1897
1923
  inputData: params.inputData,
1924
+ initialState: params.initialState,
1898
1925
  requestContext,
1899
1926
  closeOnSuspend: params.closeOnSuspend,
1900
1927
  tracingOptions: params.tracingOptions
@@ -2253,7 +2280,8 @@ var A2A = class extends BaseResource {
2253
2280
  body: {
2254
2281
  method: "message/stream",
2255
2282
  params
2256
- }
2283
+ },
2284
+ stream: true
2257
2285
  });
2258
2286
  return response;
2259
2287
  }