Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

upgrade to sonnet 4.6, refactor to streamText + Output.object

Steven Tey081a5258c346
diff --git a/apps/web/app/api/ai/support-chat/route.ts b/apps/web/app/api/ai/support-chat/route.ts
index a86aff0fd2..8f2019f2a1 100644
--- a/apps/web/app/api/ai/support-chat/route.ts
+++ b/apps/web/app/api/ai/support-chat/route.ts
@@ -51,7 +51,7 @@ export const POST = withSession(async ({ req, session }) => {
}
const result = streamText({
- model: anthropic("claude-sonnet-4-20250514"),
+ model: anthropic("claude-sonnet-4-6"),
system: buildSystemPrompt(globalContext),
messages: await convertToModelMessages(messages),
stopWhen: stepCountIs(5),
diff --git a/apps/web/lib/actions/partners/generate-lander.ts b/apps/web/lib/actions/partners/generate-lander.ts
index 77a2bdd9d2..1fc7ba31db 100644
--- a/apps/web/lib/actions/partners/generate-lander.ts
+++ b/apps/web/lib/actions/partners/generate-lander.ts
@@ -16,7 +16,7 @@ import FireCrawlApp, {
ErrorResponse,
ScrapeResponse,
} from "@mendable/firecrawl-js";
-import { generateObject } from "ai";
+import { generateText, Output } from "ai";
import * as z from "zod/v4";
import { authActionClient } from "../safe-action";
import { throwIfNoPermission } from "../throw-if-no-permission";
@@ -95,9 +95,11 @@ export const generateLanderAction = authActionClient
? cleanMarkdown(pricingScrapeResult.markdown || "")
: null;
- const { object } = await generateObject({
- model: anthropic("claude-sonnet-4-20250514"),
- schema: landerData ? programLanderSchema : programLanderSimpleSchema,
+ const { output } = await generateText({
+ model: anthropic("claude-sonnet-4-6"),
+ output: Output.object({
+ schema: landerData ? programLanderSchema : programLanderSimpleSchema,
+ }),
prompt:
// Instructions
`Generate a basic landing page for an affiliate program powered by Dub Partners based on a company website. ` +
@@ -137,7 +139,7 @@ export const generateLanderAction = authActionClient
temperature: 0.4,
});
- return programLanderSchema.parse(object);
+ return programLanderSchema.parse(output);
});
function cleanMarkdown(markdown: string) {
diff --git a/apps/web/lib/ai/generate-csv-mapping.ts b/apps/web/lib/ai/generate-csv-mapping.ts
index 301e1a7d92..d4a82d34ee 100644
--- a/apps/web/lib/ai/generate-csv-mapping.ts
+++ b/apps/web/lib/ai/generate-csv-mapping.ts
@@ -2,7 +2,7 @@
import { anthropic } from "@ai-sdk/anthropic";
import { createStreamableValue } from "@ai-sdk/rsc";
-import { streamObject } from "ai";
+import { Output, streamText } from "ai";
import * as z from "zod/v4";
export async function generateCsvMapping(
@@ -12,29 +12,33 @@ export async function generateCsvMapping(
const stream = createStreamableValue();
(async () => {
- const { partialObjectStream } = streamObject({
- model: anthropic("claude-sonnet-4-20250514"),
- schema: z.object({
- link: z
- .string()
- .optional()
- .describe("The shortlink (link), including the domain and path."),
- url: z.string().optional().describe("The full URL of the shortlink"),
- title: z.string().optional().describe("The title of the shortlink"),
- description: z
- .string()
- .optional()
- .describe("The description of the shortlink"),
- tags: z
- .string()
- .optional()
- .describe(
- "A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",
- ),
- createdAt: z
- .string()
- .optional()
- .describe("The date and time the shortlink was created (createdAt)"),
+ const { partialOutputStream } = streamText({
+ model: anthropic("claude-sonnet-6"),
+ output: Output.object({
+ schema: z.object({
+ link: z
+ .string()
+ .optional()
+ .describe("The shortlink (link), including the domain and path."),
+ url: z.string().optional().describe("The full URL of the shortlink"),
+ title: z.string().optional().describe("The title of the shortlink"),
+ description: z
+ .string()
+ .optional()
+ .describe("The description of the shortlink"),
+ tags: z
+ .string()
+ .optional()
+ .describe(
+ "A comma-separated list of tags for shortlink organization (NOT to be mapped to a description).",
+ ),
+ createdAt: z
+ .string()
+ .optional()
+ .describe(
+ "The date and time the shortlink was created (createdAt)",
+ ),
+ }),
}),
prompt:
`The following columns are the headings from a CSV import file for importing a company's short links. ` +
@@ -47,7 +51,7 @@ export async function generateCsvMapping(
temperature: 0.2,
});
- for await (const partialObject of partialObjectStream) {
+ for await (const partialObject of partialOutputStream) {
stream.update(partialObject);
}
diff --git a/apps/web/lib/ai/generate-filters.ts b/apps/web/lib/ai/generate-filters.ts
index a918bc43e8..df514d3d7e 100644
--- a/apps/web/lib/ai/generate-filters.ts
+++ b/apps/web/lib/ai/generate-filters.ts
@@ -42,7 +42,7 @@ export async function generateFilters(prompt: string) {
(async () => {
const { partialOutputStream } = streamText({
- model: anthropic("claude-sonnet-4-20250514"),
+ model: anthropic("claude-sonnet-6"),
output: Output.object({ schema: AI_FILTER_SCHEMA }),
system: SYSTEM_PROMPT,
prompt,
diff --git a/apps/web/scripts/migrations/backfill-program-categories.ts b/apps/web/scripts/migrations/backfill-program-categories.ts
index f274fe3247..dfa3e3c406 100644
--- a/apps/web/scripts/migrations/backfill-program-categories.ts
+++ b/apps/web/scripts/migrations/backfill-program-categories.ts
@@ -2,7 +2,7 @@ import { anthropic } from "@ai-sdk/anthropic";
import { prisma } from "@dub/prisma";
import { Category } from "@dub/prisma/client";
import FireCrawlApp from "@mendable/firecrawl-js";
-import { generateObject } from "ai";
+import { generateText, Output } from "ai";
import "dotenv-flow/config";
import * as z from "zod/v4";
@@ -103,13 +103,16 @@ Page Title: ${title}
Meta Description: ${description}
Website Content Preview: ${content.slice(0, 300)}...`;
- const { object } = await generateObject({
- model: anthropic("claude-sonnet-4-20250514"),
- schema: categorizationSchema,
+ const { output } = await generateText({
+ model: anthropic("claude-sonnet-4-6"),
+ output: Output.object({
+ schema: categorizationSchema,
+ }),
prompt,
+ temperature: 0.4,
});
- return object.categories;
+ return categorizationSchema.parse(output).categories;
} catch (error) {
// console.error(`Error categorizing ${programName}:`, error);
diff --git a/apps/web/scripts/programs/add-to-marketplace.ts b/apps/web/scripts/programs/add-to-marketplace.ts
index eeb0526837..5626b184a9 100644
--- a/apps/web/scripts/programs/add-to-marketplace.ts
+++ b/apps/web/scripts/programs/add-to-marketplace.ts
@@ -2,7 +2,7 @@ import { anthropic } from "@ai-sdk/anthropic";
import { prisma } from "@dub/prisma";
import { Category } from "@dub/prisma/client";
import FireCrawlApp from "@mendable/firecrawl-js";
-import { generateObject } from "ai";
+import { generateText, Output } from "ai";
import "dotenv-flow/config";
import * as z from "zod/v4";
@@ -94,13 +94,16 @@ Page Title: ${title}
Meta Description: ${description}
Website Content Preview: ${content.slice(0, 300)}...`;
- const { object } = await generateObject({
- model: anthropic("claude-sonnet-4-20250514"),
- schema: categorizationSchema,
+ const { output } = await generateText({
+ model: anthropic("claude-sonnet-4-6"),
+ output: Output.object({
+ schema: categorizationSchema,
+ }),
prompt,
+ temperature: 0.4,
});
- return object.categories;
+ return categorizationSchema.parse(output).categories;
} catch (error) {
// console.error(`Error categorizing ${programName}:`, error);