@axiom-lattice/react-sdk 2.1.57 → 2.1.58
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/index.js +80 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1737,6 +1737,7 @@ function AgentThreadProvider({
|
|
|
1737
1737
|
}));
|
|
1738
1738
|
}, [clientAssistantId, tenantId, threadId]);
|
|
1739
1739
|
const stopStreamingRef = (0, import_react7.useRef)(null);
|
|
1740
|
+
const sendMessageStreamsRef = (0, import_react7.useRef)(/* @__PURE__ */ new Map());
|
|
1740
1741
|
const chunkMessageMerger = (0, import_react7.useRef)((0, import_client_sdk3.createSimpleMessageMerger)());
|
|
1741
1742
|
const lastAgentStateCreatedAtRef = (0, import_react7.useRef)(null);
|
|
1742
1743
|
const messageCountRef = (0, import_react7.useRef)(0);
|
|
@@ -1886,19 +1887,61 @@ function AgentThreadProvider({
|
|
|
1886
1887
|
}
|
|
1887
1888
|
try {
|
|
1888
1889
|
if (options.streaming !== false && streaming !== false) {
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1890
|
+
if (stopStreamingRef.current) {
|
|
1891
|
+
client.chat.stream(
|
|
1892
|
+
{
|
|
1893
|
+
threadId,
|
|
1894
|
+
messages: [userMessage],
|
|
1895
|
+
command,
|
|
1896
|
+
custom_run_config: customRunConfig,
|
|
1897
|
+
...rest
|
|
1898
|
+
},
|
|
1899
|
+
() => {
|
|
1900
|
+
},
|
|
1901
|
+
// Empty handler - resumeStream will handle chunks
|
|
1902
|
+
async () => {
|
|
1903
|
+
if (options.enableReturnStateWhenStreamCompleted) {
|
|
1904
|
+
await fetchAndUpdateAgentState(threadId);
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
(error) => {
|
|
1908
|
+
setState((prev) => ({
|
|
1909
|
+
...prev,
|
|
1910
|
+
isLoading: false,
|
|
1911
|
+
error
|
|
1912
|
+
}));
|
|
1913
|
+
}
|
|
1914
|
+
);
|
|
1915
|
+
} else {
|
|
1916
|
+
const stopStreaming2 = client.chat.stream(
|
|
1917
|
+
{
|
|
1918
|
+
threadId,
|
|
1919
|
+
messages: [userMessage],
|
|
1920
|
+
command,
|
|
1921
|
+
custom_run_config: customRunConfig,
|
|
1922
|
+
...rest
|
|
1923
|
+
},
|
|
1924
|
+
(chunk) => handleStreamEvent(chunk),
|
|
1925
|
+
async () => {
|
|
1926
|
+
setState((prev) => ({
|
|
1927
|
+
...prev,
|
|
1928
|
+
isLoading: false
|
|
1929
|
+
}));
|
|
1930
|
+
if (options.enableReturnStateWhenStreamCompleted) {
|
|
1931
|
+
await fetchAndUpdateAgentState(threadId);
|
|
1932
|
+
}
|
|
1933
|
+
sendMessageStreamsRef.current.delete(userMessage.id);
|
|
1934
|
+
},
|
|
1935
|
+
(error) => {
|
|
1936
|
+
setState((prev) => ({
|
|
1937
|
+
...prev,
|
|
1938
|
+
isLoading: false,
|
|
1939
|
+
error
|
|
1940
|
+
}));
|
|
1941
|
+
sendMessageStreamsRef.current.delete(userMessage.id);
|
|
1942
|
+
}
|
|
1943
|
+
);
|
|
1944
|
+
sendMessageStreamsRef.current.set(userMessage.id, stopStreaming2);
|
|
1902
1945
|
}
|
|
1903
1946
|
} else {
|
|
1904
1947
|
const response = await client.chat.send({
|
|
@@ -1934,16 +1977,20 @@ function AgentThreadProvider({
|
|
|
1934
1977
|
]
|
|
1935
1978
|
);
|
|
1936
1979
|
const stopStreaming = (0, import_react7.useCallback)(() => {
|
|
1980
|
+
sendMessageStreamsRef.current.forEach((stopFn) => {
|
|
1981
|
+
stopFn();
|
|
1982
|
+
});
|
|
1983
|
+
sendMessageStreamsRef.current.clear();
|
|
1937
1984
|
if (stopStreamingRef.current) {
|
|
1938
1985
|
stopStreamingRef.current();
|
|
1939
1986
|
stopStreamingRef.current = null;
|
|
1940
|
-
const currentMessages = chunkMessageMerger.current.getMessages();
|
|
1941
|
-
setState((prev) => ({
|
|
1942
|
-
...prev,
|
|
1943
|
-
messages: currentMessages,
|
|
1944
|
-
isLoading: false
|
|
1945
|
-
}));
|
|
1946
1987
|
}
|
|
1988
|
+
const currentMessages = chunkMessageMerger.current.getMessages();
|
|
1989
|
+
setState((prev) => ({
|
|
1990
|
+
...prev,
|
|
1991
|
+
messages: currentMessages,
|
|
1992
|
+
isLoading: false
|
|
1993
|
+
}));
|
|
1947
1994
|
}, []);
|
|
1948
1995
|
const resumeStream = (0, import_react7.useCallback)(
|
|
1949
1996
|
(messageId, onMessageChunk) => {
|
|
@@ -2021,6 +2068,10 @@ function AgentThreadProvider({
|
|
|
2021
2068
|
if (!threadId) {
|
|
2022
2069
|
return;
|
|
2023
2070
|
}
|
|
2071
|
+
sendMessageStreamsRef.current.forEach((stopFn, messageId) => {
|
|
2072
|
+
stopFn();
|
|
2073
|
+
});
|
|
2074
|
+
sendMessageStreamsRef.current.clear();
|
|
2024
2075
|
if (stopStreamingRef.current) {
|
|
2025
2076
|
stopStreamingRef.current();
|
|
2026
2077
|
stopStreamingRef.current = null;
|
|
@@ -2062,7 +2113,7 @@ function AgentThreadProvider({
|
|
|
2062
2113
|
...needUpdateFields,
|
|
2063
2114
|
isLoading: false
|
|
2064
2115
|
}));
|
|
2065
|
-
if (options.enableResumeStream && needUpdateFields.messages.length > 0) {
|
|
2116
|
+
if (options.enableResumeStream && needUpdateFields.messages.length > 0 && sendMessageStreamsRef.current.size === 0) {
|
|
2066
2117
|
const lastMessage = needUpdateFields.messages[needUpdateFields.messages.length - 1];
|
|
2067
2118
|
let lastMessageIsRemoved = false;
|
|
2068
2119
|
resumeStream(lastMessage.id, (chunk) => {
|
|
@@ -2111,6 +2162,10 @@ function AgentThreadProvider({
|
|
|
2111
2162
|
clearMessages();
|
|
2112
2163
|
}
|
|
2113
2164
|
return () => {
|
|
2165
|
+
sendMessageStreamsRef.current.forEach((stopFn) => {
|
|
2166
|
+
stopFn();
|
|
2167
|
+
});
|
|
2168
|
+
sendMessageStreamsRef.current.clear();
|
|
2114
2169
|
if (stopStreamingRef.current) {
|
|
2115
2170
|
stopStreamingRef.current();
|
|
2116
2171
|
stopStreamingRef.current = null;
|
|
@@ -5833,11 +5888,15 @@ var MarkdownErrorBoundary = class extends import_react23.default.Component {
|
|
|
5833
5888
|
};
|
|
5834
5889
|
var SafeXMarkdown = import_react23.default.memo(({ content, components, className }) => {
|
|
5835
5890
|
const deferredContent = (0, import_react23.useDeferredValue)(content);
|
|
5891
|
+
if (typeof deferredContent !== "string") {
|
|
5892
|
+
console.warn("[MDResponse] Content is not a string:", typeof deferredContent, deferredContent);
|
|
5893
|
+
}
|
|
5894
|
+
const safeContent = typeof deferredContent === "string" ? deferredContent : String(deferredContent ?? "");
|
|
5836
5895
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
5837
5896
|
import_x_markdown.default,
|
|
5838
5897
|
{
|
|
5839
5898
|
components,
|
|
5840
|
-
content:
|
|
5899
|
+
content: safeContent,
|
|
5841
5900
|
paragraphTag: "div"
|
|
5842
5901
|
}
|
|
5843
5902
|
) });
|