@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/core.mjs DELETED
@@ -1,885 +0,0 @@
1
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
- if (kind === "m") throw new TypeError("Private method is not writable");
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
- };
7
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
- };
12
- var _AbstractPage_client;
13
- import { VERSION } from "./version.mjs";
14
- import { MixedbreadError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, } from "./error.mjs";
15
- import { kind as shimsKind, getDefaultAgent, fetch, init, } from "./_shims/index.mjs";
16
- // try running side effects outside of _shims/index to workaround https://github.com/vercel/next.js/issues/76881
17
- init();
18
- import { isBlobLike, isMultipartBody } from "./uploads.mjs";
19
- export { maybeMultipartFormRequestOptions, multipartFormRequestOptions, createForm, } from "./uploads.mjs";
20
- async function defaultParseResponse(props) {
21
- const { response } = props;
22
- // fetch refuses to read the body when the status code is 204.
23
- if (response.status === 204) {
24
- return null;
25
- }
26
- if (props.options.__binaryResponse) {
27
- return response;
28
- }
29
- const contentType = response.headers.get('content-type');
30
- const mediaType = contentType?.split(';')[0]?.trim();
31
- const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
32
- if (isJSON) {
33
- const json = await response.json();
34
- debug('response', response.status, response.url, response.headers, json);
35
- return json;
36
- }
37
- const text = await response.text();
38
- debug('response', response.status, response.url, response.headers, text);
39
- // TODO handle blob, arraybuffer, other content types, etc.
40
- return text;
41
- }
42
- /**
43
- * A subclass of `Promise` providing additional helper methods
44
- * for interacting with the SDK.
45
- */
46
- export class APIPromise extends Promise {
47
- constructor(responsePromise, parseResponse = defaultParseResponse) {
48
- super((resolve) => {
49
- // this is maybe a bit weird but this has to be a no-op to not implicitly
50
- // parse the response body; instead .then, .catch, .finally are overridden
51
- // to parse the response
52
- resolve(null);
53
- });
54
- this.responsePromise = responsePromise;
55
- this.parseResponse = parseResponse;
56
- }
57
- _thenUnwrap(transform) {
58
- return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props), props));
59
- }
60
- /**
61
- * Gets the raw `Response` instance instead of parsing the response
62
- * data.
63
- *
64
- * If you want to parse the response body but still get the `Response`
65
- * instance, you can use {@link withResponse()}.
66
- *
67
- * 👋 Getting the wrong TypeScript type for `Response`?
68
- * Try setting `"moduleResolution": "NodeNext"` if you can,
69
- * or add one of these imports before your first `import … from '@mixedbread/sdk'`:
70
- * - `import '@mixedbread/sdk/shims/node'` (if you're running on Node)
71
- * - `import '@mixedbread/sdk/shims/web'` (otherwise)
72
- */
73
- asResponse() {
74
- return this.responsePromise.then((p) => p.response);
75
- }
76
- /**
77
- * Gets the parsed response data and the raw `Response` instance.
78
- *
79
- * If you just want to get the raw `Response` instance without parsing it,
80
- * you can use {@link asResponse()}.
81
- *
82
- *
83
- * 👋 Getting the wrong TypeScript type for `Response`?
84
- * Try setting `"moduleResolution": "NodeNext"` if you can,
85
- * or add one of these imports before your first `import … from '@mixedbread/sdk'`:
86
- * - `import '@mixedbread/sdk/shims/node'` (if you're running on Node)
87
- * - `import '@mixedbread/sdk/shims/web'` (otherwise)
88
- */
89
- async withResponse() {
90
- const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
91
- return { data, response };
92
- }
93
- parse() {
94
- if (!this.parsedPromise) {
95
- this.parsedPromise = this.responsePromise.then(this.parseResponse);
96
- }
97
- return this.parsedPromise;
98
- }
99
- then(onfulfilled, onrejected) {
100
- return this.parse().then(onfulfilled, onrejected);
101
- }
102
- catch(onrejected) {
103
- return this.parse().catch(onrejected);
104
- }
105
- finally(onfinally) {
106
- return this.parse().finally(onfinally);
107
- }
108
- }
109
- export class APIClient {
110
- constructor({ baseURL, maxRetries = 2, timeout = 60000, // 1 minute
111
- httpAgent, fetch: overriddenFetch, }) {
112
- this.baseURL = baseURL;
113
- this.maxRetries = validatePositiveInteger('maxRetries', maxRetries);
114
- this.timeout = validatePositiveInteger('timeout', timeout);
115
- this.httpAgent = httpAgent;
116
- this.fetch = overriddenFetch ?? fetch;
117
- }
118
- authHeaders(opts) {
119
- return {};
120
- }
121
- /**
122
- * Override this to add your own default headers, for example:
123
- *
124
- * {
125
- * ...super.defaultHeaders(),
126
- * Authorization: 'Bearer 123',
127
- * }
128
- */
129
- defaultHeaders(opts) {
130
- return {
131
- Accept: 'application/json',
132
- 'Content-Type': 'application/json',
133
- 'User-Agent': this.getUserAgent(),
134
- ...getPlatformHeaders(),
135
- ...this.authHeaders(opts),
136
- };
137
- }
138
- /**
139
- * Override this to add your own headers validation:
140
- */
141
- validateHeaders(headers, customHeaders) { }
142
- defaultIdempotencyKey() {
143
- return `stainless-node-retry-${uuid4()}`;
144
- }
145
- get(path, opts) {
146
- return this.methodRequest('get', path, opts);
147
- }
148
- post(path, opts) {
149
- return this.methodRequest('post', path, opts);
150
- }
151
- patch(path, opts) {
152
- return this.methodRequest('patch', path, opts);
153
- }
154
- put(path, opts) {
155
- return this.methodRequest('put', path, opts);
156
- }
157
- delete(path, opts) {
158
- return this.methodRequest('delete', path, opts);
159
- }
160
- methodRequest(method, path, opts) {
161
- return this.request(Promise.resolve(opts).then(async (opts) => {
162
- const body = opts && isBlobLike(opts?.body) ? new DataView(await opts.body.arrayBuffer())
163
- : opts?.body instanceof DataView ? opts.body
164
- : opts?.body instanceof ArrayBuffer ? new DataView(opts.body)
165
- : opts && ArrayBuffer.isView(opts?.body) ? new DataView(opts.body.buffer)
166
- : opts?.body;
167
- return { method, path, ...opts, body };
168
- }));
169
- }
170
- getAPIList(path, Page, opts) {
171
- return this.requestAPIList(Page, { method: 'get', path, ...opts });
172
- }
173
- calculateContentLength(body) {
174
- if (typeof body === 'string') {
175
- if (typeof Buffer !== 'undefined') {
176
- return Buffer.byteLength(body, 'utf8').toString();
177
- }
178
- if (typeof TextEncoder !== 'undefined') {
179
- const encoder = new TextEncoder();
180
- const encoded = encoder.encode(body);
181
- return encoded.length.toString();
182
- }
183
- }
184
- else if (ArrayBuffer.isView(body)) {
185
- return body.byteLength.toString();
186
- }
187
- return null;
188
- }
189
- buildRequest(options, { retryCount = 0 } = {}) {
190
- options = { ...options };
191
- const { method, path, query, headers: headers = {} } = options;
192
- const body = ArrayBuffer.isView(options.body) || (options.__binaryRequest && typeof options.body === 'string') ?
193
- options.body
194
- : isMultipartBody(options.body) ? options.body.body
195
- : options.body ? JSON.stringify(options.body, null, 2)
196
- : null;
197
- const contentLength = this.calculateContentLength(body);
198
- const url = this.buildURL(path, query);
199
- if ('timeout' in options)
200
- validatePositiveInteger('timeout', options.timeout);
201
- options.timeout = options.timeout ?? this.timeout;
202
- const httpAgent = options.httpAgent ?? this.httpAgent ?? getDefaultAgent(url);
203
- const minAgentTimeout = options.timeout + 1000;
204
- if (typeof httpAgent?.options?.timeout === 'number' &&
205
- minAgentTimeout > (httpAgent.options.timeout ?? 0)) {
206
- // Allow any given request to bump our agent active socket timeout.
207
- // This may seem strange, but leaking active sockets should be rare and not particularly problematic,
208
- // and without mutating agent we would need to create more of them.
209
- // This tradeoff optimizes for performance.
210
- httpAgent.options.timeout = minAgentTimeout;
211
- }
212
- if (this.idempotencyHeader && method !== 'get') {
213
- if (!options.idempotencyKey)
214
- options.idempotencyKey = this.defaultIdempotencyKey();
215
- headers[this.idempotencyHeader] = options.idempotencyKey;
216
- }
217
- const reqHeaders = this.buildHeaders({ options, headers, contentLength, retryCount });
218
- const req = {
219
- method,
220
- ...(body && { body: body }),
221
- headers: reqHeaders,
222
- ...(httpAgent && { agent: httpAgent }),
223
- // @ts-ignore node-fetch uses a custom AbortSignal type that is
224
- // not compatible with standard web types
225
- signal: options.signal ?? null,
226
- };
227
- return { req, url, timeout: options.timeout };
228
- }
229
- buildHeaders({ options, headers, contentLength, retryCount, }) {
230
- const reqHeaders = {};
231
- if (contentLength) {
232
- reqHeaders['content-length'] = contentLength;
233
- }
234
- const defaultHeaders = this.defaultHeaders(options);
235
- applyHeadersMut(reqHeaders, defaultHeaders);
236
- applyHeadersMut(reqHeaders, headers);
237
- // let builtin fetch set the Content-Type for multipart bodies
238
- if (isMultipartBody(options.body) && shimsKind !== 'node') {
239
- delete reqHeaders['content-type'];
240
- }
241
- // Don't set theses headers if they were already set or removed through default headers or by the caller.
242
- // We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to account
243
- // for the removal case.
244
- if (getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
245
- getHeader(headers, 'x-stainless-retry-count') === undefined) {
246
- reqHeaders['x-stainless-retry-count'] = String(retryCount);
247
- }
248
- if (getHeader(defaultHeaders, 'x-stainless-timeout') === undefined &&
249
- getHeader(headers, 'x-stainless-timeout') === undefined &&
250
- options.timeout) {
251
- reqHeaders['x-stainless-timeout'] = String(Math.trunc(options.timeout / 1000));
252
- }
253
- this.validateHeaders(reqHeaders, headers);
254
- return reqHeaders;
255
- }
256
- /**
257
- * Used as a callback for mutating the given `FinalRequestOptions` object.
258
- */
259
- async prepareOptions(options) { }
260
- /**
261
- * Used as a callback for mutating the given `RequestInit` object.
262
- *
263
- * This is useful for cases where you want to add certain headers based off of
264
- * the request properties, e.g. `method` or `url`.
265
- */
266
- async prepareRequest(request, { url, options }) { }
267
- parseHeaders(headers) {
268
- return (!headers ? {}
269
- : Symbol.iterator in headers ?
270
- Object.fromEntries(Array.from(headers).map((header) => [...header]))
271
- : { ...headers });
272
- }
273
- makeStatusError(status, error, message, headers) {
274
- return APIError.generate(status, error, message, headers);
275
- }
276
- request(options, remainingRetries = null) {
277
- return new APIPromise(this.makeRequest(options, remainingRetries));
278
- }
279
- async makeRequest(optionsInput, retriesRemaining) {
280
- const options = await optionsInput;
281
- const maxRetries = options.maxRetries ?? this.maxRetries;
282
- if (retriesRemaining == null) {
283
- retriesRemaining = maxRetries;
284
- }
285
- await this.prepareOptions(options);
286
- const { req, url, timeout } = this.buildRequest(options, { retryCount: maxRetries - retriesRemaining });
287
- await this.prepareRequest(req, { url, options });
288
- debug('request', url, options, req.headers);
289
- if (options.signal?.aborted) {
290
- throw new APIUserAbortError();
291
- }
292
- const controller = new AbortController();
293
- const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
294
- if (response instanceof Error) {
295
- if (options.signal?.aborted) {
296
- throw new APIUserAbortError();
297
- }
298
- if (retriesRemaining) {
299
- return this.retryRequest(options, retriesRemaining);
300
- }
301
- if (response.name === 'AbortError') {
302
- throw new APIConnectionTimeoutError();
303
- }
304
- throw new APIConnectionError({ cause: response });
305
- }
306
- const responseHeaders = createResponseHeaders(response.headers);
307
- if (!response.ok) {
308
- if (retriesRemaining && this.shouldRetry(response)) {
309
- const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
310
- debug(`response (error; ${retryMessage})`, response.status, url, responseHeaders);
311
- return this.retryRequest(options, retriesRemaining, responseHeaders);
312
- }
313
- const errText = await response.text().catch((e) => castToError(e).message);
314
- const errJSON = safeJSON(errText);
315
- const errMessage = errJSON ? undefined : errText;
316
- const retryMessage = retriesRemaining ? `(error; no more retries left)` : `(error; not retryable)`;
317
- debug(`response (error; ${retryMessage})`, response.status, url, responseHeaders, errMessage);
318
- const err = this.makeStatusError(response.status, errJSON, errMessage, responseHeaders);
319
- throw err;
320
- }
321
- return { response, options, controller };
322
- }
323
- requestAPIList(Page, options) {
324
- const request = this.makeRequest(options, null);
325
- return new PagePromise(this, request, Page);
326
- }
327
- buildURL(path, query) {
328
- const url = isAbsoluteURL(path) ?
329
- new URL(path)
330
- : new URL(this.baseURL + (this.baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
331
- const defaultQuery = this.defaultQuery();
332
- if (!isEmptyObj(defaultQuery)) {
333
- query = { ...defaultQuery, ...query };
334
- }
335
- if (typeof query === 'object' && query && !Array.isArray(query)) {
336
- url.search = this.stringifyQuery(query);
337
- }
338
- return url.toString();
339
- }
340
- stringifyQuery(query) {
341
- return Object.entries(query)
342
- .filter(([_, value]) => typeof value !== 'undefined')
343
- .map(([key, value]) => {
344
- if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
345
- return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
346
- }
347
- if (value === null) {
348
- return `${encodeURIComponent(key)}=`;
349
- }
350
- throw new MixedbreadError(`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.`);
351
- })
352
- .join('&');
353
- }
354
- async fetchWithTimeout(url, init, ms, controller) {
355
- const { signal, ...options } = init || {};
356
- if (signal)
357
- signal.addEventListener('abort', () => controller.abort());
358
- const timeout = setTimeout(() => controller.abort(), ms);
359
- const fetchOptions = {
360
- signal: controller.signal,
361
- ...options,
362
- };
363
- if (fetchOptions.method) {
364
- // Custom methods like 'patch' need to be uppercased
365
- // See https://github.com/nodejs/undici/issues/2294
366
- fetchOptions.method = fetchOptions.method.toUpperCase();
367
- }
368
- return (
369
- // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
370
- this.fetch.call(undefined, url, fetchOptions).finally(() => {
371
- clearTimeout(timeout);
372
- }));
373
- }
374
- shouldRetry(response) {
375
- // Note this is not a standard header.
376
- const shouldRetryHeader = response.headers.get('x-should-retry');
377
- // If the server explicitly says whether or not to retry, obey.
378
- if (shouldRetryHeader === 'true')
379
- return true;
380
- if (shouldRetryHeader === 'false')
381
- return false;
382
- // Retry on request timeouts.
383
- if (response.status === 408)
384
- return true;
385
- // Retry on lock timeouts.
386
- if (response.status === 409)
387
- return true;
388
- // Retry on rate limits.
389
- if (response.status === 429)
390
- return true;
391
- // Retry internal errors.
392
- if (response.status >= 500)
393
- return true;
394
- return false;
395
- }
396
- async retryRequest(options, retriesRemaining, responseHeaders) {
397
- let timeoutMillis;
398
- // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
399
- const retryAfterMillisHeader = responseHeaders?.['retry-after-ms'];
400
- if (retryAfterMillisHeader) {
401
- const timeoutMs = parseFloat(retryAfterMillisHeader);
402
- if (!Number.isNaN(timeoutMs)) {
403
- timeoutMillis = timeoutMs;
404
- }
405
- }
406
- // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
407
- const retryAfterHeader = responseHeaders?.['retry-after'];
408
- if (retryAfterHeader && !timeoutMillis) {
409
- const timeoutSeconds = parseFloat(retryAfterHeader);
410
- if (!Number.isNaN(timeoutSeconds)) {
411
- timeoutMillis = timeoutSeconds * 1000;
412
- }
413
- else {
414
- timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
415
- }
416
- }
417
- // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
418
- // just do what it says, but otherwise calculate a default
419
- if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
420
- const maxRetries = options.maxRetries ?? this.maxRetries;
421
- timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
422
- }
423
- await sleep(timeoutMillis);
424
- return this.makeRequest(options, retriesRemaining - 1);
425
- }
426
- calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries) {
427
- const initialRetryDelay = 0.5;
428
- const maxRetryDelay = 8.0;
429
- const numRetries = maxRetries - retriesRemaining;
430
- // Apply exponential backoff, but not more than the max.
431
- const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
432
- // Apply some jitter, take up to at most 25 percent of the retry time.
433
- const jitter = 1 - Math.random() * 0.25;
434
- return sleepSeconds * jitter * 1000;
435
- }
436
- getUserAgent() {
437
- return `${this.constructor.name}/JS ${VERSION}`;
438
- }
439
- }
440
- export class AbstractPage {
441
- constructor(client, response, body, options) {
442
- _AbstractPage_client.set(this, void 0);
443
- __classPrivateFieldSet(this, _AbstractPage_client, client, "f");
444
- this.options = options;
445
- this.response = response;
446
- this.body = body;
447
- }
448
- hasNextPage() {
449
- const items = this.getPaginatedItems();
450
- if (!items.length)
451
- return false;
452
- return this.nextPageInfo() != null;
453
- }
454
- async getNextPage() {
455
- const nextInfo = this.nextPageInfo();
456
- if (!nextInfo) {
457
- throw new MixedbreadError('No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.');
458
- }
459
- const nextOptions = { ...this.options };
460
- if ('params' in nextInfo && typeof nextOptions.query === 'object') {
461
- nextOptions.query = { ...nextOptions.query, ...nextInfo.params };
462
- }
463
- else if ('url' in nextInfo) {
464
- const params = [...Object.entries(nextOptions.query || {}), ...nextInfo.url.searchParams.entries()];
465
- for (const [key, value] of params) {
466
- nextInfo.url.searchParams.set(key, value);
467
- }
468
- nextOptions.query = undefined;
469
- nextOptions.path = nextInfo.url.toString();
470
- }
471
- return await __classPrivateFieldGet(this, _AbstractPage_client, "f").requestAPIList(this.constructor, nextOptions);
472
- }
473
- async *iterPages() {
474
- // eslint-disable-next-line @typescript-eslint/no-this-alias
475
- let page = this;
476
- yield page;
477
- while (page.hasNextPage()) {
478
- page = await page.getNextPage();
479
- yield page;
480
- }
481
- }
482
- async *[(_AbstractPage_client = new WeakMap(), Symbol.asyncIterator)]() {
483
- for await (const page of this.iterPages()) {
484
- for (const item of page.getPaginatedItems()) {
485
- yield item;
486
- }
487
- }
488
- }
489
- }
490
- /**
491
- * This subclass of Promise will resolve to an instantiated Page once the request completes.
492
- *
493
- * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
494
- *
495
- * for await (const item of client.items.list()) {
496
- * console.log(item)
497
- * }
498
- */
499
- export class PagePromise extends APIPromise {
500
- constructor(client, request, Page) {
501
- super(request, async (props) => new Page(client, props.response, await defaultParseResponse(props), props.options));
502
- }
503
- /**
504
- * Allow auto-paginating iteration on an unawaited list call, eg:
505
- *
506
- * for await (const item of client.items.list()) {
507
- * console.log(item)
508
- * }
509
- */
510
- async *[Symbol.asyncIterator]() {
511
- const page = await this;
512
- for await (const item of page) {
513
- yield item;
514
- }
515
- }
516
- }
517
- export const createResponseHeaders = (headers) => {
518
- return new Proxy(Object.fromEntries(
519
- // @ts-ignore
520
- headers.entries()), {
521
- get(target, name) {
522
- const key = name.toString();
523
- return target[key.toLowerCase()] || target[key];
524
- },
525
- });
526
- };
527
- // This is required so that we can determine if a given object matches the RequestOptions
528
- // type at runtime. While this requires duplication, it is enforced by the TypeScript
529
- // compiler such that any missing / extraneous keys will cause an error.
530
- const requestOptionsKeys = {
531
- method: true,
532
- path: true,
533
- query: true,
534
- body: true,
535
- headers: true,
536
- maxRetries: true,
537
- stream: true,
538
- timeout: true,
539
- httpAgent: true,
540
- signal: true,
541
- idempotencyKey: true,
542
- __binaryRequest: true,
543
- __binaryResponse: true,
544
- };
545
- export const isRequestOptions = (obj) => {
546
- return (typeof obj === 'object' &&
547
- obj !== null &&
548
- !isEmptyObj(obj) &&
549
- Object.keys(obj).every((k) => hasOwn(requestOptionsKeys, k)));
550
- };
551
- const getPlatformProperties = () => {
552
- if (typeof Deno !== 'undefined' && Deno.build != null) {
553
- return {
554
- 'X-Stainless-Lang': 'js',
555
- 'X-Stainless-Package-Version': VERSION,
556
- 'X-Stainless-OS': normalizePlatform(Deno.build.os),
557
- 'X-Stainless-Arch': normalizeArch(Deno.build.arch),
558
- 'X-Stainless-Runtime': 'deno',
559
- 'X-Stainless-Runtime-Version': typeof Deno.version === 'string' ? Deno.version : Deno.version?.deno ?? 'unknown',
560
- };
561
- }
562
- if (typeof EdgeRuntime !== 'undefined') {
563
- return {
564
- 'X-Stainless-Lang': 'js',
565
- 'X-Stainless-Package-Version': VERSION,
566
- 'X-Stainless-OS': 'Unknown',
567
- 'X-Stainless-Arch': `other:${EdgeRuntime}`,
568
- 'X-Stainless-Runtime': 'edge',
569
- 'X-Stainless-Runtime-Version': process.version,
570
- };
571
- }
572
- // Check if Node.js
573
- if (Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]') {
574
- return {
575
- 'X-Stainless-Lang': 'js',
576
- 'X-Stainless-Package-Version': VERSION,
577
- 'X-Stainless-OS': normalizePlatform(process.platform),
578
- 'X-Stainless-Arch': normalizeArch(process.arch),
579
- 'X-Stainless-Runtime': 'node',
580
- 'X-Stainless-Runtime-Version': process.version,
581
- };
582
- }
583
- const browserInfo = getBrowserInfo();
584
- if (browserInfo) {
585
- return {
586
- 'X-Stainless-Lang': 'js',
587
- 'X-Stainless-Package-Version': VERSION,
588
- 'X-Stainless-OS': 'Unknown',
589
- 'X-Stainless-Arch': 'unknown',
590
- 'X-Stainless-Runtime': `browser:${browserInfo.browser}`,
591
- 'X-Stainless-Runtime-Version': browserInfo.version,
592
- };
593
- }
594
- // TODO add support for Cloudflare workers, etc.
595
- return {
596
- 'X-Stainless-Lang': 'js',
597
- 'X-Stainless-Package-Version': VERSION,
598
- 'X-Stainless-OS': 'Unknown',
599
- 'X-Stainless-Arch': 'unknown',
600
- 'X-Stainless-Runtime': 'unknown',
601
- 'X-Stainless-Runtime-Version': 'unknown',
602
- };
603
- };
604
- // Note: modified from https://github.com/JS-DevTools/host-environment/blob/b1ab79ecde37db5d6e163c050e54fe7d287d7c92/src/isomorphic.browser.ts
605
- function getBrowserInfo() {
606
- if (typeof navigator === 'undefined' || !navigator) {
607
- return null;
608
- }
609
- // NOTE: The order matters here!
610
- const browserPatterns = [
611
- { key: 'edge', pattern: /Edge(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
612
- { key: 'ie', pattern: /MSIE(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
613
- { key: 'ie', pattern: /Trident(?:.*rv\:(\d+)\.(\d+)(?:\.(\d+))?)?/ },
614
- { key: 'chrome', pattern: /Chrome(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
615
- { key: 'firefox', pattern: /Firefox(?:\W+(\d+)\.(\d+)(?:\.(\d+))?)?/ },
616
- { key: 'safari', pattern: /(?:Version\W+(\d+)\.(\d+)(?:\.(\d+))?)?(?:\W+Mobile\S*)?\W+Safari/ },
617
- ];
618
- // Find the FIRST matching browser
619
- for (const { key, pattern } of browserPatterns) {
620
- const match = pattern.exec(navigator.userAgent);
621
- if (match) {
622
- const major = match[1] || 0;
623
- const minor = match[2] || 0;
624
- const patch = match[3] || 0;
625
- return { browser: key, version: `${major}.${minor}.${patch}` };
626
- }
627
- }
628
- return null;
629
- }
630
- const normalizeArch = (arch) => {
631
- // Node docs:
632
- // - https://nodejs.org/api/process.html#processarch
633
- // Deno docs:
634
- // - https://doc.deno.land/deno/stable/~/Deno.build
635
- if (arch === 'x32')
636
- return 'x32';
637
- if (arch === 'x86_64' || arch === 'x64')
638
- return 'x64';
639
- if (arch === 'arm')
640
- return 'arm';
641
- if (arch === 'aarch64' || arch === 'arm64')
642
- return 'arm64';
643
- if (arch)
644
- return `other:${arch}`;
645
- return 'unknown';
646
- };
647
- const normalizePlatform = (platform) => {
648
- // Node platforms:
649
- // - https://nodejs.org/api/process.html#processplatform
650
- // Deno platforms:
651
- // - https://doc.deno.land/deno/stable/~/Deno.build
652
- // - https://github.com/denoland/deno/issues/14799
653
- platform = platform.toLowerCase();
654
- // NOTE: this iOS check is untested and may not work
655
- // Node does not work natively on IOS, there is a fork at
656
- // https://github.com/nodejs-mobile/nodejs-mobile
657
- // however it is unknown at the time of writing how to detect if it is running
658
- if (platform.includes('ios'))
659
- return 'iOS';
660
- if (platform === 'android')
661
- return 'Android';
662
- if (platform === 'darwin')
663
- return 'MacOS';
664
- if (platform === 'win32')
665
- return 'Windows';
666
- if (platform === 'freebsd')
667
- return 'FreeBSD';
668
- if (platform === 'openbsd')
669
- return 'OpenBSD';
670
- if (platform === 'linux')
671
- return 'Linux';
672
- if (platform)
673
- return `Other:${platform}`;
674
- return 'Unknown';
675
- };
676
- let _platformHeaders;
677
- const getPlatformHeaders = () => {
678
- return (_platformHeaders ?? (_platformHeaders = getPlatformProperties()));
679
- };
680
- export const safeJSON = (text) => {
681
- try {
682
- return JSON.parse(text);
683
- }
684
- catch (err) {
685
- return undefined;
686
- }
687
- };
688
- // https://url.spec.whatwg.org/#url-scheme-string
689
- const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
690
- const isAbsoluteURL = (url) => {
691
- return startsWithSchemeRegexp.test(url);
692
- };
693
- export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
694
- const validatePositiveInteger = (name, n) => {
695
- if (typeof n !== 'number' || !Number.isInteger(n)) {
696
- throw new MixedbreadError(`${name} must be an integer`);
697
- }
698
- if (n < 0) {
699
- throw new MixedbreadError(`${name} must be a positive integer`);
700
- }
701
- return n;
702
- };
703
- export const castToError = (err) => {
704
- if (err instanceof Error)
705
- return err;
706
- if (typeof err === 'object' && err !== null) {
707
- try {
708
- return new Error(JSON.stringify(err));
709
- }
710
- catch { }
711
- }
712
- return new Error(err);
713
- };
714
- export const ensurePresent = (value) => {
715
- if (value == null)
716
- throw new MixedbreadError(`Expected a value to be given but received ${value} instead.`);
717
- return value;
718
- };
719
- /**
720
- * Read an environment variable.
721
- *
722
- * Trims beginning and trailing whitespace.
723
- *
724
- * Will return undefined if the environment variable doesn't exist or cannot be accessed.
725
- */
726
- export const readEnv = (env) => {
727
- if (typeof process !== 'undefined') {
728
- return process.env?.[env]?.trim() ?? undefined;
729
- }
730
- if (typeof Deno !== 'undefined') {
731
- return Deno.env?.get?.(env)?.trim();
732
- }
733
- return undefined;
734
- };
735
- export const coerceInteger = (value) => {
736
- if (typeof value === 'number')
737
- return Math.round(value);
738
- if (typeof value === 'string')
739
- return parseInt(value, 10);
740
- throw new MixedbreadError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
741
- };
742
- export const coerceFloat = (value) => {
743
- if (typeof value === 'number')
744
- return value;
745
- if (typeof value === 'string')
746
- return parseFloat(value);
747
- throw new MixedbreadError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
748
- };
749
- export const coerceBoolean = (value) => {
750
- if (typeof value === 'boolean')
751
- return value;
752
- if (typeof value === 'string')
753
- return value === 'true';
754
- return Boolean(value);
755
- };
756
- export const maybeCoerceInteger = (value) => {
757
- if (value === undefined) {
758
- return undefined;
759
- }
760
- return coerceInteger(value);
761
- };
762
- export const maybeCoerceFloat = (value) => {
763
- if (value === undefined) {
764
- return undefined;
765
- }
766
- return coerceFloat(value);
767
- };
768
- export const maybeCoerceBoolean = (value) => {
769
- if (value === undefined) {
770
- return undefined;
771
- }
772
- return coerceBoolean(value);
773
- };
774
- // https://stackoverflow.com/a/34491287
775
- export function isEmptyObj(obj) {
776
- if (!obj)
777
- return true;
778
- for (const _k in obj)
779
- return false;
780
- return true;
781
- }
782
- // https://eslint.org/docs/latest/rules/no-prototype-builtins
783
- export function hasOwn(obj, key) {
784
- return Object.prototype.hasOwnProperty.call(obj, key);
785
- }
786
- /**
787
- * Copies headers from "newHeaders" onto "targetHeaders",
788
- * using lower-case for all properties,
789
- * ignoring any keys with undefined values,
790
- * and deleting any keys with null values.
791
- */
792
- function applyHeadersMut(targetHeaders, newHeaders) {
793
- for (const k in newHeaders) {
794
- if (!hasOwn(newHeaders, k))
795
- continue;
796
- const lowerKey = k.toLowerCase();
797
- if (!lowerKey)
798
- continue;
799
- const val = newHeaders[k];
800
- if (val === null) {
801
- delete targetHeaders[lowerKey];
802
- }
803
- else if (val !== undefined) {
804
- targetHeaders[lowerKey] = val;
805
- }
806
- }
807
- }
808
- export function debug(action, ...args) {
809
- if (typeof process !== 'undefined' && process?.env?.['DEBUG'] === 'true') {
810
- console.log(`Mixedbread:DEBUG:${action}`, ...args);
811
- }
812
- }
813
- /**
814
- * https://stackoverflow.com/a/2117523
815
- */
816
- const uuid4 = () => {
817
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
818
- const r = (Math.random() * 16) | 0;
819
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
820
- return v.toString(16);
821
- });
822
- };
823
- export const isRunningInBrowser = () => {
824
- return (
825
- // @ts-ignore
826
- typeof window !== 'undefined' &&
827
- // @ts-ignore
828
- typeof window.document !== 'undefined' &&
829
- // @ts-ignore
830
- typeof navigator !== 'undefined');
831
- };
832
- export const isHeadersProtocol = (headers) => {
833
- return typeof headers?.get === 'function';
834
- };
835
- export const getRequiredHeader = (headers, header) => {
836
- const foundHeader = getHeader(headers, header);
837
- if (foundHeader === undefined) {
838
- throw new Error(`Could not find ${header} header`);
839
- }
840
- return foundHeader;
841
- };
842
- export const getHeader = (headers, header) => {
843
- const lowerCasedHeader = header.toLowerCase();
844
- if (isHeadersProtocol(headers)) {
845
- // to deal with the case where the header looks like Stainless-Event-Id
846
- const intercapsHeader = header[0]?.toUpperCase() +
847
- header.substring(1).replace(/([^\w])(\w)/g, (_m, g1, g2) => g1 + g2.toUpperCase());
848
- for (const key of [header, lowerCasedHeader, header.toUpperCase(), intercapsHeader]) {
849
- const value = headers.get(key);
850
- if (value) {
851
- return value;
852
- }
853
- }
854
- }
855
- for (const [key, value] of Object.entries(headers)) {
856
- if (key.toLowerCase() === lowerCasedHeader) {
857
- if (Array.isArray(value)) {
858
- if (value.length <= 1)
859
- return value[0];
860
- console.warn(`Received ${value.length} entries for the ${header} header, using the first entry.`);
861
- return value[0];
862
- }
863
- return value;
864
- }
865
- }
866
- return undefined;
867
- };
868
- /**
869
- * Encodes a string to Base64 format.
870
- */
871
- export const toBase64 = (str) => {
872
- if (!str)
873
- return '';
874
- if (typeof Buffer !== 'undefined') {
875
- return Buffer.from(str).toString('base64');
876
- }
877
- if (typeof btoa !== 'undefined') {
878
- return btoa(str);
879
- }
880
- throw new MixedbreadError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
881
- };
882
- export function isObj(obj) {
883
- return obj != null && typeof obj === 'object' && !Array.isArray(obj);
884
- }
885
- //# sourceMappingURL=core.mjs.map