@dealcrawl/sdk 2.2.0 → 2.4.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 +443 -2
- package/dist/index.d.ts +443 -2
- package/dist/index.js +299 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -3
package/dist/index.js
CHANGED
|
@@ -589,6 +589,262 @@ var AccountResource = class {
|
|
|
589
589
|
}
|
|
590
590
|
};
|
|
591
591
|
|
|
592
|
+
// src/resources/agent.ts
|
|
593
|
+
var AgentResource = class {
|
|
594
|
+
constructor(ctx) {
|
|
595
|
+
this.ctx = ctx;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Create a new AI agent job
|
|
599
|
+
*
|
|
600
|
+
* @param options - Agent configuration options
|
|
601
|
+
* @returns Job creation response with jobId and status URL
|
|
602
|
+
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```ts
|
|
605
|
+
* const job = await client.agent.create({
|
|
606
|
+
* url: "https://booking.com",
|
|
607
|
+
* prompt: "Find hotels in Paris for 2 adults, March 15-17, sort by price and extract the 3 cheapest options",
|
|
608
|
+
* maxSteps: 20,
|
|
609
|
+
* takeScreenshots: true
|
|
610
|
+
* });
|
|
611
|
+
* ```
|
|
612
|
+
*/
|
|
613
|
+
async create(options) {
|
|
614
|
+
const body = {
|
|
615
|
+
url: options.url,
|
|
616
|
+
urls: options.urls,
|
|
617
|
+
prompt: options.prompt,
|
|
618
|
+
schema: options.schema,
|
|
619
|
+
maxSteps: options.maxSteps ?? 10,
|
|
620
|
+
actions: options.actions,
|
|
621
|
+
model: options.model ?? "openai",
|
|
622
|
+
timeout: options.timeout ?? 3e4,
|
|
623
|
+
onlyMainContent: options.onlyMainContent ?? true,
|
|
624
|
+
takeScreenshots: options.takeScreenshots ?? false,
|
|
625
|
+
headers: options.headers,
|
|
626
|
+
webhook: options.webhook
|
|
627
|
+
};
|
|
628
|
+
const result = await post(this.ctx, "/v1/agent", body);
|
|
629
|
+
return result.data;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get the status of an agent job
|
|
633
|
+
*
|
|
634
|
+
* @param jobId - The job ID to check
|
|
635
|
+
* @returns Agent status with progress and partial results
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```ts
|
|
639
|
+
* const status = await client.agent.getStatus(jobId);
|
|
640
|
+
* console.log(`Step ${status.partialResult?.steps.length}/${status.totalSteps}`);
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
async getStatus(jobId) {
|
|
644
|
+
const result = await get(
|
|
645
|
+
this.ctx,
|
|
646
|
+
`/v1/status/${jobId}`
|
|
647
|
+
);
|
|
648
|
+
return result.data;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Create an agent with preset actions
|
|
652
|
+
* Useful for handling common scenarios like cookie consent, popups, etc.
|
|
653
|
+
*
|
|
654
|
+
* @example
|
|
655
|
+
* ```ts
|
|
656
|
+
* const job = await client.agent.withPresetActions(
|
|
657
|
+
* "https://shop.com",
|
|
658
|
+
* "Find the best discount and extract product details",
|
|
659
|
+
* [
|
|
660
|
+
* { type: "click", selector: "#accept-cookies" },
|
|
661
|
+
* { type: "wait", milliseconds: 1000 }
|
|
662
|
+
* ]
|
|
663
|
+
* );
|
|
664
|
+
* ```
|
|
665
|
+
*/
|
|
666
|
+
async withPresetActions(url, prompt, actions, options) {
|
|
667
|
+
return this.create({
|
|
668
|
+
url,
|
|
669
|
+
prompt,
|
|
670
|
+
actions,
|
|
671
|
+
...options
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Create an agent with a JSON schema for structured output
|
|
676
|
+
* The agent will extract data matching the provided schema
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* const job = await client.agent.withSchema(
|
|
681
|
+
* "https://linkedin.com/company/example",
|
|
682
|
+
* "Extract company information",
|
|
683
|
+
* {
|
|
684
|
+
* type: "object",
|
|
685
|
+
* properties: {
|
|
686
|
+
* name: { type: "string" },
|
|
687
|
+
* employees: { type: "number" },
|
|
688
|
+
* description: { type: "string" },
|
|
689
|
+
* website: { type: "string" }
|
|
690
|
+
* },
|
|
691
|
+
* required: ["name"]
|
|
692
|
+
* }
|
|
693
|
+
* );
|
|
694
|
+
* ```
|
|
695
|
+
*/
|
|
696
|
+
async withSchema(url, prompt, schema, options) {
|
|
697
|
+
return this.create({
|
|
698
|
+
url,
|
|
699
|
+
prompt,
|
|
700
|
+
schema,
|
|
701
|
+
...options
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* Create an agent optimized for deal/product extraction
|
|
706
|
+
* Pre-configured for e-commerce scenarios
|
|
707
|
+
*
|
|
708
|
+
* @example
|
|
709
|
+
* ```ts
|
|
710
|
+
* const job = await client.agent.forDeals(
|
|
711
|
+
* "https://slickdeals.net",
|
|
712
|
+
* "Find the top 10 tech deals posted today"
|
|
713
|
+
* );
|
|
714
|
+
* ```
|
|
715
|
+
*/
|
|
716
|
+
async forDeals(url, prompt, options) {
|
|
717
|
+
return this.create({
|
|
718
|
+
url,
|
|
719
|
+
prompt: `${prompt}. Extract deal information including: product name, current price, original price (if available), discount percentage, merchant/store, and any promo codes or coupons.`,
|
|
720
|
+
schema: {
|
|
721
|
+
type: "object",
|
|
722
|
+
properties: {
|
|
723
|
+
deals: {
|
|
724
|
+
type: "array",
|
|
725
|
+
items: {
|
|
726
|
+
type: "object",
|
|
727
|
+
properties: {
|
|
728
|
+
productName: { type: "string" },
|
|
729
|
+
currentPrice: { type: "number" },
|
|
730
|
+
originalPrice: { type: "number" },
|
|
731
|
+
discountPercent: { type: "number" },
|
|
732
|
+
merchant: { type: "string" },
|
|
733
|
+
promoCode: { type: "string" },
|
|
734
|
+
url: { type: "string" },
|
|
735
|
+
expiresAt: { type: "string" }
|
|
736
|
+
},
|
|
737
|
+
required: ["productName", "currentPrice"]
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
required: ["deals"]
|
|
742
|
+
},
|
|
743
|
+
maxSteps: options?.maxSteps ?? 15,
|
|
744
|
+
...options
|
|
745
|
+
});
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Create an agent to fill and submit a form
|
|
749
|
+
* Useful for search forms, login forms, etc.
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```ts
|
|
753
|
+
* const job = await client.agent.fillForm(
|
|
754
|
+
* "https://kayak.com",
|
|
755
|
+
* "Search for flights from Paris to New York on March 20, return March 27",
|
|
756
|
+
* { takeScreenshots: true }
|
|
757
|
+
* );
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
async fillForm(url, instructions, options) {
|
|
761
|
+
return this.create({
|
|
762
|
+
url,
|
|
763
|
+
prompt: `Navigate to the form and ${instructions}. After submitting, extract the results.`,
|
|
764
|
+
maxSteps: options?.maxSteps ?? 12,
|
|
765
|
+
...options
|
|
766
|
+
});
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Create an agent using Claude (Anthropic) instead of GPT
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* const job = await client.agent.withClaude(
|
|
774
|
+
* "https://complex-site.com",
|
|
775
|
+
* "Navigate through the multi-step checkout process"
|
|
776
|
+
* );
|
|
777
|
+
* ```
|
|
778
|
+
*/
|
|
779
|
+
async withClaude(url, prompt, options) {
|
|
780
|
+
return this.create({
|
|
781
|
+
url,
|
|
782
|
+
prompt,
|
|
783
|
+
model: "anthropic",
|
|
784
|
+
...options
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Generate a JSON Schema from a natural language prompt
|
|
789
|
+
*
|
|
790
|
+
* This is useful for building extraction schemas without manual JSON writing.
|
|
791
|
+
* The generated schema can be used with the main agent.create() method.
|
|
792
|
+
*
|
|
793
|
+
* @param options - Schema generation options
|
|
794
|
+
* @returns Generated schema with refined prompt and confidence score
|
|
795
|
+
*
|
|
796
|
+
* @example Basic usage:
|
|
797
|
+
* ```ts
|
|
798
|
+
* const result = await client.agent.generateSchema({
|
|
799
|
+
* prompt: "Find the best student deals on Coursera for marketing courses"
|
|
800
|
+
* });
|
|
801
|
+
*
|
|
802
|
+
* console.log(result.schema);
|
|
803
|
+
* // { type: "object", properties: { courses: { ... } } }
|
|
804
|
+
*
|
|
805
|
+
* console.log(result.refinedPrompt);
|
|
806
|
+
* // "Extract student offers for marketing courses..."
|
|
807
|
+
*
|
|
808
|
+
* // Use the generated schema with an agent
|
|
809
|
+
* const job = await client.agent.create({
|
|
810
|
+
* url: "https://coursera.org",
|
|
811
|
+
* prompt: result.refinedPrompt,
|
|
812
|
+
* schema: result.schema
|
|
813
|
+
* });
|
|
814
|
+
* ```
|
|
815
|
+
*
|
|
816
|
+
* @example With context from conversation:
|
|
817
|
+
* ```ts
|
|
818
|
+
* const result = await client.agent.generateSchema({
|
|
819
|
+
* prompt: "Find student deals on online courses",
|
|
820
|
+
* context: {
|
|
821
|
+
* domains: ["marketing", "web development"],
|
|
822
|
+
* dataTypes: ["free courses", "discounts"],
|
|
823
|
+
* format: "json"
|
|
824
|
+
* }
|
|
825
|
+
* });
|
|
826
|
+
*
|
|
827
|
+
* if (result.confidence < 0.7 && result.suggestedQuestions) {
|
|
828
|
+
* // Ask user for clarification
|
|
829
|
+
* console.log("Please clarify:", result.suggestedQuestions);
|
|
830
|
+
* }
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
async generateSchema(options) {
|
|
834
|
+
const body = {
|
|
835
|
+
prompt: options.prompt,
|
|
836
|
+
context: options.context,
|
|
837
|
+
model: options.model ?? "openai"
|
|
838
|
+
};
|
|
839
|
+
const result = await post(
|
|
840
|
+
this.ctx,
|
|
841
|
+
"/v1/agent/schema",
|
|
842
|
+
body
|
|
843
|
+
);
|
|
844
|
+
return result.data;
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
|
|
592
848
|
// src/resources/crawl.ts
|
|
593
849
|
var CRAWL_TEMPLATES = {
|
|
594
850
|
ecommerce: {
|
|
@@ -2278,6 +2534,29 @@ var DealCrawl = class {
|
|
|
2278
2534
|
* ```
|
|
2279
2535
|
*/
|
|
2280
2536
|
dork;
|
|
2537
|
+
/**
|
|
2538
|
+
* Agent resource - AI-powered autonomous web navigation
|
|
2539
|
+
*
|
|
2540
|
+
* The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
|
|
2541
|
+
* to navigate web pages and extract structured data based on natural language.
|
|
2542
|
+
*
|
|
2543
|
+
* @example
|
|
2544
|
+
* ```ts
|
|
2545
|
+
* const job = await client.agent.create({
|
|
2546
|
+
* url: "https://amazon.com",
|
|
2547
|
+
* prompt: "Search for wireless headphones under $50 and extract top 5 results",
|
|
2548
|
+
* maxSteps: 15
|
|
2549
|
+
* });
|
|
2550
|
+
*
|
|
2551
|
+
* // With schema for structured output
|
|
2552
|
+
* const job = await client.agent.withSchema(
|
|
2553
|
+
* "https://example.com",
|
|
2554
|
+
* "Extract product info",
|
|
2555
|
+
* { type: "object", properties: {...} }
|
|
2556
|
+
* );
|
|
2557
|
+
* ```
|
|
2558
|
+
*/
|
|
2559
|
+
agent;
|
|
2281
2560
|
/**
|
|
2282
2561
|
* Status resource - Job status management
|
|
2283
2562
|
*
|
|
@@ -2377,6 +2656,7 @@ var DealCrawl = class {
|
|
|
2377
2656
|
this.crawl = new CrawlResource(this.ctx);
|
|
2378
2657
|
this.extract = new ExtractResource(this.ctx);
|
|
2379
2658
|
this.dork = new DorkResource(this.ctx);
|
|
2659
|
+
this.agent = new AgentResource(this.ctx);
|
|
2380
2660
|
this.status = new StatusResource(this.ctx);
|
|
2381
2661
|
this.data = new DataResource(this.ctx);
|
|
2382
2662
|
this.webhooks = new WebhooksResource(this.ctx);
|
|
@@ -2505,9 +2785,28 @@ var DealCrawl = class {
|
|
|
2505
2785
|
async searchAndWait(options) {
|
|
2506
2786
|
return this.search.create(options);
|
|
2507
2787
|
}
|
|
2788
|
+
/**
|
|
2789
|
+
* Create an agent job and wait for result
|
|
2790
|
+
* Combines create and waitForResult
|
|
2791
|
+
*
|
|
2792
|
+
* @example
|
|
2793
|
+
* ```ts
|
|
2794
|
+
* const result = await client.agentAndWait({
|
|
2795
|
+
* url: "https://booking.com",
|
|
2796
|
+
* prompt: "Find hotels in Paris for March 15-17",
|
|
2797
|
+
* maxSteps: 20
|
|
2798
|
+
* });
|
|
2799
|
+
* console.log(result.data);
|
|
2800
|
+
* ```
|
|
2801
|
+
*/
|
|
2802
|
+
async agentAndWait(options, waitOptions) {
|
|
2803
|
+
const job = await this.agent.create(options);
|
|
2804
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
2805
|
+
}
|
|
2508
2806
|
};
|
|
2509
2807
|
|
|
2510
2808
|
exports.AccountResource = AccountResource;
|
|
2809
|
+
exports.AgentResource = AgentResource;
|
|
2511
2810
|
exports.CrawlResource = CrawlResource;
|
|
2512
2811
|
exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
2513
2812
|
exports.DataResource = DataResource;
|