@langchain/langgraph-sdk 0.0.17 → 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 +21 -2
- package/dist/client.d.ts +6 -1
- package/dist/client.js +21 -2
- package/dist/schema.d.ts +1 -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)) {
|
|
@@ -474,6 +487,7 @@ class RunsClient extends BaseClient {
|
|
|
474
487
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
475
488
|
method: "POST",
|
|
476
489
|
json,
|
|
490
|
+
timeoutMs: null,
|
|
477
491
|
signal: payload?.signal,
|
|
478
492
|
}));
|
|
479
493
|
let parser;
|
|
@@ -582,6 +596,7 @@ class RunsClient extends BaseClient {
|
|
|
582
596
|
return this.fetch(endpoint, {
|
|
583
597
|
method: "POST",
|
|
584
598
|
json,
|
|
599
|
+
timeoutMs: null,
|
|
585
600
|
signal: payload?.signal,
|
|
586
601
|
});
|
|
587
602
|
}
|
|
@@ -633,8 +648,11 @@ class RunsClient extends BaseClient {
|
|
|
633
648
|
* @param runId The ID of the run.
|
|
634
649
|
* @returns
|
|
635
650
|
*/
|
|
636
|
-
async join(threadId, runId) {
|
|
637
|
-
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
|
+
});
|
|
638
656
|
}
|
|
639
657
|
/**
|
|
640
658
|
* Stream output from a run in real-time, until the run is done.
|
|
@@ -649,6 +667,7 @@ class RunsClient extends BaseClient {
|
|
|
649
667
|
async *joinStream(threadId, runId, signal) {
|
|
650
668
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
|
|
651
669
|
method: "GET",
|
|
670
|
+
timeoutMs: null,
|
|
652
671
|
signal,
|
|
653
672
|
}));
|
|
654
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)) {
|
|
@@ -468,6 +481,7 @@ export class RunsClient extends BaseClient {
|
|
|
468
481
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(endpoint, {
|
|
469
482
|
method: "POST",
|
|
470
483
|
json,
|
|
484
|
+
timeoutMs: null,
|
|
471
485
|
signal: payload?.signal,
|
|
472
486
|
}));
|
|
473
487
|
let parser;
|
|
@@ -576,6 +590,7 @@ export class RunsClient extends BaseClient {
|
|
|
576
590
|
return this.fetch(endpoint, {
|
|
577
591
|
method: "POST",
|
|
578
592
|
json,
|
|
593
|
+
timeoutMs: null,
|
|
579
594
|
signal: payload?.signal,
|
|
580
595
|
});
|
|
581
596
|
}
|
|
@@ -627,8 +642,11 @@ export class RunsClient extends BaseClient {
|
|
|
627
642
|
* @param runId The ID of the run.
|
|
628
643
|
* @returns
|
|
629
644
|
*/
|
|
630
|
-
async join(threadId, runId) {
|
|
631
|
-
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
|
+
});
|
|
632
650
|
}
|
|
633
651
|
/**
|
|
634
652
|
* Stream output from a run in real-time, until the run is done.
|
|
@@ -643,6 +661,7 @@ export class RunsClient extends BaseClient {
|
|
|
643
661
|
async *joinStream(threadId, runId, signal) {
|
|
644
662
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/threads/${threadId}/runs/${runId}/stream`, {
|
|
645
663
|
method: "GET",
|
|
664
|
+
timeoutMs: null,
|
|
646
665
|
signal,
|
|
647
666
|
}));
|
|
648
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
|
/**
|
|
@@ -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
|
+
}
|