@langchain/core 0.3.10-rc.0 → 0.3.11
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 +8 -4
- package/dist/context.d.ts +2 -2
- package/dist/context.js +8 -4
- package/dist/singletons/index.cjs +3 -0
- package/dist/singletons/index.d.ts +2 -0
- package/dist/singletons/index.js +3 -0
- package/dist/tools/index.cjs +17 -3
- package/dist/tools/index.js +17 -3
- package/package.json +3 -3
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.
|
|
65
|
-
|
|
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.d.ts
CHANGED
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
* @param name The name of the context variable.
|
|
49
49
|
* @param value The value to set.
|
|
50
50
|
*/
|
|
51
|
-
export declare function setContextVariable(name: PropertyKey, value:
|
|
51
|
+
export declare function setContextVariable<T>(name: PropertyKey, value: T): void;
|
|
52
52
|
/**
|
|
53
53
|
* Get the value of a previously set context variable. Context variables
|
|
54
54
|
* are scoped to any child runnables called by the current runnable,
|
|
@@ -98,4 +98,4 @@ export declare function setContextVariable(name: PropertyKey, value: any): void;
|
|
|
98
98
|
*
|
|
99
99
|
* @param name The name of the context variable.
|
|
100
100
|
*/
|
|
101
|
-
export declare function getContextVariable(name: PropertyKey):
|
|
101
|
+
export declare function getContextVariable<T = any>(name: PropertyKey): T | undefined;
|
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
|
-
|
|
62
|
-
|
|
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
|
|
@@ -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 {
|
package/dist/singletons/index.js
CHANGED
|
@@ -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/dist/tools/index.cjs
CHANGED
|
@@ -305,9 +305,23 @@ function tool(func, fields) {
|
|
|
305
305
|
description: fields.description ??
|
|
306
306
|
fields.schema?.description ??
|
|
307
307
|
`${fields.name} tool`,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
308
|
+
func: async (input, runManager, config) => {
|
|
309
|
+
return new Promise((resolve, reject) => {
|
|
310
|
+
const childConfig = (0, config_js_1.patchConfig)(config, {
|
|
311
|
+
callbacks: runManager?.getChild(),
|
|
312
|
+
});
|
|
313
|
+
void index_js_1.AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
|
|
314
|
+
try {
|
|
315
|
+
// TS doesn't restrict the type here based on the guard above
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
317
|
+
resolve(func(input, childConfig));
|
|
318
|
+
}
|
|
319
|
+
catch (e) {
|
|
320
|
+
reject(e);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
},
|
|
311
325
|
});
|
|
312
326
|
}
|
|
313
327
|
const description = fields.description ?? fields.schema.description ?? `${fields.name} tool`;
|
package/dist/tools/index.js
CHANGED
|
@@ -297,9 +297,23 @@ export function tool(func, fields) {
|
|
|
297
297
|
description: fields.description ??
|
|
298
298
|
fields.schema?.description ??
|
|
299
299
|
`${fields.name} tool`,
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
300
|
+
func: async (input, runManager, config) => {
|
|
301
|
+
return new Promise((resolve, reject) => {
|
|
302
|
+
const childConfig = patchConfig(config, {
|
|
303
|
+
callbacks: runManager?.getChild(),
|
|
304
|
+
});
|
|
305
|
+
void AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
|
|
306
|
+
try {
|
|
307
|
+
// TS doesn't restrict the type here based on the guard above
|
|
308
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
309
|
+
resolve(func(input, childConfig));
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
reject(e);
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
},
|
|
303
317
|
});
|
|
304
318
|
}
|
|
305
319
|
const description = fields.description ?? fields.schema.description ?? `${fields.name} tool`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
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.
|
|
40
|
+
"langsmith": "^0.1.65",
|
|
41
41
|
"mustache": "^4.2.0",
|
|
42
42
|
"p-queue": "^6.6.2",
|
|
43
43
|
"p-retry": "4",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"rimraf": "^5.0.1",
|
|
69
69
|
"ts-jest": "^29.1.0",
|
|
70
70
|
"typescript": "~5.1.6",
|
|
71
|
-
"web-streams-polyfill": "^
|
|
71
|
+
"web-streams-polyfill": "^4.0.0"
|
|
72
72
|
},
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|