The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
code improvements
Pedro Ladeirabbde8d47579e
diff --git a/apps/web/lib/ai/review-reward-tooltip.ts b/apps/web/lib/ai/review-reward-tooltip.tsindex fb0cc29949..bf3b5effcf 100644--- a/apps/web/lib/ai/review-reward-tooltip.ts+++ b/apps/web/lib/ai/review-reward-tooltip.ts@@ -34,17 +34,11 @@ export async function screenRewardTooltipContradiction(try {const authorized = await authorizeRewardTooltipReview(input);if (!authorized) {- console.log("[screenRewardTooltipContradiction] skipped", {- reason: "unauthorized",- });return { flagged: false };}const tooltip = stripRewardTooltipMarkdown(authorized.data.tooltip);if (!tooltip) {- console.log("[screenRewardTooltipContradiction] skipped", {- reason: "empty tooltip",- });return { flagged: false };}@@ -158,7 +152,10 @@ export async function reviewRewardTooltipConsistency(input: unknown): Promise<{schema: reviewRewardTooltipOutputSchema,}),system: buildSystemPrompt(event),- prompt: buildUserPrompt(reward),+ prompt: `Partner copy and the reward it must match:+${JSON.stringify(reward, null, 2)}++Use modifierIndex and conditionIndex from conditionGroups when a condition should change. Write the reason for a non-technical user.`,temperature: 0,maxOutputTokens: 900,});@@ -359,8 +356,6 @@ function filterPayoutFixes({continue;}- const nextAmount =- typeof fix.amount === "number" ? fix.amount : current.amount;const nextDuration =fix.maxDuration === undefined ? current.maxDuration : fix.maxDuration;const amountChanges =@@ -426,10 +421,3 @@ function formatConditionValue(return String(value);}--function buildUserPrompt(reward: ReturnType<typeof describeReward>) {- return `Partner copy and the reward it must match:-${JSON.stringify(reward, null, 2)}--Use modifierIndex and conditionIndex from conditionGroups when a condition should change. Write the reason for a non-technical user.`;-}diff --git a/apps/web/ui/partners/rewards/suggested-fix-popover.tsx b/apps/web/ui/partners/rewards/suggested-fix-popover.tsxindex 4355abf1b8..12a2294553 100644--- a/apps/web/ui/partners/rewards/suggested-fix-popover.tsx+++ b/apps/web/ui/partners/rewards/suggested-fix-popover.tsx@@ -322,6 +322,18 @@ function PayoutFixPreview({ fixes }: { fixes: PayoutFix[] }) {typeof fix.amount === "number" ? fix.amount : currentAmount;const nextDuration =fix.maxDuration === undefined ? currentDuration : fix.maxDuration;+ const amountLabel =+ nextAmount == null || Number.isNaN(nextAmount)+ ? "amount"+ : payoutType === "percentage"+ ? `${nextAmount}%`+ : `$${nextAmount}`;+ const durationLabel =+ nextDuration == null || !Number.isFinite(nextDuration)+ ? "for the customer's lifetime"+ : nextDuration === 0+ ? "one time"+ : `for ${nextDuration} month${nextDuration === 1 ? "" : "s"}`;return (<p@@ -330,11 +342,11 @@ function PayoutFixPreview({ fixes }: { fixes: PayoutFix[] }) {>{group ? "Then pay a" : "Pay a"}{" "}<PreviewChip changed={typeof fix.amount === "number"}>- {formatPayoutAmount(payoutType, nextAmount)}+ {amountLabel}</PreviewChip>{" "}per {event}{" "}<PreviewChip changed={fix.maxDuration !== undefined}>- {formatPayoutDuration(nextDuration)}+ {durationLabel}</PreviewChip></p>);@@ -345,24 +357,6 @@ function PayoutFixPreview({ fixes }: { fixes: PayoutFix[] }) {);}-function formatPayoutAmount(- type: "flat" | "percentage",- amount: number | null | undefined,-) {- if (amount == null || Number.isNaN(amount)) return "amount";- return type === "percentage" ? `${amount}%` : `$${amount}`;-}--function formatPayoutDuration(maxDuration: number | null | undefined) {- if (maxDuration == null || !Number.isFinite(maxDuration)) {- return "for the customer's lifetime";- }-- if (maxDuration === 0) return "one time";-- return `for ${maxDuration} month${maxDuration === 1 ? "" : "s"}`;-}-function SuggestedFixContent({suggestion,field,diff --git a/apps/web/ui/partners/rewards/use-reward-tooltip-consistency.ts b/apps/web/ui/partners/rewards/use-reward-tooltip-consistency.tsindex cd88bc6428..e58cb37a24 100644--- a/apps/web/ui/partners/rewards/use-reward-tooltip-consistency.ts+++ b/apps/web/ui/partners/rewards/use-reward-tooltip-consistency.ts@@ -37,7 +37,6 @@ import {const DEBOUNCE_MS = 200;const HIDE_MS = 300;const REVIEW_CACHE_VERSION = 2;-const PAYOUT_MISMATCH_NOTE = "This copy doesn't match the reward payout.";type TooltipReviewStatus = "idle" | "reviewing";@@ -189,12 +188,6 @@ export function useRewardTooltipConsistency({const reward = serializedRewardRef.current;if (!cacheKey || !workspaceId || !isAiRewardEvent(event) || !reward) {- console.log("[reward-tooltip-review] skipped", {- workspaceId: workspaceId ?? null,- event,- tooltip: tooltip || null,- hasCompleteConditions: !!reward,- });setSuggestions([]);setPayoutFixes([]);setNote(null);@@ -211,7 +204,6 @@ export function useRewardTooltipConsistency({payoutFixes: cached.payoutFixes,note: cached.note,});- console.log("[reward-tooltip-review] cache hit", cached);setSuggestions(cached.suggestions);setPayoutFixes(cached.payoutFixes);setNote(cachedNote);@@ -243,13 +235,11 @@ export function useRewardTooltipConsistency({}flagged = screen.flagged;- console.log("[reward-tooltip-review] jev", screen);- } catch (error) {+ } catch {if (requestId !== requestIdRef.current) {return;}- console.log("[reward-tooltip-review] jev failed", error);flagged = null;}@@ -295,11 +285,6 @@ export function useRewardTooltipConsistency({payoutFixes: nextPayoutFixes,note: result.note,});- console.log("[reward-tooltip-review] haiku", {- suggestions: next,- payoutFixes: nextPayoutFixes,- note: nextNote,- });reviewCache.set(cacheKey, {v: REVIEW_CACHE_VERSION,flagged: true,@@ -343,7 +328,7 @@ export function useRewardTooltipConsistency({return () => {window.clearTimeout(timeout);};- }, [REVIEW_CACHE_VERSION, cacheKey, event, tooltip, workspaceId]);+ }, [cacheKey, event, tooltip, workspaceId]);const visibleSuggestions = useMemo(() => {if (!serializedModifiers?.length) return [];@@ -589,7 +574,7 @@ function noteForFlaggedReward({const trimmed = note?.trim();if (trimmed) return trimmed;- if (flagged === true) return PAYOUT_MISMATCH_NOTE;+ if (flagged === true) return "This copy doesn't match the reward payout.";return null;}@@ -641,8 +626,10 @@ function serializeRewardForReview({basePayout: RewardPayout;modifiers: ReviewRewardTooltipModifier[];} | null {- const basePayout = toBasePayout(baseReward);- if (!isAiRewardEvent(event) || !basePayout || !modifiers?.length) return null;+ if (baseReward?.type !== "flat" && baseReward?.type !== "percentage") {+ return null;+ }+ if (!isAiRewardEvent(event) || !modifiers?.length) return null;if (!modifiers.every((modifier) =>@@ -655,91 +642,65 @@ function serializeRewardForReview({return null;}- const shownAs = stripRewardTooltipMarkdown(description ?? "");-- return {- description: shownAs || null,- basePayout,- modifiers: modifiers.map((modifier) => ({- operator: modifier?.operator ?? "AND",- payout: resolveModifierPayout(modifier, basePayout),- conditions: (modifier?.conditions ?? []).map((condition) => {- const attribute = getRewardConditionAttribute({- event,- entity: condition?.entity,- attribute: condition?.attribute,- });-- let value = condition?.value;- if (- attribute &&- ["number", "currency", "date"].includes(attribute.type) &&- !Array.isArray(value)- ) {- value = Number(value);- }-- return {- entity: condition!.entity!,- attribute: condition!.attribute!,- operator: condition!- .operator as ReviewRewardTooltipModifier["conditions"][number]["operator"],- value:- value as ReviewRewardTooltipModifier["conditions"][number]["value"],- label: condition?.label,- metadataField: condition?.metadataField,- };- }),- })),- };-}--function toBasePayout(- baseReward?: {- type?: string | null;- amount?: number | null;- maxDuration?: number | null;- } | null,-): RewardPayout | null {- if (baseReward?.type !== "flat" && baseReward?.type !== "percentage") {- return null;- }-- return {+ const basePayout: RewardPayout = {type: baseReward.type,amount: baseReward.amount ?? null,maxDuration: normalizeDuration(baseReward.maxDuration),};-}--function resolveModifierPayout(- modifier:- | {- type?: string | null;- amountInCents?: number | null;- amountInPercentage?: number | null;- maxDuration?: number | null;- }- | null- | undefined,- basePayout: RewardPayout,-): RewardPayout {- const type =- modifier?.type === "flat" || modifier?.type === "percentage"- ? modifier.type- : basePayout.type;- const amount =- type === "percentage"- ? modifier?.amountInPercentage ?? basePayout.amount- : modifier?.amountInCents ?? basePayout.amount;+ const shownAs = stripRewardTooltipMarkdown(description ?? "");return {- type,- amount: amount ?? null,- maxDuration:- modifier?.maxDuration === undefined- ? basePayout.maxDuration- : normalizeDuration(modifier.maxDuration),+ description: shownAs || null,+ basePayout,+ modifiers: modifiers.map((modifier) => {+ const type =+ modifier?.type === "flat" || modifier?.type === "percentage"+ ? modifier.type+ : basePayout.type;+ const amount =+ type === "percentage"+ ? modifier?.amountInPercentage ?? basePayout.amount+ : modifier?.amountInCents ?? basePayout.amount;++ return {+ operator: modifier?.operator ?? "AND",+ payout: {+ type,+ amount: amount ?? null,+ maxDuration:+ modifier?.maxDuration === undefined+ ? basePayout.maxDuration+ : normalizeDuration(modifier.maxDuration),+ },+ conditions: (modifier?.conditions ?? []).map((condition) => {+ const attribute = getRewardConditionAttribute({+ event,+ entity: condition?.entity,+ attribute: condition?.attribute,+ });++ let value = condition?.value;+ if (+ attribute &&+ ["number", "currency", "date"].includes(attribute.type) &&+ !Array.isArray(value)+ ) {+ value = Number(value);+ }++ return {+ entity: condition!.entity!,+ attribute: condition!.attribute!,+ operator: condition!+ .operator as ReviewRewardTooltipModifier["conditions"][number]["operator"],+ value:+ value as ReviewRewardTooltipModifier["conditions"][number]["value"],+ label: condition?.label,+ metadataField: condition?.metadataField,+ };+ }),+ };+ }),};}