@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,68 @@
1
+ /**
2
+ * Request batching for improved performance
3
+ * Combines multiple API requests into fewer network calls
4
+ */
5
+ export interface BatchRequest {
6
+ id: string;
7
+ method: string;
8
+ endpoint: string;
9
+ body?: unknown;
10
+ headers?: Record<string, string>;
11
+ }
12
+ export interface BatchResponse {
13
+ id: string;
14
+ status: number;
15
+ data?: unknown;
16
+ error?: string;
17
+ }
18
+ /**
19
+ * Batch processor for API requests
20
+ */
21
+ export declare class RequestBatcher {
22
+ private executeBatch;
23
+ private queue;
24
+ private batchTimer;
25
+ private readonly maxBatchSize;
26
+ private readonly batchDelay;
27
+ private requestCounter;
28
+ constructor(executeBatch: (requests: BatchRequest[]) => Promise<BatchResponse[]>, options?: {
29
+ maxBatchSize?: number;
30
+ batchDelay?: number;
31
+ });
32
+ /**
33
+ * Add request to batch queue
34
+ */
35
+ enqueue(method: string, endpoint: string, body?: unknown, headers?: Record<string, string>): Promise<unknown>;
36
+ /**
37
+ * Schedule batch processing after delay
38
+ */
39
+ private scheduleBatch;
40
+ /**
41
+ * Process current batch
42
+ */
43
+ private processBatch;
44
+ /**
45
+ * Flush all pending requests immediately
46
+ */
47
+ flush(): Promise<void>;
48
+ /**
49
+ * Clear queue without processing
50
+ */
51
+ clear(): void;
52
+ /**
53
+ * Get queue statistics
54
+ */
55
+ getStats(): {
56
+ queueSize: number;
57
+ maxBatchSize: number;
58
+ };
59
+ }
60
+ /**
61
+ * @internal - Internal SDK logic, not part of public API
62
+ * Check if requests can be batched together
63
+ */
64
+ export declare function canBatch(method: string, endpoint: string): boolean;
65
+ /**
66
+ * Batch multiple async operations with concurrency limit
67
+ */
68
+ export declare function batchProcess<T, R>(items: T[], processor: (item: T) => Promise<R>, concurrency?: number): Promise<R[]>;
package/dist/batch.js ADDED
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ /**
3
+ * Request batching for improved performance
4
+ * Combines multiple API requests into fewer network calls
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.RequestBatcher = void 0;
8
+ exports.canBatch = canBatch;
9
+ exports.batchProcess = batchProcess;
10
+ /**
11
+ * Batch processor for API requests
12
+ */
13
+ class RequestBatcher {
14
+ constructor(executeBatch, options = {}) {
15
+ this.executeBatch = executeBatch;
16
+ this.queue = [];
17
+ this.batchTimer = null;
18
+ this.requestCounter = 0;
19
+ this.maxBatchSize = options.maxBatchSize || 10;
20
+ this.batchDelay = options.batchDelay || 50; // 50ms
21
+ }
22
+ /**
23
+ * Add request to batch queue
24
+ */
25
+ async enqueue(method, endpoint, body, headers) {
26
+ return new Promise((resolve, reject) => {
27
+ const id = `req_${this.requestCounter++}_${Date.now()}`;
28
+ this.queue.push({
29
+ id,
30
+ resolve,
31
+ reject,
32
+ request: { id, method, endpoint, body, headers },
33
+ });
34
+ // Process immediately if batch is full
35
+ if (this.queue.length >= this.maxBatchSize) {
36
+ this.processBatch();
37
+ }
38
+ else {
39
+ // Otherwise schedule batch processing
40
+ this.scheduleBatch();
41
+ }
42
+ });
43
+ }
44
+ /**
45
+ * Schedule batch processing after delay
46
+ */
47
+ scheduleBatch() {
48
+ if (this.batchTimer) {
49
+ return;
50
+ }
51
+ this.batchTimer = setTimeout(() => {
52
+ this.processBatch();
53
+ }, this.batchDelay);
54
+ }
55
+ /**
56
+ * Process current batch
57
+ */
58
+ async processBatch() {
59
+ if (this.batchTimer) {
60
+ if (typeof this.batchTimer === "number") {
61
+ clearTimeout(this.batchTimer);
62
+ }
63
+ else {
64
+ clearTimeout(this.batchTimer);
65
+ }
66
+ this.batchTimer = null;
67
+ }
68
+ if (this.queue.length === 0) {
69
+ return;
70
+ }
71
+ // Take items from queue
72
+ const batch = this.queue.splice(0, this.maxBatchSize);
73
+ const requests = batch.map((item) => item.request);
74
+ try {
75
+ const responses = await this.executeBatch(requests);
76
+ // Match responses to requests and resolve/reject
77
+ for (const response of responses) {
78
+ const pendingRequest = batch.find((item) => item.id === response.id);
79
+ if (pendingRequest) {
80
+ if (response.status >= 200 && response.status < 300) {
81
+ pendingRequest.resolve(response.data);
82
+ }
83
+ else {
84
+ pendingRequest.reject(new Error(response.error ||
85
+ `Request failed with status ${response.status}`));
86
+ }
87
+ }
88
+ }
89
+ // Handle unknown requests that didn't get a response
90
+ for (const item of batch) {
91
+ if (!responses.find((r) => r.id === item.id)) {
92
+ item.reject(new Error("No response received for request"));
93
+ }
94
+ }
95
+ }
96
+ catch (error) {
97
+ // Reject all requests in batch on error
98
+ for (const item of batch) {
99
+ item.reject(error);
100
+ }
101
+ }
102
+ // If there are more items in queue, schedule next batch
103
+ if (this.queue.length > 0) {
104
+ this.scheduleBatch();
105
+ }
106
+ }
107
+ /**
108
+ * Flush all pending requests immediately
109
+ */
110
+ async flush() {
111
+ while (this.queue.length > 0) {
112
+ await this.processBatch();
113
+ }
114
+ }
115
+ /**
116
+ * Clear queue without processing
117
+ */
118
+ clear() {
119
+ if (this.batchTimer) {
120
+ if (typeof this.batchTimer === "number") {
121
+ clearTimeout(this.batchTimer);
122
+ }
123
+ else {
124
+ clearTimeout(this.batchTimer);
125
+ }
126
+ this.batchTimer = null;
127
+ }
128
+ // Reject all pending requests
129
+ for (const item of this.queue) {
130
+ item.reject(new Error("Batch queue cleared"));
131
+ }
132
+ this.queue = [];
133
+ }
134
+ /**
135
+ * Get queue statistics
136
+ */
137
+ getStats() {
138
+ return {
139
+ queueSize: this.queue.length,
140
+ maxBatchSize: this.maxBatchSize,
141
+ };
142
+ }
143
+ }
144
+ exports.RequestBatcher = RequestBatcher;
145
+ /**
146
+ * @internal - Internal SDK logic, not part of public API
147
+ * Check if requests can be batched together
148
+ */
149
+ function canBatch(method, endpoint) {
150
+ if (method !== "GET") {
151
+ return false;
152
+ }
153
+ const batchableEndpoints = [
154
+ "/traces",
155
+ "/evaluations",
156
+ "/annotations",
157
+ "/results",
158
+ ];
159
+ return batchableEndpoints.some((pattern) => endpoint.includes(pattern));
160
+ }
161
+ /**
162
+ * Batch multiple async operations with concurrency limit
163
+ */
164
+ async function batchProcess(items, processor, concurrency = 5) {
165
+ const results = [];
166
+ const executing = [];
167
+ for (const item of items) {
168
+ const promise = processor(item).then((result) => {
169
+ results.push(result);
170
+ });
171
+ executing.push(promise);
172
+ if (executing.length >= concurrency) {
173
+ await Promise.race(executing);
174
+ executing.splice(executing.indexOf(promise), 1);
175
+ }
176
+ }
177
+ await Promise.all(executing);
178
+ return results;
179
+ }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Simple in-memory cache with TTL for SDK requests
3
+ * Reduces redundant API calls and improves performance
4
+ */
5
+ export declare class RequestCache {
6
+ private cache;
7
+ private maxSize;
8
+ constructor(maxSize?: number);
9
+ /**
10
+ * Generate cache key from request parameters
11
+ */
12
+ private generateKey;
13
+ /**
14
+ * Check if cache entry is still valid
15
+ */
16
+ private isValid;
17
+ /**
18
+ * Get cached response if valid
19
+ */
20
+ get<T>(method: string, url: string, params?: unknown): T | null;
21
+ /**
22
+ * Store response in cache
23
+ */
24
+ set<T>(method: string, url: string, data: T, ttl: number, params?: unknown): void;
25
+ /**
26
+ * Invalidate specific cache entry
27
+ */
28
+ invalidate(method: string, url: string, params?: unknown): void;
29
+ /**
30
+ * Invalidate all cache entries matching a pattern
31
+ */
32
+ invalidatePattern(pattern: string): void;
33
+ /**
34
+ * Clear all cache entries
35
+ */
36
+ clear(): void;
37
+ /**
38
+ * Get cache statistics
39
+ */
40
+ getStats(): {
41
+ size: number;
42
+ maxSize: number;
43
+ hitRate?: number;
44
+ };
45
+ }
46
+ /**
47
+ * Default cache TTL values (in milliseconds)
48
+ * @internal - Used by SDK internally, exposed for advanced customization only
49
+ */
50
+ export declare const CacheTTL: {
51
+ readonly SHORT: number;
52
+ readonly MEDIUM: number;
53
+ readonly LONG: number;
54
+ readonly HOUR: number;
55
+ };
56
+ /**
57
+ * @internal - Internal SDK logic, not part of public API
58
+ * Determine if a request should be cached based on method and endpoint
59
+ */
60
+ export declare function shouldCache(method: string, endpoint: string): boolean;
61
+ /**
62
+ * @internal - Internal SDK logic, not part of public API
63
+ * Get appropriate TTL for an endpoint
64
+ */
65
+ export declare function getTTL(endpoint: string): number;
package/dist/cache.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ /**
3
+ * Simple in-memory cache with TTL for SDK requests
4
+ * Reduces redundant API calls and improves performance
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.CacheTTL = exports.RequestCache = void 0;
8
+ exports.shouldCache = shouldCache;
9
+ exports.getTTL = getTTL;
10
+ class RequestCache {
11
+ constructor(maxSize = 1000) {
12
+ this.cache = new Map();
13
+ this.maxSize = maxSize;
14
+ }
15
+ /**
16
+ * Generate cache key from request parameters
17
+ */
18
+ generateKey(method, url, params) {
19
+ const paramString = params ? JSON.stringify(params) : "";
20
+ return `${method}:${url}:${paramString}`;
21
+ }
22
+ /**
23
+ * Check if cache entry is still valid
24
+ */
25
+ isValid(entry) {
26
+ return Date.now() - entry.timestamp < entry.ttl;
27
+ }
28
+ /**
29
+ * Get cached response if valid
30
+ */
31
+ get(method, url, params) {
32
+ const key = this.generateKey(method, url, params);
33
+ const entry = this.cache.get(key);
34
+ if (!entry) {
35
+ return null;
36
+ }
37
+ if (!this.isValid(entry)) {
38
+ this.cache.delete(key);
39
+ return null;
40
+ }
41
+ return entry.data;
42
+ }
43
+ /**
44
+ * Store response in cache
45
+ */
46
+ set(method, url, data, ttl, params) {
47
+ // Enforce cache size limit (LRU-style)
48
+ if (this.cache.size >= this.maxSize) {
49
+ const firstKey = this.cache.keys().next().value;
50
+ if (firstKey) {
51
+ this.cache.delete(firstKey);
52
+ }
53
+ }
54
+ const key = this.generateKey(method, url, params);
55
+ this.cache.set(key, {
56
+ data,
57
+ timestamp: Date.now(),
58
+ ttl,
59
+ });
60
+ }
61
+ /**
62
+ * Invalidate specific cache entry
63
+ */
64
+ invalidate(method, url, params) {
65
+ const key = this.generateKey(method, url, params);
66
+ this.cache.delete(key);
67
+ }
68
+ /**
69
+ * Invalidate all cache entries matching a pattern
70
+ */
71
+ invalidatePattern(pattern) {
72
+ for (const key of Array.from(this.cache.keys())) {
73
+ if (key.includes(pattern)) {
74
+ this.cache.delete(key);
75
+ }
76
+ }
77
+ }
78
+ /**
79
+ * Clear all cache entries
80
+ */
81
+ clear() {
82
+ this.cache.clear();
83
+ }
84
+ /**
85
+ * Get cache statistics
86
+ */
87
+ getStats() {
88
+ return {
89
+ size: this.cache.size,
90
+ maxSize: this.maxSize,
91
+ };
92
+ }
93
+ }
94
+ exports.RequestCache = RequestCache;
95
+ /**
96
+ * Default cache TTL values (in milliseconds)
97
+ * @internal - Used by SDK internally, exposed for advanced customization only
98
+ */
99
+ exports.CacheTTL = {
100
+ SHORT: 30 * 1000,
101
+ MEDIUM: 5 * 60 * 1000,
102
+ LONG: 30 * 60 * 1000,
103
+ HOUR: 60 * 60 * 1000,
104
+ };
105
+ /**
106
+ * @internal - Internal SDK logic, not part of public API
107
+ * Determine if a request should be cached based on method and endpoint
108
+ */
109
+ function shouldCache(method, endpoint) {
110
+ if (method !== "GET") {
111
+ return false;
112
+ }
113
+ const noCacheEndpoints = ["/health", "/usage", "/deliveries"];
114
+ return !noCacheEndpoints.some((pattern) => endpoint.includes(pattern));
115
+ }
116
+ /**
117
+ * @internal - Internal SDK logic, not part of public API
118
+ * Get appropriate TTL for an endpoint
119
+ */
120
+ function getTTL(endpoint) {
121
+ if (endpoint.includes("/api-keys") || endpoint.includes("/webhooks")) {
122
+ return exports.CacheTTL.LONG;
123
+ }
124
+ if (endpoint.includes("/evaluations") || endpoint.includes("/configs")) {
125
+ return exports.CacheTTL.MEDIUM;
126
+ }
127
+ if (endpoint.includes("/traces") || endpoint.includes("/results")) {
128
+ return exports.CacheTTL.SHORT;
129
+ }
130
+ return exports.CacheTTL.MEDIUM;
131
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * API fetch helpers for evalgate check.
3
+ * Captures x-request-id from response headers.
4
+ * Sends X-EvalGate-SDK-Version and X-EvalGate-Spec-Version on all requests.
5
+ */
6
+ export type QualityLatestData = {
7
+ score?: number;
8
+ total?: number | null;
9
+ evidenceLevel?: string | null;
10
+ baselineScore?: number | null;
11
+ regressionDelta?: number | null;
12
+ baselineMissing?: boolean | null;
13
+ breakdown?: {
14
+ passRate?: number;
15
+ safety?: number;
16
+ judge?: number;
17
+ };
18
+ flags?: string[];
19
+ evaluationRunId?: number;
20
+ evaluationId?: number;
21
+ avgLatencyMs?: number | null;
22
+ costUsd?: number | null;
23
+ baselineCostUsd?: number | null;
24
+ baselineRunId?: number | null;
25
+ };
26
+ export type RunDetailsData = {
27
+ results?: Array<{
28
+ testCaseId?: number;
29
+ status?: string;
30
+ output?: string;
31
+ durationMs?: number;
32
+ assertionsJson?: Record<string, unknown>;
33
+ test_cases?: {
34
+ name?: string;
35
+ input?: string;
36
+ expectedOutput?: string;
37
+ };
38
+ }>;
39
+ };
40
+ export declare function fetchQualityLatest(baseUrl: string, apiKey: string, evaluationId: string, baseline: string): Promise<{
41
+ ok: true;
42
+ data: QualityLatestData;
43
+ requestId?: string;
44
+ } | {
45
+ ok: false;
46
+ status: number;
47
+ body: string;
48
+ requestId?: string;
49
+ }>;
50
+ export declare function fetchRunDetails(baseUrl: string, apiKey: string, evaluationId: string, runId: number): Promise<{
51
+ ok: true;
52
+ data: RunDetailsData;
53
+ } | {
54
+ ok: false;
55
+ }>;
56
+ export type CiContext = {
57
+ provider?: "github" | "gitlab" | "circle" | "unknown";
58
+ repo?: string;
59
+ sha?: string;
60
+ branch?: string;
61
+ pr?: number;
62
+ runUrl?: string;
63
+ actor?: string;
64
+ };
65
+ export type ImportResult = {
66
+ testCaseId: number;
67
+ status: "passed" | "failed";
68
+ output: string;
69
+ latencyMs?: number;
70
+ costUsd?: number;
71
+ assertionsJson?: Record<string, unknown>;
72
+ };
73
+ export type PublishShareResult = {
74
+ shareId: string;
75
+ shareUrl: string;
76
+ shareScope: string;
77
+ };
78
+ export declare function fetchRunExport(baseUrl: string, apiKey: string, evaluationId: string, runId: number): Promise<{
79
+ ok: true;
80
+ exportData: Record<string, unknown>;
81
+ } | {
82
+ ok: false;
83
+ status: number;
84
+ body: string;
85
+ }>;
86
+ export declare function publishShare(baseUrl: string, apiKey: string, evaluationId: string, exportData: Record<string, unknown>, evaluationRunId: number, options?: {
87
+ expiresInDays?: number;
88
+ }): Promise<{
89
+ ok: true;
90
+ data: PublishShareResult;
91
+ } | {
92
+ ok: false;
93
+ status: number;
94
+ body: string;
95
+ }>;
96
+ export declare function importRunOnFail(baseUrl: string, apiKey: string, evaluationId: string, results: ImportResult[], options: {
97
+ idempotencyKey?: string;
98
+ ci?: CiContext;
99
+ importClientVersion?: string;
100
+ checkReport?: Record<string, unknown>;
101
+ }): Promise<{
102
+ ok: true;
103
+ runId: number;
104
+ } | {
105
+ ok: false;
106
+ status: number;
107
+ body: string;
108
+ }>;
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ /**
3
+ * API fetch helpers for evalgate check.
4
+ * Captures x-request-id from response headers.
5
+ * Sends X-EvalGate-SDK-Version and X-EvalGate-Spec-Version on all requests.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.fetchQualityLatest = fetchQualityLatest;
9
+ exports.fetchRunDetails = fetchRunDetails;
10
+ exports.fetchRunExport = fetchRunExport;
11
+ exports.publishShare = publishShare;
12
+ exports.importRunOnFail = importRunOnFail;
13
+ const version_1 = require("../version");
14
+ const API_HEADERS = {
15
+ "X-EvalGate-SDK-Version": version_1.SDK_VERSION,
16
+ "X-EvalGate-Spec-Version": version_1.SPEC_VERSION,
17
+ };
18
+ async function fetchQualityLatest(baseUrl, apiKey, evaluationId, baseline) {
19
+ const headers = { ...API_HEADERS, Authorization: `Bearer ${apiKey}` };
20
+ const url = `${baseUrl.replace(/\/$/, "")}/api/quality?evaluationId=${evaluationId}&action=latest&baseline=${baseline}`;
21
+ try {
22
+ const res = await fetch(url, { headers });
23
+ const requestId = res.headers.get("x-request-id") ?? undefined;
24
+ const body = await res.text();
25
+ if (!res.ok) {
26
+ return { ok: false, status: res.status, body, requestId };
27
+ }
28
+ const data = JSON.parse(body);
29
+ return { ok: true, data, requestId };
30
+ }
31
+ catch (err) {
32
+ const msg = err instanceof Error ? err.message : String(err);
33
+ return { ok: false, status: 0, body: msg, requestId: undefined };
34
+ }
35
+ }
36
+ async function fetchRunDetails(baseUrl, apiKey, evaluationId, runId) {
37
+ const headers = { ...API_HEADERS, Authorization: `Bearer ${apiKey}` };
38
+ const url = `${baseUrl.replace(/\/$/, "")}/api/evaluations/${evaluationId}/runs/${runId}`;
39
+ try {
40
+ const res = await fetch(url, { headers });
41
+ if (!res.ok)
42
+ return { ok: false };
43
+ const data = (await res.json());
44
+ return { ok: true, data };
45
+ }
46
+ catch {
47
+ return { ok: false };
48
+ }
49
+ }
50
+ async function fetchRunExport(baseUrl, apiKey, evaluationId, runId) {
51
+ const headers = { ...API_HEADERS, Authorization: `Bearer ${apiKey}` };
52
+ const url = `${baseUrl.replace(/\/$/, "")}/api/evaluations/${evaluationId}/runs/${runId}/export`;
53
+ try {
54
+ const res = await fetch(url, { headers });
55
+ const text = await res.text();
56
+ if (!res.ok)
57
+ return { ok: false, status: res.status, body: text };
58
+ const exportData = JSON.parse(text);
59
+ return { ok: true, exportData };
60
+ }
61
+ catch (err) {
62
+ const msg = err instanceof Error ? err.message : String(err);
63
+ return { ok: false, status: 0, body: msg };
64
+ }
65
+ }
66
+ async function publishShare(baseUrl, apiKey, evaluationId, exportData, evaluationRunId, options) {
67
+ const headers = {
68
+ ...API_HEADERS,
69
+ Authorization: `Bearer ${apiKey}`,
70
+ "Content-Type": "application/json",
71
+ };
72
+ const body = {
73
+ exportData,
74
+ shareScope: "run",
75
+ evaluationRunId,
76
+ ...(options?.expiresInDays != null && {
77
+ expiresInDays: options.expiresInDays,
78
+ }),
79
+ };
80
+ const url = `${baseUrl.replace(/\/$/, "")}/api/evaluations/${evaluationId}/publish`;
81
+ try {
82
+ const res = await fetch(url, {
83
+ method: "POST",
84
+ headers,
85
+ body: JSON.stringify(body),
86
+ });
87
+ const text = await res.text();
88
+ if (!res.ok)
89
+ return { ok: false, status: res.status, body: text };
90
+ const data = JSON.parse(text);
91
+ return { ok: true, data };
92
+ }
93
+ catch (err) {
94
+ const msg = err instanceof Error ? err.message : String(err);
95
+ return { ok: false, status: 0, body: msg };
96
+ }
97
+ }
98
+ async function importRunOnFail(baseUrl, apiKey, evaluationId, results, options) {
99
+ const headers = {
100
+ ...API_HEADERS,
101
+ Authorization: `Bearer ${apiKey}`,
102
+ "Content-Type": "application/json",
103
+ };
104
+ if (options.idempotencyKey) {
105
+ headers["Idempotency-Key"] = options.idempotencyKey;
106
+ }
107
+ const body = {
108
+ environment: "dev",
109
+ results,
110
+ importClientVersion: options.importClientVersion ?? "evalgate-cli",
111
+ ci: options.ci,
112
+ ...(options.checkReport != null && { checkReport: options.checkReport }),
113
+ };
114
+ const url = `${baseUrl.replace(/\/$/, "")}/api/evaluations/${evaluationId}/runs/import`;
115
+ try {
116
+ const res = await fetch(url, {
117
+ method: "POST",
118
+ headers,
119
+ body: JSON.stringify(body),
120
+ });
121
+ const text = await res.text();
122
+ if (!res.ok) {
123
+ return { ok: false, status: res.status, body: text };
124
+ }
125
+ const data = JSON.parse(text);
126
+ return { ok: true, runId: data.runId };
127
+ }
128
+ catch (err) {
129
+ const msg = err instanceof Error ? err.message : String(err);
130
+ return { ok: false, status: 0, body: msg };
131
+ }
132
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * evalai baseline — Baseline management commands
3
+ *
4
+ * Subcommands:
5
+ * evalgate baseline init — Create a starter evals/baseline.json
6
+ * evalgate baseline update — Run tests + update baseline with real scores
7
+ */
8
+ export declare function runBaselineInit(cwd: string): number;
9
+ export declare function runBaselineUpdate(cwd: string): number;
10
+ export declare function runBaseline(argv: string[]): number;