@agent-native/core 0.12.40 → 0.13.0

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.
Files changed (47) hide show
  1. package/dist/agent/run-manager.d.ts +5 -1
  2. package/dist/agent/run-manager.d.ts.map +1 -1
  3. package/dist/agent/run-manager.js +48 -2
  4. package/dist/agent/run-manager.js.map +1 -1
  5. package/dist/agent/run-store.d.ts +8 -0
  6. package/dist/agent/run-store.d.ts.map +1 -1
  7. package/dist/agent/run-store.js +36 -5
  8. package/dist/agent/run-store.js.map +1 -1
  9. package/dist/client/AssistantChat.d.ts.map +1 -1
  10. package/dist/client/AssistantChat.js +42 -3
  11. package/dist/client/AssistantChat.js.map +1 -1
  12. package/dist/client/ConnectBuilderCard.js +1 -1
  13. package/dist/client/ConnectBuilderCard.js.map +1 -1
  14. package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
  15. package/dist/client/MultiTabAssistantChat.js +27 -16
  16. package/dist/client/MultiTabAssistantChat.js.map +1 -1
  17. package/dist/client/RunStuckBanner.d.ts +35 -0
  18. package/dist/client/RunStuckBanner.d.ts.map +1 -0
  19. package/dist/client/RunStuckBanner.js +66 -0
  20. package/dist/client/RunStuckBanner.js.map +1 -0
  21. package/dist/client/components/CodeRequiredDialog.js +1 -1
  22. package/dist/client/components/CodeRequiredDialog.js.map +1 -1
  23. package/dist/client/composer/ComposerPlusMenu.d.ts +3 -3
  24. package/dist/client/composer/ComposerPlusMenu.js +3 -3
  25. package/dist/client/composer/ComposerPlusMenu.js.map +1 -1
  26. package/dist/client/composer/TiptapComposer.js +1 -1
  27. package/dist/client/composer/TiptapComposer.js.map +1 -1
  28. package/dist/client/extensions/ExtensionsSidebarSection.js +1 -1
  29. package/dist/client/extensions/ExtensionsSidebarSection.js.map +1 -1
  30. package/dist/client/index.d.ts +2 -0
  31. package/dist/client/index.d.ts.map +1 -1
  32. package/dist/client/index.js +2 -0
  33. package/dist/client/index.js.map +1 -1
  34. package/dist/client/resources/ResourcesPanel.js +2 -2
  35. package/dist/client/resources/ResourcesPanel.js.map +1 -1
  36. package/dist/client/use-chat-threads.d.ts +7 -0
  37. package/dist/client/use-chat-threads.d.ts.map +1 -1
  38. package/dist/client/use-chat-threads.js +91 -43
  39. package/dist/client/use-chat-threads.js.map +1 -1
  40. package/dist/client/use-run-stuck-detection.d.ts +47 -0
  41. package/dist/client/use-run-stuck-detection.d.ts.map +1 -0
  42. package/dist/client/use-run-stuck-detection.js +102 -0
  43. package/dist/client/use-run-stuck-detection.js.map +1 -0
  44. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  45. package/dist/server/agent-chat-plugin.js +2 -0
  46. package/dist/server/agent-chat-plugin.js.map +1 -1
  47. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import React, { useState, useRef, useEffect, useCallback, useMemo, forwardRef, useImperativeHandle, } from "react";
2
+ import React, { useState, useRef, useEffect, useLayoutEffect, useCallback, useMemo, forwardRef, useImperativeHandle, } from "react";
3
3
  import { AssistantRuntimeProvider, useLocalRuntime, useThreadRuntime, useThread, useAui, useComposer, useMessageRuntime, ThreadPrimitive, ComposerPrimitive, MessagePrimitive, } from "@assistant-ui/react";
4
4
  import { SimpleImageAttachmentAdapter, CompositeAttachmentAdapter, } from "@assistant-ui/react";
5
5
  import { MarkdownTextPrimitive } from "@assistant-ui/react-markdown";
@@ -18,6 +18,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel,
18
18
  import { IframeEmbed, parseEmbedBody } from "./IframeEmbed.js";
19
19
  import { useDevMode } from "./use-dev-mode.js";
20
20
  import { agentNativePath } from "./api-path.js";
21
+ import { getThreadCacheKey } from "./use-chat-threads.js";
21
22
  import { BUILDER_SPACE_SETTINGS_URL } from "./error-format.js";
22
23
  import { ThumbsFeedback } from "./observability/ThumbsFeedback.js";
23
24
  import { TiptapComposer, } from "./composer/TiptapComposer.js";
@@ -1491,7 +1492,22 @@ const AssistantChatInner = forwardRef(function AssistantChatInner({ emptyStateTe
1491
1492
  }, [isRunning, tabId, threadId]);
1492
1493
  // ─── Chat persistence ──────────────────────────────────────────────
1493
1494
  const hasRestoredRef = useRef(false);
1494
- const [isRestoring, setIsRestoring] = useState(!!threadId && !isNewThread);
1495
+ // Cached thread data from a prior session, read synchronously so existing
1496
+ // chats can paint their messages on first commit instead of after the server
1497
+ // round-trip. The server fetch still runs to refresh with the latest.
1498
+ const [cachedThreadData] = useState(() => {
1499
+ if (typeof window === "undefined")
1500
+ return null;
1501
+ if (!threadId || isNewThread)
1502
+ return null;
1503
+ try {
1504
+ return localStorage.getItem(getThreadCacheKey(threadId));
1505
+ }
1506
+ catch {
1507
+ return null;
1508
+ }
1509
+ });
1510
+ const [isRestoring, setIsRestoring] = useState(!!threadId && !isNewThread && !cachedThreadData);
1495
1511
  const onSaveThreadRef = useRef(onSaveThread);
1496
1512
  onSaveThreadRef.current = onSaveThread;
1497
1513
  const onGenerateTitleRef = useRef(onGenerateTitle);
@@ -1692,6 +1708,23 @@ const AssistantChatInner = forwardRef(function AssistantChatInner({ emptyStateTe
1692
1708
  return false;
1693
1709
  }
1694
1710
  }, [apiUrl, refreshThreadFromServer, startReconnectToRun, threadId]);
1711
+ // Hydrate from the localStorage cache synchronously so the message bubbles
1712
+ // paint on the first commit instead of after the server round-trip. The
1713
+ // server fetch below still runs to refresh with the latest content.
1714
+ const hydratedFromCacheRef = useRef(false);
1715
+ useLayoutEffect(() => {
1716
+ if (hydratedFromCacheRef.current)
1717
+ return;
1718
+ if (!cachedThreadData)
1719
+ return;
1720
+ hydratedFromCacheRef.current = true;
1721
+ try {
1722
+ importThreadData(cachedThreadData, { markTitleGenerated: true });
1723
+ }
1724
+ catch {
1725
+ // Corrupt cache entry — ignore and let the server fetch repopulate.
1726
+ }
1727
+ }, [cachedThreadData, importThreadData]);
1695
1728
  // Restore messages from server on mount (when threadId is set)
1696
1729
  useEffect(() => {
1697
1730
  if (hasRestoredRef.current)
@@ -1706,7 +1739,12 @@ const AssistantChatInner = forwardRef(function AssistantChatInner({ emptyStateTe
1706
1739
  return;
1707
1740
  const data = await res.json();
1708
1741
  if (data.threadData) {
1709
- importThreadData(data.threadData, { markTitleGenerated: true });
1742
+ // Skip the re-import if the server data matches what we already
1743
+ // hydrated from cache — avoids a second runtime.import that would
1744
+ // briefly flicker the message list.
1745
+ if (data.threadData !== cachedThreadData) {
1746
+ importThreadData(data.threadData, { markTitleGenerated: true });
1747
+ }
1710
1748
  }
1711
1749
  // Also skip title generation if thread already has a title
1712
1750
  if (data.title) {
@@ -1746,6 +1784,7 @@ const AssistantChatInner = forwardRef(function AssistantChatInner({ emptyStateTe
1746
1784
  threadRuntime,
1747
1785
  importThreadData,
1748
1786
  reconnectActiveRunForThread,
1787
+ cachedThreadData,
1749
1788
  ]);
1750
1789
  // If assistant-ui stops the local runtime while the background server run is
1751
1790
  // still alive, immediately switch into the same reconnect path used after a