@langchain/core 0.3.25 → 0.3.26

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.
@@ -1944,32 +1944,38 @@ class RunnableWithFallbacks extends Runnable {
1944
1944
  }
1945
1945
  async invoke(input, options) {
1946
1946
  const config = (0, config_js_1.ensureConfig)(options);
1947
- const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
1947
+ const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
1948
1948
  const { runId, ...otherConfigFields } = config;
1949
1949
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
1950
- let firstError;
1951
- for (const runnable of this.runnables()) {
1952
- config?.signal?.throwIfAborted();
1953
- try {
1954
- const output = await runnable.invoke(input, (0, config_js_1.patchConfig)(otherConfigFields, { callbacks: runManager?.getChild() }));
1955
- await runManager?.handleChainEnd(_coerceToDict(output, "output"));
1956
- return output;
1957
- }
1958
- catch (e) {
1959
- if (firstError === undefined) {
1960
- firstError = e;
1950
+ const childConfig = (0, config_js_1.patchConfig)(otherConfigFields, {
1951
+ callbacks: runManager?.getChild(),
1952
+ });
1953
+ const res = await index_js_1.AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
1954
+ let firstError;
1955
+ for (const runnable of this.runnables()) {
1956
+ config?.signal?.throwIfAborted();
1957
+ try {
1958
+ const output = await runnable.invoke(input, childConfig);
1959
+ await runManager?.handleChainEnd(_coerceToDict(output, "output"));
1960
+ return output;
1961
+ }
1962
+ catch (e) {
1963
+ if (firstError === undefined) {
1964
+ firstError = e;
1965
+ }
1961
1966
  }
1962
1967
  }
1963
- }
1964
- if (firstError === undefined) {
1965
- throw new Error("No error stored at end of fallback.");
1966
- }
1967
- await runManager?.handleChainError(firstError);
1968
- throw firstError;
1968
+ if (firstError === undefined) {
1969
+ throw new Error("No error stored at end of fallback.");
1970
+ }
1971
+ await runManager?.handleChainError(firstError);
1972
+ throw firstError;
1973
+ });
1974
+ return res;
1969
1975
  }
1970
1976
  async *_streamIterator(input, options) {
1971
1977
  const config = (0, config_js_1.ensureConfig)(options);
1972
- const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
1978
+ const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(config);
1973
1979
  const { runId, ...otherConfigFields } = config;
1974
1980
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
1975
1981
  let firstError;
@@ -1980,7 +1986,8 @@ class RunnableWithFallbacks extends Runnable {
1980
1986
  callbacks: runManager?.getChild(),
1981
1987
  });
1982
1988
  try {
1983
- stream = await runnable.stream(input, childConfig);
1989
+ const originalStream = await runnable.stream(input, childConfig);
1990
+ stream = (0, iter_js_1.consumeAsyncIterableInContext)(childConfig, originalStream);
1984
1991
  break;
1985
1992
  }
1986
1993
  catch (e) {
@@ -1928,32 +1928,38 @@ export class RunnableWithFallbacks extends Runnable {
1928
1928
  }
1929
1929
  async invoke(input, options) {
1930
1930
  const config = ensureConfig(options);
1931
- const callbackManager_ = await getCallbackManagerForConfig(options);
1931
+ const callbackManager_ = await getCallbackManagerForConfig(config);
1932
1932
  const { runId, ...otherConfigFields } = config;
1933
1933
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
1934
- let firstError;
1935
- for (const runnable of this.runnables()) {
1936
- config?.signal?.throwIfAborted();
1937
- try {
1938
- const output = await runnable.invoke(input, patchConfig(otherConfigFields, { callbacks: runManager?.getChild() }));
1939
- await runManager?.handleChainEnd(_coerceToDict(output, "output"));
1940
- return output;
1941
- }
1942
- catch (e) {
1943
- if (firstError === undefined) {
1944
- firstError = e;
1934
+ const childConfig = patchConfig(otherConfigFields, {
1935
+ callbacks: runManager?.getChild(),
1936
+ });
1937
+ const res = await AsyncLocalStorageProviderSingleton.runWithConfig(childConfig, async () => {
1938
+ let firstError;
1939
+ for (const runnable of this.runnables()) {
1940
+ config?.signal?.throwIfAborted();
1941
+ try {
1942
+ const output = await runnable.invoke(input, childConfig);
1943
+ await runManager?.handleChainEnd(_coerceToDict(output, "output"));
1944
+ return output;
1945
+ }
1946
+ catch (e) {
1947
+ if (firstError === undefined) {
1948
+ firstError = e;
1949
+ }
1945
1950
  }
1946
1951
  }
1947
- }
1948
- if (firstError === undefined) {
1949
- throw new Error("No error stored at end of fallback.");
1950
- }
1951
- await runManager?.handleChainError(firstError);
1952
- throw firstError;
1952
+ if (firstError === undefined) {
1953
+ throw new Error("No error stored at end of fallback.");
1954
+ }
1955
+ await runManager?.handleChainError(firstError);
1956
+ throw firstError;
1957
+ });
1958
+ return res;
1953
1959
  }
1954
1960
  async *_streamIterator(input, options) {
1955
1961
  const config = ensureConfig(options);
1956
- const callbackManager_ = await getCallbackManagerForConfig(options);
1962
+ const callbackManager_ = await getCallbackManagerForConfig(config);
1957
1963
  const { runId, ...otherConfigFields } = config;
1958
1964
  const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), runId, undefined, undefined, undefined, otherConfigFields?.runName);
1959
1965
  let firstError;
@@ -1964,7 +1970,8 @@ export class RunnableWithFallbacks extends Runnable {
1964
1970
  callbacks: runManager?.getChild(),
1965
1971
  });
1966
1972
  try {
1967
- stream = await runnable.stream(input, childConfig);
1973
+ const originalStream = await runnable.stream(input, childConfig);
1974
+ stream = consumeAsyncIterableInContext(childConfig, originalStream);
1968
1975
  break;
1969
1976
  }
1970
1977
  catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/core",
3
- "version": "0.3.25",
3
+ "version": "0.3.26",
4
4
  "description": "Core LangChain.js abstractions and schemas",
5
5
  "type": "module",
6
6
  "engines": {