fix(chat): make links in agent questions clickable (#19197)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-10-13 17:59:02 -07:00
1 parent a74ce48f96
commit 85272eeeae
6 files changed
+70 -8

No files matched your search

@@ -21,6 +21,9 @@ import { SymbolView } from "../../components/AppSymbol";
import { AppText as Text } from "../../components/AppText";
import { ControlPill } from "../../components/ControlPill";
import { cn } from "../../lib/cn";
import { SelectableMarkdownText } from "../../native/SelectableMarkdownText";
import { useOpenPullRequest } from "../../native/useOpenPullRequest";
import { useMarkdownPreviewStyles } from "../files/FileMarkdownPreview";
import {
isPendingUserInputOptionSelected,
type PendingUserInput,
@@ -91,6 +94,19 @@ const EXPANDED_CARD_IS_OVERLAY = Platform.OS === "ios";
const CARD_LAYOUT_TRANSITION = LinearTransition.duration(200);
/** Renders question text as markdown so agent-provided links open on tap. */
function QuestionText(props: { readonly markdown: string }) {
const styles = useMarkdownPreviewStyles();
const openLink = useOpenPullRequest();
return (
<SelectableMarkdownText
markdown={props.markdown}
textStyle={styles.nativeTextStyle}
onLinkPress={(href) => void openLink(href)}
/>
);
}
export function PendingUserInputCard(props: PendingUserInputCardProps) {
const questionCount = props.pendingUserInput.questions.length;
// Message responses start a new run and remain available after the provider exits.
@@ -277,9 +293,7 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
<Text className="font-t3-bold text-xs uppercase tracking-[1px] text-foreground-muted">
{question.header}
</Text>
<Text className="font-sans text-base leading-snug text-foreground">
{question.question}
</Text>
<QuestionText markdown={question.question} />
<View className="gap-2">
{question.options.map((option) => {
const optionValue = option.value ?? option.label.trim();
@@ -6869,6 +6869,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
) : !isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (
<ComposerPendingUserInputPanel
pendingUserInputs={pendingUserInputs}
cwd={gitCwd ?? undefined}
threadRef={routeThreadRef}
disabled={!canOperateThread}
respondingRequestIds={
activePendingIsResponding && activePendingUserInput
@@ -6890,6 +6892,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
<div data-chat-composer-collapsed-controls="true">
<ComposerPendingUserInputPanel
pendingUserInputs={pendingUserInputs}
cwd={gitCwd ?? undefined}
threadRef={routeThreadRef}
disabled={!canOperateThread}
respondingRequestIds={
activePendingIsResponding && activePendingUserInput
@@ -1,4 +1,4 @@
import { RuntimeRequestId } from "@t3tools/contracts";
import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
import { act, useState, type ReactNode } from "react";
import { create, type ReactTestRenderer } from "react-test-renderer";
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
@@ -17,8 +17,12 @@ vi.mock("../ui/collapsible", () => {
};
});
vi.mock("../ChatMarkdown", () => ({ default: ({ text }: { text: string }) => <p>{text}</p> }));
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
const prompt = {
requestId: RuntimeRequestId.make("question-navigation"),
createdAt: "2026-10-09T00:00:00.000Z",
@@ -44,6 +48,8 @@ function Questions({ initialIndex = 0 }: { initialIndex?: number }) {
<button onClick={() => setQuestionIndex(questionIndex - 1)}>Previous</button>
<ComposerPendingUserInputPanel
pendingUserInputs={[prompt]}
cwd="/repo"
threadRef={threadRef}
disabled={false}
respondingRequestIds={[]}
answers={answers}
@@ -1,4 +1,4 @@
import { RuntimeRequestId } from "@t3tools/contracts";
import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
import { act, type ReactNode } from "react";
import { create, type ReactTestRenderer } from "react-test-renderer";
import { expect, it, vi } from "vite-plus/test";
@@ -12,8 +12,12 @@ vi.mock("../ui/collapsible", () => {
};
});
vi.mock("../ChatMarkdown", () => ({ default: ({ text }: { text: string }) => <p>{text}</p> }));
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
it("cancels an answer's pending auto-submit on revocation and resumes after a new grant", async () => {
vi.useFakeTimers();
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
@@ -43,6 +47,8 @@ it("cancels an answer's pending auto-submit on revocation and resumes after a ne
const panel = (disabled: boolean) => (
<ComposerPendingUserInputPanel
pendingUserInputs={[prompt]}
cwd="/repo"
threadRef={threadRef}
disabled={disabled}
respondingRequestIds={[]}
answers={{}}
@@ -1,8 +1,10 @@
import { RuntimeRequestId } from "@t3tools/contracts";
import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vite-plus/test";
import { ComposerPendingUserInputPanel } from "./ComposerPendingUserInputPanel";
const threadRef = { environmentId: EnvironmentId.make("env"), threadId: ThreadId.make("thread") };
import type { PendingUserInput } from "../../session-logic";
const prompt: PendingUserInput = {
@@ -28,6 +30,8 @@ function renderPanel(pendingUserInput: PendingUserInput = prompt) {
return renderToStaticMarkup(
<ComposerPendingUserInputPanel
pendingUserInputs={[pendingUserInput]}
cwd="/repo"
threadRef={threadRef}
respondingRequestIds={[]}
answers={{}}
questionIndex={0}
@@ -68,4 +72,15 @@ describe("ComposerPendingUserInputPanel", () => {
expect(markup).toContain("Incremental");
expect(markup).toContain("Big bang");
});
it("links URLs in the question text", () => {
const url = "https://accounts.t3.codes/device?user_code=RTJS-TQGS";
const question = prompt.questions[0]!;
const markup = renderPanel({
...prompt,
questions: [{ ...question, question: `Authorize BeeBox at ${url} and confirm.` }],
});
expect(markup).toMatch(new RegExp(`<a[^>]*href="${url.replace(/[?.]/g, "\\$&")}"`));
});
});
@@ -1,4 +1,4 @@
import { type RuntimeRequestId } from "@t3tools/contracts";
import { type RuntimeRequestId, type ScopedThreadRef } from "@t3tools/contracts";
import { memo, useCallback, useEffect, useRef, useState } from "react";
import { type PendingUserInput } from "../../session-logic";
import {
@@ -9,9 +9,13 @@ import { CheckIcon } from "lucide-react";
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
import { cn } from "~/lib/utils";
import { ComposerBanner } from "./ComposerBanner";
import ChatMarkdown from "../ChatMarkdown";
interface PendingUserInputPanelProps {
pendingUserInputs: PendingUserInput[];
/** Resolves file links in the question text. */
cwd: string | undefined;
threadRef: ScopedThreadRef;
disabled?: boolean;
respondingRequestIds: RuntimeRequestId[];
answers: Record<string, PendingUserInputDraftAnswer>;
@@ -23,6 +27,8 @@ interface PendingUserInputPanelProps {
export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserInputPanel({
pendingUserInputs,
cwd,
threadRef,
disabled = false,
respondingRequestIds,
answers,
@@ -39,6 +45,8 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
<ComposerPendingUserInputCard
key={activePrompt.requestId}
prompt={activePrompt}
cwd={cwd}
threadRef={threadRef}
disabled={disabled}
isResponding={respondingRequestIds.includes(activePrompt.requestId)}
answers={answers}
@@ -52,6 +60,8 @@ export const ComposerPendingUserInputPanel = memo(function ComposerPendingUserIn
const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard({
prompt,
cwd,
threadRef,
disabled,
isResponding,
answers,
@@ -61,6 +71,8 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
onDismiss,
}: {
prompt: PendingUserInput;
cwd: string | undefined;
threadRef: ScopedThreadRef;
disabled: boolean;
isResponding: boolean;
answers: Record<string, PendingUserInputDraftAnswer>;
@@ -242,7 +254,12 @@ const ComposerPendingUserInputCard = memo(function ComposerPendingUserInputCard(
<CollapsiblePanel>
<ComposerBanner.Scroll>
<ComposerBanner.Body className="pe-1 pb-1 wrap-anywhere">
<p className="text-sm text-foreground/85">{activeQuestion.question}</p>
<ChatMarkdown
text={activeQuestion.question}
cwd={cwd}
threadRef={threadRef}
className="text-foreground/85"
/>
{activeQuestion.multiSelect ? (
<p className="mt-1 text-secondary-label text-xs">Select one or more options.</p>
) : null}