@langchain/core 0.3.10-rc.0 → 0.3.10

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/context.cjs CHANGED
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContextVariable = exports.setContextVariable = void 0;
4
4
  /* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
5
5
  const node_async_hooks_1 = require("node:async_hooks");
6
+ const langsmith_1 = require("langsmith");
7
+ const run_trees_1 = require("langsmith/run_trees");
6
8
  const index_js_1 = require("./singletons/index.cjs");
7
9
  index_js_1.AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new node_async_hooks_1.AsyncLocalStorage());
8
10
  /**
@@ -60,11 +62,13 @@ function setContextVariable(name, value) {
60
62
  const runTree = index_js_1.AsyncLocalStorageProviderSingleton.getInstance().getStore();
61
63
  const contextVars = { ...runTree?.[index_js_1._CONTEXT_VARIABLES_KEY] };
62
64
  contextVars[name] = value;
65
+ let newValue = {};
66
+ if ((0, run_trees_1.isRunTree)(runTree)) {
67
+ newValue = new langsmith_1.RunTree(runTree);
68
+ }
63
69
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- index_js_1.AsyncLocalStorageProviderSingleton.getInstance().enterWith({
65
- ...runTree,
66
- [index_js_1._CONTEXT_VARIABLES_KEY]: contextVars,
67
- });
70
+ newValue[index_js_1._CONTEXT_VARIABLES_KEY] = contextVars;
71
+ index_js_1.AsyncLocalStorageProviderSingleton.getInstance().enterWith(newValue);
68
72
  }
69
73
  exports.setContextVariable = setContextVariable;
70
74
  /**
package/dist/context.js CHANGED
@@ -1,5 +1,7 @@
1
1
  /* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { RunTree } from "langsmith";
4
+ import { isRunTree } from "langsmith/run_trees";
3
5
  import { _CONTEXT_VARIABLES_KEY, AsyncLocalStorageProviderSingleton, } from "./singletons/index.js";
4
6
  AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new AsyncLocalStorage());
5
7
  /**
@@ -57,11 +59,13 @@ export function setContextVariable(name, value) {
57
59
  const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore();
58
60
  const contextVars = { ...runTree?.[_CONTEXT_VARIABLES_KEY] };
59
61
  contextVars[name] = value;
62
+ let newValue = {};
63
+ if (isRunTree(runTree)) {
64
+ newValue = new RunTree(runTree);
65
+ }
60
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- AsyncLocalStorageProviderSingleton.getInstance().enterWith({
62
- ...runTree,
63
- [_CONTEXT_VARIABLES_KEY]: contextVars,
64
- });
67
+ newValue[_CONTEXT_VARIABLES_KEY] = contextVars;
68
+ AsyncLocalStorageProviderSingleton.getInstance().enterWith(newValue);
65
69
  }
66
70
  /**
67
71
  * Get the value of a previously set context variable. Context variables
@@ -11,6 +11,9 @@ class MockAsyncLocalStorage {
11
11
  run(_store, callback) {
12
12
  return callback();
13
13
  }
14
+ enterWith(_store) {
15
+ return undefined;
16
+ }
14
17
  }
15
18
  exports.MockAsyncLocalStorage = MockAsyncLocalStorage;
16
19
  const mockAsyncLocalStorage = new MockAsyncLocalStorage();
@@ -1,10 +1,12 @@
1
1
  export interface AsyncLocalStorageInterface {
2
2
  getStore: () => any | undefined;
3
3
  run: <T>(store: any, callback: () => T) => T;
4
+ enterWith: (store: any) => void;
4
5
  }
5
6
  export declare class MockAsyncLocalStorage implements AsyncLocalStorageInterface {
6
7
  getStore(): any;
7
8
  run<T>(_store: any, callback: () => T): T;
9
+ enterWith(_store: any): undefined;
8
10
  }
9
11
  export declare const _CONTEXT_VARIABLES_KEY: unique symbol;
10
12
  declare class AsyncLocalStorageProvider {
@@ -8,6 +8,9 @@ export class MockAsyncLocalStorage {
8
8
  run(_store, callback) {
9
9
  return callback();
10
10
  }
11
+ enterWith(_store) {
12
+ return undefined;
13
+ }
11
14
  }
12
15
  const mockAsyncLocalStorage = new MockAsyncLocalStorage();
13
16
  const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.10-rc.0",
3
+ "version": "0.3.10",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {
@@ -37,7 +37,7 @@
37
37
  "camelcase": "6",
38
38
  "decamelize": "1.2.0",
39
39
  "js-tiktoken": "^1.0.12",
40
- "langsmith": "^0.1.64",
40
+ "langsmith": "^0.1.65",
41
41
  "mustache": "^4.2.0",
42
42
  "p-queue": "^6.6.2",
43
43
  "p-retry": "4",