From 20d1855ad5b81af9ca394ebac82c9eb13c17ed0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C5=91=20M=C3=B3ricz?= Date: Wed, 18 Sep 2024 20:47:56 +0200 Subject: [PATCH] feat(js-sdk): actions integration --- apps/js-sdk/firecrawl/src/index.ts | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index 6c859bee..4c30d5fd 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -58,7 +58,7 @@ export interface FirecrawlDocumentMetadata { * Document interface for Firecrawl. * Represents a document retrieved or processed by Firecrawl. */ -export interface FirecrawlDocument { +export interface FirecrawlDocument { url?: string; markdown?: string; html?: string; @@ -67,6 +67,7 @@ export interface FirecrawlDocument { extract?: T; screenshot?: string; metadata?: FirecrawlDocumentMetadata; + actions: ActionsSchema; } /** @@ -83,19 +84,35 @@ export interface CrawlScrapeOptions { timeout?: number; } -export interface ScrapeParams extends CrawlScrapeOptions { +export type Action = { + type: "wait", + milliseconds: number, +} | { + type: "click", + selector: string, +} | { + type: "screenshot", + fullPage?: boolean, +}; + +export interface ScrapeParams extends CrawlScrapeOptions { extract?: { prompt?: string; schema?: LLMSchema; systemPrompt?: string; }; + actions?: ActionsSchema; +} + +export interface ActionsResult { + screenshots: string[]; } /** * Response interface for scraping operations. * Defines the structure of the response received after a scraping operation. */ -export interface ScrapeResponse extends FirecrawlDocument { +export interface ScrapeResponse extends FirecrawlDocument { success: true; warning?: string; error?: string; @@ -200,10 +217,10 @@ export default class FirecrawlApp { * @param params - Additional parameters for the scrape request. * @returns The response from the scrape operation. */ - async scrapeUrl( + async scrapeUrl( url: string, - params?: ScrapeParams - ): Promise> | ErrorResponse> { + params?: ScrapeParams + ): Promise, ActionsSchema extends Action[] ? ActionsResult : never> | ErrorResponse> { const headers: AxiosRequestHeaders = { "Content-Type": "application/json", Authorization: `Bearer ${this.apiKey}`,