@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.mjs CHANGED
@@ -585,6 +585,203 @@ var AccountResource = class {
585
585
  }
586
586
  };
587
587
 
588
+ // src/resources/agent.ts
589
+ var AgentResource = class {
590
+ constructor(ctx) {
591
+ this.ctx = ctx;
592
+ }
593
+ /**
594
+ * Create a new AI agent job
595
+ *
596
+ * @param options - Agent configuration options
597
+ * @returns Job creation response with jobId and status URL
598
+ *
599
+ * @example
600
+ * ```ts
601
+ * const job = await client.agent.create({
602
+ * url: "https://booking.com",
603
+ * prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
604
+ * maxSteps: 20,
605
+ * takeScreenshots: true
606
+ * });
607
+ * ```
608
+ */
609
+ async create(options) {
610
+ const body = {
611
+ url: options.url,
612
+ urls: options.urls,
613
+ prompt: options.prompt,
614
+ schema: options.schema,
615
+ maxSteps: options.maxSteps ?? 10,
616
+ actions: options.actions,
617
+ model: options.model ?? "openai",
618
+ timeout: options.timeout ?? 3e4,
619
+ onlyMainContent: options.onlyMainContent ?? true,
620
+ takeScreenshots: options.takeScreenshots ?? false,
621
+ headers: options.headers,
622
+ webhook: options.webhook
623
+ };
624
+ const result = await post(this.ctx, "/v1/agent", body);
625
+ return result.data;
626
+ }
627
+ /**
628
+ * Get the status of an agent job
629
+ *
630
+ * @param jobId - The job ID to check
631
+ * @returns Agent status with progress and partial results
632
+ *
633
+ * @example
634
+ * ```ts
635
+ * const status = await client.agent.getStatus(jobId);
636
+ * console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
637
+ * ```
638
+ */
639
+ async getStatus(jobId) {
640
+ const result = await get(
641
+ this.ctx,
642
+ `/v1/status/${jobId}`
643
+ );
644
+ return result.data;
645
+ }
646
+ /**
647
+ * Create an agent with preset actions
648
+ * Useful for handling common scenarios like cookie consent, popups, etc.
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * const job = await client.agent.withPresetActions(
653
+ * "https://shop.com",
654
+ * "Find the best discount and extract product details",
655
+ * [
656
+ * { type: "click", selector: "#accept-cookies" },
657
+ * { type: "wait", milliseconds: 1000 }
658
+ * ]
659
+ * );
660
+ * ```
661
+ */
662
+ async withPresetActions(url, prompt, actions, options) {
663
+ return this.create({
664
+ url,
665
+ prompt,
666
+ actions,
667
+ ...options
668
+ });
669
+ }
670
+ /**
671
+ * Create an agent with a JSON schema for structured output
672
+ * The agent will extract data matching the provided schema
673
+ *
674
+ * @example
675
+ * ```ts
676
+ * const job = await client.agent.withSchema(
677
+ * "https://linkedin.com/company/example",
678
+ * "Extract company information",
679
+ * {
680
+ * type: "object",
681
+ * properties: {
682
+ * name: { type: "string" },
683
+ * employees: { type: "number" },
684
+ * description: { type: "string" },
685
+ * website: { type: "string" }
686
+ * },
687
+ * required: ["name"]
688
+ * }
689
+ * );
690
+ * ```
691
+ */
692
+ async withSchema(url, prompt, schema, options) {
693
+ return this.create({
694
+ url,
695
+ prompt,
696
+ schema,
697
+ ...options
698
+ });
699
+ }
700
+ /**
701
+ * Create an agent optimized for deal/product extraction
702
+ * Pre-configured for e-commerce scenarios
703
+ *
704
+ * @example
705
+ * ```ts
706
+ * const job = await client.agent.forDeals(
707
+ * "https://slickdeals.net",
708
+ * "Find the top 10 tech deals posted today"
709
+ * );
710
+ * ```
711
+ */
712
+ async forDeals(url, prompt, options) {
713
+ return this.create({
714
+ url,
715
+ prompt: `${prompt}. Extract deal information including: product name, current price, original price (if available), discount percentage, merchant/store, and any promo codes or coupons.`,
716
+ schema: {
717
+ type: "object",
718
+ properties: {
719
+ deals: {
720
+ type: "array",
721
+ items: {
722
+ type: "object",
723
+ properties: {
724
+ productName: { type: "string" },
725
+ currentPrice: { type: "number" },
726
+ originalPrice: { type: "number" },
727
+ discountPercent: { type: "number" },
728
+ merchant: { type: "string" },
729
+ promoCode: { type: "string" },
730
+ url: { type: "string" },
731
+ expiresAt: { type: "string" }
732
+ },
733
+ required: ["productName", "currentPrice"]
734
+ }
735
+ }
736
+ },
737
+ required: ["deals"]
738
+ },
739
+ maxSteps: options?.maxSteps ?? 15,
740
+ ...options
741
+ });
742
+ }
743
+ /**
744
+ * Create an agent to fill and submit a form
745
+ * Useful for search forms, login forms, etc.
746
+ *
747
+ * @example
748
+ * ```ts
749
+ * const job = await client.agent.fillForm(
750
+ * "https://kayak.com",
751
+ * "Search for flights from Paris to New York on March 20, return March 27",
752
+ * { takeScreenshots: true }
753
+ * );
754
+ * ```
755
+ */
756
+ async fillForm(url, instructions, options) {
757
+ return this.create({
758
+ url,
759
+ prompt: `Navigate to the form and ${instructions}. After submitting, extract the results.`,
760
+ maxSteps: options?.maxSteps ?? 12,
761
+ ...options
762
+ });
763
+ }
764
+ /**
765
+ * Create an agent using Claude (Anthropic) instead of GPT
766
+ *
767
+ * @example
768
+ * ```ts
769
+ * const job = await client.agent.withClaude(
770
+ * "https://complex-site.com",
771
+ * "Navigate through the multi-step checkout process"
772
+ * );
773
+ * ```
774
+ */
775
+ async withClaude(url, prompt, options) {
776
+ return this.create({
777
+ url,
778
+ prompt,
779
+ model: "anthropic",
780
+ ...options
781
+ });
782
+ }
783
+ };
784
+
588
785
  // src/resources/crawl.ts
589
786
  var CRAWL_TEMPLATES = {
590
787
  ecommerce: {
@@ -2274,6 +2471,29 @@ var DealCrawl = class {
2274
2471
  * ```
2275
2472
  */
2276
2473
  dork;
2474
+ /**
2475
+ * Agent resource - AI-powered autonomous web navigation
2476
+ *
2477
+ * The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
2478
+ * to navigate web pages and extract structured data based on natural language.
2479
+ *
2480
+ * @example
2481
+ * ```ts
2482
+ * const job = await client.agent.create({
2483
+ * url: "https://amazon.com",
2484
+ * prompt: "Search for wireless headphones under $50 and extract top 5 results",
2485
+ * maxSteps: 15
2486
+ * });
2487
+ *
2488
+ * // With schema for structured output
2489
+ * const job = await client.agent.withSchema(
2490
+ * "https://example.com",
2491
+ * "Extract product info",
2492
+ * { type: "object", properties: {...} }
2493
+ * );
2494
+ * ```
2495
+ */
2496
+ agent;
2277
2497
  /**
2278
2498
  * Status resource - Job status management
2279
2499
  *
@@ -2373,6 +2593,7 @@ var DealCrawl = class {
2373
2593
  this.crawl = new CrawlResource(this.ctx);
2374
2594
  this.extract = new ExtractResource(this.ctx);
2375
2595
  this.dork = new DorkResource(this.ctx);
2596
+ this.agent = new AgentResource(this.ctx);
2376
2597
  this.status = new StatusResource(this.ctx);
2377
2598
  this.data = new DataResource(this.ctx);
2378
2599
  this.webhooks = new WebhooksResource(this.ctx);
@@ -2501,8 +2722,26 @@ var DealCrawl = class {
2501
2722
  async searchAndWait(options) {
2502
2723
  return this.search.create(options);
2503
2724
  }
2725
+ /**
2726
+ * Create an agent job and wait for result
2727
+ * Combines create and waitForResult
2728
+ *
2729
+ * @example
2730
+ * ```ts
2731
+ * const result = await client.agentAndWait({
2732
+ * url: "https://booking.com",
2733
+ * prompt: "Find hotels in Paris for March 15-17",
2734
+ * maxSteps: 20
2735
+ * });
2736
+ * console.log(result.data);
2737
+ * ```
2738
+ */
2739
+ async agentAndWait(options, waitOptions) {
2740
+ const job = await this.agent.create(options);
2741
+ return this.waitForResult(job.jobId, waitOptions);
2742
+ }
2504
2743
  };
2505
2744
 
2506
- export { AccountResource, CrawlResource, DEFAULT_CONFIG, DataResource, DealCrawl, DealCrawlError, DorkResource, ERROR_CODES, ExtractResource, KeysResource, ScrapeResource, SearchResource, StatusResource, WebhooksResource, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };
2745
+ export { AccountResource, AgentResource, CrawlResource, DEFAULT_CONFIG, DataResource, DealCrawl, DealCrawlError, DorkResource, ERROR_CODES, ExtractResource, KeysResource, ScrapeResource, SearchResource, StatusResource, WebhooksResource, DealCrawl as default, pollUntil, waitForAll, waitForAny, waitForResult };
2507
2746
  //# sourceMappingURL=index.mjs.map
2508
2747
  //# sourceMappingURL=index.mjs.map