@mixedbread/sdk 0.3.0 → 0.5.0

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 (568) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +110 -37
  3. package/api-promise.d.mts +2 -0
  4. package/api-promise.d.mts.map +1 -0
  5. package/api-promise.d.ts +2 -0
  6. package/api-promise.d.ts.map +1 -0
  7. package/api-promise.js +6 -0
  8. package/api-promise.js.map +1 -0
  9. package/api-promise.mjs +2 -0
  10. package/api-promise.mjs.map +1 -0
  11. package/bin/cli +52 -0
  12. package/bin/migration-config.json +73 -0
  13. package/client.d.mts +261 -0
  14. package/client.d.mts.map +1 -0
  15. package/client.d.ts +261 -0
  16. package/client.d.ts.map +1 -0
  17. package/client.js +535 -0
  18. package/client.js.map +1 -0
  19. package/client.mjs +531 -0
  20. package/client.mjs.map +1 -0
  21. package/core/api-promise.d.mts +46 -0
  22. package/core/api-promise.d.mts.map +1 -0
  23. package/core/api-promise.d.ts +46 -0
  24. package/core/api-promise.d.ts.map +1 -0
  25. package/core/api-promise.js +74 -0
  26. package/core/api-promise.js.map +1 -0
  27. package/core/api-promise.mjs +70 -0
  28. package/core/api-promise.mjs.map +1 -0
  29. package/core/error.d.mts +46 -0
  30. package/core/error.d.mts.map +1 -0
  31. package/core/error.d.ts +46 -0
  32. package/core/error.d.ts.map +1 -0
  33. package/core/error.js +113 -0
  34. package/core/error.js.map +1 -0
  35. package/core/error.mjs +97 -0
  36. package/core/error.mjs.map +1 -0
  37. package/core/pagination.d.mts +66 -0
  38. package/core/pagination.d.mts.map +1 -0
  39. package/core/pagination.d.ts +66 -0
  40. package/core/pagination.d.ts.map +1 -0
  41. package/core/pagination.js +110 -0
  42. package/core/pagination.js.map +1 -0
  43. package/core/pagination.mjs +104 -0
  44. package/core/pagination.mjs.map +1 -0
  45. package/core/resource.d.mts +6 -0
  46. package/core/resource.d.mts.map +1 -0
  47. package/core/resource.d.ts +6 -0
  48. package/core/resource.d.ts.map +1 -0
  49. package/core/resource.js +11 -0
  50. package/core/resource.js.map +1 -0
  51. package/core/resource.mjs +7 -0
  52. package/core/resource.mjs.map +1 -0
  53. package/core/uploads.d.mts +3 -0
  54. package/core/uploads.d.mts.map +1 -0
  55. package/core/uploads.d.ts +3 -0
  56. package/core/uploads.d.ts.map +1 -0
  57. package/core/uploads.js +6 -0
  58. package/core/uploads.js.map +1 -0
  59. package/core/uploads.mjs +2 -0
  60. package/core/uploads.mjs.map +1 -0
  61. package/error.d.mts +2 -0
  62. package/error.d.mts.map +1 -0
  63. package/error.d.ts +1 -46
  64. package/error.d.ts.map +1 -1
  65. package/error.js +3 -110
  66. package/error.js.map +1 -1
  67. package/error.mjs +1 -96
  68. package/error.mjs.map +1 -1
  69. package/index.d.mts +7 -169
  70. package/index.d.mts.map +1 -0
  71. package/index.d.ts +6 -168
  72. package/index.d.ts.map +1 -1
  73. package/index.js +14 -157
  74. package/index.js.map +1 -1
  75. package/index.mjs +6 -130
  76. package/index.mjs.map +1 -1
  77. package/internal/builtin-types.d.mts +73 -0
  78. package/internal/builtin-types.d.mts.map +1 -0
  79. package/internal/builtin-types.d.ts +73 -0
  80. package/internal/builtin-types.d.ts.map +1 -0
  81. package/internal/builtin-types.js +4 -0
  82. package/internal/builtin-types.js.map +1 -0
  83. package/internal/builtin-types.mjs +3 -0
  84. package/internal/builtin-types.mjs.map +1 -0
  85. package/internal/detect-platform.d.mts +15 -0
  86. package/internal/detect-platform.d.mts.map +1 -0
  87. package/internal/detect-platform.d.ts +15 -0
  88. package/internal/detect-platform.d.ts.map +1 -0
  89. package/internal/detect-platform.js +162 -0
  90. package/internal/detect-platform.js.map +1 -0
  91. package/internal/detect-platform.mjs +157 -0
  92. package/internal/detect-platform.mjs.map +1 -0
  93. package/internal/errors.d.mts +3 -0
  94. package/internal/errors.d.mts.map +1 -0
  95. package/internal/errors.d.ts +3 -0
  96. package/internal/errors.d.ts.map +1 -0
  97. package/internal/errors.js +41 -0
  98. package/internal/errors.js.map +1 -0
  99. package/internal/errors.mjs +36 -0
  100. package/internal/errors.mjs.map +1 -0
  101. package/internal/headers.d.mts +20 -0
  102. package/internal/headers.d.mts.map +1 -0
  103. package/internal/headers.d.ts +20 -0
  104. package/internal/headers.d.ts.map +1 -0
  105. package/internal/headers.js +79 -0
  106. package/internal/headers.js.map +1 -0
  107. package/internal/headers.mjs +74 -0
  108. package/internal/headers.mjs.map +1 -0
  109. package/internal/parse.d.mts +12 -0
  110. package/internal/parse.d.mts.map +1 -0
  111. package/internal/parse.d.ts +12 -0
  112. package/internal/parse.d.ts.map +1 -0
  113. package/internal/parse.js +35 -0
  114. package/internal/parse.js.map +1 -0
  115. package/internal/parse.mjs +32 -0
  116. package/internal/parse.mjs.map +1 -0
  117. package/internal/request-options.d.mts +32 -0
  118. package/internal/request-options.d.mts.map +1 -0
  119. package/internal/request-options.d.ts +32 -0
  120. package/internal/request-options.d.ts.map +1 -0
  121. package/internal/request-options.js +14 -0
  122. package/internal/request-options.js.map +1 -0
  123. package/internal/request-options.mjs +10 -0
  124. package/internal/request-options.mjs.map +1 -0
  125. package/internal/shim-types.d.mts +28 -0
  126. package/internal/shim-types.d.ts +28 -0
  127. package/internal/shims.d.mts +20 -0
  128. package/internal/shims.d.mts.map +1 -0
  129. package/internal/shims.d.ts +20 -0
  130. package/internal/shims.d.ts.map +1 -0
  131. package/internal/shims.js +92 -0
  132. package/internal/shims.js.map +1 -0
  133. package/internal/shims.mjs +85 -0
  134. package/internal/shims.mjs.map +1 -0
  135. package/internal/to-file.d.mts +45 -0
  136. package/internal/to-file.d.mts.map +1 -0
  137. package/internal/to-file.d.ts +45 -0
  138. package/internal/to-file.d.ts.map +1 -0
  139. package/internal/to-file.js +91 -0
  140. package/internal/to-file.js.map +1 -0
  141. package/internal/to-file.mjs +88 -0
  142. package/internal/to-file.mjs.map +1 -0
  143. package/internal/tslib.js +81 -0
  144. package/internal/tslib.mjs +17 -0
  145. package/internal/types.d.mts +67 -0
  146. package/internal/types.d.mts.map +1 -0
  147. package/internal/types.d.ts +67 -0
  148. package/internal/types.d.ts.map +1 -0
  149. package/internal/types.js +4 -0
  150. package/internal/types.js.map +1 -0
  151. package/internal/types.mjs +3 -0
  152. package/internal/types.mjs.map +1 -0
  153. package/internal/uploads.d.mts +42 -0
  154. package/internal/uploads.d.mts.map +1 -0
  155. package/internal/uploads.d.ts +42 -0
  156. package/internal/uploads.d.ts.map +1 -0
  157. package/internal/uploads.js +141 -0
  158. package/internal/uploads.js.map +1 -0
  159. package/internal/uploads.mjs +131 -0
  160. package/internal/uploads.mjs.map +1 -0
  161. package/internal/utils/base64.d.mts +3 -0
  162. package/internal/utils/base64.d.mts.map +1 -0
  163. package/internal/utils/base64.d.ts +3 -0
  164. package/internal/utils/base64.d.ts.map +1 -0
  165. package/internal/utils/base64.js +38 -0
  166. package/internal/utils/base64.js.map +1 -0
  167. package/internal/utils/base64.mjs +33 -0
  168. package/internal/utils/base64.mjs.map +1 -0
  169. package/internal/utils/bytes.d.mts +4 -0
  170. package/internal/utils/bytes.d.mts.map +1 -0
  171. package/internal/utils/bytes.d.ts +4 -0
  172. package/internal/utils/bytes.d.ts.map +1 -0
  173. package/internal/utils/bytes.js +31 -0
  174. package/internal/utils/bytes.js.map +1 -0
  175. package/internal/utils/bytes.mjs +26 -0
  176. package/internal/utils/bytes.mjs.map +1 -0
  177. package/internal/utils/env.d.mts +9 -0
  178. package/internal/utils/env.d.mts.map +1 -0
  179. package/internal/utils/env.d.ts +9 -0
  180. package/internal/utils/env.d.ts.map +1 -0
  181. package/internal/utils/env.js +22 -0
  182. package/internal/utils/env.js.map +1 -0
  183. package/internal/utils/env.mjs +18 -0
  184. package/internal/utils/env.mjs.map +1 -0
  185. package/internal/utils/log.d.mts +37 -0
  186. package/internal/utils/log.d.mts.map +1 -0
  187. package/internal/utils/log.d.ts +37 -0
  188. package/internal/utils/log.d.ts.map +1 -0
  189. package/internal/utils/log.js +85 -0
  190. package/internal/utils/log.js.map +1 -0
  191. package/internal/utils/log.mjs +79 -0
  192. package/internal/utils/log.mjs.map +1 -0
  193. package/internal/utils/path.d.mts +15 -0
  194. package/internal/utils/path.d.mts.map +1 -0
  195. package/internal/utils/path.d.ts +15 -0
  196. package/internal/utils/path.d.ts.map +1 -0
  197. package/internal/utils/path.js +58 -0
  198. package/internal/utils/path.js.map +1 -0
  199. package/internal/utils/path.mjs +53 -0
  200. package/internal/utils/path.mjs.map +1 -0
  201. package/internal/utils/sleep.d.mts +2 -0
  202. package/internal/utils/sleep.d.mts.map +1 -0
  203. package/internal/utils/sleep.d.ts +2 -0
  204. package/internal/utils/sleep.d.ts.map +1 -0
  205. package/internal/utils/sleep.js +7 -0
  206. package/internal/utils/sleep.js.map +1 -0
  207. package/internal/utils/sleep.mjs +3 -0
  208. package/internal/utils/sleep.mjs.map +1 -0
  209. package/internal/utils/uuid.d.mts +5 -0
  210. package/internal/utils/uuid.d.mts.map +1 -0
  211. package/internal/utils/uuid.d.ts +5 -0
  212. package/internal/utils/uuid.d.ts.map +1 -0
  213. package/internal/utils/uuid.js +19 -0
  214. package/internal/utils/uuid.js.map +1 -0
  215. package/internal/utils/uuid.mjs +15 -0
  216. package/internal/utils/uuid.mjs.map +1 -0
  217. package/internal/utils/values.d.mts +16 -0
  218. package/internal/utils/values.d.mts.map +1 -0
  219. package/internal/utils/values.d.ts +16 -0
  220. package/internal/utils/values.d.ts.map +1 -0
  221. package/internal/utils/values.js +109 -0
  222. package/internal/utils/values.js.map +1 -0
  223. package/internal/utils/values.mjs +92 -0
  224. package/internal/utils/values.mjs.map +1 -0
  225. package/internal/utils.d.mts +7 -0
  226. package/internal/utils.d.mts.map +1 -0
  227. package/internal/utils.d.ts +7 -0
  228. package/internal/utils.d.ts.map +1 -0
  229. package/internal/utils.js +11 -0
  230. package/internal/utils.js.map +1 -0
  231. package/internal/utils.mjs +8 -0
  232. package/internal/utils.mjs.map +1 -0
  233. package/lib/polling.d.mts +48 -0
  234. package/lib/polling.d.mts.map +1 -0
  235. package/lib/polling.d.ts.map +1 -1
  236. package/lib/polling.js +1 -3
  237. package/lib/polling.js.map +1 -1
  238. package/lib/polling.mjs +0 -1
  239. package/lib/polling.mjs.map +1 -1
  240. package/package.json +129 -64
  241. package/pagination.d.mts +2 -0
  242. package/pagination.d.mts.map +1 -0
  243. package/pagination.d.ts +1 -29
  244. package/pagination.d.ts.map +1 -1
  245. package/pagination.js +3 -42
  246. package/pagination.js.map +1 -1
  247. package/pagination.mjs +1 -40
  248. package/pagination.mjs.map +1 -1
  249. package/resource.d.mts +2 -0
  250. package/resource.d.mts.map +1 -0
  251. package/resource.d.ts +1 -5
  252. package/resource.d.ts.map +1 -1
  253. package/resource.js +3 -8
  254. package/resource.js.map +1 -1
  255. package/resource.mjs +1 -6
  256. package/resource.mjs.map +1 -1
  257. package/resources/embeddings.d.mts +55 -0
  258. package/resources/embeddings.d.mts.map +1 -0
  259. package/resources/embeddings.d.ts +13 -3
  260. package/resources/embeddings.d.ts.map +1 -1
  261. package/resources/embeddings.js +10 -1
  262. package/resources/embeddings.js.map +1 -1
  263. package/resources/embeddings.mjs +10 -1
  264. package/resources/embeddings.mjs.map +1 -1
  265. package/resources/extractions/content.d.mts +80 -0
  266. package/resources/extractions/content.d.mts.map +1 -0
  267. package/resources/extractions/content.d.ts +51 -4
  268. package/resources/extractions/content.d.ts.map +1 -1
  269. package/resources/extractions/content.js +1 -1
  270. package/resources/extractions/content.js.map +1 -1
  271. package/resources/extractions/content.mjs +1 -1
  272. package/resources/extractions/content.mjs.map +1 -1
  273. package/resources/extractions/extractions.d.mts +18 -0
  274. package/resources/extractions/extractions.d.mts.map +1 -0
  275. package/resources/extractions/extractions.d.ts +1 -1
  276. package/resources/extractions/extractions.d.ts.map +1 -1
  277. package/resources/extractions/extractions.js +5 -27
  278. package/resources/extractions/extractions.js.map +1 -1
  279. package/resources/extractions/extractions.mjs +1 -1
  280. package/resources/extractions/index.d.mts +5 -0
  281. package/resources/extractions/index.d.mts.map +1 -0
  282. package/resources/extractions/index.d.ts.map +1 -1
  283. package/resources/extractions/jobs.d.mts +85 -0
  284. package/resources/extractions/jobs.d.mts.map +1 -0
  285. package/resources/extractions/jobs.d.ts +5 -4
  286. package/resources/extractions/jobs.d.ts.map +1 -1
  287. package/resources/extractions/jobs.js +4 -3
  288. package/resources/extractions/jobs.js.map +1 -1
  289. package/resources/extractions/jobs.mjs +4 -3
  290. package/resources/extractions/jobs.mjs.map +1 -1
  291. package/resources/extractions/schema.d.mts +86 -0
  292. package/resources/extractions/schema.d.mts.map +1 -0
  293. package/resources/extractions/schema.d.ts +6 -5
  294. package/resources/extractions/schema.d.ts.map +1 -1
  295. package/resources/extractions/schema.js +1 -1
  296. package/resources/extractions/schema.js.map +1 -1
  297. package/resources/extractions/schema.mjs +1 -1
  298. package/resources/extractions/schema.mjs.map +1 -1
  299. package/resources/extractions.d.mts +2 -0
  300. package/resources/extractions.d.mts.map +1 -0
  301. package/resources/extractions.d.ts.map +1 -1
  302. package/resources/extractions.js +2 -15
  303. package/resources/extractions.js.map +1 -1
  304. package/resources/files.d.mts +124 -0
  305. package/resources/files.d.mts.map +1 -0
  306. package/resources/files.d.ts +15 -16
  307. package/resources/files.d.ts.map +1 -1
  308. package/resources/files.js +24 -46
  309. package/resources/files.js.map +1 -1
  310. package/resources/files.mjs +23 -21
  311. package/resources/files.mjs.map +1 -1
  312. package/resources/index.d.mts +8 -0
  313. package/resources/index.d.mts.map +1 -0
  314. package/resources/index.d.ts +2 -2
  315. package/resources/index.d.ts.map +1 -1
  316. package/resources/index.js +3 -18
  317. package/resources/index.js.map +1 -1
  318. package/resources/index.mjs +2 -2
  319. package/resources/index.mjs.map +1 -1
  320. package/resources/parsing/index.d.mts +3 -0
  321. package/resources/parsing/index.d.mts.map +1 -0
  322. package/resources/parsing/index.d.ts +1 -1
  323. package/resources/parsing/index.d.ts.map +1 -1
  324. package/resources/parsing/index.js +1 -2
  325. package/resources/parsing/index.js.map +1 -1
  326. package/resources/parsing/index.mjs +1 -1
  327. package/resources/parsing/index.mjs.map +1 -1
  328. package/resources/parsing/jobs.d.mts +293 -0
  329. package/resources/parsing/jobs.d.mts.map +1 -0
  330. package/resources/parsing/jobs.d.ts +21 -18
  331. package/resources/parsing/jobs.d.ts.map +1 -1
  332. package/resources/parsing/jobs.js +20 -42
  333. package/resources/parsing/jobs.js.map +1 -1
  334. package/resources/parsing/jobs.mjs +17 -16
  335. package/resources/parsing/jobs.mjs.map +1 -1
  336. package/resources/parsing/parsing.d.mts +10 -0
  337. package/resources/parsing/parsing.d.mts.map +1 -0
  338. package/resources/parsing/parsing.d.ts +2 -2
  339. package/resources/parsing/parsing.d.ts.map +1 -1
  340. package/resources/parsing/parsing.js +3 -26
  341. package/resources/parsing/parsing.js.map +1 -1
  342. package/resources/parsing/parsing.mjs +2 -3
  343. package/resources/parsing/parsing.mjs.map +1 -1
  344. package/resources/parsing.d.mts +2 -0
  345. package/resources/parsing.d.mts.map +1 -0
  346. package/resources/parsing.d.ts.map +1 -1
  347. package/resources/parsing.js +2 -15
  348. package/resources/parsing.js.map +1 -1
  349. package/resources/shared.d.mts +49 -0
  350. package/resources/shared.d.mts.map +1 -0
  351. package/resources/top-level.d.mts +188 -0
  352. package/resources/top-level.d.mts.map +1 -0
  353. package/resources/top-level.d.ts +6 -2
  354. package/resources/top-level.d.ts.map +1 -1
  355. package/resources/vector-stores/files.d.mts +303 -0
  356. package/resources/vector-stores/files.d.mts.map +1 -0
  357. package/resources/vector-stores/files.d.ts +27 -16
  358. package/resources/vector-stores/files.d.ts.map +1 -1
  359. package/resources/vector-stores/files.js +25 -47
  360. package/resources/vector-stores/files.js.map +1 -1
  361. package/resources/vector-stores/files.mjs +22 -21
  362. package/resources/vector-stores/files.mjs.map +1 -1
  363. package/resources/vector-stores/index.d.mts +3 -0
  364. package/resources/vector-stores/index.d.mts.map +1 -0
  365. package/resources/vector-stores/index.d.ts +2 -2
  366. package/resources/vector-stores/index.d.ts.map +1 -1
  367. package/resources/vector-stores/index.js +1 -3
  368. package/resources/vector-stores/index.js.map +1 -1
  369. package/resources/vector-stores/index.mjs +2 -2
  370. package/resources/vector-stores/index.mjs.map +1 -1
  371. package/resources/vector-stores/vector-stores.d.mts +440 -0
  372. package/resources/vector-stores/vector-stores.d.mts.map +1 -0
  373. package/resources/vector-stores/vector-stores.d.ts +31 -20
  374. package/resources/vector-stores/vector-stores.d.ts.map +1 -1
  375. package/resources/vector-stores/vector-stores.js +20 -43
  376. package/resources/vector-stores/vector-stores.js.map +1 -1
  377. package/resources/vector-stores/vector-stores.mjs +18 -18
  378. package/resources/vector-stores/vector-stores.mjs.map +1 -1
  379. package/resources/vector-stores.d.mts +2 -0
  380. package/resources/vector-stores.d.mts.map +1 -0
  381. package/resources/vector-stores.d.ts.map +1 -1
  382. package/resources/vector-stores.js +2 -15
  383. package/resources/vector-stores.js.map +1 -1
  384. package/resources.d.mts +2 -0
  385. package/resources.d.mts.map +1 -0
  386. package/resources.d.ts.map +1 -1
  387. package/resources.js +2 -15
  388. package/resources.js.map +1 -1
  389. package/src/api-promise.ts +2 -0
  390. package/src/client.ts +900 -0
  391. package/src/core/README.md +3 -0
  392. package/src/core/api-promise.ts +92 -0
  393. package/src/core/error.ts +130 -0
  394. package/src/core/pagination.ts +183 -0
  395. package/src/core/resource.ts +11 -0
  396. package/src/core/uploads.ts +2 -0
  397. package/src/error.ts +2 -130
  398. package/src/index.ts +6 -330
  399. package/src/internal/README.md +3 -0
  400. package/src/internal/builtin-types.ts +93 -0
  401. package/src/internal/detect-platform.ts +196 -0
  402. package/src/internal/errors.ts +33 -0
  403. package/src/internal/headers.ts +97 -0
  404. package/src/internal/parse.ts +50 -0
  405. package/src/internal/request-options.ts +37 -0
  406. package/src/internal/shim-types.d.ts +28 -0
  407. package/src/internal/shims.ts +107 -0
  408. package/src/internal/to-file.ts +154 -0
  409. package/src/internal/types.ts +92 -0
  410. package/src/internal/uploads.ts +187 -0
  411. package/src/internal/utils/base64.ts +40 -0
  412. package/src/internal/utils/bytes.ts +32 -0
  413. package/src/internal/utils/env.ts +18 -0
  414. package/src/internal/utils/log.ts +126 -0
  415. package/src/internal/utils/path.ts +65 -0
  416. package/src/internal/utils/sleep.ts +3 -0
  417. package/src/internal/utils/uuid.ts +17 -0
  418. package/src/internal/utils/values.ts +102 -0
  419. package/src/internal/utils.ts +8 -0
  420. package/src/lib/polling.ts +0 -1
  421. package/src/pagination.ts +2 -82
  422. package/src/resource.ts +2 -11
  423. package/src/resources/embeddings.ts +14 -4
  424. package/src/resources/extractions/content.ts +57 -4
  425. package/src/resources/extractions/extractions.ts +1 -1
  426. package/src/resources/extractions/jobs.ts +7 -5
  427. package/src/resources/extractions/schema.ts +6 -5
  428. package/src/resources/files.ts +30 -34
  429. package/src/resources/index.ts +2 -2
  430. package/src/resources/parsing/index.ts +1 -1
  431. package/src/resources/parsing/jobs.ts +29 -33
  432. package/src/resources/parsing/parsing.ts +2 -3
  433. package/src/resources/top-level.ts +13 -4
  434. package/src/resources/vector-stores/files.ts +51 -49
  435. package/src/resources/vector-stores/index.ts +4 -2
  436. package/src/resources/vector-stores/vector-stores.ts +45 -40
  437. package/src/tsconfig.json +2 -2
  438. package/src/uploads.ts +2 -255
  439. package/src/version.ts +1 -1
  440. package/uploads.d.mts +2 -0
  441. package/uploads.d.mts.map +1 -0
  442. package/uploads.d.ts +1 -74
  443. package/uploads.d.ts.map +1 -1
  444. package/uploads.js +3 -168
  445. package/uploads.js.map +1 -1
  446. package/uploads.mjs +1 -157
  447. package/uploads.mjs.map +1 -1
  448. package/version.d.mts +2 -0
  449. package/version.d.mts.map +1 -0
  450. package/version.d.ts +1 -1
  451. package/version.js +1 -1
  452. package/version.mjs +1 -1
  453. package/_shims/MultipartBody.d.ts +0 -9
  454. package/_shims/MultipartBody.d.ts.map +0 -1
  455. package/_shims/MultipartBody.js +0 -16
  456. package/_shims/MultipartBody.js.map +0 -1
  457. package/_shims/MultipartBody.mjs +0 -12
  458. package/_shims/MultipartBody.mjs.map +0 -1
  459. package/_shims/README.md +0 -46
  460. package/_shims/auto/runtime-bun.d.ts +0 -5
  461. package/_shims/auto/runtime-bun.d.ts.map +0 -1
  462. package/_shims/auto/runtime-bun.js +0 -21
  463. package/_shims/auto/runtime-bun.js.map +0 -1
  464. package/_shims/auto/runtime-bun.mjs +0 -2
  465. package/_shims/auto/runtime-bun.mjs.map +0 -1
  466. package/_shims/auto/runtime-node.d.ts +0 -5
  467. package/_shims/auto/runtime-node.d.ts.map +0 -1
  468. package/_shims/auto/runtime-node.js +0 -21
  469. package/_shims/auto/runtime-node.js.map +0 -1
  470. package/_shims/auto/runtime-node.mjs +0 -2
  471. package/_shims/auto/runtime-node.mjs.map +0 -1
  472. package/_shims/auto/runtime.d.ts +0 -5
  473. package/_shims/auto/runtime.d.ts.map +0 -1
  474. package/_shims/auto/runtime.js +0 -21
  475. package/_shims/auto/runtime.js.map +0 -1
  476. package/_shims/auto/runtime.mjs +0 -2
  477. package/_shims/auto/runtime.mjs.map +0 -1
  478. package/_shims/auto/types-node.d.ts +0 -5
  479. package/_shims/auto/types-node.d.ts.map +0 -1
  480. package/_shims/auto/types-node.js +0 -21
  481. package/_shims/auto/types-node.js.map +0 -1
  482. package/_shims/auto/types-node.mjs +0 -2
  483. package/_shims/auto/types-node.mjs.map +0 -1
  484. package/_shims/auto/types.d.ts +0 -101
  485. package/_shims/auto/types.js +0 -3
  486. package/_shims/auto/types.mjs +0 -3
  487. package/_shims/bun-runtime.d.ts +0 -6
  488. package/_shims/bun-runtime.d.ts.map +0 -1
  489. package/_shims/bun-runtime.js +0 -14
  490. package/_shims/bun-runtime.js.map +0 -1
  491. package/_shims/bun-runtime.mjs +0 -10
  492. package/_shims/bun-runtime.mjs.map +0 -1
  493. package/_shims/index.d.ts +0 -83
  494. package/_shims/index.js +0 -17
  495. package/_shims/index.mjs +0 -11
  496. package/_shims/manual-types.d.ts +0 -12
  497. package/_shims/manual-types.js +0 -3
  498. package/_shims/manual-types.mjs +0 -3
  499. package/_shims/node-runtime.d.ts +0 -3
  500. package/_shims/node-runtime.d.ts.map +0 -1
  501. package/_shims/node-runtime.js +0 -89
  502. package/_shims/node-runtime.js.map +0 -1
  503. package/_shims/node-runtime.mjs +0 -56
  504. package/_shims/node-runtime.mjs.map +0 -1
  505. package/_shims/node-types.d.ts +0 -42
  506. package/_shims/node-types.js +0 -3
  507. package/_shims/node-types.mjs +0 -3
  508. package/_shims/registry.d.ts +0 -37
  509. package/_shims/registry.d.ts.map +0 -1
  510. package/_shims/registry.js +0 -41
  511. package/_shims/registry.js.map +0 -1
  512. package/_shims/registry.mjs +0 -37
  513. package/_shims/registry.mjs.map +0 -1
  514. package/_shims/web-runtime.d.ts +0 -5
  515. package/_shims/web-runtime.d.ts.map +0 -1
  516. package/_shims/web-runtime.js +0 -78
  517. package/_shims/web-runtime.js.map +0 -1
  518. package/_shims/web-runtime.mjs +0 -71
  519. package/_shims/web-runtime.mjs.map +0 -1
  520. package/_shims/web-types.d.ts +0 -83
  521. package/_shims/web-types.js +0 -3
  522. package/_shims/web-types.mjs +0 -3
  523. package/core.d.ts +0 -252
  524. package/core.d.ts.map +0 -1
  525. package/core.js +0 -917
  526. package/core.js.map +0 -1
  527. package/core.mjs +0 -885
  528. package/core.mjs.map +0 -1
  529. package/shims/node.d.ts +0 -30
  530. package/shims/node.d.ts.map +0 -1
  531. package/shims/node.js +0 -31
  532. package/shims/node.js.map +0 -1
  533. package/shims/node.mjs +0 -5
  534. package/shims/node.mjs.map +0 -1
  535. package/shims/web.d.ts +0 -26
  536. package/shims/web.d.ts.map +0 -1
  537. package/shims/web.js +0 -31
  538. package/shims/web.js.map +0 -1
  539. package/shims/web.mjs +0 -5
  540. package/shims/web.mjs.map +0 -1
  541. package/src/_shims/MultipartBody.ts +0 -9
  542. package/src/_shims/README.md +0 -46
  543. package/src/_shims/auto/runtime-bun.ts +0 -4
  544. package/src/_shims/auto/runtime-node.ts +0 -4
  545. package/src/_shims/auto/runtime.ts +0 -4
  546. package/src/_shims/auto/types-node.ts +0 -4
  547. package/src/_shims/auto/types.d.ts +0 -101
  548. package/src/_shims/auto/types.js +0 -3
  549. package/src/_shims/auto/types.mjs +0 -3
  550. package/src/_shims/bun-runtime.ts +0 -14
  551. package/src/_shims/index.d.ts +0 -83
  552. package/src/_shims/index.js +0 -17
  553. package/src/_shims/index.mjs +0 -11
  554. package/src/_shims/manual-types.d.ts +0 -12
  555. package/src/_shims/manual-types.js +0 -3
  556. package/src/_shims/manual-types.mjs +0 -3
  557. package/src/_shims/node-runtime.ts +0 -81
  558. package/src/_shims/node-types.d.ts +0 -42
  559. package/src/_shims/node-types.js +0 -3
  560. package/src/_shims/node-types.mjs +0 -3
  561. package/src/_shims/registry.ts +0 -67
  562. package/src/_shims/web-runtime.ts +0 -103
  563. package/src/_shims/web-types.d.ts +0 -83
  564. package/src/_shims/web-types.js +0 -3
  565. package/src/_shims/web-types.mjs +0 -3
  566. package/src/core.ts +0 -1227
  567. package/src/shims/node.ts +0 -50
  568. package/src/shims/web.ts +0 -50
package/src/client.ts ADDED
@@ -0,0 +1,900 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
4
+ import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';
5
+ import { uuid4 } from './internal/utils/uuid';
6
+ import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
7
+ import { sleep } from './internal/utils/sleep';
8
+ import { type Logger, type LogLevel, parseLogLevel } from './internal/utils/log';
9
+ export type { Logger, LogLevel } from './internal/utils/log';
10
+ import { castToError, isAbortError } from './internal/errors';
11
+ import type { APIResponseProps } from './internal/parse';
12
+ import { getPlatformHeaders } from './internal/detect-platform';
13
+ import * as Shims from './internal/shims';
14
+ import * as Opts from './internal/request-options';
15
+ import { VERSION } from './version';
16
+ import * as Errors from './core/error';
17
+ import * as Pagination from './core/pagination';
18
+ import { AbstractPage, type LimitOffsetParams, LimitOffsetResponse } from './core/pagination';
19
+ import * as Uploads from './core/uploads';
20
+ import * as API from './resources/index';
21
+ import * as TopLevelAPI from './resources/top-level';
22
+ import {
23
+ EmbedParams,
24
+ Embedding,
25
+ EmbeddingCreateResponse,
26
+ InfoResponse,
27
+ MultiEncodingEmbedding,
28
+ RerankParams,
29
+ RerankResponse,
30
+ } from './resources/top-level';
31
+ import { APIPromise } from './core/api-promise';
32
+ import { type Fetch } from './internal/builtin-types';
33
+ import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
34
+ import { FinalRequestOptions, RequestOptions } from './internal/request-options';
35
+ import { EmbeddingCreateParams, Embeddings } from './resources/embeddings';
36
+ import {
37
+ FileCreateParams,
38
+ FileDeleteResponse,
39
+ FileListParams,
40
+ FileObject,
41
+ FileObjectsLimitOffset,
42
+ FileUpdateParams,
43
+ Files,
44
+ } from './resources/files';
45
+ import { readEnv } from './internal/utils/env';
46
+ import { formatRequestDetails, loggerFor } from './internal/utils/log';
47
+ import { isEmptyObj } from './internal/utils/values';
48
+ import { Extractions } from './resources/extractions/extractions';
49
+ import { Parsing } from './resources/parsing/parsing';
50
+ import {
51
+ ExpiresAfter,
52
+ FileCounts,
53
+ ScoredVectorStoreChunk,
54
+ VectorStore,
55
+ VectorStoreChunkSearchOptions,
56
+ VectorStoreCreateParams,
57
+ VectorStoreDeleteResponse,
58
+ VectorStoreFileSearchOptions,
59
+ VectorStoreListParams,
60
+ VectorStoreQuestionAnsweringParams,
61
+ VectorStoreQuestionAnsweringResponse,
62
+ VectorStoreSearchParams,
63
+ VectorStoreSearchResponse,
64
+ VectorStoreUpdateParams,
65
+ VectorStores,
66
+ VectorStoresLimitOffset,
67
+ } from './resources/vector-stores/vector-stores';
68
+
69
+ const environments = {
70
+ production: 'https://api.mixedbread.com',
71
+ local: 'http://127.0.0.1:8000',
72
+ };
73
+ type Environment = keyof typeof environments;
74
+
75
+ export interface ClientOptions {
76
+ /**
77
+ * Api key to authenticate with Mixedbread
78
+ */
79
+ apiKey?: string | undefined;
80
+
81
+ /**
82
+ * Specifies the environment to use for the API.
83
+ *
84
+ * Each environment maps to a different base URL:
85
+ * - `production` corresponds to `https://api.mixedbread.com`
86
+ * - `local` corresponds to `http://127.0.0.1:8000`
87
+ */
88
+ environment?: Environment | undefined;
89
+
90
+ /**
91
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
92
+ *
93
+ * Defaults to process.env['MIXEDBREAD_BASE_URL'].
94
+ */
95
+ baseURL?: string | null | undefined;
96
+
97
+ /**
98
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
99
+ * from the server before timing out a single request.
100
+ *
101
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
102
+ * much longer than this timeout before the promise succeeds or fails.
103
+ */
104
+ timeout?: number | undefined;
105
+ /**
106
+ * Additional `RequestInit` options to be passed to `fetch` calls.
107
+ * Properties will be overridden by per-request `fetchOptions`.
108
+ */
109
+ fetchOptions?: MergedRequestInit | undefined;
110
+
111
+ /**
112
+ * Specify a custom `fetch` function implementation.
113
+ *
114
+ * If not provided, we expect that `fetch` is defined globally.
115
+ */
116
+ fetch?: Fetch | undefined;
117
+
118
+ /**
119
+ * The maximum number of times that the client will retry a request in case of a
120
+ * temporary failure, like a network error or a 5XX error from the server.
121
+ *
122
+ * @default 2
123
+ */
124
+ maxRetries?: number | undefined;
125
+
126
+ /**
127
+ * Default headers to include with every request to the API.
128
+ *
129
+ * These can be removed in individual requests by explicitly setting the
130
+ * header to `null` in request options.
131
+ */
132
+ defaultHeaders?: HeadersLike | undefined;
133
+
134
+ /**
135
+ * Default query parameters to include with every request to the API.
136
+ *
137
+ * These can be removed in individual requests by explicitly setting the
138
+ * param to `undefined` in request options.
139
+ */
140
+ defaultQuery?: Record<string, string | undefined> | undefined;
141
+
142
+ /**
143
+ * Set the log level.
144
+ *
145
+ * Defaults to process.env['MIXEDBREAD_LOG'] or 'warn' if it isn't set.
146
+ */
147
+ logLevel?: LogLevel | undefined;
148
+
149
+ /**
150
+ * Set the logger.
151
+ *
152
+ * Defaults to globalThis.console.
153
+ */
154
+ logger?: Logger | undefined;
155
+ }
156
+
157
+ /**
158
+ * API Client for interfacing with the Mixedbread API.
159
+ */
160
+ export class Mixedbread {
161
+ apiKey: string;
162
+
163
+ baseURL: string;
164
+ maxRetries: number;
165
+ timeout: number;
166
+ logger: Logger | undefined;
167
+ logLevel: LogLevel | undefined;
168
+ fetchOptions: MergedRequestInit | undefined;
169
+
170
+ private fetch: Fetch;
171
+ #encoder: Opts.RequestEncoder;
172
+ protected idempotencyHeader?: string;
173
+ private _options: ClientOptions;
174
+
175
+ /**
176
+ * API Client for interfacing with the Mixedbread API.
177
+ *
178
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
179
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
180
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.com] - Override the default base URL for the API.
181
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
182
+ * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
183
+ * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
184
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
185
+ * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
186
+ * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
187
+ */
188
+ constructor({
189
+ baseURL = readEnv('MIXEDBREAD_BASE_URL'),
190
+ apiKey = readEnv('MXBAI_API_KEY'),
191
+ ...opts
192
+ }: ClientOptions = {}) {
193
+ if (apiKey === undefined) {
194
+ throw new Errors.MixedbreadError(
195
+ "The MXBAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Mixedbread client with an apiKey option, like new Mixedbread({ apiKey: 'My API Key' }).",
196
+ );
197
+ }
198
+
199
+ const options: ClientOptions = {
200
+ apiKey,
201
+ ...opts,
202
+ baseURL,
203
+ environment: opts.environment ?? 'production',
204
+ };
205
+
206
+ if (baseURL && opts.environment) {
207
+ throw new Errors.MixedbreadError(
208
+ 'Ambiguous URL; The `baseURL` option (or MIXEDBREAD_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
209
+ );
210
+ }
211
+
212
+ this.baseURL = options.baseURL || environments[options.environment || 'production'];
213
+ this.timeout = options.timeout ?? Mixedbread.DEFAULT_TIMEOUT /* 1 minute */;
214
+ this.logger = options.logger ?? console;
215
+ const defaultLogLevel = 'warn';
216
+ // Set default logLevel early so that we can log a warning in parseLogLevel.
217
+ this.logLevel = defaultLogLevel;
218
+ this.logLevel =
219
+ parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
220
+ parseLogLevel(readEnv('MIXEDBREAD_LOG'), "process.env['MIXEDBREAD_LOG']", this) ??
221
+ defaultLogLevel;
222
+ this.fetchOptions = options.fetchOptions;
223
+ this.maxRetries = options.maxRetries ?? 2;
224
+ this.fetch = options.fetch ?? Shims.getDefaultFetch();
225
+ this.#encoder = Opts.FallbackEncoder;
226
+
227
+ this._options = options;
228
+
229
+ this.apiKey = apiKey;
230
+ }
231
+
232
+ /**
233
+ * Create a new client instance re-using the same options given to the current client with optional overriding.
234
+ */
235
+ withOptions(options: Partial<ClientOptions>): this {
236
+ return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
237
+ ...this._options,
238
+ environment: options.environment ? options.environment : undefined,
239
+ baseURL: options.environment ? undefined : this.baseURL,
240
+ maxRetries: this.maxRetries,
241
+ timeout: this.timeout,
242
+ logger: this.logger,
243
+ logLevel: this.logLevel,
244
+ fetchOptions: this.fetchOptions,
245
+ apiKey: this.apiKey,
246
+ ...options,
247
+ });
248
+ }
249
+
250
+ /**
251
+ * Create embeddings for text or images using the specified model, encoding format,
252
+ * and normalization.
253
+ *
254
+ * Args: params: The parameters for creating embeddings.
255
+ *
256
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * const embeddingCreateResponse = await client.embed({
261
+ * model: 'mixedbread-ai/mxbai-embed-large-v1',
262
+ * input: 'x',
263
+ * });
264
+ * ```
265
+ */
266
+ embed(
267
+ body: TopLevelAPI.EmbedParams,
268
+ options?: RequestOptions,
269
+ ): APIPromise<TopLevelAPI.EmbeddingCreateResponse> {
270
+ return this.post('/v1/embeddings', { body, ...options });
271
+ }
272
+
273
+ /**
274
+ * Returns service information, including name and version.
275
+ *
276
+ * Returns: InfoResponse: A response containing the service name and version.
277
+ *
278
+ * @example
279
+ * ```ts
280
+ * const response = await client.info();
281
+ * ```
282
+ */
283
+ info(options?: RequestOptions): APIPromise<TopLevelAPI.InfoResponse> {
284
+ return this.get('/', options);
285
+ }
286
+
287
+ /**
288
+ * Rerank different kind of documents for a given query.
289
+ *
290
+ * Args: params: RerankParams: The parameters for reranking.
291
+ *
292
+ * Returns: RerankResponse: The reranked documents for the input query.
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * const response = await client.rerank({
297
+ * query:
298
+ * 'What are the key features of the Mixedbread embedding model?',
299
+ * input: ['Document 1', 'Document 2'],
300
+ * });
301
+ * ```
302
+ */
303
+ rerank(body: TopLevelAPI.RerankParams, options?: RequestOptions): APIPromise<TopLevelAPI.RerankResponse> {
304
+ return this.post('/v1/reranking', { body, ...options });
305
+ }
306
+
307
+ protected defaultQuery(): Record<string, string | undefined> | undefined {
308
+ return this._options.defaultQuery;
309
+ }
310
+
311
+ protected validateHeaders({ values, nulls }: NullableHeaders) {
312
+ return;
313
+ }
314
+
315
+ protected authHeaders(opts: FinalRequestOptions): NullableHeaders | undefined {
316
+ return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
317
+ }
318
+
319
+ /**
320
+ * Basic re-implementation of `qs.stringify` for primitive types.
321
+ */
322
+ protected stringifyQuery(query: Record<string, unknown>): string {
323
+ return Object.entries(query)
324
+ .filter(([_, value]) => typeof value !== 'undefined')
325
+ .map(([key, value]) => {
326
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
327
+ return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
328
+ }
329
+ if (value === null) {
330
+ return `${encodeURIComponent(key)}=`;
331
+ }
332
+ throw new Errors.MixedbreadError(
333
+ `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
334
+ );
335
+ })
336
+ .join('&');
337
+ }
338
+
339
+ private getUserAgent(): string {
340
+ return `${this.constructor.name}/JS ${VERSION}`;
341
+ }
342
+
343
+ protected defaultIdempotencyKey(): string {
344
+ return `stainless-node-retry-${uuid4()}`;
345
+ }
346
+
347
+ protected makeStatusError(
348
+ status: number,
349
+ error: Object,
350
+ message: string | undefined,
351
+ headers: Headers,
352
+ ): Errors.APIError {
353
+ return Errors.APIError.generate(status, error, message, headers);
354
+ }
355
+
356
+ buildURL(path: string, query: Record<string, unknown> | null | undefined): string {
357
+ const url =
358
+ isAbsoluteURL(path) ?
359
+ new URL(path)
360
+ : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
361
+
362
+ const defaultQuery = this.defaultQuery();
363
+ if (!isEmptyObj(defaultQuery)) {
364
+ query = { ...defaultQuery, ...query };
365
+ }
366
+
367
+ if (typeof query === 'object' && query && !Array.isArray(query)) {
368
+ url.search = this.stringifyQuery(query as Record<string, unknown>);
369
+ }
370
+
371
+ return url.toString();
372
+ }
373
+
374
+ /**
375
+ * Used as a callback for mutating the given `FinalRequestOptions` object.
376
+ */
377
+ protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
378
+
379
+ /**
380
+ * Used as a callback for mutating the given `RequestInit` object.
381
+ *
382
+ * This is useful for cases where you want to add certain headers based off of
383
+ * the request properties, e.g. `method` or `url`.
384
+ */
385
+ protected async prepareRequest(
386
+ request: RequestInit,
387
+ { url, options }: { url: string; options: FinalRequestOptions },
388
+ ): Promise<void> {}
389
+
390
+ get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
391
+ return this.methodRequest('get', path, opts);
392
+ }
393
+
394
+ post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
395
+ return this.methodRequest('post', path, opts);
396
+ }
397
+
398
+ patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
399
+ return this.methodRequest('patch', path, opts);
400
+ }
401
+
402
+ put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
403
+ return this.methodRequest('put', path, opts);
404
+ }
405
+
406
+ delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
407
+ return this.methodRequest('delete', path, opts);
408
+ }
409
+
410
+ private methodRequest<Rsp>(
411
+ method: HTTPMethod,
412
+ path: string,
413
+ opts?: PromiseOrValue<RequestOptions>,
414
+ ): APIPromise<Rsp> {
415
+ return this.request(
416
+ Promise.resolve(opts).then((opts) => {
417
+ return { method, path, ...opts };
418
+ }),
419
+ );
420
+ }
421
+
422
+ request<Rsp>(
423
+ options: PromiseOrValue<FinalRequestOptions>,
424
+ remainingRetries: number | null = null,
425
+ ): APIPromise<Rsp> {
426
+ return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
427
+ }
428
+
429
+ private async makeRequest(
430
+ optionsInput: PromiseOrValue<FinalRequestOptions>,
431
+ retriesRemaining: number | null,
432
+ retryOfRequestLogID: string | undefined,
433
+ ): Promise<APIResponseProps> {
434
+ const options = await optionsInput;
435
+ const maxRetries = options.maxRetries ?? this.maxRetries;
436
+ if (retriesRemaining == null) {
437
+ retriesRemaining = maxRetries;
438
+ }
439
+
440
+ await this.prepareOptions(options);
441
+
442
+ const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
443
+
444
+ await this.prepareRequest(req, { url, options });
445
+
446
+ /** Not an API request ID, just for correlating local log entries. */
447
+ const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
448
+ const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
449
+ const startTime = Date.now();
450
+
451
+ loggerFor(this).debug(
452
+ `[${requestLogID}] sending request`,
453
+ formatRequestDetails({
454
+ retryOfRequestLogID,
455
+ method: options.method,
456
+ url,
457
+ options,
458
+ headers: req.headers,
459
+ }),
460
+ );
461
+
462
+ if (options.signal?.aborted) {
463
+ throw new Errors.APIUserAbortError();
464
+ }
465
+
466
+ const controller = new AbortController();
467
+ const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
468
+ const headersTime = Date.now();
469
+
470
+ if (response instanceof Error) {
471
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
472
+ if (options.signal?.aborted) {
473
+ throw new Errors.APIUserAbortError();
474
+ }
475
+ // detect native connection timeout errors
476
+ // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
477
+ // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
478
+ // others do not provide enough information to distinguish timeouts from other connection errors
479
+ const isTimeout =
480
+ isAbortError(response) ||
481
+ /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
482
+ if (retriesRemaining) {
483
+ loggerFor(this).info(
484
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
485
+ );
486
+ loggerFor(this).debug(
487
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
488
+ formatRequestDetails({
489
+ retryOfRequestLogID,
490
+ url,
491
+ durationMs: headersTime - startTime,
492
+ message: response.message,
493
+ }),
494
+ );
495
+ return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
496
+ }
497
+ loggerFor(this).info(
498
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
499
+ );
500
+ loggerFor(this).debug(
501
+ `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
502
+ formatRequestDetails({
503
+ retryOfRequestLogID,
504
+ url,
505
+ durationMs: headersTime - startTime,
506
+ message: response.message,
507
+ }),
508
+ );
509
+ if (isTimeout) {
510
+ throw new Errors.APIConnectionTimeoutError();
511
+ }
512
+ throw new Errors.APIConnectionError({ cause: response });
513
+ }
514
+
515
+ const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
516
+ response.ok ? 'succeeded' : 'failed'
517
+ } with status ${response.status} in ${headersTime - startTime}ms`;
518
+
519
+ if (!response.ok) {
520
+ const shouldRetry = this.shouldRetry(response);
521
+ if (retriesRemaining && shouldRetry) {
522
+ const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
523
+
524
+ // We don't need the body of this response.
525
+ await Shims.CancelReadableStream(response.body);
526
+ loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
527
+ loggerFor(this).debug(
528
+ `[${requestLogID}] response error (${retryMessage})`,
529
+ formatRequestDetails({
530
+ retryOfRequestLogID,
531
+ url: response.url,
532
+ status: response.status,
533
+ headers: response.headers,
534
+ durationMs: headersTime - startTime,
535
+ }),
536
+ );
537
+ return this.retryRequest(
538
+ options,
539
+ retriesRemaining,
540
+ retryOfRequestLogID ?? requestLogID,
541
+ response.headers,
542
+ );
543
+ }
544
+
545
+ const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
546
+
547
+ loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
548
+
549
+ const errText = await response.text().catch((err: any) => castToError(err).message);
550
+ const errJSON = safeJSON(errText);
551
+ const errMessage = errJSON ? undefined : errText;
552
+
553
+ loggerFor(this).debug(
554
+ `[${requestLogID}] response error (${retryMessage})`,
555
+ formatRequestDetails({
556
+ retryOfRequestLogID,
557
+ url: response.url,
558
+ status: response.status,
559
+ headers: response.headers,
560
+ message: errMessage,
561
+ durationMs: Date.now() - startTime,
562
+ }),
563
+ );
564
+
565
+ const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
566
+ throw err;
567
+ }
568
+
569
+ loggerFor(this).info(responseInfo);
570
+ loggerFor(this).debug(
571
+ `[${requestLogID}] response start`,
572
+ formatRequestDetails({
573
+ retryOfRequestLogID,
574
+ url: response.url,
575
+ status: response.status,
576
+ headers: response.headers,
577
+ durationMs: headersTime - startTime,
578
+ }),
579
+ );
580
+
581
+ return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
582
+ }
583
+
584
+ getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
585
+ path: string,
586
+ Page: new (...args: any[]) => PageClass,
587
+ opts?: RequestOptions,
588
+ ): Pagination.PagePromise<PageClass, Item> {
589
+ return this.requestAPIList(Page, { method: 'get', path, ...opts });
590
+ }
591
+
592
+ requestAPIList<
593
+ Item = unknown,
594
+ PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
595
+ >(
596
+ Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
597
+ options: FinalRequestOptions,
598
+ ): Pagination.PagePromise<PageClass, Item> {
599
+ const request = this.makeRequest(options, null, undefined);
600
+ return new Pagination.PagePromise<PageClass, Item>(this as any as Mixedbread, request, Page);
601
+ }
602
+
603
+ async fetchWithTimeout(
604
+ url: RequestInfo,
605
+ init: RequestInit | undefined,
606
+ ms: number,
607
+ controller: AbortController,
608
+ ): Promise<Response> {
609
+ const { signal, method, ...options } = init || {};
610
+ if (signal) signal.addEventListener('abort', () => controller.abort());
611
+
612
+ const timeout = setTimeout(() => controller.abort(), ms);
613
+
614
+ const isReadableBody =
615
+ ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
616
+ (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
617
+
618
+ const fetchOptions: RequestInit = {
619
+ signal: controller.signal as any,
620
+ ...(isReadableBody ? { duplex: 'half' } : {}),
621
+ method: 'GET',
622
+ ...options,
623
+ };
624
+ if (method) {
625
+ // Custom methods like 'patch' need to be uppercased
626
+ // See https://github.com/nodejs/undici/issues/2294
627
+ fetchOptions.method = method.toUpperCase();
628
+ }
629
+
630
+ try {
631
+ // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
632
+ return await this.fetch.call(undefined, url, fetchOptions);
633
+ } finally {
634
+ clearTimeout(timeout);
635
+ }
636
+ }
637
+
638
+ private shouldRetry(response: Response): boolean {
639
+ // Note this is not a standard header.
640
+ const shouldRetryHeader = response.headers.get('x-should-retry');
641
+
642
+ // If the server explicitly says whether or not to retry, obey.
643
+ if (shouldRetryHeader === 'true') return true;
644
+ if (shouldRetryHeader === 'false') return false;
645
+
646
+ // Retry on request timeouts.
647
+ if (response.status === 408) return true;
648
+
649
+ // Retry on lock timeouts.
650
+ if (response.status === 409) return true;
651
+
652
+ // Retry on rate limits.
653
+ if (response.status === 429) return true;
654
+
655
+ // Retry internal errors.
656
+ if (response.status >= 500) return true;
657
+
658
+ return false;
659
+ }
660
+
661
+ private async retryRequest(
662
+ options: FinalRequestOptions,
663
+ retriesRemaining: number,
664
+ requestLogID: string,
665
+ responseHeaders?: Headers | undefined,
666
+ ): Promise<APIResponseProps> {
667
+ let timeoutMillis: number | undefined;
668
+
669
+ // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
670
+ const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
671
+ if (retryAfterMillisHeader) {
672
+ const timeoutMs = parseFloat(retryAfterMillisHeader);
673
+ if (!Number.isNaN(timeoutMs)) {
674
+ timeoutMillis = timeoutMs;
675
+ }
676
+ }
677
+
678
+ // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
679
+ const retryAfterHeader = responseHeaders?.get('retry-after');
680
+ if (retryAfterHeader && !timeoutMillis) {
681
+ const timeoutSeconds = parseFloat(retryAfterHeader);
682
+ if (!Number.isNaN(timeoutSeconds)) {
683
+ timeoutMillis = timeoutSeconds * 1000;
684
+ } else {
685
+ timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
686
+ }
687
+ }
688
+
689
+ // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
690
+ // just do what it says, but otherwise calculate a default
691
+ if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
692
+ const maxRetries = options.maxRetries ?? this.maxRetries;
693
+ timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
694
+ }
695
+ await sleep(timeoutMillis);
696
+
697
+ return this.makeRequest(options, retriesRemaining - 1, requestLogID);
698
+ }
699
+
700
+ private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
701
+ const initialRetryDelay = 0.5;
702
+ const maxRetryDelay = 8.0;
703
+
704
+ const numRetries = maxRetries - retriesRemaining;
705
+
706
+ // Apply exponential backoff, but not more than the max.
707
+ const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
708
+
709
+ // Apply some jitter, take up to at most 25 percent of the retry time.
710
+ const jitter = 1 - Math.random() * 0.25;
711
+
712
+ return sleepSeconds * jitter * 1000;
713
+ }
714
+
715
+ buildRequest(
716
+ inputOptions: FinalRequestOptions,
717
+ { retryCount = 0 }: { retryCount?: number } = {},
718
+ ): { req: FinalizedRequestInit; url: string; timeout: number } {
719
+ const options = { ...inputOptions };
720
+ const { method, path, query } = options;
721
+
722
+ const url = this.buildURL(path!, query as Record<string, unknown>);
723
+ if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
724
+ options.timeout = options.timeout ?? this.timeout;
725
+ const { bodyHeaders, body } = this.buildBody({ options });
726
+ const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
727
+
728
+ const req: FinalizedRequestInit = {
729
+ method,
730
+ headers: reqHeaders,
731
+ ...(options.signal && { signal: options.signal }),
732
+ ...((globalThis as any).ReadableStream &&
733
+ body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
734
+ ...(body && { body }),
735
+ ...((this.fetchOptions as any) ?? {}),
736
+ ...((options.fetchOptions as any) ?? {}),
737
+ };
738
+
739
+ return { req, url, timeout: options.timeout };
740
+ }
741
+
742
+ private buildHeaders({
743
+ options,
744
+ method,
745
+ bodyHeaders,
746
+ retryCount,
747
+ }: {
748
+ options: FinalRequestOptions;
749
+ method: HTTPMethod;
750
+ bodyHeaders: HeadersLike;
751
+ retryCount: number;
752
+ }): Headers {
753
+ let idempotencyHeaders: HeadersLike = {};
754
+ if (this.idempotencyHeader && method !== 'get') {
755
+ if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
756
+ idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
757
+ }
758
+
759
+ const headers = buildHeaders([
760
+ idempotencyHeaders,
761
+ {
762
+ Accept: 'application/json',
763
+ 'User-Agent': this.getUserAgent(),
764
+ 'X-Stainless-Retry-Count': String(retryCount),
765
+ ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
766
+ ...getPlatformHeaders(),
767
+ },
768
+ this.authHeaders(options),
769
+ this._options.defaultHeaders,
770
+ bodyHeaders,
771
+ options.headers,
772
+ ]);
773
+
774
+ this.validateHeaders(headers);
775
+
776
+ return headers.values;
777
+ }
778
+
779
+ private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
780
+ bodyHeaders: HeadersLike;
781
+ body: BodyInit | undefined;
782
+ } {
783
+ if (!body) {
784
+ return { bodyHeaders: undefined, body: undefined };
785
+ }
786
+ const headers = buildHeaders([rawHeaders]);
787
+ if (
788
+ // Pass raw type verbatim
789
+ ArrayBuffer.isView(body) ||
790
+ body instanceof ArrayBuffer ||
791
+ body instanceof DataView ||
792
+ (typeof body === 'string' &&
793
+ // Preserve legacy string encoding behavior for now
794
+ headers.values.has('content-type')) ||
795
+ // `Blob` is superset of `File`
796
+ body instanceof Blob ||
797
+ // `FormData` -> `multipart/form-data`
798
+ body instanceof FormData ||
799
+ // `URLSearchParams` -> `application/x-www-form-urlencoded`
800
+ body instanceof URLSearchParams ||
801
+ // Send chunked stream (each chunk has own `length`)
802
+ ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
803
+ ) {
804
+ return { bodyHeaders: undefined, body: body as BodyInit };
805
+ } else if (
806
+ typeof body === 'object' &&
807
+ (Symbol.asyncIterator in body ||
808
+ (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
809
+ ) {
810
+ return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
811
+ } else {
812
+ return this.#encoder({ body, headers });
813
+ }
814
+ }
815
+
816
+ static Mixedbread = this;
817
+ static DEFAULT_TIMEOUT = 60000; // 1 minute
818
+
819
+ static MixedbreadError = Errors.MixedbreadError;
820
+ static APIError = Errors.APIError;
821
+ static APIConnectionError = Errors.APIConnectionError;
822
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
823
+ static APIUserAbortError = Errors.APIUserAbortError;
824
+ static NotFoundError = Errors.NotFoundError;
825
+ static ConflictError = Errors.ConflictError;
826
+ static RateLimitError = Errors.RateLimitError;
827
+ static BadRequestError = Errors.BadRequestError;
828
+ static AuthenticationError = Errors.AuthenticationError;
829
+ static InternalServerError = Errors.InternalServerError;
830
+ static PermissionDeniedError = Errors.PermissionDeniedError;
831
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
832
+
833
+ static toFile = Uploads.toFile;
834
+
835
+ vectorStores: API.VectorStores = new API.VectorStores(this);
836
+ parsing: API.Parsing = new API.Parsing(this);
837
+ files: API.Files = new API.Files(this);
838
+ extractions: API.Extractions = new API.Extractions(this);
839
+ embeddings: API.Embeddings = new API.Embeddings(this);
840
+ }
841
+ Mixedbread.VectorStores = VectorStores;
842
+ Mixedbread.Parsing = Parsing;
843
+ Mixedbread.Files = Files;
844
+ Mixedbread.Extractions = Extractions;
845
+ Mixedbread.Embeddings = Embeddings;
846
+ export declare namespace Mixedbread {
847
+ export type RequestOptions = Opts.RequestOptions;
848
+
849
+ export import LimitOffset = Pagination.LimitOffset;
850
+ export { type LimitOffsetParams as LimitOffsetParams, type LimitOffsetResponse as LimitOffsetResponse };
851
+
852
+ export {
853
+ type Embedding as Embedding,
854
+ type EmbeddingCreateResponse as EmbeddingCreateResponse,
855
+ type MultiEncodingEmbedding as MultiEncodingEmbedding,
856
+ type InfoResponse as InfoResponse,
857
+ type RerankResponse as RerankResponse,
858
+ type EmbedParams as EmbedParams,
859
+ type RerankParams as RerankParams,
860
+ };
861
+
862
+ export {
863
+ VectorStores as VectorStores,
864
+ type ExpiresAfter as ExpiresAfter,
865
+ type FileCounts as FileCounts,
866
+ type ScoredVectorStoreChunk as ScoredVectorStoreChunk,
867
+ type VectorStore as VectorStore,
868
+ type VectorStoreChunkSearchOptions as VectorStoreChunkSearchOptions,
869
+ type VectorStoreFileSearchOptions as VectorStoreFileSearchOptions,
870
+ type VectorStoreDeleteResponse as VectorStoreDeleteResponse,
871
+ type VectorStoreQuestionAnsweringResponse as VectorStoreQuestionAnsweringResponse,
872
+ type VectorStoreSearchResponse as VectorStoreSearchResponse,
873
+ type VectorStoresLimitOffset as VectorStoresLimitOffset,
874
+ type VectorStoreCreateParams as VectorStoreCreateParams,
875
+ type VectorStoreUpdateParams as VectorStoreUpdateParams,
876
+ type VectorStoreListParams as VectorStoreListParams,
877
+ type VectorStoreQuestionAnsweringParams as VectorStoreQuestionAnsweringParams,
878
+ type VectorStoreSearchParams as VectorStoreSearchParams,
879
+ };
880
+
881
+ export { Parsing as Parsing };
882
+
883
+ export {
884
+ Files as Files,
885
+ type FileObject as FileObject,
886
+ type FileDeleteResponse as FileDeleteResponse,
887
+ type FileObjectsLimitOffset as FileObjectsLimitOffset,
888
+ type FileCreateParams as FileCreateParams,
889
+ type FileUpdateParams as FileUpdateParams,
890
+ type FileListParams as FileListParams,
891
+ };
892
+
893
+ export { Extractions as Extractions };
894
+
895
+ export { Embeddings as Embeddings, type EmbeddingCreateParams as EmbeddingCreateParams };
896
+
897
+ export type SearchFilter = API.SearchFilter;
898
+ export type SearchFilterCondition = API.SearchFilterCondition;
899
+ export type Usage = API.Usage;
900
+ }