The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add plan features context for support chat agent
Pedro Ladeira586157cb38a7
diff --git a/apps/web/app/api/ai/support-chat/route.ts b/apps/web/app/api/ai/support-chat/route.tsindex 8f2019f2a1..21c7f531a5 100644--- a/apps/web/app/api/ai/support-chat/route.ts+++ b/apps/web/app/api/ai/support-chat/route.ts@@ -4,6 +4,7 @@ import {} from "@/lib/ai/build-system-prompt";import { createSupportTicketTool } from "@/lib/ai/create-support-ticket";import { findRelevantDocsTool } from "@/lib/ai/find-relevant-docs";+import { getPlanComparisonTool } from "@/lib/ai/get-plan-comparison";import { getProgramPerformanceTool } from "@/lib/ai/get-program-performance";import { getWorkspaceDetailsTool } from "@/lib/ai/get-workspace-details";import { requestSupportTicketTool } from "@/lib/ai/request-support-ticket";@@ -57,6 +58,7 @@ export const POST = withSession(async ({ req, session }) => {stopWhen: stepCountIs(5),tools: {findRelevantDocs: findRelevantDocsTool,+ getPlanComparison: getPlanComparisonTool,getProgramPerformance: getProgramPerformanceTool,getWorkspaceDetails: getWorkspaceDetailsTool,requestSupportTicket: requestSupportTicketTool,diff --git a/apps/web/lib/ai/build-system-prompt.ts b/apps/web/lib/ai/build-system-prompt.tsindex 937cef7b15..c2cbfedca0 100644--- a/apps/web/lib/ai/build-system-prompt.ts+++ b/apps/web/lib/ai/build-system-prompt.ts@@ -12,6 +12,7 @@ const CONTEXT_SYSTEM_PROMPTS: Record<SupportChatContext, string> = {app: `You are a helpful Dub support assistant helping users manage their Dub workspaces and links.Focus on: link shortening, custom domains, analytics, click tracking, API usage, workspace management, billing, and integrations.When the user asks about their specific workspace data — such as their plan, usage, links count, billing cycle, or payment status — call getWorkspaceDetails with the workspace's ID before answering. Use this real data in your response instead of guessing or citing generic documentation.+ When users ask about plan differences, upgrades, or which plan includes a feature, call getPlanComparison before answering.When a user has a billing issue, account access problem, or a bug that can't be resolved through documentation, first call requestSupportTicket (to show them an upload form), then after the user confirms, call createSupportTicket.`,partners: `You are a helpful Dub Partners support assistant helping affiliate partners with their programs.@@ -24,6 +25,7 @@ const CONTEXT_SYSTEM_PROMPTS: Record<SupportChatContext, string> = {const BASE_SYSTEM_PROMPT = `You are powered by Dub's documentation and help articles.ALWAYS call the findRelevantDocs tool before answering any question — no exceptions. Do not answer from memory.+ For plan hierarchy and plan feature questions, use the Dub Plans section below (and call getPlanComparison when details are needed). Do not infer plan order from plan names.Ground every answer in the content retrieved by findRelevantDocs.Respond in concise, clear markdown. Strictly avoid using headings (h1, h2, h3, h4, h5, h6) in your responses.If you find a relevant article, include a link to it in your response.diff --git a/apps/web/lib/ai/get-plan-comparison.ts b/apps/web/lib/ai/get-plan-comparison.tsnew file mode 100644index 0000000000..766bab7bdf--- /dev/null+++ b/apps/web/lib/ai/get-plan-comparison.ts@@ -0,0 +1,19 @@+import { getPlanSummaries } from "@/lib/ai/plan-context";+import { tool } from "ai";+import { z } from "zod";++const planSummarySchema = z.object({+ name: z.string(),+ order: z.number(),+ featureTitle: z.string().optional(),+ features: z.array(z.string()),+ capabilities: z.record(z.string(), z.boolean()),+});++export const getPlanComparisonTool = tool({+ description:+ "Returns the canonical Dub plan hierarchy and features. Use when users ask about plan differences, upgrades, or which plan includes a feature.",+ inputSchema: z.object({}),+ outputSchema: z.array(planSummarySchema),+ execute: async () => getPlanSummaries(),+});diff --git a/apps/web/lib/ai/plan-context.ts b/apps/web/lib/ai/plan-context.tsnew file mode 100644index 0000000000..6a9efe975b--- /dev/null+++ b/apps/web/lib/ai/plan-context.ts@@ -0,0 +1,24 @@+import { getPlanCapabilities } from "@/lib/plan-capabilities";+import { PLANS } from "@dub/utils";++export type PlanSummary = {+ name: string;+ order: number;+ featureTitle?: string;+ features: string[];+ capabilities: ReturnType<typeof getPlanCapabilities>;+};++export function getPlanSummaries(): PlanSummary[] {+ const summaries = PLANS.map((plan, index) => ({+ name: plan.name,+ order: index + 1,+ featureTitle: plan.featureTitle,+ features: plan.features?.map((feature) => feature.text) ?? [],+ capabilities: getPlanCapabilities(plan.name.toLowerCase()),+ }));++ console.log("summaries ==> ", summaries);++ return summaries;+}