TypeScript
fix(chat): make links in agent questions clickable (#19197)
Theo Browne85272eeeae53
diff --git a/apps/mobile/src/features/threads/PendingUserInputCard.tsx b/apps/mobile/src/features/threads/PendingUserInputCard.tsxindex 172eb627645..27fab480ad7 100644--- a/apps/mobile/src/features/threads/PendingUserInputCard.tsx+++ b/apps/mobile/src/features/threads/PendingUserInputCard.tsx@@ -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();diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsxindex 64514530b29..dc46376483c 100644--- a/apps/web/src/components/chat/ChatComposer.tsx+++ b/apps/web/src/components/chat/ChatComposer.tsx@@ -6869,6 +6869,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)) : !isComposerCollapsedMobile && pendingUserInputs.length > 0 ? (<ComposerPendingUserInputPanelpendingUserInputs={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"><ComposerPendingUserInputPanelpendingUserInputs={pendingUserInputs}+ cwd={gitCwd ?? undefined}+ threadRef={routeThreadRef}disabled={!canOperateThread}respondingRequestIds={activePendingIsResponding && activePendingUserInputdiff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.test.tsxindex c414934fa0d..6e5103d1ec1 100644--- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.test.tsx+++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.navigation.test.tsx@@ -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><ComposerPendingUserInputPanelpendingUserInputs={[prompt]}+ cwd="/repo"+ threadRef={threadRef}disabled={false}respondingRequestIds={[]}answers={answers}diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.permissions.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.permissions.test.tsxindex f81ed670260..ffffe2a338c 100644--- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.permissions.test.tsx+++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.permissions.test.tsx@@ -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 neconst panel = (disabled: boolean) => (<ComposerPendingUserInputPanelpendingUserInputs={[prompt]}+ cwd="/repo"+ threadRef={threadRef}disabled={disabled}respondingRequestIds={[]}answers={{}}diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.test.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.test.tsxindex 34f9467e42c..377b49d3a6b 100644--- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.test.tsx+++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.test.tsx@@ -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(<ComposerPendingUserInputPanelpendingUserInputs={[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, "\\$&")}"`));+ });});diff --git a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsxindex 1e8caefac2d..88f99997468 100644--- a/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx+++ b/apps/web/src/components/chat/ComposerPendingUserInputPanel.tsx@@ -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<ComposerPendingUserInputCardkey={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 ComposerPendingUserInconst 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}