| 1 | import { env } from "@/env"; |
| 2 | import { PostgresSaver } from "@langchain/langgraph-checkpoint-postgres"; |
| 3 | |
| 4 | export const checkpointer = PostgresSaver.fromConnString(env.DATABASE_URL); |
| 5 | |
| 6 | let setupPromise: Promise<void> | null = null; |
| 7 | |
| 8 | export async function ensureCheckpointerSetup() { |
| 9 | if (!setupPromise) { |
| 10 | setupPromise = checkpointer.setup().catch((error) => { |
| 11 | setupPromise = null; |
| 12 | throw error; |
| 13 | }); |
| 14 | } |
| 15 | |
| 16 | await setupPromise; |
| 17 | } |
| 18 |