@langchain/core 0.3.17 → 0.3.18
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/callbacks/manager.cjs +2 -30
- package/dist/callbacks/manager.d.ts +2 -30
- package/dist/callbacks/manager.js +2 -30
- package/dist/callbacks/promises.cjs +4 -43
- package/dist/callbacks/promises.d.ts +2 -11
- package/dist/callbacks/promises.js +2 -37
- package/dist/language_models/base.d.ts +2 -0
- package/dist/language_models/chat_models.cjs +3 -0
- package/dist/language_models/chat_models.js +3 -0
- package/dist/retrievers/index.cjs +52 -3
- package/dist/retrievers/index.d.ts +90 -4
- package/dist/retrievers/index.js +52 -3
- package/dist/singletons/async_local_storage/globals.cjs +12 -0
- package/dist/singletons/async_local_storage/globals.d.ts +8 -0
- package/dist/singletons/async_local_storage/globals.js +7 -0
- package/dist/singletons/async_local_storage/index.cjs +67 -0
- package/dist/singletons/async_local_storage/index.d.ts +15 -0
- package/dist/singletons/async_local_storage/index.js +63 -0
- package/dist/singletons/callbacks.cjs +66 -0
- package/dist/singletons/callbacks.d.ts +13 -0
- package/dist/singletons/callbacks.js +57 -0
- package/dist/singletons/index.cjs +5 -64
- package/dist/singletons/index.d.ts +2 -19
- package/dist/singletons/index.js +2 -62
- package/dist/singletons/tracer.cjs +19 -0
- package/dist/singletons/tracer.d.ts +2 -0
- package/dist/singletons/tracer.js +15 -0
- package/dist/tracers/tracer_langchain.cjs +2 -8
- package/dist/tracers/tracer_langchain.js +2 -8
- package/dist/vectorstores.cjs +267 -7
- package/dist/vectorstores.d.ts +519 -11
- package/dist/vectorstores.js +267 -7
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AsyncLocalStorageInterface } from "./globals.js";
|
|
2
|
+
export declare class MockAsyncLocalStorage implements AsyncLocalStorageInterface {
|
|
3
|
+
getStore(): any;
|
|
4
|
+
run<T>(_store: any, callback: () => T): T;
|
|
5
|
+
enterWith(_store: any): undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare const _CONTEXT_VARIABLES_KEY: unique symbol;
|
|
8
|
+
declare class AsyncLocalStorageProvider {
|
|
9
|
+
getInstance(): AsyncLocalStorageInterface;
|
|
10
|
+
getRunnableConfig(): any;
|
|
11
|
+
runWithConfig<T>(config: any, callback: () => T, avoidCreatingRootRunTree?: boolean): T;
|
|
12
|
+
initializeGlobalInstance(instance: AsyncLocalStorageInterface): void;
|
|
13
|
+
}
|
|
14
|
+
declare const AsyncLocalStorageProviderSingleton: AsyncLocalStorageProvider;
|
|
15
|
+
export { AsyncLocalStorageProviderSingleton, type AsyncLocalStorageInterface };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { RunTree } from "langsmith";
|
|
3
|
+
import { getGlobalAsyncLocalStorageInstance, setGlobalAsyncLocalStorageInstance, } from "./globals.js";
|
|
4
|
+
import { CallbackManager } from "../../callbacks/manager.js";
|
|
5
|
+
export class MockAsyncLocalStorage {
|
|
6
|
+
getStore() {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
run(_store, callback) {
|
|
10
|
+
return callback();
|
|
11
|
+
}
|
|
12
|
+
enterWith(_store) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const mockAsyncLocalStorage = new MockAsyncLocalStorage();
|
|
17
|
+
const LC_CHILD_KEY = Symbol.for("lc:child_config");
|
|
18
|
+
export const _CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
|
|
19
|
+
class AsyncLocalStorageProvider {
|
|
20
|
+
getInstance() {
|
|
21
|
+
return getGlobalAsyncLocalStorageInstance() ?? mockAsyncLocalStorage;
|
|
22
|
+
}
|
|
23
|
+
getRunnableConfig() {
|
|
24
|
+
const storage = this.getInstance();
|
|
25
|
+
// this has the runnable config
|
|
26
|
+
// which means that we should also have an instance of a LangChainTracer
|
|
27
|
+
// with the run map prepopulated
|
|
28
|
+
return storage.getStore()?.extra?.[LC_CHILD_KEY];
|
|
29
|
+
}
|
|
30
|
+
runWithConfig(config, callback, avoidCreatingRootRunTree) {
|
|
31
|
+
const callbackManager = CallbackManager._configureSync(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
|
|
32
|
+
const storage = this.getInstance();
|
|
33
|
+
const previousValue = storage.getStore();
|
|
34
|
+
const parentRunId = callbackManager?.getParentRunId();
|
|
35
|
+
const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name === "langchain_tracer");
|
|
36
|
+
let runTree;
|
|
37
|
+
if (langChainTracer && parentRunId) {
|
|
38
|
+
runTree = langChainTracer.convertToRunTree(parentRunId);
|
|
39
|
+
}
|
|
40
|
+
else if (!avoidCreatingRootRunTree) {
|
|
41
|
+
runTree = new RunTree({
|
|
42
|
+
name: "<runnable_lambda>",
|
|
43
|
+
tracingEnabled: false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (runTree) {
|
|
47
|
+
runTree.extra = { ...runTree.extra, [LC_CHILD_KEY]: config };
|
|
48
|
+
}
|
|
49
|
+
if (previousValue !== undefined &&
|
|
50
|
+
previousValue[_CONTEXT_VARIABLES_KEY] !== undefined) {
|
|
51
|
+
runTree[_CONTEXT_VARIABLES_KEY] =
|
|
52
|
+
previousValue[_CONTEXT_VARIABLES_KEY];
|
|
53
|
+
}
|
|
54
|
+
return storage.run(runTree, callback);
|
|
55
|
+
}
|
|
56
|
+
initializeGlobalInstance(instance) {
|
|
57
|
+
if (getGlobalAsyncLocalStorageInstance() === undefined) {
|
|
58
|
+
setGlobalAsyncLocalStorageInstance(instance);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();
|
|
63
|
+
export { AsyncLocalStorageProviderSingleton };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.awaitAllCallbacks = exports.consumeCallback = exports.getQueue = void 0;
|
|
8
|
+
const p_queue_1 = __importDefault(require("p-queue"));
|
|
9
|
+
const globals_js_1 = require("./async_local_storage/globals.cjs");
|
|
10
|
+
let queue;
|
|
11
|
+
/**
|
|
12
|
+
* Creates a queue using the p-queue library. The queue is configured to
|
|
13
|
+
* auto-start and has a concurrency of 1, meaning it will process tasks
|
|
14
|
+
* one at a time.
|
|
15
|
+
*/
|
|
16
|
+
function createQueue() {
|
|
17
|
+
const PQueue = "default" in p_queue_1.default ? p_queue_1.default.default : p_queue_1.default;
|
|
18
|
+
return new PQueue({
|
|
19
|
+
autoStart: true,
|
|
20
|
+
concurrency: 1,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function getQueue() {
|
|
24
|
+
if (typeof queue === "undefined") {
|
|
25
|
+
queue = createQueue();
|
|
26
|
+
}
|
|
27
|
+
return queue;
|
|
28
|
+
}
|
|
29
|
+
exports.getQueue = getQueue;
|
|
30
|
+
/**
|
|
31
|
+
* Consume a promise, either adding it to the queue or waiting for it to resolve
|
|
32
|
+
* @param promiseFn Promise to consume
|
|
33
|
+
* @param wait Whether to wait for the promise to resolve or resolve immediately
|
|
34
|
+
*/
|
|
35
|
+
async function consumeCallback(promiseFn, wait) {
|
|
36
|
+
if (wait === true) {
|
|
37
|
+
// Clear config since callbacks are not part of the root run
|
|
38
|
+
// Avoid using global singleton due to circuluar dependency issues
|
|
39
|
+
if ((0, globals_js_1.getGlobalAsyncLocalStorageInstance)() !== undefined) {
|
|
40
|
+
await (0, globals_js_1.getGlobalAsyncLocalStorageInstance)().run(undefined, async () => promiseFn());
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
await promiseFn();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
queue = getQueue();
|
|
48
|
+
void queue.add(async () => {
|
|
49
|
+
if ((0, globals_js_1.getGlobalAsyncLocalStorageInstance)() !== undefined) {
|
|
50
|
+
await (0, globals_js_1.getGlobalAsyncLocalStorageInstance)().run(undefined, async () => promiseFn());
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
await promiseFn();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.consumeCallback = consumeCallback;
|
|
59
|
+
/**
|
|
60
|
+
* Waits for all promises in the queue to resolve. If the queue is
|
|
61
|
+
* undefined, it immediately resolves a promise.
|
|
62
|
+
*/
|
|
63
|
+
function awaitAllCallbacks() {
|
|
64
|
+
return typeof queue !== "undefined" ? queue.onIdle() : Promise.resolve();
|
|
65
|
+
}
|
|
66
|
+
exports.awaitAllCallbacks = awaitAllCallbacks;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import PQueueMod from "p-queue";
|
|
2
|
+
export declare function getQueue(): PQueueMod.default<any, any>;
|
|
3
|
+
/**
|
|
4
|
+
* Consume a promise, either adding it to the queue or waiting for it to resolve
|
|
5
|
+
* @param promiseFn Promise to consume
|
|
6
|
+
* @param wait Whether to wait for the promise to resolve or resolve immediately
|
|
7
|
+
*/
|
|
8
|
+
export declare function consumeCallback<T>(promiseFn: () => Promise<T> | T | void, wait: boolean): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* Waits for all promises in the queue to resolve. If the queue is
|
|
11
|
+
* undefined, it immediately resolves a promise.
|
|
12
|
+
*/
|
|
13
|
+
export declare function awaitAllCallbacks(): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import PQueueMod from "p-queue";
|
|
3
|
+
import { getGlobalAsyncLocalStorageInstance } from "./async_local_storage/globals.js";
|
|
4
|
+
let queue;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a queue using the p-queue library. The queue is configured to
|
|
7
|
+
* auto-start and has a concurrency of 1, meaning it will process tasks
|
|
8
|
+
* one at a time.
|
|
9
|
+
*/
|
|
10
|
+
function createQueue() {
|
|
11
|
+
const PQueue = "default" in PQueueMod ? PQueueMod.default : PQueueMod;
|
|
12
|
+
return new PQueue({
|
|
13
|
+
autoStart: true,
|
|
14
|
+
concurrency: 1,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export function getQueue() {
|
|
18
|
+
if (typeof queue === "undefined") {
|
|
19
|
+
queue = createQueue();
|
|
20
|
+
}
|
|
21
|
+
return queue;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Consume a promise, either adding it to the queue or waiting for it to resolve
|
|
25
|
+
* @param promiseFn Promise to consume
|
|
26
|
+
* @param wait Whether to wait for the promise to resolve or resolve immediately
|
|
27
|
+
*/
|
|
28
|
+
export async function consumeCallback(promiseFn, wait) {
|
|
29
|
+
if (wait === true) {
|
|
30
|
+
// Clear config since callbacks are not part of the root run
|
|
31
|
+
// Avoid using global singleton due to circuluar dependency issues
|
|
32
|
+
if (getGlobalAsyncLocalStorageInstance() !== undefined) {
|
|
33
|
+
await getGlobalAsyncLocalStorageInstance().run(undefined, async () => promiseFn());
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
await promiseFn();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
queue = getQueue();
|
|
41
|
+
void queue.add(async () => {
|
|
42
|
+
if (getGlobalAsyncLocalStorageInstance() !== undefined) {
|
|
43
|
+
await getGlobalAsyncLocalStorageInstance().run(undefined, async () => promiseFn());
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
await promiseFn();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Waits for all promises in the queue to resolve. If the queue is
|
|
53
|
+
* undefined, it immediately resolves a promise.
|
|
54
|
+
*/
|
|
55
|
+
export function awaitAllCallbacks() {
|
|
56
|
+
return typeof queue !== "undefined" ? queue.onIdle() : Promise.resolve();
|
|
57
|
+
}
|
|
@@ -1,67 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MockAsyncLocalStorage = exports._CONTEXT_VARIABLES_KEY = exports.AsyncLocalStorageProviderSingleton = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
run(_store, callback) {
|
|
12
|
-
return callback();
|
|
13
|
-
}
|
|
14
|
-
enterWith(_store) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
exports.MockAsyncLocalStorage = MockAsyncLocalStorage;
|
|
19
|
-
const mockAsyncLocalStorage = new MockAsyncLocalStorage();
|
|
20
|
-
const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
|
|
21
|
-
const LC_CHILD_KEY = Symbol.for("lc:child_config");
|
|
22
|
-
exports._CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
|
|
23
|
-
class AsyncLocalStorageProvider {
|
|
24
|
-
getInstance() {
|
|
25
|
-
return globalThis[TRACING_ALS_KEY] ?? mockAsyncLocalStorage;
|
|
26
|
-
}
|
|
27
|
-
getRunnableConfig() {
|
|
28
|
-
const storage = this.getInstance();
|
|
29
|
-
// this has the runnable config
|
|
30
|
-
// which means that we should also have an instance of a LangChainTracer
|
|
31
|
-
// with the run map prepopulated
|
|
32
|
-
return storage.getStore()?.extra?.[LC_CHILD_KEY];
|
|
33
|
-
}
|
|
34
|
-
runWithConfig(config, callback, avoidCreatingRootRunTree) {
|
|
35
|
-
const callbackManager = manager_js_1.CallbackManager._configureSync(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
|
|
36
|
-
const storage = this.getInstance();
|
|
37
|
-
const previousValue = storage.getStore();
|
|
38
|
-
const parentRunId = callbackManager?.getParentRunId();
|
|
39
|
-
const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name === "langchain_tracer");
|
|
40
|
-
let runTree;
|
|
41
|
-
if (langChainTracer && parentRunId) {
|
|
42
|
-
runTree = langChainTracer.convertToRunTree(parentRunId);
|
|
43
|
-
}
|
|
44
|
-
else if (!avoidCreatingRootRunTree) {
|
|
45
|
-
runTree = new langsmith_1.RunTree({
|
|
46
|
-
name: "<runnable_lambda>",
|
|
47
|
-
tracingEnabled: false,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
if (runTree) {
|
|
51
|
-
runTree.extra = { ...runTree.extra, [LC_CHILD_KEY]: config };
|
|
52
|
-
}
|
|
53
|
-
if (previousValue !== undefined &&
|
|
54
|
-
previousValue[exports._CONTEXT_VARIABLES_KEY] !== undefined) {
|
|
55
|
-
runTree[exports._CONTEXT_VARIABLES_KEY] =
|
|
56
|
-
previousValue[exports._CONTEXT_VARIABLES_KEY];
|
|
57
|
-
}
|
|
58
|
-
return storage.run(runTree, callback);
|
|
59
|
-
}
|
|
60
|
-
initializeGlobalInstance(instance) {
|
|
61
|
-
if (globalThis[TRACING_ALS_KEY] === undefined) {
|
|
62
|
-
globalThis[TRACING_ALS_KEY] = instance;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();
|
|
67
|
-
exports.AsyncLocalStorageProviderSingleton = AsyncLocalStorageProviderSingleton;
|
|
5
|
+
const index_js_1 = require("./async_local_storage/index.cjs");
|
|
6
|
+
Object.defineProperty(exports, "AsyncLocalStorageProviderSingleton", { enumerable: true, get: function () { return index_js_1.AsyncLocalStorageProviderSingleton; } });
|
|
7
|
+
Object.defineProperty(exports, "_CONTEXT_VARIABLES_KEY", { enumerable: true, get: function () { return index_js_1._CONTEXT_VARIABLES_KEY; } });
|
|
8
|
+
Object.defineProperty(exports, "MockAsyncLocalStorage", { enumerable: true, get: function () { return index_js_1.MockAsyncLocalStorage; } });
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
run: <T>(store: any, callback: () => T) => T;
|
|
4
|
-
enterWith: (store: any) => void;
|
|
5
|
-
}
|
|
6
|
-
export declare class MockAsyncLocalStorage implements AsyncLocalStorageInterface {
|
|
7
|
-
getStore(): any;
|
|
8
|
-
run<T>(_store: any, callback: () => T): T;
|
|
9
|
-
enterWith(_store: any): undefined;
|
|
10
|
-
}
|
|
11
|
-
export declare const _CONTEXT_VARIABLES_KEY: unique symbol;
|
|
12
|
-
declare class AsyncLocalStorageProvider {
|
|
13
|
-
getInstance(): AsyncLocalStorageInterface;
|
|
14
|
-
getRunnableConfig(): any;
|
|
15
|
-
runWithConfig<T>(config: any, callback: () => T, avoidCreatingRootRunTree?: boolean): T;
|
|
16
|
-
initializeGlobalInstance(instance: AsyncLocalStorageInterface): void;
|
|
17
|
-
}
|
|
18
|
-
declare const AsyncLocalStorageProviderSingleton: AsyncLocalStorageProvider;
|
|
19
|
-
export { AsyncLocalStorageProviderSingleton };
|
|
1
|
+
import { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage } from "./async_local_storage/index.js";
|
|
2
|
+
export { type AsyncLocalStorageInterface, AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, };
|
package/dist/singletons/index.js
CHANGED
|
@@ -1,63 +1,3 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export class MockAsyncLocalStorage {
|
|
5
|
-
getStore() {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
run(_store, callback) {
|
|
9
|
-
return callback();
|
|
10
|
-
}
|
|
11
|
-
enterWith(_store) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
const mockAsyncLocalStorage = new MockAsyncLocalStorage();
|
|
16
|
-
const TRACING_ALS_KEY = Symbol.for("ls:tracing_async_local_storage");
|
|
17
|
-
const LC_CHILD_KEY = Symbol.for("lc:child_config");
|
|
18
|
-
export const _CONTEXT_VARIABLES_KEY = Symbol.for("lc:context_variables");
|
|
19
|
-
class AsyncLocalStorageProvider {
|
|
20
|
-
getInstance() {
|
|
21
|
-
return globalThis[TRACING_ALS_KEY] ?? mockAsyncLocalStorage;
|
|
22
|
-
}
|
|
23
|
-
getRunnableConfig() {
|
|
24
|
-
const storage = this.getInstance();
|
|
25
|
-
// this has the runnable config
|
|
26
|
-
// which means that we should also have an instance of a LangChainTracer
|
|
27
|
-
// with the run map prepopulated
|
|
28
|
-
return storage.getStore()?.extra?.[LC_CHILD_KEY];
|
|
29
|
-
}
|
|
30
|
-
runWithConfig(config, callback, avoidCreatingRootRunTree) {
|
|
31
|
-
const callbackManager = CallbackManager._configureSync(config?.callbacks, undefined, config?.tags, undefined, config?.metadata);
|
|
32
|
-
const storage = this.getInstance();
|
|
33
|
-
const previousValue = storage.getStore();
|
|
34
|
-
const parentRunId = callbackManager?.getParentRunId();
|
|
35
|
-
const langChainTracer = callbackManager?.handlers?.find((handler) => handler?.name === "langchain_tracer");
|
|
36
|
-
let runTree;
|
|
37
|
-
if (langChainTracer && parentRunId) {
|
|
38
|
-
runTree = langChainTracer.convertToRunTree(parentRunId);
|
|
39
|
-
}
|
|
40
|
-
else if (!avoidCreatingRootRunTree) {
|
|
41
|
-
runTree = new RunTree({
|
|
42
|
-
name: "<runnable_lambda>",
|
|
43
|
-
tracingEnabled: false,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (runTree) {
|
|
47
|
-
runTree.extra = { ...runTree.extra, [LC_CHILD_KEY]: config };
|
|
48
|
-
}
|
|
49
|
-
if (previousValue !== undefined &&
|
|
50
|
-
previousValue[_CONTEXT_VARIABLES_KEY] !== undefined) {
|
|
51
|
-
runTree[_CONTEXT_VARIABLES_KEY] =
|
|
52
|
-
previousValue[_CONTEXT_VARIABLES_KEY];
|
|
53
|
-
}
|
|
54
|
-
return storage.run(runTree, callback);
|
|
55
|
-
}
|
|
56
|
-
initializeGlobalInstance(instance) {
|
|
57
|
-
if (globalThis[TRACING_ALS_KEY] === undefined) {
|
|
58
|
-
globalThis[TRACING_ALS_KEY] = instance;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();
|
|
63
|
-
export { AsyncLocalStorageProviderSingleton };
|
|
2
|
+
import { AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, } from "./async_local_storage/index.js";
|
|
3
|
+
export { AsyncLocalStorageProviderSingleton, _CONTEXT_VARIABLES_KEY, MockAsyncLocalStorage, };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultLangChainClientSingleton = void 0;
|
|
4
|
+
const langsmith_1 = require("langsmith");
|
|
5
|
+
const env_js_1 = require("../utils/env.cjs");
|
|
6
|
+
let client;
|
|
7
|
+
const getDefaultLangChainClientSingleton = () => {
|
|
8
|
+
if (client === undefined) {
|
|
9
|
+
const clientParams = (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
|
|
10
|
+
? {
|
|
11
|
+
// LangSmith has its own backgrounding system
|
|
12
|
+
blockOnRootRunFinalization: true,
|
|
13
|
+
}
|
|
14
|
+
: {};
|
|
15
|
+
client = new langsmith_1.Client(clientParams);
|
|
16
|
+
}
|
|
17
|
+
return client;
|
|
18
|
+
};
|
|
19
|
+
exports.getDefaultLangChainClientSingleton = getDefaultLangChainClientSingleton;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Client } from "langsmith";
|
|
2
|
+
import { getEnvironmentVariable } from "../utils/env.js";
|
|
3
|
+
let client;
|
|
4
|
+
export const getDefaultLangChainClientSingleton = () => {
|
|
5
|
+
if (client === undefined) {
|
|
6
|
+
const clientParams = getEnvironmentVariable("LANGCHAIN_CALLBACKS_BACKGROUND") === "false"
|
|
7
|
+
? {
|
|
8
|
+
// LangSmith has its own backgrounding system
|
|
9
|
+
blockOnRootRunFinalization: true,
|
|
10
|
+
}
|
|
11
|
+
: {};
|
|
12
|
+
client = new Client(clientParams);
|
|
13
|
+
}
|
|
14
|
+
return client;
|
|
15
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LangChainTracer = void 0;
|
|
4
|
-
const langsmith_1 = require("langsmith");
|
|
5
4
|
const run_trees_1 = require("langsmith/run_trees");
|
|
6
5
|
const traceable_1 = require("langsmith/singletons/traceable");
|
|
7
6
|
const env_js_1 = require("../utils/env.cjs");
|
|
8
7
|
const base_js_1 = require("./base.cjs");
|
|
8
|
+
const tracer_js_1 = require("../singletons/tracer.cjs");
|
|
9
9
|
class LangChainTracer extends base_js_1.BaseTracer {
|
|
10
10
|
constructor(fields = {}) {
|
|
11
11
|
super(fields);
|
|
@@ -39,13 +39,7 @@ class LangChainTracer extends base_js_1.BaseTracer {
|
|
|
39
39
|
(0, env_js_1.getEnvironmentVariable)("LANGCHAIN_PROJECT") ??
|
|
40
40
|
(0, env_js_1.getEnvironmentVariable)("LANGCHAIN_SESSION");
|
|
41
41
|
this.exampleId = exampleId;
|
|
42
|
-
|
|
43
|
-
? {
|
|
44
|
-
// LangSmith has its own backgrounding system
|
|
45
|
-
blockOnRootRunFinalization: true,
|
|
46
|
-
}
|
|
47
|
-
: {};
|
|
48
|
-
this.client = client ?? new langsmith_1.Client(clientParams);
|
|
42
|
+
this.client = client ?? (0, tracer_js_1.getDefaultLangChainClientSingleton)();
|
|
49
43
|
const traceableTree = LangChainTracer.getTraceableRunTree();
|
|
50
44
|
if (traceableTree) {
|
|
51
45
|
this.updateFromRunTree(traceableTree);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Client } from "langsmith";
|
|
2
1
|
import { RunTree } from "langsmith/run_trees";
|
|
3
2
|
import { getCurrentRunTree } from "langsmith/singletons/traceable";
|
|
4
3
|
import { getEnvironmentVariable, getRuntimeEnvironment } from "../utils/env.js";
|
|
5
4
|
import { BaseTracer } from "./base.js";
|
|
5
|
+
import { getDefaultLangChainClientSingleton } from "../singletons/tracer.js";
|
|
6
6
|
export class LangChainTracer extends BaseTracer {
|
|
7
7
|
constructor(fields = {}) {
|
|
8
8
|
super(fields);
|
|
@@ -36,13 +36,7 @@ export class LangChainTracer extends BaseTracer {
|
|
|
36
36
|
getEnvironmentVariable("LANGCHAIN_PROJECT") ??
|
|
37
37
|
getEnvironmentVariable("LANGCHAIN_SESSION");
|
|
38
38
|
this.exampleId = exampleId;
|
|
39
|
-
|
|
40
|
-
? {
|
|
41
|
-
// LangSmith has its own backgrounding system
|
|
42
|
-
blockOnRootRunFinalization: true,
|
|
43
|
-
}
|
|
44
|
-
: {};
|
|
45
|
-
this.client = client ?? new Client(clientParams);
|
|
39
|
+
this.client = client ?? getDefaultLangChainClientSingleton();
|
|
46
40
|
const traceableTree = LangChainTracer.getTraceableRunTree();
|
|
47
41
|
if (traceableTree) {
|
|
48
42
|
this.updateFromRunTree(traceableTree);
|