UNPKG

@langchain/langgraph-sdk

Version:

Client library for interacting with the LangGraph API

1 lines • 3.29 kB
{"version":3,"file":"queue-adapter-local.cjs","names":["#store","#onError","EMPTY_QUEUE"],"sources":["../../src/stream/queue-adapter-local.ts"],"sourcesContent":["import { v7 as uuidv7 } from \"@langchain/core/utils/uuid\";\nimport {\n EMPTY_QUEUE,\n type QueueAdapter,\n type SubmissionQueueEntry,\n type SubmissionQueueSnapshot,\n} from \"./queue-adapter.js\";\nimport { StreamStore } from \"./store.js\";\nimport type { StreamSubmitOptions } from \"./types.js\";\n\n/**\n * Client-only defer. The default backing for `\"enqueue\"` — used\n * unless `queue: \"server\"` is set.\n */\nexport class LocalQueueAdapter<\n StateType extends object = Record<string, unknown>,\n> implements QueueAdapter<StateType> {\n readonly #store: StreamStore<SubmissionQueueSnapshot<StateType>>;\n readonly #onError: (error: unknown) => void;\n\n constructor(\n store: StreamStore<SubmissionQueueSnapshot<StateType>>,\n onError: (error: unknown) => void\n ) {\n this.#store = store;\n this.#onError = onError;\n }\n\n async hydrate(): Promise<void> {\n // No-op. Nothing to hydrate from. The queue only ever reflects\n // what this session enqueued in memory.\n }\n\n async enqueue(\n _threadId: string,\n values: Partial<StateType> | null | undefined,\n options: StreamSubmitOptions<StateType> | undefined\n ): Promise<void> {\n const entry: SubmissionQueueEntry<StateType> = {\n id: uuidv7(),\n values,\n options,\n createdAt: new Date(),\n };\n this.#store.setState((current) => [...current, entry]);\n }\n\n onIdle(\n dispatch: (\n values: unknown,\n options: StreamSubmitOptions<StateType> | undefined\n ) => Promise<void>\n ): void {\n const [head, ...rest] = this.#store.getSnapshot();\n if (!head) return;\n this.#store.setState(() => rest);\n // Strip the strategy so the drained submission doesn't recursively re-enqueue.\n dispatch(head.values, {\n ...head.options,\n multitaskStrategy: undefined,\n }).catch(this.#onError); // dispatch already routes failures to rootStore.error\n }\n\n async cancel(id: string): Promise<boolean> {\n const current = this.#store.getSnapshot();\n const next = current.filter((entry) => entry.id !== id);\n if (next.length === current.length) return false;\n this.#store.setState(() => next);\n return true;\n }\n\n async clear(): Promise<void> {\n this.#store.setState(\n () => EMPTY_QUEUE as SubmissionQueueSnapshot<StateType>\n );\n }\n\n detach(): void {\n // Nothing to release.\n }\n}\n"],"mappings":";;;;;;;;AAcA,IAAa,oBAAb,MAEqC;CACnC;CACA;CAEA,YACE,OACA,SACA;AACA,QAAA,QAAc;AACd,QAAA,UAAgB;;CAGlB,MAAM,UAAyB;CAK/B,MAAM,QACJ,WACA,QACA,SACe;EACf,MAAM,QAAyC;GAC7C,KAAA,GAAA,2BAAA,KAAY;GACZ;GACA;GACA,2BAAW,IAAI,MAAM;GACtB;AACD,QAAA,MAAY,UAAU,YAAY,CAAC,GAAG,SAAS,MAAM,CAAC;;CAGxD,OACE,UAIM;EACN,MAAM,CAAC,MAAM,GAAG,QAAQ,MAAA,MAAY,aAAa;AACjD,MAAI,CAAC,KAAM;AACX,QAAA,MAAY,eAAe,KAAK;AAEhC,WAAS,KAAK,QAAQ;GACpB,GAAG,KAAK;GACR,mBAAmB,KAAA;GACpB,CAAC,CAAC,MAAM,MAAA,QAAc;;CAGzB,MAAM,OAAO,IAA8B;EACzC,MAAM,UAAU,MAAA,MAAY,aAAa;EACzC,MAAM,OAAO,QAAQ,QAAQ,UAAU,MAAM,OAAO,GAAG;AACvD,MAAI,KAAK,WAAW,QAAQ,OAAQ,QAAO;AAC3C,QAAA,MAAY,eAAe,KAAK;AAChC,SAAO;;CAGT,MAAM,QAAuB;AAC3B,QAAA,MAAY,eACJE,sBAAAA,YACP;;CAGH,SAAe"}