@mixedbread/sdk 0.1.0-alpha.8

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 (277) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/LICENSE +201 -0
  3. package/README.md +360 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +241 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +914 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +882 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +47 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +113 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +97 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +148 -0
  87. package/index.d.ts +148 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +151 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +108 -0
  92. package/index.mjs.map +1 -0
  93. package/lib/polling.d.ts +48 -0
  94. package/lib/polling.d.ts.map +1 -0
  95. package/lib/polling.js +75 -0
  96. package/lib/polling.js.map +1 -0
  97. package/lib/polling.mjs +71 -0
  98. package/lib/polling.mjs.map +1 -0
  99. package/package.json +124 -0
  100. package/pagination.d.ts +30 -0
  101. package/pagination.d.ts.map +1 -0
  102. package/pagination.js +45 -0
  103. package/pagination.js.map +1 -0
  104. package/pagination.mjs +41 -0
  105. package/pagination.mjs.map +1 -0
  106. package/resource.d.ts +6 -0
  107. package/resource.d.ts.map +1 -0
  108. package/resource.js +11 -0
  109. package/resource.js.map +1 -0
  110. package/resource.mjs +7 -0
  111. package/resource.mjs.map +1 -0
  112. package/resources/extractions/content.d.ts +35 -0
  113. package/resources/extractions/content.d.ts.map +1 -0
  114. package/resources/extractions/content.js +19 -0
  115. package/resources/extractions/content.js.map +1 -0
  116. package/resources/extractions/content.mjs +15 -0
  117. package/resources/extractions/content.mjs.map +1 -0
  118. package/resources/extractions/extractions.d.ts +18 -0
  119. package/resources/extractions/extractions.d.ts.map +1 -0
  120. package/resources/extractions/extractions.js +47 -0
  121. package/resources/extractions/extractions.js.map +1 -0
  122. package/resources/extractions/extractions.mjs +20 -0
  123. package/resources/extractions/extractions.mjs.map +1 -0
  124. package/resources/extractions/index.d.ts +5 -0
  125. package/resources/extractions/index.d.ts.map +1 -0
  126. package/resources/extractions/index.js +13 -0
  127. package/resources/extractions/index.js.map +1 -0
  128. package/resources/extractions/index.mjs +6 -0
  129. package/resources/extractions/index.mjs.map +1 -0
  130. package/resources/extractions/jobs.d.ts +44 -0
  131. package/resources/extractions/jobs.d.ts.map +1 -0
  132. package/resources/extractions/jobs.js +29 -0
  133. package/resources/extractions/jobs.js.map +1 -0
  134. package/resources/extractions/jobs.mjs +25 -0
  135. package/resources/extractions/jobs.mjs.map +1 -0
  136. package/resources/extractions/schema.d.ts +85 -0
  137. package/resources/extractions/schema.d.ts.map +1 -0
  138. package/resources/extractions/schema.js +39 -0
  139. package/resources/extractions/schema.js.map +1 -0
  140. package/resources/extractions/schema.mjs +35 -0
  141. package/resources/extractions/schema.mjs.map +1 -0
  142. package/resources/files.d.ts +125 -0
  143. package/resources/files.d.ts.map +1 -0
  144. package/resources/files.js +99 -0
  145. package/resources/files.js.map +1 -0
  146. package/resources/files.mjs +71 -0
  147. package/resources/files.mjs.map +1 -0
  148. package/resources/index.d.ts +7 -0
  149. package/resources/index.d.ts.map +1 -0
  150. package/resources/index.js +30 -0
  151. package/resources/index.js.map +1 -0
  152. package/resources/index.mjs +7 -0
  153. package/resources/index.mjs.map +1 -0
  154. package/resources/parsing/index.d.ts +3 -0
  155. package/resources/parsing/index.d.ts.map +1 -0
  156. package/resources/parsing/index.js +10 -0
  157. package/resources/parsing/index.js.map +1 -0
  158. package/resources/parsing/index.mjs +4 -0
  159. package/resources/parsing/index.mjs.map +1 -0
  160. package/resources/parsing/jobs.d.ts +278 -0
  161. package/resources/parsing/jobs.d.ts.map +1 -0
  162. package/resources/parsing/jobs.js +147 -0
  163. package/resources/parsing/jobs.js.map +1 -0
  164. package/resources/parsing/jobs.mjs +119 -0
  165. package/resources/parsing/jobs.mjs.map +1 -0
  166. package/resources/parsing/parsing.d.ts +10 -0
  167. package/resources/parsing/parsing.d.ts.map +1 -0
  168. package/resources/parsing/parsing.js +40 -0
  169. package/resources/parsing/parsing.js.map +1 -0
  170. package/resources/parsing/parsing.mjs +13 -0
  171. package/resources/parsing/parsing.mjs.map +1 -0
  172. package/resources/shared.d.ts +35 -0
  173. package/resources/shared.d.ts.map +1 -0
  174. package/resources/shared.js +4 -0
  175. package/resources/shared.js.map +1 -0
  176. package/resources/shared.mjs +3 -0
  177. package/resources/shared.mjs.map +1 -0
  178. package/resources/top-level.d.ts +11 -0
  179. package/resources/top-level.d.ts.map +1 -0
  180. package/resources/top-level.js +4 -0
  181. package/resources/top-level.js.map +1 -0
  182. package/resources/top-level.mjs +3 -0
  183. package/resources/top-level.mjs.map +1 -0
  184. package/resources/vector-stores/files.d.ts +280 -0
  185. package/resources/vector-stores/files.d.ts.map +1 -0
  186. package/resources/vector-stores/files.js +167 -0
  187. package/resources/vector-stores/files.js.map +1 -0
  188. package/resources/vector-stores/files.mjs +139 -0
  189. package/resources/vector-stores/files.mjs.map +1 -0
  190. package/resources/vector-stores/index.d.ts +3 -0
  191. package/resources/vector-stores/index.d.ts.map +1 -0
  192. package/resources/vector-stores/index.js +11 -0
  193. package/resources/vector-stores/index.js.map +1 -0
  194. package/resources/vector-stores/index.mjs +4 -0
  195. package/resources/vector-stores/index.mjs.map +1 -0
  196. package/resources/vector-stores/vector-stores.d.ts +400 -0
  197. package/resources/vector-stores/vector-stores.d.ts.map +1 -0
  198. package/resources/vector-stores/vector-stores.js +121 -0
  199. package/resources/vector-stores/vector-stores.js.map +1 -0
  200. package/resources/vector-stores/vector-stores.mjs +93 -0
  201. package/resources/vector-stores/vector-stores.mjs.map +1 -0
  202. package/shims/node.d.ts +30 -0
  203. package/shims/node.d.ts.map +1 -0
  204. package/shims/node.js +31 -0
  205. package/shims/node.js.map +1 -0
  206. package/shims/node.mjs +5 -0
  207. package/shims/node.mjs.map +1 -0
  208. package/shims/web.d.ts +26 -0
  209. package/shims/web.d.ts.map +1 -0
  210. package/shims/web.js +31 -0
  211. package/shims/web.js.map +1 -0
  212. package/shims/web.mjs +5 -0
  213. package/shims/web.mjs.map +1 -0
  214. package/src/_shims/MultipartBody.ts +9 -0
  215. package/src/_shims/README.md +46 -0
  216. package/src/_shims/auto/runtime-bun.ts +4 -0
  217. package/src/_shims/auto/runtime-node.ts +4 -0
  218. package/src/_shims/auto/runtime.ts +4 -0
  219. package/src/_shims/auto/types-node.ts +4 -0
  220. package/src/_shims/auto/types.d.ts +101 -0
  221. package/src/_shims/auto/types.js +3 -0
  222. package/src/_shims/auto/types.mjs +3 -0
  223. package/src/_shims/bun-runtime.ts +14 -0
  224. package/src/_shims/index.d.ts +81 -0
  225. package/src/_shims/index.js +13 -0
  226. package/src/_shims/index.mjs +7 -0
  227. package/src/_shims/manual-types.d.ts +12 -0
  228. package/src/_shims/manual-types.js +3 -0
  229. package/src/_shims/manual-types.mjs +3 -0
  230. package/src/_shims/node-runtime.ts +81 -0
  231. package/src/_shims/node-types.d.ts +42 -0
  232. package/src/_shims/node-types.js +3 -0
  233. package/src/_shims/node-types.mjs +3 -0
  234. package/src/_shims/registry.ts +67 -0
  235. package/src/_shims/web-runtime.ts +103 -0
  236. package/src/_shims/web-types.d.ts +83 -0
  237. package/src/_shims/web-types.js +3 -0
  238. package/src/_shims/web-types.mjs +3 -0
  239. package/src/core.ts +1208 -0
  240. package/src/error.ts +130 -0
  241. package/src/index.ts +294 -0
  242. package/src/lib/.keep +4 -0
  243. package/src/lib/polling.ts +115 -0
  244. package/src/pagination.ts +82 -0
  245. package/src/resource.ts +11 -0
  246. package/src/resources/extractions/content.ts +43 -0
  247. package/src/resources/extractions/extractions.ts +47 -0
  248. package/src/resources/extractions/index.ts +14 -0
  249. package/src/resources/extractions/jobs.ts +55 -0
  250. package/src/resources/extractions/schema.ts +111 -0
  251. package/src/resources/files.ts +181 -0
  252. package/src/resources/index.ts +32 -0
  253. package/src/resources/parsing/index.ts +12 -0
  254. package/src/resources/parsing/jobs.ts +438 -0
  255. package/src/resources/parsing/parsing.ts +32 -0
  256. package/src/resources/shared.ts +41 -0
  257. package/src/resources/top-level.ts +14 -0
  258. package/src/resources/vector-stores/files.ts +434 -0
  259. package/src/resources/vector-stores/index.ts +30 -0
  260. package/src/resources/vector-stores/vector-stores.ts +561 -0
  261. package/src/shims/node.ts +50 -0
  262. package/src/shims/web.ts +50 -0
  263. package/src/tsconfig.json +11 -0
  264. package/src/uploads.ts +255 -0
  265. package/src/version.ts +1 -0
  266. package/uploads.d.ts +75 -0
  267. package/uploads.d.ts.map +1 -0
  268. package/uploads.js +171 -0
  269. package/uploads.js.map +1 -0
  270. package/uploads.mjs +158 -0
  271. package/uploads.mjs.map +1 -0
  272. package/version.d.ts +2 -0
  273. package/version.d.ts.map +1 -0
  274. package/version.js +5 -0
  275. package/version.js.map +1 -0
  276. package/version.mjs +2 -0
  277. package/version.mjs.map +1 -0
package/README.md ADDED
@@ -0,0 +1,360 @@
1
+ # Mixedbread Node API Library
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@mixedbread/sdk.svg)](https://npmjs.org/package/@mixedbread/sdk) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@mixedbread/sdk)
4
+
5
+ This library provides convenient access to the Mixedbread REST API from server-side TypeScript or JavaScript.
6
+
7
+ The REST API documentation can be found on [mixedbread.ai](https://mixedbread.ai/docs). The full API of this library can be found in [api.md](api.md).
8
+
9
+ It is generated with [Stainless](https://www.stainless.com/).
10
+
11
+ ## Installation
12
+
13
+ ```sh
14
+ npm install @mixedbread/sdk
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ The full API of this library can be found in [api.md](api.md).
20
+
21
+ <!-- prettier-ignore -->
22
+ ```js
23
+ import Mixedbread from '@mixedbread/sdk';
24
+
25
+ const client = new Mixedbread({
26
+ apiKey: process.env['MXBAI_API_KEY'], // This is the default and can be omitted
27
+ environment: 'local', // defaults to 'production'
28
+ });
29
+
30
+ async function main() {
31
+ const vectorStore = await client.vectorStores.create();
32
+
33
+ console.log(vectorStore.id);
34
+ }
35
+
36
+ main();
37
+ ```
38
+
39
+ ### Request & Response types
40
+
41
+ This library includes TypeScript definitions for all request params and response fields. You may import and use them like so:
42
+
43
+ <!-- prettier-ignore -->
44
+ ```ts
45
+ import Mixedbread from '@mixedbread/sdk';
46
+
47
+ const client = new Mixedbread({
48
+ apiKey: process.env['MXBAI_API_KEY'], // This is the default and can be omitted
49
+ environment: 'local', // defaults to 'production'
50
+ });
51
+
52
+ async function main() {
53
+ const vectorStore: Mixedbread.VectorStore = await client.vectorStores.create();
54
+ }
55
+
56
+ main();
57
+ ```
58
+
59
+ Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
60
+
61
+ ## File uploads
62
+
63
+ Request parameters that correspond to file uploads can be passed in many different forms:
64
+
65
+ - `File` (or an object with the same structure)
66
+ - a `fetch` `Response` (or an object with the same structure)
67
+ - an `fs.ReadStream`
68
+ - the return value of our `toFile` helper
69
+
70
+ ```ts
71
+ import fs from 'fs';
72
+ import fetch from 'node-fetch';
73
+ import Mixedbread, { toFile } from '@mixedbread/sdk';
74
+
75
+ const client = new Mixedbread();
76
+
77
+ // If you have access to Node `fs` we recommend using `fs.createReadStream()`:
78
+ await client.files.create({ file: fs.createReadStream('/path/to/file') });
79
+
80
+ // Or if you have the web `File` API you can pass a `File` instance:
81
+ await client.files.create({ file: new File(['my bytes'], 'file') });
82
+
83
+ // You can also pass a `fetch` `Response`:
84
+ await client.files.create({ file: await fetch('https://somesite/file') });
85
+
86
+ // Finally, if none of the above are convenient, you can use our `toFile` helper:
87
+ await client.files.create({ file: await toFile(Buffer.from('my bytes'), 'file') });
88
+ await client.files.create({ file: await toFile(new Uint8Array([0, 1, 2]), 'file') });
89
+ ```
90
+
91
+ ## Handling errors
92
+
93
+ When the library is unable to connect to the API,
94
+ or if the API returns a non-success status code (i.e., 4xx or 5xx response),
95
+ a subclass of `APIError` will be thrown:
96
+
97
+ <!-- prettier-ignore -->
98
+ ```ts
99
+ async function main() {
100
+ const vectorStore = await client.vectorStores.create().catch(async (err) => {
101
+ if (err instanceof Mixedbread.APIError) {
102
+ console.log(err.status); // 400
103
+ console.log(err.name); // BadRequestError
104
+ console.log(err.headers); // {server: 'nginx', ...}
105
+ } else {
106
+ throw err;
107
+ }
108
+ });
109
+ }
110
+
111
+ main();
112
+ ```
113
+
114
+ Error codes are as followed:
115
+
116
+ | Status Code | Error Type |
117
+ | ----------- | -------------------------- |
118
+ | 400 | `BadRequestError` |
119
+ | 401 | `AuthenticationError` |
120
+ | 403 | `PermissionDeniedError` |
121
+ | 404 | `NotFoundError` |
122
+ | 422 | `UnprocessableEntityError` |
123
+ | 429 | `RateLimitError` |
124
+ | >=500 | `InternalServerError` |
125
+ | N/A | `APIConnectionError` |
126
+
127
+ ### Retries
128
+
129
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
130
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
131
+ 429 Rate Limit, and >=500 Internal errors will all be retried by default.
132
+
133
+ You can use the `maxRetries` option to configure or disable this:
134
+
135
+ <!-- prettier-ignore -->
136
+ ```js
137
+ // Configure the default for all requests:
138
+ const client = new Mixedbread({
139
+ maxRetries: 0, // default is 2
140
+ });
141
+
142
+ // Or, configure per-request:
143
+ await client.vectorStores.create({
144
+ maxRetries: 5,
145
+ });
146
+ ```
147
+
148
+ ### Timeouts
149
+
150
+ Requests time out after 1 minute by default. You can configure this with a `timeout` option:
151
+
152
+ <!-- prettier-ignore -->
153
+ ```ts
154
+ // Configure the default for all requests:
155
+ const client = new Mixedbread({
156
+ timeout: 20 * 1000, // 20 seconds (default is 1 minute)
157
+ });
158
+
159
+ // Override per-request:
160
+ await client.vectorStores.create({
161
+ timeout: 5 * 1000,
162
+ });
163
+ ```
164
+
165
+ On timeout, an `APIConnectionTimeoutError` is thrown.
166
+
167
+ Note that requests which time out will be [retried twice by default](#retries).
168
+
169
+ ## Auto-pagination
170
+
171
+ List methods in the Mixedbread API are paginated.
172
+ You can use the `for await … of` syntax to iterate through items across all pages:
173
+
174
+ ```ts
175
+ async function fetchAllVectorStores(params) {
176
+ const allVectorStores = [];
177
+ // Automatically fetches more pages as needed.
178
+ for await (const vectorStore of client.vectorStores.list()) {
179
+ allVectorStores.push(vectorStore);
180
+ }
181
+ return allVectorStores;
182
+ }
183
+ ```
184
+
185
+ Alternatively, you can request a single page at a time:
186
+
187
+ ```ts
188
+ let page = await client.vectorStores.list();
189
+ for (const vectorStore of page.data) {
190
+ console.log(vectorStore);
191
+ }
192
+
193
+ // Convenience methods are provided for manually paginating:
194
+ while (page.hasNextPage()) {
195
+ page = await page.getNextPage();
196
+ // ...
197
+ }
198
+ ```
199
+
200
+ ## Advanced Usage
201
+
202
+ ### Accessing raw Response data (e.g., headers)
203
+
204
+ The "raw" `Response` returned by `fetch()` can be accessed through the `.asResponse()` method on the `APIPromise` type that all methods return.
205
+
206
+ You can also use the `.withResponse()` method to get the raw `Response` along with the parsed data.
207
+
208
+ <!-- prettier-ignore -->
209
+ ```ts
210
+ const client = new Mixedbread();
211
+
212
+ const response = await client.vectorStores.create().asResponse();
213
+ console.log(response.headers.get('X-My-Header'));
214
+ console.log(response.statusText); // access the underlying Response object
215
+
216
+ const { data: vectorStore, response: raw } = await client.vectorStores.create().withResponse();
217
+ console.log(raw.headers.get('X-My-Header'));
218
+ console.log(vectorStore.id);
219
+ ```
220
+
221
+ ### Making custom/undocumented requests
222
+
223
+ This library is typed for convenient access to the documented API. If you need to access undocumented
224
+ endpoints, params, or response properties, the library can still be used.
225
+
226
+ #### Undocumented endpoints
227
+
228
+ To make requests to undocumented endpoints, you can use `client.get`, `client.post`, and other HTTP verbs.
229
+ Options on the client, such as retries, will be respected when making these requests.
230
+
231
+ ```ts
232
+ await client.post('/some/path', {
233
+ body: { some_prop: 'foo' },
234
+ query: { some_query_arg: 'bar' },
235
+ });
236
+ ```
237
+
238
+ #### Undocumented request params
239
+
240
+ To make requests using undocumented parameters, you may use `// @ts-expect-error` on the undocumented
241
+ parameter. This library doesn't validate at runtime that the request matches the type, so any extra values you
242
+ send will be sent as-is.
243
+
244
+ ```ts
245
+ client.foo.create({
246
+ foo: 'my_param',
247
+ bar: 12,
248
+ // @ts-expect-error baz is not yet public
249
+ baz: 'undocumented option',
250
+ });
251
+ ```
252
+
253
+ For requests with the `GET` verb, any extra params will be in the query, all other requests will send the
254
+ extra param in the body.
255
+
256
+ If you want to explicitly send an extra argument, you can do so with the `query`, `body`, and `headers` request
257
+ options.
258
+
259
+ #### Undocumented response properties
260
+
261
+ To access undocumented response properties, you may access the response object with `// @ts-expect-error` on
262
+ the response object, or cast the response object to the requisite type. Like the request params, we do not
263
+ validate or strip extra properties from the response from the API.
264
+
265
+ ### Customizing the fetch client
266
+
267
+ By default, this library uses `node-fetch` in Node, and expects a global `fetch` function in other environments.
268
+
269
+ If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
270
+ (for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
271
+ add the following import before your first import `from "Mixedbread"`:
272
+
273
+ ```ts
274
+ // Tell TypeScript and the package to use the global web fetch instead of node-fetch.
275
+ // Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
276
+ import '@mixedbread/sdk/shims/web';
277
+ import Mixedbread from '@mixedbread/sdk';
278
+ ```
279
+
280
+ To do the inverse, add `import "@mixedbread/sdk/shims/node"` (which does import polyfills).
281
+ This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/mixedbread-ai/mixedbread-ts/tree/main/src/_shims#readme)).
282
+
283
+ ### Logging and middleware
284
+
285
+ You may also provide a custom `fetch` function when instantiating the client,
286
+ which can be used to inspect or alter the `Request` or `Response` before/after each request:
287
+
288
+ ```ts
289
+ import { fetch } from 'undici'; // as one example
290
+ import Mixedbread from '@mixedbread/sdk';
291
+
292
+ const client = new Mixedbread({
293
+ fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
294
+ console.log('About to make a request', url, init);
295
+ const response = await fetch(url, init);
296
+ console.log('Got response', response);
297
+ return response;
298
+ },
299
+ });
300
+ ```
301
+
302
+ Note that if given a `DEBUG=true` environment variable, this library will log all requests and responses automatically.
303
+ This is intended for debugging purposes only and may change in the future without notice.
304
+
305
+ ### Configuring an HTTP(S) Agent (e.g., for proxies)
306
+
307
+ By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
308
+
309
+ If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
310
+
311
+ <!-- prettier-ignore -->
312
+ ```ts
313
+ import http from 'http';
314
+ import { HttpsProxyAgent } from 'https-proxy-agent';
315
+
316
+ // Configure the default for all requests:
317
+ const client = new Mixedbread({
318
+ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
319
+ });
320
+
321
+ // Override per-request:
322
+ await client.vectorStores.create({
323
+ httpAgent: new http.Agent({ keepAlive: false }),
324
+ });
325
+ ```
326
+
327
+ ## Semantic versioning
328
+
329
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
330
+
331
+ 1. Changes that only affect static types, without breaking runtime behavior.
332
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
333
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
334
+
335
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
336
+
337
+ We are keen for your feedback; please open an [issue](https://www.github.com/mixedbread-ai/mixedbread-ts/issues) with questions, bugs, or suggestions.
338
+
339
+ ## Requirements
340
+
341
+ TypeScript >= 4.5 is supported.
342
+
343
+ The following runtimes are supported:
344
+
345
+ - Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
346
+ - Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
347
+ - Deno v1.28.0 or higher.
348
+ - Bun 1.0 or later.
349
+ - Cloudflare Workers.
350
+ - Vercel Edge Runtime.
351
+ - Jest 28 or greater with the `"node"` environment (`"jsdom"` is not supported at this time).
352
+ - Nitro v2.6 or greater.
353
+
354
+ Note that React Native is not supported at this time.
355
+
356
+ If you are interested in other runtime environments, please open or upvote an issue on GitHub.
357
+
358
+ ## Contributing
359
+
360
+ See [the contributing documentation](./CONTRIBUTING.md).
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export declare class MultipartBody {
5
+ body: any;
6
+ constructor(body: any);
7
+ get [Symbol.toStringTag](): string;
8
+ }
9
+ //# sourceMappingURL=MultipartBody.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.d.ts","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,aAAa;IACL,IAAI,EAAE,GAAG;gBAAT,IAAI,EAAE,GAAG;IAC5B,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;CACF"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MultipartBody = void 0;
4
+ /**
5
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
6
+ */
7
+ class MultipartBody {
8
+ constructor(body) {
9
+ this.body = body;
10
+ }
11
+ get [Symbol.toStringTag]() {
12
+ return 'MultipartBody';
13
+ }
14
+ }
15
+ exports.MultipartBody = MultipartBody;
16
+ //# sourceMappingURL=MultipartBody.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.js","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,aAAa;IACxB,YAAmB,IAAS;QAAT,SAAI,GAAJ,IAAI,CAAK;IAAG,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,eAAe,CAAC;IACzB,CAAC;CACF;AALD,sCAKC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export class MultipartBody {
5
+ constructor(body) {
6
+ this.body = body;
7
+ }
8
+ get [Symbol.toStringTag]() {
9
+ return 'MultipartBody';
10
+ }
11
+ }
12
+ //# sourceMappingURL=MultipartBody.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultipartBody.mjs","sourceRoot":"","sources":["../src/_shims/MultipartBody.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,YAAmB,IAAS;QAAT,SAAI,GAAJ,IAAI,CAAK;IAAG,CAAC;IAChC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,46 @@
1
+ # 👋 Wondering what everything in here does?
2
+
3
+ `@mixedbread/sdk` 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, `@mixedbread/sdk` 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 '@mixedbread/sdk/shims/node'`
19
+ - `import '@mixedbread/sdk/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 `@mixedbread/sdk/_shims/registry`.
26
+
27
+ Manually importing `@mixedbread/sdk/shims/node` or `@mixedbread/sdk/shims/web`, calls `setShims` with the respective runtime shims.
28
+
29
+ All client code imports shims from `@mixedbread/sdk/_shims/index`, which:
30
+
31
+ - checks if shims have been set manually
32
+ - if not, calls `setShims` with the shims from `@mixedbread/sdk/_shims/auto/runtime`
33
+ - re-exports the installed shims from `@mixedbread/sdk/_shims/registry`.
34
+
35
+ `@mixedbread/sdk/_shims/auto/runtime` exports web runtime shims.
36
+ If the `node` export condition is set, the export map replaces it with `@mixedbread/sdk/_shims/auto/runtime-node`.
37
+
38
+ ### How it works - Type time
39
+
40
+ All client code imports shim types from `@mixedbread/sdk/_shims/index`, which selects the manual types from `@mixedbread/sdk/_shims/manual-types` if they have been declared, otherwise it exports the auto types from `@mixedbread/sdk/_shims/auto/types`.
41
+
42
+ `@mixedbread/sdk/_shims/manual-types` exports an empty namespace.
43
+ Manually importing `@mixedbread/sdk/shims/node` or `@mixedbread/sdk/shims/web` merges declarations into this empty namespace, so they get picked up by `@mixedbread/sdk/_shims/index`.
44
+
45
+ `@mixedbread/sdk/_shims/auto/types` exports web type definitions.
46
+ If the `node` export condition is set, the export map replaces it with `@mixedbread/sdk/_shims/auto/types-node`, though TS only picks this up if `"moduleResolution": "nodenext"` or `"moduleResolution": "bundler"`.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../bun-runtime.js";
5
+ //# sourceMappingURL=runtime-bun.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../bun-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime-bun.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,oDAA+B"}
@@ -0,0 +1,2 @@
1
+ export * from "../bun-runtime.mjs";
2
+ //# sourceMappingURL=runtime-bun.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-bun.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime-bun.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../node-runtime.js";
5
+ //# sourceMappingURL=runtime-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../node-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,qDAAgC"}
@@ -0,0 +1,2 @@
1
+ export * from "../node-runtime.mjs";
2
+ //# sourceMappingURL=runtime-node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-node.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime-node.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../web-runtime.js";
5
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../web-runtime.js"), exports);
21
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,oDAA+B"}
@@ -0,0 +1,2 @@
1
+ export * from "../web-runtime.mjs";
2
+ //# sourceMappingURL=runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.mjs","sourceRoot":"","sources":["../../src/_shims/auto/runtime.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
3
+ */
4
+ export * from "../node-types.js";
5
+ //# sourceMappingURL=types-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-node.d.ts","sourceRoot":"","sources":["../../src/_shims/auto/types-node.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,eAAe,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Disclaimer: modules in _shims aren't intended to be imported by SDK users.
19
+ */
20
+ __exportStar(require("../node-types.js"), exports);
21
+ //# sourceMappingURL=types-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-node.js","sourceRoot":"","sources":["../../src/_shims/auto/types-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,mDAA8B"}
@@ -0,0 +1,2 @@
1
+ export * from "../node-types.mjs";
2
+ //# sourceMappingURL=types-node.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-node.mjs","sourceRoot":"","sources":["../../src/_shims/auto/types-node.ts"],"names":[],"mappings":""}