@langchain/langgraph-sdk 0.0.88 → 0.0.90
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/auth/index.d.ts +2 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/client.cjs +15 -9
- package/dist/client.d.ts +2 -2
- package/dist/client.js +12 -6
- package/dist/react/debug.cjs +1 -2
- package/dist/react/stream.cjs +17 -13
- package/dist/react/stream.js +15 -11
- package/dist/react-ui/client.cjs +30 -19
- package/dist/react-ui/client.d.ts +3 -8
- package/dist/react-ui/client.js +9 -7
- package/dist/react-ui/server/server.cjs +1 -1
- package/dist/react-ui/server/server.d.ts +8 -8
- package/dist/react-ui/server/server.js +1 -1
- package/dist/react-ui/types.cjs +3 -4
- package/dist/singletons/fetch.cjs +1 -0
- package/dist/singletons/fetch.js +1 -0
- package/dist/types.messages.d.ts +15 -23
- package/dist/utils/async_caller.cjs +2 -1
- package/dist/utils/async_caller.js +2 -1
- package/dist/utils/env.cjs +1 -2
- package/dist/utils/signals.cjs +1 -2
- package/dist/utils/sse.cjs +4 -5
- package/dist/utils/sse.d.ts +2 -2
- package/dist/utils/sse.js +2 -2
- package/package.json +27 -24
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AuthenticateCallback, AnyCallback, CallbackEvent, OnCallback, BaseAuthReturn, ToUserLike, BaseUser } from "./types.js";
|
|
2
|
-
export declare class Auth<TExtra = {},
|
|
2
|
+
export declare class Auth<TExtra = {}, // eslint-disable-line @typescript-eslint/ban-types
|
|
3
|
+
TAuthReturn extends BaseAuthReturn = BaseAuthReturn, TUser extends BaseUser = ToUserLike<TAuthReturn>> {
|
|
3
4
|
/**
|
|
4
5
|
* @internal
|
|
5
6
|
* @ignore
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -251,7 +251,7 @@ export type ToUserLike<T extends BaseAuthReturn> = T extends string ? {
|
|
|
251
251
|
is_authenticated: boolean;
|
|
252
252
|
display_name: string;
|
|
253
253
|
};
|
|
254
|
-
type CallbackParameter<Event extends string = string, Resource extends string = string, Action extends string = string, Value
|
|
254
|
+
type CallbackParameter<Event extends string = string, Resource extends string = string, Action extends string = string, Value = unknown, TUser extends BaseUser = BaseUser> = {
|
|
255
255
|
event: Event;
|
|
256
256
|
resource: Resource;
|
|
257
257
|
action: Action;
|
package/dist/client.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Client = exports.StoreClient = exports.RunsClient = exports.ThreadsClient = exports.AssistantsClient = exports.CronsClient = void 0;
|
|
4
|
+
exports.getApiKey = getApiKey;
|
|
5
|
+
exports.getClientConfigHash = getClientConfigHash;
|
|
4
6
|
const async_caller_js_1 = require("./utils/async_caller.cjs");
|
|
5
7
|
const env_js_1 = require("./utils/env.cjs");
|
|
6
8
|
const signals_js_1 = require("./utils/signals.cjs");
|
|
@@ -9,6 +11,7 @@ const stream_js_1 = require("./utils/stream.cjs");
|
|
|
9
11
|
function* iterateHeaders(headers) {
|
|
10
12
|
let iter;
|
|
11
13
|
let shouldClear = false;
|
|
14
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
12
15
|
if (headers instanceof Headers) {
|
|
13
16
|
const entries = [];
|
|
14
17
|
headers.forEach((value, name) => {
|
|
@@ -23,7 +26,7 @@ function* iterateHeaders(headers) {
|
|
|
23
26
|
shouldClear = true;
|
|
24
27
|
iter = Object.entries(headers ?? {});
|
|
25
28
|
}
|
|
26
|
-
for (
|
|
29
|
+
for (const item of iter) {
|
|
27
30
|
const name = item[0];
|
|
28
31
|
if (typeof name !== "string")
|
|
29
32
|
throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
|
|
@@ -86,7 +89,6 @@ function getApiKey(apiKey) {
|
|
|
86
89
|
}
|
|
87
90
|
return undefined;
|
|
88
91
|
}
|
|
89
|
-
exports.getApiKey = getApiKey;
|
|
90
92
|
const REGEX_RUN_METADATA = /(\/threads\/(?<thread_id>.+))?\/runs\/(?<run_id>.+)/;
|
|
91
93
|
function getRunMetadataFromResponse(response) {
|
|
92
94
|
const contentLocation = response.headers.get("Content-Location");
|
|
@@ -192,7 +194,7 @@ class BaseClient {
|
|
|
192
194
|
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
193
195
|
if (value == null)
|
|
194
196
|
continue;
|
|
195
|
-
|
|
197
|
+
const strValue = typeof value === "string" || typeof value === "number"
|
|
196
198
|
? value.toString()
|
|
197
199
|
: JSON.stringify(value);
|
|
198
200
|
targetUrl.searchParams.append(key, strValue);
|
|
@@ -586,7 +588,7 @@ class ThreadsClient extends BaseClient {
|
|
|
586
588
|
}
|
|
587
589
|
return this.fetch(`/threads/${threadId}/state`, {
|
|
588
590
|
method: "PATCH",
|
|
589
|
-
json: { metadata
|
|
591
|
+
json: { metadata },
|
|
590
592
|
});
|
|
591
593
|
}
|
|
592
594
|
/**
|
|
@@ -650,6 +652,7 @@ class RunsClient extends BaseClient {
|
|
|
650
652
|
const runMetadata = getRunMetadataFromResponse(response);
|
|
651
653
|
if (runMetadata)
|
|
652
654
|
payload?.onRunCreated?.(runMetadata);
|
|
655
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
653
656
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
654
657
|
.pipeThrough((0, sse_js_1.BytesLineDecoder)())
|
|
655
658
|
.pipeThrough((0, sse_js_1.SSEDecoder)());
|
|
@@ -812,7 +815,7 @@ class RunsClient extends BaseClient {
|
|
|
812
815
|
method: "POST",
|
|
813
816
|
params: {
|
|
814
817
|
wait: wait ? "1" : "0",
|
|
815
|
-
action
|
|
818
|
+
action,
|
|
816
819
|
},
|
|
817
820
|
});
|
|
818
821
|
}
|
|
@@ -843,9 +846,12 @@ class RunsClient extends BaseClient {
|
|
|
843
846
|
* stream modes enabled.
|
|
844
847
|
* @returns An async generator yielding stream parts.
|
|
845
848
|
*/
|
|
846
|
-
async *joinStream(threadId, runId, options
|
|
849
|
+
async *joinStream(threadId, runId, options
|
|
850
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
851
|
+
) {
|
|
847
852
|
const opts = typeof options === "object" &&
|
|
848
853
|
options != null &&
|
|
854
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
849
855
|
options instanceof AbortSignal
|
|
850
856
|
? { signal: options }
|
|
851
857
|
: options;
|
|
@@ -863,6 +869,7 @@ class RunsClient extends BaseClient {
|
|
|
863
869
|
stream_mode: opts?.streamMode,
|
|
864
870
|
},
|
|
865
871
|
}));
|
|
872
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
866
873
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
867
874
|
.pipeThrough((0, sse_js_1.BytesLineDecoder)())
|
|
868
875
|
.pipeThrough((0, sse_js_1.SSEDecoder)());
|
|
@@ -1080,7 +1087,7 @@ class UiClient extends BaseClient {
|
|
|
1080
1087
|
return promise;
|
|
1081
1088
|
}
|
|
1082
1089
|
async getComponent(assistantId, agentName) {
|
|
1083
|
-
return UiClient
|
|
1090
|
+
return UiClient.getOrCached(`${this.apiUrl}-${assistantId}-${agentName}`, async () => {
|
|
1084
1091
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/ui/${assistantId}`, {
|
|
1085
1092
|
headers: {
|
|
1086
1093
|
Accept: "text/html",
|
|
@@ -1193,4 +1200,3 @@ exports.Client = Client;
|
|
|
1193
1200
|
function getClientConfigHash(client) {
|
|
1194
1201
|
return client["~configHash"];
|
|
1195
1202
|
}
|
|
1196
|
-
exports.getClientConfigHash = getClientConfigHash;
|
package/dist/client.d.ts
CHANGED
|
@@ -464,7 +464,7 @@ export declare class StoreClient extends BaseClient {
|
|
|
464
464
|
* );
|
|
465
465
|
* ```
|
|
466
466
|
*/
|
|
467
|
-
putItem(namespace: string[], key: string, value: Record<string,
|
|
467
|
+
putItem(namespace: string[], key: string, value: Record<string, unknown>, options?: {
|
|
468
468
|
index?: false | string[] | null;
|
|
469
469
|
ttl?: number | null;
|
|
470
470
|
}): Promise<void>;
|
|
@@ -541,7 +541,7 @@ export declare class StoreClient extends BaseClient {
|
|
|
541
541
|
* ```
|
|
542
542
|
*/
|
|
543
543
|
searchItems(namespacePrefix: string[], options?: {
|
|
544
|
-
filter?: Record<string,
|
|
544
|
+
filter?: Record<string, unknown>;
|
|
545
545
|
limit?: number;
|
|
546
546
|
offset?: number;
|
|
547
547
|
query?: string;
|
package/dist/client.js
CHANGED
|
@@ -6,6 +6,7 @@ import { IterableReadableStream } from "./utils/stream.js";
|
|
|
6
6
|
function* iterateHeaders(headers) {
|
|
7
7
|
let iter;
|
|
8
8
|
let shouldClear = false;
|
|
9
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
9
10
|
if (headers instanceof Headers) {
|
|
10
11
|
const entries = [];
|
|
11
12
|
headers.forEach((value, name) => {
|
|
@@ -20,7 +21,7 @@ function* iterateHeaders(headers) {
|
|
|
20
21
|
shouldClear = true;
|
|
21
22
|
iter = Object.entries(headers ?? {});
|
|
22
23
|
}
|
|
23
|
-
for (
|
|
24
|
+
for (const item of iter) {
|
|
24
25
|
const name = item[0];
|
|
25
26
|
if (typeof name !== "string")
|
|
26
27
|
throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
|
|
@@ -188,7 +189,7 @@ class BaseClient {
|
|
|
188
189
|
for (const [key, value] of Object.entries(mutatedOptions.params)) {
|
|
189
190
|
if (value == null)
|
|
190
191
|
continue;
|
|
191
|
-
|
|
192
|
+
const strValue = typeof value === "string" || typeof value === "number"
|
|
192
193
|
? value.toString()
|
|
193
194
|
: JSON.stringify(value);
|
|
194
195
|
targetUrl.searchParams.append(key, strValue);
|
|
@@ -580,7 +581,7 @@ export class ThreadsClient extends BaseClient {
|
|
|
580
581
|
}
|
|
581
582
|
return this.fetch(`/threads/${threadId}/state`, {
|
|
582
583
|
method: "PATCH",
|
|
583
|
-
json: { metadata
|
|
584
|
+
json: { metadata },
|
|
584
585
|
});
|
|
585
586
|
}
|
|
586
587
|
/**
|
|
@@ -643,6 +644,7 @@ export class RunsClient extends BaseClient {
|
|
|
643
644
|
const runMetadata = getRunMetadataFromResponse(response);
|
|
644
645
|
if (runMetadata)
|
|
645
646
|
payload?.onRunCreated?.(runMetadata);
|
|
647
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
646
648
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
647
649
|
.pipeThrough(BytesLineDecoder())
|
|
648
650
|
.pipeThrough(SSEDecoder());
|
|
@@ -805,7 +807,7 @@ export class RunsClient extends BaseClient {
|
|
|
805
807
|
method: "POST",
|
|
806
808
|
params: {
|
|
807
809
|
wait: wait ? "1" : "0",
|
|
808
|
-
action
|
|
810
|
+
action,
|
|
809
811
|
},
|
|
810
812
|
});
|
|
811
813
|
}
|
|
@@ -836,9 +838,12 @@ export class RunsClient extends BaseClient {
|
|
|
836
838
|
* stream modes enabled.
|
|
837
839
|
* @returns An async generator yielding stream parts.
|
|
838
840
|
*/
|
|
839
|
-
async *joinStream(threadId, runId, options
|
|
841
|
+
async *joinStream(threadId, runId, options
|
|
842
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
843
|
+
) {
|
|
840
844
|
const opts = typeof options === "object" &&
|
|
841
845
|
options != null &&
|
|
846
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
842
847
|
options instanceof AbortSignal
|
|
843
848
|
? { signal: options }
|
|
844
849
|
: options;
|
|
@@ -856,6 +861,7 @@ export class RunsClient extends BaseClient {
|
|
|
856
861
|
stream_mode: opts?.streamMode,
|
|
857
862
|
},
|
|
858
863
|
}));
|
|
864
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
859
865
|
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() }))
|
|
860
866
|
.pipeThrough(BytesLineDecoder())
|
|
861
867
|
.pipeThrough(SSEDecoder());
|
|
@@ -1071,7 +1077,7 @@ class UiClient extends BaseClient {
|
|
|
1071
1077
|
return promise;
|
|
1072
1078
|
}
|
|
1073
1079
|
async getComponent(assistantId, agentName) {
|
|
1074
|
-
return UiClient
|
|
1080
|
+
return UiClient.getOrCached(`${this.apiUrl}-${assistantId}-${agentName}`, async () => {
|
|
1075
1081
|
const response = await this.asyncCaller.fetch(...this.prepareFetchOptions(`/ui/${assistantId}`, {
|
|
1076
1082
|
headers: {
|
|
1077
1083
|
Accept: "text/html",
|
package/dist/react/debug.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DebugSegmentsView =
|
|
3
|
+
exports.DebugSegmentsView = DebugSegmentsView;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
function DebugSegmentsView(props) {
|
|
6
6
|
const concatContent = (value) => {
|
|
@@ -29,4 +29,3 @@ function DebugSegmentsView(props) {
|
|
|
29
29
|
return null;
|
|
30
30
|
}) }));
|
|
31
31
|
}
|
|
32
|
-
exports.DebugSegmentsView = DebugSegmentsView;
|
package/dist/react/stream.cjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
3
3
|
"use client";
|
|
4
|
+
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
4
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.useStream =
|
|
6
|
-
const client_js_1 = require("../client.cjs");
|
|
6
|
+
exports.useStream = useStream;
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const messages_1 = require("@langchain/core/messages");
|
|
9
|
+
const client_js_1 = require("../client.cjs");
|
|
9
10
|
class StreamError extends Error {
|
|
10
11
|
constructor(data) {
|
|
11
12
|
super(data.message);
|
|
@@ -37,13 +38,14 @@ class MessageTupleManager {
|
|
|
37
38
|
// TODO: this is sometimes sent from the API
|
|
38
39
|
// figure out how to prevent this or move this to LC.js
|
|
39
40
|
if (serialized.type.endsWith("MessageChunk")) {
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
40
42
|
serialized.type = serialized.type
|
|
41
43
|
.slice(0, -"MessageChunk".length)
|
|
42
44
|
.toLowerCase();
|
|
43
45
|
}
|
|
44
46
|
const message = (0, messages_1.coerceMessageLikeToMessage)(serialized);
|
|
45
47
|
const chunk = tryConvertToChunk(message);
|
|
46
|
-
const id =
|
|
48
|
+
const { id } = chunk ?? message;
|
|
47
49
|
if (!id) {
|
|
48
50
|
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
49
51
|
return null;
|
|
@@ -77,7 +79,7 @@ function unique(array) {
|
|
|
77
79
|
return [...new Set(array)];
|
|
78
80
|
}
|
|
79
81
|
function findLastIndex(array, predicate) {
|
|
80
|
-
for (let i = array.length - 1; i >= 0; i
|
|
82
|
+
for (let i = array.length - 1; i >= 0; i -= 1) {
|
|
81
83
|
if (predicate(array[i]))
|
|
82
84
|
return i;
|
|
83
85
|
}
|
|
@@ -112,8 +114,8 @@ function getBranchSequence(history) {
|
|
|
112
114
|
}
|
|
113
115
|
for (const value of children) {
|
|
114
116
|
const id = value.checkpoint.checkpoint_id;
|
|
115
|
-
let sequence = task
|
|
116
|
-
let path = task
|
|
117
|
+
let { sequence } = task;
|
|
118
|
+
let { path } = task;
|
|
117
119
|
if (fork != null) {
|
|
118
120
|
sequence = { type: "sequence", items: [] };
|
|
119
121
|
fork.items.unshift(sequence);
|
|
@@ -188,11 +190,11 @@ function useThreadHistory(threadId, client, clearCallbackRef, submittingRef) {
|
|
|
188
190
|
setHistory([]);
|
|
189
191
|
clearCallbackRef.current?.();
|
|
190
192
|
return Promise.resolve([]);
|
|
191
|
-
}, []);
|
|
193
|
+
}, [clearCallbackRef]);
|
|
192
194
|
(0, react_1.useEffect)(() => {
|
|
193
195
|
if (submittingRef.current)
|
|
194
196
|
return;
|
|
195
|
-
fetcher(threadId);
|
|
197
|
+
void fetcher(threadId);
|
|
196
198
|
}, [fetcher, clientHash, submittingRef, threadId]);
|
|
197
199
|
return {
|
|
198
200
|
data: history,
|
|
@@ -239,6 +241,7 @@ function useStreamValuesState() {
|
|
|
239
241
|
return [values?.[0] ?? null, setStreamValues, mutate];
|
|
240
242
|
}
|
|
241
243
|
function useStream(options) {
|
|
244
|
+
// eslint-disable-next-line prefer-const
|
|
242
245
|
let { assistantId, messagesKey, onCreated, onError, onFinish } = options;
|
|
243
246
|
const reconnectOnMountRef = (0, react_1.useRef)(options.reconnectOnMount);
|
|
244
247
|
const runMetadataStorage = (0, react_1.useMemo)(() => {
|
|
@@ -371,7 +374,7 @@ function useStream(options) {
|
|
|
371
374
|
if (runMetadataStorage && threadId) {
|
|
372
375
|
const runId = runMetadataStorage.getItem(`lg:stream:${threadId}`);
|
|
373
376
|
if (runId)
|
|
374
|
-
client.runs.cancel(threadId, runId);
|
|
377
|
+
void client.runs.cancel(threadId, runId);
|
|
375
378
|
runMetadataStorage.removeItem(`lg:stream:${threadId}`);
|
|
376
379
|
}
|
|
377
380
|
options?.onStop?.({ mutate: getMutateFn("stop", historyValues) });
|
|
@@ -444,7 +447,7 @@ function useStream(options) {
|
|
|
444
447
|
onFinish?.(lastHead, getCallbackMeta?.());
|
|
445
448
|
}
|
|
446
449
|
catch (error) {
|
|
447
|
-
if (!(error instanceof Error &&
|
|
450
|
+
if (!(error instanceof Error && // eslint-disable-line no-instanceof/no-instanceof
|
|
448
451
|
(error.name === "AbortError" || error.name === "TimeoutError"))) {
|
|
449
452
|
console.error(error);
|
|
450
453
|
setStreamError(error);
|
|
@@ -460,6 +463,7 @@ function useStream(options) {
|
|
|
460
463
|
}
|
|
461
464
|
}
|
|
462
465
|
const joinStream = async (runId, lastEventId, options) => {
|
|
466
|
+
// eslint-disable-next-line no-param-reassign
|
|
463
467
|
lastEventId ??= "-1";
|
|
464
468
|
if (!threadId)
|
|
465
469
|
return;
|
|
@@ -512,6 +516,7 @@ function useStream(options) {
|
|
|
512
516
|
...callbackStreamMode,
|
|
513
517
|
]);
|
|
514
518
|
const checkpoint = submitOptions?.checkpoint ?? threadHead?.checkpoint ?? undefined;
|
|
519
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
515
520
|
// @ts-expect-error
|
|
516
521
|
if (checkpoint != null)
|
|
517
522
|
delete checkpoint.thread_id;
|
|
@@ -580,7 +585,7 @@ function useStream(options) {
|
|
|
580
585
|
(0, react_1.useEffect)(() => {
|
|
581
586
|
if (reconnectKey && reconnectRef.current.shouldReconnect) {
|
|
582
587
|
reconnectRef.current.shouldReconnect = false;
|
|
583
|
-
joinStreamRef.current?.(reconnectKey.runId);
|
|
588
|
+
void joinStreamRef.current?.(reconnectKey.runId);
|
|
584
589
|
}
|
|
585
590
|
}, [reconnectKey]);
|
|
586
591
|
const error = streamError ?? historyError;
|
|
@@ -595,7 +600,7 @@ function useStream(options) {
|
|
|
595
600
|
error,
|
|
596
601
|
isLoading,
|
|
597
602
|
stop,
|
|
598
|
-
submit,
|
|
603
|
+
submit, // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
599
604
|
joinStream,
|
|
600
605
|
branch,
|
|
601
606
|
setBranch,
|
|
@@ -626,4 +631,3 @@ function useStream(options) {
|
|
|
626
631
|
},
|
|
627
632
|
};
|
|
628
633
|
}
|
|
629
|
-
exports.useStream = useStream;
|
package/dist/react/stream.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
2
2
|
"use client";
|
|
3
|
-
import { Client, getClientConfigHash } from "../client.js";
|
|
4
3
|
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
5
4
|
import { coerceMessageLikeToMessage, convertToChunk, isBaseMessageChunk, } from "@langchain/core/messages";
|
|
5
|
+
import { Client, getClientConfigHash } from "../client.js";
|
|
6
6
|
class StreamError extends Error {
|
|
7
7
|
constructor(data) {
|
|
8
8
|
super(data.message);
|
|
@@ -34,13 +34,14 @@ class MessageTupleManager {
|
|
|
34
34
|
// TODO: this is sometimes sent from the API
|
|
35
35
|
// figure out how to prevent this or move this to LC.js
|
|
36
36
|
if (serialized.type.endsWith("MessageChunk")) {
|
|
37
|
+
// eslint-disable-next-line no-param-reassign
|
|
37
38
|
serialized.type = serialized.type
|
|
38
39
|
.slice(0, -"MessageChunk".length)
|
|
39
40
|
.toLowerCase();
|
|
40
41
|
}
|
|
41
42
|
const message = coerceMessageLikeToMessage(serialized);
|
|
42
43
|
const chunk = tryConvertToChunk(message);
|
|
43
|
-
const id =
|
|
44
|
+
const { id } = chunk ?? message;
|
|
44
45
|
if (!id) {
|
|
45
46
|
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
46
47
|
return null;
|
|
@@ -74,7 +75,7 @@ function unique(array) {
|
|
|
74
75
|
return [...new Set(array)];
|
|
75
76
|
}
|
|
76
77
|
function findLastIndex(array, predicate) {
|
|
77
|
-
for (let i = array.length - 1; i >= 0; i
|
|
78
|
+
for (let i = array.length - 1; i >= 0; i -= 1) {
|
|
78
79
|
if (predicate(array[i]))
|
|
79
80
|
return i;
|
|
80
81
|
}
|
|
@@ -109,8 +110,8 @@ function getBranchSequence(history) {
|
|
|
109
110
|
}
|
|
110
111
|
for (const value of children) {
|
|
111
112
|
const id = value.checkpoint.checkpoint_id;
|
|
112
|
-
let sequence = task
|
|
113
|
-
let path = task
|
|
113
|
+
let { sequence } = task;
|
|
114
|
+
let { path } = task;
|
|
114
115
|
if (fork != null) {
|
|
115
116
|
sequence = { type: "sequence", items: [] };
|
|
116
117
|
fork.items.unshift(sequence);
|
|
@@ -185,11 +186,11 @@ function useThreadHistory(threadId, client, clearCallbackRef, submittingRef) {
|
|
|
185
186
|
setHistory([]);
|
|
186
187
|
clearCallbackRef.current?.();
|
|
187
188
|
return Promise.resolve([]);
|
|
188
|
-
}, []);
|
|
189
|
+
}, [clearCallbackRef]);
|
|
189
190
|
useEffect(() => {
|
|
190
191
|
if (submittingRef.current)
|
|
191
192
|
return;
|
|
192
|
-
fetcher(threadId);
|
|
193
|
+
void fetcher(threadId);
|
|
193
194
|
}, [fetcher, clientHash, submittingRef, threadId]);
|
|
194
195
|
return {
|
|
195
196
|
data: history,
|
|
@@ -236,6 +237,7 @@ function useStreamValuesState() {
|
|
|
236
237
|
return [values?.[0] ?? null, setStreamValues, mutate];
|
|
237
238
|
}
|
|
238
239
|
export function useStream(options) {
|
|
240
|
+
// eslint-disable-next-line prefer-const
|
|
239
241
|
let { assistantId, messagesKey, onCreated, onError, onFinish } = options;
|
|
240
242
|
const reconnectOnMountRef = useRef(options.reconnectOnMount);
|
|
241
243
|
const runMetadataStorage = useMemo(() => {
|
|
@@ -368,7 +370,7 @@ export function useStream(options) {
|
|
|
368
370
|
if (runMetadataStorage && threadId) {
|
|
369
371
|
const runId = runMetadataStorage.getItem(`lg:stream:${threadId}`);
|
|
370
372
|
if (runId)
|
|
371
|
-
client.runs.cancel(threadId, runId);
|
|
373
|
+
void client.runs.cancel(threadId, runId);
|
|
372
374
|
runMetadataStorage.removeItem(`lg:stream:${threadId}`);
|
|
373
375
|
}
|
|
374
376
|
options?.onStop?.({ mutate: getMutateFn("stop", historyValues) });
|
|
@@ -441,7 +443,7 @@ export function useStream(options) {
|
|
|
441
443
|
onFinish?.(lastHead, getCallbackMeta?.());
|
|
442
444
|
}
|
|
443
445
|
catch (error) {
|
|
444
|
-
if (!(error instanceof Error &&
|
|
446
|
+
if (!(error instanceof Error && // eslint-disable-line no-instanceof/no-instanceof
|
|
445
447
|
(error.name === "AbortError" || error.name === "TimeoutError"))) {
|
|
446
448
|
console.error(error);
|
|
447
449
|
setStreamError(error);
|
|
@@ -457,6 +459,7 @@ export function useStream(options) {
|
|
|
457
459
|
}
|
|
458
460
|
}
|
|
459
461
|
const joinStream = async (runId, lastEventId, options) => {
|
|
462
|
+
// eslint-disable-next-line no-param-reassign
|
|
460
463
|
lastEventId ??= "-1";
|
|
461
464
|
if (!threadId)
|
|
462
465
|
return;
|
|
@@ -509,6 +512,7 @@ export function useStream(options) {
|
|
|
509
512
|
...callbackStreamMode,
|
|
510
513
|
]);
|
|
511
514
|
const checkpoint = submitOptions?.checkpoint ?? threadHead?.checkpoint ?? undefined;
|
|
515
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
512
516
|
// @ts-expect-error
|
|
513
517
|
if (checkpoint != null)
|
|
514
518
|
delete checkpoint.thread_id;
|
|
@@ -577,7 +581,7 @@ export function useStream(options) {
|
|
|
577
581
|
useEffect(() => {
|
|
578
582
|
if (reconnectKey && reconnectRef.current.shouldReconnect) {
|
|
579
583
|
reconnectRef.current.shouldReconnect = false;
|
|
580
|
-
joinStreamRef.current?.(reconnectKey.runId);
|
|
584
|
+
void joinStreamRef.current?.(reconnectKey.runId);
|
|
581
585
|
}
|
|
582
586
|
}, [reconnectKey]);
|
|
583
587
|
const error = streamError ?? historyError;
|
|
@@ -592,7 +596,7 @@ export function useStream(options) {
|
|
|
592
596
|
error,
|
|
593
597
|
isLoading,
|
|
594
598
|
stop,
|
|
595
|
-
submit,
|
|
599
|
+
submit, // eslint-disable-line @typescript-eslint/no-misused-promises
|
|
596
600
|
joinStream,
|
|
597
601
|
branch,
|
|
598
602
|
setBranch,
|
package/dist/react-ui/client.cjs
CHANGED
|
@@ -16,20 +16,33 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
37
|
+
exports.useStreamContext = useStreamContext;
|
|
38
|
+
exports.LoadExternalComponent = LoadExternalComponent;
|
|
39
|
+
exports.experimental_loadShare = experimental_loadShare;
|
|
40
|
+
exports.bootstrapUiContext = bootstrapUiContext;
|
|
28
41
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
|
-
const index_js_1 = require("../react/index.cjs");
|
|
30
42
|
const React = __importStar(require("react"));
|
|
31
43
|
const ReactDOM = __importStar(require("react-dom"));
|
|
32
44
|
const JsxRuntime = __importStar(require("react/jsx-runtime"));
|
|
45
|
+
const index_js_1 = require("../react/index.cjs");
|
|
33
46
|
const UseStreamContext = React.createContext(null);
|
|
34
47
|
function useStreamContext() {
|
|
35
48
|
const ctx = React.useContext(UseStreamContext);
|
|
@@ -44,7 +57,6 @@ function useStreamContext() {
|
|
|
44
57
|
},
|
|
45
58
|
});
|
|
46
59
|
}
|
|
47
|
-
exports.useStreamContext = useStreamContext;
|
|
48
60
|
class ComponentStore {
|
|
49
61
|
constructor() {
|
|
50
62
|
Object.defineProperty(this, "cache", {
|
|
@@ -118,17 +130,19 @@ function LoadExternalComponent({ stream, namespace, message, meta, fallback, com
|
|
|
118
130
|
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
119
131
|
const clientComponent = components?.[message.name];
|
|
120
132
|
const hasClientComponent = clientComponent != null;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
133
|
+
let fallbackComponent = null;
|
|
134
|
+
if (isReactNode(fallback)) {
|
|
135
|
+
fallbackComponent = fallback;
|
|
136
|
+
}
|
|
137
|
+
else if (typeof fallback === "object" && fallback != null) {
|
|
138
|
+
fallbackComponent = fallback?.[message.name];
|
|
139
|
+
}
|
|
126
140
|
const uiNamespace = namespace ?? stream.assistantId;
|
|
127
141
|
const uiClient = stream.client["~ui"];
|
|
128
142
|
React.useEffect(() => {
|
|
129
143
|
if (hasClientComponent)
|
|
130
144
|
return;
|
|
131
|
-
uiClient.getComponent(uiNamespace, message.name).then((html) => {
|
|
145
|
+
void uiClient.getComponent(uiNamespace, message.name).then((html) => {
|
|
132
146
|
const dom = ref.current;
|
|
133
147
|
if (!dom)
|
|
134
148
|
return;
|
|
@@ -146,14 +160,12 @@ function LoadExternalComponent({ stream, namespace, message, meta, fallback, com
|
|
|
146
160
|
? ReactDOM.createPortal(React.createElement(state.comp, message.props), state.target)
|
|
147
161
|
: fallbackComponent })] }));
|
|
148
162
|
}
|
|
149
|
-
exports.LoadExternalComponent = LoadExternalComponent;
|
|
150
163
|
function experimental_loadShare(name, module) {
|
|
151
164
|
if (typeof window === "undefined")
|
|
152
165
|
return;
|
|
153
166
|
window[REQUIRE_EXTRA_SYMBOL] ??= {};
|
|
154
167
|
window[REQUIRE_EXTRA_SYMBOL][name] = module;
|
|
155
168
|
}
|
|
156
|
-
exports.experimental_loadShare = experimental_loadShare;
|
|
157
169
|
function bootstrapUiContext() {
|
|
158
170
|
if (typeof window === "undefined") {
|
|
159
171
|
return;
|
|
@@ -184,4 +196,3 @@ function bootstrapUiContext() {
|
|
|
184
196
|
throw new Error(`Unknown module...: ${name}`);
|
|
185
197
|
};
|
|
186
198
|
}
|
|
187
|
-
exports.bootstrapUiContext = bootstrapUiContext;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import { useStream } from "../react/index.js";
|
|
2
|
-
import type { UIMessage } from "./types.js";
|
|
3
1
|
import * as React from "react";
|
|
4
2
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
3
|
+
import type { UIMessage } from "./types.js";
|
|
4
|
+
import { useStream } from "../react/index.js";
|
|
5
5
|
import type { UseStream } from "../react/stream.js";
|
|
6
6
|
declare const UseStreamContext: React.Context<{
|
|
7
|
-
stream:
|
|
8
|
-
ConfigurableType?: Record<string, unknown> | undefined;
|
|
9
|
-
InterruptType?: unknown;
|
|
10
|
-
CustomEventType?: unknown;
|
|
11
|
-
UpdateType?: unknown;
|
|
12
|
-
}>;
|
|
7
|
+
stream: ReturnType<typeof useStream>;
|
|
13
8
|
meta: unknown;
|
|
14
9
|
}>;
|
|
15
10
|
type BagTemplate = {
|
package/dist/react-ui/client.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useStream } from "../react/index.js";
|
|
4
3
|
import * as React from "react";
|
|
5
4
|
import * as ReactDOM from "react-dom";
|
|
6
5
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
6
|
+
import { useStream } from "../react/index.js";
|
|
7
7
|
const UseStreamContext = React.createContext(null);
|
|
8
8
|
export function useStreamContext() {
|
|
9
9
|
const ctx = React.useContext(UseStreamContext);
|
|
@@ -91,17 +91,19 @@ export function LoadExternalComponent({ stream, namespace, message, meta, fallba
|
|
|
91
91
|
const state = React.useSyncExternalStore(store.subscribe, store.getSnapshot);
|
|
92
92
|
const clientComponent = components?.[message.name];
|
|
93
93
|
const hasClientComponent = clientComponent != null;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
let fallbackComponent = null;
|
|
95
|
+
if (isReactNode(fallback)) {
|
|
96
|
+
fallbackComponent = fallback;
|
|
97
|
+
}
|
|
98
|
+
else if (typeof fallback === "object" && fallback != null) {
|
|
99
|
+
fallbackComponent = fallback?.[message.name];
|
|
100
|
+
}
|
|
99
101
|
const uiNamespace = namespace ?? stream.assistantId;
|
|
100
102
|
const uiClient = stream.client["~ui"];
|
|
101
103
|
React.useEffect(() => {
|
|
102
104
|
if (hasClientComponent)
|
|
103
105
|
return;
|
|
104
|
-
uiClient.getComponent(uiNamespace, message.name).then((html) => {
|
|
106
|
+
void uiClient.getComponent(uiNamespace, message.name).then((html) => {
|
|
105
107
|
const dom = ref.current;
|
|
106
108
|
if (!dom)
|
|
107
109
|
return;
|
|
@@ -27,23 +27,23 @@ export declare const typedUi: <Decl extends Record<string, ElementType>>(config:
|
|
|
27
27
|
}) => {
|
|
28
28
|
push: {
|
|
29
29
|
<K extends keyof Decl & string>(message: {
|
|
30
|
-
id?: string
|
|
30
|
+
id?: string;
|
|
31
31
|
name: K;
|
|
32
32
|
props: { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K];
|
|
33
|
-
metadata?: Record<string, unknown
|
|
33
|
+
metadata?: Record<string, unknown>;
|
|
34
34
|
}, options?: {
|
|
35
35
|
message?: MessageLike;
|
|
36
36
|
merge?: boolean;
|
|
37
37
|
}): UIMessage<K, { [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K]>;
|
|
38
|
-
<
|
|
39
|
-
id?: string
|
|
40
|
-
name:
|
|
41
|
-
props: Partial<{ [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[
|
|
42
|
-
metadata?: Record<string, unknown
|
|
38
|
+
<K extends keyof Decl & string>(message: {
|
|
39
|
+
id?: string;
|
|
40
|
+
name: K;
|
|
41
|
+
props: Partial<{ [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K]>;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
43
|
}, options: {
|
|
44
44
|
message?: MessageLike;
|
|
45
45
|
merge: true;
|
|
46
|
-
}): UIMessage<
|
|
46
|
+
}): UIMessage<K, Partial<{ [K_1 in keyof Decl]: ComponentPropsWithoutRef<Decl[K_1]>; }[K]>>;
|
|
47
47
|
};
|
|
48
48
|
delete: (id: string) => RemoveUIMessage;
|
|
49
49
|
items: (RemoveUIMessage | UIMessage<string, Record<string, unknown>>)[];
|
package/dist/react-ui/types.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isUIMessage = isUIMessage;
|
|
4
|
+
exports.isRemoveUIMessage = isRemoveUIMessage;
|
|
5
|
+
exports.uiMessageReducer = uiMessageReducer;
|
|
4
6
|
function isUIMessage(message) {
|
|
5
7
|
if (typeof message !== "object" || message == null)
|
|
6
8
|
return false;
|
|
@@ -8,7 +10,6 @@ function isUIMessage(message) {
|
|
|
8
10
|
return false;
|
|
9
11
|
return message.type === "ui";
|
|
10
12
|
}
|
|
11
|
-
exports.isUIMessage = isUIMessage;
|
|
12
13
|
function isRemoveUIMessage(message) {
|
|
13
14
|
if (typeof message !== "object" || message == null)
|
|
14
15
|
return false;
|
|
@@ -16,7 +17,6 @@ function isRemoveUIMessage(message) {
|
|
|
16
17
|
return false;
|
|
17
18
|
return message.type === "remove-ui";
|
|
18
19
|
}
|
|
19
|
-
exports.isRemoveUIMessage = isRemoveUIMessage;
|
|
20
20
|
function uiMessageReducer(state, update) {
|
|
21
21
|
const events = Array.isArray(update) ? update : [update];
|
|
22
22
|
let newState = state.slice();
|
|
@@ -40,4 +40,3 @@ function uiMessageReducer(state, update) {
|
|
|
40
40
|
}
|
|
41
41
|
return newState;
|
|
42
42
|
}
|
|
43
|
-
exports.uiMessageReducer = uiMessageReducer;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._getFetchImplementation = exports.overrideFetchImplementation = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
5
|
// Wrap the default fetch call due to issues with illegal invocations
|
|
5
6
|
// in some environments:
|
|
6
7
|
// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
|
package/dist/singletons/fetch.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
// Wrap the default fetch call due to issues with illegal invocations
|
|
2
3
|
// in some environments:
|
|
3
4
|
// https://stackoverflow.com/questions/69876859/why-does-bind-fix-failed-to-execute-fetch-on-window-illegal-invocation-err
|
package/dist/types.messages.d.ts
CHANGED
|
@@ -16,15 +16,20 @@ type MessageContent = string | MessageContentComplex[];
|
|
|
16
16
|
* Model-specific additional kwargs, which is passed back to the underlying LLM.
|
|
17
17
|
*/
|
|
18
18
|
type MessageAdditionalKwargs = Record<string, unknown>;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
id?: string | undefined;
|
|
19
|
+
type BaseMessage = {
|
|
20
|
+
additional_kwargs?: MessageAdditionalKwargs | undefined;
|
|
22
21
|
content: MessageContent;
|
|
22
|
+
id?: string | undefined;
|
|
23
|
+
name?: string | undefined;
|
|
24
|
+
response_metadata?: Record<string, unknown> | undefined;
|
|
23
25
|
};
|
|
24
|
-
export type
|
|
26
|
+
export type HumanMessage = BaseMessage & {
|
|
27
|
+
type: "human";
|
|
28
|
+
example?: boolean | undefined;
|
|
29
|
+
};
|
|
30
|
+
export type AIMessage = BaseMessage & {
|
|
25
31
|
type: "ai";
|
|
26
|
-
|
|
27
|
-
content: MessageContent;
|
|
32
|
+
example?: boolean | undefined;
|
|
28
33
|
tool_calls?: {
|
|
29
34
|
name: string;
|
|
30
35
|
args: {
|
|
@@ -54,18 +59,11 @@ export type AIMessage = {
|
|
|
54
59
|
reasoning?: number | undefined;
|
|
55
60
|
} | undefined;
|
|
56
61
|
} | undefined;
|
|
57
|
-
additional_kwargs?: MessageAdditionalKwargs | undefined;
|
|
58
|
-
response_metadata?: Record<string, unknown> | undefined;
|
|
59
62
|
};
|
|
60
|
-
export type ToolMessage = {
|
|
63
|
+
export type ToolMessage = BaseMessage & {
|
|
61
64
|
type: "tool";
|
|
62
|
-
name?: string | undefined;
|
|
63
|
-
id?: string | undefined;
|
|
64
|
-
content: MessageContent;
|
|
65
65
|
status?: "error" | "success" | undefined;
|
|
66
66
|
tool_call_id: string;
|
|
67
|
-
additional_kwargs?: MessageAdditionalKwargs | undefined;
|
|
68
|
-
response_metadata?: Record<string, unknown> | undefined;
|
|
69
67
|
/**
|
|
70
68
|
* Artifact of the Tool execution which is not meant to be sent to the model.
|
|
71
69
|
*
|
|
@@ -75,20 +73,14 @@ export type ToolMessage = {
|
|
|
75
73
|
*/
|
|
76
74
|
artifact?: any;
|
|
77
75
|
};
|
|
78
|
-
export type SystemMessage = {
|
|
76
|
+
export type SystemMessage = BaseMessage & {
|
|
79
77
|
type: "system";
|
|
80
|
-
id?: string | undefined;
|
|
81
|
-
content: MessageContent;
|
|
82
78
|
};
|
|
83
|
-
export type FunctionMessage = {
|
|
79
|
+
export type FunctionMessage = BaseMessage & {
|
|
84
80
|
type: "function";
|
|
85
|
-
id?: string | undefined;
|
|
86
|
-
content: MessageContent;
|
|
87
81
|
};
|
|
88
|
-
export type RemoveMessage = {
|
|
82
|
+
export type RemoveMessage = BaseMessage & {
|
|
89
83
|
type: "remove";
|
|
90
|
-
id: string;
|
|
91
|
-
content: MessageContent;
|
|
92
84
|
};
|
|
93
85
|
export type Message = HumanMessage | AIMessage | ToolMessage | SystemMessage | FunctionMessage | RemoveMessage;
|
|
94
86
|
export {};
|
|
@@ -128,7 +128,7 @@ class AsyncCaller {
|
|
|
128
128
|
}
|
|
129
129
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
130
|
call(callable, ...args) {
|
|
131
|
-
const onFailedResponseHook = this
|
|
131
|
+
const { onFailedResponseHook } = this;
|
|
132
132
|
return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch(async (error) => {
|
|
133
133
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
134
134
|
if (error instanceof Error) {
|
|
@@ -153,6 +153,7 @@ class AsyncCaller {
|
|
|
153
153
|
if (error?.code === "ECONNABORTED") {
|
|
154
154
|
throw error;
|
|
155
155
|
}
|
|
156
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
156
157
|
if (error instanceof HTTPError) {
|
|
157
158
|
if (STATUS_NO_RETRY.includes(error.status)) {
|
|
158
159
|
throw error;
|
|
@@ -122,7 +122,7 @@ export class AsyncCaller {
|
|
|
122
122
|
}
|
|
123
123
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
124
|
call(callable, ...args) {
|
|
125
|
-
const onFailedResponseHook = this
|
|
125
|
+
const { onFailedResponseHook } = this;
|
|
126
126
|
return this.queue.add(() => pRetry(() => callable(...args).catch(async (error) => {
|
|
127
127
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
128
128
|
if (error instanceof Error) {
|
|
@@ -147,6 +147,7 @@ export class AsyncCaller {
|
|
|
147
147
|
if (error?.code === "ECONNABORTED") {
|
|
148
148
|
throw error;
|
|
149
149
|
}
|
|
150
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
150
151
|
if (error instanceof HTTPError) {
|
|
151
152
|
if (STATUS_NO_RETRY.includes(error.status)) {
|
|
152
153
|
throw error;
|
package/dist/utils/env.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getEnvironmentVariable =
|
|
3
|
+
exports.getEnvironmentVariable = getEnvironmentVariable;
|
|
4
4
|
function getEnvironmentVariable(name) {
|
|
5
5
|
// Certain setups (Deno, frontend) will throw an error if you try to access environment variables
|
|
6
6
|
try {
|
|
@@ -13,4 +13,3 @@ function getEnvironmentVariable(name) {
|
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
exports.getEnvironmentVariable = getEnvironmentVariable;
|
package/dist/utils/signals.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeSignals =
|
|
3
|
+
exports.mergeSignals = mergeSignals;
|
|
4
4
|
function mergeSignals(...signals) {
|
|
5
5
|
const nonZeroSignals = signals.filter((signal) => signal != null);
|
|
6
6
|
if (nonZeroSignals.length === 0)
|
|
@@ -19,4 +19,3 @@ function mergeSignals(...signals) {
|
|
|
19
19
|
}
|
|
20
20
|
return controller.signal;
|
|
21
21
|
}
|
|
22
|
-
exports.mergeSignals = mergeSignals;
|
package/dist/utils/sse.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BytesLineDecoder = BytesLineDecoder;
|
|
4
|
+
exports.SSEDecoder = SSEDecoder;
|
|
4
5
|
const CR = "\r".charCodeAt(0);
|
|
5
6
|
const LF = "\n".charCodeAt(0);
|
|
6
7
|
const NULL = "\0".charCodeAt(0);
|
|
@@ -77,7 +78,6 @@ function BytesLineDecoder() {
|
|
|
77
78
|
},
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
|
-
exports.BytesLineDecoder = BytesLineDecoder;
|
|
81
81
|
function SSEDecoder() {
|
|
82
82
|
let event = "";
|
|
83
83
|
let data = [];
|
|
@@ -123,7 +123,7 @@ function SSEDecoder() {
|
|
|
123
123
|
lastEventId = decoder.decode(value);
|
|
124
124
|
}
|
|
125
125
|
else if (fieldName === "retry") {
|
|
126
|
-
const retryNum = Number.parseInt(decoder.decode(value));
|
|
126
|
+
const retryNum = Number.parseInt(decoder.decode(value), 10);
|
|
127
127
|
if (!Number.isNaN(retryNum))
|
|
128
128
|
retry = retryNum;
|
|
129
129
|
}
|
|
@@ -139,10 +139,9 @@ function SSEDecoder() {
|
|
|
139
139
|
},
|
|
140
140
|
});
|
|
141
141
|
}
|
|
142
|
-
exports.SSEDecoder = SSEDecoder;
|
|
143
142
|
function joinArrays(data) {
|
|
144
143
|
const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
|
|
145
|
-
|
|
144
|
+
const merged = new Uint8Array(totalLength);
|
|
146
145
|
let offset = 0;
|
|
147
146
|
for (const c of data) {
|
|
148
147
|
merged.set(c, offset);
|
package/dist/utils/sse.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export declare function BytesLineDecoder(): TransformStream<Uint8Array
|
|
1
|
+
export declare function BytesLineDecoder(): TransformStream<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
|
|
2
2
|
interface StreamPart {
|
|
3
3
|
id: string | undefined;
|
|
4
4
|
event: string;
|
|
5
5
|
data: unknown;
|
|
6
6
|
}
|
|
7
|
-
export declare function SSEDecoder(): TransformStream<Uint8Array
|
|
7
|
+
export declare function SSEDecoder(): TransformStream<Uint8Array<ArrayBufferLike>, StreamPart>;
|
|
8
8
|
export {};
|
package/dist/utils/sse.js
CHANGED
|
@@ -119,7 +119,7 @@ export function SSEDecoder() {
|
|
|
119
119
|
lastEventId = decoder.decode(value);
|
|
120
120
|
}
|
|
121
121
|
else if (fieldName === "retry") {
|
|
122
|
-
const retryNum = Number.parseInt(decoder.decode(value));
|
|
122
|
+
const retryNum = Number.parseInt(decoder.decode(value), 10);
|
|
123
123
|
if (!Number.isNaN(retryNum))
|
|
124
124
|
retry = retryNum;
|
|
125
125
|
}
|
|
@@ -137,7 +137,7 @@ export function SSEDecoder() {
|
|
|
137
137
|
}
|
|
138
138
|
function joinArrays(data) {
|
|
139
139
|
const totalLength = data.reduce((acc, curr) => acc + curr.length, 0);
|
|
140
|
-
|
|
140
|
+
const merged = new Uint8Array(totalLength);
|
|
141
141
|
let offset = 0;
|
|
142
142
|
for (const c of data) {
|
|
143
143
|
merged.set(c, offset);
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.90",
|
|
4
4
|
"description": "Client library for interacting with the LangGraph API",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"packageManager": "yarn@1.22.19",
|
|
7
6
|
"scripts": {
|
|
8
7
|
"clean": "rm -rf dist/ dist-cjs/",
|
|
9
|
-
"build": "yarn
|
|
8
|
+
"build": "yarn turbo:command build:internal --filter=@langchain/langgraph-sdk",
|
|
9
|
+
"build:internal": "yarn clean && yarn lc_build --create-entrypoints --pre --tree-shaking",
|
|
10
10
|
"prepack": "yarn run build",
|
|
11
|
+
"format:check": "prettier --check src",
|
|
11
12
|
"format": "prettier --write src",
|
|
12
|
-
"lint": "
|
|
13
|
-
"
|
|
13
|
+
"lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js,.jsx,.tsx src/",
|
|
14
|
+
"lint": "yarn lint:eslint",
|
|
15
|
+
"lint:fix": "yarn lint:eslint --fix",
|
|
16
|
+
"test": "vitest run",
|
|
14
17
|
"typedoc": "typedoc && typedoc src/react/index.ts --out docs/react --options typedoc.react.json && typedoc src/auth/index.ts --out docs/auth --options typedoc.auth.json"
|
|
15
18
|
},
|
|
16
19
|
"main": "index.js",
|
|
@@ -22,41 +25,41 @@
|
|
|
22
25
|
"uuid": "^9.0.0"
|
|
23
26
|
},
|
|
24
27
|
"devDependencies": {
|
|
25
|
-
"@langchain/langgraph-api": "~0.0.41",
|
|
26
28
|
"@langchain/core": "^0.3.61",
|
|
27
|
-
"@langchain/langgraph": "^0.3.5",
|
|
28
29
|
"@langchain/scripts": "^0.1.4",
|
|
29
|
-
"@testing-library/dom": "^10.4.0",
|
|
30
|
-
"@testing-library/jest-dom": "^6.6.3",
|
|
31
|
-
"@testing-library/react": "^16.3.0",
|
|
32
|
-
"@testing-library/user-event": "^14.6.1",
|
|
33
30
|
"@tsconfig/recommended": "^1.0.2",
|
|
34
|
-
"@types/node": "^
|
|
31
|
+
"@types/node": "^18.15.11",
|
|
35
32
|
"@types/react": "^19.0.8",
|
|
36
33
|
"@types/react-dom": "^19.0.3",
|
|
37
34
|
"@types/uuid": "^9.0.1",
|
|
38
|
-
"@
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
37
|
+
"eslint": "^8.33.0",
|
|
38
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
39
|
+
"eslint-config-prettier": "^8.6.0",
|
|
40
|
+
"eslint-plugin-import": "^2.29.1",
|
|
41
|
+
"eslint-plugin-no-instanceof": "^1.0.1",
|
|
42
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
43
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
44
|
+
"prettier": "^2.8.3",
|
|
44
45
|
"react": "^19.0.0",
|
|
45
46
|
"react-dom": "^19.0.0",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"typescript": "^5.4.5",
|
|
49
|
-
"vitest": "^3.1.3"
|
|
47
|
+
"typescript": "^4.9.5 || ^5.4.5",
|
|
48
|
+
"vitest": "^3.1.2"
|
|
50
49
|
},
|
|
51
50
|
"peerDependencies": {
|
|
52
51
|
"@langchain/core": ">=0.2.31 <0.4.0",
|
|
53
|
-
"react": "^18 || ^19"
|
|
52
|
+
"react": "^18 || ^19",
|
|
53
|
+
"react-dom": "^18 || ^19"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
|
+
"@langchain/core": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
56
59
|
"react": {
|
|
57
60
|
"optional": true
|
|
58
61
|
},
|
|
59
|
-
"
|
|
62
|
+
"react-dom": {
|
|
60
63
|
"optional": true
|
|
61
64
|
}
|
|
62
65
|
},
|