@mixedbread/sdk 0.4.0 → 0.6.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 (357) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +2 -2
  3. package/api-promise.js +2 -15
  4. package/api-promise.js.map +1 -1
  5. package/bin/cli +52 -0
  6. package/bin/migration-config.json +176 -0
  7. package/client.d.mts +20 -8
  8. package/client.d.mts.map +1 -1
  9. package/client.d.ts +20 -8
  10. package/client.d.ts.map +1 -1
  11. package/client.js +45 -50
  12. package/client.js.map +1 -1
  13. package/client.mjs +37 -19
  14. package/client.mjs.map +1 -1
  15. package/core/api-promise.d.mts +0 -1
  16. package/core/api-promise.d.mts.map +1 -1
  17. package/core/api-promise.d.ts +0 -1
  18. package/core/api-promise.d.ts.map +1 -1
  19. package/core/api-promise.js +4 -14
  20. package/core/api-promise.js.map +1 -1
  21. package/core/api-promise.mjs +1 -11
  22. package/core/api-promise.mjs.map +1 -1
  23. package/core/error.d.mts +0 -1
  24. package/core/error.d.mts.map +1 -1
  25. package/core/error.d.ts +0 -1
  26. package/core/error.d.ts.map +1 -1
  27. package/core/error.js.map +1 -1
  28. package/core/error.mjs.map +1 -1
  29. package/core/pagination.d.mts +0 -1
  30. package/core/pagination.d.mts.map +1 -1
  31. package/core/pagination.d.ts +0 -1
  32. package/core/pagination.d.ts.map +1 -1
  33. package/core/pagination.js +3 -13
  34. package/core/pagination.js.map +1 -1
  35. package/core/pagination.mjs +1 -11
  36. package/core/pagination.mjs.map +1 -1
  37. package/error.js +2 -15
  38. package/error.js.map +1 -1
  39. package/internal/builtin-types.d.mts +0 -2
  40. package/internal/builtin-types.d.mts.map +1 -1
  41. package/internal/builtin-types.d.ts +0 -2
  42. package/internal/builtin-types.d.ts.map +1 -1
  43. package/internal/detect-platform.js.map +1 -1
  44. package/internal/detect-platform.mjs.map +1 -1
  45. package/internal/errors.d.mts.map +1 -1
  46. package/internal/errors.d.ts.map +1 -1
  47. package/internal/errors.js +2 -2
  48. package/internal/errors.js.map +1 -1
  49. package/internal/errors.mjs.map +1 -1
  50. package/internal/headers.d.mts +1 -2
  51. package/internal/headers.d.mts.map +1 -1
  52. package/internal/headers.d.ts +1 -2
  53. package/internal/headers.d.ts.map +1 -1
  54. package/internal/headers.js +3 -1
  55. package/internal/headers.js.map +1 -1
  56. package/internal/headers.mjs +3 -1
  57. package/internal/headers.mjs.map +1 -1
  58. package/internal/parse.d.mts +0 -1
  59. package/internal/parse.d.mts.map +1 -1
  60. package/internal/parse.d.ts +0 -1
  61. package/internal/parse.d.ts.map +1 -1
  62. package/internal/parse.js +1 -2
  63. package/internal/parse.js.map +1 -1
  64. package/internal/parse.mjs.map +1 -1
  65. package/internal/request-options.d.mts +0 -1
  66. package/internal/request-options.d.mts.map +1 -1
  67. package/internal/request-options.d.ts +0 -1
  68. package/internal/request-options.d.ts.map +1 -1
  69. package/internal/shims.js +5 -6
  70. package/internal/shims.js.map +1 -1
  71. package/internal/shims.mjs.map +1 -1
  72. package/internal/to-file.d.mts +0 -1
  73. package/internal/to-file.d.mts.map +1 -1
  74. package/internal/to-file.d.ts +0 -1
  75. package/internal/to-file.d.ts.map +1 -1
  76. package/internal/to-file.js +4 -4
  77. package/internal/to-file.js.map +1 -1
  78. package/internal/to-file.mjs +3 -2
  79. package/internal/to-file.mjs.map +1 -1
  80. package/internal/tslib.js +81 -0
  81. package/internal/tslib.mjs +17 -0
  82. package/internal/types.d.mts +0 -1
  83. package/internal/types.d.mts.map +1 -1
  84. package/internal/types.d.ts +0 -1
  85. package/internal/types.d.ts.map +1 -1
  86. package/internal/uploads.d.mts +1 -3
  87. package/internal/uploads.d.mts.map +1 -1
  88. package/internal/uploads.d.ts +1 -3
  89. package/internal/uploads.d.ts.map +1 -1
  90. package/internal/uploads.js +16 -6
  91. package/internal/uploads.js.map +1 -1
  92. package/internal/uploads.mjs +12 -3
  93. package/internal/uploads.mjs.map +1 -1
  94. package/internal/utils/base64.d.mts.map +1 -1
  95. package/internal/utils/base64.d.ts.map +1 -1
  96. package/internal/utils/base64.js +12 -7
  97. package/internal/utils/base64.js.map +1 -1
  98. package/internal/utils/base64.mjs +12 -7
  99. package/internal/utils/base64.mjs.map +1 -1
  100. package/internal/utils/bytes.d.mts +4 -0
  101. package/internal/utils/bytes.d.mts.map +1 -0
  102. package/internal/utils/bytes.d.ts +4 -0
  103. package/internal/utils/bytes.d.ts.map +1 -0
  104. package/internal/utils/bytes.js +31 -0
  105. package/internal/utils/bytes.js.map +1 -0
  106. package/internal/utils/bytes.mjs +26 -0
  107. package/internal/utils/bytes.mjs.map +1 -0
  108. package/internal/utils/env.d.mts.map +1 -1
  109. package/internal/utils/env.d.ts.map +1 -1
  110. package/internal/utils/env.js.map +1 -1
  111. package/internal/utils/env.mjs.map +1 -1
  112. package/internal/utils/log.d.mts +0 -1
  113. package/internal/utils/log.d.mts.map +1 -1
  114. package/internal/utils/log.d.ts +0 -1
  115. package/internal/utils/log.d.ts.map +1 -1
  116. package/internal/utils/log.js +2 -2
  117. package/internal/utils/log.js.map +1 -1
  118. package/internal/utils/log.mjs.map +1 -1
  119. package/internal/utils/path.d.mts.map +1 -1
  120. package/internal/utils/path.d.ts.map +1 -1
  121. package/internal/utils/path.js +2 -2
  122. package/internal/utils/path.js.map +1 -1
  123. package/internal/utils/path.mjs.map +1 -1
  124. package/internal/utils/sleep.d.mts.map +1 -1
  125. package/internal/utils/sleep.d.ts.map +1 -1
  126. package/internal/utils/uuid.d.mts +1 -1
  127. package/internal/utils/uuid.d.mts.map +1 -1
  128. package/internal/utils/uuid.d.ts +1 -1
  129. package/internal/utils/uuid.d.ts.map +1 -1
  130. package/internal/utils/uuid.js +1 -2
  131. package/internal/utils/uuid.js.map +1 -1
  132. package/internal/utils/uuid.mjs +1 -2
  133. package/internal/utils/uuid.mjs.map +1 -1
  134. package/internal/utils/values.d.mts.map +1 -1
  135. package/internal/utils/values.d.ts.map +1 -1
  136. package/internal/utils/values.js +5 -5
  137. package/internal/utils/values.js.map +1 -1
  138. package/internal/utils/values.mjs.map +1 -1
  139. package/internal/utils.js +7 -20
  140. package/internal/utils.js.map +1 -1
  141. package/lib/polling.js +1 -2
  142. package/lib/polling.js.map +1 -1
  143. package/lib/polling.mjs.map +1 -1
  144. package/package.json +5 -6
  145. package/pagination.js +2 -15
  146. package/pagination.js.map +1 -1
  147. package/resource.js +2 -15
  148. package/resource.js.map +1 -1
  149. package/resources/api-keys.d.mts +171 -0
  150. package/resources/api-keys.d.mts.map +1 -0
  151. package/resources/api-keys.d.ts +171 -0
  152. package/resources/api-keys.d.ts.map +1 -0
  153. package/resources/api-keys.js +76 -0
  154. package/resources/api-keys.js.map +1 -0
  155. package/resources/api-keys.mjs +72 -0
  156. package/resources/api-keys.mjs.map +1 -0
  157. package/resources/chat.d.mts +27 -0
  158. package/resources/chat.d.mts.map +1 -0
  159. package/resources/chat.d.ts +27 -0
  160. package/resources/chat.d.ts.map +1 -0
  161. package/resources/chat.js +28 -0
  162. package/resources/chat.js.map +1 -0
  163. package/resources/chat.mjs +24 -0
  164. package/resources/chat.mjs.map +1 -0
  165. package/resources/data-sources/connectors.d.mts +193 -0
  166. package/resources/data-sources/connectors.d.mts.map +1 -0
  167. package/resources/data-sources/connectors.d.ts +193 -0
  168. package/resources/data-sources/connectors.d.ts.map +1 -0
  169. package/resources/data-sources/connectors.js +73 -0
  170. package/resources/data-sources/connectors.js.map +1 -0
  171. package/resources/data-sources/connectors.mjs +69 -0
  172. package/resources/data-sources/connectors.mjs.map +1 -0
  173. package/resources/data-sources/data-sources.d.mts +183 -0
  174. package/resources/data-sources/data-sources.d.mts.map +1 -0
  175. package/resources/data-sources/data-sources.d.ts +183 -0
  176. package/resources/data-sources/data-sources.d.ts.map +1 -0
  177. package/resources/data-sources/data-sources.js +66 -0
  178. package/resources/data-sources/data-sources.js.map +1 -0
  179. package/resources/data-sources/data-sources.mjs +61 -0
  180. package/resources/data-sources/data-sources.mjs.map +1 -0
  181. package/resources/data-sources/index.d.mts +3 -0
  182. package/resources/data-sources/index.d.mts.map +1 -0
  183. package/resources/data-sources/index.d.ts +3 -0
  184. package/resources/data-sources/index.d.ts.map +1 -0
  185. package/resources/data-sources/index.js +9 -0
  186. package/resources/data-sources/index.js.map +1 -0
  187. package/resources/data-sources/index.mjs +4 -0
  188. package/resources/data-sources/index.mjs.map +1 -0
  189. package/resources/data-sources.d.mts +2 -0
  190. package/resources/data-sources.d.mts.map +1 -0
  191. package/resources/data-sources.d.ts +2 -0
  192. package/resources/data-sources.d.ts.map +1 -0
  193. package/resources/data-sources.js +6 -0
  194. package/resources/data-sources.js.map +1 -0
  195. package/resources/data-sources.mjs +3 -0
  196. package/resources/data-sources.mjs.map +1 -0
  197. package/resources/embeddings.d.mts +7 -2
  198. package/resources/embeddings.d.mts.map +1 -1
  199. package/resources/embeddings.d.ts +7 -2
  200. package/resources/embeddings.d.ts.map +1 -1
  201. package/resources/extractions/content.d.mts +46 -2
  202. package/resources/extractions/content.d.mts.map +1 -1
  203. package/resources/extractions/content.d.ts +46 -2
  204. package/resources/extractions/content.d.ts.map +1 -1
  205. package/resources/extractions/extractions.d.mts +2 -2
  206. package/resources/extractions/extractions.d.mts.map +1 -1
  207. package/resources/extractions/extractions.d.ts +2 -2
  208. package/resources/extractions/extractions.d.ts.map +1 -1
  209. package/resources/extractions/extractions.js +4 -26
  210. package/resources/extractions/extractions.js.map +1 -1
  211. package/resources/extractions/extractions.mjs.map +1 -1
  212. package/resources/extractions/index.d.mts +1 -1
  213. package/resources/extractions/index.d.mts.map +1 -1
  214. package/resources/extractions/index.d.ts +1 -1
  215. package/resources/extractions/index.d.ts.map +1 -1
  216. package/resources/extractions/index.js.map +1 -1
  217. package/resources/extractions/index.mjs +1 -1
  218. package/resources/extractions/index.mjs.map +1 -1
  219. package/resources/extractions/jobs.d.mts +2 -1
  220. package/resources/extractions/jobs.d.mts.map +1 -1
  221. package/resources/extractions/jobs.d.ts +2 -1
  222. package/resources/extractions/jobs.d.ts.map +1 -1
  223. package/resources/extractions/jobs.js.map +1 -1
  224. package/resources/extractions/jobs.mjs.map +1 -1
  225. package/resources/extractions.js +2 -15
  226. package/resources/extractions.js.map +1 -1
  227. package/resources/files.d.mts +18 -2
  228. package/resources/files.d.mts.map +1 -1
  229. package/resources/files.d.ts +18 -2
  230. package/resources/files.d.ts.map +1 -1
  231. package/resources/index.d.mts +6 -3
  232. package/resources/index.d.mts.map +1 -1
  233. package/resources/index.d.ts +6 -3
  234. package/resources/index.d.ts.map +1 -1
  235. package/resources/index.js +9 -16
  236. package/resources/index.js.map +1 -1
  237. package/resources/index.mjs +3 -0
  238. package/resources/index.mjs.map +1 -1
  239. package/resources/parsing/index.d.mts +1 -1
  240. package/resources/parsing/index.d.mts.map +1 -1
  241. package/resources/parsing/index.d.ts +1 -1
  242. package/resources/parsing/index.d.ts.map +1 -1
  243. package/resources/parsing/index.js.map +1 -1
  244. package/resources/parsing/index.mjs.map +1 -1
  245. package/resources/parsing/jobs.d.mts +29 -11
  246. package/resources/parsing/jobs.d.mts.map +1 -1
  247. package/resources/parsing/jobs.d.ts +29 -11
  248. package/resources/parsing/jobs.d.ts.map +1 -1
  249. package/resources/parsing/jobs.js +2 -24
  250. package/resources/parsing/jobs.js.map +1 -1
  251. package/resources/parsing/jobs.mjs.map +1 -1
  252. package/resources/parsing/parsing.d.mts +2 -2
  253. package/resources/parsing/parsing.d.mts.map +1 -1
  254. package/resources/parsing/parsing.d.ts +2 -2
  255. package/resources/parsing/parsing.d.ts.map +1 -1
  256. package/resources/parsing/parsing.js +2 -24
  257. package/resources/parsing/parsing.js.map +1 -1
  258. package/resources/parsing/parsing.mjs.map +1 -1
  259. package/resources/parsing.js +2 -15
  260. package/resources/parsing.js.map +1 -1
  261. package/resources/top-level.d.mts +9 -4
  262. package/resources/top-level.d.mts.map +1 -1
  263. package/resources/top-level.d.ts +9 -4
  264. package/resources/top-level.d.ts.map +1 -1
  265. package/resources/vector-stores/files.d.mts +29 -2
  266. package/resources/vector-stores/files.d.mts.map +1 -1
  267. package/resources/vector-stores/files.d.ts +29 -2
  268. package/resources/vector-stores/files.d.ts.map +1 -1
  269. package/resources/vector-stores/files.js +2 -24
  270. package/resources/vector-stores/files.js.map +1 -1
  271. package/resources/vector-stores/index.d.mts +1 -1
  272. package/resources/vector-stores/index.d.mts.map +1 -1
  273. package/resources/vector-stores/index.d.ts +1 -1
  274. package/resources/vector-stores/index.d.ts.map +1 -1
  275. package/resources/vector-stores/index.js.map +1 -1
  276. package/resources/vector-stores/index.mjs.map +1 -1
  277. package/resources/vector-stores/vector-stores.d.mts +223 -81
  278. package/resources/vector-stores/vector-stores.d.mts.map +1 -1
  279. package/resources/vector-stores/vector-stores.d.ts +223 -81
  280. package/resources/vector-stores/vector-stores.d.ts.map +1 -1
  281. package/resources/vector-stores/vector-stores.js +2 -24
  282. package/resources/vector-stores/vector-stores.js.map +1 -1
  283. package/resources/vector-stores/vector-stores.mjs.map +1 -1
  284. package/resources/vector-stores.js +2 -15
  285. package/resources/vector-stores.js.map +1 -1
  286. package/resources.js +2 -15
  287. package/resources.js.map +1 -1
  288. package/src/client.ts +94 -16
  289. package/src/internal/headers.ts +4 -3
  290. package/src/internal/to-file.ts +4 -2
  291. package/src/internal/uploads.ts +16 -4
  292. package/src/internal/utils/base64.ts +13 -10
  293. package/src/internal/utils/bytes.ts +32 -0
  294. package/src/internal/utils/uuid.ts +1 -3
  295. package/src/resources/api-keys.ts +225 -0
  296. package/src/resources/chat.ts +33 -0
  297. package/src/resources/data-sources/connectors.ts +280 -0
  298. package/src/resources/data-sources/data-sources.ts +271 -0
  299. package/src/resources/data-sources/index.ts +24 -0
  300. package/src/resources/data-sources.ts +3 -0
  301. package/src/resources/embeddings.ts +25 -10
  302. package/src/resources/extractions/content.ts +57 -2
  303. package/src/resources/extractions/extractions.ts +3 -1
  304. package/src/resources/extractions/index.ts +7 -1
  305. package/src/resources/extractions/jobs.ts +2 -1
  306. package/src/resources/files.ts +21 -0
  307. package/src/resources/index.ts +27 -4
  308. package/src/resources/parsing/index.ts +4 -0
  309. package/src/resources/parsing/jobs.ts +48 -45
  310. package/src/resources/parsing/parsing.ts +8 -0
  311. package/src/resources/top-level.ts +10 -40
  312. package/src/resources/vector-stores/files.ts +39 -2
  313. package/src/resources/vector-stores/index.ts +4 -3
  314. package/src/resources/vector-stores/vector-stores.ts +269 -91
  315. package/src/version.ts +1 -1
  316. package/uploads.js +2 -15
  317. package/uploads.js.map +1 -1
  318. package/version.d.mts +1 -1
  319. package/version.d.ts +1 -1
  320. package/version.js +1 -1
  321. package/version.mjs +1 -1
  322. package/internal/shims/crypto.d.mts +0 -13
  323. package/internal/shims/crypto.d.mts.map +0 -1
  324. package/internal/shims/crypto.d.ts +0 -13
  325. package/internal/shims/crypto.d.ts.map +0 -1
  326. package/internal/shims/crypto.js +0 -13
  327. package/internal/shims/crypto.js.map +0 -1
  328. package/internal/shims/crypto.mjs +0 -9
  329. package/internal/shims/crypto.mjs.map +0 -1
  330. package/internal/shims/file.d.mts +0 -23
  331. package/internal/shims/file.d.mts.map +0 -1
  332. package/internal/shims/file.d.ts +0 -23
  333. package/internal/shims/file.d.ts.map +0 -1
  334. package/internal/shims/file.js +0 -16
  335. package/internal/shims/file.js.map +0 -1
  336. package/internal/shims/file.mjs +0 -12
  337. package/internal/shims/file.mjs.map +0 -1
  338. package/internal/shims/getBuiltinModule.d.mts +0 -11
  339. package/internal/shims/getBuiltinModule.d.mts.map +0 -1
  340. package/internal/shims/getBuiltinModule.d.ts +0 -11
  341. package/internal/shims/getBuiltinModule.d.ts.map +0 -1
  342. package/internal/shims/getBuiltinModule.js +0 -68
  343. package/internal/shims/getBuiltinModule.js.map +0 -1
  344. package/internal/shims/getBuiltinModule.mjs +0 -64
  345. package/internal/shims/getBuiltinModule.mjs.map +0 -1
  346. package/internal/shims/nullGetBuiltinModule.d.mts +0 -2
  347. package/internal/shims/nullGetBuiltinModule.d.mts.map +0 -1
  348. package/internal/shims/nullGetBuiltinModule.d.ts +0 -2
  349. package/internal/shims/nullGetBuiltinModule.d.ts.map +0 -1
  350. package/internal/shims/nullGetBuiltinModule.js +0 -5
  351. package/internal/shims/nullGetBuiltinModule.js.map +0 -1
  352. package/internal/shims/nullGetBuiltinModule.mjs +0 -2
  353. package/internal/shims/nullGetBuiltinModule.mjs.map +0 -1
  354. package/src/internal/shims/crypto.ts +0 -18
  355. package/src/internal/shims/file.ts +0 -32
  356. package/src/internal/shims/getBuiltinModule.ts +0 -64
  357. package/src/internal/shims/nullGetBuiltinModule.ts +0 -1
package/src/client.ts CHANGED
@@ -32,7 +32,17 @@ import { APIPromise } from './core/api-promise';
32
32
  import { type Fetch } from './internal/builtin-types';
33
33
  import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
34
34
  import { FinalRequestOptions, RequestOptions } from './internal/request-options';
35
- import { EmbeddingCreateParams, Embeddings } from './resources/embeddings';
35
+ import {
36
+ APIKey,
37
+ APIKeyCreateParams,
38
+ APIKeyCreated,
39
+ APIKeyDeleteResponse,
40
+ APIKeyListParams,
41
+ APIKeys,
42
+ APIKeysLimitOffset,
43
+ } from './resources/api-keys';
44
+ import { Chat, ChatCreateCompletionResponse } from './resources/chat';
45
+ import { EmbeddingCreateParams, Embeddings, EncodingFormat, ObjectType } from './resources/embeddings';
36
46
  import {
37
47
  FileCreateParams,
38
48
  FileDeleteResponse,
@@ -41,21 +51,34 @@ import {
41
51
  FileObjectsLimitOffset,
42
52
  FileUpdateParams,
43
53
  Files,
54
+ PaginationWithTotal,
44
55
  } from './resources/files';
45
56
  import { readEnv } from './internal/utils/env';
46
57
  import { formatRequestDetails, loggerFor } from './internal/utils/log';
47
58
  import { isEmptyObj } from './internal/utils/values';
59
+ import {
60
+ DataSource,
61
+ DataSourceCreateParams,
62
+ DataSourceDeleteResponse,
63
+ DataSourceListParams,
64
+ DataSourceOauth2Params,
65
+ DataSourceType,
66
+ DataSourceUpdateParams,
67
+ DataSources,
68
+ DataSourcesLimitOffset,
69
+ } from './resources/data-sources/data-sources';
48
70
  import { Extractions } from './resources/extractions/extractions';
49
71
  import { Parsing } from './resources/parsing/parsing';
50
72
  import {
51
73
  ExpiresAfter,
52
- FileCounts,
53
- ScoredVectorStoreChunk,
74
+ ScoredAudioURLInputChunk,
75
+ ScoredImageURLInputChunk,
76
+ ScoredTextInputChunk,
77
+ ScoredVideoURLInputChunk,
54
78
  VectorStore,
55
79
  VectorStoreChunkSearchOptions,
56
80
  VectorStoreCreateParams,
57
81
  VectorStoreDeleteResponse,
58
- VectorStoreFileSearchOptions,
59
82
  VectorStoreListParams,
60
83
  VectorStoreQuestionAnsweringParams,
61
84
  VectorStoreQuestionAnsweringResponse,
@@ -229,6 +252,24 @@ export class Mixedbread {
229
252
  this.apiKey = apiKey;
230
253
  }
231
254
 
255
+ /**
256
+ * Create a new client instance re-using the same options given to the current client with optional overriding.
257
+ */
258
+ withOptions(options: Partial<ClientOptions>): this {
259
+ return new (this.constructor as any as new (props: ClientOptions) => typeof this)({
260
+ ...this._options,
261
+ environment: options.environment ? options.environment : undefined,
262
+ baseURL: options.environment ? undefined : this.baseURL,
263
+ maxRetries: this.maxRetries,
264
+ timeout: this.timeout,
265
+ logger: this.logger,
266
+ logLevel: this.logLevel,
267
+ fetchOptions: this.fetchOptions,
268
+ apiKey: this.apiKey,
269
+ ...options,
270
+ });
271
+ }
272
+
232
273
  /**
233
274
  * Create embeddings for text or images using the specified model, encoding format,
234
275
  * and normalization.
@@ -587,12 +628,12 @@ export class Mixedbread {
587
628
  fetchOptions.method = method.toUpperCase();
588
629
  }
589
630
 
590
- return (
631
+ try {
591
632
  // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
592
- this.fetch.call(undefined, url, fetchOptions).finally(() => {
593
- clearTimeout(timeout);
594
- })
595
- );
633
+ return await this.fetch.call(undefined, url, fetchOptions);
634
+ } finally {
635
+ clearTimeout(timeout);
636
+ }
596
637
  }
597
638
 
598
639
  private shouldRetry(response: Response): boolean {
@@ -673,17 +714,17 @@ export class Mixedbread {
673
714
  }
674
715
 
675
716
  buildRequest(
676
- options: FinalRequestOptions,
717
+ inputOptions: FinalRequestOptions,
677
718
  { retryCount = 0 }: { retryCount?: number } = {},
678
719
  ): { req: FinalizedRequestInit; url: string; timeout: number } {
679
- options = { ...options };
720
+ const options = { ...inputOptions };
680
721
  const { method, path, query } = options;
681
722
 
682
723
  const url = this.buildURL(path!, query as Record<string, unknown>);
683
724
  if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
684
725
  options.timeout = options.timeout ?? this.timeout;
685
726
  const { bodyHeaders, body } = this.buildBody({ options });
686
- const reqHeaders = this.buildHeaders({ options, method, bodyHeaders, retryCount });
727
+ const reqHeaders = this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
687
728
 
688
729
  const req: FinalizedRequestInit = {
689
730
  method,
@@ -797,12 +838,18 @@ export class Mixedbread {
797
838
  files: API.Files = new API.Files(this);
798
839
  extractions: API.Extractions = new API.Extractions(this);
799
840
  embeddings: API.Embeddings = new API.Embeddings(this);
841
+ chat: API.Chat = new API.Chat(this);
842
+ dataSources: API.DataSources = new API.DataSources(this);
843
+ apiKeys: API.APIKeys = new API.APIKeys(this);
800
844
  }
801
845
  Mixedbread.VectorStores = VectorStores;
802
846
  Mixedbread.Parsing = Parsing;
803
847
  Mixedbread.Files = Files;
804
848
  Mixedbread.Extractions = Extractions;
805
849
  Mixedbread.Embeddings = Embeddings;
850
+ Mixedbread.Chat = Chat;
851
+ Mixedbread.DataSources = DataSources;
852
+ Mixedbread.APIKeys = APIKeys;
806
853
  export declare namespace Mixedbread {
807
854
  export type RequestOptions = Opts.RequestOptions;
808
855
 
@@ -822,11 +869,12 @@ export declare namespace Mixedbread {
822
869
  export {
823
870
  VectorStores as VectorStores,
824
871
  type ExpiresAfter as ExpiresAfter,
825
- type FileCounts as FileCounts,
826
- type ScoredVectorStoreChunk as ScoredVectorStoreChunk,
872
+ type ScoredAudioURLInputChunk as ScoredAudioURLInputChunk,
873
+ type ScoredImageURLInputChunk as ScoredImageURLInputChunk,
874
+ type ScoredTextInputChunk as ScoredTextInputChunk,
875
+ type ScoredVideoURLInputChunk as ScoredVideoURLInputChunk,
827
876
  type VectorStore as VectorStore,
828
877
  type VectorStoreChunkSearchOptions as VectorStoreChunkSearchOptions,
829
- type VectorStoreFileSearchOptions as VectorStoreFileSearchOptions,
830
878
  type VectorStoreDeleteResponse as VectorStoreDeleteResponse,
831
879
  type VectorStoreQuestionAnsweringResponse as VectorStoreQuestionAnsweringResponse,
832
880
  type VectorStoreSearchResponse as VectorStoreSearchResponse,
@@ -843,6 +891,7 @@ export declare namespace Mixedbread {
843
891
  export {
844
892
  Files as Files,
845
893
  type FileObject as FileObject,
894
+ type PaginationWithTotal as PaginationWithTotal,
846
895
  type FileDeleteResponse as FileDeleteResponse,
847
896
  type FileObjectsLimitOffset as FileObjectsLimitOffset,
848
897
  type FileCreateParams as FileCreateParams,
@@ -852,7 +901,36 @@ export declare namespace Mixedbread {
852
901
 
853
902
  export { Extractions as Extractions };
854
903
 
855
- export { Embeddings as Embeddings, type EmbeddingCreateParams as EmbeddingCreateParams };
904
+ export {
905
+ Embeddings as Embeddings,
906
+ type EncodingFormat as EncodingFormat,
907
+ type ObjectType as ObjectType,
908
+ type EmbeddingCreateParams as EmbeddingCreateParams,
909
+ };
910
+
911
+ export { Chat as Chat, type ChatCreateCompletionResponse as ChatCreateCompletionResponse };
912
+
913
+ export {
914
+ DataSources as DataSources,
915
+ type DataSource as DataSource,
916
+ type DataSourceOauth2Params as DataSourceOauth2Params,
917
+ type DataSourceType as DataSourceType,
918
+ type DataSourceDeleteResponse as DataSourceDeleteResponse,
919
+ type DataSourcesLimitOffset as DataSourcesLimitOffset,
920
+ type DataSourceCreateParams as DataSourceCreateParams,
921
+ type DataSourceUpdateParams as DataSourceUpdateParams,
922
+ type DataSourceListParams as DataSourceListParams,
923
+ };
924
+
925
+ export {
926
+ APIKeys as APIKeys,
927
+ type APIKey as APIKey,
928
+ type APIKeyCreated as APIKeyCreated,
929
+ type APIKeyDeleteResponse as APIKeyDeleteResponse,
930
+ type APIKeysLimitOffset as APIKeysLimitOffset,
931
+ type APIKeyCreateParams as APIKeyCreateParams,
932
+ type APIKeyListParams as APIKeyListParams,
933
+ };
856
934
 
857
935
  export type SearchFilter = API.SearchFilter;
858
936
  export type SearchFilterCondition = API.SearchFilterCondition;
@@ -3,7 +3,7 @@
3
3
  type HeaderValue = string | undefined | null;
4
4
  export type HeadersLike =
5
5
  | Headers
6
- | readonly [string, HeaderValue][]
6
+ | readonly HeaderValue[][]
7
7
  | Record<string, HeaderValue | readonly HeaderValue[]>
8
8
  | undefined
9
9
  | null
@@ -40,7 +40,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
40
40
  }
41
41
 
42
42
  let shouldClear = false;
43
- let iter: Iterable<readonly [string, HeaderValue | readonly HeaderValue[]]>;
43
+ let iter: Iterable<readonly (HeaderValue | readonly HeaderValue[])[]>;
44
44
  if (headers instanceof Headers) {
45
45
  iter = headers.entries();
46
46
  } else if (isArray(headers)) {
@@ -51,6 +51,7 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
51
51
  }
52
52
  for (let row of iter) {
53
53
  const name = row[0];
54
+ if (typeof name !== 'string') throw new TypeError('expected header name to be a string');
54
55
  const values = isArray(row[1]) ? row[1] : [row[1]];
55
56
  let didClear = false;
56
57
  for (const value of values) {
@@ -70,8 +71,8 @@ function* iterateHeaders(headers: HeadersLike): IterableIterator<readonly [strin
70
71
  export const buildHeaders = (newHeaders: HeadersLike[]): NullableHeaders => {
71
72
  const targetHeaders = new Headers();
72
73
  const nullHeaders = new Set<string>();
73
- const seenHeaders = new Set<string>();
74
74
  for (const headers of newHeaders) {
75
+ const seenHeaders = new Set<string>();
75
76
  for (const [name, value] of iterateHeaders(headers)) {
76
77
  const lowerName = name.toLowerCase();
77
78
  if (!seenHeaders.has(lowerName)) {
@@ -1,6 +1,6 @@
1
- import { type File, getFile } from './shims/file';
2
1
  import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';
3
2
  import type { FilePropertyBag } from './builtin-types';
3
+ import { checkFileSupport } from './uploads';
4
4
 
5
5
  type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
6
6
 
@@ -85,12 +85,14 @@ export async function toFile(
85
85
  name?: string | null | undefined,
86
86
  options?: FilePropertyBag | undefined,
87
87
  ): Promise<File> {
88
+ checkFileSupport();
89
+
88
90
  // If it's a promise, resolve it.
89
91
  value = await value;
90
92
 
91
93
  // If we've been given a `File` we don't need to do anything
92
94
  if (isFileLike(value)) {
93
- if (value instanceof getFile()) {
95
+ if (value instanceof File) {
94
96
  return value;
95
97
  }
96
98
  return makeFile([await value.arrayBuffer()], value.name);
@@ -1,7 +1,6 @@
1
1
  import { type RequestOptions } from './request-options';
2
2
  import type { FilePropertyBag, Fetch } from './builtin-types';
3
3
  import type { Mixedbread } from '../client';
4
- import { type File, getFile } from './shims/file';
5
4
  import { ReadableStreamFrom } from './shims';
6
5
 
7
6
  export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
@@ -12,6 +11,20 @@ interface BunFile extends Blob {
12
11
  readonly name?: string | undefined;
13
12
  }
14
13
 
14
+ export const checkFileSupport = () => {
15
+ if (typeof File === 'undefined') {
16
+ const { process } = globalThis as any;
17
+ const isOldNode =
18
+ typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
19
+ throw new Error(
20
+ '`File` is not defined as a global, which is required for file uploads.' +
21
+ (isOldNode ?
22
+ " Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
23
+ : ''),
24
+ );
25
+ }
26
+ };
27
+
15
28
  /**
16
29
  * Typically, this is a native "File" class.
17
30
  *
@@ -32,7 +45,7 @@ export function makeFile(
32
45
  fileName: string | undefined,
33
46
  options?: FilePropertyBag,
34
47
  ): File {
35
- const File = getFile();
48
+ checkFileSupport();
36
49
  return new File(fileBits as any, fileName ?? 'unknown_file', options);
37
50
  }
38
51
 
@@ -125,8 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
125
138
 
126
139
  // We check for Blob not File because Bun.File doesn't inherit from File,
127
140
  // but they both inherit from Blob and have a `name` property at runtime.
128
- const isNamedBlob = (value: object) =>
129
- value instanceof getFile() || (value instanceof Blob && 'name' in value);
141
+ const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
130
142
 
131
143
  const isUploadable = (value: unknown) =>
132
144
  typeof value === 'object' &&
@@ -1,18 +1,19 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  import { MixedbreadError } from '../../core/error';
4
+ import { encodeUTF8 } from './bytes';
4
5
 
5
6
  export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
6
7
  if (!data) return '';
7
8
 
8
- if (typeof data === 'string') {
9
- data = new (globalThis as any).TextEncoder().encode(data);
10
- }
11
-
12
9
  if (typeof (globalThis as any).Buffer !== 'undefined') {
13
10
  return (globalThis as any).Buffer.from(data).toString('base64');
14
11
  }
15
12
 
13
+ if (typeof data === 'string') {
14
+ data = encodeUTF8(data);
15
+ }
16
+
16
17
  if (typeof btoa !== 'undefined') {
17
18
  return btoa(String.fromCharCode.apply(null, data as any));
18
19
  }
@@ -22,15 +23,17 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
22
23
 
23
24
  export const fromBase64 = (str: string): Uint8Array => {
24
25
  if (typeof (globalThis as any).Buffer !== 'undefined') {
25
- return new Uint8Array((globalThis as any).Buffer.from(str, 'base64'));
26
+ const buf = (globalThis as any).Buffer.from(str, 'base64');
27
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
26
28
  }
27
29
 
28
30
  if (typeof atob !== 'undefined') {
29
- return new Uint8Array(
30
- atob(str)
31
- .split('')
32
- .map((c) => c.charCodeAt(0)),
33
- );
31
+ const bstr = atob(str);
32
+ const buf = new Uint8Array(bstr.length);
33
+ for (let i = 0; i < bstr.length; i++) {
34
+ buf[i] = bstr.charCodeAt(i);
35
+ }
36
+ return buf;
34
37
  }
35
38
 
36
39
  throw new MixedbreadError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
@@ -0,0 +1,32 @@
1
+ export function concatBytes(buffers: Uint8Array[]): Uint8Array {
2
+ let length = 0;
3
+ for (const buffer of buffers) {
4
+ length += buffer.length;
5
+ }
6
+ const output = new Uint8Array(length);
7
+ let index = 0;
8
+ for (const buffer of buffers) {
9
+ output.set(buffer, index);
10
+ index += buffer.length;
11
+ }
12
+
13
+ return output;
14
+ }
15
+
16
+ let encodeUTF8_: (str: string) => Uint8Array;
17
+ export function encodeUTF8(str: string) {
18
+ let encoder;
19
+ return (
20
+ encodeUTF8_ ??
21
+ ((encoder = new (globalThis as any).TextEncoder()), (encodeUTF8_ = encoder.encode.bind(encoder)))
22
+ )(str);
23
+ }
24
+
25
+ let decodeUTF8_: (bytes: Uint8Array) => string;
26
+ export function decodeUTF8(bytes: Uint8Array) {
27
+ let decoder;
28
+ return (
29
+ decodeUTF8_ ??
30
+ ((decoder = new (globalThis as any).TextDecoder()), (decodeUTF8_ = decoder.decode.bind(decoder)))
31
+ )(bytes);
32
+ }
@@ -1,12 +1,10 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- import { getCrypto } from '../shims/crypto';
4
-
5
3
  /**
6
4
  * https://stackoverflow.com/a/2117523
7
5
  */
8
6
  export let uuid4 = function () {
9
- const crypto = getCrypto();
7
+ const { crypto } = globalThis as any;
10
8
  if (crypto?.randomUUID) {
11
9
  uuid4 = crypto.randomUUID.bind(crypto);
12
10
  return crypto.randomUUID();
@@ -0,0 +1,225 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { LimitOffset, type LimitOffsetParams, PagePromise } from '../core/pagination';
6
+ import { RequestOptions } from '../internal/request-options';
7
+ import { path } from '../internal/utils/path';
8
+
9
+ export class APIKeys extends APIResource {
10
+ /**
11
+ * Create a new API key.
12
+ *
13
+ * Args: params: The parameters for creating the API key.
14
+ *
15
+ * Returns: ApiKeyCreated: The response containing the details of the created API
16
+ * key.
17
+ */
18
+ create(body: APIKeyCreateParams, options?: RequestOptions): APIPromise<APIKeyCreated> {
19
+ return this._client.post('/v1/api-keys', { body, ...options });
20
+ }
21
+
22
+ /**
23
+ * Retrieve details of a specific API key by its ID.
24
+ *
25
+ * Args: api_key_id: The ID of the API key to retrieve.
26
+ *
27
+ * Returns: ApiKey: The response containing the API key details.
28
+ */
29
+ retrieve(apiKeyID: string, options?: RequestOptions): APIPromise<APIKey> {
30
+ return this._client.get(path`/v1/api-keys/${apiKeyID}`, options);
31
+ }
32
+
33
+ /**
34
+ * List all API keys for the authenticated user.
35
+ *
36
+ * Args: pagination: The pagination options
37
+ *
38
+ * Returns: A list of API keys belonging to the user.
39
+ */
40
+ list(
41
+ query: APIKeyListParams | null | undefined = {},
42
+ options?: RequestOptions,
43
+ ): PagePromise<APIKeysLimitOffset, APIKey> {
44
+ return this._client.getAPIList('/v1/api-keys', LimitOffset<APIKey>, { query, ...options });
45
+ }
46
+
47
+ /**
48
+ * Delete a specific API key by its ID.
49
+ *
50
+ * Args: api_key_id: The ID of the API key to delete.
51
+ *
52
+ * Returns: ApiKeyDeleted: The response containing the details of the deleted API
53
+ * key.
54
+ */
55
+ delete(apiKeyID: string, options?: RequestOptions): APIPromise<APIKeyDeleteResponse> {
56
+ return this._client.delete(path`/v1/api-keys/${apiKeyID}`, options);
57
+ }
58
+
59
+ /**
60
+ * Reroll the secret for a specific API key by its ID.
61
+ *
62
+ * This generates a new secret key, invalidating the old one.
63
+ *
64
+ * Args: api_key_id: The ID of the API key to reroll.
65
+ *
66
+ * Returns: ApiKeyCreated: The response containing the API key details with the new
67
+ * secret key.
68
+ */
69
+ reroll(apiKeyID: string, options?: RequestOptions): APIPromise<APIKeyCreated> {
70
+ return this._client.post(path`/v1/api-keys/${apiKeyID}/reroll`, options);
71
+ }
72
+
73
+ /**
74
+ * Revoke a specific API key by its ID.
75
+ *
76
+ * Args: api_key_id: The ID of the API key to revoke.
77
+ *
78
+ * Returns: ApiKey: The response containing the details of the revoked API key.
79
+ */
80
+ revoke(apiKeyID: string, options?: RequestOptions): APIPromise<APIKey> {
81
+ return this._client.post(path`/v1/api-keys/${apiKeyID}/revoke`, options);
82
+ }
83
+ }
84
+
85
+ export type APIKeysLimitOffset = LimitOffset<APIKey>;
86
+
87
+ /**
88
+ * Response model for an API key.
89
+ */
90
+ export interface APIKey {
91
+ /**
92
+ * The ID of the API key
93
+ */
94
+ id: string;
95
+
96
+ /**
97
+ * The name of the API key
98
+ */
99
+ name: string;
100
+
101
+ /**
102
+ * The redacted value of the API key
103
+ */
104
+ redacted_value: string;
105
+
106
+ /**
107
+ * The expiration datetime of the API key
108
+ */
109
+ expires_at?: string | null;
110
+
111
+ /**
112
+ * The creation datetime of the API key
113
+ */
114
+ created_at: string;
115
+
116
+ /**
117
+ * The last update datetime of the API key
118
+ */
119
+ updated_at: string;
120
+
121
+ /**
122
+ * The last active datetime of the API key
123
+ */
124
+ last_active_at?: string | null;
125
+
126
+ /**
127
+ * The type of the object
128
+ */
129
+ object?: 'api_key';
130
+ }
131
+
132
+ /**
133
+ * Response model for creating an API key.
134
+ */
135
+ export interface APIKeyCreated {
136
+ /**
137
+ * The ID of the API key
138
+ */
139
+ id: string;
140
+
141
+ /**
142
+ * The name of the API key
143
+ */
144
+ name: string;
145
+
146
+ /**
147
+ * The redacted value of the API key
148
+ */
149
+ redacted_value: string;
150
+
151
+ /**
152
+ * The expiration datetime of the API key
153
+ */
154
+ expires_at?: string | null;
155
+
156
+ /**
157
+ * The creation datetime of the API key
158
+ */
159
+ created_at: string;
160
+
161
+ /**
162
+ * The last update datetime of the API key
163
+ */
164
+ updated_at: string;
165
+
166
+ /**
167
+ * The last active datetime of the API key
168
+ */
169
+ last_active_at?: string | null;
170
+
171
+ /**
172
+ * The type of the object
173
+ */
174
+ object?: 'api_key';
175
+
176
+ /**
177
+ * The value of the API key
178
+ */
179
+ value: string;
180
+ }
181
+
182
+ /**
183
+ * Response model for deleting an API key.
184
+ */
185
+ export interface APIKeyDeleteResponse {
186
+ /**
187
+ * The ID of the deleted API key
188
+ */
189
+ id: string;
190
+
191
+ /**
192
+ * Whether the API key was deleted
193
+ */
194
+ deleted: boolean;
195
+
196
+ /**
197
+ * The type of the object deleted
198
+ */
199
+ object?: 'api_key';
200
+ }
201
+
202
+ export interface APIKeyCreateParams {
203
+ /**
204
+ * A name/description for the API key
205
+ */
206
+ name?: string;
207
+
208
+ /**
209
+ * Optional expiration datetime
210
+ */
211
+ expires_at?: string | null;
212
+ }
213
+
214
+ export interface APIKeyListParams extends LimitOffsetParams {}
215
+
216
+ export declare namespace APIKeys {
217
+ export {
218
+ type APIKey as APIKey,
219
+ type APIKeyCreated as APIKeyCreated,
220
+ type APIKeyDeleteResponse as APIKeyDeleteResponse,
221
+ type APIKeysLimitOffset as APIKeysLimitOffset,
222
+ type APIKeyCreateParams as APIKeyCreateParams,
223
+ type APIKeyListParams as APIKeyListParams,
224
+ };
225
+ }
@@ -0,0 +1,33 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { RequestOptions } from '../internal/request-options';
6
+
7
+ export class Chat extends APIResource {
8
+ /**
9
+ * Create a chat completion using the provided parameters.
10
+ *
11
+ * Generates a completion response based on the chat messages and model parameters
12
+ * provided. The response can be either a full completion or streamed chunks
13
+ * depending on the request parameters.
14
+ *
15
+ * Args: params: Parameters for creating the chat completion including messages,
16
+ * model selection, and generation settings user: The authenticated user making the
17
+ * request
18
+ *
19
+ * Returns: Either a ChatCompletion containing the full response, or
20
+ * ChatCompletionChunk for streaming
21
+ *
22
+ * Raises: HTTPException: If there is an error creating the completion (500)
23
+ */
24
+ createCompletion(options?: RequestOptions): APIPromise<unknown> {
25
+ return this._client.post('/v1/chat/completions', options);
26
+ }
27
+ }
28
+
29
+ export type ChatCreateCompletionResponse = unknown;
30
+
31
+ export declare namespace Chat {
32
+ export { type ChatCreateCompletionResponse as ChatCreateCompletionResponse };
33
+ }