@learning-commons/evaluators 0.4.0 → 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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod';
2
- import { B as BaseEvaluator, a as BaseEvaluatorConfig } from './base-Ced9oKKa.js';
3
- export { E as EvaluatorMetadata, b as LogContext, c as LogLevel, L as Logger, T as TelemetryOptions } from './base-Ced9oKKa.js';
2
+ import { B as BaseEvaluator, P as Provider, a as BaseEvaluatorConfig } from './base-DKcAYXfb.js';
3
+ export { E as EvaluatorMetadata, L as LLMProvider, b as LLMRequest, c as LLMResponse, d as LogContext, e as LogLevel, f as Logger, M as Message, g as ModelOverride, h as ProviderConfig, i as Providers, T as TelemetryOptions, j as TextGenerationResponse } from './base-DKcAYXfb.js';
4
4
 
5
5
  /**
6
6
  * Shared complexity levels used across all text complexity evaluators
@@ -14,6 +14,8 @@ type TextComplexityLevel = z.infer<typeof TextComplexityLevel>;
14
14
  interface EvaluationMetadata {
15
15
  model: string;
16
16
  processingTimeMs: number;
17
+ inputTokens: number;
18
+ outputTokens: number;
17
19
  }
18
20
  /**
19
21
  * Base evaluation result structure
@@ -62,6 +64,111 @@ declare const GradeLevelAppropriatenessSchema: z.ZodObject<{
62
64
  }>;
63
65
  type GradeLevelAppropriatenessInternal = z.infer<typeof GradeLevelAppropriatenessSchema>;
64
66
 
67
+ declare const PurposeOutputSchema: z.ZodObject<{
68
+ complexity_score: z.ZodEnum<["slightly_complex", "moderately_complex", "very_complex", "exceedingly_complex", "more_context_needed"]>;
69
+ reasoning: z.ZodString;
70
+ details: z.ZodObject<{
71
+ detailed_summary: z.ZodArray<z.ZodObject<{
72
+ factor: z.ZodString;
73
+ description: z.ZodString;
74
+ effect_on_complexity_dimension: z.ZodString;
75
+ }, "strict", z.ZodTypeAny, {
76
+ factor: string;
77
+ description: string;
78
+ effect_on_complexity_dimension: string;
79
+ }, {
80
+ factor: string;
81
+ description: string;
82
+ effect_on_complexity_dimension: string;
83
+ }>, "many">;
84
+ adjustment_and_scaffolding: z.ZodArray<z.ZodObject<{
85
+ scaffolding_need: z.ZodString;
86
+ suggestion: z.ZodString;
87
+ }, "strict", z.ZodTypeAny, {
88
+ scaffolding_need: string;
89
+ suggestion: string;
90
+ }, {
91
+ scaffolding_need: string;
92
+ suggestion: string;
93
+ }>, "many">;
94
+ recommended_use_cases: z.ZodArray<z.ZodObject<{
95
+ opportunity: z.ZodString;
96
+ suggestion: z.ZodString;
97
+ }, "strict", z.ZodTypeAny, {
98
+ suggestion: string;
99
+ opportunity: string;
100
+ }, {
101
+ suggestion: string;
102
+ opportunity: string;
103
+ }>, "many">;
104
+ }, "strict", z.ZodTypeAny, {
105
+ detailed_summary: {
106
+ factor: string;
107
+ description: string;
108
+ effect_on_complexity_dimension: string;
109
+ }[];
110
+ adjustment_and_scaffolding: {
111
+ scaffolding_need: string;
112
+ suggestion: string;
113
+ }[];
114
+ recommended_use_cases: {
115
+ suggestion: string;
116
+ opportunity: string;
117
+ }[];
118
+ }, {
119
+ detailed_summary: {
120
+ factor: string;
121
+ description: string;
122
+ effect_on_complexity_dimension: string;
123
+ }[];
124
+ adjustment_and_scaffolding: {
125
+ scaffolding_need: string;
126
+ suggestion: string;
127
+ }[];
128
+ recommended_use_cases: {
129
+ suggestion: string;
130
+ opportunity: string;
131
+ }[];
132
+ }>;
133
+ }, "strict", z.ZodTypeAny, {
134
+ reasoning: string;
135
+ complexity_score: "slightly_complex" | "moderately_complex" | "very_complex" | "exceedingly_complex" | "more_context_needed";
136
+ details: {
137
+ detailed_summary: {
138
+ factor: string;
139
+ description: string;
140
+ effect_on_complexity_dimension: string;
141
+ }[];
142
+ adjustment_and_scaffolding: {
143
+ scaffolding_need: string;
144
+ suggestion: string;
145
+ }[];
146
+ recommended_use_cases: {
147
+ suggestion: string;
148
+ opportunity: string;
149
+ }[];
150
+ };
151
+ }, {
152
+ reasoning: string;
153
+ complexity_score: "slightly_complex" | "moderately_complex" | "very_complex" | "exceedingly_complex" | "more_context_needed";
154
+ details: {
155
+ detailed_summary: {
156
+ factor: string;
157
+ description: string;
158
+ effect_on_complexity_dimension: string;
159
+ }[];
160
+ adjustment_and_scaffolding: {
161
+ scaffolding_need: string;
162
+ suggestion: string;
163
+ }[];
164
+ recommended_use_cases: {
165
+ suggestion: string;
166
+ opportunity: string;
167
+ }[];
168
+ };
169
+ }>;
170
+ type PurposeInternal = z.infer<typeof PurposeOutputSchema>;
171
+
65
172
  /**
66
173
  * Custom error types for the Evaluators SDK
67
174
  *
@@ -204,72 +311,6 @@ declare class TimeoutError extends APIError {
204
311
  constructor(message?: string);
205
312
  }
206
313
 
207
- /**
208
- * Message format for LLM conversations
209
- */
210
- interface Message {
211
- role: 'system' | 'user' | 'assistant';
212
- content: string;
213
- }
214
- /**
215
- * Request configuration for structured LLM generation
216
- */
217
- interface LLMRequest<T> {
218
- messages: Message[];
219
- schema: z.ZodSchema<T>;
220
- temperature?: number;
221
- maxTokens?: number;
222
- model?: string;
223
- }
224
- /**
225
- * Response from LLM with usage metadata
226
- */
227
- interface LLMResponse<T> {
228
- data: T;
229
- model: string;
230
- usage: {
231
- inputTokens: number;
232
- outputTokens: number;
233
- };
234
- latencyMs: number;
235
- }
236
- /**
237
- * Response from plain text generation
238
- */
239
- interface TextGenerationResponse {
240
- text: string;
241
- usage: {
242
- inputTokens: number;
243
- outputTokens: number;
244
- };
245
- latencyMs: number;
246
- }
247
- /**
248
- * Base interface for LLM provider implementations
249
- */
250
- interface LLMProvider {
251
- /**
252
- * Generate structured output from LLM using Zod schema
253
- */
254
- generateStructured<T>(request: LLMRequest<T>): Promise<LLMResponse<T>>;
255
- /**
256
- * Generate plain text from LLM
257
- */
258
- generateText(messages: Message[], temperature?: number): Promise<TextGenerationResponse>;
259
- }
260
- /**
261
- * Configuration for LLM provider
262
- */
263
- interface ProviderConfig {
264
- type: 'openai' | 'anthropic' | 'google' | 'custom';
265
- apiKey?: string;
266
- model?: string;
267
- temperature?: number;
268
- baseURL?: string;
269
- customProvider?: LLMProvider;
270
- maxRetries?: number;
271
- }
272
-
273
314
  /**
274
315
  * Stage 1: Detailed sentence analysis output (40+ metrics)
275
316
  * Ported from Python SentenceAnalysesEvaluatorOutput
@@ -461,18 +502,18 @@ declare const VocabularyComplexitySchema: z.ZodObject<{
461
502
  reasoning: z.ZodString;
462
503
  }, "strip", z.ZodTypeAny, {
463
504
  reasoning: string;
505
+ complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
464
506
  tier_2_words: string;
465
507
  tier_3_words: string;
466
508
  archaic_words: string;
467
509
  other_complex_words: string;
468
- complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
469
510
  }, {
470
511
  reasoning: string;
512
+ complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
471
513
  tier_2_words: string;
472
514
  tier_3_words: string;
473
515
  archaic_words: string;
474
516
  other_complex_words: string;
475
- complexity_score: "Slightly complex" | "Moderately complex" | "Very complex" | "Exceedingly complex";
476
517
  }>;
477
518
  type VocabularyInternal = z.infer<typeof VocabularyComplexitySchema>;
478
519
 
@@ -559,8 +600,7 @@ declare class VocabularyEvaluator extends BaseEvaluator {
559
600
  name: string;
560
601
  description: string;
561
602
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
562
- requiresGoogleKey: boolean;
563
- requiresOpenAIKey: boolean;
603
+ defaultProviders: readonly [Provider.Google, Provider.OpenAI];
564
604
  };
565
605
  private grades34ComplexityProvider;
566
606
  private otherGradesComplexityProvider;
@@ -573,6 +613,7 @@ declare class VocabularyEvaluator extends BaseEvaluator {
573
613
  * @param grade - The target grade level (3-12)
574
614
  * @returns Evaluation result with complexity score and detailed analysis
575
615
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
616
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
576
617
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
577
618
  */
578
619
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, VocabularyInternal>>;
@@ -639,11 +680,9 @@ declare class SentenceStructureEvaluator extends BaseEvaluator {
639
680
  name: string;
640
681
  description: string;
641
682
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
642
- requiresGoogleKey: boolean;
643
- requiresOpenAIKey: boolean;
683
+ defaultProviders: readonly [Provider.OpenAI];
644
684
  };
645
- private analysisProvider;
646
- private complexityProvider;
685
+ private provider;
647
686
  constructor(config: BaseEvaluatorConfig);
648
687
  /**
649
688
  * Evaluate sentence structure complexity for a given text and grade level
@@ -652,6 +691,7 @@ declare class SentenceStructureEvaluator extends BaseEvaluator {
652
691
  * @param grade - The target grade level (3-12)
653
692
  * @returns Evaluation result with complexity score and detailed analysis
654
693
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
694
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
655
695
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
656
696
  */
657
697
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, SentenceStructureInternal>>;
@@ -717,8 +757,7 @@ declare class GradeLevelAppropriatenessEvaluator extends BaseEvaluator {
717
757
  name: string;
718
758
  description: string;
719
759
  supportedGrades: readonly [];
720
- requiresGoogleKey: boolean;
721
- requiresOpenAIKey: boolean;
760
+ defaultProviders: readonly [Provider.Google];
722
761
  };
723
762
  private provider;
724
763
  constructor(config: BaseEvaluatorConfig);
@@ -728,6 +767,7 @@ declare class GradeLevelAppropriatenessEvaluator extends BaseEvaluator {
728
767
  * @param text - The text to evaluate
729
768
  * @returns Evaluation result with grade recommendations and scaffolding suggestions
730
769
  * @throws {ValidationError} If text is empty or too short/long
770
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
731
771
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
732
772
  */
733
773
  evaluate(text: string): Promise<EvaluationResult<GradeBand, GradeLevelAppropriatenessInternal>>;
@@ -776,8 +816,7 @@ declare class SmkEvaluator extends BaseEvaluator {
776
816
  name: string;
777
817
  description: string;
778
818
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
779
- requiresGoogleKey: boolean;
780
- requiresOpenAIKey: boolean;
819
+ defaultProviders: readonly [Provider.Google];
781
820
  };
782
821
  private provider;
783
822
  constructor(config: BaseEvaluatorConfig);
@@ -788,6 +827,7 @@ declare class SmkEvaluator extends BaseEvaluator {
788
827
  * @param grade - The target grade level (3-12)
789
828
  * @returns Evaluation result with complexity score and detailed analysis
790
829
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
830
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
791
831
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
792
832
  */
793
833
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, SmkInternal>>;
@@ -839,8 +879,7 @@ declare class ConventionalityEvaluator extends BaseEvaluator {
839
879
  name: string;
840
880
  description: string;
841
881
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
842
- requiresGoogleKey: boolean;
843
- requiresOpenAIKey: boolean;
882
+ defaultProviders: readonly [Provider.Google];
844
883
  };
845
884
  private provider;
846
885
  constructor(config: BaseEvaluatorConfig);
@@ -851,6 +890,7 @@ declare class ConventionalityEvaluator extends BaseEvaluator {
851
890
  * @param grade - The target grade level (3-12)
852
891
  * @returns Evaluation result with complexity score and detailed analysis
853
892
  * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
893
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
854
894
  * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
855
895
  */
856
896
  evaluate(text: string, grade: string): Promise<EvaluationResult<TextComplexityLevel, ConventionalityInternal>>;
@@ -922,8 +962,7 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
922
962
  name: string;
923
963
  description: string;
924
964
  supportedGrades: readonly ["3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
925
- requiresGoogleKey: boolean;
926
- requiresOpenAIKey: boolean;
965
+ defaultProviders: readonly [Provider.Google, Provider.OpenAI];
927
966
  };
928
967
  private vocabularyEvaluator;
929
968
  private sentenceStructureEvaluator;
@@ -941,7 +980,8 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
941
980
  * @param text - The text to evaluate
942
981
  * @param grade - The target grade level (3-12)
943
982
  * @returns Map of sub-evaluator results
944
- * @throws {ValidationError} If text is empty or grade is invalid
983
+ * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
984
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
945
985
  * @throws {Error} If all sub-evaluators fail
946
986
  */
947
987
  evaluate(text: string, grade: string): Promise<TextComplexityResult>;
@@ -968,6 +1008,35 @@ declare class TextComplexityEvaluator extends BaseEvaluator {
968
1008
  */
969
1009
  declare function evaluateTextComplexity(text: string, grade: string, config: BaseEvaluatorConfig): Promise<TextComplexityResult>;
970
1010
 
1011
+ type PurposeComplexityLevel = TextComplexityLevel | 'More context needed';
1012
+ declare class PurposeEvaluator extends BaseEvaluator {
1013
+ static readonly metadata: {
1014
+ id: string;
1015
+ name: string;
1016
+ description: string;
1017
+ supportedGrades: string[];
1018
+ defaultProviders: readonly [Provider.Google];
1019
+ };
1020
+ private static readonly TEMPERATURE;
1021
+ private static computeFkScore;
1022
+ private provider;
1023
+ constructor(config: BaseEvaluatorConfig);
1024
+ /**
1025
+ * Evaluate purpose complexity for a given text and grade level
1026
+ *
1027
+ * @param text - The text to evaluate
1028
+ * @param grade - The target grade level (3-12)
1029
+ * @returns Evaluation result with complexity score and detailed analysis
1030
+ * @throws {ValidationError} If text is empty, too short/long, or grade is invalid
1031
+ * @throws {ConfigurationError} If modelOverride specifies a model ID that the provider rejects
1032
+ * @throws {APIError} If LLM API calls fail (includes AuthenticationError, RateLimitError, NetworkError, TimeoutError)
1033
+ */
1034
+ evaluate(text: string, grade: string): Promise<EvaluationResult<PurposeComplexityLevel, PurposeInternal>>;
1035
+ private parseAndValidateGrade;
1036
+ private callLLM;
1037
+ }
1038
+ declare function evaluatePurpose(text: string, grade: string, config: BaseEvaluatorConfig): Promise<EvaluationResult<PurposeComplexityLevel, PurposeInternal>>;
1039
+
971
1040
  /**
972
1041
  * Calculate Flesch-Kincaid Grade Level
973
1042
  * Equivalent to Python's textstat.flesch_kincaid_grade()
@@ -998,4 +1067,4 @@ declare function addEngineeredFeatures(analysis: SentenceAnalysis): SentenceFeat
998
1067
  */
999
1068
  declare function featuresToJSON(features: SentenceFeatures, decimals?: number, castToInt?: boolean): string;
1000
1069
 
1001
- export { APIError, AuthenticationError, BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, type LLMProvider, type LLMRequest, type LLMResponse, type Message, NetworkError, type ProviderConfig, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, type TextGenerationResponse, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };
1070
+ export { APIError, AuthenticationError, BaseEvaluatorConfig, type ComplexityClassification, ComplexityClassificationSchema, ConfigurationError, ConventionalityEvaluator, type ConventionalityInternal, type EvaluationError, type EvaluationMetadata, type EvaluationResult, EvaluatorError, GradeBand, GradeLevelAppropriatenessEvaluator, type GradeLevelAppropriatenessInternal, GradeLevelAppropriatenessSchema, NetworkError, Provider, type PurposeComplexityLevel, PurposeEvaluator, type PurposeInternal, RateLimitError, type ReadabilityMetrics, type SentenceAnalysis, SentenceAnalysisSchema, type SentenceFeatures, SentenceStructureEvaluator, type SentenceStructureInternal, SmkEvaluator, type SmkInternal, TextComplexityEvaluator, TextComplexityLevel, type TextComplexityResult, TimeoutError, ValidationError, VocabularyEvaluator, type VocabularyInternal, addEngineeredFeatures, calculateFleschKincaidGrade, calculateReadabilityMetrics, evaluateConventionality, evaluateGradeLevelAppropriateness, evaluatePurpose, evaluateSentenceStructure, evaluateSmk, evaluateTextComplexity, evaluateVocabulary, featuresToJSON };