diff --git a/apps/web/src/components/ChatView.browser.test.tsx b/apps/web/src/components/ChatView.browser.test.tsx
index a0458f9e80280..6b1c810141735 100644
--- a/apps/web/src/components/ChatView.browser.test.tsx
+++ b/apps/web/src/components/ChatView.browser.test.tsx
@@ -1,5 +1,6 @@
import { createMemoryHistory } from "@tanstack/react-router";
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
+import { PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES } from "@t3tools/client-runtime/text-paste";
import {
EnvironmentId,
ORCHESTRATION_V2_WS_METHODS,
@@ -662,3 +663,46 @@ it("selecting a side-chat tab focuses that side chat's composer", async () => {
await expect.element(sideEditor).toHaveFocus();
await expect.element(mainEditor).toHaveTextContent("main draft");
});
+
+it("folds a large paste that mentions a thread link into a pasted-text attachment", async () => {
+ using _environment = installFakeEnvironment([]);
+ __setClientSettingsForTests({
+ ...DEFAULT_CLIENT_SETTINGS,
+ onboardingCompletedAt: "2026-01-01T00:00:00.000Z",
+ });
+ const draftId = DraftId.make("draft-30577");
+ useComposerDraftStore
+ .getState()
+ .setProjectDraftThreadId(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID), draftId, {
+ threadId: ThreadId.make("thread-30577"),
+ });
+ const log = [
+ ...Array.from(
+ { length: 400 },
+ (_, line) => `2026-11-03T12:00:00Z worker[${line}] retrying job`,
+ ),
+ `see https://app.t3.codes/threads/${ENVIRONMENT_ID}/thread-abc for context`,
+ ...Array.from({ length: 400 }, (_, line) => `2026-11-03T12:00:01Z worker[${line}] job failed`),
+ ].join("\n");
+ expect(log.length).toBeGreaterThan(PASTED_TEXT_ATTACHMENT_THRESHOLD_BYTES);
+
+ const router = getRouter(createMemoryHistory({ initialEntries: [`/draft/${draftId}`] }));
+ await router.load();
+ await using _app = await render(, {
+ // AppRoot brings its own router.
+ router: false,
+ });
+ await expect.element(page.getByTestId("composer-editor")).toBeVisible();
+ await expect.element(page.getByText("render", { exact: true }).first()).toBeVisible();
+ const editor = page.getByTestId("composer-editor").element() as HTMLElement;
+ editor.focus();
+
+ const clipboardData = new DataTransfer();
+ clipboardData.setData("text/plain", log);
+ editor.dispatchEvent(
+ new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }),
+ );
+
+ await expect.element(page.getByText("pasted-text.txt")).toBeVisible();
+ expect(editor.textContent).not.toContain("worker[399] retrying job");
+});
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 69250e47b89c3..b45e8cf966c10 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -13,7 +13,11 @@ import {
import { isLocalEnvironmentDisabled } from "../../localEnvironment";
import { usePrimaryEnvironmentId } from "../../state/environments";
import { useRightPanelStore } from "~/rightPanelStore";
-import { importPastedComposerText, readPastedComposerContext } from "../composerInlineTokenPaste";
+import {
+ importPastedComposerText,
+ pastesCopiedComposerContext,
+ readPastedComposerContext,
+} from "../composerInlineTokenPaste";
import {
questionAttachmentDraftId,
trackOpenQuestionAttachmentDraft,
@@ -2830,7 +2834,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
return;
}
- if (pastedContext) return;
+ if (!isLiteralPendingAnswer && pastesCopiedComposerContext(event.clipboardData)) return;
if (!foldPastedText(plainText, bypassAutoAttachment)) {
return;
}
diff --git a/apps/web/src/components/chat/usePasteToFocusComposer.ts b/apps/web/src/components/chat/usePasteToFocusComposer.ts
index 84672cc570c56..c616aa085a89e 100644
--- a/apps/web/src/components/chat/usePasteToFocusComposer.ts
+++ b/apps/web/src/components/chat/usePasteToFocusComposer.ts
@@ -1,5 +1,5 @@
import { pasteTextToFocusComposer, shouldRedirectInputToComposer } from "./composerFocusRedirect";
-import { readPastedComposerContext } from "../composerInlineTokenPaste";
+import { pastesCopiedComposerContext } from "../composerInlineTokenPaste";
import { isPasteAsTextShortcut } from "@t3tools/client-runtime/text-paste";
import { useEffect, useRef } from "react";
import { isMacPlatform } from "../../lib/utils";
@@ -38,7 +38,7 @@ export function usePasteToFocusComposer(
const bypassAutoAttachment = Date.now() <= pasteAsTextShortcutUntilRef.current;
pasteAsTextShortcutUntilRef.current = 0;
if (
- ((readPastedComposerContext(clipboardData)?.records.length ?? 0) === 0 &&
+ (!pastesCopiedComposerContext(clipboardData) &&
composerRef.current?.pasteTextAtEnd(text, { bypassAutoAttachment })) ||
composerRef.current?.insertTextAtEnd(text, { clipboardData })
) {
diff --git a/apps/web/src/components/composerInlineTokenPaste.test.ts b/apps/web/src/components/composerInlineTokenPaste.test.ts
index d201cd3adc71a..7ae8b210be116 100644
--- a/apps/web/src/components/composerInlineTokenPaste.test.ts
+++ b/apps/web/src/components/composerInlineTokenPaste.test.ts
@@ -7,7 +7,7 @@ import {
import { threadContextRecord } from "@t3tools/shared/composerContextReferences";
import { describe, expect, it } from "vite-plus/test";
-import { importPastedComposerText } from "./composerInlineTokenPaste";
+import { importPastedComposerText, pastesCopiedComposerContext } from "./composerInlineTokenPaste";
const thread = {
environmentId: EnvironmentId.make("env-1"),
@@ -63,3 +63,34 @@ describe("importPastedComposerText", () => {
).toBe("x\n\ny\nz");
});
});
+
+describe("pastesCopiedComposerContext", () => {
+ it("counts a copied chip but not a bare thread link", () => {
+ const target = threadChipCopyTarget(thread, "Fix the login flow");
+ expect(
+ pastesCopiedComposerContext(
+ clipboard({
+ "text/plain": `See ${target.value}`,
+ [COMPOSER_CONTEXT_CLIPBOARD_MIME]: encodeComposerContextFragment(target.fragment!)!,
+ }),
+ ),
+ ).toBe(true);
+ expect(
+ pastesCopiedComposerContext(
+ clipboard({ "text/plain": "See https://app.t3.codes/threads/env-1/thread-1" }),
+ ),
+ ).toBe(false);
+ });
+
+ it("ignores a copied fragment the pasted text does not reference", () => {
+ const target = threadChipCopyTarget(thread, "Fix the login flow");
+ expect(
+ pastesCopiedComposerContext(
+ clipboard({
+ "text/plain": "See https://app.t3.codes/threads/env-1/thread-2",
+ [COMPOSER_CONTEXT_CLIPBOARD_MIME]: encodeComposerContextFragment(target.fragment!)!,
+ }),
+ ),
+ ).toBe(false);
+ });
+});
diff --git a/apps/web/src/components/composerInlineTokenPaste.ts b/apps/web/src/components/composerInlineTokenPaste.ts
index 0e1a84aa71af2..b55c99457899f 100644
--- a/apps/web/src/components/composerInlineTokenPaste.ts
+++ b/apps/web/src/components/composerInlineTokenPaste.ts
@@ -20,6 +20,10 @@ import { readThreadShell } from "~/state/entities";
const threadTitle = (ref: ScopedThreadRef) => readThreadShell(ref)?.title;
+const readCopiedComposerContext = (clipboardData: Pick) =>
+ decodeComposerContextFragment(clipboardData.getData(COMPOSER_CONTEXT_CLIPBOARD_MIME)) ??
+ decodeComposerContextClipboardHtml(clipboardData.getData("text/html"));
+
// Matches ProseMirror's default clipboard parser, which a custom handlePaste bypasses.
export function readPastedPlainText(clipboardData: Pick): string {
return clipboardData.getData("text/plain").replace(/\r\n?/g, "\n");
@@ -28,11 +32,9 @@ export function readPastedPlainText(clipboardData: Pick
/** Pasted thread links count as context too, so they become chips like a copied chip does. */
export function readPastedComposerContext(
clipboardData: Pick,
+ decodedFragment = readCopiedComposerContext(clipboardData),
): ComposerContextClipboardFragment | null {
const pastedText = clipboardData.getData("text/plain");
- const decodedFragment =
- decodeComposerContextFragment(clipboardData.getData(COMPOSER_CONTEXT_CLIPBOARD_MIME)) ??
- decodeComposerContextClipboardHtml(clipboardData.getData("text/html"));
const threads = threadLinkContextReferences(
pastedText,
decodedFragment?.records ?? [],
@@ -64,6 +66,18 @@ export function readPastedComposerContext(
};
}
+/** Whether the paste references context copied from T3, which folding it into a file would drop. */
+export function pastesCopiedComposerContext(clipboardData: Pick): boolean {
+ const copied = readCopiedComposerContext(clipboardData);
+ if (copied === null) return false;
+ const copiedIds = new Set(copied.records.map((record) => record.contextId));
+ return (
+ readPastedComposerContext(clipboardData, copied)?.records.some((record) =>
+ copiedIds.has(record.contextId),
+ ) ?? false
+ );
+}
+
export function importPastedComposerText(
clipboardData: Pick,
importContextFragment?: (
diff --git a/apps/web/test/fakeEnvironment.ts b/apps/web/test/fakeEnvironment.ts
index 42afe2ef59911..d11a935ea2c72 100644
--- a/apps/web/test/fakeEnvironment.ts
+++ b/apps/web/test/fakeEnvironment.ts
@@ -12,6 +12,7 @@ import {
OrchestrationV2DispatchCommandError,
ORCHESTRATION_PROTOCOL_VERSION,
ORCHESTRATION_V2_WS_METHODS,
+ PROVIDER_SEND_TURN_MAX_FILE_BYTES,
ProjectId,
ProviderInstanceId,
RunId,
@@ -67,7 +68,10 @@ const descriptor = {
// A matching version, since a mismatch adds an update banner a typical user never sees.
serverVersion: APP_VERSION,
orchestrationProtocolVersion: ORCHESTRATION_PROTOCOL_VERSION,
- capabilities: { repositoryIdentity: true },
+ capabilities: {
+ repositoryIdentity: true,
+ fileAttachments: { maxUploadBytes: PROVIDER_SEND_TURN_MAX_FILE_BYTES },
+ },
};
const auth = {
policy: "loopback-browser",