@langchain/langgraph-sdk 0.0.16 → 0.0.18
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 +24 -2
- package/dist/client.d.ts +6 -1
- package/dist/client.js +24 -2
- package/dist/schema.d.ts +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/utils/signals.cjs +22 -0
- package/dist/utils/signals.d.ts +1 -0
- package/dist/utils/signals.js +18 -0
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -4,6 +4,7 @@ exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClien
|
|
|
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
|
+
const signals_js_1 = require("./utils/signals.cjs");
|
|
7
8
|
class BaseClient {
|
|
8
9
|
constructor(config) {
|
|
9
10
|
Object.defineProperty(this, "asyncCaller", {
|
|
@@ -36,6 +37,8 @@ class BaseClient {
|
|
|
36
37
|
...config?.callerOptions,
|
|
37
38
|
});
|
|
38
39
|
this.timeoutMs = config?.timeoutMs || 12_000;
|
|
40
|
+
// default limit being capped by Chrome
|
|
41
|
+
// https://github.com/nodejs/undici/issues/1373
|
|
39
42
|
this.apiUrl = config?.apiUrl || "http://localhost:8123";
|
|
40
43
|
this.defaultHeaders = config?.defaultHeaders || {};
|
|
41
44
|
if (config?.apiKey != null) {
|
|
@@ -55,6 +58,16 @@ class BaseClient {
|
|
|
55
58
|
};
|
|
56
59
|
delete mutatedOptions.json;
|
|
57
60
|
}
|
|
61
|
+
let timeoutSignal = null;
|
|
62
|
+
if (typeof options?.timeoutMs !== "undefined") {
|
|
63
|
+
if (options.timeoutMs != null) {
|
|
64
|
+
timeoutSignal = AbortSignal.timeout(options.timeoutMs);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
69
|
+
}
|
|
70
|
+
mutatedOptions.signal = (0, signals_js_1.mergeSignals)(timeoutSignal, mutatedOptions.signal);
|
|
58
71
|
const targetUrl = new URL(`${this.apiUrl}${path}`);
|
|
59
72
|
if (mutatedOptions.params) {
|
|
60
73
|
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
@@ -462,6 +475,7 @@ class RunsClient extends BaseClient {
|
|
|
462
475
|
assistant_id: assistantId,
|
|
463
476
|
interrupt_before: payload?.interruptBefore,
|
|
464
477
|
interrupt_after: payload?.interruptAfter,
|
|
478
|
+
checkpoint: payload?.checkpoint,
|
|
465
479
|
checkpoint_id: payload?.checkpointId,
|
|
466
480
|
webhook: payload?.webhook,
|
|
467
481
|
multitask_strategy: payload?.multitaskStrategy,
|
|
@@ -473,6 +487,7 @@ class RunsClient extends BaseClient {
|
|
|
473
487
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
474
488
|
method: "POST",
|
|
475
489
|
json,
|
|
490
|
+
timeoutMs: null,
|
|
476
491
|
signal: payload?.signal,
|
|
477
492
|
}));
|
|
478
493
|
let parser;
|
|
@@ -525,6 +540,7 @@ class RunsClient extends BaseClient {
|
|
|
525
540
|
interrupt_before: payload?.interruptBefore,
|
|
526
541
|
interrupt_after: payload?.interruptAfter,
|
|
527
542
|
webhook: payload?.webhook,
|
|
543
|
+
checkpoint: payload?.checkpoint,
|
|
528
544
|
checkpoint_id: payload?.checkpointId,
|
|
529
545
|
multitask_strategy: payload?.multitaskStrategy,
|
|
530
546
|
after_seconds: payload?.afterSeconds,
|
|
@@ -568,6 +584,7 @@ class RunsClient extends BaseClient {
|
|
|
568
584
|
assistant_id: assistantId,
|
|
569
585
|
interrupt_before: payload?.interruptBefore,
|
|
570
586
|
interrupt_after: payload?.interruptAfter,
|
|
587
|
+
checkpoint: payload?.checkpoint,
|
|
571
588
|
checkpoint_id: payload?.checkpointId,
|
|
572
589
|
webhook: payload?.webhook,
|
|
573
590
|
multitask_strategy: payload?.multitaskStrategy,
|
|
@@ -579,6 +596,7 @@ class RunsClient extends BaseClient {
|
|
|
579
596
|
return this.fetch(endpoint, {
|
|
580
597
|
method: "POST",
|
|
581
598
|
json,
|
|
599
|
+
timeoutMs: null,
|
|
582
600
|
signal: payload?.signal,
|
|
583
601
|
});
|
|
584
602
|
}
|
|
@@ -630,8 +648,11 @@ class RunsClient extends BaseClient {
|
|
|
630
648
|
* @param runId The ID of the run.
|
|
631
649
|
* @returns
|
|
632
650
|
*/
|
|
633
|
-
async join(threadId, runId) {
|
|
634
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}/join
|
|
651
|
+
async join(threadId, runId, options) {
|
|
652
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}/join`, {
|
|
653
|
+
timeoutMs: null,
|
|
654
|
+
signal: options?.signal,
|
|
655
|
+
});
|
|
635
656
|
}
|
|
636
657
|
/**
|
|
637
658
|
* Stream output from a run in real-time, until the run is done.
|
|
@@ -646,6 +667,7 @@ class RunsClient extends BaseClient {
|
|
|
646
667
|
async *joinStream(threadId, runId, signal) {
|
|
647
668
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
|
|
648
669
|
method: "GET",
|
|
670
|
+
timeoutMs: null,
|
|
649
671
|
signal,
|
|
650
672
|
}));
|
|
651
673
|
let parser;
|
package/dist/client.d.ts
CHANGED
|
@@ -17,10 +17,13 @@ declare class BaseClient {
|
|
|
17
17
|
protected prepareFetchOptions(path: string, options?: RequestInit & {
|
|
18
18
|
json?: unknown;
|
|
19
19
|
params?: Record<string, unknown>;
|
|
20
|
+
timeoutMs?: number | null;
|
|
20
21
|
}): [url: URL, init: RequestInit];
|
|
21
22
|
protected fetch<T>(path: string, options?: RequestInit & {
|
|
22
23
|
json?: unknown;
|
|
23
24
|
params?: Record<string, unknown>;
|
|
25
|
+
timeoutMs?: number | null;
|
|
26
|
+
signal?: AbortSignal;
|
|
24
27
|
}): Promise<T>;
|
|
25
28
|
}
|
|
26
29
|
export declare class CronsClient extends BaseClient {
|
|
@@ -334,7 +337,9 @@ export declare class RunsClient extends BaseClient {
|
|
|
334
337
|
* @param runId The ID of the run.
|
|
335
338
|
* @returns
|
|
336
339
|
*/
|
|
337
|
-
join(threadId: string, runId: string
|
|
340
|
+
join(threadId: string, runId: string, options?: {
|
|
341
|
+
signal?: AbortSignal;
|
|
342
|
+
}): Promise<void>;
|
|
338
343
|
/**
|
|
339
344
|
* Stream output from a run in real-time, until the run is done.
|
|
340
345
|
* Output is not buffered, so any output produced before this call will
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
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
|
+
import { mergeSignals } from "./utils/signals.js";
|
|
4
5
|
class BaseClient {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
Object.defineProperty(this, "asyncCaller", {
|
|
@@ -33,6 +34,8 @@ class BaseClient {
|
|
|
33
34
|
...config?.callerOptions,
|
|
34
35
|
});
|
|
35
36
|
this.timeoutMs = config?.timeoutMs || 12_000;
|
|
37
|
+
// default limit being capped by Chrome
|
|
38
|
+
// https://github.com/nodejs/undici/issues/1373
|
|
36
39
|
this.apiUrl = config?.apiUrl || "http://localhost:8123";
|
|
37
40
|
this.defaultHeaders = config?.defaultHeaders || {};
|
|
38
41
|
if (config?.apiKey != null) {
|
|
@@ -52,6 +55,16 @@ class BaseClient {
|
|
|
52
55
|
};
|
|
53
56
|
delete mutatedOptions.json;
|
|
54
57
|
}
|
|
58
|
+
let timeoutSignal = null;
|
|
59
|
+
if (typeof options?.timeoutMs !== "undefined") {
|
|
60
|
+
if (options.timeoutMs != null) {
|
|
61
|
+
timeoutSignal = AbortSignal.timeout(options.timeoutMs);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
66
|
+
}
|
|
67
|
+
mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);
|
|
55
68
|
const targetUrl = new URL(`${this.apiUrl}${path}`);
|
|
56
69
|
if (mutatedOptions.params) {
|
|
57
70
|
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
@@ -456,6 +469,7 @@ export class RunsClient extends BaseClient {
|
|
|
456
469
|
assistant_id: assistantId,
|
|
457
470
|
interrupt_before: payload?.interruptBefore,
|
|
458
471
|
interrupt_after: payload?.interruptAfter,
|
|
472
|
+
checkpoint: payload?.checkpoint,
|
|
459
473
|
checkpoint_id: payload?.checkpointId,
|
|
460
474
|
webhook: payload?.webhook,
|
|
461
475
|
multitask_strategy: payload?.multitaskStrategy,
|
|
@@ -467,6 +481,7 @@ export class RunsClient extends BaseClient {
|
|
|
467
481
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
468
482
|
method: "POST",
|
|
469
483
|
json,
|
|
484
|
+
timeoutMs: null,
|
|
470
485
|
signal: payload?.signal,
|
|
471
486
|
}));
|
|
472
487
|
let parser;
|
|
@@ -519,6 +534,7 @@ export class RunsClient extends BaseClient {
|
|
|
519
534
|
interrupt_before: payload?.interruptBefore,
|
|
520
535
|
interrupt_after: payload?.interruptAfter,
|
|
521
536
|
webhook: payload?.webhook,
|
|
537
|
+
checkpoint: payload?.checkpoint,
|
|
522
538
|
checkpoint_id: payload?.checkpointId,
|
|
523
539
|
multitask_strategy: payload?.multitaskStrategy,
|
|
524
540
|
after_seconds: payload?.afterSeconds,
|
|
@@ -562,6 +578,7 @@ export class RunsClient extends BaseClient {
|
|
|
562
578
|
assistant_id: assistantId,
|
|
563
579
|
interrupt_before: payload?.interruptBefore,
|
|
564
580
|
interrupt_after: payload?.interruptAfter,
|
|
581
|
+
checkpoint: payload?.checkpoint,
|
|
565
582
|
checkpoint_id: payload?.checkpointId,
|
|
566
583
|
webhook: payload?.webhook,
|
|
567
584
|
multitask_strategy: payload?.multitaskStrategy,
|
|
@@ -573,6 +590,7 @@ export class RunsClient extends BaseClient {
|
|
|
573
590
|
return this.fetch(endpoint, {
|
|
574
591
|
method: "POST",
|
|
575
592
|
json,
|
|
593
|
+
timeoutMs: null,
|
|
576
594
|
signal: payload?.signal,
|
|
577
595
|
});
|
|
578
596
|
}
|
|
@@ -624,8 +642,11 @@ export class RunsClient extends BaseClient {
|
|
|
624
642
|
* @param runId The ID of the run.
|
|
625
643
|
* @returns
|
|
626
644
|
*/
|
|
627
|
-
async join(threadId, runId) {
|
|
628
|
-
return this.fetch(`/threads/${threadId}/runs/${runId}/join
|
|
645
|
+
async join(threadId, runId, options) {
|
|
646
|
+
return this.fetch(`/threads/${threadId}/runs/${runId}/join`, {
|
|
647
|
+
timeoutMs: null,
|
|
648
|
+
signal: options?.signal,
|
|
649
|
+
});
|
|
629
650
|
}
|
|
630
651
|
/**
|
|
631
652
|
* Stream output from a run in real-time, until the run is done.
|
|
@@ -640,6 +661,7 @@ export class RunsClient extends BaseClient {
|
|
|
640
661
|
async *joinStream(threadId, runId, signal) {
|
|
641
662
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
|
|
642
663
|
method: "GET",
|
|
664
|
+
timeoutMs: null,
|
|
643
665
|
signal,
|
|
644
666
|
}));
|
|
645
667
|
let parser;
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { JSONSchema7 } from "json-schema";
|
|
2
2
|
type Optional<T> = T | null | undefined;
|
|
3
3
|
type RunStatus = "pending" | "running" | "error" | "success" | "timeout" | "interrupted";
|
|
4
|
-
type ThreadStatus = "idle" | "busy" | "interrupted";
|
|
4
|
+
type ThreadStatus = "idle" | "busy" | "interrupted" | "error";
|
|
5
5
|
type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
|
|
6
6
|
export interface Config {
|
|
7
7
|
/**
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, Metadata } from "./schema.js";
|
|
1
|
+
import { Checkpoint, Config, Metadata } from "./schema.js";
|
|
2
2
|
export type StreamMode = "values" | "messages" | "updates" | "events" | "debug";
|
|
3
3
|
export type MultitaskStrategy = "reject" | "interrupt" | "rollback" | "enqueue";
|
|
4
4
|
export type OnConflictBehavior = "raise" | "do_nothing";
|
|
@@ -22,6 +22,10 @@ interface RunsInvokePayload {
|
|
|
22
22
|
* Checkpoint ID for when creating a new run.
|
|
23
23
|
*/
|
|
24
24
|
checkpointId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Checkpoint for when creating a new run.
|
|
27
|
+
*/
|
|
28
|
+
checkpoint?: Omit<Checkpoint, "thread_id">;
|
|
25
29
|
/**
|
|
26
30
|
* Interrupt execution before entering these nodes.
|
|
27
31
|
*/
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeSignals = void 0;
|
|
4
|
+
function mergeSignals(...signals) {
|
|
5
|
+
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
6
|
+
if (nonZeroSignals.length === 0)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (nonZeroSignals.length === 1)
|
|
9
|
+
return nonZeroSignals[0];
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
for (const signal of signals) {
|
|
12
|
+
if (signal?.aborted) {
|
|
13
|
+
controller.abort(signal.reason);
|
|
14
|
+
return controller.signal;
|
|
15
|
+
}
|
|
16
|
+
signal?.addEventListener("abort", () => controller.abort(signal.reason), {
|
|
17
|
+
once: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return controller.signal;
|
|
21
|
+
}
|
|
22
|
+
exports.mergeSignals = mergeSignals;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeSignals(...signals: (AbortSignal | null | undefined)[]): AbortSignal | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function mergeSignals(...signals) {
|
|
2
|
+
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
3
|
+
if (nonZeroSignals.length === 0)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (nonZeroSignals.length === 1)
|
|
6
|
+
return nonZeroSignals[0];
|
|
7
|
+
const controller = new AbortController();
|
|
8
|
+
for (const signal of signals) {
|
|
9
|
+
if (signal?.aborted) {
|
|
10
|
+
controller.abort(signal.reason);
|
|
11
|
+
return controller.signal;
|
|
12
|
+
}
|
|
13
|
+
signal?.addEventListener("abort", () => controller.abort(signal.reason), {
|
|
14
|
+
once: true,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return controller.signal;
|
|
18
|
+
}
|