/** * External dependencies */ import type { Uuid } from 'uuid'; /** * Internal dependencies */ import type { Experiment, ExperimentId, Heatmap } from '../experiments'; export type AiTestGenerationState = | AiTestGenerationIntroState | AiSiteAnalysisState | AiCandidateSearchState | AiHypothesisSelectionState | AiTestCreationFromHypothesisState | AiTestGenerationDoneState | AiTestGenerationErrorState; export type AiSiteAnalysis = { readonly content: Record< string, | ReadonlyArray< AiPostSummary > | ReadonlyArray< AiProductSummary > | undefined >; readonly metaInformation: { readonly language: string; readonly blog?: { readonly totalPostsInLastYear: number; readonly averagePostsPerMonth: number; }; readonly woocommerce?: { readonly bestSellers: ReadonlyArray< AiBestSeller >; readonly latestOrders: ReadonlyArray< AiOrderSummary >; }; readonly abTesting: { readonly experiments: ReadonlyArray< AiExperiment >; readonly heatmaps: ReadonlyArray< AiHeatmap >; }; readonly urlAnalytics: ReadonlyArray< AiUrlAnalytics >; }; }; export type AiTestCandidate = | ( AiPostSummary & AiTestCandidateExtraAttrs ) | ( AiProductSummary & AiTestCandidateExtraAttrs ); type AiTestCandidateExtraAttrs = Omit< AiCloudTestCandidate, 'id' | 'type' | 'hypotheses' > & { readonly hypothesisState: AiTestHypothesisState; }; export type AiCloudTestCandidate = { readonly id: number; readonly type: string; readonly priority: number; readonly rationale: string; readonly hypothesisGeneration: 'available' | 'subscription-required'; readonly hypotheses?: ReadonlyArray< AiCloudTestHypothesis >; }; export type AiTestHypothesis = { readonly id: Uuid; readonly name: string; readonly testType: string; readonly description: string; readonly controlUrl: string; readonly control: { readonly type: string; readonly id: number; }; readonly variants: ReadonlyArray< { readonly name: string; readonly changes: ReadonlyArray< string >; } >; readonly goals: ReadonlyArray< { readonly name: string; readonly description: string; } >; readonly details: { readonly actionable: string; readonly rationale: string; }; readonly relatedTests: ReadonlyArray< ExperimentId >; }; export type AiCloudTestHypothesis = Omit< AiTestHypothesis, 'controlUrl' | 'relatedTests' >; export type AiTestGenerationIntroState = { readonly id: Uuid; readonly type: 'intro'; }; export type AiSiteAnalysisState = { readonly id: Uuid; readonly type: 'analyzing-site'; readonly what: | 'saving-ai-settings' | 'previous-candidates' | 'ab-testing' | 'blog' | 'custom-posts' | 'ecommerce' | 'google-analytics' | 'pages' | 'first-hypotheses'; }; export type AiCandidateSearchState = { readonly id: Uuid; readonly type: 'searching-candidates'; readonly step: 'just-started' | 'keep-waiting' | 'quite-slow'; }; export type AiHypothesisSelectionState = { readonly id: Uuid; readonly type: 'hypothesis-selection'; readonly siteAnalysis: AiSiteAnalysis; readonly candidates: ReadonlyArray< AiTestCandidate >; readonly testing: { readonly experiments: ReadonlyArray< Experiment >; readonly heatmaps: ReadonlyArray< Heatmap >; }; }; export type AiTestHypothesisState = | { readonly status: 'pending'; } | { readonly status: 'generating'; } | { readonly status: 'ready'; readonly hypotheses: ReadonlyArray< AiTestHypothesis >; readonly isVisible: boolean; } | { readonly status: 'error'; readonly reason: string; }; export type AiTestCreationFromHypothesisState = { readonly id: Uuid; readonly type: 'creating-test'; }; export type AiTestGenerationDoneState = { readonly id: Uuid; readonly type: 'done'; readonly experiment: Experiment; }; export type AiTestGenerationErrorState = { readonly id: Uuid; readonly type: 'error'; readonly reason?: string; }; export type AiPostSummary = { readonly id: number; readonly type: string; readonly title: string; readonly url: string; readonly publicationDate: string; readonly lastUpdate: string; readonly monthlyViews?: number; readonly seoTitle?: string; readonly seoDescription?: string; readonly contentMetrics?: AiContentMetrics; readonly contentSummary?: ReadonlyArray< AiContentPiece >; }; export type AiContentPiece = | { type: 'heading'; text: string; level: number } | { type: 'paragraph'; text: string } | { type: 'button'; text: string } | { type: 'link'; text: string; href: string } | { type: 'image'; alt: string } | { type: 'form'; summary: string } | { type: 'input'; label: string; inputType: string } | { type: 'other'; tag: string; text: string }; export type AiContentMetrics = { readonly formCount: number; readonly buttonCount: number; readonly buttonLabels: ReadonlyArray< string >; readonly imageCount: number; readonly videoCount: number; readonly internalLinkCount: number; readonly wordCount: number; }; export type AiBestSeller = { readonly id: number; readonly quantity: number; }; export type AiProductSummary = Omit< AiPostSummary, 'title' > & { readonly name: string; readonly price: string; }; export type AiOrderSummary = { readonly date: string; readonly total: string; readonly status: string; readonly products: ReadonlyArray< number >; }; export type AiExperiment = { readonly id: number; readonly type: string; readonly status: string; readonly name: string; readonly description: string; readonly startDate?: string; readonly endDate?: string; readonly alternatives: ReadonlyArray< { readonly name: string; readonly attributes: Attrs; } >; readonly goals: ReadonlyArray< { readonly name: string; readonly actions: ReadonlyArray< { readonly type: string; readonly attributes: Attrs; } >; } >; }; export type AiHeatmap = { readonly id: number; readonly type: string; readonly status: string; readonly name: string; readonly description: string; readonly startDate?: string; readonly endDate?: string; readonly trackingMode: 'post' | 'url'; readonly trackedPostId: number | string; readonly trackedPostType: string; readonly trackedUrl: string; }; export type AiUrlAnalytics = { readonly url: string; readonly monthlyViews: number; }; // eslint-disable-next-line @typescript-eslint/no-explicit-any type Attrs = Record< string, any >;