diff --git a/langchain-core/src/runnables/base.ts b/langchain-core/src/runnables/base.ts index d2ba10b6f6bd..1cab402513ec 100644 --- a/langchain-core/src/runnables/base.ts +++ b/langchain-core/src/runnables/base.ts @@ -6,11 +6,7 @@ import { type TraceableFunction, isTraceableFunction, } from "langsmith/singletons/traceable"; -import type { - RunnableInterface, - RunnableBatchOptions, - RunnableConfig, -} from "./types.js"; +import type { RunnableInterface, RunnableBatchOptions } from "./types.js"; import { CallbackManagerForChainRun } from "../callbacks/manager.js"; import { LogStreamCallbackHandler, @@ -37,11 +33,11 @@ import { import { raceWithSignal } from "../utils/signal.js"; import { DEFAULT_RECURSION_LIMIT, + RunnableConfig, ensureConfig, getCallbackManagerForConfig, mergeConfigs, patchConfig, - pickRunnableConfigKeys, } from "./config.js"; import { AsyncCaller } from "../utils/async_caller.js"; import { Run } from "../tracers/base.js"; @@ -2533,7 +2529,7 @@ export class RunnableLambda< recursionLimit: (config?.recursionLimit ?? DEFAULT_RECURSION_LIMIT) - 1, }); void AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(childConfig), + childConfig, async () => { try { let output = await this.func(input, { @@ -2631,7 +2627,7 @@ export class RunnableLambda< const output = await new Promise( (resolve, reject) => { void AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(childConfig), + childConfig, async () => { try { const res = await this.func(finalChunk as RunInput, { diff --git a/langchain-core/src/runnables/config.ts b/langchain-core/src/runnables/config.ts index aae7164b5721..8fa9a244ee3d 100644 --- a/langchain-core/src/runnables/config.ts +++ b/langchain-core/src/runnables/config.ts @@ -233,21 +233,3 @@ export function patchConfig( } return newConfig; } - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function pickRunnableConfigKeys>( - config?: CallOptions -): Partial | undefined { - return config - ? { - configurable: config.configurable, - recursionLimit: config.recursionLimit, - callbacks: config.callbacks, - tags: config.tags, - metadata: config.metadata, - maxConcurrency: config.maxConcurrency, - timeout: config.timeout, - signal: config.signal, - } - : undefined; -} diff --git a/langchain-core/src/runnables/index.ts b/langchain-core/src/runnables/index.ts index 7d78b1c5f75a..2a34d91c8164 100644 --- a/langchain-core/src/runnables/index.ts +++ b/langchain-core/src/runnables/index.ts @@ -29,7 +29,6 @@ export { patchConfig, ensureConfig, mergeConfigs, - pickRunnableConfigKeys, } from "./config.js"; export { RunnablePassthrough } from "./passthrough.js"; export { type RouterInput, RouterRunnable } from "./router.js"; diff --git a/langchain-core/src/runnables/iter.ts b/langchain-core/src/runnables/iter.ts index 4d7ead6efa60..52b7a61db06a 100644 --- a/langchain-core/src/runnables/iter.ts +++ b/langchain-core/src/runnables/iter.ts @@ -1,6 +1,5 @@ -import type { RunnableConfig } from "../runnables/types.js"; import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js"; -import { pickRunnableConfigKeys } from "./config.js"; +import { RunnableConfig } from "./config.js"; export function isIterableIterator( thing: unknown @@ -37,7 +36,7 @@ export function* consumeIteratorInContext( ): IterableIterator { while (true) { const { value, done } = AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(context), + context, iter.next.bind(iter), true ); @@ -57,7 +56,7 @@ export async function* consumeAsyncIterableInContext( while (true) { const { value, done } = await AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(context), + context, iterator.next.bind(iter), true ); diff --git a/langchain-core/src/runnables/types.ts b/langchain-core/src/runnables/types.ts index f06e94fa1254..f40d80ee3831 100644 --- a/langchain-core/src/runnables/types.ts +++ b/langchain-core/src/runnables/types.ts @@ -1,7 +1,7 @@ import type { z } from "zod"; +import type { IterableReadableStreamInterface } from "../utils/stream.js"; import type { SerializableInterface } from "../load/serializable.js"; import type { BaseCallbackConfig } from "../callbacks/manager.js"; -import type { IterableReadableStreamInterface } from "../types/stream.js"; export type RunnableBatchOptions = { /** @deprecated Pass in via the standard runnable config object instead */ diff --git a/langchain-core/src/tools/index.ts b/langchain-core/src/tools/index.ts index 8ce02d28c935..348e85103904 100644 --- a/langchain-core/src/tools/index.ts +++ b/langchain-core/src/tools/index.ts @@ -12,7 +12,6 @@ import { import { ensureConfig, patchConfig, - pickRunnableConfigKeys, type RunnableConfig, } from "../runnables/config.js"; import type { RunnableFunc, RunnableInterface } from "../runnables/base.js"; @@ -595,7 +594,7 @@ export function tool< callbacks: runManager?.getChild(), }); void AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(childConfig), + childConfig, async () => { try { // TS doesn't restrict the type here based on the guard above @@ -626,7 +625,7 @@ export function tool< callbacks: runManager?.getChild(), }); void AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys(childConfig), + childConfig, async () => { try { // TS doesn't restrict the type here based on the guard above diff --git a/langchain-core/src/types/stream.ts b/langchain-core/src/types/stream.ts deleted file mode 100644 index ae03b69b78bb..000000000000 --- a/langchain-core/src/types/stream.ts +++ /dev/null @@ -1,5 +0,0 @@ -// Make this a type to override ReadableStream's async iterator type in case -// the popular web-streams-polyfill is imported - the supplied types -// in that case don't quite match. -export type IterableReadableStreamInterface = ReadableStream & - AsyncIterable; diff --git a/langchain-core/src/utils/stream.ts b/langchain-core/src/utils/stream.ts index cd3e592806be..aa9db0604637 100644 --- a/langchain-core/src/utils/stream.ts +++ b/langchain-core/src/utils/stream.ts @@ -1,11 +1,11 @@ -import { pickRunnableConfigKeys } from "../runnables/config.js"; import { AsyncLocalStorageProviderSingleton } from "../singletons/index.js"; -import type { IterableReadableStreamInterface } from "../types/stream.js"; import { raceWithSignal } from "./signal.js"; -// Re-exported for backwards compatibility -// Do NOT import this type from this file inside the project. Instead, always import from `types/stream.js` -export type { IterableReadableStreamInterface }; +// Make this a type to override ReadableStream's async iterator type in case +// the popular web-streams-polyfill is imported - the supplied types +// in that case don't quite match. +export type IterableReadableStreamInterface = ReadableStream & + AsyncIterable; /* * Support async iterator syntax for ReadableStreams in all environments. @@ -215,9 +215,7 @@ export class AsyncGeneratorWithSetup< // to each generator is available. this.setup = new Promise((resolve, reject) => { void AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys( - params.config as Record | undefined - ), + params.config, async () => { this.firstResult = params.generator.next(); if (params.startSetup) { @@ -240,9 +238,7 @@ export class AsyncGeneratorWithSetup< } return AsyncLocalStorageProviderSingleton.runWithConfig( - pickRunnableConfigKeys( - this.config as Record | undefined - ), + this.config, this.signal ? async () => { return raceWithSignal(this.generator.next(...args), this.signal);