@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.
- package/CHANGELOG.md +210 -0
- package/LICENSE +201 -0
- package/README.md +360 -0
- package/_shims/MultipartBody.d.ts +9 -0
- package/_shims/MultipartBody.d.ts.map +1 -0
- package/_shims/MultipartBody.js +16 -0
- package/_shims/MultipartBody.js.map +1 -0
- package/_shims/MultipartBody.mjs +12 -0
- package/_shims/MultipartBody.mjs.map +1 -0
- package/_shims/README.md +46 -0
- package/_shims/auto/runtime-bun.d.ts +5 -0
- package/_shims/auto/runtime-bun.d.ts.map +1 -0
- package/_shims/auto/runtime-bun.js +21 -0
- package/_shims/auto/runtime-bun.js.map +1 -0
- package/_shims/auto/runtime-bun.mjs +2 -0
- package/_shims/auto/runtime-bun.mjs.map +1 -0
- package/_shims/auto/runtime-node.d.ts +5 -0
- package/_shims/auto/runtime-node.d.ts.map +1 -0
- package/_shims/auto/runtime-node.js +21 -0
- package/_shims/auto/runtime-node.js.map +1 -0
- package/_shims/auto/runtime-node.mjs +2 -0
- package/_shims/auto/runtime-node.mjs.map +1 -0
- package/_shims/auto/runtime.d.ts +5 -0
- package/_shims/auto/runtime.d.ts.map +1 -0
- package/_shims/auto/runtime.js +21 -0
- package/_shims/auto/runtime.js.map +1 -0
- package/_shims/auto/runtime.mjs +2 -0
- package/_shims/auto/runtime.mjs.map +1 -0
- package/_shims/auto/types-node.d.ts +5 -0
- package/_shims/auto/types-node.d.ts.map +1 -0
- package/_shims/auto/types-node.js +21 -0
- package/_shims/auto/types-node.js.map +1 -0
- package/_shims/auto/types-node.mjs +2 -0
- package/_shims/auto/types-node.mjs.map +1 -0
- package/_shims/auto/types.d.ts +101 -0
- package/_shims/auto/types.js +3 -0
- package/_shims/auto/types.mjs +3 -0
- package/_shims/bun-runtime.d.ts +6 -0
- package/_shims/bun-runtime.d.ts.map +1 -0
- package/_shims/bun-runtime.js +14 -0
- package/_shims/bun-runtime.js.map +1 -0
- package/_shims/bun-runtime.mjs +10 -0
- package/_shims/bun-runtime.mjs.map +1 -0
- package/_shims/index.d.ts +81 -0
- package/_shims/index.js +13 -0
- package/_shims/index.mjs +7 -0
- package/_shims/manual-types.d.ts +12 -0
- package/_shims/manual-types.js +3 -0
- package/_shims/manual-types.mjs +3 -0
- package/_shims/node-runtime.d.ts +3 -0
- package/_shims/node-runtime.d.ts.map +1 -0
- package/_shims/node-runtime.js +89 -0
- package/_shims/node-runtime.js.map +1 -0
- package/_shims/node-runtime.mjs +56 -0
- package/_shims/node-runtime.mjs.map +1 -0
- package/_shims/node-types.d.ts +42 -0
- package/_shims/node-types.js +3 -0
- package/_shims/node-types.mjs +3 -0
- package/_shims/registry.d.ts +37 -0
- package/_shims/registry.d.ts.map +1 -0
- package/_shims/registry.js +41 -0
- package/_shims/registry.js.map +1 -0
- package/_shims/registry.mjs +37 -0
- package/_shims/registry.mjs.map +1 -0
- package/_shims/web-runtime.d.ts +5 -0
- package/_shims/web-runtime.d.ts.map +1 -0
- package/_shims/web-runtime.js +78 -0
- package/_shims/web-runtime.js.map +1 -0
- package/_shims/web-runtime.mjs +71 -0
- package/_shims/web-runtime.mjs.map +1 -0
- package/_shims/web-types.d.ts +83 -0
- package/_shims/web-types.js +3 -0
- package/_shims/web-types.mjs +3 -0
- package/core.d.ts +241 -0
- package/core.d.ts.map +1 -0
- package/core.js +914 -0
- package/core.js.map +1 -0
- package/core.mjs +882 -0
- package/core.mjs.map +1 -0
- package/error.d.ts +47 -0
- package/error.d.ts.map +1 -0
- package/error.js +113 -0
- package/error.js.map +1 -0
- package/error.mjs +97 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +148 -0
- package/index.d.ts +148 -0
- package/index.d.ts.map +1 -0
- package/index.js +151 -0
- package/index.js.map +1 -0
- package/index.mjs +108 -0
- package/index.mjs.map +1 -0
- package/lib/polling.d.ts +48 -0
- package/lib/polling.d.ts.map +1 -0
- package/lib/polling.js +75 -0
- package/lib/polling.js.map +1 -0
- package/lib/polling.mjs +71 -0
- package/lib/polling.mjs.map +1 -0
- package/package.json +124 -0
- package/pagination.d.ts +30 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +45 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +41 -0
- package/pagination.mjs.map +1 -0
- package/resource.d.ts +6 -0
- package/resource.d.ts.map +1 -0
- package/resource.js +11 -0
- package/resource.js.map +1 -0
- package/resource.mjs +7 -0
- package/resource.mjs.map +1 -0
- package/resources/extractions/content.d.ts +35 -0
- package/resources/extractions/content.d.ts.map +1 -0
- package/resources/extractions/content.js +19 -0
- package/resources/extractions/content.js.map +1 -0
- package/resources/extractions/content.mjs +15 -0
- package/resources/extractions/content.mjs.map +1 -0
- package/resources/extractions/extractions.d.ts +18 -0
- package/resources/extractions/extractions.d.ts.map +1 -0
- package/resources/extractions/extractions.js +47 -0
- package/resources/extractions/extractions.js.map +1 -0
- package/resources/extractions/extractions.mjs +20 -0
- package/resources/extractions/extractions.mjs.map +1 -0
- package/resources/extractions/index.d.ts +5 -0
- package/resources/extractions/index.d.ts.map +1 -0
- package/resources/extractions/index.js +13 -0
- package/resources/extractions/index.js.map +1 -0
- package/resources/extractions/index.mjs +6 -0
- package/resources/extractions/index.mjs.map +1 -0
- package/resources/extractions/jobs.d.ts +44 -0
- package/resources/extractions/jobs.d.ts.map +1 -0
- package/resources/extractions/jobs.js +29 -0
- package/resources/extractions/jobs.js.map +1 -0
- package/resources/extractions/jobs.mjs +25 -0
- package/resources/extractions/jobs.mjs.map +1 -0
- package/resources/extractions/schema.d.ts +85 -0
- package/resources/extractions/schema.d.ts.map +1 -0
- package/resources/extractions/schema.js +39 -0
- package/resources/extractions/schema.js.map +1 -0
- package/resources/extractions/schema.mjs +35 -0
- package/resources/extractions/schema.mjs.map +1 -0
- package/resources/files.d.ts +125 -0
- package/resources/files.d.ts.map +1 -0
- package/resources/files.js +99 -0
- package/resources/files.js.map +1 -0
- package/resources/files.mjs +71 -0
- package/resources/files.mjs.map +1 -0
- package/resources/index.d.ts +7 -0
- package/resources/index.d.ts.map +1 -0
- package/resources/index.js +30 -0
- package/resources/index.js.map +1 -0
- package/resources/index.mjs +7 -0
- package/resources/index.mjs.map +1 -0
- package/resources/parsing/index.d.ts +3 -0
- package/resources/parsing/index.d.ts.map +1 -0
- package/resources/parsing/index.js +10 -0
- package/resources/parsing/index.js.map +1 -0
- package/resources/parsing/index.mjs +4 -0
- package/resources/parsing/index.mjs.map +1 -0
- package/resources/parsing/jobs.d.ts +278 -0
- package/resources/parsing/jobs.d.ts.map +1 -0
- package/resources/parsing/jobs.js +147 -0
- package/resources/parsing/jobs.js.map +1 -0
- package/resources/parsing/jobs.mjs +119 -0
- package/resources/parsing/jobs.mjs.map +1 -0
- package/resources/parsing/parsing.d.ts +10 -0
- package/resources/parsing/parsing.d.ts.map +1 -0
- package/resources/parsing/parsing.js +40 -0
- package/resources/parsing/parsing.js.map +1 -0
- package/resources/parsing/parsing.mjs +13 -0
- package/resources/parsing/parsing.mjs.map +1 -0
- package/resources/shared.d.ts +35 -0
- package/resources/shared.d.ts.map +1 -0
- package/resources/shared.js +4 -0
- package/resources/shared.js.map +1 -0
- package/resources/shared.mjs +3 -0
- package/resources/shared.mjs.map +1 -0
- package/resources/top-level.d.ts +11 -0
- package/resources/top-level.d.ts.map +1 -0
- package/resources/top-level.js +4 -0
- package/resources/top-level.js.map +1 -0
- package/resources/top-level.mjs +3 -0
- package/resources/top-level.mjs.map +1 -0
- package/resources/vector-stores/files.d.ts +280 -0
- package/resources/vector-stores/files.d.ts.map +1 -0
- package/resources/vector-stores/files.js +167 -0
- package/resources/vector-stores/files.js.map +1 -0
- package/resources/vector-stores/files.mjs +139 -0
- package/resources/vector-stores/files.mjs.map +1 -0
- package/resources/vector-stores/index.d.ts +3 -0
- package/resources/vector-stores/index.d.ts.map +1 -0
- package/resources/vector-stores/index.js +11 -0
- package/resources/vector-stores/index.js.map +1 -0
- package/resources/vector-stores/index.mjs +4 -0
- package/resources/vector-stores/index.mjs.map +1 -0
- package/resources/vector-stores/vector-stores.d.ts +400 -0
- package/resources/vector-stores/vector-stores.d.ts.map +1 -0
- package/resources/vector-stores/vector-stores.js +121 -0
- package/resources/vector-stores/vector-stores.js.map +1 -0
- package/resources/vector-stores/vector-stores.mjs +93 -0
- package/resources/vector-stores/vector-stores.mjs.map +1 -0
- package/shims/node.d.ts +30 -0
- package/shims/node.d.ts.map +1 -0
- package/shims/node.js +31 -0
- package/shims/node.js.map +1 -0
- package/shims/node.mjs +5 -0
- package/shims/node.mjs.map +1 -0
- package/shims/web.d.ts +26 -0
- package/shims/web.d.ts.map +1 -0
- package/shims/web.js +31 -0
- package/shims/web.js.map +1 -0
- package/shims/web.mjs +5 -0
- package/shims/web.mjs.map +1 -0
- package/src/_shims/MultipartBody.ts +9 -0
- package/src/_shims/README.md +46 -0
- package/src/_shims/auto/runtime-bun.ts +4 -0
- package/src/_shims/auto/runtime-node.ts +4 -0
- package/src/_shims/auto/runtime.ts +4 -0
- package/src/_shims/auto/types-node.ts +4 -0
- package/src/_shims/auto/types.d.ts +101 -0
- package/src/_shims/auto/types.js +3 -0
- package/src/_shims/auto/types.mjs +3 -0
- package/src/_shims/bun-runtime.ts +14 -0
- package/src/_shims/index.d.ts +81 -0
- package/src/_shims/index.js +13 -0
- package/src/_shims/index.mjs +7 -0
- package/src/_shims/manual-types.d.ts +12 -0
- package/src/_shims/manual-types.js +3 -0
- package/src/_shims/manual-types.mjs +3 -0
- package/src/_shims/node-runtime.ts +81 -0
- package/src/_shims/node-types.d.ts +42 -0
- package/src/_shims/node-types.js +3 -0
- package/src/_shims/node-types.mjs +3 -0
- package/src/_shims/registry.ts +67 -0
- package/src/_shims/web-runtime.ts +103 -0
- package/src/_shims/web-types.d.ts +83 -0
- package/src/_shims/web-types.js +3 -0
- package/src/_shims/web-types.mjs +3 -0
- package/src/core.ts +1208 -0
- package/src/error.ts +130 -0
- package/src/index.ts +294 -0
- package/src/lib/.keep +4 -0
- package/src/lib/polling.ts +115 -0
- package/src/pagination.ts +82 -0
- package/src/resource.ts +11 -0
- package/src/resources/extractions/content.ts +43 -0
- package/src/resources/extractions/extractions.ts +47 -0
- package/src/resources/extractions/index.ts +14 -0
- package/src/resources/extractions/jobs.ts +55 -0
- package/src/resources/extractions/schema.ts +111 -0
- package/src/resources/files.ts +181 -0
- package/src/resources/index.ts +32 -0
- package/src/resources/parsing/index.ts +12 -0
- package/src/resources/parsing/jobs.ts +438 -0
- package/src/resources/parsing/parsing.ts +32 -0
- package/src/resources/shared.ts +41 -0
- package/src/resources/top-level.ts +14 -0
- package/src/resources/vector-stores/files.ts +434 -0
- package/src/resources/vector-stores/index.ts +30 -0
- package/src/resources/vector-stores/vector-stores.ts +561 -0
- package/src/shims/node.ts +50 -0
- package/src/shims/web.ts +50 -0
- package/src/tsconfig.json +11 -0
- package/src/uploads.ts +255 -0
- package/src/version.ts +1 -0
- package/uploads.d.ts +75 -0
- package/uploads.d.ts.map +1 -0
- package/uploads.js +171 -0
- package/uploads.js.map +1 -0
- package/uploads.mjs +158 -0
- package/uploads.mjs.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
package/src/error.ts
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
import { castToError, Headers } from './core';
|
4
|
+
|
5
|
+
export class MixedbreadError extends Error {}
|
6
|
+
|
7
|
+
export class APIError<
|
8
|
+
TStatus extends number | undefined = number | undefined,
|
9
|
+
THeaders extends Headers | undefined = Headers | undefined,
|
10
|
+
TError extends Object | undefined = Object | undefined,
|
11
|
+
> extends MixedbreadError {
|
12
|
+
/** HTTP status for the response that caused the error */
|
13
|
+
readonly status: TStatus;
|
14
|
+
/** HTTP headers for the response that caused the error */
|
15
|
+
readonly headers: THeaders;
|
16
|
+
/** JSON body of the response that caused the error */
|
17
|
+
readonly error: TError;
|
18
|
+
|
19
|
+
constructor(status: TStatus, error: TError, message: string | undefined, headers: THeaders) {
|
20
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
21
|
+
this.status = status;
|
22
|
+
this.headers = headers;
|
23
|
+
this.error = error;
|
24
|
+
}
|
25
|
+
|
26
|
+
private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
|
27
|
+
const msg =
|
28
|
+
error?.message ?
|
29
|
+
typeof error.message === 'string' ?
|
30
|
+
error.message
|
31
|
+
: JSON.stringify(error.message)
|
32
|
+
: error ? JSON.stringify(error)
|
33
|
+
: message;
|
34
|
+
|
35
|
+
if (status && msg) {
|
36
|
+
return `${status} ${msg}`;
|
37
|
+
}
|
38
|
+
if (status) {
|
39
|
+
return `${status} status code (no body)`;
|
40
|
+
}
|
41
|
+
if (msg) {
|
42
|
+
return msg;
|
43
|
+
}
|
44
|
+
return '(no status code or body)';
|
45
|
+
}
|
46
|
+
|
47
|
+
static generate(
|
48
|
+
status: number | undefined,
|
49
|
+
errorResponse: Object | undefined,
|
50
|
+
message: string | undefined,
|
51
|
+
headers: Headers | undefined,
|
52
|
+
): APIError {
|
53
|
+
if (!status || !headers) {
|
54
|
+
return new APIConnectionError({ message, cause: castToError(errorResponse) });
|
55
|
+
}
|
56
|
+
|
57
|
+
const error = errorResponse as Record<string, any>;
|
58
|
+
|
59
|
+
if (status === 400) {
|
60
|
+
return new BadRequestError(status, error, message, headers);
|
61
|
+
}
|
62
|
+
|
63
|
+
if (status === 401) {
|
64
|
+
return new AuthenticationError(status, error, message, headers);
|
65
|
+
}
|
66
|
+
|
67
|
+
if (status === 403) {
|
68
|
+
return new PermissionDeniedError(status, error, message, headers);
|
69
|
+
}
|
70
|
+
|
71
|
+
if (status === 404) {
|
72
|
+
return new NotFoundError(status, error, message, headers);
|
73
|
+
}
|
74
|
+
|
75
|
+
if (status === 409) {
|
76
|
+
return new ConflictError(status, error, message, headers);
|
77
|
+
}
|
78
|
+
|
79
|
+
if (status === 422) {
|
80
|
+
return new UnprocessableEntityError(status, error, message, headers);
|
81
|
+
}
|
82
|
+
|
83
|
+
if (status === 429) {
|
84
|
+
return new RateLimitError(status, error, message, headers);
|
85
|
+
}
|
86
|
+
|
87
|
+
if (status >= 500) {
|
88
|
+
return new InternalServerError(status, error, message, headers);
|
89
|
+
}
|
90
|
+
|
91
|
+
return new APIError(status, error, message, headers);
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
export class APIUserAbortError extends APIError<undefined, undefined, undefined> {
|
96
|
+
constructor({ message }: { message?: string } = {}) {
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
export class APIConnectionError extends APIError<undefined, undefined, undefined> {
|
102
|
+
constructor({ message, cause }: { message?: string | undefined; cause?: Error | undefined }) {
|
103
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
104
|
+
// in some environments the 'cause' property is already declared
|
105
|
+
// @ts-ignore
|
106
|
+
if (cause) this.cause = cause;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
export class APIConnectionTimeoutError extends APIConnectionError {
|
111
|
+
constructor({ message }: { message?: string } = {}) {
|
112
|
+
super({ message: message ?? 'Request timed out.' });
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
export class BadRequestError extends APIError<400, Headers> {}
|
117
|
+
|
118
|
+
export class AuthenticationError extends APIError<401, Headers> {}
|
119
|
+
|
120
|
+
export class PermissionDeniedError extends APIError<403, Headers> {}
|
121
|
+
|
122
|
+
export class NotFoundError extends APIError<404, Headers> {}
|
123
|
+
|
124
|
+
export class ConflictError extends APIError<409, Headers> {}
|
125
|
+
|
126
|
+
export class UnprocessableEntityError extends APIError<422, Headers> {}
|
127
|
+
|
128
|
+
export class RateLimitError extends APIError<429, Headers> {}
|
129
|
+
|
130
|
+
export class InternalServerError extends APIError<number, Headers> {}
|
package/src/index.ts
ADDED
@@ -0,0 +1,294 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
import { type Agent } from './_shims/index';
|
4
|
+
import * as Core from './core';
|
5
|
+
import * as Errors from './error';
|
6
|
+
import * as Pagination from './pagination';
|
7
|
+
import { type LimitOffsetParams, LimitOffsetResponse } from './pagination';
|
8
|
+
import * as Uploads from './uploads';
|
9
|
+
import * as API from './resources/index';
|
10
|
+
import * as TopLevelAPI from './resources/top-level';
|
11
|
+
import { InfoResponse } from './resources/top-level';
|
12
|
+
import {
|
13
|
+
FileCreateParams,
|
14
|
+
FileDeleteResponse,
|
15
|
+
FileListParams,
|
16
|
+
FileObject,
|
17
|
+
FileObjectsLimitOffset,
|
18
|
+
FileUpdateParams,
|
19
|
+
Files,
|
20
|
+
} from './resources/files';
|
21
|
+
import { Extractions } from './resources/extractions/extractions';
|
22
|
+
import { Parsing } from './resources/parsing/parsing';
|
23
|
+
import {
|
24
|
+
ExpiresAfter,
|
25
|
+
FileCounts,
|
26
|
+
ScoredVectorStoreChunk,
|
27
|
+
VectorStore,
|
28
|
+
VectorStoreCreateParams,
|
29
|
+
VectorStoreDeleteResponse,
|
30
|
+
VectorStoreListParams,
|
31
|
+
VectorStoreQuestionAnsweringParams,
|
32
|
+
VectorStoreQuestionAnsweringResponse,
|
33
|
+
VectorStoreSearchOptions,
|
34
|
+
VectorStoreSearchParams,
|
35
|
+
VectorStoreSearchResponse,
|
36
|
+
VectorStoreUpdateParams,
|
37
|
+
VectorStores,
|
38
|
+
VectorStoresLimitOffset,
|
39
|
+
} from './resources/vector-stores/vector-stores';
|
40
|
+
|
41
|
+
const environments = {
|
42
|
+
production: 'https://api.mixedbread.ai',
|
43
|
+
local: 'http://127.0.0.1:8000',
|
44
|
+
};
|
45
|
+
type Environment = keyof typeof environments;
|
46
|
+
|
47
|
+
export interface ClientOptions {
|
48
|
+
/**
|
49
|
+
* Api key to authenticate with Mixedbread
|
50
|
+
*/
|
51
|
+
apiKey?: string | undefined;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Specifies the environment to use for the API.
|
55
|
+
*
|
56
|
+
* Each environment maps to a different base URL:
|
57
|
+
* - `production` corresponds to `https://api.mixedbread.ai`
|
58
|
+
* - `local` corresponds to `http://127.0.0.1:8000`
|
59
|
+
*/
|
60
|
+
environment?: Environment | undefined;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
64
|
+
*
|
65
|
+
* Defaults to process.env['MIXEDBREAD_BASE_URL'].
|
66
|
+
*/
|
67
|
+
baseURL?: string | null | undefined;
|
68
|
+
|
69
|
+
/**
|
70
|
+
* The maximum amount of time (in milliseconds) that the client should wait for a response
|
71
|
+
* from the server before timing out a single request.
|
72
|
+
*
|
73
|
+
* Note that request timeouts are retried by default, so in a worst-case scenario you may wait
|
74
|
+
* much longer than this timeout before the promise succeeds or fails.
|
75
|
+
*/
|
76
|
+
timeout?: number | undefined;
|
77
|
+
|
78
|
+
/**
|
79
|
+
* An HTTP agent used to manage HTTP(S) connections.
|
80
|
+
*
|
81
|
+
* If not provided, an agent will be constructed by default in the Node.js environment,
|
82
|
+
* otherwise no agent is used.
|
83
|
+
*/
|
84
|
+
httpAgent?: Agent | undefined;
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Specify a custom `fetch` function implementation.
|
88
|
+
*
|
89
|
+
* If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
|
90
|
+
* defined globally.
|
91
|
+
*/
|
92
|
+
fetch?: Core.Fetch | undefined;
|
93
|
+
|
94
|
+
/**
|
95
|
+
* The maximum number of times that the client will retry a request in case of a
|
96
|
+
* temporary failure, like a network error or a 5XX error from the server.
|
97
|
+
*
|
98
|
+
* @default 2
|
99
|
+
*/
|
100
|
+
maxRetries?: number | undefined;
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Default headers to include with every request to the API.
|
104
|
+
*
|
105
|
+
* These can be removed in individual requests by explicitly setting the
|
106
|
+
* header to `undefined` or `null` in request options.
|
107
|
+
*/
|
108
|
+
defaultHeaders?: Core.Headers | undefined;
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Default query parameters to include with every request to the API.
|
112
|
+
*
|
113
|
+
* These can be removed in individual requests by explicitly setting the
|
114
|
+
* param to `undefined` in request options.
|
115
|
+
*/
|
116
|
+
defaultQuery?: Core.DefaultQuery | undefined;
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* API Client for interfacing with the Mixedbread API.
|
121
|
+
*/
|
122
|
+
export class Mixedbread extends Core.APIClient {
|
123
|
+
apiKey: string;
|
124
|
+
|
125
|
+
private _options: ClientOptions;
|
126
|
+
|
127
|
+
/**
|
128
|
+
* API Client for interfacing with the Mixedbread API.
|
129
|
+
*
|
130
|
+
* @param {string | undefined} [opts.apiKey=process.env['MXBAI_API_KEY'] ?? undefined]
|
131
|
+
* @param {Environment} [opts.environment=production] - Specifies the environment URL to use for the API.
|
132
|
+
* @param {string} [opts.baseURL=process.env['MIXEDBREAD_BASE_URL'] ?? https://api.mixedbread.ai] - Override the default base URL for the API.
|
133
|
+
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
134
|
+
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
|
135
|
+
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
136
|
+
* @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
|
137
|
+
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
|
138
|
+
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
|
139
|
+
*/
|
140
|
+
constructor({
|
141
|
+
baseURL = Core.readEnv('MIXEDBREAD_BASE_URL'),
|
142
|
+
apiKey = Core.readEnv('MXBAI_API_KEY'),
|
143
|
+
...opts
|
144
|
+
}: ClientOptions = {}) {
|
145
|
+
if (apiKey === undefined) {
|
146
|
+
throw new Errors.MixedbreadError(
|
147
|
+
"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' }).",
|
148
|
+
);
|
149
|
+
}
|
150
|
+
|
151
|
+
const options: ClientOptions = {
|
152
|
+
apiKey,
|
153
|
+
...opts,
|
154
|
+
baseURL,
|
155
|
+
environment: opts.environment ?? 'production',
|
156
|
+
};
|
157
|
+
|
158
|
+
if (baseURL && opts.environment) {
|
159
|
+
throw new Errors.MixedbreadError(
|
160
|
+
'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',
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
super({
|
165
|
+
baseURL: options.baseURL || environments[options.environment || 'production'],
|
166
|
+
timeout: options.timeout ?? 60000 /* 1 minute */,
|
167
|
+
httpAgent: options.httpAgent,
|
168
|
+
maxRetries: options.maxRetries,
|
169
|
+
fetch: options.fetch,
|
170
|
+
});
|
171
|
+
|
172
|
+
this._options = options;
|
173
|
+
|
174
|
+
this.apiKey = apiKey;
|
175
|
+
}
|
176
|
+
|
177
|
+
parsing: API.Parsing = new API.Parsing(this);
|
178
|
+
files: API.Files = new API.Files(this);
|
179
|
+
vectorStores: API.VectorStores = new API.VectorStores(this);
|
180
|
+
extractions: API.Extractions = new API.Extractions(this);
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Returns service information, including name and version.
|
184
|
+
*
|
185
|
+
* Returns: InfoResponse: A response containing the service name and version.
|
186
|
+
*/
|
187
|
+
info(options?: Core.RequestOptions): Core.APIPromise<TopLevelAPI.InfoResponse> {
|
188
|
+
return this.get('/', options);
|
189
|
+
}
|
190
|
+
|
191
|
+
protected override defaultQuery(): Core.DefaultQuery | undefined {
|
192
|
+
return this._options.defaultQuery;
|
193
|
+
}
|
194
|
+
|
195
|
+
protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
196
|
+
return {
|
197
|
+
...super.defaultHeaders(opts),
|
198
|
+
...this._options.defaultHeaders,
|
199
|
+
};
|
200
|
+
}
|
201
|
+
|
202
|
+
protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
|
203
|
+
return { Authorization: `Bearer ${this.apiKey}` };
|
204
|
+
}
|
205
|
+
|
206
|
+
static Mixedbread = this;
|
207
|
+
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
208
|
+
|
209
|
+
static MixedbreadError = Errors.MixedbreadError;
|
210
|
+
static APIError = Errors.APIError;
|
211
|
+
static APIConnectionError = Errors.APIConnectionError;
|
212
|
+
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
213
|
+
static APIUserAbortError = Errors.APIUserAbortError;
|
214
|
+
static NotFoundError = Errors.NotFoundError;
|
215
|
+
static ConflictError = Errors.ConflictError;
|
216
|
+
static RateLimitError = Errors.RateLimitError;
|
217
|
+
static BadRequestError = Errors.BadRequestError;
|
218
|
+
static AuthenticationError = Errors.AuthenticationError;
|
219
|
+
static InternalServerError = Errors.InternalServerError;
|
220
|
+
static PermissionDeniedError = Errors.PermissionDeniedError;
|
221
|
+
static UnprocessableEntityError = Errors.UnprocessableEntityError;
|
222
|
+
|
223
|
+
static toFile = Uploads.toFile;
|
224
|
+
static fileFromPath = Uploads.fileFromPath;
|
225
|
+
}
|
226
|
+
|
227
|
+
Mixedbread.Parsing = Parsing;
|
228
|
+
Mixedbread.Files = Files;
|
229
|
+
Mixedbread.FileObjectsLimitOffset = FileObjectsLimitOffset;
|
230
|
+
Mixedbread.VectorStores = VectorStores;
|
231
|
+
Mixedbread.VectorStoresLimitOffset = VectorStoresLimitOffset;
|
232
|
+
Mixedbread.Extractions = Extractions;
|
233
|
+
export declare namespace Mixedbread {
|
234
|
+
export type RequestOptions = Core.RequestOptions;
|
235
|
+
|
236
|
+
export import LimitOffset = Pagination.LimitOffset;
|
237
|
+
export { type LimitOffsetParams as LimitOffsetParams, type LimitOffsetResponse as LimitOffsetResponse };
|
238
|
+
|
239
|
+
export { type InfoResponse as InfoResponse };
|
240
|
+
|
241
|
+
export { Parsing as Parsing };
|
242
|
+
|
243
|
+
export {
|
244
|
+
Files as Files,
|
245
|
+
type FileObject as FileObject,
|
246
|
+
type FileDeleteResponse as FileDeleteResponse,
|
247
|
+
FileObjectsLimitOffset as FileObjectsLimitOffset,
|
248
|
+
type FileCreateParams as FileCreateParams,
|
249
|
+
type FileUpdateParams as FileUpdateParams,
|
250
|
+
type FileListParams as FileListParams,
|
251
|
+
};
|
252
|
+
|
253
|
+
export {
|
254
|
+
VectorStores as VectorStores,
|
255
|
+
type ExpiresAfter as ExpiresAfter,
|
256
|
+
type FileCounts as FileCounts,
|
257
|
+
type ScoredVectorStoreChunk as ScoredVectorStoreChunk,
|
258
|
+
type VectorStore as VectorStore,
|
259
|
+
type VectorStoreSearchOptions as VectorStoreSearchOptions,
|
260
|
+
type VectorStoreDeleteResponse as VectorStoreDeleteResponse,
|
261
|
+
type VectorStoreQuestionAnsweringResponse as VectorStoreQuestionAnsweringResponse,
|
262
|
+
type VectorStoreSearchResponse as VectorStoreSearchResponse,
|
263
|
+
VectorStoresLimitOffset as VectorStoresLimitOffset,
|
264
|
+
type VectorStoreCreateParams as VectorStoreCreateParams,
|
265
|
+
type VectorStoreUpdateParams as VectorStoreUpdateParams,
|
266
|
+
type VectorStoreListParams as VectorStoreListParams,
|
267
|
+
type VectorStoreQuestionAnsweringParams as VectorStoreQuestionAnsweringParams,
|
268
|
+
type VectorStoreSearchParams as VectorStoreSearchParams,
|
269
|
+
};
|
270
|
+
|
271
|
+
export { Extractions as Extractions };
|
272
|
+
|
273
|
+
export type SearchFilter = API.SearchFilter;
|
274
|
+
export type SearchFilterCondition = API.SearchFilterCondition;
|
275
|
+
}
|
276
|
+
|
277
|
+
export { toFile, fileFromPath } from './uploads';
|
278
|
+
export {
|
279
|
+
MixedbreadError,
|
280
|
+
APIError,
|
281
|
+
APIConnectionError,
|
282
|
+
APIConnectionTimeoutError,
|
283
|
+
APIUserAbortError,
|
284
|
+
NotFoundError,
|
285
|
+
ConflictError,
|
286
|
+
RateLimitError,
|
287
|
+
BadRequestError,
|
288
|
+
AuthenticationError,
|
289
|
+
InternalServerError,
|
290
|
+
PermissionDeniedError,
|
291
|
+
UnprocessableEntityError,
|
292
|
+
} from './error';
|
293
|
+
|
294
|
+
export default Mixedbread;
|
package/src/lib/.keep
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
/**
|
2
|
+
* Utilities for polling operations
|
3
|
+
*/
|
4
|
+
|
5
|
+
type ConditionFunction<T> = (result: T) => boolean;
|
6
|
+
type IntervalFunction<T> = (result: T) => number;
|
7
|
+
type ErrorHandlerFunction = (error: Error) => number | null;
|
8
|
+
type RetryCallback<T> = (result: T, attempt: number) => void;
|
9
|
+
|
10
|
+
// Use a more generic setTimeout type
|
11
|
+
declare const setTimeout: (callback: (...args: any[]) => void, ms: number) => any;
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Configuration options for the poll function.
|
15
|
+
*/
|
16
|
+
export interface PollOptions<T> {
|
17
|
+
/** Async function that performs the operation to be polled */
|
18
|
+
fn: () => Promise<T>;
|
19
|
+
/** Function that evaluates if the polling should continue */
|
20
|
+
condition: ConditionFunction<T>;
|
21
|
+
/** Maximum number of polling attempts (undefined for infinite) */
|
22
|
+
maxAttempts?: number;
|
23
|
+
/** Maximum total time to poll in seconds (undefined for infinite) */
|
24
|
+
timeoutSeconds?: number;
|
25
|
+
/** Time between polls in seconds, or function that returns interval */
|
26
|
+
intervalSeconds?: number | IntervalFunction<T>;
|
27
|
+
/** Optional callback for each retry attempt */
|
28
|
+
onRetry?: RetryCallback<T>;
|
29
|
+
/** Optional callback for handling exceptions during polling */
|
30
|
+
errorHandler?: ErrorHandlerFunction;
|
31
|
+
}
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Asynchronously polls an operation until a condition is met or timeout/max attempts are reached.
|
35
|
+
*
|
36
|
+
* @param options - Configuration options for polling
|
37
|
+
* @returns The result of the operation once condition is met
|
38
|
+
* @throws Error if maxAttempts is reached
|
39
|
+
* @throws Error if timeoutSeconds is reached
|
40
|
+
*
|
41
|
+
* @example
|
42
|
+
* ```typescript
|
43
|
+
* const result = await poll({
|
44
|
+
* fn: () => fetchData(),
|
45
|
+
* condition: (result) => result.status === 'completed',
|
46
|
+
* maxAttempts: 5,
|
47
|
+
* timeoutSeconds: 60,
|
48
|
+
* intervalSeconds: 2
|
49
|
+
* });
|
50
|
+
* ```
|
51
|
+
*/
|
52
|
+
export async function poll<T>(options: PollOptions<T>): Promise<T> {
|
53
|
+
const {
|
54
|
+
fn,
|
55
|
+
condition,
|
56
|
+
maxAttempts,
|
57
|
+
timeoutSeconds,
|
58
|
+
intervalSeconds = 1.0,
|
59
|
+
onRetry,
|
60
|
+
errorHandler,
|
61
|
+
} = options;
|
62
|
+
|
63
|
+
const startTime = new Date();
|
64
|
+
let attempt = 0;
|
65
|
+
|
66
|
+
// eslint-disable-next-line no-constant-condition
|
67
|
+
while (true) {
|
68
|
+
attempt += 1;
|
69
|
+
|
70
|
+
try {
|
71
|
+
const result = await fn();
|
72
|
+
|
73
|
+
if (condition(result)) {
|
74
|
+
return result;
|
75
|
+
}
|
76
|
+
|
77
|
+
if (onRetry) {
|
78
|
+
onRetry(result, attempt);
|
79
|
+
}
|
80
|
+
|
81
|
+
let waitTime: number;
|
82
|
+
|
83
|
+
if (typeof intervalSeconds === 'function') {
|
84
|
+
waitTime = intervalSeconds(result);
|
85
|
+
} else {
|
86
|
+
waitTime = intervalSeconds;
|
87
|
+
}
|
88
|
+
|
89
|
+
// Check timeout and attempts before sleeping
|
90
|
+
if (maxAttempts && attempt >= maxAttempts) {
|
91
|
+
throw new Error(`Maximum attempts (${maxAttempts}) reached`);
|
92
|
+
}
|
93
|
+
|
94
|
+
if (timeoutSeconds) {
|
95
|
+
const elapsed = (new Date().getTime() - startTime.getTime()) / 1000;
|
96
|
+
if (elapsed >= timeoutSeconds) {
|
97
|
+
throw new Error(`Timeout (${timeoutSeconds}s) reached`);
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
// Sleep asynchronously
|
102
|
+
await new Promise((resolve) => setTimeout(resolve, waitTime * 1000));
|
103
|
+
} catch (e) {
|
104
|
+
if (errorHandler && e instanceof Error) {
|
105
|
+
const sleepTime = errorHandler(e);
|
106
|
+
if (sleepTime !== null) {
|
107
|
+
// Sleep and continue
|
108
|
+
await new Promise((resolve) => setTimeout(resolve, sleepTime * 1000));
|
109
|
+
continue;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
throw e;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
import { AbstractPage, Response, APIClient, FinalRequestOptions, PageInfo } from './core';
|
4
|
+
|
5
|
+
export interface LimitOffsetResponse<Item> {
|
6
|
+
data: Array<Item>;
|
7
|
+
|
8
|
+
pagination: LimitOffsetResponse.Pagination;
|
9
|
+
}
|
10
|
+
|
11
|
+
export namespace LimitOffsetResponse {
|
12
|
+
export interface Pagination {
|
13
|
+
total?: number;
|
14
|
+
|
15
|
+
offset?: number;
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
export interface LimitOffsetParams {
|
20
|
+
/**
|
21
|
+
* The number of elements to skip.
|
22
|
+
*/
|
23
|
+
offset?: number;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* The maximum number of elements to fetch.
|
27
|
+
*/
|
28
|
+
limit?: number;
|
29
|
+
}
|
30
|
+
|
31
|
+
export class LimitOffset<Item> extends AbstractPage<Item> implements LimitOffsetResponse<Item> {
|
32
|
+
data: Array<Item>;
|
33
|
+
|
34
|
+
pagination: LimitOffsetResponse.Pagination;
|
35
|
+
|
36
|
+
constructor(
|
37
|
+
client: APIClient,
|
38
|
+
response: Response,
|
39
|
+
body: LimitOffsetResponse<Item>,
|
40
|
+
options: FinalRequestOptions,
|
41
|
+
) {
|
42
|
+
super(client, response, body, options);
|
43
|
+
|
44
|
+
this.data = body.data || [];
|
45
|
+
this.pagination = body.pagination || {};
|
46
|
+
}
|
47
|
+
|
48
|
+
getPaginatedItems(): Item[] {
|
49
|
+
return this.data ?? [];
|
50
|
+
}
|
51
|
+
|
52
|
+
// @deprecated Please use `nextPageInfo()` instead
|
53
|
+
nextPageParams(): Partial<LimitOffsetParams> | null {
|
54
|
+
const info = this.nextPageInfo();
|
55
|
+
if (!info) return null;
|
56
|
+
if ('params' in info) return info.params;
|
57
|
+
const params = Object.fromEntries(info.url.searchParams);
|
58
|
+
if (!Object.keys(params).length) return null;
|
59
|
+
return params;
|
60
|
+
}
|
61
|
+
|
62
|
+
nextPageInfo(): PageInfo | null {
|
63
|
+
const offset = this.pagination?.offset;
|
64
|
+
if (!offset) {
|
65
|
+
return null;
|
66
|
+
}
|
67
|
+
|
68
|
+
const length = this.getPaginatedItems().length;
|
69
|
+
const currentCount = offset + length;
|
70
|
+
|
71
|
+
const totalCount = this.pagination?.total;
|
72
|
+
if (!totalCount) {
|
73
|
+
return null;
|
74
|
+
}
|
75
|
+
|
76
|
+
if (currentCount < totalCount) {
|
77
|
+
return { params: { offset: currentCount } };
|
78
|
+
}
|
79
|
+
|
80
|
+
return null;
|
81
|
+
}
|
82
|
+
}
|
package/src/resource.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
import type { Mixedbread } from './index';
|
4
|
+
|
5
|
+
export class APIResource {
|
6
|
+
protected _client: Mixedbread;
|
7
|
+
|
8
|
+
constructor(client: Mixedbread) {
|
9
|
+
this._client = client;
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
2
|
+
|
3
|
+
import { APIResource } from '../../resource';
|
4
|
+
import * as Core from '../../core';
|
5
|
+
|
6
|
+
export class Content extends APIResource {
|
7
|
+
/**
|
8
|
+
* Extract content from a string using the provided schema.
|
9
|
+
*
|
10
|
+
* Args: params: The parameters for extracting content from a string.
|
11
|
+
*
|
12
|
+
* Returns: The extracted content.
|
13
|
+
*/
|
14
|
+
create(body: ContentCreateParams, options?: Core.RequestOptions): Core.APIPromise<ExtractionResult> {
|
15
|
+
return this._client.post('/v1/extractions/content', { body, ...options });
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Result of an extraction operation.
|
21
|
+
*/
|
22
|
+
export interface ExtractionResult {
|
23
|
+
/**
|
24
|
+
* The extracted data
|
25
|
+
*/
|
26
|
+
data: unknown;
|
27
|
+
}
|
28
|
+
|
29
|
+
export interface ContentCreateParams {
|
30
|
+
/**
|
31
|
+
* The content to extract from
|
32
|
+
*/
|
33
|
+
content: string;
|
34
|
+
|
35
|
+
/**
|
36
|
+
* The JSON schema to use for extraction
|
37
|
+
*/
|
38
|
+
json_schema: unknown;
|
39
|
+
}
|
40
|
+
|
41
|
+
export declare namespace Content {
|
42
|
+
export { type ExtractionResult as ExtractionResult, type ContentCreateParams as ContentCreateParams };
|
43
|
+
}
|