@mendable/firecrawl 4.11.0 → 4.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.
@@ -8,7 +8,7 @@ var require_package = __commonJS({
8
8
  "package.json"(exports, module) {
9
9
  module.exports = {
10
10
  name: "@mendable/firecrawl-js",
11
- version: "4.11.0",
11
+ version: "4.11.2",
12
12
  description: "JavaScript SDK for Firecrawl API",
13
13
  main: "dist/index.js",
14
14
  types: "dist/index.d.ts",
@@ -22,8 +22,8 @@ var require_package = __commonJS({
22
22
  type: "module",
23
23
  scripts: {
24
24
  build: "tsup",
25
- "build-and-publish": "npm run build && npm publish --access public",
26
- "publish-beta": "npm run build && npm publish --access public --tag beta",
25
+ "build-and-publish": "pnpm run build && pnpm publish --access public",
26
+ "publish-beta": "pnpm run build && pnpm publish --access public --tag beta",
27
27
  test: "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/e2e/v2/*.test.ts --detectOpenHandles",
28
28
  "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/unit/v2/*.test.ts"
29
29
  },
package/dist/index.cjs CHANGED
@@ -35,7 +35,7 @@ var require_package = __commonJS({
35
35
  "package.json"(exports2, module2) {
36
36
  module2.exports = {
37
37
  name: "@mendable/firecrawl-js",
38
- version: "4.11.0",
38
+ version: "4.11.2",
39
39
  description: "JavaScript SDK for Firecrawl API",
40
40
  main: "dist/index.js",
41
41
  types: "dist/index.d.ts",
@@ -49,8 +49,8 @@ var require_package = __commonJS({
49
49
  type: "module",
50
50
  scripts: {
51
51
  build: "tsup",
52
- "build-and-publish": "npm run build && npm publish --access public",
53
- "publish-beta": "npm run build && npm publish --access public --tag beta",
52
+ "build-and-publish": "pnpm run build && pnpm publish --access public",
53
+ "publish-beta": "pnpm run build && pnpm publish --access public --tag beta",
54
54
  test: "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/e2e/v2/*.test.ts --detectOpenHandles",
55
55
  "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/unit/v2/*.test.ts"
56
56
  },
@@ -251,6 +251,12 @@ var JobTimeoutError = class extends SdkError {
251
251
 
252
252
  // src/v2/utils/validation.ts
253
253
  var import_zod_to_json_schema = require("zod-to-json-schema");
254
+ function looksLikeZodShape(obj) {
255
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
256
+ const values = Object.values(obj);
257
+ if (values.length === 0) return false;
258
+ return values.some((v) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
259
+ }
254
260
  function ensureValidFormats(formats) {
255
261
  if (!formats) return;
256
262
  for (const fmt of formats) {
@@ -272,6 +278,10 @@ function ensureValidFormats(formats) {
272
278
  j.schema = (0, import_zod_to_json_schema.zodToJsonSchema)(maybeSchema);
273
279
  } catch {
274
280
  }
281
+ } else if (looksLikeZodShape(maybeSchema)) {
282
+ throw new Error(
283
+ "json format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
284
+ );
275
285
  }
276
286
  continue;
277
287
  }
@@ -284,6 +294,10 @@ function ensureValidFormats(formats) {
284
294
  ct.schema = (0, import_zod_to_json_schema.zodToJsonSchema)(maybeSchema);
285
295
  } catch {
286
296
  }
297
+ } else if (looksLikeZodShape(maybeSchema)) {
298
+ throw new Error(
299
+ "changeTracking format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
300
+ );
287
301
  }
288
302
  continue;
289
303
  }
@@ -841,6 +855,7 @@ function prepareAgentPayload(args) {
841
855
  if (args.maxCredits !== null && args.maxCredits !== void 0) body.maxCredits = args.maxCredits;
842
856
  if (args.strictConstrainToURLs !== null && args.strictConstrainToURLs !== void 0) body.strictConstrainToURLs = args.strictConstrainToURLs;
843
857
  if (args.model !== null && args.model !== void 0) body.model = args.model;
858
+ if (args.webhook != null) body.webhook = args.webhook;
844
859
  return body;
845
860
  }
846
861
  async function startAgent(http, args) {
@@ -1424,7 +1439,7 @@ var import_axios3 = __toESM(require("axios"), 1);
1424
1439
  var zt2 = require("zod");
1425
1440
  var import_zod_to_json_schema4 = require("zod-to-json-schema");
1426
1441
 
1427
- // node_modules/typescript-event-target/dist/index.mjs
1442
+ // node_modules/.pnpm/typescript-event-target@1.1.1/node_modules/typescript-event-target/dist/index.mjs
1428
1443
  var e = class extends EventTarget {
1429
1444
  dispatchTypedEvent(s, t) {
1430
1445
  return super.dispatchEvent(t);
package/dist/index.d.cts CHANGED
@@ -122,6 +122,13 @@ interface WebhookConfig {
122
122
  metadata?: Record<string, string>;
123
123
  events?: Array<'completed' | 'failed' | 'page' | 'started'>;
124
124
  }
125
+ type AgentWebhookEvent = 'started' | 'action' | 'completed' | 'failed' | 'cancelled';
126
+ interface AgentWebhookConfig {
127
+ url: string;
128
+ headers?: Record<string, string>;
129
+ metadata?: Record<string, string>;
130
+ events?: AgentWebhookEvent[];
131
+ }
125
132
  interface BrandingProfile {
126
133
  colorScheme?: 'light' | 'dark';
127
134
  logo?: string | null;
@@ -594,6 +601,7 @@ declare function prepareAgentPayload(args: {
594
601
  maxCredits?: number;
595
602
  strictConstrainToURLs?: boolean;
596
603
  model?: "spark-1-pro" | "spark-1-mini";
604
+ webhook?: string | AgentWebhookConfig;
597
605
  }): Record<string, unknown>;
598
606
  declare function startAgent(http: HttpClient, args: Parameters<typeof prepareAgentPayload>[0]): Promise<AgentResponse>;
599
607
 
@@ -1727,4 +1735,4 @@ declare class Firecrawl extends FirecrawlClient {
1727
1735
  get v1(): FirecrawlApp;
1728
1736
  }
1729
1737
 
1730
- export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
1738
+ export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
package/dist/index.d.ts CHANGED
@@ -122,6 +122,13 @@ interface WebhookConfig {
122
122
  metadata?: Record<string, string>;
123
123
  events?: Array<'completed' | 'failed' | 'page' | 'started'>;
124
124
  }
125
+ type AgentWebhookEvent = 'started' | 'action' | 'completed' | 'failed' | 'cancelled';
126
+ interface AgentWebhookConfig {
127
+ url: string;
128
+ headers?: Record<string, string>;
129
+ metadata?: Record<string, string>;
130
+ events?: AgentWebhookEvent[];
131
+ }
125
132
  interface BrandingProfile {
126
133
  colorScheme?: 'light' | 'dark';
127
134
  logo?: string | null;
@@ -594,6 +601,7 @@ declare function prepareAgentPayload(args: {
594
601
  maxCredits?: number;
595
602
  strictConstrainToURLs?: boolean;
596
603
  model?: "spark-1-pro" | "spark-1-mini";
604
+ webhook?: string | AgentWebhookConfig;
597
605
  }): Record<string, unknown>;
598
606
  declare function startAgent(http: HttpClient, args: Parameters<typeof prepareAgentPayload>[0]): Promise<AgentResponse>;
599
607
 
@@ -1727,4 +1735,4 @@ declare class Firecrawl extends FirecrawlClient {
1727
1735
  get v1(): FirecrawlApp;
1728
1736
  }
1729
1737
 
1730
- export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
1738
+ export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, JobTimeoutError, type JsonFormat, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-X3D7QXG6.js";
3
+ } from "./chunk-GVCNL5KA.js";
4
4
 
5
5
  // src/v2/utils/httpClient.ts
6
6
  import axios from "axios";
@@ -132,6 +132,12 @@ var JobTimeoutError = class extends SdkError {
132
132
 
133
133
  // src/v2/utils/validation.ts
134
134
  import { zodToJsonSchema } from "zod-to-json-schema";
135
+ function looksLikeZodShape(obj) {
136
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
137
+ const values = Object.values(obj);
138
+ if (values.length === 0) return false;
139
+ return values.some((v) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
140
+ }
135
141
  function ensureValidFormats(formats) {
136
142
  if (!formats) return;
137
143
  for (const fmt of formats) {
@@ -153,6 +159,10 @@ function ensureValidFormats(formats) {
153
159
  j.schema = zodToJsonSchema(maybeSchema);
154
160
  } catch {
155
161
  }
162
+ } else if (looksLikeZodShape(maybeSchema)) {
163
+ throw new Error(
164
+ "json format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
165
+ );
156
166
  }
157
167
  continue;
158
168
  }
@@ -165,6 +175,10 @@ function ensureValidFormats(formats) {
165
175
  ct.schema = zodToJsonSchema(maybeSchema);
166
176
  } catch {
167
177
  }
178
+ } else if (looksLikeZodShape(maybeSchema)) {
179
+ throw new Error(
180
+ "changeTracking format schema appears to be a Zod schema's .shape property. Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. The SDK will automatically convert Zod schemas to JSON Schema format."
181
+ );
168
182
  }
169
183
  continue;
170
184
  }
@@ -722,6 +736,7 @@ function prepareAgentPayload(args) {
722
736
  if (args.maxCredits !== null && args.maxCredits !== void 0) body.maxCredits = args.maxCredits;
723
737
  if (args.strictConstrainToURLs !== null && args.strictConstrainToURLs !== void 0) body.strictConstrainToURLs = args.strictConstrainToURLs;
724
738
  if (args.model !== null && args.model !== void 0) body.model = args.model;
739
+ if (args.webhook != null) body.webhook = args.webhook;
725
740
  return body;
726
741
  }
727
742
  async function startAgent(http, args) {
@@ -1305,7 +1320,7 @@ import axios2, { AxiosError } from "axios";
1305
1320
  import "zod";
1306
1321
  import { zodToJsonSchema as zodToJsonSchema4 } from "zod-to-json-schema";
1307
1322
 
1308
- // node_modules/typescript-event-target/dist/index.mjs
1323
+ // node_modules/.pnpm/typescript-event-target@1.1.1/node_modules/typescript-event-target/dist/index.mjs
1309
1324
  var e = class extends EventTarget {
1310
1325
  dispatchTypedEvent(s, t) {
1311
1326
  return super.dispatchEvent(t);
@@ -1334,7 +1349,7 @@ var FirecrawlApp = class {
1334
1349
  if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
1335
1350
  return process.env.npm_package_version;
1336
1351
  }
1337
- const packageJson = await import("./package-A5RBY34U.js");
1352
+ const packageJson = await import("./package-LU5XQZAL.js");
1338
1353
  return packageJson.default.version;
1339
1354
  } catch (error) {
1340
1355
  const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
@@ -1,4 +1,4 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-X3D7QXG6.js";
3
+ } from "./chunk-GVCNL5KA.js";
4
4
  export default require_package();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl",
3
- "version": "4.11.0",
3
+ "version": "4.11.2",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,13 +12,6 @@
12
12
  }
13
13
  },
14
14
  "type": "module",
15
- "scripts": {
16
- "build": "tsup",
17
- "build-and-publish": "npm run build && npm publish --access public",
18
- "publish-beta": "npm run build && npm publish --access public --tag beta",
19
- "test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/e2e/v2/*.test.ts --detectOpenHandles",
20
- "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/unit/v2/*.test.ts"
21
- },
22
15
  "repository": {
23
16
  "type": "git",
24
17
  "url": "git+https://github.com/firecrawl/firecrawl.git"
@@ -61,13 +54,11 @@
61
54
  "engines": {
62
55
  "node": ">=22.0.0"
63
56
  },
64
- "pnpm": {
65
- "overrides": {
66
- "@babel/helpers@<7.26.10": ">=7.26.10",
67
- "brace-expansion@>=1.0.0 <=1.1.11": ">=1.1.12",
68
- "brace-expansion@>=2.0.0 <=2.0.1": ">=2.0.2",
69
- "js-yaml@<3.14.2": ">=3.14.2",
70
- "glob@>=10.2.0 <10.5.0": ">=10.5.0"
71
- }
57
+ "scripts": {
58
+ "build": "tsup",
59
+ "build-and-publish": "pnpm run build && pnpm publish --access public",
60
+ "publish-beta": "pnpm run build && pnpm publish --access public --tag beta",
61
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/e2e/v2/*.test.ts --detectOpenHandles",
62
+ "test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --verbose src/__tests__/unit/v2/*.test.ts"
72
63
  }
73
- }
64
+ }
@@ -0,0 +1,80 @@
1
+ import { describe, test, expect } from "@jest/globals";
2
+
3
+ // We need to test the prepareAgentPayload function, but it's not exported.
4
+ // Since the function is internal, we'll test the behavior through type checking
5
+ // and verify the types are properly exported.
6
+
7
+ import type { AgentWebhookConfig, AgentWebhookEvent } from "../../../v2/types";
8
+
9
+ describe("v2 types: Agent webhook types", () => {
10
+ test("AgentWebhookConfig accepts string webhook", () => {
11
+ // Type check - this should compile without errors
12
+ const webhook: string | AgentWebhookConfig = "https://example.com/webhook";
13
+ expect(typeof webhook).toBe("string");
14
+ });
15
+
16
+ test("AgentWebhookConfig accepts config object", () => {
17
+ const config: AgentWebhookConfig = {
18
+ url: "https://example.com/webhook",
19
+ headers: { Authorization: "Bearer token" },
20
+ events: ["completed", "failed"],
21
+ };
22
+ expect(config.url).toBe("https://example.com/webhook");
23
+ expect(config.headers).toEqual({ Authorization: "Bearer token" });
24
+ expect(config.events).toEqual(["completed", "failed"]);
25
+ });
26
+
27
+ test("AgentWebhookConfig accepts minimal config", () => {
28
+ const config: AgentWebhookConfig = {
29
+ url: "https://example.com/webhook",
30
+ };
31
+ expect(config.url).toBe("https://example.com/webhook");
32
+ expect(config.headers).toBeUndefined();
33
+ expect(config.metadata).toBeUndefined();
34
+ expect(config.events).toBeUndefined();
35
+ });
36
+
37
+ test("AgentWebhookEvent includes agent-specific events", () => {
38
+ const events: AgentWebhookEvent[] = [
39
+ "started",
40
+ "action",
41
+ "completed",
42
+ "failed",
43
+ "cancelled",
44
+ ];
45
+ expect(events).toContain("action");
46
+ expect(events).toContain("cancelled");
47
+ expect(events.length).toBe(5);
48
+ });
49
+
50
+ test("AgentWebhookConfig accepts all fields", () => {
51
+ const config: AgentWebhookConfig = {
52
+ url: "https://example.com/webhook",
53
+ headers: {
54
+ Authorization: "Bearer token",
55
+ "X-Custom-Header": "value",
56
+ },
57
+ metadata: {
58
+ project: "test",
59
+ environment: "staging",
60
+ },
61
+ events: ["started", "action", "completed", "failed", "cancelled"],
62
+ };
63
+ expect(config.url).toBe("https://example.com/webhook");
64
+ expect(Object.keys(config.headers!).length).toBe(2);
65
+ expect(config.metadata!.project).toBe("test");
66
+ expect(config.events!.length).toBe(5);
67
+ });
68
+
69
+ test("AgentWebhookConfig events are agent-specific (not crawl)", () => {
70
+ // Agent has 'action' and 'cancelled', but not 'page'
71
+ const config: AgentWebhookConfig = {
72
+ url: "https://example.com/webhook",
73
+ events: ["action", "cancelled"],
74
+ };
75
+ expect(config.events).toContain("action");
76
+ expect(config.events).toContain("cancelled");
77
+ // 'page' is a crawl-specific event, not valid for agent
78
+ // This is enforced at the type level
79
+ });
80
+ });
@@ -62,5 +62,23 @@ describe("v2 utils: validation", () => {
62
62
  expect(() => ensureValidScrapeOptions(options)).not.toThrow();
63
63
  expect(options.parsers).toEqual(before);
64
64
  });
65
+
66
+ test("ensureValidFormats: detects mistaken use of zod schema.shape", () => {
67
+ const schema = z.object({ title: z.string(), count: z.number() });
68
+ // User mistakenly passes schema.shape instead of schema
69
+ const formats: FormatOption[] = [
70
+ { type: "json", prompt: "extract", schema: schema.shape } as any,
71
+ ];
72
+ expect(() => ensureValidFormats(formats)).toThrow(/\.shape property/i);
73
+ expect(() => ensureValidFormats(formats)).toThrow(/Pass the Zod schema directly/i);
74
+ });
75
+
76
+ test("ensureValidFormats: detects mistaken use of zod schema.shape in changeTracking", () => {
77
+ const schema = z.object({ title: z.string() });
78
+ const formats: FormatOption[] = [
79
+ { type: "changeTracking", modes: ["json"], schema: schema.shape } as any,
80
+ ];
81
+ expect(() => ensureValidFormats(formats)).toThrow(/\.shape property/i);
82
+ });
65
83
  });
66
84
 
@@ -1,4 +1,4 @@
1
- import { type AgentResponse, type AgentStatusResponse } from "../types";
1
+ import { type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig } from "../types";
2
2
  import { HttpClient } from "../utils/httpClient";
3
3
  import { normalizeAxiosError, throwForBadResponse } from "../utils/errorHandler";
4
4
  import { zodToJsonSchema } from "zod-to-json-schema";
@@ -12,6 +12,7 @@ function prepareAgentPayload(args: {
12
12
  maxCredits?: number;
13
13
  strictConstrainToURLs?: boolean;
14
14
  model?: "spark-1-pro" | "spark-1-mini";
15
+ webhook?: string | AgentWebhookConfig;
15
16
  }): Record<string, unknown> {
16
17
  const body: Record<string, unknown> = {};
17
18
  if (args.urls) body.urls = args.urls;
@@ -25,6 +26,7 @@ function prepareAgentPayload(args: {
25
26
  if (args.maxCredits !== null && args.maxCredits !== undefined) body.maxCredits = args.maxCredits;
26
27
  if (args.strictConstrainToURLs !== null && args.strictConstrainToURLs !== undefined) body.strictConstrainToURLs = args.strictConstrainToURLs;
27
28
  if (args.model !== null && args.model !== undefined) body.model = args.model;
29
+ if (args.webhook != null) body.webhook = args.webhook;
28
30
  return body;
29
31
  }
30
32
 
package/src/v2/types.ts CHANGED
@@ -167,6 +167,16 @@ export interface WebhookConfig {
167
167
  events?: Array<'completed' | 'failed' | 'page' | 'started'>;
168
168
  }
169
169
 
170
+ // Agent webhook events differ from crawl: has 'action' and 'cancelled', no 'page'
171
+ export type AgentWebhookEvent = 'started' | 'action' | 'completed' | 'failed' | 'cancelled';
172
+
173
+ export interface AgentWebhookConfig {
174
+ url: string;
175
+ headers?: Record<string, string>;
176
+ metadata?: Record<string, string>;
177
+ events?: AgentWebhookEvent[];
178
+ }
179
+
170
180
  export interface BrandingProfile {
171
181
  colorScheme?: 'light' | 'dark';
172
182
  logo?: string | null;
@@ -1,6 +1,19 @@
1
1
  import { type FormatOption, type JsonFormat, type ScrapeOptions, type ScreenshotFormat, type ChangeTrackingFormat } from "../types";
2
2
  import { zodToJsonSchema } from "zod-to-json-schema";
3
3
 
4
+ /**
5
+ * Detects if an object looks like a Zod schema's `.shape` property.
6
+ * When users mistakenly pass `schema.shape` instead of `schema`, the object
7
+ * will have Zod types as values but won't be a Zod schema itself.
8
+ */
9
+ function looksLikeZodShape(obj: unknown): boolean {
10
+ if (!obj || typeof obj !== "object" || Array.isArray(obj)) return false;
11
+ const values = Object.values(obj);
12
+ if (values.length === 0) return false;
13
+ // Check if at least one value looks like a Zod type
14
+ return values.some((v: any) => v && typeof v === "object" && v._def && typeof v.safeParse === "function");
15
+ }
16
+
4
17
  export function ensureValidFormats(formats?: FormatOption[]): void {
5
18
  if (!formats) return;
6
19
  for (const fmt of formats) {
@@ -24,6 +37,13 @@ export function ensureValidFormats(formats?: FormatOption[]): void {
24
37
  } catch {
25
38
  // If conversion fails, leave as-is; server-side may still handle, or request will fail explicitly
26
39
  }
40
+ } else if (looksLikeZodShape(maybeSchema)) {
41
+ // User likely passed schema.shape instead of the schema itself
42
+ throw new Error(
43
+ "json format schema appears to be a Zod schema's .shape property. " +
44
+ "Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. " +
45
+ "The SDK will automatically convert Zod schemas to JSON Schema format."
46
+ );
27
47
  }
28
48
  continue;
29
49
  }
@@ -37,6 +57,12 @@ export function ensureValidFormats(formats?: FormatOption[]): void {
37
57
  } catch {
38
58
  // Best-effort conversion; if it fails, leave original value
39
59
  }
60
+ } else if (looksLikeZodShape(maybeSchema)) {
61
+ throw new Error(
62
+ "changeTracking format schema appears to be a Zod schema's .shape property. " +
63
+ "Pass the Zod schema directly (e.g., `schema: MySchema`) instead of `schema: MySchema.shape`. " +
64
+ "The SDK will automatically convert Zod schemas to JSON Schema format."
65
+ );
40
66
  }
41
67
  continue;
42
68
  }