@mixedbread/sdk 0.1.0-alpha.10

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 (284) hide show
  1. package/CHANGELOG.md +230 -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 +915 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +883 -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 +169 -0
  87. package/index.d.ts +169 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +175 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +132 -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/embeddings.d.ts +177 -0
  113. package/resources/embeddings.d.ts.map +1 -0
  114. package/resources/embeddings.js +20 -0
  115. package/resources/embeddings.js.map +1 -0
  116. package/resources/embeddings.mjs +16 -0
  117. package/resources/embeddings.mjs.map +1 -0
  118. package/resources/extractions/content.d.ts +33 -0
  119. package/resources/extractions/content.d.ts.map +1 -0
  120. package/resources/extractions/content.js +19 -0
  121. package/resources/extractions/content.js.map +1 -0
  122. package/resources/extractions/content.mjs +15 -0
  123. package/resources/extractions/content.mjs.map +1 -0
  124. package/resources/extractions/extractions.d.ts +18 -0
  125. package/resources/extractions/extractions.d.ts.map +1 -0
  126. package/resources/extractions/extractions.js +47 -0
  127. package/resources/extractions/extractions.js.map +1 -0
  128. package/resources/extractions/extractions.mjs +20 -0
  129. package/resources/extractions/extractions.mjs.map +1 -0
  130. package/resources/extractions/index.d.ts +5 -0
  131. package/resources/extractions/index.d.ts.map +1 -0
  132. package/resources/extractions/index.js +13 -0
  133. package/resources/extractions/index.js.map +1 -0
  134. package/resources/extractions/index.mjs +6 -0
  135. package/resources/extractions/index.mjs.map +1 -0
  136. package/resources/extractions/jobs.d.ts +84 -0
  137. package/resources/extractions/jobs.d.ts.map +1 -0
  138. package/resources/extractions/jobs.js +29 -0
  139. package/resources/extractions/jobs.js.map +1 -0
  140. package/resources/extractions/jobs.mjs +25 -0
  141. package/resources/extractions/jobs.mjs.map +1 -0
  142. package/resources/extractions/schema.d.ts +85 -0
  143. package/resources/extractions/schema.d.ts.map +1 -0
  144. package/resources/extractions/schema.js +39 -0
  145. package/resources/extractions/schema.js.map +1 -0
  146. package/resources/extractions/schema.mjs +35 -0
  147. package/resources/extractions/schema.mjs.map +1 -0
  148. package/resources/files.d.ts +125 -0
  149. package/resources/files.d.ts.map +1 -0
  150. package/resources/files.js +99 -0
  151. package/resources/files.js.map +1 -0
  152. package/resources/files.mjs +71 -0
  153. package/resources/files.mjs.map +1 -0
  154. package/resources/index.d.ts +8 -0
  155. package/resources/index.d.ts.map +1 -0
  156. package/resources/index.js +32 -0
  157. package/resources/index.js.map +1 -0
  158. package/resources/index.mjs +8 -0
  159. package/resources/index.mjs.map +1 -0
  160. package/resources/parsing/index.d.ts +3 -0
  161. package/resources/parsing/index.d.ts.map +1 -0
  162. package/resources/parsing/index.js +10 -0
  163. package/resources/parsing/index.js.map +1 -0
  164. package/resources/parsing/index.mjs +4 -0
  165. package/resources/parsing/index.mjs.map +1 -0
  166. package/resources/parsing/jobs.d.ts +290 -0
  167. package/resources/parsing/jobs.d.ts.map +1 -0
  168. package/resources/parsing/jobs.js +147 -0
  169. package/resources/parsing/jobs.js.map +1 -0
  170. package/resources/parsing/jobs.mjs +119 -0
  171. package/resources/parsing/jobs.mjs.map +1 -0
  172. package/resources/parsing/parsing.d.ts +10 -0
  173. package/resources/parsing/parsing.d.ts.map +1 -0
  174. package/resources/parsing/parsing.js +40 -0
  175. package/resources/parsing/parsing.js.map +1 -0
  176. package/resources/parsing/parsing.mjs +13 -0
  177. package/resources/parsing/parsing.mjs.map +1 -0
  178. package/resources/shared.d.ts +35 -0
  179. package/resources/shared.d.ts.map +1 -0
  180. package/resources/shared.js +4 -0
  181. package/resources/shared.js.map +1 -0
  182. package/resources/shared.mjs +3 -0
  183. package/resources/shared.mjs.map +1 -0
  184. package/resources/top-level.d.ts +165 -0
  185. package/resources/top-level.d.ts.map +1 -0
  186. package/resources/top-level.js +4 -0
  187. package/resources/top-level.js.map +1 -0
  188. package/resources/top-level.mjs +3 -0
  189. package/resources/top-level.mjs.map +1 -0
  190. package/resources/vector-stores/files.d.ts +284 -0
  191. package/resources/vector-stores/files.d.ts.map +1 -0
  192. package/resources/vector-stores/files.js +167 -0
  193. package/resources/vector-stores/files.js.map +1 -0
  194. package/resources/vector-stores/files.mjs +139 -0
  195. package/resources/vector-stores/files.mjs.map +1 -0
  196. package/resources/vector-stores/index.d.ts +3 -0
  197. package/resources/vector-stores/index.d.ts.map +1 -0
  198. package/resources/vector-stores/index.js +11 -0
  199. package/resources/vector-stores/index.js.map +1 -0
  200. package/resources/vector-stores/index.mjs +4 -0
  201. package/resources/vector-stores/index.mjs.map +1 -0
  202. package/resources/vector-stores/vector-stores.d.ts +425 -0
  203. package/resources/vector-stores/vector-stores.d.ts.map +1 -0
  204. package/resources/vector-stores/vector-stores.js +121 -0
  205. package/resources/vector-stores/vector-stores.js.map +1 -0
  206. package/resources/vector-stores/vector-stores.mjs +93 -0
  207. package/resources/vector-stores/vector-stores.mjs.map +1 -0
  208. package/shims/node.d.ts +30 -0
  209. package/shims/node.d.ts.map +1 -0
  210. package/shims/node.js +31 -0
  211. package/shims/node.js.map +1 -0
  212. package/shims/node.mjs +5 -0
  213. package/shims/node.mjs.map +1 -0
  214. package/shims/web.d.ts +26 -0
  215. package/shims/web.d.ts.map +1 -0
  216. package/shims/web.js +31 -0
  217. package/shims/web.js.map +1 -0
  218. package/shims/web.mjs +5 -0
  219. package/shims/web.mjs.map +1 -0
  220. package/src/_shims/MultipartBody.ts +9 -0
  221. package/src/_shims/README.md +46 -0
  222. package/src/_shims/auto/runtime-bun.ts +4 -0
  223. package/src/_shims/auto/runtime-node.ts +4 -0
  224. package/src/_shims/auto/runtime.ts +4 -0
  225. package/src/_shims/auto/types-node.ts +4 -0
  226. package/src/_shims/auto/types.d.ts +101 -0
  227. package/src/_shims/auto/types.js +3 -0
  228. package/src/_shims/auto/types.mjs +3 -0
  229. package/src/_shims/bun-runtime.ts +14 -0
  230. package/src/_shims/index.d.ts +81 -0
  231. package/src/_shims/index.js +13 -0
  232. package/src/_shims/index.mjs +7 -0
  233. package/src/_shims/manual-types.d.ts +12 -0
  234. package/src/_shims/manual-types.js +3 -0
  235. package/src/_shims/manual-types.mjs +3 -0
  236. package/src/_shims/node-runtime.ts +81 -0
  237. package/src/_shims/node-types.d.ts +42 -0
  238. package/src/_shims/node-types.js +3 -0
  239. package/src/_shims/node-types.mjs +3 -0
  240. package/src/_shims/registry.ts +67 -0
  241. package/src/_shims/web-runtime.ts +103 -0
  242. package/src/_shims/web-types.d.ts +83 -0
  243. package/src/_shims/web-types.js +3 -0
  244. package/src/_shims/web-types.mjs +3 -0
  245. package/src/core.ts +1208 -0
  246. package/src/error.ts +130 -0
  247. package/src/index.ts +346 -0
  248. package/src/lib/.keep +4 -0
  249. package/src/lib/polling.ts +115 -0
  250. package/src/pagination.ts +82 -0
  251. package/src/resource.ts +11 -0
  252. package/src/resources/embeddings.ts +248 -0
  253. package/src/resources/extractions/content.ts +42 -0
  254. package/src/resources/extractions/extractions.ts +47 -0
  255. package/src/resources/extractions/index.ts +14 -0
  256. package/src/resources/extractions/jobs.ts +105 -0
  257. package/src/resources/extractions/schema.ts +111 -0
  258. package/src/resources/files.ts +181 -0
  259. package/src/resources/index.ts +39 -0
  260. package/src/resources/parsing/index.ts +12 -0
  261. package/src/resources/parsing/jobs.ts +453 -0
  262. package/src/resources/parsing/parsing.ts +32 -0
  263. package/src/resources/shared.ts +41 -0
  264. package/src/resources/top-level.ts +231 -0
  265. package/src/resources/vector-stores/files.ts +439 -0
  266. package/src/resources/vector-stores/index.ts +31 -0
  267. package/src/resources/vector-stores/vector-stores.ts +592 -0
  268. package/src/shims/node.ts +50 -0
  269. package/src/shims/web.ts +50 -0
  270. package/src/tsconfig.json +11 -0
  271. package/src/uploads.ts +255 -0
  272. package/src/version.ts +1 -0
  273. package/uploads.d.ts +75 -0
  274. package/uploads.d.ts.map +1 -0
  275. package/uploads.js +171 -0
  276. package/uploads.js.map +1 -0
  277. package/uploads.mjs +158 -0
  278. package/uploads.mjs.map +1 -0
  279. package/version.d.ts +2 -0
  280. package/version.d.ts.map +1 -0
  281. package/version.js +5 -0
  282. package/version.js.map +1 -0
  283. package/version.mjs +2 -0
  284. package/version.mjs.map +1 -0
package/index.d.ts ADDED
@@ -0,0 +1,169 @@
1
+ import { type Agent } from "./_shims/index.js";
2
+ import * as Core from "./core.js";
3
+ import * as Errors from "./error.js";
4
+ import * as Pagination from "./pagination.js";
5
+ import { type LimitOffsetParams, LimitOffsetResponse } from "./pagination.js";
6
+ import * as Uploads from "./uploads.js";
7
+ import * as EmbeddingsAPI from "./resources/embeddings.js";
8
+ import { Embedding, EmbeddingCreateParams, EmbeddingCreateResponse, Embeddings } from "./resources/embeddings.js";
9
+ import * as API from "./resources/index.js";
10
+ import * as TopLevelAPI from "./resources/top-level.js";
11
+ import { EmbedParams, InfoResponse, RerankParams, RerankResponse } from "./resources/top-level.js";
12
+ import { FileCreateParams, FileDeleteResponse, FileListParams, FileObject, FileObjectsLimitOffset, FileUpdateParams, Files } from "./resources/files.js";
13
+ import { Extractions } from "./resources/extractions/extractions.js";
14
+ import { Parsing } from "./resources/parsing/parsing.js";
15
+ import { ExpiresAfter, FileCounts, ScoredVectorStoreChunk, VectorStore, VectorStoreChunkSearchOptions, VectorStoreCreateParams, VectorStoreDeleteResponse, VectorStoreFileSearchOptions, VectorStoreListParams, VectorStoreQuestionAnsweringParams, VectorStoreQuestionAnsweringResponse, VectorStoreSearchParams, VectorStoreSearchResponse, VectorStoreUpdateParams, VectorStores, VectorStoresLimitOffset } from "./resources/vector-stores/vector-stores.js";
16
+ declare const environments: {
17
+ production: string;
18
+ local: string;
19
+ };
20
+ type Environment = keyof typeof environments;
21
+ export interface ClientOptions {
22
+ /**
23
+ * Api key to authenticate with Mixedbread
24
+ */
25
+ apiKey?: string | undefined;
26
+ /**
27
+ * Specifies the environment to use for the API.
28
+ *
29
+ * Each environment maps to a different base URL:
30
+ * - `production` corresponds to `https://api.mixedbread.ai`
31
+ * - `local` corresponds to `http://127.0.0.1:8000`
32
+ */
33
+ environment?: Environment | undefined;
34
+ /**
35
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
36
+ *
37
+ * Defaults to process.env['MIXEDBREAD_BASE_URL'].
38
+ */
39
+ baseURL?: string | null | undefined;
40
+ /**
41
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
42
+ * from the server before timing out a single request.
43
+ *
44
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
45
+ * much longer than this timeout before the promise succeeds or fails.
46
+ */
47
+ timeout?: number | undefined;
48
+ /**
49
+ * An HTTP agent used to manage HTTP(S) connections.
50
+ *
51
+ * If not provided, an agent will be constructed by default in the Node.js environment,
52
+ * otherwise no agent is used.
53
+ */
54
+ httpAgent?: Agent | undefined;
55
+ /**
56
+ * Specify a custom `fetch` function implementation.
57
+ *
58
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
59
+ * defined globally.
60
+ */
61
+ fetch?: Core.Fetch | undefined;
62
+ /**
63
+ * The maximum number of times that the client will retry a request in case of a
64
+ * temporary failure, like a network error or a 5XX error from the server.
65
+ *
66
+ * @default 2
67
+ */
68
+ maxRetries?: number | undefined;
69
+ /**
70
+ * Default headers to include with every request to the API.
71
+ *
72
+ * These can be removed in individual requests by explicitly setting the
73
+ * header to `undefined` or `null` in request options.
74
+ */
75
+ defaultHeaders?: Core.Headers | undefined;
76
+ /**
77
+ * Default query parameters to include with every request to the API.
78
+ *
79
+ * These can be removed in individual requests by explicitly setting the
80
+ * param to `undefined` in request options.
81
+ */
82
+ defaultQuery?: Core.DefaultQuery | undefined;
83
+ }
84
+ /**
85
+ * API Client for interfacing with the Mixedbread API.
86
+ */
87
+ export declare class Mixedbread extends Core.APIClient {
88
+ apiKey: string;
89
+ private _options;
90
+ /**
91
+ * API Client for interfacing with the Mixedbread API.
92
+ *
93
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
94
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
95
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
96
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
97
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
98
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
99
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
100
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
101
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
102
+ */
103
+ constructor({ baseURL, apiKey, ...opts }?: ClientOptions);
104
+ embeddings: API.Embeddings;
105
+ parsing: API.Parsing;
106
+ files: API.Files;
107
+ vectorStores: API.VectorStores;
108
+ extractions: API.Extractions;
109
+ /**
110
+ * Create embeddings for text or images using the specified model, encoding format,
111
+ * and normalization.
112
+ *
113
+ * Args: params: The parameters for creating embeddings.
114
+ *
115
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
116
+ */
117
+ embed(body: TopLevelAPI.EmbedParams, options?: Core.RequestOptions): Core.APIPromise<EmbeddingsAPI.EmbeddingCreateResponse>;
118
+ /**
119
+ * Returns service information, including name and version.
120
+ *
121
+ * Returns: InfoResponse: A response containing the service name and version.
122
+ */
123
+ info(options?: Core.RequestOptions): Core.APIPromise<TopLevelAPI.InfoResponse>;
124
+ /**
125
+ * Rerank different kind of documents for a given query.
126
+ *
127
+ * Args: params: RerankingCreateParams: The parameters for reranking.
128
+ *
129
+ * Returns: RerankingCreateResponse: The reranked documents for the input query.
130
+ */
131
+ rerank(body: TopLevelAPI.RerankParams, options?: Core.RequestOptions): Core.APIPromise<TopLevelAPI.RerankResponse>;
132
+ protected defaultQuery(): Core.DefaultQuery | undefined;
133
+ protected defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers;
134
+ protected authHeaders(opts: Core.FinalRequestOptions): Core.Headers;
135
+ static Mixedbread: typeof Mixedbread;
136
+ static DEFAULT_TIMEOUT: number;
137
+ static MixedbreadError: typeof Errors.MixedbreadError;
138
+ static APIError: typeof Errors.APIError;
139
+ static APIConnectionError: typeof Errors.APIConnectionError;
140
+ static APIConnectionTimeoutError: typeof Errors.APIConnectionTimeoutError;
141
+ static APIUserAbortError: typeof Errors.APIUserAbortError;
142
+ static NotFoundError: typeof Errors.NotFoundError;
143
+ static ConflictError: typeof Errors.ConflictError;
144
+ static RateLimitError: typeof Errors.RateLimitError;
145
+ static BadRequestError: typeof Errors.BadRequestError;
146
+ static AuthenticationError: typeof Errors.AuthenticationError;
147
+ static InternalServerError: typeof Errors.InternalServerError;
148
+ static PermissionDeniedError: typeof Errors.PermissionDeniedError;
149
+ static UnprocessableEntityError: typeof Errors.UnprocessableEntityError;
150
+ static toFile: typeof Uploads.toFile;
151
+ static fileFromPath: typeof Uploads.fileFromPath;
152
+ }
153
+ export declare namespace Mixedbread {
154
+ export type RequestOptions = Core.RequestOptions;
155
+ export import LimitOffset = Pagination.LimitOffset;
156
+ export { type LimitOffsetParams as LimitOffsetParams, type LimitOffsetResponse as LimitOffsetResponse };
157
+ export { type InfoResponse as InfoResponse, type RerankResponse as RerankResponse, type EmbedParams as EmbedParams, type RerankParams as RerankParams, };
158
+ export { Embeddings as Embeddings, type Embedding as Embedding, type EmbeddingCreateResponse as EmbeddingCreateResponse, type EmbeddingCreateParams as EmbeddingCreateParams, };
159
+ export { Parsing as Parsing };
160
+ export { Files as Files, type FileObject as FileObject, type FileDeleteResponse as FileDeleteResponse, FileObjectsLimitOffset as FileObjectsLimitOffset, type FileCreateParams as FileCreateParams, type FileUpdateParams as FileUpdateParams, type FileListParams as FileListParams, };
161
+ export { VectorStores as VectorStores, type ExpiresAfter as ExpiresAfter, type FileCounts as FileCounts, type ScoredVectorStoreChunk as ScoredVectorStoreChunk, type VectorStore as VectorStore, type VectorStoreChunkSearchOptions as VectorStoreChunkSearchOptions, type VectorStoreFileSearchOptions as VectorStoreFileSearchOptions, type VectorStoreDeleteResponse as VectorStoreDeleteResponse, type VectorStoreQuestionAnsweringResponse as VectorStoreQuestionAnsweringResponse, type VectorStoreSearchResponse as VectorStoreSearchResponse, VectorStoresLimitOffset as VectorStoresLimitOffset, type VectorStoreCreateParams as VectorStoreCreateParams, type VectorStoreUpdateParams as VectorStoreUpdateParams, type VectorStoreListParams as VectorStoreListParams, type VectorStoreQuestionAnsweringParams as VectorStoreQuestionAnsweringParams, type VectorStoreSearchParams as VectorStoreSearchParams, };
162
+ export { Extractions as Extractions };
163
+ export type SearchFilter = API.SearchFilter;
164
+ export type SearchFilterCondition = API.SearchFilterCondition;
165
+ }
166
+ export { toFile, fileFromPath } from "./uploads.js";
167
+ export { MixedbreadError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./error.js";
168
+ export default Mixedbread;
169
+ //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC;AAC/B,OAAO,KAAK,MAAM,MAAM,SAAS,CA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CAAC;CAC/D;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,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,MAAM,SAAS,CAAC;AAEjB,eAAe,UAAU,CAAC"}
package/index.js ADDED
@@ -0,0 +1,175 @@
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 embeddings_1 = require("./resources/embeddings.js");
34
+ const API = __importStar(require("./resources/index.js"));
35
+ const files_1 = require("./resources/files.js");
36
+ const extractions_1 = require("./resources/extractions/extractions.js");
37
+ const parsing_1 = require("./resources/parsing/parsing.js");
38
+ const vector_stores_1 = require("./resources/vector-stores/vector-stores.js");
39
+ const environments = {
40
+ production: 'https://api.mixedbread.ai',
41
+ local: 'http://127.0.0.1:8000',
42
+ };
43
+ /**
44
+ * API Client for interfacing with the Mixedbread API.
45
+ */
46
+ class Mixedbread extends Core.APIClient {
47
+ /**
48
+ * API Client for interfacing with the Mixedbread API.
49
+ *
50
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
51
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
52
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
53
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
54
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
55
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
56
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
57
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
58
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
59
+ */
60
+ constructor({ baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'), apiKey = Core.readEnv('MXBAI_API_KEY'), ...opts } = {}) {
61
+ if (apiKey === undefined) {
62
+ 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' }).");
63
+ }
64
+ const options = {
65
+ apiKey,
66
+ ...opts,
67
+ baseURL,
68
+ environment: opts.environment ?? 'production',
69
+ };
70
+ if (baseURL && opts.environment) {
71
+ 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');
72
+ }
73
+ super({
74
+ baseURL: options.baseURL || environments[options.environment || 'production'],
75
+ timeout: options.timeout ?? 60000 /* 1 minute */,
76
+ httpAgent: options.httpAgent,
77
+ maxRetries: options.maxRetries,
78
+ fetch: options.fetch,
79
+ });
80
+ this.embeddings = new API.Embeddings(this);
81
+ this.parsing = new API.Parsing(this);
82
+ this.files = new API.Files(this);
83
+ this.vectorStores = new API.VectorStores(this);
84
+ this.extractions = new API.Extractions(this);
85
+ this._options = options;
86
+ this.apiKey = apiKey;
87
+ }
88
+ /**
89
+ * Create embeddings for text or images using the specified model, encoding format,
90
+ * and normalization.
91
+ *
92
+ * Args: params: The parameters for creating embeddings.
93
+ *
94
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
95
+ */
96
+ embed(body, options) {
97
+ return this.post('/v1/embeddings', { body, ...options });
98
+ }
99
+ /**
100
+ * Returns service information, including name and version.
101
+ *
102
+ * Returns: InfoResponse: A response containing the service name and version.
103
+ */
104
+ info(options) {
105
+ return this.get('/', options);
106
+ }
107
+ /**
108
+ * Rerank different kind of documents for a given query.
109
+ *
110
+ * Args: params: RerankingCreateParams: The parameters for reranking.
111
+ *
112
+ * Returns: RerankingCreateResponse: The reranked documents for the input query.
113
+ */
114
+ rerank(body, options) {
115
+ return this.post('/v1/reranking', { body, ...options });
116
+ }
117
+ defaultQuery() {
118
+ return this._options.defaultQuery;
119
+ }
120
+ defaultHeaders(opts) {
121
+ return {
122
+ ...super.defaultHeaders(opts),
123
+ ...this._options.defaultHeaders,
124
+ };
125
+ }
126
+ authHeaders(opts) {
127
+ return { Authorization: `Bearer ${this.apiKey}` };
128
+ }
129
+ }
130
+ exports.Mixedbread = Mixedbread;
131
+ _a = Mixedbread;
132
+ Mixedbread.Mixedbread = _a;
133
+ Mixedbread.DEFAULT_TIMEOUT = 60000; // 1 minute
134
+ Mixedbread.MixedbreadError = Errors.MixedbreadError;
135
+ Mixedbread.APIError = Errors.APIError;
136
+ Mixedbread.APIConnectionError = Errors.APIConnectionError;
137
+ Mixedbread.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
138
+ Mixedbread.APIUserAbortError = Errors.APIUserAbortError;
139
+ Mixedbread.NotFoundError = Errors.NotFoundError;
140
+ Mixedbread.ConflictError = Errors.ConflictError;
141
+ Mixedbread.RateLimitError = Errors.RateLimitError;
142
+ Mixedbread.BadRequestError = Errors.BadRequestError;
143
+ Mixedbread.AuthenticationError = Errors.AuthenticationError;
144
+ Mixedbread.InternalServerError = Errors.InternalServerError;
145
+ Mixedbread.PermissionDeniedError = Errors.PermissionDeniedError;
146
+ Mixedbread.UnprocessableEntityError = Errors.UnprocessableEntityError;
147
+ Mixedbread.toFile = Uploads.toFile;
148
+ Mixedbread.fileFromPath = Uploads.fileFromPath;
149
+ Mixedbread.Embeddings = embeddings_1.Embeddings;
150
+ Mixedbread.Parsing = parsing_1.Parsing;
151
+ Mixedbread.Files = files_1.Files;
152
+ Mixedbread.FileObjectsLimitOffset = files_1.FileObjectsLimitOffset;
153
+ Mixedbread.VectorStores = vector_stores_1.VectorStores;
154
+ Mixedbread.VectorStoresLimitOffset = vector_stores_1.VectorStoresLimitOffset;
155
+ Mixedbread.Extractions = extractions_1.Extractions;
156
+ var uploads_1 = require("./uploads.js");
157
+ Object.defineProperty(exports, "toFile", { enumerable: true, get: function () { return uploads_1.toFile; } });
158
+ Object.defineProperty(exports, "fileFromPath", { enumerable: true, get: function () { return uploads_1.fileFromPath; } });
159
+ var error_1 = require("./error.js");
160
+ Object.defineProperty(exports, "MixedbreadError", { enumerable: true, get: function () { return error_1.MixedbreadError; } });
161
+ Object.defineProperty(exports, "APIError", { enumerable: true, get: function () { return error_1.APIError; } });
162
+ Object.defineProperty(exports, "APIConnectionError", { enumerable: true, get: function () { return error_1.APIConnectionError; } });
163
+ Object.defineProperty(exports, "APIConnectionTimeoutError", { enumerable: true, get: function () { return error_1.APIConnectionTimeoutError; } });
164
+ Object.defineProperty(exports, "APIUserAbortError", { enumerable: true, get: function () { return error_1.APIUserAbortError; } });
165
+ Object.defineProperty(exports, "NotFoundError", { enumerable: true, get: function () { return error_1.NotFoundError; } });
166
+ Object.defineProperty(exports, "ConflictError", { enumerable: true, get: function () { return error_1.ConflictError; } });
167
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_1.RateLimitError; } });
168
+ Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return error_1.BadRequestError; } });
169
+ Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return error_1.AuthenticationError; } });
170
+ Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_1.InternalServerError; } });
171
+ Object.defineProperty(exports, "PermissionDeniedError", { enumerable: true, get: function () { return error_1.PermissionDeniedError; } });
172
+ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, get: function () { return error_1.UnprocessableEntityError; } });
173
+ exports = module.exports = Mixedbread;
174
+ exports.default = Mixedbread;
175
+ //# 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;AAErC,0DAKgC;AAChC,0DAAyC;AAGzC,gDAQ2B;AAC3B,wEAAkE;AAClE,4DAAsD;AACtD,8EAiBiD;AAEjD,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,2BAA2B;IACvC,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.mjs ADDED
@@ -0,0 +1,132 @@
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 { Embeddings, } from "./resources/embeddings.mjs";
8
+ import * as API from "./resources/index.mjs";
9
+ import { FileObjectsLimitOffset, Files, } from "./resources/files.mjs";
10
+ import { Extractions } from "./resources/extractions/extractions.mjs";
11
+ import { Parsing } from "./resources/parsing/parsing.mjs";
12
+ import { VectorStores, VectorStoresLimitOffset, } from "./resources/vector-stores/vector-stores.mjs";
13
+ const environments = {
14
+ production: 'https://api.mixedbread.ai',
15
+ local: 'http://127.0.0.1:8000',
16
+ };
17
+ /**
18
+ * API Client for interfacing with the Mixedbread API.
19
+ */
20
+ export class Mixedbread extends Core.APIClient {
21
+ /**
22
+ * API Client for interfacing with the Mixedbread API.
23
+ *
24
+ * @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
25
+ * @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
26
+ * @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
27
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
28
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
29
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
30
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
31
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
32
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
33
+ */
34
+ constructor({ baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'), apiKey = Core.readEnv('MXBAI_API_KEY'), ...opts } = {}) {
35
+ if (apiKey === undefined) {
36
+ 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' }).");
37
+ }
38
+ const options = {
39
+ apiKey,
40
+ ...opts,
41
+ baseURL,
42
+ environment: opts.environment ?? 'production',
43
+ };
44
+ if (baseURL && opts.environment) {
45
+ 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');
46
+ }
47
+ super({
48
+ baseURL: options.baseURL || environments[options.environment || 'production'],
49
+ timeout: options.timeout ?? 60000 /* 1 minute */,
50
+ httpAgent: options.httpAgent,
51
+ maxRetries: options.maxRetries,
52
+ fetch: options.fetch,
53
+ });
54
+ this.embeddings = new API.Embeddings(this);
55
+ this.parsing = new API.Parsing(this);
56
+ this.files = new API.Files(this);
57
+ this.vectorStores = new API.VectorStores(this);
58
+ this.extractions = new API.Extractions(this);
59
+ this._options = options;
60
+ this.apiKey = apiKey;
61
+ }
62
+ /**
63
+ * Create embeddings for text or images using the specified model, encoding format,
64
+ * and normalization.
65
+ *
66
+ * Args: params: The parameters for creating embeddings.
67
+ *
68
+ * Returns: EmbeddingCreateResponse: The response containing the embeddings.
69
+ */
70
+ embed(body, options) {
71
+ return this.post('/v1/embeddings', { body, ...options });
72
+ }
73
+ /**
74
+ * Returns service information, including name and version.
75
+ *
76
+ * Returns: InfoResponse: A response containing the service name and version.
77
+ */
78
+ info(options) {
79
+ return this.get('/', options);
80
+ }
81
+ /**
82
+ * Rerank different kind of documents for a given query.
83
+ *
84
+ * Args: params: RerankingCreateParams: The parameters for reranking.
85
+ *
86
+ * Returns: RerankingCreateResponse: The reranked documents for the input query.
87
+ */
88
+ rerank(body, options) {
89
+ return this.post('/v1/reranking', { body, ...options });
90
+ }
91
+ defaultQuery() {
92
+ return this._options.defaultQuery;
93
+ }
94
+ defaultHeaders(opts) {
95
+ return {
96
+ ...super.defaultHeaders(opts),
97
+ ...this._options.defaultHeaders,
98
+ };
99
+ }
100
+ authHeaders(opts) {
101
+ return { Authorization: `Bearer ${this.apiKey}` };
102
+ }
103
+ }
104
+ _a = Mixedbread;
105
+ Mixedbread.Mixedbread = _a;
106
+ Mixedbread.DEFAULT_TIMEOUT = 60000; // 1 minute
107
+ Mixedbread.MixedbreadError = Errors.MixedbreadError;
108
+ Mixedbread.APIError = Errors.APIError;
109
+ Mixedbread.APIConnectionError = Errors.APIConnectionError;
110
+ Mixedbread.APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
111
+ Mixedbread.APIUserAbortError = Errors.APIUserAbortError;
112
+ Mixedbread.NotFoundError = Errors.NotFoundError;
113
+ Mixedbread.ConflictError = Errors.ConflictError;
114
+ Mixedbread.RateLimitError = Errors.RateLimitError;
115
+ Mixedbread.BadRequestError = Errors.BadRequestError;
116
+ Mixedbread.AuthenticationError = Errors.AuthenticationError;
117
+ Mixedbread.InternalServerError = Errors.InternalServerError;
118
+ Mixedbread.PermissionDeniedError = Errors.PermissionDeniedError;
119
+ Mixedbread.UnprocessableEntityError = Errors.UnprocessableEntityError;
120
+ Mixedbread.toFile = Uploads.toFile;
121
+ Mixedbread.fileFromPath = Uploads.fileFromPath;
122
+ Mixedbread.Embeddings = Embeddings;
123
+ Mixedbread.Parsing = Parsing;
124
+ Mixedbread.Files = Files;
125
+ Mixedbread.FileObjectsLimitOffset = FileObjectsLimitOffset;
126
+ Mixedbread.VectorStores = VectorStores;
127
+ Mixedbread.VectorStoresLimitOffset = VectorStoresLimitOffset;
128
+ Mixedbread.Extractions = Extractions;
129
+ export { toFile, fileFromPath } from "./uploads.mjs";
130
+ export { MixedbreadError, APIError, APIConnectionError, APIConnectionTimeoutError, APIUserAbortError, NotFoundError, ConflictError, RateLimitError, BadRequestError, AuthenticationError, InternalServerError, PermissionDeniedError, UnprocessableEntityError, } from "./error.mjs";
131
+ export default Mixedbread;
132
+ //# sourceMappingURL=index.mjs.map
package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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
+ //# sourceMapp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