:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): copy only agent responses (#79154)
Matt Puaa8439035e6ac
diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThread.tsx b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThread.tsxindex 0552dff4b863..63c91490154d 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThread.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/ChatThread.tsx@@ -318,7 +318,7 @@ function formatTimestamp(ts: number): string {/*** Hover-revealed footer under a completed agent turn: the turn's timestamp plus a button copying- * the whole turn. Rendered right-aligned under agent-side content — the end-aligned user bubble+ * the agent response. Rendered right-aligned under agent-side content — the end-aligned user bubble* keeps its own footer — inside a `group` container, so it fades in only while that turn is* hovered. Once per turn rather than per row, which was too noisy.*/@@ -719,11 +719,7 @@ const ThreadRow = memo(function ThreadRow({</div><TurnFootertimestamp={completedTurnTimestamp(item)}- copyText={- buildTurnCopyText(- item.prompt ? [item.prompt, ...item.items] : item.items,- ) ?? undefined- }+ copyText={buildTurnCopyText(item.items) ?? undefined}/></ChatMessageScrollerItem>);diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.test.ts b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.test.tsindex 5da454893568..46ecee662cf4 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.test.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.test.ts@@ -115,7 +115,7 @@ describe("flattenTurnRows", () => {]);});- it("leads the copy text with the prompt that opened the turn", () => {+ it("copies only the agent response", () => {const done = agentTurn("d",[@@ -127,9 +127,7 @@ describe("flattenTurnRows", () => {],userMessage("u1"),);- expect(flattenTurnRows([done]).at(-1)?.turnCopyText).toBe(- "msg u1\n\nreply",- );+ expect(flattenTurnRows([done]).at(-1)?.turnCopyText).toBe("reply");});it("leaves copy text off a turn that is still streaming", () => {diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.ts b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.tsindex ac01f36a443d..b73c829c1554 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/threadVirtualization.ts@@ -84,7 +84,7 @@ export interface FlatThreadRow {isTrailingInTurn: boolean;/** Set on the last row of a completed turn; renders the turn's hover timestamp under it. */turnTimestamp?: number;- /** Set alongside {@link turnTimestamp}: the whole turn as plain text, for its copy button. */+ /** Set alongside {@link turnTimestamp}: the agent response as plain text, for its copy button. */turnCopyText?: string;}@@ -113,9 +113,7 @@ export function flattenTurnRows(rows: TurnRow[]): FlatThreadRow[] {const copyText =timestamp == null? undefined- : (buildTurnCopyText(- row.prompt ? [row.prompt, ...row.items] : row.items,- ) ?? undefined);+ : (buildTurnCopyText(row.items) ?? undefined);for (let i = 0; i < row.items.length; i++) {const item = row.items[i];const isTrailing = i === row.items.length - 1;diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.test.ts b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.test.tsindex 01ead181622e..fa853de02c38 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.test.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.test.ts@@ -57,7 +57,7 @@ describe("buildTurnCopyText", () => {expect(text).toBe("first paragraph\n\nsecond paragraph");});- it("skips tool calls, tool groups and other non-prose rows", () => {+ it("skips user prompts, tool calls, tool groups and other non-agent rows", () => {const text = buildTurnCopyText([userMessage("u1", "do the thing"),toolCall("t1"),@@ -65,13 +65,13 @@ describe("buildTurnCopyText", () => {agentText("a1", "done"),]);- expect(text).toBe("do the thing\n\ndone");+ expect(text).toBe("done");});it.each([["no items", [] as ConversationItem[]],["tools only", [toolCall("t1"), toolGroup("g1")]],- ["blank prose", [userMessage("u1", " "), agentText("a1", "\n")]],+ ["blank agent prose", [userMessage("u1", "prompt"), agentText("a1", "\n")]],])("returns null when there is nothing to copy: %s", (_label, items) => {expect(buildTurnCopyText(items)).toBeNull();});diff --git a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.ts b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.tsindex 31c11715bf9d..3df7da176e3b 100644--- a/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.ts+++ b/products/desktop/packages/ui/src/features/sessions/components/chat-thread/turnCopyText.ts@@ -2,10 +2,10 @@ import type { ConversationItem } from "@posthog/ui/features/sessions/components/import type { ToolGroupItem } from "@posthog/ui/features/sessions/components/chat-thread/ToolGroup";/**- * Plain-text transcript of a turn's rows: user prompts and agent prose, in order.+ * Plain-text transcript of a turn's agent prose, in order.*- * Tool calls, thoughts and status rows are left out — this is for pasting an answer somewhere else,- * not for reproducing the run. Returns null when the rows carry no prose.+ * User prompts, tool calls, thoughts and status rows are left out — this is for pasting an answer+ * somewhere else, not for reproducing the run. Returns null when the rows carry no prose.*/export function buildTurnCopyText(items: Array<ConversationItem | ToolGroupItem>,@@ -13,11 +13,6 @@ export function buildTurnCopyText(const parts: string[] = [];for (const item of items) {- if (item.type === "user_message") {- const content = item.content.trim();- if (content) parts.push(content);- continue;- }if (item.type !== "session_update") continue;const update = item.update;if (update.sessionUpdate !== "agent_message_chunk") continue;