Skip to content

: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.

feat(desktop): make PostHog object references actionable (#85851)

Shy Alter538e1af7bbc9
diff --git a/products/desktop/packages/core/src/message-editor/content.test.ts b/products/desktop/packages/core/src/message-editor/content.test.ts
index c7aac6c2494e..e961ef496b4f 100644
--- a/products/desktop/packages/core/src/message-editor/content.test.ts
+++ b/products/desktop/packages/core/src/message-editor/content.test.ts
@@ -127,6 +127,73 @@ describe("xmlToContent", () => {
]);
});
+ it.each([
+ ["insight", "9pQx3", '<insight id="9pQx3" />'],
+ [
+ "hogql",
+ "SELECT count() FROM events WHERE value < 3",
+ "<hogql>SELECT count() FROM events WHERE value &lt; 3</hogql>",
+ ],
+ ] as const)(
+ "serializes a %s object chip with its exact reference",
+ (objectKind, id, expected) => {
+ const content: EditorContent = {
+ segments: [
+ {
+ type: "chip",
+ chip: {
+ type: "posthog_object",
+ objectKind,
+ id,
+ label: "Referenced object",
+ },
+ },
+ ],
+ };
+
+ expect(contentToXml(content)).toBe(expected);
+ },
+ );
+
+ it("restores a hogql chip's exact query when parsing serialized content back", () => {
+ const query =
+ "SELECT count() FROM events WHERE value < 3 AND note = 'a & b'";
+ const serialized = contentToXml({
+ segments: [
+ {
+ type: "chip",
+ chip: {
+ type: "posthog_object",
+ objectKind: "hogql",
+ id: query,
+ label: "Referenced object",
+ },
+ },
+ ],
+ });
+
+ const { segments } = xmlToContent(serialized);
+ expect(segments).toHaveLength(1);
+ expect(segments[0]).toMatchObject({
+ type: "chip",
+ chip: { type: "posthog_object", objectKind: "hogql", id: query },
+ });
+ });
+
+ it("parses a dashboard tag into a PostHog object chip", () => {
+ expect(xmlToContent('<dashboard id="17" />').segments).toEqual([
+ {
+ type: "chip",
+ chip: {
+ type: "posthog_object",
+ objectKind: "dashboard",
+ id: "17",
+ label: "17",
+ },
+ },
+ ]);
+ });
+
it("preserves surrounding text around chips", () => {
const result = xmlToContent(
'please review <file path="src/a.ts" /> and <file path="src/b.ts" />',
diff --git a/products/desktop/packages/core/src/message-editor/content.ts b/products/desktop/packages/core/src/message-editor/content.ts
index 8bdf35b75b0b..151e3163cc65 100644
--- a/products/desktop/packages/core/src/message-editor/content.ts
+++ b/products/desktop/packages/core/src/message-editor/content.ts
@@ -1,6 +1,38 @@
-import { escapeXmlAttr, type UploadableSkillSource } from "@posthog/shared";
+import {
+ escapeXmlAttr,
+ type UploadableSkillSource,
+ unescapeXmlAttr,
+} from "@posthog/shared";
import { isUploadableSkillSource, parseXmlAttrs } from "./skillTags";
+export const POSTHOG_OBJECT_KINDS = [
+ "insight",
+ "hogql",
+ "dashboard",
+ "error",
+ "replay",
+ "flag",
+ "experiment",
+ "survey",
+ "ticket",
+ "trace",
+ "eval",
+ "event",
+ "cohort",
+ "action",
+ "person",
+] as const;
+
+export type PostHogObjectKind = (typeof POSTHOG_OBJECT_KINDS)[number];
+
+const POSTHOG_OBJECT_KIND_SET: ReadonlySet<string> = new Set(
+ POSTHOG_OBJECT_KINDS,
+);
+
+export function isPostHogObjectKind(value: string): value is PostHogObjectKind {
+ return POSTHOG_OBJECT_KIND_SET.has(value);
+}
+
export interface MentionChip {
type:
| "file"
@@ -10,10 +42,12 @@ export interface MentionChip {
| "experiment"
| "insight"
| "feature_flag"
+ | "posthog_object"
| "github_issue"
| "github_pr";
id: string;
label: string;
+ objectKind?: PostHogObjectKind;
pastedText?: boolean;
chipId?: string;
skillPath?: string;
@@ -41,6 +75,7 @@ export function contentToPlainText(content: EditorContent): string {
if (chip.type === "file" || chip.type === "folder")
return `@${chip.label}`;
if (chip.type === "command") return `/${chip.label}`;
+ if (chip.type === "posthog_object") return chip.label;
return `@${chip.label}`;
})
.join("");
@@ -50,6 +85,13 @@ function isAbsolutePathLike(p: string): boolean {
return p.startsWith("/") || p.startsWith("~") || /^[A-Za-z]:[\\/]/.test(p);
}
+function escapeXmlText(value: string): string {
+ return value
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;");
+}
+
export function contentToXml(content: EditorContent): string {
const inlineFilePaths = new Set<string>();
const parts = content.segments.map((seg) => {
@@ -79,6 +121,11 @@ export function contentToXml(content: EditorContent): string {
return `<insight id="${escapedId}" />`;
case "feature_flag":
return `<feature_flag id="${escapedId}" />`;
+ case "posthog_object":
+ if (!chip.objectKind) return chip.label;
+ return chip.objectKind === "hogql"
+ ? `<hogql>${escapeXmlText(chip.id)}</hogql>`
+ : `<${chip.objectKind} id="${escapedId}" />`;
case "github_issue":
case "github_pr": {
const labelMatch = chip.label.match(/^#(\d+)(?:\s*-\s*(.*))?$/);
@@ -103,8 +150,11 @@ export function contentToXml(content: EditorContent): string {
return parts.join("");
}
+// Self-closing chip tags, plus the paired `<hogql>...</hogql>` form whose SQL
+// rides in the tag body. contentToXml XML-escapes that body, so the body is
+// captured here and decoded on the way into a chip.
const CHIP_TAG_REGEX =
- /<(file|folder|skill|error|experiment|insight|feature_flag|github_issue|github_pr)\b([^>]*?)\s*\/>/g;
+ /<(file|folder|skill|error|experiment|insight|feature_flag|dashboard|replay|flag|survey|ticket|trace|eval|event|cohort|action|person|github_issue|github_pr)\b([^>]*?)\s*\/>|<hogql\b[^>]*>([\s\S]*?)<\/hogql>/g;
export function deriveFileLabel(filePath: string): string {
const segments = filePath.split("/").filter(Boolean);
@@ -150,6 +200,26 @@ function chipFromTag(tag: string, rawAttrs: string): MentionChip | null {
if (!id) return null;
return { type: tag, id, label: id };
}
+ case "dashboard":
+ case "replay":
+ case "flag":
+ case "survey":
+ case "ticket":
+ case "trace":
+ case "eval":
+ case "event":
+ case "cohort":
+ case "action":
+ case "person": {
+ const id = attrs.id;
+ if (!id) return null;
+ return {
+ type: "posthog_object",
+ objectKind: tag,
+ id,
+ label: id,
+ };
+ }
case "github_issue":
case "github_pr": {
const number = attrs.number ?? "";
@@ -164,13 +234,30 @@ function chipFromTag(tag: string, rawAttrs: string): MentionChip | null {
}
}
+// A `<hogql>` reference carries the SQL as its tag body, XML-escaped by
+// contentToXml. Decode it back to the raw query so editing a serialized message
+// (e.g. a queued one) restores the chip instead of leaking `<hogql>...&lt;...`
+// markup and a corrupted query.
+function hogqlChipFromBody(body: string): MentionChip | null {
+ const query = unescapeXmlAttr(body).trim();
+ if (!query) return null;
+ return {
+ type: "posthog_object",
+ objectKind: "hogql",
+ id: query,
+ label: query,
+ };
+}
+
export function xmlToContent(xml: string): EditorContent {
const segments: EditorContent["segments"] = [];
let lastIndex = 0;
for (const match of xml.matchAll(CHIP_TAG_REGEX)) {
const matchIndex = match.index ?? 0;
- const chip = chipFromTag(match[1], match[2] ?? "");
+ const chip = match[1]
+ ? chipFromTag(match[1], match[2] ?? "")
+ : hogqlChipFromBody(match[3] ?? "");
if (!chip) continue;
if (matchIndex > lastIndex) {
diff --git a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.stories.tsx b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.stories.tsx
index 637e288262ae..7b8deb653345 100644
--- a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.stories.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.stories.tsx
@@ -81,6 +81,7 @@ export const HoverCardStates: Story = {
target={{ kind: "insight", id: "9pQx3" }}
url={null}
preview={undefined}
+ onExpand={() => {}}
>
Checkout funnel
</EvidenceHoverCard>
@@ -93,6 +94,7 @@ export const HoverCardStates: Story = {
title: "Coupon → purchase conversion",
detail: "Funnel conversion, last 30 days",
}}
+ onExpand={() => {}}
>
Checkout funnel
</EvidenceHoverCard>
@@ -106,6 +108,7 @@ export const HoverCardStates: Story = {
detail: "Enabled · New checkout rollout",
facts: ["100% rollout", "Used by 1 experiment"],
}}
+ onExpand={() => {}}
>
new-checkout-flow
</EvidenceHoverCard>
@@ -125,6 +128,7 @@ export const HoverCardStates: Story = {
render: "line",
},
}}
+ onExpand={() => {}}
>
active users per day
</EvidenceHoverCard>
@@ -134,6 +138,7 @@ export const HoverCardStates: Story = {
target={{ kind: "ticket", id: "conv_88" }}
url="https://us.posthog.com/project/2/insights/9pQx3"
preview={null}
+ onExpand={() => {}}
>
9 “coupon” tickets
</EvidenceHoverCard>
diff --git a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.test.tsx b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.test.tsx
index 383eabff2585..465ce94a684b 100644
--- a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.test.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.test.tsx
@@ -1,3 +1,6 @@
+import { POSTHOG_OBJECT_KINDS } from "@posthog/core/message-editor/content";
+import { useDraftStore } from "@posthog/ui/features/message-editor/draftStore";
+import { SessionTaskIdProvider } from "@posthog/ui/features/sessions/useSessionTaskId";
import { Theme } from "@radix-ui/themes";
import { fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -41,6 +44,10 @@ function signIn() {
afterEach(() => {
useAuthStore.setState({ authState: ANONYMOUS_AUTH_STATE });
+ const actions = useDraftStore.getState().actions;
+ actions.setDraft("task-1", null);
+ actions.clearPendingInsert("task-1");
+ actions.clearFocusRequest("task-1");
});
describe("EvidenceRefChip", () => {
@@ -106,7 +113,6 @@ describe("EvidenceRefChip", () => {
// real elements a keyboard user can Tab to.
const dialog = screen.getByRole("dialog");
expect(dialog).toBeDefined();
- expect(dialog.classList.contains("dark")).toBe(false);
expect(
screen.getByRole("button", { name: /Open in PostHog/ }),
).toBeDefined();
@@ -127,6 +133,72 @@ describe("EvidenceRefChip", () => {
fireEvent.click(trigger);
expect(screen.getByRole("dialog")).toBeDefined();
});
+
+ it.each(POSTHOG_OBJECT_KINDS)(
+ "offers the compact composer action for %s references",
+ (kind) => {
+ renderInTheme(
+ <SessionTaskIdProvider taskId="task-1">
+ <EvidenceRefChip target={{ kind, id: `${kind}-1` }}>
+ {kind} reference
+ </EvidenceRefChip>
+ </SessionTaskIdProvider>,
+ );
+
+ fireEvent.click(
+ screen.getByRole("button", { name: `${kind} reference` }),
+ );
+ expect(
+ screen.getByRole("button", { name: "Ask about this" }),
+ ).toBeDefined();
+ },
+ );
+
+ it("hides the composer action outside a task conversation", () => {
+ renderInTheme(
+ <EvidenceRefChip target={{ kind: "flag", id: "new-checkout" }}>
+ new-checkout
+ </EvidenceRefChip>,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "new-checkout" }));
+ expect(screen.queryByRole("button", { name: "Ask about this" })).toBeNull();
+ });
+
+ it("adds the exact object reference after an existing composer draft", () => {
+ signIn();
+ useDraftStore.getState().actions.setDraft("task-1", {
+ segments: [{ type: "text", text: "Compare the variants" }],
+ });
+ renderInTheme(
+ <SessionTaskIdProvider taskId="task-1">
+ <EvidenceRefChip target={{ kind: "insight", id: "9pQx3" }}>
+ Checkout funnel
+ </EvidenceRefChip>
+ </SessionTaskIdProvider>,
+ );
+
+ fireEvent.focus(screen.getByRole("link", { name: "Checkout funnel" }));
+ fireEvent.click(screen.getByRole("button", { name: "Ask about this" }));
+
+ expect(useDraftStore.getState().pendingInsert["task-1"]).toEqual({
+ segments: [
+ { type: "text", text: "\n\nAsk about " },
+ {
+ type: "chip",
+ chip: {
+ type: "posthog_object",
+ objectKind: "insight",
+ id: "9pQx3",
+ label: "Insight: Checkout funnel",
+ },
+ },
+ { type: "text", text: " " },
+ ],
+ });
+ expect(useDraftStore.getState().focusRequested["task-1"]).toBeDefined();
+ expect(screen.queryByRole("dialog")).toBeNull();
+ });
});
describe("EvidenceHoverCard", () => {
@@ -156,6 +228,27 @@ describe("EvidenceHoverCard", () => {
}
});
+ it("copies the exact reference from the existing footer", () => {
+ const writeText = vi.fn().mockResolvedValue(undefined);
+ Object.defineProperty(navigator, "clipboard", {
+ configurable: true,
+ value: { writeText },
+ });
+ renderInTheme(
+ <EvidenceHoverCard
+ target={{ kind: "insight", id: "9pQx3" }}
+ url={null}
+ preview={{ title: "Checkout funnel" }}
+ >
+ Checkout funnel
+ </EvidenceHoverCard>,
+ );
+
+ fireEvent.click(screen.getByRole("button", { name: "Copy reference" }));
+
+ expect(writeText).toHaveBeenCalledWith("9pQx3");
+ });
+
it("draws a sparkline and headline for a series preview and opens on click", () => {
const onOpen = vi.fn();
renderInTheme(
diff --git a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.tsx b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.tsx
index 4c738df4e1cc..62563d4968ee 100644
--- a/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.tsx
+++ b/products/desktop/packages/ui/src/features/editor/components/EvidenceRefChip.tsx
@@ -1,15 +1,22 @@
import { Popover } from "@base-ui/react/popover";
+import { CheckIcon, CopyIcon } from "@phosphor-icons/react";
+import { isPostHogObjectKind } from "@posthog/core/message-editor/content";
+import { Button } from "@posthog/quill";
import { getCloudUrlFromRegion } from "@posthog/shared";
import { type MouseEvent, type ReactNode, useId, useState } from "react";
import { useOptionalAuthenticatedClient } from "../../../features/auth/authClient";
import { useAuthStateValue } from "../../../features/auth/store";
+import { useDraftStore } from "../../../features/message-editor/draftStore";
+import { useSessionTaskId } from "../../../features/sessions/useSessionTaskId";
import { useAuthenticatedQuery } from "../../../hooks/useAuthenticatedQuery";
+import { useCopy } from "../../../primitives/useCopy";
import { openExternalUrl } from "../../../shell/openExternal";
import {
type EvidenceLinkTarget,
evidenceWebPath,
} from "../../../utils/evidenceLinks";
import { getObjectKind } from "../../../utils/objectKinds";
+import { buildEvidenceComposerContent } from "../evidenceComposer";
import {
type EvidenceCardData,
fetchEvidencePreview,
@@ -156,17 +163,20 @@ export function EvidenceHoverCard({
url,
preview,
onOpen = openExternalUrl,
+ onExpand,
}: {
target: EvidenceLinkTarget;
children: ReactNode;
url: string | null;
preview: EvidenceCardData | null | undefined;
onOpen?: (url: string) => void;
+ onExpand?: (label: string) => void;
}) {
const meta = getObjectKind(target.kind);
const KindIcon = meta.icon;
const isQuery = target.kind === "hogql";
const [showQuery, setShowQuery] = useState(false);
+ const { copied, copy } = useCopy();
return (
<div className="w-80 p-3.5">
<div className="flex items-center gap-1.5 text-(--gray-9) text-[10.5px]">
@@ -252,28 +262,50 @@ export function EvidenceHoverCard({
</div>
)}
<div className="mt-3 flex items-center justify-between gap-3 text-[10.5px]">
- {isQuery ? (
- <button
- type="button"
- onClick={() => setShowQuery((open) => !open)}
- className="min-w-0 cursor-pointer truncate border-none bg-transparent p-0 text-left font-mono text-(--gray-8) transition-colors hover:text-(--gray-11)"
- >
- {showQuery ? "Hide query" : target.id}
- </button>
- ) : (
- <span className="truncate font-mono text-(--gray-8)">
- {target.id}
- </span>
- )}
- {url && (
+ <div className="flex min-w-0 items-center gap-0.5">
+ {isQuery ? (
+ <button
+ type="button"
+ onClick={() => setShowQuery((open) => !open)}
+ className="min-w-0 cursor-pointer truncate border-none bg-transparent p-0 text-left font-mono text-(--gray-8) transition-colors hover:text-(--gray-11)"
+ >
+ {showQuery ? "Hide query" : target.id}
+ </button>
+ ) : (
+ <span className="truncate font-mono text-(--gray-8)">
+ {target.id}
+ </span>
+ )}
<button
type="button"
- onClick={() => onOpen(url)}
- className="shrink-0 cursor-pointer border-none bg-transparent p-0 text-(--gray-10) text-[10.5px] transition-colors hover:text-(--gray-12)"
+ aria-label={copied ? "Reference copied" : "Copy reference"}
+ onClick={() => copy(target.id)}
+ className="inline-flex size-5 shrink-0 cursor-pointer items-center justify-center rounded-[4px] border-none bg-transparent p-0 text-(--gray-9) transition-colors hover:bg-(--gray-a3) hover:text-(--gray-12)"
>
- Open in PostHog ↗
+ {copied ? <CheckIcon size={11} /> : <CopyIcon size={11} />}
</button>
- )}
+ </div>
+ <div className="flex shrink-0 items-center gap-1">
+ {onExpand && (
+ <Button
+ variant="link"
+ size="xs"
+ onClick={() =>
+ onExpand(
+ preview?.title ??
+ (typeof children === "string" ? children : target.id),
+ )
+ }
+ >
+ Ask about this
+ </Button>
+ )}
+ {url && (
+ <Button variant="link-muted" size="xs" onClick={() => onOpen(url)}>
+ Open in PostHog ↗
+ </Button>
+ )}
+ </div>
</div>
</div>
);
@@ -288,10 +320,12 @@ function EvidenceHoverCardLoader({
target,
children,
url,
+ onExpand,
}: {
target: EvidenceLinkTarget;
children: ReactNode;
url: string | null;
+ onExpand?: (label: string) => void;
}) {
const client = useOptionalAuthenticatedClient();
const query = useAuthenticatedQuery(
@@ -325,6 +359,7 @@ function EvidenceHoverCardLoader({
target={target}
url={url ?? resolvedUrl}
preview={preview}
+ onExpand={onExpand}
>
{children}
</EvidenceHoverCard>
@@ -350,7 +385,26 @@ export function EvidenceRefChip({
const meta = getObjectKind(target.kind);
const KindIcon = meta.icon;
const url = useEvidenceUrl(target.kind, target.id);
+ const taskId = useSessionTaskId();
+ const objectKind = isPostHogObjectKind(target.kind) ? target.kind : null;
const [open, setOpen] = useState(false);
+ const expand =
+ taskId && objectKind
+ ? (label: string) => {
+ const actions = useDraftStore.getState().actions;
+ actions.insertPendingContent(
+ taskId,
+ buildEvidenceComposerContent({
+ kind: objectKind,
+ id: target.id,
+ label: `${meta.kindLabel}: ${label}`,
+ currentDraft: actions.getDraft(taskId),
+ }),
+ );
+ actions.requestFocus(taskId);
+ setOpen(false);
+ }
+ : undefined;
const openInPostHog = (event: MouseEvent<HTMLAnchorElement>) => {
event.preventDefault();
@@ -410,10 +464,14 @@ export function EvidenceRefChip({
<Popover.Positioner side="top" sideOffset={8} className="z-[9999]">
<Popover.Popup
data-testid="evidence-hover-card"
- className="rounded-[6px] border border-(--gray-4) bg-(--gray-2) text-(--gray-12) outline-none"
+ className="dark rounded-[6px] border border-(--gray-4) bg-(--gray-2) text-(--gray-12) outline-none"
style={{ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.25)" }}
>
- <EvidenceHoverCardLoader target={target} url={url}>
+ <EvidenceHoverCardLoader
+ target={target}
+ url={url}
+ onExpand={expand}
+ >
{children}
</EvidenceHoverCardLoader>
</Popover.Popup>
diff --git a/products/desktop/packages/ui/src/features/editor/evidenceComposer.test.ts b/products/desktop/packages/ui/src/features/editor/evidenceComposer.test.ts
new file mode 100644
index 000000000000..4745be6a0cb0
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/editor/evidenceComposer.test.ts
@@ -0,0 +1,39 @@
+import type { EditorContent } from "@posthog/core/message-editor/content";
+import { describe, expect, it } from "vitest";
+import { buildEvidenceComposerContent } from "./evidenceComposer";
+
+describe("buildEvidenceComposerContent", () => {
+ it.each([
+ [null, "Ask about "],
+ [
+ { segments: [{ type: "text", text: "Compare the variants" }] },
+ "\n\nAsk about ",
+ ],
+ ] as const)(
+ "preserves the current draft boundary",
+ (currentDraft, prefix) => {
+ expect(
+ buildEvidenceComposerContent({
+ kind: "insight",
+ id: "9pQx3",
+ label: "Insight: Checkout funnel",
+ currentDraft: currentDraft as EditorContent | null,
+ }),
+ ).toEqual({
+ segments: [
+ { type: "text", text: prefix },
+ {
+ type: "chip",
+ chip: {
+ type: "posthog_object",
+ objectKind: "insight",
+ id: "9pQx3",
+ label: "Insight: Checkout funnel",
+ },
+ },
+ { type: "text", text: " " },
+ ],
+ });
+ },
+ );
+});
diff --git a/products/desktop/packages/ui/src/features/editor/evidenceComposer.ts b/products/desktop/packages/ui/src/features/editor/evidenceComposer.ts
new file mode 100644
index 000000000000..5a460fb76542
--- /dev/null
+++ b/products/desktop/packages/ui/src/features/editor/evidenceComposer.ts
@@ -0,0 +1,31 @@
+import {
+ type EditorContent,
+ isContentEmpty,
+ type PostHogObjectKind,
+} from "@posthog/core/message-editor/content";
+
+export function buildEvidenceComposerContent({
+ kind,
+ id,
+ label,
+ currentDraft,
+}: {
+ kind: PostHogObjectKind;
+ id: string;
+ label: string;
+ currentDraft: EditorContent | string | null;
+}): EditorContent {
+ return {
+ segments: [
+ {
+ type: "text",
+ text: isContentEmpty(currentDraft) ? "Ask about " : "\n\nAsk about ",
+ },
+ {
+ type: "chip",
+ chip: { type: "posthog_object", objectKind: kind, id, label },
+ },
+ { type: "text", text: " " },
+ ],
+ };
+}
diff --git a/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipNode.ts b/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipNode.ts
index ef4540fe3980..cb4dbf5b733c 100644
--- a/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipNode.ts
+++ b/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipNode.ts
@@ -1,3 +1,4 @@
+import type { PostHogObjectKind } from "@posthog/core/message-editor/content";
import type { UploadableSkillSource } from "@posthog/shared";
import { mergeAttributes, Node } from "@tiptap/core";
import { ReactNodeViewRenderer } from "@tiptap/react";
@@ -12,6 +13,7 @@ export type ChipType =
| "experiment"
| "insight"
| "feature_flag"
+ | "posthog_object"
| "github_issue"
| "github_pr";
@@ -19,6 +21,7 @@ export interface MentionChipAttrs {
type: ChipType;
id: string;
label: string;
+ objectKind?: PostHogObjectKind;
pastedText: boolean;
/** Optional unique handle so callers can later replace or remove this chip. */
chipId?: string | null;
@@ -52,6 +55,7 @@ export const MentionChipNode = Node.create({
type: { default: "file" as ChipType },
id: { default: "" },
label: { default: "" },
+ objectKind: { default: undefined },
pastedText: { default: false },
chipId: { default: null as string | null },
skillPath: { default: undefined },
@@ -67,7 +71,7 @@ export const MentionChipNode = Node.create({
renderHTML({ node, HTMLAttributes }) {
const { type, label } = node.attrs as MentionChipAttrs;
const isCommand = type === "command";
- const prefix = isCommand ? "/" : "@";
+ const prefix = isCommand ? "/" : type === "posthog_object" ? "" : "@";
return [
"span",
diff --git a/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipView.tsx b/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipView.tsx
index 220ca09d41dd..1a8ae4d76972 100644
--- a/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipView.tsx
+++ b/products/desktop/packages/ui/src/features/message-editor/tiptap/MentionChipView.tsx
@@ -6,12 +6,14 @@ import {
FolderIcon,
GithubLogoIcon,
GitPullRequestIcon,
+ PulseIcon,
TerminalIcon,
WarningIcon,
XIcon,
} from "@phosphor-icons/react";
import { Chip, cn } from "@posthog/quill";
import { Tooltip } from "@posthog/ui/primitives/Tooltip";
+import { getObjectKind } from "@posthog/ui/utils/objectKinds";
import { type NodeViewProps, NodeViewWrapper } from "@tiptap/react";
import { usePasteUndoStore } from "../pasteUndoStore";
import type { ChipType, MentionChipAttrs } from "./MentionChipNode";
@@ -30,18 +32,24 @@ const typeIconMap: Record<ChipType, React.ComponentType<{ size: number }>> = {
experiment: FlaskIcon,
insight: ChartLineIcon,
feature_flag: FlagIcon,
+ posthog_object: PulseIcon,
};
function IconCloseButton({
type,
iconSize,
+ objectKind,
onRemove,
}: {
type: ChipType;
iconSize: number;
+ objectKind?: MentionChipAttrs["objectKind"];
onRemove: () => void;
}) {
- const Icon = typeIconMap[type] || FileTextIcon;
+ const Icon =
+ type === "posthog_object" && objectKind
+ ? getObjectKind(objectKind).icon
+ : typeIconMap[type] || FileTextIcon;
return (
<button
@@ -70,6 +78,7 @@ function DefaultChip({
type,
id,
label,
+ objectKind,
chipId,
pastedText,
selected,
@@ -78,6 +87,7 @@ function DefaultChip({
type: string;
id: string;
label: string;
+ objectKind?: MentionChipAttrs["objectKind"];
chipId: string | null;
pastedText: boolean;
selected: boolean;
@@ -87,7 +97,7 @@ function DefaultChip({
const canUndoPaste =
pastedText && chipId !== null && chipId === undoableChipId;
const isCommand = type === "command";
- const prefix = isCommand ? "/" : "@";
+ const prefix = isCommand ? "/" : type === "posthog_object" ? "" : "@";
const isFile = type === "file";
const isFolder = type === "folder";
const isGithubRef = type === "github_issue" || type === "github_pr";
@@ -126,6 +136,7 @@ function DefaultChip({
<IconCloseButton
type={type as ChipType}
iconSize={isPr ? 12 : 10}
+ objectKind={objectKind}
onRemove={onRemove}
/>
{isGithubRef ? (
@@ -153,7 +164,7 @@ export function MentionChipView({
editor,
selected,
}: NodeViewProps) {
- const { type, id, label, pastedText, chipId } =
+ const { type, id, label, objectKind, pastedText, chipId } =
node.attrs as MentionChipAttrs;
const handleRemove = () => {
@@ -172,6 +183,7 @@ export function MentionChipView({
type={type}
id={id}
label={label}
+ objectKind={objectKind}
chipId={chipId ?? null}
pastedText={pastedText}
selected={selected}
diff --git a/products/desktop/packages/ui/src/features/message-editor/tiptap/markdownDoc.ts b/products/desktop/packages/ui/src/features/message-editor/tiptap/markdownDoc.ts
index 64a2fbeef0c4..53a98865e70d 100644
--- a/products/desktop/packages/ui/src/features/message-editor/tiptap/markdownDoc.ts
+++ b/products/desktop/packages/ui/src/features/message-editor/tiptap/markdownDoc.ts
@@ -36,6 +36,7 @@ function chipFromAttrs(attrs: Record<string, unknown>): MentionChip {
type: attrs.type as MentionChip["type"],
id: attrs.id as string,
label: attrs.label as string,
+ objectKind: attrs.objectKind as MentionChip["objectKind"],
pastedText: attrs.pastedText as boolean | undefined,
skillPath: attrs.skillPath as string | undefined,
skillSource: attrs.skillSource as MentionChip["skillSource"],
@@ -192,6 +193,7 @@ function segmentsToLines(segments: Segment[]): Line[] {
type: segment.chip.type,
id: segment.chip.id,
label: segment.chip.label,
+ objectKind: segment.chip.objectKind,
pastedText: segment.chip.pastedText ?? false,
skillPath: segment.chip.skillPath,
skillSource: segment.chip.skillSource,
diff --git a/products/desktop/packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts b/products/desktop/packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts
index ab67918d0744..1e45cb4cf041 100644
--- a/products/desktop/packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts
+++ b/products/desktop/packages/ui/src/features/message-editor/tiptap/useTiptapEditor.ts
@@ -888,6 +888,7 @@ export function useTiptapEditor(options: UseTiptapEditorOptions) {
type: chip.type,
id: chip.id,
label: chip.label,
+ objectKind: chip.objectKind,
pastedText: false,
chipId: chip.chipId,
skillPath: chip.skillPath,