@mixedbread/sdk 0.1.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (277) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/LICENSE +201 -0
  3. package/README.md +360 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +89 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +241 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +914 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +882 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +47 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +113 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +97 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +148 -0
  87. package/index.d.ts +148 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +151 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +108 -0
  92. package/index.mjs.map +1 -0
  93. package/lib/polling.d.ts +48 -0
  94. package/lib/polling.d.ts.map +1 -0
  95. package/lib/polling.js +75 -0
  96. package/lib/polling.js.map +1 -0
  97. package/lib/polling.mjs +71 -0
  98. package/lib/polling.mjs.map +1 -0
  99. package/package.json +124 -0
  100. package/pagination.d.ts +30 -0
  101. package/pagination.d.ts.map +1 -0
  102. package/pagination.js +45 -0
  103. package/pagination.js.map +1 -0
  104. package/pagination.mjs +41 -0
  105. package/pagination.mjs.map +1 -0
  106. package/resource.d.ts +6 -0
  107. package/resource.d.ts.map +1 -0
  108. package/resource.js +11 -0
  109. package/resource.js.map +1 -0
  110. package/resource.mjs +7 -0
  111. package/resource.mjs.map +1 -0
  112. package/resources/extractions/content.d.ts +35 -0
  113. package/resources/extractions/content.d.ts.map +1 -0
  114. package/resources/extractions/content.js +19 -0
  115. package/resources/extractions/content.js.map +1 -0
  116. package/resources/extractions/content.mjs +15 -0
  117. package/resources/extractions/content.mjs.map +1 -0
  118. package/resources/extractions/extractions.d.ts +18 -0
  119. package/resources/extractions/extractions.d.ts.map +1 -0
  120. package/resources/extractions/extractions.js +47 -0
  121. package/resources/extractions/extractions.js.map +1 -0
  122. package/resources/extractions/extractions.mjs +20 -0
  123. package/resources/extractions/extractions.mjs.map +1 -0
  124. package/resources/extractions/index.d.ts +5 -0
  125. package/resources/extractions/index.d.ts.map +1 -0
  126. package/resources/extractions/index.js +13 -0
  127. package/resources/extractions/index.js.map +1 -0
  128. package/resources/extractions/index.mjs +6 -0
  129. package/resources/extractions/index.mjs.map +1 -0
  130. package/resources/extractions/jobs.d.ts +44 -0
  131. package/resources/extractions/jobs.d.ts.map +1 -0
  132. package/resources/extractions/jobs.js +29 -0
  133. package/resources/extractions/jobs.js.map +1 -0
  134. package/resources/extractions/jobs.mjs +25 -0
  135. package/resources/extractions/jobs.mjs.map +1 -0
  136. package/resources/extractions/schema.d.ts +85 -0
  137. package/resources/extractions/schema.d.ts.map +1 -0
  138. package/resources/extractions/schema.js +39 -0
  139. package/resources/extractions/schema.js.map +1 -0
  140. package/resources/extractions/schema.mjs +35 -0
  141. package/resources/extractions/schema.mjs.map +1 -0
  142. package/resources/files.d.ts +125 -0
  143. package/resources/files.d.ts.map +1 -0
  144. package/resources/files.js +99 -0
  145. package/resources/files.js.map +1 -0
  146. package/resources/files.mjs +71 -0
  147. package/resources/files.mjs.map +1 -0
  148. package/resources/index.d.ts +7 -0
  149. package/resources/index.d.ts.map +1 -0
  150. package/resources/index.js +30 -0
  151. package/resources/index.js.map +1 -0
  152. package/resources/index.mjs +7 -0
  153. package/resources/index.mjs.map +1 -0
  154. package/resources/parsing/index.d.ts +3 -0
  155. package/resources/parsing/index.d.ts.map +1 -0
  156. package/resources/parsing/index.js +10 -0
  157. package/resources/parsing/index.js.map +1 -0
  158. package/resources/parsing/index.mjs +4 -0
  159. package/resources/parsing/index.mjs.map +1 -0
  160. package/resources/parsing/jobs.d.ts +278 -0
  161. package/resources/parsing/jobs.d.ts.map +1 -0
  162. package/resources/parsing/jobs.js +147 -0
  163. package/resources/parsing/jobs.js.map +1 -0
  164. package/resources/parsing/jobs.mjs +119 -0
  165. package/resources/parsing/jobs.mjs.map +1 -0
  166. package/resources/parsing/parsing.d.ts +10 -0
  167. package/resources/parsing/parsing.d.ts.map +1 -0
  168. package/resources/parsing/parsing.js +40 -0
  169. package/resources/parsing/parsing.js.map +1 -0
  170. package/resources/parsing/parsing.mjs +13 -0
  171. package/resources/parsing/parsing.mjs.map +1 -0
  172. package/resources/shared.d.ts +35 -0
  173. package/resources/shared.d.ts.map +1 -0
  174. package/resources/shared.js +4 -0
  175. package/resources/shared.js.map +1 -0
  176. package/resources/shared.mjs +3 -0
  177. package/resources/shared.mjs.map +1 -0
  178. package/resources/top-level.d.ts +11 -0
  179. package/resources/top-level.d.ts.map +1 -0
  180. package/resources/top-level.js +4 -0
  181. package/resources/top-level.js.map +1 -0
  182. package/resources/top-level.mjs +3 -0
  183. package/resources/top-level.mjs.map +1 -0
  184. package/resources/vector-stores/files.d.ts +280 -0
  185. package/resources/vector-stores/files.d.ts.map +1 -0
  186. package/resources/vector-stores/files.js +167 -0
  187. package/resources/vector-stores/files.js.map +1 -0
  188. package/resources/vector-stores/files.mjs +139 -0
  189. package/resources/vector-stores/files.mjs.map +1 -0
  190. package/resources/vector-stores/index.d.ts +3 -0
  191. package/resources/vector-stores/index.d.ts.map +1 -0
  192. package/resources/vector-stores/index.js +11 -0
  193. package/resources/vector-stores/index.js.map +1 -0
  194. package/resources/vector-stores/index.mjs +4 -0
  195. package/resources/vector-stores/index.mjs.map +1 -0
  196. package/resources/vector-stores/vector-stores.d.ts +400 -0
  197. package/resources/vector-stores/vector-stores.d.ts.map +1 -0
  198. package/resources/vector-stores/vector-stores.js +121 -0
  199. package/resources/vector-stores/vector-stores.js.map +1 -0
  200. package/resources/vector-stores/vector-stores.mjs +93 -0
  201. package/resources/vector-stores/vector-stores.mjs.map +1 -0
  202. package/shims/node.d.ts +30 -0
  203. package/shims/node.d.ts.map +1 -0
  204. package/shims/node.js +31 -0
  205. package/shims/node.js.map +1 -0
  206. package/shims/node.mjs +5 -0
  207. package/shims/node.mjs.map +1 -0
  208. package/shims/web.d.ts +26 -0
  209. package/shims/web.d.ts.map +1 -0
  210. package/shims/web.js +31 -0
  211. package/shims/web.js.map +1 -0
  212. package/shims/web.mjs +5 -0
  213. package/shims/web.mjs.map +1 -0
  214. package/src/_shims/MultipartBody.ts +9 -0
  215. package/src/_shims/README.md +46 -0
  216. package/src/_shims/auto/runtime-bun.ts +4 -0
  217. package/src/_shims/auto/runtime-node.ts +4 -0
  218. package/src/_shims/auto/runtime.ts +4 -0
  219. package/src/_shims/auto/types-node.ts +4 -0
  220. package/src/_shims/auto/types.d.ts +101 -0
  221. package/src/_shims/auto/types.js +3 -0
  222. package/src/_shims/auto/types.mjs +3 -0
  223. package/src/_shims/bun-runtime.ts +14 -0
  224. package/src/_shims/index.d.ts +81 -0
  225. package/src/_shims/index.js +13 -0
  226. package/src/_shims/index.mjs +7 -0
  227. package/src/_shims/manual-types.d.ts +12 -0
  228. package/src/_shims/manual-types.js +3 -0
  229. package/src/_shims/manual-types.mjs +3 -0
  230. package/src/_shims/node-runtime.ts +81 -0
  231. package/src/_shims/node-types.d.ts +42 -0
  232. package/src/_shims/node-types.js +3 -0
  233. package/src/_shims/node-types.mjs +3 -0
  234. package/src/_shims/registry.ts +67 -0
  235. package/src/_shims/web-runtime.ts +103 -0
  236. package/src/_shims/web-types.d.ts +83 -0
  237. package/src/_shims/web-types.js +3 -0
  238. package/src/_shims/web-types.mjs +3 -0
  239. package/src/core.ts +1208 -0
  240. package/src/error.ts +130 -0
  241. package/src/index.ts +294 -0
  242. package/src/lib/.keep +4 -0
  243. package/src/lib/polling.ts +115 -0
  244. package/src/pagination.ts +82 -0
  245. package/src/resource.ts +11 -0
  246. package/src/resources/extractions/content.ts +43 -0
  247. package/src/resources/extractions/extractions.ts +47 -0
  248. package/src/resources/extractions/index.ts +14 -0
  249. package/src/resources/extractions/jobs.ts +55 -0
  250. package/src/resources/extractions/schema.ts +111 -0
  251. package/src/resources/files.ts +181 -0
  252. package/src/resources/index.ts +32 -0
  253. package/src/resources/parsing/index.ts +12 -0
  254. package/src/resources/parsing/jobs.ts +438 -0
  255. package/src/resources/parsing/parsing.ts +32 -0
  256. package/src/resources/shared.ts +41 -0
  257. package/src/resources/top-level.ts +14 -0
  258. package/src/resources/vector-stores/files.ts +434 -0
  259. package/src/resources/vector-stores/index.ts +30 -0
  260. package/src/resources/vector-stores/vector-stores.ts +561 -0
  261. package/src/shims/node.ts +50 -0
  262. package/src/shims/web.ts +50 -0
  263. package/src/tsconfig.json +11 -0
  264. package/src/uploads.ts +255 -0
  265. package/src/version.ts +1 -0
  266. package/uploads.d.ts +75 -0
  267. package/uploads.d.ts.map +1 -0
  268. package/uploads.js +171 -0
  269. package/uploads.js.map +1 -0
  270. package/uploads.mjs +158 -0
  271. package/uploads.mjs.map +1 -0
  272. package/version.d.ts +2 -0
  273. package/version.d.ts.map +1 -0
  274. package/version.js +5 -0
  275. package/version.js.map +1 -0
  276. package/version.mjs +2 -0
  277. package/version.mjs.map +1 -0
package/index.js ADDED
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var _a;
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.UnprocessableEntityError = exports.PermissionDeniedError = exports.InternalServerError = exports.AuthenticationError = exports.BadRequestError = exports.RateLimitError = exports.ConflictError = exports.NotFoundError = exports.APIUserAbortError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIError = exports.MixedbreadError = exports.fileFromPath = exports.toFile = exports.Mixedbread = void 0;
29
+ const Core = __importStar(require("./core.js"));
30
+ const Errors = __importStar(require("./error.js"));
31
+ const Pagination = __importStar(require("./pagination.js"));
32
+ const Uploads = __importStar(require("./uploads.js"));
33
+ const API = __importStar(require("./resources/index.js"));
34
+ const files_1 = require("./resources/files.js");
35
+ const extractions_1 = require("./resources/extractions/extractions.js");
36
+ const parsing_1 = require("./resources/parsing/parsing.js");
37
+ const vector_stores_1 = require("./resources/vector-stores/vector-stores.js");
38
+ const environments = {
39
+ production: 'https://api.mixedbread.ai',
40
+ local: 'http://127.0.0.1:8000',
41
+ };
42
+ /**
43
+ * API Client for interfacing with the Mixedbread API.
44
+ */
45
+ class Mixedbread extends Core.APIClient {
46
+ /**
47
+ * API Client for interfacing with the Mixedbread API.
48
+ *
49
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
50
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
51
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
52
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
53
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
54
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
55
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
56
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
57
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
58
+ */
59
+ constructor({ baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'), apiKey = Core.readEnv('MXBAI_API_KEY'), ...opts } = {}) {
60
+ if (apiKey === undefined) {
61
+ throw new Errors.MixedbreadError("The MXBAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Mixedbread client with an apiKey option, like new Mixedbread({ apiKey: 'My API Key' }).");
62
+ }
63
+ const options = {
64
+ apiKey,
65
+ ...opts,
66
+ baseURL,
67
+ environment: opts.environment ?? 'production',
68
+ };
69
+ if (baseURL && opts.environment) {
70
+ throw new Errors.MixedbreadError('Ambiguous URL; The `baseURL` option (or MIXEDBREAD_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null');
71
+ }
72
+ super({
73
+ baseURL: options.baseURL || environments[options.environment || 'production'],
74
+ timeout: options.timeout ?? 60000 /* 1 minute */,
75
+ httpAgent: options.httpAgent,
76
+ maxRetries: options.maxRetries,
77
+ fetch: options.fetch,
78
+ });
79
+ this.parsing = new API.Parsing(this);
80
+ this.files = new API.Files(this);
81
+ this.vectorStores = new API.VectorStores(this);
82
+ this.extractions = new API.Extractions(this);
83
+ this._options = options;
84
+ this.apiKey = apiKey;
85
+ }
86
+ /**
87
+ * Returns service information, including name and version.
88
+ *
89
+ * Returns: InfoResponse: A response containing the service name and version.
90
+ */
91
+ info(options) {
92
+ return this.get('/', options);
93
+ }
94
+ defaultQuery() {
95
+ return this._options.defaultQuery;
96
+ }
97
+ defaultHeaders(opts) {
98
+ return {
99
+ ...super.defaultHeaders(opts),
100
+ ...this._options.defaultHeaders,
101
+ };
102
+ }
103
+ authHeaders(opts) {
104
+ return { Authorization: `Bearer ${this.apiKey}` };
105
+ }
106
+ }
107
+ exports.Mixedbread = Mixedbread;
108
+ _a = Mixedbread;
109
+ Mixedbread.Mixedbread = _a;
110
+ Mixedbread.DEFAULT_TIMEOUT = 60000; // 1 minute
111
+ Mixedbread.MixedbreadError = Errors.MixedbreadError;
112
+ Mixedbread.APIError = Errors.APIError;
113
+ Mixedbread.APIConnectionError = Errors.APIConnectionError;
114
+ Mixedbread.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
115
+ Mixedbread.APIUserAbortError = Errors.APIUserAbortError;
116
+ Mixedbread.NotFoundError = Errors.NotFoundError;
117
+ Mixedbread.ConflictError = Errors.ConflictError;
118
+ Mixedbread.RateLimitError = Errors.RateLimitError;
119
+ Mixedbread.BadRequestError = Errors.BadRequestError;
120
+ Mixedbread.AuthenticationError = Errors.AuthenticationError;
121
+ Mixedbread.InternalServerError = Errors.InternalServerError;
122
+ Mixedbread.PermissionDeniedError = Errors.PermissionDeniedError;
123
+ Mixedbread.UnprocessableEntityError = Errors.UnprocessableEntityError;
124
+ Mixedbread.toFile = Uploads.toFile;
125
+ Mixedbread.fileFromPath = Uploads.fileFromPath;
126
+ Mixedbread.Parsing = parsing_1.Parsing;
127
+ Mixedbread.Files = files_1.Files;
128
+ Mixedbread.FileObjectsLimitOffset = files_1.FileObjectsLimitOffset;
129
+ Mixedbread.VectorStores = vector_stores_1.VectorStores;
130
+ Mixedbread.VectorStoresLimitOffset = vector_stores_1.VectorStoresLimitOffset;
131
+ Mixedbread.Extractions = extractions_1.Extractions;
132
+ var uploads_1 = require("./uploads.js");
133
+ Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return uploads_1.toFile; } });
134
+ Object.defineProperty(exports, "fileFromPath", { enumerable: true, get: function () { return uploads_1.fileFromPath; } });
135
+ var error_1 = require("./error.js");
136
+ Object.defineProperty(exports, "MixedbreadError", { enumerable: true, get: function () { return error_1.MixedbreadError; } });
137
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return error_1.APIError; } });
138
+ Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return error_1.APIConnectionError; } });
139
+ Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return error_1.APIConnectionTimeoutError; } });
140
+ Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return error_1.APIUserAbortError; } });
141
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return error_1.NotFoundError; } });
142
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return error_1.ConflictError; } });
143
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_1.RateLimitError; } });
144
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return error_1.BadRequestError; } });
145
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
146
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_1.InternalServerError; } });
147
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return error_1.PermissionDeniedError; } });
148
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
149
+ exports = module.exports = Mixedbread;
150
+ exports.default = Mixedbread;
151
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGtF,gDAA+B;AAC/B,mDAAkC;AAClC,4DAA2C;AAE3C,sDAAqC;AACrC,0DAAyC;AAGzC,gDAQ2B;AAC3B,wEAAkE;AAClE,4DAAsD;AACtD,8EAgBiD;AAEjD,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,2BAA2B;IACvC,KAAK,EAAE,uBAAuB;CAC/B,CAAC;AA2EF;;GAEG;AACH,MAAa,UAAW,SAAQ,IAAI,CAAC,SAAS;IAK5C;;;;;;;;;;;;OAYG;IACH,YAAY,EACV,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAC7C,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EACtC,GAAG,IAAI,KACU,EAAE;QACnB,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,IAAI,MAAM,CAAC,eAAe,CAC9B,2LAA2L,CAC5L,CAAC;SACH;QAED,MAAM,OAAO,GAAkB;YAC7B,MAAM;YACN,GAAG,IAAI;YACP,OAAO;YACP,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,YAAY;SAC9C,CAAC;QAEF,IAAI,OAAO,IAAI,IAAI,CAAC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iBAAiB,OAAA;AACjB,sGAAA,aAAa,OAAA;AACb,sGAAA,aAAa,OAAA;AACb,uGAAA,cAAc,OAAA;AACd,wGAAA,eAAe,OAAA;AACf,4GAAA,mBAAmB,OAAA;AACnB,4GAAA,mBAAmB,OAAA;AACnB,8GAAA,qBAAqB,OAAA;AACrB,iHAAA,wBAAwB,OAAA;AAG1B,kBAAe,UAAU,CAAC"}
package/index.mjs ADDED
@@ -0,0 +1,108 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+ var _a;
3
+ import * as Core from "./core.mjs";
4
+ import * as Errors from "./error.mjs";
5
+ import * as Pagination from "./pagination.mjs";
6
+ import * as Uploads from "./uploads.mjs";
7
+ import * as API from "./resources/index.mjs";
8
+ import { FileObjectsLimitOffset, Files, } from "./resources/files.mjs";
9
+ import { Extractions } from "./resources/extractions/extractions.mjs";
10
+ import { Parsing } from "./resources/parsing/parsing.mjs";
11
+ import { VectorStores, VectorStoresLimitOffset, } from "./resources/vector-stores/vector-stores.mjs";
12
+ const environments = {
13
+ production: 'https://api.mixedbread.ai',
14
+ local: 'http://127.0.0.1:8000',
15
+ };
16
+ /**
17
+ * API Client for interfacing with the Mixedbread API.
18
+ */
19
+ export class Mixedbread extends Core.APIClient {
20
+ /**
21
+ * API Client for interfacing with the Mixedbread API.
22
+ *
23
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
24
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
25
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
26
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
27
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
28
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
29
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
30
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
31
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
32
+ */
33
+ constructor({ baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'), apiKey = Core.readEnv('MXBAI_API_KEY'), ...opts } = {}) {
34
+ if (apiKey === undefined) {
35
+ throw new Errors.MixedbreadError("The MXBAI_API_KEY environment variable is missing or empty; either provide it, or instantiate the Mixedbread client with an apiKey option, like new Mixedbread({ apiKey: 'My API Key' }).");
36
+ }
37
+ const options = {
38
+ apiKey,
39
+ ...opts,
40
+ baseURL,
41
+ environment: opts.environment ?? 'production',
42
+ };
43
+ if (baseURL && opts.environment) {
44
+ throw new Errors.MixedbreadError('Ambiguous URL; The `baseURL` option (or MIXEDBREAD_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null');
45
+ }
46
+ super({
47
+ baseURL: options.baseURL || environments[options.environment || 'production'],
48
+ timeout: options.timeout ?? 60000 /* 1 minute */,
49
+ httpAgent: options.httpAgent,
50
+ maxRetries: options.maxRetries,
51
+ fetch: options.fetch,
52
+ });
53
+ this.parsing = new API.Parsing(this);
54
+ this.files = new API.Files(this);
55
+ this.vectorStores = new API.VectorStores(this);
56
+ this.extractions = new API.Extractions(this);
57
+ this._options = options;
58
+ this.apiKey = apiKey;
59
+ }
60
+ /**
61
+ * Returns service information, including name and version.
62
+ *
63
+ * Returns: InfoResponse: A response containing the service name and version.
64
+ */
65
+ info(options) {
66
+ return this.get('/', options);
67
+ }
68
+ defaultQuery() {
69
+ return this._options.defaultQuery;
70
+ }
71
+ defaultHeaders(opts) {
72
+ return {
73
+ ...super.defaultHeaders(opts),
74
+ ...this._options.defaultHeaders,
75
+ };
76
+ }
77
+ authHeaders(opts) {
78
+ return { Authorization: `Bearer ${this.apiKey}` };
79
+ }
80
+ }
81
+ _a = Mixedbread;
82
+ Mixedbread.Mixedbread = _a;
83
+ Mixedbread.DEFAULT_TIMEOUT = 60000; // 1 minute
84
+ Mixedbread.MixedbreadError = Errors.MixedbreadError;
85
+ Mixedbread.APIError = Errors.APIError;
86
+ Mixedbread.APIConnectionError = Errors.APIConnectionError;
87
+ Mixedbread.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
88
+ Mixedbread.APIUserAbortError = Errors.APIUserAbortError;
89
+ Mixedbread.NotFoundError = Errors.NotFoundError;
90
+ Mixedbread.ConflictError = Errors.ConflictError;
91
+ Mixedbread.RateLimitError = Errors.RateLimitError;
92
+ Mixedbread.BadRequestError = Errors.BadRequestError;
93
+ Mixedbread.AuthenticationError = Errors.AuthenticationError;
94
+ Mixedbread.InternalServerError = Errors.InternalServerError;
95
+ Mixedbread.PermissionDeniedError = Errors.PermissionDeniedError;
96
+ Mixedbread.UnprocessableEntityError = Errors.UnprocessableEntityError;
97
+ Mixedbread.toFile = Uploads.toFile;
98
+ Mixedbread.fileFromPath = Uploads.fileFromPath;
99
+ Mixedbread.Parsing = Parsing;
100
+ Mixedbread.Files = Files;
101
+ Mixedbread.FileObjectsLimitOffset = FileObjectsLimitOffset;
102
+ Mixedbread.VectorStores = VectorStores;
103
+ Mixedbread.VectorStoresLimitOffset = VectorStoresLimitOffset;
104
+ Mixedbread.Extractions = Extractions;
105
+ export { toFile, fileFromPath } from "./uploads.mjs";
106
+ export { MixedbreadError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./error.mjs";
107
+ export default Mixedbread;
108
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;;OAG/E,KAAK,IAAI;OACT,KAAK,MAAM;OACX,KAAK,UAAU;OAEf,KAAK,OAAO;OACZ,KAAK,GAAG;OAGR,EAKL,sBAAsB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AAM,CAAC,mBAAmB,CAAC;AACjD,gCAAqB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACrD,mCAAwB,GAAG,MAAM,CAAC,wBAAwB,CAAC;AAE3D,iBAAM,GAAG,OAAO,CAAC,MAAM,CAAC;AACxB,uBAAY,GAAG,OAAO,CAAC,YAAY,CAAC;AAG7C,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;AAC7B,UAAU,CAAC,KAAK,GAAG,KAAK,CAAC;AACzB,UAAU,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;AAC3D,UAAU,CAAC,YAAY,GAAG,YAAY,CAAC;AACvC,UAAU,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;AAC7D,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;OA6C9B,EAAE,MAAM,EAAE,YAAY,EAAE;OACxB,EACL,eAAe,EACf,QAAQ,EACR,kBAAkB,EAClB,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB;AAED,eAAe,UAAU,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Utilities for polling operations
3
+ */
4
+ type ConditionFunction<T> = (result: T) => boolean;
5
+ type IntervalFunction<T> = (result: T) => number;
6
+ type ErrorHandlerFunction = (error: Error) => number | null;
7
+ type RetryCallback<T> = (result: T, attempt: number) => void;
8
+ /**
9
+ * Configuration options for the poll function.
10
+ */
11
+ export interface PollOptions<T> {
12
+ /** Async function that performs the operation to be polled */
13
+ fn: () => Promise<T>;
14
+ /** Function that evaluates if the polling should continue */
15
+ condition: ConditionFunction<T>;
16
+ /** Maximum number of polling attempts (undefined for infinite) */
17
+ maxAttempts?: number;
18
+ /** Maximum total time to poll in seconds (undefined for infinite) */
19
+ timeoutSeconds?: number;
20
+ /** Time between polls in seconds, or function that returns interval */
21
+ intervalSeconds?: number | IntervalFunction<T>;
22
+ /** Optional callback for each retry attempt */
23
+ onRetry?: RetryCallback<T>;
24
+ /** Optional callback for handling exceptions during polling */
25
+ errorHandler?: ErrorHandlerFunction;
26
+ }
27
+ /**
28
+ * Asynchronously polls an operation until a condition is met or timeout/max attempts are reached.
29
+ *
30
+ * @param options - Configuration options for polling
31
+ * @returns The result of the operation once condition is met
32
+ * @throws Error if maxAttempts is reached
33
+ * @throws Error if timeoutSeconds is reached
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const result = await poll({
38
+ * fn: () => fetchData(),
39
+ * condition: (result) => result.status === 'completed',
40
+ * maxAttempts: 5,
41
+ * timeoutSeconds: 60,
42
+ * intervalSeconds: 2
43
+ * });
44
+ * ```
45
+ */
46
+ export declare function poll<T>(options: PollOptions<T>): Promise<T>;
47
+ export {};
48
+ //# sourceMappingURL=polling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../src/lib/polling.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,KAAK,iBAAiB,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;AACnD,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC;AACjD,KAAK,oBAAoB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,IAAI,CAAC;AAC5D,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAK7D;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,8DAA8D;IAC9D,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,6DAA6D;IAC7D,SAAS,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAChC,kEAAkE;IAClE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uEAAuE;IACvE,eAAe,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC/C,+CAA+C;IAC/C,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAC3B,+DAA+D;IAC/D,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CA+DjE"}
package/lib/polling.js ADDED
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Utilities for polling operations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.poll = void 0;
7
+ /**
8
+ * Asynchronously polls an operation until a condition is met or timeout/max attempts are reached.
9
+ *
10
+ * @param options - Configuration options for polling
11
+ * @returns The result of the operation once condition is met
12
+ * @throws Error if maxAttempts is reached
13
+ * @throws Error if timeoutSeconds is reached
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const result = await poll({
18
+ * fn: () => fetchData(),
19
+ * condition: (result) => result.status === 'completed',
20
+ * maxAttempts: 5,
21
+ * timeoutSeconds: 60,
22
+ * intervalSeconds: 2
23
+ * });
24
+ * ```
25
+ */
26
+ async function poll(options) {
27
+ const { fn, condition, maxAttempts, timeoutSeconds, intervalSeconds = 1.0, onRetry, errorHandler, } = options;
28
+ const startTime = new Date();
29
+ let attempt = 0;
30
+ // eslint-disable-next-line no-constant-condition
31
+ while (true) {
32
+ attempt += 1;
33
+ try {
34
+ const result = await fn();
35
+ if (condition(result)) {
36
+ return result;
37
+ }
38
+ if (onRetry) {
39
+ onRetry(result, attempt);
40
+ }
41
+ let waitTime;
42
+ if (typeof intervalSeconds === 'function') {
43
+ waitTime = intervalSeconds(result);
44
+ }
45
+ else {
46
+ waitTime = intervalSeconds;
47
+ }
48
+ // Check timeout and attempts before sleeping
49
+ if (maxAttempts && attempt >= maxAttempts) {
50
+ throw new Error(`Maximum attempts (${maxAttempts}) reached`);
51
+ }
52
+ if (timeoutSeconds) {
53
+ const elapsed = (new Date().getTime() - startTime.getTime()) / 1000;
54
+ if (elapsed >= timeoutSeconds) {
55
+ throw new Error(`Timeout (${timeoutSeconds}s) reached`);
56
+ }
57
+ }
58
+ // Sleep asynchronously
59
+ await new Promise((resolve) => setTimeout(resolve, waitTime * 1000));
60
+ }
61
+ catch (e) {
62
+ if (errorHandler && e instanceof Error) {
63
+ const sleepTime = errorHandler(e);
64
+ if (sleepTime !== null) {
65
+ // Sleep and continue
66
+ await new Promise((resolve) => setTimeout(resolve, sleepTime * 1000));
67
+ continue;
68
+ }
69
+ }
70
+ throw e;
71
+ }
72
+ }
73
+ }
74
+ exports.poll = poll;
75
+ //# sourceMappingURL=polling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.js","sourceRoot":"","sources":["../src/lib/polling.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AA8BH;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,IAAI,CAAI,OAAuB;IACnD,MAAM,EACJ,EAAE,EACF,SAAS,EACT,WAAW,EACX,cAAc,EACd,eAAe,GAAG,GAAG,EACrB,OAAO,EACP,YAAY,GACb,GAAG,OAAO,CAAC;IAEZ,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,iDAAiD;IACjD,OAAO,IAAI,EAAE;QACX,OAAO,IAAI,CAAC,CAAC;QAEb,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC;YAE1B,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE;gBACrB,OAAO,MAAM,CAAC;aACf;YAED,IAAI,OAAO,EAAE;gBACX,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;aAC1B;YAED,IAAI,QAAgB,CAAC;YAErB,IAAI,OAAO,eAAe,KAAK,UAAU,EAAE;gBACzC,QAAQ,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;aACpC;iBAAM;gBACL,QAAQ,GAAG,eAAe,CAAC;aAC5B;YAED,6CAA6C;YAC7C,IAAI,WAAW,IAAI,OAAO,IAAI,WAAW,EAAE;gBACzC,MAAM,IAAI,KAAK,CAAC,qBAAqB,WAAW,WAAW,CAAC,CAAC;aAC9D;YAED,IAAI,cAAc,EAAE;gBAClB,MAAM,OAAO,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI,CAAC;gBACpE,IAAI,OAAO,IAAI,cAAc,EAAE;oBAC7B,MAAM,IAAI,KAAK,CAAC,YAAY,cAAc,YAAY,CAAC,CAAC;iBACzD;aACF;YAED,uBAAuB;YACvB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;SACtE;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,YAAY,IAAI,CAAC,YAAY,KAAK,EAAE;gBACtC,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,SAAS,KAAK,IAAI,EAAE;oBACtB,qBAAqB;oBACrB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;oBACtE,SAAS;iBACV;aACF;YACD,MAAM,CAAC,CAAC;SACT;KACF;AACH,CAAC;AA/DD,oBA+DC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Utilities for polling operations
3
+ */
4
+ /**
5
+ * Asynchronously polls an operation until a condition is met or timeout/max attempts are reached.
6
+ *
7
+ * @param options - Configuration options for polling
8
+ * @returns The result of the operation once condition is met
9
+ * @throws Error if maxAttempts is reached
10
+ * @throws Error if timeoutSeconds is reached
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const result = await poll({
15
+ * fn: () => fetchData(),
16
+ * condition: (result) => result.status === 'completed',
17
+ * maxAttempts: 5,
18
+ * timeoutSeconds: 60,
19
+ * intervalSeconds: 2
20
+ * });
21
+ * ```
22
+ */
23
+ export async function poll(options) {
24
+ const { fn, condition, maxAttempts, timeoutSeconds, intervalSeconds = 1.0, onRetry, errorHandler, } = options;
25
+ const startTime = new Date();
26
+ let attempt = 0;
27
+ // eslint-disable-next-line no-constant-condition
28
+ while (true) {
29
+ attempt += 1;
30
+ try {
31
+ const result = await fn();
32
+ if (condition(result)) {
33
+ return result;
34
+ }
35
+ if (onRetry) {
36
+ onRetry(result, attempt);
37
+ }
38
+ let waitTime;
39
+ if (typeof intervalSeconds === 'function') {
40
+ waitTime = intervalSeconds(result);
41
+ }
42
+ else {
43
+ waitTime = intervalSeconds;
44
+ }
45
+ // Check timeout and attempts before sleeping
46
+ if (maxAttempts && attempt >= maxAttempts) {
47
+ throw new Error(`Maximum attempts (${maxAttempts}) reached`);
48
+ }
49
+ if (timeoutSeconds) {
50
+ const elapsed = (new Date().getTime() - startTime.getTime()) / 1000;
51
+ if (elapsed >= timeoutSeconds) {
52
+ throw new Error(`Timeout (${timeoutSeconds}s) reached`);
53
+ }
54
+ }
55
+ // Sleep asynchronously
56
+ await new Promise((resolve) => setTimeout(resolve, waitTime * 1000));
57
+ }
58
+ catch (e) {
59
+ if (errorHandler && e instanceof Error) {
60
+ const sleepTime = errorHandler(e);
61
+ if (sleepTime !== null) {
62
+ // Sleep and continue
63
+ await new Promise((resolve) => setTimeout(resolve, sleepTime * 1000));
64
+ continue;
65
+ }
66
+ }
67
+ throw e;
68
+ }
69
+ }
70
+ }
71
+ //# sourceMappingURL=polling.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.mjs","sourceRoot":"","sources":["../src/lib/polling.ts"],"names":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U,CAAC,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;SACtE;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,YAAY,IAAI,CAAC,YAAY,KAAK,EAAE;gBACtC,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,SAAS,KAAK,IAAI,EAAE;oBACtB,qBAAqB;oBACrB,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC;oBACtE,SAAS;iBACV;aACF;YACD,MAAM,CAAC,CAAC;SACT;KACF;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,124 @@
1
+ {
2
+ "name": "@mixedbread/sdk",
3
+ "version": "0.1.0-alpha.8",
4
+ "description": "The official TypeScript library for the Mixedbread API",
5
+ "author": "Mixedbread <support@mixedbread.com>",
6
+ "types": "./index.d.ts",
7
+ "main": "./index.js",
8
+ "type": "commonjs",
9
+ "repository": "github:mixedbread-ai/mixedbread-ts",
10
+ "license": "Apache-2.0",
11
+ "packageManager": "yarn@1.22.22",
12
+ "files": [
13
+ "**/*"
14
+ ],
15
+ "private": false,
16
+ "scripts": {
17
+ "test": "./scripts/test",
18
+ "build": "./scripts/build",
19
+ "format": "prettier --write --cache --cache-strategy metadata . !dist",
20
+ "tsn": "ts-node -r tsconfig-paths/register",
21
+ "lint": "./scripts/lint",
22
+ "fix": "./scripts/format"
23
+ },
24
+ "dependencies": {
25
+ "@types/node": "^18.11.18",
26
+ "@types/node-fetch": "^2.6.4",
27
+ "abort-controller": "^3.0.0",
28
+ "agentkeepalive": "^4.2.1",
29
+ "form-data-encoder": "1.7.2",
30
+ "formdata-node": "^4.3.2",
31
+ "node-fetch": "^2.6.7"
32
+ },
33
+ "sideEffects": [
34
+ "./_shims/index.js",
35
+ "./_shims/index.mjs",
36
+ "./shims/node.js",
37
+ "./shims/node.mjs",
38
+ "./shims/web.js",
39
+ "./shims/web.mjs"
40
+ ],
41
+ "imports": {
42
+ "@mixedbread/sdk": ".",
43
+ "@mixedbread/sdk/*": "./src/*"
44
+ },
45
+ "exports": {
46
+ "./_shims/auto/*": {
47
+ "deno": {
48
+ "types": "./_shims/auto/*.d.ts",
49
+ "require": "./_shims/auto/*.js",
50
+ "default": "./_shims/auto/*.mjs"
51
+ },
52
+ "bun": {
53
+ "types": "./_shims/auto/*.d.ts",
54
+ "require": "./_shims/auto/*-bun.js",
55
+ "default": "./_shims/auto/*-bun.mjs"
56
+ },
57
+ "browser": {
58
+ "types": "./_shims/auto/*.d.ts",
59
+ "require": "./_shims/auto/*.js",
60
+ "default": "./_shims/auto/*.mjs"
61
+ },
62
+ "worker": {
63
+ "types": "./_shims/auto/*.d.ts",
64
+ "require": "./_shims/auto/*.js",
65
+ "default": "./_shims/auto/*.mjs"
66
+ },
67
+ "workerd": {
68
+ "types": "./_shims/auto/*.d.ts",
69
+ "require": "./_shims/auto/*.js",
70
+ "default": "./_shims/auto/*.mjs"
71
+ },
72
+ "node": {
73
+ "types": "./_shims/auto/*-node.d.ts",
74
+ "require": "./_shims/auto/*-node.js",
75
+ "default": "./_shims/auto/*-node.mjs"
76
+ },
77
+ "types": "./_shims/auto/*.d.ts",
78
+ "require": "./_shims/auto/*.js",
79
+ "default": "./_shims/auto/*.mjs"
80
+ },
81
+ ".": {
82
+ "require": {
83
+ "types": "./index.d.ts",
84
+ "default": "./index.js"
85
+ },
86
+ "types": "./index.d.mts",
87
+ "default": "./index.mjs"
88
+ },
89
+ "./*.mjs": {
90
+ "types": [
91
+ "./*.d.ts",
92
+ "./*/index.d.ts"
93
+ ],
94
+ "default": [
95
+ "./*.mjs",
96
+ "./*/index.mjs"
97
+ ]
98
+ },
99
+ "./*.js": {
100
+ "types": [
101
+ "./*.d.ts",
102
+ "./*/index.d.ts"
103
+ ],
104
+ "default": [
105
+ "./*.js",
106
+ "./*/index.js"
107
+ ]
108
+ },
109
+ "./*": {
110
+ "types": [
111
+ "./*.d.ts",
112
+ "./*/index.d.ts"
113
+ ],
114
+ "require": [
115
+ "./*.js",
116
+ "./*/index.js"
117
+ ],
118
+ "default": [
119
+ "./*.mjs",
120
+ "./*/index.mjs"
121
+ ]
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,30 @@
1
+ import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from "./core.js";
2
+ export interface LimitOffsetResponse<Item> {
3
+ data: Array<Item>;
4
+ pagination: LimitOffsetResponse.Pagination;
5
+ }
6
+ export declare namespace LimitOffsetResponse {
7
+ interface Pagination {
8
+ total?: number;
9
+ offset?: number;
10
+ }
11
+ }
12
+ export interface LimitOffsetParams {
13
+ /**
14
+ * The number of elements to skip.
15
+ */
16
+ offset?: number;
17
+ /**
18
+ * The maximum number of elements to fetch.
19
+ */
20
+ limit?: number;
21
+ }
22
+ export declare class LimitOffset<Item> extends AbstractPage<Item> implements LimitOffsetResponse<Item> {
23
+ data: Array<Item>;
24
+ pagination: LimitOffsetResponse.Pagination;
25
+ constructor(client: APIClient, response: Response, body: LimitOffsetResponse<Item>, options: FinalRequestOptions);
26
+ getPaginatedItems(): Item[];
27
+ nextPageParams(): Partial<LimitOffsetParams> | null;
28
+ nextPageInfo(): PageInfo | null;
29
+ }
30
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["src/pagination.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE1F,MAAM,WAAW,mBAAmB,CAAC,IAAI;IACvC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAElB,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC;CAC5C;AAED,yBAAiB,mBAAmB,CAAC;IACnC,UAAiB,UAAU;QACzB,KAAK,CAAC,EAAE,MAAM,CAAC;QAEf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB;CACF;AAED,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,WAAW,CAAC,IAAI,CAAE,SAAQ,YAAY,CAAC,IAAI,CAAE,YAAW,mBAAmB,CAAC,IAAI,CAAC;IAC5F,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAElB,UAAU,EAAE,mBAAmB,CAAC,UAAU,CAAC;gBAGzC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,mBAAmB,CAAC,IAAI,CAAC,EAC/B,OAAO,EAAE,mBAAmB;IAQ9B,iBAAiB,IAAI,IAAI,EAAE;IAK3B,cAAc,IAAI,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI;IASnD,YAAY,IAAI,QAAQ,GAAG,IAAI;CAoBhC"}