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 Ladeiraebf2b5f0c54e
diff --git a/apps/web/lib/ai/ai-reward-schema.ts b/apps/web/lib/ai/ai-reward-schema.tsindex d28e5bce1f..d0e63dcd8c 100644--- a/apps/web/lib/ai/ai-reward-schema.ts+++ b/apps/web/lib/ai/ai-reward-schema.ts@@ -223,6 +223,8 @@ export function getAICustomerSourceIds(event: AIRewardEvent) {* validate the reward with getAIRewardSchema after the stream completes.*/export function getAIRewardGenerationSchema(event: AIRewardEvent) {+ const customerSourceIds = getAICustomerSourceIds(event);+return z.object({supported: z@@ -236,8 +238,10 @@ export function getAIRewardGenerationSchema(event: AIRewardEvent) {.describe("When supported is false: brief explanation of what is not supported. When supported is true: null or omit.",),- unavailableSource: z- .enum(getAICustomerSourceIds(event))+ unavailableSource: (customerSourceIds.length+ ? z.enum(customerSourceIds)+ : z.null()+ ).nullish().describe("When supported is false because the request needs a customer source listed under 'Unavailable customer sources': that option id. Otherwise null or omit.",diff --git a/apps/web/tests/misc/ai-reward-schema.test.ts b/apps/web/tests/misc/ai-reward-schema.test.tsindex 8fdf31edd2..7265876f62 100644--- a/apps/web/tests/misc/ai-reward-schema.test.ts+++ b/apps/web/tests/misc/ai-reward-schema.test.ts@@ -292,6 +292,13 @@ describe("getAIRewardGenerationSchema — unsupported refusal", () => {expect(result.success).toBe(true);});+ it("does not send an empty enum for click rewards", () => {+ const json = JSON.stringify(+ getAIRewardGenerationSchema("click").toJSONSchema(),+ );+ expect(json).not.toContain('"enum":[]');+ });+it("rejects an unavailable customer source the event doesn't offer", () => {for (const event of ["sale", "click"] as const) {const result = getAIRewardGenerationSchema(event).safeParse({