langsmith 0.3.69 → 0.3.71

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/client.cjs CHANGED
@@ -165,7 +165,7 @@ class AutoBatchQueue {
165
165
  this.sizeBytes += size;
166
166
  return itemPromise;
167
167
  }
168
- pop(upToSizeBytes) {
168
+ pop({ upToSizeBytes, upToSize, }) {
169
169
  if (upToSizeBytes < 1) {
170
170
  throw new Error("Number of bytes to pop off may not be less than 1.");
171
171
  }
@@ -173,7 +173,8 @@ class AutoBatchQueue {
173
173
  let poppedSizeBytes = 0;
174
174
  // Pop items until we reach or exceed the size limit
175
175
  while (poppedSizeBytes + (this.peek()?.size ?? 0) < upToSizeBytes &&
176
- this.items.length > 0) {
176
+ this.items.length > 0 &&
177
+ popped.length < upToSize) {
177
178
  const item = this.items.shift();
178
179
  if (item) {
179
180
  popped.push(item);
@@ -204,6 +205,8 @@ class AutoBatchQueue {
204
205
  exports.AutoBatchQueue = AutoBatchQueue;
205
206
  exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
206
207
  const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
208
+ /** Maximum number of operations to batch in a single request. */
209
+ const DEFAULT_BATCH_SIZE_LIMIT = 100;
207
210
  const DEFAULT_API_URL = "https://api.smith.langchain.com";
208
211
  class Client {
209
212
  get _fetch() {
@@ -312,6 +315,12 @@ class Client {
312
315
  writable: true,
313
316
  value: void 0
314
317
  });
318
+ Object.defineProperty(this, "batchSizeLimit", {
319
+ enumerable: true,
320
+ configurable: true,
321
+ writable: true,
322
+ value: void 0
323
+ });
315
324
  Object.defineProperty(this, "fetchOptions", {
316
325
  enumerable: true,
317
326
  configurable: true,
@@ -419,6 +428,7 @@ class Client {
419
428
  this.blockOnRootRunFinalization =
420
429
  config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
421
430
  this.batchSizeBytesLimit = config.batchSizeBytesLimit;
431
+ this.batchSizeLimit = config.batchSizeLimit;
422
432
  this.fetchOptions = config.fetchOptions || {};
423
433
  this.manualFlushMode = config.manualFlushMode ?? this.manualFlushMode;
424
434
  if ((0, env_js_1.getOtelEnabled)()) {
@@ -660,14 +670,26 @@ class Client {
660
670
  serverInfo.batch_ingest_config?.size_limit_bytes ??
661
671
  exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES);
662
672
  }
673
+ /**
674
+ * Get the maximum number of operations to batch in a single request.
675
+ */
676
+ async _getBatchSizeLimit() {
677
+ const serverInfo = await this._ensureServerInfo();
678
+ return (this.batchSizeLimit ??
679
+ serverInfo.batch_ingest_config?.size_limit ??
680
+ DEFAULT_BATCH_SIZE_LIMIT);
681
+ }
663
682
  async _getDatasetExamplesMultiPartSupport() {
664
683
  const serverInfo = await this._ensureServerInfo();
665
684
  return (serverInfo.instance_flags?.dataset_examples_multipart_enabled ?? false);
666
685
  }
667
- drainAutoBatchQueue(batchSizeLimit) {
686
+ drainAutoBatchQueue({ batchSizeLimitBytes, batchSizeLimit, }) {
668
687
  const promises = [];
669
688
  while (this.autoBatchQueue.items.length > 0) {
670
- const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
689
+ const [batch, done] = this.autoBatchQueue.pop({
690
+ upToSizeBytes: batchSizeLimitBytes,
691
+ upToSize: batchSizeLimit,
692
+ });
671
693
  if (!batch.length) {
672
694
  done();
673
695
  break;
@@ -766,13 +788,21 @@ class Client {
766
788
  return itemPromise;
767
789
  }
768
790
  const sizeLimitBytes = await this._getBatchSizeLimitBytes();
769
- if (this.autoBatchQueue.sizeBytes > sizeLimitBytes) {
770
- void this.drainAutoBatchQueue(sizeLimitBytes);
791
+ const sizeLimit = await this._getBatchSizeLimit();
792
+ if (this.autoBatchQueue.sizeBytes > sizeLimitBytes ||
793
+ this.autoBatchQueue.items.length > sizeLimit) {
794
+ void this.drainAutoBatchQueue({
795
+ batchSizeLimitBytes: sizeLimitBytes,
796
+ batchSizeLimit: sizeLimit,
797
+ });
771
798
  }
772
799
  if (this.autoBatchQueue.items.length > 0) {
773
800
  this.autoBatchTimeout = setTimeout(() => {
774
801
  this.autoBatchTimeout = undefined;
775
- void this.drainAutoBatchQueue(sizeLimitBytes);
802
+ void this.drainAutoBatchQueue({
803
+ batchSizeLimitBytes: sizeLimitBytes,
804
+ batchSizeLimit: sizeLimit,
805
+ });
776
806
  }, this.autoBatchAggregationDelayMs);
777
807
  }
778
808
  return itemPromise;
@@ -828,7 +858,11 @@ class Client {
828
858
  */
829
859
  async flush() {
830
860
  const sizeLimitBytes = await this._getBatchSizeLimitBytes();
831
- await this.drainAutoBatchQueue(sizeLimitBytes);
861
+ const sizeLimit = await this._getBatchSizeLimit();
862
+ await this.drainAutoBatchQueue({
863
+ batchSizeLimitBytes: sizeLimitBytes,
864
+ batchSizeLimit: sizeLimit,
865
+ });
832
866
  }
833
867
  _cloneCurrentOTELContext() {
834
868
  const otel_trace = (0, otel_js_1.getOTELTrace)();
package/dist/client.d.ts CHANGED
@@ -12,7 +12,10 @@ export interface ClientConfig {
12
12
  hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
13
13
  hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
14
14
  autoBatchTracing?: boolean;
15
+ /** Maximum size of a batch of runs in bytes. */
15
16
  batchSizeBytesLimit?: number;
17
+ /** Maximum number of operations to batch in a single request. */
18
+ batchSizeLimit?: number;
16
19
  blockOnRootRunFinalization?: boolean;
17
20
  traceBatchConcurrency?: number;
18
21
  fetchOptions?: RequestInit;
@@ -292,7 +295,10 @@ export declare class AutoBatchQueue {
292
295
  apiUrl?: string;
293
296
  };
294
297
  push(item: AutoBatchQueueItem): Promise<void>;
295
- pop(upToSizeBytes: number): [AutoBatchQueueItem[], () => void];
298
+ pop({ upToSizeBytes, upToSize, }: {
299
+ upToSizeBytes: number;
300
+ upToSize: number;
301
+ }): [AutoBatchQueueItem[], () => void];
296
302
  }
297
303
  export declare const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES: number;
298
304
  export declare class Client implements LangSmithTracingClientInterface {
@@ -313,6 +319,7 @@ export declare class Client implements LangSmithTracingClientInterface {
313
319
  private autoBatchTimeout;
314
320
  private autoBatchAggregationDelayMs;
315
321
  private batchSizeBytesLimit?;
322
+ private batchSizeLimit?;
316
323
  private fetchOptions;
317
324
  private settings;
318
325
  private blockOnRootRunFinalization;
@@ -346,6 +353,10 @@ export declare class Client implements LangSmithTracingClientInterface {
346
353
  private _shouldSample;
347
354
  private _filterForSampling;
348
355
  private _getBatchSizeLimitBytes;
356
+ /**
357
+ * Get the maximum number of operations to batch in a single request.
358
+ */
359
+ private _getBatchSizeLimit;
349
360
  private _getDatasetExamplesMultiPartSupport;
350
361
  private drainAutoBatchQueue;
351
362
  private _processBatch;
package/dist/client.js CHANGED
@@ -128,7 +128,7 @@ export class AutoBatchQueue {
128
128
  this.sizeBytes += size;
129
129
  return itemPromise;
130
130
  }
131
- pop(upToSizeBytes) {
131
+ pop({ upToSizeBytes, upToSize, }) {
132
132
  if (upToSizeBytes < 1) {
133
133
  throw new Error("Number of bytes to pop off may not be less than 1.");
134
134
  }
@@ -136,7 +136,8 @@ export class AutoBatchQueue {
136
136
  let poppedSizeBytes = 0;
137
137
  // Pop items until we reach or exceed the size limit
138
138
  while (poppedSizeBytes + (this.peek()?.size ?? 0) < upToSizeBytes &&
139
- this.items.length > 0) {
139
+ this.items.length > 0 &&
140
+ popped.length < upToSize) {
140
141
  const item = this.items.shift();
141
142
  if (item) {
142
143
  popped.push(item);
@@ -166,6 +167,8 @@ export class AutoBatchQueue {
166
167
  }
167
168
  export const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
168
169
  const SERVER_INFO_REQUEST_TIMEOUT_MS = 10000;
170
+ /** Maximum number of operations to batch in a single request. */
171
+ const DEFAULT_BATCH_SIZE_LIMIT = 100;
169
172
  const DEFAULT_API_URL = "https://api.smith.langchain.com";
170
173
  export class Client {
171
174
  get _fetch() {
@@ -274,6 +277,12 @@ export class Client {
274
277
  writable: true,
275
278
  value: void 0
276
279
  });
280
+ Object.defineProperty(this, "batchSizeLimit", {
281
+ enumerable: true,
282
+ configurable: true,
283
+ writable: true,
284
+ value: void 0
285
+ });
277
286
  Object.defineProperty(this, "fetchOptions", {
278
287
  enumerable: true,
279
288
  configurable: true,
@@ -381,6 +390,7 @@ export class Client {
381
390
  this.blockOnRootRunFinalization =
382
391
  config.blockOnRootRunFinalization ?? this.blockOnRootRunFinalization;
383
392
  this.batchSizeBytesLimit = config.batchSizeBytesLimit;
393
+ this.batchSizeLimit = config.batchSizeLimit;
384
394
  this.fetchOptions = config.fetchOptions || {};
385
395
  this.manualFlushMode = config.manualFlushMode ?? this.manualFlushMode;
386
396
  if (getOtelEnabled()) {
@@ -622,14 +632,26 @@ export class Client {
622
632
  serverInfo.batch_ingest_config?.size_limit_bytes ??
623
633
  DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES);
624
634
  }
635
+ /**
636
+ * Get the maximum number of operations to batch in a single request.
637
+ */
638
+ async _getBatchSizeLimit() {
639
+ const serverInfo = await this._ensureServerInfo();
640
+ return (this.batchSizeLimit ??
641
+ serverInfo.batch_ingest_config?.size_limit ??
642
+ DEFAULT_BATCH_SIZE_LIMIT);
643
+ }
625
644
  async _getDatasetExamplesMultiPartSupport() {
626
645
  const serverInfo = await this._ensureServerInfo();
627
646
  return (serverInfo.instance_flags?.dataset_examples_multipart_enabled ?? false);
628
647
  }
629
- drainAutoBatchQueue(batchSizeLimit) {
648
+ drainAutoBatchQueue({ batchSizeLimitBytes, batchSizeLimit, }) {
630
649
  const promises = [];
631
650
  while (this.autoBatchQueue.items.length > 0) {
632
- const [batch, done] = this.autoBatchQueue.pop(batchSizeLimit);
651
+ const [batch, done] = this.autoBatchQueue.pop({
652
+ upToSizeBytes: batchSizeLimitBytes,
653
+ upToSize: batchSizeLimit,
654
+ });
633
655
  if (!batch.length) {
634
656
  done();
635
657
  break;
@@ -728,13 +750,21 @@ export class Client {
728
750
  return itemPromise;
729
751
  }
730
752
  const sizeLimitBytes = await this._getBatchSizeLimitBytes();
731
- if (this.autoBatchQueue.sizeBytes > sizeLimitBytes) {
732
- void this.drainAutoBatchQueue(sizeLimitBytes);
753
+ const sizeLimit = await this._getBatchSizeLimit();
754
+ if (this.autoBatchQueue.sizeBytes > sizeLimitBytes ||
755
+ this.autoBatchQueue.items.length > sizeLimit) {
756
+ void this.drainAutoBatchQueue({
757
+ batchSizeLimitBytes: sizeLimitBytes,
758
+ batchSizeLimit: sizeLimit,
759
+ });
733
760
  }
734
761
  if (this.autoBatchQueue.items.length > 0) {
735
762
  this.autoBatchTimeout = setTimeout(() => {
736
763
  this.autoBatchTimeout = undefined;
737
- void this.drainAutoBatchQueue(sizeLimitBytes);
764
+ void this.drainAutoBatchQueue({
765
+ batchSizeLimitBytes: sizeLimitBytes,
766
+ batchSizeLimit: sizeLimit,
767
+ });
738
768
  }, this.autoBatchAggregationDelayMs);
739
769
  }
740
770
  return itemPromise;
@@ -790,7 +820,11 @@ export class Client {
790
820
  */
791
821
  async flush() {
792
822
  const sizeLimitBytes = await this._getBatchSizeLimitBytes();
793
- await this.drainAutoBatchQueue(sizeLimitBytes);
823
+ const sizeLimit = await this._getBatchSizeLimit();
824
+ await this.drainAutoBatchQueue({
825
+ batchSizeLimitBytes: sizeLimitBytes,
826
+ batchSizeLimit: sizeLimit,
827
+ });
794
828
  }
795
829
  _cloneCurrentOTELContext() {
796
830
  const otel_trace = getOTELTrace();
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.69";
13
+ exports.__version__ = "0.3.71";
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.69";
6
+ export declare const __version__ = "0.3.71";
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.69";
6
+ export const __version__ = "0.3.71";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.69",
3
+ "version": "0.3.71",
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": [