@langchain/langgraph-sdk 0.0.1-rc.8 → 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;
@@ -138,17 +180,16 @@ declare class ThreadsClient extends BaseClient {
138
180
  * @param threadId ID of the thread.
139
181
  * @returns Thread state.
140
182
  */
141
- getState<ValuesType = DefaultValues>(threadId: string): Promise<ThreadState<ValuesType>>;
183
+ getState<ValuesType = DefaultValues>(threadId: string, checkpointId?: string): Promise<ThreadState<ValuesType>>;
142
184
  /**
143
185
  * Add state to a thread.
144
186
  *
145
- * @param threadIdOrConfig Thread ID or config that identifies the state to start from.
146
- * @param values The state update
147
- * @param options Additional options.
187
+ * @param threadId The ID of the thread.
148
188
  * @returns
149
189
  */
150
- updateState<ValuesType = DefaultValues>(threadIdOrConfig: string | Config, options: {
190
+ updateState<ValuesType = DefaultValues>(threadId: string, options: {
151
191
  values: ValuesType;
192
+ checkpointId?: string;
152
193
  asNode?: string;
153
194
  }): Promise<void>;
154
195
  /**
@@ -172,15 +213,12 @@ declare class ThreadsClient extends BaseClient {
172
213
  }): Promise<ThreadState<ValuesType>[]>;
173
214
  }
174
215
  declare class RunsClient extends BaseClient {
175
- /**
176
- * Create a run and stream the results.
177
- *
178
- * @param threadId The ID of the thread.
179
- * @param assistantId Assistant ID to use for this run.
180
- * @param payload Payload for creating a run.
181
- */
216
+ stream(threadId: null, assistantId: string, payload?: Omit<RunsStreamPayload, "multitaskStrategy">): AsyncGenerator<{
217
+ event: StreamEvent;
218
+ data: any;
219
+ }>;
182
220
  stream(threadId: string, assistantId: string, payload?: RunsStreamPayload): AsyncGenerator<{
183
- event: "events" | "metadata" | "debug" | "updates" | "values" | "messages/partial" | "messages/metadata" | "messages/complete" | (string & {});
221
+ event: StreamEvent;
184
222
  data: any;
185
223
  }>;
186
224
  /**
@@ -192,14 +230,7 @@ declare class RunsClient extends BaseClient {
192
230
  * @returns The created run.
193
231
  */
194
232
  create(threadId: string, assistantId: string, payload?: RunsCreatePayload): Promise<Run>;
195
- /**
196
- * Create a run and wait for it to complete.
197
- *
198
- * @param threadId The ID of the thread.
199
- * @param assistantId Assistant ID to use for this run.
200
- * @param payload Payload for creating a run.
201
- * @returns The last values chunk of the thread.
202
- */
233
+ wait(threadId: null, assistantId: string, payload?: Omit<RunsWaitPayload, "multitaskStrategy">): Promise<ThreadState["values"]>;
203
234
  wait(threadId: string, assistantId: string, payload?: RunsWaitPayload): Promise<ThreadState["values"]>;
204
235
  /**
205
236
  * List all runs for a thread.
@@ -229,25 +260,30 @@ declare class RunsClient extends BaseClient {
229
260
  */
230
261
  get(threadId: string, runId: string): Promise<Run>;
231
262
  /**
232
- * List all events for a run.
263
+ * Cancel a run.
233
264
  *
234
265
  * @param threadId The ID of the thread.
235
266
  * @param runId The ID of the run.
236
- * @param options Filtering and pagination options.
237
- * @returns List of events.
267
+ * @param wait Whether to block when canceling
268
+ * @returns
238
269
  */
239
- listEvents(threadId: string, runId: string, options?: {
240
- /**
241
- * Maximum number of events to return.
242
- * Defaults to 10
243
- */
244
- limit?: number;
245
- /**
246
- * Offset to start from.
247
- * Defaults to 0.
248
- */
249
- offset?: number;
250
- }): 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>;
251
287
  }
252
288
  export declare class Client {
253
289
  /**
@@ -262,6 +298,10 @@ export declare class Client {
262
298
  * The client for interacting with runs.
263
299
  */
264
300
  runs: RunsClient;
301
+ /**
302
+ * The client for interacting with cron runs.
303
+ */
304
+ crons: CronsClient;
265
305
  constructor(config?: ClientConfig);
266
306
  }
267
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,
@@ -198,34 +294,25 @@ class ThreadsClient extends BaseClient {
198
294
  * @param threadId ID of the thread.
199
295
  * @returns Thread state.
200
296
  */
201
- async getState(threadId) {
202
- return this.fetch(`/threads/${threadId}/state`);
297
+ async getState(threadId, checkpointId) {
298
+ return this.fetch(checkpointId != null
299
+ ? `/threads/${threadId}/state/${checkpointId}`
300
+ : `/threads/${threadId}/state`);
203
301
  }
204
302
  /**
205
303
  * Add state to a thread.
206
304
  *
207
- * @param threadIdOrConfig Thread ID or config that identifies the state to start from.
208
- * @param values The state update
209
- * @param options Additional options.
305
+ * @param threadId The ID of the thread.
210
306
  * @returns
211
307
  */
212
- async updateState(threadIdOrConfig, options) {
213
- let config = undefined;
214
- let threadId;
215
- if (typeof threadIdOrConfig !== "string") {
216
- config = threadIdOrConfig;
217
- if (typeof config.configurable?.thread_id !== "string") {
218
- throw new Error("Thread ID is required when updating state with a config.");
219
- }
220
- threadId = config.configurable.thread_id;
221
- }
222
- else {
223
- config = undefined;
224
- threadId = threadIdOrConfig;
225
- }
308
+ async updateState(threadId, options) {
226
309
  return this.fetch(`/threads/${threadId}/state`, {
227
310
  method: "POST",
228
- json: { values: options.values, config, as_node: options?.asNode },
311
+ json: {
312
+ values: options.values,
313
+ checkpoint_id: options.checkpointId,
314
+ as_node: options?.asNode,
315
+ },
229
316
  });
230
317
  }
231
318
  /**
@@ -277,18 +364,23 @@ class RunsClient extends BaseClient {
277
364
  * @param payload Payload for creating a run.
278
365
  */
279
366
  async *stream(threadId, assistantId, payload) {
280
- 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, {
281
382
  method: "POST",
282
- json: {
283
- input: payload?.input,
284
- config: payload?.config,
285
- metadata: payload?.metadata,
286
- stream_mode: payload?.streamMode,
287
- feedback_keys: payload?.feedbackKeys,
288
- assistant_id: assistantId,
289
- interrupt_before: payload?.interruptBefore,
290
- interrupt_after: payload?.interruptAfter,
291
- },
383
+ json,
292
384
  signal: payload?.signal,
293
385
  }));
294
386
  let parser;
@@ -324,17 +416,21 @@ class RunsClient extends BaseClient {
324
416
  * @returns The created run.
325
417
  */
326
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
+ }
327
431
  return this.fetch(`/threads/${threadId}/runs`, {
328
432
  method: "POST",
329
- json: {
330
- input: payload?.input,
331
- config: payload?.config,
332
- metadata: payload?.metadata,
333
- assistant_id: assistantId,
334
- interrupt_before: payload?.interruptBefore,
335
- interrupt_after: payload?.interruptAfter,
336
- webhook: payload?.webhook,
337
- },
433
+ json,
338
434
  signal: payload?.signal,
339
435
  });
340
436
  }
@@ -347,16 +443,21 @@ class RunsClient extends BaseClient {
347
443
  * @returns The last values chunk of the thread.
348
444
  */
349
445
  async wait(threadId, assistantId, payload) {
350
- 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, {
351
459
  method: "POST",
352
- json: {
353
- input: payload?.input,
354
- config: payload?.config,
355
- metadata: payload?.metadata,
356
- assistant_id: assistantId,
357
- interrupt_before: payload?.interruptBefore,
358
- interrupt_after: payload?.interruptAfter,
359
- },
460
+ json,
360
461
  signal: payload?.signal,
361
462
  });
362
463
  }
@@ -386,21 +487,43 @@ class RunsClient extends BaseClient {
386
487
  return this.fetch(`/threads/${threadId}/runs/${runId}`);
387
488
  }
388
489
  /**
389
- * List all events for a run.
490
+ * Cancel a run.
390
491
  *
391
492
  * @param threadId The ID of the thread.
392
493
  * @param runId The ID of the run.
393
- * @param options Filtering and pagination options.
394
- * @returns List of events.
494
+ * @param wait Whether to block when canceling
495
+ * @returns
395
496
  */
396
- async listEvents(threadId, runId, options) {
397
- 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",
398
500
  params: {
399
- limit: options?.limit ?? 10,
400
- offset: options?.offset ?? 0,
501
+ wait: wait ? "1" : "0",
401
502
  },
402
503
  });
403
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
+ }
404
527
  }
405
528
  export class Client {
406
529
  constructor(config) {
@@ -431,8 +554,18 @@ export class Client {
431
554
  writable: true,
432
555
  value: void 0
433
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
+ });
434
566
  this.assistants = new AssistantsClient(config);
435
567
  this.threads = new ThreadsClient(config);
436
568
  this.runs = new RunsClient(config);
569
+ this.crons = new CronsClient(config);
437
570
  }
438
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,14 +56,23 @@ 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;
62
71
  next: string[];
63
- config: Config;
72
+ checkpoint_id: string;
64
73
  metadata: Metadata;
65
74
  created_at: Optional<string>;
66
- parent_config: Optional<Config>;
75
+ parent_checkpoint_id: Optional<string>;
67
76
  }
68
77
  export interface Run {
69
78
  run_id: string;
@@ -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.8",
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": {