@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.
- package/dist/runnables/base.cjs +27 -20
- package/dist/runnables/base.js +27 -20
- package/package.json +1 -1
package/dist/runnables/base.cjs
CHANGED
|
@@ -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)(
|
|
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
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
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
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
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)(
|
|
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
|
-
|
|
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) {
|
package/dist/runnables/base.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
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
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
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(
|
|
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
|
-
|
|
1973
|
+
const originalStream = await runnable.stream(input, childConfig);
|
|
1974
|
+
stream = consumeAsyncIterableInContext(childConfig, originalStream);
|
|
1968
1975
|
break;
|
|
1969
1976
|
}
|
|
1970
1977
|
catch (e) {
|