@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
@@ -1,46 +0,0 @@
1
- # 👋 Wondering what everything in here does?
2
-
3
- `@mastra/client-js` supports a wide variety of runtime environments like Node.js, Deno, Bun, browsers, and various
4
- edge runtimes, as well as both CommonJS (CJS) and EcmaScript Modules (ESM).
5
-
6
- To do this, `@mastra/client-js` provides shims for either using `node-fetch` when in Node (because `fetch` is still experimental there) or the global `fetch` API built into the environment when not in Node.
7
-
8
- It uses [conditional exports](https://nodejs.org/api/packages.html#conditional-exports) to
9
- automatically select the correct shims for each environment. However, conditional exports are a fairly new
10
- feature and not supported everywhere. For instance, the TypeScript `"moduleResolution": "node"`
11
-
12
- setting doesn't consult the `exports` map, compared to `"moduleResolution": "nodeNext"`, which does.
13
- Unfortunately that's still the default setting, and it can result in errors like
14
- getting the wrong raw `Response` type from `.asResponse()`, for example.
15
-
16
- The user can work around these issues by manually importing one of:
17
-
18
- - `import '@mastra/client-js/shims/node'`
19
- - `import '@mastra/client-js/shims/web'`
20
-
21
- All of the code here in `_shims` handles selecting the automatic default shims or manual overrides.
22
-
23
- ### How it works - Runtime
24
-
25
- Runtime shims get installed by calling `setShims` exported by `@mastra/client-js/_shims/registry`.
26
-
27
- Manually importing `@mastra/client-js/shims/node` or `@mastra/client-js/shims/web`, calls `setShims` with the respective runtime shims.
28
-
29
- All client code imports shims from `@mastra/client-js/_shims/index`, which:
30
-
31
- - checks if shims have been set manually
32
- - if not, calls `setShims` with the shims from `@mastra/client-js/_shims/auto/runtime`
33
- - re-exports the installed shims from `@mastra/client-js/_shims/registry`.
34
-
35
- `@mastra/client-js/_shims/auto/runtime` exports web runtime shims.
36
- If the `node` export condition is set, the export map replaces it with `@mastra/client-js/_shims/auto/runtime-node`.
37
-
38
- ### How it works - Type time
39
-
40
- All client code imports shim types from `@mastra/client-js/_shims/index`, which selects the manual types from `@mastra/client-js/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@mastra/client-js/_shims/auto/types`.
41
-
42
- `@mastra/client-js/_shims/manual-types` exports an empty namespace.
43
- Manually importing `@mastra/client-js/shims/node` or `@mastra/client-js/shims/web` merges declarations into this empty namespace, so they get picked up by `@mastra/client-js/_shims/index`.
44
-
45
- `@mastra/client-js/_shims/auto/types` exports web type definitions.
46
- If the `node` export condition is set, the export map replaces it with `@mastra/client-js/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
@@ -1,4 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- export * from '../bun-runtime';
@@ -1,4 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- export * from '../node-runtime';
@@ -1,4 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- export * from '../web-runtime';
@@ -1,4 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- export * from '../node-types';
@@ -1,101 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- export type Agent = any;
5
-
6
- // @ts-ignore
7
- declare const _fetch: typeof fetch;
8
- export { _fetch as fetch };
9
-
10
- // @ts-ignore
11
- type _Request = Request;
12
- export { _Request as Request };
13
-
14
- // @ts-ignore
15
- type _RequestInfo = RequestInfo;
16
- export { type _RequestInfo as RequestInfo };
17
-
18
- // @ts-ignore
19
- type _RequestInit = RequestInit;
20
- export { type _RequestInit as RequestInit };
21
-
22
- // @ts-ignore
23
- type _Response = Response;
24
- export { _Response as Response };
25
-
26
- // @ts-ignore
27
- type _ResponseInit = ResponseInit;
28
- export { type _ResponseInit as ResponseInit };
29
-
30
- // @ts-ignore
31
- type _ResponseType = ResponseType;
32
- export { type _ResponseType as ResponseType };
33
-
34
- // @ts-ignore
35
- type _BodyInit = BodyInit;
36
- export { type _BodyInit as BodyInit };
37
-
38
- // @ts-ignore
39
- type _Headers = Headers;
40
- export { _Headers as Headers };
41
-
42
- // @ts-ignore
43
- type _HeadersInit = HeadersInit;
44
- export { type _HeadersInit as HeadersInit };
45
-
46
- type EndingType = 'native' | 'transparent';
47
-
48
- export interface BlobPropertyBag {
49
- endings?: EndingType;
50
- type?: string;
51
- }
52
-
53
- export interface FilePropertyBag extends BlobPropertyBag {
54
- lastModified?: number;
55
- }
56
-
57
- export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
58
-
59
- // @ts-ignore
60
- type _FormData = FormData;
61
- // @ts-ignore
62
- declare const _FormData: typeof FormData;
63
- export { _FormData as FormData };
64
-
65
- // @ts-ignore
66
- type _File = File;
67
- // @ts-ignore
68
- declare const _File: typeof File;
69
- export { _File as File };
70
-
71
- // @ts-ignore
72
- type _Blob = Blob;
73
- // @ts-ignore
74
- declare const _Blob: typeof Blob;
75
- export { _Blob as Blob };
76
-
77
- export declare class Readable {
78
- readable: boolean;
79
- readonly readableEnded: boolean;
80
- readonly readableFlowing: boolean | null;
81
- readonly readableHighWaterMark: number;
82
- readonly readableLength: number;
83
- readonly readableObjectMode: boolean;
84
- destroyed: boolean;
85
- read(size?: number): any;
86
- pause(): this;
87
- resume(): this;
88
- isPaused(): boolean;
89
- destroy(error?: Error): this;
90
- [Symbol.asyncIterator](): AsyncIterableIterator<any>;
91
- }
92
-
93
- export declare class FsReadStream extends Readable {
94
- path: {}; // node type is string | Buffer
95
- }
96
-
97
- // @ts-ignore
98
- type _ReadableStream<R = any> = ReadableStream<R>;
99
- // @ts-ignore
100
- declare const _ReadableStream: typeof ReadableStream;
101
- export { _ReadableStream as ReadableStream };
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,14 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import { type Shims } from './registry';
5
- import { getRuntime as getWebRuntime } from './web-runtime';
6
- import { ReadStream as FsReadStream } from 'node:fs';
7
-
8
- export function getRuntime(): Shims {
9
- const runtime = getWebRuntime();
10
- function isFsReadStream(value: any): value is FsReadStream {
11
- return value instanceof FsReadStream;
12
- }
13
- return { ...runtime, isFsReadStream };
14
- }
@@ -1,81 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import { manual } from './manual-types';
5
- import * as auto from "./auto/types";
6
- import { type RequestOptions } from '../core';
7
-
8
- type SelectType<Manual, Auto> = unknown extends Manual ? Auto : Manual;
9
-
10
- export const kind: string;
11
-
12
- // @ts-ignore
13
- export type Agent = SelectType<manual.Agent, auto.Agent>;
14
-
15
- // @ts-ignore
16
- export const fetch: SelectType<typeof manual.fetch, typeof auto.fetch>;
17
-
18
- // @ts-ignore
19
- export type Request = SelectType<manual.Request, auto.Request>;
20
- // @ts-ignore
21
- export type RequestInfo = SelectType<manual.RequestInfo, auto.RequestInfo>;
22
- // @ts-ignore
23
- export type RequestInit = SelectType<manual.RequestInit, auto.RequestInit>;
24
-
25
- // @ts-ignore
26
- export type Response = SelectType<manual.Response, auto.Response>;
27
- // @ts-ignore
28
- export type ResponseInit = SelectType<manual.ResponseInit, auto.ResponseInit>;
29
- // @ts-ignore
30
- export type ResponseType = SelectType<manual.ResponseType, auto.ResponseType>;
31
- // @ts-ignore
32
- export type BodyInit = SelectType<manual.BodyInit, auto.BodyInit>;
33
- // @ts-ignore
34
- export type Headers = SelectType<manual.Headers, auto.Headers>;
35
- // @ts-ignore
36
- export const Headers: SelectType<typeof manual.Headers, typeof auto.Headers>;
37
- // @ts-ignore
38
- export type HeadersInit = SelectType<manual.HeadersInit, auto.HeadersInit>;
39
-
40
- // @ts-ignore
41
- export type BlobPropertyBag = SelectType<manual.BlobPropertyBag, auto.BlobPropertyBag>;
42
- // @ts-ignore
43
- export type FilePropertyBag = SelectType<manual.FilePropertyBag, auto.FilePropertyBag>;
44
- // @ts-ignore
45
- export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;
46
- // @ts-ignore
47
- export type FormData = SelectType<manual.FormData, auto.FormData>;
48
- // @ts-ignore
49
- export const FormData: SelectType<typeof manual.FormData, typeof auto.FormData>;
50
- // @ts-ignore
51
- export type File = SelectType<manual.File, auto.File>;
52
- // @ts-ignore
53
- export const File: SelectType<typeof manual.File, typeof auto.File>;
54
- // @ts-ignore
55
- export type Blob = SelectType<manual.Blob, auto.Blob>;
56
- // @ts-ignore
57
- export const Blob: SelectType<typeof manual.Blob, typeof auto.Blob>;
58
-
59
- // @ts-ignore
60
- export type Readable = SelectType<manual.Readable, auto.Readable>;
61
- // @ts-ignore
62
- export type FsReadStream = SelectType<manual.FsReadStream, auto.FsReadStream>;
63
- // @ts-ignore
64
- export type ReadableStream = SelectType<manual.ReadableStream, auto.ReadableStream>;
65
- // @ts-ignore
66
- export const ReadableStream: SelectType<typeof manual.ReadableStream, typeof auto.ReadableStream>;
67
-
68
- export function getMultipartRequestOptions<T = Record<string, unknown>>(
69
- form: FormData,
70
- opts: RequestOptions<T>,
71
- ): Promise<RequestOptions<T>>;
72
-
73
- export function getDefaultAgent(url: string): any;
74
-
75
- // @ts-ignore
76
- export type FileFromPathOptions = SelectType<manual.FileFromPathOptions, auto.FileFromPathOptions>;
77
-
78
- export function fileFromPath(path: string, options?: FileFromPathOptions): Promise<File>;
79
- export function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
80
-
81
- export function isFsReadStream(value: any): value is FsReadStream;
@@ -1,13 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- const shims = require('./registry');
5
- const auto = require('@mastra/client-js/_shims/auto/runtime');
6
- if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
7
- for (const property of Object.keys(shims)) {
8
- Object.defineProperty(exports, property, {
9
- get() {
10
- return shims[property];
11
- },
12
- });
13
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import * as shims from './registry.mjs';
5
- import * as auto from "./auto/runtime";
6
- if (!shims.kind) shims.setShims(auto.getRuntime(), { auto: true });
7
- export * from './registry.mjs';
@@ -1,12 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- /**
5
- * Types will get added to this namespace when you import one of the following:
6
- *
7
- * import '@mastra/client-js/shims/node'
8
- * import '@mastra/client-js/shims/web'
9
- *
10
- * Importing more than one will cause type and runtime errors.
11
- */
12
- export namespace manual {}
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,81 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import * as nf from 'node-fetch';
5
- import * as fd from 'formdata-node';
6
- import { type File, type FilePropertyBag } from 'formdata-node';
7
- import KeepAliveAgent from 'agentkeepalive';
8
- import { AbortController as AbortControllerPolyfill } from 'abort-controller';
9
- import { ReadStream as FsReadStream } from 'node:fs';
10
- import { type Agent } from 'node:http';
11
- import { FormDataEncoder } from 'form-data-encoder';
12
- import { Readable } from 'node:stream';
13
- import { type RequestOptions } from '../core';
14
- import { MultipartBody } from './MultipartBody';
15
- import { type Shims } from './registry';
16
- import { ReadableStream } from 'node:stream/web';
17
-
18
- type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
19
-
20
- let fileFromPathWarned = false;
21
-
22
- /**
23
- * @deprecated use fs.createReadStream('./my/file.txt') instead
24
- */
25
- async function fileFromPath(path: string): Promise<File>;
26
- async function fileFromPath(path: string, filename?: string): Promise<File>;
27
- async function fileFromPath(path: string, options?: FileFromPathOptions): Promise<File>;
28
- async function fileFromPath(path: string, filename?: string, options?: FileFromPathOptions): Promise<File>;
29
- async function fileFromPath(path: string, ...args: any[]): Promise<File> {
30
- // this import fails in environments that don't handle export maps correctly, like old versions of Jest
31
- const { fileFromPath: _fileFromPath } = await import('formdata-node/file-from-path');
32
-
33
- if (!fileFromPathWarned) {
34
- console.warn(`fileFromPath is deprecated; use fs.createReadStream(${JSON.stringify(path)}) instead`);
35
- fileFromPathWarned = true;
36
- }
37
- // @ts-ignore
38
- return await _fileFromPath(path, ...args);
39
- }
40
-
41
- const defaultHttpAgent: Agent = new KeepAliveAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
42
- const defaultHttpsAgent: Agent = new KeepAliveAgent.HttpsAgent({ keepAlive: true, timeout: 5 * 60 * 1000 });
43
-
44
- async function getMultipartRequestOptions<T = Record<string, unknown>>(
45
- form: fd.FormData,
46
- opts: RequestOptions<T>,
47
- ): Promise<RequestOptions<T>> {
48
- const encoder = new FormDataEncoder(form);
49
- const readable = Readable.from(encoder);
50
- const body = new MultipartBody(readable);
51
- const headers = {
52
- ...opts.headers,
53
- ...encoder.headers,
54
- 'Content-Length': encoder.contentLength,
55
- };
56
-
57
- return { ...opts, body: body as any, headers };
58
- }
59
-
60
- export function getRuntime(): Shims {
61
- // Polyfill global object if needed.
62
- if (typeof AbortController === 'undefined') {
63
- // @ts-expect-error (the types are subtly different, but compatible in practice)
64
- globalThis.AbortController = AbortControllerPolyfill;
65
- }
66
- return {
67
- kind: 'node',
68
- fetch: nf.default,
69
- Request: nf.Request,
70
- Response: nf.Response,
71
- Headers: nf.Headers,
72
- FormData: fd.FormData,
73
- Blob: fd.Blob,
74
- File: fd.File,
75
- ReadableStream,
76
- getMultipartRequestOptions,
77
- getDefaultAgent: (url: string): Agent => (url.startsWith('https') ? defaultHttpsAgent : defaultHttpAgent),
78
- fileFromPath,
79
- isFsReadStream: (value: any): value is FsReadStream => value instanceof FsReadStream,
80
- };
81
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import * as nf from 'node-fetch';
5
- import * as fd from 'formdata-node';
6
-
7
- export { type Agent } from 'node:http';
8
- export { type Readable } from 'node:stream';
9
- export { type ReadStream as FsReadStream } from 'node:fs';
10
- export { ReadableStream } from 'node:stream/web';
11
-
12
- export const fetch: typeof nf.default;
13
-
14
- export type Request = nf.Request;
15
- export type RequestInfo = nf.RequestInfo;
16
- export type RequestInit = nf.RequestInit;
17
-
18
- export type Response = nf.Response;
19
- export type ResponseInit = nf.ResponseInit;
20
- export type ResponseType = nf.ResponseType;
21
- export type BodyInit = nf.BodyInit;
22
- export type Headers = nf.Headers;
23
- export type HeadersInit = nf.HeadersInit;
24
-
25
- type EndingType = 'native' | 'transparent';
26
- export interface BlobPropertyBag {
27
- endings?: EndingType;
28
- type?: string;
29
- }
30
-
31
- export interface FilePropertyBag extends BlobPropertyBag {
32
- lastModified?: number;
33
- }
34
-
35
- export type FileFromPathOptions = Omit<FilePropertyBag, 'lastModified'>;
36
-
37
- export type FormData = fd.FormData;
38
- export const FormData: typeof fd.FormData;
39
- export type File = fd.File;
40
- export const File: typeof fd.File;
41
- export type Blob = fd.Blob;
42
- export const Blob: typeof fd.Blob;
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,3 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
@@ -1,67 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import { type RequestOptions } from '../core';
5
-
6
- export interface Shims {
7
- kind: string;
8
- fetch: any;
9
- Request: any;
10
- Response: any;
11
- Headers: any;
12
- FormData: any;
13
- Blob: any;
14
- File: any;
15
- ReadableStream: any;
16
- getMultipartRequestOptions: <T = Record<string, unknown>>(
17
- form: Shims['FormData'],
18
- opts: RequestOptions<T>,
19
- ) => Promise<RequestOptions<T>>;
20
- getDefaultAgent: (url: string) => any;
21
- fileFromPath:
22
- | ((path: string, filename?: string, options?: {}) => Promise<Shims['File']>)
23
- | ((path: string, options?: {}) => Promise<Shims['File']>);
24
- isFsReadStream: (value: any) => boolean;
25
- }
26
-
27
- export let auto = false;
28
- export let kind: Shims['kind'] | undefined = undefined;
29
- export let fetch: Shims['fetch'] | undefined = undefined;
30
- export let Request: Shims['Request'] | undefined = undefined;
31
- export let Response: Shims['Response'] | undefined = undefined;
32
- export let Headers: Shims['Headers'] | undefined = undefined;
33
- export let FormData: Shims['FormData'] | undefined = undefined;
34
- export let Blob: Shims['Blob'] | undefined = undefined;
35
- export let File: Shims['File'] | undefined = undefined;
36
- export let ReadableStream: Shims['ReadableStream'] | undefined = undefined;
37
- export let getMultipartRequestOptions: Shims['getMultipartRequestOptions'] | undefined = undefined;
38
- export let getDefaultAgent: Shims['getDefaultAgent'] | undefined = undefined;
39
- export let fileFromPath: Shims['fileFromPath'] | undefined = undefined;
40
- export let isFsReadStream: Shims['isFsReadStream'] | undefined = undefined;
41
-
42
- export function setShims(shims: Shims, options: { auto: boolean } = { auto: false }) {
43
- if (auto) {
44
- throw new Error(
45
- `you must \`import '@mastra/client-js/shims/${shims.kind}'\` before importing anything else from @mastra/client-js`,
46
- );
47
- }
48
- if (kind) {
49
- throw new Error(
50
- `can't \`import '@mastra/client-js/shims/${shims.kind}'\` after \`import '@mastra/client-js/shims/${kind}'\``,
51
- );
52
- }
53
- auto = options.auto;
54
- kind = shims.kind;
55
- fetch = shims.fetch;
56
- Request = shims.Request;
57
- Response = shims.Response;
58
- Headers = shims.Headers;
59
- FormData = shims.FormData;
60
- Blob = shims.Blob;
61
- File = shims.File;
62
- ReadableStream = shims.ReadableStream;
63
- getMultipartRequestOptions = shims.getMultipartRequestOptions;
64
- getDefaultAgent = shims.getDefaultAgent;
65
- fileFromPath = shims.fileFromPath;
66
- isFsReadStream = shims.isFsReadStream;
67
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
- */
4
- import { MultipartBody } from './MultipartBody';
5
- import { type RequestOptions } from '../core';
6
- import { type Shims } from './registry';
7
-
8
- export function getRuntime({ manuallyImported }: { manuallyImported?: boolean } = {}): Shims {
9
- const recommendation =
10
- manuallyImported ?
11
- `You may need to use polyfills`
12
- : `Add one of these imports before your first \`import … from '@mastra/client-js'\`:
13
- - \`import '@mastra/client-js/shims/node'\` (if you're running on Node)
14
- - \`import '@mastra/client-js/shims/web'\` (otherwise)
15
- `;
16
-
17
- let _fetch, _Request, _Response, _Headers;
18
- try {
19
- // @ts-ignore
20
- _fetch = fetch;
21
- // @ts-ignore
22
- _Request = Request;
23
- // @ts-ignore
24
- _Response = Response;
25
- // @ts-ignore
26
- _Headers = Headers;
27
- } catch (error) {
28
- throw new Error(
29
- `this environment is missing the following Web Fetch API type: ${
30
- (error as any).message
31
- }. ${recommendation}`,
32
- );
33
- }
34
-
35
- return {
36
- kind: 'web',
37
- fetch: _fetch,
38
- Request: _Request,
39
- Response: _Response,
40
- Headers: _Headers,
41
- FormData:
42
- // @ts-ignore
43
- typeof FormData !== 'undefined' ? FormData : (
44
- class FormData {
45
- // @ts-ignore
46
- constructor() {
47
- throw new Error(
48
- `file uploads aren't supported in this environment yet as 'FormData' is undefined. ${recommendation}`,
49
- );
50
- }
51
- }
52
- ),
53
- Blob:
54
- typeof Blob !== 'undefined' ? Blob : (
55
- class Blob {
56
- constructor() {
57
- throw new Error(
58
- `file uploads aren't supported in this environment yet as 'Blob' is undefined. ${recommendation}`,
59
- );
60
- }
61
- }
62
- ),
63
- File:
64
- // @ts-ignore
65
- typeof File !== 'undefined' ? File : (
66
- class File {
67
- // @ts-ignore
68
- constructor() {
69
- throw new Error(
70
- `file uploads aren't supported in this environment yet as 'File' is undefined. ${recommendation}`,
71
- );
72
- }
73
- }
74
- ),
75
- ReadableStream:
76
- // @ts-ignore
77
- typeof ReadableStream !== 'undefined' ? ReadableStream : (
78
- class ReadableStream {
79
- // @ts-ignore
80
- constructor() {
81
- throw new Error(
82
- `streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${recommendation}`,
83
- );
84
- }
85
- }
86
- ),
87
- getMultipartRequestOptions: async <T = Record<string, unknown>>(
88
- // @ts-ignore
89
- form: FormData,
90
- opts: RequestOptions<T>,
91
- ): Promise<RequestOptions<T>> => ({
92
- ...opts,
93
- body: new MultipartBody(form) as any,
94
- }),
95
- getDefaultAgent: (url: string) => undefined,
96
- fileFromPath: () => {
97
- throw new Error(
98
- 'The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/mastra-ai/client-js#file-uploads',
99
- );
100
- },
101
- isFsReadStream: (value: any) => false,
102
- };
103
- }