interface PromptVariant { /** Variant id — matches a feature-flag payload / flag value. */ id: string; /** The prompt value to serve when this variant is picked. */ prompt: TResult; /** Relative weight used by the default sticky-hash resolver. Default 1. */ weight?: number; } interface PromptExperimentContext { /** * Opaque stable identifier used for sticky assignment — user id, * session id, or any business key. Without this, resolution is * random-per-call (fine for smoke tests, bad for A/B cohorts). */ subjectId?: string; /** Pass-through metadata handed to custom resolvers. */ metadata?: Record; } type PromptResolver = (variants: PromptVariant[], context: PromptExperimentContext) => PromptVariant | Promise> | string | Promise; interface PromptExperiment { /** Experiment name — used by analytics / flag providers as the key. */ name: string; variants: PromptVariant[]; /** * Pick a variant. Plug in your feature-flag client * (PostHog / GrowthBook / Unleash / custom) here. If it throws or * returns an unknown id, the experiment falls back to the built-in * sticky-hash resolver. */ resolve: PromptResolver; /** Fires on every resolution — feed your analytics pipeline. */ onExposure?: (decision: { name: string; variantId: string; subjectId?: string; fallback: boolean; }) => void; } interface PromptDecision { name: string; variantId: string; prompt: TResult; fallback: boolean; } /** * Deterministic sticky assignment: same `subjectId` always maps to * the same variant, weighted by `variant.weight`. When `subjectId` * is omitted, falls back to `Math.random()` — good enough for * smoke tests, not for production cohorts. */ declare function stickyResolver(): PromptResolver; /** * Build a prompt experiment. Call `.pick(context)` at the call site * to get the variant id + prompt; wire `resolve` to your flag * provider's variant-selection API (PostHog's `getFeatureFlagPayload`, * GrowthBook's `getFeatureValue`, etc.). */ declare function createPromptExperiment(config: PromptExperiment): { pick: (context?: PromptExperimentContext) => Promise>; }; /** * Convenience resolver: maps your flag client's `getVariant(name, * subjectId) => string | undefined` signature directly into a * `PromptResolver`. Works with PostHog, GrowthBook, Unleash — anything * that returns a string variant id. */ declare function flagResolver(getVariant: (name: string, context: PromptExperimentContext) => string | undefined | Promise, experimentName: string): PromptResolver; export { type PromptDecision, type PromptExperiment, type PromptExperimentContext, type PromptResolver, type PromptVariant, createPromptExperiment, flagResolver, stickyResolver };