@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/dist/index.mjs ADDED
@@ -0,0 +1,399 @@
1
+ // src/resources/agent.ts
2
+ var Agent = class {
3
+ constructor(request, agentId) {
4
+ this.request = request;
5
+ this.agentId = agentId;
6
+ }
7
+ /**
8
+ * Retrieves details about the agent
9
+ * @returns Promise containing agent details including model and instructions
10
+ */
11
+ details() {
12
+ return this.request(`/api/agents/${this.agentId}`);
13
+ }
14
+ /**
15
+ * Generates a response from the agent
16
+ * @param params - Generation parameters including prompt
17
+ * @returns Promise containing the generated response
18
+ */
19
+ generate(params) {
20
+ return this.request(`/api/agents/${this.agentId}/generate`, {
21
+ method: "POST",
22
+ body: params
23
+ });
24
+ }
25
+ /**
26
+ * Streams a response from the agent
27
+ * @param params - Stream parameters including prompt
28
+ * @returns Promise containing the streamed response
29
+ */
30
+ stream(params) {
31
+ return this.request(`/api/agents/${this.agentId}/generate`, {
32
+ method: "POST",
33
+ body: { ...params, stream: true }
34
+ });
35
+ }
36
+ /**
37
+ * Gets details about a specific tool available to the agent
38
+ * @param toolId - ID of the tool to retrieve
39
+ * @returns Promise containing tool details
40
+ */
41
+ getTool(toolId) {
42
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
43
+ }
44
+ /**
45
+ * Retrieves evaluation results for the agent
46
+ * @returns Promise containing agent evaluations
47
+ */
48
+ evals() {
49
+ return this.request(`/api/agents/${this.agentId}/evals`);
50
+ }
51
+ /**
52
+ * Retrieves live evaluation results for the agent
53
+ * @returns Promise containing live agent evaluations
54
+ */
55
+ liveEvals() {
56
+ return this.request(`/api/agents/${this.agentId}/evals/live`);
57
+ }
58
+ };
59
+
60
+ // src/resources/memory-thread.ts
61
+ var MemoryThread = class {
62
+ constructor(request, threadId) {
63
+ this.request = request;
64
+ this.threadId = threadId;
65
+ }
66
+ /**
67
+ * Retrieves the memory thread details
68
+ * @returns Promise containing thread details including title and metadata
69
+ */
70
+ get() {
71
+ return this.request(`/api/memory/threads/${this.threadId}`);
72
+ }
73
+ /**
74
+ * Updates the memory thread properties
75
+ * @param params - Update parameters including title and metadata
76
+ * @returns Promise containing updated thread details
77
+ */
78
+ update(params) {
79
+ return this.request(`/api/memory/threads/${this.threadId}`, {
80
+ method: "PATCH",
81
+ body: params
82
+ });
83
+ }
84
+ /**
85
+ * Deletes the memory thread
86
+ * @returns Promise containing deletion result
87
+ */
88
+ delete() {
89
+ return this.request(`/api/memory/threads/${this.threadId}`, {
90
+ method: "DELETE"
91
+ });
92
+ }
93
+ /**
94
+ * Retrieves messages associated with the thread
95
+ * @returns Promise containing thread messages and UI messages
96
+ */
97
+ getMessages() {
98
+ return this.request(`/api/memory/threads/${this.threadId}/messages`);
99
+ }
100
+ };
101
+
102
+ // src/resources/tool.ts
103
+ var Tool = class {
104
+ constructor(request, toolId) {
105
+ this.request = request;
106
+ this.toolId = toolId;
107
+ }
108
+ /**
109
+ * Retrieves details about the tool
110
+ * @returns Promise containing tool details including description and schemas
111
+ */
112
+ details() {
113
+ return this.request(`/api/tools/${this.toolId}`);
114
+ }
115
+ /**
116
+ * Executes the tool with the provided parameters
117
+ * @param params - Parameters required for tool execution
118
+ * @returns Promise containing the tool execution results
119
+ */
120
+ execute(params) {
121
+ return this.request(`/api/tools/${this.toolId}/execute`, {
122
+ method: "POST",
123
+ body: params
124
+ });
125
+ }
126
+ };
127
+
128
+ // src/resources/workflow.ts
129
+ var Workflow = class {
130
+ constructor(request, workflowId) {
131
+ this.request = request;
132
+ this.workflowId = workflowId;
133
+ }
134
+ /**
135
+ * Retrieves details about the workflow
136
+ * @returns Promise containing workflow details including steps and graphs
137
+ */
138
+ details() {
139
+ return this.request(`/api/workflows/${this.workflowId}`);
140
+ }
141
+ /**
142
+ * Executes the workflow with the provided parameters
143
+ * @param params - Parameters required for workflow execution
144
+ * @returns Promise containing the workflow execution results
145
+ */
146
+ execute(params) {
147
+ return this.request(`/api/workflows/${this.workflowId}/execute`, {
148
+ method: "POST",
149
+ body: params
150
+ });
151
+ }
152
+ };
153
+
154
+ // src/resources/vector.ts
155
+ var Vector = class {
156
+ constructor(request, vectorName) {
157
+ this.request = request;
158
+ this.vectorName = vectorName;
159
+ }
160
+ /**
161
+ * Retrieves details about a specific vector index
162
+ * @param indexName - Name of the index to get details for
163
+ * @returns Promise containing vector index details
164
+ */
165
+ details(indexName) {
166
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
167
+ }
168
+ /**
169
+ * Deletes a vector index
170
+ * @param indexName - Name of the index to delete
171
+ * @returns Promise indicating deletion success
172
+ */
173
+ delete(indexName) {
174
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
175
+ method: "DELETE"
176
+ });
177
+ }
178
+ /**
179
+ * Retrieves a list of all available indexes
180
+ * @returns Promise containing array of index names
181
+ */
182
+ getIndexes() {
183
+ return this.request(`/api/vector/${this.vectorName}/indexes`);
184
+ }
185
+ /**
186
+ * Creates a new vector index
187
+ * @param params - Parameters for index creation including dimension and metric
188
+ * @returns Promise indicating creation success
189
+ */
190
+ createIndex(params) {
191
+ return this.request(`/api/vector/${this.vectorName}/create-index`, {
192
+ method: "POST",
193
+ body: params
194
+ });
195
+ }
196
+ /**
197
+ * Upserts vectors into an index
198
+ * @param params - Parameters containing vectors, metadata, and optional IDs
199
+ * @returns Promise containing array of vector IDs
200
+ */
201
+ upsert(params) {
202
+ return this.request(`/api/vector/${this.vectorName}/upsert`, {
203
+ method: "POST",
204
+ body: params
205
+ });
206
+ }
207
+ /**
208
+ * Queries vectors in an index
209
+ * @param params - Query parameters including query vector and search options
210
+ * @returns Promise containing query results
211
+ */
212
+ query(params) {
213
+ return this.request(`/api/vector/${this.vectorName}/query`, {
214
+ method: "POST",
215
+ body: params
216
+ });
217
+ }
218
+ };
219
+
220
+ // src/client.ts
221
+ var MastraClient = class {
222
+ baseUrl;
223
+ retries;
224
+ backoffMs;
225
+ maxBackoffMs;
226
+ headers;
227
+ constructor(options) {
228
+ this.baseUrl = options.baseUrl.replace(/\/$/, "");
229
+ this.retries = options.retries ?? 3;
230
+ this.backoffMs = options.backoffMs ?? 300;
231
+ this.maxBackoffMs = options.maxBackoffMs ?? 5e3;
232
+ this.headers = {
233
+ "Content-Type": "application/json",
234
+ ...options.headers
235
+ };
236
+ }
237
+ /**
238
+ * Makes an HTTP request to the Mastra API
239
+ * @param path - API endpoint path
240
+ * @param options - Request options including method, headers, and body
241
+ * @returns Promise containing the API response
242
+ * @throws Error if the request fails after all retries
243
+ */
244
+ async request(path, options = {}) {
245
+ const url = `${this.baseUrl}${path}`;
246
+ let lastError = null;
247
+ let currentBackoff = this.backoffMs;
248
+ for (let attempt = 0; attempt <= this.retries; attempt++) {
249
+ try {
250
+ const response = await fetch(url, {
251
+ method: options.method ?? "GET",
252
+ headers: {
253
+ ...this.headers,
254
+ ...options.headers
255
+ },
256
+ body: options.body ? JSON.stringify(options.body) : void 0
257
+ });
258
+ if (!response.ok) {
259
+ throw new Error(`HTTP error! status: ${response.status}`);
260
+ }
261
+ return await response.json();
262
+ } catch (error) {
263
+ lastError = error;
264
+ if (attempt === this.retries) break;
265
+ await new Promise((resolve) => setTimeout(resolve, currentBackoff));
266
+ currentBackoff = Math.min(currentBackoff * 2, this.maxBackoffMs);
267
+ }
268
+ }
269
+ throw lastError;
270
+ }
271
+ /**
272
+ * Retrieves all available agents
273
+ * @returns Promise containing map of agent IDs to agent details
274
+ */
275
+ getAgents() {
276
+ return this.request("/api/agents");
277
+ }
278
+ /**
279
+ * Gets an agent instance by ID
280
+ * @param agentId - ID of the agent to retrieve
281
+ * @returns Agent instance
282
+ */
283
+ getAgent(agentId) {
284
+ return new Agent(
285
+ (path, options) => this.request(path, options),
286
+ agentId
287
+ );
288
+ }
289
+ /**
290
+ * Retrieves memory threads for a resource
291
+ * @param params - Parameters containing the resource ID
292
+ * @returns Promise containing array of memory threads
293
+ */
294
+ getMemoryThreads(params) {
295
+ return this.request(`/api/memory/threads?resourceid=${params.resourceId}`);
296
+ }
297
+ /**
298
+ * Creates a new memory thread
299
+ * @param params - Parameters for creating the memory thread
300
+ * @returns Promise containing the created memory thread
301
+ */
302
+ createMemoryThread(params) {
303
+ return this.request("/api/memory/threads", { method: "POST", body: params });
304
+ }
305
+ /**
306
+ * Gets a memory thread instance by ID
307
+ * @param threadId - ID of the memory thread to retrieve
308
+ * @returns MemoryThread instance
309
+ */
310
+ getMemoryThread(threadId) {
311
+ return new MemoryThread(
312
+ (path, options) => this.request(path, options),
313
+ threadId
314
+ );
315
+ }
316
+ /**
317
+ * Saves messages to memory
318
+ * @param params - Parameters containing messages to save
319
+ * @returns Promise containing the saved messages
320
+ */
321
+ saveMessageToMemory(params) {
322
+ return this.request("/api/memory/save-messages", {
323
+ method: "POST",
324
+ body: params
325
+ });
326
+ }
327
+ /**
328
+ * Gets the status of the memory system
329
+ * @returns Promise containing memory system status
330
+ */
331
+ getMemoryStatus() {
332
+ return this.request("/api/memory/status");
333
+ }
334
+ /**
335
+ * Retrieves all available tools
336
+ * @returns Promise containing map of tool IDs to tool details
337
+ */
338
+ getTools() {
339
+ return this.request("/api/tools");
340
+ }
341
+ /**
342
+ * Gets a tool instance by ID
343
+ * @param toolId - ID of the tool to retrieve
344
+ * @returns Tool instance
345
+ */
346
+ getTool(toolId) {
347
+ return new Tool(
348
+ (path, options) => this.request(path, options),
349
+ toolId
350
+ );
351
+ }
352
+ /**
353
+ * Retrieves all available workflows
354
+ * @returns Promise containing map of workflow IDs to workflow details
355
+ */
356
+ getWorkflows() {
357
+ return this.request("/api/workflows");
358
+ }
359
+ /**
360
+ * Gets a workflow instance by ID
361
+ * @param workflowId - ID of the workflow to retrieve
362
+ * @returns Workflow instance
363
+ */
364
+ getWorkflow(workflowId) {
365
+ return new Workflow(
366
+ (path, options) => this.request(path, options),
367
+ workflowId
368
+ );
369
+ }
370
+ /**
371
+ * Gets a vector instance by name
372
+ * @param vectorName - Name of the vector to retrieve
373
+ * @returns Vector instance
374
+ */
375
+ getVector(vectorName) {
376
+ return new Vector(
377
+ (path, options) => this.request(path, options),
378
+ vectorName
379
+ );
380
+ }
381
+ /**
382
+ * Retrieves logs
383
+ * @param params - Parameters for filtering logs
384
+ * @returns Promise containing array of log messages
385
+ */
386
+ getLogs(params) {
387
+ return this.request(`/api/logs?transportId=${params.transportId}`);
388
+ }
389
+ /**
390
+ * Gets logs for a specific run
391
+ * @param params - Parameters containing run ID to retrieve
392
+ * @returns Promise containing array of log messages
393
+ */
394
+ getLogForRun(params) {
395
+ return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
396
+ }
397
+ };
398
+
399
+ export { MastraClient };
package/package.json CHANGED
@@ -1,103 +1,38 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.0-alpha.2",
3
+ "version": "0.1.0-alpha.4",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
- "author": "Mastra Client <dev-feedback@mastra.com>",
6
- "types": "./index.d.ts",
7
- "main": "./index.js",
8
- "type": "commonjs",
9
- "repository": "github:mastra-ai/client-js",
10
- "license": "Apache-2.0",
11
- "packageManager": "yarn@1.22.22",
12
- "files": [
13
- "**/*"
14
- ],
15
- "private": false,
16
- "scripts": {
17
- "test": "./scripts/test",
18
- "build": "./scripts/build",
19
- "format": "prettier --write --cache --cache-strategy metadata . !dist",
20
- "tsn": "ts-node -r tsconfig-paths/register",
21
- "lint": "./scripts/lint",
22
- "fix": "./scripts/format"
5
+ "author": "",
6
+ "types": "dist/index.d.ts",
7
+ "main": "dist/index.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "./package.json": "./package.json"
23
16
  },
17
+ "repository": "github:mastra-ai/client-js",
18
+ "license": "ISC",
24
19
  "dependencies": {
25
- "@types/node": "^18.11.18",
26
- "@types/node-fetch": "^2.6.4",
27
- "abort-controller": "^3.0.0",
28
- "agentkeepalive": "^4.2.1",
29
- "form-data-encoder": "1.7.2",
30
- "formdata-node": "^4.3.2",
31
- "node-fetch": "^2.6.7"
20
+ "@mastra/core": "^0.2.0-alpha.83",
21
+ "json-schema": "^0.4.0"
32
22
  },
33
- "sideEffects": [
34
- "./_shims/index.js",
35
- "./_shims/index.mjs",
36
- "./shims/node.js",
37
- "./shims/node.mjs",
38
- "./shims/web.js",
39
- "./shims/web.mjs"
40
- ],
41
- "imports": {
42
- "@mastra/client-js": ".",
43
- "@mastra/client-js/*": "./src/*"
23
+ "devDependencies": {
24
+ "@babel/preset-env": "^7.26.0",
25
+ "@babel/preset-typescript": "^7.26.0",
26
+ "@tsconfig/recommended": "^1.0.7",
27
+ "@types/json-schema": "^7.0.15",
28
+ "@types/node": "^22.9.0",
29
+ "tsup": "^8.0.1",
30
+ "typescript": "^5.7.3",
31
+ "vitest": "^3.0.4"
44
32
  },
45
- "exports": {
46
- "./_shims/auto/*": {
47
- "deno": {
48
- "types": "./_shims/auto/*.d.ts",
49
- "require": "./_shims/auto/*.js",
50
- "default": "./_shims/auto/*.mjs"
51
- },
52
- "bun": {
53
- "types": "./_shims/auto/*.d.ts",
54
- "require": "./_shims/auto/*-bun.js",
55
- "default": "./_shims/auto/*-bun.mjs"
56
- },
57
- "browser": {
58
- "types": "./_shims/auto/*.d.ts",
59
- "require": "./_shims/auto/*.js",
60
- "default": "./_shims/auto/*.mjs"
61
- },
62
- "worker": {
63
- "types": "./_shims/auto/*.d.ts",
64
- "require": "./_shims/auto/*.js",
65
- "default": "./_shims/auto/*.mjs"
66
- },
67
- "workerd": {
68
- "types": "./_shims/auto/*.d.ts",
69
- "require": "./_shims/auto/*.js",
70
- "default": "./_shims/auto/*.mjs"
71
- },
72
- "node": {
73
- "types": "./_shims/auto/*-node.d.ts",
74
- "require": "./_shims/auto/*-node.js",
75
- "default": "./_shims/auto/*-node.mjs"
76
- },
77
- "types": "./_shims/auto/*.d.ts",
78
- "require": "./_shims/auto/*.js",
79
- "default": "./_shims/auto/*.mjs"
80
- },
81
- ".": {
82
- "require": {
83
- "types": "./index.d.ts",
84
- "default": "./index.js"
85
- },
86
- "types": "./index.d.mts",
87
- "default": "./index.mjs"
88
- },
89
- "./*.mjs": {
90
- "types": "./*.d.ts",
91
- "default": "./*.mjs"
92
- },
93
- "./*.js": {
94
- "types": "./*.d.ts",
95
- "default": "./*.js"
96
- },
97
- "./*": {
98
- "types": "./*.d.ts",
99
- "require": "./*.js",
100
- "default": "./*.mjs"
101
- }
33
+ "scripts": {
34
+ "build": "tsup-node src/index.ts --format esm --dts --clean --treeshake",
35
+ "dev": "tsup-node src/index.ts --format esm --dts --clean --treeshake --watch",
36
+ "test": "vitest run"
102
37
  }
103
- }
38
+ }