@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.
Files changed (141) hide show
  1. package/CHANGELOG.md +638 -0
  2. package/README.md +398 -0
  3. package/dist/assertions.d.ts +189 -0
  4. package/dist/assertions.js +662 -0
  5. package/dist/batch.d.ts +68 -0
  6. package/dist/batch.js +179 -0
  7. package/dist/cache.d.ts +65 -0
  8. package/dist/cache.js +131 -0
  9. package/dist/cli/api.d.ts +108 -0
  10. package/dist/cli/api.js +132 -0
  11. package/dist/cli/baseline.d.ts +10 -0
  12. package/dist/cli/baseline.js +172 -0
  13. package/dist/cli/check.d.ts +73 -0
  14. package/dist/cli/check.js +355 -0
  15. package/dist/cli/ci-context.d.ts +6 -0
  16. package/dist/cli/ci-context.js +112 -0
  17. package/dist/cli/ci.d.ts +45 -0
  18. package/dist/cli/ci.js +192 -0
  19. package/dist/cli/config.d.ts +30 -0
  20. package/dist/cli/config.js +230 -0
  21. package/dist/cli/constants.d.ts +15 -0
  22. package/dist/cli/constants.js +18 -0
  23. package/dist/cli/diff.d.ts +173 -0
  24. package/dist/cli/diff.js +685 -0
  25. package/dist/cli/discover.d.ts +84 -0
  26. package/dist/cli/discover.js +419 -0
  27. package/dist/cli/doctor.d.ts +88 -0
  28. package/dist/cli/doctor.js +675 -0
  29. package/dist/cli/env.d.ts +21 -0
  30. package/dist/cli/env.js +42 -0
  31. package/dist/cli/explain.d.ts +58 -0
  32. package/dist/cli/explain.js +561 -0
  33. package/dist/cli/formatters/github.d.ts +8 -0
  34. package/dist/cli/formatters/github.js +135 -0
  35. package/dist/cli/formatters/human.d.ts +6 -0
  36. package/dist/cli/formatters/human.js +110 -0
  37. package/dist/cli/formatters/json.d.ts +6 -0
  38. package/dist/cli/formatters/json.js +10 -0
  39. package/dist/cli/formatters/pr-comment.d.ts +12 -0
  40. package/dist/cli/formatters/pr-comment.js +103 -0
  41. package/dist/cli/formatters/types.d.ts +103 -0
  42. package/dist/cli/formatters/types.js +8 -0
  43. package/dist/cli/gate.d.ts +21 -0
  44. package/dist/cli/gate.js +179 -0
  45. package/dist/cli/impact-analysis.d.ts +63 -0
  46. package/dist/cli/impact-analysis.js +252 -0
  47. package/dist/cli/index.d.ts +9 -0
  48. package/dist/cli/index.js +332 -0
  49. package/dist/cli/init.d.ts +16 -0
  50. package/dist/cli/init.js +292 -0
  51. package/dist/cli/manifest.d.ts +103 -0
  52. package/dist/cli/manifest.js +282 -0
  53. package/dist/cli/migrate.d.ts +41 -0
  54. package/dist/cli/migrate.js +349 -0
  55. package/dist/cli/policy-packs.d.ts +23 -0
  56. package/dist/cli/policy-packs.js +89 -0
  57. package/dist/cli/print-config.d.ts +29 -0
  58. package/dist/cli/print-config.js +270 -0
  59. package/dist/cli/profiles.d.ts +28 -0
  60. package/dist/cli/profiles.js +30 -0
  61. package/dist/cli/reason-codes.d.ts +17 -0
  62. package/dist/cli/reason-codes.js +19 -0
  63. package/dist/cli/regression-gate.d.ts +15 -0
  64. package/dist/cli/regression-gate.js +341 -0
  65. package/dist/cli/render/snippet.d.ts +5 -0
  66. package/dist/cli/render/snippet.js +15 -0
  67. package/dist/cli/render/sort.d.ts +10 -0
  68. package/dist/cli/render/sort.js +24 -0
  69. package/dist/cli/report/build-check-report.d.ts +19 -0
  70. package/dist/cli/report/build-check-report.js +132 -0
  71. package/dist/cli/run.d.ts +101 -0
  72. package/dist/cli/run.js +395 -0
  73. package/dist/cli/share.d.ts +17 -0
  74. package/dist/cli/share.js +91 -0
  75. package/dist/cli/upgrade.d.ts +15 -0
  76. package/dist/cli/upgrade.js +492 -0
  77. package/dist/cli/workspace.d.ts +31 -0
  78. package/dist/cli/workspace.js +68 -0
  79. package/dist/client.d.ts +368 -0
  80. package/dist/client.js +893 -0
  81. package/dist/client.request.test.d.ts +1 -0
  82. package/dist/client.request.test.js +232 -0
  83. package/dist/context.d.ts +134 -0
  84. package/dist/context.js +215 -0
  85. package/dist/errors.d.ts +82 -0
  86. package/dist/errors.js +298 -0
  87. package/dist/export.d.ts +195 -0
  88. package/dist/export.js +344 -0
  89. package/dist/index.d.ts +44 -0
  90. package/dist/index.js +153 -0
  91. package/dist/integrations/anthropic.d.ts +91 -0
  92. package/dist/integrations/anthropic.js +163 -0
  93. package/dist/integrations/openai-eval.d.ts +57 -0
  94. package/dist/integrations/openai-eval.js +232 -0
  95. package/dist/integrations/openai.d.ts +92 -0
  96. package/dist/integrations/openai.js +160 -0
  97. package/dist/local.d.ts +39 -0
  98. package/dist/local.js +148 -0
  99. package/dist/logger.d.ts +128 -0
  100. package/dist/logger.js +227 -0
  101. package/dist/matchers/index.d.ts +1 -0
  102. package/dist/matchers/index.js +6 -0
  103. package/dist/matchers/to-pass-gate.d.ts +29 -0
  104. package/dist/matchers/to-pass-gate.js +35 -0
  105. package/dist/pagination.d.ts +74 -0
  106. package/dist/pagination.js +139 -0
  107. package/dist/regression.d.ts +100 -0
  108. package/dist/regression.js +44 -0
  109. package/dist/runtime/adapters/config-to-dsl.d.ts +33 -0
  110. package/dist/runtime/adapters/config-to-dsl.js +400 -0
  111. package/dist/runtime/adapters/testsuite-to-dsl.d.ts +63 -0
  112. package/dist/runtime/adapters/testsuite-to-dsl.js +276 -0
  113. package/dist/runtime/context.d.ts +26 -0
  114. package/dist/runtime/context.js +74 -0
  115. package/dist/runtime/eval.d.ts +46 -0
  116. package/dist/runtime/eval.js +244 -0
  117. package/dist/runtime/execution-mode.d.ts +80 -0
  118. package/dist/runtime/execution-mode.js +357 -0
  119. package/dist/runtime/executor.d.ts +16 -0
  120. package/dist/runtime/executor.js +152 -0
  121. package/dist/runtime/registry.d.ts +78 -0
  122. package/dist/runtime/registry.js +403 -0
  123. package/dist/runtime/run-report.d.ts +200 -0
  124. package/dist/runtime/run-report.js +222 -0
  125. package/dist/runtime/types.d.ts +356 -0
  126. package/dist/runtime/types.js +76 -0
  127. package/dist/snapshot.d.ts +176 -0
  128. package/dist/snapshot.js +322 -0
  129. package/dist/streaming.d.ts +173 -0
  130. package/dist/streaming.js +268 -0
  131. package/dist/testing.d.ts +273 -0
  132. package/dist/testing.js +317 -0
  133. package/dist/types.d.ts +754 -0
  134. package/dist/types.js +54 -0
  135. package/dist/utils/input-hash.d.ts +8 -0
  136. package/dist/utils/input-hash.js +41 -0
  137. package/dist/version.d.ts +7 -0
  138. package/dist/version.js +10 -0
  139. package/dist/workflows.d.ts +389 -0
  140. package/dist/workflows.js +671 -0
  141. package/package.json +117 -0
@@ -0,0 +1,368 @@
1
+ import { type Logger } from "./logger";
2
+ import type { Annotation, AnnotationItem, AnnotationTask, APIKey, APIKeyUsage, APIKeyWithSecret, ClientConfig, CreateAnnotationItemParams, CreateAnnotationParams, CreateAnnotationTaskParams, CreateAPIKeyParams, CreateEvaluationParams, CreateLLMJudgeConfigParams, CreateRunParams, CreateSpanParams, CreateTestCaseParams, CreateTraceParams, CreateWebhookParams, Evaluation, EvaluationRun, EvaluationRunDetail, GetLLMJudgeAlignmentParams, GetUsageParams, ListAnnotationItemsParams, ListAnnotationsParams, ListAnnotationTasksParams, ListAPIKeysParams, ListEvaluationsParams, ListLLMJudgeConfigsParams, ListLLMJudgeResultsParams, ListTracesParams, ListWebhookDeliveriesParams, ListWebhooksParams, LLMJudgeAlignment, LLMJudgeConfig, LLMJudgeEvaluateResult, LLMJudgeResult, Organization, OrganizationLimits, RunLLMJudgeParams, Span, TestCase, Trace, TraceDetail, UpdateAPIKeyParams, UpdateEvaluationParams, UpdateTraceParams, UpdateWebhookParams, UsageStats, UsageSummary, Webhook, WebhookDelivery } from "./types";
3
+ /**
4
+ * EvalGate SDK Client
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { AIEvalClient } from '@ai-eval-platform/sdk';
9
+ *
10
+ * // Zero-config initialization (uses env variables)
11
+ * const client = AIEvalClient.init();
12
+ *
13
+ * // Or with explicit config
14
+ * const client = new AIEvalClient({
15
+ * apiKey: 'your-api-key',
16
+ * organizationId: 123,
17
+ * debug: true
18
+ * });
19
+ *
20
+ * // Create a trace with automatic context propagation
21
+ * const trace = await client.traces.create({
22
+ * name: 'User Query',
23
+ * traceId: 'trace-123'
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class AIEvalClient {
28
+ private apiKey;
29
+ private baseUrl;
30
+ private organizationId?;
31
+ private timeout;
32
+ private logger;
33
+ private requestLogger;
34
+ private cache;
35
+ private batcher;
36
+ private retryConfig;
37
+ traces: TraceAPI;
38
+ evaluations: EvaluationAPI;
39
+ llmJudge: LLMJudgeAPI;
40
+ annotations: AnnotationsAPI;
41
+ developer: DeveloperAPI;
42
+ organizations: OrganizationsAPI;
43
+ constructor(config?: ClientConfig);
44
+ /**
45
+ * Zero-config initialization using environment variables
46
+ *
47
+ * Works in both Node.js and browsers. In Node.js, reads from environment variables.
48
+ * In browsers, you must provide config explicitly.
49
+ *
50
+ * Environment variables (Node.js only):
51
+ * - EVALGATE_API_KEY (or EVALAI_API_KEY): Your API key
52
+ * - EVALGATE_ORGANIZATION_ID (or EVALAI_ORGANIZATION_ID): Your organization ID
53
+ * - EVALGATE_BASE_URL (or EVALAI_BASE_URL): Custom API base URL (optional)
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Node.js - reads from env vars:
58
+ * // EVALGATE_API_KEY=your-key
59
+ * // EVALGATE_ORGANIZATION_ID=123
60
+ * const client = AIEvalClient.init();
61
+ *
62
+ * // Browser - must provide config:
63
+ * const client = AIEvalClient.init({
64
+ * apiKey: 'your-key',
65
+ * organizationId: 123
66
+ * });
67
+ * ```
68
+ */
69
+ static init(config?: Partial<ClientConfig>): AIEvalClient;
70
+ /**
71
+ * Internal method to make HTTP requests with retry logic and error handling
72
+ */
73
+ request<T>(endpoint: string, options?: RequestInit, attempt?: number): Promise<T>;
74
+ /**
75
+ * Calculate backoff delay for retries
76
+ */
77
+ private calculateBackoff;
78
+ getOrganizationId(): number | undefined;
79
+ /**
80
+ * Get the logger instance for custom logging
81
+ */
82
+ getLogger(): Logger;
83
+ /**
84
+ * @deprecated The /api/organizations/:id/limits endpoint does not exist.
85
+ * Use `organizations.getCurrent()` to get org info instead.
86
+ */
87
+ getOrganizationLimits(): Promise<OrganizationLimits>;
88
+ }
89
+ /**
90
+ * Trace API methods
91
+ */
92
+ declare class TraceAPI {
93
+ private client;
94
+ constructor(client: AIEvalClient);
95
+ /**
96
+ * Create a new trace with automatic context propagation
97
+ *
98
+ * @example
99
+ * ```typescript
100
+ * const trace = await client.traces.create({
101
+ * name: 'User Query',
102
+ * traceId: 'trace-123',
103
+ * metadata: { userId: '456' }
104
+ * });
105
+ * ```
106
+ */
107
+ create<TMetadata = Record<string, unknown>>(params: CreateTraceParams<TMetadata>): Promise<Trace<TMetadata>>;
108
+ /**
109
+ * List traces with optional filtering
110
+ */
111
+ list(params?: ListTracesParams): Promise<Trace[]>;
112
+ /**
113
+ * Delete a trace by ID
114
+ */
115
+ delete(id: number): Promise<{
116
+ message: string;
117
+ }>;
118
+ /**
119
+ * Get a single trace by ID, including its spans
120
+ */
121
+ get(id: number): Promise<TraceDetail>;
122
+ /**
123
+ * Update an existing trace (e.g. set status, duration, metadata on completion)
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * await client.traces.update(42, {
128
+ * status: 'success',
129
+ * durationMs: 1234,
130
+ * metadata: { output: 'done' }
131
+ * });
132
+ * ```
133
+ */
134
+ update<TMetadata = Record<string, unknown>>(id: number, params: UpdateTraceParams<TMetadata>): Promise<Trace<TMetadata>>;
135
+ /**
136
+ * Create a span for a trace
137
+ */
138
+ createSpan(traceId: number, params: CreateSpanParams): Promise<Span>;
139
+ /**
140
+ * List spans for a trace
141
+ */
142
+ listSpans(traceId: number): Promise<Span[]>;
143
+ }
144
+ /**
145
+ * Evaluation API methods
146
+ */
147
+ declare class EvaluationAPI {
148
+ private client;
149
+ constructor(client: AIEvalClient);
150
+ /**
151
+ * Create a new evaluation
152
+ */
153
+ create(params: CreateEvaluationParams): Promise<Evaluation>;
154
+ /**
155
+ * Get a single evaluation by ID
156
+ */
157
+ get(id: number): Promise<Evaluation>;
158
+ /**
159
+ * List evaluations with optional filtering
160
+ */
161
+ list(params?: ListEvaluationsParams): Promise<Evaluation[]>;
162
+ /**
163
+ * Update an evaluation
164
+ */
165
+ update(id: number, params: UpdateEvaluationParams): Promise<Evaluation>;
166
+ /**
167
+ * Delete an evaluation
168
+ */
169
+ delete(id: number): Promise<{
170
+ message: string;
171
+ }>;
172
+ /**
173
+ * Create a test case for an evaluation
174
+ */
175
+ createTestCase(evaluationId: number, params: CreateTestCaseParams): Promise<TestCase>;
176
+ /**
177
+ * List test cases for an evaluation
178
+ */
179
+ listTestCases(evaluationId: number): Promise<TestCase[]>;
180
+ /**
181
+ * Create a run for an evaluation
182
+ */
183
+ createRun(evaluationId: number, params: CreateRunParams): Promise<EvaluationRun>;
184
+ /**
185
+ * List runs for an evaluation
186
+ */
187
+ listRuns(evaluationId: number): Promise<EvaluationRun[]>;
188
+ /**
189
+ * Get a specific run with its results
190
+ */
191
+ getRun(evaluationId: number, runId: number): Promise<EvaluationRunDetail>;
192
+ }
193
+ /**
194
+ * LLM Judge API methods
195
+ */
196
+ declare class LLMJudgeAPI {
197
+ private client;
198
+ constructor(client: AIEvalClient);
199
+ /**
200
+ * Run an LLM judge evaluation
201
+ */
202
+ evaluate(params: RunLLMJudgeParams): Promise<{
203
+ result: LLMJudgeEvaluateResult;
204
+ }>;
205
+ /**
206
+ * Create an LLM judge configuration
207
+ */
208
+ createConfig(params: CreateLLMJudgeConfigParams): Promise<LLMJudgeConfig>;
209
+ /**
210
+ * List LLM judge configurations
211
+ */
212
+ listConfigs(params?: ListLLMJudgeConfigsParams): Promise<LLMJudgeConfig[]>;
213
+ /**
214
+ * List LLM judge results
215
+ */
216
+ listResults(params?: ListLLMJudgeResultsParams): Promise<LLMJudgeResult[]>;
217
+ /**
218
+ * Get alignment analysis
219
+ */
220
+ getAlignment(params: GetLLMJudgeAlignmentParams): Promise<LLMJudgeAlignment>;
221
+ }
222
+ /**
223
+ * Annotations API methods
224
+ */
225
+ declare class AnnotationsAPI {
226
+ private client;
227
+ readonly tasks: AnnotationTasksAPI;
228
+ constructor(client: AIEvalClient);
229
+ /**
230
+ * Create an annotation
231
+ */
232
+ create(params: CreateAnnotationParams): Promise<Annotation>;
233
+ /**
234
+ * List annotations
235
+ */
236
+ list(params?: ListAnnotationsParams): Promise<Annotation[]>;
237
+ }
238
+ /**
239
+ * Annotation Tasks API methods
240
+ */
241
+ declare class AnnotationTasksAPI {
242
+ private client;
243
+ readonly items: AnnotationTaskItemsAPI;
244
+ constructor(client: AIEvalClient);
245
+ /**
246
+ * Create an annotation task
247
+ */
248
+ create(params: CreateAnnotationTaskParams): Promise<AnnotationTask>;
249
+ /**
250
+ * List annotation tasks
251
+ */
252
+ list(params?: ListAnnotationTasksParams): Promise<AnnotationTask[]>;
253
+ /**
254
+ * Get an annotation task
255
+ */
256
+ get(taskId: number): Promise<AnnotationTask>;
257
+ }
258
+ /**
259
+ * Annotation Task Items API methods
260
+ */
261
+ declare class AnnotationTaskItemsAPI {
262
+ private client;
263
+ constructor(client: AIEvalClient);
264
+ /**
265
+ * Create an annotation item
266
+ */
267
+ create(taskId: number, params: CreateAnnotationItemParams): Promise<AnnotationItem>;
268
+ /**
269
+ * List annotation items
270
+ */
271
+ list(taskId: number, params?: ListAnnotationItemsParams): Promise<AnnotationItem[]>;
272
+ }
273
+ /**
274
+ * Developer API methods
275
+ */
276
+ declare class DeveloperAPI {
277
+ private client;
278
+ readonly apiKeys: APIKeysAPI;
279
+ readonly webhooks: WebhooksAPI;
280
+ constructor(client: AIEvalClient);
281
+ /**
282
+ * Get usage statistics
283
+ */
284
+ getUsage(params?: GetUsageParams): Promise<UsageStats>;
285
+ /**
286
+ * Get usage summary
287
+ */
288
+ getUsageSummary(params?: {
289
+ period?: "7d" | "30d" | "90d" | "all";
290
+ }): Promise<UsageSummary>;
291
+ }
292
+ /**
293
+ * API Keys API methods
294
+ */
295
+ declare class APIKeysAPI {
296
+ private client;
297
+ constructor(client: AIEvalClient);
298
+ /**
299
+ * Create an API key
300
+ */
301
+ create(params: CreateAPIKeyParams): Promise<APIKeyWithSecret>;
302
+ /**
303
+ * List API keys
304
+ */
305
+ list(params?: ListAPIKeysParams): Promise<APIKey[]>;
306
+ /**
307
+ * Update an API key
308
+ */
309
+ update(keyId: number, params: UpdateAPIKeyParams): Promise<APIKey>;
310
+ /**
311
+ * Revoke an API key
312
+ */
313
+ revoke(keyId: number): Promise<{
314
+ message: string;
315
+ }>;
316
+ /**
317
+ * Get API key usage
318
+ */
319
+ getUsage(keyId: number): Promise<APIKeyUsage>;
320
+ }
321
+ /**
322
+ * Webhooks API methods
323
+ */
324
+ declare class WebhooksAPI {
325
+ private client;
326
+ constructor(client: AIEvalClient);
327
+ /**
328
+ * Create a webhook
329
+ */
330
+ create(params: CreateWebhookParams): Promise<Webhook>;
331
+ /**
332
+ * List webhooks
333
+ */
334
+ list(params: ListWebhooksParams): Promise<Webhook[]>;
335
+ /**
336
+ * Get a webhook
337
+ */
338
+ get(webhookId: number): Promise<Webhook>;
339
+ /**
340
+ * Update a webhook
341
+ */
342
+ update(webhookId: number, params: UpdateWebhookParams): Promise<Webhook>;
343
+ /**
344
+ * Delete a webhook
345
+ */
346
+ delete(webhookId: number): Promise<{
347
+ message: string;
348
+ }>;
349
+ /**
350
+ * Get webhook deliveries
351
+ */
352
+ getDeliveries(webhookId: number, params?: ListWebhookDeliveriesParams): Promise<{
353
+ deliveries: WebhookDelivery[];
354
+ total: number;
355
+ }>;
356
+ }
357
+ /**
358
+ * Organizations API methods
359
+ */
360
+ declare class OrganizationsAPI {
361
+ private client;
362
+ constructor(client: AIEvalClient);
363
+ /**
364
+ * Get current organization
365
+ */
366
+ getCurrent(): Promise<Organization>;
367
+ }
368
+ export {};