Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

chore: Add MCP auth session handling and UI updates (#947)

harshil-2096f5672f18a6ea
diff --git a/.changeset/mcp-auth-session-turn-boundaries.md b/.changeset/mcp-auth-session-turn-boundaries.md
new file mode 100644
index 000000000..e7f5e17b7
--- /dev/null
+++ b/.changeset/mcp-auth-session-turn-boundaries.md
@@ -0,0 +1,6 @@
+---
+"@truefoundry/trueforge-assistant-ui-runtime": patch
+"@truefoundry/trueforge-ui": patch
+---
+
+Show MCP auth resume turn boundaries and unanswered ask_user prompts in Sessions view.
diff --git a/packages/assistant-ui-runtime/src/index.ts b/packages/assistant-ui-runtime/src/index.ts
index 2e50938c4..b77c27c22 100644
--- a/packages/assistant-ui-runtime/src/index.ts
+++ b/packages/assistant-ui-runtime/src/index.ts
@@ -39,6 +39,7 @@ export {
useTrueForgeTurnId,
useTrueForgeUpdateAgentSpec,
} from './hooks.js';
+export { isMcpServerAuthInfoList } from './messageCustomMetadata.js';
export type {
McpAuthMessageCustomMetadata,
SandboxMessageCustomMetadata,
diff --git a/packages/assistant-ui-runtime/src/server/index.ts b/packages/assistant-ui-runtime/src/server/index.ts
index 8b8ece6ad..b541d80b6 100644
--- a/packages/assistant-ui-runtime/src/server/index.ts
+++ b/packages/assistant-ui-runtime/src/server/index.ts
@@ -139,6 +139,7 @@ export type {
UpdateSessionRequest,
UpdateWebSearchProviderRequest,
UpdateWebSearchRequest,
+ UserMcpAuthContinueEvent,
UserMessage,
UserMessageContent,
UserToolApprovalEvent,
diff --git a/packages/assistant-ui-runtime/src/server/types.ts b/packages/assistant-ui-runtime/src/server/types.ts
index 80bf150e6..ae09d2ddc 100644
--- a/packages/assistant-ui-runtime/src/server/types.ts
+++ b/packages/assistant-ui-runtime/src/server/types.ts
@@ -267,7 +267,12 @@ export interface UserToolResponseEvent {
content: string;
}
-export type TurnInputItem = UserMessage | UserToolApprovalEvent | UserToolResponseEvent;
+/** Client resume after mcp.auth_required (OAuth completed). */
+export interface UserMcpAuthContinueEvent {
+ type: 'user.mcp_auth_continue';
+}
+
+export type TurnInputItem = UserMessage | UserToolApprovalEvent | UserToolResponseEvent | UserMcpAuthContinueEvent;
export interface TurnStateRunning {
status: 'running';
diff --git a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
index 91508a37c..b7cd00c6f 100644
--- a/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
+++ b/packages/trueforge-ui/src/containers/AgentSessionTimelineContainer.tsx
@@ -1,9 +1,10 @@
'use client';
-import { ThreadPrimitive, type ThreadMessageLike } from '@assistant-ui/react';
-import { convertTurnsToThreadMessages } from '@truefoundry/trueforge-assistant-ui-runtime';
+import { ThreadPrimitive, useAuiState, type ThreadMessageLike } from '@assistant-ui/react';
+import { convertTurnsToThreadMessages, isMcpServerAuthInfoList } from '@truefoundry/trueforge-assistant-ui-runtime';
import { Suspense, useCallback, useEffect, useMemo, useRef, useState, type ComponentType } from 'react';
+import { AssistantMessageBubble, type AssistantMessageBubbleProps } from '../atoms/AssistantMessageBubble.js';
import { Markdown, type MarkdownProps } from '../atoms/Markdown.js';
import { MessageActionBar } from '../atoms/MessageActionBar.js';
import { ToolApprovalBar, type ToolApprovalBarProps } from '../atoms/ToolApprovalBar.js';
@@ -48,7 +49,25 @@ function ReadOnlyToolCallCard(props: ToolCallCardProps) {
return <ToolCallCard {...props} awaiting={props.approvalSlot ? false : props.awaiting} />;
}
+/** In session detail replay, render any pending MCP authorization prompt in readOnly mode. */
+function ReadOnlyAssistantMessageBubble(props: AssistantMessageBubbleProps) {
+ const McpAuthPrompt = useSlot('McpAuthPrompt');
+ const custom = useAuiState(s => s.message.metadata.custom);
+ const rawServers = custom?.pendingMcpAuth === true ? custom?.mcpServers : undefined;
+ const mcpServers = isMcpServerAuthInfoList(rawServers) ? rawServers : undefined;
+
+ return (
+ <AssistantMessageBubble {...props}>
+ {props.children}
+ {mcpServers != null && mcpServers.length > 0 ? (
+ <McpAuthPrompt servers={mcpServers} readOnly={true} onConnect={() => {}} />
+ ) : null}
+ </AssistantMessageBubble>
+ );
+}
+
const READ_ONLY_SLOT_OVERRIDES: SlotOverrides = {
+ AssistantMessageBubble: ReadOnlyAssistantMessageBubble,
UserMessageActionBar: ReadOnlyUserMessageActionBar,
Markdown: ReadOnlyMarkdown,
ToolApprovalBar: ReadOnlyToolApprovalBar,
@@ -131,9 +150,63 @@ function applyTerminalState(messages: ThreadMessageLike[], turn: SessionTurnView
return messages.map((message, index) => (index === assistantIndex ? terminal : message));
}
+/** Retrieves MCP servers requiring OAuth in this turn from done actions or turn events. */
+function findTurnMcpServers(turn: SessionTurnView) {
+ const actions = turn.done?.state.status === 'done' ? turn.done.state.requiredActions : undefined;
+ if (Array.isArray(actions)) {
+ for (const action of actions) {
+ if (action.type === 'mcp.auth_required' && isMcpServerAuthInfoList(action.mcpServers)) {
+ return action.mcpServers;
+ }
+ }
+ }
+ for (const event of turn.events) {
+ if (event.type === 'mcp.auth_required' && isMcpServerAuthInfoList(event.mcpServers)) {
+ return event.mcpServers;
+ }
+ }
+ return undefined;
+}
+
+/**
+ * Re-attaches MCP auth metadata to the assistant message in session replay.
+ * History projection drops pendingMcpAuth when synthetic continuation user messages
+ * follow; restoring it here ensures ReadOnlyAssistantMessageBubble renders the auth widget.
+ */
+function applyMcpAuthState(messages: ThreadMessageLike[], turn: SessionTurnView): ThreadMessageLike[] {
+ const mcpServers = findTurnMcpServers(turn);
+ if (mcpServers == null || mcpServers.length === 0) return messages;
+
+ const assistantIndex = messages.findIndex(message => message.role === 'assistant');
+ const assistant = assistantIndex < 0 ? undefined : messages[assistantIndex];
+ const createdAt = new Date(turn.done?.createdAt ?? turn.created.createdAt);
+ const updatedAssistant: ThreadMessageLike = {
+ ...(assistant ?? {
+ id: `${turn.turnId}-assistant`,
+ role: 'assistant',
+ content: [],
+ createdAt,
+ }),
+ ...(turn.done?.state.status === 'done' ? { status: { type: 'complete', reason: 'stop' } } : {}),
+ metadata: {
+ ...assistant?.metadata,
+ custom: {
+ ...assistant?.metadata?.custom,
+ turnId: turn.turnId,
+ pendingMcpAuth: true,
+ mcpServers,
+ },
+ },
+ };
+
+ if (assistantIndex < 0) return [...messages, updatedAssistant];
+ return messages.map((message, index) => (index === assistantIndex ? updatedAssistant : message));
+}
+
function messagesForTurn(messages: ThreadMessageLike[], turn: SessionTurnView): ThreadMessageLike[] {
const matched = messages.filter(message => turnIdFromMessage(message) === turn.turnId);
- return applyTerminalState(matched, turn);
+ const withMcpAuth = applyMcpAuthState(matched, turn);
+ return applyTerminalState(withMcpAuth, turn);
}
export type AgentSessionTimelineContainerProps = {
diff --git a/packages/trueforge-ui/src/containers/ReadOnlySessionTurnRuntime.tsx b/packages/trueforge-ui/src/containers/ReadOnlySessionTurnRuntime.tsx
index c9dc8bee5..a47b1dbe7 100644
--- a/packages/trueforge-ui/src/containers/ReadOnlySessionTurnRuntime.tsx
+++ b/packages/trueforge-ui/src/containers/ReadOnlySessionTurnRuntime.tsx
@@ -4,6 +4,7 @@ import { AssistantRuntimeProvider, useExternalStoreRuntime, type ThreadMessageLi
import type { ReactNode } from 'react';
import { SlotsProvider, type SlotOverrides } from '../theme/SlotsProvider.js';
+import { SessionReplayContext } from './sessionReplayContext.js';
/** Read-only assistant-ui runtime for one turn's projected messages. */
export function ReadOnlySessionTurnRuntime({
@@ -22,7 +23,11 @@ export function ReadOnlySessionTurnRuntime({
onNew: async () => {},
});
- const tree = <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>;
+ const tree = (
+ <SessionReplayContext.Provider value={true}>
+ <AssistantRuntimeProvider runtime={runtime}>{children}</AssistantRuntimeProvider>
+ </SessionReplayContext.Provider>
+ );
if (slotOverrides == null) {
return tree;
}
diff --git a/packages/trueforge-ui/src/containers/ToolCallContainer.tsx b/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
index e47807746..dd847d9b4 100644
--- a/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
+++ b/packages/trueforge-ui/src/containers/ToolCallContainer.tsx
@@ -24,7 +24,6 @@ import {
getAskUserAnswerResult,
getJsonDisplayValue,
getToolResultContent,
- hasPendingAskUserResponse,
hasPendingToolApproval,
mcpDisplayName,
parseAskUserQuestionArgs,
@@ -38,6 +37,7 @@ import { useRegisterApprovalExpand } from './approvalFocus.js';
import { AssistantTextContainer } from './AssistantTextContainer.js';
import { NestedApprovalBridgeContext, useNestedApprovalBridge } from './nestedApprovalBridge.js';
import { SandboxToolCallContainer } from './SandboxToolCallContainer.js';
+import { useSessionReplay } from './sessionReplayContext.js';
import { ToolApprovalContainer } from './ToolApprovalContainer.js';
import { ToolCallContentBlockContainer } from './ToolCallContentBlockContainer.js';
@@ -152,6 +152,7 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
const ToolCallCard = useSlot('ToolCallCard');
const SubAgentCard = useSlot('SubAgentCard');
const AskUserPrompt = useSlot('AskUserPrompt');
+ const isSessionReplay = useSessionReplay();
const elapsedMs = useToolCallElapsed();
const isRequiresAction = part.status?.type === 'requires-action';
const isSubAgent = part.toolName === SUB_AGENT_TOOL_NAME;
@@ -172,27 +173,45 @@ export const ToolCallContainer: ToolCallMessagePartComponent = part => {
useRegisterApprovalExpand(isSubAgent ? part.toolCallId : '', expandSubAgent);
if (part.toolName === ASK_USER_TOOL_NAME) {
- if (hasPendingAskUserResponse(part)) {
- return null;
- }
+ const { question, options = [] } = parseAskUserQuestionArgs(part.argsText);
const answer = getAskUserAnswerResult(part.result);
- if (answer == null) {
+
+ if (answer != null) {
+ const isCustom = options.length > 0 && !options.includes(answer);
+ return (
+ <AskUserPrompt
+ questions={[]}
+ answeredQuestions={[
+ {
+ id: part.toolCallId,
+ question: question ?? 'Question',
+ options,
+ answer,
+ isCustom,
+ },
+ ]}
+ onSubmit={() => {}}
+ readOnly
+ />
+ );
+ }
+
+ // Live chat: hide until answered. Streaming parts have no interrupt yet;
+ // paused ones are owned by AskUserContainer in the composer.
+ if (!isSessionReplay) {
return null;
}
- const { question, options = [] } = parseAskUserQuestionArgs(part.argsText);
- const isCustom = options.length > 0 && !options.includes(answer);
+
+ const unhandledQuestion = {
+ id: part.toolCallId,
+ question: question ?? 'Question',
+ options,
+ };
return (
<AskUserPrompt
- questions={[]}
- answeredQuestions={[
- {
- id: part.toolCallId,
- question: question ?? 'Question',
- options,
- answer,
- isCustom,
- },
- ]}
+ questions={[unhandledQuestion]}
+ currentQuestion={unhandledQuestion}
+ currentAnswer={{ radioValue: '', custom: '' }}
onSubmit={() => {}}
readOnly
/>
diff --git a/packages/trueforge-ui/src/containers/sessionReplayContext.ts b/packages/trueforge-ui/src/containers/sessionReplayContext.ts
new file mode 100644
index 000000000..71ddd833a
--- /dev/null
+++ b/packages/trueforge-ui/src/containers/sessionReplayContext.ts
@@ -0,0 +1,14 @@
+'use client';
+
+import { createContext, useContext } from 'react';
+
+/**
+ * Session detail replay has no composer AskUserContainer. When true,
+ * ToolCallContainer renders pending ask_user prompts as read-only Unanswered
+ * cards instead of returning null (live chat keeps those in the composer).
+ */
+export const SessionReplayContext = createContext(false);
+
+export function useSessionReplay(): boolean {
+ return useContext(SessionReplayContext);
+}
diff --git a/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/chatServer.ts b/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/chatServer.ts
index c9f110902..8907091e6 100644
--- a/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/chatServer.ts
+++ b/packages/trueforge-ui/src/plugins/trueforge-agent-server-adapter/chatServer.ts
@@ -171,9 +171,17 @@ function toHarnessContent(content: UserMessageContent): TrueForgeApi.UserMessage
}
function toHarnessInput(input: TurnInputItem[]): TrueForgeApi.TurnInputItem[] {
- return input.map(item =>
- item.type === 'user.message' ? { ...item, content: toHarnessContent(item.content) } : item,
- );
+ const out: TrueForgeApi.TurnInputItem[] = [];
+ for (const item of input) {
+ // SDK TurnInputItem omits continue; OAuth resume is posted as a create-event.
+ if (item.type === 'user.mcp_auth_continue') continue;
+ if (item.type === 'user.message') {
+ out.push({ ...item, content: toHarnessContent(item.content) });
+ continue;
+ }
+ out.push(item);
+ }
+ return out;
}
export function createHarnessChatServer(
diff --git a/packages/trueforge-ui/src/server/types.ts b/packages/trueforge-ui/src/server/types.ts
index 27fd3f0ee..e9360a1dd 100644
--- a/packages/trueforge-ui/src/server/types.ts
+++ b/packages/trueforge-ui/src/server/types.ts
@@ -134,6 +134,7 @@ export type {
UpdateScheduleRequest,
UpdateSessionRequest,
UpdateWebSearchProviderRequest,
+ UserMcpAuthContinueEvent,
UserMessage,
UserMessageContent,
UserToolApprovalEvent,
diff --git a/packages/trueforge-ui/src/utils/sessionTimelineEvents.ts b/packages/trueforge-ui/src/utils/sessionTimelineEvents.ts
index 55401f63d..36ff7c55f 100644
--- a/packages/trueforge-ui/src/utils/sessionTimelineEvents.ts
+++ b/packages/trueforge-ui/src/utils/sessionTimelineEvents.ts
@@ -111,6 +111,7 @@ export function getTurnInputSummary(turn: SessionTurnView): string {
return 'Tool approval';
}
if (item.type === 'user.tool_response') return extractText(item.content) || 'Tool response';
+ if (item.type === 'user.mcp_auth_continue') return 'MCP authorization completed';
return extractText(item.content) || 'User message';
}
diff --git a/packages/trueforge-ui/src/utils/sessionTurnViews.ts b/packages/trueforge-ui/src/utils/sessionTurnViews.ts
index abccf4a74..26453060e 100644
--- a/packages/trueforge-ui/src/utils/sessionTurnViews.ts
+++ b/packages/trueforge-ui/src/utils/sessionTurnViews.ts
@@ -4,13 +4,15 @@ type TurnCreatedEvent = Extract<SessionEventItem['event'], { type: 'turn.created
type TurnDoneEvent = Extract<SessionEventItem['event'], { type: 'turn.done' }>;
type TurnEvent = Exclude<SessionEventItem['event'], TurnCreatedEvent | TurnDoneEvent>;
+const MCP_AUTH_CONTINUE_INPUT = { type: 'user.mcp_auth_continue' } as const;
+
export type SessionTurnView = {
turnId: string;
/** Chronological index among every event turn (1..N). Unique; used for gap compression. */
eventTurnNumber: number;
- /** Display band among renderable turns (1..R); MCP-auth resumes inherit the prior band. */
+ /** Display band among renderable turns (1..R). */
turnNumber: number;
- /** True when the turn has user.message / tool_approval / tool_response input. */
+ /** True when the turn has user/continuation input worth its own transcript section. */
renderable: boolean;
showHeader: boolean;
created: TurnCreatedEvent;
@@ -30,7 +32,12 @@ type TurnGroup = {
events: TurnEvent[];
};
-const RENDERABLE_INPUT_TYPES = new Set(['user.message', 'user.tool_approval', 'user.tool_response']);
+const RENDERABLE_INPUT_TYPES = new Set([
+ 'user.message',
+ 'user.tool_approval',
+ 'user.tool_response',
+ 'user.mcp_auth_continue',
+]);
function timestampMs(createdAt: string): number {
const value = Date.parse(createdAt);
@@ -47,6 +54,20 @@ function isRenderableTurn(created: TurnCreatedEvent): boolean {
});
}
+function turnEndedWithMcpAuth(done: TurnDoneEvent | undefined): boolean {
+ if (done == null || done.state.status !== 'done') return false;
+ const actions = done.state.requiredActions;
+ if (!Array.isArray(actions)) return false;
+ return actions.some(action => action.type === 'mcp.auth_required');
+}
+
+/** Production MCP resumes often omit input; normalize so summary/projection helpers work. */
+function withMcpAuthContinueInput(created: TurnCreatedEvent): TurnCreatedEvent {
+ const input = created.input ?? [];
+ if (input.some(item => item.type === 'user.mcp_auth_continue')) return created;
+ return { ...created, input: [...input, MCP_AUTH_CONTINUE_INPUT] };
+}
+
function readMetricNumber(metrics: object, camel: string, snake: string): number | undefined {
const camelValue = Reflect.get(metrics, camel);
if (typeof camelValue === 'number' && Number.isFinite(camelValue)) return camelValue;
@@ -118,8 +139,8 @@ export function buildSessionTurnViews(itemsAsc: SessionEventItem[]): SessionTurn
groupsByTurnId.set(turnId, group);
}
- // Include every turn.created (metrics need resume turns). Number timeline/transcript
- // bands by renderable turns only so MCP-auth resumes fold into the prior user turn.
+ // Include every turn.created (metrics need all turns). Empty-input MCP-auth
+ // resumes become their own transcript band via synthesized continue input.
const groups = Array.from(groupsByTurnId.entries())
.flatMap(([turnId, group]) => (group.created === undefined ? [] : [{ turnId, created: group.created, group }]))
.sort((left, right) => timestampMs(left.created.createdAt) - timestampMs(right.created.createdAt));
@@ -127,7 +148,10 @@ export function buildSessionTurnViews(itemsAsc: SessionEventItem[]): SessionTurn
let renderableTurnNumber = 0;
return groups.map(({ turnId, created, group }, index) => {
const done = group.done;
- const renderable = isRenderableTurn(created);
+ const previousDone = index > 0 ? groups[index - 1]?.group.done : undefined;
+ const isMcpAuthResume = !isRenderableTurn(created) && turnEndedWithMcpAuth(previousDone);
+ const viewCreated = isMcpAuthResume ? withMcpAuthContinueInput(created) : created;
+ const renderable = isRenderableTurn(viewCreated);
if (renderable) renderableTurnNumber += 1;
group.events.sort((left, right) => timestampMs(left.createdAt) - timestampMs(right.createdAt));
@@ -137,7 +161,7 @@ export function buildSessionTurnViews(itemsAsc: SessionEventItem[]): SessionTurn
turnNumber: Math.max(1, renderableTurnNumber),
renderable,
showHeader: renderable,
- created,
+ created: viewCreated,
...(done === undefined
? {}
: {
diff --git a/packages/trueforge-ui/src/utils/toolCallParsing.ts b/packages/trueforge-ui/src/utils/toolCallParsing.ts
index e31f49bf0..6a7877aef 100644
--- a/packages/trueforge-ui/src/utils/toolCallParsing.ts
+++ b/packages/trueforge-ui/src/utils/toolCallParsing.ts
@@ -86,10 +86,6 @@ export function getAskUserAnswerResult(result: unknown): string | undefined {
return undefined;
}
-export function hasPendingAskUserResponse(part: Pick<ToolCallMessagePartProps, 'interrupt' | 'result'>): boolean {
- return part.interrupt != null && part.result === undefined;
-}
-
export function hasPendingToolApproval(
approval: { approved?: boolean; resolution?: 'cancelled' | 'expired' } | undefined,
) {
diff --git a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
index b9825f451..8840cd7ac 100644
--- a/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
+++ b/packages/trueforge-ui/test/containers/AgentSessionTimelineContainer.test.tsx
@@ -365,4 +365,367 @@ describe('AgentSessionTimelineContainer', () => {
expect(screen.queryByRole('button', { name: 'Approve' })).not.toBeInTheDocument();
expect(screen.queryByText(/Awaiting Response/)).not.toBeInTheDocument();
});
+
+ it('renders unhandled ask_user_question prompt with Unanswered badge and disabled inputs in replay', async () => {
+ const askUserEvents: SessionEventItem[] = [
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.created',
+ id: 'c1',
+ turnId: 'turn-1',
+ previousTurnId: null,
+ input: [{ type: 'user.message', content: 'ask me something' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'model.message',
+ id: 'm1',
+ threadId: 'main',
+ content: '',
+ createdAt: '2026-01-01T00:00:01.000Z',
+ toolCalls: [
+ {
+ id: 'call-ask-1',
+ type: 'function',
+ function: {
+ name: 'ask_user_question',
+ arguments: JSON.stringify({
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ }),
+ },
+ },
+ ],
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'tool.response_required',
+ id: 'req-ask-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ toolCalls: [{ id: 'call-ask-1', sourceEventId: 'm1' }],
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.done',
+ id: 'd1',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:02.000Z',
+ output: null,
+ requiredActions: [
+ {
+ type: 'tool.response_required',
+ id: 'req-ask-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ toolCalls: [{ id: 'call-ask-1', sourceEventId: 'm1' }],
+ },
+ ],
+ },
+ createdAt: '2026-01-01T00:00:02.000Z',
+ threadId: null,
+ },
+ },
+ ];
+
+ render(
+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>
+ <ServerProvider server={createMockAgentUIServer()}>
+ <AgentSessionTimelineContainer sessionId="sess-1" events={askUserEvents} />
+ </ServerProvider>
+ </SlotsProvider>,
+ );
+
+ expect(await screen.findByText('Which environment?')).toBeInTheDocument();
+ expect(screen.getByText('Unanswered')).toBeInTheDocument();
+ expect(screen.getByRole('radio', { name: 'staging' })).toBeDisabled();
+ expect(screen.getByRole('radio', { name: 'production' })).toBeDisabled();
+ expect(screen.queryByRole('button', { name: 'Submit' })).not.toBeInTheDocument();
+ });
+
+ it('renders MCP Auth Required prompt with disabled Connect button in replay', async () => {
+ const mcpAuthEvents: SessionEventItem[] = [
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.created',
+ id: 'c1',
+ turnId: 'turn-1',
+ previousTurnId: null,
+ input: [{ type: 'user.message', content: 'fetch external data' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.done',
+ id: 'd1',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:02.000Z',
+ output: null,
+ requiredActions: [
+ {
+ type: 'mcp.auth_required',
+ id: 'mcp-req-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ mcpServers: [
+ {
+ id: 'github-server',
+ name: 'GitHub MCP',
+ authUrl: 'https://auth.github.com',
+ },
+ ],
+ },
+ ],
+ },
+ createdAt: '2026-01-01T00:00:02.000Z',
+ threadId: null,
+ },
+ },
+ ];
+
+ render(
+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>
+ <ServerProvider server={createMockAgentUIServer()}>
+ <AgentSessionTimelineContainer sessionId="sess-1" events={mcpAuthEvents} />
+ </ServerProvider>
+ </SlotsProvider>,
+ );
+
+ expect(await screen.findByText('MCP Authentication Required')).toBeInTheDocument();
+ expect(screen.getByText('GitHub MCP')).toBeInTheDocument();
+ const connectButton = screen.getByRole('button', { name: /Connect/ });
+ expect(connectButton).toBeInTheDocument();
+ expect(connectButton).toBeDisabled();
+ });
+
+ it('renders continuation turn header and input summary for user.mcp_auth_continue', async () => {
+ const continueEvents: SessionEventItem[] = [
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.created',
+ id: 'c1',
+ turnId: 'turn-1',
+ previousTurnId: null,
+ input: [{ type: 'user.message', content: 'fetch external data' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.done',
+ id: 'd1',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:02.000Z',
+ output: null,
+ requiredActions: [
+ {
+ type: 'mcp.auth_required',
+ id: 'mcp-req-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ mcpServers: [
+ {
+ id: 'github-server',
+ name: 'GitHub MCP',
+ authUrl: 'https://auth.github.com',
+ },
+ ],
+ },
+ ],
+ },
+ createdAt: '2026-01-01T00:00:02.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'turn.created',
+ id: 'c2',
+ turnId: 'turn-2',
+ previousTurnId: 'turn-1',
+ input: [{ type: 'user.mcp_auth_continue' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:03.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'model.message',
+ id: 'm2',
+ threadId: 'main',
+ content: 'resumed after auth',
+ createdAt: '2026-01-01T00:00:04.000Z',
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'turn.done',
+ id: 'd2',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:05.000Z',
+ output: null,
+ requiredActions: [],
+ },
+ createdAt: '2026-01-01T00:00:05.000Z',
+ threadId: null,
+ },
+ },
+ ];
+
+ render(
+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>
+ <ServerProvider server={createMockAgentUIServer()}>
+ <AgentSessionTimelineContainer sessionId="sess-1" events={continueEvents} />
+ </ServerProvider>
+ </SlotsProvider>,
+ );
+
+ expect(await screen.findByText('Turn 1')).toBeInTheDocument();
+ expect(screen.getByText('Turn 2')).toBeInTheDocument();
+ expect(screen.getByText('MCP authorization completed')).toBeInTheDocument();
+ expect(screen.getByText('resumed after auth')).toBeInTheDocument();
+ });
+
+ it('splits empty-input MCP auth resume into Turn 2 with auth widget on Turn 1', async () => {
+ const emptyInputResumeEvents: SessionEventItem[] = [
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.created',
+ id: 'c1',
+ turnId: 'turn-1',
+ previousTurnId: null,
+ input: [{ type: 'user.message', content: 'Hello' }],
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:00.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'mcp.auth_required',
+ id: 'mcp-req-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ mcpServers: [
+ {
+ id: 'linear',
+ name: 'linear',
+ authUrl: 'https://mcp.linear.app/authorize',
+ },
+ ],
+ },
+ },
+ {
+ turnId: 'turn-1',
+ event: {
+ type: 'turn.done',
+ id: 'd1',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:02.000Z',
+ output: null,
+ requiredActions: [
+ {
+ type: 'mcp.auth_required',
+ id: 'mcp-req-1',
+ threadId: 'main',
+ createdAt: '2026-01-01T00:00:01.500Z',
+ mcpServers: [
+ {
+ id: 'linear',
+ name: 'linear',
+ authUrl: 'https://mcp.linear.app/authorize',
+ },
+ ],
+ },
+ ],
+ },
+ createdAt: '2026-01-01T00:00:02.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'turn.created',
+ id: 'c2',
+ turnId: 'turn-2',
+ previousTurnId: 'turn-1',
+ state: { status: 'running' },
+ createdAt: '2026-01-01T00:00:03.000Z',
+ threadId: null,
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'model.message',
+ id: 'm2',
+ threadId: 'main',
+ content: 'Hello! How can I help you today?',
+ createdAt: '2026-01-01T00:00:04.000Z',
+ },
+ },
+ {
+ turnId: 'turn-2',
+ event: {
+ type: 'turn.done',
+ id: 'd2',
+ state: {
+ status: 'done',
+ completedAt: '2026-01-01T00:00:05.000Z',
+ output: null,
+ requiredActions: [],
+ },
+ createdAt: '2026-01-01T00:00:05.000Z',
+ threadId: null,
+ },
+ },
+ ];
+
+ render(
+ <SlotsProvider overrides={{ AgentSessionEventTimeline: () => null }}>
+ <ServerProvider server={createMockAgentUIServer()}>
+ <AgentSessionTimelineContainer sessionId="sess-1" events={emptyInputResumeEvents} />
+ </ServerProvider>
+ </SlotsProvider>,
+ );
+
+ expect(await screen.findByText('Turn 1')).toBeInTheDocument();
+ expect(screen.getByText('Turn 2')).toBeInTheDocument();
+ expect(screen.getByText('MCP Authentication Required')).toBeInTheDocument();
+ expect(screen.getByText('linear')).toBeInTheDocument();
+ expect(screen.getByRole('button', { name: /Connect/ })).toBeDisabled();
+ expect(screen.getByText('MCP authorization completed')).toBeInTheDocument();
+ expect(screen.getByText('Hello! How can I help you today?')).toBeInTheDocument();
+ });
});
diff --git a/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx b/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
index 793d80da5..70e380283 100644
--- a/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
+++ b/packages/trueforge-ui/test/containers/ToolCallContainer.test.tsx
@@ -8,6 +8,7 @@ import type { SandboxToolCallCardProps } from '@/atoms/SandboxToolCallCard.js';
import type { SubAgentCardProps } from '@/atoms/SubAgentCard.js';
import type { ToolCallCardProps } from '@/atoms/ToolCallCard.js';
import { AssistantMessageContainer } from '@/containers/AssistantMessageContainer.js';
+import { SessionReplayContext } from '@/containers/sessionReplayContext.js';
import { SlotsProvider, type SlotOverrides } from '@/theme/SlotsProvider.js';
import { RuntimeHarness } from './RuntimeHarness.js';
@@ -192,6 +193,100 @@ describe('ToolCallContainer', () => {
);
});
+ it('hides pending ask_user in live chat so the composer owns the prompt', () => {
+ const AskUserPrompt = createAskUserPromptProbe();
+
+ renderToolCallMessage(
+ [
+ {
+ type: 'tool-call',
+ toolCallId: 'question-pending',
+ toolName: 'ask_user_question',
+ args: {},
+ argsText: JSON.stringify({
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ }),
+ interrupt: { type: 'human', payload: {} },
+ },
+ ],
+ { AskUserPrompt },
+ );
+
+ expect(AskUserPrompt).not.toHaveBeenCalled();
+ });
+
+ it('hides streaming ask_user in live chat before interrupt is set', () => {
+ const AskUserPrompt = createAskUserPromptProbe();
+
+ renderToolCallMessage(
+ [
+ {
+ type: 'tool-call',
+ toolCallId: 'question-streaming',
+ toolName: 'ask_user_question',
+ args: {},
+ argsText: JSON.stringify({
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ }),
+ },
+ ],
+ { AskUserPrompt },
+ );
+
+ expect(AskUserPrompt).not.toHaveBeenCalled();
+ });
+
+ it('renders pending ask_user as read-only Unanswered in session replay', () => {
+ const AskUserPrompt = createAskUserPromptProbe();
+ const message: ThreadMessageLike = {
+ role: 'assistant',
+ content: [
+ {
+ type: 'tool-call',
+ toolCallId: 'question-pending',
+ toolName: 'ask_user_question',
+ args: {},
+ argsText: JSON.stringify({
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ }),
+ interrupt: { type: 'human', payload: {} },
+ },
+ ],
+ };
+
+ render(
+ <SlotsProvider overrides={{ AskUserPrompt }}>
+ <SessionReplayContext.Provider value={true}>
+ <RuntimeHarness messages={[message]}>
+ <ThreadPrimitive.Messages>{() => <AssistantMessageContainer />}</ThreadPrimitive.Messages>
+ </RuntimeHarness>
+ </SessionReplayContext.Provider>
+ </SlotsProvider>,
+ );
+
+ expect(AskUserPrompt.mock.calls[0]?.[0]).toEqual(
+ expect.objectContaining({
+ questions: [
+ {
+ id: 'question-pending',
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ },
+ ],
+ currentQuestion: {
+ id: 'question-pending',
+ question: 'Which environment?',
+ options: ['staging', 'production'],
+ },
+ currentAnswer: { radioValue: '', custom: '' },
+ readOnly: true,
+ }),
+ );
+ });
+
it('routes sub-agent metadata and renders its nested assistant content', () => {
const SubAgentCard = createSubAgentCardProbe();
const nestedMessage: ThreadMessage = {