From 97a473d3dec9b6dc7d51b38172e06b9200552aec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Wed, 2 Apr 2025 19:36:23 +0200 Subject: [PATCH] rename monitor to compare --- apps/api/src/controllers/v1/types.ts | 10 +++++----- apps/api/src/scraper/scrapeURL/transformers/diff.ts | 8 ++++---- apps/api/src/scraper/scrapeURL/transformers/index.ts | 10 +++++----- apps/js-sdk/firecrawl/src/index.ts | 7 ++++++- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts index c0613fcc..b610826d 100644 --- a/apps/api/src/controllers/v1/types.ts +++ b/apps/api/src/controllers/v1/types.ts @@ -21,7 +21,7 @@ export type Format = | "screenshot" | "screenshot@fullPage" | "extract" - | "monitor"; + | "compare"; export const url = z.preprocess( (x) => { @@ -166,7 +166,7 @@ const baseScrapeOptions = z "screenshot@fullPage", "extract", "json", - "monitor", + "compare", ]) .array() .optional() @@ -176,8 +176,8 @@ const baseScrapeOptions = z "You may only specify either screenshot or screenshot@fullPage", ) .refine( - (x) => !x.includes("monitor") || x.includes("markdown"), - "The monitor format requires the markdown format to be specified as well", + (x) => !x.includes("compare") || x.includes("markdown"), + "The compare format requires the markdown format to be specified as well", ), headers: z.record(z.string(), z.string()).optional(), includeTags: z.string().array().optional(), @@ -552,7 +552,7 @@ export type Document = { value: unknown }[]; }; - monitor?: { + compare?: { previousScrapeAt: string | null; changeStatus: "new" | "same" | "changed" | "removed"; visibility: "visible" | "hidden"; diff --git a/apps/api/src/scraper/scrapeURL/transformers/diff.ts b/apps/api/src/scraper/scrapeURL/transformers/diff.ts index fa61fe9a..9628844d 100644 --- a/apps/api/src/scraper/scrapeURL/transformers/diff.ts +++ b/apps/api/src/scraper/scrapeURL/transformers/diff.ts @@ -3,7 +3,7 @@ import { Document } from "../../../controllers/v1/types"; import { Meta } from "../index"; export async function deriveDiff(meta: Meta, document: Document): Promise { - if (meta.options.formats.includes("monitor")) { + if (meta.options.formats.includes("compare")) { const res = await supabase_service .rpc("diff_get_last_scrape_1", { i_team_id: meta.internalOptions.teamId, @@ -21,20 +21,20 @@ export async function deriveDiff(meta: Meta, document: Document): Promise [...x.replace(/\s+/g, "").replace(/\[iframe\]\(.+?\)/g, "")].sort().join(""); - document.monitor = { + document.compare = { previousScrapeAt: data.o_date_added, changeStatus: document.metadata.statusCode === 404 ? "removed" : transformer(previousMarkdown) === transformer(currentMarkdown) ? "same" : "changed", visibility: meta.internalOptions.urlInvisibleInCurrentCrawl ? "hidden" : "visible", } } else if (!res.error) { - document.monitor = { + document.compare = { previousScrapeAt: null, changeStatus: document.metadata.statusCode === 404 ? "removed" : "new", visibility: meta.internalOptions.urlInvisibleInCurrentCrawl ? "hidden" : "visible", } } else { meta.logger.error("Error fetching previous scrape", { error: res.error }); - document.warning = "Monitoring failed, please try again later." + (document.warning ? ` ${document.warning}` : ""); + document.warning = "Comparing failed, please try again later." + (document.warning ? ` ${document.warning}` : ""); } } diff --git a/apps/api/src/scraper/scrapeURL/transformers/index.ts b/apps/api/src/scraper/scrapeURL/transformers/index.ts index 744a4375..114c59a8 100644 --- a/apps/api/src/scraper/scrapeURL/transformers/index.ts +++ b/apps/api/src/scraper/scrapeURL/transformers/index.ts @@ -148,14 +148,14 @@ export function coerceFieldsToFormats( ); } - if (!formats.has("monitor") && document.monitor !== undefined) { + if (!formats.has("compare") && document.compare !== undefined) { meta.logger.warn( - "Removed monitor from Document because it wasn't in formats -- this is extremely wasteful and indicates a bug.", + "Removed compare from Document because it wasn't in formats -- this is extremely wasteful and indicates a bug.", ); - delete document.monitor; - } else if (formats.has("monitor") && document.monitor === undefined) { + delete document.compare; + } else if (formats.has("compare") && document.compare === undefined) { meta.logger.warn( - "Request had format monitor, but there was no monitor field in the result.", + "Request had format compare, but there was no compare field in the result.", ); } diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index 41d13da0..bec5288f 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -69,6 +69,11 @@ export interface FirecrawlDocument; includeTags?: string[]; excludeTags?: string[];