langsmith 0.3.9-rc.0 → 0.3.9-rc.2

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.
@@ -432,6 +432,28 @@ class RunTree {
432
432
  toJSON() {
433
433
  return this._convertToCreate(this, undefined, false);
434
434
  }
435
+ /**
436
+ * Add an event to the run tree.
437
+ * @param event - A single event or string to add
438
+ */
439
+ addEvent(event) {
440
+ if (!this.events) {
441
+ this.events = [];
442
+ }
443
+ if (typeof event === "string") {
444
+ this.events.push({
445
+ name: "event",
446
+ time: new Date().toISOString(),
447
+ message: event,
448
+ });
449
+ }
450
+ else {
451
+ this.events.push({
452
+ ...event,
453
+ time: event.time ?? new Date().toISOString(),
454
+ });
455
+ }
456
+ }
435
457
  static fromRunnableConfig(parentConfig, props) {
436
458
  // We only handle the callback manager case for now
437
459
  const callbackManager = parentConfig?.callbacks;
@@ -87,6 +87,11 @@ export declare class RunTree implements BaseRun {
87
87
  postRun(excludeChildRuns?: boolean): Promise<void>;
88
88
  patchRun(): Promise<void>;
89
89
  toJSON(): RunCreate;
90
+ /**
91
+ * Add an event to the run tree.
92
+ * @param event - A single event or string to add
93
+ */
94
+ addEvent(event: RunEvent | string): void;
90
95
  static fromRunnableConfig(parentConfig: RunnableConfigLike, props: RunTreeConfig): RunTree;
91
96
  static fromDottedOrder(dottedOrder: string): RunTree | undefined;
92
97
  static fromHeaders(headers: Record<string, string | string[]> | HeadersLike, inheritArgs?: RunTreeConfig): RunTree | undefined;
@@ -96,5 +101,12 @@ export declare class RunTree implements BaseRun {
96
101
  };
97
102
  }
98
103
  export declare function isRunTree(x?: unknown): x is RunTree;
104
+ export interface RunEvent {
105
+ name?: string;
106
+ time?: string;
107
+ message?: string;
108
+ kwargs?: Record<string, unknown>;
109
+ [key: string]: unknown;
110
+ }
99
111
  export declare function isRunnableConfigLike(x?: unknown): x is RunnableConfigLike;
100
112
  export {};
package/dist/run_trees.js CHANGED
@@ -405,6 +405,28 @@ export class RunTree {
405
405
  toJSON() {
406
406
  return this._convertToCreate(this, undefined, false);
407
407
  }
408
+ /**
409
+ * Add an event to the run tree.
410
+ * @param event - A single event or string to add
411
+ */
412
+ addEvent(event) {
413
+ if (!this.events) {
414
+ this.events = [];
415
+ }
416
+ if (typeof event === "string") {
417
+ this.events.push({
418
+ name: "event",
419
+ time: new Date().toISOString(),
420
+ message: event,
421
+ });
422
+ }
423
+ else {
424
+ this.events.push({
425
+ ...event,
426
+ time: event.time ?? new Date().toISOString(),
427
+ });
428
+ }
429
+ }
408
430
  static fromRunnableConfig(parentConfig, props) {
409
431
  // We only handle the callback manager case for now
410
432
  const callbackManager = parentConfig?.callbacks;
@@ -363,19 +363,14 @@ function traceable(wrappedFunc, config) {
363
363
  controller.close();
364
364
  break;
365
365
  }
366
- if (currentRunTree?.run_type === "llm") {
367
- if (currentRunTree.events === undefined) {
368
- currentRunTree.events = [];
369
- }
370
- currentRunTree.events.push({
366
+ chunks.push(result.value);
367
+ // Add new_token event for streaming LLM runs
368
+ if (currentRunTree && currentRunTree.run_type === "llm") {
369
+ currentRunTree.addEvent({
371
370
  name: "new_token",
372
- time: new Date().toISOString(),
373
- kwargs: {
374
- token: result.value,
375
- },
371
+ kwargs: { token: result.value },
376
372
  });
377
373
  }
378
- chunks.push(result.value);
379
374
  controller.enqueue(result.value);
380
375
  }
381
376
  },
@@ -401,19 +396,14 @@ function traceable(wrappedFunc, config) {
401
396
  finished = true;
402
397
  break;
403
398
  }
404
- if (currentRunTree?.run_type === "llm") {
405
- if (currentRunTree.events === undefined) {
406
- currentRunTree.events = [];
407
- }
408
- currentRunTree.events.push({
399
+ chunks.push(value);
400
+ // Add new_token event for streaming LLM runs
401
+ if (currentRunTree && currentRunTree.run_type === "llm") {
402
+ currentRunTree.addEvent({
409
403
  name: "new_token",
410
- time: new Date().toISOString(),
411
- kwargs: {
412
- token: value,
413
- },
404
+ kwargs: { token: value },
414
405
  });
415
406
  }
416
- chunks.push(value);
417
407
  yield value;
418
408
  }
419
409
  }
package/dist/traceable.js CHANGED
@@ -360,19 +360,14 @@ export function traceable(wrappedFunc, config) {
360
360
  controller.close();
361
361
  break;
362
362
  }
363
- if (currentRunTree?.run_type === "llm") {
364
- if (currentRunTree.events === undefined) {
365
- currentRunTree.events = [];
366
- }
367
- currentRunTree.events.push({
363
+ chunks.push(result.value);
364
+ // Add new_token event for streaming LLM runs
365
+ if (currentRunTree && currentRunTree.run_type === "llm") {
366
+ currentRunTree.addEvent({
368
367
  name: "new_token",
369
- time: new Date().toISOString(),
370
- kwargs: {
371
- token: result.value,
372
- },
368
+ kwargs: { token: result.value },
373
369
  });
374
370
  }
375
- chunks.push(result.value);
376
371
  controller.enqueue(result.value);
377
372
  }
378
373
  },
@@ -398,19 +393,14 @@ export function traceable(wrappedFunc, config) {
398
393
  finished = true;
399
394
  break;
400
395
  }
401
- if (currentRunTree?.run_type === "llm") {
402
- if (currentRunTree.events === undefined) {
403
- currentRunTree.events = [];
404
- }
405
- currentRunTree.events.push({
396
+ chunks.push(value);
397
+ // Add new_token event for streaming LLM runs
398
+ if (currentRunTree && currentRunTree.run_type === "llm") {
399
+ currentRunTree.addEvent({
406
400
  name: "new_token",
407
- time: new Date().toISOString(),
408
- kwargs: {
409
- token: value,
410
- },
401
+ kwargs: { token: value },
411
402
  });
412
403
  }
413
- chunks.push(value);
414
404
  yield value;
415
405
  }
416
406
  }
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.wrapEvaluator = exports.generateWrapperFromJestlikeMethods = exports._objectHash = exports.logOutputs = exports.logFeedback = void 0;
34
+ exports.wrapEvaluator = exports.isInTestContext = exports.generateWrapperFromJestlikeMethods = exports._objectHash = exports.logOutputs = exports.logFeedback = void 0;
35
35
  const crypto_1 = __importDefault(require("crypto"));
36
36
  const uuid_1 = require("uuid");
37
37
  const os = __importStar(require("node:os"));
@@ -581,6 +581,11 @@ function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
581
581
  };
582
582
  }
583
583
  exports.generateWrapperFromJestlikeMethods = generateWrapperFromJestlikeMethods;
584
+ function isInTestContext() {
585
+ const context = globals_js_1.testWrapperAsyncLocalStorageInstance.getStore();
586
+ return context !== undefined;
587
+ }
588
+ exports.isInTestContext = isInTestContext;
584
589
  var evaluatedBy_js_1 = require("./vendor/evaluatedBy.cjs");
585
590
  Object.defineProperty(exports, "wrapEvaluator", { enumerable: true, get: function () { return evaluatedBy_js_1.wrapEvaluator; } });
586
591
  __exportStar(require("./types.cjs"), exports);
@@ -90,5 +90,6 @@ export declare function generateWrapperFromJestlikeMethods(methods: Record<strin
90
90
  toBeAbsoluteCloseTo: typeof toBeAbsoluteCloseTo;
91
91
  toBeSemanticCloseTo: typeof toBeSemanticCloseTo;
92
92
  };
93
+ export declare function isInTestContext(): boolean;
93
94
  export { wrapEvaluator } from "./vendor/evaluatedBy.js";
94
95
  export * from "./types.js";
@@ -545,5 +545,9 @@ export function generateWrapperFromJestlikeMethods(methods, testRunnerName) {
545
545
  toBeSemanticCloseTo,
546
546
  };
547
547
  }
548
+ export function isInTestContext() {
549
+ const context = testWrapperAsyncLocalStorageInstance.getStore();
550
+ return context !== undefined;
551
+ }
548
552
  export { wrapEvaluator } from "./vendor/evaluatedBy.js";
549
553
  export * from "./types.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.9-rc.0",
3
+ "version": "0.3.9-rc.2",
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": [