@dealcrawl/sdk 2.2.0 → 2.3.0

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.d.mts CHANGED
@@ -776,6 +776,69 @@ interface UpdatePreferencesResponse {
776
776
  success: boolean;
777
777
  preferences: ClientPreferences;
778
778
  }
779
+ /** Agent job creation response */
780
+ interface AgentJobResponse extends JobResponse {
781
+ /** Estimated completion time based on maxSteps */
782
+ estimatedTime?: string;
783
+ }
784
+ /** Agent step in execution trace */
785
+ interface AgentStepResponse {
786
+ /** Step number (1-indexed) */
787
+ step: number;
788
+ /** Agent's reasoning before action */
789
+ thought: string;
790
+ /** Type of action taken */
791
+ actionType: string;
792
+ /** Action details */
793
+ action: Record<string, unknown>;
794
+ /** Whether the action succeeded */
795
+ result: "success" | "failed" | "skipped";
796
+ /** Duration of this step in ms */
797
+ durationMs: number;
798
+ /** Error message if failed */
799
+ error?: string;
800
+ /** Screenshot URL if captured */
801
+ screenshotUrl?: string;
802
+ /** Current URL after action */
803
+ currentUrl?: string;
804
+ }
805
+ /** Agent completion reason */
806
+ type AgentCompletionReason = "goal_achieved" | "max_steps_reached" | "stuck" | "error" | "cancelled";
807
+ /** Agent result (from completed job) */
808
+ interface AgentResultResponse {
809
+ /** Extracted/collected data (matches provided schema if given) */
810
+ data: Record<string, unknown>;
811
+ /** Steps executed by the agent */
812
+ steps: AgentStepResponse[];
813
+ /** Final URL after all navigation */
814
+ finalUrl: string;
815
+ /** Credits/tokens used */
816
+ creditsUsed: number;
817
+ /** Total execution time in ms */
818
+ totalDurationMs: number;
819
+ /** Screenshots captured (if takeScreenshots enabled) */
820
+ screenshots?: string[];
821
+ /** Completion reason */
822
+ completionReason: AgentCompletionReason;
823
+ /** Agent metadata */
824
+ metadata: {
825
+ model: string;
826
+ stepsExecuted: number;
827
+ tokensUsed?: number;
828
+ timestamp: string;
829
+ };
830
+ }
831
+ /** Agent status response (extended from JobStatusResponse) */
832
+ interface AgentStatusResponse extends JobStatusResponse {
833
+ /** Partial result with steps so far */
834
+ partialResult?: {
835
+ steps: AgentStepResponse[];
836
+ currentUrl?: string;
837
+ extractedData?: Record<string, unknown>;
838
+ };
839
+ /** Final result when completed */
840
+ result?: AgentResultResponse;
841
+ }
779
842
 
780
843
  /**
781
844
  * Polling Utilities
@@ -1197,7 +1260,7 @@ interface UpdateWebhookOptions {
1197
1260
  * API key scope - Must match @dealcrawl/shared/src/types/api-key.types.ts
1198
1261
  * These are the actual scopes enforced by the backend via requireScope() middleware
1199
1262
  */
1200
- type ApiKeyScope = "scrape" | "crawl" | "dork" | "extract" | "status" | "data:read" | "data:export" | "keys:manage" | "webhooks:manage";
1263
+ type ApiKeyScope = "scrape" | "crawl" | "dork" | "extract" | "agent" | "status" | "data:read" | "data:export" | "keys:manage" | "webhooks:manage";
1201
1264
  /**
1202
1265
  * All available scopes (for reference and validation)
1203
1266
  */
@@ -1250,6 +1313,111 @@ interface UpdatePreferencesOptions {
1250
1313
  /** Enable webhook notifications */
1251
1314
  webhookEnabled?: boolean;
1252
1315
  }
1316
+ /** LLM provider for agent */
1317
+ type AgentModel = "openai" | "anthropic";
1318
+ /** Browser action types */
1319
+ type AgentActionType = "click" | "scroll" | "write" | "wait" | "press" | "screenshot" | "hover" | "select";
1320
+ /** Base action interface */
1321
+ interface BaseAgentAction {
1322
+ type: AgentActionType;
1323
+ optional?: boolean;
1324
+ retries?: number;
1325
+ delayBefore?: number;
1326
+ }
1327
+ /** Click action */
1328
+ interface ClickAction extends BaseAgentAction {
1329
+ type: "click";
1330
+ selector: string;
1331
+ waitAfter?: number;
1332
+ button?: "left" | "right" | "middle";
1333
+ clickCount?: number;
1334
+ force?: boolean;
1335
+ }
1336
+ /** Scroll action */
1337
+ interface ScrollAction extends BaseAgentAction {
1338
+ type: "scroll";
1339
+ direction: "up" | "down" | "left" | "right" | "to-element";
1340
+ selector?: string;
1341
+ amount?: number;
1342
+ smooth?: boolean;
1343
+ }
1344
+ /** Write action */
1345
+ interface WriteAction extends BaseAgentAction {
1346
+ type: "write";
1347
+ selector: string;
1348
+ text: string;
1349
+ clearFirst?: boolean;
1350
+ pressEnter?: boolean;
1351
+ typeDelay?: number;
1352
+ }
1353
+ /** Wait action */
1354
+ interface WaitAction extends BaseAgentAction {
1355
+ type: "wait";
1356
+ milliseconds?: number;
1357
+ selector?: string;
1358
+ condition?: "visible" | "hidden" | "attached" | "detached";
1359
+ timeout?: number;
1360
+ }
1361
+ /** Press action */
1362
+ interface PressAction extends BaseAgentAction {
1363
+ type: "press";
1364
+ key: string;
1365
+ modifiers?: Array<"Alt" | "Control" | "Meta" | "Shift">;
1366
+ }
1367
+ /** Screenshot action */
1368
+ interface ScreenshotAgentAction extends BaseAgentAction {
1369
+ type: "screenshot";
1370
+ fullPage?: boolean;
1371
+ selector?: string;
1372
+ format?: "png" | "jpeg";
1373
+ quality?: number;
1374
+ name?: string;
1375
+ }
1376
+ /** Hover action */
1377
+ interface HoverAction extends BaseAgentAction {
1378
+ type: "hover";
1379
+ selector: string;
1380
+ duration?: number;
1381
+ }
1382
+ /** Select action */
1383
+ interface SelectAction extends BaseAgentAction {
1384
+ type: "select";
1385
+ selector: string;
1386
+ value: string | string[];
1387
+ byLabel?: boolean;
1388
+ }
1389
+ /** All agent action types */
1390
+ type AgentAction = ClickAction | ScrollAction | WriteAction | WaitAction | PressAction | ScreenshotAgentAction | HoverAction | SelectAction;
1391
+ /** Options for creating an AI agent job */
1392
+ interface AgentOptions {
1393
+ /** Starting URL for the agent (required) */
1394
+ url: string;
1395
+ /** Additional URLs to process */
1396
+ urls?: string[];
1397
+ /** Natural language instructions for the agent (required, 10-2000 chars) */
1398
+ prompt: string;
1399
+ /** JSON Schema for structured output */
1400
+ schema?: Record<string, unknown>;
1401
+ /** Maximum number of steps (default: 10, max: 25) */
1402
+ maxSteps?: number;
1403
+ /** Preset actions to execute before agent reasoning */
1404
+ actions?: AgentAction[];
1405
+ /** LLM provider (default: openai) */
1406
+ model?: AgentModel;
1407
+ /** Per-step timeout in milliseconds (default: 30000, max: 60000) */
1408
+ timeout?: number;
1409
+ /** Extract only main content area (default: true) */
1410
+ onlyMainContent?: boolean;
1411
+ /** Take screenshots at each step (default: false) */
1412
+ takeScreenshots?: boolean;
1413
+ /** Custom headers for HTTP requests */
1414
+ headers?: Record<string, string>;
1415
+ /** Webhook for async notification */
1416
+ webhook?: {
1417
+ url: string;
1418
+ headers?: Record<string, string>;
1419
+ };
1420
+ }
1253
1421
 
1254
1422
  /**
1255
1423
  * Account Resource
@@ -1392,6 +1560,161 @@ declare class AccountResource {
1392
1560
  isPremium(): Promise<boolean>;
1393
1561
  }
1394
1562
 
1563
+ /**
1564
+ * Agent Resource
1565
+ * Handles AI agent operations for autonomous web navigation and data extraction
1566
+ */
1567
+
1568
+ /**
1569
+ * Agent resource class
1570
+ * Provides methods for creating and managing AI agent jobs
1571
+ *
1572
+ * The agent uses the ReAct pattern (Observation → Thought → Action → Evaluation)
1573
+ * to navigate web pages and extract structured data based on natural language instructions.
1574
+ *
1575
+ * @example
1576
+ * ```ts
1577
+ * // Create an agent to search and extract product info
1578
+ * const job = await client.agent.create({
1579
+ * url: "https://amazon.com",
1580
+ * prompt: "Search for wireless headphones under $50 and extract the top 5 results with name, price, and rating",
1581
+ * schema: {
1582
+ * type: "object",
1583
+ * properties: {
1584
+ * products: {
1585
+ * type: "array",
1586
+ * items: {
1587
+ * type: "object",
1588
+ * properties: {
1589
+ * name: { type: "string" },
1590
+ * price: { type: "number" },
1591
+ * rating: { type: "number" }
1592
+ * }
1593
+ * }
1594
+ * }
1595
+ * }
1596
+ * },
1597
+ * maxSteps: 15
1598
+ * });
1599
+ *
1600
+ * // Wait for result
1601
+ * const result = await client.waitForResult(job.jobId);
1602
+ * ```
1603
+ */
1604
+ declare class AgentResource {
1605
+ private ctx;
1606
+ constructor(ctx: RequestContext);
1607
+ /**
1608
+ * Create a new AI agent job
1609
+ *
1610
+ * @param options - Agent configuration options
1611
+ * @returns Job creation response with jobId and status URL
1612
+ *
1613
+ * @example
1614
+ * ```ts
1615
+ * const job = await client.agent.create({
1616
+ * url: "https://booking.com",
1617
+ * prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
1618
+ * maxSteps: 20,
1619
+ * takeScreenshots: true
1620
+ * });
1621
+ * ```
1622
+ */
1623
+ create(options: AgentOptions): Promise<AgentJobResponse>;
1624
+ /**
1625
+ * Get the status of an agent job
1626
+ *
1627
+ * @param jobId - The job ID to check
1628
+ * @returns Agent status with progress and partial results
1629
+ *
1630
+ * @example
1631
+ * ```ts
1632
+ * const status = await client.agent.getStatus(jobId);
1633
+ * console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
1634
+ * ```
1635
+ */
1636
+ getStatus(jobId: string): Promise<AgentStatusResponse>;
1637
+ /**
1638
+ * Create an agent with preset actions
1639
+ * Useful for handling common scenarios like cookie consent, popups, etc.
1640
+ *
1641
+ * @example
1642
+ * ```ts
1643
+ * const job = await client.agent.withPresetActions(
1644
+ * "https://shop.com",
1645
+ * "Find the best discount and extract product details",
1646
+ * [
1647
+ * { type: "click", selector: "#accept-cookies" },
1648
+ * { type: "wait", milliseconds: 1000 }
1649
+ * ]
1650
+ * );
1651
+ * ```
1652
+ */
1653
+ withPresetActions(url: string, prompt: string, actions: AgentOptions["actions"], options?: Omit<AgentOptions, "url" | "prompt" | "actions">): Promise<AgentJobResponse>;
1654
+ /**
1655
+ * Create an agent with a JSON schema for structured output
1656
+ * The agent will extract data matching the provided schema
1657
+ *
1658
+ * @example
1659
+ * ```ts
1660
+ * const job = await client.agent.withSchema(
1661
+ * "https://linkedin.com/company/example",
1662
+ * "Extract company information",
1663
+ * {
1664
+ * type: "object",
1665
+ * properties: {
1666
+ * name: { type: "string" },
1667
+ * employees: { type: "number" },
1668
+ * description: { type: "string" },
1669
+ * website: { type: "string" }
1670
+ * },
1671
+ * required: ["name"]
1672
+ * }
1673
+ * );
1674
+ * ```
1675
+ */
1676
+ withSchema(url: string, prompt: string, schema: Record<string, unknown>, options?: Omit<AgentOptions, "url" | "prompt" | "schema">): Promise<AgentJobResponse>;
1677
+ /**
1678
+ * Create an agent optimized for deal/product extraction
1679
+ * Pre-configured for e-commerce scenarios
1680
+ *
1681
+ * @example
1682
+ * ```ts
1683
+ * const job = await client.agent.forDeals(
1684
+ * "https://slickdeals.net",
1685
+ * "Find the top 10 tech deals posted today"
1686
+ * );
1687
+ * ```
1688
+ */
1689
+ forDeals(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "schema">): Promise<AgentJobResponse>;
1690
+ /**
1691
+ * Create an agent to fill and submit a form
1692
+ * Useful for search forms, login forms, etc.
1693
+ *
1694
+ * @example
1695
+ * ```ts
1696
+ * const job = await client.agent.fillForm(
1697
+ * "https://kayak.com",
1698
+ * "Search for flights from Paris to New York on March 20, return March 27",
1699
+ * { takeScreenshots: true }
1700
+ * );
1701
+ * ```
1702
+ */
1703
+ fillForm(url: string, instructions: string, options?: Omit<AgentOptions, "url" | "prompt">): Promise<AgentJobResponse>;
1704
+ /**
1705
+ * Create an agent using Claude (Anthropic) instead of GPT
1706
+ *
1707
+ * @example
1708
+ * ```ts
1709
+ * const job = await client.agent.withClaude(
1710
+ * "https://complex-site.com",
1711
+ * "Navigate through the multi-step checkout process"
1712
+ * );
1713
+ * ```
1714
+ */
1715
+ withClaude(url: string, prompt: string, options?: Omit<AgentOptions, "url" | "prompt" | "model">): Promise<AgentJobResponse>;
1716
+ }
1717
+
1395
1718
  /**
1396
1719
  * Crawl Resource
1397
1720
  * Handles website crawling operations
@@ -2504,6 +2827,29 @@ declare class DealCrawl {
2504
2827
  * ```
2505
2828
  */
2506
2829
  readonly dork: DorkResource;
2830
+ /**
2831
+ * Agent resource - AI-powered autonomous web navigation
2832
+ *
2833
+ * The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
2834
+ * to navigate web pages and extract structured data based on natural language.
2835
+ *
2836
+ * @example
2837
+ * ```ts
2838
+ * const job = await client.agent.create({
2839
+ * url: "https://amazon.com",
2840
+ * prompt: "Search for wireless headphones under $50 and extract top 5 results",
2841
+ * maxSteps: 15
2842
+ * });
2843
+ *
2844
+ * // With schema for structured output
2845
+ * const job = await client.agent.withSchema(
2846
+ * "https://example.com",
2847
+ * "Extract product info",
2848
+ * { type: "object", properties: {...} }
2849
+ * );
2850
+ * ```
2851
+ */
2852
+ readonly agent: AgentResource;
2507
2853
  /**
2508
2854
  * Status resource - Job status management
2509
2855
  *
@@ -2683,6 +3029,21 @@ declare class DealCrawl {
2683
3029
  * ```
2684
3030
  */
2685
3031
  searchAndWait(options: Parameters<SearchResource["create"]>[0]): Promise<ReturnType<SearchResource["create"]>>;
3032
+ /**
3033
+ * Create an agent job and wait for result
3034
+ * Combines create and waitForResult
3035
+ *
3036
+ * @example
3037
+ * ```ts
3038
+ * const result = await client.agentAndWait({
3039
+ * url: "https://booking.com",
3040
+ * prompt: "Find hotels in Paris for March 15-17",
3041
+ * maxSteps: 20
3042
+ * });
3043
+ * console.log(result.data);
3044
+ * ```
3045
+ */
3046
+ agentAndWait<T = unknown>(options: Parameters<AgentResource["create"]>[0], waitOptions?: WaitOptions): Promise<WaitResult<T>>;
2686
3047
  }
2687
3048
 
2688
3049
  /**
@@ -2766,4 +3127,4 @@ declare class DealCrawlError extends Error {
2766
3127
  }, retryAfter?: number | string | null): DealCrawlError;
2767
3128
  }
2768
3129
 
2769
- export { ALL_API_KEY_SCOPES, type AccountInfoResponse, type AccountMetricsResponse, AccountResource, type ApiError, type ApiKeyInfo, type ApiKeyScope, type ApiResponse, type BatchScrapeDefaults, type BatchScrapeItem, type BatchScrapeOptions, type BatchScrapeResponse, type BatchScrapeResultItem, type BatchStatusResponse, type CancelJobResponse, type CheckpointInfo, type ClientPreferences, type ClientStatsResponse, type CrawlAnalysisResponse, type CrawlJobResponse, type CrawlOptions, type CrawlRecommendation, CrawlResource, type CrawlResult, type CrawlTemplate, type CrawlTemplateId, type CreateApiKeyOptions, type CreateKeyResponse, type CreateWebhookOptions, type CreateWebhookResponse, type CreatedApiKey, DEFAULT_API_KEY_SCOPES, DEFAULT_CONFIG, DataResource, DealCrawl, type DealCrawlConfig, DealCrawlError, type DealDetails, type DealItem, type DealMetrics, type DealScoreSummary, type DealSummary, type DealUpMetrics, type DealUpMetricsResponse, type DeleteKeyResponse, type DeleteWebhookResponse, type DiscountSignal, type DorkJobResponse, type DorkOptions, DorkResource, type DorkResult, ERROR_CODES, type ErrorCode, type ExportDealsOptions, type ExportFormat, type ExportJobsOptions, type ExtractJobResponse, type ExtractModel, type ExtractOptions, ExtractResource, type ExtractedDeal, type GetApiKeyStatsOptions, type GetDealsOptions, type JobDealsResponse, type JobMetricsResponse, type JobResponse, type JobStatus, type JobStatusFilter, type JobStatusResponse, type JobSummary, type JobTypeFilter, type KeyStatsResponse, KeysResource, type ListApiKeysOptions, type ListDealsOptions, type ListDealsResponse, type ListJobsOptions, type ListJobsResponse, type ListKeysResponse, type ListWebhooksResponse, type PaginatedResponse, type PaginationInfo, type ParsedPage, type PreferencesResponse, type PriceSignal, type PricingInfo, type ProductCategory, type ProductInfo, type RateLimitInfo, type RecommendationsResponse, type RequestContext, type ResumeJobResponse, type RevokeApiKeyOptions, type RotateApiKeyOptions, type RotateKeyResponse, type ScrapeJobResponse, type ScrapeOptions, ScrapeResource, type ScrapeResult, type ScreenshotOptions, type SearchAiModel, type SearchAiProvider, type SearchData, type SearchDateRange, type SearchFilters, type SearchJobResponse, type SearchOptions, SearchResource, type SearchResultItem, type SearchStatusResponse, type Signal, type SortOrder, StatusResource, type TestWebhookResponse, type UpdatePreferencesOptions, type UpdatePreferencesResponse, type UpdateWebhookOptions, type UpdateWebhookResponse, type UsageStats, type WaitOptions, type WaitResult, type WebhookEvent, type WebhookItem, WebhooksResource, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };
3130
+ export { ALL_API_KEY_SCOPES, type AccountInfoResponse, type AccountMetricsResponse, AccountResource, type AgentAction, type AgentActionType, type AgentCompletionReason, type AgentJobResponse, type AgentModel, type AgentOptions, AgentResource, type AgentResultResponse, type AgentStatusResponse, type AgentStepResponse, type ApiError, type ApiKeyInfo, type ApiKeyScope, type ApiResponse, type BatchScrapeDefaults, type BatchScrapeItem, type BatchScrapeOptions, type BatchScrapeResponse, type BatchScrapeResultItem, type BatchStatusResponse, type CancelJobResponse, type CheckpointInfo, type ClickAction, type ClientPreferences, type ClientStatsResponse, type CrawlAnalysisResponse, type CrawlJobResponse, type CrawlOptions, type CrawlRecommendation, CrawlResource, type CrawlResult, type CrawlTemplate, type CrawlTemplateId, type CreateApiKeyOptions, type CreateKeyResponse, type CreateWebhookOptions, type CreateWebhookResponse, type CreatedApiKey, DEFAULT_API_KEY_SCOPES, DEFAULT_CONFIG, DataResource, DealCrawl, type DealCrawlConfig, DealCrawlError, type DealDetails, type DealItem, type DealMetrics, type DealScoreSummary, type DealSummary, type DealUpMetrics, type DealUpMetricsResponse, type DeleteKeyResponse, type DeleteWebhookResponse, type DiscountSignal, type DorkJobResponse, type DorkOptions, DorkResource, type DorkResult, ERROR_CODES, type ErrorCode, type ExportDealsOptions, type ExportFormat, type ExportJobsOptions, type ExtractJobResponse, type ExtractModel, type ExtractOptions, ExtractResource, type ExtractedDeal, type GetApiKeyStatsOptions, type GetDealsOptions, type HoverAction, type JobDealsResponse, type JobMetricsResponse, type JobResponse, type JobStatus, type JobStatusFilter, type JobStatusResponse, type JobSummary, type JobTypeFilter, type KeyStatsResponse, KeysResource, type ListApiKeysOptions, type ListDealsOptions, type ListDealsResponse, type ListJobsOptions, type ListJobsResponse, type ListKeysResponse, type ListWebhooksResponse, type PaginatedResponse, type PaginationInfo, type ParsedPage, type PreferencesResponse, type PressAction, type PriceSignal, type PricingInfo, type ProductCategory, type ProductInfo, type RateLimitInfo, type RecommendationsResponse, type RequestContext, type ResumeJobResponse, type RevokeApiKeyOptions, type RotateApiKeyOptions, type RotateKeyResponse, type ScrapeJobResponse, type ScrapeOptions, ScrapeResource, type ScrapeResult, type ScreenshotAgentAction, type ScreenshotOptions, type ScrollAction, type SearchAiModel, type SearchAiProvider, type SearchData, type SearchDateRange, type SearchFilters, type SearchJobResponse, type SearchOptions, SearchResource, type SearchResultItem, type SearchStatusResponse, type SelectAction, type Signal, type SortOrder, StatusResource, type TestWebhookResponse, type UpdatePreferencesOptions, type UpdatePreferencesResponse, type UpdateWebhookOptions, type UpdateWebhookResponse, type UsageStats, type WaitAction, type WaitOptions, type WaitResult, type WebhookEvent, type WebhookItem, WebhooksResource, type WriteAction, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };