@wix/eval-assertions 0.1.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,24 @@
1
+ import type { LlmJudgeAssertion, AssertionResult, LLMTrace, EvaluationInput } from "../types/index.js";
2
+ import type { AssertionContext } from "./assertion-evaluator.js";
3
+ import { AssertionEvaluator } from "./assertion-evaluator.js";
4
+ export interface JudgeResult {
5
+ text: string;
6
+ score: number;
7
+ scoreReasoning: string;
8
+ }
9
+ /**
10
+ * Format LLM trace as readable text for the judge (step number, type, tool name/args, output preview).
11
+ */
12
+ export declare function formatTraceForJudge(llmTrace: LLMTrace | undefined): string;
13
+ export declare function replacePlaceholders(str: string, output: string, cwd: string, changedFiles: string, trace: string): string;
14
+ export declare function validateJudgeResult(parsed: unknown): JudgeResult;
15
+ /**
16
+ * Evaluator for "llm_judge" assertion: an LLM judges the scenario output
17
+ * (prompt with {{output}}, {{cwd}}, {{changedFiles}}, {{trace}}) and returns a score 0-100.
18
+ * Passes if score >= minScore.
19
+ */
20
+ export declare class LlmJudgeEvaluator extends AssertionEvaluator<LlmJudgeAssertion> {
21
+ readonly type: "llm_judge";
22
+ evaluate(assertion: LlmJudgeAssertion, input: EvaluationInput, context?: AssertionContext): Promise<AssertionResult>;
23
+ private callGenerateText;
24
+ }
@@ -0,0 +1,11 @@
1
+ import type { SkillWasCalledAssertion, AssertionResult, EvaluationInput } from "../types/index.js";
2
+ import type { AssertionContext } from "./assertion-evaluator.js";
3
+ import { AssertionEvaluator } from "./assertion-evaluator.js";
4
+ /**
5
+ * Evaluator for "skill_was_called" assertion: the LLM trace must contain a step
6
+ * where the "Skill" tool was used with the expected skill (by name).
7
+ */
8
+ export declare class SkillWasCalledEvaluator extends AssertionEvaluator<SkillWasCalledAssertion> {
9
+ readonly type: "skill_was_called";
10
+ evaluate(assertion: SkillWasCalledAssertion, input: EvaluationInput, _context?: AssertionContext): AssertionResult;
11
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @wix/eval-assertions
3
+ *
4
+ * Assertion framework for AI agent evaluations.
5
+ * Supports skill invocation checks, build validation, and LLM-based judging.
6
+ */
7
+ export { AssertionSchema, SkillWasCalledAssertionSchema, BuildPassedAssertionSchema, LlmJudgeAssertionSchema, type Assertion, type SkillWasCalledAssertion, type BuildPassedAssertion, type LlmJudgeAssertion, LLMTraceSchema, LLMTraceStepSchema, LLMTraceSummarySchema, LLMBreakdownStatsSchema, TokenUsageSchema, LLMStepType, type LLMTrace, type LLMTraceStep, type LLMTraceSummary, type LLMBreakdownStats, type TokenUsage, AssertionResultSchema, AssertionResultStatus, type AssertionResult, type EvaluationInput, type FileDiff, } from "./types/index.js";
8
+ export { evaluateAssertions, registerEvaluator, getEvaluator, AssertionEvaluator, SkillWasCalledEvaluator, BuildPassedEvaluator, LlmJudgeEvaluator, formatTraceForJudge, replacePlaceholders, validateJudgeResult, type AssertionContext, type LlmConfig, type LlmJudgeGenerateTextOptions, type JudgeResult, } from "./evaluators/index.js";
@@ -0,0 +1,58 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Assertion: the agent must have invoked a specific skill during the run.
4
+ * Checked by inspecting the LLM trace for a "Skill" tool use with the given skill.
5
+ * Data: skillName (the skill that must have been called).
6
+ */
7
+ export declare const SkillWasCalledAssertionSchema: z.ZodObject<{
8
+ type: z.ZodLiteral<"skill_was_called">;
9
+ skillName: z.ZodString;
10
+ }, z.core.$strip>;
11
+ export type SkillWasCalledAssertion = z.infer<typeof SkillWasCalledAssertionSchema>;
12
+ /**
13
+ * Assertion: a build command must exit with the expected code (default 0).
14
+ * Runs the command in the scenario working directory.
15
+ */
16
+ export declare const BuildPassedAssertionSchema: z.ZodObject<{
17
+ type: z.ZodLiteral<"build_passed">;
18
+ command: z.ZodOptional<z.ZodString>;
19
+ expectedExitCode: z.ZodOptional<z.ZodNumber>;
20
+ }, z.core.$strip>;
21
+ export type BuildPassedAssertion = z.infer<typeof BuildPassedAssertionSchema>;
22
+ /**
23
+ * Assertion: an LLM judges the scenario output (score 0-100).
24
+ * Prompt can use {{output}}, {{cwd}}, {{changedFiles}}, {{trace}}.
25
+ * Passes if judge score >= minScore.
26
+ */
27
+ export declare const LlmJudgeAssertionSchema: z.ZodObject<{
28
+ type: z.ZodLiteral<"llm_judge">;
29
+ prompt: z.ZodString;
30
+ systemPrompt: z.ZodOptional<z.ZodString>;
31
+ minScore: z.ZodOptional<z.ZodNumber>;
32
+ model: z.ZodOptional<z.ZodString>;
33
+ maxTokens: z.ZodOptional<z.ZodNumber>;
34
+ temperature: z.ZodOptional<z.ZodNumber>;
35
+ }, z.core.$strip>;
36
+ export type LlmJudgeAssertion = z.infer<typeof LlmJudgeAssertionSchema>;
37
+ /**
38
+ * Union of all assertion types.
39
+ * Each assertion has a type and type-specific data.
40
+ * Uses z.union (not z.discriminatedUnion) for Zod v4 compatibility when used as array element.
41
+ */
42
+ export declare const AssertionSchema: z.ZodUnion<readonly [z.ZodObject<{
43
+ type: z.ZodLiteral<"skill_was_called">;
44
+ skillName: z.ZodString;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ type: z.ZodLiteral<"build_passed">;
47
+ command: z.ZodOptional<z.ZodString>;
48
+ expectedExitCode: z.ZodOptional<z.ZodNumber>;
49
+ }, z.core.$strip>, z.ZodObject<{
50
+ type: z.ZodLiteral<"llm_judge">;
51
+ prompt: z.ZodString;
52
+ systemPrompt: z.ZodOptional<z.ZodString>;
53
+ minScore: z.ZodOptional<z.ZodNumber>;
54
+ model: z.ZodOptional<z.ZodString>;
55
+ maxTokens: z.ZodOptional<z.ZodNumber>;
56
+ temperature: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$strip>]>;
58
+ export type Assertion = z.infer<typeof AssertionSchema>;
@@ -0,0 +1,4 @@
1
+ export { AssertionSchema, SkillWasCalledAssertionSchema, BuildPassedAssertionSchema, LlmJudgeAssertionSchema, type Assertion, type SkillWasCalledAssertion, type BuildPassedAssertion, type LlmJudgeAssertion, } from "./assertions.js";
2
+ export { LLMTraceSchema, LLMTraceStepSchema, LLMTraceSummarySchema, LLMBreakdownStatsSchema, TokenUsageSchema, LLMStepType, type LLMTrace, type LLMTraceStep, type LLMTraceSummary, type LLMBreakdownStats, type TokenUsage, } from "./trace.js";
3
+ export { AssertionResultSchema, AssertionResultStatus, type AssertionResult, } from "./result.js";
4
+ export { type EvaluationInput, type FileDiff } from "./input.js";
@@ -0,0 +1,20 @@
1
+ import type { LLMTrace } from "./trace.js";
2
+ /**
3
+ * File diff information for evaluation context.
4
+ */
5
+ export interface FileDiff {
6
+ path: string;
7
+ content?: string;
8
+ }
9
+ /**
10
+ * Input data for assertion evaluation.
11
+ * This is a generic interface that can be adapted from any evaluation system.
12
+ */
13
+ export interface EvaluationInput {
14
+ /** The agent's final output text */
15
+ outputText?: string;
16
+ /** LLM trace containing tool calls and completions */
17
+ llmTrace?: LLMTrace;
18
+ /** List of files that were modified during the evaluation */
19
+ fileDiffs?: FileDiff[];
20
+ }
@@ -0,0 +1,47 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Assertion result status enum.
4
+ */
5
+ export declare enum AssertionResultStatus {
6
+ PASSED = "passed",
7
+ FAILED = "failed",
8
+ SKIPPED = "skipped",
9
+ ERROR = "error"
10
+ }
11
+ /**
12
+ * Assertion result schema.
13
+ */
14
+ export declare const AssertionResultSchema: z.ZodObject<{
15
+ id: z.ZodString;
16
+ assertionId: z.ZodString;
17
+ assertionType: z.ZodString;
18
+ assertionName: z.ZodString;
19
+ status: z.ZodEnum<typeof AssertionResultStatus>;
20
+ message: z.ZodOptional<z.ZodString>;
21
+ expected: z.ZodOptional<z.ZodString>;
22
+ actual: z.ZodOptional<z.ZodString>;
23
+ duration: z.ZodOptional<z.ZodNumber>;
24
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
25
+ llmTraceSteps: z.ZodOptional<z.ZodArray<z.ZodObject<{
26
+ id: z.ZodString;
27
+ stepNumber: z.ZodNumber;
28
+ type: z.ZodEnum<typeof import("./trace.js").LLMStepType>;
29
+ model: z.ZodString;
30
+ provider: z.ZodString;
31
+ startedAt: z.ZodString;
32
+ durationMs: z.ZodNumber;
33
+ tokenUsage: z.ZodObject<{
34
+ prompt: z.ZodNumber;
35
+ completion: z.ZodNumber;
36
+ total: z.ZodNumber;
37
+ }, z.core.$strip>;
38
+ costUsd: z.ZodNumber;
39
+ toolName: z.ZodOptional<z.ZodString>;
40
+ toolArguments: z.ZodOptional<z.ZodString>;
41
+ inputPreview: z.ZodOptional<z.ZodString>;
42
+ outputPreview: z.ZodOptional<z.ZodString>;
43
+ success: z.ZodBoolean;
44
+ error: z.ZodOptional<z.ZodString>;
45
+ }, z.core.$strip>>>;
46
+ }, z.core.$strip>;
47
+ export type AssertionResult = z.infer<typeof AssertionResultSchema>;
@@ -0,0 +1,132 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Token usage schema.
4
+ */
5
+ export declare const TokenUsageSchema: z.ZodObject<{
6
+ prompt: z.ZodNumber;
7
+ completion: z.ZodNumber;
8
+ total: z.ZodNumber;
9
+ }, z.core.$strip>;
10
+ export type TokenUsage = z.infer<typeof TokenUsageSchema>;
11
+ /**
12
+ * LLM step type enum.
13
+ */
14
+ export declare enum LLMStepType {
15
+ COMPLETION = "completion",
16
+ TOOL_USE = "tool_use",
17
+ TOOL_RESULT = "tool_result",
18
+ THINKING = "thinking"
19
+ }
20
+ /**
21
+ * LLM trace step schema.
22
+ */
23
+ export declare const LLMTraceStepSchema: z.ZodObject<{
24
+ id: z.ZodString;
25
+ stepNumber: z.ZodNumber;
26
+ type: z.ZodEnum<typeof LLMStepType>;
27
+ model: z.ZodString;
28
+ provider: z.ZodString;
29
+ startedAt: z.ZodString;
30
+ durationMs: z.ZodNumber;
31
+ tokenUsage: z.ZodObject<{
32
+ prompt: z.ZodNumber;
33
+ completion: z.ZodNumber;
34
+ total: z.ZodNumber;
35
+ }, z.core.$strip>;
36
+ costUsd: z.ZodNumber;
37
+ toolName: z.ZodOptional<z.ZodString>;
38
+ toolArguments: z.ZodOptional<z.ZodString>;
39
+ inputPreview: z.ZodOptional<z.ZodString>;
40
+ outputPreview: z.ZodOptional<z.ZodString>;
41
+ success: z.ZodBoolean;
42
+ error: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strip>;
44
+ export type LLMTraceStep = z.infer<typeof LLMTraceStepSchema>;
45
+ /**
46
+ * LLM breakdown stats schema.
47
+ */
48
+ export declare const LLMBreakdownStatsSchema: z.ZodObject<{
49
+ count: z.ZodNumber;
50
+ durationMs: z.ZodNumber;
51
+ tokens: z.ZodNumber;
52
+ costUsd: z.ZodNumber;
53
+ }, z.core.$strip>;
54
+ export type LLMBreakdownStats = z.infer<typeof LLMBreakdownStatsSchema>;
55
+ /**
56
+ * LLM trace summary schema.
57
+ */
58
+ export declare const LLMTraceSummarySchema: z.ZodObject<{
59
+ totalSteps: z.ZodNumber;
60
+ totalDurationMs: z.ZodNumber;
61
+ totalTokens: z.ZodObject<{
62
+ prompt: z.ZodNumber;
63
+ completion: z.ZodNumber;
64
+ total: z.ZodNumber;
65
+ }, z.core.$strip>;
66
+ totalCostUsd: z.ZodNumber;
67
+ stepTypeBreakdown: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
68
+ count: z.ZodNumber;
69
+ durationMs: z.ZodNumber;
70
+ tokens: z.ZodNumber;
71
+ costUsd: z.ZodNumber;
72
+ }, z.core.$strip>>>;
73
+ modelBreakdown: z.ZodRecord<z.ZodString, z.ZodObject<{
74
+ count: z.ZodNumber;
75
+ durationMs: z.ZodNumber;
76
+ tokens: z.ZodNumber;
77
+ costUsd: z.ZodNumber;
78
+ }, z.core.$strip>>;
79
+ modelsUsed: z.ZodArray<z.ZodString>;
80
+ }, z.core.$strip>;
81
+ export type LLMTraceSummary = z.infer<typeof LLMTraceSummarySchema>;
82
+ /**
83
+ * LLM trace schema.
84
+ */
85
+ export declare const LLMTraceSchema: z.ZodObject<{
86
+ id: z.ZodString;
87
+ steps: z.ZodArray<z.ZodObject<{
88
+ id: z.ZodString;
89
+ stepNumber: z.ZodNumber;
90
+ type: z.ZodEnum<typeof LLMStepType>;
91
+ model: z.ZodString;
92
+ provider: z.ZodString;
93
+ startedAt: z.ZodString;
94
+ durationMs: z.ZodNumber;
95
+ tokenUsage: z.ZodObject<{
96
+ prompt: z.ZodNumber;
97
+ completion: z.ZodNumber;
98
+ total: z.ZodNumber;
99
+ }, z.core.$strip>;
100
+ costUsd: z.ZodNumber;
101
+ toolName: z.ZodOptional<z.ZodString>;
102
+ toolArguments: z.ZodOptional<z.ZodString>;
103
+ inputPreview: z.ZodOptional<z.ZodString>;
104
+ outputPreview: z.ZodOptional<z.ZodString>;
105
+ success: z.ZodBoolean;
106
+ error: z.ZodOptional<z.ZodString>;
107
+ }, z.core.$strip>>;
108
+ summary: z.ZodObject<{
109
+ totalSteps: z.ZodNumber;
110
+ totalDurationMs: z.ZodNumber;
111
+ totalTokens: z.ZodObject<{
112
+ prompt: z.ZodNumber;
113
+ completion: z.ZodNumber;
114
+ total: z.ZodNumber;
115
+ }, z.core.$strip>;
116
+ totalCostUsd: z.ZodNumber;
117
+ stepTypeBreakdown: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
118
+ count: z.ZodNumber;
119
+ durationMs: z.ZodNumber;
120
+ tokens: z.ZodNumber;
121
+ costUsd: z.ZodNumber;
122
+ }, z.core.$strip>>>;
123
+ modelBreakdown: z.ZodRecord<z.ZodString, z.ZodObject<{
124
+ count: z.ZodNumber;
125
+ durationMs: z.ZodNumber;
126
+ tokens: z.ZodNumber;
127
+ costUsd: z.ZodNumber;
128
+ }, z.core.$strip>>;
129
+ modelsUsed: z.ZodArray<z.ZodString>;
130
+ }, z.core.$strip>;
131
+ }, z.core.$strip>;
132
+ export type LLMTrace = z.infer<typeof LLMTraceSchema>;
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@wix/eval-assertions",
3
+ "version": "0.1.0",
4
+ "description": "Assertion framework for AI agent evaluations - supports skill invocation checks, build validation, and LLM-based judging",
5
+ "files": [
6
+ "build"
7
+ ],
8
+ "scripts": {
9
+ "clean": "rm -rf build",
10
+ "build:cjs": "esbuild src/index.ts --bundle --platform=node --outfile=build/index.js --format=cjs --sourcemap --packages=external",
11
+ "build:esm": "esbuild src/index.ts --bundle --platform=node --outfile=build/index.mjs --format=esm --sourcemap --packages=external",
12
+ "build:types": "tsc --emitDeclarationOnly --outDir ./build/types",
13
+ "build": "yarn run clean && yarn run build:cjs && yarn run build:esm && yarn run build:types",
14
+ "lint": "eslint .",
15
+ "typecheck": "tsc --noEmit",
16
+ "test": "node --import tsx --test tests/**/*.test.ts"
17
+ },
18
+ "dependencies": {
19
+ "@ai-sdk/anthropic": "^3.0.2",
20
+ "ai": "^6.0.6",
21
+ "zod": "^4.3.5"
22
+ },
23
+ "devDependencies": {
24
+ "@eslint/js": "^9.39.2",
25
+ "@types/node": "^22.19.3",
26
+ "esbuild": "^0.27.2",
27
+ "eslint": "^9.39.2",
28
+ "eslint-config-prettier": "^10.1.8",
29
+ "eslint-plugin-prettier": "^5.5.4",
30
+ "prettier": "^3.7.4",
31
+ "tsx": "^4.21.0",
32
+ "typescript": "^5.9.3",
33
+ "typescript-eslint": "^8.51.0"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "types": "./build/types/index.d.ts",
38
+ "import": "./build/index.mjs",
39
+ "require": "./build/index.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "publishConfig": {
44
+ "registry": "https://registry.npmjs.org/",
45
+ "access": "public"
46
+ },
47
+ "wix": {
48
+ "artifact": {
49
+ "groupId": "com.wixpress",
50
+ "artifactId": "eval-assertions"
51
+ }
52
+ },
53
+ "keywords": [
54
+ "ai",
55
+ "evaluation",
56
+ "assertions",
57
+ "testing",
58
+ "llm",
59
+ "agent"
60
+ ],
61
+ "license": "MIT",
62
+ "author": "Wix",
63
+ "falconPackageHash": "20902c570369f86bc5193d4c20ccdd3a702068beb5ea509f142fb2f5"
64
+ }