mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-11 20:27:54 +02:00
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@langchain/langgraph-sdk",
|
||||
"version": "0.0.79",
|
||||
"version": "0.0.80",
|
||||
"description": "Client library for interacting with the LangGraph API",
|
||||
"type": "module",
|
||||
"packageManager": "yarn@1.22.19",
|
||||
|
||||
@@ -86,12 +86,18 @@ function getRunMetadataFromResponse(
|
||||
};
|
||||
}
|
||||
|
||||
export type RequestHook = (
|
||||
url: URL,
|
||||
init: RequestInit,
|
||||
) => Promise<RequestInit> | RequestInit;
|
||||
|
||||
export interface ClientConfig {
|
||||
apiUrl?: string;
|
||||
apiKey?: string;
|
||||
callerOptions?: AsyncCallerParams;
|
||||
timeoutMs?: number;
|
||||
defaultHeaders?: Record<string, string | null | undefined>;
|
||||
onRequest?: RequestHook;
|
||||
}
|
||||
|
||||
class BaseClient {
|
||||
@@ -103,6 +109,8 @@ class BaseClient {
|
||||
|
||||
protected defaultHeaders: Record<string, string | null | undefined>;
|
||||
|
||||
protected onRequest?: RequestHook;
|
||||
|
||||
constructor(config?: ClientConfig) {
|
||||
const callerOptions = {
|
||||
maxRetries: 4,
|
||||
@@ -136,6 +144,7 @@ class BaseClient {
|
||||
// Regex to remove trailing slash, if present
|
||||
this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
|
||||
this.defaultHeaders = config?.defaultHeaders || {};
|
||||
this.onRequest = config?.onRequest;
|
||||
const apiKey = getApiKey(config?.apiKey);
|
||||
if (apiKey) {
|
||||
this.defaultHeaders["X-Api-Key"] = apiKey;
|
||||
@@ -230,9 +239,14 @@ class BaseClient {
|
||||
withResponse?: boolean;
|
||||
},
|
||||
): Promise<T | [T, Response]> {
|
||||
const response = await this.asyncCaller.fetch(
|
||||
...this.prepareFetchOptions(path, options),
|
||||
);
|
||||
const [url, init] = this.prepareFetchOptions(path, options);
|
||||
|
||||
let finalInit = init;
|
||||
if (this.onRequest) {
|
||||
finalInit = await this.onRequest(url, init);
|
||||
}
|
||||
|
||||
const response = await this.asyncCaller.fetch(url, finalInit);
|
||||
|
||||
const body = (() => {
|
||||
if (response.status === 202 || response.status === 204) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export { Client } from "./client.js";
|
||||
export { Client, getApiKey } from "./client.js";
|
||||
export type { ClientConfig, RequestHook } from "./client.js";
|
||||
|
||||
export type {
|
||||
AssistantBase,
|
||||
|
||||
Reference in New Issue
Block a user