Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(pdf): grant the large-PDF cap through a team flag (#4823)
Abimael Martell24b827e7d948
diff --git a/apps/api/src/config.ts b/apps/api/src/config.tsindex 014a41cd7..1e96563eb 100644--- a/apps/api/src/config.ts+++ b/apps/api/src/config.ts@@ -453,7 +453,8 @@ const configSchema = z.object({.int().positive().default(256 * 1024 * 1024),- // Comma-separated team ids granted the privileged cap.+ // Comma-separated team ids granted the privileged cap. Prefer the+ // `largePdfs` team flag, which grants the same cap without a deploy.PDF_BY_REFERENCE_PRIVILEGED_TEAM_IDS: z.string().optional(),// RunPoddiff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.tsindex fd945c804..52d617079 100644--- a/apps/api/src/controllers/v1/types.ts+++ b/apps/api/src/controllers/v1/types.ts@@ -1382,6 +1382,8 @@ export type TeamFlags = {bypassCreditChecks?: boolean;debugBranding?: boolean;maxBrowserSessions?: number;+ // grants the privileged large-PDF size cap (PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED)+ largePdfs?: boolean;// POST /v2/search/:jobId/feedback returns 403 TEAM_OPTED_OUT when true.searchFeedbackOptOut?: boolean;researchBeta?: boolean;diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.tsindex 68f0c7e0a..3a958a0e5 100644--- a/apps/api/src/controllers/v2/types.ts+++ b/apps/api/src/controllers/v2/types.ts@@ -2069,6 +2069,8 @@ export type TeamFlags = {bypassCreditChecks?: boolean;debugBranding?: boolean;maxBrowserSessions?: number;+ // grants the privileged large-PDF size cap (PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED)+ largePdfs?: boolean;researchBeta?: boolean;menuBeta?: boolean;enrichBeta?: boolean;diff --git a/apps/api/src/scraper/scrapeURL/engines/pdf/__tests__/fireEngineHandoff.test.ts b/apps/api/src/scraper/scrapeURL/engines/pdf/__tests__/fireEngineHandoff.test.tsindex 24b57cece..9a427ef4b 100644--- a/apps/api/src/scraper/scrapeURL/engines/pdf/__tests__/fireEngineHandoff.test.ts+++ b/apps/api/src/scraper/scrapeURL/engines/pdf/__tests__/fireEngineHandoff.test.ts@@ -208,6 +208,25 @@ describe("largePdfLimitBytes (team tiers)", () => {expect(largePdfLimitBytes(metaForTeam("team-b"))).toBe(256 * 1024 * 1024);});+ it("returns the privileged cap for teams with the largePdfs flag", () => {+ (config as any).PDF_BY_REFERENCE_PRIVILEGED_TEAM_IDS = "";+ (config as any).PDF_BY_REFERENCE_MAX_BYTES_DEFAULT = 50 * 1024 * 1024;+ (config as any).PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED = 200 * 1024 * 1024;+ const meta = (teamFlags: unknown) =>+ ({ internalOptions: { teamId: "team-x", teamFlags } }) as any;+ expect(largePdfLimitBytes(meta({ largePdfs: true }))).toBe(+ 200 * 1024 * 1024,+ );+ expect(largePdfLimitBytes(meta({ largePdfs: false }))).toBe(+ 50 * 1024 * 1024,+ );+ expect(largePdfLimitBytes(meta({ largePdfs: "true" }))).toBe(+ 50 * 1024 * 1024,+ );+ expect(largePdfLimitBytes(meta({}))).toBe(50 * 1024 * 1024);+ expect(largePdfLimitBytes(meta(null))).toBe(50 * 1024 * 1024);+ });+it("clamps configured caps to the 256MB architectural ceiling", () => {(config as any).PDF_BY_REFERENCE_PRIVILEGED_TEAM_IDS = "team-a";(config as any).PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED = 999 * 1024 * 1024;diff --git a/apps/api/src/scraper/scrapeURL/engines/pdf/fire-pdf/by-reference.ts b/apps/api/src/scraper/scrapeURL/engines/pdf/fire-pdf/by-reference.tsindex d2e3cecd3..4014eb5d8 100644--- a/apps/api/src/scraper/scrapeURL/engines/pdf/fire-pdf/by-reference.ts+++ b/apps/api/src/scraper/scrapeURL/engines/pdf/fire-pdf/by-reference.ts@@ -164,8 +164,9 @@ export async function rewritePdfInputForFirePdf(}/**- * The per-team large-PDF byte limit: the privileged cap for allowlisted- * team ids, the default cap for everyone else, both clamped to the 256MB+ * The per-team large-PDF byte limit: the privileged cap for teams with the+ * `largePdfs` flag or an id on the env allowlist, the default cap for+ * everyone else, both clamped to the 256MB* architectural ceiling. Every acquisition path enforces this one number —* the direct-download admission, the fire-engine handoff download, the* by-reference routing gate, and (as pdfMaxSize) fire-engine's own capture@@ -182,10 +183,12 @@ export function largePdfLimitBytes(meta: Meta): number {.map(id => id.trim()).filter(Boolean),);- const raw =- teamId && privilegedIds.has(teamId)- ? config.PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED- : config.PDF_BY_REFERENCE_MAX_BYTES_DEFAULT;+ const privileged =+ meta.internalOptions.teamFlags?.largePdfs === true ||+ (!!teamId && privilegedIds.has(teamId));+ const raw = privileged+ ? config.PDF_BY_REFERENCE_MAX_BYTES_PRIVILEGED+ : config.PDF_BY_REFERENCE_MAX_BYTES_DEFAULT;// Config is schema-validated to positive integers; the clamp bounds both// ends anyway so an invalid value can never reject every PDF or send// fire-engine a nonsensical pdfMaxSize.