: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
feat(desktop): richer show_actions buttons with kind icons and compose cards (#93353)
Adam Bowkerb9d15525f2d4
diff --git a/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.tsindex 894e59df56c5..34c2ebf5f22c 100644--- a/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts+++ b/products/desktop/packages/agent/src/adapters/local-tools/tools/show-actions.ts@@ -20,6 +20,10 @@ const SHOW_ACTIONS_TOOL_DESCRIPTION ="`compose` opens the new-task composer prefilled with `prompt` (and `repo` " +"when given). The user reads, edits and sends it themselves, so it does NOT " +"start a task and does NOT send anything on click. " ++ "A `compose` action also takes an optional `description`, which no other " ++ "kind accepts. Giving one draws that button as a larger card instead of a " ++ "pill, so use it for the offers that matter most. Write one short sentence " ++ "on what the prefilled task will do, never a restatement of the label. " +"`open_space` opens a channel's feed. `open_canvas` opens a canvas inside a " +"channel, and needs both `channel_id` and `canvas_id`. " +"`open_inbox` opens Self-driving, where PostHog files the reports it writes " +diff --git a/products/desktop/packages/core/src/sessions/showActions.test.ts b/products/desktop/packages/core/src/sessions/showActions.test.tsindex 15d239d0b57b..e38eb5a3d85f 100644--- a/products/desktop/packages/core/src/sessions/showActions.test.ts+++ b/products/desktop/packages/core/src/sessions/showActions.test.ts@@ -29,10 +29,17 @@ describe("isShowActionsCall", () => {});describe("readShowActions", () => {+ // The description is presentation, like the label, so it has to stay out of+ // the action the host turns into a link.it("drops an action the host would refuse to open", () => {const buttons = readShowActions({actions: [- { kind: "compose", label: "Add PostHog", prompt: "/instrument" },+ {+ kind: "compose",+ label: "Add PostHog",+ description: "Instruments the app so events start arriving",+ prompt: "/instrument",+ },{ kind: "open_space", label: "Open the space", channel_id: " " },{ kind: "open_website", label: "Go", url: "https://evil.example" },],@@ -41,6 +48,7 @@ describe("readShowActions", () => {expect(buttons).toEqual([{label: "Add PostHog",+ description: "Instruments the app so events start arriving",action: { kind: "compose", prompt: "/instrument" },},]);diff --git a/products/desktop/packages/shared/src/agent-actions.ts b/products/desktop/packages/shared/src/agent-actions.tsindex 9a9bdaa5bdd8..570f34681025 100644--- a/products/desktop/packages/shared/src/agent-actions.ts+++ b/products/desktop/packages/shared/src/agent-actions.ts@@ -68,12 +68,27 @@ const labelSchema = z"Button text. Short and in sentence case, naming what the button does.",);+const descriptionSchema = z+ .string()+ .trim()+ .min(1)+ .max(140)+ .describe(+ "Optional. One short sentence saying what the prefilled task will do. " ++ "Never a restatement of the label.",+ );+/**- * One button as the agent offers it: an action plus the text on it. `label`- * never reaches a link, which is why {@link agentActionSchema} leaves it out.+ * One button as the agent offers it: an action plus the text on it. `label` and+ * `description` never reach a link, which is why {@link agentActionSchema}+ * leaves them out.*/export const showActionSchema = z.discriminatedUnion("kind", [- z.object({ ...composeFields, label: labelSchema }),+ z.object({+ ...composeFields,+ label: labelSchema,+ description: descriptionSchema.optional(),+ }),z.object({ ...openSpaceFields, label: labelSchema }),z.object({ ...openCanvasFields, label: labelSchema }),z.object({ ...openInboxFields, label: labelSchema }),@@ -86,11 +101,18 @@ export const openAgentActionInput = z.object({ action: agentActionSchema });/** One button as the renderer draws it: its text, and the verb behind it. */export interface ShowActionButton {label: string;+ description?: string;action: AgentAction;}/** Split a button back into the text on it and the verb behind it. */export function splitShowAction(button: ShowAction): ShowActionButton {+ // Only compose carries a description, so the two branches keep the rest of+ // the object typed as an action the host will accept.+ if (button.kind === "compose") {+ const { label, description, ...action } = button;+ return { label, description, action };+ }const { label, ...action } = button;return { label, action };}diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.stories.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.stories.tsxnew file mode 100644index 000000000000..65f0364fdd21--- /dev/null+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.stories.tsx@@ -0,0 +1,82 @@+import { ShowActionsRow } from "@posthog/ui/features/sessions/components/session-update/ShowActionsRow";+import type { ToolCall } from "@posthog/ui/features/sessions/types";+import type { Meta, StoryObj } from "@storybook/react-vite";++function showActionsCall(actions: unknown[]): ToolCall {+ return {+ toolCallId: "story-show-actions",+ rawInput: { actions },+ status: "completed",+ } as ToolCall;+}++const meta: Meta<typeof ShowActionsRow> = {+ title: "Features/Sessions/ShowActionsRow",+ component: ShowActionsRow,+ parameters: {+ layout: "padded",+ },+};++export default meta;+type Story = StoryObj<typeof ShowActionsRow>;++export const Pills: Story = {+ args: {+ toolCall: showActionsCall([+ {+ kind: "compose",+ label: "Fix the login bug",+ prompt: "Fix the login redirect loop on session expiry",+ },+ { kind: "open_space", label: "Open #growth", channel_id: "chan-1" },+ {+ kind: "open_canvas",+ label: "Explore PostHog Desktop",+ channel_id: "chan-1",+ canvas_id: "canvas-1",+ },+ { kind: "open_inbox", label: "Review findings" },+ ]),+ turnComplete: true,+ },+};++// A compose action with a description renders as a card; the rest stay pills.+export const CardsAndPills: Story = {+ args: {+ toolCall: showActionsCall([+ {+ kind: "compose",+ label: "Add PostHog to your app",+ description:+ "Opens a task that instruments your codebase and files a PR to review",+ prompt: "Add PostHog analytics to my app and open a pull request",+ },+ {+ kind: "compose",+ label: "Set up error tracking",+ description: "Wires exception capture into your existing SDK setup",+ prompt: "Enable PostHog error tracking in my app",+ },+ { kind: "open_inbox", label: "Review findings" },+ { kind: "open_space", label: "Open #growth", channel_id: "chan-1" },+ ]),+ turnComplete: true,+ },+};++export const SingleCard: Story = {+ args: {+ toolCall: showActionsCall([+ {+ kind: "compose",+ label: "Add PostHog to your app",+ description:+ "Opens a task that instruments your codebase and files a PR to review",+ prompt: "Add PostHog analytics to my app and open a pull request",+ },+ ]),+ turnComplete: true,+ },+};diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsxindex 4e1556e1835d..9aa13131d70a 100644--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.test.tsx@@ -2,7 +2,7 @@ import type { ToolCall } from "@posthog/ui/features/sessions/types";import { QueryClient, QueryClientProvider } from "@tanstack/react-query";import { render, screen, waitFor } from "@testing-library/react";import userEvent from "@testing-library/user-event";-import { describe, expect, it, vi } from "vitest";+import { beforeEach, describe, expect, it, vi } from "vitest";const openAgentAction = vi.hoisted(() => vi.fn());@@ -28,20 +28,54 @@ function renderCard(actions: unknown[]) {}describe("ShowActionsRow", () => {+ beforeEach(() => {+ openAgentAction.mockClear();+ });+it("draws a button per usable action and drops one that cannot open anything", () => {renderCard([{ kind: "compose", label: "Fix the bug", prompt: "Fix the login bug" },+ {+ kind: "compose",+ label: "Add PostHog",+ description: "Instruments the app and opens a task to review it",+ prompt: "/instrument",+ },{ kind: "open_space", label: "Open the space", channel_id: "chan" },// No canvas id, so this one could only ever build a broken link.{ kind: "open_canvas", label: "Open the canvas", channel_id: "chan" },]);- expect(screen.getAllByRole("button")).toHaveLength(2);+ expect(screen.getAllByRole("button")).toHaveLength(3);expect(screen.getByText("Fix the bug")).toBeTruthy();+ expect(screen.getByText("Add PostHog")).toBeTruthy();+ expect(+ screen.getByText("Instruments the app and opens a task to review it"),+ ).toBeTruthy();expect(screen.getByText("Open the space")).toBeTruthy();expect(screen.queryByText("Open the canvas")).toBeNull();});+ it("keeps the order the agent supplied, even with a pill before a card", () => {+ renderCard([+ { kind: "open_space", label: "Open the space", channel_id: "chan" },+ {+ kind: "compose",+ label: "Add PostHog",+ description: "Instruments the app and opens a task to review it",+ prompt: "/instrument",+ },+ { kind: "open_inbox", label: "Review findings" },+ ]);++ const buttons = screen.getAllByRole("button");+ expect(buttons.map((button) => button.textContent)).toEqual([+ "Open the space",+ "Add PostHogInstruments the app and opens a task to review it",+ "Review findings",+ ]);+ });+it("hands the host a typed action, never a url", async () => {renderCard([{ kind: "open_space", label: "Open the space", channel_id: "chan" },@@ -54,4 +88,29 @@ describe("ShowActionsRow", () => {action: { kind: "open_space", channel_id: "chan" },});});++ // A description is presentation, like the label, so the host must never be+ // handed one: it would ride into the url the host builds.+ it("keeps the description off the action it sends the host", async () => {+ renderCard([+ {+ kind: "compose",+ label: "Fix the bug",+ description: "Opens a task that patches the login redirect",+ prompt: "Fix the login bug",+ },+ ]);++ expect(screen.getByText("Fix the bug")).toBeTruthy();+ expect(+ screen.getByText("Opens a task that patches the login redirect"),+ ).toBeTruthy();++ await userEvent.click(screen.getByText("Fix the bug"));++ await waitFor(() => expect(openAgentAction).toHaveBeenCalled());+ expect(openAgentAction.mock.calls[0]?.[0]).toEqual({+ action: { kind: "compose", prompt: "Fix the login bug" },+ });+ });});diff --git a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsxindex 983929c48631..0a1b73669c90 100644--- a/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx+++ b/products/desktop/packages/ui/src/features/sessions/components/session-update/ShowActionsRow.tsx@@ -1,10 +1,30 @@+import {+ Hash,+ type Icon,+ Layout,+ PencilSimple,+ Tray,+} from "@phosphor-icons/react";import { readShowActions } from "@posthog/core/sessions/showActions";import { useHostTRPC } from "@posthog/host-router/react";-import { Button } from "@posthog/quill";+import { Button, Text } from "@posthog/quill";+import type { ShowActionButton } from "@posthog/shared";import type { ToolViewProps } from "@posthog/ui/features/sessions/components/session-update/toolCallUtils";import { toast } from "@posthog/ui/primitives/toast";import { useMutation } from "@tanstack/react-query";+// The UI picks the icon and accent from the verb, so the agent never gets to+// choose either and every button of a kind looks the same everywhere.+const ACTION_LOOKS: Record<+ ShowActionButton["action"]["kind"],+ { icon: Icon; color: string }+> = {+ compose: { icon: PencilSimple, color: "blue" },+ open_canvas: { icon: Layout, color: "purple" },+ open_inbox: { icon: Tray, color: "orange" },+ open_space: { icon: Hash, color: "green" },+};+/*** The buttons a `show_actions` call offered, drawn where the agent offered them.* A click sends the typed action to the host, which builds the link and opens@@ -26,21 +46,102 @@ export function ShowActionsRow({ toolCall }: ToolViewProps) {if (buttons.length === 0) return null;+ // Consecutive same-shape buttons form one run, so the agent's order+ // survives: a pill before a card still renders before that card.+ const runs: ShowActionButton[][] = [];+ for (const button of buttons) {+ const isCard = Boolean(button.description);+ const lastRun = runs.at(-1);+ if (lastRun && Boolean(lastRun[0].description) === isCard) {+ lastRun.push(button);+ } else {+ runs.push([button]);+ }+ }+// No surrounding card: the buttons sit in the conversation, which already// frames them. A box around them would draw a second frame around nothing.return (- <div className="flex flex-wrap gap-2">- {buttons.map(({ label, action }, index) => (- <Button- key={`${index}-${label}`}- variant="outline"- size="sm"- disabled={openAction.isPending}- onClick={() => openAction.mutate({ action })}- >- {label}- </Button>- ))}+ <div className="flex flex-col gap-2">+ {runs.map((run) =>+ run[0].description ? (+ <div+ key={`${run[0].label}-${run[0].action.kind}`}+ className="flex max-w-sm flex-col gap-2"+ >+ {run.map(({ label, description, action }) => {+ const { icon: ActionIcon, color } = ACTION_LOOKS[action.kind];+ return (+ <button+ key={`${label}-${action.kind}`}+ type="button"+ disabled={openAction.isPending}+ onClick={() => openAction.mutate({ action })}+ style={+ {+ "--card-hover-border": `var(--${color}-6)`,+ } as React.CSSProperties+ }+ className="flex w-full cursor-pointer items-start gap-2.5 rounded-xl border border-(--gray-a3) bg-(--color-panel-solid) px-2.5 py-2 text-left shadow-[0_1px_3px_rgba(0,0,0,0.04),0_1px_2px_rgba(0,0,0,0.02)] transition-[border-color,box-shadow] hover:border-(--card-hover-border) hover:shadow-[0_2px_8px_rgba(0,0,0,0.06),0_1px_3px_rgba(0,0,0,0.04)] disabled:cursor-default disabled:opacity-60"+ >+ <div+ className="flex h-6 w-6 shrink-0 items-center justify-center rounded-md"+ style={{ backgroundColor: `var(--${color}-3)` }}+ >+ <ActionIcon+ size={14}+ weight="duotone"+ color={`var(--${color}-9)`}+ aria-hidden+ />+ </div>+ <div className="flex min-w-0 flex-1 flex-col gap-1">+ <Text+ size="xs"+ weight="medium"+ className="min-w-0 truncate text-(--gray-12)"+ >+ {label}+ </Text>+ <Text+ size="xs"+ className="line-clamp-1 text-(--gray-11) leading-normal"+ >+ {description}+ </Text>+ </div>+ </button>+ );+ })}+ </div>+ ) : (+ <div+ key={`${run[0].label}-${run[0].action.kind}`}+ className="flex flex-wrap gap-2"+ >+ {run.map(({ label, action }) => {+ const { icon: ActionIcon, color } = ACTION_LOOKS[action.kind];+ return (+ <Button+ key={`${label}-${action.kind}`}+ variant="outline"+ size="sm"+ disabled={openAction.isPending}+ onClick={() => openAction.mutate({ action })}+ >+ <ActionIcon+ size={14}+ weight="duotone"+ color={`var(--${color}-9)`}+ aria-hidden+ />+ {label}+ </Button>+ );+ })}+ </div>+ ),+ )}</div>);}