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

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 +346 -0
  7. package/dist/index.mjs +399 -0
  8. package/package.json +28 -95
  9. package/src/client.ts +201 -0
  10. package/src/index.test.ts +507 -0
  11. package/src/index.ts +2 -200
  12. package/src/resources/agent.ts +94 -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 +121 -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/src/index.ts CHANGED
@@ -1,200 +1,2 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- import { type Agent } from './_shims/index';
4
- import * as Core from './core';
5
- import * as Errors from './error';
6
- import * as Uploads from './uploads';
7
- import * as API from './resources/index';
8
- import { Logs } from './resources/logs';
9
- import { SyncExecuteParams, Syncs } from './resources/syncs';
10
- import { System } from './resources/system';
11
- import { WorkflowExecuteParams, Workflows } from './resources/workflows';
12
- import {
13
- AgentGenerateParams,
14
- AgentStreamParams,
15
- AgentStreamResponse,
16
- Agents,
17
- } from './resources/agents/agents';
18
- import { Memory, MemorySaveMessagesParams } from './resources/memory/memory';
19
- import { ToolExecuteParams, Tools } from './resources/tools/tools';
20
-
21
- export interface ClientOptions {
22
- /**
23
- * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
24
- *
25
- * Defaults to process.env['MASTRA_CLIENT_BASE_URL'].
26
- */
27
- baseURL?: string | null | undefined;
28
-
29
- /**
30
- * The maximum amount of time (in milliseconds) that the client should wait for a response
31
- * from the server before timing out a single request.
32
- *
33
- * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
34
- * much longer than this timeout before the promise succeeds or fails.
35
- */
36
- timeout?: number | undefined;
37
-
38
- /**
39
- * An HTTP agent used to manage HTTP(S) connections.
40
- *
41
- * If not provided, an agent will be constructed by default in the Node.js environment,
42
- * otherwise no agent is used.
43
- */
44
- httpAgent?: Agent | undefined;
45
-
46
- /**
47
- * Specify a custom `fetch` function implementation.
48
- *
49
- * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
50
- * defined globally.
51
- */
52
- fetch?: Core.Fetch | undefined;
53
-
54
- /**
55
- * The maximum number of times that the client will retry a request in case of a
56
- * temporary failure, like a network error or a 5XX error from the server.
57
- *
58
- * @default 2
59
- */
60
- maxRetries?: number | undefined;
61
-
62
- /**
63
- * Default headers to include with every request to the API.
64
- *
65
- * These can be removed in individual requests by explicitly setting the
66
- * header to `undefined` or `null` in request options.
67
- */
68
- defaultHeaders?: Core.Headers | undefined;
69
-
70
- /**
71
- * Default query parameters to include with every request to the API.
72
- *
73
- * These can be removed in individual requests by explicitly setting the
74
- * param to `undefined` in request options.
75
- */
76
- defaultQuery?: Core.DefaultQuery | undefined;
77
- }
78
-
79
- /**
80
- * API Client for interfacing with the Mastra Client API.
81
- */
82
- export class MastraClient extends Core.APIClient {
83
- private _options: ClientOptions;
84
-
85
- /**
86
- * API Client for interfacing with the Mastra Client API.
87
- *
88
- * @param {string} [opts.baseURL=process.env['MASTRA_CLIENT_BASE_URL'] ?? http://localhost:4111] - Override the default base URL for the API.
89
- * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
90
- * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
91
- * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
92
- * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
93
- * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
94
- * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
95
- */
96
- constructor({ baseURL = Core.readEnv('MASTRA_CLIENT_BASE_URL'), ...opts }: ClientOptions = {}) {
97
- const options: ClientOptions = {
98
- ...opts,
99
- baseURL: baseURL || `http://localhost:4111`,
100
- };
101
-
102
- super({
103
- baseURL: options.baseURL!,
104
- timeout: options.timeout ?? 60000 /* 1 minute */,
105
- httpAgent: options.httpAgent,
106
- maxRetries: options.maxRetries,
107
- fetch: options.fetch,
108
- });
109
-
110
- this._options = options;
111
- }
112
-
113
- system: API.System = new API.System(this);
114
- agents: API.Agents = new API.Agents(this);
115
- memory: API.Memory = new API.Memory(this);
116
- workflows: API.Workflows = new API.Workflows(this);
117
- syncs: API.Syncs = new API.Syncs(this);
118
- logs: API.Logs = new API.Logs(this);
119
- tools: API.Tools = new API.Tools(this);
120
-
121
- protected override defaultQuery(): Core.DefaultQuery | undefined {
122
- return this._options.defaultQuery;
123
- }
124
-
125
- protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
126
- return {
127
- ...super.defaultHeaders(opts),
128
- ...this._options.defaultHeaders,
129
- };
130
- }
131
-
132
- static MastraClient = this;
133
- static DEFAULT_TIMEOUT = 60000; // 1 minute
134
-
135
- static MastraClientError = Errors.MastraClientError;
136
- static APIError = Errors.APIError;
137
- static APIConnectionError = Errors.APIConnectionError;
138
- static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
139
- static APIUserAbortError = Errors.APIUserAbortError;
140
- static NotFoundError = Errors.NotFoundError;
141
- static ConflictError = Errors.ConflictError;
142
- static RateLimitError = Errors.RateLimitError;
143
- static BadRequestError = Errors.BadRequestError;
144
- static AuthenticationError = Errors.AuthenticationError;
145
- static InternalServerError = Errors.InternalServerError;
146
- static PermissionDeniedError = Errors.PermissionDeniedError;
147
- static UnprocessableEntityError = Errors.UnprocessableEntityError;
148
-
149
- static toFile = Uploads.toFile;
150
- static fileFromPath = Uploads.fileFromPath;
151
- }
152
-
153
- MastraClient.System = System;
154
- MastraClient.Agents = Agents;
155
- MastraClient.Memory = Memory;
156
- MastraClient.Workflows = Workflows;
157
- MastraClient.Syncs = Syncs;
158
- MastraClient.Logs = Logs;
159
- MastraClient.Tools = Tools;
160
- export declare namespace MastraClient {
161
- export type RequestOptions = Core.RequestOptions;
162
-
163
- export { System as System };
164
-
165
- export {
166
- Agents as Agents,
167
- type AgentStreamResponse as AgentStreamResponse,
168
- type AgentGenerateParams as AgentGenerateParams,
169
- type AgentStreamParams as AgentStreamParams,
170
- };
171
-
172
- export { Memory as Memory, type MemorySaveMessagesParams as MemorySaveMessagesParams };
173
-
174
- export { Workflows as Workflows, type WorkflowExecuteParams as WorkflowExecuteParams };
175
-
176
- export { Syncs as Syncs, type SyncExecuteParams as SyncExecuteParams };
177
-
178
- export { Logs as Logs };
179
-
180
- export { Tools as Tools, type ToolExecuteParams as ToolExecuteParams };
181
- }
182
-
183
- export { toFile, fileFromPath } from './uploads';
184
- export {
185
- MastraClientError,
186
- APIError,
187
- APIConnectionError,
188
- APIConnectionTimeoutError,
189
- APIUserAbortError,
190
- NotFoundError,
191
- ConflictError,
192
- RateLimitError,
193
- BadRequestError,
194
- AuthenticationError,
195
- InternalServerError,
196
- PermissionDeniedError,
197
- UnprocessableEntityError,
198
- } from './error';
199
-
200
- export default MastraClient;
1
+ export * from './client';
2
+ export * from './types';
@@ -0,0 +1,94 @@
1
+ import type {
2
+ GetAgentResponse,
3
+ GetEvalsByAgentIdResponse,
4
+ GetToolResponse,
5
+ RequestFunction,
6
+ } from '../types';
7
+ import type {
8
+ GenerateReturn,
9
+ StreamReturn,
10
+ } from '@mastra/core';
11
+
12
+ export class AgentTool {
13
+ constructor(
14
+ private request: RequestFunction,
15
+ private agentId: string,
16
+ private toolId: string
17
+ ) { }
18
+
19
+ /**
20
+ * Executes a specific tool for an agent
21
+ * @param params - Parameters required for tool execution
22
+ * @returns Promise containing tool execution results
23
+ */
24
+ execute(params: Record<string, any>): Promise<Record<string, any>> {
25
+ return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
26
+ method: 'POST',
27
+ body: params,
28
+ });
29
+ }
30
+ }
31
+
32
+ export class Agent {
33
+ constructor(
34
+ private request: RequestFunction,
35
+ private agentId: string
36
+ ) { }
37
+
38
+ /**
39
+ * Retrieves details about the agent
40
+ * @returns Promise containing agent details including model and instructions
41
+ */
42
+ details(): Promise<GetAgentResponse> {
43
+ return this.request(`/api/agents/${this.agentId}`);
44
+ }
45
+
46
+ /**
47
+ * Generates a response from the agent
48
+ * @param params - Generation parameters including prompt
49
+ * @returns Promise containing the generated response
50
+ */
51
+ generate<T>(params: any): Promise<GenerateReturn<T>> {
52
+ return this.request(`/api/agents/${this.agentId}/generate`, {
53
+ method: 'POST',
54
+ body: params,
55
+ });
56
+ }
57
+
58
+ /**
59
+ * Streams a response from the agent
60
+ * @param params - Stream parameters including prompt
61
+ * @returns Promise containing the streamed response
62
+ */
63
+ stream<T>(params: any): Promise<StreamReturn<T>> {
64
+ return this.request(`/api/agents/${this.agentId}/generate`, {
65
+ method: 'POST',
66
+ body: { ...params, stream: true },
67
+ });
68
+ }
69
+
70
+ /**
71
+ * Gets details about a specific tool available to the agent
72
+ * @param toolId - ID of the tool to retrieve
73
+ * @returns Promise containing tool details
74
+ */
75
+ getTool(toolId: string): Promise<GetToolResponse> {
76
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
77
+ }
78
+
79
+ /**
80
+ * Retrieves evaluation results for the agent
81
+ * @returns Promise containing agent evaluations
82
+ */
83
+ evals(): Promise<GetEvalsByAgentIdResponse> {
84
+ return this.request(`/api/agents/${this.agentId}/evals`);
85
+ }
86
+
87
+ /**
88
+ * Retrieves live evaluation results for the agent
89
+ * @returns Promise containing live agent evaluations
90
+ */
91
+ liveEvals(): Promise<GetEvalsByAgentIdResponse> {
92
+ return this.request(`/api/agents/${this.agentId}/evals/live`);
93
+ }
94
+ }
@@ -1,14 +1,5 @@
1
- // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
-
3
- export {
4
- Agents,
5
- type AgentStreamResponse,
6
- type AgentGenerateParams,
7
- type AgentStreamParams,
8
- } from './agents/agents';
9
- export { Logs } from './logs';
10
- export { Memory, type MemorySaveMessagesParams } from './memory/memory';
11
- export { Syncs, type SyncExecuteParams } from './syncs';
12
- export { System } from './system';
13
- export { Tools, type ToolExecuteParams } from './tools/tools';
14
- export { Workflows, type WorkflowExecuteParams } from './workflows';
1
+ export * from './agent';
2
+ export * from './memory-thread';
3
+ export * from './tool';
4
+ export * from './workflow';
5
+ export * from './vector';
@@ -0,0 +1,51 @@
1
+ import type { StorageThreadType } from '@mastra/core/memory';
2
+ import type {
3
+ GetMemoryThreadMessagesResponse,
4
+ UpdateMemoryThreadParams,
5
+ RequestFunction
6
+ } from '../types';
7
+
8
+ export class MemoryThread {
9
+ constructor(
10
+ private request: RequestFunction,
11
+ private threadId: string
12
+ ) { }
13
+
14
+ /**
15
+ * Retrieves the memory thread details
16
+ * @returns Promise containing thread details including title and metadata
17
+ */
18
+ get(): Promise<StorageThreadType> {
19
+ return this.request(`/api/memory/threads/${this.threadId}`);
20
+ }
21
+
22
+ /**
23
+ * Updates the memory thread properties
24
+ * @param params - Update parameters including title and metadata
25
+ * @returns Promise containing updated thread details
26
+ */
27
+ update(params: UpdateMemoryThreadParams): Promise<StorageThreadType> {
28
+ return this.request(`/api/memory/threads/${this.threadId}`, {
29
+ method: 'PATCH',
30
+ body: params,
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Deletes the memory thread
36
+ * @returns Promise containing deletion result
37
+ */
38
+ delete(): Promise<{ result: string }> {
39
+ return this.request(`/api/memory/threads/${this.threadId}`, {
40
+ method: 'DELETE',
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Retrieves messages associated with the thread
46
+ * @returns Promise containing thread messages and UI messages
47
+ */
48
+ getMessages(): Promise<GetMemoryThreadMessagesResponse> {
49
+ return this.request(`/api/memory/threads/${this.threadId}/messages`);
50
+ }
51
+ }
@@ -0,0 +1,28 @@
1
+ import type { GetToolResponse, RequestFunction } from '../types';
2
+
3
+ export class Tool {
4
+ constructor(
5
+ private request: RequestFunction,
6
+ private toolId: string
7
+ ) { }
8
+
9
+ /**
10
+ * Retrieves details about the tool
11
+ * @returns Promise containing tool details including description and schemas
12
+ */
13
+ details(): Promise<GetToolResponse> {
14
+ return this.request(`/api/tools/${this.toolId}`);
15
+ }
16
+
17
+ /**
18
+ * Executes the tool with the provided parameters
19
+ * @param params - Parameters required for tool execution
20
+ * @returns Promise containing the tool execution results
21
+ */
22
+ execute(params: Record<string, any>): Promise<Record<string, any>> {
23
+ return this.request(`/api/tools/${this.toolId}/execute`, {
24
+ method: 'POST',
25
+ body: params,
26
+ });
27
+ }
28
+ }
@@ -0,0 +1,79 @@
1
+ import type {
2
+ CreateIndexParams,
3
+ GetVectorIndexResponse,
4
+ QueryVectorParams,
5
+ QueryVectorResponse,
6
+ UpsertVectorParams,
7
+ RequestFunction
8
+ } from '../types';
9
+
10
+ export class Vector {
11
+ constructor(
12
+ private request: RequestFunction,
13
+ private vectorName: string
14
+ ) { }
15
+
16
+ /**
17
+ * Retrieves details about a specific vector index
18
+ * @param indexName - Name of the index to get details for
19
+ * @returns Promise containing vector index details
20
+ */
21
+ details(indexName: string): Promise<GetVectorIndexResponse> {
22
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`);
23
+ }
24
+
25
+ /**
26
+ * Deletes a vector index
27
+ * @param indexName - Name of the index to delete
28
+ * @returns Promise indicating deletion success
29
+ */
30
+ delete(indexName: string): Promise<{ success: boolean }> {
31
+ return this.request(`/api/vector/${this.vectorName}/indexes/${indexName}`, {
32
+ method: 'DELETE'
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Retrieves a list of all available indexes
38
+ * @returns Promise containing array of index names
39
+ */
40
+ getIndexes(): Promise<{ indexes: string[] }> {
41
+ return this.request(`/api/vector/${this.vectorName}/indexes`);
42
+ }
43
+
44
+ /**
45
+ * Creates a new vector index
46
+ * @param params - Parameters for index creation including dimension and metric
47
+ * @returns Promise indicating creation success
48
+ */
49
+ createIndex(params: CreateIndexParams): Promise<{ success: boolean }> {
50
+ return this.request(`/api/vector/${this.vectorName}/create-index`, {
51
+ method: 'POST',
52
+ body: params
53
+ });
54
+ }
55
+
56
+ /**
57
+ * Upserts vectors into an index
58
+ * @param params - Parameters containing vectors, metadata, and optional IDs
59
+ * @returns Promise containing array of vector IDs
60
+ */
61
+ upsert(params: UpsertVectorParams): Promise<string[]> {
62
+ return this.request(`/api/vector/${this.vectorName}/upsert`, {
63
+ method: 'POST',
64
+ body: params
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Queries vectors in an index
70
+ * @param params - Query parameters including query vector and search options
71
+ * @returns Promise containing query results
72
+ */
73
+ query(params: QueryVectorParams): Promise<QueryVectorResponse> {
74
+ return this.request(`/api/vector/${this.vectorName}/query`, {
75
+ method: 'POST',
76
+ body: params
77
+ });
78
+ }
79
+ }
@@ -0,0 +1,28 @@
1
+ import type { GetWorkflowResponse, RequestFunction } from '../types';
2
+
3
+ export class Workflow {
4
+ constructor(
5
+ private request: RequestFunction,
6
+ private workflowId: string
7
+ ) { }
8
+
9
+ /**
10
+ * Retrieves details about the workflow
11
+ * @returns Promise containing workflow details including steps and graphs
12
+ */
13
+ details(): Promise<GetWorkflowResponse> {
14
+ return this.request(`/api/workflows/${this.workflowId}`);
15
+ }
16
+
17
+ /**
18
+ * Executes the workflow with the provided parameters
19
+ * @param params - Parameters required for workflow execution
20
+ * @returns Promise containing the workflow execution results
21
+ */
22
+ execute(params: Record<string, any>): Promise<Record<string, any>> {
23
+ return this.request(`/api/workflows/${this.workflowId}/execute`, {
24
+ method: 'POST',
25
+ body: params,
26
+ });
27
+ }
28
+ }
package/src/types.ts ADDED
@@ -0,0 +1,121 @@
1
+ import type { MessageType, AiMessageType, CoreMessage, QueryResult, StepAction, StepGraph, StorageThreadType, BaseLogMessage } from "@mastra/core";
2
+
3
+
4
+ export interface ClientOptions {
5
+ baseUrl: string;
6
+ retries?: number;
7
+ backoffMs?: number;
8
+ maxBackoffMs?: number;
9
+ headers?: Record<string, string>;
10
+ }
11
+
12
+ export interface RequestOptions {
13
+ method?: string;
14
+ headers?: Record<string, string>;
15
+ body?: any;
16
+ }
17
+
18
+ export interface GetAgentResponse {
19
+ name: string;
20
+ model: string;
21
+ instructions: string;
22
+ tools: Record<string, GetToolResponse>;
23
+ }
24
+
25
+ export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
26
+ evals: any[];
27
+ }
28
+
29
+ export interface GetToolResponse {
30
+ id: string;
31
+ description: string;
32
+ inputSchema: string;
33
+ outputSchema: string;
34
+ }
35
+
36
+ export interface GetWorkflowResponse {
37
+ name: string;
38
+ triggerSchema: string;
39
+ steps: Record<string, StepAction<any, any, any, any>>;
40
+ stepGraph: StepGraph
41
+ stepSubscriberGraph: Record<string, StepGraph>
42
+ }
43
+
44
+ export interface UpsertVectorParams {
45
+ indexName: string;
46
+ vectors: number[][];
47
+ metadata?: Record<string, any>[];
48
+ ids?: string[];
49
+ }
50
+ export interface CreateIndexParams {
51
+ indexName: string;
52
+ dimension: number;
53
+ metric?: 'cosine' | 'euclidean' | 'dotproduct';
54
+ }
55
+
56
+ export interface QueryVectorParams {
57
+ indexName: string;
58
+ queryVector: number[];
59
+ topK?: number;
60
+ filter?: Record<string, any>;
61
+ includeVector?: boolean;
62
+ }
63
+
64
+ export interface QueryVectorResponse {
65
+ results: QueryResult[];
66
+ }
67
+
68
+ export interface GetVectorIndexResponse {
69
+ dimension: number;
70
+ metric: 'cosine' | 'euclidean' | 'dotproduct';
71
+ count: number;
72
+ }
73
+
74
+ export interface SaveMessageToMemoryParams {
75
+ messages: MessageType[];
76
+ }
77
+
78
+ export type SaveMessageToMemoryResponse = MessageType[]
79
+
80
+ export interface CreateMemoryThreadParams {
81
+ title: string;
82
+ metadata: Record<string, any>;
83
+ resourceid: string;
84
+ threadId: string;
85
+ }
86
+
87
+ export type CreateMemoryThreadResponse = StorageThreadType
88
+
89
+ export interface GetMemoryThreadParams {
90
+ resourceId: string;
91
+ }
92
+
93
+ export type GetMemoryThreadResponse = StorageThreadType[]
94
+
95
+ export interface UpdateMemoryThreadParams {
96
+ title: string;
97
+ metadata: Record<string, any>;
98
+ resourceid: string;
99
+ }
100
+
101
+
102
+ export interface GetMemoryThreadMessagesResponse {
103
+ messages: CoreMessage[];
104
+ uiMessages: AiMessageType[];
105
+ }
106
+
107
+ export interface GetLogsParams {
108
+ transportId: string;
109
+ }
110
+
111
+ export interface GetLogParams {
112
+ runId: string;
113
+ transportId: string;
114
+ }
115
+
116
+ export type GetLogsResponse = BaseLogMessage[]
117
+
118
+ export type RequestFunction = (
119
+ path: string,
120
+ options?: RequestOptions
121
+ ) => Promise<any>;
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ /* Base Options: */
5
+ "esModuleInterop": true,
6
+ "skipLibCheck": true,
7
+ "target": "es2022",
8
+ "allowJs": true,
9
+ "resolveJsonModule": true,
10
+ "moduleDetection": "force",
11
+ "isolatedModules": true,
12
+ "verbatimModuleSyntax": true,
13
+ /* Strictness */
14
+ "strict": true,
15
+ "noUncheckedIndexedAccess": true,
16
+ // "noImplicitOverride": true,
17
+ /* AND if you're building for a library in a monorepo: */
18
+ // "composite": true,
19
+ "declaration": true,
20
+ "declarationMap": true,
21
+ /* If NOT transpiling with TypeScript: */
22
+ "module": "Preserve",
23
+ "noEmit": true,
24
+ /* If your code doesn't run in the DOM: */
25
+ "lib": [
26
+ "es2022"
27
+ ]
28
+ }
29
+ }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'node',
6
+ include: ['src/**/*.test.ts'],
7
+ },
8
+ });