Line data Source code
1 : import type { AgentStarterPromptId } from '@comfyorg/telemetry/types'
2 : import { hashPath } from '@/platform/workflow/persistence/base/hashUtil'
3 :
4 : /**
5 : * Stable ids for the empty state's starter prompts, index-aligned with
6 : * `agent.suggestedPrompts.{cloud,local}` and the Cloud-only
7 : * `agent.suggestedPrompts.treatment.cloud` list in the English locale, and with
8 : * the icon list in `EmptyState.vue`. A Cloud slot can show different copy by
9 : * locale while retaining its id; analytics must pair `prompt_id` with
10 : * `prompt_text_hash` and `locale` when copy identity matters.
11 : *
12 : * The copy is owned by product and is expected to change; these ids are not,
13 : * which is the whole point of them — an event keyed on display text cannot
14 : * survive a rewrite, and an event keyed on nothing cannot tell the five chips
15 : * apart. An appended prompt needs its id added here; until then that extra chip
16 : * reports `unregistered`.
17 : */
18 1 : export const STARTER_PROMPT_IDS = [
19 : 'slot_1',
20 : 'slot_2',
21 : 'slot_3',
22 : 'slot_4',
23 : 'slot_5'
24 : ] as const satisfies readonly AgentStarterPromptId[]
25 :
26 : /** What the empty state knows about the chip that was clicked. */
27 : export interface AgentStarterPromptAttribution {
28 : promptId: AgentStarterPromptId
29 : promptIndex: number
30 : promptCount: number
31 : visiblePromptCount: number
32 : promptTextHash: string
33 : locale: string
34 : }
35 :
36 : /** What the composer holds until the draft is submitted, or replaced. */
37 : export interface AgentStarterPromptSource {
38 : id: AgentStarterPromptId
39 : clickId: string
40 : }
41 :
42 0 : export function starterPromptIdAt(index: number): AgentStarterPromptId {
43 0 : return STARTER_PROMPT_IDS[index] ?? 'unregistered'
44 : }
45 :
46 : /**
47 : * `count` is the size of the rendered set; `visibleCount` is how many of that
48 : * set the viewer could actually see, which is smaller in a narrow panel. They
49 : * are two separate facts and are reported as two separate fields on purpose —
50 : * folding the width-dependent one into `promptCount` would make a set change
51 : * and a panel resize indistinguishable in analytics.
52 : * `visibleCount` defaults to `count` for callers with no layout to measure.
53 : */
54 0 : export function starterPromptAttribution(
55 : text: string,
56 : index: number,
57 : count: number,
58 : locale: string,
59 : visibleCount: number = count
60 : ): AgentStarterPromptAttribution {
61 0 : return {
62 : promptId: starterPromptIdAt(index),
63 : promptIndex: index,
64 : promptCount: count,
65 : visiblePromptCount: visibleCount,
66 : promptTextHash: hashPath(text),
67 : locale
68 : }
69 : }
|