langsmith 0.3.54 → 0.3.56-rc.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AI_SDK_TOOL_OPERATIONS = exports.AI_SDK_LLM_OPERATIONS = exports.GEN_AI_CHOICE = exports.GEN_AI_ASSISTANT_MESSAGE = exports.GEN_AI_USER_MESSAGE = exports.GEN_AI_SYSTEM_MESSAGE = exports.LANGSMITH_IS_ROOT = exports.LANGSMITH_TRACEABLE = exports.LANGSMITH_REFERENCE_EXAMPLE_ID = exports.LANGSMITH_USAGE_METADATA = exports.LANGSMITH_PARENT_RUN_ID = exports.LANGSMITH_DOTTED_ORDER = exports.LANGSMITH_TRACE_ID = exports.LANGSMITH_RUN_ID = exports.LANGSMITH_REQUEST_HEADERS = exports.LANGSMITH_REQUEST_STREAMING = exports.LANGSMITH_RUNTIME = exports.LANGSMITH_TAGS = exports.LANGSMITH_METADATA = exports.LANGSMITH_NAME = exports.LANGSMITH_RUN_TYPE = exports.LANGSMITH_SESSION_NAME = exports.LANGSMITH_SESSION_ID = exports.GEN_AI_USAGE_OUTPUT_TOKEN_DETAILS = exports.GEN_AI_USAGE_INPUT_TOKEN_DETAILS = exports.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = exports.GEN_AI_RESPONSE_SERVICE_TIER = exports.GEN_AI_RESPONSE_ID = exports.GEN_AI_SERIALIZED_DOC = exports.GEN_AI_SERIALIZED_SIGNATURE = exports.GEN_AI_SERIALIZED_NAME = exports.GEN_AI_REQUEST_EXTRA_BODY = exports.GEN_AI_REQUEST_EXTRA_QUERY = exports.GENAI_COMPLETION = exports.GENAI_PROMPT = exports.GEN_AI_RESPONSE_FINISH_REASONS = exports.GEN_AI_REQUEST_PRESENCE_PENALTY = exports.GEN_AI_REQUEST_FREQUENCY_PENALTY = exports.GEN_AI_REQUEST_TOP_P = exports.GEN_AI_REQUEST_TEMPERATURE = exports.GEN_AI_REQUEST_MAX_TOKENS = exports.GEN_AI_USAGE_TOTAL_TOKENS = exports.GEN_AI_USAGE_OUTPUT_TOKENS = exports.GEN_AI_USAGE_INPUT_TOKENS = exports.GEN_AI_RESPONSE_MODEL = exports.GEN_AI_REQUEST_MODEL = exports.GEN_AI_SYSTEM = exports.GEN_AI_OPERATION_NAME = void 0;
3
+ exports.AI_SDK_TOOL_OPERATIONS = exports.AI_SDK_LLM_OPERATIONS = exports.GEN_AI_CHOICE = exports.GEN_AI_ASSISTANT_MESSAGE = exports.GEN_AI_USER_MESSAGE = exports.GEN_AI_SYSTEM_MESSAGE = exports.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = exports.LANGSMITH_IS_ROOT = exports.LANGSMITH_TRACEABLE = exports.LANGSMITH_REFERENCE_EXAMPLE_ID = exports.LANGSMITH_USAGE_METADATA = exports.LANGSMITH_PARENT_RUN_ID = exports.LANGSMITH_DOTTED_ORDER = exports.LANGSMITH_TRACE_ID = exports.LANGSMITH_RUN_ID = exports.LANGSMITH_REQUEST_HEADERS = exports.LANGSMITH_REQUEST_STREAMING = exports.LANGSMITH_RUNTIME = exports.LANGSMITH_TAGS = exports.LANGSMITH_METADATA = exports.LANGSMITH_NAME = exports.LANGSMITH_RUN_TYPE = exports.LANGSMITH_SESSION_NAME = exports.LANGSMITH_SESSION_ID = exports.GEN_AI_USAGE_OUTPUT_TOKEN_DETAILS = exports.GEN_AI_USAGE_INPUT_TOKEN_DETAILS = exports.GEN_AI_RESPONSE_SYSTEM_FINGERPRINT = exports.GEN_AI_RESPONSE_SERVICE_TIER = exports.GEN_AI_RESPONSE_ID = exports.GEN_AI_SERIALIZED_DOC = exports.GEN_AI_SERIALIZED_SIGNATURE = exports.GEN_AI_SERIALIZED_NAME = exports.GEN_AI_REQUEST_EXTRA_BODY = exports.GEN_AI_REQUEST_EXTRA_QUERY = exports.GENAI_COMPLETION = exports.GENAI_PROMPT = exports.GEN_AI_RESPONSE_FINISH_REASONS = exports.GEN_AI_REQUEST_PRESENCE_PENALTY = exports.GEN_AI_REQUEST_FREQUENCY_PENALTY = exports.GEN_AI_REQUEST_TOP_P = exports.GEN_AI_REQUEST_TEMPERATURE = exports.GEN_AI_REQUEST_MAX_TOKENS = exports.GEN_AI_USAGE_TOTAL_TOKENS = exports.GEN_AI_USAGE_OUTPUT_TOKENS = exports.GEN_AI_USAGE_INPUT_TOKENS = exports.GEN_AI_RESPONSE_MODEL = exports.GEN_AI_REQUEST_MODEL = exports.GEN_AI_SYSTEM = exports.GEN_AI_OPERATION_NAME = void 0;
4
4
  // OpenTelemetry GenAI semantic convention attribute names
5
5
  exports.GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
6
6
  exports.GEN_AI_SYSTEM = "gen_ai.system";
@@ -45,6 +45,7 @@ exports.LANGSMITH_USAGE_METADATA = "langsmith.usage_metadata";
45
45
  exports.LANGSMITH_REFERENCE_EXAMPLE_ID = "langsmith.reference_example_id";
46
46
  exports.LANGSMITH_TRACEABLE = "langsmith.traceable";
47
47
  exports.LANGSMITH_IS_ROOT = "langsmith.is_root";
48
+ exports.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = "langsmith.traceable_parent_otel_span_id";
48
49
  // GenAI event names
49
50
  exports.GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message";
50
51
  exports.GEN_AI_USER_MESSAGE = "gen_ai.user.message";
@@ -40,6 +40,7 @@ export declare const LANGSMITH_USAGE_METADATA = "langsmith.usage_metadata";
40
40
  export declare const LANGSMITH_REFERENCE_EXAMPLE_ID = "langsmith.reference_example_id";
41
41
  export declare const LANGSMITH_TRACEABLE = "langsmith.traceable";
42
42
  export declare const LANGSMITH_IS_ROOT = "langsmith.is_root";
43
+ export declare const LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = "langsmith.traceable_parent_otel_span_id";
43
44
  export declare const GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message";
44
45
  export declare const GEN_AI_USER_MESSAGE = "gen_ai.user.message";
45
46
  export declare const GEN_AI_ASSISTANT_MESSAGE = "gen_ai.assistant.message";
@@ -42,6 +42,7 @@ export const LANGSMITH_USAGE_METADATA = "langsmith.usage_metadata";
42
42
  export const LANGSMITH_REFERENCE_EXAMPLE_ID = "langsmith.reference_example_id";
43
43
  export const LANGSMITH_TRACEABLE = "langsmith.traceable";
44
44
  export const LANGSMITH_IS_ROOT = "langsmith.is_root";
45
+ export const LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID = "langsmith.traceable_parent_otel_span_id";
45
46
  // GenAI event names
46
47
  export const GEN_AI_SYSTEM_MESSAGE = "gen_ai.system.message";
47
48
  export const GEN_AI_USER_MESSAGE = "gen_ai.user.message";
@@ -59,6 +59,8 @@ class LangSmithOTLPSpanProcessor extends sdk_trace_base_1.BatchSpanProcessor {
59
59
  else {
60
60
  span.attributes[constants_js_1.LANGSMITH_PARENT_RUN_ID] =
61
61
  (0, utils_js_1.getUuidFromOtelSpanId)(traceableParentId);
62
+ span.attributes[constants_js_1.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID] =
63
+ traceableParentId;
62
64
  }
63
65
  if (isTraceable) {
64
66
  super.onStart(span, parentContext);
@@ -1,5 +1,5 @@
1
1
  import { BatchSpanProcessor, } from "@opentelemetry/sdk-trace-base";
2
- import { LANGSMITH_IS_ROOT, LANGSMITH_PARENT_RUN_ID, LANGSMITH_TRACEABLE, } from "./constants.js";
2
+ import { LANGSMITH_IS_ROOT, LANGSMITH_PARENT_RUN_ID, LANGSMITH_TRACEABLE, LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID, } from "./constants.js";
3
3
  import { getUuidFromOtelSpanId } from "./utils.js";
4
4
  import { RunTree } from "../../run_trees.js";
5
5
  export function isTraceableSpan(span) {
@@ -55,6 +55,8 @@ export class LangSmithOTLPSpanProcessor extends BatchSpanProcessor {
55
55
  else {
56
56
  span.attributes[LANGSMITH_PARENT_RUN_ID] =
57
57
  getUuidFromOtelSpanId(traceableParentId);
58
+ span.attributes[LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID] =
59
+ traceableParentId;
58
60
  }
59
61
  if (isTraceable) {
60
62
  super.onStart(span, parentContext);
package/dist/index.cjs CHANGED
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
10
10
  var project_js_1 = require("./utils/project.cjs");
11
11
  Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
12
12
  // Update using yarn bump-version
13
- exports.__version__ = "0.3.54";
13
+ exports.__version__ = "0.3.56-rc.0";
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
- export declare const __version__ = "0.3.54";
6
+ export declare const __version__ = "0.3.56-rc.0";
package/dist/index.js CHANGED
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export { getDefaultProjectName } from "./utils/project.js";
5
5
  // Update using yarn bump-version
6
- export const __version__ = "0.3.54";
6
+ export const __version__ = "0.3.56-rc.0";
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.wrapEvaluator = exports.logOutputs = exports.logFeedback = exports.expect = exports.describe = exports.it = exports.test = void 0;
19
+ exports.wrapJest = exports.wrapEvaluator = exports.logOutputs = exports.logFeedback = exports.expect = exports.describe = exports.it = exports.test = void 0;
20
20
  const globals_1 = require("@jest/globals");
21
21
  const matchers_js_1 = require("../utils/jestlike/matchers.cjs");
22
22
  const evaluatedBy_js_1 = require("../utils/jestlike/vendor/evaluatedBy.cjs");
@@ -30,13 +30,41 @@ globals_1.expect.extend({
30
30
  toBeAbsoluteCloseTo: matchers_js_1.toBeAbsoluteCloseTo,
31
31
  toBeSemanticCloseTo: matchers_js_1.toBeSemanticCloseTo,
32
32
  });
33
- const { test, it, describe, expect } = (0, index_js_2.generateWrapperFromJestlikeMethods)({
33
+ /**
34
+ * Dynamically wrap original Jest imports.
35
+ *
36
+ * This may be necessary to ensure you are wrapping the correct
37
+ * Jest version if you are using a monorepo whose workspaces
38
+ * use multiple versions of Jest.
39
+ *
40
+ * @param originalJestMethods - The original Jest imports to wrap.
41
+ * @returns The wrapped Jest imports.
42
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
43
+ * for more details.
44
+ */
45
+ const wrapJest = (originalJestMethods) => {
46
+ const wrappedMethods = (0, index_js_2.generateWrapperFromJestlikeMethods)({
47
+ expect: originalJestMethods.expect,
48
+ test: originalJestMethods.test,
49
+ describe: originalJestMethods.describe,
50
+ beforeAll: originalJestMethods.beforeAll,
51
+ afterAll: originalJestMethods.afterAll,
52
+ }, process?.versions?.bun !== undefined ? "bun" : "jest");
53
+ return {
54
+ ...originalJestMethods,
55
+ ...wrappedMethods,
56
+ };
57
+ };
58
+ exports.wrapJest = wrapJest;
59
+ const { test, it, describe, expect } = wrapJest({
34
60
  expect: globals_1.expect,
35
61
  test: globals_1.test,
36
62
  describe: globals_1.describe,
37
63
  beforeAll: globals_1.beforeAll,
38
64
  afterAll: globals_1.afterAll,
39
- }, process?.versions?.bun !== undefined ? "bun" : "jest");
65
+ beforeEach: globals_1.beforeEach,
66
+ afterEach: globals_1.afterEach,
67
+ });
40
68
  exports.test = test;
41
69
  exports.it = it;
42
70
  exports.describe = describe;
@@ -1,4 +1,5 @@
1
- import { type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
1
+ import { expect as jestExpect, test as jestTest, describe as jestDescribe, beforeAll as jestBeforeAll, afterAll as jestAfterAll, beforeEach as jestBeforeEach, afterEach as jestAfterEach } from "@jest/globals";
2
+ import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
2
3
  import type { SimpleEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
3
4
  import { wrapEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
4
5
  import { logFeedback, logOutputs } from "../utils/jestlike/index.js";
@@ -57,6 +58,185 @@ declare global {
57
58
  }
58
59
  }
59
60
  }
61
+ /**
62
+ * Dynamically wrap original Jest imports.
63
+ *
64
+ * This may be necessary to ensure you are wrapping the correct
65
+ * Jest version if you are using a monorepo whose workspaces
66
+ * use multiple versions of Jest.
67
+ *
68
+ * @param originalJestMethods - The original Jest imports to wrap.
69
+ * @returns The wrapped Jest imports.
70
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
71
+ * for more details.
72
+ */
73
+ declare const wrapJest: (originalJestMethods: {
74
+ expect: typeof jestExpect;
75
+ test: typeof jestTest;
76
+ describe: typeof jestDescribe;
77
+ beforeAll: typeof jestBeforeAll;
78
+ afterAll: typeof jestAfterAll;
79
+ beforeEach: typeof jestBeforeEach;
80
+ afterEach: typeof jestAfterEach;
81
+ }) => {
82
+ test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
83
+ inputs: I;
84
+ referenceOutputs?: O;
85
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
86
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
87
+ inputs: I;
88
+ referenceOutputs?: O;
89
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
90
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
91
+ inputs: I;
92
+ referenceOutputs?: O;
93
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
94
+ inputs: I;
95
+ referenceOutputs?: O;
96
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
97
+ };
98
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
99
+ inputs: I;
100
+ referenceOutputs?: O;
101
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
102
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
103
+ inputs: I;
104
+ referenceOutputs?: O;
105
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
106
+ inputs: I;
107
+ referenceOutputs?: O;
108
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
109
+ };
110
+ concurrent: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
111
+ inputs: I;
112
+ referenceOutputs?: O;
113
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
114
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
115
+ inputs: I;
116
+ referenceOutputs?: O;
117
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
118
+ inputs: I;
119
+ referenceOutputs?: O;
120
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
121
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
122
+ inputs: I;
123
+ referenceOutputs?: O;
124
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
125
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
126
+ inputs: I;
127
+ referenceOutputs?: O;
128
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
129
+ inputs: I;
130
+ referenceOutputs?: O;
131
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
132
+ };
133
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
134
+ inputs: I;
135
+ referenceOutputs?: O;
136
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
137
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
138
+ inputs: I;
139
+ referenceOutputs?: O;
140
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
141
+ inputs: I;
142
+ referenceOutputs?: O;
143
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
144
+ };
145
+ };
146
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
147
+ inputs: I;
148
+ referenceOutputs?: O;
149
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
150
+ inputs: I;
151
+ referenceOutputs?: O;
152
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
153
+ };
154
+ it: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
155
+ inputs: I;
156
+ referenceOutputs?: O;
157
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
158
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
159
+ inputs: I;
160
+ referenceOutputs?: O;
161
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
162
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
163
+ inputs: I;
164
+ referenceOutputs?: O;
165
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
166
+ inputs: I;
167
+ referenceOutputs?: O;
168
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
169
+ };
170
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
171
+ inputs: I;
172
+ referenceOutputs?: O;
173
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
174
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
175
+ inputs: I;
176
+ referenceOutputs?: O;
177
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
178
+ inputs: I;
179
+ referenceOutputs?: O;
180
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
181
+ };
182
+ concurrent: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
183
+ inputs: I;
184
+ referenceOutputs?: O;
185
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
186
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
187
+ inputs: I;
188
+ referenceOutputs?: O;
189
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
190
+ inputs: I;
191
+ referenceOutputs?: O;
192
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
193
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
194
+ inputs: I;
195
+ referenceOutputs?: O;
196
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
197
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
198
+ inputs: I;
199
+ referenceOutputs?: O;
200
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
201
+ inputs: I;
202
+ referenceOutputs?: O;
203
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
204
+ };
205
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
206
+ inputs: I;
207
+ referenceOutputs?: O;
208
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
209
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
210
+ inputs: I;
211
+ referenceOutputs?: O;
212
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
213
+ inputs: I;
214
+ referenceOutputs?: O;
215
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
216
+ };
217
+ };
218
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
219
+ inputs: I;
220
+ referenceOutputs?: O;
221
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
222
+ inputs: I;
223
+ referenceOutputs?: O;
224
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
225
+ };
226
+ describe: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper & {
227
+ only: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
228
+ skip: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
229
+ concurrent: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
230
+ };
231
+ expect: jest.Expect;
232
+ toBeRelativeCloseTo: typeof toBeRelativeCloseTo;
233
+ toBeAbsoluteCloseTo: typeof toBeAbsoluteCloseTo;
234
+ toBeSemanticCloseTo: typeof toBeSemanticCloseTo;
235
+ beforeAll: typeof jestBeforeAll;
236
+ afterAll: typeof jestAfterAll;
237
+ beforeEach: typeof jestBeforeEach;
238
+ afterEach: typeof jestAfterEach;
239
+ };
60
240
  declare const test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
61
241
  inputs: I;
62
242
  referenceOutputs?: O;
@@ -505,5 +685,5 @@ logOutputs,
505
685
  * });
506
686
  * ```
507
687
  */
508
- wrapEvaluator, type LangSmithJestlikeWrapperParams, };
688
+ wrapEvaluator, type LangSmithJestlikeWrapperParams, wrapJest, };
509
689
  export * from "../utils/jestlike/types.js";
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { expect as jestExpect, test as jestTest, describe as jestDescribe, beforeAll as jestBeforeAll, afterAll as jestAfterAll, } from "@jest/globals";
3
+ import { expect as jestExpect, test as jestTest, describe as jestDescribe, beforeAll as jestBeforeAll, afterAll as jestAfterAll, beforeEach as jestBeforeEach, afterEach as jestAfterEach, } from "@jest/globals";
4
4
  import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, } from "../utils/jestlike/matchers.js";
5
5
  import { wrapEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
6
6
  import { logFeedback, logOutputs } from "../utils/jestlike/index.js";
@@ -10,13 +10,40 @@ jestExpect.extend({
10
10
  toBeAbsoluteCloseTo,
11
11
  toBeSemanticCloseTo,
12
12
  });
13
- const { test, it, describe, expect } = generateWrapperFromJestlikeMethods({
13
+ /**
14
+ * Dynamically wrap original Jest imports.
15
+ *
16
+ * This may be necessary to ensure you are wrapping the correct
17
+ * Jest version if you are using a monorepo whose workspaces
18
+ * use multiple versions of Jest.
19
+ *
20
+ * @param originalJestMethods - The original Jest imports to wrap.
21
+ * @returns The wrapped Jest imports.
22
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
23
+ * for more details.
24
+ */
25
+ const wrapJest = (originalJestMethods) => {
26
+ const wrappedMethods = generateWrapperFromJestlikeMethods({
27
+ expect: originalJestMethods.expect,
28
+ test: originalJestMethods.test,
29
+ describe: originalJestMethods.describe,
30
+ beforeAll: originalJestMethods.beforeAll,
31
+ afterAll: originalJestMethods.afterAll,
32
+ }, process?.versions?.bun !== undefined ? "bun" : "jest");
33
+ return {
34
+ ...originalJestMethods,
35
+ ...wrappedMethods,
36
+ };
37
+ };
38
+ const { test, it, describe, expect } = wrapJest({
14
39
  expect: jestExpect,
15
40
  test: jestTest,
16
41
  describe: jestDescribe,
17
42
  beforeAll: jestBeforeAll,
18
43
  afterAll: jestAfterAll,
19
- }, process?.versions?.bun !== undefined ? "bun" : "jest");
44
+ beforeEach: jestBeforeEach,
45
+ afterEach: jestAfterEach,
46
+ });
20
47
  export {
21
48
  /**
22
49
  * Defines a LangSmith test case within a suite. Takes an additional `lsParams`
@@ -318,5 +345,5 @@ logOutputs,
318
345
  * });
319
346
  * ```
320
347
  */
321
- wrapEvaluator, };
348
+ wrapEvaluator, wrapJest, };
322
349
  export * from "../utils/jestlike/types.js";
package/dist/vercel.cjs CHANGED
@@ -7,6 +7,7 @@ const uuid_1 = require("uuid");
7
7
  const traceable_js_1 = require("./singletons/traceable.cjs");
8
8
  const env_js_1 = require("./utils/env.cjs");
9
9
  const env_js_2 = require("./env.cjs");
10
+ const constants_js_1 = require("./experimental/otel/constants.cjs");
10
11
  // Attempt to convert CoreMessage to a LangChain-compatible format
11
12
  // which allows us to render messages more nicely in LangSmith
12
13
  function convertCoreToSmith(message) {
@@ -692,6 +693,14 @@ class AISDKExporter {
692
693
  const { traceId, spanId } = span.spanContext();
693
694
  const runId = (0, uuid_1.v5)(spanId, RUN_ID_NAMESPACE);
694
695
  let parentId = getParentSpanId(span);
696
+ if (constants_js_1.LANGSMITH_IS_ROOT in span.attributes) {
697
+ parentId = undefined;
698
+ }
699
+ else if (constants_js_1.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID in span.attributes &&
700
+ typeof span.attributes[constants_js_1.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID] ===
701
+ "string") {
702
+ parentId = span.attributes[constants_js_1.LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID];
703
+ }
695
704
  let parentRunId = parentId
696
705
  ? (0, uuid_1.v5)(parentId, RUN_ID_NAMESPACE)
697
706
  : undefined;
package/dist/vercel.js CHANGED
@@ -4,6 +4,7 @@ import { v5 as uuid5 } from "uuid";
4
4
  import { getCurrentRunTree } from "./singletons/traceable.js";
5
5
  import { getLangSmithEnvironmentVariable, getEnvironmentVariable, } from "./utils/env.js";
6
6
  import { isTracingEnabled } from "./env.js";
7
+ import { LANGSMITH_IS_ROOT, LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID, } from "./experimental/otel/constants.js";
7
8
  // Attempt to convert CoreMessage to a LangChain-compatible format
8
9
  // which allows us to render messages more nicely in LangSmith
9
10
  function convertCoreToSmith(message) {
@@ -688,6 +689,14 @@ export class AISDKExporter {
688
689
  const { traceId, spanId } = span.spanContext();
689
690
  const runId = uuid5(spanId, RUN_ID_NAMESPACE);
690
691
  let parentId = getParentSpanId(span);
692
+ if (LANGSMITH_IS_ROOT in span.attributes) {
693
+ parentId = undefined;
694
+ }
695
+ else if (LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID in span.attributes &&
696
+ typeof span.attributes[LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID] ===
697
+ "string") {
698
+ parentId = span.attributes[LANGSMITH_TRACEABLE_PARENT_OTEL_SPAN_ID];
699
+ }
691
700
  let parentRunId = parentId
692
701
  ? uuid5(parentId, RUN_ID_NAMESPACE)
693
702
  : undefined;
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.wrapEvaluator = exports.logOutputs = exports.logFeedback = exports.expect = exports.describe = exports.it = exports.test = void 0;
19
+ exports.wrapVitest = exports.wrapEvaluator = exports.logOutputs = exports.logFeedback = exports.expect = exports.describe = exports.it = exports.test = void 0;
20
20
  const vitest_1 = require("vitest");
21
21
  const matchers_js_1 = require("../utils/jestlike/matchers.cjs");
22
22
  const evaluatedBy_js_1 = require("../utils/jestlike/vendor/evaluatedBy.cjs");
@@ -30,13 +30,41 @@ vitest_1.expect.extend({
30
30
  toBeAbsoluteCloseTo: matchers_js_1.toBeAbsoluteCloseTo,
31
31
  toBeSemanticCloseTo: matchers_js_1.toBeSemanticCloseTo,
32
32
  });
33
- const { test, it, describe, expect } = (0, index_js_2.generateWrapperFromJestlikeMethods)({
33
+ /**
34
+ * Dynamically wrap original Vitest imports.
35
+ *
36
+ * This may be necessary to ensure you are wrapping the correct
37
+ * Vitest version if you are using a monorepo whose workspaces
38
+ * use multiple versions of Vitest.
39
+ *
40
+ * @param originalVitestMethods - The original Vitest imports to wrap.
41
+ * @returns The wrapped Vitest imports.
42
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
43
+ * for more details.
44
+ */
45
+ const wrapVitest = (originalVitestMethods) => {
46
+ const wrappedMethods = (0, index_js_2.generateWrapperFromJestlikeMethods)({
47
+ expect: originalVitestMethods.expect,
48
+ test: originalVitestMethods.test,
49
+ describe: originalVitestMethods.describe,
50
+ beforeAll: originalVitestMethods.beforeAll,
51
+ afterAll: originalVitestMethods.afterAll,
52
+ }, "vitest");
53
+ return {
54
+ ...originalVitestMethods,
55
+ ...wrappedMethods,
56
+ };
57
+ };
58
+ exports.wrapVitest = wrapVitest;
59
+ const { test, it, describe, expect } = wrapVitest({
34
60
  expect: vitest_1.expect,
35
61
  test: vitest_1.test,
36
62
  describe: vitest_1.describe,
37
63
  beforeAll: vitest_1.beforeAll,
38
64
  afterAll: vitest_1.afterAll,
39
- }, "vitest");
65
+ beforeEach: vitest_1.beforeEach,
66
+ afterEach: vitest_1.afterEach,
67
+ });
40
68
  exports.test = test;
41
69
  exports.it = it;
42
70
  exports.describe = describe;
@@ -1,5 +1,5 @@
1
- import { Assertion } from "vitest";
2
- import { type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
1
+ import { expect as vitestExpect, test as vitestTest, describe as vitestDescribe, beforeAll as vitestBeforeAll, afterAll as vitestAfterAll, beforeEach as vitestBeforeEach, afterEach as vitestAfterEach, Assertion } from "vitest";
2
+ import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
3
3
  import type { SimpleEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
4
4
  import { wrapEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
5
5
  import { logFeedback, logOutputs } from "../utils/jestlike/index.js";
@@ -55,6 +55,185 @@ declare module "vitest" {
55
55
  interface AsymmetricMatchersContaining extends CustomMatchers {
56
56
  }
57
57
  }
58
+ /**
59
+ * Dynamically wrap original Vitest imports.
60
+ *
61
+ * This may be necessary to ensure you are wrapping the correct
62
+ * Vitest version if you are using a monorepo whose workspaces
63
+ * use multiple versions of Vitest.
64
+ *
65
+ * @param originalVitestMethods - The original Vitest imports to wrap.
66
+ * @returns The wrapped Vitest imports.
67
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
68
+ * for more details.
69
+ */
70
+ declare const wrapVitest: (originalVitestMethods: {
71
+ expect: typeof vitestExpect;
72
+ test: typeof vitestTest;
73
+ describe: typeof vitestDescribe;
74
+ beforeAll: typeof vitestBeforeAll;
75
+ afterAll: typeof vitestAfterAll;
76
+ beforeEach: typeof vitestBeforeEach;
77
+ afterEach: typeof vitestAfterEach;
78
+ }) => {
79
+ test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
80
+ inputs: I;
81
+ referenceOutputs?: O;
82
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
83
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
84
+ inputs: I;
85
+ referenceOutputs?: O;
86
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
87
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
88
+ inputs: I;
89
+ referenceOutputs?: O;
90
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
91
+ inputs: I;
92
+ referenceOutputs?: O;
93
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
94
+ };
95
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
96
+ inputs: I;
97
+ referenceOutputs?: O;
98
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
99
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
100
+ inputs: I;
101
+ referenceOutputs?: O;
102
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
103
+ inputs: I;
104
+ referenceOutputs?: O;
105
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
106
+ };
107
+ concurrent: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
108
+ inputs: I;
109
+ referenceOutputs?: O;
110
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
111
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
112
+ inputs: I;
113
+ referenceOutputs?: O;
114
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
115
+ inputs: I;
116
+ referenceOutputs?: O;
117
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
118
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
119
+ inputs: I;
120
+ referenceOutputs?: O;
121
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
122
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
123
+ inputs: I;
124
+ referenceOutputs?: O;
125
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
126
+ inputs: I;
127
+ referenceOutputs?: O;
128
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
129
+ };
130
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
131
+ inputs: I;
132
+ referenceOutputs?: O;
133
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
134
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
135
+ inputs: I;
136
+ referenceOutputs?: O;
137
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
138
+ inputs: I;
139
+ referenceOutputs?: O;
140
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
141
+ };
142
+ };
143
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
144
+ inputs: I;
145
+ referenceOutputs?: O;
146
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
147
+ inputs: I;
148
+ referenceOutputs?: O;
149
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
150
+ };
151
+ it: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
152
+ inputs: I;
153
+ referenceOutputs?: O;
154
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
155
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
156
+ inputs: I;
157
+ referenceOutputs?: O;
158
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
159
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
160
+ inputs: I;
161
+ referenceOutputs?: O;
162
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
163
+ inputs: I;
164
+ referenceOutputs?: O;
165
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
166
+ };
167
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
168
+ inputs: I;
169
+ referenceOutputs?: O;
170
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
171
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
172
+ inputs: I;
173
+ referenceOutputs?: O;
174
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
175
+ inputs: I;
176
+ referenceOutputs?: O;
177
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
178
+ };
179
+ concurrent: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
180
+ inputs: I;
181
+ referenceOutputs?: O;
182
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
183
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
184
+ inputs: I;
185
+ referenceOutputs?: O;
186
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
187
+ inputs: I;
188
+ referenceOutputs?: O;
189
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
190
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
191
+ inputs: I;
192
+ referenceOutputs?: O;
193
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
194
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
195
+ inputs: I;
196
+ referenceOutputs?: O;
197
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
198
+ inputs: I;
199
+ referenceOutputs?: O;
200
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
201
+ };
202
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
203
+ inputs: I;
204
+ referenceOutputs?: O;
205
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
206
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
207
+ inputs: I;
208
+ referenceOutputs?: O;
209
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
210
+ inputs: I;
211
+ referenceOutputs?: O;
212
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
213
+ };
214
+ };
215
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
216
+ inputs: I;
217
+ referenceOutputs?: O;
218
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
219
+ inputs: I;
220
+ referenceOutputs?: O;
221
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
222
+ };
223
+ describe: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper & {
224
+ only: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
225
+ skip: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
226
+ concurrent: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
227
+ };
228
+ expect: jest.Expect;
229
+ toBeRelativeCloseTo: typeof toBeRelativeCloseTo;
230
+ toBeAbsoluteCloseTo: typeof toBeAbsoluteCloseTo;
231
+ toBeSemanticCloseTo: typeof toBeSemanticCloseTo;
232
+ beforeAll: typeof vitestBeforeAll;
233
+ afterAll: typeof vitestAfterAll;
234
+ beforeEach: typeof vitestBeforeEach;
235
+ afterEach: typeof vitestAfterEach;
236
+ };
58
237
  declare const test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
59
238
  inputs: I;
60
239
  referenceOutputs?: O;
@@ -503,5 +682,5 @@ logOutputs,
503
682
  * });
504
683
  * ```
505
684
  */
506
- wrapEvaluator, type LangSmithJestlikeWrapperParams, };
685
+ wrapEvaluator, type LangSmithJestlikeWrapperParams, wrapVitest, };
507
686
  export * from "../utils/jestlike/types.js";
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { expect as vitestExpect, test as vitestTest, describe as vitestDescribe, beforeAll as vitestBeforeAll, afterAll as vitestAfterAll, } from "vitest";
3
+ import { expect as vitestExpect, test as vitestTest, describe as vitestDescribe, beforeAll as vitestBeforeAll, afterAll as vitestAfterAll, beforeEach as vitestBeforeEach, afterEach as vitestAfterEach, } from "vitest";
4
4
  import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, } from "../utils/jestlike/matchers.js";
5
5
  import { wrapEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
6
6
  import { logFeedback, logOutputs } from "../utils/jestlike/index.js";
@@ -10,13 +10,40 @@ vitestExpect.extend({
10
10
  toBeAbsoluteCloseTo,
11
11
  toBeSemanticCloseTo,
12
12
  });
13
- const { test, it, describe, expect } = generateWrapperFromJestlikeMethods({
13
+ /**
14
+ * Dynamically wrap original Vitest imports.
15
+ *
16
+ * This may be necessary to ensure you are wrapping the correct
17
+ * Vitest version if you are using a monorepo whose workspaces
18
+ * use multiple versions of Vitest.
19
+ *
20
+ * @param originalVitestMethods - The original Vitest imports to wrap.
21
+ * @returns The wrapped Vitest imports.
22
+ * See https://docs.smith.langchain.com/evaluation/how_to_guides/vitest_jest
23
+ * for more details.
24
+ */
25
+ const wrapVitest = (originalVitestMethods) => {
26
+ const wrappedMethods = generateWrapperFromJestlikeMethods({
27
+ expect: originalVitestMethods.expect,
28
+ test: originalVitestMethods.test,
29
+ describe: originalVitestMethods.describe,
30
+ beforeAll: originalVitestMethods.beforeAll,
31
+ afterAll: originalVitestMethods.afterAll,
32
+ }, "vitest");
33
+ return {
34
+ ...originalVitestMethods,
35
+ ...wrappedMethods,
36
+ };
37
+ };
38
+ const { test, it, describe, expect } = wrapVitest({
14
39
  expect: vitestExpect,
15
40
  test: vitestTest,
16
41
  describe: vitestDescribe,
17
42
  beforeAll: vitestBeforeAll,
18
43
  afterAll: vitestAfterAll,
19
- }, "vitest");
44
+ beforeEach: vitestBeforeEach,
45
+ afterEach: vitestAfterEach,
46
+ });
20
47
  export {
21
48
  /**
22
49
  * Defines a LangSmith test case within a suite. Takes an additional `lsParams`
@@ -318,5 +345,5 @@ logOutputs,
318
345
  * });
319
346
  * ```
320
347
  */
321
- wrapEvaluator, };
348
+ wrapEvaluator, wrapVitest, };
322
349
  export * from "../utils/jestlike/types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.54",
3
+ "version": "0.3.56-rc.0",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [