UNPKG

@langchain/langgraph-sdk

Version:

Client library for interacting with the LangGraph API

49 lines (48 loc) • 1.25 kB
import { EMPTY_QUEUE } from "./queue-adapter.js"; import { v7 } from "@langchain/core/utils/uuid"; //#region src/stream/queue-adapter-local.ts /** * Client-only defer. The default backing for `"enqueue"` — used * unless `queue: "server"` is set. */ var LocalQueueAdapter = class { #store; #onError; constructor(store, onError) { this.#store = store; this.#onError = onError; } async hydrate() {} async enqueue(_threadId, values, options) { const entry = { id: v7(), values, options, createdAt: /* @__PURE__ */ new Date() }; this.#store.setState((current) => [...current, entry]); } onIdle(dispatch) { const [head, ...rest] = this.#store.getSnapshot(); if (!head) return; this.#store.setState(() => rest); dispatch(head.values, { ...head.options, multitaskStrategy: void 0 }).catch(this.#onError); } async cancel(id) { const current = this.#store.getSnapshot(); const next = current.filter((entry) => entry.id !== id); if (next.length === current.length) return false; this.#store.setState(() => next); return true; } async clear() { this.#store.setState(() => EMPTY_QUEUE); } detach() {} }; //#endregion export { LocalQueueAdapter }; //# sourceMappingURL=queue-adapter-local.js.map