langsmith 0.2.15 → 0.2.16-rc.1

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 (52) hide show
  1. package/dist/client.d.ts +9 -8
  2. package/dist/index.cjs +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/jest/index.cjs +45 -0
  6. package/dist/jest/index.d.ts +99 -0
  7. package/dist/jest/index.js +20 -0
  8. package/dist/jest/reporter.cjs +7 -0
  9. package/dist/jest/reporter.d.ts +2 -0
  10. package/dist/jest/reporter.js +2 -0
  11. package/dist/run_trees.cjs +1 -1
  12. package/dist/run_trees.d.ts +1 -1
  13. package/dist/run_trees.js +2 -2
  14. package/dist/singletons/traceable.cjs +1 -1
  15. package/dist/singletons/traceable.js +1 -1
  16. package/dist/utils/jestlike/globals.cjs +38 -0
  17. package/dist/utils/jestlike/globals.d.ts +33 -0
  18. package/dist/utils/jestlike/globals.js +33 -0
  19. package/dist/utils/jestlike/index.cjs +457 -0
  20. package/dist/utils/jestlike/index.d.ts +89 -0
  21. package/dist/utils/jestlike/index.js +425 -0
  22. package/dist/utils/jestlike/matchers.cjs +104 -0
  23. package/dist/utils/jestlike/matchers.d.ts +27 -0
  24. package/dist/utils/jestlike/matchers.js +98 -0
  25. package/dist/utils/jestlike/reporter.cjs +198 -0
  26. package/dist/utils/jestlike/reporter.d.ts +5 -0
  27. package/dist/utils/jestlike/reporter.js +170 -0
  28. package/dist/utils/jestlike/types.cjs +2 -0
  29. package/dist/utils/jestlike/types.d.ts +13 -0
  30. package/dist/utils/jestlike/types.js +1 -0
  31. package/dist/utils/jestlike/vendor/chain.cjs +93 -0
  32. package/dist/utils/jestlike/vendor/chain.d.ts +2 -0
  33. package/dist/utils/jestlike/vendor/chain.js +89 -0
  34. package/dist/utils/jestlike/vendor/evaluatedBy.cjs +55 -0
  35. package/dist/utils/jestlike/vendor/evaluatedBy.d.ts +8 -0
  36. package/dist/utils/jestlike/vendor/evaluatedBy.js +51 -0
  37. package/dist/vitest/index.cjs +45 -0
  38. package/dist/vitest/index.d.ts +97 -0
  39. package/dist/vitest/index.js +20 -0
  40. package/jest/reporter.cjs +1 -0
  41. package/jest/reporter.d.cts +1 -0
  42. package/jest/reporter.d.ts +1 -0
  43. package/jest/reporter.js +1 -0
  44. package/jest.cjs +1 -0
  45. package/jest.d.cts +1 -0
  46. package/jest.d.ts +1 -0
  47. package/jest.js +1 -0
  48. package/package.json +44 -2
  49. package/vitest.cjs +1 -0
  50. package/vitest.d.cts +1 -0
  51. package/vitest.d.ts +1 -0
  52. package/vitest.js +1 -0
package/dist/client.d.ts CHANGED
@@ -164,6 +164,14 @@ export type CreateExampleOptions = {
164
164
  /** The ID of the source run associated with this example. */
165
165
  sourceRunId?: string;
166
166
  };
167
+ export type CreateProjectParams = {
168
+ projectName: string;
169
+ description?: string | null;
170
+ metadata?: RecordStringAny | null;
171
+ upsert?: boolean;
172
+ projectExtra?: RecordStringAny | null;
173
+ referenceDatasetId?: string | null;
174
+ };
167
175
  type AutoBatchQueueItem = {
168
176
  action: "create" | "update";
169
177
  item: RunCreate | RunUpdate;
@@ -395,14 +403,7 @@ export declare class Client implements LangSmithTracingClientInterface {
395
403
  listSharedExamples(shareToken: string, options?: {
396
404
  exampleIds?: string[];
397
405
  }): Promise<Example[]>;
398
- createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: {
399
- projectName: string;
400
- description?: string | null;
401
- metadata?: RecordStringAny | null;
402
- upsert?: boolean;
403
- projectExtra?: RecordStringAny | null;
404
- referenceDatasetId?: string | null;
405
- }): Promise<TracerSession>;
406
+ createProject({ projectName, description, metadata, upsert, projectExtra, referenceDatasetId, }: CreateProjectParams): Promise<TracerSession>;
406
407
  updateProject(projectId: string, { name, description, metadata, projectExtra, endTime, }: {
407
408
  name?: string | null;
408
409
  description?: string | null;
package/dist/index.cjs CHANGED
@@ -8,4 +8,4 @@ Object.defineProperty(exports, "RunTree", { enumerable: true, get: function () {
8
8
  var fetch_js_1 = require("./singletons/fetch.cjs");
9
9
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
10
10
  // Update using yarn bump-version
11
- exports.__version__ = "0.2.15";
11
+ exports.__version__ = "0.2.16-rc.1";
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { Client, type ClientConfig, type LangSmithTracingClientInterface, } from
2
2
  export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, } from "./schemas.js";
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
- export declare const __version__ = "0.2.15";
5
+ export declare const __version__ = "0.2.16-rc.1";
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ export { Client, } from "./client.js";
2
2
  export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  // Update using yarn bump-version
5
- export const __version__ = "0.2.15";
5
+ export const __version__ = "0.2.16-rc.1";
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ /* eslint-disable @typescript-eslint/no-namespace */
4
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
+ if (k2 === undefined) k2 = k;
6
+ var desc = Object.getOwnPropertyDescriptor(m, k);
7
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
+ desc = { enumerable: true, get: function() { return m[k]; } };
9
+ }
10
+ Object.defineProperty(o, k2, desc);
11
+ }) : (function(o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ }));
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.logOutput = exports.logFeedback = exports.toBeSemanticCloseTo = exports.toBeAbsoluteCloseTo = exports.toBeRelativeCloseTo = exports.expect = exports.describe = exports.it = exports.test = void 0;
20
+ const globals_1 = require("@jest/globals");
21
+ const matchers_js_1 = require("../utils/jestlike/matchers.cjs");
22
+ Object.defineProperty(exports, "toBeRelativeCloseTo", { enumerable: true, get: function () { return matchers_js_1.toBeRelativeCloseTo; } });
23
+ Object.defineProperty(exports, "toBeAbsoluteCloseTo", { enumerable: true, get: function () { return matchers_js_1.toBeAbsoluteCloseTo; } });
24
+ Object.defineProperty(exports, "toBeSemanticCloseTo", { enumerable: true, get: function () { return matchers_js_1.toBeSemanticCloseTo; } });
25
+ const index_js_1 = require("../utils/jestlike/index.cjs");
26
+ Object.defineProperty(exports, "logFeedback", { enumerable: true, get: function () { return index_js_1.logFeedback; } });
27
+ Object.defineProperty(exports, "logOutput", { enumerable: true, get: function () { return index_js_1.logOutput; } });
28
+ const index_js_2 = require("../utils/jestlike/index.cjs");
29
+ globals_1.expect.extend({
30
+ toBeRelativeCloseTo: matchers_js_1.toBeRelativeCloseTo,
31
+ toBeAbsoluteCloseTo: matchers_js_1.toBeAbsoluteCloseTo,
32
+ toBeSemanticCloseTo: matchers_js_1.toBeSemanticCloseTo,
33
+ });
34
+ const { test, it, describe, expect } = (0, index_js_2.generateWrapperFromJestlikeMethods)({
35
+ expect: globals_1.expect,
36
+ test: globals_1.test,
37
+ describe: globals_1.describe,
38
+ beforeAll: globals_1.beforeAll,
39
+ afterAll: globals_1.afterAll,
40
+ });
41
+ exports.test = test;
42
+ exports.it = it;
43
+ exports.describe = describe;
44
+ exports.expect = expect;
45
+ __exportStar(require("../utils/jestlike/types.cjs"), exports);
@@ -0,0 +1,99 @@
1
+ /// <reference types="jest" />
2
+ import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
3
+ import type { SimpleEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
4
+ import { logFeedback, logOutput } from "../utils/jestlike/index.js";
5
+ declare global {
6
+ namespace jest {
7
+ interface AsymmetricMatchers {
8
+ toBeRelativeCloseTo(expected: string, options?: RelativeCloseToMatcherOptions): Promise<void>;
9
+ toBeAbsoluteCloseTo(expected: string, options?: AbsoluteCloseToMatcherOptions): Promise<void>;
10
+ toBeSemanticCloseTo(expected: string, options?: SemanticCloseToMatcherOptions): Promise<void>;
11
+ }
12
+ interface Matchers<R> {
13
+ toBeRelativeCloseTo(expected: string, options?: RelativeCloseToMatcherOptions): Promise<R>;
14
+ toBeAbsoluteCloseTo(expected: string, options?: AbsoluteCloseToMatcherOptions): Promise<R>;
15
+ toBeSemanticCloseTo(expected: string, options?: SemanticCloseToMatcherOptions): Promise<R>;
16
+ evaluatedBy(evaluator: SimpleEvaluator): jest.Matchers<Promise<R>> & {
17
+ not: jest.Matchers<Promise<R>>;
18
+ resolves: jest.Matchers<Promise<R>>;
19
+ rejects: jest.Matchers<Promise<R>>;
20
+ };
21
+ }
22
+ }
23
+ }
24
+ declare const test: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
25
+ inputs: I;
26
+ expected: O;
27
+ }) => unknown, timeout?: number | undefined) => void) & {
28
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
29
+ inputs: I;
30
+ expected: O;
31
+ }) => unknown, timeout?: number | undefined) => void) & {
32
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
33
+ inputs: I_1;
34
+ expected: O_1;
35
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
36
+ inputs: I_1;
37
+ expected: O_1;
38
+ }) => unknown, timeout?: number | undefined) => void;
39
+ };
40
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
41
+ inputs: I;
42
+ expected: O;
43
+ }) => unknown, timeout?: number | undefined) => void) & {
44
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
45
+ inputs: I_1;
46
+ expected: O_1;
47
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
48
+ inputs: I_1;
49
+ expected: O_1;
50
+ }) => unknown, timeout?: number | undefined) => void;
51
+ };
52
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
53
+ inputs: I_1;
54
+ expected: O_1;
55
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
56
+ inputs: I_1;
57
+ expected: O_1;
58
+ }) => unknown, timeout?: number | undefined) => void;
59
+ }, it: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
60
+ inputs: I;
61
+ expected: O;
62
+ }) => unknown, timeout?: number | undefined) => void) & {
63
+ only: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
64
+ inputs: I;
65
+ expected: O;
66
+ }) => unknown, timeout?: number | undefined) => void) & {
67
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
68
+ inputs: I_1;
69
+ expected: O_1;
70
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
71
+ inputs: I_1;
72
+ expected: O_1;
73
+ }) => unknown, timeout?: number | undefined) => void;
74
+ };
75
+ skip: (<I extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Record<string, any>>(name: string, lsParams: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperParams<I, O>, testFn: (data: {
76
+ inputs: I;
77
+ expected: O;
78
+ }) => unknown, timeout?: number | undefined) => void) & {
79
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
80
+ inputs: I_1;
81
+ expected: O_1;
82
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
83
+ inputs: I_1;
84
+ expected: O_1;
85
+ }) => unknown, timeout?: number | undefined) => void;
86
+ };
87
+ each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: {
88
+ inputs: I_1;
89
+ expected: O_1;
90
+ }[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
91
+ inputs: I_1;
92
+ expected: O_1;
93
+ }) => unknown, timeout?: number | undefined) => void;
94
+ }, describe: import("../utils/jestlike/types.js").LangSmithJestDescribeWrapper & {
95
+ only: import("../utils/jestlike/types.js").LangSmithJestDescribeWrapper;
96
+ skip: import("../utils/jestlike/types.js").LangSmithJestDescribeWrapper;
97
+ }, expect: jest.Expect;
98
+ export { test, it, describe, expect, toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, logFeedback, logOutput, };
99
+ export * from "../utils/jestlike/types.js";
@@ -0,0 +1,20 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
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";
4
+ import { toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, } from "../utils/jestlike/matchers.js";
5
+ import { logFeedback, logOutput } from "../utils/jestlike/index.js";
6
+ import { generateWrapperFromJestlikeMethods } from "../utils/jestlike/index.js";
7
+ jestExpect.extend({
8
+ toBeRelativeCloseTo,
9
+ toBeAbsoluteCloseTo,
10
+ toBeSemanticCloseTo,
11
+ });
12
+ const { test, it, describe, expect } = generateWrapperFromJestlikeMethods({
13
+ expect: jestExpect,
14
+ test: jestTest,
15
+ describe: jestDescribe,
16
+ beforeAll: jestBeforeAll,
17
+ afterAll: jestAfterAll,
18
+ });
19
+ export { test, it, describe, expect, toBeRelativeCloseTo, toBeAbsoluteCloseTo, toBeSemanticCloseTo, logFeedback, logOutput, };
20
+ export * from "../utils/jestlike/types.js";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const reporter_js_1 = __importDefault(require("../utils/jestlike/reporter.cjs"));
7
+ exports.default = reporter_js_1.default;
@@ -0,0 +1,2 @@
1
+ import CustomReporter from "../utils/jestlike/reporter.js";
2
+ export default CustomReporter;
@@ -0,0 +1,2 @@
1
+ import CustomReporter from "../utils/jestlike/reporter.js";
2
+ export default CustomReporter;
@@ -270,7 +270,7 @@ class RunTree {
270
270
  return {
271
271
  id: uuid.v4(),
272
272
  run_type: "chain",
273
- project_name: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_PROJECT") ??
273
+ project_name: (0, env_js_1.getLangSmithEnvironmentVariable)("PROJECT") ??
274
274
  (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_SESSION") ?? // TODO: Deprecate
275
275
  "default",
276
276
  child_runs: [],
@@ -80,7 +80,7 @@ export declare class RunTree implements BaseRun {
80
80
  attachments?: Attachments;
81
81
  constructor(originalConfig: RunTreeConfig | RunTree);
82
82
  private static getDefaultConfig;
83
- private static getSharedClient;
83
+ static getSharedClient(): Client;
84
84
  createChild(config: RunTreeConfig): RunTree;
85
85
  end(outputs?: KVMap, error?: string, endTime?: number, metadata?: KVMap): Promise<void>;
86
86
  private _convertToCreate;
package/dist/run_trees.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as uuid from "uuid";
2
- import { getEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
2
+ import { getEnvironmentVariable, getLangSmithEnvironmentVariable, getRuntimeEnvironment, } from "./utils/env.js";
3
3
  import { Client } from "./client.js";
4
4
  import { isTracingEnabled } from "./env.js";
5
5
  import { warnOnce } from "./utils/warn.js";
@@ -243,7 +243,7 @@ export class RunTree {
243
243
  return {
244
244
  id: uuid.v4(),
245
245
  run_type: "chain",
246
- project_name: getEnvironmentVariable("LANGCHAIN_PROJECT") ??
246
+ project_name: getLangSmithEnvironmentVariable("PROJECT") ??
247
247
  getEnvironmentVariable("LANGCHAIN_SESSION") ?? // TODO: Deprecate
248
248
  "default",
249
249
  child_runs: [],
@@ -38,7 +38,7 @@ const getCurrentRunTree = () => {
38
38
  throw new Error([
39
39
  "Could not get the current run tree.",
40
40
  "",
41
- "Please make sure you are calling this method within a traceable function or the tracing is enabled.",
41
+ "Please make sure you are calling this method within a traceable function and that tracing is enabled.",
42
42
  ].join("\n"));
43
43
  }
44
44
  return runTree;
@@ -35,7 +35,7 @@ export const getCurrentRunTree = () => {
35
35
  throw new Error([
36
36
  "Could not get the current run tree.",
37
37
  "",
38
- "Please make sure you are calling this method within a traceable function or the tracing is enabled.",
38
+ "Please make sure you are calling this method within a traceable function and that tracing is enabled.",
39
39
  ].join("\n"));
40
40
  }
41
41
  return runTree;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._logTestFeedback = exports.syncExamplePromises = exports.evaluatorLogFeedbackPromises = exports.trackingEnabled = exports.testWrapperAsyncLocalStorageInstance = void 0;
4
+ const node_async_hooks_1 = require("node:async_hooks");
5
+ const env_js_1 = require("../env.cjs");
6
+ const env_js_2 = require("../../env.cjs");
7
+ exports.testWrapperAsyncLocalStorageInstance = new node_async_hooks_1.AsyncLocalStorage();
8
+ function trackingEnabled(context) {
9
+ if (typeof context.enableTestTracking === "boolean") {
10
+ return context.enableTestTracking;
11
+ }
12
+ if ((0, env_js_1.getEnvironmentVariable)("LANGSMITH_TEST_TRACKING") === "false") {
13
+ return false;
14
+ }
15
+ return (0, env_js_2.isTracingEnabled)();
16
+ }
17
+ exports.trackingEnabled = trackingEnabled;
18
+ exports.evaluatorLogFeedbackPromises = new Set();
19
+ exports.syncExamplePromises = new Map();
20
+ function _logTestFeedback(params) {
21
+ const { exampleId, feedback, context, runTree, client, sourceRunId } = params;
22
+ if (trackingEnabled(context)) {
23
+ if (exampleId === undefined) {
24
+ throw new Error("Could not log feedback to LangSmith: missing example id. Please contact us for help.");
25
+ }
26
+ if (runTree === undefined) {
27
+ throw new Error("Could not log feedback to LangSmith: missing run information. Please contact us for help.");
28
+ }
29
+ exports.evaluatorLogFeedbackPromises.add((async () => {
30
+ await exports.syncExamplePromises.get(exampleId);
31
+ await client?.logEvaluationFeedback(feedback, runTree, sourceRunId !== undefined
32
+ ? { __run: { run_id: sourceRunId } }
33
+ : undefined);
34
+ })());
35
+ }
36
+ context.onFeedbackLogged?.(feedback);
37
+ }
38
+ exports._logTestFeedback = _logTestFeedback;
@@ -0,0 +1,33 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { Dataset, TracerSession, Example } from "../../schemas.js";
4
+ import { Client, CreateProjectParams } from "../../client.js";
5
+ import { EvaluationResult } from "../../evaluation/evaluator.js";
6
+ import { RunTree } from "../../run_trees.js";
7
+ export type TestWrapperAsyncLocalStorageData = {
8
+ enableTestTracking?: boolean;
9
+ dataset?: Dataset;
10
+ createdAt: string;
11
+ projectConfig?: Partial<CreateProjectParams>;
12
+ project?: TracerSession;
13
+ setLoggedOutput?: (value: Record<string, unknown>) => void;
14
+ onFeedbackLogged?: (feedback: EvaluationResult) => void;
15
+ currentExample?: Partial<Example> & {
16
+ syncPromise?: Promise<Example>;
17
+ };
18
+ client: Client;
19
+ suiteUuid: string;
20
+ suiteName: string;
21
+ };
22
+ export declare const testWrapperAsyncLocalStorageInstance: AsyncLocalStorage<TestWrapperAsyncLocalStorageData>;
23
+ export declare function trackingEnabled(context: TestWrapperAsyncLocalStorageData): boolean;
24
+ export declare const evaluatorLogFeedbackPromises: Set<unknown>;
25
+ export declare const syncExamplePromises: Map<any, any>;
26
+ export declare function _logTestFeedback(params: {
27
+ exampleId?: string;
28
+ feedback: EvaluationResult;
29
+ context: TestWrapperAsyncLocalStorageData;
30
+ runTree?: RunTree;
31
+ client: Client;
32
+ sourceRunId?: string;
33
+ }): void;
@@ -0,0 +1,33 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { getEnvironmentVariable } from "../env.js";
3
+ import { isTracingEnabled } from "../../env.js";
4
+ export const testWrapperAsyncLocalStorageInstance = new AsyncLocalStorage();
5
+ export function trackingEnabled(context) {
6
+ if (typeof context.enableTestTracking === "boolean") {
7
+ return context.enableTestTracking;
8
+ }
9
+ if (getEnvironmentVariable("LANGSMITH_TEST_TRACKING") === "false") {
10
+ return false;
11
+ }
12
+ return isTracingEnabled();
13
+ }
14
+ export const evaluatorLogFeedbackPromises = new Set();
15
+ export const syncExamplePromises = new Map();
16
+ export function _logTestFeedback(params) {
17
+ const { exampleId, feedback, context, runTree, client, sourceRunId } = params;
18
+ if (trackingEnabled(context)) {
19
+ if (exampleId === undefined) {
20
+ throw new Error("Could not log feedback to LangSmith: missing example id. Please contact us for help.");
21
+ }
22
+ if (runTree === undefined) {
23
+ throw new Error("Could not log feedback to LangSmith: missing run information. Please contact us for help.");
24
+ }
25
+ evaluatorLogFeedbackPromises.add((async () => {
26
+ await syncExamplePromises.get(exampleId);
27
+ await client?.logEvaluationFeedback(feedback, runTree, sourceRunId !== undefined
28
+ ? { __run: { run_id: sourceRunId } }
29
+ : undefined);
30
+ })());
31
+ }
32
+ context.onFeedbackLogged?.(feedback);
33
+ }