judgeval 0.3.0 → 0.3.2

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 (139) hide show
  1. package/dist/constants.d.ts +1 -1
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/env.d.ts +2 -0
  4. package/dist/env.d.ts.map +1 -1
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.mjs +5 -2
  8. package/dist/index.mjs.map +30 -1
  9. package/dist/index.umd.js +5 -2
  10. package/dist/index.umd.js.map +30 -1
  11. package/dist/scorers/api_scorers/prompt_scorer/base-prompt-scorer.d.ts +1 -1
  12. package/dist/scorers/api_scorers/prompt_scorer/base-prompt-scorer.d.ts.map +1 -1
  13. package/dist/scorers/base-scorer.d.ts +1 -1
  14. package/dist/scorers/base-scorer.d.ts.map +1 -1
  15. package/dist/tracer/BrowserTracer.d.ts +11 -0
  16. package/dist/tracer/BrowserTracer.d.ts.map +1 -0
  17. package/dist/tracer/NodeTracer.d.ts +16 -0
  18. package/dist/tracer/NodeTracer.d.ts.map +1 -0
  19. package/dist/tracer/OpenTelemetryKeys.d.ts +28 -1
  20. package/dist/tracer/OpenTelemetryKeys.d.ts.map +1 -1
  21. package/dist/tracer/Tracer.d.ts +22 -23
  22. package/dist/tracer/Tracer.d.ts.map +1 -1
  23. package/dist/tracer/TracerConfiguration.d.ts.map +1 -1
  24. package/dist/tracer/exporters/JudgmentSpanExporter.d.ts +49 -2
  25. package/dist/tracer/exporters/JudgmentSpanExporter.d.ts.map +1 -1
  26. package/dist/utils/guards.d.ts +4 -0
  27. package/dist/utils/guards.d.ts.map +1 -0
  28. package/dist/utils/index.d.ts +1 -0
  29. package/dist/utils/index.d.ts.map +1 -1
  30. package/dist/version.d.ts +1 -1
  31. package/package.json +19 -20
  32. package/dist/constants.js +0 -2
  33. package/dist/constants.js.map +0 -1
  34. package/dist/data/example-params.js +0 -12
  35. package/dist/data/example-params.js.map +0 -1
  36. package/dist/data/example.js +0 -10
  37. package/dist/data/example.js.map +0 -1
  38. package/dist/data/index.js +0 -3
  39. package/dist/data/index.js.map +0 -1
  40. package/dist/env.js +0 -13
  41. package/dist/env.js.map +0 -1
  42. package/dist/index.js +0 -2
  43. package/dist/index.js.map +0 -1
  44. package/dist/internal/api/index.js +0 -132
  45. package/dist/internal/api/index.js.map +0 -1
  46. package/dist/internal/api/models/BaseScorer.js +0 -6
  47. package/dist/internal/api/models/BaseScorer.js.map +0 -1
  48. package/dist/internal/api/models/EvalResults.js +0 -6
  49. package/dist/internal/api/models/EvalResults.js.map +0 -1
  50. package/dist/internal/api/models/EvalResultsFetch.js +0 -6
  51. package/dist/internal/api/models/EvalResultsFetch.js.map +0 -1
  52. package/dist/internal/api/models/Example.js +0 -6
  53. package/dist/internal/api/models/Example.js.map +0 -1
  54. package/dist/internal/api/models/ExampleEvaluationRun.js +0 -6
  55. package/dist/internal/api/models/ExampleEvaluationRun.js.map +0 -1
  56. package/dist/internal/api/models/FetchPromptScorersRequest.js +0 -6
  57. package/dist/internal/api/models/FetchPromptScorersRequest.js.map +0 -1
  58. package/dist/internal/api/models/FetchPromptScorersResponse.js +0 -6
  59. package/dist/internal/api/models/FetchPromptScorersResponse.js.map +0 -1
  60. package/dist/internal/api/models/OtelTraceSpan.js +0 -6
  61. package/dist/internal/api/models/OtelTraceSpan.js.map +0 -1
  62. package/dist/internal/api/models/PromptScorer.js +0 -6
  63. package/dist/internal/api/models/PromptScorer.js.map +0 -1
  64. package/dist/internal/api/models/ResolveProjectNameRequest.js +0 -6
  65. package/dist/internal/api/models/ResolveProjectNameRequest.js.map +0 -1
  66. package/dist/internal/api/models/ResolveProjectNameResponse.js +0 -6
  67. package/dist/internal/api/models/ResolveProjectNameResponse.js.map +0 -1
  68. package/dist/internal/api/models/SavePromptScorerRequest.js +0 -6
  69. package/dist/internal/api/models/SavePromptScorerRequest.js.map +0 -1
  70. package/dist/internal/api/models/SavePromptScorerResponse.js +0 -6
  71. package/dist/internal/api/models/SavePromptScorerResponse.js.map +0 -1
  72. package/dist/internal/api/models/ScorerConfig.js +0 -6
  73. package/dist/internal/api/models/ScorerConfig.js.map +0 -1
  74. package/dist/internal/api/models/ScorerData.js +0 -6
  75. package/dist/internal/api/models/ScorerData.js.map +0 -1
  76. package/dist/internal/api/models/ScorerExistsRequest.js +0 -6
  77. package/dist/internal/api/models/ScorerExistsRequest.js.map +0 -1
  78. package/dist/internal/api/models/ScorerExistsResponse.js +0 -6
  79. package/dist/internal/api/models/ScorerExistsResponse.js.map +0 -1
  80. package/dist/internal/api/models/ScoringResult.js +0 -6
  81. package/dist/internal/api/models/ScoringResult.js.map +0 -1
  82. package/dist/internal/api/models/TraceEvaluationRun.js +0 -6
  83. package/dist/internal/api/models/TraceEvaluationRun.js.map +0 -1
  84. package/dist/internal/api/models.js +0 -24
  85. package/dist/internal/api/models.js.map +0 -1
  86. package/dist/scorers/api-scorer.js +0 -36
  87. package/dist/scorers/api-scorer.js.map +0 -1
  88. package/dist/scorers/api_scorers/answer-correctness-scorer.js +0 -20
  89. package/dist/scorers/api_scorers/answer-correctness-scorer.js.map +0 -1
  90. package/dist/scorers/api_scorers/answer-relevancy-scorer.js +0 -19
  91. package/dist/scorers/api_scorers/answer-relevancy-scorer.js.map +0 -1
  92. package/dist/scorers/api_scorers/faithfulness-scorer.js +0 -20
  93. package/dist/scorers/api_scorers/faithfulness-scorer.js.map +0 -1
  94. package/dist/scorers/api_scorers/index.js +0 -2
  95. package/dist/scorers/api_scorers/index.js.map +0 -1
  96. package/dist/scorers/api_scorers/instruction-adherence-scorer.js +0 -20
  97. package/dist/scorers/api_scorers/instruction-adherence-scorer.js.map +0 -1
  98. package/dist/scorers/api_scorers/prompt_scorer/base-prompt-scorer.js +0 -133
  99. package/dist/scorers/api_scorers/prompt_scorer/base-prompt-scorer.js.map +0 -1
  100. package/dist/scorers/api_scorers/prompt_scorer/index.js +0 -5
  101. package/dist/scorers/api_scorers/prompt_scorer/index.js.map +0 -1
  102. package/dist/scorers/api_scorers/prompt_scorer/prompt-scorer-utils.js +0 -44
  103. package/dist/scorers/api_scorers/prompt_scorer/prompt-scorer-utils.js.map +0 -1
  104. package/dist/scorers/api_scorers/prompt_scorer/prompt-scorer.js +0 -9
  105. package/dist/scorers/api_scorers/prompt_scorer/prompt-scorer.js.map +0 -1
  106. package/dist/scorers/api_scorers/prompt_scorer/trace-prompt-scorer.js +0 -8
  107. package/dist/scorers/api_scorers/prompt_scorer/trace-prompt-scorer.js.map +0 -1
  108. package/dist/scorers/base-scorer.js +0 -41
  109. package/dist/scorers/base-scorer.js.map +0 -1
  110. package/dist/scorers/index.js +0 -4
  111. package/dist/scorers/index.js.map +0 -1
  112. package/dist/tracer/OpenTelemetryKeys.js +0 -12
  113. package/dist/tracer/OpenTelemetryKeys.js.map +0 -1
  114. package/dist/tracer/Tracer.js +0 -235
  115. package/dist/tracer/Tracer.js.map +0 -1
  116. package/dist/tracer/TracerConfiguration.js +0 -111
  117. package/dist/tracer/TracerConfiguration.js.map +0 -1
  118. package/dist/tracer/exporters/JudgmentSpanExporter.js +0 -72
  119. package/dist/tracer/exporters/JudgmentSpanExporter.js.map +0 -1
  120. package/dist/tracer/exporters/NoOpSpanExporter.js +0 -16
  121. package/dist/tracer/exporters/NoOpSpanExporter.js.map +0 -1
  122. package/dist/tracer/exporters/index.js +0 -3
  123. package/dist/tracer/exporters/index.js.map +0 -1
  124. package/dist/tracer/index.js +0 -5
  125. package/dist/tracer/index.js.map +0 -1
  126. package/dist/umd.js +0 -2
  127. package/dist/umd.js.map +0 -1
  128. package/dist/utils/annotate.js +0 -27
  129. package/dist/utils/annotate.js.map +0 -1
  130. package/dist/utils/index.js +0 -5
  131. package/dist/utils/index.js.map +0 -1
  132. package/dist/utils/logger.js +0 -70
  133. package/dist/utils/logger.js.map +0 -1
  134. package/dist/utils/types.js +0 -2
  135. package/dist/utils/types.js.map +0 -1
  136. package/dist/utils/validation.js +0 -16
  137. package/dist/utils/validation.js.map +0 -1
  138. package/dist/version.js +0 -2
  139. package/dist/version.js.map +0 -1
@@ -1,11 +1,38 @@
1
- export declare class OpenTelemetryKeys {
1
+ export declare abstract class OpenTelemetryKeys {
2
2
  static readonly AttributeKeys: {
3
3
  readonly JUDGMENT_SPAN_KIND: "judgment.span_kind";
4
4
  readonly JUDGMENT_INPUT: "judgment.input";
5
5
  readonly JUDGMENT_OUTPUT: "judgment.output";
6
+ readonly JUDGMENT_OFFLINE_MODE: "judgment.offline_mode";
7
+ readonly JUDGMENT_UPDATE_ID: "judgment.update_id";
8
+ readonly JUDGMENT_CUSTOMER_ID: "judgment.customer_id";
9
+ readonly JUDGMENT_AGENT_ID: "judgment.agent_id";
10
+ readonly JUDGMENT_PARENT_AGENT_ID: "judgment.parent_agent_id";
11
+ readonly JUDGMENT_AGENT_CLASS_NAME: "judgment.agent_class_name";
12
+ readonly JUDGMENT_AGENT_INSTANCE_NAME: "judgment.agent_instance_name";
6
13
  readonly PENDING_TRACE_EVAL: "judgment.pending_trace_eval";
14
+ readonly GEN_AI_PROMPT: "gen_ai.prompt";
15
+ readonly GEN_AI_COMPLETION: "gen_ai.completion";
16
+ readonly GEN_AI_REQUEST_MODEL: "gen_ai.request.model";
17
+ readonly GEN_AI_RESPONSE_MODEL: "gen_ai.response.model";
18
+ readonly GEN_AI_SYSTEM: "gen_ai.system";
19
+ readonly GEN_AI_USAGE_INPUT_TOKENS: "gen_ai.usage.input_tokens";
20
+ readonly GEN_AI_USAGE_OUTPUT_TOKENS: "gen_ai.usage.output_tokens";
21
+ readonly GEN_AI_USAGE_COMPLETION_TOKENS: "gen_ai.usage.completion_tokens";
22
+ readonly GEN_AI_REQUEST_TEMPERATURE: "gen_ai.request.temperature";
23
+ readonly GEN_AI_REQUEST_MAX_TOKENS: "gen_ai.request.max_tokens";
24
+ readonly GEN_AI_RESPONSE_FINISH_REASONS: "gen_ai.response.finish_reasons";
25
+ readonly GEN_AI_USAGE_TOTAL_COST: "gen_ai.usage.total_cost_usd";
26
+ };
27
+ static readonly InternalAttributeKeys: {
28
+ readonly DISABLE_PARTIAL_EMIT: "disable_partial_emit";
29
+ readonly CANCELLED: "cancelled";
7
30
  };
8
31
  static readonly ResourceKeys: {
32
+ readonly SERVICE_NAME: "service.name";
33
+ readonly TELEMETRY_SDK_LANGUAGE: "telemetry.sdk.language";
34
+ readonly TELEMETRY_SDK_NAME: "telemetry.sdk.name";
35
+ readonly TELEMETRY_SDK_VERSION: "telemetry.sdk.version";
9
36
  readonly JUDGMENT_PROJECT_ID: "judgment.project_id";
10
37
  };
11
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OpenTelemetryKeys.d.ts","sourceRoot":"","sources":["../../src/tracer/OpenTelemetryKeys.ts"],"names":[],"mappings":"AAAA,qBAAa,iBAAiB;IAC5B,gBAAuB,aAAa;;;;;MAKzB;IAEX,gBAAuB,YAAY;;MAExB;CACZ"}
1
+ {"version":3,"file":"OpenTelemetryKeys.d.ts","sourceRoot":"","sources":["../../src/tracer/OpenTelemetryKeys.ts"],"names":[],"mappings":"AAAA,8BAAsB,iBAAiB;IACrC,gBAAuB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;MA8BzB;IAEX,gBAAuB,qBAAqB;;;MAGjC;IAEX,gBAAuB,YAAY;;;;;;MAMxB;CACZ"}
@@ -4,44 +4,43 @@ import { BaseScorer } from "../scorers/base-scorer";
4
4
  import { JudgmentSpanExporter, NoOpSpanExporter } from "./exporters";
5
5
  import { TracerConfiguration } from "./TracerConfiguration";
6
6
  export type Serializer = (obj: unknown) => string;
7
- export declare class Tracer {
8
- private readonly configuration;
9
- private readonly apiClient;
10
- private readonly serializer;
7
+ type SpanKind = ("llm" | "tool" | "span") & {};
8
+ export type TracerInitializeOptions = {
9
+ resourceAttributes?: Record<string, unknown>;
10
+ [key: string]: unknown;
11
+ };
12
+ export declare abstract class Tracer {
13
+ protected static instances: Map<string, Tracer>;
14
+ apiClient: JudgmentApiClient;
15
+ tracer: unknown;
16
+ serializer: Serializer;
17
+ protected _initialized: boolean;
11
18
  private projectId;
12
- private projectIdPromise;
19
+ protected configuration: TracerConfiguration;
13
20
  getConfiguration(): TracerConfiguration;
14
21
  getProjectId(): string | null;
15
22
  getSerializer(): Serializer;
16
- constructor(configuration: TracerConfiguration, apiClient: JudgmentApiClient, serializer: Serializer);
23
+ constructor(configuration: TracerConfiguration);
24
+ abstract initialize(options: TracerInitializeOptions): Promise<Tracer>;
17
25
  private resolveProjectId;
18
- static builder(): TracerBuilder;
19
- static createDefault(projectName: string): Tracer;
20
- static createWithConfiguration(configuration: TracerConfiguration): Tracer;
26
+ static getExporter(apiKey: string, organizationId: string, projectId: string): JudgmentSpanExporter;
21
27
  getSpanExporter(): Promise<JudgmentSpanExporter | NoOpSpanExporter>;
22
- setSpanKind(kind: string | null): void;
23
- setAttribute(key: string, value: unknown, type?: any): void;
28
+ setSpanKind(kind: SpanKind): void;
29
+ setAttribute(key: string, value: unknown): void;
24
30
  setLLMSpan(): void;
25
31
  setToolSpan(): void;
26
32
  setGeneralSpan(): void;
27
33
  setAttributes(attributes: Record<string, unknown>): void;
28
- setInput(input: unknown, type?: any): void;
29
- setOutput(output: unknown, type?: any): void;
34
+ setInput(input: unknown): void;
35
+ setOutput(output: unknown): void;
30
36
  asyncEvaluate(scorer: BaseScorer, example: ExampleModel, model?: string): void;
31
37
  asyncTraceEvaluate(scorer: BaseScorer, model?: string): void;
32
38
  private createTraceEvaluationRun;
33
39
  private createJudgmentSpanExporter;
34
40
  private createEvaluationRun;
35
41
  private enqueueEvaluation;
42
+ observe<TArgs extends any[], TResult>(func: (...args: TArgs) => TResult, spanKind?: SpanKind): (...args: TArgs) => TResult;
43
+ shutdown(): Promise<void>;
36
44
  }
37
- export declare class TracerBuilder {
38
- private config?;
39
- private _apiClient?;
40
- private _serializer;
41
- static builder(): TracerBuilder;
42
- configuration(configuration: TracerConfiguration): this;
43
- apiClient(apiClient: JudgmentApiClient): this;
44
- serializer(serializer: Serializer): this;
45
- build(): Tracer;
46
- }
45
+ export {};
47
46
  //# sourceMappingURL=Tracer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tracer.d.ts","sourceRoot":"","sources":["../../src/tracer/Tracer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAEL,OAAO,IAAI,YAAY,EAExB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;AAElD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;IAC9C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,gBAAgB,CAAyB;IAE1C,gBAAgB,IAAI,mBAAmB;IAIvC,YAAY,IAAI,MAAM,GAAG,IAAI;IAI7B,aAAa,IAAI,UAAU;gBAKhC,aAAa,EAAE,mBAAmB,EAClC,SAAS,EAAE,iBAAiB,EAC5B,UAAU,EAAE,UAAU;YAQV,gBAAgB;WA4BhB,OAAO,IAAI,aAAa;WAIxB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;WAM1C,uBAAuB,CACnC,aAAa,EAAE,mBAAmB,GACjC,MAAM;IAII,eAAe,IAAI,OAAO,CACrC,oBAAoB,GAAG,gBAAgB,CACxC;IAeM,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IActC,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,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0BAA0B;CAGpD;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,0BAA0B;IACrC,OAAO,CAAC,YAAY,CAAC,CAAS;IAC9B,OAAO,CAAC,OAAO,CAAmC;IAClD,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,iBAAiB,CAAiB;IAC1C,OAAO,CAAC,WAAW,CAAqD;IAEjE,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKtC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAK5C,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,gBAAgB,CAAC,gBAAgB,EAAE,OAAO,GAAG,IAAI;IAKjD,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAKpC,KAAK,IAAI,mBAAmB;CA0BpC"}
@@ -1,11 +1,43 @@
1
- import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
2
- export declare class JudgmentSpanExporter extends OTLPTraceExporter {
1
+ import { ExportResult } from "@opentelemetry/core";
2
+ import { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
3
+ /**
4
+ * SpanExporter implementation that sends spans to Judgment Labs with project identification.
5
+ *
6
+ * This exporter wraps the OTLP HTTP exporter and adds Judgment Labs specific headers and project
7
+ * identification to all exported spans.
8
+ */
9
+ export declare class JudgmentSpanExporter implements SpanExporter {
10
+ private readonly delegate;
11
+ /**
12
+ * Creates a new JudgmentSpanExporter with the specified configuration.
13
+ *
14
+ * @param endpoint the OTLP endpoint URL
15
+ * @param apiKey the API key for authentication
16
+ * @param organizationId the organization ID
17
+ * @param projectId the project ID (must not be null or empty)
18
+ * @throws Error if projectId is null or empty
19
+ */
3
20
  constructor(endpoint: string, apiKey: string, organizationId: string, projectId: string);
4
21
  /**
5
22
  * Creates a new builder for constructing JudgmentSpanExporter instances.
6
23
  */
7
24
  static builder(): JudgmentSpanExporterBuilder;
25
+ /**
26
+ * Exports a collection of spans.
27
+ */
28
+ export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
29
+ /**
30
+ * Shuts down the exporter.
31
+ */
32
+ shutdown(): Promise<void>;
33
+ /**
34
+ * Forces the exporter to flush any pending spans.
35
+ */
36
+ forceFlush(): Promise<void>;
8
37
  }
38
+ /**
39
+ * Builder for creating JudgmentSpanExporter instances.
40
+ */
9
41
  export declare class JudgmentSpanExporterBuilder {
10
42
  private _endpoint?;
11
43
  private _apiKey?;
@@ -14,22 +46,37 @@ export declare class JudgmentSpanExporterBuilder {
14
46
  constructor();
15
47
  /**
16
48
  * Sets the OTLP endpoint URL.
49
+ *
50
+ * @param endpoint the endpoint URL
51
+ * @return this builder for method chaining
17
52
  */
18
53
  endpoint(endpoint: string): this;
19
54
  /**
20
55
  * Sets the API key for authentication.
56
+ *
57
+ * @param apiKey the API key
58
+ * @return this builder for method chaining
21
59
  */
22
60
  apiKey(apiKey: string): this;
23
61
  /**
24
62
  * Sets the organization ID.
63
+ *
64
+ * @param organizationId the organization ID
65
+ * @return this builder for method chaining
25
66
  */
26
67
  organizationId(organizationId: string): this;
27
68
  /**
28
69
  * Sets the project ID.
70
+ *
71
+ * @param projectId the project ID
72
+ * @return this builder for method chaining
29
73
  */
30
74
  projectId(projectId: string): this;
31
75
  /**
32
76
  * Builds a new JudgmentSpanExporter with the current configuration.
77
+ *
78
+ * @return a new JudgmentSpanExporter instance
79
+ * @throws Error if required fields are missing
33
80
  */
34
81
  build(): JudgmentSpanExporter;
35
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"JudgmentSpanExporter.d.ts","sourceRoot":"","sources":["../../../src/tracer/exporters/JudgmentSpanExporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAE5E,qBAAa,oBAAqB,SAAQ,iBAAiB;gBAEvD,QAAQ,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AAI,CAAC;IAIzB;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAG5B;AAED;;GAEG;AACH,qBAAa,2BAA2B;IACtC,OAAO,CAAC,SAAS,CAAC,CAAS;IAC3B,OAAO,CAAC,OAAO,CAAC,CAAS;IACzB,OAAO,CAAC,eAAe,CAAC,CAAS;IACjC,OAAO,CAAC,UAAU,CAAC,CAAS;;IAI5B;;;;;OAKG;IACI,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAKvC;;;;;OAKG;IACI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAKnC;;;;;OAKG;IACI,cAAc,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI;IAKnD;;;;;OAKG;IACI,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAKzC;;;;;OAKG;IACI,KAAK,IAAI,oBAAoB;CAqBrC"}
@@ -0,0 +1,4 @@
1
+ export declare function expect<T>(value: T | null | undefined, message: string): T;
2
+ export declare function expectApiKey(apiKey: string | null | undefined): string;
3
+ export declare function expectOrganizationId(organizationId: string | null | undefined): string;
4
+ //# sourceMappingURL=guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../src/utils/guards.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,CAKzE;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAKtE;AAED,wBAAgB,oBAAoB,CAClC,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACxC,MAAM,CAKR"}
@@ -1,4 +1,5 @@
1
1
  export * from "./annotate";
2
+ export * from "./guards";
2
3
  export * from "./logger";
3
4
  export * from "./types";
4
5
  export * from "./validation";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.3.0";
1
+ export declare const VERSION = "0.3.2";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "judgeval",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "JavaScript/TypeScript client for Judgment evaluation platform",
5
- "main": "./dist/index.js",
5
+ "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
10
  "import": "./dist/index.mjs",
11
- "require": "./dist/index.js",
12
11
  "types": "./dist/index.d.ts"
13
12
  },
13
+ "./umd": "./dist/index.umd.js",
14
14
  "./package.json": "./package.json"
15
15
  },
16
16
  "files": [
@@ -19,18 +19,17 @@
19
19
  "LICENSE"
20
20
  ],
21
21
  "scripts": {
22
- "build": "npm run build:types && npm run build:esm && npm run build:cjs && npm run build:umd",
22
+ "build": "bun run check && bun run build:types && bun scripts/build.ts lib umd",
23
23
  "build:types": "tsc -p tsconfig.build.json",
24
- "build:esm": "webpack --mode production --config webpack.config.js --env target=esm",
25
- "build:cjs": "webpack --mode production --config webpack.config.js --env target=cjs",
26
- "build:umd": "webpack --mode production --config webpack.config.js --env target=umd",
27
- "build:dev": "npm run build:types && webpack --mode development --config webpack.config.js --env target=esm",
24
+ "build:lib": "bun scripts/build.ts lib",
25
+ "build:umd": "bun scripts/build.ts umd",
26
+ "build:dev": "bun run build:types && bun scripts/build.ts lib --dev",
28
27
  "check": "tsc --noEmit",
29
28
  "format": "prettier --write \"src/**/*.ts\"",
30
- "generate-client": "ts-node scripts/generate-client.ts && npm run format",
31
- "test": "ts-node test.ts",
29
+ "generate-client": "bunx tsx scripts/generate-client.ts && bun run format",
30
+ "test": "bunx tsx test.ts",
32
31
  "clean": "rimraf dist",
33
- "prepublishOnly": "npm run clean && npm run build"
32
+ "prepublishOnly": "bun run clean && bun run build"
34
33
  },
35
34
  "keywords": [
36
35
  "judgment",
@@ -50,25 +49,25 @@
50
49
  "dependencies": {
51
50
  "@opentelemetry/api": "^1.9.0",
52
51
  "@opentelemetry/core": "^2.1.0",
52
+ "@opentelemetry/exporter-trace-otlp-http": "^0.205.0",
53
+ "@opentelemetry/resources": "^2.1.0",
54
+ "@opentelemetry/sdk-node": "^0.205.0",
53
55
  "@opentelemetry/sdk-trace-base": "^2.1.0",
54
- "@opentelemetry/exporter-trace-otlp-http": "^0.205.0"
56
+ "@opentelemetry/sdk-trace-node": "^2.1.0",
57
+ "@opentelemetry/sdk-trace-web": "^2.1.0"
55
58
  },
56
59
  "devDependencies": {
57
60
  "@opentelemetry/auto-instrumentations-node": "^0.64.1",
58
61
  "@opentelemetry/sdk-metrics": "^2.1.0",
59
- "@opentelemetry/sdk-node": "^0.205.0",
60
- "@opentelemetry/sdk-trace-node": "^2.1.0",
62
+ "@types/bun": "^1.2.22",
61
63
  "@types/node": "^24.5.2",
62
64
  "dotenv": "^17.2.2",
63
65
  "prettier": "^3.6.2",
64
66
  "rimraf": "^6.0.1",
65
- "ts-loader": "^9.5.4",
66
- "ts-node": "^10.9.2",
67
- "typescript": "^5.9.2",
68
- "webpack": "^5.101.3",
69
- "webpack-cli": "^6.0.1"
67
+ "typescript": "^5.9.2"
70
68
  },
71
69
  "engines": {
72
- "node": ">=16.0.0"
70
+ "node": ">=18.0.0",
71
+ "bun": ">=1.0.0"
73
72
  }
74
73
  }
package/dist/constants.js DELETED
@@ -1,2 +0,0 @@
1
- export const TRACER_NAME = "judgeval-tracer";
2
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC"}
@@ -1,12 +0,0 @@
1
- export var ExampleParams;
2
- (function (ExampleParams) {
3
- ExampleParams["INPUT"] = "input";
4
- ExampleParams["ACTUAL_OUTPUT"] = "actual_output";
5
- ExampleParams["EXPECTED_OUTPUT"] = "expected_output";
6
- ExampleParams["CONTEXT"] = "context";
7
- ExampleParams["RETRIEVAL_CONTEXT"] = "retrieval_context";
8
- ExampleParams["TOOLS_CALLED"] = "tools_called";
9
- ExampleParams["EXPECTED_TOOLS"] = "expected_tools";
10
- ExampleParams["ADDITIONAL_METADATA"] = "additional_metadata";
11
- })(ExampleParams || (ExampleParams = {}));
12
- //# sourceMappingURL=example-params.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"example-params.js","sourceRoot":"","sources":["../../src/data/example-params.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,aASX;AATD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,gDAA+B,CAAA;IAC/B,oDAAmC,CAAA;IACnC,oCAAmB,CAAA;IACnB,wDAAuC,CAAA;IACvC,8CAA6B,CAAA;IAC7B,kDAAiC,CAAA;IACjC,4DAA2C,CAAA;AAC7C,CAAC,EATW,aAAa,KAAb,aAAa,QASxB"}
@@ -1,10 +0,0 @@
1
- export function createExample(properties) {
2
- const example = {
3
- example_id: undefined,
4
- created_at: new Date().toISOString(),
5
- name: null,
6
- ...properties,
7
- };
8
- return example;
9
- }
10
- //# sourceMappingURL=example.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"example.js","sourceRoot":"","sources":["../../src/data/example.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,aAAa,CAC3B,UAAa;IAEb,MAAM,OAAO,GAAe;QAC1B,UAAU,EAAE,SAAS;QACrB,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACpC,IAAI,EAAE,IAAI;QACV,GAAG,UAAU;KACA,CAAC;IAEhB,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from "./example";
2
- export * from "./example-params";
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/data/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC"}
package/dist/env.js DELETED
@@ -1,13 +0,0 @@
1
- function getEnvVar(varName, defaultValue) {
2
- const value = process.env[varName];
3
- if (!value) {
4
- return defaultValue ?? null;
5
- }
6
- return value;
7
- }
8
- export const JUDGMENT_API_KEY = getEnvVar("JUDGMENT_API_KEY");
9
- export const JUDGMENT_ORG_ID = getEnvVar("JUDGMENT_ORG_ID");
10
- export const JUDGMENT_API_URL = getEnvVar("JUDGMENT_API_URL", "https://api.judgmentlabs.ai");
11
- export const JUDGMENT_DEFAULT_GPT_MODEL = getEnvVar("JUDGMENT_DEFAULT_GPT_MODEL", "gpt-4.1");
12
- export const JUDGMENT_NO_COLOR = getEnvVar("JUDGMENT_NO_COLOR");
13
- //# sourceMappingURL=env.js.map
package/dist/env.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAEA,SAAS,SAAS,CAAC,OAAe,EAAE,YAAqB;IACvD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,YAAY,IAAI,IAAI,CAAC;IAC9B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,gBAAgB,GAAG,SAAS,CACvC,kBAAkB,EAClB,6BAA6B,CAC9B,CAAC;AACF,MAAM,CAAC,MAAM,0BAA0B,GAAG,SAAS,CACjD,4BAA4B,EAC5B,SAAS,CACV,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC"}
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- (()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{APIScorerType:()=>S,BasePromptScorer:()=>b,ExampleParams:()=>P,JUDGMENT_API_KEY:()=>u,JUDGMENT_API_URL:()=>l,JUDGMENT_DEFAULT_GPT_MODEL:()=>d,JUDGMENT_NO_COLOR:()=>p,JUDGMENT_ORG_ID:()=>h,JudgmentAPIError:()=>O,JudgmentApiClient:()=>m,JudgmentSpanExporter:()=>i,Logger:()=>_,NoOpSpanExporter:()=>o,OpenTelemetryKeys:()=>n,PromptScorer:()=>j,TracePromptScorer:()=>U,Tracer:()=>f,TracerBuilder:()=>w,TracerConfiguration:()=>E,TracerConfigurationBuilder:()=>T,createAPIScorer:()=>v,createBaseScorer:()=>I,createExample:()=>y,fetchPromptScorer:()=>R,parseFunctionArgs:()=>z,pushPromptScorer:()=>N,scorerExists:()=>A});const r=require("@opentelemetry/exporter-trace-otlp-http");class i extends r.OTLPTraceExporter{constructor(t,e,r,i){if(!i||""===i.trim())throw new Error("projectId is required for JudgmentSpanExporter");super({url:t,headers:{Authorization:`Bearer ${e}`,"X-Organization-Id":r,"X-Project-Id":i}})}static builder(){return new s}}class s{constructor(){}endpoint(t){return this._endpoint=t,this}apiKey(t){return this._apiKey=t,this}organizationId(t){return this._organizationId=t,this}projectId(t){return this._projectId=t,this}build(){if(!this._endpoint||""===this._endpoint.trim())throw new Error("Endpoint is required");if(!this._apiKey||""===this._apiKey.trim())throw new Error("API key is required");if(!this._organizationId||""===this._organizationId.trim())throw new Error("Organization ID is required");if(!this._projectId||""===this._projectId.trim())throw new Error("Project ID is required");return new i(this._endpoint,this._apiKey,this._organizationId,this._projectId)}}class o{export(t,e){e({code:0})}flush(){return Promise.resolve()}shutdown(){return Promise.resolve()}}class n{}n.AttributeKeys={JUDGMENT_SPAN_KIND:"judgment.span_kind",JUDGMENT_INPUT:"judgment.input",JUDGMENT_OUTPUT:"judgment.output",PENDING_TRACE_EVAL:"judgment.pending_trace_eval"},n.ResourceKeys={JUDGMENT_PROJECT_ID:"judgment.project_id"};const a=require("@opentelemetry/api");function c(t,e){return process.env[t]||(e??null)}const u=c("JUDGMENT_API_KEY"),h=c("JUDGMENT_ORG_ID"),l=c("JUDGMENT_API_URL","https://api.judgmentlabs.ai"),d=c("JUDGMENT_DEFAULT_GPT_MODEL","gpt-4.1"),p=c("JUDGMENT_NO_COLOR");class m{constructor(t,e,r){this.baseUrl=t,this.apiKey=e,this.organizationId=r}buildUrl(t){return this.baseUrl+t}buildHeaders(){if(!this.apiKey||!this.organizationId)throw new Error("API key and organization ID cannot be null");return{"Content-Type":"application/json",Authorization:`Bearer ${this.apiKey}`,"X-Organization-Id":this.organizationId}}async addToRunEvalQueueExamples(t){const e=this.buildUrl("/add_to_run_eval_queue/examples"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`)}async addToRunEvalQueueTraces(t){const e=this.buildUrl("/add_to_run_eval_queue/traces"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`)}async logEvalResults(t){const e=this.buildUrl("/log_eval_results/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`)}async fetchExperimentRun(t){const e=this.buildUrl("/fetch_experiment_run/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`)}async getEvaluationStatus(t,e){const r=new URLSearchParams;r.set("experiment_run_id",t),r.set("project_name",e);const i=this.buildUrl("/get_evaluation_status/"+(r.toString()?"?"+r.toString():"")),s=await fetch(i,{method:"GET",headers:this.buildHeaders()});if(!s.ok)throw new Error(`HTTP Error: ${s.status} - ${await s.text()}`)}async scorerExists(t){const e=this.buildUrl("/scorer_exists/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`);return await r.json()}async saveScorer(t){const e=this.buildUrl("/save_scorer/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`);return await r.json()}async fetchScorers(t){const e=this.buildUrl("/fetch_scorers/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`);return await r.json()}async projectsResolve(t){const e=this.buildUrl("/projects/resolve/"),r=await fetch(e,{method:"POST",headers:this.buildHeaders(),body:JSON.stringify(t)});if(!r.ok)throw new Error(`HTTP Error: ${r.status} - ${await r.text()}`);return await r.json()}}class _{static initialize(){if(!_.initialized){const t=process.env.JUDGMENT_NO_COLOR;_.useColor=!t&&process.stdout.isTTY,_.initialized=!0}}static setLevel(t){_.currentLevel=t}static setUseColor(t){_.useColor=t}static log(t,e){if(_.initialize(),t<_.currentLevel)return;let r=`${(new Date).toISOString().replace("T"," ").substring(0,19)} - judgeval - ${Object.keys(_.Level).find(e=>_.Level[e]===t)||"UNKNOWN"} - ${e}`;_.useColor&&(r=`${t===_.Level.DEBUG||t===_.Level.INFO?_.GRAY:t===_.Level.WARNING?_.YELLOW:_.RED}${r}${_.RESET}`),(t>=_.Level.ERROR?process.stderr:process.stdout).write(r+"\n")}static debug(t){_.log(_.Level.DEBUG,t)}static info(t){_.log(_.Level.INFO,t)}static warning(t){_.log(_.Level.WARNING,t)}static warn(t){_.log(_.Level.WARNING,t)}static error(t){_.log(_.Level.ERROR,t)}static critical(t){_.log(_.Level.CRITICAL,t)}}_.RESET="",_.RED="",_.YELLOW="",_.GRAY="",_.Level={DEBUG:0,INFO:1,WARNING:2,ERROR:3,CRITICAL:4},_.initialized=!1,_.currentLevel=_.Level.INFO,_.useColor=!0;const g="judgeval-tracer";class E{constructor(t,e,r,i,s,o=g){this.projectName=t,this.apiKey=e,this.organizationId=r,this.apiUrl=i,this.enableEvaluation=s,this.tracerName=o}static createDefault(t){return(new T).projectName(t).build()}static builder(){return new T}}class T{constructor(){this._apiKey=u||"",this._organizationId=h||"",this._apiUrl=l||"",this._enableEvaluation=!0,this._tracerName=g}projectName(t){return this._projectName=t,this}apiKey(t){return this._apiKey=t,this}organizationId(t){return this._organizationId=t,this}apiUrl(t){return this._apiUrl=t,this}enableEvaluation(t){return this._enableEvaluation=t,this}tracerName(t){return this._tracerName=t,this}build(){if(!this._projectName)throw new Error("Project name is required");if(!this._apiKey)throw new Error("API key is required");if(!this._organizationId)throw new Error("Organization ID is required");if(!this._apiUrl)throw new Error("API URL is required");return new E(this._projectName,this._apiKey,this._organizationId,this._apiUrl,this._enableEvaluation,this._tracerName)}}class f{getConfiguration(){return this.configuration}getProjectId(){return this.projectId}getSerializer(){return this.serializer}constructor(t,e,r){this.projectId=null,this.configuration=t,this.apiClient=e,this.serializer=r,this.projectIdPromise=this.resolveProjectId()}async resolveProjectId(){try{_.info(`Resolving project ID for project: ${this.configuration.projectName}`);const t={project_name:this.configuration.projectName},e=await this.apiClient.projectsResolve(t);return this.projectId=e.project_id?.toString()||null,this.projectId?_.info(`Successfully resolved project ID: ${this.projectId}`):_.warn(`Project ID not found for project: ${this.configuration.projectName}`),this.projectId}catch(t){return this.projectId=null,null}}static builder(){return new w}static createDefault(t){return w.builder().configuration(E.createDefault(t)).build()}static createWithConfiguration(t){return w.builder().configuration(t).build()}async getSpanExporter(){const t=await this.projectIdPromise;return t?this.createJudgmentSpanExporter(t):(_.error("Failed to resolve project "+this.configuration.projectName+", please create it first at https://app.judgmentlabs.ai/org/"+this.configuration.organizationId+"/projects. Skipping Judgment export."),new o)}setSpanKind(t){const e=a.trace.getActiveSpan();e?null!==t&&e.setAttribute(n.AttributeKeys.JUDGMENT_SPAN_KIND,t):_.warn("No active span found, skipping setSpanKind")}setAttribute(t,e,r){const i=a.trace.getActiveSpan();i?i.setAttribute(t,this.serializer(e)):_.warn("No active span found, skipping setAttribute")}setLLMSpan(){this.setSpanKind("llm")}setToolSpan(){this.setSpanKind("tool")}setGeneralSpan(){this.setSpanKind("span")}setAttributes(t){if(!t)return;const e=a.trace.getActiveSpan();if(e)for(const[r,i]of Object.entries(t))e.setAttribute(r,this.serializer(i));else _.warn("No active span found, skipping setAttributes")}setInput(t,e){this.setAttribute(n.AttributeKeys.JUDGMENT_INPUT,t)}setOutput(t,e){this.setAttribute(n.AttributeKeys.JUDGMENT_OUTPUT,t)}asyncEvaluate(t,e,r){if(!this.configuration.enableEvaluation)return;const i=a.trace.getActiveSpan();if(!i)return void _.warn("No active span found, skipping asyncEvaluate");if(!i.isRecording())return void _.warn("Active span is not recording, skipping asyncEvaluate");const s=i.spanContext(),o=s.traceId,n=s.spanId;_.info(`asyncEvaluate: project=${this.configuration.projectName}, traceId=${o}, spanId=${n}, scorer=${t.name}`);const c=this.createEvaluationRun(t,e,r,o,n);this.enqueueEvaluation(c)}asyncTraceEvaluate(t,e){if(!this.configuration.enableEvaluation)return;const r=a.trace.getActiveSpan();if(!r)return void _.warn("No active span found, skipping asyncTraceEvaluate");if(!r.isRecording())return void _.warn("Active span is not recording, skipping asyncTraceEvaluate");const i=r.spanContext(),s=i.traceId,o=i.spanId;_.info(`asyncTraceEvaluate: project=${this.configuration.projectName}, traceId=${s}, spanId=${o}, scorer=${t.name}`);try{const i=this.createTraceEvaluationRun(t,e,s,o),a=this.serializer(i);r.setAttribute(n.AttributeKeys.PENDING_TRACE_EVAL,a)}catch(t){_.error(`Failed to serialize trace evaluation: ${t instanceof Error?t.message:String(t)}`)}}createTraceEvaluationRun(t,e,r,i){const s=`async_trace_evaluate_${i||Date.now()}`,o=e||d,n=t.toTransport();return{project_name:this.configuration.projectName,eval_name:s,scorer:n,model:o,organization_id:this.configuration.organizationId,trace_id:r,trace_span_id:i}}createJudgmentSpanExporter(t){const e=this.configuration.apiUrl.endsWith("/")?`${this.configuration.apiUrl}otel/v1/traces`:`${this.configuration.apiUrl}/otel/v1/traces`;return new i(e,this.configuration.apiKey,this.configuration.organizationId,t)}createEvaluationRun(t,e,r,i,s){const o=`async_evaluate_${s||Date.now()}`,n=r||d,a=t.toTransport();return{project_name:this.configuration.projectName,eval_name:o,examples:[e],custom_scorers:[],judgment_scorers:[a],model:n,trace_id:i,trace_span_id:s}}async enqueueEvaluation(t){try{await this.apiClient.addToRunEvalQueueExamples(t),_.info(`Enqueuing evaluation run: ${t.eval_name}`)}catch(t){_.error(`Failed to enqueue evaluation run: ${t instanceof Error?t.message:String(t)}`)}}}class w{constructor(){this._serializer=JSON.stringify}static builder(){return new w}configuration(t){return this.config=t,this}apiClient(t){return this._apiClient=t,this}serializer(t){return this._serializer=t,this}build(){if(!this.config)throw new Error("Configuration is required");const t=this._apiClient||new m(this.config.apiUrl,this.config.apiKey,this.config.organizationId);return new f(this.config,t,this._serializer)}}function y(t){return{example_id:void 0,created_at:(new Date).toISOString(),name:null,...t}}var P,S;function I(){const t={score_type:"",class_name:"BaseScorer",name:"",addModel:e=>{t.model=e},successCheck:()=>{if(null!=t.error)return!1;if(null==t.score)return!1;const e=t.threshold??.5,r=t.score;return null!=e&&null!=r&&r>=e},getRequiredParams:()=>[],toTransport:()=>({score_type:t.score_type,name:t.name,threshold:t.threshold??.5,strict_mode:t.strict_mode??!1,required_params:[],kwargs:{}})};return t.name=t.class_name,!0===t.strict_mode&&(t.threshold=1),t}function v(t,e){const r=I();return r.scoreType=t,r.name=t,r.score_type=t,r.requiredParams=e,r.setThreshold=t=>{if(t<0||t>1)throw new Error(`Threshold must be between 0 and 1, got: ${t}`);r.threshold=t},r.getScoreType=()=>r.scoreType,r.setRequiredParams=t=>{r.requiredParams=t},r}!function(t){t.INPUT="input",t.ACTUAL_OUTPUT="actual_output",t.EXPECTED_OUTPUT="expected_output",t.CONTEXT="context",t.RETRIEVAL_CONTEXT="retrieval_context",t.TOOLS_CALLED="tools_called",t.EXPECTED_TOOLS="expected_tools",t.ADDITIONAL_METADATA="additional_metadata"}(P||(P={})),function(t){t.PROMPT_SCORER="Prompt Scorer",t.TRACE_PROMPT_SCORER="Trace Prompt Scorer",t.FAITHFULNESS="Faithfulness",t.ANSWER_RELEVANCY="Answer Relevancy",t.ANSWER_CORRECTNESS="Answer Correctness",t.INSTRUCTION_ADHERENCE="Instruction Adherence",t.EXECUTION_ORDER="Execution Order",t.TOOL_ORDER="Tool Order",t.CLASSIFIER="Classifier",t.TOOL_DEPENDENCY="Tool Dependency",t.CUSTOM="Custom"}(S||(S={}));class O extends Error{constructor(t,e){super(e),this.statusCode=t,this.name="JudgmentAPIError"}}async function N(t,e,r,i,s=u||"",o=h||"",n){if(!l||!s||!o)throw new Error("Missing required API credentials");const a=new m(l,s,o);return(await a.saveScorer({name:t,prompt:e,threshold:r,options:i,is_trace:n})).name}async function R(t,e=u||"",r=h||""){if(!l||!e||!r)throw new Error("Missing required API credentials");const i=new m(l,e,r),s=await i.fetchScorers({names:[t]});if(0===s.scorers.length)throw new O(404,`Scorer with name ${t} not found`);const{created_at:o,updated_at:n,...a}=s.scorers[0];return a}async function A(t,e=u||"",r=h||""){if(!l||!e||!r)throw new Error("Missing required API credentials");const i=new m(l,e,r);return(await i.scorerExists({name:t})).exists}class b{constructor(t,e,r,i,s,o,n=u||"",a=h||""){this.scoreType=t,this.name=e,this.prompt=r,this.threshold=i,this.requiredParams=s,this.options=o,this.judgmentApiKey=n,this.organizationId=a,this.score_type=t,this.class_name="BasePromptScorer",this.model=void 0,this.score=void 0,this.error=null,this.strict_mode=!1}static async get(t,e=u||"",r=h||""){const i=await R(t,e,r),s=!0===i.is_trace;if(s!==(this.prototype.scoreType===S.TRACE_PROMPT_SCORER))throw new O(400,`Scorer with name ${t} is not a ${this.name}`);return new this(s?S.TRACE_PROMPT_SCORER:S.PROMPT_SCORER,i.name,i.prompt,i.threshold,[],i.options,e,r)}static async create(t,e,r=.5,i,s=u||"",o=h||""){if(await A(t,s,o))throw new O(400,`Scorer with name ${t} already exists. Either use the existing scorer with the get() method or use a new name.`);const n=this.prototype.scoreType===S.TRACE_PROMPT_SCORER,a=n?S.TRACE_PROMPT_SCORER:S.PROMPT_SCORER;return await N(t,e,r,i,s,o,n),new this(a,t,e,r,[],i,s,o)}async updateThreshold(t){this.setThreshold(t),await this.pushPromptScorer()}async setPrompt(t){this.prompt=t,await this.pushPromptScorer()}async setOptions(t){this.options=t,await this.pushPromptScorer()}async appendToPrompt(t){this.prompt+=t,await this.pushPromptScorer()}getThreshold(){return this.threshold}getPrompt(){return this.prompt}getOptions(){return this.options?{...this.options}:null}getName(){return this.name}getConfig(){return{name:this.name,prompt:this.prompt,threshold:this.threshold,options:this.options}}async pushPromptScorer(){await N(this.name,this.prompt,this.threshold,this.options,this.judgmentApiKey,this.organizationId)}toString(){return`${this.constructor.name}(name=${this.name}, prompt=${this.prompt}, threshold=${this.threshold}, options=${JSON.stringify(this.options)})`}addModel(t){this.model=t}successCheck(){if(null!=this.error)return!1;if(null==this.score)return!1;const t=this.threshold??.5,e=this.score;return null!=t&&null!=e&&e>=t}getRequiredParams(){return Array.isArray(this.requiredParams)?[...this.requiredParams]:[]}setThreshold(t){if(t<0||t>1)throw new Error(`Threshold must be between 0 and 1, got: ${t}`);this.threshold=t}getScoreType(){return this.scoreType}setRequiredParams(t){this.requiredParams=t}toTransport(){return{score_type:this.getScoreType(),name:this.getName(),threshold:this.getThreshold(),strict_mode:this.strict_mode??!1,required_params:this.getRequiredParams(),kwargs:{prompt:this.getPrompt(),...this.getOptions()?{options:this.getOptions()}:{}}}}}class j extends b{constructor(t,e,r,i,s=[],o,n=u||"",a=h||""){super(t,e,r,i,s,o,n,a)}}class U extends b{constructor(t,e,r,i,s=[],o,n=u||"",a=h||""){super(t,e,r,i,s,o,n,a)}}const C=/^([^(]+?)=>/,D=/^[^(]*\(\s*([^)]*)\)/m,$=/,/,L=/^\s*(_?)(\S+?)\1\s*$/,x=/((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm;function z(t){const e=function(t){const e=function(t){return Function.prototype.toString.call(t)}(t).replace(x,"");return e.match(C)||e.match(D)}(t);return e&&e[1]?e[1].split($).map(t=>t.replace(L,(t,e,r)=>r).trim()).filter(t=>t.length>0):[]}module.exports=e})();
2
- //# sourceMappingURL=index.js.map