The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(conversations): restore missing turn sources in chat footer
Steven Enamakel14f9f99d774e
diff --git a/app/src/features/conversations/components/aui/ChatSources.tsx b/app/src/features/conversations/components/aui/ChatSources.tsxnew file mode 100644index 0000000000..d94d1d86cc--- /dev/null+++ b/app/src/features/conversations/components/aui/ChatSources.tsx@@ -0,0 +1,44 @@+/**+ * The web sources a turn visited, as one collapsed disclosure under its answer.+ *+ * The sources arrive as assistant-ui `source` parts, emitted by `assistantParts`+ * (`providers/assistantUiMessages.ts`) through `extractAgentSources`, which is+ * the one place a model-supplied URL is admitted (http(s) only) — the `url` is a+ * raw tool-call argument and so prompt-injection-influenceable. `Thread` groups+ * the run of source parts and hands them here through its `SourceGroup` slot.+ *+ * Collapsed by default: the answer stays the top of the turn.+ */+import type { SourceUrlPart } from '../../../../components/assistant-ui/thread';+import { Sources, SourcesContent, SourcesTrigger } from '../../../../components/ai-elements';+import { useT } from '../../../../lib/i18n/I18nContext';+import { AgentSourceRow } from '../AgentSourceRow';++export function ChatSources({ sources }: { sources: readonly SourceUrlPart[] }) {+ const { t } = useT();+ if (sources.length === 0) return null;++ return (+ <Sources asChild className="mb-0 text-content-muted">+ <section data-testid="turn-sources">+ <SourcesTrigger+ count={sources.length}+ className="text-content-muted hover:text-content-secondary text-xs transition-colors">+ {t('conversations.agentTaskInsights.sourcesHeading')} ({sources.length})+ </SourcesTrigger>+ <SourcesContent className="mt-1 w-full gap-0">+ <ul className="space-y-0.5">+ {sources.map(source => (+ <AgentSourceRow+ key={source.id}+ source={{ id: source.id, url: source.url, title: source.title ?? source.url }}+ />+ ))}+ </ul>+ </SourcesContent>+ </section>+ </Sources>+ );+}++export default ChatSources;diff --git a/app/src/features/conversations/components/aui/TurnFooter.test.tsx b/app/src/features/conversations/components/aui/TurnFooter.test.tsxdeleted file mode 100644index 56c562f76c..0000000000--- a/app/src/features/conversations/components/aui/TurnFooter.test.tsx+++ /dev/null@@ -1,101 +0,0 @@-import {- AssistantRuntimeProvider,- type ThreadMessageLike,- useExternalStoreRuntime,-} from '@assistant-ui/react';-import { fireEvent, render, screen } from '@testing-library/react';-import { describe, expect, it, vi } from 'vitest';--import { Thread } from '../../../../components/assistant-ui/thread';-import type { TurnProcessTrail } from '../../../../providers/assistantUiMessages';-import { TurnFooter } from './TurnFooter';-import { TurnFooterHost } from './turnFooterHost';--const trail = (over: Partial<TurnProcessTrail> = {}): TurnProcessTrail => ({- steps: 8,- tools: 2,- timeline: [],- transcript: [],- ...over,-});--function mount(- metadata: Record<string, unknown> | undefined,- onOpenTurnProcess?: (t: TurnProcessTrail) => void-) {- const messages: ThreadMessageLike[] = [- { role: 'user', content: [{ type: 'text', text: 'hello' }] },- {- role: 'assistant',- content: [{ type: 'text', text: 'the answer' }],- ...(metadata ? { metadata: { custom: metadata } } : {}),- },- ];- function Harness() {- const runtime = useExternalStoreRuntime({- messages,- isRunning: false,- convertMessage: (m: ThreadMessageLike) => m,- onNew: async () => {},- });- return (- <AssistantRuntimeProvider runtime={runtime}>- <TurnFooterHost onOpenTurnProcess={onOpenTurnProcess}>- <Thread components={{ TurnFooter }} />- </TurnFooterHost>- </AssistantRuntimeProvider>- );- }- return render(<Harness />);-}--describe('TurnFooter', () => {- it('summarises the turn and opens the rail on that turn’s own trail', () => {- const open = vi.fn();- mount({ processTrail: trail() }, open);-- const footer = screen.getByTestId('turn-process-footer');- expect(footer.textContent).toBe('8 steps · 2 tools');-- fireEvent.click(footer);- // The trail travels with the click: the host needs no second lookup, and- // cannot show a different turn's trail by mistake.- expect(open).toHaveBeenCalledWith(expect.objectContaining({ steps: 8, tools: 2 }));- });-- it('drops the tool clause for a turn that called none', () => {- mount({ processTrail: trail({ steps: 3, tools: 0 }) }, vi.fn());- expect(screen.getByTestId('turn-process-footer').textContent).toBe('3 steps');- });-- it('reads as process, not answer: muted and no larger than 12px', () => {- // The whole point of moving reasoning and narration off this surface is- // that what is left reads as one class of thing. jsdom performs no layout,- // so the utilities are the only observable — but they are the same two the- // in-flight status line carries (`InferenceStatusLine`), which is the- // invariant worth pinning: one treatment, not three greys.- mount({ processTrail: trail() }, vi.fn());- const classes = screen.getByTestId('turn-process-footer').className.split(/\s+/);- expect(classes).toContain('text-content-muted');- expect(classes).toContain('text-xs');- });-- it('renders no door for a turn with no process behind it', () => {- mount({ processTrail: null }, vi.fn());- expect(screen.queryByTestId('turn-process-footer')).toBeNull();- });-- it('renders nothing when no host is mounted to open the rail', () => {- mount({ processTrail: trail() }, undefined);- expect(screen.queryByTestId('turn-process-footer')).toBeNull();- });-- it('survives a message this projection did not build', () => {- // The footer can be mounted on the kit's own runtime or a test harness,- // where `metadata.custom` is absent or shaped differently.- mount(undefined, vi.fn());- expect(screen.queryByTestId('turn-process-footer')).toBeNull();- mount({ processTrail: { steps: 'lots' } }, vi.fn());- expect(screen.queryByTestId('turn-process-footer')).toBeNull();- });-});diff --git a/app/src/features/conversations/components/aui/TurnFooter.tsx b/app/src/features/conversations/components/aui/TurnFooter.tsxdeleted file mode 100644index 23c3739f3e..0000000000--- a/app/src/features/conversations/components/aui/TurnFooter.tsx+++ /dev/null@@ -1,65 +0,0 @@-import { type AssistantState, useAuiState } from '@assistant-ui/react';--import { useT } from '../../../../lib/i18n/I18nContext';-import { useTurnFooterHost } from './turnFooterHost';-import { readProcessTrail } from './turnProcessTrail';--const selectMessageMetadata = (state: AssistantState) => state.message.metadata;--/**- * The settled turn's one-line process footer — `8 steps · 2 tools` — and the- * single door to the detail behind it.- *- * This is the other half of moving reasoning, narration and read-only tool- * detail off the main surface (`assistantParts`): the transcript keeps the- * answer, and everything explaining how the agent got there is one click away- * in the process rail rather than stacked above the answer.- *- * Deliberately quiet. It is process, not answer, so it takes the same- * treatment the rail already gives its own process text — `text-content-muted`- * at 12px — while the answer above it keeps full-contrast `text-foreground` at- * its normal size. Same meaning, same look, on both surfaces.- *- * Renders nothing when the turn recorded no process (a plain answer needs no- * door) or when no host is mounted to open the rail.- */-export function TurnFooter() {- const { t } = useT();- const host = useTurnFooterHost();- const trail = readProcessTrail(useAuiState(selectMessageMetadata));-- if (!host || !trail || trail.steps === 0) return null;-- // Existing, fully-translated keys rather than new ones: `I18nContext`'s- // English fallback is real, but `i18n/__tests__/coverage.test.ts` requires- // every locale to define every English key, so a new key is 14 translations- // this change is in no position to write. The cost is that- // `conversations.backgroundTasks.steps` has no singular form, so a one-step- // turn reads "1 steps". Worth a proper key next time someone touches i18n.- const stepLabel = t('conversations.backgroundTasks.steps').replace(- '{count}',- String(trail.steps)- );- const toolLabel =- trail.tools > 0- ? t(- trail.tools === 1- ? 'intelligence.agents.toolCountOne'- : 'intelligence.agents.toolCountOther'- ).replace('{count}', String(trail.tools))- : null;-- return (- <button- type="button"- data-testid="turn-process-footer"- data-analytics-id="chat-turn-process-open"- title={t('conversations.agentTaskInsights.viewProcessSource')}- onClick={() => host.open(trail)}- className="text-content-muted hover:text-content-secondary -ms-1 rounded px-1 text-xs transition-colors">- {toolLabel ? `${stepLabel} · ${toolLabel}` : stepLabel}- </button>- );-}--export default TurnFooter;diff --git a/app/src/features/conversations/components/aui/TurnSources.tsx b/app/src/features/conversations/components/aui/TurnSources.tsxdeleted file mode 100644index 66b9d8f906..0000000000--- a/app/src/features/conversations/components/aui/TurnSources.tsx+++ /dev/null@@ -1,69 +0,0 @@-/**- * The web sources a settled turn visited, listed inline under its answer.- *- * ## Why inline, when the rail already lists them- *- * The process rail (`AgentProcessSourcePanel`) has shown sources for a while,- * behind the `TurnFooter` click. This is not a second copy of something already- * on screen: on a settled turn the URL is not visible anywhere without a click.- * `web_fetch` implements no `display_detail`, so its tool card's collapsed- * trigger carries no URL chip (`AssistantUiToolCall` renders that chip only when- * `detail` is present), and the arguments live in the card's body inside a- * `Collapsible` whose `defaultOpen` is `running` — i.e. closed once the turn- * finishes. So "which pages did it read?" currently costs either one expand per- * fetch card or a trip to the rail.- *- * ## Why it reuses `extractAgentSources`- *- * Sources are not a model-declared message part — nothing in this app emits an- * assistant-ui `source` part. They are derived client-side from the `url`- * argument of the fetch/browse tools (`URL_SOURCE_TOOLS`). That argument is raw- * model output and therefore prompt-injection-influenceable, which is why- * `extractAgentSources` admits only `http(s)` URLs — a `javascript:` or `file:`- * value must never reach an `<a href>`. Deriving sources here through any other- * path would mean re-implementing that filter, so this calls the one extractor- * and renders the one shared row component.- *- * Collapsed by default, unlike the rail's copy: the answer stays the top of the- * turn. Same reasoning that put the process behind the footer to begin with.- */-import { type AssistantState, useAuiState } from '@assistant-ui/react';--import { Sources, SourcesContent, SourcesTrigger } from '../../../../components/ai-elements';-import { useT } from '../../../../lib/i18n/I18nContext';-import { extractAgentSources } from '../../../../utils/toolTimelineFormatting';-import { AgentSourceRow } from '../AgentSourceRow';-import { readProcessTrail } from './turnProcessTrail';--const selectMessageMetadata = (state: AssistantState) => state.message.metadata;--export function TurnSources() {- const { t } = useT();- const trail = readProcessTrail(useAuiState(selectMessageMetadata));- // `readProcessTrail` now validates `timeline` is an array, so this cannot be- // an unchecked read; a message with no trail at all yields `null` above.- const sources = trail ? extractAgentSources([...trail.timeline]) : [];-- if (sources.length === 0) return null;-- return (- <Sources asChild className="mb-0 text-content-muted">- <section data-testid="turn-sources">- <SourcesTrigger- count={sources.length}- className="text-content-muted hover:text-content-secondary text-xs transition-colors">- {t('conversations.agentTaskInsights.sourcesHeading')} ({sources.length})- </SourcesTrigger>- <SourcesContent className="mt-1 w-full gap-0">- <ul className="space-y-0.5">- {sources.map(source => (- <AgentSourceRow key={source.id} source={source} />- ))}- </ul>- </SourcesContent>- </section>- </Sources>- );-}--export default TurnSources;diff --git a/app/src/features/conversations/components/aui/turnFooterHost.tsx b/app/src/features/conversations/components/aui/turnFooterHost.tsxdeleted file mode 100644index b06abf60e1..0000000000--- a/app/src/features/conversations/components/aui/turnFooterHost.tsx+++ /dev/null@@ -1,46 +0,0 @@-import { createContext, type ReactNode, useContext, useMemo } from 'react';--import type { TurnProcessTrail } from '../../../../providers/assistantUiMessages';--export interface TurnFooterHostValue {- /** Opens the host's process rail on one settled turn's trail. */- open: (trail: TurnProcessTrail) => void;-}--/**- * The host that owns the process rail the turn footer opens.- *- * A context rather than a prop for the same reason- * {@link import('./subagentDrawerHost').SubagentDrawerHost} is one: the- * consumer is rendered by assistant-ui from *inside* the transcript, many- * layers below anything the host passes props to, while the panel belongs to- * `Conversations`.- *- * The trail travels with the click rather than being looked up by request id.- * `useOpenHumanExternalStore` has already paged the core transcript projection- * and split it per turn; the footer is handed those same array references on- * the message's own metadata, so opening the rail costs no second fetch and no- * second copy of the paging policy.- *- * `null` outside a provider, which is what every read-only mount wants: no- * host, no footer.- */-const TurnFooterHostContext = createContext<TurnFooterHostValue | null>(null);--export function TurnFooterHost({- onOpenTurnProcess,- children,-}: {- onOpenTurnProcess?: ((trail: TurnProcessTrail) => void) | undefined;- children: ReactNode;-}) {- const value = useMemo<TurnFooterHostValue | null>(- () => (onOpenTurnProcess ? { open: onOpenTurnProcess } : null),- [onOpenTurnProcess]- );- return <TurnFooterHostContext.Provider value={value}>{children}</TurnFooterHostContext.Provider>;-}--export function useTurnFooterHost(): TurnFooterHostValue | null {- return useContext(TurnFooterHostContext);-}diff --git a/app/src/features/conversations/components/aui/turnProcessTrail.ts b/app/src/features/conversations/components/aui/turnProcessTrail.tsdeleted file mode 100644index c034896765..0000000000--- a/app/src/features/conversations/components/aui/turnProcessTrail.ts+++ /dev/null@@ -1,34 +0,0 @@-/**- * Read the settled turn's `TurnProcessTrail` off assistant-ui's message- * metadata.- *- * Shared by the two consumers of that trail — `TurnFooter` (the `8 steps ·- * 2 tools` door) and `TurnSources` (the inline source list) — so both agree on- * what counts as a usable trail.- */-import type { TurnProcessTrail } from '../../../../providers/assistantUiMessages';--/**- * Narrow the runtime's untyped `message.metadata.custom` back to our own shape.- *- * `custom` is `unknown` by contract and either consumer can be mounted on a- * message this projection did not build (the kit's own demo runtime, a test- * harness), so this returns `null` rather than asserting.- *- * **Every field is checked, including the two arrays.** The previous version- * validated `steps` and `tools` and then cast, which asserted more than it had- * proven: a caller reading `trail.timeline` got a typed array that the- * validator had never looked at. `TurnSources` reads exactly that field, so the- * gap stopped being theoretical.- */-export function readProcessTrail(metadata: unknown): TurnProcessTrail | null {- if (typeof metadata !== 'object' || metadata === null) return null;- const custom = (metadata as { custom?: unknown }).custom;- if (typeof custom !== 'object' || custom === null) return null;- const trail = (custom as { processTrail?: unknown }).processTrail;- if (typeof trail !== 'object' || trail === null) return null;- const candidate = trail as Partial<TurnProcessTrail>;- if (typeof candidate.steps !== 'number' || typeof candidate.tools !== 'number') return null;- if (!Array.isArray(candidate.timeline) || !Array.isArray(candidate.transcript)) return null;- return candidate as TurnProcessTrail;-}