Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/react-headless/src/hooks/useIsThreadStreaming.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useStore } from "zustand";
import { useChatStore } from "../store/ChatContext";

/**
* Whether `threadId` is currently streaming in the **background** — i.e. it has a
* run in flight while NOT being the active thread. Background streams are exactly
* the keys of {@link ChatStore.inFlightThreads} (the active thread lives in the
* flat store fields and is never here, and an entry is dropped the moment its run
* completes), so this is the direct signal for the sidebar loader.
*
* @category Hooks
*/
export function useIsThreadStreaming(threadId: string | null): boolean {
const store = useChatStore();
return useStore(store, (s) => threadId != null && threadId in s.inFlightThreads);
}
2 changes: 2 additions & 0 deletions packages/react-headless/src/hooks/useThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
type ThreadSlice = ThreadState & ThreadActions;
type ThreadListSlice = ThreadListState & ThreadListActions;

// The active thread lives directly in the store's flat fields.
const threadSelector = (s: ChatStore): ThreadSlice => ({
messages: s.messages,
isRunning: s.isRunning,
Expand All @@ -32,6 +33,7 @@ const threadListSelector = (s: ChatStore): ThreadListSlice => ({
threadListError: s.threadListError,
selectedThreadId: s.selectedThreadId,
hasMoreThreads: s.hasMoreThreads,
isCreatingThread: s.isCreatingThread,
loadThreads: s.loadThreads,
loadMoreThreads: s.loadMoreThreads,
switchToNewThread: s.switchToNewThread,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type { ArtifactListFilter } from "./hooks/useArtifactList";
export { useArtifactRenderer } from "./hooks/useArtifactRenderer";
export { useDetailedView } from "./hooks/useDetailedView";
export { useDetailedViewPortalTarget } from "./hooks/useDetailedViewPortalTarget";
export { useIsThreadStreaming } from "./hooks/useIsThreadStreaming";
export { MessageContext, MessageProvider, useMessage } from "./hooks/useMessage";
export { useThread, useThreadList } from "./hooks/useThread";
export { useToolActivities } from "./hooks/useToolActivities";
Expand Down Expand Up @@ -78,6 +79,7 @@ export type {
ThreadListActions,
ThreadListState,
ThreadState,
ThreadStateEntry,
} from "./store/types";

export type {
Expand Down
Loading
Loading