notdiamond 2.0.0-rc2 → 2.0.0-rc20
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 +185 -0
- package/LICENSE +1 -1
- package/README.md +261 -168
- package/client.d.mts +26 -43
- package/client.d.mts.map +1 -1
- package/client.d.ts +26 -43
- package/client.d.ts.map +1 -1
- package/client.js +49 -68
- package/client.js.map +1 -1
- package/client.mjs +47 -66
- package/client.mjs.map +1 -1
- package/core/api-promise.d.mts +2 -2
- package/core/api-promise.d.ts +2 -2
- package/core/error.d.mts +2 -2
- package/core/error.d.ts +2 -2
- package/core/error.js +4 -4
- package/core/error.mjs +2 -2
- package/core/resource.d.mts +3 -3
- package/core/resource.d.ts +3 -3
- package/index.d.mts +3 -3
- package/index.d.ts +3 -3
- package/index.js +4 -4
- package/index.mjs +3 -3
- package/internal/parse.d.mts +2 -2
- package/internal/parse.d.ts +2 -2
- package/internal/shims.js +1 -1
- package/internal/shims.mjs +1 -1
- package/internal/uploads.d.mts +4 -4
- package/internal/uploads.d.ts +4 -4
- package/internal/utils/base64.js +2 -2
- package/internal/utils/base64.mjs +3 -3
- package/internal/utils/env.d.mts.map +1 -1
- package/internal/utils/env.d.ts.map +1 -1
- package/internal/utils/env.js +4 -2
- package/internal/utils/env.js.map +1 -1
- package/internal/utils/env.mjs +4 -2
- package/internal/utils/env.mjs.map +1 -1
- package/internal/utils/log.d.mts +3 -3
- package/internal/utils/log.d.ts +3 -3
- package/internal/utils/path.js +1 -1
- package/internal/utils/path.mjs +2 -2
- package/internal/utils/values.js +5 -5
- package/internal/utils/values.mjs +6 -6
- package/package.json +11 -12
- package/resources/custom-router.d.mts +145 -0
- package/resources/custom-router.d.mts.map +1 -0
- package/resources/custom-router.d.ts +145 -0
- package/resources/custom-router.d.ts.map +1 -0
- package/resources/custom-router.js +83 -0
- package/resources/custom-router.js.map +1 -0
- package/resources/custom-router.mjs +79 -0
- package/resources/custom-router.mjs.map +1 -0
- package/resources/index.d.mts +5 -6
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +5 -6
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -7
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -3
- package/resources/index.mjs.map +1 -1
- package/resources/model-router.d.mts +194 -0
- package/resources/model-router.d.mts.map +1 -0
- package/resources/model-router.d.ts +194 -0
- package/resources/model-router.d.ts.map +1 -0
- package/resources/model-router.js +68 -0
- package/resources/model-router.js.map +1 -0
- package/resources/model-router.mjs +64 -0
- package/resources/model-router.mjs.map +1 -0
- package/resources/models.d.mts +50 -25
- package/resources/models.d.mts.map +1 -1
- package/resources/models.d.ts +50 -25
- package/resources/models.d.ts.map +1 -1
- package/resources/models.js +5 -0
- package/resources/models.js.map +1 -1
- package/resources/models.mjs +5 -0
- package/resources/models.mjs.map +1 -1
- package/resources/preferences.d.mts +37 -54
- package/resources/preferences.d.mts.map +1 -1
- package/resources/preferences.d.ts +37 -54
- package/resources/preferences.d.ts.map +1 -1
- package/resources/preferences.js +17 -42
- package/resources/preferences.js.map +1 -1
- package/resources/preferences.mjs +17 -42
- package/resources/preferences.mjs.map +1 -1
- package/resources/prompt-adaptation.d.mts +340 -249
- package/resources/prompt-adaptation.d.mts.map +1 -1
- package/resources/prompt-adaptation.d.ts +340 -249
- package/resources/prompt-adaptation.d.ts.map +1 -1
- package/resources/prompt-adaptation.js +36 -79
- package/resources/prompt-adaptation.js.map +1 -1
- package/resources/prompt-adaptation.mjs +36 -79
- package/resources/prompt-adaptation.mjs.map +1 -1
- package/src/client.ts +72 -128
- package/src/core/api-promise.ts +4 -4
- package/src/core/error.ts +2 -2
- package/src/core/resource.ts +3 -3
- package/src/index.ts +3 -3
- package/src/internal/parse.ts +2 -2
- package/src/internal/shims.ts +1 -1
- package/src/internal/uploads.ts +5 -5
- package/src/internal/utils/base64.ts +3 -3
- package/src/internal/utils/env.ts +4 -2
- package/src/internal/utils/log.ts +3 -3
- package/src/internal/utils/path.ts +2 -2
- package/src/internal/utils/values.ts +6 -6
- package/src/resources/custom-router.ts +168 -0
- package/src/resources/index.ts +20 -32
- package/src/resources/model-router.ts +222 -0
- package/src/resources/models.ts +55 -32
- package/src/resources/preferences.ts +43 -83
- package/src/resources/prompt-adaptation.ts +358 -300
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/resources/admin.d.mts +0 -4
- package/resources/admin.d.mts.map +0 -1
- package/resources/admin.d.ts +0 -4
- package/resources/admin.d.ts.map +0 -1
- package/resources/admin.js +0 -9
- package/resources/admin.js.map +0 -1
- package/resources/admin.mjs +0 -5
- package/resources/admin.mjs.map +0 -1
- package/resources/report.d.mts +0 -245
- package/resources/report.d.mts.map +0 -1
- package/resources/report.d.ts +0 -245
- package/resources/report.d.ts.map +0 -1
- package/resources/report.js +0 -86
- package/resources/report.js.map +0 -1
- package/resources/report.mjs +0 -82
- package/resources/report.mjs.map +0 -1
- package/resources/routing.d.mts +0 -391
- package/resources/routing.d.mts.map +0 -1
- package/resources/routing.d.ts +0 -391
- package/resources/routing.d.ts.map +0 -1
- package/resources/routing.js +0 -163
- package/resources/routing.js.map +0 -1
- package/resources/routing.mjs +0 -159
- package/resources/routing.mjs.map +0 -1
- package/src/resources/admin.ts +0 -5
- package/src/resources/report.ts +0 -300
- package/src/resources/routing.ts +0 -476
package/src/client.ts
CHANGED
|
@@ -17,48 +17,36 @@ import * as Errors from './core/error';
|
|
|
17
17
|
import * as Uploads from './core/uploads';
|
|
18
18
|
import * as API from './resources/index';
|
|
19
19
|
import { APIPromise } from './core/api-promise';
|
|
20
|
-
import { Admin } from './resources/admin';
|
|
21
|
-
import { ModelListParams, ModelListResponse, Models } from './resources/models';
|
|
22
20
|
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
CustomRouter,
|
|
22
|
+
CustomRouterTrainCustomRouterParams,
|
|
23
|
+
CustomRouterTrainCustomRouterResponse,
|
|
24
|
+
} from './resources/custom-router';
|
|
25
|
+
import {
|
|
26
|
+
ModelRouter,
|
|
27
|
+
ModelRouterSelectModelParams,
|
|
28
|
+
ModelRouterSelectModelResponse,
|
|
29
|
+
} from './resources/model-router';
|
|
30
|
+
import { Model, ModelListParams, ModelListResponse, Models } from './resources/models';
|
|
31
|
+
import {
|
|
32
|
+
PreferenceCreateParams,
|
|
33
|
+
PreferenceCreateResponse,
|
|
34
|
+
PreferenceDeleteResponse,
|
|
35
|
+
PreferenceUpdateParams,
|
|
36
|
+
PreferenceUpdateResponse,
|
|
30
37
|
Preferences,
|
|
31
38
|
} from './resources/preferences';
|
|
32
39
|
import {
|
|
33
|
-
|
|
40
|
+
GoldenRecord,
|
|
34
41
|
JobStatus,
|
|
35
42
|
PromptAdaptation,
|
|
36
43
|
PromptAdaptationAdaptParams,
|
|
37
44
|
PromptAdaptationAdaptResponse,
|
|
38
|
-
|
|
39
|
-
PromptAdaptationGetAdaptRunsParams,
|
|
40
|
-
PromptAdaptationGetAdaptRunsResponse,
|
|
45
|
+
PromptAdaptationGetAdaptResultsResponse,
|
|
41
46
|
PromptAdaptationGetAdaptStatusResponse,
|
|
42
|
-
|
|
47
|
+
PromptAdaptationGetCostResponse,
|
|
48
|
+
RequestProvider,
|
|
43
49
|
} from './resources/prompt-adaptation';
|
|
44
|
-
import {
|
|
45
|
-
Report,
|
|
46
|
-
ReportEvaluateHallucinationParams,
|
|
47
|
-
ReportEvaluateHallucinationResponse,
|
|
48
|
-
ReportLatencyParams,
|
|
49
|
-
ReportLatencyResponse,
|
|
50
|
-
ReportSubmitFeedbackParams,
|
|
51
|
-
ReportSubmitFeedbackResponse,
|
|
52
|
-
} from './resources/report';
|
|
53
|
-
import {
|
|
54
|
-
Routing,
|
|
55
|
-
RoutingCreateSurveyResponseParams,
|
|
56
|
-
RoutingCreateSurveyResponseResponse,
|
|
57
|
-
RoutingSelectModelParams,
|
|
58
|
-
RoutingSelectModelResponse,
|
|
59
|
-
RoutingTrainCustomRouterParams,
|
|
60
|
-
RoutingTrainCustomRouterResponse,
|
|
61
|
-
} from './resources/routing';
|
|
62
50
|
import { type Fetch } from './internal/builtin-types';
|
|
63
51
|
import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
|
|
64
52
|
import { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
@@ -72,31 +60,16 @@ import {
|
|
|
72
60
|
} from './internal/utils/log';
|
|
73
61
|
import { isEmptyObj } from './internal/utils/values';
|
|
74
62
|
|
|
75
|
-
const environments = {
|
|
76
|
-
production: 'https://api.notdiamond.ai',
|
|
77
|
-
staging: 'https://staging-api.notdiamond.ai',
|
|
78
|
-
};
|
|
79
|
-
type Environment = keyof typeof environments;
|
|
80
|
-
|
|
81
63
|
export interface ClientOptions {
|
|
82
64
|
/**
|
|
83
|
-
*
|
|
65
|
+
* API key authentication using Bearer token
|
|
84
66
|
*/
|
|
85
|
-
apiKey?: string |
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Specifies the environment to use for the API.
|
|
89
|
-
*
|
|
90
|
-
* Each environment maps to a different base URL:
|
|
91
|
-
* - `production` corresponds to `https://api.notdiamond.ai`
|
|
92
|
-
* - `staging` corresponds to `https://staging-api.notdiamond.ai`
|
|
93
|
-
*/
|
|
94
|
-
environment?: Environment | undefined;
|
|
67
|
+
apiKey?: string | undefined;
|
|
95
68
|
|
|
96
69
|
/**
|
|
97
70
|
* Override the default base URL for the API, e.g., "https://api.example.com/v2/"
|
|
98
71
|
*
|
|
99
|
-
* Defaults to process.env['
|
|
72
|
+
* Defaults to process.env['NOTDIAMOND_BASE_URL'].
|
|
100
73
|
*/
|
|
101
74
|
baseURL?: string | null | undefined;
|
|
102
75
|
|
|
@@ -150,7 +123,7 @@ export interface ClientOptions {
|
|
|
150
123
|
/**
|
|
151
124
|
* Set the log level.
|
|
152
125
|
*
|
|
153
|
-
* Defaults to process.env['
|
|
126
|
+
* Defaults to process.env['NOTDIAMOND_LOG'] or 'warn' if it isn't set.
|
|
154
127
|
*/
|
|
155
128
|
logLevel?: LogLevel | undefined;
|
|
156
129
|
|
|
@@ -163,15 +136,15 @@ export interface ClientOptions {
|
|
|
163
136
|
}
|
|
164
137
|
|
|
165
138
|
/**
|
|
166
|
-
* API Client for interfacing with the
|
|
139
|
+
* API Client for interfacing with the Notdiamond API.
|
|
167
140
|
*/
|
|
168
|
-
export class
|
|
169
|
-
apiKey: string
|
|
141
|
+
export class Notdiamond {
|
|
142
|
+
apiKey: string;
|
|
170
143
|
|
|
171
144
|
baseURL: string;
|
|
172
145
|
maxRetries: number;
|
|
173
146
|
timeout: number;
|
|
174
|
-
logger: Logger
|
|
147
|
+
logger: Logger;
|
|
175
148
|
logLevel: LogLevel | undefined;
|
|
176
149
|
fetchOptions: MergedRequestInit | undefined;
|
|
177
150
|
|
|
@@ -181,11 +154,10 @@ export class NotDiamond {
|
|
|
181
154
|
private _options: ClientOptions;
|
|
182
155
|
|
|
183
156
|
/**
|
|
184
|
-
* API Client for interfacing with the
|
|
157
|
+
* API Client for interfacing with the Notdiamond API.
|
|
185
158
|
*
|
|
186
|
-
* @param {string |
|
|
187
|
-
* @param {
|
|
188
|
-
* @param {string} [opts.baseURL=process.env['NOT_DIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
159
|
+
* @param {string | undefined} [opts.apiKey=process.env['NOT_DIAMOND_API_KEY'] ?? undefined]
|
|
160
|
+
* @param {string} [opts.baseURL=process.env['NOTDIAMOND_BASE_URL'] ?? https://api.notdiamond.ai] - Override the default base URL for the API.
|
|
189
161
|
* @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
|
|
190
162
|
* @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
|
|
191
163
|
* @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
|
|
@@ -194,32 +166,31 @@ export class NotDiamond {
|
|
|
194
166
|
* @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
|
|
195
167
|
*/
|
|
196
168
|
constructor({
|
|
197
|
-
baseURL = readEnv('
|
|
198
|
-
apiKey = readEnv('NOT_DIAMOND_API_KEY')
|
|
169
|
+
baseURL = readEnv('NOTDIAMOND_BASE_URL'),
|
|
170
|
+
apiKey = readEnv('NOT_DIAMOND_API_KEY'),
|
|
199
171
|
...opts
|
|
200
172
|
}: ClientOptions = {}) {
|
|
173
|
+
if (apiKey === undefined) {
|
|
174
|
+
throw new Errors.NotdiamondError(
|
|
175
|
+
"The NOT_DIAMOND_API_KEY environment variable is missing or empty; either provide it, or instantiate the Notdiamond client with an apiKey option, like new Notdiamond({ apiKey: 'My API Key' }).",
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
201
179
|
const options: ClientOptions = {
|
|
202
180
|
apiKey,
|
|
203
181
|
...opts,
|
|
204
|
-
baseURL
|
|
205
|
-
environment: opts.environment ?? 'production',
|
|
182
|
+
baseURL: baseURL || `https://api.notdiamond.ai`,
|
|
206
183
|
};
|
|
207
184
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
'Ambiguous URL; The `baseURL` option (or NOT_DIAMOND_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
this.baseURL = options.baseURL || environments[options.environment || 'production'];
|
|
215
|
-
this.timeout = options.timeout ?? NotDiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
185
|
+
this.baseURL = options.baseURL!;
|
|
186
|
+
this.timeout = options.timeout ?? Notdiamond.DEFAULT_TIMEOUT /* 1 minute */;
|
|
216
187
|
this.logger = options.logger ?? console;
|
|
217
188
|
const defaultLogLevel = 'warn';
|
|
218
189
|
// Set default logLevel early so that we can log a warning in parseLogLevel.
|
|
219
190
|
this.logLevel = defaultLogLevel;
|
|
220
191
|
this.logLevel =
|
|
221
192
|
parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
|
|
222
|
-
parseLogLevel(readEnv('
|
|
193
|
+
parseLogLevel(readEnv('NOTDIAMOND_LOG'), "process.env['NOTDIAMOND_LOG']", this) ??
|
|
223
194
|
defaultLogLevel;
|
|
224
195
|
this.fetchOptions = options.fetchOptions;
|
|
225
196
|
this.maxRetries = options.maxRetries ?? 2;
|
|
@@ -237,8 +208,7 @@ export class NotDiamond {
|
|
|
237
208
|
withOptions(options: Partial<ClientOptions>): this {
|
|
238
209
|
const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
|
|
239
210
|
...this._options,
|
|
240
|
-
|
|
241
|
-
baseURL: options.environment ? undefined : this.baseURL,
|
|
211
|
+
baseURL: this.baseURL,
|
|
242
212
|
maxRetries: this.maxRetries,
|
|
243
213
|
timeout: this.timeout,
|
|
244
214
|
logger: this.logger,
|
|
@@ -255,7 +225,7 @@ export class NotDiamond {
|
|
|
255
225
|
* Check whether the base URL is set to its default.
|
|
256
226
|
*/
|
|
257
227
|
#baseURLOverridden(): boolean {
|
|
258
|
-
return this.baseURL !==
|
|
228
|
+
return this.baseURL !== 'https://api.notdiamond.ai';
|
|
259
229
|
}
|
|
260
230
|
|
|
261
231
|
protected defaultQuery(): Record<string, string | undefined> | undefined {
|
|
@@ -263,22 +233,10 @@ export class NotDiamond {
|
|
|
263
233
|
}
|
|
264
234
|
|
|
265
235
|
protected validateHeaders({ values, nulls }: NullableHeaders) {
|
|
266
|
-
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
if (nulls.has('authorization')) {
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
throw new Error(
|
|
274
|
-
'Could not resolve authentication method. Expected the apiKey to be set. Or for the "Authorization" headers to be explicitly omitted',
|
|
275
|
-
);
|
|
236
|
+
return;
|
|
276
237
|
}
|
|
277
238
|
|
|
278
239
|
protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
|
|
279
|
-
if (this.apiKey == null) {
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
240
|
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
283
241
|
}
|
|
284
242
|
|
|
@@ -751,10 +709,10 @@ export class NotDiamond {
|
|
|
751
709
|
}
|
|
752
710
|
}
|
|
753
711
|
|
|
754
|
-
static
|
|
712
|
+
static Notdiamond = this;
|
|
755
713
|
static DEFAULT_TIMEOUT = 60000; // 1 minute
|
|
756
714
|
|
|
757
|
-
static
|
|
715
|
+
static NotdiamondError = Errors.NotdiamondError;
|
|
758
716
|
static APIError = Errors.APIError;
|
|
759
717
|
static APIConnectionError = Errors.APIConnectionError;
|
|
760
718
|
static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
|
|
@@ -770,73 +728,59 @@ export class NotDiamond {
|
|
|
770
728
|
|
|
771
729
|
static toFile = Uploads.toFile;
|
|
772
730
|
|
|
773
|
-
|
|
731
|
+
modelRouter: API.ModelRouter = new API.ModelRouter(this);
|
|
774
732
|
preferences: API.Preferences = new API.Preferences(this);
|
|
775
733
|
promptAdaptation: API.PromptAdaptation = new API.PromptAdaptation(this);
|
|
776
|
-
|
|
734
|
+
customRouter: API.CustomRouter = new API.CustomRouter(this);
|
|
777
735
|
models: API.Models = new API.Models(this);
|
|
778
|
-
admin: API.Admin = new API.Admin(this);
|
|
779
736
|
}
|
|
780
737
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
NotDiamond.Admin = Admin;
|
|
738
|
+
Notdiamond.ModelRouter = ModelRouter;
|
|
739
|
+
Notdiamond.Preferences = Preferences;
|
|
740
|
+
Notdiamond.PromptAdaptation = PromptAdaptation;
|
|
741
|
+
Notdiamond.CustomRouter = CustomRouter;
|
|
742
|
+
Notdiamond.Models = Models;
|
|
787
743
|
|
|
788
|
-
export declare namespace
|
|
744
|
+
export declare namespace Notdiamond {
|
|
789
745
|
export type RequestOptions = Opts.RequestOptions;
|
|
790
746
|
|
|
791
747
|
export {
|
|
792
|
-
|
|
793
|
-
type
|
|
794
|
-
type
|
|
795
|
-
type RoutingTrainCustomRouterResponse as RoutingTrainCustomRouterResponse,
|
|
796
|
-
type RoutingCreateSurveyResponseParams as RoutingCreateSurveyResponseParams,
|
|
797
|
-
type RoutingSelectModelParams as RoutingSelectModelParams,
|
|
798
|
-
type RoutingTrainCustomRouterParams as RoutingTrainCustomRouterParams,
|
|
748
|
+
ModelRouter as ModelRouter,
|
|
749
|
+
type ModelRouterSelectModelResponse as ModelRouterSelectModelResponse,
|
|
750
|
+
type ModelRouterSelectModelParams as ModelRouterSelectModelParams,
|
|
799
751
|
};
|
|
800
752
|
|
|
801
753
|
export {
|
|
802
754
|
Preferences as Preferences,
|
|
803
|
-
type
|
|
804
|
-
type
|
|
805
|
-
type
|
|
806
|
-
type
|
|
807
|
-
type
|
|
808
|
-
type PreferenceCreateUserPreferenceParams as PreferenceCreateUserPreferenceParams,
|
|
809
|
-
type PreferenceUpdateUserPreferenceParams as PreferenceUpdateUserPreferenceParams,
|
|
755
|
+
type PreferenceCreateResponse as PreferenceCreateResponse,
|
|
756
|
+
type PreferenceUpdateResponse as PreferenceUpdateResponse,
|
|
757
|
+
type PreferenceDeleteResponse as PreferenceDeleteResponse,
|
|
758
|
+
type PreferenceCreateParams as PreferenceCreateParams,
|
|
759
|
+
type PreferenceUpdateParams as PreferenceUpdateParams,
|
|
810
760
|
};
|
|
811
761
|
|
|
812
762
|
export {
|
|
813
763
|
PromptAdaptation as PromptAdaptation,
|
|
814
|
-
type
|
|
764
|
+
type GoldenRecord as GoldenRecord,
|
|
815
765
|
type JobStatus as JobStatus,
|
|
766
|
+
type RequestProvider as RequestProvider,
|
|
816
767
|
type PromptAdaptationAdaptResponse as PromptAdaptationAdaptResponse,
|
|
817
|
-
type
|
|
768
|
+
type PromptAdaptationGetAdaptResultsResponse as PromptAdaptationGetAdaptResultsResponse,
|
|
818
769
|
type PromptAdaptationGetAdaptStatusResponse as PromptAdaptationGetAdaptStatusResponse,
|
|
819
|
-
type
|
|
770
|
+
type PromptAdaptationGetCostResponse as PromptAdaptationGetCostResponse,
|
|
820
771
|
type PromptAdaptationAdaptParams as PromptAdaptationAdaptParams,
|
|
821
|
-
type PromptAdaptationGetAdaptRunResultsParams as PromptAdaptationGetAdaptRunResultsParams,
|
|
822
|
-
type PromptAdaptationGetAdaptRunsParams as PromptAdaptationGetAdaptRunsParams,
|
|
823
772
|
};
|
|
824
773
|
|
|
825
774
|
export {
|
|
826
|
-
|
|
827
|
-
type
|
|
828
|
-
type
|
|
829
|
-
type ReportSubmitFeedbackResponse as ReportSubmitFeedbackResponse,
|
|
830
|
-
type ReportEvaluateHallucinationParams as ReportEvaluateHallucinationParams,
|
|
831
|
-
type ReportLatencyParams as ReportLatencyParams,
|
|
832
|
-
type ReportSubmitFeedbackParams as ReportSubmitFeedbackParams,
|
|
775
|
+
CustomRouter as CustomRouter,
|
|
776
|
+
type CustomRouterTrainCustomRouterResponse as CustomRouterTrainCustomRouterResponse,
|
|
777
|
+
type CustomRouterTrainCustomRouterParams as CustomRouterTrainCustomRouterParams,
|
|
833
778
|
};
|
|
834
779
|
|
|
835
780
|
export {
|
|
836
781
|
Models as Models,
|
|
782
|
+
type Model as Model,
|
|
837
783
|
type ModelListResponse as ModelListResponse,
|
|
838
784
|
type ModelListParams as ModelListParams,
|
|
839
785
|
};
|
|
840
|
-
|
|
841
|
-
export { Admin as Admin };
|
|
842
786
|
}
|
package/src/core/api-promise.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import { type
|
|
3
|
+
import { type Notdiamond } from '../client';
|
|
4
4
|
|
|
5
5
|
import { type PromiseOrValue } from '../internal/types';
|
|
6
6
|
import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
@@ -11,13 +11,13 @@ import { APIResponseProps, defaultParseResponse } from '../internal/parse';
|
|
|
11
11
|
*/
|
|
12
12
|
export class APIPromise<T> extends Promise<T> {
|
|
13
13
|
private parsedPromise: Promise<T> | undefined;
|
|
14
|
-
#client:
|
|
14
|
+
#client: Notdiamond;
|
|
15
15
|
|
|
16
16
|
constructor(
|
|
17
|
-
client:
|
|
17
|
+
client: Notdiamond,
|
|
18
18
|
private responsePromise: Promise<APIResponseProps>,
|
|
19
19
|
private parseResponse: (
|
|
20
|
-
client:
|
|
20
|
+
client: Notdiamond,
|
|
21
21
|
props: APIResponseProps,
|
|
22
22
|
) => PromiseOrValue<T> = defaultParseResponse,
|
|
23
23
|
) {
|
package/src/core/error.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { castToError } from '../internal/errors';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class NotdiamondError extends Error {}
|
|
6
6
|
|
|
7
7
|
export class APIError<
|
|
8
8
|
TStatus extends number | undefined = number | undefined,
|
|
9
9
|
THeaders extends Headers | undefined = Headers | undefined,
|
|
10
10
|
TError extends Object | undefined = Object | undefined,
|
|
11
|
-
> extends
|
|
11
|
+
> extends NotdiamondError {
|
|
12
12
|
/** HTTP status for the response that caused the error */
|
|
13
13
|
readonly status: TStatus;
|
|
14
14
|
/** HTTP headers for the response that caused the error */
|
package/src/core/resource.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Notdiamond } from '../client';
|
|
4
4
|
|
|
5
5
|
export abstract class APIResource {
|
|
6
|
-
protected _client:
|
|
6
|
+
protected _client: Notdiamond;
|
|
7
7
|
|
|
8
|
-
constructor(client:
|
|
8
|
+
constructor(client: Notdiamond) {
|
|
9
9
|
this._client = client;
|
|
10
10
|
}
|
|
11
11
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { Notdiamond as default } from './client';
|
|
4
4
|
|
|
5
5
|
export { type Uploadable, toFile } from './core/uploads';
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
|
-
export {
|
|
7
|
+
export { Notdiamond, type ClientOptions } from './client';
|
|
8
8
|
export {
|
|
9
|
-
|
|
9
|
+
NotdiamondError,
|
|
10
10
|
APIError,
|
|
11
11
|
APIConnectionError,
|
|
12
12
|
APIConnectionTimeoutError,
|
package/src/internal/parse.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import type { FinalRequestOptions } from './request-options';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Notdiamond } from '../client';
|
|
5
5
|
import { formatRequestDetails, loggerFor } from './utils/log';
|
|
6
6
|
|
|
7
7
|
export type APIResponseProps = {
|
|
@@ -13,7 +13,7 @@ export type APIResponseProps = {
|
|
|
13
13
|
startTime: number;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export async function defaultParseResponse<T>(client:
|
|
16
|
+
export async function defaultParseResponse<T>(client: Notdiamond, props: APIResponseProps): Promise<T> {
|
|
17
17
|
const { response, requestLogID, retryOfRequestLogID, startTime } = props;
|
|
18
18
|
const body = await (async () => {
|
|
19
19
|
// fetch refuses to read the body when the status code is 204.
|
package/src/internal/shims.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function getDefaultFetch(): Fetch {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
throw new Error(
|
|
19
|
-
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new
|
|
19
|
+
'`fetch` is not defined as a global; Either pass `fetch` to the client, `new Notdiamond({ fetch })` or polyfill the global, `globalThis.fetch = fetch`',
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
package/src/internal/uploads.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type RequestOptions } from './request-options';
|
|
2
2
|
import type { FilePropertyBag, Fetch } from './builtin-types';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Notdiamond } from '../client';
|
|
4
4
|
import { ReadableStreamFrom } from './shims';
|
|
5
5
|
|
|
6
6
|
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
|
|
@@ -74,7 +74,7 @@ export const isAsyncIterable = (value: any): value is AsyncIterable<any> =>
|
|
|
74
74
|
*/
|
|
75
75
|
export const maybeMultipartFormRequestOptions = async (
|
|
76
76
|
opts: RequestOptions,
|
|
77
|
-
fetch:
|
|
77
|
+
fetch: Notdiamond | Fetch,
|
|
78
78
|
): Promise<RequestOptions> => {
|
|
79
79
|
if (!hasUploadableValue(opts.body)) return opts;
|
|
80
80
|
|
|
@@ -85,7 +85,7 @@ type MultipartFormRequestOptions = Omit<RequestOptions, 'body'> & { body: unknow
|
|
|
85
85
|
|
|
86
86
|
export const multipartFormRequestOptions = async (
|
|
87
87
|
opts: MultipartFormRequestOptions,
|
|
88
|
-
fetch:
|
|
88
|
+
fetch: Notdiamond | Fetch,
|
|
89
89
|
): Promise<RequestOptions> => {
|
|
90
90
|
return { ...opts, body: await createForm(opts.body, fetch) };
|
|
91
91
|
};
|
|
@@ -98,7 +98,7 @@ const supportsFormDataMap = /* @__PURE__ */ new WeakMap<Fetch, Promise<boolean>>
|
|
|
98
98
|
* This function detects if the fetch function provided supports the global FormData object to avoid
|
|
99
99
|
* confusing error messages later on.
|
|
100
100
|
*/
|
|
101
|
-
function supportsFormData(fetchObject:
|
|
101
|
+
function supportsFormData(fetchObject: Notdiamond | Fetch): Promise<boolean> {
|
|
102
102
|
const fetch: Fetch = typeof fetchObject === 'function' ? fetchObject : (fetchObject as any).fetch;
|
|
103
103
|
const cached = supportsFormDataMap.get(fetch);
|
|
104
104
|
if (cached) return cached;
|
|
@@ -124,7 +124,7 @@ function supportsFormData(fetchObject: NotDiamond | Fetch): Promise<boolean> {
|
|
|
124
124
|
|
|
125
125
|
export const createForm = async <T = Record<string, unknown>>(
|
|
126
126
|
body: T | undefined,
|
|
127
|
-
fetch:
|
|
127
|
+
fetch: Notdiamond | Fetch,
|
|
128
128
|
): Promise<FormData> => {
|
|
129
129
|
if (!(await supportsFormData(fetch))) {
|
|
130
130
|
throw new TypeError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NotdiamondError } from '../../core/error';
|
|
4
4
|
import { encodeUTF8 } from './bytes';
|
|
5
5
|
|
|
6
6
|
export const toBase64 = (data: string | Uint8Array | null | undefined): string => {
|
|
@@ -18,7 +18,7 @@ export const toBase64 = (data: string | Uint8Array | null | undefined): string =
|
|
|
18
18
|
return btoa(String.fromCharCode.apply(null, data as any));
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
throw new
|
|
21
|
+
throw new NotdiamondError('Cannot generate base64 string; Expected `Buffer` or `btoa` to be defined');
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export const fromBase64 = (str: string): Uint8Array => {
|
|
@@ -36,5 +36,5 @@ export const fromBase64 = (str: string): Uint8Array => {
|
|
|
36
36
|
return buf;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
throw new
|
|
39
|
+
throw new NotdiamondError('Cannot decode base64 string; Expected `Buffer` or `atob` to be defined');
|
|
40
40
|
};
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export const readEnv = (env: string): string | undefined => {
|
|
11
11
|
if (typeof (globalThis as any).process !== 'undefined') {
|
|
12
|
-
|
|
12
|
+
const value = (globalThis as any).process.env?.[env]?.trim() ?? undefined;
|
|
13
|
+
return value === '' ? undefined : value;
|
|
13
14
|
}
|
|
14
15
|
if (typeof (globalThis as any).Deno !== 'undefined') {
|
|
15
|
-
|
|
16
|
+
const value = (globalThis as any).Deno.env?.get?.(env)?.trim();
|
|
17
|
+
return value === '' ? undefined : value;
|
|
16
18
|
}
|
|
17
19
|
return undefined;
|
|
18
20
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { hasOwn } from './values';
|
|
4
|
-
import { type
|
|
4
|
+
import { type Notdiamond } from '../../client';
|
|
5
5
|
import { RequestOptions } from '../request-options';
|
|
6
6
|
|
|
7
7
|
type LogFn = (message: string, ...rest: unknown[]) => void;
|
|
@@ -24,7 +24,7 @@ const levelNumbers = {
|
|
|
24
24
|
export const parseLogLevel = (
|
|
25
25
|
maybeLevel: string | undefined,
|
|
26
26
|
sourceName: string,
|
|
27
|
-
client:
|
|
27
|
+
client: Notdiamond,
|
|
28
28
|
): LogLevel | undefined => {
|
|
29
29
|
if (!maybeLevel) {
|
|
30
30
|
return undefined;
|
|
@@ -60,7 +60,7 @@ const noopLogger = {
|
|
|
60
60
|
|
|
61
61
|
let cachedLoggers = /* @__PURE__ */ new WeakMap<Logger, [LogLevel, Logger]>();
|
|
62
62
|
|
|
63
|
-
export function loggerFor(client:
|
|
63
|
+
export function loggerFor(client: Notdiamond): Logger {
|
|
64
64
|
const logger = client.logger;
|
|
65
65
|
const logLevel = client.logLevel ?? 'off';
|
|
66
66
|
if (!logger) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NotdiamondError } from '../../core/error';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Percent-encode everything that isn't safe to have in a path without encoding safe chars.
|
|
@@ -72,7 +72,7 @@ export const createPathTagFunction = (pathEncoder = encodeURIPath) =>
|
|
|
72
72
|
return acc + spaces + arrows;
|
|
73
73
|
}, '');
|
|
74
74
|
|
|
75
|
-
throw new
|
|
75
|
+
throw new NotdiamondError(
|
|
76
76
|
`Path parameters result in path with invalid segments:\n${invalidSegments
|
|
77
77
|
.map((e) => e.error)
|
|
78
78
|
.join('\n')}\n${path}\n${underline}`,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { NotdiamondError } from '../../core/error';
|
|
4
4
|
|
|
5
5
|
// https://url.spec.whatwg.org/#url-scheme-string
|
|
6
6
|
const startsWithSchemeRegexp = /^[a-z][a-z0-9+.-]*:/i;
|
|
@@ -39,7 +39,7 @@ export function isObj(obj: unknown): obj is Record<string, unknown> {
|
|
|
39
39
|
|
|
40
40
|
export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
41
41
|
if (value == null) {
|
|
42
|
-
throw new
|
|
42
|
+
throw new NotdiamondError(`Expected a value to be given but received ${value} instead.`);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
return value;
|
|
@@ -47,10 +47,10 @@ export const ensurePresent = <T>(value: T | null | undefined): T => {
|
|
|
47
47
|
|
|
48
48
|
export const validatePositiveInteger = (name: string, n: unknown): number => {
|
|
49
49
|
if (typeof n !== 'number' || !Number.isInteger(n)) {
|
|
50
|
-
throw new
|
|
50
|
+
throw new NotdiamondError(`${name} must be an integer`);
|
|
51
51
|
}
|
|
52
52
|
if (n < 0) {
|
|
53
|
-
throw new
|
|
53
|
+
throw new NotdiamondError(`${name} must be a positive integer`);
|
|
54
54
|
}
|
|
55
55
|
return n;
|
|
56
56
|
};
|
|
@@ -59,14 +59,14 @@ export const coerceInteger = (value: unknown): number => {
|
|
|
59
59
|
if (typeof value === 'number') return Math.round(value);
|
|
60
60
|
if (typeof value === 'string') return parseInt(value, 10);
|
|
61
61
|
|
|
62
|
-
throw new
|
|
62
|
+
throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
export const coerceFloat = (value: unknown): number => {
|
|
66
66
|
if (typeof value === 'number') return value;
|
|
67
67
|
if (typeof value === 'string') return parseFloat(value);
|
|
68
68
|
|
|
69
|
-
throw new
|
|
69
|
+
throw new NotdiamondError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const coerceBoolean = (value: unknown): boolean => {
|