langsmith 0.3.13 → 0.3.15

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 (44) hide show
  1. package/dist/anonymizer/index.cjs +1 -2
  2. package/dist/client.cjs +49 -19
  3. package/dist/client.d.ts +2 -0
  4. package/dist/client.js +30 -10
  5. package/dist/evaluation/_random_name.cjs +1 -2
  6. package/dist/evaluation/_runner.cjs +2 -2
  7. package/dist/evaluation/evaluate_comparative.cjs +1 -2
  8. package/dist/evaluation/evaluator.cjs +2 -2
  9. package/dist/evaluation/langchain.cjs +1 -2
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/jest/index.d.ts +45 -46
  14. package/dist/langchain.cjs +2 -2
  15. package/dist/run_trees.cjs +21 -11
  16. package/dist/singletons/traceable.cjs +3 -3
  17. package/dist/traceable.cjs +2 -3
  18. package/dist/traceable.js +0 -1
  19. package/dist/utils/_uuid.cjs +18 -9
  20. package/dist/utils/asserts.cjs +3 -3
  21. package/dist/utils/asserts.d.ts +3 -3
  22. package/dist/utils/atee.cjs +1 -2
  23. package/dist/utils/env.cjs +9 -9
  24. package/dist/utils/error.cjs +3 -3
  25. package/dist/utils/fast-safe-stringify/index.cjs +1 -2
  26. package/dist/utils/fast-safe-stringify/index.d.ts +1 -1
  27. package/dist/utils/jestlike/globals.cjs +3 -3
  28. package/dist/utils/jestlike/globals.d.ts +0 -1
  29. package/dist/utils/jestlike/index.cjs +23 -13
  30. package/dist/utils/jestlike/index.d.ts +30 -31
  31. package/dist/utils/jestlike/matchers.cjs +3 -4
  32. package/dist/utils/jestlike/reporter.cjs +18 -9
  33. package/dist/utils/jestlike/vendor/chain.cjs +1 -2
  34. package/dist/utils/jestlike/vendor/chain.d.ts +0 -1
  35. package/dist/utils/jestlike/vendor/evaluatedBy.cjs +2 -3
  36. package/dist/utils/messages.cjs +2 -3
  37. package/dist/utils/prompts.cjs +2 -3
  38. package/dist/utils/shuffle.cjs +1 -2
  39. package/dist/utils/warn.cjs +1 -2
  40. package/dist/vercel.cjs +17 -0
  41. package/dist/vercel.d.ts +4 -4
  42. package/dist/vercel.js +17 -0
  43. package/dist/vitest/index.d.ts +45 -46
  44. package/package.json +1 -1
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createAnonymizer = void 0;
6
+ exports.createAnonymizer = createAnonymizer;
7
7
  const set_js_1 = __importDefault(require("../utils/lodash/set.cjs"));
8
8
  function extractStringNodes(data, options) {
9
9
  const parsedOptions = { ...options, maxDepth: options.maxDepth ?? 10 };
@@ -99,4 +99,3 @@ function createAnonymizer(replacer, options) {
99
99
  return mutateValue;
100
100
  };
101
101
  }
102
- exports.createAnonymizer = createAnonymizer;
package/dist/client.cjs CHANGED
@@ -15,15 +15,26 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Client = exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = exports.AutoBatchQueue = exports.mergeRuntimeEnvIntoRunCreate = void 0;
36
+ exports.Client = exports.DEFAULT_BATCH_SIZE_LIMIT_BYTES = exports.AutoBatchQueue = void 0;
37
+ exports.mergeRuntimeEnvIntoRunCreate = mergeRuntimeEnvIntoRunCreate;
27
38
  const uuid = __importStar(require("uuid"));
28
39
  const async_caller_js_1 = require("./utils/async_caller.cjs");
29
40
  const messages_js_1 = require("./utils/messages.cjs");
@@ -56,9 +67,9 @@ function mergeRuntimeEnvIntoRunCreate(run) {
56
67
  };
57
68
  return run;
58
69
  }
59
- exports.mergeRuntimeEnvIntoRunCreate = mergeRuntimeEnvIntoRunCreate;
60
- const getTracingSamplingRate = () => {
61
- const samplingRateStr = (0, env_js_1.getLangSmithEnvironmentVariable)("TRACING_SAMPLING_RATE");
70
+ const getTracingSamplingRate = (configRate) => {
71
+ const samplingRateStr = configRate?.toString() ??
72
+ (0, env_js_1.getLangSmithEnvironmentVariable)("TRACING_SAMPLING_RATE");
62
73
  if (samplingRateStr === undefined) {
63
74
  return undefined;
64
75
  }
@@ -322,7 +333,7 @@ class Client {
322
333
  value: false
323
334
  });
324
335
  const defaultConfig = Client.getDefaultClientConfig();
325
- this.tracingSampleRate = getTracingSamplingRate();
336
+ this.tracingSampleRate = getTracingSamplingRate(config.tracingSamplingRate);
326
337
  this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
327
338
  if (this.apiUrl.endsWith("/")) {
328
339
  this.apiUrl = this.apiUrl.slice(0, -1);
@@ -518,6 +529,13 @@ class Client {
518
529
  bodyParams.cursor = cursors.next;
519
530
  }
520
531
  }
532
+ // Allows mocking for tests
533
+ _shouldSample() {
534
+ if (this.tracingSampleRate === undefined) {
535
+ return true;
536
+ }
537
+ return Math.random() < this.tracingSampleRate;
538
+ }
521
539
  _filterForSampling(runs, patch = false) {
522
540
  if (this.tracingSampleRate === undefined) {
523
541
  return runs;
@@ -535,15 +553,26 @@ class Client {
535
553
  return sampled;
536
554
  }
537
555
  else {
556
+ // For new runs, sample at trace level to maintain consistency
538
557
  const sampled = [];
539
558
  for (const run of runs) {
540
- if ((run.id !== run.trace_id &&
541
- !this.filteredPostUuids.has(run.trace_id)) ||
542
- Math.random() < this.tracingSampleRate) {
543
- sampled.push(run);
559
+ const traceId = run.trace_id ?? run.id;
560
+ // If we've already made a decision about this trace, follow it
561
+ if (this.filteredPostUuids.has(traceId)) {
562
+ continue;
563
+ }
564
+ // For new traces, apply sampling
565
+ if (run.id === traceId) {
566
+ if (this._shouldSample()) {
567
+ sampled.push(run);
568
+ }
569
+ else {
570
+ this.filteredPostUuids.add(traceId);
571
+ }
544
572
  }
545
573
  else {
546
- this.filteredPostUuids.add(run.id);
574
+ // Child runs follow their trace's sampling decision
575
+ sampled.push(run);
547
576
  }
548
577
  }
549
578
  return sampled;
@@ -730,8 +759,8 @@ class Client {
730
759
  preparedUpdateParams = standaloneUpdates;
731
760
  }
732
761
  const rawBatch = {
733
- post: this._filterForSampling(preparedCreateParams),
734
- patch: this._filterForSampling(preparedUpdateParams, true),
762
+ post: preparedCreateParams,
763
+ patch: preparedUpdateParams,
735
764
  };
736
765
  if (!rawBatch.post.length && !rawBatch.patch.length) {
737
766
  return;
@@ -745,6 +774,7 @@ class Client {
745
774
  const batchItems = rawBatch[key].reverse();
746
775
  let batchItem = batchItems.pop();
747
776
  while (batchItem !== undefined) {
777
+ // Type is wrong but this is a deprecated code path anyway
748
778
  batchChunks[key].push(batchItem);
749
779
  batchItem = batchItems.pop();
750
780
  }
package/dist/client.d.ts CHANGED
@@ -20,6 +20,7 @@ export interface ClientConfig {
20
20
  * Useful if encountering network rate limits at trace high volumes.
21
21
  */
22
22
  manualFlushMode?: boolean;
23
+ tracingSamplingRate?: number;
23
24
  }
24
25
  /**
25
26
  * Represents the parameters for listing runs (spans) from the Langsmith server.
@@ -244,6 +245,7 @@ export declare class Client implements LangSmithTracingClientInterface {
244
245
  private _get;
245
246
  private _getPaginated;
246
247
  private _getCursorPaginatedList;
248
+ private _shouldSample;
247
249
  private _filterForSampling;
248
250
  private _getBatchSizeLimitBytes;
249
251
  private _getMultiPartSupport;
package/dist/client.js CHANGED
@@ -30,8 +30,9 @@ export function mergeRuntimeEnvIntoRunCreate(run) {
30
30
  };
31
31
  return run;
32
32
  }
33
- const getTracingSamplingRate = () => {
34
- const samplingRateStr = getLangSmithEnvironmentVariable("TRACING_SAMPLING_RATE");
33
+ const getTracingSamplingRate = (configRate) => {
34
+ const samplingRateStr = configRate?.toString() ??
35
+ getLangSmithEnvironmentVariable("TRACING_SAMPLING_RATE");
35
36
  if (samplingRateStr === undefined) {
36
37
  return undefined;
37
38
  }
@@ -294,7 +295,7 @@ export class Client {
294
295
  value: false
295
296
  });
296
297
  const defaultConfig = Client.getDefaultClientConfig();
297
- this.tracingSampleRate = getTracingSamplingRate();
298
+ this.tracingSampleRate = getTracingSamplingRate(config.tracingSamplingRate);
298
299
  this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
299
300
  if (this.apiUrl.endsWith("/")) {
300
301
  this.apiUrl = this.apiUrl.slice(0, -1);
@@ -490,6 +491,13 @@ export class Client {
490
491
  bodyParams.cursor = cursors.next;
491
492
  }
492
493
  }
494
+ // Allows mocking for tests
495
+ _shouldSample() {
496
+ if (this.tracingSampleRate === undefined) {
497
+ return true;
498
+ }
499
+ return Math.random() < this.tracingSampleRate;
500
+ }
493
501
  _filterForSampling(runs, patch = false) {
494
502
  if (this.tracingSampleRate === undefined) {
495
503
  return runs;
@@ -507,15 +515,26 @@ export class Client {
507
515
  return sampled;
508
516
  }
509
517
  else {
518
+ // For new runs, sample at trace level to maintain consistency
510
519
  const sampled = [];
511
520
  for (const run of runs) {
512
- if ((run.id !== run.trace_id &&
513
- !this.filteredPostUuids.has(run.trace_id)) ||
514
- Math.random() < this.tracingSampleRate) {
515
- sampled.push(run);
521
+ const traceId = run.trace_id ?? run.id;
522
+ // If we've already made a decision about this trace, follow it
523
+ if (this.filteredPostUuids.has(traceId)) {
524
+ continue;
525
+ }
526
+ // For new traces, apply sampling
527
+ if (run.id === traceId) {
528
+ if (this._shouldSample()) {
529
+ sampled.push(run);
530
+ }
531
+ else {
532
+ this.filteredPostUuids.add(traceId);
533
+ }
516
534
  }
517
535
  else {
518
- this.filteredPostUuids.add(run.id);
536
+ // Child runs follow their trace's sampling decision
537
+ sampled.push(run);
519
538
  }
520
539
  }
521
540
  return sampled;
@@ -702,8 +721,8 @@ export class Client {
702
721
  preparedUpdateParams = standaloneUpdates;
703
722
  }
704
723
  const rawBatch = {
705
- post: this._filterForSampling(preparedCreateParams),
706
- patch: this._filterForSampling(preparedUpdateParams, true),
724
+ post: preparedCreateParams,
725
+ patch: preparedUpdateParams,
707
726
  };
708
727
  if (!rawBatch.post.length && !rawBatch.patch.length) {
709
728
  return;
@@ -717,6 +736,7 @@ export class Client {
717
736
  const batchItems = rawBatch[key].reverse();
718
737
  let batchItem = batchItems.pop();
719
738
  while (batchItem !== undefined) {
739
+ // Type is wrong but this is a deprecated code path anyway
720
740
  batchChunks[key].push(batchItem);
721
741
  batchItem = batchItems.pop();
722
742
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.randomName = void 0;
3
+ exports.randomName = randomName;
4
4
  const adjectives = [
5
5
  "abandoned",
6
6
  "aching",
@@ -727,4 +727,3 @@ function randomName() {
727
727
  const number = Math.floor(Math.random() * 100);
728
728
  return `${adjective}-${noun}-${number}`;
729
729
  }
730
- exports.randomName = randomName;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports._ExperimentManager = exports.evaluate = void 0;
3
+ exports._ExperimentManager = void 0;
4
+ exports.evaluate = evaluate;
4
5
  const index_js_1 = require("../index.cjs");
5
6
  const traceable_js_1 = require("../traceable.cjs");
6
7
  const _git_js_1 = require("../utils/_git.cjs");
@@ -17,7 +18,6 @@ const evaluate_comparative_js_1 = require("./evaluate_comparative.cjs");
17
18
  function evaluate(target, options) {
18
19
  return _evaluate(target, options);
19
20
  }
20
- exports.evaluate = evaluate;
21
21
  /**
22
22
  * Manage the execution of experiments.
23
23
  *
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.evaluateComparative = void 0;
6
+ exports.evaluateComparative = evaluateComparative;
7
7
  const uuid_1 = require("uuid");
8
8
  const index_js_1 = require("../index.cjs");
9
9
  const shuffle_js_1 = require("../utils/shuffle.cjs");
@@ -216,4 +216,3 @@ async function evaluateComparative(experiments, options) {
216
216
  const results = await Promise.all(promises);
217
217
  return { experimentName, results };
218
218
  }
219
- exports.evaluateComparative = evaluateComparative;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runEvaluator = exports.DynamicRunEvaluator = void 0;
3
+ exports.DynamicRunEvaluator = void 0;
4
+ exports.runEvaluator = runEvaluator;
4
5
  const uuid_1 = require("uuid");
5
6
  const traceable_js_1 = require("../traceable.cjs");
6
7
  /**
@@ -109,4 +110,3 @@ exports.DynamicRunEvaluator = DynamicRunEvaluator;
109
110
  function runEvaluator(func) {
110
111
  return new DynamicRunEvaluator(func);
111
112
  }
112
- exports.runEvaluator = runEvaluator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLangchainStringEvaluator = void 0;
3
+ exports.getLangchainStringEvaluator = getLangchainStringEvaluator;
4
4
  // eslint-disable-next-line import/no-extraneous-dependencies
5
5
  const evaluation_1 = require("langchain/evaluation");
6
6
  const langchain_js_1 = require("../langchain.cjs");
@@ -52,4 +52,3 @@ async function getLangchainStringEvaluator(type, options) {
52
52
  return { key: feedbackKey, ...score };
53
53
  };
54
54
  }
55
- exports.getLangchainStringEvaluator = getLangchainStringEvaluator;
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.13";
11
+ exports.__version__ = "0.3.15";
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.13";
5
+ export declare const __version__ = "0.3.15";
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.13";
5
+ export const __version__ = "0.3.15";
@@ -1,4 +1,3 @@
1
- /// <reference types="jest" />
2
1
  import { type AbsoluteCloseToMatcherOptions, type SemanticCloseToMatcherOptions, type RelativeCloseToMatcherOptions } from "../utils/jestlike/matchers.js";
3
2
  import type { SimpleEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
4
3
  import { wrapEvaluator } from "../utils/jestlike/vendor/evaluatedBy.js";
@@ -60,74 +59,74 @@ declare global {
60
59
  }
61
60
  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: {
62
61
  inputs: I;
63
- referenceOutputs?: O | undefined;
64
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
62
+ referenceOutputs?: O;
63
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
65
64
  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: {
66
65
  inputs: I;
67
- referenceOutputs?: O | undefined;
68
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
69
- each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: ({
70
- inputs: I_1;
71
- referenceOutputs?: O_1 | undefined;
72
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
73
- inputs: I_1;
74
- referenceOutputs?: O_1 | undefined;
75
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
66
+ referenceOutputs?: O;
67
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
68
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
69
+ inputs: I;
70
+ referenceOutputs?: O;
71
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
72
+ inputs: I;
73
+ referenceOutputs?: O;
74
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
76
75
  };
77
76
  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: {
78
77
  inputs: I;
79
- referenceOutputs?: O | undefined;
80
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
81
- each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: ({
82
- inputs: I_1;
83
- referenceOutputs?: O_1 | undefined;
84
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
85
- inputs: I_1;
86
- referenceOutputs?: O_1 | undefined;
87
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
78
+ referenceOutputs?: O;
79
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
80
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
81
+ inputs: I;
82
+ referenceOutputs?: O;
83
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
84
+ inputs: I;
85
+ referenceOutputs?: O;
86
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
88
87
  };
89
- each: <I_1 extends import("../schemas.js").KVMap, O_1 extends import("../schemas.js").KVMap>(table: ({
90
- inputs: I_1;
91
- referenceOutputs?: O_1 | undefined;
92
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
93
- inputs: I_1;
94
- referenceOutputs?: O_1 | undefined;
95
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
88
+ each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
89
+ inputs: I;
90
+ referenceOutputs?: O;
91
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
92
+ inputs: I;
93
+ referenceOutputs?: O;
94
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
96
95
  }, 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: {
97
96
  inputs: I;
98
- referenceOutputs?: O | undefined;
99
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
97
+ referenceOutputs?: O;
98
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
100
99
  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: {
101
100
  inputs: I;
102
- referenceOutputs?: O | undefined;
103
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
101
+ referenceOutputs?: O;
102
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
104
103
  each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
105
104
  inputs: I;
106
- referenceOutputs?: O | undefined;
107
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
105
+ referenceOutputs?: O;
106
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
108
107
  inputs: I;
109
- referenceOutputs?: O | undefined;
110
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
108
+ referenceOutputs?: O;
109
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
111
110
  };
112
111
  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: {
113
112
  inputs: I;
114
- referenceOutputs?: O | undefined;
115
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void) & {
113
+ referenceOutputs?: O;
114
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void) & {
116
115
  each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
117
116
  inputs: I;
118
- referenceOutputs?: O | undefined;
119
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
117
+ referenceOutputs?: O;
118
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
120
119
  inputs: I;
121
- referenceOutputs?: O | undefined;
122
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
120
+ referenceOutputs?: O;
121
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
123
122
  };
124
123
  each: <I extends import("../schemas.js").KVMap, O extends import("../schemas.js").KVMap>(table: ({
125
124
  inputs: I;
126
- referenceOutputs?: O | undefined;
127
- } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig | undefined) => (name: string, fn: (params: {
125
+ referenceOutputs?: O;
126
+ } & Record<string, any>)[], config?: import("../utils/jestlike/types.js").LangSmithJestlikeWrapperConfig) => (name: string, fn: (params: {
128
127
  inputs: I;
129
- referenceOutputs?: O | undefined;
130
- } & Record<string, any>) => unknown, timeout?: number | undefined) => void;
128
+ referenceOutputs?: O;
129
+ } & Record<string, any>) => unknown | Promise<unknown>, timeout?: number) => void;
131
130
  }, describe: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper & {
132
131
  only: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
133
132
  skip: import("../utils/jestlike/types.js").LangSmithJestlikeDescribeWrapper;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RunnableTraceable = exports.getLangchainCallbacks = void 0;
3
+ exports.RunnableTraceable = void 0;
4
+ exports.getLangchainCallbacks = getLangchainCallbacks;
4
5
  // These `@langchain/core` imports are intentionally not peer dependencies
5
6
  // to avoid package manager issues around circular dependencies.
6
7
  // eslint-disable-next-line import/no-extraneous-dependencies
@@ -77,7 +78,6 @@ async function getLangchainCallbacks(currentRunTree) {
77
78
  }
78
79
  return callbacks;
79
80
  }
80
- exports.getLangchainCallbacks = getLangchainCallbacks;
81
81
  /**
82
82
  * RunnableTraceable is a Runnable that wraps a traceable function.
83
83
  * This allows adding Langsmith traced functions into LangChain sequences.
@@ -15,15 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.isRunnableConfigLike = exports.isRunTree = exports.RunTree = exports.convertToDottedOrderFormat = void 0;
36
+ exports.RunTree = void 0;
37
+ exports.convertToDottedOrderFormat = convertToDottedOrderFormat;
38
+ exports.isRunTree = isRunTree;
39
+ exports.isRunnableConfigLike = isRunnableConfigLike;
27
40
  const uuid = __importStar(require("uuid"));
28
41
  const env_js_1 = require("./utils/env.cjs");
29
42
  const client_js_1 = require("./client.cjs");
@@ -39,7 +52,6 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
39
52
  const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
40
53
  return (stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`) + runId);
41
54
  }
42
- exports.convertToDottedOrderFormat = convertToDottedOrderFormat;
43
55
  /**
44
56
  * Baggage header information
45
57
  */
@@ -557,7 +569,6 @@ function isRunTree(x) {
557
569
  typeof x.createChild === "function" &&
558
570
  typeof x.postRun === "function");
559
571
  }
560
- exports.isRunTree = isRunTree;
561
572
  function isLangChainTracerLike(x) {
562
573
  return (typeof x === "object" &&
563
574
  x != null &&
@@ -583,4 +594,3 @@ function isRunnableConfigLike(x) {
583
594
  // Or it's an array with a LangChainTracerLike object within it
584
595
  containsLangChainTracerLike(x.callbacks)));
585
596
  }
586
- exports.isRunnableConfigLike = isRunnableConfigLike;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isTraceableFunction = exports.ROOT = exports.withRunTree = exports.getCurrentRunTree = exports.AsyncLocalStorageProviderSingleton = void 0;
3
+ exports.ROOT = exports.getCurrentRunTree = exports.AsyncLocalStorageProviderSingleton = void 0;
4
+ exports.withRunTree = withRunTree;
5
+ exports.isTraceableFunction = isTraceableFunction;
4
6
  const run_trees_js_1 = require("../run_trees.cjs");
5
7
  class MockAsyncLocalStorage {
6
8
  getStore() {
@@ -51,11 +53,9 @@ function withRunTree(runTree, fn) {
51
53
  storage.run(runTree, () => void Promise.resolve(fn()).then(resolve).catch(reject));
52
54
  });
53
55
  }
54
- exports.withRunTree = withRunTree;
55
56
  exports.ROOT = Symbol.for("langsmith:traceable:root");
56
57
  function isTraceableFunction(x
57
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
59
  ) {
59
60
  return typeof x === "function" && "langsmith:traceable" in x;
60
61
  }
61
- exports.isTraceableFunction = isTraceableFunction;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ROOT = exports.withRunTree = exports.isTraceableFunction = exports.getCurrentRunTree = exports.traceable = void 0;
3
+ exports.ROOT = exports.withRunTree = exports.isTraceableFunction = exports.getCurrentRunTree = void 0;
4
+ exports.traceable = traceable;
4
5
  const node_async_hooks_1 = require("node:async_hooks");
5
6
  const run_trees_js_1 = require("./run_trees.cjs");
6
7
  const env_js_1 = require("./env.cjs");
@@ -189,7 +190,6 @@ const convertSerializableArg = (arg) => {
189
190
  if (prop === "next" || prop === "return" || prop === "throw") {
190
191
  const bound = arg[prop]?.bind(arg);
191
192
  return (...args) => {
192
- // @ts-expect-error TS cannot infer the argument types for the bound function
193
193
  const next = bound?.(...args);
194
194
  if (next != null)
195
195
  proxyState.push(next);
@@ -546,7 +546,6 @@ function traceable(wrappedFunc, config) {
546
546
  });
547
547
  return traceableFunc;
548
548
  }
549
- exports.traceable = traceable;
550
549
  var traceable_js_2 = require("./singletons/traceable.cjs");
551
550
  Object.defineProperty(exports, "getCurrentRunTree", { enumerable: true, get: function () { return traceable_js_2.getCurrentRunTree; } });
552
551
  Object.defineProperty(exports, "isTraceableFunction", { enumerable: true, get: function () { return traceable_js_2.isTraceableFunction; } });
package/dist/traceable.js CHANGED
@@ -186,7 +186,6 @@ const convertSerializableArg = (arg) => {
186
186
  if (prop === "next" || prop === "return" || prop === "throw") {
187
187
  const bound = arg[prop]?.bind(arg);
188
188
  return (...args) => {
189
- // @ts-expect-error TS cannot infer the argument types for the bound function
190
189
  const next = bound?.(...args);
191
190
  if (next != null)
192
191
  proxyState.push(next);
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.assertUuid = void 0;
36
+ exports.assertUuid = assertUuid;
27
37
  const uuid = __importStar(require("uuid"));
28
38
  function assertUuid(str, which) {
29
39
  if (!uuid.validate(str)) {
@@ -34,4 +44,3 @@ function assertUuid(str, which) {
34
44
  }
35
45
  return str;
36
46
  }
37
- exports.assertUuid = assertUuid;