The open-source agent harness - the runtime layer that turns an LLM into a working agent.
Refresh generated chat titles during streaming
debajyoti-truefoundry52c800851bd8
diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsxindex 75656a893..bb9851a12 100644--- a/packages/frontend/src/App.tsx+++ b/packages/frontend/src/App.tsx@@ -1,7 +1,7 @@-import { AssistantRuntimeProvider } from '@assistant-ui/react';+import { AssistantRuntimeProvider, useAui, useAuiState } from '@assistant-ui/react';import { ErrorToasterProvider, SlotsProvider, Thread } from '@truefoundry/agent-ui-sdk';import { useTrueFoundryAgentRuntime, type AgentSpec } from '@truefoundry/assistant-ui-runtime';-import { useEffect, useMemo, useState } from 'react';+import { useEffect, useMemo, useRef, useState } from 'react';import { ThemeProvider } from 'tfy-web-components/components/theme/useTheme';import { AgentSessionClient } from 'truefoundry-gateway-sdk/agents';import { PrivateAgentSessionClient } from 'truefoundry-gateway-sdk/agents/private';@@ -31,6 +31,25 @@ const slotOverrides = {ComposerSendButton: () => null,};+/**+ * The backend generates the session title once the first turn streams. Reload+ * the thread list when streaming starts and ends so the sidebar and header+ * (both read from `threads.threadItems`) pick up the new title.+ */+function ThreadTitleSync() {+ const aui = useAui();+ const isRunning = useAuiState(state => state.threads.main.isRunning);+ const mounted = useRef(false);+ useEffect(() => {+ if (!mounted.current) {+ mounted.current = true;+ return;+ }+ void aui.threads().reload();+ }, [aui, isRunning]);+ return null;+}+function ChatApp({defaultAgentSpec,capabilities,@@ -54,6 +73,7 @@ function ChatApp({<ThemeProvider theme="dark"><SlotsProvider theme="dark" overrides={slotOverrides}><ErrorToasterProvider>+ <ThreadTitleSync /><div className="app-shell">{sidebarOpen ? (<aside className="app-sidebar">diff --git a/packages/frontend/src/ThreadHeader.tsx b/packages/frontend/src/ThreadHeader.tsxindex 956a5e7fb..2d92e15b0 100644--- a/packages/frontend/src/ThreadHeader.tsx+++ b/packages/frontend/src/ThreadHeader.tsx@@ -10,7 +10,12 @@ interface Props {export function ThreadHeader({ sidebarCollapsed, onExpandSidebar }: Props) {const mainThreadId = useAuiState(state => state.threads.mainThreadId);const threadItems = useAuiState(state => state.threads.threadItems);- const rawTitle = threadItems.find(item => item.id === mainThreadId)?.title?.trim();+ // A thread started locally keeps its local id as mainThreadId, while the+ // reloaded backend list carries the title under the remote id. Follow the+ // remoteId link so the header picks up the backend-generated title.+ const mainItem = threadItems.find(item => item.id === mainThreadId);+ const listItem = threadItems.find(item => item.id === mainItem?.remoteId);+ const rawTitle = (listItem?.title ?? mainItem?.title)?.trim();const title = rawTitle && rawTitle.length > 0 ? rawTitle : 'New Chat';return (diff --git a/packages/frontend/src/ThreadSidebar.tsx b/packages/frontend/src/ThreadSidebar.tsxindex bf91130a9..3a28f1f30 100644--- a/packages/frontend/src/ThreadSidebar.tsx+++ b/packages/frontend/src/ThreadSidebar.tsx@@ -56,6 +56,9 @@ export function ThreadSidebar() {}, [aui, hasMore, isLoadingMore]);const itemsById = new Map(threadItems.map(item => [item.id, item]));+ // Rows are keyed by remote id after a list reload, but a locally started+ // thread keeps a local mainThreadId; compare against its remoteId too.+ const mainRemoteId = itemsById.get(mainThreadId)?.remoteId;return (<div className="sidebar-shell">@@ -83,13 +86,14 @@ export function ThreadSidebar() {const item = itemsById.get(id);const title = item?.title ?? 'New Chat';const time = relativeTime(item?.lastMessageAt, nowMs);+ const isActive = id === mainThreadId || id === mainRemoteId;return (<buttonkey={id}type="button"className="sidebar-row"- data-active={id === mainThreadId || undefined}- aria-current={id === mainThreadId ? 'page' : undefined}+ data-active={isActive || undefined}+ aria-current={isActive ? 'page' : undefined}title={title}onClick={() => {aui.threads().switchToThread(id);