Skip to content

Commit

Permalink
Merge branch 'main' into sdk/fixed-none-undefined-on-response
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsideguide authored Jan 3, 2025
2 parents bafcc00 + 87757d9 commit 2e53eb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/js-sdk/firecrawl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mendable/firecrawl-js",
"version": "1.11.1",
"version": "1.11.3",
"description": "JavaScript SDK for Firecrawl API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
18 changes: 10 additions & 8 deletions apps/js-sdk/firecrawl/src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -247,7 +247,7 @@ export interface MapResponse {
*/
export interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
prompt?: string;
schema?: LLMSchema;
schema?: LLMSchema | object;
systemPrompt?: string;
allowExternalLinks?: boolean;
includeSubdomains?: boolean;
Expand Down Expand Up @@ -861,16 +861,18 @@ export default class FirecrawlApp {
async extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse> {
const headers = this.prepareHeaders();

if (!params?.prompt) {
throw new FirecrawlError("Prompt is required", 400);
}

let jsonData: { urls: string[] } & ExtractParams<T> = { 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 {
Expand Down

0 comments on commit 2e53eb9

Please sign in to comment.