@langchain/langgraph-sdk 0.0.25 → 0.0.27

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
@@ -1,10 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClient = exports.AssistantsClient = exports.CronsClient = void 0;
3
+ exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClient = exports.AssistantsClient = exports.CronsClient = exports.getApiKey = void 0;
4
4
  const async_caller_js_1 = require("./utils/async_caller.cjs");
5
5
  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
+ /**
9
+ * Get the API key from the environment.
10
+ * Precedence:
11
+ * 1. explicit argument
12
+ * 2. LANGGRAPH_API_KEY
13
+ * 3. LANGSMITH_API_KEY
14
+ * 4. LANGCHAIN_API_KEY
15
+ *
16
+ * @param apiKey - Optional API key provided as an argument
17
+ * @returns The API key if found, otherwise undefined
18
+ */
19
+ function getApiKey(apiKey) {
20
+ if (apiKey) {
21
+ return apiKey;
22
+ }
23
+ const prefixes = ["LANGGRAPH", "LANGSMITH", "LANGCHAIN"];
24
+ for (const prefix of prefixes) {
25
+ const envKey = process.env[`${prefix}_API_KEY`];
26
+ if (envKey) {
27
+ // Remove surrounding quotes
28
+ return envKey.trim().replace(/^["']|["']$/g, "");
29
+ }
30
+ }
31
+ return undefined;
32
+ }
33
+ exports.getApiKey = getApiKey;
8
34
  class BaseClient {
9
35
  constructor(config) {
10
36
  Object.defineProperty(this, "asyncCaller", {
@@ -39,10 +65,12 @@ class BaseClient {
39
65
  this.timeoutMs = config?.timeoutMs || 12_000;
40
66
  // default limit being capped by Chrome
41
67
  // https://github.com/nodejs/undici/issues/1373
42
- this.apiUrl = config?.apiUrl || "http://localhost:8123";
68
+ // Regex to remove trailing slash, if present
69
+ this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || "http://localhost:8123";
43
70
  this.defaultHeaders = config?.defaultHeaders || {};
44
- if (config?.apiKey != null) {
45
- this.defaultHeaders["X-Api-Key"] = config.apiKey;
71
+ const apiKey = getApiKey(config?.apiKey);
72
+ if (apiKey) {
73
+ this.defaultHeaders["X-Api-Key"] = apiKey;
46
74
  }
47
75
  }
48
76
  prepareFetchOptions(path, options) {
package/dist/client.d.ts CHANGED
@@ -1,6 +1,18 @@
1
1
  import { Assistant, AssistantGraph, CancelAction, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, AssistantVersion, Subgraphs, Checkpoint, SearchItemsResponse, ListNamespaceResponse, Item, ThreadStatus } from "./schema.js";
2
2
  import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.js";
3
3
  import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, CronsCreatePayload, OnConflictBehavior } from "./types.js";
4
+ /**
5
+ * Get the API key from the environment.
6
+ * Precedence:
7
+ * 1. explicit argument
8
+ * 2. LANGGRAPH_API_KEY
9
+ * 3. LANGSMITH_API_KEY
10
+ * 4. LANGCHAIN_API_KEY
11
+ *
12
+ * @param apiKey - Optional API key provided as an argument
13
+ * @returns The API key if found, otherwise undefined
14
+ */
15
+ export declare function getApiKey(apiKey?: string): string | undefined;
4
16
  interface ClientConfig {
5
17
  apiUrl?: string;
6
18
  apiKey?: string;
package/dist/client.js CHANGED
@@ -2,6 +2,31 @@ import { AsyncCaller } from "./utils/async_caller.js";
2
2
  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
+ /**
6
+ * Get the API key from the environment.
7
+ * Precedence:
8
+ * 1. explicit argument
9
+ * 2. LANGGRAPH_API_KEY
10
+ * 3. LANGSMITH_API_KEY
11
+ * 4. LANGCHAIN_API_KEY
12
+ *
13
+ * @param apiKey - Optional API key provided as an argument
14
+ * @returns The API key if found, otherwise undefined
15
+ */
16
+ export function getApiKey(apiKey) {
17
+ if (apiKey) {
18
+ return apiKey;
19
+ }
20
+ const prefixes = ["LANGGRAPH", "LANGSMITH", "LANGCHAIN"];
21
+ for (const prefix of prefixes) {
22
+ const envKey = process.env[`${prefix}_API_KEY`];
23
+ if (envKey) {
24
+ // Remove surrounding quotes
25
+ return envKey.trim().replace(/^["']|["']$/g, "");
26
+ }
27
+ }
28
+ return undefined;
29
+ }
5
30
  class BaseClient {
6
31
  constructor(config) {
7
32
  Object.defineProperty(this, "asyncCaller", {
@@ -36,10 +61,12 @@ class BaseClient {
36
61
  this.timeoutMs = config?.timeoutMs || 12_000;
37
62
  // default limit being capped by Chrome
38
63
  // https://github.com/nodejs/undici/issues/1373
39
- this.apiUrl = config?.apiUrl || "http://localhost:8123";
64
+ // Regex to remove trailing slash, if present
65
+ this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || "http://localhost:8123";
40
66
  this.defaultHeaders = config?.defaultHeaders || {};
41
- if (config?.apiKey != null) {
42
- this.defaultHeaders["X-Api-Key"] = config.apiKey;
67
+ const apiKey = getApiKey(config?.apiKey);
68
+ if (apiKey) {
69
+ this.defaultHeaders["X-Api-Key"] = apiKey;
43
70
  }
44
71
  }
45
72
  prepareFetchOptions(path, options) {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { Client } from "./client.js";
2
- export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, } from "./schema.js";
3
- export type { OnConflictBehavior } from "./types.js";
2
+ export type { Assistant, AssistantVersion, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadTask, ThreadState, ThreadStatus, Cron, Checkpoint, Interrupt, } from "./schema.js";
3
+ export type { OnConflictBehavior, Command } from "./types.js";
package/dist/schema.d.ts CHANGED
@@ -100,6 +100,15 @@ export interface AssistantGraph {
100
100
  conditional?: boolean;
101
101
  }>;
102
102
  }
103
+ /**
104
+ * An interrupt thrown inside a thread.
105
+ */
106
+ export interface Interrupt {
107
+ value: unknown;
108
+ when: "during";
109
+ resumable: boolean;
110
+ ns?: string[];
111
+ }
103
112
  export interface Thread<ValuesType = DefaultValues> {
104
113
  /** The ID of the thread. */
105
114
  thread_id: string;
@@ -113,6 +122,8 @@ export interface Thread<ValuesType = DefaultValues> {
113
122
  status: ThreadStatus;
114
123
  /** The current state of the thread. */
115
124
  values: ValuesType;
125
+ /** Interrupts which were thrown in this thread */
126
+ interrupts: Record<string, Array<Interrupt>>;
116
127
  }
117
128
  export interface Cron {
118
129
  /** The ID of the cron */
@@ -152,12 +163,7 @@ export interface ThreadTask {
152
163
  name: string;
153
164
  result?: unknown;
154
165
  error: Optional<string>;
155
- interrupts: Array<{
156
- value: unknown;
157
- when: "during";
158
- resumable: boolean;
159
- ns?: string[];
160
- }>;
166
+ interrupts: Array<Interrupt>;
161
167
  checkpoint: Optional<Checkpoint>;
162
168
  state: Optional<ThreadState>;
163
169
  }
package/dist/types.d.ts CHANGED
@@ -10,8 +10,17 @@ export interface Send {
10
10
  input: Record<string, unknown> | null;
11
11
  }
12
12
  export interface Command {
13
+ /**
14
+ * An object to update the thread state with.
15
+ */
13
16
  update?: Record<string, unknown>;
17
+ /**
18
+ * The value to return from an `interrupt` function call.
19
+ */
14
20
  resume?: unknown;
21
+ /**
22
+ * A single, or array of `Send` commands to trigger nodes.
23
+ */
15
24
  send?: Send | Send[];
16
25
  }
17
26
  interface RunsInvokePayload {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",