@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.mjs CHANGED
@@ -1668,6 +1668,7 @@ function AgentThreadProvider({
1668
1668
  }));
1669
1669
  }, [clientAssistantId, tenantId, threadId]);
1670
1670
  const stopStreamingRef = useRef5(null);
1671
+ const sendMessageStreamsRef = useRef5(/* @__PURE__ */ new Map());
1671
1672
  const chunkMessageMerger = useRef5(createSimpleMessageMerger2());
1672
1673
  const lastAgentStateCreatedAtRef = useRef5(null);
1673
1674
  const messageCountRef = useRef5(0);
@@ -1735,7 +1736,13 @@ function AgentThreadProvider({
1735
1736
  }
1736
1737
  let interrupt;
1737
1738
  if (chunk.type === "interrupt") {
1738
- interrupt = chunk;
1739
+ const rawChunk = chunk;
1740
+ interrupt = {
1741
+ type: "interrupt",
1742
+ id: rawChunk.id,
1743
+ role: "ai",
1744
+ value: rawChunk.data?.content || rawChunk.data
1745
+ };
1739
1746
  } else if (anyChunk.type === "queue_status") {
1740
1747
  return;
1741
1748
  } else {
@@ -1759,7 +1766,8 @@ function AgentThreadProvider({
1759
1766
  ...prev,
1760
1767
  todos: todos || prev.todos,
1761
1768
  messages: updatedMessages,
1762
- isLoading: true
1769
+ isLoading: true,
1770
+ interrupts: interrupt ? [interrupt] : void 0
1763
1771
  }));
1764
1772
  },
1765
1773
  []
@@ -1810,19 +1818,61 @@ function AgentThreadProvider({
1810
1818
  }
1811
1819
  try {
1812
1820
  if (options.streaming !== false && streaming !== false) {
1813
- client.chat.stream(
1814
- {
1815
- threadId,
1816
- messages: [userMessage],
1817
- command,
1818
- custom_run_config: customRunConfig,
1819
- ...rest
1820
- },
1821
- () => {
1822
- }
1823
- );
1824
- if (!stopStreamingRef.current) {
1825
- loadMessages();
1821
+ if (stopStreamingRef.current) {
1822
+ client.chat.stream(
1823
+ {
1824
+ threadId,
1825
+ messages: [userMessage],
1826
+ command,
1827
+ custom_run_config: customRunConfig,
1828
+ ...rest
1829
+ },
1830
+ () => {
1831
+ },
1832
+ // Empty handler - resumeStream will handle chunks
1833
+ async () => {
1834
+ if (options.enableReturnStateWhenStreamCompleted) {
1835
+ await fetchAndUpdateAgentState(threadId);
1836
+ }
1837
+ },
1838
+ (error) => {
1839
+ setState((prev) => ({
1840
+ ...prev,
1841
+ isLoading: false,
1842
+ error
1843
+ }));
1844
+ }
1845
+ );
1846
+ } else {
1847
+ const stopStreaming2 = client.chat.stream(
1848
+ {
1849
+ threadId,
1850
+ messages: [userMessage],
1851
+ command,
1852
+ custom_run_config: customRunConfig,
1853
+ ...rest
1854
+ },
1855
+ (chunk) => handleStreamEvent(chunk),
1856
+ async () => {
1857
+ setState((prev) => ({
1858
+ ...prev,
1859
+ isLoading: false
1860
+ }));
1861
+ if (options.enableReturnStateWhenStreamCompleted) {
1862
+ await fetchAndUpdateAgentState(threadId);
1863
+ }
1864
+ sendMessageStreamsRef.current.delete(userMessage.id);
1865
+ },
1866
+ (error) => {
1867
+ setState((prev) => ({
1868
+ ...prev,
1869
+ isLoading: false,
1870
+ error
1871
+ }));
1872
+ sendMessageStreamsRef.current.delete(userMessage.id);
1873
+ }
1874
+ );
1875
+ sendMessageStreamsRef.current.set(userMessage.id, stopStreaming2);
1826
1876
  }
1827
1877
  } else {
1828
1878
  const response = await client.chat.send({
@@ -1858,16 +1908,20 @@ function AgentThreadProvider({
1858
1908
  ]
1859
1909
  );
1860
1910
  const stopStreaming = useCallback7(() => {
1911
+ sendMessageStreamsRef.current.forEach((stopFn) => {
1912
+ stopFn();
1913
+ });
1914
+ sendMessageStreamsRef.current.clear();
1861
1915
  if (stopStreamingRef.current) {
1862
1916
  stopStreamingRef.current();
1863
1917
  stopStreamingRef.current = null;
1864
- const currentMessages = chunkMessageMerger.current.getMessages();
1865
- setState((prev) => ({
1866
- ...prev,
1867
- messages: currentMessages,
1868
- isLoading: false
1869
- }));
1870
1918
  }
1919
+ const currentMessages = chunkMessageMerger.current.getMessages();
1920
+ setState((prev) => ({
1921
+ ...prev,
1922
+ messages: currentMessages,
1923
+ isLoading: false
1924
+ }));
1871
1925
  }, []);
1872
1926
  const resumeStream = useCallback7(
1873
1927
  (messageId, onMessageChunk) => {
@@ -1945,6 +1999,10 @@ function AgentThreadProvider({
1945
1999
  if (!threadId) {
1946
2000
  return;
1947
2001
  }
2002
+ sendMessageStreamsRef.current.forEach((stopFn, messageId) => {
2003
+ stopFn();
2004
+ });
2005
+ sendMessageStreamsRef.current.clear();
1948
2006
  if (stopStreamingRef.current) {
1949
2007
  stopStreamingRef.current();
1950
2008
  stopStreamingRef.current = null;
@@ -1986,7 +2044,7 @@ function AgentThreadProvider({
1986
2044
  ...needUpdateFields,
1987
2045
  isLoading: false
1988
2046
  }));
1989
- if (options.enableResumeStream && needUpdateFields.messages.length > 0) {
2047
+ if (options.enableResumeStream && needUpdateFields.messages.length > 0 && sendMessageStreamsRef.current.size === 0) {
1990
2048
  const lastMessage = needUpdateFields.messages[needUpdateFields.messages.length - 1];
1991
2049
  let lastMessageIsRemoved = false;
1992
2050
  resumeStream(lastMessage.id, (chunk) => {
@@ -2035,6 +2093,10 @@ function AgentThreadProvider({
2035
2093
  clearMessages();
2036
2094
  }
2037
2095
  return () => {
2096
+ sendMessageStreamsRef.current.forEach((stopFn) => {
2097
+ stopFn();
2098
+ });
2099
+ sendMessageStreamsRef.current.clear();
2038
2100
  if (stopStreamingRef.current) {
2039
2101
  stopStreamingRef.current();
2040
2102
  stopStreamingRef.current = null;
@@ -5777,11 +5839,15 @@ var MarkdownErrorBoundary = class extends React11.Component {
5777
5839
  };
5778
5840
  var SafeXMarkdown = React11.memo(({ content, components, className }) => {
5779
5841
  const deferredContent = useDeferredValue(content);
5842
+ if (typeof deferredContent !== "string") {
5843
+ console.warn("[MDResponse] Content is not a string:", typeof deferredContent, deferredContent);
5844
+ }
5845
+ const safeContent = typeof deferredContent === "string" ? deferredContent : String(deferredContent ?? "");
5780
5846
  return /* @__PURE__ */ jsx22("div", { className, children: /* @__PURE__ */ jsx22(
5781
5847
  XMarkdown,
5782
5848
  {
5783
5849
  components,
5784
- content: deferredContent,
5850
+ content: safeContent,
5785
5851
  paragraphTag: "div"
5786
5852
  }
5787
5853
  ) });