@langchain/langgraph-sdk 0.0.79 → 0.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.cjs CHANGED
@@ -71,6 +71,12 @@ class BaseClient {
71
71
  writable: true,
72
72
  value: void 0
73
73
  });
74
+ Object.defineProperty(this, "onRequest", {
75
+ enumerable: true,
76
+ configurable: true,
77
+ writable: true,
78
+ value: void 0
79
+ });
74
80
  const callerOptions = {
75
81
  maxRetries: 4,
76
82
  maxConcurrency: 4,
@@ -95,6 +101,7 @@ class BaseClient {
95
101
  // Regex to remove trailing slash, if present
96
102
  this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
97
103
  this.defaultHeaders = config?.defaultHeaders || {};
104
+ this.onRequest = config?.onRequest;
98
105
  const apiKey = getApiKey(config?.apiKey);
99
106
  if (apiKey) {
100
107
  this.defaultHeaders["X-Api-Key"] = apiKey;
@@ -141,7 +148,12 @@ class BaseClient {
141
148
  return [targetUrl, mutatedOptions];
142
149
  }
143
150
  async fetch(path, options) {
144
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
151
+ const [url, init] = this.prepareFetchOptions(path, options);
152
+ let finalInit = init;
153
+ if (this.onRequest) {
154
+ finalInit = await this.onRequest(url, init);
155
+ }
156
+ const response = await this.asyncCaller.fetch(url, finalInit);
145
157
  const body = (() => {
146
158
  if (response.status === 202 || response.status === 204) {
147
159
  return undefined;
package/dist/client.d.ts CHANGED
@@ -14,18 +14,21 @@ import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
14
14
  * @returns The API key if found, otherwise undefined
15
15
  */
16
16
  export declare function getApiKey(apiKey?: string): string | undefined;
17
+ export type RequestHook = (url: URL, init: RequestInit) => Promise<RequestInit> | RequestInit;
17
18
  export interface ClientConfig {
18
19
  apiUrl?: string;
19
20
  apiKey?: string;
20
21
  callerOptions?: AsyncCallerParams;
21
22
  timeoutMs?: number;
22
23
  defaultHeaders?: Record<string, string | null | undefined>;
24
+ onRequest?: RequestHook;
23
25
  }
24
26
  declare class BaseClient {
25
27
  protected asyncCaller: AsyncCaller;
26
28
  protected timeoutMs: number | undefined;
27
29
  protected apiUrl: string;
28
30
  protected defaultHeaders: Record<string, string | null | undefined>;
31
+ protected onRequest?: RequestHook;
29
32
  constructor(config?: ClientConfig);
30
33
  protected prepareFetchOptions(path: string, options?: RequestInit & {
31
34
  json?: unknown;
package/dist/client.js CHANGED
@@ -67,6 +67,12 @@ class BaseClient {
67
67
  writable: true,
68
68
  value: void 0
69
69
  });
70
+ Object.defineProperty(this, "onRequest", {
71
+ enumerable: true,
72
+ configurable: true,
73
+ writable: true,
74
+ value: void 0
75
+ });
70
76
  const callerOptions = {
71
77
  maxRetries: 4,
72
78
  maxConcurrency: 4,
@@ -91,6 +97,7 @@ class BaseClient {
91
97
  // Regex to remove trailing slash, if present
92
98
  this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
93
99
  this.defaultHeaders = config?.defaultHeaders || {};
100
+ this.onRequest = config?.onRequest;
94
101
  const apiKey = getApiKey(config?.apiKey);
95
102
  if (apiKey) {
96
103
  this.defaultHeaders["X-Api-Key"] = apiKey;
@@ -137,7 +144,12 @@ class BaseClient {
137
144
  return [targetUrl, mutatedOptions];
138
145
  }
139
146
  async fetch(path, options) {
140
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
147
+ const [url, init] = this.prepareFetchOptions(path, options);
148
+ let finalInit = init;
149
+ if (this.onRequest) {
150
+ finalInit = await this.onRequest(url, init);
151
+ }
152
+ const response = await this.asyncCaller.fetch(url, finalInit);
141
153
  const body = (() => {
142
154
  if (response.status === 202 || response.status === 204) {
143
155
  return undefined;
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.overrideFetchImplementation = exports.Client = void 0;
3
+ exports.overrideFetchImplementation = exports.getApiKey = exports.Client = void 0;
4
4
  var client_js_1 = require("./client.cjs");
5
5
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
6
+ Object.defineProperty(exports, "getApiKey", { enumerable: true, get: function () { return client_js_1.getApiKey; } });
6
7
  var fetch_js_1 = require("./singletons/fetch.cjs");
7
8
  Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- export { Client } from "./client.js";
1
+ export { Client, getApiKey } from "./client.js";
2
+ export type { ClientConfig, RequestHook } from "./client.js";
2
3
  export type { AssistantBase, Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, ListNamespaceResponse, Item, SearchItem, SearchItemsResponse, CronCreateResponse, CronCreateForThreadResponse, } from "./schema.js";
3
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
5
  export type { OnConflictBehavior, Command } from "./types.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { Client } from "./client.js";
1
+ export { Client, getApiKey } from "./client.js";
2
2
  export { overrideFetchImplementation } from "./singletons/fetch.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",