From 87757d9b8e6bacc658b48832deb47c51eaf7412a Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 3 Jan 2025 13:19:08 -0300 Subject: [PATCH] Nick: fixed schemas on extract for node --- apps/js-sdk/firecrawl/package.json | 2 +- apps/js-sdk/firecrawl/src/index.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/js-sdk/firecrawl/package.json b/apps/js-sdk/firecrawl/package.json index 9aab848a..68140437 100644 --- a/apps/js-sdk/firecrawl/package.json +++ b/apps/js-sdk/firecrawl/package.json @@ -1,6 +1,6 @@ { "name": "@mendable/firecrawl-js", - "version": "1.11.0", + "version": "1.11.2", "description": "JavaScript SDK for Firecrawl API", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/apps/js-sdk/firecrawl/src/index.ts b/apps/js-sdk/firecrawl/src/index.ts index af9dbc75..60f485d0 100644 --- a/apps/js-sdk/firecrawl/src/index.ts +++ b/apps/js-sdk/firecrawl/src/index.ts @@ -1,5 +1,5 @@ import axios, { type AxiosResponse, type AxiosRequestHeaders, AxiosError } from "axios"; -import type * as zt from "zod"; +import * as zt from "zod"; import { zodToJsonSchema } from "zod-to-json-schema"; import { WebSocket } from "isows"; import { TypedEventTarget } from "typescript-event-target"; @@ -247,7 +247,7 @@ export interface MapResponse { */ export interface ExtractParams { prompt?: string; - schema?: LLMSchema; + schema?: LLMSchema | object; systemPrompt?: string; allowExternalLinks?: boolean; includeSubdomains?: boolean; @@ -835,16 +835,18 @@ export default class FirecrawlApp { async extract(urls: string[], params?: ExtractParams): Promise> | ErrorResponse> { const headers = this.prepareHeaders(); - if (!params?.prompt) { - throw new FirecrawlError("Prompt is required", 400); - } - let jsonData: { urls: string[] } & ExtractParams = { urls, ...params }; let jsonSchema: any; try { - jsonSchema = params?.schema ? zodToJsonSchema(params.schema) : undefined; + if (!params?.schema) { + jsonSchema = undefined; + } else if (params.schema instanceof zt.ZodType) { + jsonSchema = zodToJsonSchema(params.schema); + } else { + jsonSchema = params.schema; + } } catch (error: any) { - throw new FirecrawlError("Invalid schema. Use a valid Zod schema.", 400); + throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400); } try {