@axiom-lattice/react-sdk 2.1.56 → 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.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +89 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
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);
|
|
@@ -1804,7 +1805,13 @@ function AgentThreadProvider({
|
|
|
1804
1805
|
}
|
|
1805
1806
|
let interrupt;
|
|
1806
1807
|
if (chunk.type === "interrupt") {
|
|
1807
|
-
|
|
1808
|
+
const rawChunk = chunk;
|
|
1809
|
+
interrupt = {
|
|
1810
|
+
type: "interrupt",
|
|
1811
|
+
id: rawChunk.id,
|
|
1812
|
+
role: "ai",
|
|
1813
|
+
value: rawChunk.data?.content || rawChunk.data
|
|
1814
|
+
};
|
|
1808
1815
|
} else if (anyChunk.type === "queue_status") {
|
|
1809
1816
|
return;
|
|
1810
1817
|
} else {
|
|
@@ -1828,7 +1835,8 @@ function AgentThreadProvider({
|
|
|
1828
1835
|
...prev,
|
|
1829
1836
|
todos: todos || prev.todos,
|
|
1830
1837
|
messages: updatedMessages,
|
|
1831
|
-
isLoading: true
|
|
1838
|
+
isLoading: true,
|
|
1839
|
+
interrupts: interrupt ? [interrupt] : void 0
|
|
1832
1840
|
}));
|
|
1833
1841
|
},
|
|
1834
1842
|
[]
|
|
@@ -1879,19 +1887,61 @@ function AgentThreadProvider({
|
|
|
1879
1887
|
}
|
|
1880
1888
|
try {
|
|
1881
1889
|
if (options.streaming !== false && streaming !== false) {
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
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);
|
|
1895
1945
|
}
|
|
1896
1946
|
} else {
|
|
1897
1947
|
const response = await client.chat.send({
|
|
@@ -1927,16 +1977,20 @@ function AgentThreadProvider({
|
|
|
1927
1977
|
]
|
|
1928
1978
|
);
|
|
1929
1979
|
const stopStreaming = (0, import_react7.useCallback)(() => {
|
|
1980
|
+
sendMessageStreamsRef.current.forEach((stopFn) => {
|
|
1981
|
+
stopFn();
|
|
1982
|
+
});
|
|
1983
|
+
sendMessageStreamsRef.current.clear();
|
|
1930
1984
|
if (stopStreamingRef.current) {
|
|
1931
1985
|
stopStreamingRef.current();
|
|
1932
1986
|
stopStreamingRef.current = null;
|
|
1933
|
-
const currentMessages = chunkMessageMerger.current.getMessages();
|
|
1934
|
-
setState((prev) => ({
|
|
1935
|
-
...prev,
|
|
1936
|
-
messages: currentMessages,
|
|
1937
|
-
isLoading: false
|
|
1938
|
-
}));
|
|
1939
1987
|
}
|
|
1988
|
+
const currentMessages = chunkMessageMerger.current.getMessages();
|
|
1989
|
+
setState((prev) => ({
|
|
1990
|
+
...prev,
|
|
1991
|
+
messages: currentMessages,
|
|
1992
|
+
isLoading: false
|
|
1993
|
+
}));
|
|
1940
1994
|
}, []);
|
|
1941
1995
|
const resumeStream = (0, import_react7.useCallback)(
|
|
1942
1996
|
(messageId, onMessageChunk) => {
|
|
@@ -2014,6 +2068,10 @@ function AgentThreadProvider({
|
|
|
2014
2068
|
if (!threadId) {
|
|
2015
2069
|
return;
|
|
2016
2070
|
}
|
|
2071
|
+
sendMessageStreamsRef.current.forEach((stopFn, messageId) => {
|
|
2072
|
+
stopFn();
|
|
2073
|
+
});
|
|
2074
|
+
sendMessageStreamsRef.current.clear();
|
|
2017
2075
|
if (stopStreamingRef.current) {
|
|
2018
2076
|
stopStreamingRef.current();
|
|
2019
2077
|
stopStreamingRef.current = null;
|
|
@@ -2055,7 +2113,7 @@ function AgentThreadProvider({
|
|
|
2055
2113
|
...needUpdateFields,
|
|
2056
2114
|
isLoading: false
|
|
2057
2115
|
}));
|
|
2058
|
-
if (options.enableResumeStream && needUpdateFields.messages.length > 0) {
|
|
2116
|
+
if (options.enableResumeStream && needUpdateFields.messages.length > 0 && sendMessageStreamsRef.current.size === 0) {
|
|
2059
2117
|
const lastMessage = needUpdateFields.messages[needUpdateFields.messages.length - 1];
|
|
2060
2118
|
let lastMessageIsRemoved = false;
|
|
2061
2119
|
resumeStream(lastMessage.id, (chunk) => {
|
|
@@ -2104,6 +2162,10 @@ function AgentThreadProvider({
|
|
|
2104
2162
|
clearMessages();
|
|
2105
2163
|
}
|
|
2106
2164
|
return () => {
|
|
2165
|
+
sendMessageStreamsRef.current.forEach((stopFn) => {
|
|
2166
|
+
stopFn();
|
|
2167
|
+
});
|
|
2168
|
+
sendMessageStreamsRef.current.clear();
|
|
2107
2169
|
if (stopStreamingRef.current) {
|
|
2108
2170
|
stopStreamingRef.current();
|
|
2109
2171
|
stopStreamingRef.current = null;
|
|
@@ -5826,11 +5888,15 @@ var MarkdownErrorBoundary = class extends import_react23.default.Component {
|
|
|
5826
5888
|
};
|
|
5827
5889
|
var SafeXMarkdown = import_react23.default.memo(({ content, components, className }) => {
|
|
5828
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 ?? "");
|
|
5829
5895
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
|
5830
5896
|
import_x_markdown.default,
|
|
5831
5897
|
{
|
|
5832
5898
|
components,
|
|
5833
|
-
content:
|
|
5899
|
+
content: safeContent,
|
|
5834
5900
|
paragraphTag: "div"
|
|
5835
5901
|
}
|
|
5836
5902
|
) });
|