@langchain/langgraph-sdk 0.0.37 → 0.0.38

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
@@ -6,6 +6,7 @@ const index_js_1 = require("./utils/eventsource-parser/index.cjs");
6
6
  const stream_js_1 = require("./utils/stream.cjs");
7
7
  const signals_js_1 = require("./utils/signals.cjs");
8
8
  const env_js_1 = require("./utils/env.cjs");
9
+ const fetch_js_1 = require("./singletons/fetch.cjs");
9
10
  /**
10
11
  * Get the API key from the environment.
11
12
  * Precedence:
@@ -63,7 +64,7 @@ class BaseClient {
63
64
  maxConcurrency: 4,
64
65
  ...config?.callerOptions,
65
66
  });
66
- this.timeoutMs = config?.timeoutMs || 12_000;
67
+ this.timeoutMs = config?.timeoutMs;
67
68
  // default limit being capped by Chrome
68
69
  // https://github.com/nodejs/undici/issues/1373
69
70
  // Regex to remove trailing slash, if present
@@ -93,7 +94,7 @@ class BaseClient {
93
94
  timeoutSignal = AbortSignal.timeout(options.timeoutMs);
94
95
  }
95
96
  }
96
- else {
97
+ else if (this.timeoutMs != null) {
97
98
  timeoutSignal = AbortSignal.timeout(this.timeoutMs);
98
99
  }
99
100
  mutatedOptions.signal = (0, signals_js_1.mergeSignals)(timeoutSignal, mutatedOptions.signal);
@@ -112,7 +113,7 @@ class BaseClient {
112
113
  return [targetUrl, mutatedOptions];
113
114
  }
114
115
  async fetch(path, options) {
115
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
116
+ const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(path, options));
116
117
  if (response.status === 202 || response.status === 204) {
117
118
  return undefined;
118
119
  }
@@ -455,7 +456,7 @@ class ThreadsClient extends BaseClient {
455
456
  async patchState(threadIdOrConfig, metadata) {
456
457
  let threadId;
457
458
  if (typeof threadIdOrConfig !== "string") {
458
- if (typeof threadIdOrConfig.configurable.thread_id !== "string") {
459
+ if (typeof threadIdOrConfig.configurable?.thread_id !== "string") {
459
460
  throw new Error("Thread ID is required when updating state with a config.");
460
461
  }
461
462
  threadId = threadIdOrConfig.configurable.thread_id;
@@ -518,7 +519,7 @@ class RunsClient extends BaseClient {
518
519
  if_not_exists: payload?.ifNotExists,
519
520
  };
520
521
  const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
521
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
522
+ const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(endpoint, {
522
523
  method: "POST",
523
524
  json,
524
525
  timeoutMs: null,
@@ -722,7 +723,7 @@ class RunsClient extends BaseClient {
722
723
  options instanceof AbortSignal
723
724
  ? { signal: options }
724
725
  : options;
725
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
726
+ const response = await this.asyncCaller.call((0, fetch_js_1._getFetchImplementation)(), ...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
726
727
  method: "GET",
727
728
  timeoutMs: null,
728
729
  signal: opts?.signal,
package/dist/client.d.ts CHANGED
@@ -22,7 +22,7 @@ interface ClientConfig {
22
22
  }
23
23
  declare class BaseClient {
24
24
  protected asyncCaller: AsyncCaller;
25
- protected timeoutMs: number;
25
+ protected timeoutMs: number | undefined;
26
26
  protected apiUrl: string;
27
27
  protected defaultHeaders: Record<string, string | null | undefined>;
28
28
  constructor(config?: ClientConfig);
package/dist/client.js CHANGED
@@ -3,6 +3,7 @@ import { createParser, } from "./utils/eventsource-parser/index.js";
3
3
  import { IterableReadableStream } from "./utils/stream.js";
4
4
  import { mergeSignals } from "./utils/signals.js";
5
5
  import { getEnvironmentVariable } from "./utils/env.js";
6
+ import { _getFetchImplementation } from "./singletons/fetch.js";
6
7
  /**
7
8
  * Get the API key from the environment.
8
9
  * Precedence:
@@ -59,7 +60,7 @@ class BaseClient {
59
60
  maxConcurrency: 4,
60
61
  ...config?.callerOptions,
61
62
  });
62
- this.timeoutMs = config?.timeoutMs || 12_000;
63
+ this.timeoutMs = config?.timeoutMs;
63
64
  // default limit being capped by Chrome
64
65
  // https://github.com/nodejs/undici/issues/1373
65
66
  // Regex to remove trailing slash, if present
@@ -89,7 +90,7 @@ class BaseClient {
89
90
  timeoutSignal = AbortSignal.timeout(options.timeoutMs);
90
91
  }
91
92
  }
92
- else {
93
+ else if (this.timeoutMs != null) {
93
94
  timeoutSignal = AbortSignal.timeout(this.timeoutMs);
94
95
  }
95
96
  mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);
@@ -108,7 +109,7 @@ class BaseClient {
108
109
  return [targetUrl, mutatedOptions];
109
110
  }
110
111
  async fetch(path, options) {
111
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
112
+ const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(path, options));
112
113
  if (response.status === 202 || response.status === 204) {
113
114
  return undefined;
114
115
  }
@@ -449,7 +450,7 @@ export class ThreadsClient extends BaseClient {
449
450
  async patchState(threadIdOrConfig, metadata) {
450
451
  let threadId;
451
452
  if (typeof threadIdOrConfig !== "string") {
452
- if (typeof threadIdOrConfig.configurable.thread_id !== "string") {
453
+ if (typeof threadIdOrConfig.configurable?.thread_id !== "string") {
453
454
  throw new Error("Thread ID is required when updating state with a config.");
454
455
  }
455
456
  threadId = threadIdOrConfig.configurable.thread_id;
@@ -511,7 +512,7 @@ export class RunsClient extends BaseClient {
511
512
  if_not_exists: payload?.ifNotExists,
512
513
  };
513
514
  const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
514
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
515
+ const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(endpoint, {
515
516
  method: "POST",
516
517
  json,
517
518
  timeoutMs: null,
@@ -715,7 +716,7 @@ export class RunsClient extends BaseClient {
715
716
  options instanceof AbortSignal
716
717
  ? { signal: options }
717
718
  : options;
718
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
719
+ const response = await this.asyncCaller.call(_getFetchImplementation(), ...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
719
720
  method: "GET",
720
721
  timeoutMs: null,
721
722
  signal: opts?.signal,
package/dist/index.cjs CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = void 0;
3
+ exports.overrideFetchImplementation = 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
+ var fetch_js_1 = require("./singletons/fetch.cjs");
7
+ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true, get: function () { return fetch_js_1.overrideFetchImplementation; } });
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { Client } from "./client.js";
2
- export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, } from "./schema.js";
2
+ export type { 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
+ export { overrideFetchImplementation } from "./singletons/fetch.js";
3
4
  export type { OnConflictBehavior, Command } from "./types.js";
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
1
  export { Client } from "./client.js";
2
+ export { overrideFetchImplementation } from "./singletons/fetch.js";
package/dist/schema.d.ts CHANGED
@@ -4,7 +4,7 @@ export type RunStatus = "pending" | "running" | "error" | "success" | "timeout"
4
4
  export type ThreadStatus = "idle" | "busy" | "interrupted" | "error";
5
5
  type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
6
6
  export type CancelAction = "interrupt" | "rollback";
7
- export interface Config {
7
+ export type Config = {
8
8
  /**
9
9
  * Tags for this call and any sub-calls (eg. a Chain calling an LLM).
10
10
  * You can use these to filter calls.
@@ -18,18 +18,18 @@ export interface Config {
18
18
  /**
19
19
  * Runtime values for attributes previously made configurable on this Runnable.
20
20
  */
21
- configurable: {
21
+ configurable?: {
22
22
  /**
23
23
  * ID of the thread
24
24
  */
25
- thread_id?: string;
25
+ thread_id?: Optional<string>;
26
26
  /**
27
27
  * Timestamp of the state checkpoint
28
28
  */
29
- checkpoint_id?: string;
29
+ checkpoint_id?: Optional<string>;
30
30
  [key: string]: unknown;
31
31
  };
32
- }
32
+ };
33
33
  export interface GraphSchema {
34
34
  /**
35
35
  * The ID of the graph.
@@ -185,12 +185,12 @@ export interface Run {
185
185
  /** Strategy to handle concurrent runs on the same thread */
186
186
  multitask_strategy: Optional<MultitaskStrategy>;
187
187
  }
188
- export interface Checkpoint {
188
+ export type Checkpoint = {
189
189
  thread_id: string;
190
190
  checkpoint_ns: string;
191
191
  checkpoint_id: Optional<string>;
192
192
  checkpoint_map: Optional<Record<string, unknown>>;
193
- }
193
+ };
194
194
  export interface ListNamespaceResponse {
195
195
  namespaces: string[][];
196
196
  }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._getFetchImplementation = exports.overrideFetchImplementation = void 0;
4
+ // Wrap the default fetch call due to issues with illegal invocations
5
+ // in some environments:
6
+ // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
7
+ // @ts-expect-error Broad typing to support a range of fetch implementations
8
+ const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
9
+ const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("lg:fetch_implementation");
10
+ /**
11
+ * Overrides the fetch implementation used for LangSmith calls.
12
+ * You should use this if you need to use an implementation of fetch
13
+ * other than the default global (e.g. for dealing with proxies).
14
+ * @param fetch The new fetch function to use.
15
+ */
16
+ const overrideFetchImplementation = (fetch) => {
17
+ globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
18
+ };
19
+ exports.overrideFetchImplementation = overrideFetchImplementation;
20
+ /**
21
+ * @internal
22
+ */
23
+ const _getFetchImplementation = () => {
24
+ return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
25
+ DEFAULT_FETCH_IMPLEMENTATION);
26
+ };
27
+ exports._getFetchImplementation = _getFetchImplementation;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Overrides the fetch implementation used for LangSmith calls.
3
+ * You should use this if you need to use an implementation of fetch
4
+ * other than the default global (e.g. for dealing with proxies).
5
+ * @param fetch The new fetch function to use.
6
+ */
7
+ export declare const overrideFetchImplementation: (fetch: (...args: any[]) => any) => void;
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare const _getFetchImplementation: () => (...args: any[]) => any;
@@ -0,0 +1,22 @@
1
+ // Wrap the default fetch call due to issues with illegal invocations
2
+ // in some environments:
3
+ // https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
4
+ // @ts-expect-error Broad typing to support a range of fetch implementations
5
+ const DEFAULT_FETCH_IMPLEMENTATION = (...args) => fetch(...args);
6
+ const LANGSMITH_FETCH_IMPLEMENTATION_KEY = Symbol.for("lg:fetch_implementation");
7
+ /**
8
+ * Overrides the fetch implementation used for LangSmith calls.
9
+ * You should use this if you need to use an implementation of fetch
10
+ * other than the default global (e.g. for dealing with proxies).
11
+ * @param fetch The new fetch function to use.
12
+ */
13
+ export const overrideFetchImplementation = (fetch) => {
14
+ globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] = fetch;
15
+ };
16
+ /**
17
+ * @internal
18
+ */
19
+ export const _getFetchImplementation = () => {
20
+ return (globalThis[LANGSMITH_FETCH_IMPLEMENTATION_KEY] ??
21
+ DEFAULT_FETCH_IMPLEMENTATION);
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",