@pauly4010/evalai-sdk 1.3.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.
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Enhanced Assertion Library
3
+ * Tier 1.3: Pre-Built Assertion Library with 20+ built-in assertions
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { expect } from '@ai-eval-platform/sdk';
8
+ *
9
+ * const output = "Hello, how can I help you today?";
10
+ *
11
+ * expect(output).toContainKeywords(['help', 'today']);
12
+ * expect(output).toHaveSentiment('positive');
13
+ * expect(output).toMatchPattern(/help/i);
14
+ * expect(output).toHaveLength({ min: 10, max: 100 });
15
+ * ```
16
+ */
17
+ export interface AssertionResult {
18
+ name: string;
19
+ passed: boolean;
20
+ expected: any;
21
+ actual: any;
22
+ message?: string;
23
+ }
24
+ export declare class AssertionError extends Error {
25
+ expected: any;
26
+ actual: any;
27
+ constructor(message: string, expected: any, actual: any);
28
+ }
29
+ /**
30
+ * Fluent assertion builder
31
+ */
32
+ export declare class Expectation {
33
+ private value;
34
+ constructor(value: any);
35
+ /**
36
+ * Assert value equals expected
37
+ * @example expect(output).toEqual("Hello")
38
+ */
39
+ toEqual(expected: any, message?: string): AssertionResult;
40
+ /**
41
+ * Assert value contains substring
42
+ * @example expect(output).toContain("help")
43
+ */
44
+ toContain(substring: string, message?: string): AssertionResult;
45
+ /**
46
+ * Assert value contains all keywords
47
+ * @example expect(output).toContainKeywords(['help', 'support'])
48
+ */
49
+ toContainKeywords(keywords: string[], message?: string): AssertionResult;
50
+ /**
51
+ * Assert value does not contain substring
52
+ * @example expect(output).toNotContain("error")
53
+ */
54
+ toNotContain(substring: string, message?: string): AssertionResult;
55
+ /**
56
+ * Assert value does not contain PII (emails, phone numbers, SSN)
57
+ * @example expect(output).toNotContainPII()
58
+ */
59
+ toNotContainPII(message?: string): AssertionResult;
60
+ /**
61
+ * Assert value matches regular expression
62
+ * @example expect(output).toMatchPattern(/\d{3}-\d{3}-\d{4}/)
63
+ */
64
+ toMatchPattern(pattern: RegExp, message?: string): AssertionResult;
65
+ /**
66
+ * Assert value is valid JSON
67
+ * @example expect(output).toBeValidJSON()
68
+ */
69
+ toBeValidJSON(message?: string): AssertionResult;
70
+ /**
71
+ * Assert JSON matches schema
72
+ * @example expect(output).toMatchJSON({ status: 'success' })
73
+ */
74
+ toMatchJSON(schema: Record<string, any>, message?: string): AssertionResult;
75
+ /**
76
+ * Assert value has expected sentiment
77
+ * @example expect(output).toHaveSentiment('positive')
78
+ */
79
+ toHaveSentiment(expected: 'positive' | 'negative' | 'neutral', message?: string): AssertionResult;
80
+ /**
81
+ * Assert string length is within range
82
+ * @example expect(output).toHaveLength({ min: 10, max: 100 })
83
+ */
84
+ toHaveLength(range: {
85
+ min?: number;
86
+ max?: number;
87
+ }, message?: string): AssertionResult;
88
+ /**
89
+ * Assert no hallucinations (all ground truth facts present)
90
+ * @example expect(output).toNotHallucinate(['fact1', 'fact2'])
91
+ */
92
+ toNotHallucinate(groundTruth: string[], message?: string): AssertionResult;
93
+ /**
94
+ * Assert response latency is within limit
95
+ * @example expect(durationMs).toBeFasterThan(1000)
96
+ */
97
+ toBeFasterThan(maxMs: number, message?: string): AssertionResult;
98
+ /**
99
+ * Assert value is truthy
100
+ * @example expect(result).toBeTruthy()
101
+ */
102
+ toBeTruthy(message?: string): AssertionResult;
103
+ /**
104
+ * Assert value is falsy
105
+ * @example expect(error).toBeFalsy()
106
+ */
107
+ toBeFalsy(message?: string): AssertionResult;
108
+ /**
109
+ * Assert value is greater than expected
110
+ * @example expect(score).toBeGreaterThan(0.8)
111
+ */
112
+ toBeGreaterThan(expected: number, message?: string): AssertionResult;
113
+ /**
114
+ * Assert value is less than expected
115
+ * @example expect(errorRate).toBeLessThan(0.05)
116
+ */
117
+ toBeLessThan(expected: number, message?: string): AssertionResult;
118
+ /**
119
+ * Assert value is between min and max
120
+ * @example expect(score).toBeBetween(0, 1)
121
+ */
122
+ toBeBetween(min: number, max: number, message?: string): AssertionResult;
123
+ /**
124
+ * Assert value contains code block
125
+ * @example expect(output).toContainCode()
126
+ */
127
+ toContainCode(message?: string): AssertionResult;
128
+ /**
129
+ * Assert value is professional tone (no profanity)
130
+ * @example expect(output).toBeProfessional()
131
+ */
132
+ toBeProfessional(message?: string): AssertionResult;
133
+ /**
134
+ * Assert value has proper grammar (basic checks)
135
+ * @example expect(output).toHaveProperGrammar()
136
+ */
137
+ toHaveProperGrammar(message?: string): AssertionResult;
138
+ }
139
+ /**
140
+ * Create an expectation for fluent assertions
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const output = "Hello, how can I help you?";
145
+ *
146
+ * expect(output).toContain("help");
147
+ * expect(output).toHaveSentiment('positive');
148
+ * expect(output).toHaveLength({ min: 10, max: 100 });
149
+ * ```
150
+ */
151
+ export declare function expect(value: any): Expectation;
152
+ /**
153
+ * Run multiple assertions and collect results
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * const results = runAssertions([
158
+ * () => expect(output).toContain("help"),
159
+ * () => expect(output).toHaveSentiment('positive'),
160
+ * () => expect(output).toHaveLength({ min: 10 })
161
+ * ]);
162
+ *
163
+ * const allPassed = results.every(r => r.passed);
164
+ * ```
165
+ */
166
+ export declare function runAssertions(assertions: (() => AssertionResult)[]): AssertionResult[];
167
+ export declare function containsKeywords(text: string, keywords: string[]): boolean;
168
+ export declare function matchesPattern(text: string, pattern: RegExp): boolean;
169
+ export declare function hasLength(text: string, range: {
170
+ min?: number;
171
+ max?: number;
172
+ }): boolean;
173
+ export declare function containsJSON(text: string): boolean;
174
+ export declare function notContainsPII(text: string): boolean;
175
+ export declare function hasSentiment(text: string, expected: 'positive' | 'negative' | 'neutral'): boolean;
176
+ export declare function similarTo(text1: string, text2: string, threshold?: number): boolean;
177
+ export declare function withinRange(value: number, min: number, max: number): boolean;
178
+ export declare function isValidEmail(email: string): boolean;
179
+ export declare function isValidURL(url: string): boolean;
180
+ export declare function hasNoHallucinations(text: string, groundTruth: string[]): boolean;
181
+ export declare function matchesSchema(value: any, schema: Record<string, any>): boolean;
182
+ export declare function hasReadabilityScore(text: string, minScore: number): boolean;
183
+ export declare function containsLanguage(text: string, language: string): boolean;
184
+ export declare function hasFactualAccuracy(text: string, facts: string[]): boolean;
185
+ export declare function respondedWithinTime(startTime: number, maxMs: number): boolean;
186
+ export declare function hasNoToxicity(text: string): boolean;
187
+ export declare function followsInstructions(text: string, instructions: string[]): boolean;
188
+ export declare function containsAllRequiredFields(obj: any, requiredFields: string[]): boolean;
189
+ export declare function hasValidCodeSyntax(code: string, language: string): boolean;