@langchain/langgraph-sdk 0.0.44 → 0.0.45
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/react/stream.cjs +22 -4
- package/dist/react/stream.js +23 -5
- package/package.json +1 -1
package/dist/react/stream.cjs
CHANGED
|
@@ -15,6 +15,14 @@ class StreamError extends Error {
|
|
|
15
15
|
return typeof error === "object" && error != null && "message" in error;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
function tryConvertToChunk(message) {
|
|
19
|
+
try {
|
|
20
|
+
return (0, messages_1.convertToChunk)(message);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
class MessageTupleManager {
|
|
19
27
|
constructor() {
|
|
20
28
|
Object.defineProperty(this, "chunks", {
|
|
@@ -33,12 +41,22 @@ class MessageTupleManager {
|
|
|
33
41
|
.slice(0, -"MessageChunk".length)
|
|
34
42
|
.toLowerCase();
|
|
35
43
|
}
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
44
|
+
const message = (0, messages_1.coerceMessageLikeToMessage)(serialized);
|
|
45
|
+
const chunk = tryConvertToChunk(message);
|
|
46
|
+
const id = (chunk ?? message).id;
|
|
47
|
+
if (!id) {
|
|
48
|
+
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
39
49
|
return null;
|
|
50
|
+
}
|
|
40
51
|
this.chunks[id] ??= {};
|
|
41
|
-
|
|
52
|
+
if (chunk) {
|
|
53
|
+
const prev = this.chunks[id].chunk;
|
|
54
|
+
this.chunks[id].chunk =
|
|
55
|
+
((0, messages_1.isBaseMessageChunk)(prev) ? prev : null)?.concat(chunk) ?? chunk;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.chunks[id].chunk = message;
|
|
59
|
+
}
|
|
42
60
|
return id;
|
|
43
61
|
}
|
|
44
62
|
clear() {
|
package/dist/react/stream.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use client";
|
|
3
3
|
import { Client } from "../client.js";
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
|
|
5
|
-
import { coerceMessageLikeToMessage, convertToChunk, } from "@langchain/core/messages";
|
|
5
|
+
import { coerceMessageLikeToMessage, convertToChunk, isBaseMessageChunk, } from "@langchain/core/messages";
|
|
6
6
|
class StreamError extends Error {
|
|
7
7
|
constructor(data) {
|
|
8
8
|
super(data.message);
|
|
@@ -12,6 +12,14 @@ class StreamError extends Error {
|
|
|
12
12
|
return typeof error === "object" && error != null && "message" in error;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
function tryConvertToChunk(message) {
|
|
16
|
+
try {
|
|
17
|
+
return convertToChunk(message);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
15
23
|
class MessageTupleManager {
|
|
16
24
|
constructor() {
|
|
17
25
|
Object.defineProperty(this, "chunks", {
|
|
@@ -30,12 +38,22 @@ class MessageTupleManager {
|
|
|
30
38
|
.slice(0, -"MessageChunk".length)
|
|
31
39
|
.toLowerCase();
|
|
32
40
|
}
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
41
|
+
const message = coerceMessageLikeToMessage(serialized);
|
|
42
|
+
const chunk = tryConvertToChunk(message);
|
|
43
|
+
const id = (chunk ?? message).id;
|
|
44
|
+
if (!id) {
|
|
45
|
+
console.warn("No message ID found for chunk, ignoring in state", serialized);
|
|
36
46
|
return null;
|
|
47
|
+
}
|
|
37
48
|
this.chunks[id] ??= {};
|
|
38
|
-
|
|
49
|
+
if (chunk) {
|
|
50
|
+
const prev = this.chunks[id].chunk;
|
|
51
|
+
this.chunks[id].chunk =
|
|
52
|
+
(isBaseMessageChunk(prev) ? prev : null)?.concat(chunk) ?? chunk;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.chunks[id].chunk = message;
|
|
56
|
+
}
|
|
39
57
|
return id;
|
|
40
58
|
}
|
|
41
59
|
clear() {
|