@langchain/langgraph-sdk 0.0.1-rc.9 → 0.0.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License
1
+ MIT License
2
2
 
3
- Copyright (c) 2024 LangChain
3
+ Copyright (c) 2024 LangChain, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
9
  copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
14
 
15
15
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
16
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
17
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # LangGraph JS/TS SDK
2
+
3
+ This repository contains the JS/TS SDK for interacting with the LangGraph REST API.
4
+
5
+ ## Quick Start
6
+
7
+ To get started with the JS/TS SDK, [install the package](https://www.npmjs.com/package/@langchain/langgraph-sdk)
8
+
9
+ ```bash
10
+ yarn add @langchain/langgraph-sdk
11
+ ```
12
+
13
+ You will need a running LangGraph API server. If you're running a server locally using `langgraph-cli`, SDK will automatically point at `http://localhost:8123`, otherwise
14
+ you would need to specify the server URL when creating a client.
15
+
16
+ ```js
17
+ import { Client } from "@langchain/langgraph-sdk";
18
+
19
+ const client = new Client();
20
+
21
+ // List all assistants
22
+ const assistants = await client.assistants.search({
23
+ metadata: null,
24
+ offset: 0,
25
+ limit: 10,
26
+ });
27
+
28
+ // We auto-create an assistant for each graph you register in config.
29
+ const agent = assistants[0];
30
+
31
+ // Start a new thread
32
+ const thread = await client.threads.create();
33
+
34
+ // Start a streaming run
35
+ const messages = [{ role: "human", content: "what's the weather in la" }];
36
+
37
+ const streamResponse = client.runs.stream(
38
+ thread["thread_id"],
39
+ agent["assistant_id"],
40
+ {
41
+ input: { messages },
42
+ }
43
+ );
44
+
45
+ for await (const chunk of streamResponse) {
46
+ console.log(chunk);
47
+ }
48
+ ```
49
+
50
+ ## Documentation
51
+
52
+ To generate documentation, run the following commands:
53
+
54
+ 1. Generate docs.
55
+
56
+ yarn typedoc
57
+
58
+ 1. Consolidate doc files into one markdown file.
59
+
60
+ npx concat-md --decrease-title-levels --ignore=js_ts_sdk_ref.md --start-title-level-at 2 docs > docs/js_ts_sdk_ref.md
61
+
62
+ 1. Copy `js_ts_sdk_ref.md` to MkDocs directory.
63
+
64
+ cp docs/js_ts_sdk_ref.md ../../docs/docs/cloud/reference/sdk/js_ts_sdk_ref.md
package/dist/client.d.mts CHANGED
@@ -1,15 +1,17 @@
1
- import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, RunEvent, Thread, ThreadState } from "./schema.js";
1
+ import { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron } from "./schema.js";
2
2
  import { AsyncCaller, AsyncCallerParams } from "./utils/async_caller.mjs";
3
- import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload } from "./types.mjs";
3
+ import { RunsCreatePayload, RunsStreamPayload, RunsWaitPayload, StreamEvent, CronsCreatePayload } from "./types.mjs";
4
4
  interface ClientConfig {
5
5
  apiUrl?: string;
6
6
  callerOptions?: AsyncCallerParams;
7
7
  timeoutMs?: number;
8
+ defaultHeaders?: Record<string, string | null | undefined>;
8
9
  }
9
10
  declare class BaseClient {
10
11
  protected asyncCaller: AsyncCaller;
11
12
  protected timeoutMs: number;
12
13
  protected apiUrl: string;
14
+ protected defaultHeaders: Record<string, string | null | undefined>;
13
15
  constructor(config?: ClientConfig);
14
16
  protected prepareFetchOptions(path: string, options?: RequestInit & {
15
17
  json?: unknown;
@@ -20,6 +22,39 @@ declare class BaseClient {
20
22
  params?: Record<string, unknown>;
21
23
  }): Promise<T>;
22
24
  }
25
+ declare class CronsClient extends BaseClient {
26
+ /**
27
+ *
28
+ * @param threadId The ID of the thread.
29
+ * @param assistantId Assistant ID to use for this cron job.
30
+ * @param payload Payload for creating a cron job.
31
+ * @returns The created background run.
32
+ */
33
+ createForThread(threadId: string, assistantId: string, payload?: CronsCreatePayload): Promise<Run>;
34
+ /**
35
+ *
36
+ * @param assistantId Assistant ID to use for this cron job.
37
+ * @param payload Payload for creating a cron job.
38
+ * @returns
39
+ */
40
+ create(assistantId: string, payload?: CronsCreatePayload): Promise<Run>;
41
+ /**
42
+ *
43
+ * @param cronId Cron ID of Cron job to delete.
44
+ */
45
+ delete(cronId: string): Promise<void>;
46
+ /**
47
+ *
48
+ * @param query Query options.
49
+ * @returns List of crons.
50
+ */
51
+ search(query?: {
52
+ assistantId?: string;
53
+ threadId?: string;
54
+ limit?: number;
55
+ offset?: number;
56
+ }): Promise<Cron[]>;
57
+ }
23
58
  declare class AssistantsClient extends BaseClient {
24
59
  /**
25
60
  * Get an assistant by ID.
@@ -61,12 +96,19 @@ declare class AssistantsClient extends BaseClient {
61
96
  config?: Config;
62
97
  metadata?: Metadata;
63
98
  }): Promise<Assistant>;
99
+ /**
100
+ * Delete an assistant.
101
+ *
102
+ * @param assistantId ID of the assistant.
103
+ */
104
+ delete(assistantId: string): Promise<void>;
64
105
  /**
65
106
  * List assistants.
66
107
  * @param query Query options.
67
108
  * @returns List of assistants.
68
109
  */
69
110
  search(query?: {
111
+ graphId?: string;
70
112
  metadata?: Metadata;
71
113
  limit?: number;
72
114
  offset?: number;
@@ -171,15 +213,12 @@ declare class ThreadsClient extends BaseClient {
171
213
  }): Promise<ThreadState<ValuesType>[]>;
172
214
  }
173
215
  declare class RunsClient extends BaseClient {
174
- /**
175
- * Create a run and stream the results.
176
- *
177
- * @param threadId The ID of the thread.
178
- * @param assistantId Assistant ID to use for this run.
179
- * @param payload Payload for creating a run.
180
- */
216
+ stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy">): AsyncGenerator<{
217
+ event: StreamEvent;
218
+ data: any;
219
+ }>;
181
220
  stream(threadId: string, assistantId: string, payload?: RunsStreamPayload): AsyncGenerator<{
182
- event: "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | (string & {});
221
+ event: StreamEvent;
183
222
  data: any;
184
223
  }>;
185
224
  /**
@@ -191,14 +230,7 @@ declare class RunsClient extends BaseClient {
191
230
  * @returns The created run.
192
231
  */
193
232
  create(threadId: string, assistantId: string, payload?: RunsCreatePayload): Promise<Run>;
194
- /**
195
- * Create a run and wait for it to complete.
196
- *
197
- * @param threadId The ID of the thread.
198
- * @param assistantId Assistant ID to use for this run.
199
- * @param payload Payload for creating a run.
200
- * @returns The last values chunk of the thread.
201
- */
233
+ wait(threadId: null, assistantId: string, payload?: Omit<RunsWaitPayload, "multitaskStrategy">): Promise<ThreadState["values"]>;
202
234
  wait(threadId: string, assistantId: string, payload?: RunsWaitPayload): Promise<ThreadState["values"]>;
203
235
  /**
204
236
  * List all runs for a thread.
@@ -228,25 +260,30 @@ declare class RunsClient extends BaseClient {
228
260
  */
229
261
  get(threadId: string, runId: string): Promise<Run>;
230
262
  /**
231
- * List all events for a run.
263
+ * Cancel a run.
232
264
  *
233
265
  * @param threadId The ID of the thread.
234
266
  * @param runId The ID of the run.
235
- * @param options Filtering and pagination options.
236
- * @returns List of events.
267
+ * @param wait Whether to block when canceling
268
+ * @returns
237
269
  */
238
- listEvents(threadId: string, runId: string, options?: {
239
- /**
240
- * Maximum number of events to return.
241
- * Defaults to 10
242
- */
243
- limit?: number;
244
- /**
245
- * Offset to start from.
246
- * Defaults to 0.
247
- */
248
- offset?: number;
249
- }): Promise<RunEvent[]>;
270
+ cancel(threadId: string, runId: string, wait?: boolean): Promise<void>;
271
+ /**
272
+ * Block until a run is done.
273
+ *
274
+ * @param threadId The ID of the thread.
275
+ * @param runId The ID of the run.
276
+ * @returns
277
+ */
278
+ join(threadId: string, runId: string): Promise<void>;
279
+ /**
280
+ * Delete a run.
281
+ *
282
+ * @param threadId The ID of the thread.
283
+ * @param runId The ID of the run.
284
+ * @returns
285
+ */
286
+ delete(threadId: string, runId: string): Promise<void>;
250
287
  }
251
288
  export declare class Client {
252
289
  /**
@@ -261,6 +298,10 @@ export declare class Client {
261
298
  * The client for interacting with runs.
262
299
  */
263
300
  runs: RunsClient;
301
+ /**
302
+ * The client for interacting with cron runs.
303
+ */
304
+ crons: CronsClient;
264
305
  constructor(config?: ClientConfig);
265
306
  }
266
307
  export {};
package/dist/client.mjs CHANGED
@@ -21,6 +21,12 @@ class BaseClient {
21
21
  writable: true,
22
22
  value: void 0
23
23
  });
24
+ Object.defineProperty(this, "defaultHeaders", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
24
30
  this.asyncCaller = new AsyncCaller({
25
31
  maxRetries: 4,
26
32
  maxConcurrency: 4,
@@ -28,9 +34,13 @@ class BaseClient {
28
34
  });
29
35
  this.timeoutMs = config?.timeoutMs || 12_000;
30
36
  this.apiUrl = config?.apiUrl || "http://localhost:8123";
37
+ this.defaultHeaders = config?.defaultHeaders || {};
31
38
  }
32
39
  prepareFetchOptions(path, options) {
33
- const mutatedOptions = { ...options };
40
+ const mutatedOptions = {
41
+ ...options,
42
+ headers: { ...this.defaultHeaders, ...options?.headers },
43
+ };
34
44
  if (mutatedOptions.json) {
35
45
  mutatedOptions.body = JSON.stringify(mutatedOptions.json);
36
46
  mutatedOptions.headers = {
@@ -55,9 +65,84 @@ class BaseClient {
55
65
  }
56
66
  async fetch(path, options) {
57
67
  const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(path, options));
68
+ if (response.status === 202 || response.status === 204) {
69
+ return undefined;
70
+ }
58
71
  return response.json();
59
72
  }
60
73
  }
74
+ class CronsClient extends BaseClient {
75
+ /**
76
+ *
77
+ * @param threadId The ID of the thread.
78
+ * @param assistantId Assistant ID to use for this cron job.
79
+ * @param payload Payload for creating a cron job.
80
+ * @returns The created background run.
81
+ */
82
+ async createForThread(threadId, assistantId, payload) {
83
+ const json = {
84
+ schedule: payload?.schedule,
85
+ input: payload?.input,
86
+ config: payload?.config,
87
+ metadata: payload?.metadata,
88
+ assistant_id: assistantId,
89
+ interrupt_before: payload?.interruptBefore,
90
+ interrupt_after: payload?.interruptAfter,
91
+ webhook: payload?.webhook,
92
+ };
93
+ return this.fetch(`/threads/${threadId}/runs/crons`, {
94
+ method: "POST",
95
+ json,
96
+ });
97
+ }
98
+ /**
99
+ *
100
+ * @param assistantId Assistant ID to use for this cron job.
101
+ * @param payload Payload for creating a cron job.
102
+ * @returns
103
+ */
104
+ async create(assistantId, payload) {
105
+ const json = {
106
+ schedule: payload?.schedule,
107
+ input: payload?.input,
108
+ config: payload?.config,
109
+ metadata: payload?.metadata,
110
+ assistant_id: assistantId,
111
+ interrupt_before: payload?.interruptBefore,
112
+ interrupt_after: payload?.interruptAfter,
113
+ webhook: payload?.webhook,
114
+ };
115
+ return this.fetch(`/runs/crons`, {
116
+ method: "POST",
117
+ json,
118
+ });
119
+ }
120
+ /**
121
+ *
122
+ * @param cronId Cron ID of Cron job to delete.
123
+ */
124
+ async delete(cronId) {
125
+ await this.fetch(`/runs/crons/${cronId}`, {
126
+ method: "DELETE",
127
+ });
128
+ }
129
+ /**
130
+ *
131
+ * @param query Query options.
132
+ * @returns List of crons.
133
+ */
134
+ async search(query) {
135
+ return this.fetch("/runs/crons/search", {
136
+ method: "POST",
137
+ json: {
138
+ assistant_id: query?.assistantId ?? undefined,
139
+ thread_id: query?.threadId ?? undefined,
140
+ limit: query?.limit ?? 10,
141
+ offset: query?.offset ?? 0,
142
+ },
143
+ });
144
+ }
145
+ }
61
146
  class AssistantsClient extends BaseClient {
62
147
  /**
63
148
  * Get an assistant by ID.
@@ -115,6 +200,16 @@ class AssistantsClient extends BaseClient {
115
200
  },
116
201
  });
117
202
  }
203
+ /**
204
+ * Delete an assistant.
205
+ *
206
+ * @param assistantId ID of the assistant.
207
+ */
208
+ async delete(assistantId) {
209
+ return this.fetch(`/assistants/${assistantId}`, {
210
+ method: "DELETE",
211
+ });
212
+ }
118
213
  /**
119
214
  * List assistants.
120
215
  * @param query Query options.
@@ -124,6 +219,7 @@ class AssistantsClient extends BaseClient {
124
219
  return this.fetch("/assistants/search", {
125
220
  method: "POST",
126
221
  json: {
222
+ graph_id: query?.graphId ?? undefined,
127
223
  metadata: query?.metadata ?? undefined,
128
224
  limit: query?.limit ?? 10,
129
225
  offset: query?.offset ?? 0,
@@ -268,18 +364,23 @@ class RunsClient extends BaseClient {
268
364
  * @param payload Payload for creating a run.
269
365
  */
270
366
  async *stream(threadId, assistantId, payload) {
271
- const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/stream`, {
367
+ const json = {
368
+ input: payload?.input,
369
+ config: payload?.config,
370
+ metadata: payload?.metadata,
371
+ stream_mode: payload?.streamMode,
372
+ feedback_keys: payload?.feedbackKeys,
373
+ assistant_id: assistantId,
374
+ interrupt_before: payload?.interruptBefore,
375
+ interrupt_after: payload?.interruptAfter,
376
+ };
377
+ if (payload?.multitaskStrategy != null) {
378
+ json["multitask_strategy"] = payload?.multitaskStrategy;
379
+ }
380
+ const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
381
+ const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
272
382
  method: "POST",
273
- json: {
274
- input: payload?.input,
275
- config: payload?.config,
276
- metadata: payload?.metadata,
277
- stream_mode: payload?.streamMode,
278
- feedback_keys: payload?.feedbackKeys,
279
- assistant_id: assistantId,
280
- interrupt_before: payload?.interruptBefore,
281
- interrupt_after: payload?.interruptAfter,
282
- },
383
+ json,
283
384
  signal: payload?.signal,
284
385
  }));
285
386
  let parser;
@@ -315,17 +416,21 @@ class RunsClient extends BaseClient {
315
416
  * @returns The created run.
316
417
  */
317
418
  async create(threadId, assistantId, payload) {
419
+ const json = {
420
+ input: payload?.input,
421
+ config: payload?.config,
422
+ metadata: payload?.metadata,
423
+ assistant_id: assistantId,
424
+ interrupt_before: payload?.interruptBefore,
425
+ interrupt_after: payload?.interruptAfter,
426
+ webhook: payload?.webhook,
427
+ };
428
+ if (payload?.multitaskStrategy != null) {
429
+ json["multitask_strategy"] = payload?.multitaskStrategy;
430
+ }
318
431
  return this.fetch(`/threads/${threadId}/runs`, {
319
432
  method: "POST",
320
- json: {
321
- input: payload?.input,
322
- config: payload?.config,
323
- metadata: payload?.metadata,
324
- assistant_id: assistantId,
325
- interrupt_before: payload?.interruptBefore,
326
- interrupt_after: payload?.interruptAfter,
327
- webhook: payload?.webhook,
328
- },
433
+ json,
329
434
  signal: payload?.signal,
330
435
  });
331
436
  }
@@ -338,16 +443,21 @@ class RunsClient extends BaseClient {
338
443
  * @returns The last values chunk of the thread.
339
444
  */
340
445
  async wait(threadId, assistantId, payload) {
341
- return this.fetch(`/threads/${threadId}/runs/wait`, {
446
+ const json = {
447
+ input: payload?.input,
448
+ config: payload?.config,
449
+ metadata: payload?.metadata,
450
+ assistant_id: assistantId,
451
+ interrupt_before: payload?.interruptBefore,
452
+ interrupt_after: payload?.interruptAfter,
453
+ };
454
+ if (payload?.multitaskStrategy != null) {
455
+ json["multitask_strategy"] = payload?.multitaskStrategy;
456
+ }
457
+ const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
458
+ return this.fetch(endpoint, {
342
459
  method: "POST",
343
- json: {
344
- input: payload?.input,
345
- config: payload?.config,
346
- metadata: payload?.metadata,
347
- assistant_id: assistantId,
348
- interrupt_before: payload?.interruptBefore,
349
- interrupt_after: payload?.interruptAfter,
350
- },
460
+ json,
351
461
  signal: payload?.signal,
352
462
  });
353
463
  }
@@ -377,21 +487,43 @@ class RunsClient extends BaseClient {
377
487
  return this.fetch(`/threads/${threadId}/runs/${runId}`);
378
488
  }
379
489
  /**
380
- * List all events for a run.
490
+ * Cancel a run.
381
491
  *
382
492
  * @param threadId The ID of the thread.
383
493
  * @param runId The ID of the run.
384
- * @param options Filtering and pagination options.
385
- * @returns List of events.
494
+ * @param wait Whether to block when canceling
495
+ * @returns
386
496
  */
387
- async listEvents(threadId, runId, options) {
388
- return this.fetch(`/threads/${threadId}/runs/${runId}/events`, {
497
+ async cancel(threadId, runId, wait = false) {
498
+ return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, {
499
+ method: "POST",
389
500
  params: {
390
- limit: options?.limit ?? 10,
391
- offset: options?.offset ?? 0,
501
+ wait: wait ? "1" : "0",
392
502
  },
393
503
  });
394
504
  }
505
+ /**
506
+ * Block until a run is done.
507
+ *
508
+ * @param threadId The ID of the thread.
509
+ * @param runId The ID of the run.
510
+ * @returns
511
+ */
512
+ async join(threadId, runId) {
513
+ return this.fetch(`/threads/${threadId}/runs/${runId}/join`);
514
+ }
515
+ /**
516
+ * Delete a run.
517
+ *
518
+ * @param threadId The ID of the thread.
519
+ * @param runId The ID of the run.
520
+ * @returns
521
+ */
522
+ async delete(threadId, runId) {
523
+ return this.fetch(`/threads/${threadId}/runs/${runId}`, {
524
+ method: "DELETE",
525
+ });
526
+ }
395
527
  }
396
528
  export class Client {
397
529
  constructor(config) {
@@ -422,8 +554,18 @@ export class Client {
422
554
  writable: true,
423
555
  value: void 0
424
556
  });
557
+ /**
558
+ * The client for interacting with cron runs.
559
+ */
560
+ Object.defineProperty(this, "crons", {
561
+ enumerable: true,
562
+ configurable: true,
563
+ writable: true,
564
+ value: void 0
565
+ });
425
566
  this.assistants = new AssistantsClient(config);
426
567
  this.threads = new ThreadsClient(config);
427
568
  this.runs = new RunsClient(config);
569
+ this.crons = new CronsClient(config);
428
570
  }
429
571
  }
package/dist/index.d.mts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { Client } from "./client.mjs";
2
- export type { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, RunEvent, Thread, ThreadState, } from "./schema.js";
2
+ export type { Assistant, AssistantGraph, Config, DefaultValues, GraphSchema, Metadata, Run, Thread, ThreadState, Cron, } from "./schema.js";
package/dist/schema.d.ts CHANGED
@@ -56,6 +56,15 @@ export interface Thread {
56
56
  updated_at: string;
57
57
  metadata: Metadata;
58
58
  }
59
+ export interface Cron {
60
+ cron_id: string;
61
+ thread_id: Optional<string>;
62
+ end_time: Optional<string>;
63
+ schedule: string;
64
+ created_at: string;
65
+ updated_at: string;
66
+ payload: Record<string, unknown>;
67
+ }
59
68
  export type DefaultValues = Record<string, unknown>[] | Record<string, unknown>;
60
69
  export interface ThreadState<ValuesType = DefaultValues> {
61
70
  values: ValuesType;
@@ -74,15 +83,4 @@ export interface Run {
74
83
  status: "pending" | "running" | "error" | "success" | "timeout" | "interrupted";
75
84
  metadata: Metadata;
76
85
  }
77
- export interface RunEvent {
78
- event_id: string;
79
- run_id: string;
80
- received_at: string;
81
- span_id: string;
82
- event: string;
83
- name: string;
84
- data: Record<string, unknown>;
85
- metadata: Record<string, unknown>;
86
- tags: string[];
87
- }
88
86
  export {};
package/dist/types.d.mts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { Config, Metadata } from "./schema.js";
2
2
  export type StreamMode = "values" | "messages" | "updates" | "events" | "debug";
3
+ export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
4
+ export type StreamEvent = "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | (string & {});
3
5
  interface RunsInvokePayload {
4
6
  /**
5
7
  * Input to the run. Pass `null` to resume from the current state of the thread.
@@ -21,6 +23,17 @@ interface RunsInvokePayload {
21
23
  * Interrupt execution after leaving these nodes.
22
24
  */
23
25
  interruptAfter?: string[];
26
+ /**
27
+ * Strategy to handle concurrent runs on the same thread. Only relevant if
28
+ * there is a pending/inflight run on the same thread. One of:
29
+ * - "reject": Reject the new run.
30
+ * - "interrupt": Interrupt the current run, keeping steps completed until now,
31
+ and start a new one.
32
+ * - "rollback": Cancel and delete the existing run, rolling back the thread to
33
+ the state before it had started, then start the new run.
34
+ * - "enqueue": Queue up the new run to start after the current run finishes.
35
+ */
36
+ multitaskStrategy?: MultitaskStrategy;
24
37
  /**
25
38
  * Abort controller signal to cancel the run.
26
39
  */
@@ -49,5 +62,11 @@ export interface RunsCreatePayload extends RunsInvokePayload {
49
62
  */
50
63
  webhook?: string;
51
64
  }
65
+ export interface CronsCreatePayload extends RunsCreatePayload {
66
+ /**
67
+ * Schedule for running the Cron Job
68
+ */
69
+ schedule: string;
70
+ }
52
71
  export type RunsWaitPayload = RunsStreamPayload;
53
72
  export {};
@@ -11,6 +11,12 @@ export interface AsyncCallerParams {
11
11
  */
12
12
  maxRetries?: number;
13
13
  onFailedResponseHook?: ResponseCallback;
14
+ /**
15
+ * Specify a custom fetch implementation.
16
+ *
17
+ * By default we expect the `fetch` is available in the global scope.
18
+ */
19
+ fetch?: typeof fetch;
14
20
  }
15
21
  export interface AsyncCallerCallOptions {
16
22
  signal?: AbortSignal;
@@ -33,6 +39,7 @@ export declare class AsyncCaller {
33
39
  protected maxRetries: AsyncCallerParams["maxRetries"];
34
40
  private queue;
35
41
  private onFailedResponseHook?;
42
+ private customFetch?;
36
43
  constructor(params: AsyncCallerParams);
37
44
  call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
38
45
  callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
@@ -99,6 +99,12 @@ export class AsyncCaller {
99
99
  writable: true,
100
100
  value: void 0
101
101
  });
102
+ Object.defineProperty(this, "customFetch", {
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true,
106
+ value: void 0
107
+ });
102
108
  this.maxConcurrency = params.maxConcurrency ?? Infinity;
103
109
  this.maxRetries = params.maxRetries ?? 4;
104
110
  if ("default" in PQueueMod) {
@@ -112,6 +118,7 @@ export class AsyncCaller {
112
118
  this.queue = new PQueueMod({ concurrency: this.maxConcurrency });
113
119
  }
114
120
  this.onFailedResponseHook = params?.onFailedResponseHook;
121
+ this.customFetch = params.fetch;
115
122
  }
116
123
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
124
  call(callable, ...args) {
@@ -175,6 +182,7 @@ export class AsyncCaller {
175
182
  return this.call(callable, ...args);
176
183
  }
177
184
  fetch(...args) {
178
- return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
185
+ const fetchFn = this.customFetch ?? fetch;
186
+ return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))));
179
187
  }
180
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-sdk",
3
- "version": "0.0.1-rc.9",
3
+ "version": "0.0.1",
4
4
  "description": "Client library for interacting with the LangGraph API",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@1.22.19",
@@ -26,7 +26,10 @@
26
26
  "@tsconfig/recommended": "^1.0.2",
27
27
  "@types/node": "^20.12.12",
28
28
  "@types/uuid": "^9.0.1",
29
+ "concat-md": "^0.5.1",
29
30
  "prettier": "^3.2.5",
31
+ "typedoc": "^0.26.1",
32
+ "typedoc-plugin-markdown": "^4.1.0",
30
33
  "typescript": "^5.4.5"
31
34
  },
32
35
  "exports": {