@evalgate/sdk 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +638 -0
- package/README.md +398 -0
- package/dist/assertions.d.ts +189 -0
- package/dist/assertions.js +662 -0
- package/dist/batch.d.ts +68 -0
- package/dist/batch.js +179 -0
- package/dist/cache.d.ts +65 -0
- package/dist/cache.js +131 -0
- package/dist/cli/api.d.ts +108 -0
- package/dist/cli/api.js +132 -0
- package/dist/cli/baseline.d.ts +10 -0
- package/dist/cli/baseline.js +172 -0
- package/dist/cli/check.d.ts +73 -0
- package/dist/cli/check.js +355 -0
- package/dist/cli/ci-context.d.ts +6 -0
- package/dist/cli/ci-context.js +112 -0
- package/dist/cli/ci.d.ts +45 -0
- package/dist/cli/ci.js +192 -0
- package/dist/cli/config.d.ts +30 -0
- package/dist/cli/config.js +230 -0
- package/dist/cli/constants.d.ts +15 -0
- package/dist/cli/constants.js +18 -0
- package/dist/cli/diff.d.ts +173 -0
- package/dist/cli/diff.js +685 -0
- package/dist/cli/discover.d.ts +84 -0
- package/dist/cli/discover.js +419 -0
- package/dist/cli/doctor.d.ts +88 -0
- package/dist/cli/doctor.js +675 -0
- package/dist/cli/env.d.ts +21 -0
- package/dist/cli/env.js +42 -0
- package/dist/cli/explain.d.ts +58 -0
- package/dist/cli/explain.js +561 -0
- package/dist/cli/formatters/github.d.ts +8 -0
- package/dist/cli/formatters/github.js +135 -0
- package/dist/cli/formatters/human.d.ts +6 -0
- package/dist/cli/formatters/human.js +110 -0
- package/dist/cli/formatters/json.d.ts +6 -0
- package/dist/cli/formatters/json.js +10 -0
- package/dist/cli/formatters/pr-comment.d.ts +12 -0
- package/dist/cli/formatters/pr-comment.js +103 -0
- package/dist/cli/formatters/types.d.ts +103 -0
- package/dist/cli/formatters/types.js +8 -0
- package/dist/cli/gate.d.ts +21 -0
- package/dist/cli/gate.js +179 -0
- package/dist/cli/impact-analysis.d.ts +63 -0
- package/dist/cli/impact-analysis.js +252 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.js +332 -0
- package/dist/cli/init.d.ts +16 -0
- package/dist/cli/init.js +292 -0
- package/dist/cli/manifest.d.ts +103 -0
- package/dist/cli/manifest.js +282 -0
- package/dist/cli/migrate.d.ts +41 -0
- package/dist/cli/migrate.js +349 -0
- package/dist/cli/policy-packs.d.ts +23 -0
- package/dist/cli/policy-packs.js +89 -0
- package/dist/cli/print-config.d.ts +29 -0
- package/dist/cli/print-config.js +270 -0
- package/dist/cli/profiles.d.ts +28 -0
- package/dist/cli/profiles.js +30 -0
- package/dist/cli/reason-codes.d.ts +17 -0
- package/dist/cli/reason-codes.js +19 -0
- package/dist/cli/regression-gate.d.ts +15 -0
- package/dist/cli/regression-gate.js +341 -0
- package/dist/cli/render/snippet.d.ts +5 -0
- package/dist/cli/render/snippet.js +15 -0
- package/dist/cli/render/sort.d.ts +10 -0
- package/dist/cli/render/sort.js +24 -0
- package/dist/cli/report/build-check-report.d.ts +19 -0
- package/dist/cli/report/build-check-report.js +132 -0
- package/dist/cli/run.d.ts +101 -0
- package/dist/cli/run.js +395 -0
- package/dist/cli/share.d.ts +17 -0
- package/dist/cli/share.js +91 -0
- package/dist/cli/upgrade.d.ts +15 -0
- package/dist/cli/upgrade.js +492 -0
- package/dist/cli/workspace.d.ts +31 -0
- package/dist/cli/workspace.js +68 -0
- package/dist/client.d.ts +368 -0
- package/dist/client.js +893 -0
- package/dist/client.request.test.d.ts +1 -0
- package/dist/client.request.test.js +232 -0
- package/dist/context.d.ts +134 -0
- package/dist/context.js +215 -0
- package/dist/errors.d.ts +82 -0
- package/dist/errors.js +298 -0
- package/dist/export.d.ts +195 -0
- package/dist/export.js +344 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +153 -0
- package/dist/integrations/anthropic.d.ts +91 -0
- package/dist/integrations/anthropic.js +163 -0
- package/dist/integrations/openai-eval.d.ts +57 -0
- package/dist/integrations/openai-eval.js +232 -0
- package/dist/integrations/openai.d.ts +92 -0
- package/dist/integrations/openai.js +160 -0
- package/dist/local.d.ts +39 -0
- package/dist/local.js +148 -0
- package/dist/logger.d.ts +128 -0
- package/dist/logger.js +227 -0
- package/dist/matchers/index.d.ts +1 -0
- package/dist/matchers/index.js +6 -0
- package/dist/matchers/to-pass-gate.d.ts +29 -0
- package/dist/matchers/to-pass-gate.js +35 -0
- package/dist/pagination.d.ts +74 -0
- package/dist/pagination.js +139 -0
- package/dist/regression.d.ts +100 -0
- package/dist/regression.js +44 -0
- package/dist/runtime/adapters/config-to-dsl.d.ts +33 -0
- package/dist/runtime/adapters/config-to-dsl.js +400 -0
- package/dist/runtime/adapters/testsuite-to-dsl.d.ts +63 -0
- package/dist/runtime/adapters/testsuite-to-dsl.js +276 -0
- package/dist/runtime/context.d.ts +26 -0
- package/dist/runtime/context.js +74 -0
- package/dist/runtime/eval.d.ts +46 -0
- package/dist/runtime/eval.js +244 -0
- package/dist/runtime/execution-mode.d.ts +80 -0
- package/dist/runtime/execution-mode.js +357 -0
- package/dist/runtime/executor.d.ts +16 -0
- package/dist/runtime/executor.js +152 -0
- package/dist/runtime/registry.d.ts +78 -0
- package/dist/runtime/registry.js +403 -0
- package/dist/runtime/run-report.d.ts +200 -0
- package/dist/runtime/run-report.js +222 -0
- package/dist/runtime/types.d.ts +356 -0
- package/dist/runtime/types.js +76 -0
- package/dist/snapshot.d.ts +176 -0
- package/dist/snapshot.js +322 -0
- package/dist/streaming.d.ts +173 -0
- package/dist/streaming.js +268 -0
- package/dist/testing.d.ts +273 -0
- package/dist/testing.js +317 -0
- package/dist/types.d.ts +754 -0
- package/dist/types.js +54 -0
- package/dist/utils/input-hash.d.ts +8 -0
- package/dist/utils/input-hash.js +41 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.js +10 -0
- package/dist/workflows.d.ts +389 -0
- package/dist/workflows.js +671 -0
- package/package.json +117 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced SDK Error system with documentation links
|
|
4
|
+
* Tier 1.5: Rich Error Messages
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SDKError = exports.NetworkError = exports.ValidationError = exports.AuthenticationError = exports.RateLimitError = exports.EvalGateError = void 0;
|
|
8
|
+
exports.createErrorFromResponse = createErrorFromResponse;
|
|
9
|
+
/**
|
|
10
|
+
* Comprehensive error documentation
|
|
11
|
+
*/
|
|
12
|
+
const ERROR_DOCS = {
|
|
13
|
+
MISSING_API_KEY: {
|
|
14
|
+
code: "MISSING_API_KEY",
|
|
15
|
+
message: "API key is required to initialize the SDK",
|
|
16
|
+
documentation: "https://docs.ai-eval-platform.com/errors/missing-api-key",
|
|
17
|
+
solutions: [
|
|
18
|
+
"Set EVALGATE_API_KEY environment variable",
|
|
19
|
+
'Pass apiKey in config: new AIEvalClient({ apiKey: "..." })',
|
|
20
|
+
"Get your API key from https://platform.ai-eval-platform.com/settings/api-keys",
|
|
21
|
+
],
|
|
22
|
+
retryable: false,
|
|
23
|
+
},
|
|
24
|
+
MISSING_ORGANIZATION_ID: {
|
|
25
|
+
code: "MISSING_ORGANIZATION_ID",
|
|
26
|
+
message: "Organization ID is required for this operation",
|
|
27
|
+
documentation: "https://docs.ai-eval-platform.com/errors/missing-org-id",
|
|
28
|
+
solutions: [
|
|
29
|
+
"Set EVALGATE_ORGANIZATION_ID environment variable",
|
|
30
|
+
"Pass organizationId in config: new AIEvalClient({ organizationId: 123 })",
|
|
31
|
+
"Pass organizationId in method params",
|
|
32
|
+
],
|
|
33
|
+
retryable: false,
|
|
34
|
+
},
|
|
35
|
+
RATE_LIMIT_EXCEEDED: {
|
|
36
|
+
code: "RATE_LIMIT_EXCEEDED",
|
|
37
|
+
message: "Rate limit exceeded",
|
|
38
|
+
documentation: "https://docs.ai-eval-platform.com/errors/rate-limit",
|
|
39
|
+
solutions: [
|
|
40
|
+
"Wait before retrying (check retryAfter property)",
|
|
41
|
+
"Upgrade your plan for higher rate limits",
|
|
42
|
+
"Implement exponential backoff in your application",
|
|
43
|
+
],
|
|
44
|
+
retryable: true,
|
|
45
|
+
},
|
|
46
|
+
TIMEOUT: {
|
|
47
|
+
code: "TIMEOUT",
|
|
48
|
+
message: "Request timed out",
|
|
49
|
+
documentation: "https://docs.ai-eval-platform.com/errors/timeout",
|
|
50
|
+
solutions: [
|
|
51
|
+
"Increase timeout: new AIEvalClient({ timeout: 60000 })",
|
|
52
|
+
"Check your network connection",
|
|
53
|
+
"The service may be experiencing high load",
|
|
54
|
+
],
|
|
55
|
+
retryable: true,
|
|
56
|
+
},
|
|
57
|
+
NETWORK_ERROR: {
|
|
58
|
+
code: "NETWORK_ERROR",
|
|
59
|
+
message: "Network connectivity issue",
|
|
60
|
+
documentation: "https://docs.ai-eval-platform.com/errors/network",
|
|
61
|
+
solutions: [
|
|
62
|
+
"Check your internet connection",
|
|
63
|
+
"Verify the baseUrl is correct",
|
|
64
|
+
"Check if you can reach the API endpoint",
|
|
65
|
+
],
|
|
66
|
+
retryable: true,
|
|
67
|
+
},
|
|
68
|
+
UNAUTHORIZED: {
|
|
69
|
+
code: "UNAUTHORIZED",
|
|
70
|
+
message: "Authentication failed",
|
|
71
|
+
documentation: "https://docs.ai-eval-platform.com/errors/unauthorized",
|
|
72
|
+
solutions: [
|
|
73
|
+
"Verify your API key is correct",
|
|
74
|
+
"Check if your API key has expired",
|
|
75
|
+
"Ensure your API key has the required permissions",
|
|
76
|
+
],
|
|
77
|
+
retryable: false,
|
|
78
|
+
},
|
|
79
|
+
FORBIDDEN: {
|
|
80
|
+
code: "FORBIDDEN",
|
|
81
|
+
message: "Access forbidden",
|
|
82
|
+
documentation: "https://docs.ai-eval-platform.com/errors/forbidden",
|
|
83
|
+
solutions: [
|
|
84
|
+
"Check if you have permission for this resource",
|
|
85
|
+
"Verify you're using the correct organization ID",
|
|
86
|
+
"Contact support if you believe this is an error",
|
|
87
|
+
],
|
|
88
|
+
retryable: false,
|
|
89
|
+
},
|
|
90
|
+
NOT_FOUND: {
|
|
91
|
+
code: "NOT_FOUND",
|
|
92
|
+
message: "Resource not found",
|
|
93
|
+
documentation: "https://docs.ai-eval-platform.com/errors/not-found",
|
|
94
|
+
solutions: [
|
|
95
|
+
"Verify the resource ID is correct",
|
|
96
|
+
"Check if the resource was deleted",
|
|
97
|
+
"Ensure you're querying the correct organization",
|
|
98
|
+
],
|
|
99
|
+
retryable: false,
|
|
100
|
+
},
|
|
101
|
+
VALIDATION_ERROR: {
|
|
102
|
+
code: "VALIDATION_ERROR",
|
|
103
|
+
message: "Request validation failed",
|
|
104
|
+
documentation: "https://docs.ai-eval-platform.com/errors/validation",
|
|
105
|
+
solutions: [
|
|
106
|
+
"Check the error details for specific validation failures",
|
|
107
|
+
"Verify all required fields are provided",
|
|
108
|
+
"Ensure field types match the expected format",
|
|
109
|
+
],
|
|
110
|
+
retryable: false,
|
|
111
|
+
},
|
|
112
|
+
INTERNAL_SERVER_ERROR: {
|
|
113
|
+
code: "INTERNAL_SERVER_ERROR",
|
|
114
|
+
message: "Internal server error",
|
|
115
|
+
documentation: "https://docs.ai-eval-platform.com/errors/server-error",
|
|
116
|
+
solutions: [
|
|
117
|
+
"Retry the request after a brief delay",
|
|
118
|
+
"Check status page: https://status.ai-eval-platform.com",
|
|
119
|
+
"Contact support if the issue persists",
|
|
120
|
+
],
|
|
121
|
+
retryable: true,
|
|
122
|
+
},
|
|
123
|
+
FEATURE_LIMIT_REACHED: {
|
|
124
|
+
code: "FEATURE_LIMIT_REACHED",
|
|
125
|
+
message: "Feature usage limit reached",
|
|
126
|
+
documentation: "https://docs.ai-eval-platform.com/errors/feature-limit",
|
|
127
|
+
solutions: [
|
|
128
|
+
"Upgrade your plan for higher limits",
|
|
129
|
+
"Wait for your usage to reset (check resetAt property)",
|
|
130
|
+
"Optimize your usage patterns",
|
|
131
|
+
],
|
|
132
|
+
retryable: false,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Enhanced SDK Error class with rich error information and documentation
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* try {
|
|
141
|
+
* await client.traces.create({ ... });
|
|
142
|
+
* } catch (error) {
|
|
143
|
+
* if (error instanceof EvalGateError) {
|
|
144
|
+
* console.log(error.code); // 'RATE_LIMIT_EXCEEDED'
|
|
145
|
+
* console.log(error.documentation); // Link to docs
|
|
146
|
+
* console.log(error.solutions); // Array of solutions
|
|
147
|
+
* console.log(error.retryable); // true/false
|
|
148
|
+
*
|
|
149
|
+
* if (error.retryAfter) {
|
|
150
|
+
* console.log(`Retry after ${error.retryAfter} seconds`);
|
|
151
|
+
* }
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
class EvalGateError extends Error {
|
|
157
|
+
constructor(message, code, statusCode, details) {
|
|
158
|
+
super(message);
|
|
159
|
+
this.name = "EvalGateError";
|
|
160
|
+
this.code = code;
|
|
161
|
+
this.statusCode = statusCode;
|
|
162
|
+
this.details = details;
|
|
163
|
+
// Initialize required properties from ERROR_DOCS
|
|
164
|
+
const doc = ERROR_DOCS[code];
|
|
165
|
+
this.documentation =
|
|
166
|
+
doc?.documentation ?? `https://docs.ai-eval-platform.com/errors/${code}`;
|
|
167
|
+
this.solutions = doc?.solutions ?? [
|
|
168
|
+
"Check the error details for more information",
|
|
169
|
+
];
|
|
170
|
+
this.retryable = doc?.retryable ?? false;
|
|
171
|
+
// Extract retry-after for rate limits
|
|
172
|
+
const errorDetails = details;
|
|
173
|
+
if (code === "RATE_LIMIT_EXCEEDED" && errorDetails?.retryAfter) {
|
|
174
|
+
this.retryAfter = errorDetails.retryAfter;
|
|
175
|
+
}
|
|
176
|
+
// Extract reset time for feature limits
|
|
177
|
+
if (code === "FEATURE_LIMIT_REACHED" && errorDetails?.resetAt) {
|
|
178
|
+
this.resetAt = new Date(errorDetails.resetAt);
|
|
179
|
+
}
|
|
180
|
+
this.requestId =
|
|
181
|
+
errorDetails?.error?.requestId ?? errorDetails?.requestId;
|
|
182
|
+
// Ensure proper prototype chain
|
|
183
|
+
Object.setPrototypeOf(this, EvalGateError.prototype);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Get formatted error message with solutions
|
|
187
|
+
*/
|
|
188
|
+
getDetailedMessage() {
|
|
189
|
+
let msg = `${this.code}: ${this.message}\n\n`;
|
|
190
|
+
msg += `Documentation: ${this.documentation}\n\n`;
|
|
191
|
+
msg += "Suggested solutions:\n";
|
|
192
|
+
this.solutions.forEach((solution, i) => {
|
|
193
|
+
msg += ` ${i + 1}. ${solution}\n`;
|
|
194
|
+
});
|
|
195
|
+
if (this.retryAfter) {
|
|
196
|
+
msg += `\nRetry after: ${this.retryAfter} seconds`;
|
|
197
|
+
}
|
|
198
|
+
if (this.resetAt) {
|
|
199
|
+
msg += `\nLimit resets at: ${this.resetAt.toISOString()}`;
|
|
200
|
+
}
|
|
201
|
+
return msg;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Check if this error should be retried
|
|
205
|
+
*/
|
|
206
|
+
shouldRetry() {
|
|
207
|
+
return this.retryable;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Convert to JSON for logging
|
|
211
|
+
*/
|
|
212
|
+
toJSON() {
|
|
213
|
+
return {
|
|
214
|
+
name: this.name,
|
|
215
|
+
code: this.code,
|
|
216
|
+
message: this.message,
|
|
217
|
+
statusCode: this.statusCode,
|
|
218
|
+
documentation: this.documentation,
|
|
219
|
+
solutions: this.solutions,
|
|
220
|
+
retryable: this.retryable,
|
|
221
|
+
retryAfter: this.retryAfter,
|
|
222
|
+
resetAt: this.resetAt,
|
|
223
|
+
requestId: this.requestId,
|
|
224
|
+
details: this.details,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.EvalGateError = EvalGateError;
|
|
229
|
+
exports.SDKError = EvalGateError;
|
|
230
|
+
/**
|
|
231
|
+
* Create an error from an HTTP response
|
|
232
|
+
*/
|
|
233
|
+
function createErrorFromResponse(response, data) {
|
|
234
|
+
const status = response.status;
|
|
235
|
+
const errorData = data;
|
|
236
|
+
const errObj = errorData?.error && typeof errorData.error === "object"
|
|
237
|
+
? errorData.error
|
|
238
|
+
: errorData;
|
|
239
|
+
let code = errObj?.code ?? errorData?.code ?? "UNKNOWN_ERROR";
|
|
240
|
+
const message = typeof errorData?.error === "string"
|
|
241
|
+
? errorData.error
|
|
242
|
+
: (errObj?.message ?? errorData?.message ?? response.statusText);
|
|
243
|
+
const requestId = errObj?.requestId ??
|
|
244
|
+
errorData?.requestId ??
|
|
245
|
+
response.headers.get("x-request-id") ??
|
|
246
|
+
undefined;
|
|
247
|
+
// Map HTTP status to error codes when code not in response
|
|
248
|
+
if (!errObj?.code && !errorData?.code) {
|
|
249
|
+
if (status === 401)
|
|
250
|
+
code = "UNAUTHORIZED";
|
|
251
|
+
else if (status === 403)
|
|
252
|
+
code = "FORBIDDEN";
|
|
253
|
+
else if (status === 404)
|
|
254
|
+
code = "NOT_FOUND";
|
|
255
|
+
else if (status === 408)
|
|
256
|
+
code = "TIMEOUT";
|
|
257
|
+
else if (status === 422)
|
|
258
|
+
code = "VALIDATION_ERROR";
|
|
259
|
+
else if (status === 429)
|
|
260
|
+
code = "RATE_LIMIT_EXCEEDED";
|
|
261
|
+
else if (status >= 500)
|
|
262
|
+
code = "INTERNAL_SERVER_ERROR";
|
|
263
|
+
}
|
|
264
|
+
const err = new EvalGateError(message, code, status, data);
|
|
265
|
+
if (requestId)
|
|
266
|
+
err.requestId = requestId;
|
|
267
|
+
return err;
|
|
268
|
+
}
|
|
269
|
+
// Specific error types
|
|
270
|
+
class RateLimitError extends EvalGateError {
|
|
271
|
+
constructor(message, retryAfter) {
|
|
272
|
+
super(message, "RATE_LIMIT_EXCEEDED", 429, { retryAfter });
|
|
273
|
+
this.name = "RateLimitError";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.RateLimitError = RateLimitError;
|
|
277
|
+
class AuthenticationError extends EvalGateError {
|
|
278
|
+
constructor(message = "Authentication failed") {
|
|
279
|
+
super(message, "AUTHENTICATION_ERROR", 401);
|
|
280
|
+
this.name = "AuthenticationError";
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
exports.AuthenticationError = AuthenticationError;
|
|
284
|
+
class ValidationError extends EvalGateError {
|
|
285
|
+
constructor(message = "Validation failed", details) {
|
|
286
|
+
super(message, "VALIDATION_ERROR", 400, details);
|
|
287
|
+
this.name = "ValidationError";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.ValidationError = ValidationError;
|
|
291
|
+
class NetworkError extends EvalGateError {
|
|
292
|
+
constructor(message = "Network request failed") {
|
|
293
|
+
super(message, "NETWORK_ERROR", 0);
|
|
294
|
+
this.name = "NetworkError";
|
|
295
|
+
this.retryable = true;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.NetworkError = NetworkError;
|
package/dist/export.d.ts
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data Export/Import System
|
|
3
|
+
* Tier 4.18: Platform migration and backup utilities
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import { exportData, importData } from '@ai-eval-platform/sdk';
|
|
8
|
+
*
|
|
9
|
+
* // Export all data
|
|
10
|
+
* const data = await exportData(client, {
|
|
11
|
+
* format: 'json',
|
|
12
|
+
* includeTraces: true,
|
|
13
|
+
* includeEvaluations: true
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* // Save to file
|
|
17
|
+
* fs.writeFileSync('backup.json', JSON.stringify(data, null, 2));
|
|
18
|
+
*
|
|
19
|
+
* // Import from another platform
|
|
20
|
+
* await importFromLangSmith(client, langsmithData);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
import type { AIEvalClient } from "./client";
|
|
24
|
+
import type { Evaluation, EvaluationRun, TestCase, Trace } from "./types";
|
|
25
|
+
export type ExportFormat = "json" | "csv" | "jsonl";
|
|
26
|
+
export type { ExportFormat as ExportType };
|
|
27
|
+
export interface ExportOptions {
|
|
28
|
+
/** Export format */
|
|
29
|
+
format: "json" | "csv" | "jsonl";
|
|
30
|
+
/** Include traces */
|
|
31
|
+
includeTraces?: boolean;
|
|
32
|
+
/** Include evaluations */
|
|
33
|
+
includeEvaluations?: boolean;
|
|
34
|
+
/** Include test cases */
|
|
35
|
+
includeTestCases?: boolean;
|
|
36
|
+
/** Include evaluation runs */
|
|
37
|
+
includeRuns?: boolean;
|
|
38
|
+
/** Date range filter */
|
|
39
|
+
dateRange?: {
|
|
40
|
+
from: string;
|
|
41
|
+
to: string;
|
|
42
|
+
};
|
|
43
|
+
/** Organization ID filter */
|
|
44
|
+
organizationId?: number;
|
|
45
|
+
/** Maximum items to export (default: no limit) */
|
|
46
|
+
limit?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ExportData {
|
|
49
|
+
/** Export metadata */
|
|
50
|
+
metadata: {
|
|
51
|
+
exportedAt: string;
|
|
52
|
+
version: string;
|
|
53
|
+
format: string;
|
|
54
|
+
organizationId?: number;
|
|
55
|
+
};
|
|
56
|
+
/** Exported traces */
|
|
57
|
+
traces?: Trace[];
|
|
58
|
+
/** Exported evaluations */
|
|
59
|
+
evaluations?: Evaluation[];
|
|
60
|
+
/** Exported test cases */
|
|
61
|
+
testCases?: TestCase[];
|
|
62
|
+
/** Exported runs */
|
|
63
|
+
runs?: EvaluationRun[];
|
|
64
|
+
}
|
|
65
|
+
export interface ImportOptions {
|
|
66
|
+
/** Organization ID to import into */
|
|
67
|
+
organizationId?: number;
|
|
68
|
+
/** User ID for created resources */
|
|
69
|
+
createdBy?: number;
|
|
70
|
+
/** Skip duplicates (based on name) */
|
|
71
|
+
skipDuplicates?: boolean;
|
|
72
|
+
/** Dry run (don't actually import) */
|
|
73
|
+
dryRun?: boolean;
|
|
74
|
+
}
|
|
75
|
+
export interface ImportResult {
|
|
76
|
+
/** Import summary */
|
|
77
|
+
summary: {
|
|
78
|
+
total: number;
|
|
79
|
+
imported: number;
|
|
80
|
+
skipped: number;
|
|
81
|
+
failed: number;
|
|
82
|
+
};
|
|
83
|
+
/** Detailed results */
|
|
84
|
+
details: {
|
|
85
|
+
traces?: {
|
|
86
|
+
imported: number;
|
|
87
|
+
skipped: number;
|
|
88
|
+
failed: number;
|
|
89
|
+
};
|
|
90
|
+
evaluations?: {
|
|
91
|
+
imported: number;
|
|
92
|
+
skipped: number;
|
|
93
|
+
failed: number;
|
|
94
|
+
};
|
|
95
|
+
testCases?: {
|
|
96
|
+
imported: number;
|
|
97
|
+
skipped: number;
|
|
98
|
+
failed: number;
|
|
99
|
+
};
|
|
100
|
+
runs?: {
|
|
101
|
+
imported: number;
|
|
102
|
+
skipped: number;
|
|
103
|
+
failed: number;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
/** Errors encountered */
|
|
107
|
+
errors?: Array<{
|
|
108
|
+
item: string;
|
|
109
|
+
error: string;
|
|
110
|
+
}>;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Export data from the platform
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const data = await exportData(client, {
|
|
118
|
+
* format: 'json',
|
|
119
|
+
* includeTraces: true,
|
|
120
|
+
* includeEvaluations: true,
|
|
121
|
+
* dateRange: { from: '2024-01-01', to: '2024-12-31' }
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* // Save to file
|
|
125
|
+
* fs.writeFileSync('backup.json', JSON.stringify(data, null, 2));
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function exportData(client: AIEvalClient, options: ExportOptions): Promise<ExportData>;
|
|
129
|
+
/**
|
|
130
|
+
* Import data into the platform
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```typescript
|
|
134
|
+
* const data = JSON.parse(fs.readFileSync('backup.json', 'utf-8'));
|
|
135
|
+
* const result = await importData(client, data, {
|
|
136
|
+
* organizationId: 123,
|
|
137
|
+
* skipDuplicates: true
|
|
138
|
+
* });
|
|
139
|
+
*
|
|
140
|
+
* console.log(`Imported ${result.summary.imported} items`);
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function importData(client: AIEvalClient, data: ExportData, options: ImportOptions): Promise<ImportResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Export data to JSON file
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* await exportToFile(client, './backup.json', {
|
|
150
|
+
* includeTraces: true,
|
|
151
|
+
* includeEvaluations: true
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function exportToFile(client: AIEvalClient, filePath: string, options: Omit<ExportOptions, "format">): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Import data from JSON file
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const result = await importFromFile(client, './backup.json', {
|
|
162
|
+
* organizationId: 123,
|
|
163
|
+
* createdBy: 1
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export declare function importFromFile(client: AIEvalClient, filePath: string, options: ImportOptions): Promise<ImportResult>;
|
|
168
|
+
/**
|
|
169
|
+
* Import from LangSmith format
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const langsmithData = {
|
|
174
|
+
* runs: [
|
|
175
|
+
* { name: 'test-1', inputs: { ... }, outputs: { ... } }
|
|
176
|
+
* ]
|
|
177
|
+
* };
|
|
178
|
+
*
|
|
179
|
+
* await importFromLangSmith(client, langsmithData, {
|
|
180
|
+
* organizationId: 123
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
export declare function importFromLangSmith(client: AIEvalClient, langsmithData: unknown, options: ImportOptions): Promise<ImportResult>;
|
|
185
|
+
/**
|
|
186
|
+
* Convert export data to CSV format
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const data = await exportData(client, { format: 'json', includeTraces: true });
|
|
191
|
+
* const csv = convertToCSV(data, 'traces');
|
|
192
|
+
* fs.writeFileSync('traces.csv', csv);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export declare function convertToCSV(data: ExportData, type: "traces" | "evaluations"): string;
|