UNPKG

@langchain/langgraph-sdk

Version:

Client library for interacting with the LangGraph API

1 lines • 24.1 kB
{"version":3,"file":"base.cjs","names":["getEnvironmentVariable","AsyncCaller","mergeSignals","#performFetch","#performFetchWithResponse","BytesLineDecoder","idleReconnectStream","SSEDecoder","streamWithRetry"],"sources":["../../src/client/base.ts"],"sourcesContent":["import { AsyncCaller, AsyncCallerParams } from \"../utils/async_caller.js\";\nimport { getEnvironmentVariable } from \"../utils/env.js\";\nimport { mergeSignals } from \"../utils/signals.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../utils/sse.js\";\nimport {\n streamWithRetry,\n idleReconnectStream,\n type IdleReconnectMode,\n StreamRequestParams,\n DEFAULT_IDLE_RECONNECT,\n} from \"../utils/stream.js\";\nimport { DEFAULT_MAX_RECONNECT_ATTEMPTS } from \"../utils/reconnect.js\";\nimport type { StreamProtocol } from \"../types.js\";\n\nexport type HeaderValue = string | undefined | null;\n\nexport function* iterateHeaders(\n headers: HeadersInit | Record<string, HeaderValue>\n): IterableIterator<[string, string | null]> {\n let iter: Iterable<(HeaderValue | HeaderValue | null[])[]>;\n let shouldClear = false;\n\n // eslint-disable-next-line no-instanceof/no-instanceof\n if (headers instanceof Headers) {\n const entries: [string, string][] = [];\n headers.forEach((value, name) => {\n entries.push([name, value]);\n });\n iter = entries;\n } else if (Array.isArray(headers)) {\n iter = headers;\n } else {\n shouldClear = true;\n iter = Object.entries(headers ?? {});\n }\n\n for (const item of iter) {\n const name = item[0];\n if (typeof name !== \"string\")\n throw new TypeError(\n `Expected header name to be a string, got ${typeof name}`\n );\n const values = Array.isArray(item[1]) ? item[1] : [item[1]];\n let didClear = false;\n\n for (const value of values) {\n if (value === undefined) continue;\n\n if (shouldClear && !didClear) {\n didClear = true;\n yield [name, null];\n }\n yield [name, value];\n }\n }\n}\n\nexport function mergeHeaders(\n ...headerObjects: (\n | HeadersInit\n | Record<string, HeaderValue>\n | undefined\n | null\n )[]\n) {\n const outputHeaders = new Headers();\n for (const headers of headerObjects) {\n if (!headers) continue;\n for (const [name, value] of iterateHeaders(headers)) {\n if (value === null) outputHeaders.delete(name);\n else outputHeaders.append(name, value);\n }\n }\n const headerEntries: [string, string][] = [];\n outputHeaders.forEach((value, name) => {\n headerEntries.push([name, value]);\n });\n return Object.fromEntries(headerEntries);\n}\n\n/**\n * Get the API key from the environment.\n * Precedence:\n * 1. explicit argument (if string)\n * 2. LANGGRAPH_API_KEY\n * 3. LANGSMITH_API_KEY\n * 4. LANGCHAIN_API_KEY\n *\n * @param apiKey - API key provided as an argument. If null, skips environment lookup. If undefined, tries environment.\n * @returns The API key if found, otherwise undefined\n */\nexport function getApiKey(apiKey?: string | null): string | undefined {\n if (apiKey === null) {\n return undefined;\n }\n\n if (apiKey) {\n return apiKey;\n }\n\n const prefixes = [\"LANGGRAPH\", \"LANGSMITH\", \"LANGCHAIN\"];\n\n for (const prefix of prefixes) {\n const envKey = getEnvironmentVariable(`${prefix}_API_KEY`);\n if (envKey) {\n return envKey.trim().replace(/^[\"']|[\"']$/g, \"\");\n }\n }\n\n return undefined;\n}\n\n/**\n * Encode an identifier as a single URL path segment so it can't change the\n * request's path or query. `.` and `..` are rejected since `new URL()` would\n * resolve them as dot segments.\n */\nexport function encodePathSegment(value: string): string {\n if (value === \".\" || value === \"..\") {\n throw new Error(`Invalid path segment: ${JSON.stringify(value)}`);\n }\n return encodeURIComponent(value);\n}\n\nexport type RequestHook = (\n url: URL,\n init: RequestInit\n) => Promise<RequestInit> | RequestInit;\n\n/**\n * Configuration for {@link BaseClient} and the exported LangGraph SDK\n * {@link Client}.\n */\nexport interface ClientConfig {\n /**\n * Base URL of the LangGraph API server.\n *\n * Defaults to `http://localhost:8123`, unless the runtime provides a\n * `langgraph_api:url` global override.\n */\n apiUrl?: string;\n /**\n * API key for authentication.\n * - If a string is provided, that key will be used\n * - If undefined (default), the key will be auto-loaded from environment variables (LANGGRAPH_API_KEY, LANGSMITH_API_KEY, or LANGCHAIN_API_KEY)\n * - If null, no API key will be set (skips auto-loading)\n */\n apiKey?: string | null;\n /**\n * Options forwarded to the internal {@link AsyncCaller}, such as retry,\n * concurrency, or custom `fetch` behavior.\n */\n callerOptions?: AsyncCallerParams;\n /**\n * Default timeout, in milliseconds, applied to client requests.\n *\n * Per-request `timeoutMs` values override this default. Passing `null`\n * at the request level disables the configured timeout for that request.\n */\n timeoutMs?: number;\n /**\n * Headers applied to every request.\n *\n * The configured API key, when present, is added as the `x-api-key`\n * header after these defaults are initialized.\n */\n defaultHeaders?: Record<string, HeaderValue>;\n /**\n * Hook for inspecting or mutating a request before it is sent.\n *\n * Receives the resolved URL and prepared `RequestInit`; return the\n * original init or a replacement object to continue the request.\n */\n onRequest?: RequestHook;\n /**\n * Streaming protocol used by stream-capable endpoints.\n *\n * Defaults to `\"legacy\"` for backwards compatibility.\n */\n streamProtocol?: StreamProtocol;\n}\n\nexport class BaseClient {\n protected asyncCaller: AsyncCaller;\n\n protected timeoutMs: number | undefined;\n\n protected apiUrl: string;\n\n protected defaultHeaders: Record<string, HeaderValue>;\n\n protected onRequest?: RequestHook;\n\n protected streamProtocol: StreamProtocol;\n\n constructor(config?: ClientConfig) {\n const callerOptions = {\n maxRetries: 4,\n maxConcurrency: 4,\n ...config?.callerOptions,\n };\n\n let defaultApiUrl = \"http://localhost:8123\";\n if (\n !config?.apiUrl &&\n typeof globalThis === \"object\" &&\n globalThis != null\n ) {\n const fetchSmb = Symbol.for(\"langgraph_api:fetch\");\n const urlSmb = Symbol.for(\"langgraph_api:url\");\n\n const global = globalThis as unknown as {\n [fetchSmb]?: typeof fetch;\n [urlSmb]?: string;\n };\n\n if (global[fetchSmb]) callerOptions.fetch ??= global[fetchSmb];\n if (global[urlSmb]) defaultApiUrl = global[urlSmb];\n }\n\n this.asyncCaller = new AsyncCaller(callerOptions);\n this.timeoutMs = config?.timeoutMs;\n\n this.apiUrl = config?.apiUrl?.replace(/\\/$/, \"\") || defaultApiUrl;\n this.defaultHeaders = mergeHeaders(config?.defaultHeaders);\n this.onRequest = config?.onRequest;\n this.streamProtocol = config?.streamProtocol ?? \"legacy\";\n const apiKey = getApiKey(config?.apiKey);\n if (apiKey) {\n this.defaultHeaders[\"x-api-key\"] = apiKey;\n }\n }\n\n protected prepareFetchOptions(\n path: string,\n options?: RequestInit & {\n json?: unknown;\n params?: Record<string, unknown>;\n timeoutMs?: number | null;\n withResponse?: boolean;\n dedupe?: boolean;\n }\n ): [url: URL, init: RequestInit] {\n const mutatedOptions = {\n ...options,\n headers: mergeHeaders(this.defaultHeaders, options?.headers),\n };\n\n if (mutatedOptions.json) {\n mutatedOptions.body = JSON.stringify(mutatedOptions.json);\n mutatedOptions.headers = mergeHeaders(mutatedOptions.headers, {\n \"content-type\": \"application/json\",\n });\n delete mutatedOptions.json;\n }\n\n if (mutatedOptions.withResponse) {\n delete mutatedOptions.withResponse;\n }\n\n if (\"dedupe\" in mutatedOptions) {\n delete mutatedOptions.dedupe;\n }\n\n let timeoutSignal: AbortSignal | null = null;\n if (typeof options?.timeoutMs !== \"undefined\") {\n if (options.timeoutMs != null) {\n timeoutSignal = AbortSignal.timeout(options.timeoutMs);\n }\n } else if (this.timeoutMs != null) {\n timeoutSignal = AbortSignal.timeout(this.timeoutMs);\n }\n\n mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);\n const targetUrl = new URL(`${this.apiUrl}${path}`);\n\n if (mutatedOptions.params) {\n for (const [key, value] of Object.entries(mutatedOptions.params)) {\n if (value == null) continue;\n\n // Send each array element as its own repeated key=value pair.\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item == null) continue;\n targetUrl.searchParams.append(\n key,\n typeof item === \"string\" || typeof item === \"number\"\n ? item.toString()\n : JSON.stringify(item)\n );\n }\n continue;\n }\n\n const strValue =\n typeof value === \"string\" || typeof value === \"number\"\n ? value.toString()\n : JSON.stringify(value);\n\n targetUrl.searchParams.append(key, strValue);\n }\n delete mutatedOptions.params;\n }\n\n return [targetUrl, mutatedOptions];\n }\n\n protected async fetch<T>(\n path: string,\n options: RequestInit & {\n json?: unknown;\n params?: Record<string, unknown>;\n timeoutMs?: number | null;\n signal: AbortSignal | undefined;\n withResponse: true;\n }\n ): Promise<[T, Response]>;\n\n protected async fetch<T>(\n path: string,\n options?: RequestInit & {\n json?: unknown;\n params?: Record<string, unknown>;\n timeoutMs?: number | null;\n signal: AbortSignal | undefined;\n withResponse?: false;\n dedupe?: boolean;\n }\n ): Promise<T>;\n\n protected async fetch<T>(\n path: string,\n options?: RequestInit & {\n json?: unknown;\n params?: Record<string, unknown>;\n timeoutMs?: number | null;\n signal: AbortSignal | undefined;\n withResponse?: boolean;\n dedupe?: boolean;\n }\n ): Promise<T | [T, Response]> {\n const [url, init] = this.prepareFetchOptions(path, options);\n\n /**\n * Coalesce concurrent, identical idempotent reads onto a single\n * in-flight request. Only engaged when the caller opts in\n * (`dedupe: true`), is not asking for the raw `Response`, did not\n * supply its own `AbortSignal` (sharing a request across consumers\n * must never let one consumer's abort cancel another's), and no\n * `onRequest` hook is configured.\n *\n * `onRequest` is excluded because it can inject per-request headers\n * (e.g. a freshly-minted `Authorization` bearer) that are not\n * visible until *after* it runs — i.e. after the dedupe key is\n * computed — so two requests that look identical here could be sent\n * with different credentials. Coalescing them would let one\n * consumer receive a response fetched with another's auth.\n */\n const canDedupe =\n options?.dedupe === true &&\n options?.withResponse !== true &&\n options?.signal == null &&\n this.onRequest == null;\n\n if (canDedupe) {\n const body = typeof init.body === \"string\" ? init.body : \"\";\n /**\n * The key must capture the FULL request identity, including every\n * prepared header. `inFlightReads` is module-scoped across all\n * `Client` instances, so omitting headers would let two clients\n * pointed at the same URL/thread but using different credentials\n * (Authorization, custom auth headers, tenant-scoping defaults, …)\n * share one in-flight promise — a cross-tenant data leak.\n */\n const headers = serializeHeaders(init.headers);\n const key = `${init.method ?? \"GET\"} ${url.toString()} ${body} ${headers}`;\n const existing = inFlightReads.get(key);\n if (existing != null) return existing as Promise<T>;\n\n const promise = this.#performFetch<T>(url, init);\n inFlightReads.set(key, promise);\n const clear = () => {\n if (inFlightReads.get(key) === promise) inFlightReads.delete(key);\n };\n promise.then(clear, clear);\n return promise;\n }\n\n const [body, response] = await this.#performFetchWithResponse<T>(url, init);\n if (options?.withResponse) {\n return [body, response];\n }\n return body;\n }\n\n /**\n * Issue the prepared request (applying the `onRequest` hook) and\n * resolve the parsed body. Shared by the deduped and direct paths.\n */\n async #performFetch<T>(url: URL, init: RequestInit): Promise<T> {\n const [body] = await this.#performFetchWithResponse<T>(url, init);\n return body;\n }\n\n async #performFetchWithResponse<T>(\n url: URL,\n init: RequestInit\n ): Promise<[T, Response]> {\n let finalInit = init;\n if (this.onRequest) {\n finalInit = await this.onRequest(url, init);\n }\n\n const response = await this.asyncCaller.fetch(url.toString(), finalInit);\n\n const body = await (async () => {\n if (response.status === 202 || response.status === 204) {\n return undefined as T;\n }\n return response.json() as Promise<T>;\n })();\n\n return [body, response];\n }\n\n protected async *streamWithRetry<\n T extends { id?: string; event: string; data: unknown },\n >(config: {\n endpoint: string;\n method?: string;\n signal?: AbortSignal;\n headers?: Record<string, string>;\n params?: Record<string, unknown>;\n json?: unknown;\n maxRetries?: number;\n idleReconnect?: IdleReconnectMode;\n onReconnect?: (options: {\n attempt: number;\n lastEventId?: string;\n cause: unknown;\n }) => void;\n onInitialResponse?: (response: Response) => void | Promise<void>;\n }): AsyncGenerator<T> {\n const makeRequest = async (reconnectParams?: StreamRequestParams) => {\n const requestEndpoint = reconnectParams?.reconnectPath || config.endpoint;\n\n const isReconnect = !!reconnectParams?.reconnectPath;\n const method = isReconnect ? \"GET\" : config.method || \"GET\";\n\n const requestHeaders =\n isReconnect && reconnectParams?.lastEventId\n ? { ...config.headers, \"Last-Event-ID\": reconnectParams.lastEventId }\n : config.headers;\n\n // oxlint-disable-next-line prefer-const -- init is reassigned by onRequest hook\n let [url, init] = this.prepareFetchOptions(requestEndpoint, {\n method,\n timeoutMs: null,\n signal: config.signal,\n headers: requestHeaders,\n params: config.params,\n json: isReconnect ? undefined : config.json,\n });\n\n if (this.onRequest != null) {\n init = await this.onRequest(url, init);\n }\n\n const response = await this.asyncCaller.fetch(url.toString(), init);\n if (!response.body) {\n throw new Error(\"Expected response body from stream endpoint\");\n }\n\n if (!isReconnect && config.onInitialResponse) {\n await config.onInitialResponse(response);\n }\n\n // Insert the idle watchdog on the line stream (between the byte-line\n // decoder and the SSE decoder) so it can both reset on any line and\n // recognise `:` keep-alive heartbeats to drive `\"auto\"` mode. The SSE\n // decoder downstream discards those comment lines.\n const idleMode = config.idleReconnect ?? DEFAULT_IDLE_RECONNECT;\n const enableIdle = idleMode === \"auto\" || idleMode > 0;\n\n const lines = response.body.pipeThrough(BytesLineDecoder());\n const watched = enableIdle\n ? lines.pipeThrough(idleReconnectStream({ mode: idleMode }))\n : lines;\n const stream: ReadableStream<T> = watched.pipeThrough(\n SSEDecoder()\n ) as ReadableStream<T>;\n\n return { response, stream };\n };\n\n yield* streamWithRetry(makeRequest, {\n maxRetries: config.maxRetries ?? DEFAULT_MAX_RECONNECT_ATTEMPTS,\n signal: config.signal,\n onReconnect: config.onReconnect,\n });\n }\n}\n\nexport const REGEX_RUN_METADATA =\n /(\\/threads\\/(?<thread_id>.+))?\\/runs\\/(?<run_id>.+)/;\n\nexport function getRunMetadataFromResponse(\n response: Response\n): { run_id: string; thread_id?: string } | undefined {\n const contentLocation = response.headers.get(\"Content-Location\");\n if (!contentLocation) return undefined;\n\n const match = REGEX_RUN_METADATA.exec(contentLocation);\n\n if (!match?.groups?.run_id) return undefined;\n return {\n run_id: match.groups.run_id,\n thread_id: match.groups.thread_id || undefined,\n };\n}\n\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null;\n\n/**\n * Module-scoped, in-flight-only coalescing map for idempotent reads.\n *\n * Two independently-constructed clients (e.g. a React component that\n * remounts under Suspense / a reachability state flip, each minting a\n * fresh `Client`) can fire the *same* `getState` / `getHistory` read a\n * few milliseconds apart, before the first has resolved. Without\n * coalescing each pays the full round-trip — the duplicate\n * `threads/{id}/state` and `threads/{id}/history` requests seen on\n * reconnect.\n *\n * Keyed by `method + url + body + auth`, entries live only while a\n * request is in flight and are removed the moment it settles. This is\n * deliberately *not* a result cache: there is no TTL and no stored\n * payload, so it cannot serve stale data — it only ever shares a\n * promise that is already on the wire. Opt-in per call via\n * `{ dedupe: true }`, and skipped whenever the caller supplies its own\n * `AbortSignal` (so one consumer aborting can never cancel another's\n * read).\n */\nconst inFlightReads = new Map<string, Promise<unknown>>();\n\n/**\n * Deterministically serialize a prepared request's headers into a\n * stable string for use in the {@link inFlightReads} dedupe key. Header\n * names are normalized and sorted so ordering differences never produce\n * a different key, and every header (not just `x-api-key`) is included\n * so requests carrying different credentials never collide.\n */\nfunction serializeHeaders(headers: RequestInit[\"headers\"]): string {\n const normalized = mergeHeaders(\n headers as Record<string, HeaderValue> | undefined\n );\n return Object.keys(normalized)\n .sort()\n .map((name) => `${name}:${normalized[name]}`)\n .join(\"\\n\");\n}\n"],"mappings":";;;;;;AAgBA,UAAiB,eACf,SAC2C;CAC3C,IAAI;CACJ,IAAI,cAAc;AAGlB,KAAI,mBAAmB,SAAS;EAC9B,MAAM,UAA8B,EAAE;AACtC,UAAQ,SAAS,OAAO,SAAS;AAC/B,WAAQ,KAAK,CAAC,MAAM,MAAM,CAAC;IAC3B;AACF,SAAO;YACE,MAAM,QAAQ,QAAQ,CAC/B,QAAO;MACF;AACL,gBAAc;AACd,SAAO,OAAO,QAAQ,WAAW,EAAE,CAAC;;AAGtC,MAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK;AAClB,MAAI,OAAO,SAAS,SAClB,OAAM,IAAI,UACR,4CAA4C,OAAO,OACpD;EACH,MAAM,SAAS,MAAM,QAAQ,KAAK,GAAG,GAAG,KAAK,KAAK,CAAC,KAAK,GAAG;EAC3D,IAAI,WAAW;AAEf,OAAK,MAAM,SAAS,QAAQ;AAC1B,OAAI,UAAU,KAAA,EAAW;AAEzB,OAAI,eA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