diff --git a/apps/billing/src/lib/db-marketing/schemas/entries.ts b/apps/billing/src/lib/db-marketing/schemas/entries.ts index da465e8869..ae0e4b73da 100644 --- a/apps/billing/src/lib/db-marketing/schemas/entries.ts +++ b/apps/billing/src/lib/db-marketing/schemas/entries.ts @@ -1,8 +1,8 @@ -import { index, int, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core"; -import { searchQueries } from "./searchQuery"; import { relations } from "drizzle-orm"; +import { index, int, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core"; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import type { z } from "zod"; +import { searchQueries } from "./searchQuery"; import { sections } from "./sections"; export const entries = mysqlTable( diff --git a/apps/billing/src/lib/db-marketing/schemas/evals.ts b/apps/billing/src/lib/db-marketing/schemas/evals.ts index 21ee8a5836..a1f1bfac31 100644 --- a/apps/billing/src/lib/db-marketing/schemas/evals.ts +++ b/apps/billing/src/lib/db-marketing/schemas/evals.ts @@ -1,8 +1,8 @@ -import { mysqlTable, int, timestamp, mysqlEnum, text, index } from "drizzle-orm/mysql-core"; +import { relations } from "drizzle-orm"; +import { index, int, mysqlEnum, mysqlTable, text, timestamp } from "drizzle-orm/mysql-core"; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import { z } from "zod"; import { entries } from "./entries"; -import { relations } from "drizzle-orm"; export const evalTypes = ["technical", "seo", "editorial"] as const; export type EvalType = (typeof evalTypes)[number]; diff --git a/apps/billing/src/lib/db-marketing/schemas/firecrawl.ts b/apps/billing/src/lib/db-marketing/schemas/firecrawl.ts index b6c636a7f8..e6ab48b6ac 100644 --- a/apps/billing/src/lib/db-marketing/schemas/firecrawl.ts +++ b/apps/billing/src/lib/db-marketing/schemas/firecrawl.ts @@ -1,4 +1,4 @@ -import { relations, sql } from "drizzle-orm"; +import { relations } from "drizzle-orm"; import { boolean, index, @@ -9,10 +9,10 @@ import { unique, varchar, } from "drizzle-orm/mysql-core"; -import { serperOrganicResults } from "./serper"; -import { searchQueries } from "./searchQuery"; import { createInsertSchema } from "drizzle-zod"; import type { z } from "zod"; +import { searchQueries } from "./searchQuery"; +import { serperOrganicResults } from "./serper"; export const firecrawlResponses = mysqlTable( "firecrawl_responses", diff --git a/apps/billing/src/lib/db-marketing/schemas/keywords.ts b/apps/billing/src/lib/db-marketing/schemas/keywords.ts index baa3425b6c..e63c40e307 100644 --- a/apps/billing/src/lib/db-marketing/schemas/keywords.ts +++ b/apps/billing/src/lib/db-marketing/schemas/keywords.ts @@ -1,10 +1,10 @@ import { relations } from "drizzle-orm"; import { index, int, mysqlTable, timestamp, unique, varchar } from "drizzle-orm/mysql-core"; -import { searchQueries } from "./searchQuery"; -import { serperOrganicResults } from "./serper"; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; import type { z } from "zod"; +import { searchQueries } from "./searchQuery"; import { sectionsToKeywords } from "./sections"; +import { serperOrganicResults } from "./serper"; export const keywords = mysqlTable( "keywords", diff --git a/apps/billing/src/lib/db-marketing/schemas/searchQuery.ts b/apps/billing/src/lib/db-marketing/schemas/searchQuery.ts index 1f0e0f2e2f..dd1c997a49 100644 --- a/apps/billing/src/lib/db-marketing/schemas/searchQuery.ts +++ b/apps/billing/src/lib/db-marketing/schemas/searchQuery.ts @@ -10,9 +10,9 @@ import { } from "drizzle-orm/mysql-core"; import { createInsertSchema } from "drizzle-zod"; import type { z } from "zod"; -import { serperSearchResponses } from "./serper"; -import { firecrawlResponses } from "./firecrawl"; import { entries } from "./entries"; +import { firecrawlResponses } from "./firecrawl"; +import { serperSearchResponses } from "./serper"; export const searchQueries = mysqlTable( "search_queries", diff --git a/apps/billing/src/lib/db-marketing/schemas/sections.ts b/apps/billing/src/lib/db-marketing/schemas/sections.ts index 2a1f27cdfb..7deeacc3c3 100644 --- a/apps/billing/src/lib/db-marketing/schemas/sections.ts +++ b/apps/billing/src/lib/db-marketing/schemas/sections.ts @@ -1,19 +1,17 @@ +import { relations } from "drizzle-orm"; import { + int, + mysqlEnum, mysqlTable, - varchar, + primaryKey, text, timestamp, - int, - primaryKey, - mysqlEnum, - index, - unique, + varchar, } from "drizzle-orm/mysql-core"; -import { relations } from "drizzle-orm"; import { createInsertSchema, createSelectSchema } from "drizzle-zod"; -import { keywords } from "./keywords"; import type { z } from "zod"; import { entries } from "./entries"; +import { keywords } from "./keywords"; export const sections = mysqlTable("sections", { id: int("id").primaryKey().autoincrement(), diff --git a/apps/billing/src/lib/db-marketing/schemas/serper.ts b/apps/billing/src/lib/db-marketing/schemas/serper.ts index 3875c4f339..8b4ab56cf0 100644 --- a/apps/billing/src/lib/db-marketing/schemas/serper.ts +++ b/apps/billing/src/lib/db-marketing/schemas/serper.ts @@ -2,8 +2,8 @@ import { relations } from "drizzle-orm"; import { index, int, json, mysqlTable, text, timestamp, varchar } from "drizzle-orm/mysql-core"; import { createSelectSchema } from "drizzle-zod"; import type { z } from "zod"; -import { searchQueries } from "./searchQuery"; import { firecrawlResponses } from "./firecrawl"; +import { searchQueries } from "./searchQuery"; // Main SearchResponse table export const serperSearchResponses = mysqlTable( diff --git a/apps/billing/src/lib/firecrawl.ts b/apps/billing/src/lib/firecrawl.ts index 4e748be33a..13ddcba937 100644 --- a/apps/billing/src/lib/firecrawl.ts +++ b/apps/billing/src/lib/firecrawl.ts @@ -1,20 +1,10 @@ import { db } from "@/lib/db-marketing/client"; -import { - firecrawlResponses, - firecrawlResponses, - keywords, - serperOrganicResults, - serperSearchResponses, -} from "@/lib/db-marketing/schemas"; -import { THREE } from "@/trigger/glossary/keyword-research"; -import FirecrawlApp from "@mendable/firecrawl-js"; -import { and, desc, eq, inArray, isNotNull, lte, sql } from "drizzle-orm"; -import { getOrCreateSearchResponse } from "./serper"; -import { generateObject, generateText } from "ai"; -import { openai } from "@ai-sdk/openai"; -import { z } from "zod"; -import { keywordResearchSystemPrompt } from "./keywords"; +import { firecrawlResponses, serperOrganicResults } from "@/lib/db-marketing/schemas"; import type { CacheStrategy } from "@/trigger/glossary/_generate-glossary-entry"; +import { openai } from "@ai-sdk/openai"; +import FirecrawlApp from "@mendable/firecrawl-js"; +import { generateText } from "ai"; +import { eq } from "drizzle-orm"; const firecrawl = new FirecrawlApp({ apiKey: process.env.FIRECRAWL_API_KEY!, @@ -170,7 +160,9 @@ Accurately and concisely summarize the content from the page that ranks #${ - Mention the types of content included, such as images, tables, code snippets, etc. - Cite the term the content is ranking for and its position in the SERP.`; - const prompt = `Summarize the following content for the term "${connectTo.term}" that's ranking #${serperResult?.position ?? "unknown"}: + const prompt = `Summarize the following content for the term "${ + connectTo.term + }" that's ranking #${serperResult?.position ?? "unknown"}: ======= ${firecrawlResponse.markdown} =======`; diff --git a/apps/billing/src/lib/keywords.ts b/apps/billing/src/lib/keywords.ts index 0dbc2b314b..b2ec5a47dc 100644 --- a/apps/billing/src/lib/keywords.ts +++ b/apps/billing/src/lib/keywords.ts @@ -1,12 +1,12 @@ +import { openai } from "@ai-sdk/openai"; +import { generateObject } from "ai"; import { sql } from "drizzle-orm"; import { and } from "drizzle-orm"; import { inArray } from "drizzle-orm"; import { eq } from "drizzle-orm"; +import { z } from "zod"; import { db } from "./db-marketing/client"; import { firecrawlResponses, keywords, serperSearchResponses } from "./db-marketing/schemas"; -import { z } from "zod"; -import { openai } from "@ai-sdk/openai"; -import { generateObject } from "ai"; export const keywordResearchSystemPrompt = ` You are an SEO Expert & Content Writer specializing in creating technical content for Developer Tools that are highly SEO optimized. diff --git a/apps/billing/src/lib/search-query.ts b/apps/billing/src/lib/search-query.ts index 76c5e1a811..7ff8fd6193 100644 --- a/apps/billing/src/lib/search-query.ts +++ b/apps/billing/src/lib/search-query.ts @@ -3,7 +3,7 @@ import { openai } from "@ai-sdk/openai"; import { generateObject } from "ai"; import { eq, sql } from "drizzle-orm"; -import { insertSearchQuerySchema, searchQueries, entries } from "@/lib/db-marketing/schemas"; +import { entries, insertSearchQuerySchema, searchQueries } from "@/lib/db-marketing/schemas"; export async function getOrCreateSearchQuery(args: { term: string }) { const { term } = args; diff --git a/apps/billing/src/trigger/glossary/_generate-glossary-entry.ts b/apps/billing/src/trigger/glossary/_generate-glossary-entry.ts index 9c9a6d88f1..3bd0c09773 100644 --- a/apps/billing/src/trigger/glossary/_generate-glossary-entry.ts +++ b/apps/billing/src/trigger/glossary/_generate-glossary-entry.ts @@ -1,13 +1,13 @@ +import { db } from "@/lib/db-marketing/client"; +import { entries } from "@/lib/db-marketing/schemas"; import { task } from "@trigger.dev/sdk/v3"; -import { keywordResearchTask } from "./keyword-research"; -import { generateOutlineTask } from "./generate-outline"; -import { draftSectionsTask } from "./draft-sections"; -import { seoMetaTagsTask } from "./seo-meta-tags"; -import { createPrTask } from "./create-pr"; import { AbortTaskRunError } from "@trigger.dev/sdk/v3"; -import { db } from "@/lib/db-marketing/client"; import { eq } from "drizzle-orm"; -import { entries } from "@/lib/db-marketing/schemas"; +import { createPrTask } from "./create-pr"; +import { draftSectionsTask } from "./draft-sections"; +import { generateOutlineTask } from "./generate-outline"; +import { keywordResearchTask } from "./keyword-research"; +import { seoMetaTagsTask } from "./seo-meta-tags"; export type CacheStrategy = "revalidate" | "stale"; /** diff --git a/apps/billing/src/trigger/glossary/create-pr.ts b/apps/billing/src/trigger/glossary/create-pr.ts index 932349f8b9..f057af0018 100644 --- a/apps/billing/src/trigger/glossary/create-pr.ts +++ b/apps/billing/src/trigger/glossary/create-pr.ts @@ -1,7 +1,7 @@ -import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; -import { Octokit } from "@octokit/rest"; import { db } from "@/lib/db-marketing/client"; import { entries } from "@/lib/db-marketing/schemas"; +import { Octokit } from "@octokit/rest"; +import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; import { eq } from "drizzle-orm"; import type { CacheStrategy } from "./_generate-glossary-entry"; diff --git a/apps/billing/src/trigger/glossary/draft-sections.ts b/apps/billing/src/trigger/glossary/draft-sections.ts index 3c281310f6..8d95137a7c 100644 --- a/apps/billing/src/trigger/glossary/draft-sections.ts +++ b/apps/billing/src/trigger/glossary/draft-sections.ts @@ -1,12 +1,12 @@ import { db } from "@/lib/db-marketing/client"; import { - type sectionContentTypes, + type SelectEntry, entries, firecrawlResponses, type keywords, + type sectionContentTypes, type sections, type sectionsToKeywords, - type SelectEntry, } from "@/lib/db-marketing/schemas"; import { openai } from "@ai-sdk/openai"; import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; diff --git a/apps/billing/src/trigger/glossary/evals.ts b/apps/billing/src/trigger/glossary/evals.ts index 6dab8d8a7f..7f3c8550ba 100644 --- a/apps/billing/src/trigger/glossary/evals.ts +++ b/apps/billing/src/trigger/glossary/evals.ts @@ -1,17 +1,14 @@ import { db } from "@/lib/db-marketing/client"; +import { entries } from "@/lib/db-marketing/schemas"; import { - evals, - evalTypes, type EvalType, + evals, ratingsSchema, recommendationsSchema, - type Recommendations, } from "@/lib/db-marketing/schemas/evals"; -import { entries } from "@/lib/db-marketing/schemas"; import { openai } from "@ai-sdk/openai"; -import { generateObject } from "ai"; -import { z } from "zod"; import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; +import { generateObject } from "ai"; import { eq } from "drizzle-orm"; import type { CacheStrategy } from "./_generate-glossary-entry"; diff --git a/apps/billing/src/trigger/glossary/generate-outline.ts b/apps/billing/src/trigger/glossary/generate-outline.ts index c43cd2bc65..c27722add6 100644 --- a/apps/billing/src/trigger/glossary/generate-outline.ts +++ b/apps/billing/src/trigger/glossary/generate-outline.ts @@ -1,7 +1,7 @@ import { db } from "@/lib/db-marketing/client"; import { + type SelectKeywords, entries, - type FirecrawlResponse, firecrawlResponses, insertSectionContentTypeSchema, insertSectionSchema, @@ -10,18 +10,17 @@ import { sectionContentTypes, sections, sectionsToKeywords, - type SelectKeywords, selectKeywordsSchema, } from "@/lib/db-marketing/schemas"; +import type { Keyword } from "@/lib/db-marketing/schemas/keywords"; +import { getOrCreateSummary } from "@/lib/firecrawl"; import { openai } from "@ai-sdk/openai"; import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; import { generateObject } from "ai"; import { and, eq, or } from "drizzle-orm"; import { z } from "zod"; import type { CacheStrategy } from "./_generate-glossary-entry"; -import { getOrCreateSummary } from "@/lib/firecrawl"; -import type { Keyword } from "@/lib/db-marketing/schemas/keywords"; -import { performTechnicalEvalTask, performSEOEvalTask, performEditorialEvalTask } from "./evals"; +import { performEditorialEvalTask, performSEOEvalTask, performTechnicalEvalTask } from "./evals"; // TODO: this task is a bit flake-y still // - split up into smaller tasks, and/or diff --git a/apps/billing/src/trigger/glossary/keyword-research.ts b/apps/billing/src/trigger/glossary/keyword-research.ts index 78c330e2ab..8373569415 100644 --- a/apps/billing/src/trigger/glossary/keyword-research.ts +++ b/apps/billing/src/trigger/glossary/keyword-research.ts @@ -1,13 +1,13 @@ import { db } from "@/lib/db-marketing/client"; import { keywords } from "@/lib/db-marketing/schemas"; +import { getOrCreateFirecrawlResponse } from "@/lib/firecrawl"; import { AbortTaskRunError, task } from "@trigger.dev/sdk/v3"; import { sql } from "drizzle-orm"; import { inArray } from "drizzle-orm"; import { and, eq } from "drizzle-orm"; +import { getOrCreateKeywordsFromHeaders, getOrCreateKeywordsFromTitles } from "../../lib/keywords"; import { getOrCreateSearchQuery } from "../../lib/search-query"; import { getOrCreateSearchResponse } from "../../lib/serper"; -import { getOrCreateKeywordsFromHeaders, getOrCreateKeywordsFromTitles } from "../../lib/keywords"; -import { getOrCreateFirecrawlResponse } from "@/lib/firecrawl"; import type { CacheStrategy } from "./_generate-glossary-entry"; export const THREE = 3; diff --git a/apps/billing/src/trigger/glossary/seo-meta-tags.ts b/apps/billing/src/trigger/glossary/seo-meta-tags.ts index 456357a11c..38682bb619 100644 --- a/apps/billing/src/trigger/glossary/seo-meta-tags.ts +++ b/apps/billing/src/trigger/glossary/seo-meta-tags.ts @@ -1,11 +1,10 @@ -import { Trigger } from "@trigger.dev/sdk"; -import { z } from "zod"; -import { eq, and, or } from "drizzle-orm"; -import { keywords, firecrawlResponses, entries } from "../../lib/db-marketing/schemas"; -import { task } from "@trigger.dev/sdk/v3"; import { db } from "@/lib/db-marketing/client"; -import { generateObject, generateText } from "ai"; import { openai } from "@ai-sdk/openai"; +import { task } from "@trigger.dev/sdk/v3"; +import { generateObject } from "ai"; +import { and, eq, or } from "drizzle-orm"; +import { z } from "zod"; +import { entries, firecrawlResponses, keywords } from "../../lib/db-marketing/schemas"; import type { CacheStrategy } from "./_generate-glossary-entry"; // Define the job