@langchain/langgraph
Version:
50 lines (49 loc) • 1.72 kB
JavaScript
const require_constants = require("../constants.cjs");
const require_utils = require("../utils.cjs");
const require_write = require("./write.cjs");
let _langchain_core_singletons = require("@langchain/core/singletons");
let _langchain_core_runnables = require("@langchain/core/runnables");
//#region src/pregel/call.ts
/**
* Wraps a user function in a Runnable that writes the returned value to the RETURN channel.
*/
function getRunnableForFunc(name, func) {
return new _langchain_core_runnables.RunnableSequence({
name,
first: new require_utils.RunnableCallable({
func: (input) => func(...input),
name,
trace: false,
recurse: false
}),
last: new require_write.ChannelWrite([{
channel: require_constants.RETURN,
value: require_write.PASSTHROUGH
}], [require_constants.TAG_HIDDEN])
});
}
function getRunnableForEntrypoint(name, func) {
return new require_utils.RunnableCallable({
func: (input, config) => {
return func(input, config);
},
name,
trace: false,
recurse: false
});
}
function call({ func, name, cache, retry, timeout }, ...args) {
const config = _langchain_core_singletons.AsyncLocalStorageProviderSingleton.getRunnableConfig();
if (typeof config.configurable?.["__pregel_call"] === "function") return config.configurable[require_constants.CONFIG_KEY_CALL](func, name, args, {
retry,
cache,
timeout,
callbacks: config.callbacks
});
throw new Error("Async local storage not initialized. Please call initializeAsyncLocalStorageSingleton() before using this function.");
}
//#endregion
exports.call = call;
exports.getRunnableForEntrypoint = getRunnableForEntrypoint;
exports.getRunnableForFunc = getRunnableForFunc;
//# sourceMappingURL=call.cjs.map