@mastra/client-js 0.1.0-alpha.1 → 0.1.0-alpha.11

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