langsmith 0.3.17 → 0.3.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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.3.17";
11
+ exports.__version__ = "0.3.18";
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.3.17";
5
+ export declare const __version__ = "0.3.18";
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.3.17";
5
+ export const __version__ = "0.3.18";
@@ -18,6 +18,7 @@ export type TestWrapperAsyncLocalStorageData = {
18
18
  client: Client;
19
19
  suiteUuid: string;
20
20
  suiteName: string;
21
+ testRootRunTree?: RunTree;
21
22
  };
22
23
  export declare const testWrapperAsyncLocalStorageInstance: AsyncLocalStorage<TestWrapperAsyncLocalStorageData>;
23
24
  export declare function trackingEnabled(context: TestWrapperAsyncLocalStorageData): boolean;
@@ -79,7 +79,7 @@ function logFeedback(feedback, config) {
79
79
  exampleId: context.currentExample.id,
80
80
  feedback: feedback,
81
81
  context,
82
- runTree: (0, globals_js_1.trackingEnabled)(context) ? (0, traceable_js_1.getCurrentRunTree)() : undefined,
82
+ runTree: context.testRootRunTree,
83
83
  client: context.client,
84
84
  });
85
85
  }
@@ -399,52 +399,59 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
399
399
  };
400
400
  let exampleId;
401
401
  const runTestFn = async () => {
402
- const testContext = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
402
+ let testContext = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
403
403
  if (testContext === undefined) {
404
404
  throw new Error("Could not identify test context. Please contact us for help.");
405
405
  }
406
- try {
407
- const res = await testFn({
408
- ...rest,
409
- inputs: testInput,
410
- referenceOutputs: testOutput,
411
- });
412
- (0, globals_js_1._logTestFeedback)({
413
- exampleId,
414
- feedback: { key: "pass", score: true },
415
- context: testContext,
416
- runTree: (0, globals_js_1.trackingEnabled)(testContext)
417
- ? (0, traceable_js_1.getCurrentRunTree)()
418
- : undefined,
419
- client: testContext.client,
420
- });
421
- if (res != null) {
422
- if (loggedOutput !== undefined) {
423
- console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
406
+ return globals_js_1.testWrapperAsyncLocalStorageInstance.run({
407
+ ...testContext,
408
+ testRootRunTree: (0, globals_js_1.trackingEnabled)(testContext)
409
+ ? (0, traceable_js_1.getCurrentRunTree)()
410
+ : undefined,
411
+ }, async () => {
412
+ testContext = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
413
+ if (testContext === undefined) {
414
+ throw new Error("Could not identify test context after setting test root run tree. Please contact us for help.");
415
+ }
416
+ try {
417
+ const res = await testFn({
418
+ ...rest,
419
+ inputs: testInput,
420
+ referenceOutputs: testOutput,
421
+ });
422
+ (0, globals_js_1._logTestFeedback)({
423
+ exampleId,
424
+ feedback: { key: "pass", score: true },
425
+ context: testContext,
426
+ runTree: testContext.testRootRunTree,
427
+ client: testContext.client,
428
+ });
429
+ if (res != null) {
430
+ if (loggedOutput !== undefined) {
431
+ console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
432
+ }
433
+ loggedOutput =
434
+ typeof res === "object"
435
+ ? res
436
+ : { result: res };
424
437
  }
425
- loggedOutput =
426
- typeof res === "object"
427
- ? res
428
- : { result: res };
438
+ return loggedOutput;
429
439
  }
430
- return loggedOutput;
431
- }
432
- catch (e) {
433
- (0, globals_js_1._logTestFeedback)({
434
- exampleId,
435
- feedback: { key: "pass", score: false },
436
- context: testContext,
437
- runTree: (0, globals_js_1.trackingEnabled)(testContext)
438
- ? (0, traceable_js_1.getCurrentRunTree)()
439
- : undefined,
440
- client: testContext.client,
441
- });
442
- const rawError = e;
443
- const strippedErrorMessage = e.message.replace(constants_js_1.STRIP_ANSI_REGEX, "");
444
- const langsmithFriendlyError = new Error(strippedErrorMessage);
445
- langsmithFriendlyError.rawJestError = rawError;
446
- throw langsmithFriendlyError;
447
- }
440
+ catch (e) {
441
+ (0, globals_js_1._logTestFeedback)({
442
+ exampleId,
443
+ feedback: { key: "pass", score: false },
444
+ context: testContext,
445
+ runTree: testContext.testRootRunTree,
446
+ client: testContext.client,
447
+ });
448
+ const rawError = e;
449
+ const strippedErrorMessage = e.message.replace(constants_js_1.STRIP_ANSI_REGEX, "");
450
+ const langsmithFriendlyError = new Error(strippedErrorMessage);
451
+ langsmithFriendlyError.rawJestError = rawError;
452
+ throw langsmithFriendlyError;
453
+ }
454
+ });
448
455
  };
449
456
  try {
450
457
  if ((0, globals_js_1.trackingEnabled)(context)) {
@@ -32,7 +32,7 @@ export function logFeedback(feedback, config) {
32
32
  exampleId: context.currentExample.id,
33
33
  feedback: feedback,
34
34
  context,
35
- runTree: trackingEnabled(context) ? getCurrentRunTree() : undefined,
35
+ runTree: context.testRootRunTree,
36
36
  client: context.client,
37
37
  });
38
38
  }
@@ -352,52 +352,59 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
352
352
  };
353
353
  let exampleId;
354
354
  const runTestFn = async () => {
355
- const testContext = testWrapperAsyncLocalStorageInstance.getStore();
355
+ let testContext = testWrapperAsyncLocalStorageInstance.getStore();
356
356
  if (testContext === undefined) {
357
357
  throw new Error("Could not identify test context. Please contact us for help.");
358
358
  }
359
- try {
360
- const res = await testFn({
361
- ...rest,
362
- inputs: testInput,
363
- referenceOutputs: testOutput,
364
- });
365
- _logTestFeedback({
366
- exampleId,
367
- feedback: { key: "pass", score: true },
368
- context: testContext,
369
- runTree: trackingEnabled(testContext)
370
- ? getCurrentRunTree()
371
- : undefined,
372
- client: testContext.client,
373
- });
374
- if (res != null) {
375
- if (loggedOutput !== undefined) {
376
- console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
359
+ return testWrapperAsyncLocalStorageInstance.run({
360
+ ...testContext,
361
+ testRootRunTree: trackingEnabled(testContext)
362
+ ? getCurrentRunTree()
363
+ : undefined,
364
+ }, async () => {
365
+ testContext = testWrapperAsyncLocalStorageInstance.getStore();
366
+ if (testContext === undefined) {
367
+ throw new Error("Could not identify test context after setting test root run tree. Please contact us for help.");
368
+ }
369
+ try {
370
+ const res = await testFn({
371
+ ...rest,
372
+ inputs: testInput,
373
+ referenceOutputs: testOutput,
374
+ });
375
+ _logTestFeedback({
376
+ exampleId,
377
+ feedback: { key: "pass", score: true },
378
+ context: testContext,
379
+ runTree: testContext.testRootRunTree,
380
+ client: testContext.client,
381
+ });
382
+ if (res != null) {
383
+ if (loggedOutput !== undefined) {
384
+ console.warn(`[WARN]: Returned value from test function will override output set by previous "logOutputs()" call.`);
385
+ }
386
+ loggedOutput =
387
+ typeof res === "object"
388
+ ? res
389
+ : { result: res };
377
390
  }
378
- loggedOutput =
379
- typeof res === "object"
380
- ? res
381
- : { result: res };
391
+ return loggedOutput;
382
392
  }
383
- return loggedOutput;
384
- }
385
- catch (e) {
386
- _logTestFeedback({
387
- exampleId,
388
- feedback: { key: "pass", score: false },
389
- context: testContext,
390
- runTree: trackingEnabled(testContext)
391
- ? getCurrentRunTree()
392
- : undefined,
393
- client: testContext.client,
394
- });
395
- const rawError = e;
396
- const strippedErrorMessage = e.message.replace(STRIP_ANSI_REGEX, "");
397
- const langsmithFriendlyError = new Error(strippedErrorMessage);
398
- langsmithFriendlyError.rawJestError = rawError;
399
- throw langsmithFriendlyError;
400
- }
393
+ catch (e) {
394
+ _logTestFeedback({
395
+ exampleId,
396
+ feedback: { key: "pass", score: false },
397
+ context: testContext,
398
+ runTree: testContext.testRootRunTree,
399
+ client: testContext.client,
400
+ });
401
+ const rawError = e;
402
+ const strippedErrorMessage = e.message.replace(STRIP_ANSI_REGEX, "");
403
+ const langsmithFriendlyError = new Error(strippedErrorMessage);
404
+ langsmithFriendlyError.rawJestError = rawError;
405
+ throw langsmithFriendlyError;
406
+ }
407
+ });
401
408
  };
402
409
  try {
403
410
  if (trackingEnabled(context)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
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": [