@mastra/client-js 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
Files changed (292) hide show
  1. package/.eslintrc.js +10 -0
  2. package/.prettierignore +3 -0
  3. package/.prettierrc.json +26 -0
  4. package/LICENSE +44 -201
  5. package/README.md +90 -271
  6. package/dist/index.d.mts +359 -0
  7. package/dist/index.mjs +399 -0
  8. package/package.json +30 -95
  9. package/src/client.ts +201 -0
  10. package/src/index.test.ts +528 -0
  11. package/src/index.ts +2 -200
  12. package/src/resources/agent.ts +97 -0
  13. package/src/resources/index.ts +5 -14
  14. package/src/resources/memory-thread.ts +51 -0
  15. package/src/resources/tool.ts +28 -0
  16. package/src/resources/vector.ts +79 -0
  17. package/src/resources/workflow.ts +28 -0
  18. package/src/types.ts +135 -0
  19. package/tsconfig.json +29 -0
  20. package/vitest.config.js +8 -0
  21. package/CHANGELOG.md +0 -29
  22. package/_shims/MultipartBody.d.ts +0 -9
  23. package/_shims/MultipartBody.d.ts.map +0 -1
  24. package/_shims/MultipartBody.js +0 -16
  25. package/_shims/MultipartBody.js.map +0 -1
  26. package/_shims/MultipartBody.mjs +0 -12
  27. package/_shims/MultipartBody.mjs.map +0 -1
  28. package/_shims/README.md +0 -46
  29. package/_shims/auto/runtime-bun.d.ts +0 -5
  30. package/_shims/auto/runtime-bun.d.ts.map +0 -1
  31. package/_shims/auto/runtime-bun.js +0 -21
  32. package/_shims/auto/runtime-bun.js.map +0 -1
  33. package/_shims/auto/runtime-bun.mjs +0 -2
  34. package/_shims/auto/runtime-bun.mjs.map +0 -1
  35. package/_shims/auto/runtime-node.d.ts +0 -5
  36. package/_shims/auto/runtime-node.d.ts.map +0 -1
  37. package/_shims/auto/runtime-node.js +0 -21
  38. package/_shims/auto/runtime-node.js.map +0 -1
  39. package/_shims/auto/runtime-node.mjs +0 -2
  40. package/_shims/auto/runtime-node.mjs.map +0 -1
  41. package/_shims/auto/runtime.d.ts +0 -5
  42. package/_shims/auto/runtime.d.ts.map +0 -1
  43. package/_shims/auto/runtime.js +0 -21
  44. package/_shims/auto/runtime.js.map +0 -1
  45. package/_shims/auto/runtime.mjs +0 -2
  46. package/_shims/auto/runtime.mjs.map +0 -1
  47. package/_shims/auto/types-node.d.ts +0 -5
  48. package/_shims/auto/types-node.d.ts.map +0 -1
  49. package/_shims/auto/types-node.js +0 -21
  50. package/_shims/auto/types-node.js.map +0 -1
  51. package/_shims/auto/types-node.mjs +0 -2
  52. package/_shims/auto/types-node.mjs.map +0 -1
  53. package/_shims/auto/types.d.ts +0 -101
  54. package/_shims/auto/types.js +0 -3
  55. package/_shims/auto/types.mjs +0 -3
  56. package/_shims/bun-runtime.d.ts +0 -6
  57. package/_shims/bun-runtime.d.ts.map +0 -1
  58. package/_shims/bun-runtime.js +0 -14
  59. package/_shims/bun-runtime.js.map +0 -1
  60. package/_shims/bun-runtime.mjs +0 -10
  61. package/_shims/bun-runtime.mjs.map +0 -1
  62. package/_shims/index.d.ts +0 -81
  63. package/_shims/index.js +0 -13
  64. package/_shims/index.mjs +0 -7
  65. package/_shims/manual-types.d.ts +0 -12
  66. package/_shims/manual-types.js +0 -3
  67. package/_shims/manual-types.mjs +0 -3
  68. package/_shims/node-runtime.d.ts +0 -3
  69. package/_shims/node-runtime.d.ts.map +0 -1
  70. package/_shims/node-runtime.js +0 -89
  71. package/_shims/node-runtime.js.map +0 -1
  72. package/_shims/node-runtime.mjs +0 -56
  73. package/_shims/node-runtime.mjs.map +0 -1
  74. package/_shims/node-types.d.ts +0 -42
  75. package/_shims/node-types.js +0 -3
  76. package/_shims/node-types.mjs +0 -3
  77. package/_shims/registry.d.ts +0 -37
  78. package/_shims/registry.d.ts.map +0 -1
  79. package/_shims/registry.js +0 -41
  80. package/_shims/registry.js.map +0 -1
  81. package/_shims/registry.mjs +0 -37
  82. package/_shims/registry.mjs.map +0 -1
  83. package/_shims/web-runtime.d.ts +0 -5
  84. package/_shims/web-runtime.d.ts.map +0 -1
  85. package/_shims/web-runtime.js +0 -78
  86. package/_shims/web-runtime.js.map +0 -1
  87. package/_shims/web-runtime.mjs +0 -71
  88. package/_shims/web-runtime.mjs.map +0 -1
  89. package/_shims/web-types.d.ts +0 -83
  90. package/_shims/web-types.js +0 -3
  91. package/_shims/web-types.mjs +0 -3
  92. package/core.d.ts +0 -241
  93. package/core.d.ts.map +0 -1
  94. package/core.js +0 -908
  95. package/core.js.map +0 -1
  96. package/core.mjs +0 -876
  97. package/core.mjs.map +0 -1
  98. package/error.d.ts +0 -47
  99. package/error.d.ts.map +0 -1
  100. package/error.js +0 -113
  101. package/error.js.map +0 -1
  102. package/error.mjs +0 -97
  103. package/error.mjs.map +0 -1
  104. package/index.d.mts +0 -121
  105. package/index.d.ts +0 -121
  106. package/index.d.ts.map +0 -1
  107. package/index.js +0 -131
  108. package/index.js.map +0 -1
  109. package/index.mjs +0 -88
  110. package/index.mjs.map +0 -1
  111. package/resource.d.ts +0 -6
  112. package/resource.d.ts.map +0 -1
  113. package/resource.js +0 -11
  114. package/resource.js.map +0 -1
  115. package/resource.mjs +0 -7
  116. package/resource.mjs.map +0 -1
  117. package/resources/agents/agents.d.ts +0 -41
  118. package/resources/agents/agents.d.ts.map +0 -1
  119. package/resources/agents/agents.js +0 -74
  120. package/resources/agents/agents.js.map +0 -1
  121. package/resources/agents/agents.mjs +0 -47
  122. package/resources/agents/agents.mjs.map +0 -1
  123. package/resources/agents/index.d.ts +0 -3
  124. package/resources/agents/index.d.ts.map +0 -1
  125. package/resources/agents/index.js +0 -9
  126. package/resources/agents/index.js.map +0 -1
  127. package/resources/agents/index.mjs +0 -4
  128. package/resources/agents/index.mjs.map +0 -1
  129. package/resources/agents/tools.d.ts +0 -17
  130. package/resources/agents/tools.d.ts.map +0 -1
  131. package/resources/agents/tools.js +0 -19
  132. package/resources/agents/tools.js.map +0 -1
  133. package/resources/agents/tools.mjs +0 -15
  134. package/resources/agents/tools.mjs.map +0 -1
  135. package/resources/index.d.ts +0 -8
  136. package/resources/index.d.ts.map +0 -1
  137. package/resources/index.js +0 -19
  138. package/resources/index.js.map +0 -1
  139. package/resources/index.mjs +0 -9
  140. package/resources/index.mjs.map +0 -1
  141. package/resources/logs.d.ts +0 -13
  142. package/resources/logs.d.ts.map +0 -1
  143. package/resources/logs.js +0 -24
  144. package/resources/logs.js.map +0 -1
  145. package/resources/logs.mjs +0 -20
  146. package/resources/logs.mjs.map +0 -1
  147. package/resources/memory/index.d.ts +0 -4
  148. package/resources/memory/index.d.ts.map +0 -1
  149. package/resources/memory/index.js +0 -11
  150. package/resources/memory/index.js.map +0 -1
  151. package/resources/memory/index.mjs +0 -5
  152. package/resources/memory/index.mjs.map +0 -1
  153. package/resources/memory/memory.d.ts +0 -23
  154. package/resources/memory/memory.d.ts.map +0 -1
  155. package/resources/memory/memory.js +0 -53
  156. package/resources/memory/memory.js.map +0 -1
  157. package/resources/memory/memory.mjs +0 -26
  158. package/resources/memory/memory.mjs.map +0 -1
  159. package/resources/memory/status.d.ts +0 -9
  160. package/resources/memory/status.d.ts.map +0 -1
  161. package/resources/memory/status.js +0 -18
  162. package/resources/memory/status.js.map +0 -1
  163. package/resources/memory/status.mjs +0 -14
  164. package/resources/memory/status.mjs.map +0 -1
  165. package/resources/memory/threads/index.d.ts +0 -3
  166. package/resources/memory/threads/index.d.ts.map +0 -1
  167. package/resources/memory/threads/index.js +0 -9
  168. package/resources/memory/threads/index.js.map +0 -1
  169. package/resources/memory/threads/index.mjs +0 -4
  170. package/resources/memory/threads/index.mjs.map +0 -1
  171. package/resources/memory/threads/messages.d.ts +0 -9
  172. package/resources/memory/threads/messages.d.ts.map +0 -1
  173. package/resources/memory/threads/messages.js +0 -18
  174. package/resources/memory/threads/messages.js.map +0 -1
  175. package/resources/memory/threads/messages.mjs +0 -14
  176. package/resources/memory/threads/messages.mjs.map +0 -1
  177. package/resources/memory/threads/threads.d.ts +0 -45
  178. package/resources/memory/threads/threads.d.ts.map +0 -1
  179. package/resources/memory/threads/threads.js +0 -104
  180. package/resources/memory/threads/threads.js.map +0 -1
  181. package/resources/memory/threads/threads.mjs +0 -77
  182. package/resources/memory/threads/threads.mjs.map +0 -1
  183. package/resources/syncs.d.ts +0 -15
  184. package/resources/syncs.d.ts.map +0 -1
  185. package/resources/syncs.js +0 -19
  186. package/resources/syncs.js.map +0 -1
  187. package/resources/syncs.mjs +0 -15
  188. package/resources/syncs.mjs.map +0 -1
  189. package/resources/system.d.ts +0 -9
  190. package/resources/system.d.ts.map +0 -1
  191. package/resources/system.js +0 -15
  192. package/resources/system.js.map +0 -1
  193. package/resources/system.mjs +0 -11
  194. package/resources/system.mjs.map +0 -1
  195. package/resources/tools/index.d.ts +0 -3
  196. package/resources/tools/index.d.ts.map +0 -1
  197. package/resources/tools/index.js +0 -9
  198. package/resources/tools/index.js.map +0 -1
  199. package/resources/tools/index.mjs +0 -4
  200. package/resources/tools/index.mjs.map +0 -1
  201. package/resources/tools/result.d.ts +0 -9
  202. package/resources/tools/result.d.ts.map +0 -1
  203. package/resources/tools/result.js +0 -18
  204. package/resources/tools/result.js.map +0 -1
  205. package/resources/tools/result.mjs +0 -14
  206. package/resources/tools/result.mjs.map +0 -1
  207. package/resources/tools/tools.d.ts +0 -29
  208. package/resources/tools/tools.d.ts.map +0 -1
  209. package/resources/tools/tools.js +0 -64
  210. package/resources/tools/tools.js.map +0 -1
  211. package/resources/tools/tools.mjs +0 -37
  212. package/resources/tools/tools.mjs.map +0 -1
  213. package/resources/workflows.d.ts +0 -23
  214. package/resources/workflows.d.ts.map +0 -1
  215. package/resources/workflows.js +0 -37
  216. package/resources/workflows.js.map +0 -1
  217. package/resources/workflows.mjs +0 -33
  218. package/resources/workflows.mjs.map +0 -1
  219. package/shims/node.d.ts +0 -30
  220. package/shims/node.d.ts.map +0 -1
  221. package/shims/node.js +0 -31
  222. package/shims/node.js.map +0 -1
  223. package/shims/node.mjs +0 -5
  224. package/shims/node.mjs.map +0 -1
  225. package/shims/web.d.ts +0 -26
  226. package/shims/web.d.ts.map +0 -1
  227. package/shims/web.js +0 -31
  228. package/shims/web.js.map +0 -1
  229. package/shims/web.mjs +0 -5
  230. package/shims/web.mjs.map +0 -1
  231. package/src/_shims/MultipartBody.ts +0 -9
  232. package/src/_shims/README.md +0 -46
  233. package/src/_shims/auto/runtime-bun.ts +0 -4
  234. package/src/_shims/auto/runtime-node.ts +0 -4
  235. package/src/_shims/auto/runtime.ts +0 -4
  236. package/src/_shims/auto/types-node.ts +0 -4
  237. package/src/_shims/auto/types.d.ts +0 -101
  238. package/src/_shims/auto/types.js +0 -3
  239. package/src/_shims/auto/types.mjs +0 -3
  240. package/src/_shims/bun-runtime.ts +0 -14
  241. package/src/_shims/index.d.ts +0 -81
  242. package/src/_shims/index.js +0 -13
  243. package/src/_shims/index.mjs +0 -7
  244. package/src/_shims/manual-types.d.ts +0 -12
  245. package/src/_shims/manual-types.js +0 -3
  246. package/src/_shims/manual-types.mjs +0 -3
  247. package/src/_shims/node-runtime.ts +0 -81
  248. package/src/_shims/node-types.d.ts +0 -42
  249. package/src/_shims/node-types.js +0 -3
  250. package/src/_shims/node-types.mjs +0 -3
  251. package/src/_shims/registry.ts +0 -67
  252. package/src/_shims/web-runtime.ts +0 -103
  253. package/src/_shims/web-types.d.ts +0 -83
  254. package/src/_shims/web-types.js +0 -3
  255. package/src/_shims/web-types.mjs +0 -3
  256. package/src/core.ts +0 -1201
  257. package/src/error.ts +0 -130
  258. package/src/lib/.keep +0 -4
  259. package/src/resource.ts +0 -11
  260. package/src/resources/agents/agents.ts +0 -83
  261. package/src/resources/agents/index.ts +0 -4
  262. package/src/resources/agents/tools.ts +0 -34
  263. package/src/resources/logs.ts +0 -23
  264. package/src/resources/memory/index.ts +0 -5
  265. package/src/resources/memory/memory.ts +0 -43
  266. package/src/resources/memory/status.ts +0 -16
  267. package/src/resources/memory/threads/index.ts +0 -4
  268. package/src/resources/memory/threads/messages.ts +0 -16
  269. package/src/resources/memory/threads/threads.ts +0 -105
  270. package/src/resources/syncs.ts +0 -25
  271. package/src/resources/system.ts +0 -13
  272. package/src/resources/tools/index.ts +0 -4
  273. package/src/resources/tools/result.ts +0 -16
  274. package/src/resources/tools/tools.ts +0 -54
  275. package/src/resources/workflows.ts +0 -49
  276. package/src/shims/node.ts +0 -50
  277. package/src/shims/web.ts +0 -50
  278. package/src/tsconfig.json +0 -11
  279. package/src/uploads.ts +0 -255
  280. package/src/version.ts +0 -1
  281. package/uploads.d.ts +0 -75
  282. package/uploads.d.ts.map +0 -1
  283. package/uploads.js +0 -171
  284. package/uploads.js.map +0 -1
  285. package/uploads.mjs +0 -158
  286. package/uploads.mjs.map +0 -1
  287. package/version.d.ts +0 -2
  288. package/version.d.ts.map +0 -1
  289. package/version.js +0 -5
  290. package/version.js.map +0 -1
  291. package/version.mjs +0 -2
  292. package/version.mjs.map +0 -1
package/README.md CHANGED
@@ -1,291 +1,110 @@
1
- # Mastra Client Node API Library
1
+ # Mastra Client
2
2
 
3
- [![NPM version](https://img.shields.io/npm/v/@mastra/client-js.svg)](https://npmjs.org/package/@mastra/client-js) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@mastra/client-js)
4
-
5
- This library provides convenient access to the Mastra Client REST API from server-side TypeScript or JavaScript.
6
-
7
- The REST API documentation can be found on [mastra.ai](https://mastra.ai/docs). The full API of this library can be found in [api.md](api.md).
8
-
9
- It is generated with [Stainless](https://www.stainlessapi.com/).
3
+ JavaScript/TypeScript client library for the [Mastra AI](https://mastra.ai) framework. This client provides a simple interface to interact with Mastra AI's APIs for agents, vectors, memory, tools, and workflows.
10
4
 
11
5
  ## Installation
12
6
 
13
- ```sh
7
+ ```bash
14
8
  npm install @mastra/client-js
15
9
  ```
16
10
 
17
- ## Usage
18
-
19
- The full API of this library can be found in [api.md](api.md).
20
-
21
- <!-- prettier-ignore -->
22
- ```js
23
- import MastraClient from '@mastra/client-js';
24
-
25
- const client = new MastraClient();
26
-
27
- async function main() {
28
- await client.agents.list();
29
- }
30
-
31
- main();
32
- ```
33
-
34
- ### Request & Response types
35
-
36
- This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
37
-
38
- <!-- prettier-ignore -->
39
- ```ts
40
- import MastraClient from '@mastra/client-js';
41
-
42
- const client = new MastraClient();
43
-
44
- async function main() {
45
- await client.agents.list();
46
- }
47
-
48
- main();
49
- ```
50
-
51
- Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
52
-
53
- ## Handling errors
54
-
55
- When the library is unable to connect to the API,
56
- or if the API returns a non-success status code (i.e., 4xx or 5xx response),
57
- a subclass of `APIError` will be thrown:
58
-
59
- <!-- prettier-ignore -->
60
- ```ts
61
- async function main() {
62
- const response = await client.agents.list().catch(async (err) => {
63
- if (err instanceof MastraClient.APIError) {
64
- console.log(err.status); // 400
65
- console.log(err.name); // BadRequestError
66
- console.log(err.headers); // {server: 'nginx', ...}
67
- } else {
68
- throw err;
69
- }
70
- });
71
- }
72
-
73
- main();
74
- ```
75
-
76
- Error codes are as followed:
77
-
78
- | Status Code | Error Type |
79
- | ----------- | -------------------------- |
80
- | 400 | `BadRequestError` |
81
- | 401 | `AuthenticationError` |
82
- | 403 | `PermissionDeniedError` |
83
- | 404 | `NotFoundError` |
84
- | 422 | `UnprocessableEntityError` |
85
- | 429 | `RateLimitError` |
86
- | >=500 | `InternalServerError` |
87
- | N/A | `APIConnectionError` |
88
-
89
- ### Retries
90
-
91
- Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
92
- Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
93
- 429 Rate Limit, and >=500 Internal errors will all be retried by default.
11
+ ## Quick Start
94
12
 
95
- You can use the `maxRetries` option to configure or disable this:
13
+ ```typescript
14
+ import { MastraClient } from '@mastra/client';
96
15
 
97
- <!-- prettier-ignore -->
98
- ```js
99
- // Configure the default for all requests:
16
+ // Initialize the client
100
17
  const client = new MastraClient({
101
- maxRetries: 0, // default is 2
18
+ baseUrl: 'http://localhost:4111', // Your Mastra API endpoint
102
19
  });
103
20
 
104
- // Or, configure per-request:
105
- await client.agents.list({
106
- maxRetries: 5,
107
- });
108
- ```
109
-
110
- ### Timeouts
111
-
112
- Requests time out after 1 minute by default. You can configure this with a `timeout` option:
113
-
114
- <!-- prettier-ignore -->
115
- ```ts
116
- // Configure the default for all requests:
117
- const client = new MastraClient({
118
- timeout: 20 * 1000, // 20 seconds (default is 1 minute)
119
- });
120
-
121
- // Override per-request:
122
- await client.agents.list({
123
- timeout: 5 * 1000,
124
- });
125
- ```
126
-
127
- On timeout, an `APIConnectionTimeoutError` is thrown.
128
-
129
- Note that requests which time out will be [retried twice by default](#retries).
130
-
131
- ## Advanced Usage
132
-
133
- ### Accessing raw Response data (e.g., headers)
134
-
135
- The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
136
-
137
- You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
138
-
139
- <!-- prettier-ignore -->
140
- ```ts
141
- const client = new MastraClient();
142
-
143
- const response = await client.agents.list().asResponse();
144
- console.log(response.headers.get('X-My-Header'));
145
- console.log(response.statusText); // access the underlying Response object
146
-
147
- const { data: result, response: raw } = await client.agents.list().withResponse();
148
- console.log(raw.headers.get('X-My-Header'));
149
- console.log(result);
150
- ```
151
-
152
- ### Making custom/undocumented requests
153
-
154
- This library is typed for convenient access to the documented API. If you need to access undocumented
155
- endpoints, params, or response properties, the library can still be used.
156
-
157
- #### Undocumented endpoints
158
-
159
- To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
160
- Options on the client, such as retries, will be respected when making these requests.
161
-
162
- ```ts
163
- await client.post('/some/path', {
164
- body: { some_prop: 'foo' },
165
- query: { some_query_arg: 'bar' },
166
- });
167
- ```
168
-
169
- #### Undocumented request params
170
-
171
- To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
172
- parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
173
- send will be sent as-is.
174
-
175
- ```ts
176
- client.foo.create({
177
- foo: 'my_param',
178
- bar: 12,
179
- // @ts-expect-error baz is not yet public
180
- baz: 'undocumented option',
181
- });
182
- ```
183
-
184
- For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
185
- extra param in the body.
186
-
187
- If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
188
- options.
189
-
190
- #### Undocumented response properties
191
-
192
- To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
193
- the response object, or cast the response object to the requisite type. Like the request params, we do not
194
- validate or strip extra properties from the response from the API.
195
-
196
- ### Customizing the fetch client
197
-
198
- By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
199
-
200
- If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
201
- (for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
202
- add the following import before your first import `from "MastraClient"`:
203
-
204
- ```ts
205
- // Tell TypeScript and the package to use the global web fetch instead of node-fetch.
206
- // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
207
- import '@mastra/client-js/shims/web';
208
- import MastraClient from '@mastra/client-js';
209
- ```
210
-
211
- To do the inverse, add `import "@mastra/client-js/shims/node"` (which does import polyfills).
212
- This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/mastra-ai/client-js/tree/main/src/_shims#readme)).
213
-
214
- ### Logging and middleware
215
-
216
- You may also provide a custom `fetch` function when instantiating the client,
217
- which can be used to inspect or alter the `Request` or `Response` before/after each request:
218
-
219
- ```ts
220
- import { fetch } from 'undici'; // as one example
221
- import MastraClient from '@mastra/client-js';
222
-
223
- const client = new MastraClient({
224
- fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
225
- console.log('About to make a request', url, init);
226
- const response = await fetch(url, init);
227
- console.log('Got response', response);
228
- return response;
229
- },
230
- });
21
+ // Example: Working with an Agent
22
+ async function main() {
23
+ // Get an agent instance
24
+ const agent = client.getAgent('your-agent-id');
25
+
26
+ // Generate a response
27
+ const response = await agent.generate({
28
+ messages: [{ role: 'user', content: "What's the weather like today?" }],
29
+ });
30
+
31
+ console.log(response);
32
+ }
231
33
  ```
232
34
 
233
- Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
234
- This is intended for debugging purposes only and may change in the future without notice.
235
-
236
- ### Configuring an HTTP(S) Agent (e.g., for proxies)
237
-
238
- By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
35
+ ## Client Configuration
239
36
 
240
- If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
37
+ The client can be configured with several options:
241
38
 
242
- <!-- prettier-ignore -->
243
- ```ts
244
- import http from 'http';
245
- import { HttpsProxyAgent } from 'https-proxy-agent';
246
-
247
- // Configure the default for all requests:
39
+ ```typescript
248
40
  const client = new MastraClient({
249
- httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
250
- });
251
-
252
- // Override per-request:
253
- await client.agents.list({
254
- httpAgent: new http.Agent({ keepAlive: false }),
41
+ baseUrl: string; // Base URL for the Mastra API
42
+ retries?: number; // Number of retry attempts (default: 3)
43
+ backoffMs?: number; // Initial backoff time in ms (default: 300)
44
+ maxBackoffMs?: number; // Maximum backoff time in ms (default: 5000)
45
+ headers?: Record<string, string>; // Custom headers
255
46
  });
256
47
  ```
257
48
 
258
- ## Semantic versioning
259
-
260
- This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
261
-
262
- 1. Changes that only affect static types, without breaking runtime behavior.
263
- 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
264
- 3. Changes that we do not expect to impact the vast majority of users in practice.
265
-
266
- We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
267
-
268
- We are keen for your feedback; please open an [issue](https://www.github.com/mastra-ai/client-js/issues) with questions, bugs, or suggestions.
269
-
270
- ## Requirements
271
-
272
- TypeScript >= 4.5 is supported.
273
-
274
- The following runtimes are supported:
275
-
276
- - Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
277
- - Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
278
- - Deno v1.28.0 or higher.
279
- - Bun 1.0 or later.
280
- - Cloudflare Workers.
281
- - Vercel Edge Runtime.
282
- - Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
283
- - Nitro v2.6 or greater.
284
-
285
- Note that React Native is not supported at this time.
286
-
287
- If you are interested in other runtime environments, please open or upvote an issue on GitHub.
288
-
289
- ## Contributing
290
-
291
- See [the contributing documentation](./CONTRIBUTING.md).
49
+ ## Available Methods
50
+
51
+ ### Agents
52
+ - `getAgents()`: Get all available agents
53
+ - `getAgent(agentId)`: Get a specific agent instance
54
+ - `agent.details()`: Get agent details
55
+ - `agent.generate(params)`: Generate a response
56
+ - `agent.stream(params)`: Stream a response
57
+ - `agent.getTool(toolId)`: Get agent tool details
58
+ - `agent.evals()`: Get agent evaluations
59
+ - `agent.liveEvals()`: Get live evaluations
60
+
61
+ ### Memory
62
+ - `getMemoryThreads(params)`: Get memory threads
63
+ - `createMemoryThread(params)`: Create a new memory thread
64
+ - `getMemoryThread(threadId)`: Get a memory thread instance
65
+ - `saveMessageToMemory(params)`: Save messages to memory
66
+ - `getMemoryStatus()`: Get memory system status
67
+
68
+ ### Tools
69
+ - `getTools()`: Get all available tools
70
+ - `getTool(toolId)`: Get a tool instance
71
+ - `tool.details()`: Get tool details
72
+ - `tool.execute(params)`: Execute the tool
73
+
74
+ ### Workflows
75
+ - `getWorkflows()`: Get all workflows
76
+ - `getWorkflow(workflowId)`: Get a workflow instance
77
+ - `workflow.details()`: Get workflow details
78
+ - `workflow.execute(params)`: Execute the workflow
79
+
80
+ ### Vectors
81
+ - `getVector(vectorName)`: Get a vector instance
82
+ - `vector.details(indexName)`: Get vector index details
83
+ - `vector.delete(indexName)`: Delete a vector index
84
+ - `vector.getIndexes()`: Get all indexes
85
+ - `vector.createIndex(params)`: Create a new index
86
+ - `vector.upsert(params)`: Upsert vectors
87
+ - `vector.query(params)`: Query vectors
88
+
89
+ ### Logs
90
+ - `getLogs(params)`: Get system logs
91
+ - `getLog(params)`: Get specific log entry
92
+
93
+ ## Error Handling
94
+
95
+ The client includes built-in retry logic for failed requests:
96
+ - Automatically retries failed requests with exponential backoff
97
+ - Configurable retry count and backoff timing
98
+ - Throws error after max retries reached
99
+
100
+ ## Internal Implementation
101
+
102
+ The client uses the native `fetch` API internally for making HTTP requests. All requests are automatically handled with:
103
+ - JSON serialization/deserialization
104
+ - Retry logic with exponential backoff
105
+ - Custom header management
106
+ - Error handling
107
+
108
+ ## License
109
+
110
+ MIT