@langchain/langgraph-sdk 0.0.23-dev.0 → 0.0.23-dev.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/dist/client.cjs +25 -16
- package/dist/index.cjs +5 -1
- package/dist/schema.cjs +2 -1
- package/dist/types.cjs +2 -1
- package/dist/utils/async_caller.cjs +14 -7
- package/dist/utils/eventsource-parser/index.cjs +5 -1
- package/dist/utils/eventsource-parser/parse.cjs +5 -1
- package/dist/utils/eventsource-parser/stream.cjs +7 -3
- package/dist/utils/eventsource-parser/types.cjs +2 -1
- package/dist/utils/signals.cjs +5 -1
- package/dist/utils/stream.cjs +5 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClient = exports.AssistantsClient = exports.CronsClient = void 0;
|
|
4
|
+
const async_caller_js_1 = require("./utils/async_caller.cjs");
|
|
5
|
+
const index_js_1 = require("./utils/eventsource-parser/index.cjs");
|
|
6
|
+
const stream_js_1 = require("./utils/stream.cjs");
|
|
7
|
+
const signals_js_1 = require("./utils/signals.cjs");
|
|
5
8
|
class BaseClient {
|
|
6
9
|
constructor(config) {
|
|
7
10
|
Object.defineProperty(this, "asyncCaller", {
|
|
@@ -28,7 +31,7 @@ class BaseClient {
|
|
|
28
31
|
writable: true,
|
|
29
32
|
value: void 0
|
|
30
33
|
});
|
|
31
|
-
this.asyncCaller = new AsyncCaller({
|
|
34
|
+
this.asyncCaller = new async_caller_js_1.AsyncCaller({
|
|
32
35
|
maxRetries: 4,
|
|
33
36
|
maxConcurrency: 4,
|
|
34
37
|
...config?.callerOptions,
|
|
@@ -64,7 +67,7 @@ class BaseClient {
|
|
|
64
67
|
else {
|
|
65
68
|
timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
66
69
|
}
|
|
67
|
-
mutatedOptions.signal = mergeSignals(timeoutSignal, mutatedOptions.signal);
|
|
70
|
+
mutatedOptions.signal = (0, signals_js_1.mergeSignals)(timeoutSignal, mutatedOptions.signal);
|
|
68
71
|
const targetUrl = new URL(`${this.apiUrl}${path}`);
|
|
69
72
|
if (mutatedOptions.params) {
|
|
70
73
|
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
@@ -87,7 +90,7 @@ class BaseClient {
|
|
|
87
90
|
return response.json();
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
|
-
|
|
93
|
+
class CronsClient extends BaseClient {
|
|
91
94
|
/**
|
|
92
95
|
*
|
|
93
96
|
* @param threadId The ID of the thread.
|
|
@@ -163,7 +166,8 @@ export class CronsClient extends BaseClient {
|
|
|
163
166
|
});
|
|
164
167
|
}
|
|
165
168
|
}
|
|
166
|
-
|
|
169
|
+
exports.CronsClient = CronsClient;
|
|
170
|
+
class AssistantsClient extends BaseClient {
|
|
167
171
|
/**
|
|
168
172
|
* Get an assistant by ID.
|
|
169
173
|
*
|
|
@@ -298,7 +302,8 @@ export class AssistantsClient extends BaseClient {
|
|
|
298
302
|
});
|
|
299
303
|
}
|
|
300
304
|
}
|
|
301
|
-
|
|
305
|
+
exports.AssistantsClient = AssistantsClient;
|
|
306
|
+
class ThreadsClient extends BaseClient {
|
|
302
307
|
/**
|
|
303
308
|
* Get a thread by ID.
|
|
304
309
|
*
|
|
@@ -453,7 +458,8 @@ export class ThreadsClient extends BaseClient {
|
|
|
453
458
|
});
|
|
454
459
|
}
|
|
455
460
|
}
|
|
456
|
-
|
|
461
|
+
exports.ThreadsClient = ThreadsClient;
|
|
462
|
+
class RunsClient extends BaseClient {
|
|
457
463
|
/**
|
|
458
464
|
* Create a run and stream the results.
|
|
459
465
|
*
|
|
@@ -493,7 +499,7 @@ export class RunsClient extends BaseClient {
|
|
|
493
499
|
const textDecoder = new TextDecoder();
|
|
494
500
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
495
501
|
async start(ctrl) {
|
|
496
|
-
parser = createParser((event) => {
|
|
502
|
+
parser = (0, index_js_1.createParser)((event) => {
|
|
497
503
|
if ((payload?.signal && payload.signal.aborted) ||
|
|
498
504
|
(event.type === "event" && event.data === "[DONE]")) {
|
|
499
505
|
ctrl.terminate();
|
|
@@ -519,7 +525,7 @@ export class RunsClient extends BaseClient {
|
|
|
519
525
|
onEndEvent();
|
|
520
526
|
},
|
|
521
527
|
}));
|
|
522
|
-
yield* IterableReadableStream.fromReadableStream(stream);
|
|
528
|
+
yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
|
|
523
529
|
}
|
|
524
530
|
/**
|
|
525
531
|
* Create a run.
|
|
@@ -687,7 +693,7 @@ export class RunsClient extends BaseClient {
|
|
|
687
693
|
const textDecoder = new TextDecoder();
|
|
688
694
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(new TransformStream({
|
|
689
695
|
async start(ctrl) {
|
|
690
|
-
parser = createParser((event) => {
|
|
696
|
+
parser = (0, index_js_1.createParser)((event) => {
|
|
691
697
|
if ((signal && signal.aborted) ||
|
|
692
698
|
(event.type === "event" && event.data === "[DONE]")) {
|
|
693
699
|
ctrl.terminate();
|
|
@@ -713,7 +719,7 @@ export class RunsClient extends BaseClient {
|
|
|
713
719
|
onEndEvent();
|
|
714
720
|
},
|
|
715
721
|
}));
|
|
716
|
-
yield* IterableReadableStream.fromReadableStream(stream);
|
|
722
|
+
yield* stream_js_1.IterableReadableStream.fromReadableStream(stream);
|
|
717
723
|
}
|
|
718
724
|
/**
|
|
719
725
|
* Delete a run.
|
|
@@ -728,7 +734,8 @@ export class RunsClient extends BaseClient {
|
|
|
728
734
|
});
|
|
729
735
|
}
|
|
730
736
|
}
|
|
731
|
-
|
|
737
|
+
exports.RunsClient = RunsClient;
|
|
738
|
+
class StoreClient extends BaseClient {
|
|
732
739
|
/**
|
|
733
740
|
* Store or update an item.
|
|
734
741
|
*
|
|
@@ -847,7 +854,8 @@ export class StoreClient extends BaseClient {
|
|
|
847
854
|
});
|
|
848
855
|
}
|
|
849
856
|
}
|
|
850
|
-
|
|
857
|
+
exports.StoreClient = StoreClient;
|
|
858
|
+
class Client {
|
|
851
859
|
constructor(config) {
|
|
852
860
|
/**
|
|
853
861
|
* The client for interacting with assistants.
|
|
@@ -901,3 +909,4 @@ export class Client {
|
|
|
901
909
|
this.store = new StoreClient(config);
|
|
902
910
|
}
|
|
903
911
|
}
|
|
912
|
+
exports.Client = Client;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Client = void 0;
|
|
4
|
+
var client_js_1 = require("./client.cjs");
|
|
5
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return client_js_1.Client; } });
|
package/dist/schema.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/types.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AsyncCaller = void 0;
|
|
7
|
+
const p_retry_1 = __importDefault(require("p-retry"));
|
|
8
|
+
const p_queue_1 = __importDefault(require("p-queue"));
|
|
3
9
|
const STATUS_NO_RETRY = [
|
|
4
10
|
400, // Bad Request
|
|
5
11
|
401, // Unauthorized
|
|
@@ -73,7 +79,7 @@ class HTTPError extends Error {
|
|
|
73
79
|
* means that by default, each call will be retried up to 5 times, with an
|
|
74
80
|
* exponential backoff between each attempt.
|
|
75
81
|
*/
|
|
76
|
-
|
|
82
|
+
class AsyncCaller {
|
|
77
83
|
constructor(params) {
|
|
78
84
|
Object.defineProperty(this, "maxConcurrency", {
|
|
79
85
|
enumerable: true,
|
|
@@ -107,15 +113,15 @@ export class AsyncCaller {
|
|
|
107
113
|
});
|
|
108
114
|
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
109
115
|
this.maxRetries = params.maxRetries ?? 4;
|
|
110
|
-
if ("default" in
|
|
116
|
+
if ("default" in p_queue_1.default) {
|
|
111
117
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
-
this.queue = new
|
|
118
|
+
this.queue = new p_queue_1.default.default({
|
|
113
119
|
concurrency: this.maxConcurrency,
|
|
114
120
|
});
|
|
115
121
|
}
|
|
116
122
|
else {
|
|
117
123
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
118
|
-
this.queue = new
|
|
124
|
+
this.queue = new p_queue_1.default({ concurrency: this.maxConcurrency });
|
|
119
125
|
}
|
|
120
126
|
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
121
127
|
this.customFetch = params.fetch;
|
|
@@ -123,7 +129,7 @@ export class AsyncCaller {
|
|
|
123
129
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
130
|
call(callable, ...args) {
|
|
125
131
|
const onFailedResponseHook = this.onFailedResponseHook;
|
|
126
|
-
return this.queue.add(() =>
|
|
132
|
+
return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch(async (error) => {
|
|
127
133
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
128
134
|
if (error instanceof Error) {
|
|
129
135
|
throw error;
|
|
@@ -186,3 +192,4 @@ export class AsyncCaller {
|
|
|
186
192
|
return this.call(() => fetchFn(...args).then((res) => (res.ok ? res : Promise.reject(res))));
|
|
187
193
|
}
|
|
188
194
|
}
|
|
195
|
+
exports.AsyncCaller = AsyncCaller;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// From https://github.com/rexxars/eventsource-parser
|
|
2
3
|
// Inlined due to CJS import issues
|
|
3
|
-
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.createParser = void 0;
|
|
6
|
+
var parse_js_1 = require("./parse.cjs");
|
|
7
|
+
Object.defineProperty(exports, "createParser", { enumerable: true, get: function () { return parse_js_1.createParser; } });
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createParser = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Creates a new EventSource parser.
|
|
3
6
|
*
|
|
@@ -7,7 +10,7 @@
|
|
|
7
10
|
* @returns A new EventSource parser, with `parse` and `reset` methods.
|
|
8
11
|
* @public
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
function createParser(onParse) {
|
|
11
14
|
// Processing state
|
|
12
15
|
let isFirstChunk;
|
|
13
16
|
let buffer;
|
|
@@ -140,6 +143,7 @@ export function createParser(onParse) {
|
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
145
|
}
|
|
146
|
+
exports.createParser = createParser;
|
|
143
147
|
const BOM = [239, 187, 191];
|
|
144
148
|
function hasBom(buffer) {
|
|
145
149
|
return BOM.every((charCode, index) => buffer.charCodeAt(index) === charCode);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventSourceParserStream = void 0;
|
|
4
|
+
const parse_js_1 = require("./parse.cjs");
|
|
2
5
|
/**
|
|
3
6
|
* A TransformStream that ingests a stream of strings and produces a stream of ParsedEvents.
|
|
4
7
|
*
|
|
@@ -11,12 +14,12 @@ import { createParser } from "./parse.js";
|
|
|
11
14
|
* ```
|
|
12
15
|
* @public
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
class EventSourceParserStream extends TransformStream {
|
|
15
18
|
constructor() {
|
|
16
19
|
let parser;
|
|
17
20
|
super({
|
|
18
21
|
start(controller) {
|
|
19
|
-
parser = createParser((event) => {
|
|
22
|
+
parser = (0, parse_js_1.createParser)((event) => {
|
|
20
23
|
if (event.type === "event") {
|
|
21
24
|
controller.enqueue(event);
|
|
22
25
|
}
|
|
@@ -28,3 +31,4 @@ export class EventSourceParserStream extends TransformStream {
|
|
|
28
31
|
});
|
|
29
32
|
}
|
|
30
33
|
}
|
|
34
|
+
exports.EventSourceParserStream = EventSourceParserStream;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist/utils/signals.cjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mergeSignals = void 0;
|
|
4
|
+
function mergeSignals(...signals) {
|
|
2
5
|
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
3
6
|
if (nonZeroSignals.length === 0)
|
|
4
7
|
return undefined;
|
|
@@ -16,3 +19,4 @@ export function mergeSignals(...signals) {
|
|
|
16
19
|
}
|
|
17
20
|
return controller.signal;
|
|
18
21
|
}
|
|
22
|
+
exports.mergeSignals = mergeSignals;
|
package/dist/utils/stream.cjs
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IterableReadableStream = void 0;
|
|
1
4
|
/*
|
|
2
5
|
* Support async iterator syntax for ReadableStreams in all environments.
|
|
3
6
|
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
4
7
|
*/
|
|
5
|
-
|
|
8
|
+
class IterableReadableStream extends ReadableStream {
|
|
6
9
|
constructor() {
|
|
7
10
|
super(...arguments);
|
|
8
11
|
Object.defineProperty(this, "reader", {
|
|
@@ -109,3 +112,4 @@ export class IterableReadableStream extends ReadableStream {
|
|
|
109
112
|
});
|
|
110
113
|
}
|
|
111
114
|
}
|
|
115
|
+
exports.IterableReadableStream = IterableReadableStream;
|