@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.mjs
CHANGED
|
@@ -585,6 +585,262 @@ 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
|
+
* Generate a JSON Schema from a natural language prompt
|
|
785
|
+
*
|
|
786
|
+
* This is useful for building extraction schemas without manual JSON writing.
|
|
787
|
+
* The generated schema can be used with the main agent.create() method.
|
|
788
|
+
*
|
|
789
|
+
* @param options - Schema generation options
|
|
790
|
+
* @returns Generated schema with refined prompt and confidence score
|
|
791
|
+
*
|
|
792
|
+
* @example Basic usage:
|
|
793
|
+
* ```ts
|
|
794
|
+
* const result = await client.agent.generateSchema({
|
|
795
|
+
* prompt: "Find the best student deals on Coursera for marketing courses"
|
|
796
|
+
* });
|
|
797
|
+
*
|
|
798
|
+
* console.log(result.schema);
|
|
799
|
+
* // { type: "object", properties: { courses: { ... } } }
|
|
800
|
+
*
|
|
801
|
+
* console.log(result.refinedPrompt);
|
|
802
|
+
* // "Extract student offers for marketing courses..."
|
|
803
|
+
*
|
|
804
|
+
* // Use the generated schema with an agent
|
|
805
|
+
* const job = await client.agent.create({
|
|
806
|
+
* url: "https://coursera.org",
|
|
807
|
+
* prompt: result.refinedPrompt,
|
|
808
|
+
* schema: result.schema
|
|
809
|
+
* });
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* @example With context from conversation:
|
|
813
|
+
* ```ts
|
|
814
|
+
* const result = await client.agent.generateSchema({
|
|
815
|
+
* prompt: "Find student deals on online courses",
|
|
816
|
+
* context: {
|
|
817
|
+
* domains: ["marketing", "web development"],
|
|
818
|
+
* dataTypes: ["free courses", "discounts"],
|
|
819
|
+
* format: "json"
|
|
820
|
+
* }
|
|
821
|
+
* });
|
|
822
|
+
*
|
|
823
|
+
* if (result.confidence < 0.7 && result.suggestedQuestions) {
|
|
824
|
+
* // Ask user for clarification
|
|
825
|
+
* console.log("Please clarify:", result.suggestedQuestions);
|
|
826
|
+
* }
|
|
827
|
+
* ```
|
|
828
|
+
*/
|
|
829
|
+
async generateSchema(options) {
|
|
830
|
+
const body = {
|
|
831
|
+
prompt: options.prompt,
|
|
832
|
+
context: options.context,
|
|
833
|
+
model: options.model ?? "openai"
|
|
834
|
+
};
|
|
835
|
+
const result = await post(
|
|
836
|
+
this.ctx,
|
|
837
|
+
"/v1/agent/schema",
|
|
838
|
+
body
|
|
839
|
+
);
|
|
840
|
+
return result.data;
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
|
|
588
844
|
// src/resources/crawl.ts
|
|
589
845
|
var CRAWL_TEMPLATES = {
|
|
590
846
|
ecommerce: {
|
|
@@ -2274,6 +2530,29 @@ var DealCrawl = class {
|
|
|
2274
2530
|
* ```
|
|
2275
2531
|
*/
|
|
2276
2532
|
dork;
|
|
2533
|
+
/**
|
|
2534
|
+
* Agent resource - AI-powered autonomous web navigation
|
|
2535
|
+
*
|
|
2536
|
+
* The agent uses ReAct pattern (Observation → Thought → Action → Evaluation)
|
|
2537
|
+
* to navigate web pages and extract structured data based on natural language.
|
|
2538
|
+
*
|
|
2539
|
+
* @example
|
|
2540
|
+
* ```ts
|
|
2541
|
+
* const job = await client.agent.create({
|
|
2542
|
+
* url: "https://amazon.com",
|
|
2543
|
+
* prompt: "Search for wireless headphones under $50 and extract top 5 results",
|
|
2544
|
+
* maxSteps: 15
|
|
2545
|
+
* });
|
|
2546
|
+
*
|
|
2547
|
+
* // With schema for structured output
|
|
2548
|
+
* const job = await client.agent.withSchema(
|
|
2549
|
+
* "https://example.com",
|
|
2550
|
+
* "Extract product info",
|
|
2551
|
+
* { type: "object", properties: {...} }
|
|
2552
|
+
* );
|
|
2553
|
+
* ```
|
|
2554
|
+
*/
|
|
2555
|
+
agent;
|
|
2277
2556
|
/**
|
|
2278
2557
|
* Status resource - Job status management
|
|
2279
2558
|
*
|
|
@@ -2373,6 +2652,7 @@ var DealCrawl = class {
|
|
|
2373
2652
|
this.crawl = new CrawlResource(this.ctx);
|
|
2374
2653
|
this.extract = new ExtractResource(this.ctx);
|
|
2375
2654
|
this.dork = new DorkResource(this.ctx);
|
|
2655
|
+
this.agent = new AgentResource(this.ctx);
|
|
2376
2656
|
this.status = new StatusResource(this.ctx);
|
|
2377
2657
|
this.data = new DataResource(this.ctx);
|
|
2378
2658
|
this.webhooks = new WebhooksResource(this.ctx);
|
|
@@ -2501,8 +2781,26 @@ var DealCrawl = class {
|
|
|
2501
2781
|
async searchAndWait(options) {
|
|
2502
2782
|
return this.search.create(options);
|
|
2503
2783
|
}
|
|
2784
|
+
/**
|
|
2785
|
+
* Create an agent job and wait for result
|
|
2786
|
+
* Combines create and waitForResult
|
|
2787
|
+
*
|
|
2788
|
+
* @example
|
|
2789
|
+
* ```ts
|
|
2790
|
+
* const result = await client.agentAndWait({
|
|
2791
|
+
* url: "https://booking.com",
|
|
2792
|
+
* prompt: "Find hotels in Paris for March 15-17",
|
|
2793
|
+
* maxSteps: 20
|
|
2794
|
+
* });
|
|
2795
|
+
* console.log(result.data);
|
|
2796
|
+
* ```
|
|
2797
|
+
*/
|
|
2798
|
+
async agentAndWait(options, waitOptions) {
|
|
2799
|
+
const job = await this.agent.create(options);
|
|
2800
|
+
return this.waitForResult(job.jobId, waitOptions);
|
|
2801
|
+
}
|
|
2504
2802
|
};
|
|
2505
2803
|
|
|
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 };
|
|
2804
|
+
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
2805
|
//# sourceMappingURL=index.mjs.map
|
|
2508
2806
|
//# sourceMappingURL=index.mjs.map
|