@arizeai/phoenix-evals 0.5.1 → 0.6.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 (120) hide show
  1. package/README.md +42 -0
  2. package/dist/esm/core/EvaluatorBase.d.ts +19 -0
  3. package/dist/esm/core/EvaluatorBase.d.ts.map +1 -0
  4. package/dist/esm/core/EvaluatorBase.js +18 -0
  5. package/dist/esm/core/EvaluatorBase.js.map +1 -0
  6. package/dist/esm/index.d.ts +1 -0
  7. package/dist/esm/index.d.ts.map +1 -1
  8. package/dist/esm/index.js +1 -0
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/llm/ClassificationEvaluator.d.ts +19 -2
  11. package/dist/esm/llm/ClassificationEvaluator.d.ts.map +1 -1
  12. package/dist/esm/llm/ClassificationEvaluator.js +29 -2
  13. package/dist/esm/llm/ClassificationEvaluator.js.map +1 -1
  14. package/dist/esm/llm/LLMEvaluator.d.ts +4 -7
  15. package/dist/esm/llm/LLMEvaluator.d.ts.map +1 -1
  16. package/dist/esm/llm/LLMEvaluator.js +4 -7
  17. package/dist/esm/llm/LLMEvaluator.js.map +1 -1
  18. package/dist/esm/llm/createClassificationEvaluator.d.ts +1 -1
  19. package/dist/esm/llm/createClassificationEvaluator.d.ts.map +1 -1
  20. package/dist/esm/llm/createClassificationEvaluator.js.map +1 -1
  21. package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts +8 -7
  22. package/dist/esm/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
  23. package/dist/esm/llm/createDocumentRelevancyEvaluator.js +1 -2
  24. package/dist/esm/llm/createDocumentRelevancyEvaluator.js.map +1 -1
  25. package/dist/esm/llm/createHallucinationEvaluator.d.ts +6 -6
  26. package/dist/esm/llm/createHallucinationEvaluator.d.ts.map +1 -1
  27. package/dist/esm/llm/createHallucinationEvaluator.js +1 -2
  28. package/dist/esm/llm/createHallucinationEvaluator.js.map +1 -1
  29. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  30. package/dist/esm/types/data.d.ts +194 -0
  31. package/dist/esm/types/data.d.ts.map +1 -0
  32. package/dist/esm/types/data.js +2 -0
  33. package/dist/esm/types/data.js.map +1 -0
  34. package/dist/esm/types/evals.d.ts +17 -3
  35. package/dist/esm/types/evals.d.ts.map +1 -1
  36. package/dist/esm/types/index.d.ts +1 -0
  37. package/dist/esm/types/index.d.ts.map +1 -1
  38. package/dist/esm/types/index.js +1 -0
  39. package/dist/esm/types/index.js.map +1 -1
  40. package/dist/esm/types/otel.d.ts +14 -13
  41. package/dist/esm/types/otel.d.ts.map +1 -1
  42. package/dist/esm/utils/bindEvaluator.d.ts +219 -0
  43. package/dist/esm/utils/bindEvaluator.d.ts.map +1 -0
  44. package/dist/esm/utils/bindEvaluator.js +163 -0
  45. package/dist/esm/utils/bindEvaluator.js.map +1 -0
  46. package/dist/esm/utils/index.d.ts +2 -0
  47. package/dist/esm/utils/index.d.ts.map +1 -0
  48. package/dist/esm/utils/index.js +2 -0
  49. package/dist/esm/utils/index.js.map +1 -0
  50. package/dist/esm/utils/objectMappingUtils.d.ts +166 -0
  51. package/dist/esm/utils/objectMappingUtils.d.ts.map +1 -0
  52. package/dist/esm/utils/objectMappingUtils.js +191 -0
  53. package/dist/esm/utils/objectMappingUtils.js.map +1 -0
  54. package/dist/src/core/EvaluatorBase.d.ts +19 -0
  55. package/dist/src/core/EvaluatorBase.d.ts.map +1 -0
  56. package/dist/src/core/EvaluatorBase.js +17 -0
  57. package/dist/src/core/EvaluatorBase.js.map +1 -0
  58. package/dist/src/index.d.ts +1 -0
  59. package/dist/src/index.d.ts.map +1 -1
  60. package/dist/src/index.js +1 -0
  61. package/dist/src/index.js.map +1 -1
  62. package/dist/src/llm/ClassificationEvaluator.d.ts +19 -2
  63. package/dist/src/llm/ClassificationEvaluator.d.ts.map +1 -1
  64. package/dist/src/llm/ClassificationEvaluator.js +13 -2
  65. package/dist/src/llm/ClassificationEvaluator.js.map +1 -1
  66. package/dist/src/llm/LLMEvaluator.d.ts +4 -7
  67. package/dist/src/llm/LLMEvaluator.d.ts.map +1 -1
  68. package/dist/src/llm/LLMEvaluator.js +16 -5
  69. package/dist/src/llm/LLMEvaluator.js.map +1 -1
  70. package/dist/src/llm/createClassificationEvaluator.d.ts +1 -1
  71. package/dist/src/llm/createClassificationEvaluator.d.ts.map +1 -1
  72. package/dist/src/llm/createClassificationEvaluator.js.map +1 -1
  73. package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts +8 -7
  74. package/dist/src/llm/createDocumentRelevancyEvaluator.d.ts.map +1 -1
  75. package/dist/src/llm/createDocumentRelevancyEvaluator.js +2 -2
  76. package/dist/src/llm/createDocumentRelevancyEvaluator.js.map +1 -1
  77. package/dist/src/llm/createHallucinationEvaluator.d.ts +6 -6
  78. package/dist/src/llm/createHallucinationEvaluator.d.ts.map +1 -1
  79. package/dist/src/llm/createHallucinationEvaluator.js +2 -2
  80. package/dist/src/llm/createHallucinationEvaluator.js.map +1 -1
  81. package/dist/src/types/data.d.ts +194 -0
  82. package/dist/src/types/data.d.ts.map +1 -0
  83. package/dist/src/types/data.js +3 -0
  84. package/dist/src/types/data.js.map +1 -0
  85. package/dist/src/types/evals.d.ts +17 -3
  86. package/dist/src/types/evals.d.ts.map +1 -1
  87. package/dist/src/types/index.d.ts +1 -0
  88. package/dist/src/types/index.d.ts.map +1 -1
  89. package/dist/src/types/index.js +1 -0
  90. package/dist/src/types/index.js.map +1 -1
  91. package/dist/src/types/otel.d.ts +14 -13
  92. package/dist/src/types/otel.d.ts.map +1 -1
  93. package/dist/src/utils/bindEvaluator.d.ts +219 -0
  94. package/dist/src/utils/bindEvaluator.d.ts.map +1 -0
  95. package/dist/src/utils/bindEvaluator.js +166 -0
  96. package/dist/src/utils/bindEvaluator.js.map +1 -0
  97. package/dist/src/utils/index.d.ts +2 -0
  98. package/dist/src/utils/index.d.ts.map +1 -0
  99. package/dist/src/utils/index.js +18 -0
  100. package/dist/src/utils/index.js.map +1 -0
  101. package/dist/src/utils/objectMappingUtils.d.ts +166 -0
  102. package/dist/src/utils/objectMappingUtils.d.ts.map +1 -0
  103. package/dist/src/utils/objectMappingUtils.js +191 -0
  104. package/dist/src/utils/objectMappingUtils.js.map +1 -0
  105. package/dist/tsconfig.tsbuildinfo +1 -1
  106. package/package.json +2 -1
  107. package/src/core/EvaluatorBase.ts +43 -0
  108. package/src/index.ts +1 -0
  109. package/src/llm/ClassificationEvaluator.ts +39 -3
  110. package/src/llm/LLMEvaluator.ts +7 -16
  111. package/src/llm/createClassificationEvaluator.ts +1 -1
  112. package/src/llm/createDocumentRelevancyEvaluator.ts +17 -12
  113. package/src/llm/createHallucinationEvaluator.ts +12 -10
  114. package/src/types/data.ts +200 -0
  115. package/src/types/evals.ts +25 -5
  116. package/src/types/index.ts +1 -0
  117. package/src/types/otel.ts +15 -13
  118. package/src/utils/bindEvaluator.ts +229 -0
  119. package/src/utils/index.ts +1 -0
  120. package/src/utils/objectMappingUtils.ts +202 -0
@@ -0,0 +1,219 @@
1
+ import { EvaluatorBase } from "../core/EvaluatorBase";
2
+ import { ObjectMapping } from "../types/data";
3
+ /**
4
+ * Context for binding an evaluator with input mapping configuration.
5
+ *
6
+ * This type defines the structure for binding an evaluator to a specific data shape
7
+ * by mapping the evaluator's expected input fields to the actual data structure.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // Map evaluator fields to your data structure
12
+ * const context: BindingContext<MyDataType> = {
13
+ * inputMapping: {
14
+ * input: "userQuery", // Maps "input" to "userQuery" field
15
+ * reference: "context", // Maps "reference" to "context" field
16
+ * output: "modelResponse", // Maps "output" to "modelResponse" field
17
+ * },
18
+ * };
19
+ * ```
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * // Using nested property access
24
+ * const context: BindingContext<ApiResponse> = {
25
+ * inputMapping: {
26
+ * input: "request.body.query",
27
+ * reference: "request.body.context",
28
+ * output: "response.data.text",
29
+ * },
30
+ * };
31
+ * ```
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Using function-based mapping for transformations
36
+ * const context: BindingContext<RawData> = {
37
+ * inputMapping: {
38
+ * input: "question",
39
+ * reference: (data) => data.context.join("\n"), // Transform array to string
40
+ * output: "answer",
41
+ * },
42
+ * };
43
+ * ```
44
+ *
45
+ * @typeParam RecordType - The type of the data record that will be evaluated
46
+ */
47
+ export type BindingContext<RecordType extends Record<string, unknown>> = {
48
+ /**
49
+ * Mapping of evaluator input fields to data source fields.
50
+ *
51
+ * The keys represent the field names expected by the evaluator (e.g., "input", "output", "reference"),
52
+ * and the values specify how to extract those fields from your data structure.
53
+ *
54
+ * Supports:
55
+ * - Simple property names: `"fieldName"`
56
+ * - Dot notation: `"user.profile.name"`
57
+ * - Array access: `"items[0].id"`
58
+ * - JSONPath expressions: `"$.items[*].id"`
59
+ * - Function extractors: `(data) => data.customField.toUpperCase()`
60
+ */
61
+ inputMapping: ObjectMapping<RecordType>;
62
+ };
63
+ /**
64
+ * Binds an evaluator to a specific data structure using input mapping.
65
+ *
66
+ * This function creates a new evaluator instance that automatically transforms
67
+ * your data structure to match what the evaluator expects. This is particularly
68
+ * useful when your data schema doesn't match the evaluator's expected input format.
69
+ *
70
+ * @param evaluator - The evaluator to bind (e.g., a hallucination evaluator)
71
+ * @param context - The binding context containing the input mapping configuration
72
+ * @returns A new evaluator instance with the input mapping applied
73
+ *
74
+ * @example
75
+ * **Basic usage with simple field mapping:**
76
+ * ```typescript
77
+ * import { bindEvaluator, createHallucinationEvaluator } from "@arizeai/phoenix-evals";
78
+ * import { openai } from "@ai-sdk/openai";
79
+ *
80
+ * type MyData = {
81
+ * question: string;
82
+ * context: string;
83
+ * answer: string;
84
+ * };
85
+ *
86
+ * const evaluator = bindEvaluator<MyData>(
87
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
88
+ * {
89
+ * inputMapping: {
90
+ * input: "question", // Evaluator expects "input", map from "question"
91
+ * reference: "context", // Evaluator expects "reference", map from "context"
92
+ * output: "answer", // Evaluator expects "output", map from "answer"
93
+ * },
94
+ * }
95
+ * );
96
+ *
97
+ * // Now you can evaluate with your data structure
98
+ * const result = await evaluator.evaluate({
99
+ * question: "What is AI?",
100
+ * context: "AI is artificial intelligence...",
101
+ * answer: "AI stands for artificial intelligence",
102
+ * });
103
+ * ```
104
+ *
105
+ * @example
106
+ * **Using nested property access:**
107
+ * ```typescript
108
+ * type ApiResponse = {
109
+ * request: {
110
+ * body: {
111
+ * query: string;
112
+ * context: string;
113
+ * };
114
+ * };
115
+ * response: {
116
+ * data: {
117
+ * text: string;
118
+ * };
119
+ * };
120
+ * };
121
+ *
122
+ * const evaluator = bindEvaluator<ApiResponse>(
123
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
124
+ * {
125
+ * inputMapping: {
126
+ * input: "request.body.query",
127
+ * reference: "request.body.context",
128
+ * output: "response.data.text",
129
+ * },
130
+ * }
131
+ * );
132
+ * ```
133
+ *
134
+ * @example
135
+ * **Using function-based mapping for data transformation:**
136
+ * ```typescript
137
+ * type RawData = {
138
+ * question: string;
139
+ * contexts: string[]; // Array of context strings
140
+ * answer: string;
141
+ * };
142
+ *
143
+ * const evaluator = bindEvaluator<RawData>(
144
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
145
+ * {
146
+ * inputMapping: {
147
+ * input: "question",
148
+ * // Transform array to single string
149
+ * reference: (data) => data.contexts.join("\n\n"),
150
+ * output: "answer",
151
+ * },
152
+ * }
153
+ * );
154
+ * ```
155
+ *
156
+ * @example
157
+ * **Using JSONPath for complex queries:**
158
+ * ```typescript
159
+ * type ComplexData = {
160
+ * conversation: {
161
+ * messages: Array<{ role: string; content: string }>;
162
+ * };
163
+ * metadata: {
164
+ * sources: string[];
165
+ * };
166
+ * };
167
+ *
168
+ * const evaluator = bindEvaluator<ComplexData>(
169
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
170
+ * {
171
+ * inputMapping: {
172
+ * // Extract last user message
173
+ * input: "$.conversation.messages[?(@.role=='user')].content[-1]",
174
+ * // Extract all sources
175
+ * reference: "$.metadata.sources[*]",
176
+ * // Extract last assistant message
177
+ * output: "$.conversation.messages[?(@.role=='assistant')].content[-1]",
178
+ * },
179
+ * }
180
+ * );
181
+ * ```
182
+ *
183
+ * @example
184
+ * **Binding multiple evaluators with different mappings:**
185
+ * ```typescript
186
+ * type EvaluationData = {
187
+ * userQuery: string;
188
+ * systemContext: string;
189
+ * modelOutput: string;
190
+ * expectedOutput?: string;
191
+ * };
192
+ *
193
+ * // Hallucination evaluator
194
+ * const hallucinationEvaluator = bindEvaluator<EvaluationData>(
195
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
196
+ * {
197
+ * inputMapping: {
198
+ * input: "userQuery",
199
+ * reference: "systemContext",
200
+ * output: "modelOutput",
201
+ * },
202
+ * }
203
+ * );
204
+ *
205
+ * // Document relevancy evaluator (if it exists)
206
+ * const relevancyEvaluator = bindEvaluator<EvaluationData>(
207
+ * createDocumentRelevancyEvaluator({ model: openai("gpt-4") }),
208
+ * {
209
+ * inputMapping: {
210
+ * query: "userQuery",
211
+ * document: "systemContext",
212
+ * output: "modelOutput",
213
+ * },
214
+ * }
215
+ * );
216
+ * ```
217
+ */
218
+ export declare function bindEvaluator<RecordType extends Record<string, unknown>>(evaluator: EvaluatorBase<RecordType>, context: BindingContext<RecordType>): EvaluatorBase<RecordType>;
219
+ //# sourceMappingURL=bindEvaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindEvaluator.d.ts","sourceRoot":"","sources":["../../../src/utils/bindEvaluator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,MAAM,cAAc,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IACvE;;;;;;;;;;;;OAYG;IACH,YAAY,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0JG;AACH,wBAAgB,aAAa,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtE,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,EACpC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,GAClC,aAAa,CAAC,UAAU,CAAC,CAM3B"}
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bindEvaluator = bindEvaluator;
4
+ /**
5
+ * Binds an evaluator to a specific data structure using input mapping.
6
+ *
7
+ * This function creates a new evaluator instance that automatically transforms
8
+ * your data structure to match what the evaluator expects. This is particularly
9
+ * useful when your data schema doesn't match the evaluator's expected input format.
10
+ *
11
+ * @param evaluator - The evaluator to bind (e.g., a hallucination evaluator)
12
+ * @param context - The binding context containing the input mapping configuration
13
+ * @returns A new evaluator instance with the input mapping applied
14
+ *
15
+ * @example
16
+ * **Basic usage with simple field mapping:**
17
+ * ```typescript
18
+ * import { bindEvaluator, createHallucinationEvaluator } from "@arizeai/phoenix-evals";
19
+ * import { openai } from "@ai-sdk/openai";
20
+ *
21
+ * type MyData = {
22
+ * question: string;
23
+ * context: string;
24
+ * answer: string;
25
+ * };
26
+ *
27
+ * const evaluator = bindEvaluator<MyData>(
28
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
29
+ * {
30
+ * inputMapping: {
31
+ * input: "question", // Evaluator expects "input", map from "question"
32
+ * reference: "context", // Evaluator expects "reference", map from "context"
33
+ * output: "answer", // Evaluator expects "output", map from "answer"
34
+ * },
35
+ * }
36
+ * );
37
+ *
38
+ * // Now you can evaluate with your data structure
39
+ * const result = await evaluator.evaluate({
40
+ * question: "What is AI?",
41
+ * context: "AI is artificial intelligence...",
42
+ * answer: "AI stands for artificial intelligence",
43
+ * });
44
+ * ```
45
+ *
46
+ * @example
47
+ * **Using nested property access:**
48
+ * ```typescript
49
+ * type ApiResponse = {
50
+ * request: {
51
+ * body: {
52
+ * query: string;
53
+ * context: string;
54
+ * };
55
+ * };
56
+ * response: {
57
+ * data: {
58
+ * text: string;
59
+ * };
60
+ * };
61
+ * };
62
+ *
63
+ * const evaluator = bindEvaluator<ApiResponse>(
64
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
65
+ * {
66
+ * inputMapping: {
67
+ * input: "request.body.query",
68
+ * reference: "request.body.context",
69
+ * output: "response.data.text",
70
+ * },
71
+ * }
72
+ * );
73
+ * ```
74
+ *
75
+ * @example
76
+ * **Using function-based mapping for data transformation:**
77
+ * ```typescript
78
+ * type RawData = {
79
+ * question: string;
80
+ * contexts: string[]; // Array of context strings
81
+ * answer: string;
82
+ * };
83
+ *
84
+ * const evaluator = bindEvaluator<RawData>(
85
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
86
+ * {
87
+ * inputMapping: {
88
+ * input: "question",
89
+ * // Transform array to single string
90
+ * reference: (data) => data.contexts.join("\n\n"),
91
+ * output: "answer",
92
+ * },
93
+ * }
94
+ * );
95
+ * ```
96
+ *
97
+ * @example
98
+ * **Using JSONPath for complex queries:**
99
+ * ```typescript
100
+ * type ComplexData = {
101
+ * conversation: {
102
+ * messages: Array<{ role: string; content: string }>;
103
+ * };
104
+ * metadata: {
105
+ * sources: string[];
106
+ * };
107
+ * };
108
+ *
109
+ * const evaluator = bindEvaluator<ComplexData>(
110
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
111
+ * {
112
+ * inputMapping: {
113
+ * // Extract last user message
114
+ * input: "$.conversation.messages[?(@.role=='user')].content[-1]",
115
+ * // Extract all sources
116
+ * reference: "$.metadata.sources[*]",
117
+ * // Extract last assistant message
118
+ * output: "$.conversation.messages[?(@.role=='assistant')].content[-1]",
119
+ * },
120
+ * }
121
+ * );
122
+ * ```
123
+ *
124
+ * @example
125
+ * **Binding multiple evaluators with different mappings:**
126
+ * ```typescript
127
+ * type EvaluationData = {
128
+ * userQuery: string;
129
+ * systemContext: string;
130
+ * modelOutput: string;
131
+ * expectedOutput?: string;
132
+ * };
133
+ *
134
+ * // Hallucination evaluator
135
+ * const hallucinationEvaluator = bindEvaluator<EvaluationData>(
136
+ * createHallucinationEvaluator({ model: openai("gpt-4") }),
137
+ * {
138
+ * inputMapping: {
139
+ * input: "userQuery",
140
+ * reference: "systemContext",
141
+ * output: "modelOutput",
142
+ * },
143
+ * }
144
+ * );
145
+ *
146
+ * // Document relevancy evaluator (if it exists)
147
+ * const relevancyEvaluator = bindEvaluator<EvaluationData>(
148
+ * createDocumentRelevancyEvaluator({ model: openai("gpt-4") }),
149
+ * {
150
+ * inputMapping: {
151
+ * query: "userQuery",
152
+ * document: "systemContext",
153
+ * output: "modelOutput",
154
+ * },
155
+ * }
156
+ * );
157
+ * ```
158
+ */
159
+ function bindEvaluator(evaluator, context) {
160
+ let boundEvaluator = evaluator;
161
+ if (context.inputMapping) {
162
+ boundEvaluator = boundEvaluator.bindInputMapping(context.inputMapping);
163
+ }
164
+ return boundEvaluator;
165
+ }
166
+ //# sourceMappingURL=bindEvaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bindEvaluator.js","sourceRoot":"","sources":["../../../src/utils/bindEvaluator.ts"],"names":[],"mappings":";;AA2NA,sCASC;AApKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0JG;AACH,SAAgB,aAAa,CAC3B,SAAoC,EACpC,OAAmC;IAEnC,IAAI,cAAc,GAA8B,SAAS,CAAC;IAC1D,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,cAAc,GAAG,cAAc,CAAC,gBAAgB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./bindEvaluator";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./bindEvaluator"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAAgC"}
@@ -0,0 +1,166 @@
1
+ import { ObjectMapping } from "../types/data";
2
+ /**
3
+ * Remaps an object by applying field mappings while preserving original data.
4
+ *
5
+ * This function takes your original data object and a mapping configuration,
6
+ * then returns a new object that contains:
7
+ * - All original fields from the input data
8
+ * - Additional/overridden fields based on the mapping
9
+ *
10
+ * The mapping allows you to extract values using:
11
+ * - Simple property names: `"fieldName"`
12
+ * - Dot notation: `"user.profile.name"`
13
+ * - Array access: `"items[0].id"`
14
+ * - JSONPath expressions: `"$.items[*].id"`
15
+ * - Function extractors: `(data) => data.customField`
16
+ *
17
+ * @param data - The input data object to remap
18
+ * @param mapping - The mapping configuration defining how to extract/transform values
19
+ * @returns A new object with original fields plus mapped fields
20
+ *
21
+ * @example
22
+ * **Basic remapping:**
23
+ * ```typescript
24
+ * const data = {
25
+ * name: "John",
26
+ * age: 30,
27
+ * email: "john@example.com",
28
+ * };
29
+ *
30
+ * const mapping: ObjectMapping<typeof data> = {
31
+ * userName: "name",
32
+ * userAge: "age",
33
+ * };
34
+ *
35
+ * const result = remapObject(data, mapping);
36
+ * // Result: {
37
+ * // name: "John",
38
+ * // age: 30,
39
+ * // email: "john@example.com",
40
+ * // userName: "John", // Added from mapping
41
+ * // userAge: 30, // Added from mapping
42
+ * // }
43
+ * ```
44
+ *
45
+ * @example
46
+ * **Nested property extraction:**
47
+ * ```typescript
48
+ * const data = {
49
+ * user: {
50
+ * profile: {
51
+ * firstName: "John",
52
+ * lastName: "Doe",
53
+ * },
54
+ * email: "john@example.com",
55
+ * },
56
+ * };
57
+ *
58
+ * const mapping: ObjectMapping<typeof data> = {
59
+ * firstName: "user.profile.firstName",
60
+ * lastName: "user.profile.lastName",
61
+ * email: "user.email",
62
+ * };
63
+ *
64
+ * const result = remapObject(data, mapping);
65
+ * // Result includes original data plus:
66
+ * // {
67
+ * // firstName: "John",
68
+ * // lastName: "Doe",
69
+ * // email: "john@example.com",
70
+ * // }
71
+ * ```
72
+ *
73
+ * @example
74
+ * **Array element access:**
75
+ * ```typescript
76
+ * const data = {
77
+ * items: [
78
+ * { id: 1, name: "Apple" },
79
+ * { id: 2, name: "Banana" },
80
+ * ],
81
+ * };
82
+ *
83
+ * const mapping: ObjectMapping<typeof data> = {
84
+ * firstItemId: "items[0].id",
85
+ * firstItemName: "items[0].name",
86
+ * };
87
+ *
88
+ * const result = remapObject(data, mapping);
89
+ * // Result includes:
90
+ * // {
91
+ * // firstItemId: 1,
92
+ * // firstItemName: "Apple",
93
+ * // }
94
+ * ```
95
+ *
96
+ * @example
97
+ * **Function-based transformation:**
98
+ * ```typescript
99
+ * const data = {
100
+ * firstName: "John",
101
+ * lastName: "Doe",
102
+ * scores: [85, 92, 78],
103
+ * };
104
+ *
105
+ * const mapping: ObjectMapping<typeof data> = {
106
+ * fullName: (data) => `${data.firstName} ${data.lastName}`,
107
+ * averageScore: (data) =>
108
+ * data.scores.reduce((a, b) => a + b, 0) / data.scores.length,
109
+ * };
110
+ *
111
+ * const result = remapObject(data, mapping);
112
+ * // Result includes:
113
+ * // {
114
+ * // fullName: "John Doe",
115
+ * // averageScore: 85,
116
+ * // }
117
+ * ```
118
+ *
119
+ * @example
120
+ * **Field override:**
121
+ * ```typescript
122
+ * const data = {
123
+ * name: "John",
124
+ * status: "inactive",
125
+ * };
126
+ *
127
+ * const mapping: ObjectMapping<typeof data> = {
128
+ * // Override existing field
129
+ * status: (data) => data.name === "John" ? "active" : "inactive",
130
+ * // Add new field
131
+ * displayName: (data) => `User: ${data.name}`,
132
+ * };
133
+ *
134
+ * const result = remapObject(data, mapping);
135
+ * // Result:
136
+ * // {
137
+ * // name: "John",
138
+ * // status: "active", // Overridden
139
+ * // displayName: "User: John", // Added
140
+ * // }
141
+ * ```
142
+ *
143
+ * @example
144
+ * **Real-world evaluator usage:**
145
+ * ```typescript
146
+ * // Your data structure
147
+ * const example = {
148
+ * question: "What is AI?",
149
+ * context: "AI is artificial intelligence...",
150
+ * answer: "AI stands for artificial intelligence",
151
+ * };
152
+ *
153
+ * // Evaluator expects: { input, reference, output }
154
+ * const mapping: ObjectMapping<typeof example> = {
155
+ * input: "question",
156
+ * reference: "context",
157
+ * output: "answer",
158
+ * };
159
+ *
160
+ * const remapped = remapObject(example, mapping);
161
+ * // Now remapped has: { question, context, answer, input, reference, output }
162
+ * // The evaluator can access input, reference, and output fields
163
+ * ```
164
+ */
165
+ export declare function remapObject<DataType extends Record<string, unknown>>(data: DataType, mapping: ObjectMapping<DataType>): DataType;
166
+ //# sourceMappingURL=objectMappingUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"objectMappingUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/objectMappingUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAe,MAAM,eAAe,CAAC;AAI3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkKG;AACH,wBAAgB,WAAW,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC,GAC/B,QAAQ,CAUV"}