firecrawl 1.11.0 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +9 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -5
- package/package.json +1 -1
- package/src/index.ts +10 -8
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,7 @@ __export(src_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
|
38
38
|
var import_axios = __toESM(require("axios"), 1);
|
|
39
|
+
var zt = __toESM(require("zod"), 1);
|
|
39
40
|
var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
40
41
|
var import_isows = require("isows");
|
|
41
42
|
var import_typescript_event_target = require("typescript-event-target");
|
|
@@ -492,15 +493,18 @@ var FirecrawlApp = class {
|
|
|
492
493
|
*/
|
|
493
494
|
async extract(urls, params) {
|
|
494
495
|
const headers = this.prepareHeaders();
|
|
495
|
-
if (!params?.prompt) {
|
|
496
|
-
throw new FirecrawlError("Prompt is required", 400);
|
|
497
|
-
}
|
|
498
496
|
let jsonData = { urls, ...params };
|
|
499
497
|
let jsonSchema;
|
|
500
498
|
try {
|
|
501
|
-
|
|
499
|
+
if (!params?.schema) {
|
|
500
|
+
jsonSchema = void 0;
|
|
501
|
+
} else if (params.schema instanceof zt.ZodType) {
|
|
502
|
+
jsonSchema = (0, import_zod_to_json_schema.zodToJsonSchema)(params.schema);
|
|
503
|
+
} else {
|
|
504
|
+
jsonSchema = params.schema;
|
|
505
|
+
}
|
|
502
506
|
} catch (error) {
|
|
503
|
-
throw new FirecrawlError("Invalid schema.
|
|
507
|
+
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
|
|
504
508
|
}
|
|
505
509
|
try {
|
|
506
510
|
const response = await this.postRequest(
|
package/dist/index.d.cts
CHANGED
|
@@ -229,7 +229,7 @@ interface MapResponse {
|
|
|
229
229
|
*/
|
|
230
230
|
interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
231
231
|
prompt?: string;
|
|
232
|
-
schema?: LLMSchema;
|
|
232
|
+
schema?: LLMSchema | object;
|
|
233
233
|
systemPrompt?: string;
|
|
234
234
|
allowExternalLinks?: boolean;
|
|
235
235
|
includeSubdomains?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -229,7 +229,7 @@ interface MapResponse {
|
|
|
229
229
|
*/
|
|
230
230
|
interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
231
231
|
prompt?: string;
|
|
232
|
-
schema?: LLMSchema;
|
|
232
|
+
schema?: LLMSchema | object;
|
|
233
233
|
systemPrompt?: string;
|
|
234
234
|
allowExternalLinks?: boolean;
|
|
235
235
|
includeSubdomains?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import axios, { AxiosError } from "axios";
|
|
3
|
+
import * as zt from "zod";
|
|
3
4
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
5
|
import { WebSocket } from "isows";
|
|
5
6
|
import { TypedEventTarget } from "typescript-event-target";
|
|
@@ -456,15 +457,18 @@ var FirecrawlApp = class {
|
|
|
456
457
|
*/
|
|
457
458
|
async extract(urls, params) {
|
|
458
459
|
const headers = this.prepareHeaders();
|
|
459
|
-
if (!params?.prompt) {
|
|
460
|
-
throw new FirecrawlError("Prompt is required", 400);
|
|
461
|
-
}
|
|
462
460
|
let jsonData = { urls, ...params };
|
|
463
461
|
let jsonSchema;
|
|
464
462
|
try {
|
|
465
|
-
|
|
463
|
+
if (!params?.schema) {
|
|
464
|
+
jsonSchema = void 0;
|
|
465
|
+
} else if (params.schema instanceof zt.ZodType) {
|
|
466
|
+
jsonSchema = zodToJsonSchema(params.schema);
|
|
467
|
+
} else {
|
|
468
|
+
jsonSchema = params.schema;
|
|
469
|
+
}
|
|
466
470
|
} catch (error) {
|
|
467
|
-
throw new FirecrawlError("Invalid schema.
|
|
471
|
+
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
|
|
468
472
|
}
|
|
469
473
|
try {
|
|
470
474
|
const response = await this.postRequest(
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { type AxiosResponse, type AxiosRequestHeaders, AxiosError } from "axios";
|
|
2
|
-
import
|
|
2
|
+
import * as zt from "zod";
|
|
3
3
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
4
|
import { WebSocket } from "isows";
|
|
5
5
|
import { TypedEventTarget } from "typescript-event-target";
|
|
@@ -247,7 +247,7 @@ export interface MapResponse {
|
|
|
247
247
|
*/
|
|
248
248
|
export interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
249
249
|
prompt?: string;
|
|
250
|
-
schema?: LLMSchema;
|
|
250
|
+
schema?: LLMSchema | object;
|
|
251
251
|
systemPrompt?: string;
|
|
252
252
|
allowExternalLinks?: boolean;
|
|
253
253
|
includeSubdomains?: boolean;
|
|
@@ -835,16 +835,18 @@ export default class FirecrawlApp {
|
|
|
835
835
|
async extract<T extends zt.ZodSchema = any>(urls: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse> {
|
|
836
836
|
const headers = this.prepareHeaders();
|
|
837
837
|
|
|
838
|
-
if (!params?.prompt) {
|
|
839
|
-
throw new FirecrawlError("Prompt is required", 400);
|
|
840
|
-
}
|
|
841
|
-
|
|
842
838
|
let jsonData: { urls: string[] } & ExtractParams<T> = { urls, ...params };
|
|
843
839
|
let jsonSchema: any;
|
|
844
840
|
try {
|
|
845
|
-
|
|
841
|
+
if (!params?.schema) {
|
|
842
|
+
jsonSchema = undefined;
|
|
843
|
+
} else if (params.schema instanceof zt.ZodType) {
|
|
844
|
+
jsonSchema = zodToJsonSchema(params.schema);
|
|
845
|
+
} else {
|
|
846
|
+
jsonSchema = params.schema;
|
|
847
|
+
}
|
|
846
848
|
} catch (error: any) {
|
|
847
|
-
throw new FirecrawlError("Invalid schema.
|
|
849
|
+
throw new FirecrawlError("Invalid schema. Schema must be either a valid Zod schema or JSON schema object.", 400);
|
|
848
850
|
}
|
|
849
851
|
|
|
850
852
|
try {
|