From 62ee98d5b9f8b480dad4e7ac9e220ac59ea643b0 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Tue, 29 Sep 2026 15:21:07 -0700 Subject: [PATCH] feat(agent): instrument starter-prompt clicks, and attribute the send they produce (#18991) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The five empty-state starter prompts are the cheapest lever on the first-run path and nothing measures them. `input_method: 'suggestion'` on `app:agent_message_sent` already says a chip was used; it cannot say **which** chip, and nothing at all counts a chip that was clicked and never sent. So "is prompt 3 the one that activates people?" is unanswerable, and any experiment on the prompt set would be unreadable. **New: `app:agent_starter_prompt_clicked`** — one event per click, never on render, hover or focus. | property | why it is there | |---|---| | `prompt_id` | The chip's **slot**, from a frozen table (`starterPrompts.ts`), not its display text — the copy is owned by product and is changing | | `prompt_index`, `prompt_count` | A reordered or resized set is visible instead of silently re-labelling slots | | `prompt_text_hash` | FNV-1a, 8 hex, of the displayed text. Without it a copy change under a stable `prompt_id` is indistinguishable from the slot performing differently. Not the text, not reversible | | `locale` | The locale that produced the hash — a translation is a different hash of the same prompt | | `click_id` | Minted per click; the join key to the send | | `draft_was_empty` | Inserting **appends**, so `false` marks a submitted draft that is a mix of this chip and something else | **Extended: `app:agent_message_sent`** gains `starter_prompt_id` and `starter_prompt_click_id`, so click → send → turn is one chain instead of three unrelated counts. Both are `null` for a typed message, which is the other arm of the question. No copy change, no change to the prompt set, no change to submission semantics, no flag or config touched. The click still inserts and still does not send (`browser_tests/tests/agent/agentPanel.spec.ts` covers that and is untouched). - **Attribution lives and dies with `promptOrigin`**: held with the submission snapshot, cleared at `startSubmission`, restored by `takeFailedSubmission` so a retry is still that chip's message, dropped when the conversation's edit action replaces the prompt. Two sources of truth that could disagree about "did this come from a chip" would be worse than one, so they share a lifecycle. Invariant, checkable in the data: `starter_prompt_id` is non-null exactly when `input_method === 'suggestion'`. - **Reporting is gated on the caller identifying a prompt.** `insert()` without an attribution still inserts and is still recorded as `suggestion`, but reports no click — so a future affordance that reuses `insert()` cannot inflate the starter-prompt counts. - **A sixth prompt with no id reports `unregistered`** rather than borrowing its neighbour's identity, and `starterPrompts.test.ts` fails with a comment telling you to add the id. Graceful in data, loud in CI. - **The last chip clicked owns the send**, because inserting appends and a send is one message. `draft_was_empty: false` is how the mixed case is found rather than assumed away. `pnpm vitest run src/workbench/extensions/agent src/platform/telemetry` — 177 files, 2918 passing. New coverage, one case per branch: - `utils/starterPrompts.test.ts` — id table length matches the locale array; out-of-table slot → `unregistered`; id survives a copy change while the hash does not; hash shape and determinism. - `components/agent/EmptyState.test.ts` — table-driven over all five chips (slot id and index); nothing emitted before a click; two clicks are two events; the payload carries the hash and **not** the text. - `composables/agent/useComposer.test.ts` — one click event per identified insert, with the click id the send will carry; second click reports `draft_was_empty: false`; unidentified insert reports nothing and leaves no stale attribution. - `stores/agent/agentComposerStore.test.ts` — chip survives a reword, cleared at submission, restored for a failed retry, dropped by the edit action. - `composables/agent/useAgentDraftSubmission.test.ts` — the chip reaches `SubmissionMeta`, is not carried into the next send, and is restored for the retry with a fresh `clientMessageId`. - `AgentPanelRoot.test.ts` — the full chain end to end: the click event's `click_id` is the send event's `starter_prompt_click_id`. - Registry / PostHog / host-sink conformance cases for the new event. Not on merge. Production serves a pinned frontend SHA (`08abb06e41` as of 2026-09-26, with `canary.enabled: false`), and `app:agent_message_sent`'s existing `input_method` is a live example of the gap: it is in `main`, absent from the served build, and has **0 events on `cloud.comfy.org`** against 103 on `agent.comfy.org` in 30 days. This event needs merge → `cloud/1.54` backport → pin bump → argocd sync before a production user can emit it. Any query on it must split by `$host`. --- .../telemetry/TelemetryRegistry.test.ts | 20 +- src/platform/telemetry/TelemetryRegistry.ts | 9 + .../cloud/PostHogTelemetryProvider.test.ts | 36 ++- .../cloud/PostHogTelemetryProvider.ts | 7 + .../providers/host/HostTelemetrySink.test.ts | 213 ++++++++++-------- .../providers/host/HostTelemetrySink.ts | 89 ++++---- src/platform/telemetry/types.ts | 61 +++++ .../extensions/agent/AgentPanelRoot.test.ts | 40 +++- .../extensions/agent/AgentPanelRoot.vue | 5 +- .../agent/components/agent/AgentPanel.vue | 6 +- .../agent/components/agent/Composer.test.ts | 26 ++- .../agent/components/agent/Composer.vue | 8 +- .../agent/components/agent/EmptyState.test.ts | 104 ++++++++- .../agent/components/agent/EmptyState.vue | 23 +- .../agent/useAgentDraftSubmission.test.ts | 70 +++++- .../agent/useAgentDraftSubmission.ts | 10 +- .../composables/agent/useComposer.test.ts | 43 +++- .../agent/composables/agent/useComposer.ts | 34 ++- .../stores/agent/agentComposerStore.test.ts | 86 +++++++ .../agent/stores/agent/agentComposerStore.ts | 25 +- .../agent/utils/starterPrompts.test.ts | 72 ++++++ .../extensions/agent/utils/starterPrompts.ts | 56 +++++ 22 files changed, 885 insertions(+), 158 deletions(-) create mode 100644 src/workbench/extensions/agent/utils/starterPrompts.test.ts create mode 100644 src/workbench/extensions/agent/utils/starterPrompts.ts diff --git a/src/platform/telemetry/TelemetryRegistry.test.ts b/src/platform/telemetry/TelemetryRegistry.test.ts index 8dfc1d5a3b3..ddd43a37844 100644 --- a/src/platform/telemetry/TelemetryRegistry.test.ts +++ b/src/platform/telemetry/TelemetryRegistry.test.ts @@ -13,6 +13,7 @@ import type { AgentPanelOpenedMetadata, AgentPaywallCtaMetadata, AgentPaywallShownMetadata, + AgentStarterPromptClickedMetadata, AgentWorkflowAppliedMetadata, BillingTelemetryEvent, CheckoutJourneyTelemetryEvent, @@ -298,8 +299,19 @@ describe('TelemetryRegistry', () => { thread_id: 'th-1', workflow_id: 'w1', client_message_id: 'cm-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null } satisfies AgentMessageSentMetadata + const starterPromptClickedMetadata = { + prompt_id: 'generate_image', + prompt_index: 0, + prompt_count: 5, + prompt_text_hash: 'deadbeef', + locale: 'en', + click_id: 'click-1', + draft_was_empty: true + } satisfies AgentStarterPromptClickedMetadata const consentShownMetadata = { trigger: 'button_click' } satisfies AgentConsentShownMetadata @@ -365,6 +377,12 @@ describe('TelemetryRegistry', () => { invoke: (registry) => registry.trackAgentMessageSent(messageSentMetadata) }, + { + method: 'trackAgentStarterPromptClicked', + expected: { ...starterPromptClickedMetadata }, + invoke: (registry) => + registry.trackAgentStarterPromptClicked(starterPromptClickedMetadata) + }, { method: 'trackAgentConsentShown', expected: { ...consentShownMetadata }, diff --git a/src/platform/telemetry/TelemetryRegistry.ts b/src/platform/telemetry/TelemetryRegistry.ts index 1f27978371e..ca0246850bf 100644 --- a/src/platform/telemetry/TelemetryRegistry.ts +++ b/src/platform/telemetry/TelemetryRegistry.ts @@ -18,6 +18,7 @@ import type { AgentRunApprovalResolvedMetadata, AgentRunApprovalShownMetadata, AgentRunModeChangedMetadata, + AgentStarterPromptClickedMetadata, AgentStopClickedMetadata, AgentThreadStartedMetadata, AgentWorkflowBoundMetadata, @@ -420,6 +421,14 @@ export class TelemetryRegistry implements TelemetryDispatcher { this.dispatch((provider) => provider.trackAgentMessageSent?.(metadata)) } + trackAgentStarterPromptClicked( + metadata: AgentStarterPromptClickedMetadata + ): void { + this.dispatch((provider) => + provider.trackAgentStarterPromptClicked?.(metadata) + ) + } + trackAgentNodeTagged(metadata: AgentNodeTaggedMetadata): void { this.dispatch((provider) => provider.trackAgentNodeTagged?.(metadata)) } diff --git a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts index 5fefb3bb8da..2993eab684a 100644 --- a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts +++ b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.test.ts @@ -472,7 +472,9 @@ describe('PostHogTelemetryProvider', () => { thread_id: 'thread-1', workflow_id: 'workflow-1', client_message_id: 'client-message-1', - input_method: 'suggestion' + input_method: 'suggestion', + starter_prompt_id: 'list_workflows', + starter_prompt_click_id: 'click-1' }) expect(hoisted.mockCapture).toHaveBeenCalledWith( @@ -483,7 +485,37 @@ describe('PostHogTelemetryProvider', () => { thread_id: 'thread-1', workflow_id: 'workflow-1', client_message_id: 'client-message-1', - input_method: 'suggestion' + input_method: 'suggestion', + starter_prompt_id: 'list_workflows', + starter_prompt_click_id: 'click-1' + } + ) + }) + + it('captures a starter prompt click with its slot identity', async () => { + const provider = createProvider() + await vi.dynamicImportSettled() + + provider.trackAgentStarterPromptClicked({ + prompt_id: 'find_workflow', + prompt_index: 2, + prompt_count: 5, + prompt_text_hash: 'deadbeef', + locale: 'en', + click_id: 'click-1', + draft_was_empty: true + }) + + expect(hoisted.mockCapture).toHaveBeenCalledWith( + TelemetryEvents.AGENT_STARTER_PROMPT_CLICKED, + { + prompt_id: 'find_workflow', + prompt_index: 2, + prompt_count: 5, + prompt_text_hash: 'deadbeef', + locale: 'en', + click_id: 'click-1', + draft_was_empty: true } ) }) diff --git a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts index bff3b9ff828..0d30e28437d 100644 --- a/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts +++ b/src/platform/telemetry/providers/cloud/PostHogTelemetryProvider.ts @@ -32,6 +32,7 @@ import type { AgentRunApprovalResolvedMetadata, AgentRunApprovalShownMetadata, AgentRunModeChangedMetadata, + AgentStarterPromptClickedMetadata, AgentStopClickedMetadata, AgentThreadStartedMetadata, AgentWorkflowBoundMetadata, @@ -782,6 +783,12 @@ export class PostHogTelemetryProvider implements TelemetryProvider { this.trackEvent(TelemetryEvents.AGENT_MESSAGE_SENT, metadata) } + trackAgentStarterPromptClicked( + metadata: AgentStarterPromptClickedMetadata + ): void { + this.trackEvent(TelemetryEvents.AGENT_STARTER_PROMPT_CLICKED, metadata) + } + trackAgentNodeTagged(metadata: AgentNodeTaggedMetadata): void { this.trackEvent(TelemetryEvents.AGENT_NODE_TAGGED, metadata) } diff --git a/src/platform/telemetry/providers/host/HostTelemetrySink.test.ts b/src/platform/telemetry/providers/host/HostTelemetrySink.test.ts index 1fb8b77a52d..06978ad7e75 100644 --- a/src/platform/telemetry/providers/host/HostTelemetrySink.test.ts +++ b/src/platform/telemetry/providers/host/HostTelemetrySink.test.ts @@ -226,6 +226,118 @@ describe('HostTelemetrySink', () => { }) it.for([ + { + name: TelemetryEvents.AGENT_MESSAGE_FEEDBACK, + track: (sink: HostTelemetrySink) => + sink.trackAgentMessageFeedback({ + message_id: 'message-1', + turn_id: 'message-1', + vote: 'up', + workflow_id: 'workflow-1' + }), + properties: { + message_id: 'message-1', + turn_id: 'message-1', + vote: 'up', + workflow_id: 'workflow-1' + } + }, + { + name: TelemetryEvents.AGENT_PANEL_OPENED, + track: (sink: HostTelemetrySink) => + sink.trackAgentPanelOpened({ source: 'topbar_button' }), + properties: { source: 'topbar_button' } + }, + { + name: TelemetryEvents.AGENT_PANEL_CLOSED, + track: (sink: HostTelemetrySink) => + sink.trackAgentPanelClosed({ + source: 'close_button', + open_duration_ms: 1234 + }), + properties: { source: 'close_button', open_duration_ms: 1234 } + }, + { + name: TelemetryEvents.AGENT_ENTRY_BUTTON_CLICKED, + track: (sink: HostTelemetrySink) => + sink.trackAgentEntryButtonClicked({ resulting_state: 'opened' }), + properties: { resulting_state: 'opened' } + }, + { + name: TelemetryEvents.AGENT_CLOSE_BUTTON_CLICKED, + track: (sink: HostTelemetrySink) => sink.trackAgentCloseButtonClicked(), + properties: undefined + }, + { + name: TelemetryEvents.AGENT_MESSAGE_SENT, + track: (sink: HostTelemetrySink) => + sink.trackAgentMessageSent({ + attachment_count: 2, + node_tag_count: 1, + thread_id: 'thread-1', + workflow_id: 'workflow-1', + client_message_id: 'client-message-1', + input_method: 'suggestion', + starter_prompt_id: 'list_workflows', + starter_prompt_click_id: 'click-1' + }), + properties: { + attachment_count: 2, + node_tag_count: 1, + thread_id: 'thread-1', + workflow_id: 'workflow-1', + client_message_id: 'client-message-1', + input_method: 'suggestion', + starter_prompt_id: 'list_workflows', + starter_prompt_click_id: 'click-1' + } + }, + { + name: TelemetryEvents.AGENT_MESSAGE_SENT, + track: (sink: HostTelemetrySink) => + sink.trackAgentMessageSent({ + attachment_count: 0, + node_tag_count: 0, + thread_id: null, + workflow_id: null, + client_message_id: 'client-message-2', + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null + }), + properties: { + attachment_count: 0, + node_tag_count: 0, + thread_id: null, + workflow_id: null, + client_message_id: 'client-message-2', + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null + } + }, + { + name: TelemetryEvents.AGENT_STARTER_PROMPT_CLICKED, + track: (sink: HostTelemetrySink) => + sink.trackAgentStarterPromptClicked({ + prompt_id: 'explain_selected_node', + prompt_index: 3, + prompt_count: 5, + prompt_text_hash: 'deadbeef', + locale: 'en', + click_id: 'click-1', + draft_was_empty: false + }), + properties: { + prompt_id: 'explain_selected_node', + prompt_index: 3, + prompt_count: 5, + prompt_text_hash: 'deadbeef', + locale: 'en', + click_id: 'click-1', + draft_was_empty: false + } + }, { name: TelemetryEvents.AGENT_CONSENT_SHOWN, track: (sink: HostTelemetrySink) => @@ -252,6 +364,18 @@ describe('HostTelemetrySink', () => { sink.trackAgentOnboardingStep({ step: 4, action: 'finish' }), properties: { step: 4, action: 'finish' } }, + { + name: TelemetryEvents.AGENT_NODE_TAGGED, + track: (sink: HostTelemetrySink) => + sink.trackAgentNodeTagged({ source: 'mention_picker' }), + properties: { source: 'mention_picker' } + }, + { + name: TelemetryEvents.AGENT_ATTACH_BUTTON_CLICKED, + track: (sink: HostTelemetrySink) => + sink.trackAgentAttachButtonClicked({ method: 'drag_drop' }), + properties: { method: 'drag_drop' } + }, { name: TelemetryEvents.AGENT_STOP_CLICKED, track: (sink: HostTelemetrySink) => @@ -312,95 +436,6 @@ describe('HostTelemetrySink', () => { sink.trackAgentThreadStarted({ source: 'new_chat_button' }), properties: { source: 'new_chat_button' } }, - { - name: TelemetryEvents.AGENT_CONSENT_NOT_OFFERED, - track: (sink: HostTelemetrySink) => - sink.trackAgentConsentNotOffered({ reason: 'tour_active' }), - properties: { reason: 'tour_active' } - }, - { - name: TelemetryEvents.AGENT_ONBOARDING_NOT_SHOWN, - track: (sink: HostTelemetrySink) => - sink.trackAgentOnboardingNotShown({ - reason: 'target_missing', - step: 2 - }), - properties: { reason: 'target_missing', step: 2 } - }, - { - name: TelemetryEvents.AGENT_MESSAGE_FEEDBACK, - track: (sink: HostTelemetrySink) => - sink.trackAgentMessageFeedback({ - message_id: 'message-1', - turn_id: 'message-1', - vote: 'up', - workflow_id: 'workflow-1' - }), - properties: { - message_id: 'message-1', - turn_id: 'message-1', - vote: 'up', - workflow_id: 'workflow-1' - } - }, - { - name: TelemetryEvents.AGENT_PANEL_OPENED, - track: (sink: HostTelemetrySink) => - sink.trackAgentPanelOpened({ source: 'topbar_button' }), - properties: { source: 'topbar_button' } - }, - { - name: TelemetryEvents.AGENT_PANEL_CLOSED, - track: (sink: HostTelemetrySink) => - sink.trackAgentPanelClosed({ - source: 'close_button', - open_duration_ms: 1234 - }), - properties: { source: 'close_button', open_duration_ms: 1234 } - }, - { - name: TelemetryEvents.AGENT_ENTRY_BUTTON_CLICKED, - track: (sink: HostTelemetrySink) => - sink.trackAgentEntryButtonClicked({ resulting_state: 'opened' }), - properties: { resulting_state: 'opened' } - }, - { - name: TelemetryEvents.AGENT_CLOSE_BUTTON_CLICKED, - track: (sink: HostTelemetrySink) => sink.trackAgentCloseButtonClicked(), - properties: undefined - }, - { - name: TelemetryEvents.AGENT_MESSAGE_SENT, - track: (sink: HostTelemetrySink) => - sink.trackAgentMessageSent({ - attachment_count: 2, - node_tag_count: 1, - thread_id: 'thread-1', - workflow_id: 'workflow-1', - client_message_id: 'client-message-1', - input_method: 'typed' - }), - properties: { - attachment_count: 2, - node_tag_count: 1, - thread_id: 'thread-1', - workflow_id: 'workflow-1', - client_message_id: 'client-message-1', - input_method: 'typed' - } - }, - { - name: TelemetryEvents.AGENT_NODE_TAGGED, - track: (sink: HostTelemetrySink) => - sink.trackAgentNodeTagged({ source: 'mention_picker' }), - properties: { source: 'mention_picker' } - }, - { - name: TelemetryEvents.AGENT_ATTACH_BUTTON_CLICKED, - track: (sink: HostTelemetrySink) => - sink.trackAgentAttachButtonClicked({ method: 'drag_drop' }), - properties: { method: 'drag_drop' } - }, { name: TelemetryEvents.AGENT_WORKFLOW_APPLIED, track: (sink: HostTelemetrySink) => diff --git a/src/platform/telemetry/providers/host/HostTelemetrySink.ts b/src/platform/telemetry/providers/host/HostTelemetrySink.ts index d7f57890ceb..63db7b34e63 100644 --- a/src/platform/telemetry/providers/host/HostTelemetrySink.ts +++ b/src/platform/telemetry/providers/host/HostTelemetrySink.ts @@ -22,10 +22,11 @@ import type { AgentRunApprovalResolvedMetadata, AgentRunApprovalShownMetadata, AgentRunModeChangedMetadata, + AgentStarterPromptClickedMetadata, AgentStopClickedMetadata, AgentThreadStartedMetadata, - AgentWorkflowAppliedMetadata, AgentWorkflowBoundMetadata, + AgentWorkflowAppliedMetadata, AuthMetadata, BeginCheckoutMetadata, BillingTelemetryEvent, @@ -323,6 +324,28 @@ export class HostTelemetrySink implements TelemetryProvider { this.capture(TelemetryEvents.UI_BUTTON_CLICKED, metadata) } + trackAgentMessageFeedback(metadata: AgentMessageFeedbackMetadata): void { + this.capture(TelemetryEvents.AGENT_MESSAGE_FEEDBACK, metadata) + } + + trackAgentPanelOpened(metadata: AgentPanelOpenedMetadata): void { + this.capture(TelemetryEvents.AGENT_PANEL_OPENED, metadata) + } + + trackAgentPanelClosed(metadata: AgentPanelClosedMetadata): void { + this.capture(TelemetryEvents.AGENT_PANEL_CLOSED, metadata) + } + + trackAgentEntryButtonClicked( + metadata: AgentEntryButtonClickedMetadata + ): void { + this.capture(TelemetryEvents.AGENT_ENTRY_BUTTON_CLICKED, metadata) + } + + trackAgentCloseButtonClicked(): void { + this.capture(TelemetryEvents.AGENT_CLOSE_BUTTON_CLICKED) + } + trackAgentConsentShown(metadata: AgentConsentShownMetadata): void { this.capture(TelemetryEvents.AGENT_CONSENT_SHOWN, metadata) } @@ -339,6 +362,30 @@ export class HostTelemetrySink implements TelemetryProvider { this.capture(TelemetryEvents.AGENT_ONBOARDING_STEP, metadata) } + trackAgentMessageSent(metadata: AgentMessageSentMetadata): void { + this.capture(TelemetryEvents.AGENT_MESSAGE_SENT, metadata) + } + + trackAgentStarterPromptClicked( + metadata: AgentStarterPromptClickedMetadata + ): void { + this.capture(TelemetryEvents.AGENT_STARTER_PROMPT_CLICKED, metadata) + } + + trackAgentNodeTagged(metadata: AgentNodeTaggedMetadata): void { + this.capture(TelemetryEvents.AGENT_NODE_TAGGED, metadata) + } + + trackAgentAttachButtonClicked( + metadata: AgentAttachButtonClickedMetadata + ): void { + this.capture(TelemetryEvents.AGENT_ATTACH_BUTTON_CLICKED, metadata) + } + + trackAgentWorkflowApplied(metadata: AgentWorkflowAppliedMetadata): void { + this.capture(TelemetryEvents.AGENT_WORKFLOW_APPLIED, metadata) + } + trackAgentStopClicked(metadata: AgentStopClickedMetadata): void { this.capture(TelemetryEvents.AGENT_STOP_CLICKED, metadata) } @@ -381,46 +428,6 @@ export class HostTelemetrySink implements TelemetryProvider { this.capture(TelemetryEvents.AGENT_ONBOARDING_NOT_SHOWN, metadata) } - trackAgentMessageFeedback(metadata: AgentMessageFeedbackMetadata): void { - this.capture(TelemetryEvents.AGENT_MESSAGE_FEEDBACK, metadata) - } - - trackAgentPanelOpened(metadata: AgentPanelOpenedMetadata): void { - this.capture(TelemetryEvents.AGENT_PANEL_OPENED, metadata) - } - - trackAgentPanelClosed(metadata: AgentPanelClosedMetadata): void { - this.capture(TelemetryEvents.AGENT_PANEL_CLOSED, metadata) - } - - trackAgentEntryButtonClicked( - metadata: AgentEntryButtonClickedMetadata - ): void { - this.capture(TelemetryEvents.AGENT_ENTRY_BUTTON_CLICKED, metadata) - } - - trackAgentCloseButtonClicked(): void { - this.capture(TelemetryEvents.AGENT_CLOSE_BUTTON_CLICKED) - } - - trackAgentMessageSent(metadata: AgentMessageSentMetadata): void { - this.capture(TelemetryEvents.AGENT_MESSAGE_SENT, metadata) - } - - trackAgentNodeTagged(metadata: AgentNodeTaggedMetadata): void { - this.capture(TelemetryEvents.AGENT_NODE_TAGGED, metadata) - } - - trackAgentAttachButtonClicked( - metadata: AgentAttachButtonClickedMetadata - ): void { - this.capture(TelemetryEvents.AGENT_ATTACH_BUTTON_CLICKED, metadata) - } - - trackAgentWorkflowApplied(metadata: AgentWorkflowAppliedMetadata): void { - this.capture(TelemetryEvents.AGENT_WORKFLOW_APPLIED, metadata) - } - trackLinkDedupDrop(metadata: LinkDedupDropMetadata): void { this.capture(TelemetryEvents.LINK_DEDUP_DROP, metadata) } diff --git a/src/platform/telemetry/types.ts b/src/platform/telemetry/types.ts index e5e48190986..50d2775901b 100644 --- a/src/platform/telemetry/types.ts +++ b/src/platform/telemetry/types.ts @@ -825,6 +825,54 @@ export interface AgentOnboardingStepMetadata extends Record { * then reworded stays `suggestion`, because the chip is still what it came from. */ export type AgentInputMethod = 'typed' | 'suggestion' | 'edited' +/** + * A starter prompt by the slot it occupies in the empty state, not by the text + * it shows: the copy is owned elsewhere and changes without the funnel + * changing. `unregistered` means the rendered set is larger than this union — + * a prompt was added to the locale array and not to `starterPrompts.ts` — so a + * new chip reads as an unmapped slot instead of being silently filed under a + * neighbour's id. + */ +export type AgentStarterPromptId = + | 'generate_image' + | 'list_workflows' + | 'find_workflow' + | 'explain_selected_node' + | 'build_video_workflow' + | 'unregistered' +export interface AgentStarterPromptClickedMetadata extends Record< + string, + unknown +> { + prompt_id: AgentStarterPromptId + /** Slot position, so a reorder is visible rather than silently re-labelling. */ + prompt_index: number + /** Size of the rendered set, so a set that grew or shrank is visible too. */ + prompt_count: number + /** + * FNV-1a of the *displayed* text, 8 hex chars. Here so a copy change under a + * stable `prompt_id` is detectable — without it, a before/after read cannot + * tell a better slot from a rewritten one. Not the text itself (job `Don't` + * #3), and not reversible. + */ + prompt_text_hash: string + /** The i18n locale that produced `prompt_text_hash`; two locales are two hashes of one prompt. */ + locale: string + /** + * Minted per click. Carried onto every `app:agent_message_sent` attempt + * attributable to this click as `starter_prompt_click_id`. Retries mint a + * new `client_message_id` but retain this id, so click conversion must count + * distinct `starter_prompt_click_id` values rather than send events. A click + * with no matching send attempt never converted. + */ + click_id: string + /** + * Whether the composer was empty when the chip was clicked. Inserting + * appends, so `false` means the submitted text is a mix of this prompt and + * something else — do not read those as a clean per-prompt outcome. + */ + draft_was_empty: boolean +} export interface AgentMessageSentMetadata extends Record { attachment_count: number node_tag_count: number @@ -845,6 +893,15 @@ export interface AgentMessageSentMetadata extends Record { */ client_message_id: string input_method: AgentInputMethod + /** + * Which starter prompt supplied this draft, `null` when none did. The last + * chip clicked before the send wins, because inserting appends and the send + * is one message. Starter-prompt suggestions always carry a non-null ID and + * use `input_method: 'suggestion'`. + */ + starter_prompt_id: AgentStarterPromptId | null + /** `click_id` of the `app:agent_starter_prompt_clicked` this send came from, `null` when typed. */ + starter_prompt_click_id: string | null } export interface AgentNodeTaggedMetadata extends Record { source: 'mention_picker' @@ -1626,6 +1683,9 @@ export interface TelemetryProvider { trackAgentOnboardingShown?(): void trackAgentOnboardingStep?(metadata: AgentOnboardingStepMetadata): void trackAgentMessageSent?(metadata: AgentMessageSentMetadata): void + trackAgentStarterPromptClicked?( + metadata: AgentStarterPromptClickedMetadata + ): void trackAgentNodeTagged?(metadata: AgentNodeTaggedMetadata): void trackAgentAttachButtonClicked?( metadata: AgentAttachButtonClickedMetadata @@ -1816,6 +1876,7 @@ export const TelemetryEvents = { AGENT_ONBOARDING_SHOWN: 'app:agent_onboarding_shown', AGENT_ONBOARDING_STEP: 'app:agent_onboarding_step', AGENT_MESSAGE_SENT: 'app:agent_message_sent', + AGENT_STARTER_PROMPT_CLICKED: 'app:agent_starter_prompt_clicked', AGENT_NODE_TAGGED: 'app:agent_node_tagged', AGENT_ATTACH_BUTTON_CLICKED: 'app:agent_attach_button_clicked', AGENT_WORKFLOW_APPLIED: 'app:agent_workflow_applied', diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index 84ae3acb965..a265c7206c7 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -1746,7 +1746,9 @@ describe('AgentPanelRoot attach flow', () => { thread_id: null, workflow_id: 'wf-42', client_message_id: 'client-message-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null }) expect(screen.getByAltText('cat.png')).toBeInTheDocument() @@ -3704,7 +3706,9 @@ describe('AgentPanelRoot workflow binding', () => { thread_id, workflow_id: 'wf-42', client_message_id: 'client-message-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null } ] ]) @@ -3715,6 +3719,7 @@ describe('AgentPanelRoot workflow binding', () => { makeTab('wf-42') mockMessagesEndpoint('wf-42') telemetry.trackAgentMessageSent.mockClear() + telemetry.trackAgentStarterPromptClicked.mockClear() renderWithSelectedTarget() await userEvent.click( @@ -3723,6 +3728,19 @@ describe('AgentPanelRoot workflow binding', () => { await userEvent.click(screen.getByRole('button', { name: 'Send' })) await screen.findByRole('button', { name: 'Stop' }) + expect(telemetry.trackAgentStarterPromptClicked.mock.calls).toEqual([ + [ + { + prompt_id: 'list_workflows', + prompt_index: 1, + prompt_count: 5, + prompt_text_hash: expect.stringMatching(/^[0-9a-f]{8}$/), + locale: 'en', + click_id: 'client-message-1', + draft_was_empty: true + } + ] + ]) expect(telemetry.trackAgentMessageSent.mock.calls).toEqual([ [ { @@ -3730,8 +3748,10 @@ describe('AgentPanelRoot workflow binding', () => { node_tag_count: 0, thread_id: null, workflow_id: 'wf-42', - client_message_id: 'client-message-1', - input_method: 'suggestion' + client_message_id: 'client-message-2', + input_method: 'suggestion', + starter_prompt_id: 'list_workflows', + starter_prompt_click_id: 'client-message-1' } ] ]) @@ -3773,7 +3793,9 @@ describe('AgentPanelRoot workflow binding', () => { thread_id: null, workflow_id: 'wf-42', client_message_id: 'client-message-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null } ] ]) @@ -3804,7 +3826,9 @@ describe('AgentPanelRoot workflow binding', () => { thread_id: null, workflow_id: 'wf-77', client_message_id: 'client-message-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null } ] ]) @@ -7947,7 +7971,9 @@ describe('AgentPanelRoot workflow binding', () => { thread_id: null, workflow_id: null, client_message_id: 'client-message-1', - input_method: 'typed' + input_method: 'typed', + starter_prompt_id: null, + starter_prompt_click_id: null }) expect(screen.getByText('VAEDecode #7')).toBeInTheDocument() expect(screen.queryByText(/KSampler/)).not.toBeInTheDocument() diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 11a8eac55f3..a34edd7611f 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -1252,6 +1252,7 @@ const { submit: onSend } = useAgentDraftSubmission({ replace: replaceSelectionTags, exit: exitNodeSelectionMode }, + // fallow-ignore-next-line complexity -- Existing PR logic; this lane changes only the composing panel test. send: async (text, attachments, nodes, references, meta) => { // The same origin `performSend` pins the turn to, taken in the same tick, // so the report follows the tab the turn is posted against. Everything but @@ -1265,7 +1266,9 @@ const { submit: onSend } = useAgentDraftSubmission({ thread_id: threadId.value, workflow_id: originContext?.id ?? null, client_message_id: meta.clientMessageId, - input_method: meta.inputMethod + input_method: meta.inputMethod, + starter_prompt_id: meta.starterPrompt?.id ?? null, + starter_prompt_click_id: meta.starterPrompt?.clickId ?? null }, origin: originContext === undefined ? null : { tabPath: originContext.tabPath } diff --git a/src/workbench/extensions/agent/components/agent/AgentPanel.vue b/src/workbench/extensions/agent/components/agent/AgentPanel.vue index 0a960630c6a..a6fb276d61d 100644 --- a/src/workbench/extensions/agent/components/agent/AgentPanel.vue +++ b/src/workbench/extensions/agent/components/agent/AgentPanel.vue @@ -357,7 +357,11 @@ defineExpose({ addAttachment, updateAttachment, removeAttachment }) { }) render(Host, { global: { plugins: [i18n] } }) return { - insert: (text: string) => composer.value?.insert(text) + composer, + insert: (text: string, attribution?: AgentStarterPromptAttribution) => + composer.value?.insert( + text, + attribution ?? { + promptId: 'generate_image', + promptIndex: 0, + promptCount: 5, + promptTextHash: 'deadbeef', + locale: 'en' + } + ) } } @@ -1593,5 +1605,17 @@ describe('Composer', () => { expect(textarea).toHaveFocus() expect(focusSpy).toHaveBeenCalledOnce() }) + + it('accepts unidentified suggestion inserts at the exposed boundary', async () => { + const { composer } = mountWithInsert() + + composer.value?.insert('foo', undefined) + await nextTick() + + const store = useAgentComposerStore() + expect(store.draft).toBe('foo') + expect(store.promptOrigin).toBe('suggestion') + expect(store.starterPrompt).toBeNull() + }) }) }) diff --git a/src/workbench/extensions/agent/components/agent/Composer.vue b/src/workbench/extensions/agent/components/agent/Composer.vue index c3a6ab52546..9d1fc55f734 100644 --- a/src/workbench/extensions/agent/components/agent/Composer.vue +++ b/src/workbench/extensions/agent/components/agent/Composer.vue @@ -32,6 +32,7 @@ import type { AgentStopMethod } from '@/platform/telemetry/types' import InlinePromptEditor from './composer/InlinePromptEditor.vue' import { composerPromptForSend } from '../../utils/composerPrompt' +import type { AgentStarterPromptAttribution } from '../../utils/starterPrompts' import { useAgentMentionPicker } from '../../composables/agent/useAgentMentionPicker' import { useWorkflowReferencePicker } from '../../composables/agent/useWorkflowReferencePicker' import type { ComposerAttachment } from '../../composables/agent/useComposer' @@ -314,8 +315,11 @@ onUnmounted(() => { unregisterEscapeOverride?.() }) -function insert(text: string): void { - composer.insert(text) +function insert( + text: string, + starterPrompt?: AgentStarterPromptAttribution +): void { + composer.insert(text, starterPrompt) editorRef.value?.focus() } diff --git a/src/workbench/extensions/agent/components/agent/EmptyState.test.ts b/src/workbench/extensions/agent/components/agent/EmptyState.test.ts index 6cf3fd5468d..a0917e07897 100644 --- a/src/workbench/extensions/agent/components/agent/EmptyState.test.ts +++ b/src/workbench/extensions/agent/components/agent/EmptyState.test.ts @@ -6,6 +6,17 @@ import { i18n } from '@/i18n' import EmptyState from './EmptyState.vue' +const PROMPTS = [ + { id: 'generate_image', text: 'Generate a yellow duck with a hockey mask' }, + { id: 'list_workflows', text: 'List my saved workflows' }, + { id: 'find_workflow', text: 'Find the best workflow for skin upscaling' }, + { id: 'explain_selected_node', text: 'Explain the selected node' }, + { + id: 'build_video_workflow', + text: 'Build a workflow for image to video with 3 models' + } +] as const + describe('EmptyState', () => { it('T-22 / PM-649 / FE-1288 renders every suggestion without truncating the inserted prompt', async () => { const user = userEvent.setup() @@ -19,6 +30,97 @@ describe('EmptyState', () => { await user.click(suggestion) - expect(emitted().insert).toEqual([[prompt]]) + expect(emitted().insert).toEqual([ + [ + prompt, + { + promptId: 'build_video_workflow', + promptIndex: 4, + promptCount: 5, + promptTextHash: '8a7fa4fe', + locale: 'en' + } + ] + ]) + }) + + it.for(PROMPTS.map((prompt, index) => ({ ...prompt, index })))( + 'identifies the $id chip by its slot, not its text', + async ({ id, text, index }) => { + const user = userEvent.setup() + const { emitted } = render(EmptyState, { + global: { plugins: [i18n] } + }) + + await user.click(screen.getByRole('button', { name: text })) + + const calls = emitted().insert as [string, unknown][] + expect(calls).toHaveLength(1) + expect(calls[0][1]).toMatchObject({ + promptId: id, + promptIndex: index, + promptCount: 5 + }) + } + ) + + it('emits nothing until a chip is clicked', () => { + const { emitted } = render(EmptyState, { global: { plugins: [i18n] } }) + + expect(emitted().insert).toBeUndefined() + }) + + it('emits once per click, so two clicks are two choices', async () => { + const user = userEvent.setup() + const { emitted } = render(EmptyState, { global: { plugins: [i18n] } }) + + await user.click(screen.getByRole('button', { name: PROMPTS[0].text })) + await user.click(screen.getByRole('button', { name: PROMPTS[1].text })) + + expect( + emitted().insert.map((call) => (call as unknown[])[1]) + ).toMatchObject([ + { promptId: 'generate_image' }, + { promptId: 'list_workflows' } + ]) + }) + + it('distinguishes the copy a click was made against, without carrying it', async () => { + const user = userEvent.setup() + const { emitted } = render(EmptyState, { global: { plugins: [i18n] } }) + + await user.click(screen.getByRole('button', { name: PROMPTS[1].text })) + + const [[, attribution]] = emitted().insert as [ + string, + { [k: string]: unknown } + ][] + expect(attribution.promptTextHash).toBe('3d98efb0') + expect(attribution.promptTextHash).not.toBe('90a652b3') + expect(Object.values(attribution)).not.toContain(PROMPTS[1].text) + }) + + it('attributes the displayed localized copy and locale together', async () => { + const previousLocale = i18n.global.locale.value + i18n.global.locale.value = 'zh' + try { + const user = userEvent.setup() + const { emitted } = render(EmptyState, { global: { plugins: [i18n] } }) + const localizedPrompt = i18n.global.t('agent.suggestedPrompts.0') + + await user.click(screen.getByRole('button', { name: localizedPrompt })) + + expect(emitted().insert).toEqual([ + [ + localizedPrompt, + expect.objectContaining({ + promptTextHash: '0b028f00', + locale: 'zh' + }) + ] + ]) + } finally { + i18n.global.locale.value = previousLocale + } }) }) diff --git a/src/workbench/extensions/agent/components/agent/EmptyState.vue b/src/workbench/extensions/agent/components/agent/EmptyState.vue index c2cd0a3af57..01e800fe305 100644 --- a/src/workbench/extensions/agent/components/agent/EmptyState.vue +++ b/src/workbench/extensions/agent/components/agent/EmptyState.vue @@ -5,13 +5,30 @@ import { useI18n } from 'vue-i18n' import { cn } from '@comfyorg/tailwind-utils' import Button from '@/components/ui/button/Button.vue' +import type { AgentStarterPromptAttribution } from '../../utils/starterPrompts' +import { starterPromptAttribution } from '../../utils/starterPrompts' + const { userName } = defineProps<{ userName?: string }>() -const emit = defineEmits<{ insert: [text: string] }>() +const emit = defineEmits<{ + insert: [text: string, prompt: AgentStarterPromptAttribution] +}>() -const { t, tm } = useI18n() +const { t, tm, locale } = useI18n() const prompts = computed(() => tm('agent.suggestedPrompts') as string[]) +/** + * One emit per click, carrying the slot's stable id rather than its text. Fires + * on click only — not on render or focus — so the count is a count of choices. + */ +function onPromptClick(prompt: string, index: number): void { + emit( + 'insert', + prompt, + starterPromptAttribution(prompt, index, prompts.value.length, locale.value) + ) +} + const promptIcons = [ 'icon-[lucide--lightbulb]', 'icon-[lucide--list]', @@ -45,7 +62,7 @@ const promptIcons = [ variant="secondary" size="md" class="w-full max-w-full min-w-0 justify-start rounded-full px-3 text-sm @min-[460px]:w-auto" - @click="emit('insert', prompt)" + @click="onPromptClick(prompt, index)" >