import { LangGraphRunnableConfig } from "../pregel/runnable_types.js"; //#region src/func/types.d.ts /** * Allows the entrypoint function to return a value to the caller, as well as a separate state value to persist to the checkpoint */ type EntrypointFinal = { /** * The value to return to the caller */ value?: ValueT; /** * The value to save to the checkpoint */ save?: SaveT; __lg_type: "__pregel_final"; }; /** * The return type of an entrypoint function. */ type EntrypointReturnT = OutputT extends EntrypointFinal | Promise> ? ValueT : OutputT; /** * The value to be saved when a function returns an EntrypointFinal. */ type EntrypointFinalSaveT = OutputT extends EntrypointFinal | Promise> ? SaveT : OutputT; /** * Checks if an AsyncGenerator exists in the ES target/lib that we're compiling to. * * This is necessary because `tsc --init` targets ES2016 by default, which doesn't include AsyncGenerators. * * This works because when `skipLibCheck` is true (and it is in the default `tsconfig.json` created by `tsc --init`), * TypeScript will replace any unresolved library types with `any`. So, when `AsyncGenerator` doesn't exist, this checks * if `any` extends `object`, which it doesn't. When that happens, this type resolves to the `false` literal, and we can * use it in the type predicates below to skip over the AsyncGenerator-specific logic. * * If we didn't have this, then the types below would be checking if the user's function extends `any` in place of the * `AsyncGenerator` type, and the type predicate would branch to `never`, disallowing any valid function from being passed * to `task` or `entrypoint`. */ type AsyncGeneratorExists = AsyncGenerator extends object ? true : false; /** * Matches valid function signatures for entrypoints. Disallows generator functions. */ type EntrypointFunc = [OutputT] extends never ? (input: InputT, config: LangGraphRunnableConfig) => never : AsyncGeneratorExists extends true ? OutputT extends AsyncGenerator ? never : OutputT extends Generator ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT : OutputT extends Generator ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT; /** * Matches valid function signatures for tasks. Disallows generator functions. */ type TaskFunc = [OutputT] extends [never] ? (...args: ArgsT) => never : AsyncGeneratorExists extends true ? OutputT extends AsyncGenerator ? never : OutputT extends Generator ? never : (...args: ArgsT) => OutputT : OutputT extends Generator ? never : (...args: ArgsT) => OutputT; //#endregion export { EntrypointFinal, EntrypointFinalSaveT, EntrypointFunc, EntrypointReturnT, TaskFunc }; //# sourceMappingURL=types.d.ts.map