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